blob: afc6ef81ca0c1c0f1e3d30f3f367023d7ee8b536 [file] [log] [blame]
Daniel Vetter9c065a72014-09-30 10:56:38 +02001/*
2 * Copyright © 2012-2014 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 *
23 * Authors:
24 * Eugeni Dodonov <eugeni.dodonov@intel.com>
25 * Daniel Vetter <daniel.vetter@ffwll.ch>
26 *
27 */
28
29#include <linux/pm_runtime.h>
30#include <linux/vgaarb.h>
31
32#include "i915_drv.h"
33#include "intel_drv.h"
Daniel Vetter9c065a72014-09-30 10:56:38 +020034
Daniel Vettere4e76842014-09-30 10:56:42 +020035/**
36 * DOC: runtime pm
37 *
38 * The i915 driver supports dynamic enabling and disabling of entire hardware
39 * blocks at runtime. This is especially important on the display side where
40 * software is supposed to control many power gates manually on recent hardware,
41 * since on the GT side a lot of the power management is done by the hardware.
42 * But even there some manual control at the device level is required.
43 *
44 * Since i915 supports a diverse set of platforms with a unified codebase and
45 * hardware engineers just love to shuffle functionality around between power
46 * domains there's a sizeable amount of indirection required. This file provides
47 * generic functions to the driver for grabbing and releasing references for
48 * abstract power domains. It then maps those to the actual power wells
49 * present for a given platform.
50 */
51
Suketu Shah5aefb232015-04-16 14:22:10 +053052bool intel_display_power_well_is_enabled(struct drm_i915_private *dev_priv,
Imre Deak438b8dc2017-07-11 23:42:30 +030053 enum i915_power_well_id power_well_id);
Suketu Shah5aefb232015-04-16 14:22:10 +053054
Imre Deak9c8d0b82016-06-13 16:44:34 +030055static struct i915_power_well *
Imre Deak438b8dc2017-07-11 23:42:30 +030056lookup_power_well(struct drm_i915_private *dev_priv,
57 enum i915_power_well_id power_well_id);
Imre Deak9c8d0b82016-06-13 16:44:34 +030058
Daniel Stone9895ad02015-11-20 15:55:33 +000059const char *
60intel_display_power_domain_str(enum intel_display_power_domain domain)
61{
62 switch (domain) {
63 case POWER_DOMAIN_PIPE_A:
64 return "PIPE_A";
65 case POWER_DOMAIN_PIPE_B:
66 return "PIPE_B";
67 case POWER_DOMAIN_PIPE_C:
68 return "PIPE_C";
69 case POWER_DOMAIN_PIPE_A_PANEL_FITTER:
70 return "PIPE_A_PANEL_FITTER";
71 case POWER_DOMAIN_PIPE_B_PANEL_FITTER:
72 return "PIPE_B_PANEL_FITTER";
73 case POWER_DOMAIN_PIPE_C_PANEL_FITTER:
74 return "PIPE_C_PANEL_FITTER";
75 case POWER_DOMAIN_TRANSCODER_A:
76 return "TRANSCODER_A";
77 case POWER_DOMAIN_TRANSCODER_B:
78 return "TRANSCODER_B";
79 case POWER_DOMAIN_TRANSCODER_C:
80 return "TRANSCODER_C";
81 case POWER_DOMAIN_TRANSCODER_EDP:
82 return "TRANSCODER_EDP";
Jani Nikula4d1de972016-03-18 17:05:42 +020083 case POWER_DOMAIN_TRANSCODER_DSI_A:
84 return "TRANSCODER_DSI_A";
85 case POWER_DOMAIN_TRANSCODER_DSI_C:
86 return "TRANSCODER_DSI_C";
Daniel Stone9895ad02015-11-20 15:55:33 +000087 case POWER_DOMAIN_PORT_DDI_A_LANES:
88 return "PORT_DDI_A_LANES";
89 case POWER_DOMAIN_PORT_DDI_B_LANES:
90 return "PORT_DDI_B_LANES";
91 case POWER_DOMAIN_PORT_DDI_C_LANES:
92 return "PORT_DDI_C_LANES";
93 case POWER_DOMAIN_PORT_DDI_D_LANES:
94 return "PORT_DDI_D_LANES";
95 case POWER_DOMAIN_PORT_DDI_E_LANES:
96 return "PORT_DDI_E_LANES";
Rodrigo Vivi9787e832018-01-29 15:22:22 -080097 case POWER_DOMAIN_PORT_DDI_F_LANES:
98 return "PORT_DDI_F_LANES";
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +020099 case POWER_DOMAIN_PORT_DDI_A_IO:
100 return "PORT_DDI_A_IO";
101 case POWER_DOMAIN_PORT_DDI_B_IO:
102 return "PORT_DDI_B_IO";
103 case POWER_DOMAIN_PORT_DDI_C_IO:
104 return "PORT_DDI_C_IO";
105 case POWER_DOMAIN_PORT_DDI_D_IO:
106 return "PORT_DDI_D_IO";
107 case POWER_DOMAIN_PORT_DDI_E_IO:
108 return "PORT_DDI_E_IO";
Rodrigo Vivi9787e832018-01-29 15:22:22 -0800109 case POWER_DOMAIN_PORT_DDI_F_IO:
110 return "PORT_DDI_F_IO";
Daniel Stone9895ad02015-11-20 15:55:33 +0000111 case POWER_DOMAIN_PORT_DSI:
112 return "PORT_DSI";
113 case POWER_DOMAIN_PORT_CRT:
114 return "PORT_CRT";
115 case POWER_DOMAIN_PORT_OTHER:
116 return "PORT_OTHER";
117 case POWER_DOMAIN_VGA:
118 return "VGA";
119 case POWER_DOMAIN_AUDIO:
120 return "AUDIO";
121 case POWER_DOMAIN_PLLS:
122 return "PLLS";
123 case POWER_DOMAIN_AUX_A:
124 return "AUX_A";
125 case POWER_DOMAIN_AUX_B:
126 return "AUX_B";
127 case POWER_DOMAIN_AUX_C:
128 return "AUX_C";
129 case POWER_DOMAIN_AUX_D:
130 return "AUX_D";
Rodrigo Vivia324fca2018-01-29 15:22:15 -0800131 case POWER_DOMAIN_AUX_F:
132 return "AUX_F";
Dhinakaran Pandiyanb891d5e2018-02-23 14:15:15 -0800133 case POWER_DOMAIN_AUX_IO_A:
134 return "AUX_IO_A";
Daniel Stone9895ad02015-11-20 15:55:33 +0000135 case POWER_DOMAIN_GMBUS:
136 return "GMBUS";
137 case POWER_DOMAIN_INIT:
138 return "INIT";
139 case POWER_DOMAIN_MODESET:
140 return "MODESET";
Tvrtko Ursulinb6876372017-12-05 13:28:54 +0000141 case POWER_DOMAIN_GT_IRQ:
142 return "GT_IRQ";
Daniel Stone9895ad02015-11-20 15:55:33 +0000143 default:
144 MISSING_CASE(domain);
145 return "?";
146 }
147}
148
Damien Lespiaue8ca9322015-07-30 18:20:26 -0300149static void intel_power_well_enable(struct drm_i915_private *dev_priv,
150 struct i915_power_well *power_well)
151{
152 DRM_DEBUG_KMS("enabling %s\n", power_well->name);
153 power_well->ops->enable(dev_priv, power_well);
154 power_well->hw_enabled = true;
155}
156
Damien Lespiaudcddab32015-07-30 18:20:27 -0300157static void intel_power_well_disable(struct drm_i915_private *dev_priv,
158 struct i915_power_well *power_well)
159{
160 DRM_DEBUG_KMS("disabling %s\n", power_well->name);
161 power_well->hw_enabled = false;
162 power_well->ops->disable(dev_priv, power_well);
163}
164
Imre Deakb409ca92016-06-13 16:44:33 +0300165static void intel_power_well_get(struct drm_i915_private *dev_priv,
166 struct i915_power_well *power_well)
167{
168 if (!power_well->count++)
169 intel_power_well_enable(dev_priv, power_well);
170}
171
172static void intel_power_well_put(struct drm_i915_private *dev_priv,
173 struct i915_power_well *power_well)
174{
175 WARN(!power_well->count, "Use count on power well %s is already zero",
176 power_well->name);
177
178 if (!--power_well->count)
179 intel_power_well_disable(dev_priv, power_well);
180}
181
Daniel Vettere4e76842014-09-30 10:56:42 +0200182/**
183 * __intel_display_power_is_enabled - unlocked check for a power domain
184 * @dev_priv: i915 device instance
185 * @domain: power domain to check
186 *
187 * This is the unlocked version of intel_display_power_is_enabled() and should
188 * only be used from error capture and recovery code where deadlocks are
189 * possible.
190 *
191 * Returns:
192 * True when the power domain is enabled, false otherwise.
193 */
Daniel Vetterf458ebb2014-09-30 10:56:39 +0200194bool __intel_display_power_is_enabled(struct drm_i915_private *dev_priv,
195 enum intel_display_power_domain domain)
Daniel Vetter9c065a72014-09-30 10:56:38 +0200196{
Daniel Vetter9c065a72014-09-30 10:56:38 +0200197 struct i915_power_well *power_well;
198 bool is_enabled;
Daniel Vetter9c065a72014-09-30 10:56:38 +0200199
Sagar Arun Kamblead1443f2017-10-10 22:30:04 +0100200 if (dev_priv->runtime_pm.suspended)
Daniel Vetter9c065a72014-09-30 10:56:38 +0200201 return false;
202
Daniel Vetter9c065a72014-09-30 10:56:38 +0200203 is_enabled = true;
204
Imre Deak75ccb2e2017-02-17 17:39:43 +0200205 for_each_power_domain_well_rev(dev_priv, power_well, BIT_ULL(domain)) {
Daniel Vetter9c065a72014-09-30 10:56:38 +0200206 if (power_well->always_on)
207 continue;
208
209 if (!power_well->hw_enabled) {
210 is_enabled = false;
211 break;
212 }
213 }
214
215 return is_enabled;
216}
217
Daniel Vettere4e76842014-09-30 10:56:42 +0200218/**
Damien Lespiauf61ccae2014-11-25 13:45:41 +0000219 * intel_display_power_is_enabled - check for a power domain
Daniel Vettere4e76842014-09-30 10:56:42 +0200220 * @dev_priv: i915 device instance
221 * @domain: power domain to check
222 *
223 * This function can be used to check the hw power domain state. It is mostly
224 * used in hardware state readout functions. Everywhere else code should rely
225 * upon explicit power domain reference counting to ensure that the hardware
226 * block is powered up before accessing it.
227 *
228 * Callers must hold the relevant modesetting locks to ensure that concurrent
229 * threads can't disable the power well while the caller tries to read a few
230 * registers.
231 *
232 * Returns:
233 * True when the power domain is enabled, false otherwise.
234 */
Daniel Vetterf458ebb2014-09-30 10:56:39 +0200235bool intel_display_power_is_enabled(struct drm_i915_private *dev_priv,
236 enum intel_display_power_domain domain)
Daniel Vetter9c065a72014-09-30 10:56:38 +0200237{
238 struct i915_power_domains *power_domains;
239 bool ret;
240
241 power_domains = &dev_priv->power_domains;
242
243 mutex_lock(&power_domains->lock);
Daniel Vetterf458ebb2014-09-30 10:56:39 +0200244 ret = __intel_display_power_is_enabled(dev_priv, domain);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200245 mutex_unlock(&power_domains->lock);
246
247 return ret;
248}
249
Daniel Vettere4e76842014-09-30 10:56:42 +0200250/**
251 * intel_display_set_init_power - set the initial power domain state
252 * @dev_priv: i915 device instance
253 * @enable: whether to enable or disable the initial power domain state
254 *
255 * For simplicity our driver load/unload and system suspend/resume code assumes
256 * that all power domains are always enabled. This functions controls the state
257 * of this little hack. While the initial power domain state is enabled runtime
258 * pm is effectively disabled.
259 */
Daniel Vetterd9bc89d92014-09-30 10:56:40 +0200260void intel_display_set_init_power(struct drm_i915_private *dev_priv,
261 bool enable)
262{
263 if (dev_priv->power_domains.init_power_on == enable)
264 return;
265
266 if (enable)
267 intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
268 else
269 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
270
271 dev_priv->power_domains.init_power_on = enable;
272}
273
Daniel Vetter9c065a72014-09-30 10:56:38 +0200274/*
275 * Starting with Haswell, we have a "Power Down Well" that can be turned off
276 * when not needed anymore. We have 4 registers that can request the power well
277 * to be enabled, and it will only be disabled if none of the registers is
278 * requesting it to be enabled.
279 */
Imre Deak001bd2c2017-07-12 18:54:13 +0300280static void hsw_power_well_post_enable(struct drm_i915_private *dev_priv,
281 u8 irq_pipe_mask, bool has_vga)
Daniel Vetter9c065a72014-09-30 10:56:38 +0200282{
David Weinehall52a05c32016-08-22 13:32:44 +0300283 struct pci_dev *pdev = dev_priv->drm.pdev;
Daniel Vetter9c065a72014-09-30 10:56:38 +0200284
285 /*
286 * After we re-enable the power well, if we touch VGA register 0x3d5
287 * we'll get unclaimed register interrupts. This stops after we write
288 * anything to the VGA MSR register. The vgacon module uses this
289 * register all the time, so if we unbind our driver and, as a
290 * consequence, bind vgacon, we'll get stuck in an infinite loop at
291 * console_unlock(). So make here we touch the VGA MSR register, making
292 * sure vgacon can keep working normally without triggering interrupts
293 * and error messages.
294 */
Imre Deak001bd2c2017-07-12 18:54:13 +0300295 if (has_vga) {
296 vga_get_uninterruptible(pdev, VGA_RSRC_LEGACY_IO);
297 outb(inb(VGA_MSR_READ), VGA_MSR_WRITE);
298 vga_put(pdev, VGA_RSRC_LEGACY_IO);
299 }
Daniel Vetter9c065a72014-09-30 10:56:38 +0200300
Imre Deak001bd2c2017-07-12 18:54:13 +0300301 if (irq_pipe_mask)
302 gen8_irq_power_well_post_enable(dev_priv, irq_pipe_mask);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200303}
304
Imre Deak001bd2c2017-07-12 18:54:13 +0300305static void hsw_power_well_pre_disable(struct drm_i915_private *dev_priv,
306 u8 irq_pipe_mask)
Ville Syrjäläaae8ba82016-02-19 20:47:30 +0200307{
Imre Deak001bd2c2017-07-12 18:54:13 +0300308 if (irq_pipe_mask)
309 gen8_irq_power_well_pre_disable(dev_priv, irq_pipe_mask);
Ville Syrjäläaae8ba82016-02-19 20:47:30 +0200310}
311
Ville Syrjäläaae8ba82016-02-19 20:47:30 +0200312
Imre Deak76347c02017-07-06 17:40:36 +0300313static void hsw_wait_for_power_well_enable(struct drm_i915_private *dev_priv,
314 struct i915_power_well *power_well)
Imre Deak42d93662017-06-29 18:37:01 +0300315{
Imre Deak438b8dc2017-07-11 23:42:30 +0300316 enum i915_power_well_id id = power_well->id;
Imre Deak42d93662017-06-29 18:37:01 +0300317
318 /* Timeout for PW1:10 us, AUX:not specified, other PWs:20 us. */
319 WARN_ON(intel_wait_for_register(dev_priv,
Imre Deak9c3a16c2017-08-14 18:15:30 +0300320 HSW_PWR_WELL_CTL_DRIVER(id),
Imre Deak1af474f2017-07-06 17:40:34 +0300321 HSW_PWR_WELL_CTL_STATE(id),
322 HSW_PWR_WELL_CTL_STATE(id),
Imre Deak42d93662017-06-29 18:37:01 +0300323 1));
324}
325
Imre Deak76347c02017-07-06 17:40:36 +0300326static u32 hsw_power_well_requesters(struct drm_i915_private *dev_priv,
327 enum i915_power_well_id id)
Imre Deak42d93662017-06-29 18:37:01 +0300328{
Imre Deak1af474f2017-07-06 17:40:34 +0300329 u32 req_mask = HSW_PWR_WELL_CTL_REQ(id);
Imre Deak42d93662017-06-29 18:37:01 +0300330 u32 ret;
331
Imre Deak9c3a16c2017-08-14 18:15:30 +0300332 ret = I915_READ(HSW_PWR_WELL_CTL_BIOS(id)) & req_mask ? 1 : 0;
333 ret |= I915_READ(HSW_PWR_WELL_CTL_DRIVER(id)) & req_mask ? 2 : 0;
334 ret |= I915_READ(HSW_PWR_WELL_CTL_KVMR) & req_mask ? 4 : 0;
335 ret |= I915_READ(HSW_PWR_WELL_CTL_DEBUG(id)) & req_mask ? 8 : 0;
Imre Deak42d93662017-06-29 18:37:01 +0300336
337 return ret;
338}
339
Imre Deak76347c02017-07-06 17:40:36 +0300340static void hsw_wait_for_power_well_disable(struct drm_i915_private *dev_priv,
341 struct i915_power_well *power_well)
Imre Deak42d93662017-06-29 18:37:01 +0300342{
Imre Deak438b8dc2017-07-11 23:42:30 +0300343 enum i915_power_well_id id = power_well->id;
Imre Deak42d93662017-06-29 18:37:01 +0300344 bool disabled;
345 u32 reqs;
346
347 /*
348 * Bspec doesn't require waiting for PWs to get disabled, but still do
349 * this for paranoia. The known cases where a PW will be forced on:
350 * - a KVMR request on any power well via the KVMR request register
351 * - a DMC request on PW1 and MISC_IO power wells via the BIOS and
352 * DEBUG request registers
353 * Skip the wait in case any of the request bits are set and print a
354 * diagnostic message.
355 */
Imre Deak9c3a16c2017-08-14 18:15:30 +0300356 wait_for((disabled = !(I915_READ(HSW_PWR_WELL_CTL_DRIVER(id)) &
Imre Deak1af474f2017-07-06 17:40:34 +0300357 HSW_PWR_WELL_CTL_STATE(id))) ||
Imre Deak76347c02017-07-06 17:40:36 +0300358 (reqs = hsw_power_well_requesters(dev_priv, id)), 1);
Imre Deak42d93662017-06-29 18:37:01 +0300359 if (disabled)
360 return;
361
362 DRM_DEBUG_KMS("%s forced on (bios:%d driver:%d kvmr:%d debug:%d)\n",
363 power_well->name,
364 !!(reqs & 1), !!(reqs & 2), !!(reqs & 4), !!(reqs & 8));
365}
366
Imre Deakb2891eb2017-07-11 23:42:35 +0300367static void gen9_wait_for_power_well_fuses(struct drm_i915_private *dev_priv,
368 enum skl_power_gate pg)
369{
370 /* Timeout 5us for PG#0, for other PGs 1us */
371 WARN_ON(intel_wait_for_register(dev_priv, SKL_FUSE_STATUS,
372 SKL_FUSE_PG_DIST_STATUS(pg),
373 SKL_FUSE_PG_DIST_STATUS(pg), 1));
374}
375
Imre Deakec46d482017-07-06 17:40:33 +0300376static void hsw_power_well_enable(struct drm_i915_private *dev_priv,
377 struct i915_power_well *power_well)
Daniel Vetter9c065a72014-09-30 10:56:38 +0200378{
Imre Deak1af474f2017-07-06 17:40:34 +0300379 enum i915_power_well_id id = power_well->id;
Imre Deakb2891eb2017-07-11 23:42:35 +0300380 bool wait_fuses = power_well->hsw.has_fuses;
Chris Wilson320671f2017-10-02 11:04:16 +0100381 enum skl_power_gate uninitialized_var(pg);
Imre Deak1af474f2017-07-06 17:40:34 +0300382 u32 val;
383
Imre Deakb2891eb2017-07-11 23:42:35 +0300384 if (wait_fuses) {
385 pg = SKL_PW_TO_PG(id);
386 /*
387 * For PW1 we have to wait both for the PW0/PG0 fuse state
388 * before enabling the power well and PW1/PG1's own fuse
389 * state after the enabling. For all other power wells with
390 * fuses we only have to wait for that PW/PG's fuse state
391 * after the enabling.
392 */
393 if (pg == SKL_PG1)
394 gen9_wait_for_power_well_fuses(dev_priv, SKL_PG0);
395 }
396
Imre Deak9c3a16c2017-08-14 18:15:30 +0300397 val = I915_READ(HSW_PWR_WELL_CTL_DRIVER(id));
398 I915_WRITE(HSW_PWR_WELL_CTL_DRIVER(id), val | HSW_PWR_WELL_CTL_REQ(id));
Imre Deak76347c02017-07-06 17:40:36 +0300399 hsw_wait_for_power_well_enable(dev_priv, power_well);
Imre Deak001bd2c2017-07-12 18:54:13 +0300400
Lucas De Marchiddd39e42017-11-28 14:05:53 -0800401 /* Display WA #1178: cnl */
402 if (IS_CANNONLAKE(dev_priv) &&
403 (id == CNL_DISP_PW_AUX_B || id == CNL_DISP_PW_AUX_C ||
Rodrigo Vivib1ae6a82018-01-29 15:22:16 -0800404 id == CNL_DISP_PW_AUX_D || id == CNL_DISP_PW_AUX_F)) {
Lucas De Marchiddd39e42017-11-28 14:05:53 -0800405 val = I915_READ(CNL_AUX_ANAOVRD1(id));
406 val |= CNL_AUX_ANAOVRD1_ENABLE | CNL_AUX_ANAOVRD1_LDO_BYPASS;
407 I915_WRITE(CNL_AUX_ANAOVRD1(id), val);
408 }
409
Imre Deakb2891eb2017-07-11 23:42:35 +0300410 if (wait_fuses)
411 gen9_wait_for_power_well_fuses(dev_priv, pg);
412
Imre Deak001bd2c2017-07-12 18:54:13 +0300413 hsw_power_well_post_enable(dev_priv, power_well->hsw.irq_pipe_mask,
414 power_well->hsw.has_vga);
Imre Deakec46d482017-07-06 17:40:33 +0300415}
Daniel Vetter9c065a72014-09-30 10:56:38 +0200416
Imre Deakec46d482017-07-06 17:40:33 +0300417static void hsw_power_well_disable(struct drm_i915_private *dev_priv,
418 struct i915_power_well *power_well)
419{
Imre Deak1af474f2017-07-06 17:40:34 +0300420 enum i915_power_well_id id = power_well->id;
421 u32 val;
422
Imre Deak001bd2c2017-07-12 18:54:13 +0300423 hsw_power_well_pre_disable(dev_priv, power_well->hsw.irq_pipe_mask);
424
Imre Deak9c3a16c2017-08-14 18:15:30 +0300425 val = I915_READ(HSW_PWR_WELL_CTL_DRIVER(id));
426 I915_WRITE(HSW_PWR_WELL_CTL_DRIVER(id),
427 val & ~HSW_PWR_WELL_CTL_REQ(id));
Imre Deak76347c02017-07-06 17:40:36 +0300428 hsw_wait_for_power_well_disable(dev_priv, power_well);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200429}
430
Imre Deakd42539b2017-07-06 17:40:39 +0300431/*
432 * We should only use the power well if we explicitly asked the hardware to
433 * enable it, so check if it's enabled and also check if we've requested it to
434 * be enabled.
435 */
436static bool hsw_power_well_enabled(struct drm_i915_private *dev_priv,
437 struct i915_power_well *power_well)
438{
439 enum i915_power_well_id id = power_well->id;
440 u32 mask = HSW_PWR_WELL_CTL_REQ(id) | HSW_PWR_WELL_CTL_STATE(id);
441
Imre Deak9c3a16c2017-08-14 18:15:30 +0300442 return (I915_READ(HSW_PWR_WELL_CTL_DRIVER(id)) & mask) == mask;
Imre Deakd42539b2017-07-06 17:40:39 +0300443}
444
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530445static void assert_can_enable_dc9(struct drm_i915_private *dev_priv)
446{
Imre Deak9c3a16c2017-08-14 18:15:30 +0300447 enum i915_power_well_id id = SKL_DISP_PW_2;
448
Imre Deakbfcdabe2016-04-01 16:02:37 +0300449 WARN_ONCE((I915_READ(DC_STATE_EN) & DC_STATE_EN_DC9),
450 "DC9 already programmed to be enabled.\n");
451 WARN_ONCE(I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC5,
452 "DC5 still not disabled to enable DC9.\n");
Imre Deak9c3a16c2017-08-14 18:15:30 +0300453 WARN_ONCE(I915_READ(HSW_PWR_WELL_CTL_DRIVER(id)) &
454 HSW_PWR_WELL_CTL_REQ(id),
Imre Deake8a3a2a2017-06-29 18:37:00 +0300455 "Power well 2 on.\n");
Imre Deakbfcdabe2016-04-01 16:02:37 +0300456 WARN_ONCE(intel_irqs_enabled(dev_priv),
457 "Interrupts not disabled yet.\n");
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530458
459 /*
460 * TODO: check for the following to verify the conditions to enter DC9
461 * state are satisfied:
462 * 1] Check relevant display engine registers to verify if mode set
463 * disable sequence was followed.
464 * 2] Check if display uninitialize sequence is initialized.
465 */
466}
467
468static void assert_can_disable_dc9(struct drm_i915_private *dev_priv)
469{
Imre Deakbfcdabe2016-04-01 16:02:37 +0300470 WARN_ONCE(intel_irqs_enabled(dev_priv),
471 "Interrupts not disabled yet.\n");
472 WARN_ONCE(I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC5,
473 "DC5 still not disabled.\n");
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530474
475 /*
476 * TODO: check for the following to verify DC9 state was indeed
477 * entered before programming to disable it:
478 * 1] Check relevant display engine registers to verify if mode
479 * set disable sequence was followed.
480 * 2] Check if display uninitialize sequence is initialized.
481 */
482}
483
Mika Kuoppala779cb5d2016-02-18 17:58:09 +0200484static void gen9_write_dc_state(struct drm_i915_private *dev_priv,
485 u32 state)
486{
487 int rewrites = 0;
488 int rereads = 0;
489 u32 v;
490
491 I915_WRITE(DC_STATE_EN, state);
492
493 /* It has been observed that disabling the dc6 state sometimes
494 * doesn't stick and dmc keeps returning old value. Make sure
495 * the write really sticks enough times and also force rewrite until
496 * we are confident that state is exactly what we want.
497 */
498 do {
499 v = I915_READ(DC_STATE_EN);
500
501 if (v != state) {
502 I915_WRITE(DC_STATE_EN, state);
503 rewrites++;
504 rereads = 0;
505 } else if (rereads++ > 5) {
506 break;
507 }
508
509 } while (rewrites < 100);
510
511 if (v != state)
512 DRM_ERROR("Writing dc state to 0x%x failed, now 0x%x\n",
513 state, v);
514
515 /* Most of the times we need one retry, avoid spam */
516 if (rewrites > 1)
517 DRM_DEBUG_KMS("Rewrote dc state to 0x%x %d times\n",
518 state, rewrites);
519}
520
Imre Deakda2f41d2016-04-20 20:27:56 +0300521static u32 gen9_dc_mask(struct drm_i915_private *dev_priv)
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530522{
Imre Deakda2f41d2016-04-20 20:27:56 +0300523 u32 mask;
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530524
Imre Deak13ae3a02015-11-04 19:24:16 +0200525 mask = DC_STATE_EN_UPTO_DC5;
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200526 if (IS_GEN9_LP(dev_priv))
Imre Deak13ae3a02015-11-04 19:24:16 +0200527 mask |= DC_STATE_EN_DC9;
528 else
529 mask |= DC_STATE_EN_UPTO_DC6;
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530530
Imre Deakda2f41d2016-04-20 20:27:56 +0300531 return mask;
532}
533
534void gen9_sanitize_dc_state(struct drm_i915_private *dev_priv)
535{
536 u32 val;
537
538 val = I915_READ(DC_STATE_EN) & gen9_dc_mask(dev_priv);
539
540 DRM_DEBUG_KMS("Resetting DC state tracking from %02x to %02x\n",
541 dev_priv->csr.dc_state, val);
542 dev_priv->csr.dc_state = val;
543}
544
545static void gen9_set_dc_state(struct drm_i915_private *dev_priv, uint32_t state)
546{
547 uint32_t val;
548 uint32_t mask;
549
Imre Deaka37baf32016-02-29 22:49:03 +0200550 if (WARN_ON_ONCE(state & ~dev_priv->csr.allowed_dc_mask))
551 state &= dev_priv->csr.allowed_dc_mask;
Patrik Jakobsson443646c2015-11-16 15:01:06 +0100552
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530553 val = I915_READ(DC_STATE_EN);
Imre Deakda2f41d2016-04-20 20:27:56 +0300554 mask = gen9_dc_mask(dev_priv);
Imre Deak13ae3a02015-11-04 19:24:16 +0200555 DRM_DEBUG_KMS("Setting DC state from %02x to %02x\n",
556 val & mask, state);
Patrik Jakobsson832dba82016-02-18 17:21:11 +0200557
558 /* Check if DMC is ignoring our DC state requests */
559 if ((val & mask) != dev_priv->csr.dc_state)
560 DRM_ERROR("DC state mismatch (0x%x -> 0x%x)\n",
561 dev_priv->csr.dc_state, val & mask);
562
Imre Deak13ae3a02015-11-04 19:24:16 +0200563 val &= ~mask;
564 val |= state;
Mika Kuoppala779cb5d2016-02-18 17:58:09 +0200565
566 gen9_write_dc_state(dev_priv, val);
Patrik Jakobsson832dba82016-02-18 17:21:11 +0200567
568 dev_priv->csr.dc_state = val & mask;
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530569}
570
Imre Deak13ae3a02015-11-04 19:24:16 +0200571void bxt_enable_dc9(struct drm_i915_private *dev_priv)
572{
573 assert_can_enable_dc9(dev_priv);
574
575 DRM_DEBUG_KMS("Enabling DC9\n");
576
Imre Deak78597992016-06-16 16:37:20 +0300577 intel_power_sequencer_reset(dev_priv);
Imre Deak13ae3a02015-11-04 19:24:16 +0200578 gen9_set_dc_state(dev_priv, DC_STATE_EN_DC9);
579}
580
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530581void bxt_disable_dc9(struct drm_i915_private *dev_priv)
582{
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530583 assert_can_disable_dc9(dev_priv);
584
585 DRM_DEBUG_KMS("Disabling DC9\n");
586
Imre Deak13ae3a02015-11-04 19:24:16 +0200587 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
Imre Deak8090ba82016-08-10 14:07:33 +0300588
589 intel_pps_unlock_regs_wa(dev_priv);
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530590}
591
Daniel Vetteraf5fead2015-10-28 23:58:57 +0200592static void assert_csr_loaded(struct drm_i915_private *dev_priv)
593{
594 WARN_ONCE(!I915_READ(CSR_PROGRAM(0)),
595 "CSR program storage start is NULL\n");
596 WARN_ONCE(!I915_READ(CSR_SSP_BASE), "CSR SSP Base Not fine\n");
597 WARN_ONCE(!I915_READ(CSR_HTP_SKL), "CSR HTP Not fine\n");
598}
599
Suketu Shah5aefb232015-04-16 14:22:10 +0530600static void assert_can_enable_dc5(struct drm_i915_private *dev_priv)
Suketu Shahdc174302015-04-17 19:46:16 +0530601{
Suketu Shah5aefb232015-04-16 14:22:10 +0530602 bool pg2_enabled = intel_display_power_well_is_enabled(dev_priv,
603 SKL_DISP_PW_2);
604
Jesse Barnes6ff8ab02015-09-10 08:20:28 -0700605 WARN_ONCE(pg2_enabled, "PG2 not disabled to enable DC5.\n");
Suketu Shah5aefb232015-04-16 14:22:10 +0530606
Jesse Barnes6ff8ab02015-09-10 08:20:28 -0700607 WARN_ONCE((I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC5),
608 "DC5 already programmed to be enabled.\n");
Imre Deakc9b88462015-12-15 20:10:34 +0200609 assert_rpm_wakelock_held(dev_priv);
Suketu Shah5aefb232015-04-16 14:22:10 +0530610
611 assert_csr_loaded(dev_priv);
612}
613
Imre Deakf62c79b2016-04-20 20:27:57 +0300614void gen9_enable_dc5(struct drm_i915_private *dev_priv)
Suketu Shah5aefb232015-04-16 14:22:10 +0530615{
Suketu Shah5aefb232015-04-16 14:22:10 +0530616 assert_can_enable_dc5(dev_priv);
A.Sunil Kamath6b457d32015-04-16 14:22:09 +0530617
618 DRM_DEBUG_KMS("Enabling DC5\n");
619
Lucas De Marchi53421c22017-12-04 15:22:10 -0800620 /* Wa Display #1183: skl,kbl,cfl */
621 if (IS_GEN9_BC(dev_priv))
622 I915_WRITE(GEN8_CHICKEN_DCPR_1, I915_READ(GEN8_CHICKEN_DCPR_1) |
623 SKL_SELECT_ALTERNATE_DC_EXIT);
624
Imre Deak13ae3a02015-11-04 19:24:16 +0200625 gen9_set_dc_state(dev_priv, DC_STATE_EN_UPTO_DC5);
Suketu Shahdc174302015-04-17 19:46:16 +0530626}
627
Suketu Shah93c7cb62015-04-16 14:22:13 +0530628static void assert_can_enable_dc6(struct drm_i915_private *dev_priv)
Suketu Shahf75a1982015-04-16 14:22:11 +0530629{
Jesse Barnes6ff8ab02015-09-10 08:20:28 -0700630 WARN_ONCE(I915_READ(UTIL_PIN_CTL) & UTIL_PIN_ENABLE,
631 "Backlight is not disabled.\n");
632 WARN_ONCE((I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC6),
633 "DC6 already programmed to be enabled.\n");
Suketu Shah93c7cb62015-04-16 14:22:13 +0530634
635 assert_csr_loaded(dev_priv);
636}
637
Daniel Vetterc4c25252018-04-17 12:02:25 +0200638static void skl_enable_dc6(struct drm_i915_private *dev_priv)
Suketu Shah93c7cb62015-04-16 14:22:13 +0530639{
Suketu Shah93c7cb62015-04-16 14:22:13 +0530640 assert_can_enable_dc6(dev_priv);
A.Sunil Kamath74b4f372015-04-16 14:22:12 +0530641
642 DRM_DEBUG_KMS("Enabling DC6\n");
643
Imre Deakb49be662018-04-19 18:51:09 +0300644 /* 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);
Imre Deak13ae3a02015-11-04 19:24:16 +0200648
Imre Deakb49be662018-04-19 18:51:09 +0300649 gen9_set_dc_state(dev_priv, DC_STATE_EN_UPTO_DC6);
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) | \
Rodrigo Vivi9787e832018-01-29 15:22:22 -08001828 BIT_ULL(POWER_DOMAIN_PORT_DDI_F_LANES) | \
Imre Deak965a79a2017-07-06 17:40:40 +03001829 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1830 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1831 BIT_ULL(POWER_DOMAIN_AUX_D) | \
Rodrigo Vivia324fca2018-01-29 15:22:15 -08001832 BIT_ULL(POWER_DOMAIN_AUX_F) | \
Imre Deak965a79a2017-07-06 17:40:40 +03001833 BIT_ULL(POWER_DOMAIN_AUDIO) | \
1834 BIT_ULL(POWER_DOMAIN_VGA) | \
1835 BIT_ULL(POWER_DOMAIN_INIT))
1836#define CNL_DISPLAY_DDI_A_IO_POWER_DOMAINS ( \
1837 BIT_ULL(POWER_DOMAIN_PORT_DDI_A_IO) | \
Imre Deak965a79a2017-07-06 17:40:40 +03001838 BIT_ULL(POWER_DOMAIN_INIT))
1839#define CNL_DISPLAY_DDI_B_IO_POWER_DOMAINS ( \
1840 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_IO) | \
1841 BIT_ULL(POWER_DOMAIN_INIT))
1842#define CNL_DISPLAY_DDI_C_IO_POWER_DOMAINS ( \
1843 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_IO) | \
1844 BIT_ULL(POWER_DOMAIN_INIT))
1845#define CNL_DISPLAY_DDI_D_IO_POWER_DOMAINS ( \
1846 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_IO) | \
1847 BIT_ULL(POWER_DOMAIN_INIT))
1848#define CNL_DISPLAY_AUX_A_POWER_DOMAINS ( \
1849 BIT_ULL(POWER_DOMAIN_AUX_A) | \
Dhinakaran Pandiyanb891d5e2018-02-23 14:15:15 -08001850 BIT_ULL(POWER_DOMAIN_AUX_IO_A) | \
Imre Deak965a79a2017-07-06 17:40:40 +03001851 BIT_ULL(POWER_DOMAIN_INIT))
1852#define CNL_DISPLAY_AUX_B_POWER_DOMAINS ( \
1853 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1854 BIT_ULL(POWER_DOMAIN_INIT))
1855#define CNL_DISPLAY_AUX_C_POWER_DOMAINS ( \
1856 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1857 BIT_ULL(POWER_DOMAIN_INIT))
1858#define CNL_DISPLAY_AUX_D_POWER_DOMAINS ( \
1859 BIT_ULL(POWER_DOMAIN_AUX_D) | \
1860 BIT_ULL(POWER_DOMAIN_INIT))
Rodrigo Vivia324fca2018-01-29 15:22:15 -08001861#define CNL_DISPLAY_AUX_F_POWER_DOMAINS ( \
1862 BIT_ULL(POWER_DOMAIN_AUX_F) | \
1863 BIT_ULL(POWER_DOMAIN_INIT))
Rodrigo Vivi9787e832018-01-29 15:22:22 -08001864#define CNL_DISPLAY_DDI_F_IO_POWER_DOMAINS ( \
1865 BIT_ULL(POWER_DOMAIN_PORT_DDI_F_IO) | \
1866 BIT_ULL(POWER_DOMAIN_INIT))
Imre Deak965a79a2017-07-06 17:40:40 +03001867#define CNL_DISPLAY_DC_OFF_POWER_DOMAINS ( \
1868 CNL_DISPLAY_POWERWELL_2_POWER_DOMAINS | \
Tvrtko Ursulin6e7a3f52018-01-11 08:24:17 +00001869 BIT_ULL(POWER_DOMAIN_GT_IRQ) | \
Imre Deak965a79a2017-07-06 17:40:40 +03001870 BIT_ULL(POWER_DOMAIN_MODESET) | \
1871 BIT_ULL(POWER_DOMAIN_AUX_A) | \
Ville Syrjälä2ee0da12017-06-01 17:36:16 +03001872 BIT_ULL(POWER_DOMAIN_INIT))
1873
Daniel Vetter9c065a72014-09-30 10:56:38 +02001874static const struct i915_power_well_ops i9xx_always_on_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02001875 .sync_hw = i9xx_power_well_sync_hw_noop,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001876 .enable = i9xx_always_on_power_well_noop,
1877 .disable = i9xx_always_on_power_well_noop,
1878 .is_enabled = i9xx_always_on_power_well_enabled,
1879};
1880
1881static const struct i915_power_well_ops chv_pipe_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02001882 .sync_hw = i9xx_power_well_sync_hw_noop,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001883 .enable = chv_pipe_power_well_enable,
1884 .disable = chv_pipe_power_well_disable,
1885 .is_enabled = chv_pipe_power_well_enabled,
1886};
1887
1888static const struct i915_power_well_ops chv_dpio_cmn_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02001889 .sync_hw = i9xx_power_well_sync_hw_noop,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001890 .enable = chv_dpio_cmn_power_well_enable,
1891 .disable = chv_dpio_cmn_power_well_disable,
1892 .is_enabled = vlv_power_well_enabled,
1893};
1894
1895static struct i915_power_well i9xx_always_on_power_well[] = {
1896 {
1897 .name = "always-on",
1898 .always_on = 1,
1899 .domains = POWER_DOMAIN_MASK,
1900 .ops = &i9xx_always_on_power_well_ops,
Imre Deak029d80d2017-07-06 17:40:25 +03001901 .id = I915_DISP_PW_ALWAYS_ON,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001902 },
1903};
1904
Ville Syrjälä2ee0da12017-06-01 17:36:16 +03001905static const struct i915_power_well_ops i830_pipes_power_well_ops = {
1906 .sync_hw = i830_pipes_power_well_sync_hw,
1907 .enable = i830_pipes_power_well_enable,
1908 .disable = i830_pipes_power_well_disable,
1909 .is_enabled = i830_pipes_power_well_enabled,
1910};
1911
1912static struct i915_power_well i830_power_wells[] = {
1913 {
1914 .name = "always-on",
1915 .always_on = 1,
1916 .domains = POWER_DOMAIN_MASK,
1917 .ops = &i9xx_always_on_power_well_ops,
Imre Deak029d80d2017-07-06 17:40:25 +03001918 .id = I915_DISP_PW_ALWAYS_ON,
Ville Syrjälä2ee0da12017-06-01 17:36:16 +03001919 },
1920 {
1921 .name = "pipes",
1922 .domains = I830_PIPES_POWER_DOMAINS,
1923 .ops = &i830_pipes_power_well_ops,
Imre Deak120b56a2017-07-11 23:42:31 +03001924 .id = I830_DISP_PW_PIPES,
Ville Syrjälä2ee0da12017-06-01 17:36:16 +03001925 },
1926};
1927
Daniel Vetter9c065a72014-09-30 10:56:38 +02001928static const struct i915_power_well_ops hsw_power_well_ops = {
1929 .sync_hw = hsw_power_well_sync_hw,
1930 .enable = hsw_power_well_enable,
1931 .disable = hsw_power_well_disable,
1932 .is_enabled = hsw_power_well_enabled,
1933};
1934
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01001935static const struct i915_power_well_ops gen9_dc_off_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02001936 .sync_hw = i9xx_power_well_sync_hw_noop,
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01001937 .enable = gen9_dc_off_power_well_enable,
1938 .disable = gen9_dc_off_power_well_disable,
1939 .is_enabled = gen9_dc_off_power_well_enabled,
1940};
1941
Imre Deak9c8d0b82016-06-13 16:44:34 +03001942static const struct i915_power_well_ops bxt_dpio_cmn_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02001943 .sync_hw = i9xx_power_well_sync_hw_noop,
Imre Deak9c8d0b82016-06-13 16:44:34 +03001944 .enable = bxt_dpio_cmn_power_well_enable,
1945 .disable = bxt_dpio_cmn_power_well_disable,
1946 .is_enabled = bxt_dpio_cmn_power_well_enabled,
1947};
1948
Daniel Vetter9c065a72014-09-30 10:56:38 +02001949static struct i915_power_well hsw_power_wells[] = {
1950 {
1951 .name = "always-on",
1952 .always_on = 1,
Ville Syrjälä998bd662016-04-18 14:02:26 +03001953 .domains = POWER_DOMAIN_MASK,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001954 .ops = &i9xx_always_on_power_well_ops,
Imre Deak029d80d2017-07-06 17:40:25 +03001955 .id = I915_DISP_PW_ALWAYS_ON,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001956 },
1957 {
1958 .name = "display",
1959 .domains = HSW_DISPLAY_POWER_DOMAINS,
1960 .ops = &hsw_power_well_ops,
Imre Deakfb9248e2017-07-11 23:42:32 +03001961 .id = HSW_DISP_PW_GLOBAL,
Imre Deak0a445942017-08-14 18:15:29 +03001962 {
1963 .hsw.has_vga = true,
1964 },
Daniel Vetter9c065a72014-09-30 10:56:38 +02001965 },
1966};
1967
1968static struct i915_power_well bdw_power_wells[] = {
1969 {
1970 .name = "always-on",
1971 .always_on = 1,
Ville Syrjälä998bd662016-04-18 14:02:26 +03001972 .domains = POWER_DOMAIN_MASK,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001973 .ops = &i9xx_always_on_power_well_ops,
Imre Deak029d80d2017-07-06 17:40:25 +03001974 .id = I915_DISP_PW_ALWAYS_ON,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001975 },
1976 {
1977 .name = "display",
1978 .domains = BDW_DISPLAY_POWER_DOMAINS,
1979 .ops = &hsw_power_well_ops,
Imre Deakfb9248e2017-07-11 23:42:32 +03001980 .id = HSW_DISP_PW_GLOBAL,
Imre Deak0a445942017-08-14 18:15:29 +03001981 {
1982 .hsw.irq_pipe_mask = BIT(PIPE_B) | BIT(PIPE_C),
1983 .hsw.has_vga = true,
1984 },
Daniel Vetter9c065a72014-09-30 10:56:38 +02001985 },
1986};
1987
1988static const struct i915_power_well_ops vlv_display_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02001989 .sync_hw = i9xx_power_well_sync_hw_noop,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001990 .enable = vlv_display_power_well_enable,
1991 .disable = vlv_display_power_well_disable,
1992 .is_enabled = vlv_power_well_enabled,
1993};
1994
1995static const struct i915_power_well_ops vlv_dpio_cmn_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02001996 .sync_hw = i9xx_power_well_sync_hw_noop,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001997 .enable = vlv_dpio_cmn_power_well_enable,
1998 .disable = vlv_dpio_cmn_power_well_disable,
1999 .is_enabled = vlv_power_well_enabled,
2000};
2001
2002static const struct i915_power_well_ops vlv_dpio_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02002003 .sync_hw = i9xx_power_well_sync_hw_noop,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002004 .enable = vlv_power_well_enable,
2005 .disable = vlv_power_well_disable,
2006 .is_enabled = vlv_power_well_enabled,
2007};
2008
2009static struct i915_power_well vlv_power_wells[] = {
2010 {
2011 .name = "always-on",
2012 .always_on = 1,
Ville Syrjälä998bd662016-04-18 14:02:26 +03002013 .domains = POWER_DOMAIN_MASK,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002014 .ops = &i9xx_always_on_power_well_ops,
Imre Deak438b8dc2017-07-11 23:42:30 +03002015 .id = I915_DISP_PW_ALWAYS_ON,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002016 },
2017 {
2018 .name = "display",
2019 .domains = VLV_DISPLAY_POWER_DOMAINS,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002020 .id = PUNIT_POWER_WELL_DISP2D,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002021 .ops = &vlv_display_power_well_ops,
2022 },
2023 {
2024 .name = "dpio-tx-b-01",
2025 .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
2026 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
2027 VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
2028 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
2029 .ops = &vlv_dpio_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002030 .id = PUNIT_POWER_WELL_DPIO_TX_B_LANES_01,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002031 },
2032 {
2033 .name = "dpio-tx-b-23",
2034 .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
2035 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
2036 VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
2037 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
2038 .ops = &vlv_dpio_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002039 .id = PUNIT_POWER_WELL_DPIO_TX_B_LANES_23,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002040 },
2041 {
2042 .name = "dpio-tx-c-01",
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_01,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002049 },
2050 {
2051 .name = "dpio-tx-c-23",
2052 .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
2053 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
2054 VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
2055 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
2056 .ops = &vlv_dpio_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002057 .id = PUNIT_POWER_WELL_DPIO_TX_C_LANES_23,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002058 },
2059 {
2060 .name = "dpio-common",
2061 .domains = VLV_DPIO_CMN_BC_POWER_DOMAINS,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002062 .id = PUNIT_POWER_WELL_DPIO_CMN_BC,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002063 .ops = &vlv_dpio_cmn_power_well_ops,
2064 },
2065};
2066
2067static struct i915_power_well chv_power_wells[] = {
2068 {
2069 .name = "always-on",
2070 .always_on = 1,
Ville Syrjälä998bd662016-04-18 14:02:26 +03002071 .domains = POWER_DOMAIN_MASK,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002072 .ops = &i9xx_always_on_power_well_ops,
Imre Deak029d80d2017-07-06 17:40:25 +03002073 .id = I915_DISP_PW_ALWAYS_ON,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002074 },
Daniel Vetter9c065a72014-09-30 10:56:38 +02002075 {
2076 .name = "display",
Ville Syrjäläbaa4e572014-10-27 16:07:32 +02002077 /*
Ville Syrjäläfde61e42015-05-26 20:22:39 +03002078 * Pipe A power well is the new disp2d well. Pipe B and C
2079 * power wells don't actually exist. Pipe A power well is
2080 * required for any pipe to work.
Ville Syrjäläbaa4e572014-10-27 16:07:32 +02002081 */
Ville Syrjälä465ac0c2016-04-18 14:02:27 +03002082 .domains = CHV_DISPLAY_POWER_DOMAINS,
Imre Deakf49193c2017-07-06 17:40:23 +03002083 .id = CHV_DISP_PW_PIPE_A,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002084 .ops = &chv_pipe_power_well_ops,
2085 },
Daniel Vetter9c065a72014-09-30 10:56:38 +02002086 {
2087 .name = "dpio-common-bc",
Ville Syrjälä71849b62015-04-10 18:21:29 +03002088 .domains = CHV_DPIO_CMN_BC_POWER_DOMAINS,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002089 .id = PUNIT_POWER_WELL_DPIO_CMN_BC,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002090 .ops = &chv_dpio_cmn_power_well_ops,
2091 },
2092 {
2093 .name = "dpio-common-d",
Ville Syrjälä71849b62015-04-10 18:21:29 +03002094 .domains = CHV_DPIO_CMN_D_POWER_DOMAINS,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002095 .id = PUNIT_POWER_WELL_DPIO_CMN_D,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002096 .ops = &chv_dpio_cmn_power_well_ops,
2097 },
Daniel Vetter9c065a72014-09-30 10:56:38 +02002098};
2099
Suketu Shah5aefb232015-04-16 14:22:10 +05302100bool intel_display_power_well_is_enabled(struct drm_i915_private *dev_priv,
Imre Deak438b8dc2017-07-11 23:42:30 +03002101 enum i915_power_well_id power_well_id)
Suketu Shah5aefb232015-04-16 14:22:10 +05302102{
2103 struct i915_power_well *power_well;
2104 bool ret;
2105
2106 power_well = lookup_power_well(dev_priv, power_well_id);
2107 ret = power_well->ops->is_enabled(dev_priv, power_well);
2108
2109 return ret;
2110}
2111
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002112static struct i915_power_well skl_power_wells[] = {
2113 {
2114 .name = "always-on",
2115 .always_on = 1,
Ville Syrjälä998bd662016-04-18 14:02:26 +03002116 .domains = POWER_DOMAIN_MASK,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002117 .ops = &i9xx_always_on_power_well_ops,
Imre Deak438b8dc2017-07-11 23:42:30 +03002118 .id = I915_DISP_PW_ALWAYS_ON,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002119 },
2120 {
2121 .name = "power well 1",
Imre Deak4a76f292015-11-04 19:24:15 +02002122 /* Handled by the DMC firmware */
2123 .domains = 0,
Imre Deak4196b912017-07-11 23:42:36 +03002124 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002125 .id = SKL_DISP_PW_1,
Imre Deak0a445942017-08-14 18:15:29 +03002126 {
2127 .hsw.has_fuses = true,
2128 },
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002129 },
2130 {
2131 .name = "MISC IO power well",
Imre Deak4a76f292015-11-04 19:24:15 +02002132 /* Handled by the DMC firmware */
2133 .domains = 0,
Imre Deak4196b912017-07-11 23:42:36 +03002134 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002135 .id = SKL_DISP_PW_MISC_IO,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002136 },
2137 {
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01002138 .name = "DC off",
2139 .domains = SKL_DISPLAY_DC_OFF_POWER_DOMAINS,
2140 .ops = &gen9_dc_off_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002141 .id = SKL_DISP_PW_DC_OFF,
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01002142 },
2143 {
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002144 .name = "power well 2",
2145 .domains = SKL_DISPLAY_POWERWELL_2_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002146 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002147 .id = SKL_DISP_PW_2,
Imre Deak0a445942017-08-14 18:15:29 +03002148 {
2149 .hsw.irq_pipe_mask = BIT(PIPE_B) | BIT(PIPE_C),
2150 .hsw.has_vga = true,
2151 .hsw.has_fuses = true,
2152 },
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002153 },
2154 {
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002155 .name = "DDI A/E IO power well",
2156 .domains = SKL_DISPLAY_DDI_IO_A_E_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002157 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002158 .id = SKL_DISP_PW_DDI_A_E,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002159 },
2160 {
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002161 .name = "DDI B IO power well",
2162 .domains = SKL_DISPLAY_DDI_IO_B_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002163 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002164 .id = SKL_DISP_PW_DDI_B,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002165 },
2166 {
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002167 .name = "DDI C IO power well",
2168 .domains = SKL_DISPLAY_DDI_IO_C_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002169 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002170 .id = SKL_DISP_PW_DDI_C,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002171 },
2172 {
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002173 .name = "DDI D IO power well",
2174 .domains = SKL_DISPLAY_DDI_IO_D_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002175 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002176 .id = SKL_DISP_PW_DDI_D,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002177 },
2178};
2179
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302180static struct i915_power_well bxt_power_wells[] = {
2181 {
2182 .name = "always-on",
2183 .always_on = 1,
Ville Syrjälä998bd662016-04-18 14:02:26 +03002184 .domains = POWER_DOMAIN_MASK,
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302185 .ops = &i9xx_always_on_power_well_ops,
Imre Deak029d80d2017-07-06 17:40:25 +03002186 .id = I915_DISP_PW_ALWAYS_ON,
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302187 },
2188 {
2189 .name = "power well 1",
Imre Deakd7d7c9e2016-04-01 16:02:42 +03002190 .domains = 0,
Imre Deak4196b912017-07-11 23:42:36 +03002191 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002192 .id = SKL_DISP_PW_1,
Imre Deak0a445942017-08-14 18:15:29 +03002193 {
2194 .hsw.has_fuses = true,
2195 },
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302196 },
2197 {
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01002198 .name = "DC off",
2199 .domains = BXT_DISPLAY_DC_OFF_POWER_DOMAINS,
2200 .ops = &gen9_dc_off_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002201 .id = SKL_DISP_PW_DC_OFF,
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01002202 },
2203 {
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302204 .name = "power well 2",
2205 .domains = BXT_DISPLAY_POWERWELL_2_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002206 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002207 .id = SKL_DISP_PW_2,
Imre Deak0a445942017-08-14 18:15:29 +03002208 {
2209 .hsw.irq_pipe_mask = BIT(PIPE_B) | BIT(PIPE_C),
2210 .hsw.has_vga = true,
2211 .hsw.has_fuses = true,
2212 },
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01002213 },
Imre Deak9c8d0b82016-06-13 16:44:34 +03002214 {
2215 .name = "dpio-common-a",
2216 .domains = BXT_DPIO_CMN_A_POWER_DOMAINS,
2217 .ops = &bxt_dpio_cmn_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002218 .id = BXT_DPIO_CMN_A,
Imre Deak0a445942017-08-14 18:15:29 +03002219 {
2220 .bxt.phy = DPIO_PHY1,
2221 },
Imre Deak9c8d0b82016-06-13 16:44:34 +03002222 },
2223 {
2224 .name = "dpio-common-bc",
2225 .domains = BXT_DPIO_CMN_BC_POWER_DOMAINS,
2226 .ops = &bxt_dpio_cmn_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002227 .id = BXT_DPIO_CMN_BC,
Imre Deak0a445942017-08-14 18:15:29 +03002228 {
2229 .bxt.phy = DPIO_PHY0,
2230 },
Imre Deak9c8d0b82016-06-13 16:44:34 +03002231 },
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302232};
2233
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002234static struct i915_power_well glk_power_wells[] = {
2235 {
2236 .name = "always-on",
2237 .always_on = 1,
2238 .domains = POWER_DOMAIN_MASK,
2239 .ops = &i9xx_always_on_power_well_ops,
Imre Deak029d80d2017-07-06 17:40:25 +03002240 .id = I915_DISP_PW_ALWAYS_ON,
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002241 },
2242 {
2243 .name = "power well 1",
2244 /* Handled by the DMC firmware */
2245 .domains = 0,
Imre Deak4196b912017-07-11 23:42:36 +03002246 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002247 .id = SKL_DISP_PW_1,
Imre Deak0a445942017-08-14 18:15:29 +03002248 {
2249 .hsw.has_fuses = true,
2250 },
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002251 },
2252 {
2253 .name = "DC off",
2254 .domains = GLK_DISPLAY_DC_OFF_POWER_DOMAINS,
2255 .ops = &gen9_dc_off_power_well_ops,
2256 .id = SKL_DISP_PW_DC_OFF,
2257 },
2258 {
2259 .name = "power well 2",
2260 .domains = GLK_DISPLAY_POWERWELL_2_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002261 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002262 .id = SKL_DISP_PW_2,
Imre Deak0a445942017-08-14 18:15:29 +03002263 {
2264 .hsw.irq_pipe_mask = BIT(PIPE_B) | BIT(PIPE_C),
2265 .hsw.has_vga = true,
2266 .hsw.has_fuses = true,
2267 },
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002268 },
2269 {
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +02002270 .name = "dpio-common-a",
2271 .domains = GLK_DPIO_CMN_A_POWER_DOMAINS,
2272 .ops = &bxt_dpio_cmn_power_well_ops,
2273 .id = BXT_DPIO_CMN_A,
Imre Deak0a445942017-08-14 18:15:29 +03002274 {
2275 .bxt.phy = DPIO_PHY1,
2276 },
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +02002277 },
2278 {
2279 .name = "dpio-common-b",
2280 .domains = GLK_DPIO_CMN_B_POWER_DOMAINS,
2281 .ops = &bxt_dpio_cmn_power_well_ops,
2282 .id = BXT_DPIO_CMN_BC,
Imre Deak0a445942017-08-14 18:15:29 +03002283 {
2284 .bxt.phy = DPIO_PHY0,
2285 },
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +02002286 },
2287 {
2288 .name = "dpio-common-c",
2289 .domains = GLK_DPIO_CMN_C_POWER_DOMAINS,
2290 .ops = &bxt_dpio_cmn_power_well_ops,
2291 .id = GLK_DPIO_CMN_C,
Imre Deak0a445942017-08-14 18:15:29 +03002292 {
2293 .bxt.phy = DPIO_PHY2,
2294 },
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +02002295 },
2296 {
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002297 .name = "AUX A",
2298 .domains = GLK_DISPLAY_AUX_A_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002299 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002300 .id = GLK_DISP_PW_AUX_A,
2301 },
2302 {
2303 .name = "AUX B",
2304 .domains = GLK_DISPLAY_AUX_B_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002305 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002306 .id = GLK_DISP_PW_AUX_B,
2307 },
2308 {
2309 .name = "AUX C",
2310 .domains = GLK_DISPLAY_AUX_C_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002311 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002312 .id = GLK_DISP_PW_AUX_C,
2313 },
2314 {
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002315 .name = "DDI A IO power well",
2316 .domains = GLK_DISPLAY_DDI_IO_A_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002317 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002318 .id = GLK_DISP_PW_DDI_A,
2319 },
2320 {
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002321 .name = "DDI B IO power well",
2322 .domains = GLK_DISPLAY_DDI_IO_B_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002323 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002324 .id = SKL_DISP_PW_DDI_B,
2325 },
2326 {
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002327 .name = "DDI C IO power well",
2328 .domains = GLK_DISPLAY_DDI_IO_C_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002329 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002330 .id = SKL_DISP_PW_DDI_C,
2331 },
2332};
2333
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002334static struct i915_power_well cnl_power_wells[] = {
2335 {
2336 .name = "always-on",
2337 .always_on = 1,
2338 .domains = POWER_DOMAIN_MASK,
2339 .ops = &i9xx_always_on_power_well_ops,
Imre Deak029d80d2017-07-06 17:40:25 +03002340 .id = I915_DISP_PW_ALWAYS_ON,
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002341 },
2342 {
2343 .name = "power well 1",
2344 /* Handled by the DMC firmware */
2345 .domains = 0,
Imre Deak4196b912017-07-11 23:42:36 +03002346 .ops = &hsw_power_well_ops,
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002347 .id = SKL_DISP_PW_1,
Imre Deak0a445942017-08-14 18:15:29 +03002348 {
2349 .hsw.has_fuses = true,
2350 },
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002351 },
2352 {
2353 .name = "AUX A",
2354 .domains = CNL_DISPLAY_AUX_A_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002355 .ops = &hsw_power_well_ops,
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002356 .id = CNL_DISP_PW_AUX_A,
2357 },
2358 {
2359 .name = "AUX B",
2360 .domains = CNL_DISPLAY_AUX_B_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002361 .ops = &hsw_power_well_ops,
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002362 .id = CNL_DISP_PW_AUX_B,
2363 },
2364 {
2365 .name = "AUX C",
2366 .domains = CNL_DISPLAY_AUX_C_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002367 .ops = &hsw_power_well_ops,
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002368 .id = CNL_DISP_PW_AUX_C,
2369 },
2370 {
2371 .name = "AUX D",
2372 .domains = CNL_DISPLAY_AUX_D_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002373 .ops = &hsw_power_well_ops,
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002374 .id = CNL_DISP_PW_AUX_D,
2375 },
2376 {
2377 .name = "DC off",
2378 .domains = CNL_DISPLAY_DC_OFF_POWER_DOMAINS,
2379 .ops = &gen9_dc_off_power_well_ops,
2380 .id = SKL_DISP_PW_DC_OFF,
2381 },
2382 {
2383 .name = "power well 2",
2384 .domains = CNL_DISPLAY_POWERWELL_2_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002385 .ops = &hsw_power_well_ops,
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002386 .id = SKL_DISP_PW_2,
Imre Deak0a445942017-08-14 18:15:29 +03002387 {
2388 .hsw.irq_pipe_mask = BIT(PIPE_B) | BIT(PIPE_C),
2389 .hsw.has_vga = true,
2390 .hsw.has_fuses = true,
2391 },
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002392 },
2393 {
2394 .name = "DDI A IO power well",
2395 .domains = CNL_DISPLAY_DDI_A_IO_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002396 .ops = &hsw_power_well_ops,
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002397 .id = CNL_DISP_PW_DDI_A,
2398 },
2399 {
2400 .name = "DDI B IO power well",
2401 .domains = CNL_DISPLAY_DDI_B_IO_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002402 .ops = &hsw_power_well_ops,
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002403 .id = SKL_DISP_PW_DDI_B,
2404 },
2405 {
2406 .name = "DDI C IO power well",
2407 .domains = CNL_DISPLAY_DDI_C_IO_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002408 .ops = &hsw_power_well_ops,
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002409 .id = SKL_DISP_PW_DDI_C,
2410 },
2411 {
2412 .name = "DDI D IO power well",
2413 .domains = CNL_DISPLAY_DDI_D_IO_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002414 .ops = &hsw_power_well_ops,
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002415 .id = SKL_DISP_PW_DDI_D,
2416 },
Rodrigo Vivia324fca2018-01-29 15:22:15 -08002417 {
Rodrigo Vivi9787e832018-01-29 15:22:22 -08002418 .name = "DDI F IO power well",
2419 .domains = CNL_DISPLAY_DDI_F_IO_POWER_DOMAINS,
2420 .ops = &hsw_power_well_ops,
2421 .id = CNL_DISP_PW_DDI_F,
2422 },
2423 {
Rodrigo Vivia324fca2018-01-29 15:22:15 -08002424 .name = "AUX F",
2425 .domains = CNL_DISPLAY_AUX_F_POWER_DOMAINS,
2426 .ops = &hsw_power_well_ops,
2427 .id = CNL_DISP_PW_AUX_F,
2428 },
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002429};
2430
Imre Deak1b0e3a02015-11-05 23:04:11 +02002431static int
2432sanitize_disable_power_well_option(const struct drm_i915_private *dev_priv,
2433 int disable_power_well)
2434{
2435 if (disable_power_well >= 0)
2436 return !!disable_power_well;
2437
Imre Deak1b0e3a02015-11-05 23:04:11 +02002438 return 1;
2439}
2440
Imre Deaka37baf32016-02-29 22:49:03 +02002441static uint32_t get_allowed_dc_mask(const struct drm_i915_private *dev_priv,
2442 int enable_dc)
2443{
2444 uint32_t mask;
2445 int requested_dc;
2446 int max_dc;
2447
Rodrigo Vivi6d6a8972017-07-06 13:45:08 -07002448 if (IS_GEN9_BC(dev_priv) || IS_CANNONLAKE(dev_priv)) {
Imre Deaka37baf32016-02-29 22:49:03 +02002449 max_dc = 2;
2450 mask = 0;
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02002451 } else if (IS_GEN9_LP(dev_priv)) {
Imre Deaka37baf32016-02-29 22:49:03 +02002452 max_dc = 1;
2453 /*
2454 * DC9 has a separate HW flow from the rest of the DC states,
2455 * not depending on the DMC firmware. It's needed by system
2456 * suspend/resume, so allow it unconditionally.
2457 */
2458 mask = DC_STATE_EN_DC9;
2459 } else {
2460 max_dc = 0;
2461 mask = 0;
2462 }
2463
Michal Wajdeczko4f044a82017-09-19 19:38:44 +00002464 if (!i915_modparams.disable_power_well)
Imre Deak66e2c4c2016-02-29 22:49:04 +02002465 max_dc = 0;
2466
Imre Deaka37baf32016-02-29 22:49:03 +02002467 if (enable_dc >= 0 && enable_dc <= max_dc) {
2468 requested_dc = enable_dc;
2469 } else if (enable_dc == -1) {
2470 requested_dc = max_dc;
2471 } else if (enable_dc > max_dc && enable_dc <= 2) {
2472 DRM_DEBUG_KMS("Adjusting requested max DC state (%d->%d)\n",
2473 enable_dc, max_dc);
2474 requested_dc = max_dc;
2475 } else {
2476 DRM_ERROR("Unexpected value for enable_dc (%d)\n", enable_dc);
2477 requested_dc = max_dc;
2478 }
2479
2480 if (requested_dc > 1)
2481 mask |= DC_STATE_EN_UPTO_DC6;
2482 if (requested_dc > 0)
2483 mask |= DC_STATE_EN_UPTO_DC5;
2484
2485 DRM_DEBUG_KMS("Allowed DC state mask %02x\n", mask);
2486
2487 return mask;
2488}
2489
Imre Deak21792c62017-07-11 23:42:33 +03002490static void assert_power_well_ids_unique(struct drm_i915_private *dev_priv)
2491{
2492 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2493 u64 power_well_ids;
2494 int i;
2495
2496 power_well_ids = 0;
2497 for (i = 0; i < power_domains->power_well_count; i++) {
2498 enum i915_power_well_id id = power_domains->power_wells[i].id;
2499
2500 WARN_ON(id >= sizeof(power_well_ids) * 8);
2501 WARN_ON(power_well_ids & BIT_ULL(id));
2502 power_well_ids |= BIT_ULL(id);
2503 }
2504}
2505
Daniel Vetter9c065a72014-09-30 10:56:38 +02002506#define set_power_wells(power_domains, __power_wells) ({ \
2507 (power_domains)->power_wells = (__power_wells); \
2508 (power_domains)->power_well_count = ARRAY_SIZE(__power_wells); \
2509})
2510
Daniel Vettere4e76842014-09-30 10:56:42 +02002511/**
2512 * intel_power_domains_init - initializes the power domain structures
2513 * @dev_priv: i915 device instance
2514 *
2515 * Initializes the power domain structures for @dev_priv depending upon the
2516 * supported platform.
2517 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02002518int intel_power_domains_init(struct drm_i915_private *dev_priv)
2519{
2520 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2521
Michal Wajdeczko4f044a82017-09-19 19:38:44 +00002522 i915_modparams.disable_power_well =
2523 sanitize_disable_power_well_option(dev_priv,
2524 i915_modparams.disable_power_well);
2525 dev_priv->csr.allowed_dc_mask =
2526 get_allowed_dc_mask(dev_priv, i915_modparams.enable_dc);
Imre Deak1b0e3a02015-11-05 23:04:11 +02002527
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02002528 BUILD_BUG_ON(POWER_DOMAIN_NUM > 64);
Ville Syrjäläf0ab43e2015-11-09 16:48:19 +01002529
Daniel Vetter9c065a72014-09-30 10:56:38 +02002530 mutex_init(&power_domains->lock);
2531
2532 /*
2533 * The enabling order will be from lower to higher indexed wells,
2534 * the disabling order is reversed.
2535 */
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002536 if (IS_HASWELL(dev_priv)) {
Daniel Vetter9c065a72014-09-30 10:56:38 +02002537 set_power_wells(power_domains, hsw_power_wells);
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002538 } else if (IS_BROADWELL(dev_priv)) {
Daniel Vetter9c065a72014-09-30 10:56:38 +02002539 set_power_wells(power_domains, bdw_power_wells);
Rodrigo Vivib976dc52017-01-23 10:32:37 -08002540 } else if (IS_GEN9_BC(dev_priv)) {
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002541 set_power_wells(power_domains, skl_power_wells);
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002542 } else if (IS_CANNONLAKE(dev_priv)) {
2543 set_power_wells(power_domains, cnl_power_wells);
Rodrigo Vivia324fca2018-01-29 15:22:15 -08002544
2545 /*
Rodrigo Vivi9787e832018-01-29 15:22:22 -08002546 * DDI and Aux IO are getting enabled for all ports
Rodrigo Vivia324fca2018-01-29 15:22:15 -08002547 * regardless the presence or use. So, in order to avoid
Rodrigo Vivi9787e832018-01-29 15:22:22 -08002548 * timeouts, lets remove them from the list
Rodrigo Vivia324fca2018-01-29 15:22:15 -08002549 * for the SKUs without port F.
2550 */
2551 if (!IS_CNL_WITH_PORT_F(dev_priv))
Rodrigo Vivi9787e832018-01-29 15:22:22 -08002552 power_domains->power_well_count -= 2;
Rodrigo Vivia324fca2018-01-29 15:22:15 -08002553
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002554 } else if (IS_BROXTON(dev_priv)) {
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302555 set_power_wells(power_domains, bxt_power_wells);
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002556 } else if (IS_GEMINILAKE(dev_priv)) {
2557 set_power_wells(power_domains, glk_power_wells);
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002558 } else if (IS_CHERRYVIEW(dev_priv)) {
Daniel Vetter9c065a72014-09-30 10:56:38 +02002559 set_power_wells(power_domains, chv_power_wells);
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002560 } else if (IS_VALLEYVIEW(dev_priv)) {
Daniel Vetter9c065a72014-09-30 10:56:38 +02002561 set_power_wells(power_domains, vlv_power_wells);
Ville Syrjälä2ee0da12017-06-01 17:36:16 +03002562 } else if (IS_I830(dev_priv)) {
2563 set_power_wells(power_domains, i830_power_wells);
Daniel Vetter9c065a72014-09-30 10:56:38 +02002564 } else {
2565 set_power_wells(power_domains, i9xx_always_on_power_well);
2566 }
2567
Imre Deak21792c62017-07-11 23:42:33 +03002568 assert_power_well_ids_unique(dev_priv);
2569
Daniel Vetter9c065a72014-09-30 10:56:38 +02002570 return 0;
2571}
2572
Daniel Vettere4e76842014-09-30 10:56:42 +02002573/**
2574 * intel_power_domains_fini - finalizes the power domain structures
2575 * @dev_priv: i915 device instance
2576 *
2577 * Finalizes the power domain structures for @dev_priv depending upon the
2578 * supported platform. This function also disables runtime pm and ensures that
2579 * the device stays powered up so that the driver can be reloaded.
2580 */
Daniel Vetterf458ebb2014-09-30 10:56:39 +02002581void intel_power_domains_fini(struct drm_i915_private *dev_priv)
Daniel Vetter9c065a72014-09-30 10:56:38 +02002582{
David Weinehallc49d13e2016-08-22 13:32:42 +03002583 struct device *kdev = &dev_priv->drm.pdev->dev;
Imre Deak25b181b2015-12-17 13:44:56 +02002584
Imre Deakaabee1b2015-12-15 20:10:29 +02002585 /*
2586 * The i915.ko module is still not prepared to be loaded when
Daniel Vetterf458ebb2014-09-30 10:56:39 +02002587 * the power well is not enabled, so just enable it in case
Imre Deakaabee1b2015-12-15 20:10:29 +02002588 * we're going to unload/reload.
2589 * The following also reacquires the RPM reference the core passed
2590 * to the driver during loading, which is dropped in
2591 * intel_runtime_pm_enable(). We have to hand back the control of the
2592 * device to the core with this reference held.
2593 */
Daniel Vetterf458ebb2014-09-30 10:56:39 +02002594 intel_display_set_init_power(dev_priv, true);
Imre Deakd314cd42015-11-17 17:44:23 +02002595
2596 /* Remove the refcount we took to keep power well support disabled. */
Michal Wajdeczko4f044a82017-09-19 19:38:44 +00002597 if (!i915_modparams.disable_power_well)
Imre Deakd314cd42015-11-17 17:44:23 +02002598 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
Imre Deak25b181b2015-12-17 13:44:56 +02002599
2600 /*
2601 * Remove the refcount we took in intel_runtime_pm_enable() in case
2602 * the platform doesn't support runtime PM.
2603 */
2604 if (!HAS_RUNTIME_PM(dev_priv))
David Weinehallc49d13e2016-08-22 13:32:42 +03002605 pm_runtime_put(kdev);
Daniel Vetter9c065a72014-09-30 10:56:38 +02002606}
2607
Imre Deak30eade12015-11-04 19:24:13 +02002608static void intel_power_domains_sync_hw(struct drm_i915_private *dev_priv)
Daniel Vetter9c065a72014-09-30 10:56:38 +02002609{
2610 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2611 struct i915_power_well *power_well;
Daniel Vetter9c065a72014-09-30 10:56:38 +02002612
2613 mutex_lock(&power_domains->lock);
Imre Deak75ccb2e2017-02-17 17:39:43 +02002614 for_each_power_well(dev_priv, power_well) {
Daniel Vetter9c065a72014-09-30 10:56:38 +02002615 power_well->ops->sync_hw(dev_priv, power_well);
2616 power_well->hw_enabled = power_well->ops->is_enabled(dev_priv,
2617 power_well);
2618 }
2619 mutex_unlock(&power_domains->lock);
2620}
2621
Ville Syrjälä70c2c182016-05-13 23:41:30 +03002622static void gen9_dbuf_enable(struct drm_i915_private *dev_priv)
2623{
2624 I915_WRITE(DBUF_CTL, I915_READ(DBUF_CTL) | DBUF_POWER_REQUEST);
2625 POSTING_READ(DBUF_CTL);
2626
2627 udelay(10);
2628
2629 if (!(I915_READ(DBUF_CTL) & DBUF_POWER_STATE))
2630 DRM_ERROR("DBuf power enable timeout\n");
2631}
2632
2633static void gen9_dbuf_disable(struct drm_i915_private *dev_priv)
2634{
2635 I915_WRITE(DBUF_CTL, I915_READ(DBUF_CTL) & ~DBUF_POWER_REQUEST);
2636 POSTING_READ(DBUF_CTL);
2637
2638 udelay(10);
2639
2640 if (I915_READ(DBUF_CTL) & DBUF_POWER_STATE)
2641 DRM_ERROR("DBuf power disable timeout!\n");
2642}
2643
Mahesh Kumar746edf82018-02-05 13:40:44 -02002644/*
2645 * TODO: we shouldn't always enable DBUF_CTL_S2, we should only enable it when
2646 * needed and keep it disabled as much as possible.
2647 */
2648static void icl_dbuf_enable(struct drm_i915_private *dev_priv)
2649{
2650 I915_WRITE(DBUF_CTL_S1, I915_READ(DBUF_CTL_S1) | DBUF_POWER_REQUEST);
2651 I915_WRITE(DBUF_CTL_S2, I915_READ(DBUF_CTL_S2) | DBUF_POWER_REQUEST);
2652 POSTING_READ(DBUF_CTL_S2);
2653
2654 udelay(10);
2655
2656 if (!(I915_READ(DBUF_CTL_S1) & DBUF_POWER_STATE) ||
2657 !(I915_READ(DBUF_CTL_S2) & DBUF_POWER_STATE))
2658 DRM_ERROR("DBuf power enable timeout\n");
Mahesh Kumar74bd8002018-04-26 19:55:15 +05302659 else
2660 dev_priv->wm.skl_hw.ddb.enabled_slices = 2;
Mahesh Kumar746edf82018-02-05 13:40:44 -02002661}
2662
2663static void icl_dbuf_disable(struct drm_i915_private *dev_priv)
2664{
2665 I915_WRITE(DBUF_CTL_S1, I915_READ(DBUF_CTL_S1) & ~DBUF_POWER_REQUEST);
2666 I915_WRITE(DBUF_CTL_S2, I915_READ(DBUF_CTL_S2) & ~DBUF_POWER_REQUEST);
2667 POSTING_READ(DBUF_CTL_S2);
2668
2669 udelay(10);
2670
2671 if ((I915_READ(DBUF_CTL_S1) & DBUF_POWER_STATE) ||
2672 (I915_READ(DBUF_CTL_S2) & DBUF_POWER_STATE))
2673 DRM_ERROR("DBuf power disable timeout!\n");
Mahesh Kumar74bd8002018-04-26 19:55:15 +05302674 else
2675 dev_priv->wm.skl_hw.ddb.enabled_slices = 0;
Mahesh Kumar746edf82018-02-05 13:40:44 -02002676}
2677
Mahesh Kumar4cb45852018-02-05 13:40:45 -02002678static void icl_mbus_init(struct drm_i915_private *dev_priv)
2679{
2680 uint32_t val;
2681
2682 val = MBUS_ABOX_BT_CREDIT_POOL1(16) |
2683 MBUS_ABOX_BT_CREDIT_POOL2(16) |
2684 MBUS_ABOX_B_CREDIT(1) |
2685 MBUS_ABOX_BW_CREDIT(1);
2686
2687 I915_WRITE(MBUS_ABOX_CTL, val);
2688}
2689
Imre Deak73dfc222015-11-17 17:33:53 +02002690static void skl_display_core_init(struct drm_i915_private *dev_priv,
Imre Deak443a93a2016-04-04 15:42:57 +03002691 bool resume)
Imre Deak73dfc222015-11-17 17:33:53 +02002692{
2693 struct i915_power_domains *power_domains = &dev_priv->power_domains;
Imre Deak443a93a2016-04-04 15:42:57 +03002694 struct i915_power_well *well;
Imre Deak73dfc222015-11-17 17:33:53 +02002695 uint32_t val;
2696
Imre Deakd26fa1d2015-11-04 19:24:17 +02002697 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
2698
Imre Deak73dfc222015-11-17 17:33:53 +02002699 /* enable PCH reset handshake */
2700 val = I915_READ(HSW_NDE_RSTWRN_OPT);
2701 I915_WRITE(HSW_NDE_RSTWRN_OPT, val | RESET_PCH_HANDSHAKE_ENABLE);
2702
2703 /* enable PG1 and Misc I/O */
2704 mutex_lock(&power_domains->lock);
Imre Deak443a93a2016-04-04 15:42:57 +03002705
2706 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
2707 intel_power_well_enable(dev_priv, well);
2708
2709 well = lookup_power_well(dev_priv, SKL_DISP_PW_MISC_IO);
2710 intel_power_well_enable(dev_priv, well);
2711
Imre Deak73dfc222015-11-17 17:33:53 +02002712 mutex_unlock(&power_domains->lock);
2713
Imre Deak73dfc222015-11-17 17:33:53 +02002714 skl_init_cdclk(dev_priv);
2715
Ville Syrjälä70c2c182016-05-13 23:41:30 +03002716 gen9_dbuf_enable(dev_priv);
2717
Ville Syrjälä9f7eb312016-05-13 23:41:29 +03002718 if (resume && dev_priv->csr.dmc_payload)
Imre Deak2abc5252016-03-04 21:57:41 +02002719 intel_csr_load_program(dev_priv);
Imre Deak73dfc222015-11-17 17:33:53 +02002720}
2721
2722static void skl_display_core_uninit(struct drm_i915_private *dev_priv)
2723{
2724 struct i915_power_domains *power_domains = &dev_priv->power_domains;
Imre Deak443a93a2016-04-04 15:42:57 +03002725 struct i915_power_well *well;
Imre Deak73dfc222015-11-17 17:33:53 +02002726
Imre Deakd26fa1d2015-11-04 19:24:17 +02002727 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
2728
Ville Syrjälä70c2c182016-05-13 23:41:30 +03002729 gen9_dbuf_disable(dev_priv);
2730
Imre Deak73dfc222015-11-17 17:33:53 +02002731 skl_uninit_cdclk(dev_priv);
2732
2733 /* The spec doesn't call for removing the reset handshake flag */
2734 /* disable PG1 and Misc I/O */
Imre Deak443a93a2016-04-04 15:42:57 +03002735
Imre Deak73dfc222015-11-17 17:33:53 +02002736 mutex_lock(&power_domains->lock);
Imre Deak443a93a2016-04-04 15:42:57 +03002737
Imre Deakedfda8e2017-06-29 18:36:59 +03002738 /*
2739 * BSpec says to keep the MISC IO power well enabled here, only
2740 * remove our request for power well 1.
Imre Deak42d93662017-06-29 18:37:01 +03002741 * Note that even though the driver's request is removed power well 1
2742 * may stay enabled after this due to DMC's own request on it.
Imre Deakedfda8e2017-06-29 18:36:59 +03002743 */
Imre Deak443a93a2016-04-04 15:42:57 +03002744 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
2745 intel_power_well_disable(dev_priv, well);
2746
Imre Deak73dfc222015-11-17 17:33:53 +02002747 mutex_unlock(&power_domains->lock);
Imre Deak846c6b22017-06-29 18:36:58 +03002748
2749 usleep_range(10, 30); /* 10 us delay per Bspec */
Imre Deak73dfc222015-11-17 17:33:53 +02002750}
2751
Imre Deakd7d7c9e2016-04-01 16:02:42 +03002752void bxt_display_core_init(struct drm_i915_private *dev_priv,
2753 bool resume)
2754{
2755 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2756 struct i915_power_well *well;
2757 uint32_t val;
2758
2759 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
2760
2761 /*
2762 * NDE_RSTWRN_OPT RST PCH Handshake En must always be 0b on BXT
2763 * or else the reset will hang because there is no PCH to respond.
2764 * Move the handshake programming to initialization sequence.
2765 * Previously was left up to BIOS.
2766 */
2767 val = I915_READ(HSW_NDE_RSTWRN_OPT);
2768 val &= ~RESET_PCH_HANDSHAKE_ENABLE;
2769 I915_WRITE(HSW_NDE_RSTWRN_OPT, val);
2770
2771 /* Enable PG1 */
2772 mutex_lock(&power_domains->lock);
2773
2774 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
2775 intel_power_well_enable(dev_priv, well);
2776
2777 mutex_unlock(&power_domains->lock);
2778
Imre Deak324513c2016-06-13 16:44:36 +03002779 bxt_init_cdclk(dev_priv);
Ville Syrjälä70c2c182016-05-13 23:41:30 +03002780
2781 gen9_dbuf_enable(dev_priv);
2782
Imre Deakd7d7c9e2016-04-01 16:02:42 +03002783 if (resume && dev_priv->csr.dmc_payload)
2784 intel_csr_load_program(dev_priv);
2785}
2786
2787void bxt_display_core_uninit(struct drm_i915_private *dev_priv)
2788{
2789 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2790 struct i915_power_well *well;
2791
2792 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
2793
Ville Syrjälä70c2c182016-05-13 23:41:30 +03002794 gen9_dbuf_disable(dev_priv);
2795
Imre Deak324513c2016-06-13 16:44:36 +03002796 bxt_uninit_cdclk(dev_priv);
Imre Deakd7d7c9e2016-04-01 16:02:42 +03002797
2798 /* The spec doesn't call for removing the reset handshake flag */
2799
Imre Deak42d93662017-06-29 18:37:01 +03002800 /*
2801 * Disable PW1 (PG1).
2802 * Note that even though the driver's request is removed power well 1
2803 * may stay enabled after this due to DMC's own request on it.
2804 */
Imre Deakd7d7c9e2016-04-01 16:02:42 +03002805 mutex_lock(&power_domains->lock);
2806
2807 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
2808 intel_power_well_disable(dev_priv, well);
2809
2810 mutex_unlock(&power_domains->lock);
Imre Deak846c6b22017-06-29 18:36:58 +03002811
2812 usleep_range(10, 30); /* 10 us delay per Bspec */
Imre Deakd7d7c9e2016-04-01 16:02:42 +03002813}
2814
Paulo Zanonie0b8acf2017-08-21 17:03:55 -07002815enum {
2816 PROCMON_0_85V_DOT_0,
2817 PROCMON_0_95V_DOT_0,
2818 PROCMON_0_95V_DOT_1,
2819 PROCMON_1_05V_DOT_0,
2820 PROCMON_1_05V_DOT_1,
2821};
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07002822
2823static const struct cnl_procmon {
2824 u32 dw1, dw9, dw10;
Paulo Zanonie0b8acf2017-08-21 17:03:55 -07002825} cnl_procmon_values[] = {
2826 [PROCMON_0_85V_DOT_0] =
2827 { .dw1 = 0x00000000, .dw9 = 0x62AB67BB, .dw10 = 0x51914F96, },
2828 [PROCMON_0_95V_DOT_0] =
2829 { .dw1 = 0x00000000, .dw9 = 0x86E172C7, .dw10 = 0x77CA5EAB, },
2830 [PROCMON_0_95V_DOT_1] =
2831 { .dw1 = 0x00000000, .dw9 = 0x93F87FE1, .dw10 = 0x8AE871C5, },
2832 [PROCMON_1_05V_DOT_0] =
2833 { .dw1 = 0x00000000, .dw9 = 0x98FA82DD, .dw10 = 0x89E46DC1, },
2834 [PROCMON_1_05V_DOT_1] =
2835 { .dw1 = 0x00440000, .dw9 = 0x9A00AB25, .dw10 = 0x8AE38FF1, },
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07002836};
2837
Paulo Zanoni62d4a5e2018-02-05 13:40:41 -02002838/*
2839 * CNL has just one set of registers, while ICL has two sets: one for port A and
2840 * the other for port B. The CNL registers are equivalent to the ICL port A
2841 * registers, that's why we call the ICL macros even though the function has CNL
2842 * on its name.
2843 */
2844static void cnl_set_procmon_ref_values(struct drm_i915_private *dev_priv,
2845 enum port port)
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07002846{
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07002847 const struct cnl_procmon *procmon;
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07002848 u32 val;
2849
Paulo Zanoni62d4a5e2018-02-05 13:40:41 -02002850 val = I915_READ(ICL_PORT_COMP_DW3(port));
Paulo Zanonie0b8acf2017-08-21 17:03:55 -07002851 switch (val & (PROCESS_INFO_MASK | VOLTAGE_INFO_MASK)) {
2852 default:
2853 MISSING_CASE(val);
2854 case VOLTAGE_INFO_0_85V | PROCESS_INFO_DOT_0:
2855 procmon = &cnl_procmon_values[PROCMON_0_85V_DOT_0];
2856 break;
2857 case VOLTAGE_INFO_0_95V | PROCESS_INFO_DOT_0:
2858 procmon = &cnl_procmon_values[PROCMON_0_95V_DOT_0];
2859 break;
2860 case VOLTAGE_INFO_0_95V | PROCESS_INFO_DOT_1:
2861 procmon = &cnl_procmon_values[PROCMON_0_95V_DOT_1];
2862 break;
2863 case VOLTAGE_INFO_1_05V | PROCESS_INFO_DOT_0:
2864 procmon = &cnl_procmon_values[PROCMON_1_05V_DOT_0];
2865 break;
2866 case VOLTAGE_INFO_1_05V | PROCESS_INFO_DOT_1:
2867 procmon = &cnl_procmon_values[PROCMON_1_05V_DOT_1];
2868 break;
2869 }
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07002870
Paulo Zanoni62d4a5e2018-02-05 13:40:41 -02002871 val = I915_READ(ICL_PORT_COMP_DW1(port));
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07002872 val &= ~((0xff << 16) | 0xff);
2873 val |= procmon->dw1;
Paulo Zanoni62d4a5e2018-02-05 13:40:41 -02002874 I915_WRITE(ICL_PORT_COMP_DW1(port), val);
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07002875
Paulo Zanoni62d4a5e2018-02-05 13:40:41 -02002876 I915_WRITE(ICL_PORT_COMP_DW9(port), procmon->dw9);
2877 I915_WRITE(ICL_PORT_COMP_DW10(port), procmon->dw10);
Paulo Zanoniade5ee72017-08-21 17:03:56 -07002878}
2879
2880static void cnl_display_core_init(struct drm_i915_private *dev_priv, bool resume)
2881{
2882 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2883 struct i915_power_well *well;
2884 u32 val;
2885
2886 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
2887
2888 /* 1. Enable PCH Reset Handshake */
2889 val = I915_READ(HSW_NDE_RSTWRN_OPT);
2890 val |= RESET_PCH_HANDSHAKE_ENABLE;
2891 I915_WRITE(HSW_NDE_RSTWRN_OPT, val);
2892
2893 /* 2. Enable Comp */
2894 val = I915_READ(CHICKEN_MISC_2);
2895 val &= ~CNL_COMP_PWR_DOWN;
2896 I915_WRITE(CHICKEN_MISC_2, val);
2897
Paulo Zanoni62d4a5e2018-02-05 13:40:41 -02002898 /* Dummy PORT_A to get the correct CNL register from the ICL macro */
2899 cnl_set_procmon_ref_values(dev_priv, PORT_A);
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07002900
2901 val = I915_READ(CNL_PORT_COMP_DW0);
2902 val |= COMP_INIT;
2903 I915_WRITE(CNL_PORT_COMP_DW0, val);
2904
2905 /* 3. */
2906 val = I915_READ(CNL_PORT_CL1CM_DW5);
2907 val |= CL_POWER_DOWN_ENABLE;
2908 I915_WRITE(CNL_PORT_CL1CM_DW5, val);
2909
Imre Deakb38131f2017-06-29 18:37:02 +03002910 /*
2911 * 4. Enable Power Well 1 (PG1).
2912 * The AUX IO power wells will be enabled on demand.
2913 */
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07002914 mutex_lock(&power_domains->lock);
2915 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
2916 intel_power_well_enable(dev_priv, well);
2917 mutex_unlock(&power_domains->lock);
2918
2919 /* 5. Enable CD clock */
2920 cnl_init_cdclk(dev_priv);
2921
2922 /* 6. Enable DBUF */
2923 gen9_dbuf_enable(dev_priv);
Imre Deak57522c42017-10-03 12:51:58 +03002924
2925 if (resume && dev_priv->csr.dmc_payload)
2926 intel_csr_load_program(dev_priv);
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07002927}
2928
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07002929static void cnl_display_core_uninit(struct drm_i915_private *dev_priv)
2930{
2931 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2932 struct i915_power_well *well;
2933 u32 val;
2934
2935 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
2936
2937 /* 1. Disable all display engine functions -> aready done */
2938
2939 /* 2. Disable DBUF */
2940 gen9_dbuf_disable(dev_priv);
2941
2942 /* 3. Disable CD clock */
2943 cnl_uninit_cdclk(dev_priv);
2944
Imre Deakb38131f2017-06-29 18:37:02 +03002945 /*
2946 * 4. Disable Power Well 1 (PG1).
2947 * The AUX IO power wells are toggled on demand, so they are already
2948 * disabled at this point.
2949 */
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07002950 mutex_lock(&power_domains->lock);
2951 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
2952 intel_power_well_disable(dev_priv, well);
2953 mutex_unlock(&power_domains->lock);
2954
Imre Deak846c6b22017-06-29 18:36:58 +03002955 usleep_range(10, 30); /* 10 us delay per Bspec */
2956
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07002957 /* 5. Disable Comp */
2958 val = I915_READ(CHICKEN_MISC_2);
Paulo Zanoni746a5172017-07-14 14:52:28 -03002959 val |= CNL_COMP_PWR_DOWN;
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07002960 I915_WRITE(CHICKEN_MISC_2, val);
2961}
2962
Paulo Zanoniad186f32018-02-05 13:40:43 -02002963static void icl_display_core_init(struct drm_i915_private *dev_priv,
2964 bool resume)
2965{
2966 enum port port;
2967 u32 val;
2968
2969 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
2970
2971 /* 1. Enable PCH reset handshake. */
2972 val = I915_READ(HSW_NDE_RSTWRN_OPT);
2973 val |= RESET_PCH_HANDSHAKE_ENABLE;
2974 I915_WRITE(HSW_NDE_RSTWRN_OPT, val);
2975
2976 for (port = PORT_A; port <= PORT_B; port++) {
2977 /* 2. Enable DDI combo PHY comp. */
2978 val = I915_READ(ICL_PHY_MISC(port));
2979 val &= ~ICL_PHY_MISC_DE_IO_COMP_PWR_DOWN;
2980 I915_WRITE(ICL_PHY_MISC(port), val);
2981
2982 cnl_set_procmon_ref_values(dev_priv, port);
2983
2984 val = I915_READ(ICL_PORT_COMP_DW0(port));
2985 val |= COMP_INIT;
2986 I915_WRITE(ICL_PORT_COMP_DW0(port), val);
2987
2988 /* 3. Set power down enable. */
2989 val = I915_READ(ICL_PORT_CL_DW5(port));
2990 val |= CL_POWER_DOWN_ENABLE;
2991 I915_WRITE(ICL_PORT_CL_DW5(port), val);
2992 }
2993
2994 /* 4. Enable power well 1 (PG1) and aux IO power. */
2995 /* FIXME: ICL power wells code not here yet. */
2996
2997 /* 5. Enable CDCLK. */
2998 icl_init_cdclk(dev_priv);
2999
3000 /* 6. Enable DBUF. */
Mahesh Kumar746edf82018-02-05 13:40:44 -02003001 icl_dbuf_enable(dev_priv);
Paulo Zanoniad186f32018-02-05 13:40:43 -02003002
3003 /* 7. Setup MBUS. */
Mahesh Kumar4cb45852018-02-05 13:40:45 -02003004 icl_mbus_init(dev_priv);
Paulo Zanoniad186f32018-02-05 13:40:43 -02003005
3006 /* 8. CHICKEN_DCPR_1 */
3007 I915_WRITE(GEN8_CHICKEN_DCPR_1, I915_READ(GEN8_CHICKEN_DCPR_1) |
3008 CNL_DDI_CLOCK_REG_ACCESS_ON);
3009}
3010
3011static void icl_display_core_uninit(struct drm_i915_private *dev_priv)
3012{
3013 enum port port;
3014 u32 val;
3015
3016 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
3017
3018 /* 1. Disable all display engine functions -> aready done */
3019
3020 /* 2. Disable DBUF */
Mahesh Kumar746edf82018-02-05 13:40:44 -02003021 icl_dbuf_disable(dev_priv);
Paulo Zanoniad186f32018-02-05 13:40:43 -02003022
3023 /* 3. Disable CD clock */
3024 icl_uninit_cdclk(dev_priv);
3025
3026 /* 4. Disable Power Well 1 (PG1) and Aux IO Power */
3027 /* FIXME: ICL power wells code not here yet. */
3028
3029 /* 5. Disable Comp */
3030 for (port = PORT_A; port <= PORT_B; port++) {
3031 val = I915_READ(ICL_PHY_MISC(port));
3032 val |= ICL_PHY_MISC_DE_IO_COMP_PWR_DOWN;
3033 I915_WRITE(ICL_PHY_MISC(port), val);
3034 }
3035}
3036
Ville Syrjälä70722462015-04-10 18:21:28 +03003037static void chv_phy_control_init(struct drm_i915_private *dev_priv)
3038{
3039 struct i915_power_well *cmn_bc =
3040 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_BC);
3041 struct i915_power_well *cmn_d =
3042 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_D);
3043
3044 /*
3045 * DISPLAY_PHY_CONTROL can get corrupted if read. As a
3046 * workaround never ever read DISPLAY_PHY_CONTROL, and
3047 * instead maintain a shadow copy ourselves. Use the actual
Ville Syrjäläe0fce782015-07-08 23:45:54 +03003048 * power well state and lane status to reconstruct the
3049 * expected initial value.
Ville Syrjälä70722462015-04-10 18:21:28 +03003050 */
3051 dev_priv->chv_phy_control =
Ville Syrjäläbc284542015-05-26 20:22:38 +03003052 PHY_LDO_SEQ_DELAY(PHY_LDO_DELAY_600NS, DPIO_PHY0) |
3053 PHY_LDO_SEQ_DELAY(PHY_LDO_DELAY_600NS, DPIO_PHY1) |
Ville Syrjäläe0fce782015-07-08 23:45:54 +03003054 PHY_CH_POWER_MODE(PHY_CH_DEEP_PSR, DPIO_PHY0, DPIO_CH0) |
3055 PHY_CH_POWER_MODE(PHY_CH_DEEP_PSR, DPIO_PHY0, DPIO_CH1) |
3056 PHY_CH_POWER_MODE(PHY_CH_DEEP_PSR, DPIO_PHY1, DPIO_CH0);
3057
3058 /*
3059 * If all lanes are disabled we leave the override disabled
3060 * with all power down bits cleared to match the state we
3061 * would use after disabling the port. Otherwise enable the
3062 * override and set the lane powerdown bits accding to the
3063 * current lane status.
3064 */
3065 if (cmn_bc->ops->is_enabled(dev_priv, cmn_bc)) {
3066 uint32_t status = I915_READ(DPLL(PIPE_A));
3067 unsigned int mask;
3068
3069 mask = status & DPLL_PORTB_READY_MASK;
3070 if (mask == 0xf)
3071 mask = 0x0;
3072 else
3073 dev_priv->chv_phy_control |=
3074 PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY0, DPIO_CH0);
3075
3076 dev_priv->chv_phy_control |=
3077 PHY_CH_POWER_DOWN_OVRD(mask, DPIO_PHY0, DPIO_CH0);
3078
3079 mask = (status & DPLL_PORTC_READY_MASK) >> 4;
3080 if (mask == 0xf)
3081 mask = 0x0;
3082 else
3083 dev_priv->chv_phy_control |=
3084 PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY0, DPIO_CH1);
3085
3086 dev_priv->chv_phy_control |=
3087 PHY_CH_POWER_DOWN_OVRD(mask, DPIO_PHY0, DPIO_CH1);
3088
Ville Syrjälä70722462015-04-10 18:21:28 +03003089 dev_priv->chv_phy_control |= PHY_COM_LANE_RESET_DEASSERT(DPIO_PHY0);
Ville Syrjälä3be60de2015-09-08 18:05:45 +03003090
3091 dev_priv->chv_phy_assert[DPIO_PHY0] = false;
3092 } else {
3093 dev_priv->chv_phy_assert[DPIO_PHY0] = true;
Ville Syrjäläe0fce782015-07-08 23:45:54 +03003094 }
3095
3096 if (cmn_d->ops->is_enabled(dev_priv, cmn_d)) {
3097 uint32_t status = I915_READ(DPIO_PHY_STATUS);
3098 unsigned int mask;
3099
3100 mask = status & DPLL_PORTD_READY_MASK;
3101
3102 if (mask == 0xf)
3103 mask = 0x0;
3104 else
3105 dev_priv->chv_phy_control |=
3106 PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY1, DPIO_CH0);
3107
3108 dev_priv->chv_phy_control |=
3109 PHY_CH_POWER_DOWN_OVRD(mask, DPIO_PHY1, DPIO_CH0);
3110
Ville Syrjälä70722462015-04-10 18:21:28 +03003111 dev_priv->chv_phy_control |= PHY_COM_LANE_RESET_DEASSERT(DPIO_PHY1);
Ville Syrjälä3be60de2015-09-08 18:05:45 +03003112
3113 dev_priv->chv_phy_assert[DPIO_PHY1] = false;
3114 } else {
3115 dev_priv->chv_phy_assert[DPIO_PHY1] = true;
Ville Syrjäläe0fce782015-07-08 23:45:54 +03003116 }
3117
3118 I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
3119
3120 DRM_DEBUG_KMS("Initial PHY_CONTROL=0x%08x\n",
3121 dev_priv->chv_phy_control);
Ville Syrjälä70722462015-04-10 18:21:28 +03003122}
3123
Daniel Vetter9c065a72014-09-30 10:56:38 +02003124static void vlv_cmnlane_wa(struct drm_i915_private *dev_priv)
3125{
3126 struct i915_power_well *cmn =
3127 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_BC);
3128 struct i915_power_well *disp2d =
3129 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DISP2D);
3130
Daniel Vetter9c065a72014-09-30 10:56:38 +02003131 /* If the display might be already active skip this */
Ville Syrjälä5d93a6e2014-10-16 20:52:33 +03003132 if (cmn->ops->is_enabled(dev_priv, cmn) &&
3133 disp2d->ops->is_enabled(dev_priv, disp2d) &&
Daniel Vetter9c065a72014-09-30 10:56:38 +02003134 I915_READ(DPIO_CTL) & DPIO_CMNRST)
3135 return;
3136
3137 DRM_DEBUG_KMS("toggling display PHY side reset\n");
3138
3139 /* cmnlane needs DPLL registers */
3140 disp2d->ops->enable(dev_priv, disp2d);
3141
3142 /*
3143 * From VLV2A0_DP_eDP_HDMI_DPIO_driver_vbios_notes_11.docx:
3144 * Need to assert and de-assert PHY SB reset by gating the
3145 * common lane power, then un-gating it.
3146 * Simply ungating isn't enough to reset the PHY enough to get
3147 * ports and lanes running.
3148 */
3149 cmn->ops->disable(dev_priv, cmn);
3150}
3151
Daniel Vettere4e76842014-09-30 10:56:42 +02003152/**
3153 * intel_power_domains_init_hw - initialize hardware power domain state
3154 * @dev_priv: i915 device instance
Tvrtko Ursulin14bb2c12016-06-03 14:02:17 +01003155 * @resume: Called from resume code paths or not
Daniel Vettere4e76842014-09-30 10:56:42 +02003156 *
3157 * This function initializes the hardware power domain state and enables all
Imre Deak8d8c3862017-02-17 17:39:46 +02003158 * power wells belonging to the INIT power domain. Power wells in other
3159 * domains (and not in the INIT domain) are referenced or disabled during the
3160 * modeset state HW readout. After that the reference count of each power well
3161 * must match its HW enabled state, see intel_power_domains_verify_state().
Daniel Vettere4e76842014-09-30 10:56:42 +02003162 */
Imre Deak73dfc222015-11-17 17:33:53 +02003163void intel_power_domains_init_hw(struct drm_i915_private *dev_priv, bool resume)
Daniel Vetter9c065a72014-09-30 10:56:38 +02003164{
Daniel Vetter9c065a72014-09-30 10:56:38 +02003165 struct i915_power_domains *power_domains = &dev_priv->power_domains;
3166
3167 power_domains->initializing = true;
3168
Paulo Zanoniad186f32018-02-05 13:40:43 -02003169 if (IS_ICELAKE(dev_priv)) {
3170 icl_display_core_init(dev_priv, resume);
3171 } else if (IS_CANNONLAKE(dev_priv)) {
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07003172 cnl_display_core_init(dev_priv, resume);
3173 } else if (IS_GEN9_BC(dev_priv)) {
Imre Deak73dfc222015-11-17 17:33:53 +02003174 skl_display_core_init(dev_priv, resume);
Ander Conselvan de Oliveirab817c442016-12-02 10:23:56 +02003175 } else if (IS_GEN9_LP(dev_priv)) {
Imre Deakd7d7c9e2016-04-01 16:02:42 +03003176 bxt_display_core_init(dev_priv, resume);
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01003177 } else if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä770effb2015-07-08 23:45:51 +03003178 mutex_lock(&power_domains->lock);
Ville Syrjälä70722462015-04-10 18:21:28 +03003179 chv_phy_control_init(dev_priv);
Ville Syrjälä770effb2015-07-08 23:45:51 +03003180 mutex_unlock(&power_domains->lock);
Tvrtko Ursulin11a914c2016-10-13 11:03:08 +01003181 } else if (IS_VALLEYVIEW(dev_priv)) {
Daniel Vetter9c065a72014-09-30 10:56:38 +02003182 mutex_lock(&power_domains->lock);
3183 vlv_cmnlane_wa(dev_priv);
3184 mutex_unlock(&power_domains->lock);
3185 }
3186
3187 /* For now, we need the power well to be always enabled. */
3188 intel_display_set_init_power(dev_priv, true);
Imre Deakd314cd42015-11-17 17:44:23 +02003189 /* Disable power support if the user asked so. */
Michal Wajdeczko4f044a82017-09-19 19:38:44 +00003190 if (!i915_modparams.disable_power_well)
Imre Deakd314cd42015-11-17 17:44:23 +02003191 intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
Imre Deak30eade12015-11-04 19:24:13 +02003192 intel_power_domains_sync_hw(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02003193 power_domains->initializing = false;
3194}
3195
Daniel Vettere4e76842014-09-30 10:56:42 +02003196/**
Imre Deak73dfc222015-11-17 17:33:53 +02003197 * intel_power_domains_suspend - suspend power domain state
3198 * @dev_priv: i915 device instance
3199 *
3200 * This function prepares the hardware power domain state before entering
3201 * system suspend. It must be paired with intel_power_domains_init_hw().
3202 */
3203void intel_power_domains_suspend(struct drm_i915_private *dev_priv)
3204{
Imre Deakd314cd42015-11-17 17:44:23 +02003205 /*
3206 * Even if power well support was disabled we still want to disable
3207 * power wells while we are system suspended.
3208 */
Michal Wajdeczko4f044a82017-09-19 19:38:44 +00003209 if (!i915_modparams.disable_power_well)
Imre Deakd314cd42015-11-17 17:44:23 +02003210 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
Imre Deak2622d792016-02-29 22:49:02 +02003211
Paulo Zanoniad186f32018-02-05 13:40:43 -02003212 if (IS_ICELAKE(dev_priv))
3213 icl_display_core_uninit(dev_priv);
3214 else if (IS_CANNONLAKE(dev_priv))
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07003215 cnl_display_core_uninit(dev_priv);
3216 else if (IS_GEN9_BC(dev_priv))
Imre Deak2622d792016-02-29 22:49:02 +02003217 skl_display_core_uninit(dev_priv);
Ander Conselvan de Oliveirab817c442016-12-02 10:23:56 +02003218 else if (IS_GEN9_LP(dev_priv))
Imre Deakd7d7c9e2016-04-01 16:02:42 +03003219 bxt_display_core_uninit(dev_priv);
Imre Deak73dfc222015-11-17 17:33:53 +02003220}
3221
Imre Deak8d8c3862017-02-17 17:39:46 +02003222static void intel_power_domains_dump_info(struct drm_i915_private *dev_priv)
3223{
3224 struct i915_power_domains *power_domains = &dev_priv->power_domains;
3225 struct i915_power_well *power_well;
3226
3227 for_each_power_well(dev_priv, power_well) {
3228 enum intel_display_power_domain domain;
3229
3230 DRM_DEBUG_DRIVER("%-25s %d\n",
3231 power_well->name, power_well->count);
3232
3233 for_each_power_domain(domain, power_well->domains)
3234 DRM_DEBUG_DRIVER(" %-23s %d\n",
3235 intel_display_power_domain_str(domain),
3236 power_domains->domain_use_count[domain]);
3237 }
3238}
3239
3240/**
3241 * intel_power_domains_verify_state - verify the HW/SW state for all power wells
3242 * @dev_priv: i915 device instance
3243 *
3244 * Verify if the reference count of each power well matches its HW enabled
3245 * state and the total refcount of the domains it belongs to. This must be
3246 * called after modeset HW state sanitization, which is responsible for
3247 * acquiring reference counts for any power wells in use and disabling the
3248 * ones left on by BIOS but not required by any active output.
3249 */
3250void intel_power_domains_verify_state(struct drm_i915_private *dev_priv)
3251{
3252 struct i915_power_domains *power_domains = &dev_priv->power_domains;
3253 struct i915_power_well *power_well;
3254 bool dump_domain_info;
3255
3256 mutex_lock(&power_domains->lock);
3257
3258 dump_domain_info = false;
3259 for_each_power_well(dev_priv, power_well) {
3260 enum intel_display_power_domain domain;
3261 int domains_count;
3262 bool enabled;
3263
3264 /*
3265 * Power wells not belonging to any domain (like the MISC_IO
3266 * and PW1 power wells) are under FW control, so ignore them,
3267 * since their state can change asynchronously.
3268 */
3269 if (!power_well->domains)
3270 continue;
3271
3272 enabled = power_well->ops->is_enabled(dev_priv, power_well);
3273 if ((power_well->count || power_well->always_on) != enabled)
3274 DRM_ERROR("power well %s state mismatch (refcount %d/enabled %d)",
3275 power_well->name, power_well->count, enabled);
3276
3277 domains_count = 0;
3278 for_each_power_domain(domain, power_well->domains)
3279 domains_count += power_domains->domain_use_count[domain];
3280
3281 if (power_well->count != domains_count) {
3282 DRM_ERROR("power well %s refcount/domain refcount mismatch "
3283 "(refcount %d/domains refcount %d)\n",
3284 power_well->name, power_well->count,
3285 domains_count);
3286 dump_domain_info = true;
3287 }
3288 }
3289
3290 if (dump_domain_info) {
3291 static bool dumped;
3292
3293 if (!dumped) {
3294 intel_power_domains_dump_info(dev_priv);
3295 dumped = true;
3296 }
3297 }
3298
3299 mutex_unlock(&power_domains->lock);
3300}
3301
Imre Deak73dfc222015-11-17 17:33:53 +02003302/**
Daniel Vettere4e76842014-09-30 10:56:42 +02003303 * intel_runtime_pm_get - grab a runtime pm reference
3304 * @dev_priv: i915 device instance
3305 *
3306 * This function grabs a device-level runtime pm reference (mostly used for GEM
3307 * code to ensure the GTT or GT is on) and ensures that it is powered up.
3308 *
3309 * Any runtime pm reference obtained by this function must have a symmetric
3310 * call to intel_runtime_pm_put() to release the reference again.
3311 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02003312void intel_runtime_pm_get(struct drm_i915_private *dev_priv)
3313{
David Weinehall52a05c32016-08-22 13:32:44 +03003314 struct pci_dev *pdev = dev_priv->drm.pdev;
3315 struct device *kdev = &pdev->dev;
Imre Deakf5073822017-03-28 12:38:55 +03003316 int ret;
Daniel Vetter9c065a72014-09-30 10:56:38 +02003317
Imre Deakf5073822017-03-28 12:38:55 +03003318 ret = pm_runtime_get_sync(kdev);
3319 WARN_ONCE(ret < 0, "pm_runtime_get_sync() failed: %d\n", ret);
Imre Deak1f814da2015-12-16 02:52:19 +02003320
Sagar Arun Kamblead1443f2017-10-10 22:30:04 +01003321 atomic_inc(&dev_priv->runtime_pm.wakeref_count);
Imre Deakc9b88462015-12-15 20:10:34 +02003322 assert_rpm_wakelock_held(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02003323}
3324
Daniel Vettere4e76842014-09-30 10:56:42 +02003325/**
Imre Deak09731282016-02-17 14:17:42 +02003326 * intel_runtime_pm_get_if_in_use - grab a runtime pm reference if device in use
3327 * @dev_priv: i915 device instance
3328 *
3329 * This function grabs a device-level runtime pm reference if the device is
Chris Wilsonacb79142018-02-19 12:50:46 +00003330 * already in use and ensures that it is powered up. It is illegal to try
3331 * and access the HW should intel_runtime_pm_get_if_in_use() report failure.
Imre Deak09731282016-02-17 14:17:42 +02003332 *
3333 * Any runtime pm reference obtained by this function must have a symmetric
3334 * call to intel_runtime_pm_put() to release the reference again.
Chris Wilsonacb79142018-02-19 12:50:46 +00003335 *
3336 * Returns: True if the wakeref was acquired, or False otherwise.
Imre Deak09731282016-02-17 14:17:42 +02003337 */
3338bool intel_runtime_pm_get_if_in_use(struct drm_i915_private *dev_priv)
3339{
Chris Wilson135dc792016-02-25 21:10:28 +00003340 if (IS_ENABLED(CONFIG_PM)) {
Chris Wilsonacb79142018-02-19 12:50:46 +00003341 struct pci_dev *pdev = dev_priv->drm.pdev;
3342 struct device *kdev = &pdev->dev;
Imre Deak09731282016-02-17 14:17:42 +02003343
Chris Wilson135dc792016-02-25 21:10:28 +00003344 /*
3345 * In cases runtime PM is disabled by the RPM core and we get
3346 * an -EINVAL return value we are not supposed to call this
3347 * function, since the power state is undefined. This applies
3348 * atm to the late/early system suspend/resume handlers.
3349 */
Chris Wilsonacb79142018-02-19 12:50:46 +00003350 if (pm_runtime_get_if_in_use(kdev) <= 0)
Chris Wilson135dc792016-02-25 21:10:28 +00003351 return false;
3352 }
Imre Deak09731282016-02-17 14:17:42 +02003353
Sagar Arun Kamblead1443f2017-10-10 22:30:04 +01003354 atomic_inc(&dev_priv->runtime_pm.wakeref_count);
Imre Deak09731282016-02-17 14:17:42 +02003355 assert_rpm_wakelock_held(dev_priv);
3356
3357 return true;
3358}
3359
3360/**
Daniel Vettere4e76842014-09-30 10:56:42 +02003361 * intel_runtime_pm_get_noresume - grab a runtime pm reference
3362 * @dev_priv: i915 device instance
3363 *
3364 * This function grabs a device-level runtime pm reference (mostly used for GEM
3365 * code to ensure the GTT or GT is on).
3366 *
3367 * It will _not_ power up the device but instead only check that it's powered
3368 * on. Therefore it is only valid to call this functions from contexts where
3369 * the device is known to be powered up and where trying to power it up would
3370 * result in hilarity and deadlocks. That pretty much means only the system
3371 * suspend/resume code where this is used to grab runtime pm references for
3372 * delayed setup down in work items.
3373 *
3374 * Any runtime pm reference obtained by this function must have a symmetric
3375 * call to intel_runtime_pm_put() to release the reference again.
3376 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02003377void intel_runtime_pm_get_noresume(struct drm_i915_private *dev_priv)
3378{
David Weinehall52a05c32016-08-22 13:32:44 +03003379 struct pci_dev *pdev = dev_priv->drm.pdev;
3380 struct device *kdev = &pdev->dev;
Daniel Vetter9c065a72014-09-30 10:56:38 +02003381
Imre Deakc9b88462015-12-15 20:10:34 +02003382 assert_rpm_wakelock_held(dev_priv);
David Weinehallc49d13e2016-08-22 13:32:42 +03003383 pm_runtime_get_noresume(kdev);
Imre Deak1f814da2015-12-16 02:52:19 +02003384
Sagar Arun Kamblead1443f2017-10-10 22:30:04 +01003385 atomic_inc(&dev_priv->runtime_pm.wakeref_count);
Daniel Vetter9c065a72014-09-30 10:56:38 +02003386}
3387
Daniel Vettere4e76842014-09-30 10:56:42 +02003388/**
3389 * intel_runtime_pm_put - release a runtime pm reference
3390 * @dev_priv: i915 device instance
3391 *
3392 * This function drops the device-level runtime pm reference obtained by
3393 * intel_runtime_pm_get() and might power down the corresponding
3394 * hardware block right away if this is the last reference.
3395 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02003396void intel_runtime_pm_put(struct drm_i915_private *dev_priv)
3397{
David Weinehall52a05c32016-08-22 13:32:44 +03003398 struct pci_dev *pdev = dev_priv->drm.pdev;
3399 struct device *kdev = &pdev->dev;
Daniel Vetter9c065a72014-09-30 10:56:38 +02003400
Imre Deak542db3c2015-12-15 20:10:36 +02003401 assert_rpm_wakelock_held(dev_priv);
Sagar Arun Kamblead1443f2017-10-10 22:30:04 +01003402 atomic_dec(&dev_priv->runtime_pm.wakeref_count);
Imre Deak1f814da2015-12-16 02:52:19 +02003403
David Weinehallc49d13e2016-08-22 13:32:42 +03003404 pm_runtime_mark_last_busy(kdev);
3405 pm_runtime_put_autosuspend(kdev);
Daniel Vetter9c065a72014-09-30 10:56:38 +02003406}
3407
Daniel Vettere4e76842014-09-30 10:56:42 +02003408/**
3409 * intel_runtime_pm_enable - enable runtime pm
3410 * @dev_priv: i915 device instance
3411 *
3412 * This function enables runtime pm at the end of the driver load sequence.
3413 *
3414 * Note that this function does currently not enable runtime pm for the
3415 * subordinate display power domains. That is only done on the first modeset
3416 * using intel_display_set_init_power().
3417 */
Daniel Vetterf458ebb2014-09-30 10:56:39 +02003418void intel_runtime_pm_enable(struct drm_i915_private *dev_priv)
Daniel Vetter9c065a72014-09-30 10:56:38 +02003419{
David Weinehall52a05c32016-08-22 13:32:44 +03003420 struct pci_dev *pdev = dev_priv->drm.pdev;
David Weinehall52a05c32016-08-22 13:32:44 +03003421 struct device *kdev = &pdev->dev;
Daniel Vetter9c065a72014-09-30 10:56:38 +02003422
David Weinehallc49d13e2016-08-22 13:32:42 +03003423 pm_runtime_set_autosuspend_delay(kdev, 10000); /* 10s */
3424 pm_runtime_mark_last_busy(kdev);
Imre Deakcbc68dc2015-12-17 19:04:33 +02003425
Imre Deak25b181b2015-12-17 13:44:56 +02003426 /*
3427 * Take a permanent reference to disable the RPM functionality and drop
3428 * it only when unloading the driver. Use the low level get/put helpers,
3429 * so the driver's own RPM reference tracking asserts also work on
3430 * platforms without RPM support.
3431 */
Tvrtko Ursulin6772ffe2016-10-13 11:02:55 +01003432 if (!HAS_RUNTIME_PM(dev_priv)) {
Imre Deakf5073822017-03-28 12:38:55 +03003433 int ret;
3434
David Weinehallc49d13e2016-08-22 13:32:42 +03003435 pm_runtime_dont_use_autosuspend(kdev);
Imre Deakf5073822017-03-28 12:38:55 +03003436 ret = pm_runtime_get_sync(kdev);
3437 WARN(ret < 0, "pm_runtime_get_sync() failed: %d\n", ret);
Imre Deakcbc68dc2015-12-17 19:04:33 +02003438 } else {
David Weinehallc49d13e2016-08-22 13:32:42 +03003439 pm_runtime_use_autosuspend(kdev);
Imre Deakcbc68dc2015-12-17 19:04:33 +02003440 }
Daniel Vetter9c065a72014-09-30 10:56:38 +02003441
Imre Deakaabee1b2015-12-15 20:10:29 +02003442 /*
3443 * The core calls the driver load handler with an RPM reference held.
3444 * We drop that here and will reacquire it during unloading in
3445 * intel_power_domains_fini().
3446 */
David Weinehallc49d13e2016-08-22 13:32:42 +03003447 pm_runtime_put_autosuspend(kdev);
Daniel Vetter9c065a72014-09-30 10:56:38 +02003448}