blob: bbade8a5918f4637eee929002ce4651093e02335 [file] [log] [blame]
Daniel Vetter9c065a72014-09-30 10:56:38 +02001/*
2 * Copyright © 2012-2014 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 *
23 * Authors:
24 * Eugeni Dodonov <eugeni.dodonov@intel.com>
25 * Daniel Vetter <daniel.vetter@ffwll.ch>
26 *
27 */
28
29#include <linux/pm_runtime.h>
30#include <linux/vgaarb.h>
31
32#include "i915_drv.h"
33#include "intel_drv.h"
Daniel Vetter9c065a72014-09-30 10:56:38 +020034
Daniel Vettere4e76842014-09-30 10:56:42 +020035/**
36 * DOC: runtime pm
37 *
38 * The i915 driver supports dynamic enabling and disabling of entire hardware
39 * blocks at runtime. This is especially important on the display side where
40 * software is supposed to control many power gates manually on recent hardware,
41 * since on the GT side a lot of the power management is done by the hardware.
42 * But even there some manual control at the device level is required.
43 *
44 * Since i915 supports a diverse set of platforms with a unified codebase and
45 * hardware engineers just love to shuffle functionality around between power
46 * domains there's a sizeable amount of indirection required. This file provides
47 * generic functions to the driver for grabbing and releasing references for
48 * abstract power domains. It then maps those to the actual power wells
49 * present for a given platform.
50 */
51
Suketu Shah5aefb232015-04-16 14:22:10 +053052bool intel_display_power_well_is_enabled(struct drm_i915_private *dev_priv,
Imre Deak438b8dc2017-07-11 23:42:30 +030053 enum i915_power_well_id power_well_id);
Suketu Shah5aefb232015-04-16 14:22:10 +053054
Imre Deak9c8d0b82016-06-13 16:44:34 +030055static struct i915_power_well *
Imre Deak438b8dc2017-07-11 23:42:30 +030056lookup_power_well(struct drm_i915_private *dev_priv,
57 enum i915_power_well_id power_well_id);
Imre Deak9c8d0b82016-06-13 16:44:34 +030058
Daniel Stone9895ad02015-11-20 15:55:33 +000059const char *
60intel_display_power_domain_str(enum intel_display_power_domain domain)
61{
62 switch (domain) {
63 case POWER_DOMAIN_PIPE_A:
64 return "PIPE_A";
65 case POWER_DOMAIN_PIPE_B:
66 return "PIPE_B";
67 case POWER_DOMAIN_PIPE_C:
68 return "PIPE_C";
69 case POWER_DOMAIN_PIPE_A_PANEL_FITTER:
70 return "PIPE_A_PANEL_FITTER";
71 case POWER_DOMAIN_PIPE_B_PANEL_FITTER:
72 return "PIPE_B_PANEL_FITTER";
73 case POWER_DOMAIN_PIPE_C_PANEL_FITTER:
74 return "PIPE_C_PANEL_FITTER";
75 case POWER_DOMAIN_TRANSCODER_A:
76 return "TRANSCODER_A";
77 case POWER_DOMAIN_TRANSCODER_B:
78 return "TRANSCODER_B";
79 case POWER_DOMAIN_TRANSCODER_C:
80 return "TRANSCODER_C";
81 case POWER_DOMAIN_TRANSCODER_EDP:
82 return "TRANSCODER_EDP";
Jani Nikula4d1de972016-03-18 17:05:42 +020083 case POWER_DOMAIN_TRANSCODER_DSI_A:
84 return "TRANSCODER_DSI_A";
85 case POWER_DOMAIN_TRANSCODER_DSI_C:
86 return "TRANSCODER_DSI_C";
Daniel Stone9895ad02015-11-20 15:55:33 +000087 case POWER_DOMAIN_PORT_DDI_A_LANES:
88 return "PORT_DDI_A_LANES";
89 case POWER_DOMAIN_PORT_DDI_B_LANES:
90 return "PORT_DDI_B_LANES";
91 case POWER_DOMAIN_PORT_DDI_C_LANES:
92 return "PORT_DDI_C_LANES";
93 case POWER_DOMAIN_PORT_DDI_D_LANES:
94 return "PORT_DDI_D_LANES";
95 case POWER_DOMAIN_PORT_DDI_E_LANES:
96 return "PORT_DDI_E_LANES";
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +020097 case POWER_DOMAIN_PORT_DDI_A_IO:
98 return "PORT_DDI_A_IO";
99 case POWER_DOMAIN_PORT_DDI_B_IO:
100 return "PORT_DDI_B_IO";
101 case POWER_DOMAIN_PORT_DDI_C_IO:
102 return "PORT_DDI_C_IO";
103 case POWER_DOMAIN_PORT_DDI_D_IO:
104 return "PORT_DDI_D_IO";
105 case POWER_DOMAIN_PORT_DDI_E_IO:
106 return "PORT_DDI_E_IO";
Daniel Stone9895ad02015-11-20 15:55:33 +0000107 case POWER_DOMAIN_PORT_DSI:
108 return "PORT_DSI";
109 case POWER_DOMAIN_PORT_CRT:
110 return "PORT_CRT";
111 case POWER_DOMAIN_PORT_OTHER:
112 return "PORT_OTHER";
113 case POWER_DOMAIN_VGA:
114 return "VGA";
115 case POWER_DOMAIN_AUDIO:
116 return "AUDIO";
117 case POWER_DOMAIN_PLLS:
118 return "PLLS";
119 case POWER_DOMAIN_AUX_A:
120 return "AUX_A";
121 case POWER_DOMAIN_AUX_B:
122 return "AUX_B";
123 case POWER_DOMAIN_AUX_C:
124 return "AUX_C";
125 case POWER_DOMAIN_AUX_D:
126 return "AUX_D";
127 case POWER_DOMAIN_GMBUS:
128 return "GMBUS";
129 case POWER_DOMAIN_INIT:
130 return "INIT";
131 case POWER_DOMAIN_MODESET:
132 return "MODESET";
133 default:
134 MISSING_CASE(domain);
135 return "?";
136 }
137}
138
Damien Lespiaue8ca9322015-07-30 18:20:26 -0300139static void intel_power_well_enable(struct drm_i915_private *dev_priv,
140 struct i915_power_well *power_well)
141{
142 DRM_DEBUG_KMS("enabling %s\n", power_well->name);
143 power_well->ops->enable(dev_priv, power_well);
144 power_well->hw_enabled = true;
145}
146
Damien Lespiaudcddab32015-07-30 18:20:27 -0300147static void intel_power_well_disable(struct drm_i915_private *dev_priv,
148 struct i915_power_well *power_well)
149{
150 DRM_DEBUG_KMS("disabling %s\n", power_well->name);
151 power_well->hw_enabled = false;
152 power_well->ops->disable(dev_priv, power_well);
153}
154
Imre Deakb409ca92016-06-13 16:44:33 +0300155static void intel_power_well_get(struct drm_i915_private *dev_priv,
156 struct i915_power_well *power_well)
157{
158 if (!power_well->count++)
159 intel_power_well_enable(dev_priv, power_well);
160}
161
162static void intel_power_well_put(struct drm_i915_private *dev_priv,
163 struct i915_power_well *power_well)
164{
165 WARN(!power_well->count, "Use count on power well %s is already zero",
166 power_well->name);
167
168 if (!--power_well->count)
169 intel_power_well_disable(dev_priv, power_well);
170}
171
Daniel Vettere4e76842014-09-30 10:56:42 +0200172/*
Daniel Vetter9c065a72014-09-30 10:56:38 +0200173 * We should only use the power well if we explicitly asked the hardware to
174 * enable it, so check if it's enabled and also check if we've requested it to
175 * be enabled.
176 */
177static bool hsw_power_well_enabled(struct drm_i915_private *dev_priv,
178 struct i915_power_well *power_well)
179{
180 return I915_READ(HSW_PWR_WELL_DRIVER) ==
181 (HSW_PWR_WELL_ENABLE_REQUEST | HSW_PWR_WELL_STATE_ENABLED);
182}
183
Daniel Vettere4e76842014-09-30 10:56:42 +0200184/**
185 * __intel_display_power_is_enabled - unlocked check for a power domain
186 * @dev_priv: i915 device instance
187 * @domain: power domain to check
188 *
189 * This is the unlocked version of intel_display_power_is_enabled() and should
190 * only be used from error capture and recovery code where deadlocks are
191 * possible.
192 *
193 * Returns:
194 * True when the power domain is enabled, false otherwise.
195 */
Daniel Vetterf458ebb2014-09-30 10:56:39 +0200196bool __intel_display_power_is_enabled(struct drm_i915_private *dev_priv,
197 enum intel_display_power_domain domain)
Daniel Vetter9c065a72014-09-30 10:56:38 +0200198{
Daniel Vetter9c065a72014-09-30 10:56:38 +0200199 struct i915_power_well *power_well;
200 bool is_enabled;
Daniel Vetter9c065a72014-09-30 10:56:38 +0200201
202 if (dev_priv->pm.suspended)
203 return false;
204
Daniel Vetter9c065a72014-09-30 10:56:38 +0200205 is_enabled = true;
206
Imre Deak75ccb2e2017-02-17 17:39:43 +0200207 for_each_power_domain_well_rev(dev_priv, power_well, BIT_ULL(domain)) {
Daniel Vetter9c065a72014-09-30 10:56:38 +0200208 if (power_well->always_on)
209 continue;
210
211 if (!power_well->hw_enabled) {
212 is_enabled = false;
213 break;
214 }
215 }
216
217 return is_enabled;
218}
219
Daniel Vettere4e76842014-09-30 10:56:42 +0200220/**
Damien Lespiauf61ccae2014-11-25 13:45:41 +0000221 * intel_display_power_is_enabled - check for a power domain
Daniel Vettere4e76842014-09-30 10:56:42 +0200222 * @dev_priv: i915 device instance
223 * @domain: power domain to check
224 *
225 * This function can be used to check the hw power domain state. It is mostly
226 * used in hardware state readout functions. Everywhere else code should rely
227 * upon explicit power domain reference counting to ensure that the hardware
228 * block is powered up before accessing it.
229 *
230 * Callers must hold the relevant modesetting locks to ensure that concurrent
231 * threads can't disable the power well while the caller tries to read a few
232 * registers.
233 *
234 * Returns:
235 * True when the power domain is enabled, false otherwise.
236 */
Daniel Vetterf458ebb2014-09-30 10:56:39 +0200237bool intel_display_power_is_enabled(struct drm_i915_private *dev_priv,
238 enum intel_display_power_domain domain)
Daniel Vetter9c065a72014-09-30 10:56:38 +0200239{
240 struct i915_power_domains *power_domains;
241 bool ret;
242
243 power_domains = &dev_priv->power_domains;
244
245 mutex_lock(&power_domains->lock);
Daniel Vetterf458ebb2014-09-30 10:56:39 +0200246 ret = __intel_display_power_is_enabled(dev_priv, domain);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200247 mutex_unlock(&power_domains->lock);
248
249 return ret;
250}
251
Daniel Vettere4e76842014-09-30 10:56:42 +0200252/**
253 * intel_display_set_init_power - set the initial power domain state
254 * @dev_priv: i915 device instance
255 * @enable: whether to enable or disable the initial power domain state
256 *
257 * For simplicity our driver load/unload and system suspend/resume code assumes
258 * that all power domains are always enabled. This functions controls the state
259 * of this little hack. While the initial power domain state is enabled runtime
260 * pm is effectively disabled.
261 */
Daniel Vetterd9bc89d92014-09-30 10:56:40 +0200262void intel_display_set_init_power(struct drm_i915_private *dev_priv,
263 bool enable)
264{
265 if (dev_priv->power_domains.init_power_on == enable)
266 return;
267
268 if (enable)
269 intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
270 else
271 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
272
273 dev_priv->power_domains.init_power_on = enable;
274}
275
Daniel Vetter9c065a72014-09-30 10:56:38 +0200276/*
277 * Starting with Haswell, we have a "Power Down Well" that can be turned off
278 * when not needed anymore. We have 4 registers that can request the power well
279 * to be enabled, and it will only be disabled if none of the registers is
280 * requesting it to be enabled.
281 */
282static void hsw_power_well_post_enable(struct drm_i915_private *dev_priv)
283{
David Weinehall52a05c32016-08-22 13:32:44 +0300284 struct pci_dev *pdev = dev_priv->drm.pdev;
Daniel Vetter9c065a72014-09-30 10:56:38 +0200285
286 /*
287 * After we re-enable the power well, if we touch VGA register 0x3d5
288 * we'll get unclaimed register interrupts. This stops after we write
289 * anything to the VGA MSR register. The vgacon module uses this
290 * register all the time, so if we unbind our driver and, as a
291 * consequence, bind vgacon, we'll get stuck in an infinite loop at
292 * console_unlock(). So make here we touch the VGA MSR register, making
293 * sure vgacon can keep working normally without triggering interrupts
294 * and error messages.
295 */
David Weinehall52a05c32016-08-22 13:32:44 +0300296 vga_get_uninterruptible(pdev, VGA_RSRC_LEGACY_IO);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200297 outb(inb(VGA_MSR_READ), VGA_MSR_WRITE);
David Weinehall52a05c32016-08-22 13:32:44 +0300298 vga_put(pdev, VGA_RSRC_LEGACY_IO);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200299
Tvrtko Ursulin86527442016-10-13 11:03:00 +0100300 if (IS_BROADWELL(dev_priv))
Damien Lespiau4c6c03b2015-03-06 18:50:48 +0000301 gen8_irq_power_well_post_enable(dev_priv,
302 1 << PIPE_C | 1 << PIPE_B);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200303}
304
Ville Syrjäläaae8ba82016-02-19 20:47:30 +0200305static void hsw_power_well_pre_disable(struct drm_i915_private *dev_priv)
306{
307 if (IS_BROADWELL(dev_priv))
308 gen8_irq_power_well_pre_disable(dev_priv,
309 1 << PIPE_C | 1 << PIPE_B);
310}
311
Damien Lespiaud14c0342015-03-06 18:50:51 +0000312static void skl_power_well_post_enable(struct drm_i915_private *dev_priv,
313 struct i915_power_well *power_well)
314{
David Weinehall52a05c32016-08-22 13:32:44 +0300315 struct pci_dev *pdev = dev_priv->drm.pdev;
Damien Lespiaud14c0342015-03-06 18:50:51 +0000316
317 /*
318 * After we re-enable the power well, if we touch VGA register 0x3d5
319 * we'll get unclaimed register interrupts. This stops after we write
320 * anything to the VGA MSR register. The vgacon module uses this
321 * register all the time, so if we unbind our driver and, as a
322 * consequence, bind vgacon, we'll get stuck in an infinite loop at
323 * console_unlock(). So make here we touch the VGA MSR register, making
324 * sure vgacon can keep working normally without triggering interrupts
325 * and error messages.
326 */
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +0300327 if (power_well->id == SKL_DISP_PW_2) {
David Weinehall52a05c32016-08-22 13:32:44 +0300328 vga_get_uninterruptible(pdev, VGA_RSRC_LEGACY_IO);
Damien Lespiaud14c0342015-03-06 18:50:51 +0000329 outb(inb(VGA_MSR_READ), VGA_MSR_WRITE);
David Weinehall52a05c32016-08-22 13:32:44 +0300330 vga_put(pdev, VGA_RSRC_LEGACY_IO);
Damien Lespiaud14c0342015-03-06 18:50:51 +0000331
332 gen8_irq_power_well_post_enable(dev_priv,
333 1 << PIPE_C | 1 << PIPE_B);
334 }
Damien Lespiaud14c0342015-03-06 18:50:51 +0000335}
336
Ville Syrjäläaae8ba82016-02-19 20:47:30 +0200337static void skl_power_well_pre_disable(struct drm_i915_private *dev_priv,
338 struct i915_power_well *power_well)
339{
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +0300340 if (power_well->id == SKL_DISP_PW_2)
Ville Syrjäläaae8ba82016-02-19 20:47:30 +0200341 gen8_irq_power_well_pre_disable(dev_priv,
342 1 << PIPE_C | 1 << PIPE_B);
343}
344
Imre Deak42d93662017-06-29 18:37:01 +0300345static void gen9_wait_for_power_well_enable(struct drm_i915_private *dev_priv,
346 struct i915_power_well *power_well)
347{
Imre Deak438b8dc2017-07-11 23:42:30 +0300348 enum i915_power_well_id id = power_well->id;
Imre Deak42d93662017-06-29 18:37:01 +0300349
350 /* Timeout for PW1:10 us, AUX:not specified, other PWs:20 us. */
351 WARN_ON(intel_wait_for_register(dev_priv,
352 HSW_PWR_WELL_DRIVER,
353 SKL_POWER_WELL_STATE(id),
354 SKL_POWER_WELL_STATE(id),
355 1));
356}
357
Imre Deak438b8dc2017-07-11 23:42:30 +0300358static u32 gen9_power_well_requesters(struct drm_i915_private *dev_priv,
359 enum i915_power_well_id id)
Imre Deak42d93662017-06-29 18:37:01 +0300360{
361 u32 req_mask = SKL_POWER_WELL_REQ(id);
362 u32 ret;
363
364 ret = I915_READ(HSW_PWR_WELL_BIOS) & req_mask ? 1 : 0;
365 ret |= I915_READ(HSW_PWR_WELL_DRIVER) & req_mask ? 2 : 0;
366 ret |= I915_READ(HSW_PWR_WELL_KVMR) & req_mask ? 4 : 0;
367 ret |= I915_READ(HSW_PWR_WELL_DEBUG) & req_mask ? 8 : 0;
368
369 return ret;
370}
371
372static void gen9_wait_for_power_well_disable(struct drm_i915_private *dev_priv,
373 struct i915_power_well *power_well)
374{
Imre Deak438b8dc2017-07-11 23:42:30 +0300375 enum i915_power_well_id id = power_well->id;
Imre Deak42d93662017-06-29 18:37:01 +0300376 bool disabled;
377 u32 reqs;
378
379 /*
380 * Bspec doesn't require waiting for PWs to get disabled, but still do
381 * this for paranoia. The known cases where a PW will be forced on:
382 * - a KVMR request on any power well via the KVMR request register
383 * - a DMC request on PW1 and MISC_IO power wells via the BIOS and
384 * DEBUG request registers
385 * Skip the wait in case any of the request bits are set and print a
386 * diagnostic message.
387 */
388 wait_for((disabled = !(I915_READ(HSW_PWR_WELL_DRIVER) &
389 SKL_POWER_WELL_STATE(id))) ||
390 (reqs = gen9_power_well_requesters(dev_priv, id)), 1);
391 if (disabled)
392 return;
393
394 DRM_DEBUG_KMS("%s forced on (bios:%d driver:%d kvmr:%d debug:%d)\n",
395 power_well->name,
396 !!(reqs & 1), !!(reqs & 2), !!(reqs & 4), !!(reqs & 8));
397}
398
Daniel Vetter9c065a72014-09-30 10:56:38 +0200399static void hsw_set_power_well(struct drm_i915_private *dev_priv,
400 struct i915_power_well *power_well, bool enable)
401{
402 bool is_enabled, enable_requested;
403 uint32_t tmp;
404
405 tmp = I915_READ(HSW_PWR_WELL_DRIVER);
406 is_enabled = tmp & HSW_PWR_WELL_STATE_ENABLED;
407 enable_requested = tmp & HSW_PWR_WELL_ENABLE_REQUEST;
408
409 if (enable) {
410 if (!enable_requested)
411 I915_WRITE(HSW_PWR_WELL_DRIVER,
412 HSW_PWR_WELL_ENABLE_REQUEST);
413
414 if (!is_enabled) {
415 DRM_DEBUG_KMS("Enabling power well\n");
Chris Wilson2c2ccc32016-06-30 15:33:32 +0100416 if (intel_wait_for_register(dev_priv,
417 HSW_PWR_WELL_DRIVER,
418 HSW_PWR_WELL_STATE_ENABLED,
419 HSW_PWR_WELL_STATE_ENABLED,
420 20))
Daniel Vetter9c065a72014-09-30 10:56:38 +0200421 DRM_ERROR("Timeout enabling power well\n");
Paulo Zanoni6d729bf2014-10-07 16:11:11 -0300422 hsw_power_well_post_enable(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200423 }
424
Daniel Vetter9c065a72014-09-30 10:56:38 +0200425 } else {
426 if (enable_requested) {
Ville Syrjäläaae8ba82016-02-19 20:47:30 +0200427 hsw_power_well_pre_disable(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200428 I915_WRITE(HSW_PWR_WELL_DRIVER, 0);
429 POSTING_READ(HSW_PWR_WELL_DRIVER);
430 DRM_DEBUG_KMS("Requesting to disable the power well\n");
431 }
432 }
433}
434
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000435#define SKL_DISPLAY_POWERWELL_2_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200436 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
437 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
438 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
439 BIT_ULL(POWER_DOMAIN_PIPE_C) | \
440 BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
441 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
442 BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
443 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
444 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
445 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_LANES) | \
446 BIT_ULL(POWER_DOMAIN_PORT_DDI_E_LANES) | \
447 BIT_ULL(POWER_DOMAIN_AUX_B) | \
448 BIT_ULL(POWER_DOMAIN_AUX_C) | \
449 BIT_ULL(POWER_DOMAIN_AUX_D) | \
450 BIT_ULL(POWER_DOMAIN_AUDIO) | \
451 BIT_ULL(POWER_DOMAIN_VGA) | \
452 BIT_ULL(POWER_DOMAIN_INIT))
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +0200453#define SKL_DISPLAY_DDI_IO_A_E_POWER_DOMAINS ( \
454 BIT_ULL(POWER_DOMAIN_PORT_DDI_A_IO) | \
455 BIT_ULL(POWER_DOMAIN_PORT_DDI_E_IO) | \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200456 BIT_ULL(POWER_DOMAIN_INIT))
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +0200457#define SKL_DISPLAY_DDI_IO_B_POWER_DOMAINS ( \
458 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_IO) | \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200459 BIT_ULL(POWER_DOMAIN_INIT))
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +0200460#define SKL_DISPLAY_DDI_IO_C_POWER_DOMAINS ( \
461 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_IO) | \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200462 BIT_ULL(POWER_DOMAIN_INIT))
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +0200463#define SKL_DISPLAY_DDI_IO_D_POWER_DOMAINS ( \
464 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_IO) | \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200465 BIT_ULL(POWER_DOMAIN_INIT))
Patrik Jakobsson9f836f92015-11-16 16:20:01 +0100466#define SKL_DISPLAY_DC_OFF_POWER_DOMAINS ( \
467 SKL_DISPLAY_POWERWELL_2_POWER_DOMAINS | \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200468 BIT_ULL(POWER_DOMAIN_MODESET) | \
469 BIT_ULL(POWER_DOMAIN_AUX_A) | \
470 BIT_ULL(POWER_DOMAIN_INIT))
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000471
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +0530472#define BXT_DISPLAY_POWERWELL_2_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200473 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
474 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
475 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
476 BIT_ULL(POWER_DOMAIN_PIPE_C) | \
477 BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
478 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
479 BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
480 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
481 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
482 BIT_ULL(POWER_DOMAIN_AUX_B) | \
483 BIT_ULL(POWER_DOMAIN_AUX_C) | \
484 BIT_ULL(POWER_DOMAIN_AUDIO) | \
485 BIT_ULL(POWER_DOMAIN_VGA) | \
486 BIT_ULL(POWER_DOMAIN_GMBUS) | \
487 BIT_ULL(POWER_DOMAIN_INIT))
Patrik Jakobsson9f836f92015-11-16 16:20:01 +0100488#define BXT_DISPLAY_DC_OFF_POWER_DOMAINS ( \
489 BXT_DISPLAY_POWERWELL_2_POWER_DOMAINS | \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200490 BIT_ULL(POWER_DOMAIN_MODESET) | \
491 BIT_ULL(POWER_DOMAIN_AUX_A) | \
492 BIT_ULL(POWER_DOMAIN_INIT))
Imre Deak9c8d0b82016-06-13 16:44:34 +0300493#define BXT_DPIO_CMN_A_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200494 BIT_ULL(POWER_DOMAIN_PORT_DDI_A_LANES) | \
495 BIT_ULL(POWER_DOMAIN_AUX_A) | \
496 BIT_ULL(POWER_DOMAIN_INIT))
Imre Deak9c8d0b82016-06-13 16:44:34 +0300497#define BXT_DPIO_CMN_BC_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200498 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
499 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
500 BIT_ULL(POWER_DOMAIN_AUX_B) | \
501 BIT_ULL(POWER_DOMAIN_AUX_C) | \
502 BIT_ULL(POWER_DOMAIN_INIT))
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +0530503
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +0200504#define GLK_DISPLAY_POWERWELL_2_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200505 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
506 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
507 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
508 BIT_ULL(POWER_DOMAIN_PIPE_C) | \
509 BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
510 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
511 BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
512 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
513 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
514 BIT_ULL(POWER_DOMAIN_AUX_B) | \
515 BIT_ULL(POWER_DOMAIN_AUX_C) | \
516 BIT_ULL(POWER_DOMAIN_AUDIO) | \
517 BIT_ULL(POWER_DOMAIN_VGA) | \
518 BIT_ULL(POWER_DOMAIN_INIT))
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +0200519#define GLK_DISPLAY_DDI_IO_A_POWER_DOMAINS ( \
520 BIT_ULL(POWER_DOMAIN_PORT_DDI_A_IO))
521#define GLK_DISPLAY_DDI_IO_B_POWER_DOMAINS ( \
522 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_IO))
523#define GLK_DISPLAY_DDI_IO_C_POWER_DOMAINS ( \
524 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_IO))
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +0200525#define GLK_DPIO_CMN_A_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200526 BIT_ULL(POWER_DOMAIN_PORT_DDI_A_LANES) | \
527 BIT_ULL(POWER_DOMAIN_AUX_A) | \
528 BIT_ULL(POWER_DOMAIN_INIT))
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +0200529#define GLK_DPIO_CMN_B_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200530 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
531 BIT_ULL(POWER_DOMAIN_AUX_B) | \
532 BIT_ULL(POWER_DOMAIN_INIT))
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +0200533#define GLK_DPIO_CMN_C_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200534 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
535 BIT_ULL(POWER_DOMAIN_AUX_C) | \
536 BIT_ULL(POWER_DOMAIN_INIT))
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +0200537#define GLK_DISPLAY_AUX_A_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200538 BIT_ULL(POWER_DOMAIN_AUX_A) | \
539 BIT_ULL(POWER_DOMAIN_INIT))
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +0200540#define GLK_DISPLAY_AUX_B_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200541 BIT_ULL(POWER_DOMAIN_AUX_B) | \
542 BIT_ULL(POWER_DOMAIN_INIT))
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +0200543#define GLK_DISPLAY_AUX_C_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200544 BIT_ULL(POWER_DOMAIN_AUX_C) | \
545 BIT_ULL(POWER_DOMAIN_INIT))
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +0200546#define GLK_DISPLAY_DC_OFF_POWER_DOMAINS ( \
547 GLK_DISPLAY_POWERWELL_2_POWER_DOMAINS | \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200548 BIT_ULL(POWER_DOMAIN_MODESET) | \
549 BIT_ULL(POWER_DOMAIN_AUX_A) | \
550 BIT_ULL(POWER_DOMAIN_INIT))
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +0200551
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -0700552#define CNL_DISPLAY_POWERWELL_2_POWER_DOMAINS ( \
553 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
554 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
555 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
556 BIT_ULL(POWER_DOMAIN_PIPE_C) | \
557 BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
558 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
559 BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
560 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
561 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
562 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_LANES) | \
563 BIT_ULL(POWER_DOMAIN_PORT_DDI_E_LANES) | \
564 BIT_ULL(POWER_DOMAIN_AUX_B) | \
565 BIT_ULL(POWER_DOMAIN_AUX_C) | \
566 BIT_ULL(POWER_DOMAIN_AUX_D) | \
567 BIT_ULL(POWER_DOMAIN_AUDIO) | \
568 BIT_ULL(POWER_DOMAIN_VGA) | \
569 BIT_ULL(POWER_DOMAIN_INIT))
570#define CNL_DISPLAY_DDI_A_IO_POWER_DOMAINS ( \
571 BIT_ULL(POWER_DOMAIN_PORT_DDI_A_IO) | \
572 BIT_ULL(POWER_DOMAIN_PORT_DDI_E_IO) | \
573 BIT_ULL(POWER_DOMAIN_INIT))
574#define CNL_DISPLAY_DDI_B_IO_POWER_DOMAINS ( \
575 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_IO) | \
576 BIT_ULL(POWER_DOMAIN_INIT))
577#define CNL_DISPLAY_DDI_C_IO_POWER_DOMAINS ( \
578 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_IO) | \
579 BIT_ULL(POWER_DOMAIN_INIT))
580#define CNL_DISPLAY_DDI_D_IO_POWER_DOMAINS ( \
581 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_IO) | \
582 BIT_ULL(POWER_DOMAIN_INIT))
583#define CNL_DISPLAY_AUX_A_POWER_DOMAINS ( \
584 BIT_ULL(POWER_DOMAIN_AUX_A) | \
585 BIT_ULL(POWER_DOMAIN_INIT))
586#define CNL_DISPLAY_AUX_B_POWER_DOMAINS ( \
587 BIT_ULL(POWER_DOMAIN_AUX_B) | \
588 BIT_ULL(POWER_DOMAIN_INIT))
589#define CNL_DISPLAY_AUX_C_POWER_DOMAINS ( \
590 BIT_ULL(POWER_DOMAIN_AUX_C) | \
591 BIT_ULL(POWER_DOMAIN_INIT))
592#define CNL_DISPLAY_AUX_D_POWER_DOMAINS ( \
593 BIT_ULL(POWER_DOMAIN_AUX_D) | \
594 BIT_ULL(POWER_DOMAIN_INIT))
595#define CNL_DISPLAY_DC_OFF_POWER_DOMAINS ( \
596 CNL_DISPLAY_POWERWELL_2_POWER_DOMAINS | \
597 BIT_ULL(POWER_DOMAIN_MODESET) | \
598 BIT_ULL(POWER_DOMAIN_AUX_A) | \
599 BIT_ULL(POWER_DOMAIN_INIT))
600
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530601static void assert_can_enable_dc9(struct drm_i915_private *dev_priv)
602{
Imre Deakbfcdabe2016-04-01 16:02:37 +0300603 WARN_ONCE((I915_READ(DC_STATE_EN) & DC_STATE_EN_DC9),
604 "DC9 already programmed to be enabled.\n");
605 WARN_ONCE(I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC5,
606 "DC5 still not disabled to enable DC9.\n");
Imre Deake8a3a2a2017-06-29 18:37:00 +0300607 WARN_ONCE(I915_READ(HSW_PWR_WELL_DRIVER) &
608 SKL_POWER_WELL_REQ(SKL_DISP_PW_2),
609 "Power well 2 on.\n");
Imre Deakbfcdabe2016-04-01 16:02:37 +0300610 WARN_ONCE(intel_irqs_enabled(dev_priv),
611 "Interrupts not disabled yet.\n");
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530612
613 /*
614 * TODO: check for the following to verify the conditions to enter DC9
615 * state are satisfied:
616 * 1] Check relevant display engine registers to verify if mode set
617 * disable sequence was followed.
618 * 2] Check if display uninitialize sequence is initialized.
619 */
620}
621
622static void assert_can_disable_dc9(struct drm_i915_private *dev_priv)
623{
Imre Deakbfcdabe2016-04-01 16:02:37 +0300624 WARN_ONCE(intel_irqs_enabled(dev_priv),
625 "Interrupts not disabled yet.\n");
626 WARN_ONCE(I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC5,
627 "DC5 still not disabled.\n");
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530628
629 /*
630 * TODO: check for the following to verify DC9 state was indeed
631 * entered before programming to disable it:
632 * 1] Check relevant display engine registers to verify if mode
633 * set disable sequence was followed.
634 * 2] Check if display uninitialize sequence is initialized.
635 */
636}
637
Mika Kuoppala779cb5d2016-02-18 17:58:09 +0200638static void gen9_write_dc_state(struct drm_i915_private *dev_priv,
639 u32 state)
640{
641 int rewrites = 0;
642 int rereads = 0;
643 u32 v;
644
645 I915_WRITE(DC_STATE_EN, state);
646
647 /* It has been observed that disabling the dc6 state sometimes
648 * doesn't stick and dmc keeps returning old value. Make sure
649 * the write really sticks enough times and also force rewrite until
650 * we are confident that state is exactly what we want.
651 */
652 do {
653 v = I915_READ(DC_STATE_EN);
654
655 if (v != state) {
656 I915_WRITE(DC_STATE_EN, state);
657 rewrites++;
658 rereads = 0;
659 } else if (rereads++ > 5) {
660 break;
661 }
662
663 } while (rewrites < 100);
664
665 if (v != state)
666 DRM_ERROR("Writing dc state to 0x%x failed, now 0x%x\n",
667 state, v);
668
669 /* Most of the times we need one retry, avoid spam */
670 if (rewrites > 1)
671 DRM_DEBUG_KMS("Rewrote dc state to 0x%x %d times\n",
672 state, rewrites);
673}
674
Imre Deakda2f41d2016-04-20 20:27:56 +0300675static u32 gen9_dc_mask(struct drm_i915_private *dev_priv)
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530676{
Imre Deakda2f41d2016-04-20 20:27:56 +0300677 u32 mask;
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530678
Imre Deak13ae3a02015-11-04 19:24:16 +0200679 mask = DC_STATE_EN_UPTO_DC5;
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200680 if (IS_GEN9_LP(dev_priv))
Imre Deak13ae3a02015-11-04 19:24:16 +0200681 mask |= DC_STATE_EN_DC9;
682 else
683 mask |= DC_STATE_EN_UPTO_DC6;
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530684
Imre Deakda2f41d2016-04-20 20:27:56 +0300685 return mask;
686}
687
688void gen9_sanitize_dc_state(struct drm_i915_private *dev_priv)
689{
690 u32 val;
691
692 val = I915_READ(DC_STATE_EN) & gen9_dc_mask(dev_priv);
693
694 DRM_DEBUG_KMS("Resetting DC state tracking from %02x to %02x\n",
695 dev_priv->csr.dc_state, val);
696 dev_priv->csr.dc_state = val;
697}
698
699static void gen9_set_dc_state(struct drm_i915_private *dev_priv, uint32_t state)
700{
701 uint32_t val;
702 uint32_t mask;
703
Imre Deaka37baf32016-02-29 22:49:03 +0200704 if (WARN_ON_ONCE(state & ~dev_priv->csr.allowed_dc_mask))
705 state &= dev_priv->csr.allowed_dc_mask;
Patrik Jakobsson443646c2015-11-16 15:01:06 +0100706
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530707 val = I915_READ(DC_STATE_EN);
Imre Deakda2f41d2016-04-20 20:27:56 +0300708 mask = gen9_dc_mask(dev_priv);
Imre Deak13ae3a02015-11-04 19:24:16 +0200709 DRM_DEBUG_KMS("Setting DC state from %02x to %02x\n",
710 val & mask, state);
Patrik Jakobsson832dba82016-02-18 17:21:11 +0200711
712 /* Check if DMC is ignoring our DC state requests */
713 if ((val & mask) != dev_priv->csr.dc_state)
714 DRM_ERROR("DC state mismatch (0x%x -> 0x%x)\n",
715 dev_priv->csr.dc_state, val & mask);
716
Imre Deak13ae3a02015-11-04 19:24:16 +0200717 val &= ~mask;
718 val |= state;
Mika Kuoppala779cb5d2016-02-18 17:58:09 +0200719
720 gen9_write_dc_state(dev_priv, val);
Patrik Jakobsson832dba82016-02-18 17:21:11 +0200721
722 dev_priv->csr.dc_state = val & mask;
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530723}
724
Imre Deak13ae3a02015-11-04 19:24:16 +0200725void bxt_enable_dc9(struct drm_i915_private *dev_priv)
726{
727 assert_can_enable_dc9(dev_priv);
728
729 DRM_DEBUG_KMS("Enabling DC9\n");
730
Imre Deak78597992016-06-16 16:37:20 +0300731 intel_power_sequencer_reset(dev_priv);
Imre Deak13ae3a02015-11-04 19:24:16 +0200732 gen9_set_dc_state(dev_priv, DC_STATE_EN_DC9);
733}
734
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530735void bxt_disable_dc9(struct drm_i915_private *dev_priv)
736{
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530737 assert_can_disable_dc9(dev_priv);
738
739 DRM_DEBUG_KMS("Disabling DC9\n");
740
Imre Deak13ae3a02015-11-04 19:24:16 +0200741 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
Imre Deak8090ba82016-08-10 14:07:33 +0300742
743 intel_pps_unlock_regs_wa(dev_priv);
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530744}
745
Daniel Vetteraf5fead2015-10-28 23:58:57 +0200746static void assert_csr_loaded(struct drm_i915_private *dev_priv)
747{
748 WARN_ONCE(!I915_READ(CSR_PROGRAM(0)),
749 "CSR program storage start is NULL\n");
750 WARN_ONCE(!I915_READ(CSR_SSP_BASE), "CSR SSP Base Not fine\n");
751 WARN_ONCE(!I915_READ(CSR_HTP_SKL), "CSR HTP Not fine\n");
752}
753
Suketu Shah5aefb232015-04-16 14:22:10 +0530754static void assert_can_enable_dc5(struct drm_i915_private *dev_priv)
Suketu Shahdc174302015-04-17 19:46:16 +0530755{
Suketu Shah5aefb232015-04-16 14:22:10 +0530756 bool pg2_enabled = intel_display_power_well_is_enabled(dev_priv,
757 SKL_DISP_PW_2);
758
Jesse Barnes6ff8ab02015-09-10 08:20:28 -0700759 WARN_ONCE(pg2_enabled, "PG2 not disabled to enable DC5.\n");
Suketu Shah5aefb232015-04-16 14:22:10 +0530760
Jesse Barnes6ff8ab02015-09-10 08:20:28 -0700761 WARN_ONCE((I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC5),
762 "DC5 already programmed to be enabled.\n");
Imre Deakc9b88462015-12-15 20:10:34 +0200763 assert_rpm_wakelock_held(dev_priv);
Suketu Shah5aefb232015-04-16 14:22:10 +0530764
765 assert_csr_loaded(dev_priv);
766}
767
Imre Deakf62c79b2016-04-20 20:27:57 +0300768void gen9_enable_dc5(struct drm_i915_private *dev_priv)
Suketu Shah5aefb232015-04-16 14:22:10 +0530769{
Suketu Shah5aefb232015-04-16 14:22:10 +0530770 assert_can_enable_dc5(dev_priv);
A.Sunil Kamath6b457d32015-04-16 14:22:09 +0530771
772 DRM_DEBUG_KMS("Enabling DC5\n");
773
Imre Deak13ae3a02015-11-04 19:24:16 +0200774 gen9_set_dc_state(dev_priv, DC_STATE_EN_UPTO_DC5);
Suketu Shahdc174302015-04-17 19:46:16 +0530775}
776
Suketu Shah93c7cb62015-04-16 14:22:13 +0530777static void assert_can_enable_dc6(struct drm_i915_private *dev_priv)
Suketu Shahf75a1982015-04-16 14:22:11 +0530778{
Jesse Barnes6ff8ab02015-09-10 08:20:28 -0700779 WARN_ONCE(I915_READ(UTIL_PIN_CTL) & UTIL_PIN_ENABLE,
780 "Backlight is not disabled.\n");
781 WARN_ONCE((I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC6),
782 "DC6 already programmed to be enabled.\n");
Suketu Shah93c7cb62015-04-16 14:22:13 +0530783
784 assert_csr_loaded(dev_priv);
785}
786
Animesh Manna0a9d2be2015-09-29 11:01:59 +0530787void skl_enable_dc6(struct drm_i915_private *dev_priv)
Suketu Shah93c7cb62015-04-16 14:22:13 +0530788{
Suketu Shah93c7cb62015-04-16 14:22:13 +0530789 assert_can_enable_dc6(dev_priv);
A.Sunil Kamath74b4f372015-04-16 14:22:12 +0530790
791 DRM_DEBUG_KMS("Enabling DC6\n");
792
Imre Deak13ae3a02015-11-04 19:24:16 +0200793 gen9_set_dc_state(dev_priv, DC_STATE_EN_UPTO_DC6);
794
Suketu Shahf75a1982015-04-16 14:22:11 +0530795}
796
Animesh Manna0a9d2be2015-09-29 11:01:59 +0530797void skl_disable_dc6(struct drm_i915_private *dev_priv)
Suketu Shahf75a1982015-04-16 14:22:11 +0530798{
A.Sunil Kamath74b4f372015-04-16 14:22:12 +0530799 DRM_DEBUG_KMS("Disabling DC6\n");
800
Imre Deak13ae3a02015-11-04 19:24:16 +0200801 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
Suketu Shahf75a1982015-04-16 14:22:11 +0530802}
803
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000804static void skl_set_power_well(struct drm_i915_private *dev_priv,
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +0200805 struct i915_power_well *power_well, bool enable)
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000806{
807 uint32_t tmp, fuse_status;
808 uint32_t req_mask, state_mask;
Damien Lespiau2a518352015-03-06 18:50:49 +0000809 bool is_enabled, enable_requested, check_fuse_status = false;
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000810
811 tmp = I915_READ(HSW_PWR_WELL_DRIVER);
812 fuse_status = I915_READ(SKL_FUSE_STATUS);
813
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +0300814 switch (power_well->id) {
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000815 case SKL_DISP_PW_1:
Chris Wilson117c1142016-06-30 15:33:33 +0100816 if (intel_wait_for_register(dev_priv,
817 SKL_FUSE_STATUS,
818 SKL_FUSE_PG0_DIST_STATUS,
819 SKL_FUSE_PG0_DIST_STATUS,
820 1)) {
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000821 DRM_ERROR("PG0 not enabled\n");
822 return;
823 }
824 break;
825 case SKL_DISP_PW_2:
826 if (!(fuse_status & SKL_FUSE_PG1_DIST_STATUS)) {
827 DRM_ERROR("PG1 in disabled state\n");
828 return;
829 }
830 break;
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +0200831 case SKL_DISP_PW_MISC_IO:
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -0700832 case SKL_DISP_PW_DDI_A_E: /* GLK_DISP_PW_DDI_A, CNL_DISP_PW_DDI_A */
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000833 case SKL_DISP_PW_DDI_B:
834 case SKL_DISP_PW_DDI_C:
835 case SKL_DISP_PW_DDI_D:
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -0700836 case GLK_DISP_PW_AUX_A: /* CNL_DISP_PW_AUX_A */
837 case GLK_DISP_PW_AUX_B: /* CNL_DISP_PW_AUX_B */
838 case GLK_DISP_PW_AUX_C: /* CNL_DISP_PW_AUX_C */
839 case CNL_DISP_PW_AUX_D:
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000840 break;
841 default:
Imre Deak438b8dc2017-07-11 23:42:30 +0300842 WARN(1, "Unknown power well %u\n", power_well->id);
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000843 return;
844 }
845
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +0300846 req_mask = SKL_POWER_WELL_REQ(power_well->id);
Damien Lespiau2a518352015-03-06 18:50:49 +0000847 enable_requested = tmp & req_mask;
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +0300848 state_mask = SKL_POWER_WELL_STATE(power_well->id);
Damien Lespiau2a518352015-03-06 18:50:49 +0000849 is_enabled = tmp & state_mask;
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000850
Ville Syrjäläaae8ba82016-02-19 20:47:30 +0200851 if (!enable && enable_requested)
852 skl_power_well_pre_disable(dev_priv, power_well);
853
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000854 if (enable) {
Damien Lespiau2a518352015-03-06 18:50:49 +0000855 if (!enable_requested) {
Suketu Shahdc174302015-04-17 19:46:16 +0530856 WARN((tmp & state_mask) &&
857 !I915_READ(HSW_PWR_WELL_BIOS),
858 "Invalid for power well status to be enabled, unless done by the BIOS, \
859 when request is to disable!\n");
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000860 I915_WRITE(HSW_PWR_WELL_DRIVER, tmp | req_mask);
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000861 }
862
Damien Lespiau2a518352015-03-06 18:50:49 +0000863 if (!is_enabled) {
Damien Lespiau510e6fd2015-03-06 18:50:50 +0000864 DRM_DEBUG_KMS("Enabling %s\n", power_well->name);
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000865 check_fuse_status = true;
866 }
Imre Deak42d93662017-06-29 18:37:01 +0300867
868 gen9_wait_for_power_well_enable(dev_priv, power_well);
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000869 } else {
Damien Lespiau2a518352015-03-06 18:50:49 +0000870 if (enable_requested) {
Imre Deak4a76f292015-11-04 19:24:15 +0200871 I915_WRITE(HSW_PWR_WELL_DRIVER, tmp & ~req_mask);
872 POSTING_READ(HSW_PWR_WELL_DRIVER);
873 DRM_DEBUG_KMS("Disabling %s\n", power_well->name);
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000874 }
Imre Deakc6782b72016-04-05 13:26:05 +0300875
Imre Deak42d93662017-06-29 18:37:01 +0300876 gen9_wait_for_power_well_disable(dev_priv, power_well);
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000877 }
878
879 if (check_fuse_status) {
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +0300880 if (power_well->id == SKL_DISP_PW_1) {
Chris Wilson8b00f552016-06-30 15:33:34 +0100881 if (intel_wait_for_register(dev_priv,
882 SKL_FUSE_STATUS,
883 SKL_FUSE_PG1_DIST_STATUS,
884 SKL_FUSE_PG1_DIST_STATUS,
885 1))
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000886 DRM_ERROR("PG1 distributing status timeout\n");
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +0300887 } else if (power_well->id == SKL_DISP_PW_2) {
Chris Wilson8b00f552016-06-30 15:33:34 +0100888 if (intel_wait_for_register(dev_priv,
889 SKL_FUSE_STATUS,
890 SKL_FUSE_PG2_DIST_STATUS,
891 SKL_FUSE_PG2_DIST_STATUS,
892 1))
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000893 DRM_ERROR("PG2 distributing status timeout\n");
894 }
895 }
Damien Lespiaud14c0342015-03-06 18:50:51 +0000896
897 if (enable && !is_enabled)
898 skl_power_well_post_enable(dev_priv, power_well);
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000899}
900
Daniel Vetter9c065a72014-09-30 10:56:38 +0200901static void hsw_power_well_sync_hw(struct drm_i915_private *dev_priv,
902 struct i915_power_well *power_well)
903{
Imre Deak16e84912017-02-17 17:39:45 +0200904 /* Take over the request bit if set by BIOS. */
905 if (I915_READ(HSW_PWR_WELL_BIOS) & HSW_PWR_WELL_ENABLE_REQUEST) {
906 if (!(I915_READ(HSW_PWR_WELL_DRIVER) &
907 HSW_PWR_WELL_ENABLE_REQUEST))
908 I915_WRITE(HSW_PWR_WELL_DRIVER,
909 HSW_PWR_WELL_ENABLE_REQUEST);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200910 I915_WRITE(HSW_PWR_WELL_BIOS, 0);
Imre Deak16e84912017-02-17 17:39:45 +0200911 }
Daniel Vetter9c065a72014-09-30 10:56:38 +0200912}
913
914static void hsw_power_well_enable(struct drm_i915_private *dev_priv,
915 struct i915_power_well *power_well)
916{
917 hsw_set_power_well(dev_priv, power_well, true);
918}
919
920static void hsw_power_well_disable(struct drm_i915_private *dev_priv,
921 struct i915_power_well *power_well)
922{
923 hsw_set_power_well(dev_priv, power_well, false);
924}
925
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000926static bool skl_power_well_enabled(struct drm_i915_private *dev_priv,
927 struct i915_power_well *power_well)
928{
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +0300929 uint32_t mask = SKL_POWER_WELL_REQ(power_well->id) |
930 SKL_POWER_WELL_STATE(power_well->id);
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000931
932 return (I915_READ(HSW_PWR_WELL_DRIVER) & mask) == mask;
933}
934
935static void skl_power_well_sync_hw(struct drm_i915_private *dev_priv,
936 struct i915_power_well *power_well)
937{
Imre Deak14544e12017-02-17 17:39:44 +0200938 uint32_t mask = SKL_POWER_WELL_REQ(power_well->id);
939 uint32_t bios_req = I915_READ(HSW_PWR_WELL_BIOS);
940
Imre Deak16e84912017-02-17 17:39:45 +0200941 /* Take over the request bit if set by BIOS. */
Imre Deak14544e12017-02-17 17:39:44 +0200942 if (bios_req & mask) {
Imre Deak16e84912017-02-17 17:39:45 +0200943 uint32_t drv_req = I915_READ(HSW_PWR_WELL_DRIVER);
944
945 if (!(drv_req & mask))
946 I915_WRITE(HSW_PWR_WELL_DRIVER, drv_req | mask);
Imre Deak14544e12017-02-17 17:39:44 +0200947 I915_WRITE(HSW_PWR_WELL_BIOS, bios_req & ~mask);
948 }
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000949}
950
951static void skl_power_well_enable(struct drm_i915_private *dev_priv,
952 struct i915_power_well *power_well)
953{
954 skl_set_power_well(dev_priv, power_well, true);
955}
956
957static void skl_power_well_disable(struct drm_i915_private *dev_priv,
958 struct i915_power_well *power_well)
959{
960 skl_set_power_well(dev_priv, power_well, false);
961}
962
Imre Deak9c8d0b82016-06-13 16:44:34 +0300963static void bxt_dpio_cmn_power_well_enable(struct drm_i915_private *dev_priv,
964 struct i915_power_well *power_well)
965{
Ander Conselvan de Oliveira362624c2016-10-06 19:22:15 +0300966 bxt_ddi_phy_init(dev_priv, power_well->data);
Imre Deak9c8d0b82016-06-13 16:44:34 +0300967}
968
969static void bxt_dpio_cmn_power_well_disable(struct drm_i915_private *dev_priv,
970 struct i915_power_well *power_well)
971{
Ander Conselvan de Oliveira362624c2016-10-06 19:22:15 +0300972 bxt_ddi_phy_uninit(dev_priv, power_well->data);
Imre Deak9c8d0b82016-06-13 16:44:34 +0300973}
974
975static bool bxt_dpio_cmn_power_well_enabled(struct drm_i915_private *dev_priv,
976 struct i915_power_well *power_well)
977{
Ander Conselvan de Oliveira362624c2016-10-06 19:22:15 +0300978 return bxt_ddi_phy_is_enabled(dev_priv, power_well->data);
Imre Deak9c8d0b82016-06-13 16:44:34 +0300979}
980
Imre Deak9c8d0b82016-06-13 16:44:34 +0300981static void bxt_verify_ddi_phy_power_wells(struct drm_i915_private *dev_priv)
982{
983 struct i915_power_well *power_well;
984
985 power_well = lookup_power_well(dev_priv, BXT_DPIO_CMN_A);
986 if (power_well->count > 0)
Ander Conselvan de Oliveira362624c2016-10-06 19:22:15 +0300987 bxt_ddi_phy_verify_state(dev_priv, power_well->data);
Imre Deak9c8d0b82016-06-13 16:44:34 +0300988
989 power_well = lookup_power_well(dev_priv, BXT_DPIO_CMN_BC);
990 if (power_well->count > 0)
Ander Conselvan de Oliveira362624c2016-10-06 19:22:15 +0300991 bxt_ddi_phy_verify_state(dev_priv, power_well->data);
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +0200992
993 if (IS_GEMINILAKE(dev_priv)) {
994 power_well = lookup_power_well(dev_priv, GLK_DPIO_CMN_C);
995 if (power_well->count > 0)
996 bxt_ddi_phy_verify_state(dev_priv, power_well->data);
997 }
Imre Deak9c8d0b82016-06-13 16:44:34 +0300998}
999
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01001000static bool gen9_dc_off_power_well_enabled(struct drm_i915_private *dev_priv,
1001 struct i915_power_well *power_well)
1002{
1003 return (I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC5_DC6_MASK) == 0;
1004}
1005
Ville Syrjälä18a80672016-05-16 16:59:40 +03001006static void gen9_assert_dbuf_enabled(struct drm_i915_private *dev_priv)
1007{
1008 u32 tmp = I915_READ(DBUF_CTL);
1009
1010 WARN((tmp & (DBUF_POWER_STATE | DBUF_POWER_REQUEST)) !=
1011 (DBUF_POWER_STATE | DBUF_POWER_REQUEST),
1012 "Unexpected DBuf power power state (0x%08x)\n", tmp);
1013}
1014
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01001015static void gen9_dc_off_power_well_enable(struct drm_i915_private *dev_priv,
1016 struct i915_power_well *power_well)
1017{
Ville Syrjälä49cd97a2017-02-07 20:33:45 +02001018 struct intel_cdclk_state cdclk_state = {};
1019
Imre Deak5b773eb2016-02-29 22:49:05 +02001020 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
Imre Deakadc7f042016-04-04 17:27:10 +03001021
Ville Syrjälä49cd97a2017-02-07 20:33:45 +02001022 dev_priv->display.get_cdclk(dev_priv, &cdclk_state);
1023 WARN_ON(!intel_cdclk_state_compare(&dev_priv->cdclk.hw, &cdclk_state));
Ville Syrjälä342be922016-05-13 23:41:39 +03001024
Ville Syrjälä18a80672016-05-16 16:59:40 +03001025 gen9_assert_dbuf_enabled(dev_priv);
1026
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02001027 if (IS_GEN9_LP(dev_priv))
Imre Deak9c8d0b82016-06-13 16:44:34 +03001028 bxt_verify_ddi_phy_power_wells(dev_priv);
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01001029}
1030
1031static void gen9_dc_off_power_well_disable(struct drm_i915_private *dev_priv,
1032 struct i915_power_well *power_well)
1033{
Imre Deakf74ed082016-04-18 14:48:21 +03001034 if (!dev_priv->csr.dmc_payload)
1035 return;
1036
Imre Deaka37baf32016-02-29 22:49:03 +02001037 if (dev_priv->csr.allowed_dc_mask & DC_STATE_EN_UPTO_DC6)
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01001038 skl_enable_dc6(dev_priv);
Imre Deaka37baf32016-02-29 22:49:03 +02001039 else if (dev_priv->csr.allowed_dc_mask & DC_STATE_EN_UPTO_DC5)
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01001040 gen9_enable_dc5(dev_priv);
1041}
1042
Imre Deak3c1b38e2017-02-17 17:39:42 +02001043static void i9xx_power_well_sync_hw_noop(struct drm_i915_private *dev_priv,
1044 struct i915_power_well *power_well)
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01001045{
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01001046}
1047
Daniel Vetter9c065a72014-09-30 10:56:38 +02001048static void i9xx_always_on_power_well_noop(struct drm_i915_private *dev_priv,
1049 struct i915_power_well *power_well)
1050{
1051}
1052
1053static bool i9xx_always_on_power_well_enabled(struct drm_i915_private *dev_priv,
1054 struct i915_power_well *power_well)
1055{
1056 return true;
1057}
1058
Ville Syrjälä2ee0da12017-06-01 17:36:16 +03001059static void i830_pipes_power_well_enable(struct drm_i915_private *dev_priv,
1060 struct i915_power_well *power_well)
1061{
1062 if ((I915_READ(PIPECONF(PIPE_A)) & PIPECONF_ENABLE) == 0)
1063 i830_enable_pipe(dev_priv, PIPE_A);
1064 if ((I915_READ(PIPECONF(PIPE_B)) & PIPECONF_ENABLE) == 0)
1065 i830_enable_pipe(dev_priv, PIPE_B);
1066}
1067
1068static void i830_pipes_power_well_disable(struct drm_i915_private *dev_priv,
1069 struct i915_power_well *power_well)
1070{
1071 i830_disable_pipe(dev_priv, PIPE_B);
1072 i830_disable_pipe(dev_priv, PIPE_A);
1073}
1074
1075static bool i830_pipes_power_well_enabled(struct drm_i915_private *dev_priv,
1076 struct i915_power_well *power_well)
1077{
1078 return I915_READ(PIPECONF(PIPE_A)) & PIPECONF_ENABLE &&
1079 I915_READ(PIPECONF(PIPE_B)) & PIPECONF_ENABLE;
1080}
1081
1082static void i830_pipes_power_well_sync_hw(struct drm_i915_private *dev_priv,
1083 struct i915_power_well *power_well)
1084{
1085 if (power_well->count > 0)
1086 i830_pipes_power_well_enable(dev_priv, power_well);
1087 else
1088 i830_pipes_power_well_disable(dev_priv, power_well);
1089}
1090
Daniel Vetter9c065a72014-09-30 10:56:38 +02001091static void vlv_set_power_well(struct drm_i915_private *dev_priv,
1092 struct i915_power_well *power_well, bool enable)
1093{
Imre Deak438b8dc2017-07-11 23:42:30 +03001094 enum i915_power_well_id power_well_id = power_well->id;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001095 u32 mask;
1096 u32 state;
1097 u32 ctrl;
1098
1099 mask = PUNIT_PWRGT_MASK(power_well_id);
1100 state = enable ? PUNIT_PWRGT_PWR_ON(power_well_id) :
1101 PUNIT_PWRGT_PWR_GATE(power_well_id);
1102
1103 mutex_lock(&dev_priv->rps.hw_lock);
1104
1105#define COND \
1106 ((vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_STATUS) & mask) == state)
1107
1108 if (COND)
1109 goto out;
1110
1111 ctrl = vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_CTRL);
1112 ctrl &= ~mask;
1113 ctrl |= state;
1114 vlv_punit_write(dev_priv, PUNIT_REG_PWRGT_CTRL, ctrl);
1115
1116 if (wait_for(COND, 100))
Masanari Iida7e35ab82015-05-10 01:00:23 +09001117 DRM_ERROR("timeout setting power well state %08x (%08x)\n",
Daniel Vetter9c065a72014-09-30 10:56:38 +02001118 state,
1119 vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_CTRL));
1120
1121#undef COND
1122
1123out:
1124 mutex_unlock(&dev_priv->rps.hw_lock);
1125}
1126
Daniel Vetter9c065a72014-09-30 10:56:38 +02001127static void vlv_power_well_enable(struct drm_i915_private *dev_priv,
1128 struct i915_power_well *power_well)
1129{
1130 vlv_set_power_well(dev_priv, power_well, true);
1131}
1132
1133static void vlv_power_well_disable(struct drm_i915_private *dev_priv,
1134 struct i915_power_well *power_well)
1135{
1136 vlv_set_power_well(dev_priv, power_well, false);
1137}
1138
1139static bool vlv_power_well_enabled(struct drm_i915_private *dev_priv,
1140 struct i915_power_well *power_well)
1141{
Imre Deak438b8dc2017-07-11 23:42:30 +03001142 enum i915_power_well_id power_well_id = power_well->id;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001143 bool enabled = false;
1144 u32 mask;
1145 u32 state;
1146 u32 ctrl;
1147
1148 mask = PUNIT_PWRGT_MASK(power_well_id);
1149 ctrl = PUNIT_PWRGT_PWR_ON(power_well_id);
1150
1151 mutex_lock(&dev_priv->rps.hw_lock);
1152
1153 state = vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_STATUS) & mask;
1154 /*
1155 * We only ever set the power-on and power-gate states, anything
1156 * else is unexpected.
1157 */
1158 WARN_ON(state != PUNIT_PWRGT_PWR_ON(power_well_id) &&
1159 state != PUNIT_PWRGT_PWR_GATE(power_well_id));
1160 if (state == ctrl)
1161 enabled = true;
1162
1163 /*
1164 * A transient state at this point would mean some unexpected party
1165 * is poking at the power controls too.
1166 */
1167 ctrl = vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_CTRL) & mask;
1168 WARN_ON(ctrl != state);
1169
1170 mutex_unlock(&dev_priv->rps.hw_lock);
1171
1172 return enabled;
1173}
1174
Ville Syrjälä766078d2016-04-11 16:56:30 +03001175static void vlv_init_display_clock_gating(struct drm_i915_private *dev_priv)
1176{
Hans de Goede721d4842016-12-02 15:29:04 +01001177 u32 val;
1178
1179 /*
1180 * On driver load, a pipe may be active and driving a DSI display.
1181 * Preserve DPOUNIT_CLOCK_GATE_DISABLE to avoid the pipe getting stuck
1182 * (and never recovering) in this case. intel_dsi_post_disable() will
1183 * clear it when we turn off the display.
1184 */
1185 val = I915_READ(DSPCLK_GATE_D);
1186 val &= DPOUNIT_CLOCK_GATE_DISABLE;
1187 val |= VRHUNIT_CLOCK_GATE_DISABLE;
1188 I915_WRITE(DSPCLK_GATE_D, val);
Ville Syrjälä766078d2016-04-11 16:56:30 +03001189
1190 /*
1191 * Disable trickle feed and enable pnd deadline calculation
1192 */
1193 I915_WRITE(MI_ARB_VLV, MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE);
1194 I915_WRITE(CBR1_VLV, 0);
Ville Syrjälä19ab4ed2016-04-27 17:43:22 +03001195
1196 WARN_ON(dev_priv->rawclk_freq == 0);
1197
1198 I915_WRITE(RAWCLK_FREQ_VLV,
1199 DIV_ROUND_CLOSEST(dev_priv->rawclk_freq, 1000));
Ville Syrjälä766078d2016-04-11 16:56:30 +03001200}
1201
Ville Syrjälä2be7d542015-06-29 15:25:51 +03001202static void vlv_display_power_well_init(struct drm_i915_private *dev_priv)
Daniel Vetter9c065a72014-09-30 10:56:38 +02001203{
Lyude9504a892016-06-21 17:03:42 -04001204 struct intel_encoder *encoder;
Ville Syrjälä5a8fbb72015-06-29 15:25:53 +03001205 enum pipe pipe;
1206
1207 /*
1208 * Enable the CRI clock source so we can get at the
1209 * display and the reference clock for VGA
1210 * hotplug / manual detection. Supposedly DSI also
1211 * needs the ref clock up and running.
1212 *
1213 * CHV DPLL B/C have some issues if VGA mode is enabled.
1214 */
Tvrtko Ursulin801388c2016-11-16 08:55:44 +00001215 for_each_pipe(dev_priv, pipe) {
Ville Syrjälä5a8fbb72015-06-29 15:25:53 +03001216 u32 val = I915_READ(DPLL(pipe));
1217
1218 val |= DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
1219 if (pipe != PIPE_A)
1220 val |= DPLL_INTEGRATED_CRI_CLK_VLV;
1221
1222 I915_WRITE(DPLL(pipe), val);
1223 }
Daniel Vetter9c065a72014-09-30 10:56:38 +02001224
Ville Syrjälä766078d2016-04-11 16:56:30 +03001225 vlv_init_display_clock_gating(dev_priv);
1226
Daniel Vetter9c065a72014-09-30 10:56:38 +02001227 spin_lock_irq(&dev_priv->irq_lock);
1228 valleyview_enable_display_irqs(dev_priv);
1229 spin_unlock_irq(&dev_priv->irq_lock);
1230
1231 /*
1232 * During driver initialization/resume we can avoid restoring the
1233 * part of the HW/SW state that will be inited anyway explicitly.
1234 */
1235 if (dev_priv->power_domains.initializing)
1236 return;
1237
Daniel Vetterb9632912014-09-30 10:56:44 +02001238 intel_hpd_init(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001239
Lyude9504a892016-06-21 17:03:42 -04001240 /* Re-enable the ADPA, if we have one */
1241 for_each_intel_encoder(&dev_priv->drm, encoder) {
1242 if (encoder->type == INTEL_OUTPUT_ANALOG)
1243 intel_crt_reset(&encoder->base);
1244 }
1245
Tvrtko Ursulin29b74b72016-11-16 08:55:39 +00001246 i915_redisable_vga_power_on(dev_priv);
Imre Deak8090ba82016-08-10 14:07:33 +03001247
1248 intel_pps_unlock_regs_wa(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001249}
1250
Ville Syrjälä2be7d542015-06-29 15:25:51 +03001251static void vlv_display_power_well_deinit(struct drm_i915_private *dev_priv)
1252{
1253 spin_lock_irq(&dev_priv->irq_lock);
1254 valleyview_disable_display_irqs(dev_priv);
1255 spin_unlock_irq(&dev_priv->irq_lock);
1256
Ville Syrjälä2230fde2016-02-19 18:41:52 +02001257 /* make sure we're done processing display irqs */
Chris Wilson91c8a322016-07-05 10:40:23 +01001258 synchronize_irq(dev_priv->drm.irq);
Ville Syrjälä2230fde2016-02-19 18:41:52 +02001259
Imre Deak78597992016-06-16 16:37:20 +03001260 intel_power_sequencer_reset(dev_priv);
Lyude19625e82016-06-21 17:03:44 -04001261
Lyudeb64b5402016-10-26 12:36:09 -04001262 /* Prevent us from re-enabling polling on accident in late suspend */
1263 if (!dev_priv->drm.dev->power.is_suspended)
1264 intel_hpd_poll_init(dev_priv);
Ville Syrjälä2be7d542015-06-29 15:25:51 +03001265}
1266
1267static void vlv_display_power_well_enable(struct drm_i915_private *dev_priv,
1268 struct i915_power_well *power_well)
1269{
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001270 WARN_ON_ONCE(power_well->id != PUNIT_POWER_WELL_DISP2D);
Ville Syrjälä2be7d542015-06-29 15:25:51 +03001271
1272 vlv_set_power_well(dev_priv, power_well, true);
1273
1274 vlv_display_power_well_init(dev_priv);
1275}
1276
Daniel Vetter9c065a72014-09-30 10:56:38 +02001277static void vlv_display_power_well_disable(struct drm_i915_private *dev_priv,
1278 struct i915_power_well *power_well)
1279{
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001280 WARN_ON_ONCE(power_well->id != PUNIT_POWER_WELL_DISP2D);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001281
Ville Syrjälä2be7d542015-06-29 15:25:51 +03001282 vlv_display_power_well_deinit(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001283
1284 vlv_set_power_well(dev_priv, power_well, false);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001285}
1286
1287static void vlv_dpio_cmn_power_well_enable(struct drm_i915_private *dev_priv,
1288 struct i915_power_well *power_well)
1289{
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001290 WARN_ON_ONCE(power_well->id != PUNIT_POWER_WELL_DPIO_CMN_BC);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001291
Ville Syrjälä5a8fbb72015-06-29 15:25:53 +03001292 /* since ref/cri clock was enabled */
Daniel Vetter9c065a72014-09-30 10:56:38 +02001293 udelay(1); /* >10ns for cmnreset, >0ns for sidereset */
1294
1295 vlv_set_power_well(dev_priv, power_well, true);
1296
1297 /*
1298 * From VLV2A0_DP_eDP_DPIO_driver_vbios_notes_10.docx -
1299 * 6. De-assert cmn_reset/side_reset. Same as VLV X0.
1300 * a. GUnit 0x2110 bit[0] set to 1 (def 0)
1301 * b. The other bits such as sfr settings / modesel may all
1302 * be set to 0.
1303 *
1304 * This should only be done on init and resume from S3 with
1305 * both PLLs disabled, or we risk losing DPIO and PLL
1306 * synchronization.
1307 */
1308 I915_WRITE(DPIO_CTL, I915_READ(DPIO_CTL) | DPIO_CMNRST);
1309}
1310
1311static void vlv_dpio_cmn_power_well_disable(struct drm_i915_private *dev_priv,
1312 struct i915_power_well *power_well)
1313{
1314 enum pipe pipe;
1315
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001316 WARN_ON_ONCE(power_well->id != PUNIT_POWER_WELL_DPIO_CMN_BC);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001317
1318 for_each_pipe(dev_priv, pipe)
1319 assert_pll_disabled(dev_priv, pipe);
1320
1321 /* Assert common reset */
1322 I915_WRITE(DPIO_CTL, I915_READ(DPIO_CTL) & ~DPIO_CMNRST);
1323
1324 vlv_set_power_well(dev_priv, power_well, false);
1325}
1326
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001327#define POWER_DOMAIN_MASK (GENMASK_ULL(POWER_DOMAIN_NUM - 1, 0))
Ville Syrjälä30142272015-07-08 23:46:01 +03001328
Imre Deak438b8dc2017-07-11 23:42:30 +03001329static struct i915_power_well *
1330lookup_power_well(struct drm_i915_private *dev_priv,
1331 enum i915_power_well_id power_well_id)
Ville Syrjälä30142272015-07-08 23:46:01 +03001332{
1333 struct i915_power_domains *power_domains = &dev_priv->power_domains;
Ville Syrjälä30142272015-07-08 23:46:01 +03001334 int i;
1335
Imre Deakfc17f222015-11-04 19:24:11 +02001336 for (i = 0; i < power_domains->power_well_count; i++) {
1337 struct i915_power_well *power_well;
1338
1339 power_well = &power_domains->power_wells[i];
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001340 if (power_well->id == power_well_id)
Ville Syrjälä30142272015-07-08 23:46:01 +03001341 return power_well;
1342 }
1343
1344 return NULL;
1345}
1346
1347#define BITS_SET(val, bits) (((val) & (bits)) == (bits))
1348
1349static void assert_chv_phy_status(struct drm_i915_private *dev_priv)
1350{
1351 struct i915_power_well *cmn_bc =
1352 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_BC);
1353 struct i915_power_well *cmn_d =
1354 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_D);
1355 u32 phy_control = dev_priv->chv_phy_control;
1356 u32 phy_status = 0;
Ville Syrjälä3be60de2015-09-08 18:05:45 +03001357 u32 phy_status_mask = 0xffffffff;
Ville Syrjälä30142272015-07-08 23:46:01 +03001358
Ville Syrjälä3be60de2015-09-08 18:05:45 +03001359 /*
1360 * The BIOS can leave the PHY is some weird state
1361 * where it doesn't fully power down some parts.
1362 * Disable the asserts until the PHY has been fully
1363 * reset (ie. the power well has been disabled at
1364 * least once).
1365 */
1366 if (!dev_priv->chv_phy_assert[DPIO_PHY0])
1367 phy_status_mask &= ~(PHY_STATUS_CMN_LDO(DPIO_PHY0, DPIO_CH0) |
1368 PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH0, 0) |
1369 PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH0, 1) |
1370 PHY_STATUS_CMN_LDO(DPIO_PHY0, DPIO_CH1) |
1371 PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH1, 0) |
1372 PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH1, 1));
1373
1374 if (!dev_priv->chv_phy_assert[DPIO_PHY1])
1375 phy_status_mask &= ~(PHY_STATUS_CMN_LDO(DPIO_PHY1, DPIO_CH0) |
1376 PHY_STATUS_SPLINE_LDO(DPIO_PHY1, DPIO_CH0, 0) |
1377 PHY_STATUS_SPLINE_LDO(DPIO_PHY1, DPIO_CH0, 1));
1378
Ville Syrjälä30142272015-07-08 23:46:01 +03001379 if (cmn_bc->ops->is_enabled(dev_priv, cmn_bc)) {
1380 phy_status |= PHY_POWERGOOD(DPIO_PHY0);
1381
1382 /* this assumes override is only used to enable lanes */
1383 if ((phy_control & PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY0, DPIO_CH0)) == 0)
1384 phy_control |= PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH0);
1385
1386 if ((phy_control & PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY0, DPIO_CH1)) == 0)
1387 phy_control |= PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH1);
1388
1389 /* CL1 is on whenever anything is on in either channel */
1390 if (BITS_SET(phy_control,
1391 PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH0) |
1392 PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH1)))
1393 phy_status |= PHY_STATUS_CMN_LDO(DPIO_PHY0, DPIO_CH0);
1394
1395 /*
1396 * The DPLLB check accounts for the pipe B + port A usage
1397 * with CL2 powered up but all the lanes in the second channel
1398 * powered down.
1399 */
1400 if (BITS_SET(phy_control,
1401 PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH1)) &&
1402 (I915_READ(DPLL(PIPE_B)) & DPLL_VCO_ENABLE) == 0)
1403 phy_status |= PHY_STATUS_CMN_LDO(DPIO_PHY0, DPIO_CH1);
1404
1405 if (BITS_SET(phy_control,
1406 PHY_CH_POWER_DOWN_OVRD(0x3, DPIO_PHY0, DPIO_CH0)))
1407 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH0, 0);
1408 if (BITS_SET(phy_control,
1409 PHY_CH_POWER_DOWN_OVRD(0xc, DPIO_PHY0, DPIO_CH0)))
1410 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH0, 1);
1411
1412 if (BITS_SET(phy_control,
1413 PHY_CH_POWER_DOWN_OVRD(0x3, DPIO_PHY0, DPIO_CH1)))
1414 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH1, 0);
1415 if (BITS_SET(phy_control,
1416 PHY_CH_POWER_DOWN_OVRD(0xc, DPIO_PHY0, DPIO_CH1)))
1417 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH1, 1);
1418 }
1419
1420 if (cmn_d->ops->is_enabled(dev_priv, cmn_d)) {
1421 phy_status |= PHY_POWERGOOD(DPIO_PHY1);
1422
1423 /* this assumes override is only used to enable lanes */
1424 if ((phy_control & PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY1, DPIO_CH0)) == 0)
1425 phy_control |= PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY1, DPIO_CH0);
1426
1427 if (BITS_SET(phy_control,
1428 PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY1, DPIO_CH0)))
1429 phy_status |= PHY_STATUS_CMN_LDO(DPIO_PHY1, DPIO_CH0);
1430
1431 if (BITS_SET(phy_control,
1432 PHY_CH_POWER_DOWN_OVRD(0x3, DPIO_PHY1, DPIO_CH0)))
1433 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY1, DPIO_CH0, 0);
1434 if (BITS_SET(phy_control,
1435 PHY_CH_POWER_DOWN_OVRD(0xc, DPIO_PHY1, DPIO_CH0)))
1436 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY1, DPIO_CH0, 1);
1437 }
1438
Ville Syrjälä3be60de2015-09-08 18:05:45 +03001439 phy_status &= phy_status_mask;
1440
Ville Syrjälä30142272015-07-08 23:46:01 +03001441 /*
1442 * The PHY may be busy with some initial calibration and whatnot,
1443 * so the power state can take a while to actually change.
1444 */
Chris Wilson919fcd52016-06-30 15:33:35 +01001445 if (intel_wait_for_register(dev_priv,
1446 DISPLAY_PHY_STATUS,
1447 phy_status_mask,
1448 phy_status,
1449 10))
1450 DRM_ERROR("Unexpected PHY_STATUS 0x%08x, expected 0x%08x (PHY_CONTROL=0x%08x)\n",
1451 I915_READ(DISPLAY_PHY_STATUS) & phy_status_mask,
1452 phy_status, dev_priv->chv_phy_control);
Ville Syrjälä30142272015-07-08 23:46:01 +03001453}
1454
1455#undef BITS_SET
1456
Daniel Vetter9c065a72014-09-30 10:56:38 +02001457static void chv_dpio_cmn_power_well_enable(struct drm_i915_private *dev_priv,
1458 struct i915_power_well *power_well)
1459{
1460 enum dpio_phy phy;
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001461 enum pipe pipe;
1462 uint32_t tmp;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001463
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001464 WARN_ON_ONCE(power_well->id != PUNIT_POWER_WELL_DPIO_CMN_BC &&
1465 power_well->id != PUNIT_POWER_WELL_DPIO_CMN_D);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001466
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001467 if (power_well->id == PUNIT_POWER_WELL_DPIO_CMN_BC) {
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001468 pipe = PIPE_A;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001469 phy = DPIO_PHY0;
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001470 } else {
1471 pipe = PIPE_C;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001472 phy = DPIO_PHY1;
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001473 }
Ville Syrjälä5a8fbb72015-06-29 15:25:53 +03001474
1475 /* since ref/cri clock was enabled */
Daniel Vetter9c065a72014-09-30 10:56:38 +02001476 udelay(1); /* >10ns for cmnreset, >0ns for sidereset */
1477 vlv_set_power_well(dev_priv, power_well, true);
1478
1479 /* Poll for phypwrgood signal */
Chris Wilsonffebb832016-06-30 15:33:36 +01001480 if (intel_wait_for_register(dev_priv,
1481 DISPLAY_PHY_STATUS,
1482 PHY_POWERGOOD(phy),
1483 PHY_POWERGOOD(phy),
1484 1))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001485 DRM_ERROR("Display PHY %d is not power up\n", phy);
1486
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001487 mutex_lock(&dev_priv->sb_lock);
1488
1489 /* Enable dynamic power down */
1490 tmp = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW28);
Ville Syrjäläee279212015-07-08 23:45:57 +03001491 tmp |= DPIO_DYNPWRDOWNEN_CH0 | DPIO_CL1POWERDOWNEN |
1492 DPIO_SUS_CLK_CONFIG_GATE_CLKREQ;
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001493 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW28, tmp);
1494
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001495 if (power_well->id == PUNIT_POWER_WELL_DPIO_CMN_BC) {
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001496 tmp = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW6_CH1);
1497 tmp |= DPIO_DYNPWRDOWNEN_CH1;
1498 vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW6_CH1, tmp);
Ville Syrjälä3e288782015-07-08 23:45:58 +03001499 } else {
1500 /*
1501 * Force the non-existing CL2 off. BXT does this
1502 * too, so maybe it saves some power even though
1503 * CL2 doesn't exist?
1504 */
1505 tmp = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW30);
1506 tmp |= DPIO_CL2_LDOFUSE_PWRENB;
1507 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW30, tmp);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001508 }
1509
1510 mutex_unlock(&dev_priv->sb_lock);
1511
Ville Syrjälä70722462015-04-10 18:21:28 +03001512 dev_priv->chv_phy_control |= PHY_COM_LANE_RESET_DEASSERT(phy);
1513 I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001514
1515 DRM_DEBUG_KMS("Enabled DPIO PHY%d (PHY_CONTROL=0x%08x)\n",
1516 phy, dev_priv->chv_phy_control);
Ville Syrjälä30142272015-07-08 23:46:01 +03001517
1518 assert_chv_phy_status(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001519}
1520
1521static void chv_dpio_cmn_power_well_disable(struct drm_i915_private *dev_priv,
1522 struct i915_power_well *power_well)
1523{
1524 enum dpio_phy phy;
1525
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001526 WARN_ON_ONCE(power_well->id != PUNIT_POWER_WELL_DPIO_CMN_BC &&
1527 power_well->id != PUNIT_POWER_WELL_DPIO_CMN_D);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001528
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001529 if (power_well->id == PUNIT_POWER_WELL_DPIO_CMN_BC) {
Daniel Vetter9c065a72014-09-30 10:56:38 +02001530 phy = DPIO_PHY0;
1531 assert_pll_disabled(dev_priv, PIPE_A);
1532 assert_pll_disabled(dev_priv, PIPE_B);
1533 } else {
1534 phy = DPIO_PHY1;
1535 assert_pll_disabled(dev_priv, PIPE_C);
1536 }
1537
Ville Syrjälä70722462015-04-10 18:21:28 +03001538 dev_priv->chv_phy_control &= ~PHY_COM_LANE_RESET_DEASSERT(phy);
1539 I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001540
1541 vlv_set_power_well(dev_priv, power_well, false);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001542
1543 DRM_DEBUG_KMS("Disabled DPIO PHY%d (PHY_CONTROL=0x%08x)\n",
1544 phy, dev_priv->chv_phy_control);
Ville Syrjälä30142272015-07-08 23:46:01 +03001545
Ville Syrjälä3be60de2015-09-08 18:05:45 +03001546 /* PHY is fully reset now, so we can enable the PHY state asserts */
1547 dev_priv->chv_phy_assert[phy] = true;
1548
Ville Syrjälä30142272015-07-08 23:46:01 +03001549 assert_chv_phy_status(dev_priv);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001550}
1551
Ville Syrjälä6669e392015-07-08 23:46:00 +03001552static void assert_chv_phy_powergate(struct drm_i915_private *dev_priv, enum dpio_phy phy,
1553 enum dpio_channel ch, bool override, unsigned int mask)
1554{
1555 enum pipe pipe = phy == DPIO_PHY0 ? PIPE_A : PIPE_C;
1556 u32 reg, val, expected, actual;
1557
Ville Syrjälä3be60de2015-09-08 18:05:45 +03001558 /*
1559 * The BIOS can leave the PHY is some weird state
1560 * where it doesn't fully power down some parts.
1561 * Disable the asserts until the PHY has been fully
1562 * reset (ie. the power well has been disabled at
1563 * least once).
1564 */
1565 if (!dev_priv->chv_phy_assert[phy])
1566 return;
1567
Ville Syrjälä6669e392015-07-08 23:46:00 +03001568 if (ch == DPIO_CH0)
1569 reg = _CHV_CMN_DW0_CH0;
1570 else
1571 reg = _CHV_CMN_DW6_CH1;
1572
1573 mutex_lock(&dev_priv->sb_lock);
1574 val = vlv_dpio_read(dev_priv, pipe, reg);
1575 mutex_unlock(&dev_priv->sb_lock);
1576
1577 /*
1578 * This assumes !override is only used when the port is disabled.
1579 * All lanes should power down even without the override when
1580 * the port is disabled.
1581 */
1582 if (!override || mask == 0xf) {
1583 expected = DPIO_ALLDL_POWERDOWN | DPIO_ANYDL_POWERDOWN;
1584 /*
1585 * If CH1 common lane is not active anymore
1586 * (eg. for pipe B DPLL) the entire channel will
1587 * shut down, which causes the common lane registers
1588 * to read as 0. That means we can't actually check
1589 * the lane power down status bits, but as the entire
1590 * register reads as 0 it's a good indication that the
1591 * channel is indeed entirely powered down.
1592 */
1593 if (ch == DPIO_CH1 && val == 0)
1594 expected = 0;
1595 } else if (mask != 0x0) {
1596 expected = DPIO_ANYDL_POWERDOWN;
1597 } else {
1598 expected = 0;
1599 }
1600
1601 if (ch == DPIO_CH0)
1602 actual = val >> DPIO_ANYDL_POWERDOWN_SHIFT_CH0;
1603 else
1604 actual = val >> DPIO_ANYDL_POWERDOWN_SHIFT_CH1;
1605 actual &= DPIO_ALLDL_POWERDOWN | DPIO_ANYDL_POWERDOWN;
1606
1607 WARN(actual != expected,
1608 "Unexpected DPIO lane power down: all %d, any %d. Expected: all %d, any %d. (0x%x = 0x%08x)\n",
1609 !!(actual & DPIO_ALLDL_POWERDOWN), !!(actual & DPIO_ANYDL_POWERDOWN),
1610 !!(expected & DPIO_ALLDL_POWERDOWN), !!(expected & DPIO_ANYDL_POWERDOWN),
1611 reg, val);
1612}
1613
Ville Syrjäläb0b33842015-07-08 23:45:55 +03001614bool chv_phy_powergate_ch(struct drm_i915_private *dev_priv, enum dpio_phy phy,
1615 enum dpio_channel ch, bool override)
1616{
1617 struct i915_power_domains *power_domains = &dev_priv->power_domains;
1618 bool was_override;
1619
1620 mutex_lock(&power_domains->lock);
1621
1622 was_override = dev_priv->chv_phy_control & PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
1623
1624 if (override == was_override)
1625 goto out;
1626
1627 if (override)
1628 dev_priv->chv_phy_control |= PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
1629 else
1630 dev_priv->chv_phy_control &= ~PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
1631
1632 I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
1633
1634 DRM_DEBUG_KMS("Power gating DPIO PHY%d CH%d (DPIO_PHY_CONTROL=0x%08x)\n",
1635 phy, ch, dev_priv->chv_phy_control);
1636
Ville Syrjälä30142272015-07-08 23:46:01 +03001637 assert_chv_phy_status(dev_priv);
1638
Ville Syrjäläb0b33842015-07-08 23:45:55 +03001639out:
1640 mutex_unlock(&power_domains->lock);
1641
1642 return was_override;
1643}
1644
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001645void chv_phy_powergate_lanes(struct intel_encoder *encoder,
1646 bool override, unsigned int mask)
1647{
1648 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
1649 struct i915_power_domains *power_domains = &dev_priv->power_domains;
1650 enum dpio_phy phy = vlv_dport_to_phy(enc_to_dig_port(&encoder->base));
1651 enum dpio_channel ch = vlv_dport_to_channel(enc_to_dig_port(&encoder->base));
1652
1653 mutex_lock(&power_domains->lock);
1654
1655 dev_priv->chv_phy_control &= ~PHY_CH_POWER_DOWN_OVRD(0xf, phy, ch);
1656 dev_priv->chv_phy_control |= PHY_CH_POWER_DOWN_OVRD(mask, phy, ch);
1657
1658 if (override)
1659 dev_priv->chv_phy_control |= PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
1660 else
1661 dev_priv->chv_phy_control &= ~PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
1662
1663 I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
1664
1665 DRM_DEBUG_KMS("Power gating DPIO PHY%d CH%d lanes 0x%x (PHY_CONTROL=0x%08x)\n",
1666 phy, ch, mask, dev_priv->chv_phy_control);
1667
Ville Syrjälä30142272015-07-08 23:46:01 +03001668 assert_chv_phy_status(dev_priv);
1669
Ville Syrjälä6669e392015-07-08 23:46:00 +03001670 assert_chv_phy_powergate(dev_priv, phy, ch, override, mask);
1671
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001672 mutex_unlock(&power_domains->lock);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001673}
1674
1675static bool chv_pipe_power_well_enabled(struct drm_i915_private *dev_priv,
1676 struct i915_power_well *power_well)
1677{
Imre Deakf49193c2017-07-06 17:40:23 +03001678 enum pipe pipe = PIPE_A;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001679 bool enabled;
1680 u32 state, ctrl;
1681
1682 mutex_lock(&dev_priv->rps.hw_lock);
1683
1684 state = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & DP_SSS_MASK(pipe);
1685 /*
1686 * We only ever set the power-on and power-gate states, anything
1687 * else is unexpected.
1688 */
1689 WARN_ON(state != DP_SSS_PWR_ON(pipe) && state != DP_SSS_PWR_GATE(pipe));
1690 enabled = state == DP_SSS_PWR_ON(pipe);
1691
1692 /*
1693 * A transient state at this point would mean some unexpected party
1694 * is poking at the power controls too.
1695 */
1696 ctrl = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & DP_SSC_MASK(pipe);
1697 WARN_ON(ctrl << 16 != state);
1698
1699 mutex_unlock(&dev_priv->rps.hw_lock);
1700
1701 return enabled;
1702}
1703
1704static void chv_set_pipe_power_well(struct drm_i915_private *dev_priv,
1705 struct i915_power_well *power_well,
1706 bool enable)
1707{
Imre Deakf49193c2017-07-06 17:40:23 +03001708 enum pipe pipe = PIPE_A;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001709 u32 state;
1710 u32 ctrl;
1711
1712 state = enable ? DP_SSS_PWR_ON(pipe) : DP_SSS_PWR_GATE(pipe);
1713
1714 mutex_lock(&dev_priv->rps.hw_lock);
1715
1716#define COND \
1717 ((vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & DP_SSS_MASK(pipe)) == state)
1718
1719 if (COND)
1720 goto out;
1721
1722 ctrl = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ);
1723 ctrl &= ~DP_SSC_MASK(pipe);
1724 ctrl |= enable ? DP_SSC_PWR_ON(pipe) : DP_SSC_PWR_GATE(pipe);
1725 vlv_punit_write(dev_priv, PUNIT_REG_DSPFREQ, ctrl);
1726
1727 if (wait_for(COND, 100))
Masanari Iida7e35ab82015-05-10 01:00:23 +09001728 DRM_ERROR("timeout setting power well state %08x (%08x)\n",
Daniel Vetter9c065a72014-09-30 10:56:38 +02001729 state,
1730 vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ));
1731
1732#undef COND
1733
1734out:
1735 mutex_unlock(&dev_priv->rps.hw_lock);
1736}
1737
Daniel Vetter9c065a72014-09-30 10:56:38 +02001738static void chv_pipe_power_well_enable(struct drm_i915_private *dev_priv,
1739 struct i915_power_well *power_well)
1740{
Imre Deakf49193c2017-07-06 17:40:23 +03001741 WARN_ON_ONCE(power_well->id != CHV_DISP_PW_PIPE_A);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001742
1743 chv_set_pipe_power_well(dev_priv, power_well, true);
Ville Syrjäläafd62752014-10-30 19:43:03 +02001744
Ville Syrjälä2be7d542015-06-29 15:25:51 +03001745 vlv_display_power_well_init(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001746}
1747
1748static void chv_pipe_power_well_disable(struct drm_i915_private *dev_priv,
1749 struct i915_power_well *power_well)
1750{
Imre Deakf49193c2017-07-06 17:40:23 +03001751 WARN_ON_ONCE(power_well->id != CHV_DISP_PW_PIPE_A);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001752
Ville Syrjälä2be7d542015-06-29 15:25:51 +03001753 vlv_display_power_well_deinit(dev_priv);
Ville Syrjäläafd62752014-10-30 19:43:03 +02001754
Daniel Vetter9c065a72014-09-30 10:56:38 +02001755 chv_set_pipe_power_well(dev_priv, power_well, false);
1756}
1757
Imre Deak09731282016-02-17 14:17:42 +02001758static void
1759__intel_display_power_get_domain(struct drm_i915_private *dev_priv,
1760 enum intel_display_power_domain domain)
1761{
1762 struct i915_power_domains *power_domains = &dev_priv->power_domains;
1763 struct i915_power_well *power_well;
Imre Deak09731282016-02-17 14:17:42 +02001764
Imre Deak75ccb2e2017-02-17 17:39:43 +02001765 for_each_power_domain_well(dev_priv, power_well, BIT_ULL(domain))
Imre Deakb409ca92016-06-13 16:44:33 +03001766 intel_power_well_get(dev_priv, power_well);
Imre Deak09731282016-02-17 14:17:42 +02001767
1768 power_domains->domain_use_count[domain]++;
1769}
1770
Daniel Vettere4e76842014-09-30 10:56:42 +02001771/**
1772 * intel_display_power_get - grab a power domain reference
1773 * @dev_priv: i915 device instance
1774 * @domain: power domain to reference
1775 *
1776 * This function grabs a power domain reference for @domain and ensures that the
1777 * power domain and all its parents are powered up. Therefore users should only
1778 * grab a reference to the innermost power domain they need.
1779 *
1780 * Any power domain reference obtained by this function must have a symmetric
1781 * call to intel_display_power_put() to release the reference again.
1782 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02001783void intel_display_power_get(struct drm_i915_private *dev_priv,
1784 enum intel_display_power_domain domain)
1785{
Imre Deak09731282016-02-17 14:17:42 +02001786 struct i915_power_domains *power_domains = &dev_priv->power_domains;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001787
1788 intel_runtime_pm_get(dev_priv);
1789
Imre Deak09731282016-02-17 14:17:42 +02001790 mutex_lock(&power_domains->lock);
1791
1792 __intel_display_power_get_domain(dev_priv, domain);
1793
1794 mutex_unlock(&power_domains->lock);
1795}
1796
1797/**
1798 * intel_display_power_get_if_enabled - grab a reference for an enabled display power domain
1799 * @dev_priv: i915 device instance
1800 * @domain: power domain to reference
1801 *
1802 * This function grabs a power domain reference for @domain and ensures that the
1803 * power domain and all its parents are powered up. Therefore users should only
1804 * grab a reference to the innermost power domain they need.
1805 *
1806 * Any power domain reference obtained by this function must have a symmetric
1807 * call to intel_display_power_put() to release the reference again.
1808 */
1809bool intel_display_power_get_if_enabled(struct drm_i915_private *dev_priv,
1810 enum intel_display_power_domain domain)
1811{
1812 struct i915_power_domains *power_domains = &dev_priv->power_domains;
1813 bool is_enabled;
1814
1815 if (!intel_runtime_pm_get_if_in_use(dev_priv))
1816 return false;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001817
1818 mutex_lock(&power_domains->lock);
1819
Imre Deak09731282016-02-17 14:17:42 +02001820 if (__intel_display_power_is_enabled(dev_priv, domain)) {
1821 __intel_display_power_get_domain(dev_priv, domain);
1822 is_enabled = true;
1823 } else {
1824 is_enabled = false;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001825 }
1826
Daniel Vetter9c065a72014-09-30 10:56:38 +02001827 mutex_unlock(&power_domains->lock);
Imre Deak09731282016-02-17 14:17:42 +02001828
1829 if (!is_enabled)
1830 intel_runtime_pm_put(dev_priv);
1831
1832 return is_enabled;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001833}
1834
Daniel Vettere4e76842014-09-30 10:56:42 +02001835/**
1836 * intel_display_power_put - release a power domain reference
1837 * @dev_priv: i915 device instance
1838 * @domain: power domain to reference
1839 *
1840 * This function drops the power domain reference obtained by
1841 * intel_display_power_get() and might power down the corresponding hardware
1842 * block right away if this is the last reference.
1843 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02001844void intel_display_power_put(struct drm_i915_private *dev_priv,
1845 enum intel_display_power_domain domain)
1846{
1847 struct i915_power_domains *power_domains;
1848 struct i915_power_well *power_well;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001849
1850 power_domains = &dev_priv->power_domains;
1851
1852 mutex_lock(&power_domains->lock);
1853
Daniel Stone11c86db2015-11-20 15:55:34 +00001854 WARN(!power_domains->domain_use_count[domain],
1855 "Use count on domain %s is already zero\n",
1856 intel_display_power_domain_str(domain));
Daniel Vetter9c065a72014-09-30 10:56:38 +02001857 power_domains->domain_use_count[domain]--;
1858
Imre Deak75ccb2e2017-02-17 17:39:43 +02001859 for_each_power_domain_well_rev(dev_priv, power_well, BIT_ULL(domain))
Imre Deakb409ca92016-06-13 16:44:33 +03001860 intel_power_well_put(dev_priv, power_well);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001861
1862 mutex_unlock(&power_domains->lock);
1863
1864 intel_runtime_pm_put(dev_priv);
1865}
1866
Ville Syrjälä9d0996b2016-04-18 14:02:28 +03001867#define HSW_DISPLAY_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001868 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
1869 BIT_ULL(POWER_DOMAIN_PIPE_C) | \
1870 BIT_ULL(POWER_DOMAIN_PIPE_A_PANEL_FITTER) | \
1871 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1872 BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
1873 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
1874 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
1875 BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
1876 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1877 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1878 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_LANES) | \
1879 BIT_ULL(POWER_DOMAIN_PORT_CRT) | /* DDI E */ \
1880 BIT_ULL(POWER_DOMAIN_VGA) | \
1881 BIT_ULL(POWER_DOMAIN_AUDIO) | \
1882 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001883
Ville Syrjälä9d0996b2016-04-18 14:02:28 +03001884#define BDW_DISPLAY_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001885 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
1886 BIT_ULL(POWER_DOMAIN_PIPE_C) | \
1887 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1888 BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
1889 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
1890 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
1891 BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
1892 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1893 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1894 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_LANES) | \
1895 BIT_ULL(POWER_DOMAIN_PORT_CRT) | /* DDI E */ \
1896 BIT_ULL(POWER_DOMAIN_VGA) | \
1897 BIT_ULL(POWER_DOMAIN_AUDIO) | \
1898 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001899
Ville Syrjälä465ac0c2016-04-18 14:02:27 +03001900#define VLV_DISPLAY_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001901 BIT_ULL(POWER_DOMAIN_PIPE_A) | \
1902 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
1903 BIT_ULL(POWER_DOMAIN_PIPE_A_PANEL_FITTER) | \
1904 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1905 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
1906 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
1907 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1908 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1909 BIT_ULL(POWER_DOMAIN_PORT_DSI) | \
1910 BIT_ULL(POWER_DOMAIN_PORT_CRT) | \
1911 BIT_ULL(POWER_DOMAIN_VGA) | \
1912 BIT_ULL(POWER_DOMAIN_AUDIO) | \
1913 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1914 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1915 BIT_ULL(POWER_DOMAIN_GMBUS) | \
1916 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001917
1918#define VLV_DPIO_CMN_BC_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001919 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1920 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1921 BIT_ULL(POWER_DOMAIN_PORT_CRT) | \
1922 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1923 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1924 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001925
1926#define VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001927 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1928 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1929 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001930
1931#define VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001932 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1933 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1934 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001935
1936#define VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001937 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1938 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1939 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001940
1941#define VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001942 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1943 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1944 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001945
Ville Syrjälä465ac0c2016-04-18 14:02:27 +03001946#define CHV_DISPLAY_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001947 BIT_ULL(POWER_DOMAIN_PIPE_A) | \
1948 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
1949 BIT_ULL(POWER_DOMAIN_PIPE_C) | \
1950 BIT_ULL(POWER_DOMAIN_PIPE_A_PANEL_FITTER) | \
1951 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1952 BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
1953 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
1954 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
1955 BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
1956 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1957 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1958 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_LANES) | \
1959 BIT_ULL(POWER_DOMAIN_PORT_DSI) | \
1960 BIT_ULL(POWER_DOMAIN_VGA) | \
1961 BIT_ULL(POWER_DOMAIN_AUDIO) | \
1962 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1963 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1964 BIT_ULL(POWER_DOMAIN_AUX_D) | \
1965 BIT_ULL(POWER_DOMAIN_GMBUS) | \
1966 BIT_ULL(POWER_DOMAIN_INIT))
Ville Syrjälä465ac0c2016-04-18 14:02:27 +03001967
Daniel Vetter9c065a72014-09-30 10:56:38 +02001968#define CHV_DPIO_CMN_BC_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001969 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1970 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1971 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1972 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1973 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001974
1975#define CHV_DPIO_CMN_D_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001976 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_LANES) | \
1977 BIT_ULL(POWER_DOMAIN_AUX_D) | \
1978 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001979
Ville Syrjälä2ee0da12017-06-01 17:36:16 +03001980#define I830_PIPES_POWER_DOMAINS ( \
1981 BIT_ULL(POWER_DOMAIN_PIPE_A) | \
1982 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
1983 BIT_ULL(POWER_DOMAIN_PIPE_A_PANEL_FITTER) | \
1984 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1985 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
1986 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
1987 BIT_ULL(POWER_DOMAIN_INIT))
1988
Daniel Vetter9c065a72014-09-30 10:56:38 +02001989static const struct i915_power_well_ops i9xx_always_on_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02001990 .sync_hw = i9xx_power_well_sync_hw_noop,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001991 .enable = i9xx_always_on_power_well_noop,
1992 .disable = i9xx_always_on_power_well_noop,
1993 .is_enabled = i9xx_always_on_power_well_enabled,
1994};
1995
1996static const struct i915_power_well_ops chv_pipe_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02001997 .sync_hw = i9xx_power_well_sync_hw_noop,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001998 .enable = chv_pipe_power_well_enable,
1999 .disable = chv_pipe_power_well_disable,
2000 .is_enabled = chv_pipe_power_well_enabled,
2001};
2002
2003static const struct i915_power_well_ops chv_dpio_cmn_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02002004 .sync_hw = i9xx_power_well_sync_hw_noop,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002005 .enable = chv_dpio_cmn_power_well_enable,
2006 .disable = chv_dpio_cmn_power_well_disable,
2007 .is_enabled = vlv_power_well_enabled,
2008};
2009
2010static struct i915_power_well i9xx_always_on_power_well[] = {
2011 {
2012 .name = "always-on",
2013 .always_on = 1,
2014 .domains = POWER_DOMAIN_MASK,
2015 .ops = &i9xx_always_on_power_well_ops,
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,
2039 },
2040};
2041
Daniel Vetter9c065a72014-09-30 10:56:38 +02002042static const struct i915_power_well_ops hsw_power_well_ops = {
2043 .sync_hw = hsw_power_well_sync_hw,
2044 .enable = hsw_power_well_enable,
2045 .disable = hsw_power_well_disable,
2046 .is_enabled = hsw_power_well_enabled,
2047};
2048
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002049static const struct i915_power_well_ops skl_power_well_ops = {
2050 .sync_hw = skl_power_well_sync_hw,
2051 .enable = skl_power_well_enable,
2052 .disable = skl_power_well_disable,
2053 .is_enabled = skl_power_well_enabled,
2054};
2055
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01002056static const struct i915_power_well_ops gen9_dc_off_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02002057 .sync_hw = i9xx_power_well_sync_hw_noop,
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01002058 .enable = gen9_dc_off_power_well_enable,
2059 .disable = gen9_dc_off_power_well_disable,
2060 .is_enabled = gen9_dc_off_power_well_enabled,
2061};
2062
Imre Deak9c8d0b82016-06-13 16:44:34 +03002063static const struct i915_power_well_ops bxt_dpio_cmn_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02002064 .sync_hw = i9xx_power_well_sync_hw_noop,
Imre Deak9c8d0b82016-06-13 16:44:34 +03002065 .enable = bxt_dpio_cmn_power_well_enable,
2066 .disable = bxt_dpio_cmn_power_well_disable,
2067 .is_enabled = bxt_dpio_cmn_power_well_enabled,
2068};
2069
Daniel Vetter9c065a72014-09-30 10:56:38 +02002070static struct i915_power_well hsw_power_wells[] = {
2071 {
2072 .name = "always-on",
2073 .always_on = 1,
Ville Syrjälä998bd662016-04-18 14:02:26 +03002074 .domains = POWER_DOMAIN_MASK,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002075 .ops = &i9xx_always_on_power_well_ops,
Imre Deak029d80d2017-07-06 17:40:25 +03002076 .id = I915_DISP_PW_ALWAYS_ON,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002077 },
2078 {
2079 .name = "display",
2080 .domains = HSW_DISPLAY_POWER_DOMAINS,
2081 .ops = &hsw_power_well_ops,
2082 },
2083};
2084
2085static struct i915_power_well bdw_power_wells[] = {
2086 {
2087 .name = "always-on",
2088 .always_on = 1,
Ville Syrjälä998bd662016-04-18 14:02:26 +03002089 .domains = POWER_DOMAIN_MASK,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002090 .ops = &i9xx_always_on_power_well_ops,
Imre Deak029d80d2017-07-06 17:40:25 +03002091 .id = I915_DISP_PW_ALWAYS_ON,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002092 },
2093 {
2094 .name = "display",
2095 .domains = BDW_DISPLAY_POWER_DOMAINS,
2096 .ops = &hsw_power_well_ops,
2097 },
2098};
2099
2100static const struct i915_power_well_ops vlv_display_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02002101 .sync_hw = i9xx_power_well_sync_hw_noop,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002102 .enable = vlv_display_power_well_enable,
2103 .disable = vlv_display_power_well_disable,
2104 .is_enabled = vlv_power_well_enabled,
2105};
2106
2107static const struct i915_power_well_ops vlv_dpio_cmn_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02002108 .sync_hw = i9xx_power_well_sync_hw_noop,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002109 .enable = vlv_dpio_cmn_power_well_enable,
2110 .disable = vlv_dpio_cmn_power_well_disable,
2111 .is_enabled = vlv_power_well_enabled,
2112};
2113
2114static const struct i915_power_well_ops vlv_dpio_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02002115 .sync_hw = i9xx_power_well_sync_hw_noop,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002116 .enable = vlv_power_well_enable,
2117 .disable = vlv_power_well_disable,
2118 .is_enabled = vlv_power_well_enabled,
2119};
2120
2121static struct i915_power_well vlv_power_wells[] = {
2122 {
2123 .name = "always-on",
2124 .always_on = 1,
Ville Syrjälä998bd662016-04-18 14:02:26 +03002125 .domains = POWER_DOMAIN_MASK,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002126 .ops = &i9xx_always_on_power_well_ops,
Imre Deak438b8dc2017-07-11 23:42:30 +03002127 .id = I915_DISP_PW_ALWAYS_ON,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002128 },
2129 {
2130 .name = "display",
2131 .domains = VLV_DISPLAY_POWER_DOMAINS,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002132 .id = PUNIT_POWER_WELL_DISP2D,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002133 .ops = &vlv_display_power_well_ops,
2134 },
2135 {
2136 .name = "dpio-tx-b-01",
2137 .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
2138 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
2139 VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
2140 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
2141 .ops = &vlv_dpio_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002142 .id = PUNIT_POWER_WELL_DPIO_TX_B_LANES_01,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002143 },
2144 {
2145 .name = "dpio-tx-b-23",
2146 .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
2147 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
2148 VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
2149 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
2150 .ops = &vlv_dpio_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002151 .id = PUNIT_POWER_WELL_DPIO_TX_B_LANES_23,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002152 },
2153 {
2154 .name = "dpio-tx-c-01",
2155 .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
2156 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
2157 VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
2158 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
2159 .ops = &vlv_dpio_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002160 .id = PUNIT_POWER_WELL_DPIO_TX_C_LANES_01,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002161 },
2162 {
2163 .name = "dpio-tx-c-23",
2164 .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
2165 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
2166 VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
2167 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
2168 .ops = &vlv_dpio_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002169 .id = PUNIT_POWER_WELL_DPIO_TX_C_LANES_23,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002170 },
2171 {
2172 .name = "dpio-common",
2173 .domains = VLV_DPIO_CMN_BC_POWER_DOMAINS,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002174 .id = PUNIT_POWER_WELL_DPIO_CMN_BC,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002175 .ops = &vlv_dpio_cmn_power_well_ops,
2176 },
2177};
2178
2179static struct i915_power_well chv_power_wells[] = {
2180 {
2181 .name = "always-on",
2182 .always_on = 1,
Ville Syrjälä998bd662016-04-18 14:02:26 +03002183 .domains = POWER_DOMAIN_MASK,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002184 .ops = &i9xx_always_on_power_well_ops,
Imre Deak029d80d2017-07-06 17:40:25 +03002185 .id = I915_DISP_PW_ALWAYS_ON,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002186 },
Daniel Vetter9c065a72014-09-30 10:56:38 +02002187 {
2188 .name = "display",
Ville Syrjäläbaa4e572014-10-27 16:07:32 +02002189 /*
Ville Syrjäläfde61e42015-05-26 20:22:39 +03002190 * Pipe A power well is the new disp2d well. Pipe B and C
2191 * power wells don't actually exist. Pipe A power well is
2192 * required for any pipe to work.
Ville Syrjäläbaa4e572014-10-27 16:07:32 +02002193 */
Ville Syrjälä465ac0c2016-04-18 14:02:27 +03002194 .domains = CHV_DISPLAY_POWER_DOMAINS,
Imre Deakf49193c2017-07-06 17:40:23 +03002195 .id = CHV_DISP_PW_PIPE_A,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002196 .ops = &chv_pipe_power_well_ops,
2197 },
Daniel Vetter9c065a72014-09-30 10:56:38 +02002198 {
2199 .name = "dpio-common-bc",
Ville Syrjälä71849b62015-04-10 18:21:29 +03002200 .domains = CHV_DPIO_CMN_BC_POWER_DOMAINS,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002201 .id = PUNIT_POWER_WELL_DPIO_CMN_BC,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002202 .ops = &chv_dpio_cmn_power_well_ops,
2203 },
2204 {
2205 .name = "dpio-common-d",
Ville Syrjälä71849b62015-04-10 18:21:29 +03002206 .domains = CHV_DPIO_CMN_D_POWER_DOMAINS,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002207 .id = PUNIT_POWER_WELL_DPIO_CMN_D,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002208 .ops = &chv_dpio_cmn_power_well_ops,
2209 },
Daniel Vetter9c065a72014-09-30 10:56:38 +02002210};
2211
Suketu Shah5aefb232015-04-16 14:22:10 +05302212bool intel_display_power_well_is_enabled(struct drm_i915_private *dev_priv,
Imre Deak438b8dc2017-07-11 23:42:30 +03002213 enum i915_power_well_id power_well_id)
Suketu Shah5aefb232015-04-16 14:22:10 +05302214{
2215 struct i915_power_well *power_well;
2216 bool ret;
2217
2218 power_well = lookup_power_well(dev_priv, power_well_id);
2219 ret = power_well->ops->is_enabled(dev_priv, power_well);
2220
2221 return ret;
2222}
2223
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002224static struct i915_power_well skl_power_wells[] = {
2225 {
2226 .name = "always-on",
2227 .always_on = 1,
Ville Syrjälä998bd662016-04-18 14:02:26 +03002228 .domains = POWER_DOMAIN_MASK,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002229 .ops = &i9xx_always_on_power_well_ops,
Imre Deak438b8dc2017-07-11 23:42:30 +03002230 .id = I915_DISP_PW_ALWAYS_ON,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002231 },
2232 {
2233 .name = "power well 1",
Imre Deak4a76f292015-11-04 19:24:15 +02002234 /* Handled by the DMC firmware */
2235 .domains = 0,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002236 .ops = &skl_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002237 .id = SKL_DISP_PW_1,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002238 },
2239 {
2240 .name = "MISC IO power well",
Imre Deak4a76f292015-11-04 19:24:15 +02002241 /* Handled by the DMC firmware */
2242 .domains = 0,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002243 .ops = &skl_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002244 .id = SKL_DISP_PW_MISC_IO,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002245 },
2246 {
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01002247 .name = "DC off",
2248 .domains = SKL_DISPLAY_DC_OFF_POWER_DOMAINS,
2249 .ops = &gen9_dc_off_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002250 .id = SKL_DISP_PW_DC_OFF,
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01002251 },
2252 {
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002253 .name = "power well 2",
2254 .domains = SKL_DISPLAY_POWERWELL_2_POWER_DOMAINS,
2255 .ops = &skl_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002256 .id = SKL_DISP_PW_2,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002257 },
2258 {
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002259 .name = "DDI A/E IO power well",
2260 .domains = SKL_DISPLAY_DDI_IO_A_E_POWER_DOMAINS,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002261 .ops = &skl_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002262 .id = SKL_DISP_PW_DDI_A_E,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002263 },
2264 {
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002265 .name = "DDI B IO power well",
2266 .domains = SKL_DISPLAY_DDI_IO_B_POWER_DOMAINS,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002267 .ops = &skl_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002268 .id = SKL_DISP_PW_DDI_B,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002269 },
2270 {
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002271 .name = "DDI C IO power well",
2272 .domains = SKL_DISPLAY_DDI_IO_C_POWER_DOMAINS,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002273 .ops = &skl_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002274 .id = SKL_DISP_PW_DDI_C,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002275 },
2276 {
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002277 .name = "DDI D IO power well",
2278 .domains = SKL_DISPLAY_DDI_IO_D_POWER_DOMAINS,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002279 .ops = &skl_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002280 .id = SKL_DISP_PW_DDI_D,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002281 },
2282};
2283
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302284static struct i915_power_well bxt_power_wells[] = {
2285 {
2286 .name = "always-on",
2287 .always_on = 1,
Ville Syrjälä998bd662016-04-18 14:02:26 +03002288 .domains = POWER_DOMAIN_MASK,
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302289 .ops = &i9xx_always_on_power_well_ops,
Imre Deak029d80d2017-07-06 17:40:25 +03002290 .id = I915_DISP_PW_ALWAYS_ON,
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302291 },
2292 {
2293 .name = "power well 1",
Imre Deakd7d7c9e2016-04-01 16:02:42 +03002294 .domains = 0,
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302295 .ops = &skl_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002296 .id = SKL_DISP_PW_1,
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302297 },
2298 {
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01002299 .name = "DC off",
2300 .domains = BXT_DISPLAY_DC_OFF_POWER_DOMAINS,
2301 .ops = &gen9_dc_off_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002302 .id = SKL_DISP_PW_DC_OFF,
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01002303 },
2304 {
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302305 .name = "power well 2",
2306 .domains = BXT_DISPLAY_POWERWELL_2_POWER_DOMAINS,
2307 .ops = &skl_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002308 .id = SKL_DISP_PW_2,
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01002309 },
Imre Deak9c8d0b82016-06-13 16:44:34 +03002310 {
2311 .name = "dpio-common-a",
2312 .domains = BXT_DPIO_CMN_A_POWER_DOMAINS,
2313 .ops = &bxt_dpio_cmn_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002314 .id = BXT_DPIO_CMN_A,
Ander Conselvan de Oliveira362624c2016-10-06 19:22:15 +03002315 .data = DPIO_PHY1,
Imre Deak9c8d0b82016-06-13 16:44:34 +03002316 },
2317 {
2318 .name = "dpio-common-bc",
2319 .domains = BXT_DPIO_CMN_BC_POWER_DOMAINS,
2320 .ops = &bxt_dpio_cmn_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002321 .id = BXT_DPIO_CMN_BC,
Ander Conselvan de Oliveira362624c2016-10-06 19:22:15 +03002322 .data = DPIO_PHY0,
Imre Deak9c8d0b82016-06-13 16:44:34 +03002323 },
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302324};
2325
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002326static struct i915_power_well glk_power_wells[] = {
2327 {
2328 .name = "always-on",
2329 .always_on = 1,
2330 .domains = POWER_DOMAIN_MASK,
2331 .ops = &i9xx_always_on_power_well_ops,
Imre Deak029d80d2017-07-06 17:40:25 +03002332 .id = I915_DISP_PW_ALWAYS_ON,
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002333 },
2334 {
2335 .name = "power well 1",
2336 /* Handled by the DMC firmware */
2337 .domains = 0,
2338 .ops = &skl_power_well_ops,
2339 .id = SKL_DISP_PW_1,
2340 },
2341 {
2342 .name = "DC off",
2343 .domains = GLK_DISPLAY_DC_OFF_POWER_DOMAINS,
2344 .ops = &gen9_dc_off_power_well_ops,
2345 .id = SKL_DISP_PW_DC_OFF,
2346 },
2347 {
2348 .name = "power well 2",
2349 .domains = GLK_DISPLAY_POWERWELL_2_POWER_DOMAINS,
2350 .ops = &skl_power_well_ops,
2351 .id = SKL_DISP_PW_2,
2352 },
2353 {
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +02002354 .name = "dpio-common-a",
2355 .domains = GLK_DPIO_CMN_A_POWER_DOMAINS,
2356 .ops = &bxt_dpio_cmn_power_well_ops,
2357 .id = BXT_DPIO_CMN_A,
2358 .data = DPIO_PHY1,
2359 },
2360 {
2361 .name = "dpio-common-b",
2362 .domains = GLK_DPIO_CMN_B_POWER_DOMAINS,
2363 .ops = &bxt_dpio_cmn_power_well_ops,
2364 .id = BXT_DPIO_CMN_BC,
2365 .data = DPIO_PHY0,
2366 },
2367 {
2368 .name = "dpio-common-c",
2369 .domains = GLK_DPIO_CMN_C_POWER_DOMAINS,
2370 .ops = &bxt_dpio_cmn_power_well_ops,
2371 .id = GLK_DPIO_CMN_C,
2372 .data = DPIO_PHY2,
2373 },
2374 {
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002375 .name = "AUX A",
2376 .domains = GLK_DISPLAY_AUX_A_POWER_DOMAINS,
2377 .ops = &skl_power_well_ops,
2378 .id = GLK_DISP_PW_AUX_A,
2379 },
2380 {
2381 .name = "AUX B",
2382 .domains = GLK_DISPLAY_AUX_B_POWER_DOMAINS,
2383 .ops = &skl_power_well_ops,
2384 .id = GLK_DISP_PW_AUX_B,
2385 },
2386 {
2387 .name = "AUX C",
2388 .domains = GLK_DISPLAY_AUX_C_POWER_DOMAINS,
2389 .ops = &skl_power_well_ops,
2390 .id = GLK_DISP_PW_AUX_C,
2391 },
2392 {
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002393 .name = "DDI A IO power well",
2394 .domains = GLK_DISPLAY_DDI_IO_A_POWER_DOMAINS,
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002395 .ops = &skl_power_well_ops,
2396 .id = GLK_DISP_PW_DDI_A,
2397 },
2398 {
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002399 .name = "DDI B IO power well",
2400 .domains = GLK_DISPLAY_DDI_IO_B_POWER_DOMAINS,
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002401 .ops = &skl_power_well_ops,
2402 .id = SKL_DISP_PW_DDI_B,
2403 },
2404 {
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002405 .name = "DDI C IO power well",
2406 .domains = GLK_DISPLAY_DDI_IO_C_POWER_DOMAINS,
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002407 .ops = &skl_power_well_ops,
2408 .id = SKL_DISP_PW_DDI_C,
2409 },
2410};
2411
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002412static struct i915_power_well cnl_power_wells[] = {
2413 {
2414 .name = "always-on",
2415 .always_on = 1,
2416 .domains = POWER_DOMAIN_MASK,
2417 .ops = &i9xx_always_on_power_well_ops,
Imre Deak029d80d2017-07-06 17:40:25 +03002418 .id = I915_DISP_PW_ALWAYS_ON,
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002419 },
2420 {
2421 .name = "power well 1",
2422 /* Handled by the DMC firmware */
2423 .domains = 0,
2424 .ops = &skl_power_well_ops,
2425 .id = SKL_DISP_PW_1,
2426 },
2427 {
2428 .name = "AUX A",
2429 .domains = CNL_DISPLAY_AUX_A_POWER_DOMAINS,
2430 .ops = &skl_power_well_ops,
2431 .id = CNL_DISP_PW_AUX_A,
2432 },
2433 {
2434 .name = "AUX B",
2435 .domains = CNL_DISPLAY_AUX_B_POWER_DOMAINS,
2436 .ops = &skl_power_well_ops,
2437 .id = CNL_DISP_PW_AUX_B,
2438 },
2439 {
2440 .name = "AUX C",
2441 .domains = CNL_DISPLAY_AUX_C_POWER_DOMAINS,
2442 .ops = &skl_power_well_ops,
2443 .id = CNL_DISP_PW_AUX_C,
2444 },
2445 {
2446 .name = "AUX D",
2447 .domains = CNL_DISPLAY_AUX_D_POWER_DOMAINS,
2448 .ops = &skl_power_well_ops,
2449 .id = CNL_DISP_PW_AUX_D,
2450 },
2451 {
2452 .name = "DC off",
2453 .domains = CNL_DISPLAY_DC_OFF_POWER_DOMAINS,
2454 .ops = &gen9_dc_off_power_well_ops,
2455 .id = SKL_DISP_PW_DC_OFF,
2456 },
2457 {
2458 .name = "power well 2",
2459 .domains = CNL_DISPLAY_POWERWELL_2_POWER_DOMAINS,
2460 .ops = &skl_power_well_ops,
2461 .id = SKL_DISP_PW_2,
2462 },
2463 {
2464 .name = "DDI A IO power well",
2465 .domains = CNL_DISPLAY_DDI_A_IO_POWER_DOMAINS,
2466 .ops = &skl_power_well_ops,
2467 .id = CNL_DISP_PW_DDI_A,
2468 },
2469 {
2470 .name = "DDI B IO power well",
2471 .domains = CNL_DISPLAY_DDI_B_IO_POWER_DOMAINS,
2472 .ops = &skl_power_well_ops,
2473 .id = SKL_DISP_PW_DDI_B,
2474 },
2475 {
2476 .name = "DDI C IO power well",
2477 .domains = CNL_DISPLAY_DDI_C_IO_POWER_DOMAINS,
2478 .ops = &skl_power_well_ops,
2479 .id = SKL_DISP_PW_DDI_C,
2480 },
2481 {
2482 .name = "DDI D IO power well",
2483 .domains = CNL_DISPLAY_DDI_D_IO_POWER_DOMAINS,
2484 .ops = &skl_power_well_ops,
2485 .id = SKL_DISP_PW_DDI_D,
2486 },
2487};
2488
Imre Deak1b0e3a02015-11-05 23:04:11 +02002489static int
2490sanitize_disable_power_well_option(const struct drm_i915_private *dev_priv,
2491 int disable_power_well)
2492{
2493 if (disable_power_well >= 0)
2494 return !!disable_power_well;
2495
Imre Deak1b0e3a02015-11-05 23:04:11 +02002496 return 1;
2497}
2498
Imre Deaka37baf32016-02-29 22:49:03 +02002499static uint32_t get_allowed_dc_mask(const struct drm_i915_private *dev_priv,
2500 int enable_dc)
2501{
2502 uint32_t mask;
2503 int requested_dc;
2504 int max_dc;
2505
Rodrigo Vivi6d6a8972017-07-06 13:45:08 -07002506 if (IS_GEN9_BC(dev_priv) || IS_CANNONLAKE(dev_priv)) {
Imre Deaka37baf32016-02-29 22:49:03 +02002507 max_dc = 2;
2508 mask = 0;
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02002509 } else if (IS_GEN9_LP(dev_priv)) {
Imre Deaka37baf32016-02-29 22:49:03 +02002510 max_dc = 1;
2511 /*
2512 * DC9 has a separate HW flow from the rest of the DC states,
2513 * not depending on the DMC firmware. It's needed by system
2514 * suspend/resume, so allow it unconditionally.
2515 */
2516 mask = DC_STATE_EN_DC9;
2517 } else {
2518 max_dc = 0;
2519 mask = 0;
2520 }
2521
Imre Deak66e2c4c2016-02-29 22:49:04 +02002522 if (!i915.disable_power_well)
2523 max_dc = 0;
2524
Imre Deaka37baf32016-02-29 22:49:03 +02002525 if (enable_dc >= 0 && enable_dc <= max_dc) {
2526 requested_dc = enable_dc;
2527 } else if (enable_dc == -1) {
2528 requested_dc = max_dc;
2529 } else if (enable_dc > max_dc && enable_dc <= 2) {
2530 DRM_DEBUG_KMS("Adjusting requested max DC state (%d->%d)\n",
2531 enable_dc, max_dc);
2532 requested_dc = max_dc;
2533 } else {
2534 DRM_ERROR("Unexpected value for enable_dc (%d)\n", enable_dc);
2535 requested_dc = max_dc;
2536 }
2537
2538 if (requested_dc > 1)
2539 mask |= DC_STATE_EN_UPTO_DC6;
2540 if (requested_dc > 0)
2541 mask |= DC_STATE_EN_UPTO_DC5;
2542
2543 DRM_DEBUG_KMS("Allowed DC state mask %02x\n", mask);
2544
2545 return mask;
2546}
2547
Daniel Vetter9c065a72014-09-30 10:56:38 +02002548#define set_power_wells(power_domains, __power_wells) ({ \
2549 (power_domains)->power_wells = (__power_wells); \
2550 (power_domains)->power_well_count = ARRAY_SIZE(__power_wells); \
2551})
2552
Daniel Vettere4e76842014-09-30 10:56:42 +02002553/**
2554 * intel_power_domains_init - initializes the power domain structures
2555 * @dev_priv: i915 device instance
2556 *
2557 * Initializes the power domain structures for @dev_priv depending upon the
2558 * supported platform.
2559 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02002560int intel_power_domains_init(struct drm_i915_private *dev_priv)
2561{
2562 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2563
Imre Deak1b0e3a02015-11-05 23:04:11 +02002564 i915.disable_power_well = sanitize_disable_power_well_option(dev_priv,
2565 i915.disable_power_well);
Imre Deaka37baf32016-02-29 22:49:03 +02002566 dev_priv->csr.allowed_dc_mask = get_allowed_dc_mask(dev_priv,
2567 i915.enable_dc);
Imre Deak1b0e3a02015-11-05 23:04:11 +02002568
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02002569 BUILD_BUG_ON(POWER_DOMAIN_NUM > 64);
Ville Syrjäläf0ab43e2015-11-09 16:48:19 +01002570
Daniel Vetter9c065a72014-09-30 10:56:38 +02002571 mutex_init(&power_domains->lock);
2572
2573 /*
2574 * The enabling order will be from lower to higher indexed wells,
2575 * the disabling order is reversed.
2576 */
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002577 if (IS_HASWELL(dev_priv)) {
Daniel Vetter9c065a72014-09-30 10:56:38 +02002578 set_power_wells(power_domains, hsw_power_wells);
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002579 } else if (IS_BROADWELL(dev_priv)) {
Daniel Vetter9c065a72014-09-30 10:56:38 +02002580 set_power_wells(power_domains, bdw_power_wells);
Rodrigo Vivib976dc52017-01-23 10:32:37 -08002581 } else if (IS_GEN9_BC(dev_priv)) {
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002582 set_power_wells(power_domains, skl_power_wells);
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002583 } else if (IS_CANNONLAKE(dev_priv)) {
2584 set_power_wells(power_domains, cnl_power_wells);
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002585 } else if (IS_BROXTON(dev_priv)) {
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302586 set_power_wells(power_domains, bxt_power_wells);
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002587 } else if (IS_GEMINILAKE(dev_priv)) {
2588 set_power_wells(power_domains, glk_power_wells);
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002589 } else if (IS_CHERRYVIEW(dev_priv)) {
Daniel Vetter9c065a72014-09-30 10:56:38 +02002590 set_power_wells(power_domains, chv_power_wells);
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002591 } else if (IS_VALLEYVIEW(dev_priv)) {
Daniel Vetter9c065a72014-09-30 10:56:38 +02002592 set_power_wells(power_domains, vlv_power_wells);
Ville Syrjälä2ee0da12017-06-01 17:36:16 +03002593 } else if (IS_I830(dev_priv)) {
2594 set_power_wells(power_domains, i830_power_wells);
Daniel Vetter9c065a72014-09-30 10:56:38 +02002595 } else {
2596 set_power_wells(power_domains, i9xx_always_on_power_well);
2597 }
2598
2599 return 0;
2600}
2601
Daniel Vettere4e76842014-09-30 10:56:42 +02002602/**
2603 * intel_power_domains_fini - finalizes the power domain structures
2604 * @dev_priv: i915 device instance
2605 *
2606 * Finalizes the power domain structures for @dev_priv depending upon the
2607 * supported platform. This function also disables runtime pm and ensures that
2608 * the device stays powered up so that the driver can be reloaded.
2609 */
Daniel Vetterf458ebb2014-09-30 10:56:39 +02002610void intel_power_domains_fini(struct drm_i915_private *dev_priv)
Daniel Vetter9c065a72014-09-30 10:56:38 +02002611{
David Weinehallc49d13e2016-08-22 13:32:42 +03002612 struct device *kdev = &dev_priv->drm.pdev->dev;
Imre Deak25b181b2015-12-17 13:44:56 +02002613
Imre Deakaabee1b2015-12-15 20:10:29 +02002614 /*
2615 * The i915.ko module is still not prepared to be loaded when
Daniel Vetterf458ebb2014-09-30 10:56:39 +02002616 * the power well is not enabled, so just enable it in case
Imre Deakaabee1b2015-12-15 20:10:29 +02002617 * we're going to unload/reload.
2618 * The following also reacquires the RPM reference the core passed
2619 * to the driver during loading, which is dropped in
2620 * intel_runtime_pm_enable(). We have to hand back the control of the
2621 * device to the core with this reference held.
2622 */
Daniel Vetterf458ebb2014-09-30 10:56:39 +02002623 intel_display_set_init_power(dev_priv, true);
Imre Deakd314cd42015-11-17 17:44:23 +02002624
2625 /* Remove the refcount we took to keep power well support disabled. */
2626 if (!i915.disable_power_well)
2627 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
Imre Deak25b181b2015-12-17 13:44:56 +02002628
2629 /*
2630 * Remove the refcount we took in intel_runtime_pm_enable() in case
2631 * the platform doesn't support runtime PM.
2632 */
2633 if (!HAS_RUNTIME_PM(dev_priv))
David Weinehallc49d13e2016-08-22 13:32:42 +03002634 pm_runtime_put(kdev);
Daniel Vetter9c065a72014-09-30 10:56:38 +02002635}
2636
Imre Deak30eade12015-11-04 19:24:13 +02002637static void intel_power_domains_sync_hw(struct drm_i915_private *dev_priv)
Daniel Vetter9c065a72014-09-30 10:56:38 +02002638{
2639 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2640 struct i915_power_well *power_well;
Daniel Vetter9c065a72014-09-30 10:56:38 +02002641
2642 mutex_lock(&power_domains->lock);
Imre Deak75ccb2e2017-02-17 17:39:43 +02002643 for_each_power_well(dev_priv, power_well) {
Daniel Vetter9c065a72014-09-30 10:56:38 +02002644 power_well->ops->sync_hw(dev_priv, power_well);
2645 power_well->hw_enabled = power_well->ops->is_enabled(dev_priv,
2646 power_well);
2647 }
2648 mutex_unlock(&power_domains->lock);
2649}
2650
Ville Syrjälä70c2c182016-05-13 23:41:30 +03002651static void gen9_dbuf_enable(struct drm_i915_private *dev_priv)
2652{
2653 I915_WRITE(DBUF_CTL, I915_READ(DBUF_CTL) | DBUF_POWER_REQUEST);
2654 POSTING_READ(DBUF_CTL);
2655
2656 udelay(10);
2657
2658 if (!(I915_READ(DBUF_CTL) & DBUF_POWER_STATE))
2659 DRM_ERROR("DBuf power enable timeout\n");
2660}
2661
2662static void gen9_dbuf_disable(struct drm_i915_private *dev_priv)
2663{
2664 I915_WRITE(DBUF_CTL, I915_READ(DBUF_CTL) & ~DBUF_POWER_REQUEST);
2665 POSTING_READ(DBUF_CTL);
2666
2667 udelay(10);
2668
2669 if (I915_READ(DBUF_CTL) & DBUF_POWER_STATE)
2670 DRM_ERROR("DBuf power disable timeout!\n");
2671}
2672
Imre Deak73dfc222015-11-17 17:33:53 +02002673static void skl_display_core_init(struct drm_i915_private *dev_priv,
Imre Deak443a93a2016-04-04 15:42:57 +03002674 bool resume)
Imre Deak73dfc222015-11-17 17:33:53 +02002675{
2676 struct i915_power_domains *power_domains = &dev_priv->power_domains;
Imre Deak443a93a2016-04-04 15:42:57 +03002677 struct i915_power_well *well;
Imre Deak73dfc222015-11-17 17:33:53 +02002678 uint32_t val;
2679
Imre Deakd26fa1d2015-11-04 19:24:17 +02002680 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
2681
Imre Deak73dfc222015-11-17 17:33:53 +02002682 /* enable PCH reset handshake */
2683 val = I915_READ(HSW_NDE_RSTWRN_OPT);
2684 I915_WRITE(HSW_NDE_RSTWRN_OPT, val | RESET_PCH_HANDSHAKE_ENABLE);
2685
2686 /* enable PG1 and Misc I/O */
2687 mutex_lock(&power_domains->lock);
Imre Deak443a93a2016-04-04 15:42:57 +03002688
2689 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
2690 intel_power_well_enable(dev_priv, well);
2691
2692 well = lookup_power_well(dev_priv, SKL_DISP_PW_MISC_IO);
2693 intel_power_well_enable(dev_priv, well);
2694
Imre Deak73dfc222015-11-17 17:33:53 +02002695 mutex_unlock(&power_domains->lock);
2696
Imre Deak73dfc222015-11-17 17:33:53 +02002697 skl_init_cdclk(dev_priv);
2698
Ville Syrjälä70c2c182016-05-13 23:41:30 +03002699 gen9_dbuf_enable(dev_priv);
2700
Ville Syrjälä9f7eb312016-05-13 23:41:29 +03002701 if (resume && dev_priv->csr.dmc_payload)
Imre Deak2abc5252016-03-04 21:57:41 +02002702 intel_csr_load_program(dev_priv);
Imre Deak73dfc222015-11-17 17:33:53 +02002703}
2704
2705static void skl_display_core_uninit(struct drm_i915_private *dev_priv)
2706{
2707 struct i915_power_domains *power_domains = &dev_priv->power_domains;
Imre Deak443a93a2016-04-04 15:42:57 +03002708 struct i915_power_well *well;
Imre Deak73dfc222015-11-17 17:33:53 +02002709
Imre Deakd26fa1d2015-11-04 19:24:17 +02002710 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
2711
Ville Syrjälä70c2c182016-05-13 23:41:30 +03002712 gen9_dbuf_disable(dev_priv);
2713
Imre Deak73dfc222015-11-17 17:33:53 +02002714 skl_uninit_cdclk(dev_priv);
2715
2716 /* The spec doesn't call for removing the reset handshake flag */
2717 /* disable PG1 and Misc I/O */
Imre Deak443a93a2016-04-04 15:42:57 +03002718
Imre Deak73dfc222015-11-17 17:33:53 +02002719 mutex_lock(&power_domains->lock);
Imre Deak443a93a2016-04-04 15:42:57 +03002720
Imre Deakedfda8e2017-06-29 18:36:59 +03002721 /*
2722 * BSpec says to keep the MISC IO power well enabled here, only
2723 * remove our request for power well 1.
Imre Deak42d93662017-06-29 18:37:01 +03002724 * Note that even though the driver's request is removed power well 1
2725 * may stay enabled after this due to DMC's own request on it.
Imre Deakedfda8e2017-06-29 18:36:59 +03002726 */
Imre Deak443a93a2016-04-04 15:42:57 +03002727 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
2728 intel_power_well_disable(dev_priv, well);
2729
Imre Deak73dfc222015-11-17 17:33:53 +02002730 mutex_unlock(&power_domains->lock);
Imre Deak846c6b22017-06-29 18:36:58 +03002731
2732 usleep_range(10, 30); /* 10 us delay per Bspec */
Imre Deak73dfc222015-11-17 17:33:53 +02002733}
2734
Imre Deakd7d7c9e2016-04-01 16:02:42 +03002735void bxt_display_core_init(struct drm_i915_private *dev_priv,
2736 bool resume)
2737{
2738 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2739 struct i915_power_well *well;
2740 uint32_t val;
2741
2742 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
2743
2744 /*
2745 * NDE_RSTWRN_OPT RST PCH Handshake En must always be 0b on BXT
2746 * or else the reset will hang because there is no PCH to respond.
2747 * Move the handshake programming to initialization sequence.
2748 * Previously was left up to BIOS.
2749 */
2750 val = I915_READ(HSW_NDE_RSTWRN_OPT);
2751 val &= ~RESET_PCH_HANDSHAKE_ENABLE;
2752 I915_WRITE(HSW_NDE_RSTWRN_OPT, val);
2753
2754 /* Enable PG1 */
2755 mutex_lock(&power_domains->lock);
2756
2757 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
2758 intel_power_well_enable(dev_priv, well);
2759
2760 mutex_unlock(&power_domains->lock);
2761
Imre Deak324513c2016-06-13 16:44:36 +03002762 bxt_init_cdclk(dev_priv);
Ville Syrjälä70c2c182016-05-13 23:41:30 +03002763
2764 gen9_dbuf_enable(dev_priv);
2765
Imre Deakd7d7c9e2016-04-01 16:02:42 +03002766 if (resume && dev_priv->csr.dmc_payload)
2767 intel_csr_load_program(dev_priv);
2768}
2769
2770void bxt_display_core_uninit(struct drm_i915_private *dev_priv)
2771{
2772 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2773 struct i915_power_well *well;
2774
2775 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
2776
Ville Syrjälä70c2c182016-05-13 23:41:30 +03002777 gen9_dbuf_disable(dev_priv);
2778
Imre Deak324513c2016-06-13 16:44:36 +03002779 bxt_uninit_cdclk(dev_priv);
Imre Deakd7d7c9e2016-04-01 16:02:42 +03002780
2781 /* The spec doesn't call for removing the reset handshake flag */
2782
Imre Deak42d93662017-06-29 18:37:01 +03002783 /*
2784 * Disable PW1 (PG1).
2785 * Note that even though the driver's request is removed power well 1
2786 * may stay enabled after this due to DMC's own request on it.
2787 */
Imre Deakd7d7c9e2016-04-01 16:02:42 +03002788 mutex_lock(&power_domains->lock);
2789
2790 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
2791 intel_power_well_disable(dev_priv, well);
2792
2793 mutex_unlock(&power_domains->lock);
Imre Deak846c6b22017-06-29 18:36:58 +03002794
2795 usleep_range(10, 30); /* 10 us delay per Bspec */
Imre Deakd7d7c9e2016-04-01 16:02:42 +03002796}
2797
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07002798#define CNL_PROCMON_IDX(val) \
2799 (((val) & (PROCESS_INFO_MASK | VOLTAGE_INFO_MASK)) >> VOLTAGE_INFO_SHIFT)
2800#define NUM_CNL_PROCMON \
2801 (CNL_PROCMON_IDX(VOLTAGE_INFO_MASK | PROCESS_INFO_MASK) + 1)
2802
2803static const struct cnl_procmon {
2804 u32 dw1, dw9, dw10;
2805} cnl_procmon_values[NUM_CNL_PROCMON] = {
2806 [CNL_PROCMON_IDX(VOLTAGE_INFO_0_85V | PROCESS_INFO_DOT_0)] =
2807 { .dw1 = 0x00 << 16, .dw9 = 0x62AB67BB, .dw10 = 0x51914F96, },
2808 [CNL_PROCMON_IDX(VOLTAGE_INFO_0_95V | PROCESS_INFO_DOT_0)] =
2809 { .dw1 = 0x00 << 16, .dw9 = 0x86E172C7, .dw10 = 0x77CA5EAB, },
2810 [CNL_PROCMON_IDX(VOLTAGE_INFO_0_95V | PROCESS_INFO_DOT_1)] =
2811 { .dw1 = 0x00 << 16, .dw9 = 0x93F87FE1, .dw10 = 0x8AE871C5, },
2812 [CNL_PROCMON_IDX(VOLTAGE_INFO_1_05V | PROCESS_INFO_DOT_0)] =
2813 { .dw1 = 0x00 << 16, .dw9 = 0x98FA82DD, .dw10 = 0x89E46DC1, },
2814 [CNL_PROCMON_IDX(VOLTAGE_INFO_1_05V | PROCESS_INFO_DOT_1)] =
2815 { .dw1 = 0x44 << 16, .dw9 = 0x9A00AB25, .dw10 = 0x8AE38FF1, },
2816};
2817
2818static void cnl_display_core_init(struct drm_i915_private *dev_priv, bool resume)
2819{
2820 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2821 const struct cnl_procmon *procmon;
2822 struct i915_power_well *well;
2823 u32 val;
2824
2825 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
2826
2827 /* 1. Enable PCH Reset Handshake */
2828 val = I915_READ(HSW_NDE_RSTWRN_OPT);
2829 val |= RESET_PCH_HANDSHAKE_ENABLE;
2830 I915_WRITE(HSW_NDE_RSTWRN_OPT, val);
2831
2832 /* 2. Enable Comp */
2833 val = I915_READ(CHICKEN_MISC_2);
2834 val &= ~COMP_PWR_DOWN;
2835 I915_WRITE(CHICKEN_MISC_2, val);
2836
2837 val = I915_READ(CNL_PORT_COMP_DW3);
2838 procmon = &cnl_procmon_values[CNL_PROCMON_IDX(val)];
2839
2840 WARN_ON(procmon->dw10 == 0);
2841
2842 val = I915_READ(CNL_PORT_COMP_DW1);
2843 val &= ~((0xff << 16) | 0xff);
2844 val |= procmon->dw1;
2845 I915_WRITE(CNL_PORT_COMP_DW1, val);
2846
2847 I915_WRITE(CNL_PORT_COMP_DW9, procmon->dw9);
2848 I915_WRITE(CNL_PORT_COMP_DW10, procmon->dw10);
2849
2850 val = I915_READ(CNL_PORT_COMP_DW0);
2851 val |= COMP_INIT;
2852 I915_WRITE(CNL_PORT_COMP_DW0, val);
2853
2854 /* 3. */
2855 val = I915_READ(CNL_PORT_CL1CM_DW5);
2856 val |= CL_POWER_DOWN_ENABLE;
2857 I915_WRITE(CNL_PORT_CL1CM_DW5, val);
2858
Imre Deakb38131f2017-06-29 18:37:02 +03002859 /*
2860 * 4. Enable Power Well 1 (PG1).
2861 * The AUX IO power wells will be enabled on demand.
2862 */
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07002863 mutex_lock(&power_domains->lock);
2864 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
2865 intel_power_well_enable(dev_priv, well);
2866 mutex_unlock(&power_domains->lock);
2867
2868 /* 5. Enable CD clock */
2869 cnl_init_cdclk(dev_priv);
2870
2871 /* 6. Enable DBUF */
2872 gen9_dbuf_enable(dev_priv);
2873}
2874
2875#undef CNL_PROCMON_IDX
2876#undef NUM_CNL_PROCMON
2877
2878static void cnl_display_core_uninit(struct drm_i915_private *dev_priv)
2879{
2880 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2881 struct i915_power_well *well;
2882 u32 val;
2883
2884 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
2885
2886 /* 1. Disable all display engine functions -> aready done */
2887
2888 /* 2. Disable DBUF */
2889 gen9_dbuf_disable(dev_priv);
2890
2891 /* 3. Disable CD clock */
2892 cnl_uninit_cdclk(dev_priv);
2893
Imre Deakb38131f2017-06-29 18:37:02 +03002894 /*
2895 * 4. Disable Power Well 1 (PG1).
2896 * The AUX IO power wells are toggled on demand, so they are already
2897 * disabled at this point.
2898 */
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07002899 mutex_lock(&power_domains->lock);
2900 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
2901 intel_power_well_disable(dev_priv, well);
2902 mutex_unlock(&power_domains->lock);
2903
Imre Deak846c6b22017-06-29 18:36:58 +03002904 usleep_range(10, 30); /* 10 us delay per Bspec */
2905
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07002906 /* 5. Disable Comp */
2907 val = I915_READ(CHICKEN_MISC_2);
2908 val |= COMP_PWR_DOWN;
2909 I915_WRITE(CHICKEN_MISC_2, val);
2910}
2911
Ville Syrjälä70722462015-04-10 18:21:28 +03002912static void chv_phy_control_init(struct drm_i915_private *dev_priv)
2913{
2914 struct i915_power_well *cmn_bc =
2915 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_BC);
2916 struct i915_power_well *cmn_d =
2917 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_D);
2918
2919 /*
2920 * DISPLAY_PHY_CONTROL can get corrupted if read. As a
2921 * workaround never ever read DISPLAY_PHY_CONTROL, and
2922 * instead maintain a shadow copy ourselves. Use the actual
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002923 * power well state and lane status to reconstruct the
2924 * expected initial value.
Ville Syrjälä70722462015-04-10 18:21:28 +03002925 */
2926 dev_priv->chv_phy_control =
Ville Syrjäläbc284542015-05-26 20:22:38 +03002927 PHY_LDO_SEQ_DELAY(PHY_LDO_DELAY_600NS, DPIO_PHY0) |
2928 PHY_LDO_SEQ_DELAY(PHY_LDO_DELAY_600NS, DPIO_PHY1) |
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002929 PHY_CH_POWER_MODE(PHY_CH_DEEP_PSR, DPIO_PHY0, DPIO_CH0) |
2930 PHY_CH_POWER_MODE(PHY_CH_DEEP_PSR, DPIO_PHY0, DPIO_CH1) |
2931 PHY_CH_POWER_MODE(PHY_CH_DEEP_PSR, DPIO_PHY1, DPIO_CH0);
2932
2933 /*
2934 * If all lanes are disabled we leave the override disabled
2935 * with all power down bits cleared to match the state we
2936 * would use after disabling the port. Otherwise enable the
2937 * override and set the lane powerdown bits accding to the
2938 * current lane status.
2939 */
2940 if (cmn_bc->ops->is_enabled(dev_priv, cmn_bc)) {
2941 uint32_t status = I915_READ(DPLL(PIPE_A));
2942 unsigned int mask;
2943
2944 mask = status & DPLL_PORTB_READY_MASK;
2945 if (mask == 0xf)
2946 mask = 0x0;
2947 else
2948 dev_priv->chv_phy_control |=
2949 PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY0, DPIO_CH0);
2950
2951 dev_priv->chv_phy_control |=
2952 PHY_CH_POWER_DOWN_OVRD(mask, DPIO_PHY0, DPIO_CH0);
2953
2954 mask = (status & DPLL_PORTC_READY_MASK) >> 4;
2955 if (mask == 0xf)
2956 mask = 0x0;
2957 else
2958 dev_priv->chv_phy_control |=
2959 PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY0, DPIO_CH1);
2960
2961 dev_priv->chv_phy_control |=
2962 PHY_CH_POWER_DOWN_OVRD(mask, DPIO_PHY0, DPIO_CH1);
2963
Ville Syrjälä70722462015-04-10 18:21:28 +03002964 dev_priv->chv_phy_control |= PHY_COM_LANE_RESET_DEASSERT(DPIO_PHY0);
Ville Syrjälä3be60de2015-09-08 18:05:45 +03002965
2966 dev_priv->chv_phy_assert[DPIO_PHY0] = false;
2967 } else {
2968 dev_priv->chv_phy_assert[DPIO_PHY0] = true;
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002969 }
2970
2971 if (cmn_d->ops->is_enabled(dev_priv, cmn_d)) {
2972 uint32_t status = I915_READ(DPIO_PHY_STATUS);
2973 unsigned int mask;
2974
2975 mask = status & DPLL_PORTD_READY_MASK;
2976
2977 if (mask == 0xf)
2978 mask = 0x0;
2979 else
2980 dev_priv->chv_phy_control |=
2981 PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY1, DPIO_CH0);
2982
2983 dev_priv->chv_phy_control |=
2984 PHY_CH_POWER_DOWN_OVRD(mask, DPIO_PHY1, DPIO_CH0);
2985
Ville Syrjälä70722462015-04-10 18:21:28 +03002986 dev_priv->chv_phy_control |= PHY_COM_LANE_RESET_DEASSERT(DPIO_PHY1);
Ville Syrjälä3be60de2015-09-08 18:05:45 +03002987
2988 dev_priv->chv_phy_assert[DPIO_PHY1] = false;
2989 } else {
2990 dev_priv->chv_phy_assert[DPIO_PHY1] = true;
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002991 }
2992
2993 I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
2994
2995 DRM_DEBUG_KMS("Initial PHY_CONTROL=0x%08x\n",
2996 dev_priv->chv_phy_control);
Ville Syrjälä70722462015-04-10 18:21:28 +03002997}
2998
Daniel Vetter9c065a72014-09-30 10:56:38 +02002999static void vlv_cmnlane_wa(struct drm_i915_private *dev_priv)
3000{
3001 struct i915_power_well *cmn =
3002 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_BC);
3003 struct i915_power_well *disp2d =
3004 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DISP2D);
3005
Daniel Vetter9c065a72014-09-30 10:56:38 +02003006 /* If the display might be already active skip this */
Ville Syrjälä5d93a6e2014-10-16 20:52:33 +03003007 if (cmn->ops->is_enabled(dev_priv, cmn) &&
3008 disp2d->ops->is_enabled(dev_priv, disp2d) &&
Daniel Vetter9c065a72014-09-30 10:56:38 +02003009 I915_READ(DPIO_CTL) & DPIO_CMNRST)
3010 return;
3011
3012 DRM_DEBUG_KMS("toggling display PHY side reset\n");
3013
3014 /* cmnlane needs DPLL registers */
3015 disp2d->ops->enable(dev_priv, disp2d);
3016
3017 /*
3018 * From VLV2A0_DP_eDP_HDMI_DPIO_driver_vbios_notes_11.docx:
3019 * Need to assert and de-assert PHY SB reset by gating the
3020 * common lane power, then un-gating it.
3021 * Simply ungating isn't enough to reset the PHY enough to get
3022 * ports and lanes running.
3023 */
3024 cmn->ops->disable(dev_priv, cmn);
3025}
3026
Daniel Vettere4e76842014-09-30 10:56:42 +02003027/**
3028 * intel_power_domains_init_hw - initialize hardware power domain state
3029 * @dev_priv: i915 device instance
Tvrtko Ursulin14bb2c12016-06-03 14:02:17 +01003030 * @resume: Called from resume code paths or not
Daniel Vettere4e76842014-09-30 10:56:42 +02003031 *
3032 * This function initializes the hardware power domain state and enables all
Imre Deak8d8c3862017-02-17 17:39:46 +02003033 * power wells belonging to the INIT power domain. Power wells in other
3034 * domains (and not in the INIT domain) are referenced or disabled during the
3035 * modeset state HW readout. After that the reference count of each power well
3036 * must match its HW enabled state, see intel_power_domains_verify_state().
Daniel Vettere4e76842014-09-30 10:56:42 +02003037 */
Imre Deak73dfc222015-11-17 17:33:53 +02003038void intel_power_domains_init_hw(struct drm_i915_private *dev_priv, bool resume)
Daniel Vetter9c065a72014-09-30 10:56:38 +02003039{
Daniel Vetter9c065a72014-09-30 10:56:38 +02003040 struct i915_power_domains *power_domains = &dev_priv->power_domains;
3041
3042 power_domains->initializing = true;
3043
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07003044 if (IS_CANNONLAKE(dev_priv)) {
3045 cnl_display_core_init(dev_priv, resume);
3046 } else if (IS_GEN9_BC(dev_priv)) {
Imre Deak73dfc222015-11-17 17:33:53 +02003047 skl_display_core_init(dev_priv, resume);
Ander Conselvan de Oliveirab817c442016-12-02 10:23:56 +02003048 } else if (IS_GEN9_LP(dev_priv)) {
Imre Deakd7d7c9e2016-04-01 16:02:42 +03003049 bxt_display_core_init(dev_priv, resume);
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01003050 } else if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä770effb2015-07-08 23:45:51 +03003051 mutex_lock(&power_domains->lock);
Ville Syrjälä70722462015-04-10 18:21:28 +03003052 chv_phy_control_init(dev_priv);
Ville Syrjälä770effb2015-07-08 23:45:51 +03003053 mutex_unlock(&power_domains->lock);
Tvrtko Ursulin11a914c2016-10-13 11:03:08 +01003054 } else if (IS_VALLEYVIEW(dev_priv)) {
Daniel Vetter9c065a72014-09-30 10:56:38 +02003055 mutex_lock(&power_domains->lock);
3056 vlv_cmnlane_wa(dev_priv);
3057 mutex_unlock(&power_domains->lock);
3058 }
3059
3060 /* For now, we need the power well to be always enabled. */
3061 intel_display_set_init_power(dev_priv, true);
Imre Deakd314cd42015-11-17 17:44:23 +02003062 /* Disable power support if the user asked so. */
3063 if (!i915.disable_power_well)
3064 intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
Imre Deak30eade12015-11-04 19:24:13 +02003065 intel_power_domains_sync_hw(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02003066 power_domains->initializing = false;
3067}
3068
Daniel Vettere4e76842014-09-30 10:56:42 +02003069/**
Imre Deak73dfc222015-11-17 17:33:53 +02003070 * intel_power_domains_suspend - suspend power domain state
3071 * @dev_priv: i915 device instance
3072 *
3073 * This function prepares the hardware power domain state before entering
3074 * system suspend. It must be paired with intel_power_domains_init_hw().
3075 */
3076void intel_power_domains_suspend(struct drm_i915_private *dev_priv)
3077{
Imre Deakd314cd42015-11-17 17:44:23 +02003078 /*
3079 * Even if power well support was disabled we still want to disable
3080 * power wells while we are system suspended.
3081 */
3082 if (!i915.disable_power_well)
3083 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
Imre Deak2622d792016-02-29 22:49:02 +02003084
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07003085 if (IS_CANNONLAKE(dev_priv))
3086 cnl_display_core_uninit(dev_priv);
3087 else if (IS_GEN9_BC(dev_priv))
Imre Deak2622d792016-02-29 22:49:02 +02003088 skl_display_core_uninit(dev_priv);
Ander Conselvan de Oliveirab817c442016-12-02 10:23:56 +02003089 else if (IS_GEN9_LP(dev_priv))
Imre Deakd7d7c9e2016-04-01 16:02:42 +03003090 bxt_display_core_uninit(dev_priv);
Imre Deak73dfc222015-11-17 17:33:53 +02003091}
3092
Imre Deak8d8c3862017-02-17 17:39:46 +02003093static void intel_power_domains_dump_info(struct drm_i915_private *dev_priv)
3094{
3095 struct i915_power_domains *power_domains = &dev_priv->power_domains;
3096 struct i915_power_well *power_well;
3097
3098 for_each_power_well(dev_priv, power_well) {
3099 enum intel_display_power_domain domain;
3100
3101 DRM_DEBUG_DRIVER("%-25s %d\n",
3102 power_well->name, power_well->count);
3103
3104 for_each_power_domain(domain, power_well->domains)
3105 DRM_DEBUG_DRIVER(" %-23s %d\n",
3106 intel_display_power_domain_str(domain),
3107 power_domains->domain_use_count[domain]);
3108 }
3109}
3110
3111/**
3112 * intel_power_domains_verify_state - verify the HW/SW state for all power wells
3113 * @dev_priv: i915 device instance
3114 *
3115 * Verify if the reference count of each power well matches its HW enabled
3116 * state and the total refcount of the domains it belongs to. This must be
3117 * called after modeset HW state sanitization, which is responsible for
3118 * acquiring reference counts for any power wells in use and disabling the
3119 * ones left on by BIOS but not required by any active output.
3120 */
3121void intel_power_domains_verify_state(struct drm_i915_private *dev_priv)
3122{
3123 struct i915_power_domains *power_domains = &dev_priv->power_domains;
3124 struct i915_power_well *power_well;
3125 bool dump_domain_info;
3126
3127 mutex_lock(&power_domains->lock);
3128
3129 dump_domain_info = false;
3130 for_each_power_well(dev_priv, power_well) {
3131 enum intel_display_power_domain domain;
3132 int domains_count;
3133 bool enabled;
3134
3135 /*
3136 * Power wells not belonging to any domain (like the MISC_IO
3137 * and PW1 power wells) are under FW control, so ignore them,
3138 * since their state can change asynchronously.
3139 */
3140 if (!power_well->domains)
3141 continue;
3142
3143 enabled = power_well->ops->is_enabled(dev_priv, power_well);
3144 if ((power_well->count || power_well->always_on) != enabled)
3145 DRM_ERROR("power well %s state mismatch (refcount %d/enabled %d)",
3146 power_well->name, power_well->count, enabled);
3147
3148 domains_count = 0;
3149 for_each_power_domain(domain, power_well->domains)
3150 domains_count += power_domains->domain_use_count[domain];
3151
3152 if (power_well->count != domains_count) {
3153 DRM_ERROR("power well %s refcount/domain refcount mismatch "
3154 "(refcount %d/domains refcount %d)\n",
3155 power_well->name, power_well->count,
3156 domains_count);
3157 dump_domain_info = true;
3158 }
3159 }
3160
3161 if (dump_domain_info) {
3162 static bool dumped;
3163
3164 if (!dumped) {
3165 intel_power_domains_dump_info(dev_priv);
3166 dumped = true;
3167 }
3168 }
3169
3170 mutex_unlock(&power_domains->lock);
3171}
3172
Imre Deak73dfc222015-11-17 17:33:53 +02003173/**
Daniel Vettere4e76842014-09-30 10:56:42 +02003174 * intel_runtime_pm_get - grab a runtime pm reference
3175 * @dev_priv: i915 device instance
3176 *
3177 * This function grabs a device-level runtime pm reference (mostly used for GEM
3178 * code to ensure the GTT or GT is on) and ensures that it is powered up.
3179 *
3180 * Any runtime pm reference obtained by this function must have a symmetric
3181 * call to intel_runtime_pm_put() to release the reference again.
3182 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02003183void intel_runtime_pm_get(struct drm_i915_private *dev_priv)
3184{
David Weinehall52a05c32016-08-22 13:32:44 +03003185 struct pci_dev *pdev = dev_priv->drm.pdev;
3186 struct device *kdev = &pdev->dev;
Imre Deakf5073822017-03-28 12:38:55 +03003187 int ret;
Daniel Vetter9c065a72014-09-30 10:56:38 +02003188
Imre Deakf5073822017-03-28 12:38:55 +03003189 ret = pm_runtime_get_sync(kdev);
3190 WARN_ONCE(ret < 0, "pm_runtime_get_sync() failed: %d\n", ret);
Imre Deak1f814da2015-12-16 02:52:19 +02003191
3192 atomic_inc(&dev_priv->pm.wakeref_count);
Imre Deakc9b88462015-12-15 20:10:34 +02003193 assert_rpm_wakelock_held(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02003194}
3195
Daniel Vettere4e76842014-09-30 10:56:42 +02003196/**
Imre Deak09731282016-02-17 14:17:42 +02003197 * intel_runtime_pm_get_if_in_use - grab a runtime pm reference if device in use
3198 * @dev_priv: i915 device instance
3199 *
3200 * This function grabs a device-level runtime pm reference if the device is
3201 * already in use and ensures that it is powered up.
3202 *
3203 * Any runtime pm reference obtained by this function must have a symmetric
3204 * call to intel_runtime_pm_put() to release the reference again.
3205 */
3206bool intel_runtime_pm_get_if_in_use(struct drm_i915_private *dev_priv)
3207{
David Weinehall52a05c32016-08-22 13:32:44 +03003208 struct pci_dev *pdev = dev_priv->drm.pdev;
3209 struct device *kdev = &pdev->dev;
Imre Deak09731282016-02-17 14:17:42 +02003210
Chris Wilson135dc792016-02-25 21:10:28 +00003211 if (IS_ENABLED(CONFIG_PM)) {
David Weinehallc49d13e2016-08-22 13:32:42 +03003212 int ret = pm_runtime_get_if_in_use(kdev);
Imre Deak09731282016-02-17 14:17:42 +02003213
Chris Wilson135dc792016-02-25 21:10:28 +00003214 /*
3215 * In cases runtime PM is disabled by the RPM core and we get
3216 * an -EINVAL return value we are not supposed to call this
3217 * function, since the power state is undefined. This applies
3218 * atm to the late/early system suspend/resume handlers.
3219 */
Imre Deakf5073822017-03-28 12:38:55 +03003220 WARN_ONCE(ret < 0,
3221 "pm_runtime_get_if_in_use() failed: %d\n", ret);
Chris Wilson135dc792016-02-25 21:10:28 +00003222 if (ret <= 0)
3223 return false;
3224 }
Imre Deak09731282016-02-17 14:17:42 +02003225
3226 atomic_inc(&dev_priv->pm.wakeref_count);
3227 assert_rpm_wakelock_held(dev_priv);
3228
3229 return true;
3230}
3231
3232/**
Daniel Vettere4e76842014-09-30 10:56:42 +02003233 * intel_runtime_pm_get_noresume - grab a runtime pm reference
3234 * @dev_priv: i915 device instance
3235 *
3236 * This function grabs a device-level runtime pm reference (mostly used for GEM
3237 * code to ensure the GTT or GT is on).
3238 *
3239 * It will _not_ power up the device but instead only check that it's powered
3240 * on. Therefore it is only valid to call this functions from contexts where
3241 * the device is known to be powered up and where trying to power it up would
3242 * result in hilarity and deadlocks. That pretty much means only the system
3243 * suspend/resume code where this is used to grab runtime pm references for
3244 * delayed setup down in work items.
3245 *
3246 * Any runtime pm reference obtained by this function must have a symmetric
3247 * call to intel_runtime_pm_put() to release the reference again.
3248 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02003249void intel_runtime_pm_get_noresume(struct drm_i915_private *dev_priv)
3250{
David Weinehall52a05c32016-08-22 13:32:44 +03003251 struct pci_dev *pdev = dev_priv->drm.pdev;
3252 struct device *kdev = &pdev->dev;
Daniel Vetter9c065a72014-09-30 10:56:38 +02003253
Imre Deakc9b88462015-12-15 20:10:34 +02003254 assert_rpm_wakelock_held(dev_priv);
David Weinehallc49d13e2016-08-22 13:32:42 +03003255 pm_runtime_get_noresume(kdev);
Imre Deak1f814da2015-12-16 02:52:19 +02003256
3257 atomic_inc(&dev_priv->pm.wakeref_count);
Daniel Vetter9c065a72014-09-30 10:56:38 +02003258}
3259
Daniel Vettere4e76842014-09-30 10:56:42 +02003260/**
3261 * intel_runtime_pm_put - release a runtime pm reference
3262 * @dev_priv: i915 device instance
3263 *
3264 * This function drops the device-level runtime pm reference obtained by
3265 * intel_runtime_pm_get() and might power down the corresponding
3266 * hardware block right away if this is the last reference.
3267 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02003268void intel_runtime_pm_put(struct drm_i915_private *dev_priv)
3269{
David Weinehall52a05c32016-08-22 13:32:44 +03003270 struct pci_dev *pdev = dev_priv->drm.pdev;
3271 struct device *kdev = &pdev->dev;
Daniel Vetter9c065a72014-09-30 10:56:38 +02003272
Imre Deak542db3c2015-12-15 20:10:36 +02003273 assert_rpm_wakelock_held(dev_priv);
Chris Wilson2eedfc72016-10-24 13:42:17 +01003274 atomic_dec(&dev_priv->pm.wakeref_count);
Imre Deak1f814da2015-12-16 02:52:19 +02003275
David Weinehallc49d13e2016-08-22 13:32:42 +03003276 pm_runtime_mark_last_busy(kdev);
3277 pm_runtime_put_autosuspend(kdev);
Daniel Vetter9c065a72014-09-30 10:56:38 +02003278}
3279
Daniel Vettere4e76842014-09-30 10:56:42 +02003280/**
3281 * intel_runtime_pm_enable - enable runtime pm
3282 * @dev_priv: i915 device instance
3283 *
3284 * This function enables runtime pm at the end of the driver load sequence.
3285 *
3286 * Note that this function does currently not enable runtime pm for the
3287 * subordinate display power domains. That is only done on the first modeset
3288 * using intel_display_set_init_power().
3289 */
Daniel Vetterf458ebb2014-09-30 10:56:39 +02003290void intel_runtime_pm_enable(struct drm_i915_private *dev_priv)
Daniel Vetter9c065a72014-09-30 10:56:38 +02003291{
David Weinehall52a05c32016-08-22 13:32:44 +03003292 struct pci_dev *pdev = dev_priv->drm.pdev;
David Weinehall52a05c32016-08-22 13:32:44 +03003293 struct device *kdev = &pdev->dev;
Daniel Vetter9c065a72014-09-30 10:56:38 +02003294
David Weinehallc49d13e2016-08-22 13:32:42 +03003295 pm_runtime_set_autosuspend_delay(kdev, 10000); /* 10s */
3296 pm_runtime_mark_last_busy(kdev);
Imre Deakcbc68dc2015-12-17 19:04:33 +02003297
Imre Deak25b181b2015-12-17 13:44:56 +02003298 /*
3299 * Take a permanent reference to disable the RPM functionality and drop
3300 * it only when unloading the driver. Use the low level get/put helpers,
3301 * so the driver's own RPM reference tracking asserts also work on
3302 * platforms without RPM support.
3303 */
Tvrtko Ursulin6772ffe2016-10-13 11:02:55 +01003304 if (!HAS_RUNTIME_PM(dev_priv)) {
Imre Deakf5073822017-03-28 12:38:55 +03003305 int ret;
3306
David Weinehallc49d13e2016-08-22 13:32:42 +03003307 pm_runtime_dont_use_autosuspend(kdev);
Imre Deakf5073822017-03-28 12:38:55 +03003308 ret = pm_runtime_get_sync(kdev);
3309 WARN(ret < 0, "pm_runtime_get_sync() failed: %d\n", ret);
Imre Deakcbc68dc2015-12-17 19:04:33 +02003310 } else {
David Weinehallc49d13e2016-08-22 13:32:42 +03003311 pm_runtime_use_autosuspend(kdev);
Imre Deakcbc68dc2015-12-17 19:04:33 +02003312 }
Daniel Vetter9c065a72014-09-30 10:56:38 +02003313
Imre Deakaabee1b2015-12-15 20:10:29 +02003314 /*
3315 * The core calls the driver load handler with an RPM reference held.
3316 * We drop that here and will reacquire it during unloading in
3317 * intel_power_domains_fini().
3318 */
David Weinehallc49d13e2016-08-22 13:32:42 +03003319 pm_runtime_put_autosuspend(kdev);
Daniel Vetter9c065a72014-09-30 10:56:38 +02003320}