blob: 29988d8c0cf626a088fbc65d3c6809fae3f36f7a [file] [log] [blame]
Daniel Vetter9c065a72014-09-30 10:56:38 +02001/*
2 * Copyright © 2012-2014 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 *
23 * Authors:
24 * Eugeni Dodonov <eugeni.dodonov@intel.com>
25 * Daniel Vetter <daniel.vetter@ffwll.ch>
26 *
27 */
28
29#include <linux/pm_runtime.h>
30#include <linux/vgaarb.h>
31
32#include "i915_drv.h"
33#include "intel_drv.h"
Daniel Vetter9c065a72014-09-30 10:56:38 +020034
Daniel Vettere4e76842014-09-30 10:56:42 +020035/**
36 * DOC: runtime pm
37 *
38 * The i915 driver supports dynamic enabling and disabling of entire hardware
39 * blocks at runtime. This is especially important on the display side where
40 * software is supposed to control many power gates manually on recent hardware,
41 * since on the GT side a lot of the power management is done by the hardware.
42 * But even there some manual control at the device level is required.
43 *
44 * Since i915 supports a diverse set of platforms with a unified codebase and
45 * hardware engineers just love to shuffle functionality around between power
46 * domains there's a sizeable amount of indirection required. This file provides
47 * generic functions to the driver for grabbing and releasing references for
48 * abstract power domains. It then maps those to the actual power wells
49 * present for a given platform.
50 */
51
Suketu Shah5aefb232015-04-16 14:22:10 +053052bool intel_display_power_well_is_enabled(struct drm_i915_private *dev_priv,
Imre Deak438b8dc2017-07-11 23:42:30 +030053 enum i915_power_well_id power_well_id);
Suketu Shah5aefb232015-04-16 14:22:10 +053054
Imre Deak9c8d0b82016-06-13 16:44:34 +030055static struct i915_power_well *
Imre Deak438b8dc2017-07-11 23:42:30 +030056lookup_power_well(struct drm_i915_private *dev_priv,
57 enum i915_power_well_id power_well_id);
Imre Deak9c8d0b82016-06-13 16:44:34 +030058
Daniel Stone9895ad02015-11-20 15:55:33 +000059const char *
60intel_display_power_domain_str(enum intel_display_power_domain domain)
61{
62 switch (domain) {
63 case POWER_DOMAIN_PIPE_A:
64 return "PIPE_A";
65 case POWER_DOMAIN_PIPE_B:
66 return "PIPE_B";
67 case POWER_DOMAIN_PIPE_C:
68 return "PIPE_C";
69 case POWER_DOMAIN_PIPE_A_PANEL_FITTER:
70 return "PIPE_A_PANEL_FITTER";
71 case POWER_DOMAIN_PIPE_B_PANEL_FITTER:
72 return "PIPE_B_PANEL_FITTER";
73 case POWER_DOMAIN_PIPE_C_PANEL_FITTER:
74 return "PIPE_C_PANEL_FITTER";
75 case POWER_DOMAIN_TRANSCODER_A:
76 return "TRANSCODER_A";
77 case POWER_DOMAIN_TRANSCODER_B:
78 return "TRANSCODER_B";
79 case POWER_DOMAIN_TRANSCODER_C:
80 return "TRANSCODER_C";
81 case POWER_DOMAIN_TRANSCODER_EDP:
82 return "TRANSCODER_EDP";
Jani Nikula4d1de972016-03-18 17:05:42 +020083 case POWER_DOMAIN_TRANSCODER_DSI_A:
84 return "TRANSCODER_DSI_A";
85 case POWER_DOMAIN_TRANSCODER_DSI_C:
86 return "TRANSCODER_DSI_C";
Daniel Stone9895ad02015-11-20 15:55:33 +000087 case POWER_DOMAIN_PORT_DDI_A_LANES:
88 return "PORT_DDI_A_LANES";
89 case POWER_DOMAIN_PORT_DDI_B_LANES:
90 return "PORT_DDI_B_LANES";
91 case POWER_DOMAIN_PORT_DDI_C_LANES:
92 return "PORT_DDI_C_LANES";
93 case POWER_DOMAIN_PORT_DDI_D_LANES:
94 return "PORT_DDI_D_LANES";
95 case POWER_DOMAIN_PORT_DDI_E_LANES:
96 return "PORT_DDI_E_LANES";
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +020097 case POWER_DOMAIN_PORT_DDI_A_IO:
98 return "PORT_DDI_A_IO";
99 case POWER_DOMAIN_PORT_DDI_B_IO:
100 return "PORT_DDI_B_IO";
101 case POWER_DOMAIN_PORT_DDI_C_IO:
102 return "PORT_DDI_C_IO";
103 case POWER_DOMAIN_PORT_DDI_D_IO:
104 return "PORT_DDI_D_IO";
105 case POWER_DOMAIN_PORT_DDI_E_IO:
106 return "PORT_DDI_E_IO";
Daniel Stone9895ad02015-11-20 15:55:33 +0000107 case POWER_DOMAIN_PORT_DSI:
108 return "PORT_DSI";
109 case POWER_DOMAIN_PORT_CRT:
110 return "PORT_CRT";
111 case POWER_DOMAIN_PORT_OTHER:
112 return "PORT_OTHER";
113 case POWER_DOMAIN_VGA:
114 return "VGA";
115 case POWER_DOMAIN_AUDIO:
116 return "AUDIO";
117 case POWER_DOMAIN_PLLS:
118 return "PLLS";
119 case POWER_DOMAIN_AUX_A:
120 return "AUX_A";
121 case POWER_DOMAIN_AUX_B:
122 return "AUX_B";
123 case POWER_DOMAIN_AUX_C:
124 return "AUX_C";
125 case POWER_DOMAIN_AUX_D:
126 return "AUX_D";
127 case POWER_DOMAIN_GMBUS:
128 return "GMBUS";
129 case POWER_DOMAIN_INIT:
130 return "INIT";
131 case POWER_DOMAIN_MODESET:
132 return "MODESET";
133 default:
134 MISSING_CASE(domain);
135 return "?";
136 }
137}
138
Damien Lespiaue8ca9322015-07-30 18:20:26 -0300139static void intel_power_well_enable(struct drm_i915_private *dev_priv,
140 struct i915_power_well *power_well)
141{
142 DRM_DEBUG_KMS("enabling %s\n", power_well->name);
143 power_well->ops->enable(dev_priv, power_well);
144 power_well->hw_enabled = true;
145}
146
Damien Lespiaudcddab32015-07-30 18:20:27 -0300147static void intel_power_well_disable(struct drm_i915_private *dev_priv,
148 struct i915_power_well *power_well)
149{
150 DRM_DEBUG_KMS("disabling %s\n", power_well->name);
151 power_well->hw_enabled = false;
152 power_well->ops->disable(dev_priv, power_well);
153}
154
Imre Deakb409ca92016-06-13 16:44:33 +0300155static void intel_power_well_get(struct drm_i915_private *dev_priv,
156 struct i915_power_well *power_well)
157{
158 if (!power_well->count++)
159 intel_power_well_enable(dev_priv, power_well);
160}
161
162static void intel_power_well_put(struct drm_i915_private *dev_priv,
163 struct i915_power_well *power_well)
164{
165 WARN(!power_well->count, "Use count on power well %s is already zero",
166 power_well->name);
167
168 if (!--power_well->count)
169 intel_power_well_disable(dev_priv, power_well);
170}
171
Daniel Vettere4e76842014-09-30 10:56:42 +0200172/*
Daniel Vetter9c065a72014-09-30 10:56:38 +0200173 * We should only use the power well if we explicitly asked the hardware to
174 * enable it, so check if it's enabled and also check if we've requested it to
175 * be enabled.
176 */
177static bool hsw_power_well_enabled(struct drm_i915_private *dev_priv,
178 struct i915_power_well *power_well)
179{
180 return I915_READ(HSW_PWR_WELL_DRIVER) ==
181 (HSW_PWR_WELL_ENABLE_REQUEST | HSW_PWR_WELL_STATE_ENABLED);
182}
183
Daniel Vettere4e76842014-09-30 10:56:42 +0200184/**
185 * __intel_display_power_is_enabled - unlocked check for a power domain
186 * @dev_priv: i915 device instance
187 * @domain: power domain to check
188 *
189 * This is the unlocked version of intel_display_power_is_enabled() and should
190 * only be used from error capture and recovery code where deadlocks are
191 * possible.
192 *
193 * Returns:
194 * True when the power domain is enabled, false otherwise.
195 */
Daniel Vetterf458ebb2014-09-30 10:56:39 +0200196bool __intel_display_power_is_enabled(struct drm_i915_private *dev_priv,
197 enum intel_display_power_domain domain)
Daniel Vetter9c065a72014-09-30 10:56:38 +0200198{
Daniel Vetter9c065a72014-09-30 10:56:38 +0200199 struct i915_power_well *power_well;
200 bool is_enabled;
Daniel Vetter9c065a72014-09-30 10:56:38 +0200201
202 if (dev_priv->pm.suspended)
203 return false;
204
Daniel Vetter9c065a72014-09-30 10:56:38 +0200205 is_enabled = true;
206
Imre Deak75ccb2e2017-02-17 17:39:43 +0200207 for_each_power_domain_well_rev(dev_priv, power_well, BIT_ULL(domain)) {
Daniel Vetter9c065a72014-09-30 10:56:38 +0200208 if (power_well->always_on)
209 continue;
210
211 if (!power_well->hw_enabled) {
212 is_enabled = false;
213 break;
214 }
215 }
216
217 return is_enabled;
218}
219
Daniel Vettere4e76842014-09-30 10:56:42 +0200220/**
Damien Lespiauf61ccae2014-11-25 13:45:41 +0000221 * intel_display_power_is_enabled - check for a power domain
Daniel Vettere4e76842014-09-30 10:56:42 +0200222 * @dev_priv: i915 device instance
223 * @domain: power domain to check
224 *
225 * This function can be used to check the hw power domain state. It is mostly
226 * used in hardware state readout functions. Everywhere else code should rely
227 * upon explicit power domain reference counting to ensure that the hardware
228 * block is powered up before accessing it.
229 *
230 * Callers must hold the relevant modesetting locks to ensure that concurrent
231 * threads can't disable the power well while the caller tries to read a few
232 * registers.
233 *
234 * Returns:
235 * True when the power domain is enabled, false otherwise.
236 */
Daniel Vetterf458ebb2014-09-30 10:56:39 +0200237bool intel_display_power_is_enabled(struct drm_i915_private *dev_priv,
238 enum intel_display_power_domain domain)
Daniel Vetter9c065a72014-09-30 10:56:38 +0200239{
240 struct i915_power_domains *power_domains;
241 bool ret;
242
243 power_domains = &dev_priv->power_domains;
244
245 mutex_lock(&power_domains->lock);
Daniel Vetterf458ebb2014-09-30 10:56:39 +0200246 ret = __intel_display_power_is_enabled(dev_priv, domain);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200247 mutex_unlock(&power_domains->lock);
248
249 return ret;
250}
251
Daniel Vettere4e76842014-09-30 10:56:42 +0200252/**
253 * intel_display_set_init_power - set the initial power domain state
254 * @dev_priv: i915 device instance
255 * @enable: whether to enable or disable the initial power domain state
256 *
257 * For simplicity our driver load/unload and system suspend/resume code assumes
258 * that all power domains are always enabled. This functions controls the state
259 * of this little hack. While the initial power domain state is enabled runtime
260 * pm is effectively disabled.
261 */
Daniel Vetterd9bc89d92014-09-30 10:56:40 +0200262void intel_display_set_init_power(struct drm_i915_private *dev_priv,
263 bool enable)
264{
265 if (dev_priv->power_domains.init_power_on == enable)
266 return;
267
268 if (enable)
269 intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
270 else
271 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
272
273 dev_priv->power_domains.init_power_on = enable;
274}
275
Daniel Vetter9c065a72014-09-30 10:56:38 +0200276/*
277 * Starting with Haswell, we have a "Power Down Well" that can be turned off
278 * when not needed anymore. We have 4 registers that can request the power well
279 * to be enabled, and it will only be disabled if none of the registers is
280 * requesting it to be enabled.
281 */
282static void hsw_power_well_post_enable(struct drm_i915_private *dev_priv)
283{
David Weinehall52a05c32016-08-22 13:32:44 +0300284 struct pci_dev *pdev = dev_priv->drm.pdev;
Daniel Vetter9c065a72014-09-30 10:56:38 +0200285
286 /*
287 * After we re-enable the power well, if we touch VGA register 0x3d5
288 * we'll get unclaimed register interrupts. This stops after we write
289 * anything to the VGA MSR register. The vgacon module uses this
290 * register all the time, so if we unbind our driver and, as a
291 * consequence, bind vgacon, we'll get stuck in an infinite loop at
292 * console_unlock(). So make here we touch the VGA MSR register, making
293 * sure vgacon can keep working normally without triggering interrupts
294 * and error messages.
295 */
David Weinehall52a05c32016-08-22 13:32:44 +0300296 vga_get_uninterruptible(pdev, VGA_RSRC_LEGACY_IO);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200297 outb(inb(VGA_MSR_READ), VGA_MSR_WRITE);
David Weinehall52a05c32016-08-22 13:32:44 +0300298 vga_put(pdev, VGA_RSRC_LEGACY_IO);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200299
Tvrtko Ursulin86527442016-10-13 11:03:00 +0100300 if (IS_BROADWELL(dev_priv))
Damien Lespiau4c6c03b2015-03-06 18:50:48 +0000301 gen8_irq_power_well_post_enable(dev_priv,
302 1 << PIPE_C | 1 << PIPE_B);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200303}
304
Ville Syrjäläaae8ba82016-02-19 20:47:30 +0200305static void hsw_power_well_pre_disable(struct drm_i915_private *dev_priv)
306{
307 if (IS_BROADWELL(dev_priv))
308 gen8_irq_power_well_pre_disable(dev_priv,
309 1 << PIPE_C | 1 << PIPE_B);
310}
311
Damien Lespiaud14c0342015-03-06 18:50:51 +0000312static void skl_power_well_post_enable(struct drm_i915_private *dev_priv,
313 struct i915_power_well *power_well)
314{
David Weinehall52a05c32016-08-22 13:32:44 +0300315 struct pci_dev *pdev = dev_priv->drm.pdev;
Damien Lespiaud14c0342015-03-06 18:50:51 +0000316
317 /*
318 * After we re-enable the power well, if we touch VGA register 0x3d5
319 * we'll get unclaimed register interrupts. This stops after we write
320 * anything to the VGA MSR register. The vgacon module uses this
321 * register all the time, so if we unbind our driver and, as a
322 * consequence, bind vgacon, we'll get stuck in an infinite loop at
323 * console_unlock(). So make here we touch the VGA MSR register, making
324 * sure vgacon can keep working normally without triggering interrupts
325 * and error messages.
326 */
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +0300327 if (power_well->id == SKL_DISP_PW_2) {
David Weinehall52a05c32016-08-22 13:32:44 +0300328 vga_get_uninterruptible(pdev, VGA_RSRC_LEGACY_IO);
Damien Lespiaud14c0342015-03-06 18:50:51 +0000329 outb(inb(VGA_MSR_READ), VGA_MSR_WRITE);
David Weinehall52a05c32016-08-22 13:32:44 +0300330 vga_put(pdev, VGA_RSRC_LEGACY_IO);
Damien Lespiaud14c0342015-03-06 18:50:51 +0000331
332 gen8_irq_power_well_post_enable(dev_priv,
333 1 << PIPE_C | 1 << PIPE_B);
334 }
Damien Lespiaud14c0342015-03-06 18:50:51 +0000335}
336
Ville Syrjäläaae8ba82016-02-19 20:47:30 +0200337static void skl_power_well_pre_disable(struct drm_i915_private *dev_priv,
338 struct i915_power_well *power_well)
339{
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +0300340 if (power_well->id == SKL_DISP_PW_2)
Ville Syrjäläaae8ba82016-02-19 20:47:30 +0200341 gen8_irq_power_well_pre_disable(dev_priv,
342 1 << PIPE_C | 1 << PIPE_B);
343}
344
Imre Deak42d93662017-06-29 18:37:01 +0300345static void gen9_wait_for_power_well_enable(struct drm_i915_private *dev_priv,
346 struct i915_power_well *power_well)
347{
Imre Deak438b8dc2017-07-11 23:42:30 +0300348 enum i915_power_well_id id = power_well->id;
Imre Deak42d93662017-06-29 18:37:01 +0300349
350 /* Timeout for PW1:10 us, AUX:not specified, other PWs:20 us. */
351 WARN_ON(intel_wait_for_register(dev_priv,
352 HSW_PWR_WELL_DRIVER,
353 SKL_POWER_WELL_STATE(id),
354 SKL_POWER_WELL_STATE(id),
355 1));
356}
357
Imre Deak438b8dc2017-07-11 23:42:30 +0300358static u32 gen9_power_well_requesters(struct drm_i915_private *dev_priv,
359 enum i915_power_well_id id)
Imre Deak42d93662017-06-29 18:37:01 +0300360{
361 u32 req_mask = SKL_POWER_WELL_REQ(id);
362 u32 ret;
363
364 ret = I915_READ(HSW_PWR_WELL_BIOS) & req_mask ? 1 : 0;
365 ret |= I915_READ(HSW_PWR_WELL_DRIVER) & req_mask ? 2 : 0;
366 ret |= I915_READ(HSW_PWR_WELL_KVMR) & req_mask ? 4 : 0;
367 ret |= I915_READ(HSW_PWR_WELL_DEBUG) & req_mask ? 8 : 0;
368
369 return ret;
370}
371
372static void gen9_wait_for_power_well_disable(struct drm_i915_private *dev_priv,
373 struct i915_power_well *power_well)
374{
Imre Deak438b8dc2017-07-11 23:42:30 +0300375 enum i915_power_well_id id = power_well->id;
Imre Deak42d93662017-06-29 18:37:01 +0300376 bool disabled;
377 u32 reqs;
378
379 /*
380 * Bspec doesn't require waiting for PWs to get disabled, but still do
381 * this for paranoia. The known cases where a PW will be forced on:
382 * - a KVMR request on any power well via the KVMR request register
383 * - a DMC request on PW1 and MISC_IO power wells via the BIOS and
384 * DEBUG request registers
385 * Skip the wait in case any of the request bits are set and print a
386 * diagnostic message.
387 */
388 wait_for((disabled = !(I915_READ(HSW_PWR_WELL_DRIVER) &
389 SKL_POWER_WELL_STATE(id))) ||
390 (reqs = gen9_power_well_requesters(dev_priv, id)), 1);
391 if (disabled)
392 return;
393
394 DRM_DEBUG_KMS("%s forced on (bios:%d driver:%d kvmr:%d debug:%d)\n",
395 power_well->name,
396 !!(reqs & 1), !!(reqs & 2), !!(reqs & 4), !!(reqs & 8));
397}
398
Daniel Vetter9c065a72014-09-30 10:56:38 +0200399static void hsw_set_power_well(struct drm_i915_private *dev_priv,
400 struct i915_power_well *power_well, bool enable)
401{
Daniel Vetter9c065a72014-09-30 10:56:38 +0200402 uint32_t tmp;
403
404 tmp = I915_READ(HSW_PWR_WELL_DRIVER);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200405
406 if (enable) {
Imre Deak00742ca2017-07-06 17:40:32 +0300407 I915_WRITE(HSW_PWR_WELL_DRIVER, HSW_PWR_WELL_ENABLE_REQUEST);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200408
Imre Deak00742ca2017-07-06 17:40:32 +0300409 DRM_DEBUG_KMS("Enabling power well\n");
410 if (intel_wait_for_register(dev_priv,
411 HSW_PWR_WELL_DRIVER,
412 HSW_PWR_WELL_STATE_ENABLED,
413 HSW_PWR_WELL_STATE_ENABLED,
414 20))
415 DRM_ERROR("Timeout enabling power well\n");
416 hsw_power_well_post_enable(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200417 } else {
Imre Deak00742ca2017-07-06 17:40:32 +0300418 hsw_power_well_pre_disable(dev_priv);
419 I915_WRITE(HSW_PWR_WELL_DRIVER, 0);
420 POSTING_READ(HSW_PWR_WELL_DRIVER);
421 DRM_DEBUG_KMS("Requesting to disable the power well\n");
Daniel Vetter9c065a72014-09-30 10:56:38 +0200422 }
423}
424
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000425#define SKL_DISPLAY_POWERWELL_2_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200426 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
427 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
428 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
429 BIT_ULL(POWER_DOMAIN_PIPE_C) | \
430 BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
431 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
432 BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
433 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
434 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
435 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_LANES) | \
436 BIT_ULL(POWER_DOMAIN_PORT_DDI_E_LANES) | \
437 BIT_ULL(POWER_DOMAIN_AUX_B) | \
438 BIT_ULL(POWER_DOMAIN_AUX_C) | \
439 BIT_ULL(POWER_DOMAIN_AUX_D) | \
440 BIT_ULL(POWER_DOMAIN_AUDIO) | \
441 BIT_ULL(POWER_DOMAIN_VGA) | \
442 BIT_ULL(POWER_DOMAIN_INIT))
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +0200443#define SKL_DISPLAY_DDI_IO_A_E_POWER_DOMAINS ( \
444 BIT_ULL(POWER_DOMAIN_PORT_DDI_A_IO) | \
445 BIT_ULL(POWER_DOMAIN_PORT_DDI_E_IO) | \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200446 BIT_ULL(POWER_DOMAIN_INIT))
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +0200447#define SKL_DISPLAY_DDI_IO_B_POWER_DOMAINS ( \
448 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_IO) | \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200449 BIT_ULL(POWER_DOMAIN_INIT))
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +0200450#define SKL_DISPLAY_DDI_IO_C_POWER_DOMAINS ( \
451 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_IO) | \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200452 BIT_ULL(POWER_DOMAIN_INIT))
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +0200453#define SKL_DISPLAY_DDI_IO_D_POWER_DOMAINS ( \
454 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_IO) | \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200455 BIT_ULL(POWER_DOMAIN_INIT))
Patrik Jakobsson9f836f92015-11-16 16:20:01 +0100456#define SKL_DISPLAY_DC_OFF_POWER_DOMAINS ( \
457 SKL_DISPLAY_POWERWELL_2_POWER_DOMAINS | \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200458 BIT_ULL(POWER_DOMAIN_MODESET) | \
459 BIT_ULL(POWER_DOMAIN_AUX_A) | \
460 BIT_ULL(POWER_DOMAIN_INIT))
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000461
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +0530462#define BXT_DISPLAY_POWERWELL_2_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200463 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
464 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
465 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
466 BIT_ULL(POWER_DOMAIN_PIPE_C) | \
467 BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
468 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
469 BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
470 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
471 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
472 BIT_ULL(POWER_DOMAIN_AUX_B) | \
473 BIT_ULL(POWER_DOMAIN_AUX_C) | \
474 BIT_ULL(POWER_DOMAIN_AUDIO) | \
475 BIT_ULL(POWER_DOMAIN_VGA) | \
476 BIT_ULL(POWER_DOMAIN_GMBUS) | \
477 BIT_ULL(POWER_DOMAIN_INIT))
Patrik Jakobsson9f836f92015-11-16 16:20:01 +0100478#define BXT_DISPLAY_DC_OFF_POWER_DOMAINS ( \
479 BXT_DISPLAY_POWERWELL_2_POWER_DOMAINS | \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200480 BIT_ULL(POWER_DOMAIN_MODESET) | \
481 BIT_ULL(POWER_DOMAIN_AUX_A) | \
482 BIT_ULL(POWER_DOMAIN_INIT))
Imre Deak9c8d0b82016-06-13 16:44:34 +0300483#define BXT_DPIO_CMN_A_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200484 BIT_ULL(POWER_DOMAIN_PORT_DDI_A_LANES) | \
485 BIT_ULL(POWER_DOMAIN_AUX_A) | \
486 BIT_ULL(POWER_DOMAIN_INIT))
Imre Deak9c8d0b82016-06-13 16:44:34 +0300487#define BXT_DPIO_CMN_BC_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200488 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
489 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
490 BIT_ULL(POWER_DOMAIN_AUX_B) | \
491 BIT_ULL(POWER_DOMAIN_AUX_C) | \
492 BIT_ULL(POWER_DOMAIN_INIT))
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +0530493
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +0200494#define GLK_DISPLAY_POWERWELL_2_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200495 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
496 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
497 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
498 BIT_ULL(POWER_DOMAIN_PIPE_C) | \
499 BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
500 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
501 BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
502 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
503 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
504 BIT_ULL(POWER_DOMAIN_AUX_B) | \
505 BIT_ULL(POWER_DOMAIN_AUX_C) | \
506 BIT_ULL(POWER_DOMAIN_AUDIO) | \
507 BIT_ULL(POWER_DOMAIN_VGA) | \
508 BIT_ULL(POWER_DOMAIN_INIT))
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +0200509#define GLK_DISPLAY_DDI_IO_A_POWER_DOMAINS ( \
510 BIT_ULL(POWER_DOMAIN_PORT_DDI_A_IO))
511#define GLK_DISPLAY_DDI_IO_B_POWER_DOMAINS ( \
512 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_IO))
513#define GLK_DISPLAY_DDI_IO_C_POWER_DOMAINS ( \
514 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_IO))
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +0200515#define GLK_DPIO_CMN_A_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200516 BIT_ULL(POWER_DOMAIN_PORT_DDI_A_LANES) | \
517 BIT_ULL(POWER_DOMAIN_AUX_A) | \
518 BIT_ULL(POWER_DOMAIN_INIT))
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +0200519#define GLK_DPIO_CMN_B_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200520 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
521 BIT_ULL(POWER_DOMAIN_AUX_B) | \
522 BIT_ULL(POWER_DOMAIN_INIT))
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +0200523#define GLK_DPIO_CMN_C_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200524 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
525 BIT_ULL(POWER_DOMAIN_AUX_C) | \
526 BIT_ULL(POWER_DOMAIN_INIT))
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +0200527#define GLK_DISPLAY_AUX_A_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200528 BIT_ULL(POWER_DOMAIN_AUX_A) | \
529 BIT_ULL(POWER_DOMAIN_INIT))
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +0200530#define GLK_DISPLAY_AUX_B_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200531 BIT_ULL(POWER_DOMAIN_AUX_B) | \
532 BIT_ULL(POWER_DOMAIN_INIT))
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +0200533#define GLK_DISPLAY_AUX_C_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200534 BIT_ULL(POWER_DOMAIN_AUX_C) | \
535 BIT_ULL(POWER_DOMAIN_INIT))
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +0200536#define GLK_DISPLAY_DC_OFF_POWER_DOMAINS ( \
537 GLK_DISPLAY_POWERWELL_2_POWER_DOMAINS | \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200538 BIT_ULL(POWER_DOMAIN_MODESET) | \
539 BIT_ULL(POWER_DOMAIN_AUX_A) | \
540 BIT_ULL(POWER_DOMAIN_INIT))
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +0200541
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -0700542#define CNL_DISPLAY_POWERWELL_2_POWER_DOMAINS ( \
543 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
544 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
545 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
546 BIT_ULL(POWER_DOMAIN_PIPE_C) | \
547 BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
548 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
549 BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
550 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
551 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
552 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_LANES) | \
553 BIT_ULL(POWER_DOMAIN_PORT_DDI_E_LANES) | \
554 BIT_ULL(POWER_DOMAIN_AUX_B) | \
555 BIT_ULL(POWER_DOMAIN_AUX_C) | \
556 BIT_ULL(POWER_DOMAIN_AUX_D) | \
557 BIT_ULL(POWER_DOMAIN_AUDIO) | \
558 BIT_ULL(POWER_DOMAIN_VGA) | \
559 BIT_ULL(POWER_DOMAIN_INIT))
560#define CNL_DISPLAY_DDI_A_IO_POWER_DOMAINS ( \
561 BIT_ULL(POWER_DOMAIN_PORT_DDI_A_IO) | \
562 BIT_ULL(POWER_DOMAIN_PORT_DDI_E_IO) | \
563 BIT_ULL(POWER_DOMAIN_INIT))
564#define CNL_DISPLAY_DDI_B_IO_POWER_DOMAINS ( \
565 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_IO) | \
566 BIT_ULL(POWER_DOMAIN_INIT))
567#define CNL_DISPLAY_DDI_C_IO_POWER_DOMAINS ( \
568 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_IO) | \
569 BIT_ULL(POWER_DOMAIN_INIT))
570#define CNL_DISPLAY_DDI_D_IO_POWER_DOMAINS ( \
571 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_IO) | \
572 BIT_ULL(POWER_DOMAIN_INIT))
573#define CNL_DISPLAY_AUX_A_POWER_DOMAINS ( \
574 BIT_ULL(POWER_DOMAIN_AUX_A) | \
575 BIT_ULL(POWER_DOMAIN_INIT))
576#define CNL_DISPLAY_AUX_B_POWER_DOMAINS ( \
577 BIT_ULL(POWER_DOMAIN_AUX_B) | \
578 BIT_ULL(POWER_DOMAIN_INIT))
579#define CNL_DISPLAY_AUX_C_POWER_DOMAINS ( \
580 BIT_ULL(POWER_DOMAIN_AUX_C) | \
581 BIT_ULL(POWER_DOMAIN_INIT))
582#define CNL_DISPLAY_AUX_D_POWER_DOMAINS ( \
583 BIT_ULL(POWER_DOMAIN_AUX_D) | \
584 BIT_ULL(POWER_DOMAIN_INIT))
585#define CNL_DISPLAY_DC_OFF_POWER_DOMAINS ( \
586 CNL_DISPLAY_POWERWELL_2_POWER_DOMAINS | \
587 BIT_ULL(POWER_DOMAIN_MODESET) | \
588 BIT_ULL(POWER_DOMAIN_AUX_A) | \
589 BIT_ULL(POWER_DOMAIN_INIT))
590
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530591static void assert_can_enable_dc9(struct drm_i915_private *dev_priv)
592{
Imre Deakbfcdabe2016-04-01 16:02:37 +0300593 WARN_ONCE((I915_READ(DC_STATE_EN) & DC_STATE_EN_DC9),
594 "DC9 already programmed to be enabled.\n");
595 WARN_ONCE(I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC5,
596 "DC5 still not disabled to enable DC9.\n");
Imre Deake8a3a2a2017-06-29 18:37:00 +0300597 WARN_ONCE(I915_READ(HSW_PWR_WELL_DRIVER) &
598 SKL_POWER_WELL_REQ(SKL_DISP_PW_2),
599 "Power well 2 on.\n");
Imre Deakbfcdabe2016-04-01 16:02:37 +0300600 WARN_ONCE(intel_irqs_enabled(dev_priv),
601 "Interrupts not disabled yet.\n");
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530602
603 /*
604 * TODO: check for the following to verify the conditions to enter DC9
605 * state are satisfied:
606 * 1] Check relevant display engine registers to verify if mode set
607 * disable sequence was followed.
608 * 2] Check if display uninitialize sequence is initialized.
609 */
610}
611
612static void assert_can_disable_dc9(struct drm_i915_private *dev_priv)
613{
Imre Deakbfcdabe2016-04-01 16:02:37 +0300614 WARN_ONCE(intel_irqs_enabled(dev_priv),
615 "Interrupts not disabled yet.\n");
616 WARN_ONCE(I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC5,
617 "DC5 still not disabled.\n");
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530618
619 /*
620 * TODO: check for the following to verify DC9 state was indeed
621 * entered before programming to disable it:
622 * 1] Check relevant display engine registers to verify if mode
623 * set disable sequence was followed.
624 * 2] Check if display uninitialize sequence is initialized.
625 */
626}
627
Mika Kuoppala779cb5d2016-02-18 17:58:09 +0200628static void gen9_write_dc_state(struct drm_i915_private *dev_priv,
629 u32 state)
630{
631 int rewrites = 0;
632 int rereads = 0;
633 u32 v;
634
635 I915_WRITE(DC_STATE_EN, state);
636
637 /* It has been observed that disabling the dc6 state sometimes
638 * doesn't stick and dmc keeps returning old value. Make sure
639 * the write really sticks enough times and also force rewrite until
640 * we are confident that state is exactly what we want.
641 */
642 do {
643 v = I915_READ(DC_STATE_EN);
644
645 if (v != state) {
646 I915_WRITE(DC_STATE_EN, state);
647 rewrites++;
648 rereads = 0;
649 } else if (rereads++ > 5) {
650 break;
651 }
652
653 } while (rewrites < 100);
654
655 if (v != state)
656 DRM_ERROR("Writing dc state to 0x%x failed, now 0x%x\n",
657 state, v);
658
659 /* Most of the times we need one retry, avoid spam */
660 if (rewrites > 1)
661 DRM_DEBUG_KMS("Rewrote dc state to 0x%x %d times\n",
662 state, rewrites);
663}
664
Imre Deakda2f41d2016-04-20 20:27:56 +0300665static u32 gen9_dc_mask(struct drm_i915_private *dev_priv)
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530666{
Imre Deakda2f41d2016-04-20 20:27:56 +0300667 u32 mask;
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530668
Imre Deak13ae3a02015-11-04 19:24:16 +0200669 mask = DC_STATE_EN_UPTO_DC5;
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200670 if (IS_GEN9_LP(dev_priv))
Imre Deak13ae3a02015-11-04 19:24:16 +0200671 mask |= DC_STATE_EN_DC9;
672 else
673 mask |= DC_STATE_EN_UPTO_DC6;
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530674
Imre Deakda2f41d2016-04-20 20:27:56 +0300675 return mask;
676}
677
678void gen9_sanitize_dc_state(struct drm_i915_private *dev_priv)
679{
680 u32 val;
681
682 val = I915_READ(DC_STATE_EN) & gen9_dc_mask(dev_priv);
683
684 DRM_DEBUG_KMS("Resetting DC state tracking from %02x to %02x\n",
685 dev_priv->csr.dc_state, val);
686 dev_priv->csr.dc_state = val;
687}
688
689static void gen9_set_dc_state(struct drm_i915_private *dev_priv, uint32_t state)
690{
691 uint32_t val;
692 uint32_t mask;
693
Imre Deaka37baf32016-02-29 22:49:03 +0200694 if (WARN_ON_ONCE(state & ~dev_priv->csr.allowed_dc_mask))
695 state &= dev_priv->csr.allowed_dc_mask;
Patrik Jakobsson443646c2015-11-16 15:01:06 +0100696
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530697 val = I915_READ(DC_STATE_EN);
Imre Deakda2f41d2016-04-20 20:27:56 +0300698 mask = gen9_dc_mask(dev_priv);
Imre Deak13ae3a02015-11-04 19:24:16 +0200699 DRM_DEBUG_KMS("Setting DC state from %02x to %02x\n",
700 val & mask, state);
Patrik Jakobsson832dba82016-02-18 17:21:11 +0200701
702 /* Check if DMC is ignoring our DC state requests */
703 if ((val & mask) != dev_priv->csr.dc_state)
704 DRM_ERROR("DC state mismatch (0x%x -> 0x%x)\n",
705 dev_priv->csr.dc_state, val & mask);
706
Imre Deak13ae3a02015-11-04 19:24:16 +0200707 val &= ~mask;
708 val |= state;
Mika Kuoppala779cb5d2016-02-18 17:58:09 +0200709
710 gen9_write_dc_state(dev_priv, val);
Patrik Jakobsson832dba82016-02-18 17:21:11 +0200711
712 dev_priv->csr.dc_state = val & mask;
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530713}
714
Imre Deak13ae3a02015-11-04 19:24:16 +0200715void bxt_enable_dc9(struct drm_i915_private *dev_priv)
716{
717 assert_can_enable_dc9(dev_priv);
718
719 DRM_DEBUG_KMS("Enabling DC9\n");
720
Imre Deak78597992016-06-16 16:37:20 +0300721 intel_power_sequencer_reset(dev_priv);
Imre Deak13ae3a02015-11-04 19:24:16 +0200722 gen9_set_dc_state(dev_priv, DC_STATE_EN_DC9);
723}
724
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530725void bxt_disable_dc9(struct drm_i915_private *dev_priv)
726{
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530727 assert_can_disable_dc9(dev_priv);
728
729 DRM_DEBUG_KMS("Disabling DC9\n");
730
Imre Deak13ae3a02015-11-04 19:24:16 +0200731 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
Imre Deak8090ba82016-08-10 14:07:33 +0300732
733 intel_pps_unlock_regs_wa(dev_priv);
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530734}
735
Daniel Vetteraf5fead2015-10-28 23:58:57 +0200736static void assert_csr_loaded(struct drm_i915_private *dev_priv)
737{
738 WARN_ONCE(!I915_READ(CSR_PROGRAM(0)),
739 "CSR program storage start is NULL\n");
740 WARN_ONCE(!I915_READ(CSR_SSP_BASE), "CSR SSP Base Not fine\n");
741 WARN_ONCE(!I915_READ(CSR_HTP_SKL), "CSR HTP Not fine\n");
742}
743
Suketu Shah5aefb232015-04-16 14:22:10 +0530744static void assert_can_enable_dc5(struct drm_i915_private *dev_priv)
Suketu Shahdc174302015-04-17 19:46:16 +0530745{
Suketu Shah5aefb232015-04-16 14:22:10 +0530746 bool pg2_enabled = intel_display_power_well_is_enabled(dev_priv,
747 SKL_DISP_PW_2);
748
Jesse Barnes6ff8ab02015-09-10 08:20:28 -0700749 WARN_ONCE(pg2_enabled, "PG2 not disabled to enable DC5.\n");
Suketu Shah5aefb232015-04-16 14:22:10 +0530750
Jesse Barnes6ff8ab02015-09-10 08:20:28 -0700751 WARN_ONCE((I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC5),
752 "DC5 already programmed to be enabled.\n");
Imre Deakc9b88462015-12-15 20:10:34 +0200753 assert_rpm_wakelock_held(dev_priv);
Suketu Shah5aefb232015-04-16 14:22:10 +0530754
755 assert_csr_loaded(dev_priv);
756}
757
Imre Deakf62c79b2016-04-20 20:27:57 +0300758void gen9_enable_dc5(struct drm_i915_private *dev_priv)
Suketu Shah5aefb232015-04-16 14:22:10 +0530759{
Suketu Shah5aefb232015-04-16 14:22:10 +0530760 assert_can_enable_dc5(dev_priv);
A.Sunil Kamath6b457d32015-04-16 14:22:09 +0530761
762 DRM_DEBUG_KMS("Enabling DC5\n");
763
Imre Deak13ae3a02015-11-04 19:24:16 +0200764 gen9_set_dc_state(dev_priv, DC_STATE_EN_UPTO_DC5);
Suketu Shahdc174302015-04-17 19:46:16 +0530765}
766
Suketu Shah93c7cb62015-04-16 14:22:13 +0530767static void assert_can_enable_dc6(struct drm_i915_private *dev_priv)
Suketu Shahf75a1982015-04-16 14:22:11 +0530768{
Jesse Barnes6ff8ab02015-09-10 08:20:28 -0700769 WARN_ONCE(I915_READ(UTIL_PIN_CTL) & UTIL_PIN_ENABLE,
770 "Backlight is not disabled.\n");
771 WARN_ONCE((I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC6),
772 "DC6 already programmed to be enabled.\n");
Suketu Shah93c7cb62015-04-16 14:22:13 +0530773
774 assert_csr_loaded(dev_priv);
775}
776
Animesh Manna0a9d2be2015-09-29 11:01:59 +0530777void skl_enable_dc6(struct drm_i915_private *dev_priv)
Suketu Shah93c7cb62015-04-16 14:22:13 +0530778{
Suketu Shah93c7cb62015-04-16 14:22:13 +0530779 assert_can_enable_dc6(dev_priv);
A.Sunil Kamath74b4f372015-04-16 14:22:12 +0530780
781 DRM_DEBUG_KMS("Enabling DC6\n");
782
Imre Deak13ae3a02015-11-04 19:24:16 +0200783 gen9_set_dc_state(dev_priv, DC_STATE_EN_UPTO_DC6);
784
Suketu Shahf75a1982015-04-16 14:22:11 +0530785}
786
Animesh Manna0a9d2be2015-09-29 11:01:59 +0530787void skl_disable_dc6(struct drm_i915_private *dev_priv)
Suketu Shahf75a1982015-04-16 14:22:11 +0530788{
A.Sunil Kamath74b4f372015-04-16 14:22:12 +0530789 DRM_DEBUG_KMS("Disabling DC6\n");
790
Imre Deak13ae3a02015-11-04 19:24:16 +0200791 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
Suketu Shahf75a1982015-04-16 14:22:11 +0530792}
793
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000794static void skl_set_power_well(struct drm_i915_private *dev_priv,
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +0200795 struct i915_power_well *power_well, bool enable)
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000796{
797 uint32_t tmp, fuse_status;
798 uint32_t req_mask, state_mask;
Imre Deak91377262017-07-06 17:40:31 +0300799 bool check_fuse_status = false;
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000800
801 tmp = I915_READ(HSW_PWR_WELL_DRIVER);
802 fuse_status = I915_READ(SKL_FUSE_STATUS);
803
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +0300804 switch (power_well->id) {
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000805 case SKL_DISP_PW_1:
Chris Wilson117c1142016-06-30 15:33:33 +0100806 if (intel_wait_for_register(dev_priv,
807 SKL_FUSE_STATUS,
808 SKL_FUSE_PG0_DIST_STATUS,
809 SKL_FUSE_PG0_DIST_STATUS,
810 1)) {
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000811 DRM_ERROR("PG0 not enabled\n");
812 return;
813 }
814 break;
815 case SKL_DISP_PW_2:
816 if (!(fuse_status & SKL_FUSE_PG1_DIST_STATUS)) {
817 DRM_ERROR("PG1 in disabled state\n");
818 return;
819 }
820 break;
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +0200821 case SKL_DISP_PW_MISC_IO:
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -0700822 case SKL_DISP_PW_DDI_A_E: /* GLK_DISP_PW_DDI_A, CNL_DISP_PW_DDI_A */
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000823 case SKL_DISP_PW_DDI_B:
824 case SKL_DISP_PW_DDI_C:
825 case SKL_DISP_PW_DDI_D:
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -0700826 case GLK_DISP_PW_AUX_A: /* CNL_DISP_PW_AUX_A */
827 case GLK_DISP_PW_AUX_B: /* CNL_DISP_PW_AUX_B */
828 case GLK_DISP_PW_AUX_C: /* CNL_DISP_PW_AUX_C */
829 case CNL_DISP_PW_AUX_D:
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000830 break;
831 default:
Imre Deak438b8dc2017-07-11 23:42:30 +0300832 WARN(1, "Unknown power well %u\n", power_well->id);
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000833 return;
834 }
835
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +0300836 req_mask = SKL_POWER_WELL_REQ(power_well->id);
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +0300837 state_mask = SKL_POWER_WELL_STATE(power_well->id);
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000838
Imre Deak91377262017-07-06 17:40:31 +0300839 if (!enable)
Ville Syrjäläaae8ba82016-02-19 20:47:30 +0200840 skl_power_well_pre_disable(dev_priv, power_well);
841
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000842 if (enable) {
Imre Deak91377262017-07-06 17:40:31 +0300843 I915_WRITE(HSW_PWR_WELL_DRIVER, tmp | req_mask);
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000844
Imre Deak91377262017-07-06 17:40:31 +0300845 DRM_DEBUG_KMS("Enabling %s\n", power_well->name);
846 check_fuse_status = true;
Imre Deak42d93662017-06-29 18:37:01 +0300847
848 gen9_wait_for_power_well_enable(dev_priv, power_well);
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000849 } else {
Imre Deak91377262017-07-06 17:40:31 +0300850 I915_WRITE(HSW_PWR_WELL_DRIVER, tmp & ~req_mask);
851 POSTING_READ(HSW_PWR_WELL_DRIVER);
852 DRM_DEBUG_KMS("Disabling %s\n", power_well->name);
Imre Deakc6782b72016-04-05 13:26:05 +0300853
Imre Deak42d93662017-06-29 18:37:01 +0300854 gen9_wait_for_power_well_disable(dev_priv, power_well);
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000855 }
856
857 if (check_fuse_status) {
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +0300858 if (power_well->id == SKL_DISP_PW_1) {
Chris Wilson8b00f552016-06-30 15:33:34 +0100859 if (intel_wait_for_register(dev_priv,
860 SKL_FUSE_STATUS,
861 SKL_FUSE_PG1_DIST_STATUS,
862 SKL_FUSE_PG1_DIST_STATUS,
863 1))
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000864 DRM_ERROR("PG1 distributing status timeout\n");
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +0300865 } else if (power_well->id == SKL_DISP_PW_2) {
Chris Wilson8b00f552016-06-30 15:33:34 +0100866 if (intel_wait_for_register(dev_priv,
867 SKL_FUSE_STATUS,
868 SKL_FUSE_PG2_DIST_STATUS,
869 SKL_FUSE_PG2_DIST_STATUS,
870 1))
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000871 DRM_ERROR("PG2 distributing status timeout\n");
872 }
873 }
Damien Lespiaud14c0342015-03-06 18:50:51 +0000874
Imre Deak91377262017-07-06 17:40:31 +0300875 if (enable)
Damien Lespiaud14c0342015-03-06 18:50:51 +0000876 skl_power_well_post_enable(dev_priv, power_well);
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000877}
878
Daniel Vetter9c065a72014-09-30 10:56:38 +0200879static void hsw_power_well_sync_hw(struct drm_i915_private *dev_priv,
880 struct i915_power_well *power_well)
881{
Imre Deak16e84912017-02-17 17:39:45 +0200882 /* Take over the request bit if set by BIOS. */
883 if (I915_READ(HSW_PWR_WELL_BIOS) & HSW_PWR_WELL_ENABLE_REQUEST) {
884 if (!(I915_READ(HSW_PWR_WELL_DRIVER) &
885 HSW_PWR_WELL_ENABLE_REQUEST))
886 I915_WRITE(HSW_PWR_WELL_DRIVER,
887 HSW_PWR_WELL_ENABLE_REQUEST);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200888 I915_WRITE(HSW_PWR_WELL_BIOS, 0);
Imre Deak16e84912017-02-17 17:39:45 +0200889 }
Daniel Vetter9c065a72014-09-30 10:56:38 +0200890}
891
892static void hsw_power_well_enable(struct drm_i915_private *dev_priv,
893 struct i915_power_well *power_well)
894{
895 hsw_set_power_well(dev_priv, power_well, true);
896}
897
898static void hsw_power_well_disable(struct drm_i915_private *dev_priv,
899 struct i915_power_well *power_well)
900{
901 hsw_set_power_well(dev_priv, power_well, false);
902}
903
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000904static bool skl_power_well_enabled(struct drm_i915_private *dev_priv,
905 struct i915_power_well *power_well)
906{
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +0300907 uint32_t mask = SKL_POWER_WELL_REQ(power_well->id) |
908 SKL_POWER_WELL_STATE(power_well->id);
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000909
910 return (I915_READ(HSW_PWR_WELL_DRIVER) & mask) == mask;
911}
912
913static void skl_power_well_sync_hw(struct drm_i915_private *dev_priv,
914 struct i915_power_well *power_well)
915{
Imre Deak14544e12017-02-17 17:39:44 +0200916 uint32_t mask = SKL_POWER_WELL_REQ(power_well->id);
917 uint32_t bios_req = I915_READ(HSW_PWR_WELL_BIOS);
918
Imre Deak16e84912017-02-17 17:39:45 +0200919 /* Take over the request bit if set by BIOS. */
Imre Deak14544e12017-02-17 17:39:44 +0200920 if (bios_req & mask) {
Imre Deak16e84912017-02-17 17:39:45 +0200921 uint32_t drv_req = I915_READ(HSW_PWR_WELL_DRIVER);
922
923 if (!(drv_req & mask))
924 I915_WRITE(HSW_PWR_WELL_DRIVER, drv_req | mask);
Imre Deak14544e12017-02-17 17:39:44 +0200925 I915_WRITE(HSW_PWR_WELL_BIOS, bios_req & ~mask);
926 }
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000927}
928
929static void skl_power_well_enable(struct drm_i915_private *dev_priv,
930 struct i915_power_well *power_well)
931{
932 skl_set_power_well(dev_priv, power_well, true);
933}
934
935static void skl_power_well_disable(struct drm_i915_private *dev_priv,
936 struct i915_power_well *power_well)
937{
938 skl_set_power_well(dev_priv, power_well, false);
939}
940
Imre Deak9c8d0b82016-06-13 16:44:34 +0300941static void bxt_dpio_cmn_power_well_enable(struct drm_i915_private *dev_priv,
942 struct i915_power_well *power_well)
943{
Imre Deakb5565a22017-07-06 17:40:29 +0300944 bxt_ddi_phy_init(dev_priv, power_well->bxt.phy);
Imre Deak9c8d0b82016-06-13 16:44:34 +0300945}
946
947static void bxt_dpio_cmn_power_well_disable(struct drm_i915_private *dev_priv,
948 struct i915_power_well *power_well)
949{
Imre Deakb5565a22017-07-06 17:40:29 +0300950 bxt_ddi_phy_uninit(dev_priv, power_well->bxt.phy);
Imre Deak9c8d0b82016-06-13 16:44:34 +0300951}
952
953static bool bxt_dpio_cmn_power_well_enabled(struct drm_i915_private *dev_priv,
954 struct i915_power_well *power_well)
955{
Imre Deakb5565a22017-07-06 17:40:29 +0300956 return bxt_ddi_phy_is_enabled(dev_priv, power_well->bxt.phy);
Imre Deak9c8d0b82016-06-13 16:44:34 +0300957}
958
Imre Deak9c8d0b82016-06-13 16:44:34 +0300959static void bxt_verify_ddi_phy_power_wells(struct drm_i915_private *dev_priv)
960{
961 struct i915_power_well *power_well;
962
963 power_well = lookup_power_well(dev_priv, BXT_DPIO_CMN_A);
964 if (power_well->count > 0)
Imre Deakb5565a22017-07-06 17:40:29 +0300965 bxt_ddi_phy_verify_state(dev_priv, power_well->bxt.phy);
Imre Deak9c8d0b82016-06-13 16:44:34 +0300966
967 power_well = lookup_power_well(dev_priv, BXT_DPIO_CMN_BC);
968 if (power_well->count > 0)
Imre Deakb5565a22017-07-06 17:40:29 +0300969 bxt_ddi_phy_verify_state(dev_priv, power_well->bxt.phy);
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +0200970
971 if (IS_GEMINILAKE(dev_priv)) {
972 power_well = lookup_power_well(dev_priv, GLK_DPIO_CMN_C);
973 if (power_well->count > 0)
Imre Deakb5565a22017-07-06 17:40:29 +0300974 bxt_ddi_phy_verify_state(dev_priv, power_well->bxt.phy);
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +0200975 }
Imre Deak9c8d0b82016-06-13 16:44:34 +0300976}
977
Patrik Jakobsson9f836f92015-11-16 16:20:01 +0100978static bool gen9_dc_off_power_well_enabled(struct drm_i915_private *dev_priv,
979 struct i915_power_well *power_well)
980{
981 return (I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC5_DC6_MASK) == 0;
982}
983
Ville Syrjälä18a80672016-05-16 16:59:40 +0300984static void gen9_assert_dbuf_enabled(struct drm_i915_private *dev_priv)
985{
986 u32 tmp = I915_READ(DBUF_CTL);
987
988 WARN((tmp & (DBUF_POWER_STATE | DBUF_POWER_REQUEST)) !=
989 (DBUF_POWER_STATE | DBUF_POWER_REQUEST),
990 "Unexpected DBuf power power state (0x%08x)\n", tmp);
991}
992
Patrik Jakobsson9f836f92015-11-16 16:20:01 +0100993static void gen9_dc_off_power_well_enable(struct drm_i915_private *dev_priv,
994 struct i915_power_well *power_well)
995{
Ville Syrjälä49cd97a2017-02-07 20:33:45 +0200996 struct intel_cdclk_state cdclk_state = {};
997
Imre Deak5b773eb2016-02-29 22:49:05 +0200998 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
Imre Deakadc7f042016-04-04 17:27:10 +0300999
Ville Syrjälä49cd97a2017-02-07 20:33:45 +02001000 dev_priv->display.get_cdclk(dev_priv, &cdclk_state);
1001 WARN_ON(!intel_cdclk_state_compare(&dev_priv->cdclk.hw, &cdclk_state));
Ville Syrjälä342be922016-05-13 23:41:39 +03001002
Ville Syrjälä18a80672016-05-16 16:59:40 +03001003 gen9_assert_dbuf_enabled(dev_priv);
1004
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02001005 if (IS_GEN9_LP(dev_priv))
Imre Deak9c8d0b82016-06-13 16:44:34 +03001006 bxt_verify_ddi_phy_power_wells(dev_priv);
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01001007}
1008
1009static void gen9_dc_off_power_well_disable(struct drm_i915_private *dev_priv,
1010 struct i915_power_well *power_well)
1011{
Imre Deakf74ed082016-04-18 14:48:21 +03001012 if (!dev_priv->csr.dmc_payload)
1013 return;
1014
Imre Deaka37baf32016-02-29 22:49:03 +02001015 if (dev_priv->csr.allowed_dc_mask & DC_STATE_EN_UPTO_DC6)
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01001016 skl_enable_dc6(dev_priv);
Imre Deaka37baf32016-02-29 22:49:03 +02001017 else if (dev_priv->csr.allowed_dc_mask & DC_STATE_EN_UPTO_DC5)
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01001018 gen9_enable_dc5(dev_priv);
1019}
1020
Imre Deak3c1b38e2017-02-17 17:39:42 +02001021static void i9xx_power_well_sync_hw_noop(struct drm_i915_private *dev_priv,
1022 struct i915_power_well *power_well)
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01001023{
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01001024}
1025
Daniel Vetter9c065a72014-09-30 10:56:38 +02001026static void i9xx_always_on_power_well_noop(struct drm_i915_private *dev_priv,
1027 struct i915_power_well *power_well)
1028{
1029}
1030
1031static bool i9xx_always_on_power_well_enabled(struct drm_i915_private *dev_priv,
1032 struct i915_power_well *power_well)
1033{
1034 return true;
1035}
1036
Ville Syrjälä2ee0da12017-06-01 17:36:16 +03001037static void i830_pipes_power_well_enable(struct drm_i915_private *dev_priv,
1038 struct i915_power_well *power_well)
1039{
1040 if ((I915_READ(PIPECONF(PIPE_A)) & PIPECONF_ENABLE) == 0)
1041 i830_enable_pipe(dev_priv, PIPE_A);
1042 if ((I915_READ(PIPECONF(PIPE_B)) & PIPECONF_ENABLE) == 0)
1043 i830_enable_pipe(dev_priv, PIPE_B);
1044}
1045
1046static void i830_pipes_power_well_disable(struct drm_i915_private *dev_priv,
1047 struct i915_power_well *power_well)
1048{
1049 i830_disable_pipe(dev_priv, PIPE_B);
1050 i830_disable_pipe(dev_priv, PIPE_A);
1051}
1052
1053static bool i830_pipes_power_well_enabled(struct drm_i915_private *dev_priv,
1054 struct i915_power_well *power_well)
1055{
1056 return I915_READ(PIPECONF(PIPE_A)) & PIPECONF_ENABLE &&
1057 I915_READ(PIPECONF(PIPE_B)) & PIPECONF_ENABLE;
1058}
1059
1060static void i830_pipes_power_well_sync_hw(struct drm_i915_private *dev_priv,
1061 struct i915_power_well *power_well)
1062{
1063 if (power_well->count > 0)
1064 i830_pipes_power_well_enable(dev_priv, power_well);
1065 else
1066 i830_pipes_power_well_disable(dev_priv, power_well);
1067}
1068
Daniel Vetter9c065a72014-09-30 10:56:38 +02001069static void vlv_set_power_well(struct drm_i915_private *dev_priv,
1070 struct i915_power_well *power_well, bool enable)
1071{
Imre Deak438b8dc2017-07-11 23:42:30 +03001072 enum i915_power_well_id power_well_id = power_well->id;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001073 u32 mask;
1074 u32 state;
1075 u32 ctrl;
1076
1077 mask = PUNIT_PWRGT_MASK(power_well_id);
1078 state = enable ? PUNIT_PWRGT_PWR_ON(power_well_id) :
1079 PUNIT_PWRGT_PWR_GATE(power_well_id);
1080
1081 mutex_lock(&dev_priv->rps.hw_lock);
1082
1083#define COND \
1084 ((vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_STATUS) & mask) == state)
1085
1086 if (COND)
1087 goto out;
1088
1089 ctrl = vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_CTRL);
1090 ctrl &= ~mask;
1091 ctrl |= state;
1092 vlv_punit_write(dev_priv, PUNIT_REG_PWRGT_CTRL, ctrl);
1093
1094 if (wait_for(COND, 100))
Masanari Iida7e35ab82015-05-10 01:00:23 +09001095 DRM_ERROR("timeout setting power well state %08x (%08x)\n",
Daniel Vetter9c065a72014-09-30 10:56:38 +02001096 state,
1097 vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_CTRL));
1098
1099#undef COND
1100
1101out:
1102 mutex_unlock(&dev_priv->rps.hw_lock);
1103}
1104
Daniel Vetter9c065a72014-09-30 10:56:38 +02001105static void vlv_power_well_enable(struct drm_i915_private *dev_priv,
1106 struct i915_power_well *power_well)
1107{
1108 vlv_set_power_well(dev_priv, power_well, true);
1109}
1110
1111static void vlv_power_well_disable(struct drm_i915_private *dev_priv,
1112 struct i915_power_well *power_well)
1113{
1114 vlv_set_power_well(dev_priv, power_well, false);
1115}
1116
1117static bool vlv_power_well_enabled(struct drm_i915_private *dev_priv,
1118 struct i915_power_well *power_well)
1119{
Imre Deak438b8dc2017-07-11 23:42:30 +03001120 enum i915_power_well_id power_well_id = power_well->id;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001121 bool enabled = false;
1122 u32 mask;
1123 u32 state;
1124 u32 ctrl;
1125
1126 mask = PUNIT_PWRGT_MASK(power_well_id);
1127 ctrl = PUNIT_PWRGT_PWR_ON(power_well_id);
1128
1129 mutex_lock(&dev_priv->rps.hw_lock);
1130
1131 state = vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_STATUS) & mask;
1132 /*
1133 * We only ever set the power-on and power-gate states, anything
1134 * else is unexpected.
1135 */
1136 WARN_ON(state != PUNIT_PWRGT_PWR_ON(power_well_id) &&
1137 state != PUNIT_PWRGT_PWR_GATE(power_well_id));
1138 if (state == ctrl)
1139 enabled = true;
1140
1141 /*
1142 * A transient state at this point would mean some unexpected party
1143 * is poking at the power controls too.
1144 */
1145 ctrl = vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_CTRL) & mask;
1146 WARN_ON(ctrl != state);
1147
1148 mutex_unlock(&dev_priv->rps.hw_lock);
1149
1150 return enabled;
1151}
1152
Ville Syrjälä766078d2016-04-11 16:56:30 +03001153static void vlv_init_display_clock_gating(struct drm_i915_private *dev_priv)
1154{
Hans de Goede721d4842016-12-02 15:29:04 +01001155 u32 val;
1156
1157 /*
1158 * On driver load, a pipe may be active and driving a DSI display.
1159 * Preserve DPOUNIT_CLOCK_GATE_DISABLE to avoid the pipe getting stuck
1160 * (and never recovering) in this case. intel_dsi_post_disable() will
1161 * clear it when we turn off the display.
1162 */
1163 val = I915_READ(DSPCLK_GATE_D);
1164 val &= DPOUNIT_CLOCK_GATE_DISABLE;
1165 val |= VRHUNIT_CLOCK_GATE_DISABLE;
1166 I915_WRITE(DSPCLK_GATE_D, val);
Ville Syrjälä766078d2016-04-11 16:56:30 +03001167
1168 /*
1169 * Disable trickle feed and enable pnd deadline calculation
1170 */
1171 I915_WRITE(MI_ARB_VLV, MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE);
1172 I915_WRITE(CBR1_VLV, 0);
Ville Syrjälä19ab4ed2016-04-27 17:43:22 +03001173
1174 WARN_ON(dev_priv->rawclk_freq == 0);
1175
1176 I915_WRITE(RAWCLK_FREQ_VLV,
1177 DIV_ROUND_CLOSEST(dev_priv->rawclk_freq, 1000));
Ville Syrjälä766078d2016-04-11 16:56:30 +03001178}
1179
Ville Syrjälä2be7d542015-06-29 15:25:51 +03001180static void vlv_display_power_well_init(struct drm_i915_private *dev_priv)
Daniel Vetter9c065a72014-09-30 10:56:38 +02001181{
Lyude9504a892016-06-21 17:03:42 -04001182 struct intel_encoder *encoder;
Ville Syrjälä5a8fbb72015-06-29 15:25:53 +03001183 enum pipe pipe;
1184
1185 /*
1186 * Enable the CRI clock source so we can get at the
1187 * display and the reference clock for VGA
1188 * hotplug / manual detection. Supposedly DSI also
1189 * needs the ref clock up and running.
1190 *
1191 * CHV DPLL B/C have some issues if VGA mode is enabled.
1192 */
Tvrtko Ursulin801388c2016-11-16 08:55:44 +00001193 for_each_pipe(dev_priv, pipe) {
Ville Syrjälä5a8fbb72015-06-29 15:25:53 +03001194 u32 val = I915_READ(DPLL(pipe));
1195
1196 val |= DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
1197 if (pipe != PIPE_A)
1198 val |= DPLL_INTEGRATED_CRI_CLK_VLV;
1199
1200 I915_WRITE(DPLL(pipe), val);
1201 }
Daniel Vetter9c065a72014-09-30 10:56:38 +02001202
Ville Syrjälä766078d2016-04-11 16:56:30 +03001203 vlv_init_display_clock_gating(dev_priv);
1204
Daniel Vetter9c065a72014-09-30 10:56:38 +02001205 spin_lock_irq(&dev_priv->irq_lock);
1206 valleyview_enable_display_irqs(dev_priv);
1207 spin_unlock_irq(&dev_priv->irq_lock);
1208
1209 /*
1210 * During driver initialization/resume we can avoid restoring the
1211 * part of the HW/SW state that will be inited anyway explicitly.
1212 */
1213 if (dev_priv->power_domains.initializing)
1214 return;
1215
Daniel Vetterb9632912014-09-30 10:56:44 +02001216 intel_hpd_init(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001217
Lyude9504a892016-06-21 17:03:42 -04001218 /* Re-enable the ADPA, if we have one */
1219 for_each_intel_encoder(&dev_priv->drm, encoder) {
1220 if (encoder->type == INTEL_OUTPUT_ANALOG)
1221 intel_crt_reset(&encoder->base);
1222 }
1223
Tvrtko Ursulin29b74b72016-11-16 08:55:39 +00001224 i915_redisable_vga_power_on(dev_priv);
Imre Deak8090ba82016-08-10 14:07:33 +03001225
1226 intel_pps_unlock_regs_wa(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001227}
1228
Ville Syrjälä2be7d542015-06-29 15:25:51 +03001229static void vlv_display_power_well_deinit(struct drm_i915_private *dev_priv)
1230{
1231 spin_lock_irq(&dev_priv->irq_lock);
1232 valleyview_disable_display_irqs(dev_priv);
1233 spin_unlock_irq(&dev_priv->irq_lock);
1234
Ville Syrjälä2230fde2016-02-19 18:41:52 +02001235 /* make sure we're done processing display irqs */
Chris Wilson91c8a322016-07-05 10:40:23 +01001236 synchronize_irq(dev_priv->drm.irq);
Ville Syrjälä2230fde2016-02-19 18:41:52 +02001237
Imre Deak78597992016-06-16 16:37:20 +03001238 intel_power_sequencer_reset(dev_priv);
Lyude19625e82016-06-21 17:03:44 -04001239
Lyudeb64b5402016-10-26 12:36:09 -04001240 /* Prevent us from re-enabling polling on accident in late suspend */
1241 if (!dev_priv->drm.dev->power.is_suspended)
1242 intel_hpd_poll_init(dev_priv);
Ville Syrjälä2be7d542015-06-29 15:25:51 +03001243}
1244
1245static void vlv_display_power_well_enable(struct drm_i915_private *dev_priv,
1246 struct i915_power_well *power_well)
1247{
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001248 WARN_ON_ONCE(power_well->id != PUNIT_POWER_WELL_DISP2D);
Ville Syrjälä2be7d542015-06-29 15:25:51 +03001249
1250 vlv_set_power_well(dev_priv, power_well, true);
1251
1252 vlv_display_power_well_init(dev_priv);
1253}
1254
Daniel Vetter9c065a72014-09-30 10:56:38 +02001255static void vlv_display_power_well_disable(struct drm_i915_private *dev_priv,
1256 struct i915_power_well *power_well)
1257{
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001258 WARN_ON_ONCE(power_well->id != PUNIT_POWER_WELL_DISP2D);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001259
Ville Syrjälä2be7d542015-06-29 15:25:51 +03001260 vlv_display_power_well_deinit(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001261
1262 vlv_set_power_well(dev_priv, power_well, false);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001263}
1264
1265static void vlv_dpio_cmn_power_well_enable(struct drm_i915_private *dev_priv,
1266 struct i915_power_well *power_well)
1267{
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001268 WARN_ON_ONCE(power_well->id != PUNIT_POWER_WELL_DPIO_CMN_BC);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001269
Ville Syrjälä5a8fbb72015-06-29 15:25:53 +03001270 /* since ref/cri clock was enabled */
Daniel Vetter9c065a72014-09-30 10:56:38 +02001271 udelay(1); /* >10ns for cmnreset, >0ns for sidereset */
1272
1273 vlv_set_power_well(dev_priv, power_well, true);
1274
1275 /*
1276 * From VLV2A0_DP_eDP_DPIO_driver_vbios_notes_10.docx -
1277 * 6. De-assert cmn_reset/side_reset. Same as VLV X0.
1278 * a. GUnit 0x2110 bit[0] set to 1 (def 0)
1279 * b. The other bits such as sfr settings / modesel may all
1280 * be set to 0.
1281 *
1282 * This should only be done on init and resume from S3 with
1283 * both PLLs disabled, or we risk losing DPIO and PLL
1284 * synchronization.
1285 */
1286 I915_WRITE(DPIO_CTL, I915_READ(DPIO_CTL) | DPIO_CMNRST);
1287}
1288
1289static void vlv_dpio_cmn_power_well_disable(struct drm_i915_private *dev_priv,
1290 struct i915_power_well *power_well)
1291{
1292 enum pipe pipe;
1293
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001294 WARN_ON_ONCE(power_well->id != PUNIT_POWER_WELL_DPIO_CMN_BC);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001295
1296 for_each_pipe(dev_priv, pipe)
1297 assert_pll_disabled(dev_priv, pipe);
1298
1299 /* Assert common reset */
1300 I915_WRITE(DPIO_CTL, I915_READ(DPIO_CTL) & ~DPIO_CMNRST);
1301
1302 vlv_set_power_well(dev_priv, power_well, false);
1303}
1304
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001305#define POWER_DOMAIN_MASK (GENMASK_ULL(POWER_DOMAIN_NUM - 1, 0))
Ville Syrjälä30142272015-07-08 23:46:01 +03001306
Imre Deak438b8dc2017-07-11 23:42:30 +03001307static struct i915_power_well *
1308lookup_power_well(struct drm_i915_private *dev_priv,
1309 enum i915_power_well_id power_well_id)
Ville Syrjälä30142272015-07-08 23:46:01 +03001310{
1311 struct i915_power_domains *power_domains = &dev_priv->power_domains;
Ville Syrjälä30142272015-07-08 23:46:01 +03001312 int i;
1313
Imre Deakfc17f222015-11-04 19:24:11 +02001314 for (i = 0; i < power_domains->power_well_count; i++) {
1315 struct i915_power_well *power_well;
1316
1317 power_well = &power_domains->power_wells[i];
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001318 if (power_well->id == power_well_id)
Ville Syrjälä30142272015-07-08 23:46:01 +03001319 return power_well;
1320 }
1321
1322 return NULL;
1323}
1324
1325#define BITS_SET(val, bits) (((val) & (bits)) == (bits))
1326
1327static void assert_chv_phy_status(struct drm_i915_private *dev_priv)
1328{
1329 struct i915_power_well *cmn_bc =
1330 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_BC);
1331 struct i915_power_well *cmn_d =
1332 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_D);
1333 u32 phy_control = dev_priv->chv_phy_control;
1334 u32 phy_status = 0;
Ville Syrjälä3be60de2015-09-08 18:05:45 +03001335 u32 phy_status_mask = 0xffffffff;
Ville Syrjälä30142272015-07-08 23:46:01 +03001336
Ville Syrjälä3be60de2015-09-08 18:05:45 +03001337 /*
1338 * The BIOS can leave the PHY is some weird state
1339 * where it doesn't fully power down some parts.
1340 * Disable the asserts until the PHY has been fully
1341 * reset (ie. the power well has been disabled at
1342 * least once).
1343 */
1344 if (!dev_priv->chv_phy_assert[DPIO_PHY0])
1345 phy_status_mask &= ~(PHY_STATUS_CMN_LDO(DPIO_PHY0, DPIO_CH0) |
1346 PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH0, 0) |
1347 PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH0, 1) |
1348 PHY_STATUS_CMN_LDO(DPIO_PHY0, DPIO_CH1) |
1349 PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH1, 0) |
1350 PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH1, 1));
1351
1352 if (!dev_priv->chv_phy_assert[DPIO_PHY1])
1353 phy_status_mask &= ~(PHY_STATUS_CMN_LDO(DPIO_PHY1, DPIO_CH0) |
1354 PHY_STATUS_SPLINE_LDO(DPIO_PHY1, DPIO_CH0, 0) |
1355 PHY_STATUS_SPLINE_LDO(DPIO_PHY1, DPIO_CH0, 1));
1356
Ville Syrjälä30142272015-07-08 23:46:01 +03001357 if (cmn_bc->ops->is_enabled(dev_priv, cmn_bc)) {
1358 phy_status |= PHY_POWERGOOD(DPIO_PHY0);
1359
1360 /* this assumes override is only used to enable lanes */
1361 if ((phy_control & PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY0, DPIO_CH0)) == 0)
1362 phy_control |= PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH0);
1363
1364 if ((phy_control & PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY0, DPIO_CH1)) == 0)
1365 phy_control |= PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH1);
1366
1367 /* CL1 is on whenever anything is on in either channel */
1368 if (BITS_SET(phy_control,
1369 PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH0) |
1370 PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH1)))
1371 phy_status |= PHY_STATUS_CMN_LDO(DPIO_PHY0, DPIO_CH0);
1372
1373 /*
1374 * The DPLLB check accounts for the pipe B + port A usage
1375 * with CL2 powered up but all the lanes in the second channel
1376 * powered down.
1377 */
1378 if (BITS_SET(phy_control,
1379 PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH1)) &&
1380 (I915_READ(DPLL(PIPE_B)) & DPLL_VCO_ENABLE) == 0)
1381 phy_status |= PHY_STATUS_CMN_LDO(DPIO_PHY0, DPIO_CH1);
1382
1383 if (BITS_SET(phy_control,
1384 PHY_CH_POWER_DOWN_OVRD(0x3, DPIO_PHY0, DPIO_CH0)))
1385 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH0, 0);
1386 if (BITS_SET(phy_control,
1387 PHY_CH_POWER_DOWN_OVRD(0xc, DPIO_PHY0, DPIO_CH0)))
1388 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH0, 1);
1389
1390 if (BITS_SET(phy_control,
1391 PHY_CH_POWER_DOWN_OVRD(0x3, DPIO_PHY0, DPIO_CH1)))
1392 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH1, 0);
1393 if (BITS_SET(phy_control,
1394 PHY_CH_POWER_DOWN_OVRD(0xc, DPIO_PHY0, DPIO_CH1)))
1395 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH1, 1);
1396 }
1397
1398 if (cmn_d->ops->is_enabled(dev_priv, cmn_d)) {
1399 phy_status |= PHY_POWERGOOD(DPIO_PHY1);
1400
1401 /* this assumes override is only used to enable lanes */
1402 if ((phy_control & PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY1, DPIO_CH0)) == 0)
1403 phy_control |= PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY1, DPIO_CH0);
1404
1405 if (BITS_SET(phy_control,
1406 PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY1, DPIO_CH0)))
1407 phy_status |= PHY_STATUS_CMN_LDO(DPIO_PHY1, DPIO_CH0);
1408
1409 if (BITS_SET(phy_control,
1410 PHY_CH_POWER_DOWN_OVRD(0x3, DPIO_PHY1, DPIO_CH0)))
1411 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY1, DPIO_CH0, 0);
1412 if (BITS_SET(phy_control,
1413 PHY_CH_POWER_DOWN_OVRD(0xc, DPIO_PHY1, DPIO_CH0)))
1414 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY1, DPIO_CH0, 1);
1415 }
1416
Ville Syrjälä3be60de2015-09-08 18:05:45 +03001417 phy_status &= phy_status_mask;
1418
Ville Syrjälä30142272015-07-08 23:46:01 +03001419 /*
1420 * The PHY may be busy with some initial calibration and whatnot,
1421 * so the power state can take a while to actually change.
1422 */
Chris Wilson919fcd52016-06-30 15:33:35 +01001423 if (intel_wait_for_register(dev_priv,
1424 DISPLAY_PHY_STATUS,
1425 phy_status_mask,
1426 phy_status,
1427 10))
1428 DRM_ERROR("Unexpected PHY_STATUS 0x%08x, expected 0x%08x (PHY_CONTROL=0x%08x)\n",
1429 I915_READ(DISPLAY_PHY_STATUS) & phy_status_mask,
1430 phy_status, dev_priv->chv_phy_control);
Ville Syrjälä30142272015-07-08 23:46:01 +03001431}
1432
1433#undef BITS_SET
1434
Daniel Vetter9c065a72014-09-30 10:56:38 +02001435static void chv_dpio_cmn_power_well_enable(struct drm_i915_private *dev_priv,
1436 struct i915_power_well *power_well)
1437{
1438 enum dpio_phy phy;
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001439 enum pipe pipe;
1440 uint32_t tmp;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001441
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001442 WARN_ON_ONCE(power_well->id != PUNIT_POWER_WELL_DPIO_CMN_BC &&
1443 power_well->id != PUNIT_POWER_WELL_DPIO_CMN_D);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001444
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001445 if (power_well->id == PUNIT_POWER_WELL_DPIO_CMN_BC) {
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001446 pipe = PIPE_A;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001447 phy = DPIO_PHY0;
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001448 } else {
1449 pipe = PIPE_C;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001450 phy = DPIO_PHY1;
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001451 }
Ville Syrjälä5a8fbb72015-06-29 15:25:53 +03001452
1453 /* since ref/cri clock was enabled */
Daniel Vetter9c065a72014-09-30 10:56:38 +02001454 udelay(1); /* >10ns for cmnreset, >0ns for sidereset */
1455 vlv_set_power_well(dev_priv, power_well, true);
1456
1457 /* Poll for phypwrgood signal */
Chris Wilsonffebb832016-06-30 15:33:36 +01001458 if (intel_wait_for_register(dev_priv,
1459 DISPLAY_PHY_STATUS,
1460 PHY_POWERGOOD(phy),
1461 PHY_POWERGOOD(phy),
1462 1))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001463 DRM_ERROR("Display PHY %d is not power up\n", phy);
1464
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001465 mutex_lock(&dev_priv->sb_lock);
1466
1467 /* Enable dynamic power down */
1468 tmp = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW28);
Ville Syrjäläee279212015-07-08 23:45:57 +03001469 tmp |= DPIO_DYNPWRDOWNEN_CH0 | DPIO_CL1POWERDOWNEN |
1470 DPIO_SUS_CLK_CONFIG_GATE_CLKREQ;
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001471 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW28, tmp);
1472
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001473 if (power_well->id == PUNIT_POWER_WELL_DPIO_CMN_BC) {
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001474 tmp = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW6_CH1);
1475 tmp |= DPIO_DYNPWRDOWNEN_CH1;
1476 vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW6_CH1, tmp);
Ville Syrjälä3e288782015-07-08 23:45:58 +03001477 } else {
1478 /*
1479 * Force the non-existing CL2 off. BXT does this
1480 * too, so maybe it saves some power even though
1481 * CL2 doesn't exist?
1482 */
1483 tmp = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW30);
1484 tmp |= DPIO_CL2_LDOFUSE_PWRENB;
1485 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW30, tmp);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001486 }
1487
1488 mutex_unlock(&dev_priv->sb_lock);
1489
Ville Syrjälä70722462015-04-10 18:21:28 +03001490 dev_priv->chv_phy_control |= PHY_COM_LANE_RESET_DEASSERT(phy);
1491 I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001492
1493 DRM_DEBUG_KMS("Enabled DPIO PHY%d (PHY_CONTROL=0x%08x)\n",
1494 phy, dev_priv->chv_phy_control);
Ville Syrjälä30142272015-07-08 23:46:01 +03001495
1496 assert_chv_phy_status(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001497}
1498
1499static void chv_dpio_cmn_power_well_disable(struct drm_i915_private *dev_priv,
1500 struct i915_power_well *power_well)
1501{
1502 enum dpio_phy phy;
1503
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001504 WARN_ON_ONCE(power_well->id != PUNIT_POWER_WELL_DPIO_CMN_BC &&
1505 power_well->id != PUNIT_POWER_WELL_DPIO_CMN_D);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001506
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001507 if (power_well->id == PUNIT_POWER_WELL_DPIO_CMN_BC) {
Daniel Vetter9c065a72014-09-30 10:56:38 +02001508 phy = DPIO_PHY0;
1509 assert_pll_disabled(dev_priv, PIPE_A);
1510 assert_pll_disabled(dev_priv, PIPE_B);
1511 } else {
1512 phy = DPIO_PHY1;
1513 assert_pll_disabled(dev_priv, PIPE_C);
1514 }
1515
Ville Syrjälä70722462015-04-10 18:21:28 +03001516 dev_priv->chv_phy_control &= ~PHY_COM_LANE_RESET_DEASSERT(phy);
1517 I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001518
1519 vlv_set_power_well(dev_priv, power_well, false);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001520
1521 DRM_DEBUG_KMS("Disabled DPIO PHY%d (PHY_CONTROL=0x%08x)\n",
1522 phy, dev_priv->chv_phy_control);
Ville Syrjälä30142272015-07-08 23:46:01 +03001523
Ville Syrjälä3be60de2015-09-08 18:05:45 +03001524 /* PHY is fully reset now, so we can enable the PHY state asserts */
1525 dev_priv->chv_phy_assert[phy] = true;
1526
Ville Syrjälä30142272015-07-08 23:46:01 +03001527 assert_chv_phy_status(dev_priv);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001528}
1529
Ville Syrjälä6669e392015-07-08 23:46:00 +03001530static void assert_chv_phy_powergate(struct drm_i915_private *dev_priv, enum dpio_phy phy,
1531 enum dpio_channel ch, bool override, unsigned int mask)
1532{
1533 enum pipe pipe = phy == DPIO_PHY0 ? PIPE_A : PIPE_C;
1534 u32 reg, val, expected, actual;
1535
Ville Syrjälä3be60de2015-09-08 18:05:45 +03001536 /*
1537 * The BIOS can leave the PHY is some weird state
1538 * where it doesn't fully power down some parts.
1539 * Disable the asserts until the PHY has been fully
1540 * reset (ie. the power well has been disabled at
1541 * least once).
1542 */
1543 if (!dev_priv->chv_phy_assert[phy])
1544 return;
1545
Ville Syrjälä6669e392015-07-08 23:46:00 +03001546 if (ch == DPIO_CH0)
1547 reg = _CHV_CMN_DW0_CH0;
1548 else
1549 reg = _CHV_CMN_DW6_CH1;
1550
1551 mutex_lock(&dev_priv->sb_lock);
1552 val = vlv_dpio_read(dev_priv, pipe, reg);
1553 mutex_unlock(&dev_priv->sb_lock);
1554
1555 /*
1556 * This assumes !override is only used when the port is disabled.
1557 * All lanes should power down even without the override when
1558 * the port is disabled.
1559 */
1560 if (!override || mask == 0xf) {
1561 expected = DPIO_ALLDL_POWERDOWN | DPIO_ANYDL_POWERDOWN;
1562 /*
1563 * If CH1 common lane is not active anymore
1564 * (eg. for pipe B DPLL) the entire channel will
1565 * shut down, which causes the common lane registers
1566 * to read as 0. That means we can't actually check
1567 * the lane power down status bits, but as the entire
1568 * register reads as 0 it's a good indication that the
1569 * channel is indeed entirely powered down.
1570 */
1571 if (ch == DPIO_CH1 && val == 0)
1572 expected = 0;
1573 } else if (mask != 0x0) {
1574 expected = DPIO_ANYDL_POWERDOWN;
1575 } else {
1576 expected = 0;
1577 }
1578
1579 if (ch == DPIO_CH0)
1580 actual = val >> DPIO_ANYDL_POWERDOWN_SHIFT_CH0;
1581 else
1582 actual = val >> DPIO_ANYDL_POWERDOWN_SHIFT_CH1;
1583 actual &= DPIO_ALLDL_POWERDOWN | DPIO_ANYDL_POWERDOWN;
1584
1585 WARN(actual != expected,
1586 "Unexpected DPIO lane power down: all %d, any %d. Expected: all %d, any %d. (0x%x = 0x%08x)\n",
1587 !!(actual & DPIO_ALLDL_POWERDOWN), !!(actual & DPIO_ANYDL_POWERDOWN),
1588 !!(expected & DPIO_ALLDL_POWERDOWN), !!(expected & DPIO_ANYDL_POWERDOWN),
1589 reg, val);
1590}
1591
Ville Syrjäläb0b33842015-07-08 23:45:55 +03001592bool chv_phy_powergate_ch(struct drm_i915_private *dev_priv, enum dpio_phy phy,
1593 enum dpio_channel ch, bool override)
1594{
1595 struct i915_power_domains *power_domains = &dev_priv->power_domains;
1596 bool was_override;
1597
1598 mutex_lock(&power_domains->lock);
1599
1600 was_override = dev_priv->chv_phy_control & PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
1601
1602 if (override == was_override)
1603 goto out;
1604
1605 if (override)
1606 dev_priv->chv_phy_control |= PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
1607 else
1608 dev_priv->chv_phy_control &= ~PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
1609
1610 I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
1611
1612 DRM_DEBUG_KMS("Power gating DPIO PHY%d CH%d (DPIO_PHY_CONTROL=0x%08x)\n",
1613 phy, ch, dev_priv->chv_phy_control);
1614
Ville Syrjälä30142272015-07-08 23:46:01 +03001615 assert_chv_phy_status(dev_priv);
1616
Ville Syrjäläb0b33842015-07-08 23:45:55 +03001617out:
1618 mutex_unlock(&power_domains->lock);
1619
1620 return was_override;
1621}
1622
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001623void chv_phy_powergate_lanes(struct intel_encoder *encoder,
1624 bool override, unsigned int mask)
1625{
1626 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
1627 struct i915_power_domains *power_domains = &dev_priv->power_domains;
1628 enum dpio_phy phy = vlv_dport_to_phy(enc_to_dig_port(&encoder->base));
1629 enum dpio_channel ch = vlv_dport_to_channel(enc_to_dig_port(&encoder->base));
1630
1631 mutex_lock(&power_domains->lock);
1632
1633 dev_priv->chv_phy_control &= ~PHY_CH_POWER_DOWN_OVRD(0xf, phy, ch);
1634 dev_priv->chv_phy_control |= PHY_CH_POWER_DOWN_OVRD(mask, phy, ch);
1635
1636 if (override)
1637 dev_priv->chv_phy_control |= PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
1638 else
1639 dev_priv->chv_phy_control &= ~PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
1640
1641 I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
1642
1643 DRM_DEBUG_KMS("Power gating DPIO PHY%d CH%d lanes 0x%x (PHY_CONTROL=0x%08x)\n",
1644 phy, ch, mask, dev_priv->chv_phy_control);
1645
Ville Syrjälä30142272015-07-08 23:46:01 +03001646 assert_chv_phy_status(dev_priv);
1647
Ville Syrjälä6669e392015-07-08 23:46:00 +03001648 assert_chv_phy_powergate(dev_priv, phy, ch, override, mask);
1649
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001650 mutex_unlock(&power_domains->lock);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001651}
1652
1653static bool chv_pipe_power_well_enabled(struct drm_i915_private *dev_priv,
1654 struct i915_power_well *power_well)
1655{
Imre Deakf49193c2017-07-06 17:40:23 +03001656 enum pipe pipe = PIPE_A;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001657 bool enabled;
1658 u32 state, ctrl;
1659
1660 mutex_lock(&dev_priv->rps.hw_lock);
1661
1662 state = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & DP_SSS_MASK(pipe);
1663 /*
1664 * We only ever set the power-on and power-gate states, anything
1665 * else is unexpected.
1666 */
1667 WARN_ON(state != DP_SSS_PWR_ON(pipe) && state != DP_SSS_PWR_GATE(pipe));
1668 enabled = state == DP_SSS_PWR_ON(pipe);
1669
1670 /*
1671 * A transient state at this point would mean some unexpected party
1672 * is poking at the power controls too.
1673 */
1674 ctrl = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & DP_SSC_MASK(pipe);
1675 WARN_ON(ctrl << 16 != state);
1676
1677 mutex_unlock(&dev_priv->rps.hw_lock);
1678
1679 return enabled;
1680}
1681
1682static void chv_set_pipe_power_well(struct drm_i915_private *dev_priv,
1683 struct i915_power_well *power_well,
1684 bool enable)
1685{
Imre Deakf49193c2017-07-06 17:40:23 +03001686 enum pipe pipe = PIPE_A;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001687 u32 state;
1688 u32 ctrl;
1689
1690 state = enable ? DP_SSS_PWR_ON(pipe) : DP_SSS_PWR_GATE(pipe);
1691
1692 mutex_lock(&dev_priv->rps.hw_lock);
1693
1694#define COND \
1695 ((vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & DP_SSS_MASK(pipe)) == state)
1696
1697 if (COND)
1698 goto out;
1699
1700 ctrl = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ);
1701 ctrl &= ~DP_SSC_MASK(pipe);
1702 ctrl |= enable ? DP_SSC_PWR_ON(pipe) : DP_SSC_PWR_GATE(pipe);
1703 vlv_punit_write(dev_priv, PUNIT_REG_DSPFREQ, ctrl);
1704
1705 if (wait_for(COND, 100))
Masanari Iida7e35ab82015-05-10 01:00:23 +09001706 DRM_ERROR("timeout setting power well state %08x (%08x)\n",
Daniel Vetter9c065a72014-09-30 10:56:38 +02001707 state,
1708 vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ));
1709
1710#undef COND
1711
1712out:
1713 mutex_unlock(&dev_priv->rps.hw_lock);
1714}
1715
Daniel Vetter9c065a72014-09-30 10:56:38 +02001716static void chv_pipe_power_well_enable(struct drm_i915_private *dev_priv,
1717 struct i915_power_well *power_well)
1718{
Imre Deakf49193c2017-07-06 17:40:23 +03001719 WARN_ON_ONCE(power_well->id != CHV_DISP_PW_PIPE_A);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001720
1721 chv_set_pipe_power_well(dev_priv, power_well, true);
Ville Syrjäläafd62752014-10-30 19:43:03 +02001722
Ville Syrjälä2be7d542015-06-29 15:25:51 +03001723 vlv_display_power_well_init(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001724}
1725
1726static void chv_pipe_power_well_disable(struct drm_i915_private *dev_priv,
1727 struct i915_power_well *power_well)
1728{
Imre Deakf49193c2017-07-06 17:40:23 +03001729 WARN_ON_ONCE(power_well->id != CHV_DISP_PW_PIPE_A);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001730
Ville Syrjälä2be7d542015-06-29 15:25:51 +03001731 vlv_display_power_well_deinit(dev_priv);
Ville Syrjäläafd62752014-10-30 19:43:03 +02001732
Daniel Vetter9c065a72014-09-30 10:56:38 +02001733 chv_set_pipe_power_well(dev_priv, power_well, false);
1734}
1735
Imre Deak09731282016-02-17 14:17:42 +02001736static void
1737__intel_display_power_get_domain(struct drm_i915_private *dev_priv,
1738 enum intel_display_power_domain domain)
1739{
1740 struct i915_power_domains *power_domains = &dev_priv->power_domains;
1741 struct i915_power_well *power_well;
Imre Deak09731282016-02-17 14:17:42 +02001742
Imre Deak75ccb2e2017-02-17 17:39:43 +02001743 for_each_power_domain_well(dev_priv, power_well, BIT_ULL(domain))
Imre Deakb409ca92016-06-13 16:44:33 +03001744 intel_power_well_get(dev_priv, power_well);
Imre Deak09731282016-02-17 14:17:42 +02001745
1746 power_domains->domain_use_count[domain]++;
1747}
1748
Daniel Vettere4e76842014-09-30 10:56:42 +02001749/**
1750 * intel_display_power_get - grab a power domain reference
1751 * @dev_priv: i915 device instance
1752 * @domain: power domain to reference
1753 *
1754 * This function grabs a power domain reference for @domain and ensures that the
1755 * power domain and all its parents are powered up. Therefore users should only
1756 * grab a reference to the innermost power domain they need.
1757 *
1758 * Any power domain reference obtained by this function must have a symmetric
1759 * call to intel_display_power_put() to release the reference again.
1760 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02001761void intel_display_power_get(struct drm_i915_private *dev_priv,
1762 enum intel_display_power_domain domain)
1763{
Imre Deak09731282016-02-17 14:17:42 +02001764 struct i915_power_domains *power_domains = &dev_priv->power_domains;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001765
1766 intel_runtime_pm_get(dev_priv);
1767
Imre Deak09731282016-02-17 14:17:42 +02001768 mutex_lock(&power_domains->lock);
1769
1770 __intel_display_power_get_domain(dev_priv, domain);
1771
1772 mutex_unlock(&power_domains->lock);
1773}
1774
1775/**
1776 * intel_display_power_get_if_enabled - grab a reference for an enabled display power domain
1777 * @dev_priv: i915 device instance
1778 * @domain: power domain to reference
1779 *
1780 * This function grabs a power domain reference for @domain and ensures that the
1781 * power domain and all its parents are powered up. Therefore users should only
1782 * grab a reference to the innermost power domain they need.
1783 *
1784 * Any power domain reference obtained by this function must have a symmetric
1785 * call to intel_display_power_put() to release the reference again.
1786 */
1787bool intel_display_power_get_if_enabled(struct drm_i915_private *dev_priv,
1788 enum intel_display_power_domain domain)
1789{
1790 struct i915_power_domains *power_domains = &dev_priv->power_domains;
1791 bool is_enabled;
1792
1793 if (!intel_runtime_pm_get_if_in_use(dev_priv))
1794 return false;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001795
1796 mutex_lock(&power_domains->lock);
1797
Imre Deak09731282016-02-17 14:17:42 +02001798 if (__intel_display_power_is_enabled(dev_priv, domain)) {
1799 __intel_display_power_get_domain(dev_priv, domain);
1800 is_enabled = true;
1801 } else {
1802 is_enabled = false;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001803 }
1804
Daniel Vetter9c065a72014-09-30 10:56:38 +02001805 mutex_unlock(&power_domains->lock);
Imre Deak09731282016-02-17 14:17:42 +02001806
1807 if (!is_enabled)
1808 intel_runtime_pm_put(dev_priv);
1809
1810 return is_enabled;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001811}
1812
Daniel Vettere4e76842014-09-30 10:56:42 +02001813/**
1814 * intel_display_power_put - release a power domain reference
1815 * @dev_priv: i915 device instance
1816 * @domain: power domain to reference
1817 *
1818 * This function drops the power domain reference obtained by
1819 * intel_display_power_get() and might power down the corresponding hardware
1820 * block right away if this is the last reference.
1821 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02001822void intel_display_power_put(struct drm_i915_private *dev_priv,
1823 enum intel_display_power_domain domain)
1824{
1825 struct i915_power_domains *power_domains;
1826 struct i915_power_well *power_well;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001827
1828 power_domains = &dev_priv->power_domains;
1829
1830 mutex_lock(&power_domains->lock);
1831
Daniel Stone11c86db2015-11-20 15:55:34 +00001832 WARN(!power_domains->domain_use_count[domain],
1833 "Use count on domain %s is already zero\n",
1834 intel_display_power_domain_str(domain));
Daniel Vetter9c065a72014-09-30 10:56:38 +02001835 power_domains->domain_use_count[domain]--;
1836
Imre Deak75ccb2e2017-02-17 17:39:43 +02001837 for_each_power_domain_well_rev(dev_priv, power_well, BIT_ULL(domain))
Imre Deakb409ca92016-06-13 16:44:33 +03001838 intel_power_well_put(dev_priv, power_well);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001839
1840 mutex_unlock(&power_domains->lock);
1841
1842 intel_runtime_pm_put(dev_priv);
1843}
1844
Ville Syrjälä9d0996b2016-04-18 14:02:28 +03001845#define HSW_DISPLAY_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001846 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
1847 BIT_ULL(POWER_DOMAIN_PIPE_C) | \
1848 BIT_ULL(POWER_DOMAIN_PIPE_A_PANEL_FITTER) | \
1849 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1850 BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
1851 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
1852 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
1853 BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
1854 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1855 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1856 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_LANES) | \
1857 BIT_ULL(POWER_DOMAIN_PORT_CRT) | /* DDI E */ \
1858 BIT_ULL(POWER_DOMAIN_VGA) | \
1859 BIT_ULL(POWER_DOMAIN_AUDIO) | \
1860 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001861
Ville Syrjälä9d0996b2016-04-18 14:02:28 +03001862#define BDW_DISPLAY_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001863 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
1864 BIT_ULL(POWER_DOMAIN_PIPE_C) | \
1865 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1866 BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
1867 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
1868 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
1869 BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
1870 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1871 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1872 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_LANES) | \
1873 BIT_ULL(POWER_DOMAIN_PORT_CRT) | /* DDI E */ \
1874 BIT_ULL(POWER_DOMAIN_VGA) | \
1875 BIT_ULL(POWER_DOMAIN_AUDIO) | \
1876 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001877
Ville Syrjälä465ac0c2016-04-18 14:02:27 +03001878#define VLV_DISPLAY_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001879 BIT_ULL(POWER_DOMAIN_PIPE_A) | \
1880 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
1881 BIT_ULL(POWER_DOMAIN_PIPE_A_PANEL_FITTER) | \
1882 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1883 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
1884 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
1885 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1886 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1887 BIT_ULL(POWER_DOMAIN_PORT_DSI) | \
1888 BIT_ULL(POWER_DOMAIN_PORT_CRT) | \
1889 BIT_ULL(POWER_DOMAIN_VGA) | \
1890 BIT_ULL(POWER_DOMAIN_AUDIO) | \
1891 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1892 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1893 BIT_ULL(POWER_DOMAIN_GMBUS) | \
1894 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001895
1896#define VLV_DPIO_CMN_BC_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001897 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1898 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1899 BIT_ULL(POWER_DOMAIN_PORT_CRT) | \
1900 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1901 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1902 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001903
1904#define VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001905 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1906 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1907 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001908
1909#define VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001910 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1911 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1912 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001913
1914#define VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001915 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1916 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1917 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001918
1919#define VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001920 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1921 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1922 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001923
Ville Syrjälä465ac0c2016-04-18 14:02:27 +03001924#define CHV_DISPLAY_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001925 BIT_ULL(POWER_DOMAIN_PIPE_A) | \
1926 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
1927 BIT_ULL(POWER_DOMAIN_PIPE_C) | \
1928 BIT_ULL(POWER_DOMAIN_PIPE_A_PANEL_FITTER) | \
1929 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1930 BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
1931 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
1932 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
1933 BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
1934 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1935 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1936 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_LANES) | \
1937 BIT_ULL(POWER_DOMAIN_PORT_DSI) | \
1938 BIT_ULL(POWER_DOMAIN_VGA) | \
1939 BIT_ULL(POWER_DOMAIN_AUDIO) | \
1940 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1941 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1942 BIT_ULL(POWER_DOMAIN_AUX_D) | \
1943 BIT_ULL(POWER_DOMAIN_GMBUS) | \
1944 BIT_ULL(POWER_DOMAIN_INIT))
Ville Syrjälä465ac0c2016-04-18 14:02:27 +03001945
Daniel Vetter9c065a72014-09-30 10:56:38 +02001946#define CHV_DPIO_CMN_BC_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001947 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1948 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1949 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1950 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1951 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001952
1953#define CHV_DPIO_CMN_D_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001954 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_LANES) | \
1955 BIT_ULL(POWER_DOMAIN_AUX_D) | \
1956 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001957
Ville Syrjälä2ee0da12017-06-01 17:36:16 +03001958#define I830_PIPES_POWER_DOMAINS ( \
1959 BIT_ULL(POWER_DOMAIN_PIPE_A) | \
1960 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
1961 BIT_ULL(POWER_DOMAIN_PIPE_A_PANEL_FITTER) | \
1962 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1963 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
1964 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
1965 BIT_ULL(POWER_DOMAIN_INIT))
1966
Daniel Vetter9c065a72014-09-30 10:56:38 +02001967static const struct i915_power_well_ops i9xx_always_on_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02001968 .sync_hw = i9xx_power_well_sync_hw_noop,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001969 .enable = i9xx_always_on_power_well_noop,
1970 .disable = i9xx_always_on_power_well_noop,
1971 .is_enabled = i9xx_always_on_power_well_enabled,
1972};
1973
1974static const struct i915_power_well_ops chv_pipe_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02001975 .sync_hw = i9xx_power_well_sync_hw_noop,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001976 .enable = chv_pipe_power_well_enable,
1977 .disable = chv_pipe_power_well_disable,
1978 .is_enabled = chv_pipe_power_well_enabled,
1979};
1980
1981static const struct i915_power_well_ops chv_dpio_cmn_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02001982 .sync_hw = i9xx_power_well_sync_hw_noop,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001983 .enable = chv_dpio_cmn_power_well_enable,
1984 .disable = chv_dpio_cmn_power_well_disable,
1985 .is_enabled = vlv_power_well_enabled,
1986};
1987
1988static struct i915_power_well i9xx_always_on_power_well[] = {
1989 {
1990 .name = "always-on",
1991 .always_on = 1,
1992 .domains = POWER_DOMAIN_MASK,
1993 .ops = &i9xx_always_on_power_well_ops,
Imre Deak029d80d2017-07-06 17:40:25 +03001994 .id = I915_DISP_PW_ALWAYS_ON,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001995 },
1996};
1997
Ville Syrjälä2ee0da12017-06-01 17:36:16 +03001998static const struct i915_power_well_ops i830_pipes_power_well_ops = {
1999 .sync_hw = i830_pipes_power_well_sync_hw,
2000 .enable = i830_pipes_power_well_enable,
2001 .disable = i830_pipes_power_well_disable,
2002 .is_enabled = i830_pipes_power_well_enabled,
2003};
2004
2005static struct i915_power_well i830_power_wells[] = {
2006 {
2007 .name = "always-on",
2008 .always_on = 1,
2009 .domains = POWER_DOMAIN_MASK,
2010 .ops = &i9xx_always_on_power_well_ops,
Imre Deak029d80d2017-07-06 17:40:25 +03002011 .id = I915_DISP_PW_ALWAYS_ON,
Ville Syrjälä2ee0da12017-06-01 17:36:16 +03002012 },
2013 {
2014 .name = "pipes",
2015 .domains = I830_PIPES_POWER_DOMAINS,
2016 .ops = &i830_pipes_power_well_ops,
Imre Deak120b56a2017-07-11 23:42:31 +03002017 .id = I830_DISP_PW_PIPES,
Ville Syrjälä2ee0da12017-06-01 17:36:16 +03002018 },
2019};
2020
Daniel Vetter9c065a72014-09-30 10:56:38 +02002021static const struct i915_power_well_ops hsw_power_well_ops = {
2022 .sync_hw = hsw_power_well_sync_hw,
2023 .enable = hsw_power_well_enable,
2024 .disable = hsw_power_well_disable,
2025 .is_enabled = hsw_power_well_enabled,
2026};
2027
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002028static const struct i915_power_well_ops skl_power_well_ops = {
2029 .sync_hw = skl_power_well_sync_hw,
2030 .enable = skl_power_well_enable,
2031 .disable = skl_power_well_disable,
2032 .is_enabled = skl_power_well_enabled,
2033};
2034
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01002035static const struct i915_power_well_ops gen9_dc_off_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02002036 .sync_hw = i9xx_power_well_sync_hw_noop,
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01002037 .enable = gen9_dc_off_power_well_enable,
2038 .disable = gen9_dc_off_power_well_disable,
2039 .is_enabled = gen9_dc_off_power_well_enabled,
2040};
2041
Imre Deak9c8d0b82016-06-13 16:44:34 +03002042static const struct i915_power_well_ops bxt_dpio_cmn_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02002043 .sync_hw = i9xx_power_well_sync_hw_noop,
Imre Deak9c8d0b82016-06-13 16:44:34 +03002044 .enable = bxt_dpio_cmn_power_well_enable,
2045 .disable = bxt_dpio_cmn_power_well_disable,
2046 .is_enabled = bxt_dpio_cmn_power_well_enabled,
2047};
2048
Daniel Vetter9c065a72014-09-30 10:56:38 +02002049static struct i915_power_well hsw_power_wells[] = {
2050 {
2051 .name = "always-on",
2052 .always_on = 1,
Ville Syrjälä998bd662016-04-18 14:02:26 +03002053 .domains = POWER_DOMAIN_MASK,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002054 .ops = &i9xx_always_on_power_well_ops,
Imre Deak029d80d2017-07-06 17:40:25 +03002055 .id = I915_DISP_PW_ALWAYS_ON,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002056 },
2057 {
2058 .name = "display",
2059 .domains = HSW_DISPLAY_POWER_DOMAINS,
2060 .ops = &hsw_power_well_ops,
Imre Deakfb9248e2017-07-11 23:42:32 +03002061 .id = HSW_DISP_PW_GLOBAL,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002062 },
2063};
2064
2065static struct i915_power_well bdw_power_wells[] = {
2066 {
2067 .name = "always-on",
2068 .always_on = 1,
Ville Syrjälä998bd662016-04-18 14:02:26 +03002069 .domains = POWER_DOMAIN_MASK,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002070 .ops = &i9xx_always_on_power_well_ops,
Imre Deak029d80d2017-07-06 17:40:25 +03002071 .id = I915_DISP_PW_ALWAYS_ON,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002072 },
2073 {
2074 .name = "display",
2075 .domains = BDW_DISPLAY_POWER_DOMAINS,
2076 .ops = &hsw_power_well_ops,
Imre Deakfb9248e2017-07-11 23:42:32 +03002077 .id = HSW_DISP_PW_GLOBAL,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002078 },
2079};
2080
2081static const struct i915_power_well_ops vlv_display_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02002082 .sync_hw = i9xx_power_well_sync_hw_noop,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002083 .enable = vlv_display_power_well_enable,
2084 .disable = vlv_display_power_well_disable,
2085 .is_enabled = vlv_power_well_enabled,
2086};
2087
2088static const struct i915_power_well_ops vlv_dpio_cmn_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02002089 .sync_hw = i9xx_power_well_sync_hw_noop,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002090 .enable = vlv_dpio_cmn_power_well_enable,
2091 .disable = vlv_dpio_cmn_power_well_disable,
2092 .is_enabled = vlv_power_well_enabled,
2093};
2094
2095static const struct i915_power_well_ops vlv_dpio_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02002096 .sync_hw = i9xx_power_well_sync_hw_noop,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002097 .enable = vlv_power_well_enable,
2098 .disable = vlv_power_well_disable,
2099 .is_enabled = vlv_power_well_enabled,
2100};
2101
2102static struct i915_power_well vlv_power_wells[] = {
2103 {
2104 .name = "always-on",
2105 .always_on = 1,
Ville Syrjälä998bd662016-04-18 14:02:26 +03002106 .domains = POWER_DOMAIN_MASK,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002107 .ops = &i9xx_always_on_power_well_ops,
Imre Deak438b8dc2017-07-11 23:42:30 +03002108 .id = I915_DISP_PW_ALWAYS_ON,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002109 },
2110 {
2111 .name = "display",
2112 .domains = VLV_DISPLAY_POWER_DOMAINS,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002113 .id = PUNIT_POWER_WELL_DISP2D,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002114 .ops = &vlv_display_power_well_ops,
2115 },
2116 {
2117 .name = "dpio-tx-b-01",
2118 .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
2119 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
2120 VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
2121 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
2122 .ops = &vlv_dpio_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002123 .id = PUNIT_POWER_WELL_DPIO_TX_B_LANES_01,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002124 },
2125 {
2126 .name = "dpio-tx-b-23",
2127 .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
2128 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
2129 VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
2130 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
2131 .ops = &vlv_dpio_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002132 .id = PUNIT_POWER_WELL_DPIO_TX_B_LANES_23,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002133 },
2134 {
2135 .name = "dpio-tx-c-01",
2136 .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
2137 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
2138 VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
2139 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
2140 .ops = &vlv_dpio_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002141 .id = PUNIT_POWER_WELL_DPIO_TX_C_LANES_01,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002142 },
2143 {
2144 .name = "dpio-tx-c-23",
2145 .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
2146 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
2147 VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
2148 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
2149 .ops = &vlv_dpio_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002150 .id = PUNIT_POWER_WELL_DPIO_TX_C_LANES_23,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002151 },
2152 {
2153 .name = "dpio-common",
2154 .domains = VLV_DPIO_CMN_BC_POWER_DOMAINS,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002155 .id = PUNIT_POWER_WELL_DPIO_CMN_BC,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002156 .ops = &vlv_dpio_cmn_power_well_ops,
2157 },
2158};
2159
2160static struct i915_power_well chv_power_wells[] = {
2161 {
2162 .name = "always-on",
2163 .always_on = 1,
Ville Syrjälä998bd662016-04-18 14:02:26 +03002164 .domains = POWER_DOMAIN_MASK,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002165 .ops = &i9xx_always_on_power_well_ops,
Imre Deak029d80d2017-07-06 17:40:25 +03002166 .id = I915_DISP_PW_ALWAYS_ON,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002167 },
Daniel Vetter9c065a72014-09-30 10:56:38 +02002168 {
2169 .name = "display",
Ville Syrjäläbaa4e572014-10-27 16:07:32 +02002170 /*
Ville Syrjäläfde61e42015-05-26 20:22:39 +03002171 * Pipe A power well is the new disp2d well. Pipe B and C
2172 * power wells don't actually exist. Pipe A power well is
2173 * required for any pipe to work.
Ville Syrjäläbaa4e572014-10-27 16:07:32 +02002174 */
Ville Syrjälä465ac0c2016-04-18 14:02:27 +03002175 .domains = CHV_DISPLAY_POWER_DOMAINS,
Imre Deakf49193c2017-07-06 17:40:23 +03002176 .id = CHV_DISP_PW_PIPE_A,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002177 .ops = &chv_pipe_power_well_ops,
2178 },
Daniel Vetter9c065a72014-09-30 10:56:38 +02002179 {
2180 .name = "dpio-common-bc",
Ville Syrjälä71849b62015-04-10 18:21:29 +03002181 .domains = CHV_DPIO_CMN_BC_POWER_DOMAINS,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002182 .id = PUNIT_POWER_WELL_DPIO_CMN_BC,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002183 .ops = &chv_dpio_cmn_power_well_ops,
2184 },
2185 {
2186 .name = "dpio-common-d",
Ville Syrjälä71849b62015-04-10 18:21:29 +03002187 .domains = CHV_DPIO_CMN_D_POWER_DOMAINS,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002188 .id = PUNIT_POWER_WELL_DPIO_CMN_D,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002189 .ops = &chv_dpio_cmn_power_well_ops,
2190 },
Daniel Vetter9c065a72014-09-30 10:56:38 +02002191};
2192
Suketu Shah5aefb232015-04-16 14:22:10 +05302193bool intel_display_power_well_is_enabled(struct drm_i915_private *dev_priv,
Imre Deak438b8dc2017-07-11 23:42:30 +03002194 enum i915_power_well_id power_well_id)
Suketu Shah5aefb232015-04-16 14:22:10 +05302195{
2196 struct i915_power_well *power_well;
2197 bool ret;
2198
2199 power_well = lookup_power_well(dev_priv, power_well_id);
2200 ret = power_well->ops->is_enabled(dev_priv, power_well);
2201
2202 return ret;
2203}
2204
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002205static struct i915_power_well skl_power_wells[] = {
2206 {
2207 .name = "always-on",
2208 .always_on = 1,
Ville Syrjälä998bd662016-04-18 14:02:26 +03002209 .domains = POWER_DOMAIN_MASK,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002210 .ops = &i9xx_always_on_power_well_ops,
Imre Deak438b8dc2017-07-11 23:42:30 +03002211 .id = I915_DISP_PW_ALWAYS_ON,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002212 },
2213 {
2214 .name = "power well 1",
Imre Deak4a76f292015-11-04 19:24:15 +02002215 /* Handled by the DMC firmware */
2216 .domains = 0,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002217 .ops = &skl_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002218 .id = SKL_DISP_PW_1,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002219 },
2220 {
2221 .name = "MISC IO power well",
Imre Deak4a76f292015-11-04 19:24:15 +02002222 /* Handled by the DMC firmware */
2223 .domains = 0,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002224 .ops = &skl_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002225 .id = SKL_DISP_PW_MISC_IO,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002226 },
2227 {
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01002228 .name = "DC off",
2229 .domains = SKL_DISPLAY_DC_OFF_POWER_DOMAINS,
2230 .ops = &gen9_dc_off_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002231 .id = SKL_DISP_PW_DC_OFF,
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01002232 },
2233 {
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002234 .name = "power well 2",
2235 .domains = SKL_DISPLAY_POWERWELL_2_POWER_DOMAINS,
2236 .ops = &skl_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002237 .id = SKL_DISP_PW_2,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002238 },
2239 {
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002240 .name = "DDI A/E IO power well",
2241 .domains = SKL_DISPLAY_DDI_IO_A_E_POWER_DOMAINS,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002242 .ops = &skl_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002243 .id = SKL_DISP_PW_DDI_A_E,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002244 },
2245 {
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002246 .name = "DDI B IO power well",
2247 .domains = SKL_DISPLAY_DDI_IO_B_POWER_DOMAINS,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002248 .ops = &skl_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002249 .id = SKL_DISP_PW_DDI_B,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002250 },
2251 {
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002252 .name = "DDI C IO power well",
2253 .domains = SKL_DISPLAY_DDI_IO_C_POWER_DOMAINS,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002254 .ops = &skl_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002255 .id = SKL_DISP_PW_DDI_C,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002256 },
2257 {
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002258 .name = "DDI D IO power well",
2259 .domains = SKL_DISPLAY_DDI_IO_D_POWER_DOMAINS,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002260 .ops = &skl_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002261 .id = SKL_DISP_PW_DDI_D,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002262 },
2263};
2264
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302265static struct i915_power_well bxt_power_wells[] = {
2266 {
2267 .name = "always-on",
2268 .always_on = 1,
Ville Syrjälä998bd662016-04-18 14:02:26 +03002269 .domains = POWER_DOMAIN_MASK,
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302270 .ops = &i9xx_always_on_power_well_ops,
Imre Deak029d80d2017-07-06 17:40:25 +03002271 .id = I915_DISP_PW_ALWAYS_ON,
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302272 },
2273 {
2274 .name = "power well 1",
Imre Deakd7d7c9e2016-04-01 16:02:42 +03002275 .domains = 0,
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302276 .ops = &skl_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002277 .id = SKL_DISP_PW_1,
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302278 },
2279 {
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01002280 .name = "DC off",
2281 .domains = BXT_DISPLAY_DC_OFF_POWER_DOMAINS,
2282 .ops = &gen9_dc_off_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002283 .id = SKL_DISP_PW_DC_OFF,
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01002284 },
2285 {
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302286 .name = "power well 2",
2287 .domains = BXT_DISPLAY_POWERWELL_2_POWER_DOMAINS,
2288 .ops = &skl_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002289 .id = SKL_DISP_PW_2,
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01002290 },
Imre Deak9c8d0b82016-06-13 16:44:34 +03002291 {
2292 .name = "dpio-common-a",
2293 .domains = BXT_DPIO_CMN_A_POWER_DOMAINS,
2294 .ops = &bxt_dpio_cmn_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002295 .id = BXT_DPIO_CMN_A,
Imre Deakb5565a22017-07-06 17:40:29 +03002296 .bxt.phy = DPIO_PHY1,
Imre Deak9c8d0b82016-06-13 16:44:34 +03002297 },
2298 {
2299 .name = "dpio-common-bc",
2300 .domains = BXT_DPIO_CMN_BC_POWER_DOMAINS,
2301 .ops = &bxt_dpio_cmn_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002302 .id = BXT_DPIO_CMN_BC,
Imre Deakb5565a22017-07-06 17:40:29 +03002303 .bxt.phy = DPIO_PHY0,
Imre Deak9c8d0b82016-06-13 16:44:34 +03002304 },
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302305};
2306
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002307static struct i915_power_well glk_power_wells[] = {
2308 {
2309 .name = "always-on",
2310 .always_on = 1,
2311 .domains = POWER_DOMAIN_MASK,
2312 .ops = &i9xx_always_on_power_well_ops,
Imre Deak029d80d2017-07-06 17:40:25 +03002313 .id = I915_DISP_PW_ALWAYS_ON,
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002314 },
2315 {
2316 .name = "power well 1",
2317 /* Handled by the DMC firmware */
2318 .domains = 0,
2319 .ops = &skl_power_well_ops,
2320 .id = SKL_DISP_PW_1,
2321 },
2322 {
2323 .name = "DC off",
2324 .domains = GLK_DISPLAY_DC_OFF_POWER_DOMAINS,
2325 .ops = &gen9_dc_off_power_well_ops,
2326 .id = SKL_DISP_PW_DC_OFF,
2327 },
2328 {
2329 .name = "power well 2",
2330 .domains = GLK_DISPLAY_POWERWELL_2_POWER_DOMAINS,
2331 .ops = &skl_power_well_ops,
2332 .id = SKL_DISP_PW_2,
2333 },
2334 {
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +02002335 .name = "dpio-common-a",
2336 .domains = GLK_DPIO_CMN_A_POWER_DOMAINS,
2337 .ops = &bxt_dpio_cmn_power_well_ops,
2338 .id = BXT_DPIO_CMN_A,
Imre Deakb5565a22017-07-06 17:40:29 +03002339 .bxt.phy = DPIO_PHY1,
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +02002340 },
2341 {
2342 .name = "dpio-common-b",
2343 .domains = GLK_DPIO_CMN_B_POWER_DOMAINS,
2344 .ops = &bxt_dpio_cmn_power_well_ops,
2345 .id = BXT_DPIO_CMN_BC,
Imre Deakb5565a22017-07-06 17:40:29 +03002346 .bxt.phy = DPIO_PHY0,
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +02002347 },
2348 {
2349 .name = "dpio-common-c",
2350 .domains = GLK_DPIO_CMN_C_POWER_DOMAINS,
2351 .ops = &bxt_dpio_cmn_power_well_ops,
2352 .id = GLK_DPIO_CMN_C,
Imre Deakb5565a22017-07-06 17:40:29 +03002353 .bxt.phy = DPIO_PHY2,
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +02002354 },
2355 {
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002356 .name = "AUX A",
2357 .domains = GLK_DISPLAY_AUX_A_POWER_DOMAINS,
2358 .ops = &skl_power_well_ops,
2359 .id = GLK_DISP_PW_AUX_A,
2360 },
2361 {
2362 .name = "AUX B",
2363 .domains = GLK_DISPLAY_AUX_B_POWER_DOMAINS,
2364 .ops = &skl_power_well_ops,
2365 .id = GLK_DISP_PW_AUX_B,
2366 },
2367 {
2368 .name = "AUX C",
2369 .domains = GLK_DISPLAY_AUX_C_POWER_DOMAINS,
2370 .ops = &skl_power_well_ops,
2371 .id = GLK_DISP_PW_AUX_C,
2372 },
2373 {
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002374 .name = "DDI A IO power well",
2375 .domains = GLK_DISPLAY_DDI_IO_A_POWER_DOMAINS,
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002376 .ops = &skl_power_well_ops,
2377 .id = GLK_DISP_PW_DDI_A,
2378 },
2379 {
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002380 .name = "DDI B IO power well",
2381 .domains = GLK_DISPLAY_DDI_IO_B_POWER_DOMAINS,
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002382 .ops = &skl_power_well_ops,
2383 .id = SKL_DISP_PW_DDI_B,
2384 },
2385 {
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002386 .name = "DDI C IO power well",
2387 .domains = GLK_DISPLAY_DDI_IO_C_POWER_DOMAINS,
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002388 .ops = &skl_power_well_ops,
2389 .id = SKL_DISP_PW_DDI_C,
2390 },
2391};
2392
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002393static struct i915_power_well cnl_power_wells[] = {
2394 {
2395 .name = "always-on",
2396 .always_on = 1,
2397 .domains = POWER_DOMAIN_MASK,
2398 .ops = &i9xx_always_on_power_well_ops,
Imre Deak029d80d2017-07-06 17:40:25 +03002399 .id = I915_DISP_PW_ALWAYS_ON,
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002400 },
2401 {
2402 .name = "power well 1",
2403 /* Handled by the DMC firmware */
2404 .domains = 0,
2405 .ops = &skl_power_well_ops,
2406 .id = SKL_DISP_PW_1,
2407 },
2408 {
2409 .name = "AUX A",
2410 .domains = CNL_DISPLAY_AUX_A_POWER_DOMAINS,
2411 .ops = &skl_power_well_ops,
2412 .id = CNL_DISP_PW_AUX_A,
2413 },
2414 {
2415 .name = "AUX B",
2416 .domains = CNL_DISPLAY_AUX_B_POWER_DOMAINS,
2417 .ops = &skl_power_well_ops,
2418 .id = CNL_DISP_PW_AUX_B,
2419 },
2420 {
2421 .name = "AUX C",
2422 .domains = CNL_DISPLAY_AUX_C_POWER_DOMAINS,
2423 .ops = &skl_power_well_ops,
2424 .id = CNL_DISP_PW_AUX_C,
2425 },
2426 {
2427 .name = "AUX D",
2428 .domains = CNL_DISPLAY_AUX_D_POWER_DOMAINS,
2429 .ops = &skl_power_well_ops,
2430 .id = CNL_DISP_PW_AUX_D,
2431 },
2432 {
2433 .name = "DC off",
2434 .domains = CNL_DISPLAY_DC_OFF_POWER_DOMAINS,
2435 .ops = &gen9_dc_off_power_well_ops,
2436 .id = SKL_DISP_PW_DC_OFF,
2437 },
2438 {
2439 .name = "power well 2",
2440 .domains = CNL_DISPLAY_POWERWELL_2_POWER_DOMAINS,
2441 .ops = &skl_power_well_ops,
2442 .id = SKL_DISP_PW_2,
2443 },
2444 {
2445 .name = "DDI A IO power well",
2446 .domains = CNL_DISPLAY_DDI_A_IO_POWER_DOMAINS,
2447 .ops = &skl_power_well_ops,
2448 .id = CNL_DISP_PW_DDI_A,
2449 },
2450 {
2451 .name = "DDI B IO power well",
2452 .domains = CNL_DISPLAY_DDI_B_IO_POWER_DOMAINS,
2453 .ops = &skl_power_well_ops,
2454 .id = SKL_DISP_PW_DDI_B,
2455 },
2456 {
2457 .name = "DDI C IO power well",
2458 .domains = CNL_DISPLAY_DDI_C_IO_POWER_DOMAINS,
2459 .ops = &skl_power_well_ops,
2460 .id = SKL_DISP_PW_DDI_C,
2461 },
2462 {
2463 .name = "DDI D IO power well",
2464 .domains = CNL_DISPLAY_DDI_D_IO_POWER_DOMAINS,
2465 .ops = &skl_power_well_ops,
2466 .id = SKL_DISP_PW_DDI_D,
2467 },
2468};
2469
Imre Deak1b0e3a02015-11-05 23:04:11 +02002470static int
2471sanitize_disable_power_well_option(const struct drm_i915_private *dev_priv,
2472 int disable_power_well)
2473{
2474 if (disable_power_well >= 0)
2475 return !!disable_power_well;
2476
Imre Deak1b0e3a02015-11-05 23:04:11 +02002477 return 1;
2478}
2479
Imre Deaka37baf32016-02-29 22:49:03 +02002480static uint32_t get_allowed_dc_mask(const struct drm_i915_private *dev_priv,
2481 int enable_dc)
2482{
2483 uint32_t mask;
2484 int requested_dc;
2485 int max_dc;
2486
Rodrigo Vivi6d6a8972017-07-06 13:45:08 -07002487 if (IS_GEN9_BC(dev_priv) || IS_CANNONLAKE(dev_priv)) {
Imre Deaka37baf32016-02-29 22:49:03 +02002488 max_dc = 2;
2489 mask = 0;
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02002490 } else if (IS_GEN9_LP(dev_priv)) {
Imre Deaka37baf32016-02-29 22:49:03 +02002491 max_dc = 1;
2492 /*
2493 * DC9 has a separate HW flow from the rest of the DC states,
2494 * not depending on the DMC firmware. It's needed by system
2495 * suspend/resume, so allow it unconditionally.
2496 */
2497 mask = DC_STATE_EN_DC9;
2498 } else {
2499 max_dc = 0;
2500 mask = 0;
2501 }
2502
Imre Deak66e2c4c2016-02-29 22:49:04 +02002503 if (!i915.disable_power_well)
2504 max_dc = 0;
2505
Imre Deaka37baf32016-02-29 22:49:03 +02002506 if (enable_dc >= 0 && enable_dc <= max_dc) {
2507 requested_dc = enable_dc;
2508 } else if (enable_dc == -1) {
2509 requested_dc = max_dc;
2510 } else if (enable_dc > max_dc && enable_dc <= 2) {
2511 DRM_DEBUG_KMS("Adjusting requested max DC state (%d->%d)\n",
2512 enable_dc, max_dc);
2513 requested_dc = max_dc;
2514 } else {
2515 DRM_ERROR("Unexpected value for enable_dc (%d)\n", enable_dc);
2516 requested_dc = max_dc;
2517 }
2518
2519 if (requested_dc > 1)
2520 mask |= DC_STATE_EN_UPTO_DC6;
2521 if (requested_dc > 0)
2522 mask |= DC_STATE_EN_UPTO_DC5;
2523
2524 DRM_DEBUG_KMS("Allowed DC state mask %02x\n", mask);
2525
2526 return mask;
2527}
2528
Imre Deak21792c62017-07-11 23:42:33 +03002529static void assert_power_well_ids_unique(struct drm_i915_private *dev_priv)
2530{
2531 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2532 u64 power_well_ids;
2533 int i;
2534
2535 power_well_ids = 0;
2536 for (i = 0; i < power_domains->power_well_count; i++) {
2537 enum i915_power_well_id id = power_domains->power_wells[i].id;
2538
2539 WARN_ON(id >= sizeof(power_well_ids) * 8);
2540 WARN_ON(power_well_ids & BIT_ULL(id));
2541 power_well_ids |= BIT_ULL(id);
2542 }
2543}
2544
Daniel Vetter9c065a72014-09-30 10:56:38 +02002545#define set_power_wells(power_domains, __power_wells) ({ \
2546 (power_domains)->power_wells = (__power_wells); \
2547 (power_domains)->power_well_count = ARRAY_SIZE(__power_wells); \
2548})
2549
Daniel Vettere4e76842014-09-30 10:56:42 +02002550/**
2551 * intel_power_domains_init - initializes the power domain structures
2552 * @dev_priv: i915 device instance
2553 *
2554 * Initializes the power domain structures for @dev_priv depending upon the
2555 * supported platform.
2556 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02002557int intel_power_domains_init(struct drm_i915_private *dev_priv)
2558{
2559 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2560
Imre Deak1b0e3a02015-11-05 23:04:11 +02002561 i915.disable_power_well = sanitize_disable_power_well_option(dev_priv,
2562 i915.disable_power_well);
Imre Deaka37baf32016-02-29 22:49:03 +02002563 dev_priv->csr.allowed_dc_mask = get_allowed_dc_mask(dev_priv,
2564 i915.enable_dc);
Imre Deak1b0e3a02015-11-05 23:04:11 +02002565
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02002566 BUILD_BUG_ON(POWER_DOMAIN_NUM > 64);
Ville Syrjäläf0ab43e2015-11-09 16:48:19 +01002567
Daniel Vetter9c065a72014-09-30 10:56:38 +02002568 mutex_init(&power_domains->lock);
2569
2570 /*
2571 * The enabling order will be from lower to higher indexed wells,
2572 * the disabling order is reversed.
2573 */
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002574 if (IS_HASWELL(dev_priv)) {
Daniel Vetter9c065a72014-09-30 10:56:38 +02002575 set_power_wells(power_domains, hsw_power_wells);
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002576 } else if (IS_BROADWELL(dev_priv)) {
Daniel Vetter9c065a72014-09-30 10:56:38 +02002577 set_power_wells(power_domains, bdw_power_wells);
Rodrigo Vivib976dc52017-01-23 10:32:37 -08002578 } else if (IS_GEN9_BC(dev_priv)) {
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002579 set_power_wells(power_domains, skl_power_wells);
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002580 } else if (IS_CANNONLAKE(dev_priv)) {
2581 set_power_wells(power_domains, cnl_power_wells);
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002582 } else if (IS_BROXTON(dev_priv)) {
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302583 set_power_wells(power_domains, bxt_power_wells);
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002584 } else if (IS_GEMINILAKE(dev_priv)) {
2585 set_power_wells(power_domains, glk_power_wells);
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002586 } else if (IS_CHERRYVIEW(dev_priv)) {
Daniel Vetter9c065a72014-09-30 10:56:38 +02002587 set_power_wells(power_domains, chv_power_wells);
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002588 } else if (IS_VALLEYVIEW(dev_priv)) {
Daniel Vetter9c065a72014-09-30 10:56:38 +02002589 set_power_wells(power_domains, vlv_power_wells);
Ville Syrjälä2ee0da12017-06-01 17:36:16 +03002590 } else if (IS_I830(dev_priv)) {
2591 set_power_wells(power_domains, i830_power_wells);
Daniel Vetter9c065a72014-09-30 10:56:38 +02002592 } else {
2593 set_power_wells(power_domains, i9xx_always_on_power_well);
2594 }
2595
Imre Deak21792c62017-07-11 23:42:33 +03002596 assert_power_well_ids_unique(dev_priv);
2597
Daniel Vetter9c065a72014-09-30 10:56:38 +02002598 return 0;
2599}
2600
Daniel Vettere4e76842014-09-30 10:56:42 +02002601/**
2602 * intel_power_domains_fini - finalizes the power domain structures
2603 * @dev_priv: i915 device instance
2604 *
2605 * Finalizes the power domain structures for @dev_priv depending upon the
2606 * supported platform. This function also disables runtime pm and ensures that
2607 * the device stays powered up so that the driver can be reloaded.
2608 */
Daniel Vetterf458ebb2014-09-30 10:56:39 +02002609void intel_power_domains_fini(struct drm_i915_private *dev_priv)
Daniel Vetter9c065a72014-09-30 10:56:38 +02002610{
David Weinehallc49d13e2016-08-22 13:32:42 +03002611 struct device *kdev = &dev_priv->drm.pdev->dev;
Imre Deak25b181b2015-12-17 13:44:56 +02002612
Imre Deakaabee1b2015-12-15 20:10:29 +02002613 /*
2614 * The i915.ko module is still not prepared to be loaded when
Daniel Vetterf458ebb2014-09-30 10:56:39 +02002615 * the power well is not enabled, so just enable it in case
Imre Deakaabee1b2015-12-15 20:10:29 +02002616 * we're going to unload/reload.
2617 * The following also reacquires the RPM reference the core passed
2618 * to the driver during loading, which is dropped in
2619 * intel_runtime_pm_enable(). We have to hand back the control of the
2620 * device to the core with this reference held.
2621 */
Daniel Vetterf458ebb2014-09-30 10:56:39 +02002622 intel_display_set_init_power(dev_priv, true);
Imre Deakd314cd42015-11-17 17:44:23 +02002623
2624 /* Remove the refcount we took to keep power well support disabled. */
2625 if (!i915.disable_power_well)
2626 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
Imre Deak25b181b2015-12-17 13:44:56 +02002627
2628 /*
2629 * Remove the refcount we took in intel_runtime_pm_enable() in case
2630 * the platform doesn't support runtime PM.
2631 */
2632 if (!HAS_RUNTIME_PM(dev_priv))
David Weinehallc49d13e2016-08-22 13:32:42 +03002633 pm_runtime_put(kdev);
Daniel Vetter9c065a72014-09-30 10:56:38 +02002634}
2635
Imre Deak30eade12015-11-04 19:24:13 +02002636static void intel_power_domains_sync_hw(struct drm_i915_private *dev_priv)
Daniel Vetter9c065a72014-09-30 10:56:38 +02002637{
2638 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2639 struct i915_power_well *power_well;
Daniel Vetter9c065a72014-09-30 10:56:38 +02002640
2641 mutex_lock(&power_domains->lock);
Imre Deak75ccb2e2017-02-17 17:39:43 +02002642 for_each_power_well(dev_priv, power_well) {
Daniel Vetter9c065a72014-09-30 10:56:38 +02002643 power_well->ops->sync_hw(dev_priv, power_well);
2644 power_well->hw_enabled = power_well->ops->is_enabled(dev_priv,
2645 power_well);
2646 }
2647 mutex_unlock(&power_domains->lock);
2648}
2649
Ville Syrjälä70c2c182016-05-13 23:41:30 +03002650static void gen9_dbuf_enable(struct drm_i915_private *dev_priv)
2651{
2652 I915_WRITE(DBUF_CTL, I915_READ(DBUF_CTL) | DBUF_POWER_REQUEST);
2653 POSTING_READ(DBUF_CTL);
2654
2655 udelay(10);
2656
2657 if (!(I915_READ(DBUF_CTL) & DBUF_POWER_STATE))
2658 DRM_ERROR("DBuf power enable timeout\n");
2659}
2660
2661static void gen9_dbuf_disable(struct drm_i915_private *dev_priv)
2662{
2663 I915_WRITE(DBUF_CTL, I915_READ(DBUF_CTL) & ~DBUF_POWER_REQUEST);
2664 POSTING_READ(DBUF_CTL);
2665
2666 udelay(10);
2667
2668 if (I915_READ(DBUF_CTL) & DBUF_POWER_STATE)
2669 DRM_ERROR("DBuf power disable timeout!\n");
2670}
2671
Imre Deak73dfc222015-11-17 17:33:53 +02002672static void skl_display_core_init(struct drm_i915_private *dev_priv,
Imre Deak443a93a2016-04-04 15:42:57 +03002673 bool resume)
Imre Deak73dfc222015-11-17 17:33:53 +02002674{
2675 struct i915_power_domains *power_domains = &dev_priv->power_domains;
Imre Deak443a93a2016-04-04 15:42:57 +03002676 struct i915_power_well *well;
Imre Deak73dfc222015-11-17 17:33:53 +02002677 uint32_t val;
2678
Imre Deakd26fa1d2015-11-04 19:24:17 +02002679 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
2680
Imre Deak73dfc222015-11-17 17:33:53 +02002681 /* enable PCH reset handshake */
2682 val = I915_READ(HSW_NDE_RSTWRN_OPT);
2683 I915_WRITE(HSW_NDE_RSTWRN_OPT, val | RESET_PCH_HANDSHAKE_ENABLE);
2684
2685 /* enable PG1 and Misc I/O */
2686 mutex_lock(&power_domains->lock);
Imre Deak443a93a2016-04-04 15:42:57 +03002687
2688 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
2689 intel_power_well_enable(dev_priv, well);
2690
2691 well = lookup_power_well(dev_priv, SKL_DISP_PW_MISC_IO);
2692 intel_power_well_enable(dev_priv, well);
2693
Imre Deak73dfc222015-11-17 17:33:53 +02002694 mutex_unlock(&power_domains->lock);
2695
Imre Deak73dfc222015-11-17 17:33:53 +02002696 skl_init_cdclk(dev_priv);
2697
Ville Syrjälä70c2c182016-05-13 23:41:30 +03002698 gen9_dbuf_enable(dev_priv);
2699
Ville Syrjälä9f7eb312016-05-13 23:41:29 +03002700 if (resume && dev_priv->csr.dmc_payload)
Imre Deak2abc5252016-03-04 21:57:41 +02002701 intel_csr_load_program(dev_priv);
Imre Deak73dfc222015-11-17 17:33:53 +02002702}
2703
2704static void skl_display_core_uninit(struct drm_i915_private *dev_priv)
2705{
2706 struct i915_power_domains *power_domains = &dev_priv->power_domains;
Imre Deak443a93a2016-04-04 15:42:57 +03002707 struct i915_power_well *well;
Imre Deak73dfc222015-11-17 17:33:53 +02002708
Imre Deakd26fa1d2015-11-04 19:24:17 +02002709 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
2710
Ville Syrjälä70c2c182016-05-13 23:41:30 +03002711 gen9_dbuf_disable(dev_priv);
2712
Imre Deak73dfc222015-11-17 17:33:53 +02002713 skl_uninit_cdclk(dev_priv);
2714
2715 /* The spec doesn't call for removing the reset handshake flag */
2716 /* disable PG1 and Misc I/O */
Imre Deak443a93a2016-04-04 15:42:57 +03002717
Imre Deak73dfc222015-11-17 17:33:53 +02002718 mutex_lock(&power_domains->lock);
Imre Deak443a93a2016-04-04 15:42:57 +03002719
Imre Deakedfda8e2017-06-29 18:36:59 +03002720 /*
2721 * BSpec says to keep the MISC IO power well enabled here, only
2722 * remove our request for power well 1.
Imre Deak42d93662017-06-29 18:37:01 +03002723 * Note that even though the driver's request is removed power well 1
2724 * may stay enabled after this due to DMC's own request on it.
Imre Deakedfda8e2017-06-29 18:36:59 +03002725 */
Imre Deak443a93a2016-04-04 15:42:57 +03002726 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
2727 intel_power_well_disable(dev_priv, well);
2728
Imre Deak73dfc222015-11-17 17:33:53 +02002729 mutex_unlock(&power_domains->lock);
Imre Deak846c6b22017-06-29 18:36:58 +03002730
2731 usleep_range(10, 30); /* 10 us delay per Bspec */
Imre Deak73dfc222015-11-17 17:33:53 +02002732}
2733
Imre Deakd7d7c9e2016-04-01 16:02:42 +03002734void bxt_display_core_init(struct drm_i915_private *dev_priv,
2735 bool resume)
2736{
2737 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2738 struct i915_power_well *well;
2739 uint32_t val;
2740
2741 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
2742
2743 /*
2744 * NDE_RSTWRN_OPT RST PCH Handshake En must always be 0b on BXT
2745 * or else the reset will hang because there is no PCH to respond.
2746 * Move the handshake programming to initialization sequence.
2747 * Previously was left up to BIOS.
2748 */
2749 val = I915_READ(HSW_NDE_RSTWRN_OPT);
2750 val &= ~RESET_PCH_HANDSHAKE_ENABLE;
2751 I915_WRITE(HSW_NDE_RSTWRN_OPT, val);
2752
2753 /* Enable PG1 */
2754 mutex_lock(&power_domains->lock);
2755
2756 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
2757 intel_power_well_enable(dev_priv, well);
2758
2759 mutex_unlock(&power_domains->lock);
2760
Imre Deak324513c2016-06-13 16:44:36 +03002761 bxt_init_cdclk(dev_priv);
Ville Syrjälä70c2c182016-05-13 23:41:30 +03002762
2763 gen9_dbuf_enable(dev_priv);
2764
Imre Deakd7d7c9e2016-04-01 16:02:42 +03002765 if (resume && dev_priv->csr.dmc_payload)
2766 intel_csr_load_program(dev_priv);
2767}
2768
2769void bxt_display_core_uninit(struct drm_i915_private *dev_priv)
2770{
2771 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2772 struct i915_power_well *well;
2773
2774 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
2775
Ville Syrjälä70c2c182016-05-13 23:41:30 +03002776 gen9_dbuf_disable(dev_priv);
2777
Imre Deak324513c2016-06-13 16:44:36 +03002778 bxt_uninit_cdclk(dev_priv);
Imre Deakd7d7c9e2016-04-01 16:02:42 +03002779
2780 /* The spec doesn't call for removing the reset handshake flag */
2781
Imre Deak42d93662017-06-29 18:37:01 +03002782 /*
2783 * Disable PW1 (PG1).
2784 * Note that even though the driver's request is removed power well 1
2785 * may stay enabled after this due to DMC's own request on it.
2786 */
Imre Deakd7d7c9e2016-04-01 16:02:42 +03002787 mutex_lock(&power_domains->lock);
2788
2789 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
2790 intel_power_well_disable(dev_priv, well);
2791
2792 mutex_unlock(&power_domains->lock);
Imre Deak846c6b22017-06-29 18:36:58 +03002793
2794 usleep_range(10, 30); /* 10 us delay per Bspec */
Imre Deakd7d7c9e2016-04-01 16:02:42 +03002795}
2796
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07002797#define CNL_PROCMON_IDX(val) \
2798 (((val) & (PROCESS_INFO_MASK | VOLTAGE_INFO_MASK)) >> VOLTAGE_INFO_SHIFT)
2799#define NUM_CNL_PROCMON \
2800 (CNL_PROCMON_IDX(VOLTAGE_INFO_MASK | PROCESS_INFO_MASK) + 1)
2801
2802static const struct cnl_procmon {
2803 u32 dw1, dw9, dw10;
2804} cnl_procmon_values[NUM_CNL_PROCMON] = {
2805 [CNL_PROCMON_IDX(VOLTAGE_INFO_0_85V | PROCESS_INFO_DOT_0)] =
2806 { .dw1 = 0x00 << 16, .dw9 = 0x62AB67BB, .dw10 = 0x51914F96, },
2807 [CNL_PROCMON_IDX(VOLTAGE_INFO_0_95V | PROCESS_INFO_DOT_0)] =
2808 { .dw1 = 0x00 << 16, .dw9 = 0x86E172C7, .dw10 = 0x77CA5EAB, },
2809 [CNL_PROCMON_IDX(VOLTAGE_INFO_0_95V | PROCESS_INFO_DOT_1)] =
2810 { .dw1 = 0x00 << 16, .dw9 = 0x93F87FE1, .dw10 = 0x8AE871C5, },
2811 [CNL_PROCMON_IDX(VOLTAGE_INFO_1_05V | PROCESS_INFO_DOT_0)] =
2812 { .dw1 = 0x00 << 16, .dw9 = 0x98FA82DD, .dw10 = 0x89E46DC1, },
2813 [CNL_PROCMON_IDX(VOLTAGE_INFO_1_05V | PROCESS_INFO_DOT_1)] =
2814 { .dw1 = 0x44 << 16, .dw9 = 0x9A00AB25, .dw10 = 0x8AE38FF1, },
2815};
2816
2817static void cnl_display_core_init(struct drm_i915_private *dev_priv, bool resume)
2818{
2819 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2820 const struct cnl_procmon *procmon;
2821 struct i915_power_well *well;
2822 u32 val;
2823
2824 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
2825
2826 /* 1. Enable PCH Reset Handshake */
2827 val = I915_READ(HSW_NDE_RSTWRN_OPT);
2828 val |= RESET_PCH_HANDSHAKE_ENABLE;
2829 I915_WRITE(HSW_NDE_RSTWRN_OPT, val);
2830
2831 /* 2. Enable Comp */
2832 val = I915_READ(CHICKEN_MISC_2);
2833 val &= ~COMP_PWR_DOWN;
2834 I915_WRITE(CHICKEN_MISC_2, val);
2835
2836 val = I915_READ(CNL_PORT_COMP_DW3);
2837 procmon = &cnl_procmon_values[CNL_PROCMON_IDX(val)];
2838
2839 WARN_ON(procmon->dw10 == 0);
2840
2841 val = I915_READ(CNL_PORT_COMP_DW1);
2842 val &= ~((0xff << 16) | 0xff);
2843 val |= procmon->dw1;
2844 I915_WRITE(CNL_PORT_COMP_DW1, val);
2845
2846 I915_WRITE(CNL_PORT_COMP_DW9, procmon->dw9);
2847 I915_WRITE(CNL_PORT_COMP_DW10, procmon->dw10);
2848
2849 val = I915_READ(CNL_PORT_COMP_DW0);
2850 val |= COMP_INIT;
2851 I915_WRITE(CNL_PORT_COMP_DW0, val);
2852
2853 /* 3. */
2854 val = I915_READ(CNL_PORT_CL1CM_DW5);
2855 val |= CL_POWER_DOWN_ENABLE;
2856 I915_WRITE(CNL_PORT_CL1CM_DW5, val);
2857
Imre Deakb38131f2017-06-29 18:37:02 +03002858 /*
2859 * 4. Enable Power Well 1 (PG1).
2860 * The AUX IO power wells will be enabled on demand.
2861 */
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07002862 mutex_lock(&power_domains->lock);
2863 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
2864 intel_power_well_enable(dev_priv, well);
2865 mutex_unlock(&power_domains->lock);
2866
2867 /* 5. Enable CD clock */
2868 cnl_init_cdclk(dev_priv);
2869
2870 /* 6. Enable DBUF */
2871 gen9_dbuf_enable(dev_priv);
2872}
2873
2874#undef CNL_PROCMON_IDX
2875#undef NUM_CNL_PROCMON
2876
2877static void cnl_display_core_uninit(struct drm_i915_private *dev_priv)
2878{
2879 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2880 struct i915_power_well *well;
2881 u32 val;
2882
2883 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
2884
2885 /* 1. Disable all display engine functions -> aready done */
2886
2887 /* 2. Disable DBUF */
2888 gen9_dbuf_disable(dev_priv);
2889
2890 /* 3. Disable CD clock */
2891 cnl_uninit_cdclk(dev_priv);
2892
Imre Deakb38131f2017-06-29 18:37:02 +03002893 /*
2894 * 4. Disable Power Well 1 (PG1).
2895 * The AUX IO power wells are toggled on demand, so they are already
2896 * disabled at this point.
2897 */
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07002898 mutex_lock(&power_domains->lock);
2899 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
2900 intel_power_well_disable(dev_priv, well);
2901 mutex_unlock(&power_domains->lock);
2902
Imre Deak846c6b22017-06-29 18:36:58 +03002903 usleep_range(10, 30); /* 10 us delay per Bspec */
2904
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07002905 /* 5. Disable Comp */
2906 val = I915_READ(CHICKEN_MISC_2);
2907 val |= COMP_PWR_DOWN;
2908 I915_WRITE(CHICKEN_MISC_2, val);
2909}
2910
Ville Syrjälä70722462015-04-10 18:21:28 +03002911static void chv_phy_control_init(struct drm_i915_private *dev_priv)
2912{
2913 struct i915_power_well *cmn_bc =
2914 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_BC);
2915 struct i915_power_well *cmn_d =
2916 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_D);
2917
2918 /*
2919 * DISPLAY_PHY_CONTROL can get corrupted if read. As a
2920 * workaround never ever read DISPLAY_PHY_CONTROL, and
2921 * instead maintain a shadow copy ourselves. Use the actual
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002922 * power well state and lane status to reconstruct the
2923 * expected initial value.
Ville Syrjälä70722462015-04-10 18:21:28 +03002924 */
2925 dev_priv->chv_phy_control =
Ville Syrjäläbc284542015-05-26 20:22:38 +03002926 PHY_LDO_SEQ_DELAY(PHY_LDO_DELAY_600NS, DPIO_PHY0) |
2927 PHY_LDO_SEQ_DELAY(PHY_LDO_DELAY_600NS, DPIO_PHY1) |
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002928 PHY_CH_POWER_MODE(PHY_CH_DEEP_PSR, DPIO_PHY0, DPIO_CH0) |
2929 PHY_CH_POWER_MODE(PHY_CH_DEEP_PSR, DPIO_PHY0, DPIO_CH1) |
2930 PHY_CH_POWER_MODE(PHY_CH_DEEP_PSR, DPIO_PHY1, DPIO_CH0);
2931
2932 /*
2933 * If all lanes are disabled we leave the override disabled
2934 * with all power down bits cleared to match the state we
2935 * would use after disabling the port. Otherwise enable the
2936 * override and set the lane powerdown bits accding to the
2937 * current lane status.
2938 */
2939 if (cmn_bc->ops->is_enabled(dev_priv, cmn_bc)) {
2940 uint32_t status = I915_READ(DPLL(PIPE_A));
2941 unsigned int mask;
2942
2943 mask = status & DPLL_PORTB_READY_MASK;
2944 if (mask == 0xf)
2945 mask = 0x0;
2946 else
2947 dev_priv->chv_phy_control |=
2948 PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY0, DPIO_CH0);
2949
2950 dev_priv->chv_phy_control |=
2951 PHY_CH_POWER_DOWN_OVRD(mask, DPIO_PHY0, DPIO_CH0);
2952
2953 mask = (status & DPLL_PORTC_READY_MASK) >> 4;
2954 if (mask == 0xf)
2955 mask = 0x0;
2956 else
2957 dev_priv->chv_phy_control |=
2958 PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY0, DPIO_CH1);
2959
2960 dev_priv->chv_phy_control |=
2961 PHY_CH_POWER_DOWN_OVRD(mask, DPIO_PHY0, DPIO_CH1);
2962
Ville Syrjälä70722462015-04-10 18:21:28 +03002963 dev_priv->chv_phy_control |= PHY_COM_LANE_RESET_DEASSERT(DPIO_PHY0);
Ville Syrjälä3be60de2015-09-08 18:05:45 +03002964
2965 dev_priv->chv_phy_assert[DPIO_PHY0] = false;
2966 } else {
2967 dev_priv->chv_phy_assert[DPIO_PHY0] = true;
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002968 }
2969
2970 if (cmn_d->ops->is_enabled(dev_priv, cmn_d)) {
2971 uint32_t status = I915_READ(DPIO_PHY_STATUS);
2972 unsigned int mask;
2973
2974 mask = status & DPLL_PORTD_READY_MASK;
2975
2976 if (mask == 0xf)
2977 mask = 0x0;
2978 else
2979 dev_priv->chv_phy_control |=
2980 PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY1, DPIO_CH0);
2981
2982 dev_priv->chv_phy_control |=
2983 PHY_CH_POWER_DOWN_OVRD(mask, DPIO_PHY1, DPIO_CH0);
2984
Ville Syrjälä70722462015-04-10 18:21:28 +03002985 dev_priv->chv_phy_control |= PHY_COM_LANE_RESET_DEASSERT(DPIO_PHY1);
Ville Syrjälä3be60de2015-09-08 18:05:45 +03002986
2987 dev_priv->chv_phy_assert[DPIO_PHY1] = false;
2988 } else {
2989 dev_priv->chv_phy_assert[DPIO_PHY1] = true;
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002990 }
2991
2992 I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
2993
2994 DRM_DEBUG_KMS("Initial PHY_CONTROL=0x%08x\n",
2995 dev_priv->chv_phy_control);
Ville Syrjälä70722462015-04-10 18:21:28 +03002996}
2997
Daniel Vetter9c065a72014-09-30 10:56:38 +02002998static void vlv_cmnlane_wa(struct drm_i915_private *dev_priv)
2999{
3000 struct i915_power_well *cmn =
3001 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_BC);
3002 struct i915_power_well *disp2d =
3003 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DISP2D);
3004
Daniel Vetter9c065a72014-09-30 10:56:38 +02003005 /* If the display might be already active skip this */
Ville Syrjälä5d93a6e2014-10-16 20:52:33 +03003006 if (cmn->ops->is_enabled(dev_priv, cmn) &&
3007 disp2d->ops->is_enabled(dev_priv, disp2d) &&
Daniel Vetter9c065a72014-09-30 10:56:38 +02003008 I915_READ(DPIO_CTL) & DPIO_CMNRST)
3009 return;
3010
3011 DRM_DEBUG_KMS("toggling display PHY side reset\n");
3012
3013 /* cmnlane needs DPLL registers */
3014 disp2d->ops->enable(dev_priv, disp2d);
3015
3016 /*
3017 * From VLV2A0_DP_eDP_HDMI_DPIO_driver_vbios_notes_11.docx:
3018 * Need to assert and de-assert PHY SB reset by gating the
3019 * common lane power, then un-gating it.
3020 * Simply ungating isn't enough to reset the PHY enough to get
3021 * ports and lanes running.
3022 */
3023 cmn->ops->disable(dev_priv, cmn);
3024}
3025
Daniel Vettere4e76842014-09-30 10:56:42 +02003026/**
3027 * intel_power_domains_init_hw - initialize hardware power domain state
3028 * @dev_priv: i915 device instance
Tvrtko Ursulin14bb2c12016-06-03 14:02:17 +01003029 * @resume: Called from resume code paths or not
Daniel Vettere4e76842014-09-30 10:56:42 +02003030 *
3031 * This function initializes the hardware power domain state and enables all
Imre Deak8d8c3862017-02-17 17:39:46 +02003032 * power wells belonging to the INIT power domain. Power wells in other
3033 * domains (and not in the INIT domain) are referenced or disabled during the
3034 * modeset state HW readout. After that the reference count of each power well
3035 * must match its HW enabled state, see intel_power_domains_verify_state().
Daniel Vettere4e76842014-09-30 10:56:42 +02003036 */
Imre Deak73dfc222015-11-17 17:33:53 +02003037void intel_power_domains_init_hw(struct drm_i915_private *dev_priv, bool resume)
Daniel Vetter9c065a72014-09-30 10:56:38 +02003038{
Daniel Vetter9c065a72014-09-30 10:56:38 +02003039 struct i915_power_domains *power_domains = &dev_priv->power_domains;
3040
3041 power_domains->initializing = true;
3042
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07003043 if (IS_CANNONLAKE(dev_priv)) {
3044 cnl_display_core_init(dev_priv, resume);
3045 } else if (IS_GEN9_BC(dev_priv)) {
Imre Deak73dfc222015-11-17 17:33:53 +02003046 skl_display_core_init(dev_priv, resume);
Ander Conselvan de Oliveirab817c442016-12-02 10:23:56 +02003047 } else if (IS_GEN9_LP(dev_priv)) {
Imre Deakd7d7c9e2016-04-01 16:02:42 +03003048 bxt_display_core_init(dev_priv, resume);
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01003049 } else if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä770effb2015-07-08 23:45:51 +03003050 mutex_lock(&power_domains->lock);
Ville Syrjälä70722462015-04-10 18:21:28 +03003051 chv_phy_control_init(dev_priv);
Ville Syrjälä770effb2015-07-08 23:45:51 +03003052 mutex_unlock(&power_domains->lock);
Tvrtko Ursulin11a914c2016-10-13 11:03:08 +01003053 } else if (IS_VALLEYVIEW(dev_priv)) {
Daniel Vetter9c065a72014-09-30 10:56:38 +02003054 mutex_lock(&power_domains->lock);
3055 vlv_cmnlane_wa(dev_priv);
3056 mutex_unlock(&power_domains->lock);
3057 }
3058
3059 /* For now, we need the power well to be always enabled. */
3060 intel_display_set_init_power(dev_priv, true);
Imre Deakd314cd42015-11-17 17:44:23 +02003061 /* Disable power support if the user asked so. */
3062 if (!i915.disable_power_well)
3063 intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
Imre Deak30eade12015-11-04 19:24:13 +02003064 intel_power_domains_sync_hw(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02003065 power_domains->initializing = false;
3066}
3067
Daniel Vettere4e76842014-09-30 10:56:42 +02003068/**
Imre Deak73dfc222015-11-17 17:33:53 +02003069 * intel_power_domains_suspend - suspend power domain state
3070 * @dev_priv: i915 device instance
3071 *
3072 * This function prepares the hardware power domain state before entering
3073 * system suspend. It must be paired with intel_power_domains_init_hw().
3074 */
3075void intel_power_domains_suspend(struct drm_i915_private *dev_priv)
3076{
Imre Deakd314cd42015-11-17 17:44:23 +02003077 /*
3078 * Even if power well support was disabled we still want to disable
3079 * power wells while we are system suspended.
3080 */
3081 if (!i915.disable_power_well)
3082 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
Imre Deak2622d792016-02-29 22:49:02 +02003083
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07003084 if (IS_CANNONLAKE(dev_priv))
3085 cnl_display_core_uninit(dev_priv);
3086 else if (IS_GEN9_BC(dev_priv))
Imre Deak2622d792016-02-29 22:49:02 +02003087 skl_display_core_uninit(dev_priv);
Ander Conselvan de Oliveirab817c442016-12-02 10:23:56 +02003088 else if (IS_GEN9_LP(dev_priv))
Imre Deakd7d7c9e2016-04-01 16:02:42 +03003089 bxt_display_core_uninit(dev_priv);
Imre Deak73dfc222015-11-17 17:33:53 +02003090}
3091
Imre Deak8d8c3862017-02-17 17:39:46 +02003092static void intel_power_domains_dump_info(struct drm_i915_private *dev_priv)
3093{
3094 struct i915_power_domains *power_domains = &dev_priv->power_domains;
3095 struct i915_power_well *power_well;
3096
3097 for_each_power_well(dev_priv, power_well) {
3098 enum intel_display_power_domain domain;
3099
3100 DRM_DEBUG_DRIVER("%-25s %d\n",
3101 power_well->name, power_well->count);
3102
3103 for_each_power_domain(domain, power_well->domains)
3104 DRM_DEBUG_DRIVER(" %-23s %d\n",
3105 intel_display_power_domain_str(domain),
3106 power_domains->domain_use_count[domain]);
3107 }
3108}
3109
3110/**
3111 * intel_power_domains_verify_state - verify the HW/SW state for all power wells
3112 * @dev_priv: i915 device instance
3113 *
3114 * Verify if the reference count of each power well matches its HW enabled
3115 * state and the total refcount of the domains it belongs to. This must be
3116 * called after modeset HW state sanitization, which is responsible for
3117 * acquiring reference counts for any power wells in use and disabling the
3118 * ones left on by BIOS but not required by any active output.
3119 */
3120void intel_power_domains_verify_state(struct drm_i915_private *dev_priv)
3121{
3122 struct i915_power_domains *power_domains = &dev_priv->power_domains;
3123 struct i915_power_well *power_well;
3124 bool dump_domain_info;
3125
3126 mutex_lock(&power_domains->lock);
3127
3128 dump_domain_info = false;
3129 for_each_power_well(dev_priv, power_well) {
3130 enum intel_display_power_domain domain;
3131 int domains_count;
3132 bool enabled;
3133
3134 /*
3135 * Power wells not belonging to any domain (like the MISC_IO
3136 * and PW1 power wells) are under FW control, so ignore them,
3137 * since their state can change asynchronously.
3138 */
3139 if (!power_well->domains)
3140 continue;
3141
3142 enabled = power_well->ops->is_enabled(dev_priv, power_well);
3143 if ((power_well->count || power_well->always_on) != enabled)
3144 DRM_ERROR("power well %s state mismatch (refcount %d/enabled %d)",
3145 power_well->name, power_well->count, enabled);
3146
3147 domains_count = 0;
3148 for_each_power_domain(domain, power_well->domains)
3149 domains_count += power_domains->domain_use_count[domain];
3150
3151 if (power_well->count != domains_count) {
3152 DRM_ERROR("power well %s refcount/domain refcount mismatch "
3153 "(refcount %d/domains refcount %d)\n",
3154 power_well->name, power_well->count,
3155 domains_count);
3156 dump_domain_info = true;
3157 }
3158 }
3159
3160 if (dump_domain_info) {
3161 static bool dumped;
3162
3163 if (!dumped) {
3164 intel_power_domains_dump_info(dev_priv);
3165 dumped = true;
3166 }
3167 }
3168
3169 mutex_unlock(&power_domains->lock);
3170}
3171
Imre Deak73dfc222015-11-17 17:33:53 +02003172/**
Daniel Vettere4e76842014-09-30 10:56:42 +02003173 * intel_runtime_pm_get - grab a runtime pm reference
3174 * @dev_priv: i915 device instance
3175 *
3176 * This function grabs a device-level runtime pm reference (mostly used for GEM
3177 * code to ensure the GTT or GT is on) and ensures that it is powered up.
3178 *
3179 * Any runtime pm reference obtained by this function must have a symmetric
3180 * call to intel_runtime_pm_put() to release the reference again.
3181 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02003182void intel_runtime_pm_get(struct drm_i915_private *dev_priv)
3183{
David Weinehall52a05c32016-08-22 13:32:44 +03003184 struct pci_dev *pdev = dev_priv->drm.pdev;
3185 struct device *kdev = &pdev->dev;
Imre Deakf5073822017-03-28 12:38:55 +03003186 int ret;
Daniel Vetter9c065a72014-09-30 10:56:38 +02003187
Imre Deakf5073822017-03-28 12:38:55 +03003188 ret = pm_runtime_get_sync(kdev);
3189 WARN_ONCE(ret < 0, "pm_runtime_get_sync() failed: %d\n", ret);
Imre Deak1f814da2015-12-16 02:52:19 +02003190
3191 atomic_inc(&dev_priv->pm.wakeref_count);
Imre Deakc9b88462015-12-15 20:10:34 +02003192 assert_rpm_wakelock_held(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02003193}
3194
Daniel Vettere4e76842014-09-30 10:56:42 +02003195/**
Imre Deak09731282016-02-17 14:17:42 +02003196 * intel_runtime_pm_get_if_in_use - grab a runtime pm reference if device in use
3197 * @dev_priv: i915 device instance
3198 *
3199 * This function grabs a device-level runtime pm reference if the device is
3200 * already in use and ensures that it is powered up.
3201 *
3202 * Any runtime pm reference obtained by this function must have a symmetric
3203 * call to intel_runtime_pm_put() to release the reference again.
3204 */
3205bool intel_runtime_pm_get_if_in_use(struct drm_i915_private *dev_priv)
3206{
David Weinehall52a05c32016-08-22 13:32:44 +03003207 struct pci_dev *pdev = dev_priv->drm.pdev;
3208 struct device *kdev = &pdev->dev;
Imre Deak09731282016-02-17 14:17:42 +02003209
Chris Wilson135dc792016-02-25 21:10:28 +00003210 if (IS_ENABLED(CONFIG_PM)) {
David Weinehallc49d13e2016-08-22 13:32:42 +03003211 int ret = pm_runtime_get_if_in_use(kdev);
Imre Deak09731282016-02-17 14:17:42 +02003212
Chris Wilson135dc792016-02-25 21:10:28 +00003213 /*
3214 * In cases runtime PM is disabled by the RPM core and we get
3215 * an -EINVAL return value we are not supposed to call this
3216 * function, since the power state is undefined. This applies
3217 * atm to the late/early system suspend/resume handlers.
3218 */
Imre Deakf5073822017-03-28 12:38:55 +03003219 WARN_ONCE(ret < 0,
3220 "pm_runtime_get_if_in_use() failed: %d\n", ret);
Chris Wilson135dc792016-02-25 21:10:28 +00003221 if (ret <= 0)
3222 return false;
3223 }
Imre Deak09731282016-02-17 14:17:42 +02003224
3225 atomic_inc(&dev_priv->pm.wakeref_count);
3226 assert_rpm_wakelock_held(dev_priv);
3227
3228 return true;
3229}
3230
3231/**
Daniel Vettere4e76842014-09-30 10:56:42 +02003232 * intel_runtime_pm_get_noresume - grab a runtime pm reference
3233 * @dev_priv: i915 device instance
3234 *
3235 * This function grabs a device-level runtime pm reference (mostly used for GEM
3236 * code to ensure the GTT or GT is on).
3237 *
3238 * It will _not_ power up the device but instead only check that it's powered
3239 * on. Therefore it is only valid to call this functions from contexts where
3240 * the device is known to be powered up and where trying to power it up would
3241 * result in hilarity and deadlocks. That pretty much means only the system
3242 * suspend/resume code where this is used to grab runtime pm references for
3243 * delayed setup down in work items.
3244 *
3245 * Any runtime pm reference obtained by this function must have a symmetric
3246 * call to intel_runtime_pm_put() to release the reference again.
3247 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02003248void intel_runtime_pm_get_noresume(struct drm_i915_private *dev_priv)
3249{
David Weinehall52a05c32016-08-22 13:32:44 +03003250 struct pci_dev *pdev = dev_priv->drm.pdev;
3251 struct device *kdev = &pdev->dev;
Daniel Vetter9c065a72014-09-30 10:56:38 +02003252
Imre Deakc9b88462015-12-15 20:10:34 +02003253 assert_rpm_wakelock_held(dev_priv);
David Weinehallc49d13e2016-08-22 13:32:42 +03003254 pm_runtime_get_noresume(kdev);
Imre Deak1f814da2015-12-16 02:52:19 +02003255
3256 atomic_inc(&dev_priv->pm.wakeref_count);
Daniel Vetter9c065a72014-09-30 10:56:38 +02003257}
3258
Daniel Vettere4e76842014-09-30 10:56:42 +02003259/**
3260 * intel_runtime_pm_put - release a runtime pm reference
3261 * @dev_priv: i915 device instance
3262 *
3263 * This function drops the device-level runtime pm reference obtained by
3264 * intel_runtime_pm_get() and might power down the corresponding
3265 * hardware block right away if this is the last reference.
3266 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02003267void intel_runtime_pm_put(struct drm_i915_private *dev_priv)
3268{
David Weinehall52a05c32016-08-22 13:32:44 +03003269 struct pci_dev *pdev = dev_priv->drm.pdev;
3270 struct device *kdev = &pdev->dev;
Daniel Vetter9c065a72014-09-30 10:56:38 +02003271
Imre Deak542db3c2015-12-15 20:10:36 +02003272 assert_rpm_wakelock_held(dev_priv);
Chris Wilson2eedfc72016-10-24 13:42:17 +01003273 atomic_dec(&dev_priv->pm.wakeref_count);
Imre Deak1f814da2015-12-16 02:52:19 +02003274
David Weinehallc49d13e2016-08-22 13:32:42 +03003275 pm_runtime_mark_last_busy(kdev);
3276 pm_runtime_put_autosuspend(kdev);
Daniel Vetter9c065a72014-09-30 10:56:38 +02003277}
3278
Daniel Vettere4e76842014-09-30 10:56:42 +02003279/**
3280 * intel_runtime_pm_enable - enable runtime pm
3281 * @dev_priv: i915 device instance
3282 *
3283 * This function enables runtime pm at the end of the driver load sequence.
3284 *
3285 * Note that this function does currently not enable runtime pm for the
3286 * subordinate display power domains. That is only done on the first modeset
3287 * using intel_display_set_init_power().
3288 */
Daniel Vetterf458ebb2014-09-30 10:56:39 +02003289void intel_runtime_pm_enable(struct drm_i915_private *dev_priv)
Daniel Vetter9c065a72014-09-30 10:56:38 +02003290{
David Weinehall52a05c32016-08-22 13:32:44 +03003291 struct pci_dev *pdev = dev_priv->drm.pdev;
David Weinehall52a05c32016-08-22 13:32:44 +03003292 struct device *kdev = &pdev->dev;
Daniel Vetter9c065a72014-09-30 10:56:38 +02003293
David Weinehallc49d13e2016-08-22 13:32:42 +03003294 pm_runtime_set_autosuspend_delay(kdev, 10000); /* 10s */
3295 pm_runtime_mark_last_busy(kdev);
Imre Deakcbc68dc2015-12-17 19:04:33 +02003296
Imre Deak25b181b2015-12-17 13:44:56 +02003297 /*
3298 * Take a permanent reference to disable the RPM functionality and drop
3299 * it only when unloading the driver. Use the low level get/put helpers,
3300 * so the driver's own RPM reference tracking asserts also work on
3301 * platforms without RPM support.
3302 */
Tvrtko Ursulin6772ffe2016-10-13 11:02:55 +01003303 if (!HAS_RUNTIME_PM(dev_priv)) {
Imre Deakf5073822017-03-28 12:38:55 +03003304 int ret;
3305
David Weinehallc49d13e2016-08-22 13:32:42 +03003306 pm_runtime_dont_use_autosuspend(kdev);
Imre Deakf5073822017-03-28 12:38:55 +03003307 ret = pm_runtime_get_sync(kdev);
3308 WARN(ret < 0, "pm_runtime_get_sync() failed: %d\n", ret);
Imre Deakcbc68dc2015-12-17 19:04:33 +02003309 } else {
David Weinehallc49d13e2016-08-22 13:32:42 +03003310 pm_runtime_use_autosuspend(kdev);
Imre Deakcbc68dc2015-12-17 19:04:33 +02003311 }
Daniel Vetter9c065a72014-09-30 10:56:38 +02003312
Imre Deakaabee1b2015-12-15 20:10:29 +02003313 /*
3314 * The core calls the driver load handler with an RPM reference held.
3315 * We drop that here and will reacquire it during unloading in
3316 * intel_power_domains_fini().
3317 */
David Weinehallc49d13e2016-08-22 13:32:42 +03003318 pm_runtime_put_autosuspend(kdev);
Daniel Vetter9c065a72014-09-30 10:56:38 +02003319}