blob: 00ae25b5966150d00a67983fcd6c9e06b6ae9f2d [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{
402 bool is_enabled, enable_requested;
403 uint32_t tmp;
404
405 tmp = I915_READ(HSW_PWR_WELL_DRIVER);
406 is_enabled = tmp & HSW_PWR_WELL_STATE_ENABLED;
407 enable_requested = tmp & HSW_PWR_WELL_ENABLE_REQUEST;
408
409 if (enable) {
410 if (!enable_requested)
411 I915_WRITE(HSW_PWR_WELL_DRIVER,
412 HSW_PWR_WELL_ENABLE_REQUEST);
413
414 if (!is_enabled) {
415 DRM_DEBUG_KMS("Enabling power well\n");
Chris Wilson2c2ccc32016-06-30 15:33:32 +0100416 if (intel_wait_for_register(dev_priv,
417 HSW_PWR_WELL_DRIVER,
418 HSW_PWR_WELL_STATE_ENABLED,
419 HSW_PWR_WELL_STATE_ENABLED,
420 20))
Daniel Vetter9c065a72014-09-30 10:56:38 +0200421 DRM_ERROR("Timeout enabling power well\n");
Paulo Zanoni6d729bf2014-10-07 16:11:11 -0300422 hsw_power_well_post_enable(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200423 }
424
Daniel Vetter9c065a72014-09-30 10:56:38 +0200425 } else {
426 if (enable_requested) {
Ville Syrjäläaae8ba82016-02-19 20:47:30 +0200427 hsw_power_well_pre_disable(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200428 I915_WRITE(HSW_PWR_WELL_DRIVER, 0);
429 POSTING_READ(HSW_PWR_WELL_DRIVER);
430 DRM_DEBUG_KMS("Requesting to disable the power well\n");
431 }
432 }
433}
434
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000435#define SKL_DISPLAY_POWERWELL_2_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200436 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
437 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
438 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
439 BIT_ULL(POWER_DOMAIN_PIPE_C) | \
440 BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
441 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
442 BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
443 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
444 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
445 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_LANES) | \
446 BIT_ULL(POWER_DOMAIN_PORT_DDI_E_LANES) | \
447 BIT_ULL(POWER_DOMAIN_AUX_B) | \
448 BIT_ULL(POWER_DOMAIN_AUX_C) | \
449 BIT_ULL(POWER_DOMAIN_AUX_D) | \
450 BIT_ULL(POWER_DOMAIN_AUDIO) | \
451 BIT_ULL(POWER_DOMAIN_VGA) | \
452 BIT_ULL(POWER_DOMAIN_INIT))
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +0200453#define SKL_DISPLAY_DDI_IO_A_E_POWER_DOMAINS ( \
454 BIT_ULL(POWER_DOMAIN_PORT_DDI_A_IO) | \
455 BIT_ULL(POWER_DOMAIN_PORT_DDI_E_IO) | \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200456 BIT_ULL(POWER_DOMAIN_INIT))
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +0200457#define SKL_DISPLAY_DDI_IO_B_POWER_DOMAINS ( \
458 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_IO) | \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200459 BIT_ULL(POWER_DOMAIN_INIT))
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +0200460#define SKL_DISPLAY_DDI_IO_C_POWER_DOMAINS ( \
461 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_IO) | \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200462 BIT_ULL(POWER_DOMAIN_INIT))
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +0200463#define SKL_DISPLAY_DDI_IO_D_POWER_DOMAINS ( \
464 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_IO) | \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200465 BIT_ULL(POWER_DOMAIN_INIT))
Patrik Jakobsson9f836f92015-11-16 16:20:01 +0100466#define SKL_DISPLAY_DC_OFF_POWER_DOMAINS ( \
467 SKL_DISPLAY_POWERWELL_2_POWER_DOMAINS | \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200468 BIT_ULL(POWER_DOMAIN_MODESET) | \
469 BIT_ULL(POWER_DOMAIN_AUX_A) | \
470 BIT_ULL(POWER_DOMAIN_INIT))
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000471
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +0530472#define BXT_DISPLAY_POWERWELL_2_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200473 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
474 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
475 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
476 BIT_ULL(POWER_DOMAIN_PIPE_C) | \
477 BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
478 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
479 BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
480 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
481 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
482 BIT_ULL(POWER_DOMAIN_AUX_B) | \
483 BIT_ULL(POWER_DOMAIN_AUX_C) | \
484 BIT_ULL(POWER_DOMAIN_AUDIO) | \
485 BIT_ULL(POWER_DOMAIN_VGA) | \
486 BIT_ULL(POWER_DOMAIN_GMBUS) | \
487 BIT_ULL(POWER_DOMAIN_INIT))
Patrik Jakobsson9f836f92015-11-16 16:20:01 +0100488#define BXT_DISPLAY_DC_OFF_POWER_DOMAINS ( \
489 BXT_DISPLAY_POWERWELL_2_POWER_DOMAINS | \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200490 BIT_ULL(POWER_DOMAIN_MODESET) | \
491 BIT_ULL(POWER_DOMAIN_AUX_A) | \
492 BIT_ULL(POWER_DOMAIN_INIT))
Imre Deak9c8d0b82016-06-13 16:44:34 +0300493#define BXT_DPIO_CMN_A_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200494 BIT_ULL(POWER_DOMAIN_PORT_DDI_A_LANES) | \
495 BIT_ULL(POWER_DOMAIN_AUX_A) | \
496 BIT_ULL(POWER_DOMAIN_INIT))
Imre Deak9c8d0b82016-06-13 16:44:34 +0300497#define BXT_DPIO_CMN_BC_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200498 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
499 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
500 BIT_ULL(POWER_DOMAIN_AUX_B) | \
501 BIT_ULL(POWER_DOMAIN_AUX_C) | \
502 BIT_ULL(POWER_DOMAIN_INIT))
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +0530503
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +0200504#define GLK_DISPLAY_POWERWELL_2_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200505 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
506 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
507 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
508 BIT_ULL(POWER_DOMAIN_PIPE_C) | \
509 BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
510 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
511 BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
512 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
513 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
514 BIT_ULL(POWER_DOMAIN_AUX_B) | \
515 BIT_ULL(POWER_DOMAIN_AUX_C) | \
516 BIT_ULL(POWER_DOMAIN_AUDIO) | \
517 BIT_ULL(POWER_DOMAIN_VGA) | \
518 BIT_ULL(POWER_DOMAIN_INIT))
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +0200519#define GLK_DISPLAY_DDI_IO_A_POWER_DOMAINS ( \
520 BIT_ULL(POWER_DOMAIN_PORT_DDI_A_IO))
521#define GLK_DISPLAY_DDI_IO_B_POWER_DOMAINS ( \
522 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_IO))
523#define GLK_DISPLAY_DDI_IO_C_POWER_DOMAINS ( \
524 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_IO))
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +0200525#define GLK_DPIO_CMN_A_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200526 BIT_ULL(POWER_DOMAIN_PORT_DDI_A_LANES) | \
527 BIT_ULL(POWER_DOMAIN_AUX_A) | \
528 BIT_ULL(POWER_DOMAIN_INIT))
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +0200529#define GLK_DPIO_CMN_B_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200530 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
531 BIT_ULL(POWER_DOMAIN_AUX_B) | \
532 BIT_ULL(POWER_DOMAIN_INIT))
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +0200533#define GLK_DPIO_CMN_C_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200534 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
535 BIT_ULL(POWER_DOMAIN_AUX_C) | \
536 BIT_ULL(POWER_DOMAIN_INIT))
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +0200537#define GLK_DISPLAY_AUX_A_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200538 BIT_ULL(POWER_DOMAIN_AUX_A) | \
539 BIT_ULL(POWER_DOMAIN_INIT))
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +0200540#define GLK_DISPLAY_AUX_B_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200541 BIT_ULL(POWER_DOMAIN_AUX_B) | \
542 BIT_ULL(POWER_DOMAIN_INIT))
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +0200543#define GLK_DISPLAY_AUX_C_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200544 BIT_ULL(POWER_DOMAIN_AUX_C) | \
545 BIT_ULL(POWER_DOMAIN_INIT))
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +0200546#define GLK_DISPLAY_DC_OFF_POWER_DOMAINS ( \
547 GLK_DISPLAY_POWERWELL_2_POWER_DOMAINS | \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200548 BIT_ULL(POWER_DOMAIN_MODESET) | \
549 BIT_ULL(POWER_DOMAIN_AUX_A) | \
550 BIT_ULL(POWER_DOMAIN_INIT))
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +0200551
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -0700552#define CNL_DISPLAY_POWERWELL_2_POWER_DOMAINS ( \
553 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
554 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
555 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
556 BIT_ULL(POWER_DOMAIN_PIPE_C) | \
557 BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
558 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
559 BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
560 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
561 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
562 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_LANES) | \
563 BIT_ULL(POWER_DOMAIN_PORT_DDI_E_LANES) | \
564 BIT_ULL(POWER_DOMAIN_AUX_B) | \
565 BIT_ULL(POWER_DOMAIN_AUX_C) | \
566 BIT_ULL(POWER_DOMAIN_AUX_D) | \
567 BIT_ULL(POWER_DOMAIN_AUDIO) | \
568 BIT_ULL(POWER_DOMAIN_VGA) | \
569 BIT_ULL(POWER_DOMAIN_INIT))
570#define CNL_DISPLAY_DDI_A_IO_POWER_DOMAINS ( \
571 BIT_ULL(POWER_DOMAIN_PORT_DDI_A_IO) | \
572 BIT_ULL(POWER_DOMAIN_PORT_DDI_E_IO) | \
573 BIT_ULL(POWER_DOMAIN_INIT))
574#define CNL_DISPLAY_DDI_B_IO_POWER_DOMAINS ( \
575 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_IO) | \
576 BIT_ULL(POWER_DOMAIN_INIT))
577#define CNL_DISPLAY_DDI_C_IO_POWER_DOMAINS ( \
578 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_IO) | \
579 BIT_ULL(POWER_DOMAIN_INIT))
580#define CNL_DISPLAY_DDI_D_IO_POWER_DOMAINS ( \
581 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_IO) | \
582 BIT_ULL(POWER_DOMAIN_INIT))
583#define CNL_DISPLAY_AUX_A_POWER_DOMAINS ( \
584 BIT_ULL(POWER_DOMAIN_AUX_A) | \
585 BIT_ULL(POWER_DOMAIN_INIT))
586#define CNL_DISPLAY_AUX_B_POWER_DOMAINS ( \
587 BIT_ULL(POWER_DOMAIN_AUX_B) | \
588 BIT_ULL(POWER_DOMAIN_INIT))
589#define CNL_DISPLAY_AUX_C_POWER_DOMAINS ( \
590 BIT_ULL(POWER_DOMAIN_AUX_C) | \
591 BIT_ULL(POWER_DOMAIN_INIT))
592#define CNL_DISPLAY_AUX_D_POWER_DOMAINS ( \
593 BIT_ULL(POWER_DOMAIN_AUX_D) | \
594 BIT_ULL(POWER_DOMAIN_INIT))
595#define CNL_DISPLAY_DC_OFF_POWER_DOMAINS ( \
596 CNL_DISPLAY_POWERWELL_2_POWER_DOMAINS | \
597 BIT_ULL(POWER_DOMAIN_MODESET) | \
598 BIT_ULL(POWER_DOMAIN_AUX_A) | \
599 BIT_ULL(POWER_DOMAIN_INIT))
600
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530601static void assert_can_enable_dc9(struct drm_i915_private *dev_priv)
602{
Imre Deakbfcdabe2016-04-01 16:02:37 +0300603 WARN_ONCE((I915_READ(DC_STATE_EN) & DC_STATE_EN_DC9),
604 "DC9 already programmed to be enabled.\n");
605 WARN_ONCE(I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC5,
606 "DC5 still not disabled to enable DC9.\n");
Imre Deake8a3a2a2017-06-29 18:37:00 +0300607 WARN_ONCE(I915_READ(HSW_PWR_WELL_DRIVER) &
608 SKL_POWER_WELL_REQ(SKL_DISP_PW_2),
609 "Power well 2 on.\n");
Imre Deakbfcdabe2016-04-01 16:02:37 +0300610 WARN_ONCE(intel_irqs_enabled(dev_priv),
611 "Interrupts not disabled yet.\n");
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530612
613 /*
614 * TODO: check for the following to verify the conditions to enter DC9
615 * state are satisfied:
616 * 1] Check relevant display engine registers to verify if mode set
617 * disable sequence was followed.
618 * 2] Check if display uninitialize sequence is initialized.
619 */
620}
621
622static void assert_can_disable_dc9(struct drm_i915_private *dev_priv)
623{
Imre Deakbfcdabe2016-04-01 16:02:37 +0300624 WARN_ONCE(intel_irqs_enabled(dev_priv),
625 "Interrupts not disabled yet.\n");
626 WARN_ONCE(I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC5,
627 "DC5 still not disabled.\n");
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530628
629 /*
630 * TODO: check for the following to verify DC9 state was indeed
631 * entered before programming to disable it:
632 * 1] Check relevant display engine registers to verify if mode
633 * set disable sequence was followed.
634 * 2] Check if display uninitialize sequence is initialized.
635 */
636}
637
Mika Kuoppala779cb5d2016-02-18 17:58:09 +0200638static void gen9_write_dc_state(struct drm_i915_private *dev_priv,
639 u32 state)
640{
641 int rewrites = 0;
642 int rereads = 0;
643 u32 v;
644
645 I915_WRITE(DC_STATE_EN, state);
646
647 /* It has been observed that disabling the dc6 state sometimes
648 * doesn't stick and dmc keeps returning old value. Make sure
649 * the write really sticks enough times and also force rewrite until
650 * we are confident that state is exactly what we want.
651 */
652 do {
653 v = I915_READ(DC_STATE_EN);
654
655 if (v != state) {
656 I915_WRITE(DC_STATE_EN, state);
657 rewrites++;
658 rereads = 0;
659 } else if (rereads++ > 5) {
660 break;
661 }
662
663 } while (rewrites < 100);
664
665 if (v != state)
666 DRM_ERROR("Writing dc state to 0x%x failed, now 0x%x\n",
667 state, v);
668
669 /* Most of the times we need one retry, avoid spam */
670 if (rewrites > 1)
671 DRM_DEBUG_KMS("Rewrote dc state to 0x%x %d times\n",
672 state, rewrites);
673}
674
Imre Deakda2f41d2016-04-20 20:27:56 +0300675static u32 gen9_dc_mask(struct drm_i915_private *dev_priv)
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530676{
Imre Deakda2f41d2016-04-20 20:27:56 +0300677 u32 mask;
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530678
Imre Deak13ae3a02015-11-04 19:24:16 +0200679 mask = DC_STATE_EN_UPTO_DC5;
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200680 if (IS_GEN9_LP(dev_priv))
Imre Deak13ae3a02015-11-04 19:24:16 +0200681 mask |= DC_STATE_EN_DC9;
682 else
683 mask |= DC_STATE_EN_UPTO_DC6;
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530684
Imre Deakda2f41d2016-04-20 20:27:56 +0300685 return mask;
686}
687
688void gen9_sanitize_dc_state(struct drm_i915_private *dev_priv)
689{
690 u32 val;
691
692 val = I915_READ(DC_STATE_EN) & gen9_dc_mask(dev_priv);
693
694 DRM_DEBUG_KMS("Resetting DC state tracking from %02x to %02x\n",
695 dev_priv->csr.dc_state, val);
696 dev_priv->csr.dc_state = val;
697}
698
699static void gen9_set_dc_state(struct drm_i915_private *dev_priv, uint32_t state)
700{
701 uint32_t val;
702 uint32_t mask;
703
Imre Deaka37baf32016-02-29 22:49:03 +0200704 if (WARN_ON_ONCE(state & ~dev_priv->csr.allowed_dc_mask))
705 state &= dev_priv->csr.allowed_dc_mask;
Patrik Jakobsson443646c2015-11-16 15:01:06 +0100706
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530707 val = I915_READ(DC_STATE_EN);
Imre Deakda2f41d2016-04-20 20:27:56 +0300708 mask = gen9_dc_mask(dev_priv);
Imre Deak13ae3a02015-11-04 19:24:16 +0200709 DRM_DEBUG_KMS("Setting DC state from %02x to %02x\n",
710 val & mask, state);
Patrik Jakobsson832dba82016-02-18 17:21:11 +0200711
712 /* Check if DMC is ignoring our DC state requests */
713 if ((val & mask) != dev_priv->csr.dc_state)
714 DRM_ERROR("DC state mismatch (0x%x -> 0x%x)\n",
715 dev_priv->csr.dc_state, val & mask);
716
Imre Deak13ae3a02015-11-04 19:24:16 +0200717 val &= ~mask;
718 val |= state;
Mika Kuoppala779cb5d2016-02-18 17:58:09 +0200719
720 gen9_write_dc_state(dev_priv, val);
Patrik Jakobsson832dba82016-02-18 17:21:11 +0200721
722 dev_priv->csr.dc_state = val & mask;
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530723}
724
Imre Deak13ae3a02015-11-04 19:24:16 +0200725void bxt_enable_dc9(struct drm_i915_private *dev_priv)
726{
727 assert_can_enable_dc9(dev_priv);
728
729 DRM_DEBUG_KMS("Enabling DC9\n");
730
Imre Deak78597992016-06-16 16:37:20 +0300731 intel_power_sequencer_reset(dev_priv);
Imre Deak13ae3a02015-11-04 19:24:16 +0200732 gen9_set_dc_state(dev_priv, DC_STATE_EN_DC9);
733}
734
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530735void bxt_disable_dc9(struct drm_i915_private *dev_priv)
736{
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530737 assert_can_disable_dc9(dev_priv);
738
739 DRM_DEBUG_KMS("Disabling DC9\n");
740
Imre Deak13ae3a02015-11-04 19:24:16 +0200741 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
Imre Deak8090ba82016-08-10 14:07:33 +0300742
743 intel_pps_unlock_regs_wa(dev_priv);
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530744}
745
Daniel Vetteraf5fead2015-10-28 23:58:57 +0200746static void assert_csr_loaded(struct drm_i915_private *dev_priv)
747{
748 WARN_ONCE(!I915_READ(CSR_PROGRAM(0)),
749 "CSR program storage start is NULL\n");
750 WARN_ONCE(!I915_READ(CSR_SSP_BASE), "CSR SSP Base Not fine\n");
751 WARN_ONCE(!I915_READ(CSR_HTP_SKL), "CSR HTP Not fine\n");
752}
753
Suketu Shah5aefb232015-04-16 14:22:10 +0530754static void assert_can_enable_dc5(struct drm_i915_private *dev_priv)
Suketu Shahdc174302015-04-17 19:46:16 +0530755{
Suketu Shah5aefb232015-04-16 14:22:10 +0530756 bool pg2_enabled = intel_display_power_well_is_enabled(dev_priv,
757 SKL_DISP_PW_2);
758
Jesse Barnes6ff8ab02015-09-10 08:20:28 -0700759 WARN_ONCE(pg2_enabled, "PG2 not disabled to enable DC5.\n");
Suketu Shah5aefb232015-04-16 14:22:10 +0530760
Jesse Barnes6ff8ab02015-09-10 08:20:28 -0700761 WARN_ONCE((I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC5),
762 "DC5 already programmed to be enabled.\n");
Imre Deakc9b88462015-12-15 20:10:34 +0200763 assert_rpm_wakelock_held(dev_priv);
Suketu Shah5aefb232015-04-16 14:22:10 +0530764
765 assert_csr_loaded(dev_priv);
766}
767
Imre Deakf62c79b2016-04-20 20:27:57 +0300768void gen9_enable_dc5(struct drm_i915_private *dev_priv)
Suketu Shah5aefb232015-04-16 14:22:10 +0530769{
Suketu Shah5aefb232015-04-16 14:22:10 +0530770 assert_can_enable_dc5(dev_priv);
A.Sunil Kamath6b457d32015-04-16 14:22:09 +0530771
772 DRM_DEBUG_KMS("Enabling DC5\n");
773
Imre Deak13ae3a02015-11-04 19:24:16 +0200774 gen9_set_dc_state(dev_priv, DC_STATE_EN_UPTO_DC5);
Suketu Shahdc174302015-04-17 19:46:16 +0530775}
776
Suketu Shah93c7cb62015-04-16 14:22:13 +0530777static void assert_can_enable_dc6(struct drm_i915_private *dev_priv)
Suketu Shahf75a1982015-04-16 14:22:11 +0530778{
Jesse Barnes6ff8ab02015-09-10 08:20:28 -0700779 WARN_ONCE(I915_READ(UTIL_PIN_CTL) & UTIL_PIN_ENABLE,
780 "Backlight is not disabled.\n");
781 WARN_ONCE((I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC6),
782 "DC6 already programmed to be enabled.\n");
Suketu Shah93c7cb62015-04-16 14:22:13 +0530783
784 assert_csr_loaded(dev_priv);
785}
786
Animesh Manna0a9d2be2015-09-29 11:01:59 +0530787void skl_enable_dc6(struct drm_i915_private *dev_priv)
Suketu Shah93c7cb62015-04-16 14:22:13 +0530788{
Suketu Shah93c7cb62015-04-16 14:22:13 +0530789 assert_can_enable_dc6(dev_priv);
A.Sunil Kamath74b4f372015-04-16 14:22:12 +0530790
791 DRM_DEBUG_KMS("Enabling DC6\n");
792
Imre Deak13ae3a02015-11-04 19:24:16 +0200793 gen9_set_dc_state(dev_priv, DC_STATE_EN_UPTO_DC6);
794
Suketu Shahf75a1982015-04-16 14:22:11 +0530795}
796
Animesh Manna0a9d2be2015-09-29 11:01:59 +0530797void skl_disable_dc6(struct drm_i915_private *dev_priv)
Suketu Shahf75a1982015-04-16 14:22:11 +0530798{
A.Sunil Kamath74b4f372015-04-16 14:22:12 +0530799 DRM_DEBUG_KMS("Disabling DC6\n");
800
Imre Deak13ae3a02015-11-04 19:24:16 +0200801 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
Suketu Shahf75a1982015-04-16 14:22:11 +0530802}
803
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000804static void skl_set_power_well(struct drm_i915_private *dev_priv,
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +0200805 struct i915_power_well *power_well, bool enable)
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000806{
807 uint32_t tmp, fuse_status;
808 uint32_t req_mask, state_mask;
Damien Lespiau2a518352015-03-06 18:50:49 +0000809 bool is_enabled, enable_requested, check_fuse_status = false;
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000810
811 tmp = I915_READ(HSW_PWR_WELL_DRIVER);
812 fuse_status = I915_READ(SKL_FUSE_STATUS);
813
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +0300814 switch (power_well->id) {
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000815 case SKL_DISP_PW_1:
Chris Wilson117c1142016-06-30 15:33:33 +0100816 if (intel_wait_for_register(dev_priv,
817 SKL_FUSE_STATUS,
818 SKL_FUSE_PG0_DIST_STATUS,
819 SKL_FUSE_PG0_DIST_STATUS,
820 1)) {
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000821 DRM_ERROR("PG0 not enabled\n");
822 return;
823 }
824 break;
825 case SKL_DISP_PW_2:
826 if (!(fuse_status & SKL_FUSE_PG1_DIST_STATUS)) {
827 DRM_ERROR("PG1 in disabled state\n");
828 return;
829 }
830 break;
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +0200831 case SKL_DISP_PW_MISC_IO:
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -0700832 case SKL_DISP_PW_DDI_A_E: /* GLK_DISP_PW_DDI_A, CNL_DISP_PW_DDI_A */
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000833 case SKL_DISP_PW_DDI_B:
834 case SKL_DISP_PW_DDI_C:
835 case SKL_DISP_PW_DDI_D:
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -0700836 case GLK_DISP_PW_AUX_A: /* CNL_DISP_PW_AUX_A */
837 case GLK_DISP_PW_AUX_B: /* CNL_DISP_PW_AUX_B */
838 case GLK_DISP_PW_AUX_C: /* CNL_DISP_PW_AUX_C */
839 case CNL_DISP_PW_AUX_D:
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000840 break;
841 default:
Imre Deak438b8dc2017-07-11 23:42:30 +0300842 WARN(1, "Unknown power well %u\n", power_well->id);
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000843 return;
844 }
845
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +0300846 req_mask = SKL_POWER_WELL_REQ(power_well->id);
Damien Lespiau2a518352015-03-06 18:50:49 +0000847 enable_requested = tmp & req_mask;
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +0300848 state_mask = SKL_POWER_WELL_STATE(power_well->id);
Damien Lespiau2a518352015-03-06 18:50:49 +0000849 is_enabled = tmp & state_mask;
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000850
Ville Syrjäläaae8ba82016-02-19 20:47:30 +0200851 if (!enable && enable_requested)
852 skl_power_well_pre_disable(dev_priv, power_well);
853
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000854 if (enable) {
Damien Lespiau2a518352015-03-06 18:50:49 +0000855 if (!enable_requested) {
Suketu Shahdc174302015-04-17 19:46:16 +0530856 WARN((tmp & state_mask) &&
857 !I915_READ(HSW_PWR_WELL_BIOS),
858 "Invalid for power well status to be enabled, unless done by the BIOS, \
859 when request is to disable!\n");
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000860 I915_WRITE(HSW_PWR_WELL_DRIVER, tmp | req_mask);
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000861 }
862
Damien Lespiau2a518352015-03-06 18:50:49 +0000863 if (!is_enabled) {
Damien Lespiau510e6fd2015-03-06 18:50:50 +0000864 DRM_DEBUG_KMS("Enabling %s\n", power_well->name);
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000865 check_fuse_status = true;
866 }
Imre Deak42d93662017-06-29 18:37:01 +0300867
868 gen9_wait_for_power_well_enable(dev_priv, power_well);
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000869 } else {
Damien Lespiau2a518352015-03-06 18:50:49 +0000870 if (enable_requested) {
Imre Deak4a76f292015-11-04 19:24:15 +0200871 I915_WRITE(HSW_PWR_WELL_DRIVER, tmp & ~req_mask);
872 POSTING_READ(HSW_PWR_WELL_DRIVER);
873 DRM_DEBUG_KMS("Disabling %s\n", power_well->name);
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000874 }
Imre Deakc6782b72016-04-05 13:26:05 +0300875
Imre Deak42d93662017-06-29 18:37:01 +0300876 gen9_wait_for_power_well_disable(dev_priv, power_well);
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000877 }
878
879 if (check_fuse_status) {
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +0300880 if (power_well->id == SKL_DISP_PW_1) {
Chris Wilson8b00f552016-06-30 15:33:34 +0100881 if (intel_wait_for_register(dev_priv,
882 SKL_FUSE_STATUS,
883 SKL_FUSE_PG1_DIST_STATUS,
884 SKL_FUSE_PG1_DIST_STATUS,
885 1))
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000886 DRM_ERROR("PG1 distributing status timeout\n");
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +0300887 } else if (power_well->id == SKL_DISP_PW_2) {
Chris Wilson8b00f552016-06-30 15:33:34 +0100888 if (intel_wait_for_register(dev_priv,
889 SKL_FUSE_STATUS,
890 SKL_FUSE_PG2_DIST_STATUS,
891 SKL_FUSE_PG2_DIST_STATUS,
892 1))
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000893 DRM_ERROR("PG2 distributing status timeout\n");
894 }
895 }
Damien Lespiaud14c0342015-03-06 18:50:51 +0000896
897 if (enable && !is_enabled)
898 skl_power_well_post_enable(dev_priv, power_well);
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000899}
900
Daniel Vetter9c065a72014-09-30 10:56:38 +0200901static void hsw_power_well_sync_hw(struct drm_i915_private *dev_priv,
902 struct i915_power_well *power_well)
903{
Imre Deak16e84912017-02-17 17:39:45 +0200904 /* Take over the request bit if set by BIOS. */
905 if (I915_READ(HSW_PWR_WELL_BIOS) & HSW_PWR_WELL_ENABLE_REQUEST) {
906 if (!(I915_READ(HSW_PWR_WELL_DRIVER) &
907 HSW_PWR_WELL_ENABLE_REQUEST))
908 I915_WRITE(HSW_PWR_WELL_DRIVER,
909 HSW_PWR_WELL_ENABLE_REQUEST);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200910 I915_WRITE(HSW_PWR_WELL_BIOS, 0);
Imre Deak16e84912017-02-17 17:39:45 +0200911 }
Daniel Vetter9c065a72014-09-30 10:56:38 +0200912}
913
914static void hsw_power_well_enable(struct drm_i915_private *dev_priv,
915 struct i915_power_well *power_well)
916{
917 hsw_set_power_well(dev_priv, power_well, true);
918}
919
920static void hsw_power_well_disable(struct drm_i915_private *dev_priv,
921 struct i915_power_well *power_well)
922{
923 hsw_set_power_well(dev_priv, power_well, false);
924}
925
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000926static bool skl_power_well_enabled(struct drm_i915_private *dev_priv,
927 struct i915_power_well *power_well)
928{
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +0300929 uint32_t mask = SKL_POWER_WELL_REQ(power_well->id) |
930 SKL_POWER_WELL_STATE(power_well->id);
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000931
932 return (I915_READ(HSW_PWR_WELL_DRIVER) & mask) == mask;
933}
934
935static void skl_power_well_sync_hw(struct drm_i915_private *dev_priv,
936 struct i915_power_well *power_well)
937{
Imre Deak14544e12017-02-17 17:39:44 +0200938 uint32_t mask = SKL_POWER_WELL_REQ(power_well->id);
939 uint32_t bios_req = I915_READ(HSW_PWR_WELL_BIOS);
940
Imre Deak16e84912017-02-17 17:39:45 +0200941 /* Take over the request bit if set by BIOS. */
Imre Deak14544e12017-02-17 17:39:44 +0200942 if (bios_req & mask) {
Imre Deak16e84912017-02-17 17:39:45 +0200943 uint32_t drv_req = I915_READ(HSW_PWR_WELL_DRIVER);
944
945 if (!(drv_req & mask))
946 I915_WRITE(HSW_PWR_WELL_DRIVER, drv_req | mask);
Imre Deak14544e12017-02-17 17:39:44 +0200947 I915_WRITE(HSW_PWR_WELL_BIOS, bios_req & ~mask);
948 }
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000949}
950
951static void skl_power_well_enable(struct drm_i915_private *dev_priv,
952 struct i915_power_well *power_well)
953{
954 skl_set_power_well(dev_priv, power_well, true);
955}
956
957static void skl_power_well_disable(struct drm_i915_private *dev_priv,
958 struct i915_power_well *power_well)
959{
960 skl_set_power_well(dev_priv, power_well, false);
961}
962
Imre Deak9c8d0b82016-06-13 16:44:34 +0300963static void bxt_dpio_cmn_power_well_enable(struct drm_i915_private *dev_priv,
964 struct i915_power_well *power_well)
965{
Ander Conselvan de Oliveira362624c2016-10-06 19:22:15 +0300966 bxt_ddi_phy_init(dev_priv, power_well->data);
Imre Deak9c8d0b82016-06-13 16:44:34 +0300967}
968
969static void bxt_dpio_cmn_power_well_disable(struct drm_i915_private *dev_priv,
970 struct i915_power_well *power_well)
971{
Ander Conselvan de Oliveira362624c2016-10-06 19:22:15 +0300972 bxt_ddi_phy_uninit(dev_priv, power_well->data);
Imre Deak9c8d0b82016-06-13 16:44:34 +0300973}
974
975static bool bxt_dpio_cmn_power_well_enabled(struct drm_i915_private *dev_priv,
976 struct i915_power_well *power_well)
977{
Ander Conselvan de Oliveira362624c2016-10-06 19:22:15 +0300978 return bxt_ddi_phy_is_enabled(dev_priv, power_well->data);
Imre Deak9c8d0b82016-06-13 16:44:34 +0300979}
980
Imre Deak9c8d0b82016-06-13 16:44:34 +0300981static void bxt_verify_ddi_phy_power_wells(struct drm_i915_private *dev_priv)
982{
983 struct i915_power_well *power_well;
984
985 power_well = lookup_power_well(dev_priv, BXT_DPIO_CMN_A);
986 if (power_well->count > 0)
Ander Conselvan de Oliveira362624c2016-10-06 19:22:15 +0300987 bxt_ddi_phy_verify_state(dev_priv, power_well->data);
Imre Deak9c8d0b82016-06-13 16:44:34 +0300988
989 power_well = lookup_power_well(dev_priv, BXT_DPIO_CMN_BC);
990 if (power_well->count > 0)
Ander Conselvan de Oliveira362624c2016-10-06 19:22:15 +0300991 bxt_ddi_phy_verify_state(dev_priv, power_well->data);
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +0200992
993 if (IS_GEMINILAKE(dev_priv)) {
994 power_well = lookup_power_well(dev_priv, GLK_DPIO_CMN_C);
995 if (power_well->count > 0)
996 bxt_ddi_phy_verify_state(dev_priv, power_well->data);
997 }
Imre Deak9c8d0b82016-06-13 16:44:34 +0300998}
999
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01001000static bool gen9_dc_off_power_well_enabled(struct drm_i915_private *dev_priv,
1001 struct i915_power_well *power_well)
1002{
1003 return (I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC5_DC6_MASK) == 0;
1004}
1005
Ville Syrjälä18a80672016-05-16 16:59:40 +03001006static void gen9_assert_dbuf_enabled(struct drm_i915_private *dev_priv)
1007{
1008 u32 tmp = I915_READ(DBUF_CTL);
1009
1010 WARN((tmp & (DBUF_POWER_STATE | DBUF_POWER_REQUEST)) !=
1011 (DBUF_POWER_STATE | DBUF_POWER_REQUEST),
1012 "Unexpected DBuf power power state (0x%08x)\n", tmp);
1013}
1014
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01001015static void gen9_dc_off_power_well_enable(struct drm_i915_private *dev_priv,
1016 struct i915_power_well *power_well)
1017{
Ville Syrjälä49cd97a2017-02-07 20:33:45 +02001018 struct intel_cdclk_state cdclk_state = {};
1019
Imre Deak5b773eb2016-02-29 22:49:05 +02001020 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
Imre Deakadc7f042016-04-04 17:27:10 +03001021
Ville Syrjälä49cd97a2017-02-07 20:33:45 +02001022 dev_priv->display.get_cdclk(dev_priv, &cdclk_state);
1023 WARN_ON(!intel_cdclk_state_compare(&dev_priv->cdclk.hw, &cdclk_state));
Ville Syrjälä342be922016-05-13 23:41:39 +03001024
Ville Syrjälä18a80672016-05-16 16:59:40 +03001025 gen9_assert_dbuf_enabled(dev_priv);
1026
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02001027 if (IS_GEN9_LP(dev_priv))
Imre Deak9c8d0b82016-06-13 16:44:34 +03001028 bxt_verify_ddi_phy_power_wells(dev_priv);
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01001029}
1030
1031static void gen9_dc_off_power_well_disable(struct drm_i915_private *dev_priv,
1032 struct i915_power_well *power_well)
1033{
Imre Deakf74ed082016-04-18 14:48:21 +03001034 if (!dev_priv->csr.dmc_payload)
1035 return;
1036
Imre Deaka37baf32016-02-29 22:49:03 +02001037 if (dev_priv->csr.allowed_dc_mask & DC_STATE_EN_UPTO_DC6)
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01001038 skl_enable_dc6(dev_priv);
Imre Deaka37baf32016-02-29 22:49:03 +02001039 else if (dev_priv->csr.allowed_dc_mask & DC_STATE_EN_UPTO_DC5)
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01001040 gen9_enable_dc5(dev_priv);
1041}
1042
Imre Deak3c1b38e2017-02-17 17:39:42 +02001043static void i9xx_power_well_sync_hw_noop(struct drm_i915_private *dev_priv,
1044 struct i915_power_well *power_well)
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01001045{
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01001046}
1047
Daniel Vetter9c065a72014-09-30 10:56:38 +02001048static void i9xx_always_on_power_well_noop(struct drm_i915_private *dev_priv,
1049 struct i915_power_well *power_well)
1050{
1051}
1052
1053static bool i9xx_always_on_power_well_enabled(struct drm_i915_private *dev_priv,
1054 struct i915_power_well *power_well)
1055{
1056 return true;
1057}
1058
Ville Syrjälä2ee0da12017-06-01 17:36:16 +03001059static void i830_pipes_power_well_enable(struct drm_i915_private *dev_priv,
1060 struct i915_power_well *power_well)
1061{
1062 if ((I915_READ(PIPECONF(PIPE_A)) & PIPECONF_ENABLE) == 0)
1063 i830_enable_pipe(dev_priv, PIPE_A);
1064 if ((I915_READ(PIPECONF(PIPE_B)) & PIPECONF_ENABLE) == 0)
1065 i830_enable_pipe(dev_priv, PIPE_B);
1066}
1067
1068static void i830_pipes_power_well_disable(struct drm_i915_private *dev_priv,
1069 struct i915_power_well *power_well)
1070{
1071 i830_disable_pipe(dev_priv, PIPE_B);
1072 i830_disable_pipe(dev_priv, PIPE_A);
1073}
1074
1075static bool i830_pipes_power_well_enabled(struct drm_i915_private *dev_priv,
1076 struct i915_power_well *power_well)
1077{
1078 return I915_READ(PIPECONF(PIPE_A)) & PIPECONF_ENABLE &&
1079 I915_READ(PIPECONF(PIPE_B)) & PIPECONF_ENABLE;
1080}
1081
1082static void i830_pipes_power_well_sync_hw(struct drm_i915_private *dev_priv,
1083 struct i915_power_well *power_well)
1084{
1085 if (power_well->count > 0)
1086 i830_pipes_power_well_enable(dev_priv, power_well);
1087 else
1088 i830_pipes_power_well_disable(dev_priv, power_well);
1089}
1090
Daniel Vetter9c065a72014-09-30 10:56:38 +02001091static void vlv_set_power_well(struct drm_i915_private *dev_priv,
1092 struct i915_power_well *power_well, bool enable)
1093{
Imre Deak438b8dc2017-07-11 23:42:30 +03001094 enum i915_power_well_id power_well_id = power_well->id;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001095 u32 mask;
1096 u32 state;
1097 u32 ctrl;
1098
1099 mask = PUNIT_PWRGT_MASK(power_well_id);
1100 state = enable ? PUNIT_PWRGT_PWR_ON(power_well_id) :
1101 PUNIT_PWRGT_PWR_GATE(power_well_id);
1102
1103 mutex_lock(&dev_priv->rps.hw_lock);
1104
1105#define COND \
1106 ((vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_STATUS) & mask) == state)
1107
1108 if (COND)
1109 goto out;
1110
1111 ctrl = vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_CTRL);
1112 ctrl &= ~mask;
1113 ctrl |= state;
1114 vlv_punit_write(dev_priv, PUNIT_REG_PWRGT_CTRL, ctrl);
1115
1116 if (wait_for(COND, 100))
Masanari Iida7e35ab82015-05-10 01:00:23 +09001117 DRM_ERROR("timeout setting power well state %08x (%08x)\n",
Daniel Vetter9c065a72014-09-30 10:56:38 +02001118 state,
1119 vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_CTRL));
1120
1121#undef COND
1122
1123out:
1124 mutex_unlock(&dev_priv->rps.hw_lock);
1125}
1126
Daniel Vetter9c065a72014-09-30 10:56:38 +02001127static void vlv_power_well_enable(struct drm_i915_private *dev_priv,
1128 struct i915_power_well *power_well)
1129{
1130 vlv_set_power_well(dev_priv, power_well, true);
1131}
1132
1133static void vlv_power_well_disable(struct drm_i915_private *dev_priv,
1134 struct i915_power_well *power_well)
1135{
1136 vlv_set_power_well(dev_priv, power_well, false);
1137}
1138
1139static bool vlv_power_well_enabled(struct drm_i915_private *dev_priv,
1140 struct i915_power_well *power_well)
1141{
Imre Deak438b8dc2017-07-11 23:42:30 +03001142 enum i915_power_well_id power_well_id = power_well->id;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001143 bool enabled = false;
1144 u32 mask;
1145 u32 state;
1146 u32 ctrl;
1147
1148 mask = PUNIT_PWRGT_MASK(power_well_id);
1149 ctrl = PUNIT_PWRGT_PWR_ON(power_well_id);
1150
1151 mutex_lock(&dev_priv->rps.hw_lock);
1152
1153 state = vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_STATUS) & mask;
1154 /*
1155 * We only ever set the power-on and power-gate states, anything
1156 * else is unexpected.
1157 */
1158 WARN_ON(state != PUNIT_PWRGT_PWR_ON(power_well_id) &&
1159 state != PUNIT_PWRGT_PWR_GATE(power_well_id));
1160 if (state == ctrl)
1161 enabled = true;
1162
1163 /*
1164 * A transient state at this point would mean some unexpected party
1165 * is poking at the power controls too.
1166 */
1167 ctrl = vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_CTRL) & mask;
1168 WARN_ON(ctrl != state);
1169
1170 mutex_unlock(&dev_priv->rps.hw_lock);
1171
1172 return enabled;
1173}
1174
Ville Syrjälä766078d2016-04-11 16:56:30 +03001175static void vlv_init_display_clock_gating(struct drm_i915_private *dev_priv)
1176{
Hans de Goede721d4842016-12-02 15:29:04 +01001177 u32 val;
1178
1179 /*
1180 * On driver load, a pipe may be active and driving a DSI display.
1181 * Preserve DPOUNIT_CLOCK_GATE_DISABLE to avoid the pipe getting stuck
1182 * (and never recovering) in this case. intel_dsi_post_disable() will
1183 * clear it when we turn off the display.
1184 */
1185 val = I915_READ(DSPCLK_GATE_D);
1186 val &= DPOUNIT_CLOCK_GATE_DISABLE;
1187 val |= VRHUNIT_CLOCK_GATE_DISABLE;
1188 I915_WRITE(DSPCLK_GATE_D, val);
Ville Syrjälä766078d2016-04-11 16:56:30 +03001189
1190 /*
1191 * Disable trickle feed and enable pnd deadline calculation
1192 */
1193 I915_WRITE(MI_ARB_VLV, MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE);
1194 I915_WRITE(CBR1_VLV, 0);
Ville Syrjälä19ab4ed2016-04-27 17:43:22 +03001195
1196 WARN_ON(dev_priv->rawclk_freq == 0);
1197
1198 I915_WRITE(RAWCLK_FREQ_VLV,
1199 DIV_ROUND_CLOSEST(dev_priv->rawclk_freq, 1000));
Ville Syrjälä766078d2016-04-11 16:56:30 +03001200}
1201
Ville Syrjälä2be7d542015-06-29 15:25:51 +03001202static void vlv_display_power_well_init(struct drm_i915_private *dev_priv)
Daniel Vetter9c065a72014-09-30 10:56:38 +02001203{
Lyude9504a892016-06-21 17:03:42 -04001204 struct intel_encoder *encoder;
Ville Syrjälä5a8fbb72015-06-29 15:25:53 +03001205 enum pipe pipe;
1206
1207 /*
1208 * Enable the CRI clock source so we can get at the
1209 * display and the reference clock for VGA
1210 * hotplug / manual detection. Supposedly DSI also
1211 * needs the ref clock up and running.
1212 *
1213 * CHV DPLL B/C have some issues if VGA mode is enabled.
1214 */
Tvrtko Ursulin801388c2016-11-16 08:55:44 +00001215 for_each_pipe(dev_priv, pipe) {
Ville Syrjälä5a8fbb72015-06-29 15:25:53 +03001216 u32 val = I915_READ(DPLL(pipe));
1217
1218 val |= DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
1219 if (pipe != PIPE_A)
1220 val |= DPLL_INTEGRATED_CRI_CLK_VLV;
1221
1222 I915_WRITE(DPLL(pipe), val);
1223 }
Daniel Vetter9c065a72014-09-30 10:56:38 +02001224
Ville Syrjälä766078d2016-04-11 16:56:30 +03001225 vlv_init_display_clock_gating(dev_priv);
1226
Daniel Vetter9c065a72014-09-30 10:56:38 +02001227 spin_lock_irq(&dev_priv->irq_lock);
1228 valleyview_enable_display_irqs(dev_priv);
1229 spin_unlock_irq(&dev_priv->irq_lock);
1230
1231 /*
1232 * During driver initialization/resume we can avoid restoring the
1233 * part of the HW/SW state that will be inited anyway explicitly.
1234 */
1235 if (dev_priv->power_domains.initializing)
1236 return;
1237
Daniel Vetterb9632912014-09-30 10:56:44 +02001238 intel_hpd_init(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001239
Lyude9504a892016-06-21 17:03:42 -04001240 /* Re-enable the ADPA, if we have one */
1241 for_each_intel_encoder(&dev_priv->drm, encoder) {
1242 if (encoder->type == INTEL_OUTPUT_ANALOG)
1243 intel_crt_reset(&encoder->base);
1244 }
1245
Tvrtko Ursulin29b74b72016-11-16 08:55:39 +00001246 i915_redisable_vga_power_on(dev_priv);
Imre Deak8090ba82016-08-10 14:07:33 +03001247
1248 intel_pps_unlock_regs_wa(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001249}
1250
Ville Syrjälä2be7d542015-06-29 15:25:51 +03001251static void vlv_display_power_well_deinit(struct drm_i915_private *dev_priv)
1252{
1253 spin_lock_irq(&dev_priv->irq_lock);
1254 valleyview_disable_display_irqs(dev_priv);
1255 spin_unlock_irq(&dev_priv->irq_lock);
1256
Ville Syrjälä2230fde2016-02-19 18:41:52 +02001257 /* make sure we're done processing display irqs */
Chris Wilson91c8a322016-07-05 10:40:23 +01001258 synchronize_irq(dev_priv->drm.irq);
Ville Syrjälä2230fde2016-02-19 18:41:52 +02001259
Imre Deak78597992016-06-16 16:37:20 +03001260 intel_power_sequencer_reset(dev_priv);
Lyude19625e82016-06-21 17:03:44 -04001261
Lyudeb64b5402016-10-26 12:36:09 -04001262 /* Prevent us from re-enabling polling on accident in late suspend */
1263 if (!dev_priv->drm.dev->power.is_suspended)
1264 intel_hpd_poll_init(dev_priv);
Ville Syrjälä2be7d542015-06-29 15:25:51 +03001265}
1266
1267static void vlv_display_power_well_enable(struct drm_i915_private *dev_priv,
1268 struct i915_power_well *power_well)
1269{
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001270 WARN_ON_ONCE(power_well->id != PUNIT_POWER_WELL_DISP2D);
Ville Syrjälä2be7d542015-06-29 15:25:51 +03001271
1272 vlv_set_power_well(dev_priv, power_well, true);
1273
1274 vlv_display_power_well_init(dev_priv);
1275}
1276
Daniel Vetter9c065a72014-09-30 10:56:38 +02001277static void vlv_display_power_well_disable(struct drm_i915_private *dev_priv,
1278 struct i915_power_well *power_well)
1279{
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001280 WARN_ON_ONCE(power_well->id != PUNIT_POWER_WELL_DISP2D);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001281
Ville Syrjälä2be7d542015-06-29 15:25:51 +03001282 vlv_display_power_well_deinit(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001283
1284 vlv_set_power_well(dev_priv, power_well, false);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001285}
1286
1287static void vlv_dpio_cmn_power_well_enable(struct drm_i915_private *dev_priv,
1288 struct i915_power_well *power_well)
1289{
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001290 WARN_ON_ONCE(power_well->id != PUNIT_POWER_WELL_DPIO_CMN_BC);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001291
Ville Syrjälä5a8fbb72015-06-29 15:25:53 +03001292 /* since ref/cri clock was enabled */
Daniel Vetter9c065a72014-09-30 10:56:38 +02001293 udelay(1); /* >10ns for cmnreset, >0ns for sidereset */
1294
1295 vlv_set_power_well(dev_priv, power_well, true);
1296
1297 /*
1298 * From VLV2A0_DP_eDP_DPIO_driver_vbios_notes_10.docx -
1299 * 6. De-assert cmn_reset/side_reset. Same as VLV X0.
1300 * a. GUnit 0x2110 bit[0] set to 1 (def 0)
1301 * b. The other bits such as sfr settings / modesel may all
1302 * be set to 0.
1303 *
1304 * This should only be done on init and resume from S3 with
1305 * both PLLs disabled, or we risk losing DPIO and PLL
1306 * synchronization.
1307 */
1308 I915_WRITE(DPIO_CTL, I915_READ(DPIO_CTL) | DPIO_CMNRST);
1309}
1310
1311static void vlv_dpio_cmn_power_well_disable(struct drm_i915_private *dev_priv,
1312 struct i915_power_well *power_well)
1313{
1314 enum pipe pipe;
1315
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001316 WARN_ON_ONCE(power_well->id != PUNIT_POWER_WELL_DPIO_CMN_BC);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001317
1318 for_each_pipe(dev_priv, pipe)
1319 assert_pll_disabled(dev_priv, pipe);
1320
1321 /* Assert common reset */
1322 I915_WRITE(DPIO_CTL, I915_READ(DPIO_CTL) & ~DPIO_CMNRST);
1323
1324 vlv_set_power_well(dev_priv, power_well, false);
1325}
1326
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001327#define POWER_DOMAIN_MASK (GENMASK_ULL(POWER_DOMAIN_NUM - 1, 0))
Ville Syrjälä30142272015-07-08 23:46:01 +03001328
Imre Deak438b8dc2017-07-11 23:42:30 +03001329static struct i915_power_well *
1330lookup_power_well(struct drm_i915_private *dev_priv,
1331 enum i915_power_well_id power_well_id)
Ville Syrjälä30142272015-07-08 23:46:01 +03001332{
1333 struct i915_power_domains *power_domains = &dev_priv->power_domains;
Ville Syrjälä30142272015-07-08 23:46:01 +03001334 int i;
1335
Imre Deakfc17f222015-11-04 19:24:11 +02001336 for (i = 0; i < power_domains->power_well_count; i++) {
1337 struct i915_power_well *power_well;
1338
1339 power_well = &power_domains->power_wells[i];
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001340 if (power_well->id == power_well_id)
Ville Syrjälä30142272015-07-08 23:46:01 +03001341 return power_well;
1342 }
1343
1344 return NULL;
1345}
1346
1347#define BITS_SET(val, bits) (((val) & (bits)) == (bits))
1348
1349static void assert_chv_phy_status(struct drm_i915_private *dev_priv)
1350{
1351 struct i915_power_well *cmn_bc =
1352 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_BC);
1353 struct i915_power_well *cmn_d =
1354 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_D);
1355 u32 phy_control = dev_priv->chv_phy_control;
1356 u32 phy_status = 0;
Ville Syrjälä3be60de2015-09-08 18:05:45 +03001357 u32 phy_status_mask = 0xffffffff;
Ville Syrjälä30142272015-07-08 23:46:01 +03001358
Ville Syrjälä3be60de2015-09-08 18:05:45 +03001359 /*
1360 * The BIOS can leave the PHY is some weird state
1361 * where it doesn't fully power down some parts.
1362 * Disable the asserts until the PHY has been fully
1363 * reset (ie. the power well has been disabled at
1364 * least once).
1365 */
1366 if (!dev_priv->chv_phy_assert[DPIO_PHY0])
1367 phy_status_mask &= ~(PHY_STATUS_CMN_LDO(DPIO_PHY0, DPIO_CH0) |
1368 PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH0, 0) |
1369 PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH0, 1) |
1370 PHY_STATUS_CMN_LDO(DPIO_PHY0, DPIO_CH1) |
1371 PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH1, 0) |
1372 PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH1, 1));
1373
1374 if (!dev_priv->chv_phy_assert[DPIO_PHY1])
1375 phy_status_mask &= ~(PHY_STATUS_CMN_LDO(DPIO_PHY1, DPIO_CH0) |
1376 PHY_STATUS_SPLINE_LDO(DPIO_PHY1, DPIO_CH0, 0) |
1377 PHY_STATUS_SPLINE_LDO(DPIO_PHY1, DPIO_CH0, 1));
1378
Ville Syrjälä30142272015-07-08 23:46:01 +03001379 if (cmn_bc->ops->is_enabled(dev_priv, cmn_bc)) {
1380 phy_status |= PHY_POWERGOOD(DPIO_PHY0);
1381
1382 /* this assumes override is only used to enable lanes */
1383 if ((phy_control & PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY0, DPIO_CH0)) == 0)
1384 phy_control |= PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH0);
1385
1386 if ((phy_control & PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY0, DPIO_CH1)) == 0)
1387 phy_control |= PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH1);
1388
1389 /* CL1 is on whenever anything is on in either channel */
1390 if (BITS_SET(phy_control,
1391 PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH0) |
1392 PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH1)))
1393 phy_status |= PHY_STATUS_CMN_LDO(DPIO_PHY0, DPIO_CH0);
1394
1395 /*
1396 * The DPLLB check accounts for the pipe B + port A usage
1397 * with CL2 powered up but all the lanes in the second channel
1398 * powered down.
1399 */
1400 if (BITS_SET(phy_control,
1401 PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH1)) &&
1402 (I915_READ(DPLL(PIPE_B)) & DPLL_VCO_ENABLE) == 0)
1403 phy_status |= PHY_STATUS_CMN_LDO(DPIO_PHY0, DPIO_CH1);
1404
1405 if (BITS_SET(phy_control,
1406 PHY_CH_POWER_DOWN_OVRD(0x3, DPIO_PHY0, DPIO_CH0)))
1407 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH0, 0);
1408 if (BITS_SET(phy_control,
1409 PHY_CH_POWER_DOWN_OVRD(0xc, DPIO_PHY0, DPIO_CH0)))
1410 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH0, 1);
1411
1412 if (BITS_SET(phy_control,
1413 PHY_CH_POWER_DOWN_OVRD(0x3, DPIO_PHY0, DPIO_CH1)))
1414 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH1, 0);
1415 if (BITS_SET(phy_control,
1416 PHY_CH_POWER_DOWN_OVRD(0xc, DPIO_PHY0, DPIO_CH1)))
1417 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH1, 1);
1418 }
1419
1420 if (cmn_d->ops->is_enabled(dev_priv, cmn_d)) {
1421 phy_status |= PHY_POWERGOOD(DPIO_PHY1);
1422
1423 /* this assumes override is only used to enable lanes */
1424 if ((phy_control & PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY1, DPIO_CH0)) == 0)
1425 phy_control |= PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY1, DPIO_CH0);
1426
1427 if (BITS_SET(phy_control,
1428 PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY1, DPIO_CH0)))
1429 phy_status |= PHY_STATUS_CMN_LDO(DPIO_PHY1, DPIO_CH0);
1430
1431 if (BITS_SET(phy_control,
1432 PHY_CH_POWER_DOWN_OVRD(0x3, DPIO_PHY1, DPIO_CH0)))
1433 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY1, DPIO_CH0, 0);
1434 if (BITS_SET(phy_control,
1435 PHY_CH_POWER_DOWN_OVRD(0xc, DPIO_PHY1, DPIO_CH0)))
1436 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY1, DPIO_CH0, 1);
1437 }
1438
Ville Syrjälä3be60de2015-09-08 18:05:45 +03001439 phy_status &= phy_status_mask;
1440
Ville Syrjälä30142272015-07-08 23:46:01 +03001441 /*
1442 * The PHY may be busy with some initial calibration and whatnot,
1443 * so the power state can take a while to actually change.
1444 */
Chris Wilson919fcd52016-06-30 15:33:35 +01001445 if (intel_wait_for_register(dev_priv,
1446 DISPLAY_PHY_STATUS,
1447 phy_status_mask,
1448 phy_status,
1449 10))
1450 DRM_ERROR("Unexpected PHY_STATUS 0x%08x, expected 0x%08x (PHY_CONTROL=0x%08x)\n",
1451 I915_READ(DISPLAY_PHY_STATUS) & phy_status_mask,
1452 phy_status, dev_priv->chv_phy_control);
Ville Syrjälä30142272015-07-08 23:46:01 +03001453}
1454
1455#undef BITS_SET
1456
Daniel Vetter9c065a72014-09-30 10:56:38 +02001457static void chv_dpio_cmn_power_well_enable(struct drm_i915_private *dev_priv,
1458 struct i915_power_well *power_well)
1459{
1460 enum dpio_phy phy;
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001461 enum pipe pipe;
1462 uint32_t tmp;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001463
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001464 WARN_ON_ONCE(power_well->id != PUNIT_POWER_WELL_DPIO_CMN_BC &&
1465 power_well->id != PUNIT_POWER_WELL_DPIO_CMN_D);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001466
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001467 if (power_well->id == PUNIT_POWER_WELL_DPIO_CMN_BC) {
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001468 pipe = PIPE_A;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001469 phy = DPIO_PHY0;
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001470 } else {
1471 pipe = PIPE_C;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001472 phy = DPIO_PHY1;
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001473 }
Ville Syrjälä5a8fbb72015-06-29 15:25:53 +03001474
1475 /* since ref/cri clock was enabled */
Daniel Vetter9c065a72014-09-30 10:56:38 +02001476 udelay(1); /* >10ns for cmnreset, >0ns for sidereset */
1477 vlv_set_power_well(dev_priv, power_well, true);
1478
1479 /* Poll for phypwrgood signal */
Chris Wilsonffebb832016-06-30 15:33:36 +01001480 if (intel_wait_for_register(dev_priv,
1481 DISPLAY_PHY_STATUS,
1482 PHY_POWERGOOD(phy),
1483 PHY_POWERGOOD(phy),
1484 1))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001485 DRM_ERROR("Display PHY %d is not power up\n", phy);
1486
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001487 mutex_lock(&dev_priv->sb_lock);
1488
1489 /* Enable dynamic power down */
1490 tmp = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW28);
Ville Syrjäläee279212015-07-08 23:45:57 +03001491 tmp |= DPIO_DYNPWRDOWNEN_CH0 | DPIO_CL1POWERDOWNEN |
1492 DPIO_SUS_CLK_CONFIG_GATE_CLKREQ;
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001493 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW28, tmp);
1494
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001495 if (power_well->id == PUNIT_POWER_WELL_DPIO_CMN_BC) {
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001496 tmp = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW6_CH1);
1497 tmp |= DPIO_DYNPWRDOWNEN_CH1;
1498 vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW6_CH1, tmp);
Ville Syrjälä3e288782015-07-08 23:45:58 +03001499 } else {
1500 /*
1501 * Force the non-existing CL2 off. BXT does this
1502 * too, so maybe it saves some power even though
1503 * CL2 doesn't exist?
1504 */
1505 tmp = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW30);
1506 tmp |= DPIO_CL2_LDOFUSE_PWRENB;
1507 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW30, tmp);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001508 }
1509
1510 mutex_unlock(&dev_priv->sb_lock);
1511
Ville Syrjälä70722462015-04-10 18:21:28 +03001512 dev_priv->chv_phy_control |= PHY_COM_LANE_RESET_DEASSERT(phy);
1513 I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001514
1515 DRM_DEBUG_KMS("Enabled DPIO PHY%d (PHY_CONTROL=0x%08x)\n",
1516 phy, dev_priv->chv_phy_control);
Ville Syrjälä30142272015-07-08 23:46:01 +03001517
1518 assert_chv_phy_status(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001519}
1520
1521static void chv_dpio_cmn_power_well_disable(struct drm_i915_private *dev_priv,
1522 struct i915_power_well *power_well)
1523{
1524 enum dpio_phy phy;
1525
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001526 WARN_ON_ONCE(power_well->id != PUNIT_POWER_WELL_DPIO_CMN_BC &&
1527 power_well->id != PUNIT_POWER_WELL_DPIO_CMN_D);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001528
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001529 if (power_well->id == PUNIT_POWER_WELL_DPIO_CMN_BC) {
Daniel Vetter9c065a72014-09-30 10:56:38 +02001530 phy = DPIO_PHY0;
1531 assert_pll_disabled(dev_priv, PIPE_A);
1532 assert_pll_disabled(dev_priv, PIPE_B);
1533 } else {
1534 phy = DPIO_PHY1;
1535 assert_pll_disabled(dev_priv, PIPE_C);
1536 }
1537
Ville Syrjälä70722462015-04-10 18:21:28 +03001538 dev_priv->chv_phy_control &= ~PHY_COM_LANE_RESET_DEASSERT(phy);
1539 I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001540
1541 vlv_set_power_well(dev_priv, power_well, false);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001542
1543 DRM_DEBUG_KMS("Disabled DPIO PHY%d (PHY_CONTROL=0x%08x)\n",
1544 phy, dev_priv->chv_phy_control);
Ville Syrjälä30142272015-07-08 23:46:01 +03001545
Ville Syrjälä3be60de2015-09-08 18:05:45 +03001546 /* PHY is fully reset now, so we can enable the PHY state asserts */
1547 dev_priv->chv_phy_assert[phy] = true;
1548
Ville Syrjälä30142272015-07-08 23:46:01 +03001549 assert_chv_phy_status(dev_priv);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001550}
1551
Ville Syrjälä6669e392015-07-08 23:46:00 +03001552static void assert_chv_phy_powergate(struct drm_i915_private *dev_priv, enum dpio_phy phy,
1553 enum dpio_channel ch, bool override, unsigned int mask)
1554{
1555 enum pipe pipe = phy == DPIO_PHY0 ? PIPE_A : PIPE_C;
1556 u32 reg, val, expected, actual;
1557
Ville Syrjälä3be60de2015-09-08 18:05:45 +03001558 /*
1559 * The BIOS can leave the PHY is some weird state
1560 * where it doesn't fully power down some parts.
1561 * Disable the asserts until the PHY has been fully
1562 * reset (ie. the power well has been disabled at
1563 * least once).
1564 */
1565 if (!dev_priv->chv_phy_assert[phy])
1566 return;
1567
Ville Syrjälä6669e392015-07-08 23:46:00 +03001568 if (ch == DPIO_CH0)
1569 reg = _CHV_CMN_DW0_CH0;
1570 else
1571 reg = _CHV_CMN_DW6_CH1;
1572
1573 mutex_lock(&dev_priv->sb_lock);
1574 val = vlv_dpio_read(dev_priv, pipe, reg);
1575 mutex_unlock(&dev_priv->sb_lock);
1576
1577 /*
1578 * This assumes !override is only used when the port is disabled.
1579 * All lanes should power down even without the override when
1580 * the port is disabled.
1581 */
1582 if (!override || mask == 0xf) {
1583 expected = DPIO_ALLDL_POWERDOWN | DPIO_ANYDL_POWERDOWN;
1584 /*
1585 * If CH1 common lane is not active anymore
1586 * (eg. for pipe B DPLL) the entire channel will
1587 * shut down, which causes the common lane registers
1588 * to read as 0. That means we can't actually check
1589 * the lane power down status bits, but as the entire
1590 * register reads as 0 it's a good indication that the
1591 * channel is indeed entirely powered down.
1592 */
1593 if (ch == DPIO_CH1 && val == 0)
1594 expected = 0;
1595 } else if (mask != 0x0) {
1596 expected = DPIO_ANYDL_POWERDOWN;
1597 } else {
1598 expected = 0;
1599 }
1600
1601 if (ch == DPIO_CH0)
1602 actual = val >> DPIO_ANYDL_POWERDOWN_SHIFT_CH0;
1603 else
1604 actual = val >> DPIO_ANYDL_POWERDOWN_SHIFT_CH1;
1605 actual &= DPIO_ALLDL_POWERDOWN | DPIO_ANYDL_POWERDOWN;
1606
1607 WARN(actual != expected,
1608 "Unexpected DPIO lane power down: all %d, any %d. Expected: all %d, any %d. (0x%x = 0x%08x)\n",
1609 !!(actual & DPIO_ALLDL_POWERDOWN), !!(actual & DPIO_ANYDL_POWERDOWN),
1610 !!(expected & DPIO_ALLDL_POWERDOWN), !!(expected & DPIO_ANYDL_POWERDOWN),
1611 reg, val);
1612}
1613
Ville Syrjäläb0b33842015-07-08 23:45:55 +03001614bool chv_phy_powergate_ch(struct drm_i915_private *dev_priv, enum dpio_phy phy,
1615 enum dpio_channel ch, bool override)
1616{
1617 struct i915_power_domains *power_domains = &dev_priv->power_domains;
1618 bool was_override;
1619
1620 mutex_lock(&power_domains->lock);
1621
1622 was_override = dev_priv->chv_phy_control & PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
1623
1624 if (override == was_override)
1625 goto out;
1626
1627 if (override)
1628 dev_priv->chv_phy_control |= PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
1629 else
1630 dev_priv->chv_phy_control &= ~PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
1631
1632 I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
1633
1634 DRM_DEBUG_KMS("Power gating DPIO PHY%d CH%d (DPIO_PHY_CONTROL=0x%08x)\n",
1635 phy, ch, dev_priv->chv_phy_control);
1636
Ville Syrjälä30142272015-07-08 23:46:01 +03001637 assert_chv_phy_status(dev_priv);
1638
Ville Syrjäläb0b33842015-07-08 23:45:55 +03001639out:
1640 mutex_unlock(&power_domains->lock);
1641
1642 return was_override;
1643}
1644
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001645void chv_phy_powergate_lanes(struct intel_encoder *encoder,
1646 bool override, unsigned int mask)
1647{
1648 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
1649 struct i915_power_domains *power_domains = &dev_priv->power_domains;
1650 enum dpio_phy phy = vlv_dport_to_phy(enc_to_dig_port(&encoder->base));
1651 enum dpio_channel ch = vlv_dport_to_channel(enc_to_dig_port(&encoder->base));
1652
1653 mutex_lock(&power_domains->lock);
1654
1655 dev_priv->chv_phy_control &= ~PHY_CH_POWER_DOWN_OVRD(0xf, phy, ch);
1656 dev_priv->chv_phy_control |= PHY_CH_POWER_DOWN_OVRD(mask, phy, ch);
1657
1658 if (override)
1659 dev_priv->chv_phy_control |= PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
1660 else
1661 dev_priv->chv_phy_control &= ~PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
1662
1663 I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
1664
1665 DRM_DEBUG_KMS("Power gating DPIO PHY%d CH%d lanes 0x%x (PHY_CONTROL=0x%08x)\n",
1666 phy, ch, mask, dev_priv->chv_phy_control);
1667
Ville Syrjälä30142272015-07-08 23:46:01 +03001668 assert_chv_phy_status(dev_priv);
1669
Ville Syrjälä6669e392015-07-08 23:46:00 +03001670 assert_chv_phy_powergate(dev_priv, phy, ch, override, mask);
1671
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001672 mutex_unlock(&power_domains->lock);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001673}
1674
1675static bool chv_pipe_power_well_enabled(struct drm_i915_private *dev_priv,
1676 struct i915_power_well *power_well)
1677{
Imre Deakf49193c2017-07-06 17:40:23 +03001678 enum pipe pipe = PIPE_A;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001679 bool enabled;
1680 u32 state, ctrl;
1681
1682 mutex_lock(&dev_priv->rps.hw_lock);
1683
1684 state = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & DP_SSS_MASK(pipe);
1685 /*
1686 * We only ever set the power-on and power-gate states, anything
1687 * else is unexpected.
1688 */
1689 WARN_ON(state != DP_SSS_PWR_ON(pipe) && state != DP_SSS_PWR_GATE(pipe));
1690 enabled = state == DP_SSS_PWR_ON(pipe);
1691
1692 /*
1693 * A transient state at this point would mean some unexpected party
1694 * is poking at the power controls too.
1695 */
1696 ctrl = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & DP_SSC_MASK(pipe);
1697 WARN_ON(ctrl << 16 != state);
1698
1699 mutex_unlock(&dev_priv->rps.hw_lock);
1700
1701 return enabled;
1702}
1703
1704static void chv_set_pipe_power_well(struct drm_i915_private *dev_priv,
1705 struct i915_power_well *power_well,
1706 bool enable)
1707{
Imre Deakf49193c2017-07-06 17:40:23 +03001708 enum pipe pipe = PIPE_A;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001709 u32 state;
1710 u32 ctrl;
1711
1712 state = enable ? DP_SSS_PWR_ON(pipe) : DP_SSS_PWR_GATE(pipe);
1713
1714 mutex_lock(&dev_priv->rps.hw_lock);
1715
1716#define COND \
1717 ((vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & DP_SSS_MASK(pipe)) == state)
1718
1719 if (COND)
1720 goto out;
1721
1722 ctrl = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ);
1723 ctrl &= ~DP_SSC_MASK(pipe);
1724 ctrl |= enable ? DP_SSC_PWR_ON(pipe) : DP_SSC_PWR_GATE(pipe);
1725 vlv_punit_write(dev_priv, PUNIT_REG_DSPFREQ, ctrl);
1726
1727 if (wait_for(COND, 100))
Masanari Iida7e35ab82015-05-10 01:00:23 +09001728 DRM_ERROR("timeout setting power well state %08x (%08x)\n",
Daniel Vetter9c065a72014-09-30 10:56:38 +02001729 state,
1730 vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ));
1731
1732#undef COND
1733
1734out:
1735 mutex_unlock(&dev_priv->rps.hw_lock);
1736}
1737
Daniel Vetter9c065a72014-09-30 10:56:38 +02001738static void chv_pipe_power_well_enable(struct drm_i915_private *dev_priv,
1739 struct i915_power_well *power_well)
1740{
Imre Deakf49193c2017-07-06 17:40:23 +03001741 WARN_ON_ONCE(power_well->id != CHV_DISP_PW_PIPE_A);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001742
1743 chv_set_pipe_power_well(dev_priv, power_well, true);
Ville Syrjäläafd62752014-10-30 19:43:03 +02001744
Ville Syrjälä2be7d542015-06-29 15:25:51 +03001745 vlv_display_power_well_init(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001746}
1747
1748static void chv_pipe_power_well_disable(struct drm_i915_private *dev_priv,
1749 struct i915_power_well *power_well)
1750{
Imre Deakf49193c2017-07-06 17:40:23 +03001751 WARN_ON_ONCE(power_well->id != CHV_DISP_PW_PIPE_A);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001752
Ville Syrjälä2be7d542015-06-29 15:25:51 +03001753 vlv_display_power_well_deinit(dev_priv);
Ville Syrjäläafd62752014-10-30 19:43:03 +02001754
Daniel Vetter9c065a72014-09-30 10:56:38 +02001755 chv_set_pipe_power_well(dev_priv, power_well, false);
1756}
1757
Imre Deak09731282016-02-17 14:17:42 +02001758static void
1759__intel_display_power_get_domain(struct drm_i915_private *dev_priv,
1760 enum intel_display_power_domain domain)
1761{
1762 struct i915_power_domains *power_domains = &dev_priv->power_domains;
1763 struct i915_power_well *power_well;
Imre Deak09731282016-02-17 14:17:42 +02001764
Imre Deak75ccb2e2017-02-17 17:39:43 +02001765 for_each_power_domain_well(dev_priv, power_well, BIT_ULL(domain))
Imre Deakb409ca92016-06-13 16:44:33 +03001766 intel_power_well_get(dev_priv, power_well);
Imre Deak09731282016-02-17 14:17:42 +02001767
1768 power_domains->domain_use_count[domain]++;
1769}
1770
Daniel Vettere4e76842014-09-30 10:56:42 +02001771/**
1772 * intel_display_power_get - grab a power domain reference
1773 * @dev_priv: i915 device instance
1774 * @domain: power domain to reference
1775 *
1776 * This function grabs a power domain reference for @domain and ensures that the
1777 * power domain and all its parents are powered up. Therefore users should only
1778 * grab a reference to the innermost power domain they need.
1779 *
1780 * Any power domain reference obtained by this function must have a symmetric
1781 * call to intel_display_power_put() to release the reference again.
1782 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02001783void intel_display_power_get(struct drm_i915_private *dev_priv,
1784 enum intel_display_power_domain domain)
1785{
Imre Deak09731282016-02-17 14:17:42 +02001786 struct i915_power_domains *power_domains = &dev_priv->power_domains;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001787
1788 intel_runtime_pm_get(dev_priv);
1789
Imre Deak09731282016-02-17 14:17:42 +02001790 mutex_lock(&power_domains->lock);
1791
1792 __intel_display_power_get_domain(dev_priv, domain);
1793
1794 mutex_unlock(&power_domains->lock);
1795}
1796
1797/**
1798 * intel_display_power_get_if_enabled - grab a reference for an enabled display power domain
1799 * @dev_priv: i915 device instance
1800 * @domain: power domain to reference
1801 *
1802 * This function grabs a power domain reference for @domain and ensures that the
1803 * power domain and all its parents are powered up. Therefore users should only
1804 * grab a reference to the innermost power domain they need.
1805 *
1806 * Any power domain reference obtained by this function must have a symmetric
1807 * call to intel_display_power_put() to release the reference again.
1808 */
1809bool intel_display_power_get_if_enabled(struct drm_i915_private *dev_priv,
1810 enum intel_display_power_domain domain)
1811{
1812 struct i915_power_domains *power_domains = &dev_priv->power_domains;
1813 bool is_enabled;
1814
1815 if (!intel_runtime_pm_get_if_in_use(dev_priv))
1816 return false;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001817
1818 mutex_lock(&power_domains->lock);
1819
Imre Deak09731282016-02-17 14:17:42 +02001820 if (__intel_display_power_is_enabled(dev_priv, domain)) {
1821 __intel_display_power_get_domain(dev_priv, domain);
1822 is_enabled = true;
1823 } else {
1824 is_enabled = false;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001825 }
1826
Daniel Vetter9c065a72014-09-30 10:56:38 +02001827 mutex_unlock(&power_domains->lock);
Imre Deak09731282016-02-17 14:17:42 +02001828
1829 if (!is_enabled)
1830 intel_runtime_pm_put(dev_priv);
1831
1832 return is_enabled;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001833}
1834
Daniel Vettere4e76842014-09-30 10:56:42 +02001835/**
1836 * intel_display_power_put - release a power domain reference
1837 * @dev_priv: i915 device instance
1838 * @domain: power domain to reference
1839 *
1840 * This function drops the power domain reference obtained by
1841 * intel_display_power_get() and might power down the corresponding hardware
1842 * block right away if this is the last reference.
1843 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02001844void intel_display_power_put(struct drm_i915_private *dev_priv,
1845 enum intel_display_power_domain domain)
1846{
1847 struct i915_power_domains *power_domains;
1848 struct i915_power_well *power_well;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001849
1850 power_domains = &dev_priv->power_domains;
1851
1852 mutex_lock(&power_domains->lock);
1853
Daniel Stone11c86db2015-11-20 15:55:34 +00001854 WARN(!power_domains->domain_use_count[domain],
1855 "Use count on domain %s is already zero\n",
1856 intel_display_power_domain_str(domain));
Daniel Vetter9c065a72014-09-30 10:56:38 +02001857 power_domains->domain_use_count[domain]--;
1858
Imre Deak75ccb2e2017-02-17 17:39:43 +02001859 for_each_power_domain_well_rev(dev_priv, power_well, BIT_ULL(domain))
Imre Deakb409ca92016-06-13 16:44:33 +03001860 intel_power_well_put(dev_priv, power_well);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001861
1862 mutex_unlock(&power_domains->lock);
1863
1864 intel_runtime_pm_put(dev_priv);
1865}
1866
Ville Syrjälä9d0996b2016-04-18 14:02:28 +03001867#define HSW_DISPLAY_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001868 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
1869 BIT_ULL(POWER_DOMAIN_PIPE_C) | \
1870 BIT_ULL(POWER_DOMAIN_PIPE_A_PANEL_FITTER) | \
1871 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1872 BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
1873 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
1874 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
1875 BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
1876 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1877 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1878 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_LANES) | \
1879 BIT_ULL(POWER_DOMAIN_PORT_CRT) | /* DDI E */ \
1880 BIT_ULL(POWER_DOMAIN_VGA) | \
1881 BIT_ULL(POWER_DOMAIN_AUDIO) | \
1882 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001883
Ville Syrjälä9d0996b2016-04-18 14:02:28 +03001884#define BDW_DISPLAY_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001885 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
1886 BIT_ULL(POWER_DOMAIN_PIPE_C) | \
1887 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1888 BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
1889 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
1890 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
1891 BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
1892 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1893 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1894 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_LANES) | \
1895 BIT_ULL(POWER_DOMAIN_PORT_CRT) | /* DDI E */ \
1896 BIT_ULL(POWER_DOMAIN_VGA) | \
1897 BIT_ULL(POWER_DOMAIN_AUDIO) | \
1898 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001899
Ville Syrjälä465ac0c2016-04-18 14:02:27 +03001900#define VLV_DISPLAY_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001901 BIT_ULL(POWER_DOMAIN_PIPE_A) | \
1902 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
1903 BIT_ULL(POWER_DOMAIN_PIPE_A_PANEL_FITTER) | \
1904 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1905 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
1906 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
1907 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1908 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1909 BIT_ULL(POWER_DOMAIN_PORT_DSI) | \
1910 BIT_ULL(POWER_DOMAIN_PORT_CRT) | \
1911 BIT_ULL(POWER_DOMAIN_VGA) | \
1912 BIT_ULL(POWER_DOMAIN_AUDIO) | \
1913 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1914 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1915 BIT_ULL(POWER_DOMAIN_GMBUS) | \
1916 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001917
1918#define VLV_DPIO_CMN_BC_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001919 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1920 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1921 BIT_ULL(POWER_DOMAIN_PORT_CRT) | \
1922 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1923 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1924 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001925
1926#define VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001927 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1928 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1929 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001930
1931#define VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001932 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1933 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1934 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001935
1936#define VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001937 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1938 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1939 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001940
1941#define VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001942 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1943 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1944 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001945
Ville Syrjälä465ac0c2016-04-18 14:02:27 +03001946#define CHV_DISPLAY_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001947 BIT_ULL(POWER_DOMAIN_PIPE_A) | \
1948 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
1949 BIT_ULL(POWER_DOMAIN_PIPE_C) | \
1950 BIT_ULL(POWER_DOMAIN_PIPE_A_PANEL_FITTER) | \
1951 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1952 BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
1953 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
1954 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
1955 BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
1956 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1957 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1958 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_LANES) | \
1959 BIT_ULL(POWER_DOMAIN_PORT_DSI) | \
1960 BIT_ULL(POWER_DOMAIN_VGA) | \
1961 BIT_ULL(POWER_DOMAIN_AUDIO) | \
1962 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1963 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1964 BIT_ULL(POWER_DOMAIN_AUX_D) | \
1965 BIT_ULL(POWER_DOMAIN_GMBUS) | \
1966 BIT_ULL(POWER_DOMAIN_INIT))
Ville Syrjälä465ac0c2016-04-18 14:02:27 +03001967
Daniel Vetter9c065a72014-09-30 10:56:38 +02001968#define CHV_DPIO_CMN_BC_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001969 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1970 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1971 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1972 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1973 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001974
1975#define CHV_DPIO_CMN_D_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001976 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_LANES) | \
1977 BIT_ULL(POWER_DOMAIN_AUX_D) | \
1978 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001979
Ville Syrjälä2ee0da12017-06-01 17:36:16 +03001980#define I830_PIPES_POWER_DOMAINS ( \
1981 BIT_ULL(POWER_DOMAIN_PIPE_A) | \
1982 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
1983 BIT_ULL(POWER_DOMAIN_PIPE_A_PANEL_FITTER) | \
1984 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1985 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
1986 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
1987 BIT_ULL(POWER_DOMAIN_INIT))
1988
Daniel Vetter9c065a72014-09-30 10:56:38 +02001989static const struct i915_power_well_ops i9xx_always_on_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02001990 .sync_hw = i9xx_power_well_sync_hw_noop,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001991 .enable = i9xx_always_on_power_well_noop,
1992 .disable = i9xx_always_on_power_well_noop,
1993 .is_enabled = i9xx_always_on_power_well_enabled,
1994};
1995
1996static const struct i915_power_well_ops chv_pipe_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02001997 .sync_hw = i9xx_power_well_sync_hw_noop,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001998 .enable = chv_pipe_power_well_enable,
1999 .disable = chv_pipe_power_well_disable,
2000 .is_enabled = chv_pipe_power_well_enabled,
2001};
2002
2003static const struct i915_power_well_ops chv_dpio_cmn_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02002004 .sync_hw = i9xx_power_well_sync_hw_noop,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002005 .enable = chv_dpio_cmn_power_well_enable,
2006 .disable = chv_dpio_cmn_power_well_disable,
2007 .is_enabled = vlv_power_well_enabled,
2008};
2009
2010static struct i915_power_well i9xx_always_on_power_well[] = {
2011 {
2012 .name = "always-on",
2013 .always_on = 1,
2014 .domains = POWER_DOMAIN_MASK,
2015 .ops = &i9xx_always_on_power_well_ops,
2016 },
2017};
2018
Ville Syrjälä2ee0da12017-06-01 17:36:16 +03002019static const struct i915_power_well_ops i830_pipes_power_well_ops = {
2020 .sync_hw = i830_pipes_power_well_sync_hw,
2021 .enable = i830_pipes_power_well_enable,
2022 .disable = i830_pipes_power_well_disable,
2023 .is_enabled = i830_pipes_power_well_enabled,
2024};
2025
2026static struct i915_power_well i830_power_wells[] = {
2027 {
2028 .name = "always-on",
2029 .always_on = 1,
2030 .domains = POWER_DOMAIN_MASK,
2031 .ops = &i9xx_always_on_power_well_ops,
2032 },
2033 {
2034 .name = "pipes",
2035 .domains = I830_PIPES_POWER_DOMAINS,
2036 .ops = &i830_pipes_power_well_ops,
2037 },
2038};
2039
Daniel Vetter9c065a72014-09-30 10:56:38 +02002040static const struct i915_power_well_ops hsw_power_well_ops = {
2041 .sync_hw = hsw_power_well_sync_hw,
2042 .enable = hsw_power_well_enable,
2043 .disable = hsw_power_well_disable,
2044 .is_enabled = hsw_power_well_enabled,
2045};
2046
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002047static const struct i915_power_well_ops skl_power_well_ops = {
2048 .sync_hw = skl_power_well_sync_hw,
2049 .enable = skl_power_well_enable,
2050 .disable = skl_power_well_disable,
2051 .is_enabled = skl_power_well_enabled,
2052};
2053
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01002054static const struct i915_power_well_ops gen9_dc_off_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02002055 .sync_hw = i9xx_power_well_sync_hw_noop,
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01002056 .enable = gen9_dc_off_power_well_enable,
2057 .disable = gen9_dc_off_power_well_disable,
2058 .is_enabled = gen9_dc_off_power_well_enabled,
2059};
2060
Imre Deak9c8d0b82016-06-13 16:44:34 +03002061static const struct i915_power_well_ops bxt_dpio_cmn_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02002062 .sync_hw = i9xx_power_well_sync_hw_noop,
Imre Deak9c8d0b82016-06-13 16:44:34 +03002063 .enable = bxt_dpio_cmn_power_well_enable,
2064 .disable = bxt_dpio_cmn_power_well_disable,
2065 .is_enabled = bxt_dpio_cmn_power_well_enabled,
2066};
2067
Daniel Vetter9c065a72014-09-30 10:56:38 +02002068static struct i915_power_well hsw_power_wells[] = {
2069 {
2070 .name = "always-on",
2071 .always_on = 1,
Ville Syrjälä998bd662016-04-18 14:02:26 +03002072 .domains = POWER_DOMAIN_MASK,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002073 .ops = &i9xx_always_on_power_well_ops,
2074 },
2075 {
2076 .name = "display",
2077 .domains = HSW_DISPLAY_POWER_DOMAINS,
2078 .ops = &hsw_power_well_ops,
2079 },
2080};
2081
2082static struct i915_power_well bdw_power_wells[] = {
2083 {
2084 .name = "always-on",
2085 .always_on = 1,
Ville Syrjälä998bd662016-04-18 14:02:26 +03002086 .domains = POWER_DOMAIN_MASK,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002087 .ops = &i9xx_always_on_power_well_ops,
2088 },
2089 {
2090 .name = "display",
2091 .domains = BDW_DISPLAY_POWER_DOMAINS,
2092 .ops = &hsw_power_well_ops,
2093 },
2094};
2095
2096static const struct i915_power_well_ops vlv_display_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02002097 .sync_hw = i9xx_power_well_sync_hw_noop,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002098 .enable = vlv_display_power_well_enable,
2099 .disable = vlv_display_power_well_disable,
2100 .is_enabled = vlv_power_well_enabled,
2101};
2102
2103static const struct i915_power_well_ops vlv_dpio_cmn_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02002104 .sync_hw = i9xx_power_well_sync_hw_noop,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002105 .enable = vlv_dpio_cmn_power_well_enable,
2106 .disable = vlv_dpio_cmn_power_well_disable,
2107 .is_enabled = vlv_power_well_enabled,
2108};
2109
2110static const struct i915_power_well_ops vlv_dpio_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02002111 .sync_hw = i9xx_power_well_sync_hw_noop,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002112 .enable = vlv_power_well_enable,
2113 .disable = vlv_power_well_disable,
2114 .is_enabled = vlv_power_well_enabled,
2115};
2116
2117static struct i915_power_well vlv_power_wells[] = {
2118 {
2119 .name = "always-on",
2120 .always_on = 1,
Ville Syrjälä998bd662016-04-18 14:02:26 +03002121 .domains = POWER_DOMAIN_MASK,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002122 .ops = &i9xx_always_on_power_well_ops,
Imre Deak438b8dc2017-07-11 23:42:30 +03002123 .id = I915_DISP_PW_ALWAYS_ON,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002124 },
2125 {
2126 .name = "display",
2127 .domains = VLV_DISPLAY_POWER_DOMAINS,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002128 .id = PUNIT_POWER_WELL_DISP2D,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002129 .ops = &vlv_display_power_well_ops,
2130 },
2131 {
2132 .name = "dpio-tx-b-01",
2133 .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
2134 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
2135 VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
2136 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
2137 .ops = &vlv_dpio_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002138 .id = PUNIT_POWER_WELL_DPIO_TX_B_LANES_01,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002139 },
2140 {
2141 .name = "dpio-tx-b-23",
2142 .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
2143 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
2144 VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
2145 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
2146 .ops = &vlv_dpio_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002147 .id = PUNIT_POWER_WELL_DPIO_TX_B_LANES_23,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002148 },
2149 {
2150 .name = "dpio-tx-c-01",
2151 .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
2152 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
2153 VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
2154 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
2155 .ops = &vlv_dpio_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002156 .id = PUNIT_POWER_WELL_DPIO_TX_C_LANES_01,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002157 },
2158 {
2159 .name = "dpio-tx-c-23",
2160 .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
2161 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
2162 VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
2163 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
2164 .ops = &vlv_dpio_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002165 .id = PUNIT_POWER_WELL_DPIO_TX_C_LANES_23,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002166 },
2167 {
2168 .name = "dpio-common",
2169 .domains = VLV_DPIO_CMN_BC_POWER_DOMAINS,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002170 .id = PUNIT_POWER_WELL_DPIO_CMN_BC,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002171 .ops = &vlv_dpio_cmn_power_well_ops,
2172 },
2173};
2174
2175static struct i915_power_well chv_power_wells[] = {
2176 {
2177 .name = "always-on",
2178 .always_on = 1,
Ville Syrjälä998bd662016-04-18 14:02:26 +03002179 .domains = POWER_DOMAIN_MASK,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002180 .ops = &i9xx_always_on_power_well_ops,
2181 },
Daniel Vetter9c065a72014-09-30 10:56:38 +02002182 {
2183 .name = "display",
Ville Syrjäläbaa4e572014-10-27 16:07:32 +02002184 /*
Ville Syrjäläfde61e42015-05-26 20:22:39 +03002185 * Pipe A power well is the new disp2d well. Pipe B and C
2186 * power wells don't actually exist. Pipe A power well is
2187 * required for any pipe to work.
Ville Syrjäläbaa4e572014-10-27 16:07:32 +02002188 */
Ville Syrjälä465ac0c2016-04-18 14:02:27 +03002189 .domains = CHV_DISPLAY_POWER_DOMAINS,
Imre Deakf49193c2017-07-06 17:40:23 +03002190 .id = CHV_DISP_PW_PIPE_A,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002191 .ops = &chv_pipe_power_well_ops,
2192 },
Daniel Vetter9c065a72014-09-30 10:56:38 +02002193 {
2194 .name = "dpio-common-bc",
Ville Syrjälä71849b62015-04-10 18:21:29 +03002195 .domains = CHV_DPIO_CMN_BC_POWER_DOMAINS,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002196 .id = PUNIT_POWER_WELL_DPIO_CMN_BC,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002197 .ops = &chv_dpio_cmn_power_well_ops,
2198 },
2199 {
2200 .name = "dpio-common-d",
Ville Syrjälä71849b62015-04-10 18:21:29 +03002201 .domains = CHV_DPIO_CMN_D_POWER_DOMAINS,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002202 .id = PUNIT_POWER_WELL_DPIO_CMN_D,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002203 .ops = &chv_dpio_cmn_power_well_ops,
2204 },
Daniel Vetter9c065a72014-09-30 10:56:38 +02002205};
2206
Suketu Shah5aefb232015-04-16 14:22:10 +05302207bool intel_display_power_well_is_enabled(struct drm_i915_private *dev_priv,
Imre Deak438b8dc2017-07-11 23:42:30 +03002208 enum i915_power_well_id power_well_id)
Suketu Shah5aefb232015-04-16 14:22:10 +05302209{
2210 struct i915_power_well *power_well;
2211 bool ret;
2212
2213 power_well = lookup_power_well(dev_priv, power_well_id);
2214 ret = power_well->ops->is_enabled(dev_priv, power_well);
2215
2216 return ret;
2217}
2218
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002219static struct i915_power_well skl_power_wells[] = {
2220 {
2221 .name = "always-on",
2222 .always_on = 1,
Ville Syrjälä998bd662016-04-18 14:02:26 +03002223 .domains = POWER_DOMAIN_MASK,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002224 .ops = &i9xx_always_on_power_well_ops,
Imre Deak438b8dc2017-07-11 23:42:30 +03002225 .id = I915_DISP_PW_ALWAYS_ON,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002226 },
2227 {
2228 .name = "power well 1",
Imre Deak4a76f292015-11-04 19:24:15 +02002229 /* Handled by the DMC firmware */
2230 .domains = 0,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002231 .ops = &skl_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002232 .id = SKL_DISP_PW_1,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002233 },
2234 {
2235 .name = "MISC IO power well",
Imre Deak4a76f292015-11-04 19:24:15 +02002236 /* Handled by the DMC firmware */
2237 .domains = 0,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002238 .ops = &skl_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002239 .id = SKL_DISP_PW_MISC_IO,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002240 },
2241 {
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01002242 .name = "DC off",
2243 .domains = SKL_DISPLAY_DC_OFF_POWER_DOMAINS,
2244 .ops = &gen9_dc_off_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002245 .id = SKL_DISP_PW_DC_OFF,
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01002246 },
2247 {
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002248 .name = "power well 2",
2249 .domains = SKL_DISPLAY_POWERWELL_2_POWER_DOMAINS,
2250 .ops = &skl_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002251 .id = SKL_DISP_PW_2,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002252 },
2253 {
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002254 .name = "DDI A/E IO power well",
2255 .domains = SKL_DISPLAY_DDI_IO_A_E_POWER_DOMAINS,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002256 .ops = &skl_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002257 .id = SKL_DISP_PW_DDI_A_E,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002258 },
2259 {
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002260 .name = "DDI B IO power well",
2261 .domains = SKL_DISPLAY_DDI_IO_B_POWER_DOMAINS,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002262 .ops = &skl_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002263 .id = SKL_DISP_PW_DDI_B,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002264 },
2265 {
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002266 .name = "DDI C IO power well",
2267 .domains = SKL_DISPLAY_DDI_IO_C_POWER_DOMAINS,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002268 .ops = &skl_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002269 .id = SKL_DISP_PW_DDI_C,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002270 },
2271 {
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002272 .name = "DDI D IO power well",
2273 .domains = SKL_DISPLAY_DDI_IO_D_POWER_DOMAINS,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002274 .ops = &skl_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002275 .id = SKL_DISP_PW_DDI_D,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002276 },
2277};
2278
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302279static struct i915_power_well bxt_power_wells[] = {
2280 {
2281 .name = "always-on",
2282 .always_on = 1,
Ville Syrjälä998bd662016-04-18 14:02:26 +03002283 .domains = POWER_DOMAIN_MASK,
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302284 .ops = &i9xx_always_on_power_well_ops,
2285 },
2286 {
2287 .name = "power well 1",
Imre Deakd7d7c9e2016-04-01 16:02:42 +03002288 .domains = 0,
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302289 .ops = &skl_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002290 .id = SKL_DISP_PW_1,
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302291 },
2292 {
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01002293 .name = "DC off",
2294 .domains = BXT_DISPLAY_DC_OFF_POWER_DOMAINS,
2295 .ops = &gen9_dc_off_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002296 .id = SKL_DISP_PW_DC_OFF,
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01002297 },
2298 {
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302299 .name = "power well 2",
2300 .domains = BXT_DISPLAY_POWERWELL_2_POWER_DOMAINS,
2301 .ops = &skl_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002302 .id = SKL_DISP_PW_2,
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01002303 },
Imre Deak9c8d0b82016-06-13 16:44:34 +03002304 {
2305 .name = "dpio-common-a",
2306 .domains = BXT_DPIO_CMN_A_POWER_DOMAINS,
2307 .ops = &bxt_dpio_cmn_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002308 .id = BXT_DPIO_CMN_A,
Ander Conselvan de Oliveira362624c2016-10-06 19:22:15 +03002309 .data = DPIO_PHY1,
Imre Deak9c8d0b82016-06-13 16:44:34 +03002310 },
2311 {
2312 .name = "dpio-common-bc",
2313 .domains = BXT_DPIO_CMN_BC_POWER_DOMAINS,
2314 .ops = &bxt_dpio_cmn_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002315 .id = BXT_DPIO_CMN_BC,
Ander Conselvan de Oliveira362624c2016-10-06 19:22:15 +03002316 .data = DPIO_PHY0,
Imre Deak9c8d0b82016-06-13 16:44:34 +03002317 },
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302318};
2319
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002320static struct i915_power_well glk_power_wells[] = {
2321 {
2322 .name = "always-on",
2323 .always_on = 1,
2324 .domains = POWER_DOMAIN_MASK,
2325 .ops = &i9xx_always_on_power_well_ops,
2326 },
2327 {
2328 .name = "power well 1",
2329 /* Handled by the DMC firmware */
2330 .domains = 0,
2331 .ops = &skl_power_well_ops,
2332 .id = SKL_DISP_PW_1,
2333 },
2334 {
2335 .name = "DC off",
2336 .domains = GLK_DISPLAY_DC_OFF_POWER_DOMAINS,
2337 .ops = &gen9_dc_off_power_well_ops,
2338 .id = SKL_DISP_PW_DC_OFF,
2339 },
2340 {
2341 .name = "power well 2",
2342 .domains = GLK_DISPLAY_POWERWELL_2_POWER_DOMAINS,
2343 .ops = &skl_power_well_ops,
2344 .id = SKL_DISP_PW_2,
2345 },
2346 {
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +02002347 .name = "dpio-common-a",
2348 .domains = GLK_DPIO_CMN_A_POWER_DOMAINS,
2349 .ops = &bxt_dpio_cmn_power_well_ops,
2350 .id = BXT_DPIO_CMN_A,
2351 .data = DPIO_PHY1,
2352 },
2353 {
2354 .name = "dpio-common-b",
2355 .domains = GLK_DPIO_CMN_B_POWER_DOMAINS,
2356 .ops = &bxt_dpio_cmn_power_well_ops,
2357 .id = BXT_DPIO_CMN_BC,
2358 .data = DPIO_PHY0,
2359 },
2360 {
2361 .name = "dpio-common-c",
2362 .domains = GLK_DPIO_CMN_C_POWER_DOMAINS,
2363 .ops = &bxt_dpio_cmn_power_well_ops,
2364 .id = GLK_DPIO_CMN_C,
2365 .data = DPIO_PHY2,
2366 },
2367 {
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002368 .name = "AUX A",
2369 .domains = GLK_DISPLAY_AUX_A_POWER_DOMAINS,
2370 .ops = &skl_power_well_ops,
2371 .id = GLK_DISP_PW_AUX_A,
2372 },
2373 {
2374 .name = "AUX B",
2375 .domains = GLK_DISPLAY_AUX_B_POWER_DOMAINS,
2376 .ops = &skl_power_well_ops,
2377 .id = GLK_DISP_PW_AUX_B,
2378 },
2379 {
2380 .name = "AUX C",
2381 .domains = GLK_DISPLAY_AUX_C_POWER_DOMAINS,
2382 .ops = &skl_power_well_ops,
2383 .id = GLK_DISP_PW_AUX_C,
2384 },
2385 {
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002386 .name = "DDI A IO power well",
2387 .domains = GLK_DISPLAY_DDI_IO_A_POWER_DOMAINS,
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002388 .ops = &skl_power_well_ops,
2389 .id = GLK_DISP_PW_DDI_A,
2390 },
2391 {
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002392 .name = "DDI B IO power well",
2393 .domains = GLK_DISPLAY_DDI_IO_B_POWER_DOMAINS,
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002394 .ops = &skl_power_well_ops,
2395 .id = SKL_DISP_PW_DDI_B,
2396 },
2397 {
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002398 .name = "DDI C IO power well",
2399 .domains = GLK_DISPLAY_DDI_IO_C_POWER_DOMAINS,
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002400 .ops = &skl_power_well_ops,
2401 .id = SKL_DISP_PW_DDI_C,
2402 },
2403};
2404
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002405static struct i915_power_well cnl_power_wells[] = {
2406 {
2407 .name = "always-on",
2408 .always_on = 1,
2409 .domains = POWER_DOMAIN_MASK,
2410 .ops = &i9xx_always_on_power_well_ops,
2411 },
2412 {
2413 .name = "power well 1",
2414 /* Handled by the DMC firmware */
2415 .domains = 0,
2416 .ops = &skl_power_well_ops,
2417 .id = SKL_DISP_PW_1,
2418 },
2419 {
2420 .name = "AUX A",
2421 .domains = CNL_DISPLAY_AUX_A_POWER_DOMAINS,
2422 .ops = &skl_power_well_ops,
2423 .id = CNL_DISP_PW_AUX_A,
2424 },
2425 {
2426 .name = "AUX B",
2427 .domains = CNL_DISPLAY_AUX_B_POWER_DOMAINS,
2428 .ops = &skl_power_well_ops,
2429 .id = CNL_DISP_PW_AUX_B,
2430 },
2431 {
2432 .name = "AUX C",
2433 .domains = CNL_DISPLAY_AUX_C_POWER_DOMAINS,
2434 .ops = &skl_power_well_ops,
2435 .id = CNL_DISP_PW_AUX_C,
2436 },
2437 {
2438 .name = "AUX D",
2439 .domains = CNL_DISPLAY_AUX_D_POWER_DOMAINS,
2440 .ops = &skl_power_well_ops,
2441 .id = CNL_DISP_PW_AUX_D,
2442 },
2443 {
2444 .name = "DC off",
2445 .domains = CNL_DISPLAY_DC_OFF_POWER_DOMAINS,
2446 .ops = &gen9_dc_off_power_well_ops,
2447 .id = SKL_DISP_PW_DC_OFF,
2448 },
2449 {
2450 .name = "power well 2",
2451 .domains = CNL_DISPLAY_POWERWELL_2_POWER_DOMAINS,
2452 .ops = &skl_power_well_ops,
2453 .id = SKL_DISP_PW_2,
2454 },
2455 {
2456 .name = "DDI A IO power well",
2457 .domains = CNL_DISPLAY_DDI_A_IO_POWER_DOMAINS,
2458 .ops = &skl_power_well_ops,
2459 .id = CNL_DISP_PW_DDI_A,
2460 },
2461 {
2462 .name = "DDI B IO power well",
2463 .domains = CNL_DISPLAY_DDI_B_IO_POWER_DOMAINS,
2464 .ops = &skl_power_well_ops,
2465 .id = SKL_DISP_PW_DDI_B,
2466 },
2467 {
2468 .name = "DDI C IO power well",
2469 .domains = CNL_DISPLAY_DDI_C_IO_POWER_DOMAINS,
2470 .ops = &skl_power_well_ops,
2471 .id = SKL_DISP_PW_DDI_C,
2472 },
2473 {
2474 .name = "DDI D IO power well",
2475 .domains = CNL_DISPLAY_DDI_D_IO_POWER_DOMAINS,
2476 .ops = &skl_power_well_ops,
2477 .id = SKL_DISP_PW_DDI_D,
2478 },
2479};
2480
Imre Deak1b0e3a02015-11-05 23:04:11 +02002481static int
2482sanitize_disable_power_well_option(const struct drm_i915_private *dev_priv,
2483 int disable_power_well)
2484{
2485 if (disable_power_well >= 0)
2486 return !!disable_power_well;
2487
Imre Deak1b0e3a02015-11-05 23:04:11 +02002488 return 1;
2489}
2490
Imre Deaka37baf32016-02-29 22:49:03 +02002491static uint32_t get_allowed_dc_mask(const struct drm_i915_private *dev_priv,
2492 int enable_dc)
2493{
2494 uint32_t mask;
2495 int requested_dc;
2496 int max_dc;
2497
Rodrigo Vivi6d6a8972017-07-06 13:45:08 -07002498 if (IS_GEN9_BC(dev_priv) || IS_CANNONLAKE(dev_priv)) {
Imre Deaka37baf32016-02-29 22:49:03 +02002499 max_dc = 2;
2500 mask = 0;
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02002501 } else if (IS_GEN9_LP(dev_priv)) {
Imre Deaka37baf32016-02-29 22:49:03 +02002502 max_dc = 1;
2503 /*
2504 * DC9 has a separate HW flow from the rest of the DC states,
2505 * not depending on the DMC firmware. It's needed by system
2506 * suspend/resume, so allow it unconditionally.
2507 */
2508 mask = DC_STATE_EN_DC9;
2509 } else {
2510 max_dc = 0;
2511 mask = 0;
2512 }
2513
Imre Deak66e2c4c2016-02-29 22:49:04 +02002514 if (!i915.disable_power_well)
2515 max_dc = 0;
2516
Imre Deaka37baf32016-02-29 22:49:03 +02002517 if (enable_dc >= 0 && enable_dc <= max_dc) {
2518 requested_dc = enable_dc;
2519 } else if (enable_dc == -1) {
2520 requested_dc = max_dc;
2521 } else if (enable_dc > max_dc && enable_dc <= 2) {
2522 DRM_DEBUG_KMS("Adjusting requested max DC state (%d->%d)\n",
2523 enable_dc, max_dc);
2524 requested_dc = max_dc;
2525 } else {
2526 DRM_ERROR("Unexpected value for enable_dc (%d)\n", enable_dc);
2527 requested_dc = max_dc;
2528 }
2529
2530 if (requested_dc > 1)
2531 mask |= DC_STATE_EN_UPTO_DC6;
2532 if (requested_dc > 0)
2533 mask |= DC_STATE_EN_UPTO_DC5;
2534
2535 DRM_DEBUG_KMS("Allowed DC state mask %02x\n", mask);
2536
2537 return mask;
2538}
2539
Daniel Vetter9c065a72014-09-30 10:56:38 +02002540#define set_power_wells(power_domains, __power_wells) ({ \
2541 (power_domains)->power_wells = (__power_wells); \
2542 (power_domains)->power_well_count = ARRAY_SIZE(__power_wells); \
2543})
2544
Daniel Vettere4e76842014-09-30 10:56:42 +02002545/**
2546 * intel_power_domains_init - initializes the power domain structures
2547 * @dev_priv: i915 device instance
2548 *
2549 * Initializes the power domain structures for @dev_priv depending upon the
2550 * supported platform.
2551 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02002552int intel_power_domains_init(struct drm_i915_private *dev_priv)
2553{
2554 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2555
Imre Deak1b0e3a02015-11-05 23:04:11 +02002556 i915.disable_power_well = sanitize_disable_power_well_option(dev_priv,
2557 i915.disable_power_well);
Imre Deaka37baf32016-02-29 22:49:03 +02002558 dev_priv->csr.allowed_dc_mask = get_allowed_dc_mask(dev_priv,
2559 i915.enable_dc);
Imre Deak1b0e3a02015-11-05 23:04:11 +02002560
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02002561 BUILD_BUG_ON(POWER_DOMAIN_NUM > 64);
Ville Syrjäläf0ab43e2015-11-09 16:48:19 +01002562
Daniel Vetter9c065a72014-09-30 10:56:38 +02002563 mutex_init(&power_domains->lock);
2564
2565 /*
2566 * The enabling order will be from lower to higher indexed wells,
2567 * the disabling order is reversed.
2568 */
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002569 if (IS_HASWELL(dev_priv)) {
Daniel Vetter9c065a72014-09-30 10:56:38 +02002570 set_power_wells(power_domains, hsw_power_wells);
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002571 } else if (IS_BROADWELL(dev_priv)) {
Daniel Vetter9c065a72014-09-30 10:56:38 +02002572 set_power_wells(power_domains, bdw_power_wells);
Rodrigo Vivib976dc52017-01-23 10:32:37 -08002573 } else if (IS_GEN9_BC(dev_priv)) {
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002574 set_power_wells(power_domains, skl_power_wells);
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002575 } else if (IS_CANNONLAKE(dev_priv)) {
2576 set_power_wells(power_domains, cnl_power_wells);
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002577 } else if (IS_BROXTON(dev_priv)) {
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302578 set_power_wells(power_domains, bxt_power_wells);
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002579 } else if (IS_GEMINILAKE(dev_priv)) {
2580 set_power_wells(power_domains, glk_power_wells);
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002581 } else if (IS_CHERRYVIEW(dev_priv)) {
Daniel Vetter9c065a72014-09-30 10:56:38 +02002582 set_power_wells(power_domains, chv_power_wells);
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002583 } else if (IS_VALLEYVIEW(dev_priv)) {
Daniel Vetter9c065a72014-09-30 10:56:38 +02002584 set_power_wells(power_domains, vlv_power_wells);
Ville Syrjälä2ee0da12017-06-01 17:36:16 +03002585 } else if (IS_I830(dev_priv)) {
2586 set_power_wells(power_domains, i830_power_wells);
Daniel Vetter9c065a72014-09-30 10:56:38 +02002587 } else {
2588 set_power_wells(power_domains, i9xx_always_on_power_well);
2589 }
2590
2591 return 0;
2592}
2593
Daniel Vettere4e76842014-09-30 10:56:42 +02002594/**
2595 * intel_power_domains_fini - finalizes the power domain structures
2596 * @dev_priv: i915 device instance
2597 *
2598 * Finalizes the power domain structures for @dev_priv depending upon the
2599 * supported platform. This function also disables runtime pm and ensures that
2600 * the device stays powered up so that the driver can be reloaded.
2601 */
Daniel Vetterf458ebb2014-09-30 10:56:39 +02002602void intel_power_domains_fini(struct drm_i915_private *dev_priv)
Daniel Vetter9c065a72014-09-30 10:56:38 +02002603{
David Weinehallc49d13e2016-08-22 13:32:42 +03002604 struct device *kdev = &dev_priv->drm.pdev->dev;
Imre Deak25b181b2015-12-17 13:44:56 +02002605
Imre Deakaabee1b2015-12-15 20:10:29 +02002606 /*
2607 * The i915.ko module is still not prepared to be loaded when
Daniel Vetterf458ebb2014-09-30 10:56:39 +02002608 * the power well is not enabled, so just enable it in case
Imre Deakaabee1b2015-12-15 20:10:29 +02002609 * we're going to unload/reload.
2610 * The following also reacquires the RPM reference the core passed
2611 * to the driver during loading, which is dropped in
2612 * intel_runtime_pm_enable(). We have to hand back the control of the
2613 * device to the core with this reference held.
2614 */
Daniel Vetterf458ebb2014-09-30 10:56:39 +02002615 intel_display_set_init_power(dev_priv, true);
Imre Deakd314cd42015-11-17 17:44:23 +02002616
2617 /* Remove the refcount we took to keep power well support disabled. */
2618 if (!i915.disable_power_well)
2619 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
Imre Deak25b181b2015-12-17 13:44:56 +02002620
2621 /*
2622 * Remove the refcount we took in intel_runtime_pm_enable() in case
2623 * the platform doesn't support runtime PM.
2624 */
2625 if (!HAS_RUNTIME_PM(dev_priv))
David Weinehallc49d13e2016-08-22 13:32:42 +03002626 pm_runtime_put(kdev);
Daniel Vetter9c065a72014-09-30 10:56:38 +02002627}
2628
Imre Deak30eade12015-11-04 19:24:13 +02002629static void intel_power_domains_sync_hw(struct drm_i915_private *dev_priv)
Daniel Vetter9c065a72014-09-30 10:56:38 +02002630{
2631 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2632 struct i915_power_well *power_well;
Daniel Vetter9c065a72014-09-30 10:56:38 +02002633
2634 mutex_lock(&power_domains->lock);
Imre Deak75ccb2e2017-02-17 17:39:43 +02002635 for_each_power_well(dev_priv, power_well) {
Daniel Vetter9c065a72014-09-30 10:56:38 +02002636 power_well->ops->sync_hw(dev_priv, power_well);
2637 power_well->hw_enabled = power_well->ops->is_enabled(dev_priv,
2638 power_well);
2639 }
2640 mutex_unlock(&power_domains->lock);
2641}
2642
Ville Syrjälä70c2c182016-05-13 23:41:30 +03002643static void gen9_dbuf_enable(struct drm_i915_private *dev_priv)
2644{
2645 I915_WRITE(DBUF_CTL, I915_READ(DBUF_CTL) | DBUF_POWER_REQUEST);
2646 POSTING_READ(DBUF_CTL);
2647
2648 udelay(10);
2649
2650 if (!(I915_READ(DBUF_CTL) & DBUF_POWER_STATE))
2651 DRM_ERROR("DBuf power enable timeout\n");
2652}
2653
2654static void gen9_dbuf_disable(struct drm_i915_private *dev_priv)
2655{
2656 I915_WRITE(DBUF_CTL, I915_READ(DBUF_CTL) & ~DBUF_POWER_REQUEST);
2657 POSTING_READ(DBUF_CTL);
2658
2659 udelay(10);
2660
2661 if (I915_READ(DBUF_CTL) & DBUF_POWER_STATE)
2662 DRM_ERROR("DBuf power disable timeout!\n");
2663}
2664
Imre Deak73dfc222015-11-17 17:33:53 +02002665static void skl_display_core_init(struct drm_i915_private *dev_priv,
Imre Deak443a93a2016-04-04 15:42:57 +03002666 bool resume)
Imre Deak73dfc222015-11-17 17:33:53 +02002667{
2668 struct i915_power_domains *power_domains = &dev_priv->power_domains;
Imre Deak443a93a2016-04-04 15:42:57 +03002669 struct i915_power_well *well;
Imre Deak73dfc222015-11-17 17:33:53 +02002670 uint32_t val;
2671
Imre Deakd26fa1d2015-11-04 19:24:17 +02002672 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
2673
Imre Deak73dfc222015-11-17 17:33:53 +02002674 /* enable PCH reset handshake */
2675 val = I915_READ(HSW_NDE_RSTWRN_OPT);
2676 I915_WRITE(HSW_NDE_RSTWRN_OPT, val | RESET_PCH_HANDSHAKE_ENABLE);
2677
2678 /* enable PG1 and Misc I/O */
2679 mutex_lock(&power_domains->lock);
Imre Deak443a93a2016-04-04 15:42:57 +03002680
2681 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
2682 intel_power_well_enable(dev_priv, well);
2683
2684 well = lookup_power_well(dev_priv, SKL_DISP_PW_MISC_IO);
2685 intel_power_well_enable(dev_priv, well);
2686
Imre Deak73dfc222015-11-17 17:33:53 +02002687 mutex_unlock(&power_domains->lock);
2688
Imre Deak73dfc222015-11-17 17:33:53 +02002689 skl_init_cdclk(dev_priv);
2690
Ville Syrjälä70c2c182016-05-13 23:41:30 +03002691 gen9_dbuf_enable(dev_priv);
2692
Ville Syrjälä9f7eb312016-05-13 23:41:29 +03002693 if (resume && dev_priv->csr.dmc_payload)
Imre Deak2abc5252016-03-04 21:57:41 +02002694 intel_csr_load_program(dev_priv);
Imre Deak73dfc222015-11-17 17:33:53 +02002695}
2696
2697static void skl_display_core_uninit(struct drm_i915_private *dev_priv)
2698{
2699 struct i915_power_domains *power_domains = &dev_priv->power_domains;
Imre Deak443a93a2016-04-04 15:42:57 +03002700 struct i915_power_well *well;
Imre Deak73dfc222015-11-17 17:33:53 +02002701
Imre Deakd26fa1d2015-11-04 19:24:17 +02002702 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
2703
Ville Syrjälä70c2c182016-05-13 23:41:30 +03002704 gen9_dbuf_disable(dev_priv);
2705
Imre Deak73dfc222015-11-17 17:33:53 +02002706 skl_uninit_cdclk(dev_priv);
2707
2708 /* The spec doesn't call for removing the reset handshake flag */
2709 /* disable PG1 and Misc I/O */
Imre Deak443a93a2016-04-04 15:42:57 +03002710
Imre Deak73dfc222015-11-17 17:33:53 +02002711 mutex_lock(&power_domains->lock);
Imre Deak443a93a2016-04-04 15:42:57 +03002712
Imre Deakedfda8e2017-06-29 18:36:59 +03002713 /*
2714 * BSpec says to keep the MISC IO power well enabled here, only
2715 * remove our request for power well 1.
Imre Deak42d93662017-06-29 18:37:01 +03002716 * Note that even though the driver's request is removed power well 1
2717 * may stay enabled after this due to DMC's own request on it.
Imre Deakedfda8e2017-06-29 18:36:59 +03002718 */
Imre Deak443a93a2016-04-04 15:42:57 +03002719 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
2720 intel_power_well_disable(dev_priv, well);
2721
Imre Deak73dfc222015-11-17 17:33:53 +02002722 mutex_unlock(&power_domains->lock);
Imre Deak846c6b22017-06-29 18:36:58 +03002723
2724 usleep_range(10, 30); /* 10 us delay per Bspec */
Imre Deak73dfc222015-11-17 17:33:53 +02002725}
2726
Imre Deakd7d7c9e2016-04-01 16:02:42 +03002727void bxt_display_core_init(struct drm_i915_private *dev_priv,
2728 bool resume)
2729{
2730 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2731 struct i915_power_well *well;
2732 uint32_t val;
2733
2734 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
2735
2736 /*
2737 * NDE_RSTWRN_OPT RST PCH Handshake En must always be 0b on BXT
2738 * or else the reset will hang because there is no PCH to respond.
2739 * Move the handshake programming to initialization sequence.
2740 * Previously was left up to BIOS.
2741 */
2742 val = I915_READ(HSW_NDE_RSTWRN_OPT);
2743 val &= ~RESET_PCH_HANDSHAKE_ENABLE;
2744 I915_WRITE(HSW_NDE_RSTWRN_OPT, val);
2745
2746 /* Enable PG1 */
2747 mutex_lock(&power_domains->lock);
2748
2749 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
2750 intel_power_well_enable(dev_priv, well);
2751
2752 mutex_unlock(&power_domains->lock);
2753
Imre Deak324513c2016-06-13 16:44:36 +03002754 bxt_init_cdclk(dev_priv);
Ville Syrjälä70c2c182016-05-13 23:41:30 +03002755
2756 gen9_dbuf_enable(dev_priv);
2757
Imre Deakd7d7c9e2016-04-01 16:02:42 +03002758 if (resume && dev_priv->csr.dmc_payload)
2759 intel_csr_load_program(dev_priv);
2760}
2761
2762void bxt_display_core_uninit(struct drm_i915_private *dev_priv)
2763{
2764 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2765 struct i915_power_well *well;
2766
2767 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
2768
Ville Syrjälä70c2c182016-05-13 23:41:30 +03002769 gen9_dbuf_disable(dev_priv);
2770
Imre Deak324513c2016-06-13 16:44:36 +03002771 bxt_uninit_cdclk(dev_priv);
Imre Deakd7d7c9e2016-04-01 16:02:42 +03002772
2773 /* The spec doesn't call for removing the reset handshake flag */
2774
Imre Deak42d93662017-06-29 18:37:01 +03002775 /*
2776 * Disable PW1 (PG1).
2777 * Note that even though the driver's request is removed power well 1
2778 * may stay enabled after this due to DMC's own request on it.
2779 */
Imre Deakd7d7c9e2016-04-01 16:02:42 +03002780 mutex_lock(&power_domains->lock);
2781
2782 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
2783 intel_power_well_disable(dev_priv, well);
2784
2785 mutex_unlock(&power_domains->lock);
Imre Deak846c6b22017-06-29 18:36:58 +03002786
2787 usleep_range(10, 30); /* 10 us delay per Bspec */
Imre Deakd7d7c9e2016-04-01 16:02:42 +03002788}
2789
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07002790#define CNL_PROCMON_IDX(val) \
2791 (((val) & (PROCESS_INFO_MASK | VOLTAGE_INFO_MASK)) >> VOLTAGE_INFO_SHIFT)
2792#define NUM_CNL_PROCMON \
2793 (CNL_PROCMON_IDX(VOLTAGE_INFO_MASK | PROCESS_INFO_MASK) + 1)
2794
2795static const struct cnl_procmon {
2796 u32 dw1, dw9, dw10;
2797} cnl_procmon_values[NUM_CNL_PROCMON] = {
2798 [CNL_PROCMON_IDX(VOLTAGE_INFO_0_85V | PROCESS_INFO_DOT_0)] =
2799 { .dw1 = 0x00 << 16, .dw9 = 0x62AB67BB, .dw10 = 0x51914F96, },
2800 [CNL_PROCMON_IDX(VOLTAGE_INFO_0_95V | PROCESS_INFO_DOT_0)] =
2801 { .dw1 = 0x00 << 16, .dw9 = 0x86E172C7, .dw10 = 0x77CA5EAB, },
2802 [CNL_PROCMON_IDX(VOLTAGE_INFO_0_95V | PROCESS_INFO_DOT_1)] =
2803 { .dw1 = 0x00 << 16, .dw9 = 0x93F87FE1, .dw10 = 0x8AE871C5, },
2804 [CNL_PROCMON_IDX(VOLTAGE_INFO_1_05V | PROCESS_INFO_DOT_0)] =
2805 { .dw1 = 0x00 << 16, .dw9 = 0x98FA82DD, .dw10 = 0x89E46DC1, },
2806 [CNL_PROCMON_IDX(VOLTAGE_INFO_1_05V | PROCESS_INFO_DOT_1)] =
2807 { .dw1 = 0x44 << 16, .dw9 = 0x9A00AB25, .dw10 = 0x8AE38FF1, },
2808};
2809
2810static void cnl_display_core_init(struct drm_i915_private *dev_priv, bool resume)
2811{
2812 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2813 const struct cnl_procmon *procmon;
2814 struct i915_power_well *well;
2815 u32 val;
2816
2817 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
2818
2819 /* 1. Enable PCH Reset Handshake */
2820 val = I915_READ(HSW_NDE_RSTWRN_OPT);
2821 val |= RESET_PCH_HANDSHAKE_ENABLE;
2822 I915_WRITE(HSW_NDE_RSTWRN_OPT, val);
2823
2824 /* 2. Enable Comp */
2825 val = I915_READ(CHICKEN_MISC_2);
2826 val &= ~COMP_PWR_DOWN;
2827 I915_WRITE(CHICKEN_MISC_2, val);
2828
2829 val = I915_READ(CNL_PORT_COMP_DW3);
2830 procmon = &cnl_procmon_values[CNL_PROCMON_IDX(val)];
2831
2832 WARN_ON(procmon->dw10 == 0);
2833
2834 val = I915_READ(CNL_PORT_COMP_DW1);
2835 val &= ~((0xff << 16) | 0xff);
2836 val |= procmon->dw1;
2837 I915_WRITE(CNL_PORT_COMP_DW1, val);
2838
2839 I915_WRITE(CNL_PORT_COMP_DW9, procmon->dw9);
2840 I915_WRITE(CNL_PORT_COMP_DW10, procmon->dw10);
2841
2842 val = I915_READ(CNL_PORT_COMP_DW0);
2843 val |= COMP_INIT;
2844 I915_WRITE(CNL_PORT_COMP_DW0, val);
2845
2846 /* 3. */
2847 val = I915_READ(CNL_PORT_CL1CM_DW5);
2848 val |= CL_POWER_DOWN_ENABLE;
2849 I915_WRITE(CNL_PORT_CL1CM_DW5, val);
2850
Imre Deakb38131f2017-06-29 18:37:02 +03002851 /*
2852 * 4. Enable Power Well 1 (PG1).
2853 * The AUX IO power wells will be enabled on demand.
2854 */
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07002855 mutex_lock(&power_domains->lock);
2856 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
2857 intel_power_well_enable(dev_priv, well);
2858 mutex_unlock(&power_domains->lock);
2859
2860 /* 5. Enable CD clock */
2861 cnl_init_cdclk(dev_priv);
2862
2863 /* 6. Enable DBUF */
2864 gen9_dbuf_enable(dev_priv);
2865}
2866
2867#undef CNL_PROCMON_IDX
2868#undef NUM_CNL_PROCMON
2869
2870static void cnl_display_core_uninit(struct drm_i915_private *dev_priv)
2871{
2872 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2873 struct i915_power_well *well;
2874 u32 val;
2875
2876 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
2877
2878 /* 1. Disable all display engine functions -> aready done */
2879
2880 /* 2. Disable DBUF */
2881 gen9_dbuf_disable(dev_priv);
2882
2883 /* 3. Disable CD clock */
2884 cnl_uninit_cdclk(dev_priv);
2885
Imre Deakb38131f2017-06-29 18:37:02 +03002886 /*
2887 * 4. Disable Power Well 1 (PG1).
2888 * The AUX IO power wells are toggled on demand, so they are already
2889 * disabled at this point.
2890 */
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07002891 mutex_lock(&power_domains->lock);
2892 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
2893 intel_power_well_disable(dev_priv, well);
2894 mutex_unlock(&power_domains->lock);
2895
Imre Deak846c6b22017-06-29 18:36:58 +03002896 usleep_range(10, 30); /* 10 us delay per Bspec */
2897
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07002898 /* 5. Disable Comp */
2899 val = I915_READ(CHICKEN_MISC_2);
2900 val |= COMP_PWR_DOWN;
2901 I915_WRITE(CHICKEN_MISC_2, val);
2902}
2903
Ville Syrjälä70722462015-04-10 18:21:28 +03002904static void chv_phy_control_init(struct drm_i915_private *dev_priv)
2905{
2906 struct i915_power_well *cmn_bc =
2907 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_BC);
2908 struct i915_power_well *cmn_d =
2909 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_D);
2910
2911 /*
2912 * DISPLAY_PHY_CONTROL can get corrupted if read. As a
2913 * workaround never ever read DISPLAY_PHY_CONTROL, and
2914 * instead maintain a shadow copy ourselves. Use the actual
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002915 * power well state and lane status to reconstruct the
2916 * expected initial value.
Ville Syrjälä70722462015-04-10 18:21:28 +03002917 */
2918 dev_priv->chv_phy_control =
Ville Syrjäläbc284542015-05-26 20:22:38 +03002919 PHY_LDO_SEQ_DELAY(PHY_LDO_DELAY_600NS, DPIO_PHY0) |
2920 PHY_LDO_SEQ_DELAY(PHY_LDO_DELAY_600NS, DPIO_PHY1) |
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002921 PHY_CH_POWER_MODE(PHY_CH_DEEP_PSR, DPIO_PHY0, DPIO_CH0) |
2922 PHY_CH_POWER_MODE(PHY_CH_DEEP_PSR, DPIO_PHY0, DPIO_CH1) |
2923 PHY_CH_POWER_MODE(PHY_CH_DEEP_PSR, DPIO_PHY1, DPIO_CH0);
2924
2925 /*
2926 * If all lanes are disabled we leave the override disabled
2927 * with all power down bits cleared to match the state we
2928 * would use after disabling the port. Otherwise enable the
2929 * override and set the lane powerdown bits accding to the
2930 * current lane status.
2931 */
2932 if (cmn_bc->ops->is_enabled(dev_priv, cmn_bc)) {
2933 uint32_t status = I915_READ(DPLL(PIPE_A));
2934 unsigned int mask;
2935
2936 mask = status & DPLL_PORTB_READY_MASK;
2937 if (mask == 0xf)
2938 mask = 0x0;
2939 else
2940 dev_priv->chv_phy_control |=
2941 PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY0, DPIO_CH0);
2942
2943 dev_priv->chv_phy_control |=
2944 PHY_CH_POWER_DOWN_OVRD(mask, DPIO_PHY0, DPIO_CH0);
2945
2946 mask = (status & DPLL_PORTC_READY_MASK) >> 4;
2947 if (mask == 0xf)
2948 mask = 0x0;
2949 else
2950 dev_priv->chv_phy_control |=
2951 PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY0, DPIO_CH1);
2952
2953 dev_priv->chv_phy_control |=
2954 PHY_CH_POWER_DOWN_OVRD(mask, DPIO_PHY0, DPIO_CH1);
2955
Ville Syrjälä70722462015-04-10 18:21:28 +03002956 dev_priv->chv_phy_control |= PHY_COM_LANE_RESET_DEASSERT(DPIO_PHY0);
Ville Syrjälä3be60de2015-09-08 18:05:45 +03002957
2958 dev_priv->chv_phy_assert[DPIO_PHY0] = false;
2959 } else {
2960 dev_priv->chv_phy_assert[DPIO_PHY0] = true;
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002961 }
2962
2963 if (cmn_d->ops->is_enabled(dev_priv, cmn_d)) {
2964 uint32_t status = I915_READ(DPIO_PHY_STATUS);
2965 unsigned int mask;
2966
2967 mask = status & DPLL_PORTD_READY_MASK;
2968
2969 if (mask == 0xf)
2970 mask = 0x0;
2971 else
2972 dev_priv->chv_phy_control |=
2973 PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY1, DPIO_CH0);
2974
2975 dev_priv->chv_phy_control |=
2976 PHY_CH_POWER_DOWN_OVRD(mask, DPIO_PHY1, DPIO_CH0);
2977
Ville Syrjälä70722462015-04-10 18:21:28 +03002978 dev_priv->chv_phy_control |= PHY_COM_LANE_RESET_DEASSERT(DPIO_PHY1);
Ville Syrjälä3be60de2015-09-08 18:05:45 +03002979
2980 dev_priv->chv_phy_assert[DPIO_PHY1] = false;
2981 } else {
2982 dev_priv->chv_phy_assert[DPIO_PHY1] = true;
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002983 }
2984
2985 I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
2986
2987 DRM_DEBUG_KMS("Initial PHY_CONTROL=0x%08x\n",
2988 dev_priv->chv_phy_control);
Ville Syrjälä70722462015-04-10 18:21:28 +03002989}
2990
Daniel Vetter9c065a72014-09-30 10:56:38 +02002991static void vlv_cmnlane_wa(struct drm_i915_private *dev_priv)
2992{
2993 struct i915_power_well *cmn =
2994 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_BC);
2995 struct i915_power_well *disp2d =
2996 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DISP2D);
2997
Daniel Vetter9c065a72014-09-30 10:56:38 +02002998 /* If the display might be already active skip this */
Ville Syrjälä5d93a6e2014-10-16 20:52:33 +03002999 if (cmn->ops->is_enabled(dev_priv, cmn) &&
3000 disp2d->ops->is_enabled(dev_priv, disp2d) &&
Daniel Vetter9c065a72014-09-30 10:56:38 +02003001 I915_READ(DPIO_CTL) & DPIO_CMNRST)
3002 return;
3003
3004 DRM_DEBUG_KMS("toggling display PHY side reset\n");
3005
3006 /* cmnlane needs DPLL registers */
3007 disp2d->ops->enable(dev_priv, disp2d);
3008
3009 /*
3010 * From VLV2A0_DP_eDP_HDMI_DPIO_driver_vbios_notes_11.docx:
3011 * Need to assert and de-assert PHY SB reset by gating the
3012 * common lane power, then un-gating it.
3013 * Simply ungating isn't enough to reset the PHY enough to get
3014 * ports and lanes running.
3015 */
3016 cmn->ops->disable(dev_priv, cmn);
3017}
3018
Daniel Vettere4e76842014-09-30 10:56:42 +02003019/**
3020 * intel_power_domains_init_hw - initialize hardware power domain state
3021 * @dev_priv: i915 device instance
Tvrtko Ursulin14bb2c12016-06-03 14:02:17 +01003022 * @resume: Called from resume code paths or not
Daniel Vettere4e76842014-09-30 10:56:42 +02003023 *
3024 * This function initializes the hardware power domain state and enables all
Imre Deak8d8c3862017-02-17 17:39:46 +02003025 * power wells belonging to the INIT power domain. Power wells in other
3026 * domains (and not in the INIT domain) are referenced or disabled during the
3027 * modeset state HW readout. After that the reference count of each power well
3028 * must match its HW enabled state, see intel_power_domains_verify_state().
Daniel Vettere4e76842014-09-30 10:56:42 +02003029 */
Imre Deak73dfc222015-11-17 17:33:53 +02003030void intel_power_domains_init_hw(struct drm_i915_private *dev_priv, bool resume)
Daniel Vetter9c065a72014-09-30 10:56:38 +02003031{
Daniel Vetter9c065a72014-09-30 10:56:38 +02003032 struct i915_power_domains *power_domains = &dev_priv->power_domains;
3033
3034 power_domains->initializing = true;
3035
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07003036 if (IS_CANNONLAKE(dev_priv)) {
3037 cnl_display_core_init(dev_priv, resume);
3038 } else if (IS_GEN9_BC(dev_priv)) {
Imre Deak73dfc222015-11-17 17:33:53 +02003039 skl_display_core_init(dev_priv, resume);
Ander Conselvan de Oliveirab817c442016-12-02 10:23:56 +02003040 } else if (IS_GEN9_LP(dev_priv)) {
Imre Deakd7d7c9e2016-04-01 16:02:42 +03003041 bxt_display_core_init(dev_priv, resume);
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01003042 } else if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä770effb2015-07-08 23:45:51 +03003043 mutex_lock(&power_domains->lock);
Ville Syrjälä70722462015-04-10 18:21:28 +03003044 chv_phy_control_init(dev_priv);
Ville Syrjälä770effb2015-07-08 23:45:51 +03003045 mutex_unlock(&power_domains->lock);
Tvrtko Ursulin11a914c2016-10-13 11:03:08 +01003046 } else if (IS_VALLEYVIEW(dev_priv)) {
Daniel Vetter9c065a72014-09-30 10:56:38 +02003047 mutex_lock(&power_domains->lock);
3048 vlv_cmnlane_wa(dev_priv);
3049 mutex_unlock(&power_domains->lock);
3050 }
3051
3052 /* For now, we need the power well to be always enabled. */
3053 intel_display_set_init_power(dev_priv, true);
Imre Deakd314cd42015-11-17 17:44:23 +02003054 /* Disable power support if the user asked so. */
3055 if (!i915.disable_power_well)
3056 intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
Imre Deak30eade12015-11-04 19:24:13 +02003057 intel_power_domains_sync_hw(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02003058 power_domains->initializing = false;
3059}
3060
Daniel Vettere4e76842014-09-30 10:56:42 +02003061/**
Imre Deak73dfc222015-11-17 17:33:53 +02003062 * intel_power_domains_suspend - suspend power domain state
3063 * @dev_priv: i915 device instance
3064 *
3065 * This function prepares the hardware power domain state before entering
3066 * system suspend. It must be paired with intel_power_domains_init_hw().
3067 */
3068void intel_power_domains_suspend(struct drm_i915_private *dev_priv)
3069{
Imre Deakd314cd42015-11-17 17:44:23 +02003070 /*
3071 * Even if power well support was disabled we still want to disable
3072 * power wells while we are system suspended.
3073 */
3074 if (!i915.disable_power_well)
3075 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
Imre Deak2622d792016-02-29 22:49:02 +02003076
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07003077 if (IS_CANNONLAKE(dev_priv))
3078 cnl_display_core_uninit(dev_priv);
3079 else if (IS_GEN9_BC(dev_priv))
Imre Deak2622d792016-02-29 22:49:02 +02003080 skl_display_core_uninit(dev_priv);
Ander Conselvan de Oliveirab817c442016-12-02 10:23:56 +02003081 else if (IS_GEN9_LP(dev_priv))
Imre Deakd7d7c9e2016-04-01 16:02:42 +03003082 bxt_display_core_uninit(dev_priv);
Imre Deak73dfc222015-11-17 17:33:53 +02003083}
3084
Imre Deak8d8c3862017-02-17 17:39:46 +02003085static void intel_power_domains_dump_info(struct drm_i915_private *dev_priv)
3086{
3087 struct i915_power_domains *power_domains = &dev_priv->power_domains;
3088 struct i915_power_well *power_well;
3089
3090 for_each_power_well(dev_priv, power_well) {
3091 enum intel_display_power_domain domain;
3092
3093 DRM_DEBUG_DRIVER("%-25s %d\n",
3094 power_well->name, power_well->count);
3095
3096 for_each_power_domain(domain, power_well->domains)
3097 DRM_DEBUG_DRIVER(" %-23s %d\n",
3098 intel_display_power_domain_str(domain),
3099 power_domains->domain_use_count[domain]);
3100 }
3101}
3102
3103/**
3104 * intel_power_domains_verify_state - verify the HW/SW state for all power wells
3105 * @dev_priv: i915 device instance
3106 *
3107 * Verify if the reference count of each power well matches its HW enabled
3108 * state and the total refcount of the domains it belongs to. This must be
3109 * called after modeset HW state sanitization, which is responsible for
3110 * acquiring reference counts for any power wells in use and disabling the
3111 * ones left on by BIOS but not required by any active output.
3112 */
3113void intel_power_domains_verify_state(struct drm_i915_private *dev_priv)
3114{
3115 struct i915_power_domains *power_domains = &dev_priv->power_domains;
3116 struct i915_power_well *power_well;
3117 bool dump_domain_info;
3118
3119 mutex_lock(&power_domains->lock);
3120
3121 dump_domain_info = false;
3122 for_each_power_well(dev_priv, power_well) {
3123 enum intel_display_power_domain domain;
3124 int domains_count;
3125 bool enabled;
3126
3127 /*
3128 * Power wells not belonging to any domain (like the MISC_IO
3129 * and PW1 power wells) are under FW control, so ignore them,
3130 * since their state can change asynchronously.
3131 */
3132 if (!power_well->domains)
3133 continue;
3134
3135 enabled = power_well->ops->is_enabled(dev_priv, power_well);
3136 if ((power_well->count || power_well->always_on) != enabled)
3137 DRM_ERROR("power well %s state mismatch (refcount %d/enabled %d)",
3138 power_well->name, power_well->count, enabled);
3139
3140 domains_count = 0;
3141 for_each_power_domain(domain, power_well->domains)
3142 domains_count += power_domains->domain_use_count[domain];
3143
3144 if (power_well->count != domains_count) {
3145 DRM_ERROR("power well %s refcount/domain refcount mismatch "
3146 "(refcount %d/domains refcount %d)\n",
3147 power_well->name, power_well->count,
3148 domains_count);
3149 dump_domain_info = true;
3150 }
3151 }
3152
3153 if (dump_domain_info) {
3154 static bool dumped;
3155
3156 if (!dumped) {
3157 intel_power_domains_dump_info(dev_priv);
3158 dumped = true;
3159 }
3160 }
3161
3162 mutex_unlock(&power_domains->lock);
3163}
3164
Imre Deak73dfc222015-11-17 17:33:53 +02003165/**
Daniel Vettere4e76842014-09-30 10:56:42 +02003166 * intel_runtime_pm_get - grab a runtime pm reference
3167 * @dev_priv: i915 device instance
3168 *
3169 * This function grabs a device-level runtime pm reference (mostly used for GEM
3170 * code to ensure the GTT or GT is on) and ensures that it is powered up.
3171 *
3172 * Any runtime pm reference obtained by this function must have a symmetric
3173 * call to intel_runtime_pm_put() to release the reference again.
3174 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02003175void intel_runtime_pm_get(struct drm_i915_private *dev_priv)
3176{
David Weinehall52a05c32016-08-22 13:32:44 +03003177 struct pci_dev *pdev = dev_priv->drm.pdev;
3178 struct device *kdev = &pdev->dev;
Imre Deakf5073822017-03-28 12:38:55 +03003179 int ret;
Daniel Vetter9c065a72014-09-30 10:56:38 +02003180
Imre Deakf5073822017-03-28 12:38:55 +03003181 ret = pm_runtime_get_sync(kdev);
3182 WARN_ONCE(ret < 0, "pm_runtime_get_sync() failed: %d\n", ret);
Imre Deak1f814da2015-12-16 02:52:19 +02003183
3184 atomic_inc(&dev_priv->pm.wakeref_count);
Imre Deakc9b88462015-12-15 20:10:34 +02003185 assert_rpm_wakelock_held(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02003186}
3187
Daniel Vettere4e76842014-09-30 10:56:42 +02003188/**
Imre Deak09731282016-02-17 14:17:42 +02003189 * intel_runtime_pm_get_if_in_use - grab a runtime pm reference if device in use
3190 * @dev_priv: i915 device instance
3191 *
3192 * This function grabs a device-level runtime pm reference if the device is
3193 * already in use and ensures that it is powered up.
3194 *
3195 * Any runtime pm reference obtained by this function must have a symmetric
3196 * call to intel_runtime_pm_put() to release the reference again.
3197 */
3198bool intel_runtime_pm_get_if_in_use(struct drm_i915_private *dev_priv)
3199{
David Weinehall52a05c32016-08-22 13:32:44 +03003200 struct pci_dev *pdev = dev_priv->drm.pdev;
3201 struct device *kdev = &pdev->dev;
Imre Deak09731282016-02-17 14:17:42 +02003202
Chris Wilson135dc792016-02-25 21:10:28 +00003203 if (IS_ENABLED(CONFIG_PM)) {
David Weinehallc49d13e2016-08-22 13:32:42 +03003204 int ret = pm_runtime_get_if_in_use(kdev);
Imre Deak09731282016-02-17 14:17:42 +02003205
Chris Wilson135dc792016-02-25 21:10:28 +00003206 /*
3207 * In cases runtime PM is disabled by the RPM core and we get
3208 * an -EINVAL return value we are not supposed to call this
3209 * function, since the power state is undefined. This applies
3210 * atm to the late/early system suspend/resume handlers.
3211 */
Imre Deakf5073822017-03-28 12:38:55 +03003212 WARN_ONCE(ret < 0,
3213 "pm_runtime_get_if_in_use() failed: %d\n", ret);
Chris Wilson135dc792016-02-25 21:10:28 +00003214 if (ret <= 0)
3215 return false;
3216 }
Imre Deak09731282016-02-17 14:17:42 +02003217
3218 atomic_inc(&dev_priv->pm.wakeref_count);
3219 assert_rpm_wakelock_held(dev_priv);
3220
3221 return true;
3222}
3223
3224/**
Daniel Vettere4e76842014-09-30 10:56:42 +02003225 * intel_runtime_pm_get_noresume - grab a runtime pm reference
3226 * @dev_priv: i915 device instance
3227 *
3228 * This function grabs a device-level runtime pm reference (mostly used for GEM
3229 * code to ensure the GTT or GT is on).
3230 *
3231 * It will _not_ power up the device but instead only check that it's powered
3232 * on. Therefore it is only valid to call this functions from contexts where
3233 * the device is known to be powered up and where trying to power it up would
3234 * result in hilarity and deadlocks. That pretty much means only the system
3235 * suspend/resume code where this is used to grab runtime pm references for
3236 * delayed setup down in work items.
3237 *
3238 * Any runtime pm reference obtained by this function must have a symmetric
3239 * call to intel_runtime_pm_put() to release the reference again.
3240 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02003241void intel_runtime_pm_get_noresume(struct drm_i915_private *dev_priv)
3242{
David Weinehall52a05c32016-08-22 13:32:44 +03003243 struct pci_dev *pdev = dev_priv->drm.pdev;
3244 struct device *kdev = &pdev->dev;
Daniel Vetter9c065a72014-09-30 10:56:38 +02003245
Imre Deakc9b88462015-12-15 20:10:34 +02003246 assert_rpm_wakelock_held(dev_priv);
David Weinehallc49d13e2016-08-22 13:32:42 +03003247 pm_runtime_get_noresume(kdev);
Imre Deak1f814da2015-12-16 02:52:19 +02003248
3249 atomic_inc(&dev_priv->pm.wakeref_count);
Daniel Vetter9c065a72014-09-30 10:56:38 +02003250}
3251
Daniel Vettere4e76842014-09-30 10:56:42 +02003252/**
3253 * intel_runtime_pm_put - release a runtime pm reference
3254 * @dev_priv: i915 device instance
3255 *
3256 * This function drops the device-level runtime pm reference obtained by
3257 * intel_runtime_pm_get() and might power down the corresponding
3258 * hardware block right away if this is the last reference.
3259 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02003260void intel_runtime_pm_put(struct drm_i915_private *dev_priv)
3261{
David Weinehall52a05c32016-08-22 13:32:44 +03003262 struct pci_dev *pdev = dev_priv->drm.pdev;
3263 struct device *kdev = &pdev->dev;
Daniel Vetter9c065a72014-09-30 10:56:38 +02003264
Imre Deak542db3c2015-12-15 20:10:36 +02003265 assert_rpm_wakelock_held(dev_priv);
Chris Wilson2eedfc72016-10-24 13:42:17 +01003266 atomic_dec(&dev_priv->pm.wakeref_count);
Imre Deak1f814da2015-12-16 02:52:19 +02003267
David Weinehallc49d13e2016-08-22 13:32:42 +03003268 pm_runtime_mark_last_busy(kdev);
3269 pm_runtime_put_autosuspend(kdev);
Daniel Vetter9c065a72014-09-30 10:56:38 +02003270}
3271
Daniel Vettere4e76842014-09-30 10:56:42 +02003272/**
3273 * intel_runtime_pm_enable - enable runtime pm
3274 * @dev_priv: i915 device instance
3275 *
3276 * This function enables runtime pm at the end of the driver load sequence.
3277 *
3278 * Note that this function does currently not enable runtime pm for the
3279 * subordinate display power domains. That is only done on the first modeset
3280 * using intel_display_set_init_power().
3281 */
Daniel Vetterf458ebb2014-09-30 10:56:39 +02003282void intel_runtime_pm_enable(struct drm_i915_private *dev_priv)
Daniel Vetter9c065a72014-09-30 10:56:38 +02003283{
David Weinehall52a05c32016-08-22 13:32:44 +03003284 struct pci_dev *pdev = dev_priv->drm.pdev;
David Weinehall52a05c32016-08-22 13:32:44 +03003285 struct device *kdev = &pdev->dev;
Daniel Vetter9c065a72014-09-30 10:56:38 +02003286
David Weinehallc49d13e2016-08-22 13:32:42 +03003287 pm_runtime_set_autosuspend_delay(kdev, 10000); /* 10s */
3288 pm_runtime_mark_last_busy(kdev);
Imre Deakcbc68dc2015-12-17 19:04:33 +02003289
Imre Deak25b181b2015-12-17 13:44:56 +02003290 /*
3291 * Take a permanent reference to disable the RPM functionality and drop
3292 * it only when unloading the driver. Use the low level get/put helpers,
3293 * so the driver's own RPM reference tracking asserts also work on
3294 * platforms without RPM support.
3295 */
Tvrtko Ursulin6772ffe2016-10-13 11:02:55 +01003296 if (!HAS_RUNTIME_PM(dev_priv)) {
Imre Deakf5073822017-03-28 12:38:55 +03003297 int ret;
3298
David Weinehallc49d13e2016-08-22 13:32:42 +03003299 pm_runtime_dont_use_autosuspend(kdev);
Imre Deakf5073822017-03-28 12:38:55 +03003300 ret = pm_runtime_get_sync(kdev);
3301 WARN(ret < 0, "pm_runtime_get_sync() failed: %d\n", ret);
Imre Deakcbc68dc2015-12-17 19:04:33 +02003302 } else {
David Weinehallc49d13e2016-08-22 13:32:42 +03003303 pm_runtime_use_autosuspend(kdev);
Imre Deakcbc68dc2015-12-17 19:04:33 +02003304 }
Daniel Vetter9c065a72014-09-30 10:56:38 +02003305
Imre Deakaabee1b2015-12-15 20:10:29 +02003306 /*
3307 * The core calls the driver load handler with an RPM reference held.
3308 * We drop that here and will reacquire it during unloading in
3309 * intel_power_domains_fini().
3310 */
David Weinehallc49d13e2016-08-22 13:32:42 +03003311 pm_runtime_put_autosuspend(kdev);
Daniel Vetter9c065a72014-09-30 10:56:38 +02003312}