blob: fc1377e7b1497b9a7b2c75fd13ac97baf42eea31 [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{
Imre Deakb5565a22017-07-06 17:40:29 +0300966 bxt_ddi_phy_init(dev_priv, power_well->bxt.phy);
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{
Imre Deakb5565a22017-07-06 17:40:29 +0300972 bxt_ddi_phy_uninit(dev_priv, power_well->bxt.phy);
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{
Imre Deakb5565a22017-07-06 17:40:29 +0300978 return bxt_ddi_phy_is_enabled(dev_priv, power_well->bxt.phy);
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)
Imre Deakb5565a22017-07-06 17:40:29 +0300987 bxt_ddi_phy_verify_state(dev_priv, power_well->bxt.phy);
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)
Imre Deakb5565a22017-07-06 17:40:29 +0300991 bxt_ddi_phy_verify_state(dev_priv, power_well->bxt.phy);
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)
Imre Deakb5565a22017-07-06 17:40:29 +0300996 bxt_ddi_phy_verify_state(dev_priv, power_well->bxt.phy);
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +0200997 }
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,
Imre Deak029d80d2017-07-06 17:40:25 +03002016 .id = I915_DISP_PW_ALWAYS_ON,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002017 },
2018};
2019
Ville Syrjälä2ee0da12017-06-01 17:36:16 +03002020static const struct i915_power_well_ops i830_pipes_power_well_ops = {
2021 .sync_hw = i830_pipes_power_well_sync_hw,
2022 .enable = i830_pipes_power_well_enable,
2023 .disable = i830_pipes_power_well_disable,
2024 .is_enabled = i830_pipes_power_well_enabled,
2025};
2026
2027static struct i915_power_well i830_power_wells[] = {
2028 {
2029 .name = "always-on",
2030 .always_on = 1,
2031 .domains = POWER_DOMAIN_MASK,
2032 .ops = &i9xx_always_on_power_well_ops,
Imre Deak029d80d2017-07-06 17:40:25 +03002033 .id = I915_DISP_PW_ALWAYS_ON,
Ville Syrjälä2ee0da12017-06-01 17:36:16 +03002034 },
2035 {
2036 .name = "pipes",
2037 .domains = I830_PIPES_POWER_DOMAINS,
2038 .ops = &i830_pipes_power_well_ops,
Imre Deak120b56a2017-07-11 23:42:31 +03002039 .id = I830_DISP_PW_PIPES,
Ville Syrjälä2ee0da12017-06-01 17:36:16 +03002040 },
2041};
2042
Daniel Vetter9c065a72014-09-30 10:56:38 +02002043static const struct i915_power_well_ops hsw_power_well_ops = {
2044 .sync_hw = hsw_power_well_sync_hw,
2045 .enable = hsw_power_well_enable,
2046 .disable = hsw_power_well_disable,
2047 .is_enabled = hsw_power_well_enabled,
2048};
2049
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002050static const struct i915_power_well_ops skl_power_well_ops = {
2051 .sync_hw = skl_power_well_sync_hw,
2052 .enable = skl_power_well_enable,
2053 .disable = skl_power_well_disable,
2054 .is_enabled = skl_power_well_enabled,
2055};
2056
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01002057static const struct i915_power_well_ops gen9_dc_off_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02002058 .sync_hw = i9xx_power_well_sync_hw_noop,
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01002059 .enable = gen9_dc_off_power_well_enable,
2060 .disable = gen9_dc_off_power_well_disable,
2061 .is_enabled = gen9_dc_off_power_well_enabled,
2062};
2063
Imre Deak9c8d0b82016-06-13 16:44:34 +03002064static const struct i915_power_well_ops bxt_dpio_cmn_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02002065 .sync_hw = i9xx_power_well_sync_hw_noop,
Imre Deak9c8d0b82016-06-13 16:44:34 +03002066 .enable = bxt_dpio_cmn_power_well_enable,
2067 .disable = bxt_dpio_cmn_power_well_disable,
2068 .is_enabled = bxt_dpio_cmn_power_well_enabled,
2069};
2070
Daniel Vetter9c065a72014-09-30 10:56:38 +02002071static struct i915_power_well hsw_power_wells[] = {
2072 {
2073 .name = "always-on",
2074 .always_on = 1,
Ville Syrjälä998bd662016-04-18 14:02:26 +03002075 .domains = POWER_DOMAIN_MASK,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002076 .ops = &i9xx_always_on_power_well_ops,
Imre Deak029d80d2017-07-06 17:40:25 +03002077 .id = I915_DISP_PW_ALWAYS_ON,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002078 },
2079 {
2080 .name = "display",
2081 .domains = HSW_DISPLAY_POWER_DOMAINS,
2082 .ops = &hsw_power_well_ops,
Imre Deakfb9248e2017-07-11 23:42:32 +03002083 .id = HSW_DISP_PW_GLOBAL,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002084 },
2085};
2086
2087static struct i915_power_well bdw_power_wells[] = {
2088 {
2089 .name = "always-on",
2090 .always_on = 1,
Ville Syrjälä998bd662016-04-18 14:02:26 +03002091 .domains = POWER_DOMAIN_MASK,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002092 .ops = &i9xx_always_on_power_well_ops,
Imre Deak029d80d2017-07-06 17:40:25 +03002093 .id = I915_DISP_PW_ALWAYS_ON,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002094 },
2095 {
2096 .name = "display",
2097 .domains = BDW_DISPLAY_POWER_DOMAINS,
2098 .ops = &hsw_power_well_ops,
Imre Deakfb9248e2017-07-11 23:42:32 +03002099 .id = HSW_DISP_PW_GLOBAL,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002100 },
2101};
2102
2103static const struct i915_power_well_ops vlv_display_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_display_power_well_enable,
2106 .disable = vlv_display_power_well_disable,
2107 .is_enabled = vlv_power_well_enabled,
2108};
2109
2110static const struct i915_power_well_ops vlv_dpio_cmn_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_dpio_cmn_power_well_enable,
2113 .disable = vlv_dpio_cmn_power_well_disable,
2114 .is_enabled = vlv_power_well_enabled,
2115};
2116
2117static const struct i915_power_well_ops vlv_dpio_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02002118 .sync_hw = i9xx_power_well_sync_hw_noop,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002119 .enable = vlv_power_well_enable,
2120 .disable = vlv_power_well_disable,
2121 .is_enabled = vlv_power_well_enabled,
2122};
2123
2124static struct i915_power_well vlv_power_wells[] = {
2125 {
2126 .name = "always-on",
2127 .always_on = 1,
Ville Syrjälä998bd662016-04-18 14:02:26 +03002128 .domains = POWER_DOMAIN_MASK,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002129 .ops = &i9xx_always_on_power_well_ops,
Imre Deak438b8dc2017-07-11 23:42:30 +03002130 .id = I915_DISP_PW_ALWAYS_ON,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002131 },
2132 {
2133 .name = "display",
2134 .domains = VLV_DISPLAY_POWER_DOMAINS,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002135 .id = PUNIT_POWER_WELL_DISP2D,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002136 .ops = &vlv_display_power_well_ops,
2137 },
2138 {
2139 .name = "dpio-tx-b-01",
2140 .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
2141 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
2142 VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
2143 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
2144 .ops = &vlv_dpio_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002145 .id = PUNIT_POWER_WELL_DPIO_TX_B_LANES_01,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002146 },
2147 {
2148 .name = "dpio-tx-b-23",
2149 .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
2150 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
2151 VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
2152 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
2153 .ops = &vlv_dpio_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002154 .id = PUNIT_POWER_WELL_DPIO_TX_B_LANES_23,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002155 },
2156 {
2157 .name = "dpio-tx-c-01",
2158 .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
2159 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
2160 VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
2161 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
2162 .ops = &vlv_dpio_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002163 .id = PUNIT_POWER_WELL_DPIO_TX_C_LANES_01,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002164 },
2165 {
2166 .name = "dpio-tx-c-23",
2167 .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
2168 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
2169 VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
2170 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
2171 .ops = &vlv_dpio_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002172 .id = PUNIT_POWER_WELL_DPIO_TX_C_LANES_23,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002173 },
2174 {
2175 .name = "dpio-common",
2176 .domains = VLV_DPIO_CMN_BC_POWER_DOMAINS,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002177 .id = PUNIT_POWER_WELL_DPIO_CMN_BC,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002178 .ops = &vlv_dpio_cmn_power_well_ops,
2179 },
2180};
2181
2182static struct i915_power_well chv_power_wells[] = {
2183 {
2184 .name = "always-on",
2185 .always_on = 1,
Ville Syrjälä998bd662016-04-18 14:02:26 +03002186 .domains = POWER_DOMAIN_MASK,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002187 .ops = &i9xx_always_on_power_well_ops,
Imre Deak029d80d2017-07-06 17:40:25 +03002188 .id = I915_DISP_PW_ALWAYS_ON,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002189 },
Daniel Vetter9c065a72014-09-30 10:56:38 +02002190 {
2191 .name = "display",
Ville Syrjäläbaa4e572014-10-27 16:07:32 +02002192 /*
Ville Syrjäläfde61e42015-05-26 20:22:39 +03002193 * Pipe A power well is the new disp2d well. Pipe B and C
2194 * power wells don't actually exist. Pipe A power well is
2195 * required for any pipe to work.
Ville Syrjäläbaa4e572014-10-27 16:07:32 +02002196 */
Ville Syrjälä465ac0c2016-04-18 14:02:27 +03002197 .domains = CHV_DISPLAY_POWER_DOMAINS,
Imre Deakf49193c2017-07-06 17:40:23 +03002198 .id = CHV_DISP_PW_PIPE_A,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002199 .ops = &chv_pipe_power_well_ops,
2200 },
Daniel Vetter9c065a72014-09-30 10:56:38 +02002201 {
2202 .name = "dpio-common-bc",
Ville Syrjälä71849b62015-04-10 18:21:29 +03002203 .domains = CHV_DPIO_CMN_BC_POWER_DOMAINS,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002204 .id = PUNIT_POWER_WELL_DPIO_CMN_BC,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002205 .ops = &chv_dpio_cmn_power_well_ops,
2206 },
2207 {
2208 .name = "dpio-common-d",
Ville Syrjälä71849b62015-04-10 18:21:29 +03002209 .domains = CHV_DPIO_CMN_D_POWER_DOMAINS,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002210 .id = PUNIT_POWER_WELL_DPIO_CMN_D,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002211 .ops = &chv_dpio_cmn_power_well_ops,
2212 },
Daniel Vetter9c065a72014-09-30 10:56:38 +02002213};
2214
Suketu Shah5aefb232015-04-16 14:22:10 +05302215bool intel_display_power_well_is_enabled(struct drm_i915_private *dev_priv,
Imre Deak438b8dc2017-07-11 23:42:30 +03002216 enum i915_power_well_id power_well_id)
Suketu Shah5aefb232015-04-16 14:22:10 +05302217{
2218 struct i915_power_well *power_well;
2219 bool ret;
2220
2221 power_well = lookup_power_well(dev_priv, power_well_id);
2222 ret = power_well->ops->is_enabled(dev_priv, power_well);
2223
2224 return ret;
2225}
2226
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002227static struct i915_power_well skl_power_wells[] = {
2228 {
2229 .name = "always-on",
2230 .always_on = 1,
Ville Syrjälä998bd662016-04-18 14:02:26 +03002231 .domains = POWER_DOMAIN_MASK,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002232 .ops = &i9xx_always_on_power_well_ops,
Imre Deak438b8dc2017-07-11 23:42:30 +03002233 .id = I915_DISP_PW_ALWAYS_ON,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002234 },
2235 {
2236 .name = "power well 1",
Imre Deak4a76f292015-11-04 19:24:15 +02002237 /* Handled by the DMC firmware */
2238 .domains = 0,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002239 .ops = &skl_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002240 .id = SKL_DISP_PW_1,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002241 },
2242 {
2243 .name = "MISC IO power well",
Imre Deak4a76f292015-11-04 19:24:15 +02002244 /* Handled by the DMC firmware */
2245 .domains = 0,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002246 .ops = &skl_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002247 .id = SKL_DISP_PW_MISC_IO,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002248 },
2249 {
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01002250 .name = "DC off",
2251 .domains = SKL_DISPLAY_DC_OFF_POWER_DOMAINS,
2252 .ops = &gen9_dc_off_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002253 .id = SKL_DISP_PW_DC_OFF,
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01002254 },
2255 {
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002256 .name = "power well 2",
2257 .domains = SKL_DISPLAY_POWERWELL_2_POWER_DOMAINS,
2258 .ops = &skl_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002259 .id = SKL_DISP_PW_2,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002260 },
2261 {
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002262 .name = "DDI A/E IO power well",
2263 .domains = SKL_DISPLAY_DDI_IO_A_E_POWER_DOMAINS,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002264 .ops = &skl_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002265 .id = SKL_DISP_PW_DDI_A_E,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002266 },
2267 {
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002268 .name = "DDI B IO power well",
2269 .domains = SKL_DISPLAY_DDI_IO_B_POWER_DOMAINS,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002270 .ops = &skl_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002271 .id = SKL_DISP_PW_DDI_B,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002272 },
2273 {
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002274 .name = "DDI C IO power well",
2275 .domains = SKL_DISPLAY_DDI_IO_C_POWER_DOMAINS,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002276 .ops = &skl_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002277 .id = SKL_DISP_PW_DDI_C,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002278 },
2279 {
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002280 .name = "DDI D IO power well",
2281 .domains = SKL_DISPLAY_DDI_IO_D_POWER_DOMAINS,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002282 .ops = &skl_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002283 .id = SKL_DISP_PW_DDI_D,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002284 },
2285};
2286
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302287static struct i915_power_well bxt_power_wells[] = {
2288 {
2289 .name = "always-on",
2290 .always_on = 1,
Ville Syrjälä998bd662016-04-18 14:02:26 +03002291 .domains = POWER_DOMAIN_MASK,
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302292 .ops = &i9xx_always_on_power_well_ops,
Imre Deak029d80d2017-07-06 17:40:25 +03002293 .id = I915_DISP_PW_ALWAYS_ON,
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302294 },
2295 {
2296 .name = "power well 1",
Imre Deakd7d7c9e2016-04-01 16:02:42 +03002297 .domains = 0,
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302298 .ops = &skl_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002299 .id = SKL_DISP_PW_1,
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302300 },
2301 {
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01002302 .name = "DC off",
2303 .domains = BXT_DISPLAY_DC_OFF_POWER_DOMAINS,
2304 .ops = &gen9_dc_off_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002305 .id = SKL_DISP_PW_DC_OFF,
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01002306 },
2307 {
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302308 .name = "power well 2",
2309 .domains = BXT_DISPLAY_POWERWELL_2_POWER_DOMAINS,
2310 .ops = &skl_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002311 .id = SKL_DISP_PW_2,
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01002312 },
Imre Deak9c8d0b82016-06-13 16:44:34 +03002313 {
2314 .name = "dpio-common-a",
2315 .domains = BXT_DPIO_CMN_A_POWER_DOMAINS,
2316 .ops = &bxt_dpio_cmn_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002317 .id = BXT_DPIO_CMN_A,
Imre Deakb5565a22017-07-06 17:40:29 +03002318 .bxt.phy = DPIO_PHY1,
Imre Deak9c8d0b82016-06-13 16:44:34 +03002319 },
2320 {
2321 .name = "dpio-common-bc",
2322 .domains = BXT_DPIO_CMN_BC_POWER_DOMAINS,
2323 .ops = &bxt_dpio_cmn_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002324 .id = BXT_DPIO_CMN_BC,
Imre Deakb5565a22017-07-06 17:40:29 +03002325 .bxt.phy = DPIO_PHY0,
Imre Deak9c8d0b82016-06-13 16:44:34 +03002326 },
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302327};
2328
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002329static struct i915_power_well glk_power_wells[] = {
2330 {
2331 .name = "always-on",
2332 .always_on = 1,
2333 .domains = POWER_DOMAIN_MASK,
2334 .ops = &i9xx_always_on_power_well_ops,
Imre Deak029d80d2017-07-06 17:40:25 +03002335 .id = I915_DISP_PW_ALWAYS_ON,
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002336 },
2337 {
2338 .name = "power well 1",
2339 /* Handled by the DMC firmware */
2340 .domains = 0,
2341 .ops = &skl_power_well_ops,
2342 .id = SKL_DISP_PW_1,
2343 },
2344 {
2345 .name = "DC off",
2346 .domains = GLK_DISPLAY_DC_OFF_POWER_DOMAINS,
2347 .ops = &gen9_dc_off_power_well_ops,
2348 .id = SKL_DISP_PW_DC_OFF,
2349 },
2350 {
2351 .name = "power well 2",
2352 .domains = GLK_DISPLAY_POWERWELL_2_POWER_DOMAINS,
2353 .ops = &skl_power_well_ops,
2354 .id = SKL_DISP_PW_2,
2355 },
2356 {
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +02002357 .name = "dpio-common-a",
2358 .domains = GLK_DPIO_CMN_A_POWER_DOMAINS,
2359 .ops = &bxt_dpio_cmn_power_well_ops,
2360 .id = BXT_DPIO_CMN_A,
Imre Deakb5565a22017-07-06 17:40:29 +03002361 .bxt.phy = DPIO_PHY1,
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +02002362 },
2363 {
2364 .name = "dpio-common-b",
2365 .domains = GLK_DPIO_CMN_B_POWER_DOMAINS,
2366 .ops = &bxt_dpio_cmn_power_well_ops,
2367 .id = BXT_DPIO_CMN_BC,
Imre Deakb5565a22017-07-06 17:40:29 +03002368 .bxt.phy = DPIO_PHY0,
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +02002369 },
2370 {
2371 .name = "dpio-common-c",
2372 .domains = GLK_DPIO_CMN_C_POWER_DOMAINS,
2373 .ops = &bxt_dpio_cmn_power_well_ops,
2374 .id = GLK_DPIO_CMN_C,
Imre Deakb5565a22017-07-06 17:40:29 +03002375 .bxt.phy = DPIO_PHY2,
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +02002376 },
2377 {
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002378 .name = "AUX A",
2379 .domains = GLK_DISPLAY_AUX_A_POWER_DOMAINS,
2380 .ops = &skl_power_well_ops,
2381 .id = GLK_DISP_PW_AUX_A,
2382 },
2383 {
2384 .name = "AUX B",
2385 .domains = GLK_DISPLAY_AUX_B_POWER_DOMAINS,
2386 .ops = &skl_power_well_ops,
2387 .id = GLK_DISP_PW_AUX_B,
2388 },
2389 {
2390 .name = "AUX C",
2391 .domains = GLK_DISPLAY_AUX_C_POWER_DOMAINS,
2392 .ops = &skl_power_well_ops,
2393 .id = GLK_DISP_PW_AUX_C,
2394 },
2395 {
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002396 .name = "DDI A IO power well",
2397 .domains = GLK_DISPLAY_DDI_IO_A_POWER_DOMAINS,
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002398 .ops = &skl_power_well_ops,
2399 .id = GLK_DISP_PW_DDI_A,
2400 },
2401 {
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002402 .name = "DDI B IO power well",
2403 .domains = GLK_DISPLAY_DDI_IO_B_POWER_DOMAINS,
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002404 .ops = &skl_power_well_ops,
2405 .id = SKL_DISP_PW_DDI_B,
2406 },
2407 {
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002408 .name = "DDI C IO power well",
2409 .domains = GLK_DISPLAY_DDI_IO_C_POWER_DOMAINS,
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002410 .ops = &skl_power_well_ops,
2411 .id = SKL_DISP_PW_DDI_C,
2412 },
2413};
2414
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002415static struct i915_power_well cnl_power_wells[] = {
2416 {
2417 .name = "always-on",
2418 .always_on = 1,
2419 .domains = POWER_DOMAIN_MASK,
2420 .ops = &i9xx_always_on_power_well_ops,
Imre Deak029d80d2017-07-06 17:40:25 +03002421 .id = I915_DISP_PW_ALWAYS_ON,
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002422 },
2423 {
2424 .name = "power well 1",
2425 /* Handled by the DMC firmware */
2426 .domains = 0,
2427 .ops = &skl_power_well_ops,
2428 .id = SKL_DISP_PW_1,
2429 },
2430 {
2431 .name = "AUX A",
2432 .domains = CNL_DISPLAY_AUX_A_POWER_DOMAINS,
2433 .ops = &skl_power_well_ops,
2434 .id = CNL_DISP_PW_AUX_A,
2435 },
2436 {
2437 .name = "AUX B",
2438 .domains = CNL_DISPLAY_AUX_B_POWER_DOMAINS,
2439 .ops = &skl_power_well_ops,
2440 .id = CNL_DISP_PW_AUX_B,
2441 },
2442 {
2443 .name = "AUX C",
2444 .domains = CNL_DISPLAY_AUX_C_POWER_DOMAINS,
2445 .ops = &skl_power_well_ops,
2446 .id = CNL_DISP_PW_AUX_C,
2447 },
2448 {
2449 .name = "AUX D",
2450 .domains = CNL_DISPLAY_AUX_D_POWER_DOMAINS,
2451 .ops = &skl_power_well_ops,
2452 .id = CNL_DISP_PW_AUX_D,
2453 },
2454 {
2455 .name = "DC off",
2456 .domains = CNL_DISPLAY_DC_OFF_POWER_DOMAINS,
2457 .ops = &gen9_dc_off_power_well_ops,
2458 .id = SKL_DISP_PW_DC_OFF,
2459 },
2460 {
2461 .name = "power well 2",
2462 .domains = CNL_DISPLAY_POWERWELL_2_POWER_DOMAINS,
2463 .ops = &skl_power_well_ops,
2464 .id = SKL_DISP_PW_2,
2465 },
2466 {
2467 .name = "DDI A IO power well",
2468 .domains = CNL_DISPLAY_DDI_A_IO_POWER_DOMAINS,
2469 .ops = &skl_power_well_ops,
2470 .id = CNL_DISP_PW_DDI_A,
2471 },
2472 {
2473 .name = "DDI B IO power well",
2474 .domains = CNL_DISPLAY_DDI_B_IO_POWER_DOMAINS,
2475 .ops = &skl_power_well_ops,
2476 .id = SKL_DISP_PW_DDI_B,
2477 },
2478 {
2479 .name = "DDI C IO power well",
2480 .domains = CNL_DISPLAY_DDI_C_IO_POWER_DOMAINS,
2481 .ops = &skl_power_well_ops,
2482 .id = SKL_DISP_PW_DDI_C,
2483 },
2484 {
2485 .name = "DDI D IO power well",
2486 .domains = CNL_DISPLAY_DDI_D_IO_POWER_DOMAINS,
2487 .ops = &skl_power_well_ops,
2488 .id = SKL_DISP_PW_DDI_D,
2489 },
2490};
2491
Imre Deak1b0e3a02015-11-05 23:04:11 +02002492static int
2493sanitize_disable_power_well_option(const struct drm_i915_private *dev_priv,
2494 int disable_power_well)
2495{
2496 if (disable_power_well >= 0)
2497 return !!disable_power_well;
2498
Imre Deak1b0e3a02015-11-05 23:04:11 +02002499 return 1;
2500}
2501
Imre Deaka37baf32016-02-29 22:49:03 +02002502static uint32_t get_allowed_dc_mask(const struct drm_i915_private *dev_priv,
2503 int enable_dc)
2504{
2505 uint32_t mask;
2506 int requested_dc;
2507 int max_dc;
2508
Rodrigo Vivi6d6a8972017-07-06 13:45:08 -07002509 if (IS_GEN9_BC(dev_priv) || IS_CANNONLAKE(dev_priv)) {
Imre Deaka37baf32016-02-29 22:49:03 +02002510 max_dc = 2;
2511 mask = 0;
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02002512 } else if (IS_GEN9_LP(dev_priv)) {
Imre Deaka37baf32016-02-29 22:49:03 +02002513 max_dc = 1;
2514 /*
2515 * DC9 has a separate HW flow from the rest of the DC states,
2516 * not depending on the DMC firmware. It's needed by system
2517 * suspend/resume, so allow it unconditionally.
2518 */
2519 mask = DC_STATE_EN_DC9;
2520 } else {
2521 max_dc = 0;
2522 mask = 0;
2523 }
2524
Imre Deak66e2c4c2016-02-29 22:49:04 +02002525 if (!i915.disable_power_well)
2526 max_dc = 0;
2527
Imre Deaka37baf32016-02-29 22:49:03 +02002528 if (enable_dc >= 0 && enable_dc <= max_dc) {
2529 requested_dc = enable_dc;
2530 } else if (enable_dc == -1) {
2531 requested_dc = max_dc;
2532 } else if (enable_dc > max_dc && enable_dc <= 2) {
2533 DRM_DEBUG_KMS("Adjusting requested max DC state (%d->%d)\n",
2534 enable_dc, max_dc);
2535 requested_dc = max_dc;
2536 } else {
2537 DRM_ERROR("Unexpected value for enable_dc (%d)\n", enable_dc);
2538 requested_dc = max_dc;
2539 }
2540
2541 if (requested_dc > 1)
2542 mask |= DC_STATE_EN_UPTO_DC6;
2543 if (requested_dc > 0)
2544 mask |= DC_STATE_EN_UPTO_DC5;
2545
2546 DRM_DEBUG_KMS("Allowed DC state mask %02x\n", mask);
2547
2548 return mask;
2549}
2550
Imre Deak21792c62017-07-11 23:42:33 +03002551static void assert_power_well_ids_unique(struct drm_i915_private *dev_priv)
2552{
2553 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2554 u64 power_well_ids;
2555 int i;
2556
2557 power_well_ids = 0;
2558 for (i = 0; i < power_domains->power_well_count; i++) {
2559 enum i915_power_well_id id = power_domains->power_wells[i].id;
2560
2561 WARN_ON(id >= sizeof(power_well_ids) * 8);
2562 WARN_ON(power_well_ids & BIT_ULL(id));
2563 power_well_ids |= BIT_ULL(id);
2564 }
2565}
2566
Daniel Vetter9c065a72014-09-30 10:56:38 +02002567#define set_power_wells(power_domains, __power_wells) ({ \
2568 (power_domains)->power_wells = (__power_wells); \
2569 (power_domains)->power_well_count = ARRAY_SIZE(__power_wells); \
2570})
2571
Daniel Vettere4e76842014-09-30 10:56:42 +02002572/**
2573 * intel_power_domains_init - initializes the power domain structures
2574 * @dev_priv: i915 device instance
2575 *
2576 * Initializes the power domain structures for @dev_priv depending upon the
2577 * supported platform.
2578 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02002579int intel_power_domains_init(struct drm_i915_private *dev_priv)
2580{
2581 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2582
Imre Deak1b0e3a02015-11-05 23:04:11 +02002583 i915.disable_power_well = sanitize_disable_power_well_option(dev_priv,
2584 i915.disable_power_well);
Imre Deaka37baf32016-02-29 22:49:03 +02002585 dev_priv->csr.allowed_dc_mask = get_allowed_dc_mask(dev_priv,
2586 i915.enable_dc);
Imre Deak1b0e3a02015-11-05 23:04:11 +02002587
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02002588 BUILD_BUG_ON(POWER_DOMAIN_NUM > 64);
Ville Syrjäläf0ab43e2015-11-09 16:48:19 +01002589
Daniel Vetter9c065a72014-09-30 10:56:38 +02002590 mutex_init(&power_domains->lock);
2591
2592 /*
2593 * The enabling order will be from lower to higher indexed wells,
2594 * the disabling order is reversed.
2595 */
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002596 if (IS_HASWELL(dev_priv)) {
Daniel Vetter9c065a72014-09-30 10:56:38 +02002597 set_power_wells(power_domains, hsw_power_wells);
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002598 } else if (IS_BROADWELL(dev_priv)) {
Daniel Vetter9c065a72014-09-30 10:56:38 +02002599 set_power_wells(power_domains, bdw_power_wells);
Rodrigo Vivib976dc52017-01-23 10:32:37 -08002600 } else if (IS_GEN9_BC(dev_priv)) {
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002601 set_power_wells(power_domains, skl_power_wells);
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002602 } else if (IS_CANNONLAKE(dev_priv)) {
2603 set_power_wells(power_domains, cnl_power_wells);
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002604 } else if (IS_BROXTON(dev_priv)) {
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302605 set_power_wells(power_domains, bxt_power_wells);
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002606 } else if (IS_GEMINILAKE(dev_priv)) {
2607 set_power_wells(power_domains, glk_power_wells);
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002608 } else if (IS_CHERRYVIEW(dev_priv)) {
Daniel Vetter9c065a72014-09-30 10:56:38 +02002609 set_power_wells(power_domains, chv_power_wells);
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002610 } else if (IS_VALLEYVIEW(dev_priv)) {
Daniel Vetter9c065a72014-09-30 10:56:38 +02002611 set_power_wells(power_domains, vlv_power_wells);
Ville Syrjälä2ee0da12017-06-01 17:36:16 +03002612 } else if (IS_I830(dev_priv)) {
2613 set_power_wells(power_domains, i830_power_wells);
Daniel Vetter9c065a72014-09-30 10:56:38 +02002614 } else {
2615 set_power_wells(power_domains, i9xx_always_on_power_well);
2616 }
2617
Imre Deak21792c62017-07-11 23:42:33 +03002618 assert_power_well_ids_unique(dev_priv);
2619
Daniel Vetter9c065a72014-09-30 10:56:38 +02002620 return 0;
2621}
2622
Daniel Vettere4e76842014-09-30 10:56:42 +02002623/**
2624 * intel_power_domains_fini - finalizes the power domain structures
2625 * @dev_priv: i915 device instance
2626 *
2627 * Finalizes the power domain structures for @dev_priv depending upon the
2628 * supported platform. This function also disables runtime pm and ensures that
2629 * the device stays powered up so that the driver can be reloaded.
2630 */
Daniel Vetterf458ebb2014-09-30 10:56:39 +02002631void intel_power_domains_fini(struct drm_i915_private *dev_priv)
Daniel Vetter9c065a72014-09-30 10:56:38 +02002632{
David Weinehallc49d13e2016-08-22 13:32:42 +03002633 struct device *kdev = &dev_priv->drm.pdev->dev;
Imre Deak25b181b2015-12-17 13:44:56 +02002634
Imre Deakaabee1b2015-12-15 20:10:29 +02002635 /*
2636 * The i915.ko module is still not prepared to be loaded when
Daniel Vetterf458ebb2014-09-30 10:56:39 +02002637 * the power well is not enabled, so just enable it in case
Imre Deakaabee1b2015-12-15 20:10:29 +02002638 * we're going to unload/reload.
2639 * The following also reacquires the RPM reference the core passed
2640 * to the driver during loading, which is dropped in
2641 * intel_runtime_pm_enable(). We have to hand back the control of the
2642 * device to the core with this reference held.
2643 */
Daniel Vetterf458ebb2014-09-30 10:56:39 +02002644 intel_display_set_init_power(dev_priv, true);
Imre Deakd314cd42015-11-17 17:44:23 +02002645
2646 /* Remove the refcount we took to keep power well support disabled. */
2647 if (!i915.disable_power_well)
2648 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
Imre Deak25b181b2015-12-17 13:44:56 +02002649
2650 /*
2651 * Remove the refcount we took in intel_runtime_pm_enable() in case
2652 * the platform doesn't support runtime PM.
2653 */
2654 if (!HAS_RUNTIME_PM(dev_priv))
David Weinehallc49d13e2016-08-22 13:32:42 +03002655 pm_runtime_put(kdev);
Daniel Vetter9c065a72014-09-30 10:56:38 +02002656}
2657
Imre Deak30eade12015-11-04 19:24:13 +02002658static void intel_power_domains_sync_hw(struct drm_i915_private *dev_priv)
Daniel Vetter9c065a72014-09-30 10:56:38 +02002659{
2660 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2661 struct i915_power_well *power_well;
Daniel Vetter9c065a72014-09-30 10:56:38 +02002662
2663 mutex_lock(&power_domains->lock);
Imre Deak75ccb2e2017-02-17 17:39:43 +02002664 for_each_power_well(dev_priv, power_well) {
Daniel Vetter9c065a72014-09-30 10:56:38 +02002665 power_well->ops->sync_hw(dev_priv, power_well);
2666 power_well->hw_enabled = power_well->ops->is_enabled(dev_priv,
2667 power_well);
2668 }
2669 mutex_unlock(&power_domains->lock);
2670}
2671
Ville Syrjälä70c2c182016-05-13 23:41:30 +03002672static void gen9_dbuf_enable(struct drm_i915_private *dev_priv)
2673{
2674 I915_WRITE(DBUF_CTL, I915_READ(DBUF_CTL) | DBUF_POWER_REQUEST);
2675 POSTING_READ(DBUF_CTL);
2676
2677 udelay(10);
2678
2679 if (!(I915_READ(DBUF_CTL) & DBUF_POWER_STATE))
2680 DRM_ERROR("DBuf power enable timeout\n");
2681}
2682
2683static void gen9_dbuf_disable(struct drm_i915_private *dev_priv)
2684{
2685 I915_WRITE(DBUF_CTL, I915_READ(DBUF_CTL) & ~DBUF_POWER_REQUEST);
2686 POSTING_READ(DBUF_CTL);
2687
2688 udelay(10);
2689
2690 if (I915_READ(DBUF_CTL) & DBUF_POWER_STATE)
2691 DRM_ERROR("DBuf power disable timeout!\n");
2692}
2693
Imre Deak73dfc222015-11-17 17:33:53 +02002694static void skl_display_core_init(struct drm_i915_private *dev_priv,
Imre Deak443a93a2016-04-04 15:42:57 +03002695 bool resume)
Imre Deak73dfc222015-11-17 17:33:53 +02002696{
2697 struct i915_power_domains *power_domains = &dev_priv->power_domains;
Imre Deak443a93a2016-04-04 15:42:57 +03002698 struct i915_power_well *well;
Imre Deak73dfc222015-11-17 17:33:53 +02002699 uint32_t val;
2700
Imre Deakd26fa1d2015-11-04 19:24:17 +02002701 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
2702
Imre Deak73dfc222015-11-17 17:33:53 +02002703 /* enable PCH reset handshake */
2704 val = I915_READ(HSW_NDE_RSTWRN_OPT);
2705 I915_WRITE(HSW_NDE_RSTWRN_OPT, val | RESET_PCH_HANDSHAKE_ENABLE);
2706
2707 /* enable PG1 and Misc I/O */
2708 mutex_lock(&power_domains->lock);
Imre Deak443a93a2016-04-04 15:42:57 +03002709
2710 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
2711 intel_power_well_enable(dev_priv, well);
2712
2713 well = lookup_power_well(dev_priv, SKL_DISP_PW_MISC_IO);
2714 intel_power_well_enable(dev_priv, well);
2715
Imre Deak73dfc222015-11-17 17:33:53 +02002716 mutex_unlock(&power_domains->lock);
2717
Imre Deak73dfc222015-11-17 17:33:53 +02002718 skl_init_cdclk(dev_priv);
2719
Ville Syrjälä70c2c182016-05-13 23:41:30 +03002720 gen9_dbuf_enable(dev_priv);
2721
Ville Syrjälä9f7eb312016-05-13 23:41:29 +03002722 if (resume && dev_priv->csr.dmc_payload)
Imre Deak2abc5252016-03-04 21:57:41 +02002723 intel_csr_load_program(dev_priv);
Imre Deak73dfc222015-11-17 17:33:53 +02002724}
2725
2726static void skl_display_core_uninit(struct drm_i915_private *dev_priv)
2727{
2728 struct i915_power_domains *power_domains = &dev_priv->power_domains;
Imre Deak443a93a2016-04-04 15:42:57 +03002729 struct i915_power_well *well;
Imre Deak73dfc222015-11-17 17:33:53 +02002730
Imre Deakd26fa1d2015-11-04 19:24:17 +02002731 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
2732
Ville Syrjälä70c2c182016-05-13 23:41:30 +03002733 gen9_dbuf_disable(dev_priv);
2734
Imre Deak73dfc222015-11-17 17:33:53 +02002735 skl_uninit_cdclk(dev_priv);
2736
2737 /* The spec doesn't call for removing the reset handshake flag */
2738 /* disable PG1 and Misc I/O */
Imre Deak443a93a2016-04-04 15:42:57 +03002739
Imre Deak73dfc222015-11-17 17:33:53 +02002740 mutex_lock(&power_domains->lock);
Imre Deak443a93a2016-04-04 15:42:57 +03002741
Imre Deakedfda8e2017-06-29 18:36:59 +03002742 /*
2743 * BSpec says to keep the MISC IO power well enabled here, only
2744 * remove our request for power well 1.
Imre Deak42d93662017-06-29 18:37:01 +03002745 * Note that even though the driver's request is removed power well 1
2746 * may stay enabled after this due to DMC's own request on it.
Imre Deakedfda8e2017-06-29 18:36:59 +03002747 */
Imre Deak443a93a2016-04-04 15:42:57 +03002748 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
2749 intel_power_well_disable(dev_priv, well);
2750
Imre Deak73dfc222015-11-17 17:33:53 +02002751 mutex_unlock(&power_domains->lock);
Imre Deak846c6b22017-06-29 18:36:58 +03002752
2753 usleep_range(10, 30); /* 10 us delay per Bspec */
Imre Deak73dfc222015-11-17 17:33:53 +02002754}
2755
Imre Deakd7d7c9e2016-04-01 16:02:42 +03002756void bxt_display_core_init(struct drm_i915_private *dev_priv,
2757 bool resume)
2758{
2759 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2760 struct i915_power_well *well;
2761 uint32_t val;
2762
2763 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
2764
2765 /*
2766 * NDE_RSTWRN_OPT RST PCH Handshake En must always be 0b on BXT
2767 * or else the reset will hang because there is no PCH to respond.
2768 * Move the handshake programming to initialization sequence.
2769 * Previously was left up to BIOS.
2770 */
2771 val = I915_READ(HSW_NDE_RSTWRN_OPT);
2772 val &= ~RESET_PCH_HANDSHAKE_ENABLE;
2773 I915_WRITE(HSW_NDE_RSTWRN_OPT, val);
2774
2775 /* Enable PG1 */
2776 mutex_lock(&power_domains->lock);
2777
2778 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
2779 intel_power_well_enable(dev_priv, well);
2780
2781 mutex_unlock(&power_domains->lock);
2782
Imre Deak324513c2016-06-13 16:44:36 +03002783 bxt_init_cdclk(dev_priv);
Ville Syrjälä70c2c182016-05-13 23:41:30 +03002784
2785 gen9_dbuf_enable(dev_priv);
2786
Imre Deakd7d7c9e2016-04-01 16:02:42 +03002787 if (resume && dev_priv->csr.dmc_payload)
2788 intel_csr_load_program(dev_priv);
2789}
2790
2791void bxt_display_core_uninit(struct drm_i915_private *dev_priv)
2792{
2793 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2794 struct i915_power_well *well;
2795
2796 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
2797
Ville Syrjälä70c2c182016-05-13 23:41:30 +03002798 gen9_dbuf_disable(dev_priv);
2799
Imre Deak324513c2016-06-13 16:44:36 +03002800 bxt_uninit_cdclk(dev_priv);
Imre Deakd7d7c9e2016-04-01 16:02:42 +03002801
2802 /* The spec doesn't call for removing the reset handshake flag */
2803
Imre Deak42d93662017-06-29 18:37:01 +03002804 /*
2805 * Disable PW1 (PG1).
2806 * Note that even though the driver's request is removed power well 1
2807 * may stay enabled after this due to DMC's own request on it.
2808 */
Imre Deakd7d7c9e2016-04-01 16:02:42 +03002809 mutex_lock(&power_domains->lock);
2810
2811 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
2812 intel_power_well_disable(dev_priv, well);
2813
2814 mutex_unlock(&power_domains->lock);
Imre Deak846c6b22017-06-29 18:36:58 +03002815
2816 usleep_range(10, 30); /* 10 us delay per Bspec */
Imre Deakd7d7c9e2016-04-01 16:02:42 +03002817}
2818
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07002819#define CNL_PROCMON_IDX(val) \
2820 (((val) & (PROCESS_INFO_MASK | VOLTAGE_INFO_MASK)) >> VOLTAGE_INFO_SHIFT)
2821#define NUM_CNL_PROCMON \
2822 (CNL_PROCMON_IDX(VOLTAGE_INFO_MASK | PROCESS_INFO_MASK) + 1)
2823
2824static const struct cnl_procmon {
2825 u32 dw1, dw9, dw10;
2826} cnl_procmon_values[NUM_CNL_PROCMON] = {
2827 [CNL_PROCMON_IDX(VOLTAGE_INFO_0_85V | PROCESS_INFO_DOT_0)] =
2828 { .dw1 = 0x00 << 16, .dw9 = 0x62AB67BB, .dw10 = 0x51914F96, },
2829 [CNL_PROCMON_IDX(VOLTAGE_INFO_0_95V | PROCESS_INFO_DOT_0)] =
2830 { .dw1 = 0x00 << 16, .dw9 = 0x86E172C7, .dw10 = 0x77CA5EAB, },
2831 [CNL_PROCMON_IDX(VOLTAGE_INFO_0_95V | PROCESS_INFO_DOT_1)] =
2832 { .dw1 = 0x00 << 16, .dw9 = 0x93F87FE1, .dw10 = 0x8AE871C5, },
2833 [CNL_PROCMON_IDX(VOLTAGE_INFO_1_05V | PROCESS_INFO_DOT_0)] =
2834 { .dw1 = 0x00 << 16, .dw9 = 0x98FA82DD, .dw10 = 0x89E46DC1, },
2835 [CNL_PROCMON_IDX(VOLTAGE_INFO_1_05V | PROCESS_INFO_DOT_1)] =
2836 { .dw1 = 0x44 << 16, .dw9 = 0x9A00AB25, .dw10 = 0x8AE38FF1, },
2837};
2838
2839static void cnl_display_core_init(struct drm_i915_private *dev_priv, bool resume)
2840{
2841 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2842 const struct cnl_procmon *procmon;
2843 struct i915_power_well *well;
2844 u32 val;
2845
2846 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
2847
2848 /* 1. Enable PCH Reset Handshake */
2849 val = I915_READ(HSW_NDE_RSTWRN_OPT);
2850 val |= RESET_PCH_HANDSHAKE_ENABLE;
2851 I915_WRITE(HSW_NDE_RSTWRN_OPT, val);
2852
2853 /* 2. Enable Comp */
2854 val = I915_READ(CHICKEN_MISC_2);
2855 val &= ~COMP_PWR_DOWN;
2856 I915_WRITE(CHICKEN_MISC_2, val);
2857
2858 val = I915_READ(CNL_PORT_COMP_DW3);
2859 procmon = &cnl_procmon_values[CNL_PROCMON_IDX(val)];
2860
2861 WARN_ON(procmon->dw10 == 0);
2862
2863 val = I915_READ(CNL_PORT_COMP_DW1);
2864 val &= ~((0xff << 16) | 0xff);
2865 val |= procmon->dw1;
2866 I915_WRITE(CNL_PORT_COMP_DW1, val);
2867
2868 I915_WRITE(CNL_PORT_COMP_DW9, procmon->dw9);
2869 I915_WRITE(CNL_PORT_COMP_DW10, procmon->dw10);
2870
2871 val = I915_READ(CNL_PORT_COMP_DW0);
2872 val |= COMP_INIT;
2873 I915_WRITE(CNL_PORT_COMP_DW0, val);
2874
2875 /* 3. */
2876 val = I915_READ(CNL_PORT_CL1CM_DW5);
2877 val |= CL_POWER_DOWN_ENABLE;
2878 I915_WRITE(CNL_PORT_CL1CM_DW5, val);
2879
Imre Deakb38131f2017-06-29 18:37:02 +03002880 /*
2881 * 4. Enable Power Well 1 (PG1).
2882 * The AUX IO power wells will be enabled on demand.
2883 */
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07002884 mutex_lock(&power_domains->lock);
2885 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
2886 intel_power_well_enable(dev_priv, well);
2887 mutex_unlock(&power_domains->lock);
2888
2889 /* 5. Enable CD clock */
2890 cnl_init_cdclk(dev_priv);
2891
2892 /* 6. Enable DBUF */
2893 gen9_dbuf_enable(dev_priv);
2894}
2895
2896#undef CNL_PROCMON_IDX
2897#undef NUM_CNL_PROCMON
2898
2899static void cnl_display_core_uninit(struct drm_i915_private *dev_priv)
2900{
2901 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2902 struct i915_power_well *well;
2903 u32 val;
2904
2905 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
2906
2907 /* 1. Disable all display engine functions -> aready done */
2908
2909 /* 2. Disable DBUF */
2910 gen9_dbuf_disable(dev_priv);
2911
2912 /* 3. Disable CD clock */
2913 cnl_uninit_cdclk(dev_priv);
2914
Imre Deakb38131f2017-06-29 18:37:02 +03002915 /*
2916 * 4. Disable Power Well 1 (PG1).
2917 * The AUX IO power wells are toggled on demand, so they are already
2918 * disabled at this point.
2919 */
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07002920 mutex_lock(&power_domains->lock);
2921 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
2922 intel_power_well_disable(dev_priv, well);
2923 mutex_unlock(&power_domains->lock);
2924
Imre Deak846c6b22017-06-29 18:36:58 +03002925 usleep_range(10, 30); /* 10 us delay per Bspec */
2926
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07002927 /* 5. Disable Comp */
2928 val = I915_READ(CHICKEN_MISC_2);
2929 val |= COMP_PWR_DOWN;
2930 I915_WRITE(CHICKEN_MISC_2, val);
2931}
2932
Ville Syrjälä70722462015-04-10 18:21:28 +03002933static void chv_phy_control_init(struct drm_i915_private *dev_priv)
2934{
2935 struct i915_power_well *cmn_bc =
2936 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_BC);
2937 struct i915_power_well *cmn_d =
2938 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_D);
2939
2940 /*
2941 * DISPLAY_PHY_CONTROL can get corrupted if read. As a
2942 * workaround never ever read DISPLAY_PHY_CONTROL, and
2943 * instead maintain a shadow copy ourselves. Use the actual
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002944 * power well state and lane status to reconstruct the
2945 * expected initial value.
Ville Syrjälä70722462015-04-10 18:21:28 +03002946 */
2947 dev_priv->chv_phy_control =
Ville Syrjäläbc284542015-05-26 20:22:38 +03002948 PHY_LDO_SEQ_DELAY(PHY_LDO_DELAY_600NS, DPIO_PHY0) |
2949 PHY_LDO_SEQ_DELAY(PHY_LDO_DELAY_600NS, DPIO_PHY1) |
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002950 PHY_CH_POWER_MODE(PHY_CH_DEEP_PSR, DPIO_PHY0, DPIO_CH0) |
2951 PHY_CH_POWER_MODE(PHY_CH_DEEP_PSR, DPIO_PHY0, DPIO_CH1) |
2952 PHY_CH_POWER_MODE(PHY_CH_DEEP_PSR, DPIO_PHY1, DPIO_CH0);
2953
2954 /*
2955 * If all lanes are disabled we leave the override disabled
2956 * with all power down bits cleared to match the state we
2957 * would use after disabling the port. Otherwise enable the
2958 * override and set the lane powerdown bits accding to the
2959 * current lane status.
2960 */
2961 if (cmn_bc->ops->is_enabled(dev_priv, cmn_bc)) {
2962 uint32_t status = I915_READ(DPLL(PIPE_A));
2963 unsigned int mask;
2964
2965 mask = status & DPLL_PORTB_READY_MASK;
2966 if (mask == 0xf)
2967 mask = 0x0;
2968 else
2969 dev_priv->chv_phy_control |=
2970 PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY0, DPIO_CH0);
2971
2972 dev_priv->chv_phy_control |=
2973 PHY_CH_POWER_DOWN_OVRD(mask, DPIO_PHY0, DPIO_CH0);
2974
2975 mask = (status & DPLL_PORTC_READY_MASK) >> 4;
2976 if (mask == 0xf)
2977 mask = 0x0;
2978 else
2979 dev_priv->chv_phy_control |=
2980 PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY0, DPIO_CH1);
2981
2982 dev_priv->chv_phy_control |=
2983 PHY_CH_POWER_DOWN_OVRD(mask, DPIO_PHY0, DPIO_CH1);
2984
Ville Syrjälä70722462015-04-10 18:21:28 +03002985 dev_priv->chv_phy_control |= PHY_COM_LANE_RESET_DEASSERT(DPIO_PHY0);
Ville Syrjälä3be60de2015-09-08 18:05:45 +03002986
2987 dev_priv->chv_phy_assert[DPIO_PHY0] = false;
2988 } else {
2989 dev_priv->chv_phy_assert[DPIO_PHY0] = true;
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002990 }
2991
2992 if (cmn_d->ops->is_enabled(dev_priv, cmn_d)) {
2993 uint32_t status = I915_READ(DPIO_PHY_STATUS);
2994 unsigned int mask;
2995
2996 mask = status & DPLL_PORTD_READY_MASK;
2997
2998 if (mask == 0xf)
2999 mask = 0x0;
3000 else
3001 dev_priv->chv_phy_control |=
3002 PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY1, DPIO_CH0);
3003
3004 dev_priv->chv_phy_control |=
3005 PHY_CH_POWER_DOWN_OVRD(mask, DPIO_PHY1, DPIO_CH0);
3006
Ville Syrjälä70722462015-04-10 18:21:28 +03003007 dev_priv->chv_phy_control |= PHY_COM_LANE_RESET_DEASSERT(DPIO_PHY1);
Ville Syrjälä3be60de2015-09-08 18:05:45 +03003008
3009 dev_priv->chv_phy_assert[DPIO_PHY1] = false;
3010 } else {
3011 dev_priv->chv_phy_assert[DPIO_PHY1] = true;
Ville Syrjäläe0fce782015-07-08 23:45:54 +03003012 }
3013
3014 I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
3015
3016 DRM_DEBUG_KMS("Initial PHY_CONTROL=0x%08x\n",
3017 dev_priv->chv_phy_control);
Ville Syrjälä70722462015-04-10 18:21:28 +03003018}
3019
Daniel Vetter9c065a72014-09-30 10:56:38 +02003020static void vlv_cmnlane_wa(struct drm_i915_private *dev_priv)
3021{
3022 struct i915_power_well *cmn =
3023 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_BC);
3024 struct i915_power_well *disp2d =
3025 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DISP2D);
3026
Daniel Vetter9c065a72014-09-30 10:56:38 +02003027 /* If the display might be already active skip this */
Ville Syrjälä5d93a6e2014-10-16 20:52:33 +03003028 if (cmn->ops->is_enabled(dev_priv, cmn) &&
3029 disp2d->ops->is_enabled(dev_priv, disp2d) &&
Daniel Vetter9c065a72014-09-30 10:56:38 +02003030 I915_READ(DPIO_CTL) & DPIO_CMNRST)
3031 return;
3032
3033 DRM_DEBUG_KMS("toggling display PHY side reset\n");
3034
3035 /* cmnlane needs DPLL registers */
3036 disp2d->ops->enable(dev_priv, disp2d);
3037
3038 /*
3039 * From VLV2A0_DP_eDP_HDMI_DPIO_driver_vbios_notes_11.docx:
3040 * Need to assert and de-assert PHY SB reset by gating the
3041 * common lane power, then un-gating it.
3042 * Simply ungating isn't enough to reset the PHY enough to get
3043 * ports and lanes running.
3044 */
3045 cmn->ops->disable(dev_priv, cmn);
3046}
3047
Daniel Vettere4e76842014-09-30 10:56:42 +02003048/**
3049 * intel_power_domains_init_hw - initialize hardware power domain state
3050 * @dev_priv: i915 device instance
Tvrtko Ursulin14bb2c12016-06-03 14:02:17 +01003051 * @resume: Called from resume code paths or not
Daniel Vettere4e76842014-09-30 10:56:42 +02003052 *
3053 * This function initializes the hardware power domain state and enables all
Imre Deak8d8c3862017-02-17 17:39:46 +02003054 * power wells belonging to the INIT power domain. Power wells in other
3055 * domains (and not in the INIT domain) are referenced or disabled during the
3056 * modeset state HW readout. After that the reference count of each power well
3057 * must match its HW enabled state, see intel_power_domains_verify_state().
Daniel Vettere4e76842014-09-30 10:56:42 +02003058 */
Imre Deak73dfc222015-11-17 17:33:53 +02003059void intel_power_domains_init_hw(struct drm_i915_private *dev_priv, bool resume)
Daniel Vetter9c065a72014-09-30 10:56:38 +02003060{
Daniel Vetter9c065a72014-09-30 10:56:38 +02003061 struct i915_power_domains *power_domains = &dev_priv->power_domains;
3062
3063 power_domains->initializing = true;
3064
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07003065 if (IS_CANNONLAKE(dev_priv)) {
3066 cnl_display_core_init(dev_priv, resume);
3067 } else if (IS_GEN9_BC(dev_priv)) {
Imre Deak73dfc222015-11-17 17:33:53 +02003068 skl_display_core_init(dev_priv, resume);
Ander Conselvan de Oliveirab817c442016-12-02 10:23:56 +02003069 } else if (IS_GEN9_LP(dev_priv)) {
Imre Deakd7d7c9e2016-04-01 16:02:42 +03003070 bxt_display_core_init(dev_priv, resume);
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01003071 } else if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä770effb2015-07-08 23:45:51 +03003072 mutex_lock(&power_domains->lock);
Ville Syrjälä70722462015-04-10 18:21:28 +03003073 chv_phy_control_init(dev_priv);
Ville Syrjälä770effb2015-07-08 23:45:51 +03003074 mutex_unlock(&power_domains->lock);
Tvrtko Ursulin11a914c2016-10-13 11:03:08 +01003075 } else if (IS_VALLEYVIEW(dev_priv)) {
Daniel Vetter9c065a72014-09-30 10:56:38 +02003076 mutex_lock(&power_domains->lock);
3077 vlv_cmnlane_wa(dev_priv);
3078 mutex_unlock(&power_domains->lock);
3079 }
3080
3081 /* For now, we need the power well to be always enabled. */
3082 intel_display_set_init_power(dev_priv, true);
Imre Deakd314cd42015-11-17 17:44:23 +02003083 /* Disable power support if the user asked so. */
3084 if (!i915.disable_power_well)
3085 intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
Imre Deak30eade12015-11-04 19:24:13 +02003086 intel_power_domains_sync_hw(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02003087 power_domains->initializing = false;
3088}
3089
Daniel Vettere4e76842014-09-30 10:56:42 +02003090/**
Imre Deak73dfc222015-11-17 17:33:53 +02003091 * intel_power_domains_suspend - suspend power domain state
3092 * @dev_priv: i915 device instance
3093 *
3094 * This function prepares the hardware power domain state before entering
3095 * system suspend. It must be paired with intel_power_domains_init_hw().
3096 */
3097void intel_power_domains_suspend(struct drm_i915_private *dev_priv)
3098{
Imre Deakd314cd42015-11-17 17:44:23 +02003099 /*
3100 * Even if power well support was disabled we still want to disable
3101 * power wells while we are system suspended.
3102 */
3103 if (!i915.disable_power_well)
3104 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
Imre Deak2622d792016-02-29 22:49:02 +02003105
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07003106 if (IS_CANNONLAKE(dev_priv))
3107 cnl_display_core_uninit(dev_priv);
3108 else if (IS_GEN9_BC(dev_priv))
Imre Deak2622d792016-02-29 22:49:02 +02003109 skl_display_core_uninit(dev_priv);
Ander Conselvan de Oliveirab817c442016-12-02 10:23:56 +02003110 else if (IS_GEN9_LP(dev_priv))
Imre Deakd7d7c9e2016-04-01 16:02:42 +03003111 bxt_display_core_uninit(dev_priv);
Imre Deak73dfc222015-11-17 17:33:53 +02003112}
3113
Imre Deak8d8c3862017-02-17 17:39:46 +02003114static void intel_power_domains_dump_info(struct drm_i915_private *dev_priv)
3115{
3116 struct i915_power_domains *power_domains = &dev_priv->power_domains;
3117 struct i915_power_well *power_well;
3118
3119 for_each_power_well(dev_priv, power_well) {
3120 enum intel_display_power_domain domain;
3121
3122 DRM_DEBUG_DRIVER("%-25s %d\n",
3123 power_well->name, power_well->count);
3124
3125 for_each_power_domain(domain, power_well->domains)
3126 DRM_DEBUG_DRIVER(" %-23s %d\n",
3127 intel_display_power_domain_str(domain),
3128 power_domains->domain_use_count[domain]);
3129 }
3130}
3131
3132/**
3133 * intel_power_domains_verify_state - verify the HW/SW state for all power wells
3134 * @dev_priv: i915 device instance
3135 *
3136 * Verify if the reference count of each power well matches its HW enabled
3137 * state and the total refcount of the domains it belongs to. This must be
3138 * called after modeset HW state sanitization, which is responsible for
3139 * acquiring reference counts for any power wells in use and disabling the
3140 * ones left on by BIOS but not required by any active output.
3141 */
3142void intel_power_domains_verify_state(struct drm_i915_private *dev_priv)
3143{
3144 struct i915_power_domains *power_domains = &dev_priv->power_domains;
3145 struct i915_power_well *power_well;
3146 bool dump_domain_info;
3147
3148 mutex_lock(&power_domains->lock);
3149
3150 dump_domain_info = false;
3151 for_each_power_well(dev_priv, power_well) {
3152 enum intel_display_power_domain domain;
3153 int domains_count;
3154 bool enabled;
3155
3156 /*
3157 * Power wells not belonging to any domain (like the MISC_IO
3158 * and PW1 power wells) are under FW control, so ignore them,
3159 * since their state can change asynchronously.
3160 */
3161 if (!power_well->domains)
3162 continue;
3163
3164 enabled = power_well->ops->is_enabled(dev_priv, power_well);
3165 if ((power_well->count || power_well->always_on) != enabled)
3166 DRM_ERROR("power well %s state mismatch (refcount %d/enabled %d)",
3167 power_well->name, power_well->count, enabled);
3168
3169 domains_count = 0;
3170 for_each_power_domain(domain, power_well->domains)
3171 domains_count += power_domains->domain_use_count[domain];
3172
3173 if (power_well->count != domains_count) {
3174 DRM_ERROR("power well %s refcount/domain refcount mismatch "
3175 "(refcount %d/domains refcount %d)\n",
3176 power_well->name, power_well->count,
3177 domains_count);
3178 dump_domain_info = true;
3179 }
3180 }
3181
3182 if (dump_domain_info) {
3183 static bool dumped;
3184
3185 if (!dumped) {
3186 intel_power_domains_dump_info(dev_priv);
3187 dumped = true;
3188 }
3189 }
3190
3191 mutex_unlock(&power_domains->lock);
3192}
3193
Imre Deak73dfc222015-11-17 17:33:53 +02003194/**
Daniel Vettere4e76842014-09-30 10:56:42 +02003195 * intel_runtime_pm_get - grab a runtime pm reference
3196 * @dev_priv: i915 device instance
3197 *
3198 * This function grabs a device-level runtime pm reference (mostly used for GEM
3199 * code to ensure the GTT or GT is on) and ensures that it is powered up.
3200 *
3201 * Any runtime pm reference obtained by this function must have a symmetric
3202 * call to intel_runtime_pm_put() to release the reference again.
3203 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02003204void intel_runtime_pm_get(struct drm_i915_private *dev_priv)
3205{
David Weinehall52a05c32016-08-22 13:32:44 +03003206 struct pci_dev *pdev = dev_priv->drm.pdev;
3207 struct device *kdev = &pdev->dev;
Imre Deakf5073822017-03-28 12:38:55 +03003208 int ret;
Daniel Vetter9c065a72014-09-30 10:56:38 +02003209
Imre Deakf5073822017-03-28 12:38:55 +03003210 ret = pm_runtime_get_sync(kdev);
3211 WARN_ONCE(ret < 0, "pm_runtime_get_sync() failed: %d\n", ret);
Imre Deak1f814da2015-12-16 02:52:19 +02003212
3213 atomic_inc(&dev_priv->pm.wakeref_count);
Imre Deakc9b88462015-12-15 20:10:34 +02003214 assert_rpm_wakelock_held(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02003215}
3216
Daniel Vettere4e76842014-09-30 10:56:42 +02003217/**
Imre Deak09731282016-02-17 14:17:42 +02003218 * intel_runtime_pm_get_if_in_use - grab a runtime pm reference if device in use
3219 * @dev_priv: i915 device instance
3220 *
3221 * This function grabs a device-level runtime pm reference if the device is
3222 * already in use and ensures that it is powered up.
3223 *
3224 * Any runtime pm reference obtained by this function must have a symmetric
3225 * call to intel_runtime_pm_put() to release the reference again.
3226 */
3227bool intel_runtime_pm_get_if_in_use(struct drm_i915_private *dev_priv)
3228{
David Weinehall52a05c32016-08-22 13:32:44 +03003229 struct pci_dev *pdev = dev_priv->drm.pdev;
3230 struct device *kdev = &pdev->dev;
Imre Deak09731282016-02-17 14:17:42 +02003231
Chris Wilson135dc792016-02-25 21:10:28 +00003232 if (IS_ENABLED(CONFIG_PM)) {
David Weinehallc49d13e2016-08-22 13:32:42 +03003233 int ret = pm_runtime_get_if_in_use(kdev);
Imre Deak09731282016-02-17 14:17:42 +02003234
Chris Wilson135dc792016-02-25 21:10:28 +00003235 /*
3236 * In cases runtime PM is disabled by the RPM core and we get
3237 * an -EINVAL return value we are not supposed to call this
3238 * function, since the power state is undefined. This applies
3239 * atm to the late/early system suspend/resume handlers.
3240 */
Imre Deakf5073822017-03-28 12:38:55 +03003241 WARN_ONCE(ret < 0,
3242 "pm_runtime_get_if_in_use() failed: %d\n", ret);
Chris Wilson135dc792016-02-25 21:10:28 +00003243 if (ret <= 0)
3244 return false;
3245 }
Imre Deak09731282016-02-17 14:17:42 +02003246
3247 atomic_inc(&dev_priv->pm.wakeref_count);
3248 assert_rpm_wakelock_held(dev_priv);
3249
3250 return true;
3251}
3252
3253/**
Daniel Vettere4e76842014-09-30 10:56:42 +02003254 * intel_runtime_pm_get_noresume - grab a runtime pm reference
3255 * @dev_priv: i915 device instance
3256 *
3257 * This function grabs a device-level runtime pm reference (mostly used for GEM
3258 * code to ensure the GTT or GT is on).
3259 *
3260 * It will _not_ power up the device but instead only check that it's powered
3261 * on. Therefore it is only valid to call this functions from contexts where
3262 * the device is known to be powered up and where trying to power it up would
3263 * result in hilarity and deadlocks. That pretty much means only the system
3264 * suspend/resume code where this is used to grab runtime pm references for
3265 * delayed setup down in work items.
3266 *
3267 * Any runtime pm reference obtained by this function must have a symmetric
3268 * call to intel_runtime_pm_put() to release the reference again.
3269 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02003270void intel_runtime_pm_get_noresume(struct drm_i915_private *dev_priv)
3271{
David Weinehall52a05c32016-08-22 13:32:44 +03003272 struct pci_dev *pdev = dev_priv->drm.pdev;
3273 struct device *kdev = &pdev->dev;
Daniel Vetter9c065a72014-09-30 10:56:38 +02003274
Imre Deakc9b88462015-12-15 20:10:34 +02003275 assert_rpm_wakelock_held(dev_priv);
David Weinehallc49d13e2016-08-22 13:32:42 +03003276 pm_runtime_get_noresume(kdev);
Imre Deak1f814da2015-12-16 02:52:19 +02003277
3278 atomic_inc(&dev_priv->pm.wakeref_count);
Daniel Vetter9c065a72014-09-30 10:56:38 +02003279}
3280
Daniel Vettere4e76842014-09-30 10:56:42 +02003281/**
3282 * intel_runtime_pm_put - release a runtime pm reference
3283 * @dev_priv: i915 device instance
3284 *
3285 * This function drops the device-level runtime pm reference obtained by
3286 * intel_runtime_pm_get() and might power down the corresponding
3287 * hardware block right away if this is the last reference.
3288 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02003289void intel_runtime_pm_put(struct drm_i915_private *dev_priv)
3290{
David Weinehall52a05c32016-08-22 13:32:44 +03003291 struct pci_dev *pdev = dev_priv->drm.pdev;
3292 struct device *kdev = &pdev->dev;
Daniel Vetter9c065a72014-09-30 10:56:38 +02003293
Imre Deak542db3c2015-12-15 20:10:36 +02003294 assert_rpm_wakelock_held(dev_priv);
Chris Wilson2eedfc72016-10-24 13:42:17 +01003295 atomic_dec(&dev_priv->pm.wakeref_count);
Imre Deak1f814da2015-12-16 02:52:19 +02003296
David Weinehallc49d13e2016-08-22 13:32:42 +03003297 pm_runtime_mark_last_busy(kdev);
3298 pm_runtime_put_autosuspend(kdev);
Daniel Vetter9c065a72014-09-30 10:56:38 +02003299}
3300
Daniel Vettere4e76842014-09-30 10:56:42 +02003301/**
3302 * intel_runtime_pm_enable - enable runtime pm
3303 * @dev_priv: i915 device instance
3304 *
3305 * This function enables runtime pm at the end of the driver load sequence.
3306 *
3307 * Note that this function does currently not enable runtime pm for the
3308 * subordinate display power domains. That is only done on the first modeset
3309 * using intel_display_set_init_power().
3310 */
Daniel Vetterf458ebb2014-09-30 10:56:39 +02003311void intel_runtime_pm_enable(struct drm_i915_private *dev_priv)
Daniel Vetter9c065a72014-09-30 10:56:38 +02003312{
David Weinehall52a05c32016-08-22 13:32:44 +03003313 struct pci_dev *pdev = dev_priv->drm.pdev;
David Weinehall52a05c32016-08-22 13:32:44 +03003314 struct device *kdev = &pdev->dev;
Daniel Vetter9c065a72014-09-30 10:56:38 +02003315
David Weinehallc49d13e2016-08-22 13:32:42 +03003316 pm_runtime_set_autosuspend_delay(kdev, 10000); /* 10s */
3317 pm_runtime_mark_last_busy(kdev);
Imre Deakcbc68dc2015-12-17 19:04:33 +02003318
Imre Deak25b181b2015-12-17 13:44:56 +02003319 /*
3320 * Take a permanent reference to disable the RPM functionality and drop
3321 * it only when unloading the driver. Use the low level get/put helpers,
3322 * so the driver's own RPM reference tracking asserts also work on
3323 * platforms without RPM support.
3324 */
Tvrtko Ursulin6772ffe2016-10-13 11:02:55 +01003325 if (!HAS_RUNTIME_PM(dev_priv)) {
Imre Deakf5073822017-03-28 12:38:55 +03003326 int ret;
3327
David Weinehallc49d13e2016-08-22 13:32:42 +03003328 pm_runtime_dont_use_autosuspend(kdev);
Imre Deakf5073822017-03-28 12:38:55 +03003329 ret = pm_runtime_get_sync(kdev);
3330 WARN(ret < 0, "pm_runtime_get_sync() failed: %d\n", ret);
Imre Deakcbc68dc2015-12-17 19:04:33 +02003331 } else {
David Weinehallc49d13e2016-08-22 13:32:42 +03003332 pm_runtime_use_autosuspend(kdev);
Imre Deakcbc68dc2015-12-17 19:04:33 +02003333 }
Daniel Vetter9c065a72014-09-30 10:56:38 +02003334
Imre Deakaabee1b2015-12-15 20:10:29 +02003335 /*
3336 * The core calls the driver load handler with an RPM reference held.
3337 * We drop that here and will reacquire it during unloading in
3338 * intel_power_domains_fini().
3339 */
David Weinehallc49d13e2016-08-22 13:32:42 +03003340 pm_runtime_put_autosuspend(kdev);
Daniel Vetter9c065a72014-09-30 10:56:38 +02003341}