blob: f630d632a976eb5a39db843855ad44b27bac76ed [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,
53 int power_well_id);
54
Imre Deak9c8d0b82016-06-13 16:44:34 +030055static struct i915_power_well *
56lookup_power_well(struct drm_i915_private *dev_priv, int power_well_id);
57
Daniel Stone9895ad02015-11-20 15:55:33 +000058const char *
59intel_display_power_domain_str(enum intel_display_power_domain domain)
60{
61 switch (domain) {
62 case POWER_DOMAIN_PIPE_A:
63 return "PIPE_A";
64 case POWER_DOMAIN_PIPE_B:
65 return "PIPE_B";
66 case POWER_DOMAIN_PIPE_C:
67 return "PIPE_C";
68 case POWER_DOMAIN_PIPE_A_PANEL_FITTER:
69 return "PIPE_A_PANEL_FITTER";
70 case POWER_DOMAIN_PIPE_B_PANEL_FITTER:
71 return "PIPE_B_PANEL_FITTER";
72 case POWER_DOMAIN_PIPE_C_PANEL_FITTER:
73 return "PIPE_C_PANEL_FITTER";
74 case POWER_DOMAIN_TRANSCODER_A:
75 return "TRANSCODER_A";
76 case POWER_DOMAIN_TRANSCODER_B:
77 return "TRANSCODER_B";
78 case POWER_DOMAIN_TRANSCODER_C:
79 return "TRANSCODER_C";
80 case POWER_DOMAIN_TRANSCODER_EDP:
81 return "TRANSCODER_EDP";
Jani Nikula4d1de972016-03-18 17:05:42 +020082 case POWER_DOMAIN_TRANSCODER_DSI_A:
83 return "TRANSCODER_DSI_A";
84 case POWER_DOMAIN_TRANSCODER_DSI_C:
85 return "TRANSCODER_DSI_C";
Daniel Stone9895ad02015-11-20 15:55:33 +000086 case POWER_DOMAIN_PORT_DDI_A_LANES:
87 return "PORT_DDI_A_LANES";
88 case POWER_DOMAIN_PORT_DDI_B_LANES:
89 return "PORT_DDI_B_LANES";
90 case POWER_DOMAIN_PORT_DDI_C_LANES:
91 return "PORT_DDI_C_LANES";
92 case POWER_DOMAIN_PORT_DDI_D_LANES:
93 return "PORT_DDI_D_LANES";
94 case POWER_DOMAIN_PORT_DDI_E_LANES:
95 return "PORT_DDI_E_LANES";
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +020096 case POWER_DOMAIN_PORT_DDI_A_IO:
97 return "PORT_DDI_A_IO";
98 case POWER_DOMAIN_PORT_DDI_B_IO:
99 return "PORT_DDI_B_IO";
100 case POWER_DOMAIN_PORT_DDI_C_IO:
101 return "PORT_DDI_C_IO";
102 case POWER_DOMAIN_PORT_DDI_D_IO:
103 return "PORT_DDI_D_IO";
104 case POWER_DOMAIN_PORT_DDI_E_IO:
105 return "PORT_DDI_E_IO";
Daniel Stone9895ad02015-11-20 15:55:33 +0000106 case POWER_DOMAIN_PORT_DSI:
107 return "PORT_DSI";
108 case POWER_DOMAIN_PORT_CRT:
109 return "PORT_CRT";
110 case POWER_DOMAIN_PORT_OTHER:
111 return "PORT_OTHER";
112 case POWER_DOMAIN_VGA:
113 return "VGA";
114 case POWER_DOMAIN_AUDIO:
115 return "AUDIO";
116 case POWER_DOMAIN_PLLS:
117 return "PLLS";
118 case POWER_DOMAIN_AUX_A:
119 return "AUX_A";
120 case POWER_DOMAIN_AUX_B:
121 return "AUX_B";
122 case POWER_DOMAIN_AUX_C:
123 return "AUX_C";
124 case POWER_DOMAIN_AUX_D:
125 return "AUX_D";
126 case POWER_DOMAIN_GMBUS:
127 return "GMBUS";
128 case POWER_DOMAIN_INIT:
129 return "INIT";
130 case POWER_DOMAIN_MODESET:
131 return "MODESET";
132 default:
133 MISSING_CASE(domain);
134 return "?";
135 }
136}
137
Damien Lespiaue8ca9322015-07-30 18:20:26 -0300138static void intel_power_well_enable(struct drm_i915_private *dev_priv,
139 struct i915_power_well *power_well)
140{
141 DRM_DEBUG_KMS("enabling %s\n", power_well->name);
142 power_well->ops->enable(dev_priv, power_well);
143 power_well->hw_enabled = true;
144}
145
Damien Lespiaudcddab32015-07-30 18:20:27 -0300146static void intel_power_well_disable(struct drm_i915_private *dev_priv,
147 struct i915_power_well *power_well)
148{
149 DRM_DEBUG_KMS("disabling %s\n", power_well->name);
150 power_well->hw_enabled = false;
151 power_well->ops->disable(dev_priv, power_well);
152}
153
Imre Deakb409ca92016-06-13 16:44:33 +0300154static void intel_power_well_get(struct drm_i915_private *dev_priv,
155 struct i915_power_well *power_well)
156{
157 if (!power_well->count++)
158 intel_power_well_enable(dev_priv, power_well);
159}
160
161static void intel_power_well_put(struct drm_i915_private *dev_priv,
162 struct i915_power_well *power_well)
163{
164 WARN(!power_well->count, "Use count on power well %s is already zero",
165 power_well->name);
166
167 if (!--power_well->count)
168 intel_power_well_disable(dev_priv, power_well);
169}
170
Daniel Vettere4e76842014-09-30 10:56:42 +0200171/*
Daniel Vetter9c065a72014-09-30 10:56:38 +0200172 * We should only use the power well if we explicitly asked the hardware to
173 * enable it, so check if it's enabled and also check if we've requested it to
174 * be enabled.
175 */
176static bool hsw_power_well_enabled(struct drm_i915_private *dev_priv,
177 struct i915_power_well *power_well)
178{
179 return I915_READ(HSW_PWR_WELL_DRIVER) ==
180 (HSW_PWR_WELL_ENABLE_REQUEST | HSW_PWR_WELL_STATE_ENABLED);
181}
182
Daniel Vettere4e76842014-09-30 10:56:42 +0200183/**
184 * __intel_display_power_is_enabled - unlocked check for a power domain
185 * @dev_priv: i915 device instance
186 * @domain: power domain to check
187 *
188 * This is the unlocked version of intel_display_power_is_enabled() and should
189 * only be used from error capture and recovery code where deadlocks are
190 * possible.
191 *
192 * Returns:
193 * True when the power domain is enabled, false otherwise.
194 */
Daniel Vetterf458ebb2014-09-30 10:56:39 +0200195bool __intel_display_power_is_enabled(struct drm_i915_private *dev_priv,
196 enum intel_display_power_domain domain)
Daniel Vetter9c065a72014-09-30 10:56:38 +0200197{
Daniel Vetter9c065a72014-09-30 10:56:38 +0200198 struct i915_power_well *power_well;
199 bool is_enabled;
Daniel Vetter9c065a72014-09-30 10:56:38 +0200200
201 if (dev_priv->pm.suspended)
202 return false;
203
Daniel Vetter9c065a72014-09-30 10:56:38 +0200204 is_enabled = true;
205
Imre Deak75ccb2e2017-02-17 17:39:43 +0200206 for_each_power_domain_well_rev(dev_priv, power_well, BIT_ULL(domain)) {
Daniel Vetter9c065a72014-09-30 10:56:38 +0200207 if (power_well->always_on)
208 continue;
209
210 if (!power_well->hw_enabled) {
211 is_enabled = false;
212 break;
213 }
214 }
215
216 return is_enabled;
217}
218
Daniel Vettere4e76842014-09-30 10:56:42 +0200219/**
Damien Lespiauf61ccae2014-11-25 13:45:41 +0000220 * intel_display_power_is_enabled - check for a power domain
Daniel Vettere4e76842014-09-30 10:56:42 +0200221 * @dev_priv: i915 device instance
222 * @domain: power domain to check
223 *
224 * This function can be used to check the hw power domain state. It is mostly
225 * used in hardware state readout functions. Everywhere else code should rely
226 * upon explicit power domain reference counting to ensure that the hardware
227 * block is powered up before accessing it.
228 *
229 * Callers must hold the relevant modesetting locks to ensure that concurrent
230 * threads can't disable the power well while the caller tries to read a few
231 * registers.
232 *
233 * Returns:
234 * True when the power domain is enabled, false otherwise.
235 */
Daniel Vetterf458ebb2014-09-30 10:56:39 +0200236bool intel_display_power_is_enabled(struct drm_i915_private *dev_priv,
237 enum intel_display_power_domain domain)
Daniel Vetter9c065a72014-09-30 10:56:38 +0200238{
239 struct i915_power_domains *power_domains;
240 bool ret;
241
242 power_domains = &dev_priv->power_domains;
243
244 mutex_lock(&power_domains->lock);
Daniel Vetterf458ebb2014-09-30 10:56:39 +0200245 ret = __intel_display_power_is_enabled(dev_priv, domain);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200246 mutex_unlock(&power_domains->lock);
247
248 return ret;
249}
250
Daniel Vettere4e76842014-09-30 10:56:42 +0200251/**
252 * intel_display_set_init_power - set the initial power domain state
253 * @dev_priv: i915 device instance
254 * @enable: whether to enable or disable the initial power domain state
255 *
256 * For simplicity our driver load/unload and system suspend/resume code assumes
257 * that all power domains are always enabled. This functions controls the state
258 * of this little hack. While the initial power domain state is enabled runtime
259 * pm is effectively disabled.
260 */
Daniel Vetterd9bc89d92014-09-30 10:56:40 +0200261void intel_display_set_init_power(struct drm_i915_private *dev_priv,
262 bool enable)
263{
264 if (dev_priv->power_domains.init_power_on == enable)
265 return;
266
267 if (enable)
268 intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
269 else
270 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
271
272 dev_priv->power_domains.init_power_on = enable;
273}
274
Daniel Vetter9c065a72014-09-30 10:56:38 +0200275/*
276 * Starting with Haswell, we have a "Power Down Well" that can be turned off
277 * when not needed anymore. We have 4 registers that can request the power well
278 * to be enabled, and it will only be disabled if none of the registers is
279 * requesting it to be enabled.
280 */
281static void hsw_power_well_post_enable(struct drm_i915_private *dev_priv)
282{
David Weinehall52a05c32016-08-22 13:32:44 +0300283 struct pci_dev *pdev = dev_priv->drm.pdev;
Daniel Vetter9c065a72014-09-30 10:56:38 +0200284
285 /*
286 * After we re-enable the power well, if we touch VGA register 0x3d5
287 * we'll get unclaimed register interrupts. This stops after we write
288 * anything to the VGA MSR register. The vgacon module uses this
289 * register all the time, so if we unbind our driver and, as a
290 * consequence, bind vgacon, we'll get stuck in an infinite loop at
291 * console_unlock(). So make here we touch the VGA MSR register, making
292 * sure vgacon can keep working normally without triggering interrupts
293 * and error messages.
294 */
David Weinehall52a05c32016-08-22 13:32:44 +0300295 vga_get_uninterruptible(pdev, VGA_RSRC_LEGACY_IO);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200296 outb(inb(VGA_MSR_READ), VGA_MSR_WRITE);
David Weinehall52a05c32016-08-22 13:32:44 +0300297 vga_put(pdev, VGA_RSRC_LEGACY_IO);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200298
Tvrtko Ursulin86527442016-10-13 11:03:00 +0100299 if (IS_BROADWELL(dev_priv))
Damien Lespiau4c6c03b2015-03-06 18:50:48 +0000300 gen8_irq_power_well_post_enable(dev_priv,
301 1 << PIPE_C | 1 << PIPE_B);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200302}
303
Ville Syrjäläaae8ba82016-02-19 20:47:30 +0200304static void hsw_power_well_pre_disable(struct drm_i915_private *dev_priv)
305{
306 if (IS_BROADWELL(dev_priv))
307 gen8_irq_power_well_pre_disable(dev_priv,
308 1 << PIPE_C | 1 << PIPE_B);
309}
310
Damien Lespiaud14c0342015-03-06 18:50:51 +0000311static void skl_power_well_post_enable(struct drm_i915_private *dev_priv,
312 struct i915_power_well *power_well)
313{
David Weinehall52a05c32016-08-22 13:32:44 +0300314 struct pci_dev *pdev = dev_priv->drm.pdev;
Damien Lespiaud14c0342015-03-06 18:50:51 +0000315
316 /*
317 * After we re-enable the power well, if we touch VGA register 0x3d5
318 * we'll get unclaimed register interrupts. This stops after we write
319 * anything to the VGA MSR register. The vgacon module uses this
320 * register all the time, so if we unbind our driver and, as a
321 * consequence, bind vgacon, we'll get stuck in an infinite loop at
322 * console_unlock(). So make here we touch the VGA MSR register, making
323 * sure vgacon can keep working normally without triggering interrupts
324 * and error messages.
325 */
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +0300326 if (power_well->id == SKL_DISP_PW_2) {
David Weinehall52a05c32016-08-22 13:32:44 +0300327 vga_get_uninterruptible(pdev, VGA_RSRC_LEGACY_IO);
Damien Lespiaud14c0342015-03-06 18:50:51 +0000328 outb(inb(VGA_MSR_READ), VGA_MSR_WRITE);
David Weinehall52a05c32016-08-22 13:32:44 +0300329 vga_put(pdev, VGA_RSRC_LEGACY_IO);
Damien Lespiaud14c0342015-03-06 18:50:51 +0000330
331 gen8_irq_power_well_post_enable(dev_priv,
332 1 << PIPE_C | 1 << PIPE_B);
333 }
Damien Lespiaud14c0342015-03-06 18:50:51 +0000334}
335
Ville Syrjäläaae8ba82016-02-19 20:47:30 +0200336static void skl_power_well_pre_disable(struct drm_i915_private *dev_priv,
337 struct i915_power_well *power_well)
338{
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +0300339 if (power_well->id == SKL_DISP_PW_2)
Ville Syrjäläaae8ba82016-02-19 20:47:30 +0200340 gen8_irq_power_well_pre_disable(dev_priv,
341 1 << PIPE_C | 1 << PIPE_B);
342}
343
Imre Deak42d93662017-06-29 18:37:01 +0300344static void gen9_wait_for_power_well_enable(struct drm_i915_private *dev_priv,
345 struct i915_power_well *power_well)
346{
347 int id = power_well->id;
348
349 /* Timeout for PW1:10 us, AUX:not specified, other PWs:20 us. */
350 WARN_ON(intel_wait_for_register(dev_priv,
351 HSW_PWR_WELL_DRIVER,
352 SKL_POWER_WELL_STATE(id),
353 SKL_POWER_WELL_STATE(id),
354 1));
355}
356
357static u32 gen9_power_well_requesters(struct drm_i915_private *dev_priv, int id)
358{
359 u32 req_mask = SKL_POWER_WELL_REQ(id);
360 u32 ret;
361
362 ret = I915_READ(HSW_PWR_WELL_BIOS) & req_mask ? 1 : 0;
363 ret |= I915_READ(HSW_PWR_WELL_DRIVER) & req_mask ? 2 : 0;
364 ret |= I915_READ(HSW_PWR_WELL_KVMR) & req_mask ? 4 : 0;
365 ret |= I915_READ(HSW_PWR_WELL_DEBUG) & req_mask ? 8 : 0;
366
367 return ret;
368}
369
370static void gen9_wait_for_power_well_disable(struct drm_i915_private *dev_priv,
371 struct i915_power_well *power_well)
372{
373 int id = power_well->id;
374 bool disabled;
375 u32 reqs;
376
377 /*
378 * Bspec doesn't require waiting for PWs to get disabled, but still do
379 * this for paranoia. The known cases where a PW will be forced on:
380 * - a KVMR request on any power well via the KVMR request register
381 * - a DMC request on PW1 and MISC_IO power wells via the BIOS and
382 * DEBUG request registers
383 * Skip the wait in case any of the request bits are set and print a
384 * diagnostic message.
385 */
386 wait_for((disabled = !(I915_READ(HSW_PWR_WELL_DRIVER) &
387 SKL_POWER_WELL_STATE(id))) ||
388 (reqs = gen9_power_well_requesters(dev_priv, id)), 1);
389 if (disabled)
390 return;
391
392 DRM_DEBUG_KMS("%s forced on (bios:%d driver:%d kvmr:%d debug:%d)\n",
393 power_well->name,
394 !!(reqs & 1), !!(reqs & 2), !!(reqs & 4), !!(reqs & 8));
395}
396
Daniel Vetter9c065a72014-09-30 10:56:38 +0200397static void hsw_set_power_well(struct drm_i915_private *dev_priv,
398 struct i915_power_well *power_well, bool enable)
399{
400 bool is_enabled, enable_requested;
401 uint32_t tmp;
402
403 tmp = I915_READ(HSW_PWR_WELL_DRIVER);
404 is_enabled = tmp & HSW_PWR_WELL_STATE_ENABLED;
405 enable_requested = tmp & HSW_PWR_WELL_ENABLE_REQUEST;
406
407 if (enable) {
408 if (!enable_requested)
409 I915_WRITE(HSW_PWR_WELL_DRIVER,
410 HSW_PWR_WELL_ENABLE_REQUEST);
411
412 if (!is_enabled) {
413 DRM_DEBUG_KMS("Enabling power well\n");
Chris Wilson2c2ccc32016-06-30 15:33:32 +0100414 if (intel_wait_for_register(dev_priv,
415 HSW_PWR_WELL_DRIVER,
416 HSW_PWR_WELL_STATE_ENABLED,
417 HSW_PWR_WELL_STATE_ENABLED,
418 20))
Daniel Vetter9c065a72014-09-30 10:56:38 +0200419 DRM_ERROR("Timeout enabling power well\n");
Paulo Zanoni6d729bf2014-10-07 16:11:11 -0300420 hsw_power_well_post_enable(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200421 }
422
Daniel Vetter9c065a72014-09-30 10:56:38 +0200423 } else {
424 if (enable_requested) {
Ville Syrjäläaae8ba82016-02-19 20:47:30 +0200425 hsw_power_well_pre_disable(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200426 I915_WRITE(HSW_PWR_WELL_DRIVER, 0);
427 POSTING_READ(HSW_PWR_WELL_DRIVER);
428 DRM_DEBUG_KMS("Requesting to disable the power well\n");
429 }
430 }
431}
432
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000433#define SKL_DISPLAY_POWERWELL_2_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200434 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
435 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
436 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
437 BIT_ULL(POWER_DOMAIN_PIPE_C) | \
438 BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
439 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
440 BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
441 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
442 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
443 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_LANES) | \
444 BIT_ULL(POWER_DOMAIN_PORT_DDI_E_LANES) | \
445 BIT_ULL(POWER_DOMAIN_AUX_B) | \
446 BIT_ULL(POWER_DOMAIN_AUX_C) | \
447 BIT_ULL(POWER_DOMAIN_AUX_D) | \
448 BIT_ULL(POWER_DOMAIN_AUDIO) | \
449 BIT_ULL(POWER_DOMAIN_VGA) | \
450 BIT_ULL(POWER_DOMAIN_INIT))
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +0200451#define SKL_DISPLAY_DDI_IO_A_E_POWER_DOMAINS ( \
452 BIT_ULL(POWER_DOMAIN_PORT_DDI_A_IO) | \
453 BIT_ULL(POWER_DOMAIN_PORT_DDI_E_IO) | \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200454 BIT_ULL(POWER_DOMAIN_INIT))
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +0200455#define SKL_DISPLAY_DDI_IO_B_POWER_DOMAINS ( \
456 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_IO) | \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200457 BIT_ULL(POWER_DOMAIN_INIT))
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +0200458#define SKL_DISPLAY_DDI_IO_C_POWER_DOMAINS ( \
459 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_IO) | \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200460 BIT_ULL(POWER_DOMAIN_INIT))
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +0200461#define SKL_DISPLAY_DDI_IO_D_POWER_DOMAINS ( \
462 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_IO) | \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200463 BIT_ULL(POWER_DOMAIN_INIT))
Patrik Jakobsson9f836f92015-11-16 16:20:01 +0100464#define SKL_DISPLAY_DC_OFF_POWER_DOMAINS ( \
465 SKL_DISPLAY_POWERWELL_2_POWER_DOMAINS | \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200466 BIT_ULL(POWER_DOMAIN_MODESET) | \
467 BIT_ULL(POWER_DOMAIN_AUX_A) | \
468 BIT_ULL(POWER_DOMAIN_INIT))
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000469
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +0530470#define BXT_DISPLAY_POWERWELL_2_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200471 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
472 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
473 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
474 BIT_ULL(POWER_DOMAIN_PIPE_C) | \
475 BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
476 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
477 BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
478 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
479 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
480 BIT_ULL(POWER_DOMAIN_AUX_B) | \
481 BIT_ULL(POWER_DOMAIN_AUX_C) | \
482 BIT_ULL(POWER_DOMAIN_AUDIO) | \
483 BIT_ULL(POWER_DOMAIN_VGA) | \
484 BIT_ULL(POWER_DOMAIN_GMBUS) | \
485 BIT_ULL(POWER_DOMAIN_INIT))
Patrik Jakobsson9f836f92015-11-16 16:20:01 +0100486#define BXT_DISPLAY_DC_OFF_POWER_DOMAINS ( \
487 BXT_DISPLAY_POWERWELL_2_POWER_DOMAINS | \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200488 BIT_ULL(POWER_DOMAIN_MODESET) | \
489 BIT_ULL(POWER_DOMAIN_AUX_A) | \
490 BIT_ULL(POWER_DOMAIN_INIT))
Imre Deak9c8d0b82016-06-13 16:44:34 +0300491#define BXT_DPIO_CMN_A_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200492 BIT_ULL(POWER_DOMAIN_PORT_DDI_A_LANES) | \
493 BIT_ULL(POWER_DOMAIN_AUX_A) | \
494 BIT_ULL(POWER_DOMAIN_INIT))
Imre Deak9c8d0b82016-06-13 16:44:34 +0300495#define BXT_DPIO_CMN_BC_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200496 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
497 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
498 BIT_ULL(POWER_DOMAIN_AUX_B) | \
499 BIT_ULL(POWER_DOMAIN_AUX_C) | \
500 BIT_ULL(POWER_DOMAIN_INIT))
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +0530501
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +0200502#define GLK_DISPLAY_POWERWELL_2_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200503 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
504 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
505 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
506 BIT_ULL(POWER_DOMAIN_PIPE_C) | \
507 BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
508 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
509 BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
510 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
511 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
512 BIT_ULL(POWER_DOMAIN_AUX_B) | \
513 BIT_ULL(POWER_DOMAIN_AUX_C) | \
514 BIT_ULL(POWER_DOMAIN_AUDIO) | \
515 BIT_ULL(POWER_DOMAIN_VGA) | \
516 BIT_ULL(POWER_DOMAIN_INIT))
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +0200517#define GLK_DISPLAY_DDI_IO_A_POWER_DOMAINS ( \
518 BIT_ULL(POWER_DOMAIN_PORT_DDI_A_IO))
519#define GLK_DISPLAY_DDI_IO_B_POWER_DOMAINS ( \
520 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_IO))
521#define GLK_DISPLAY_DDI_IO_C_POWER_DOMAINS ( \
522 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_IO))
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +0200523#define GLK_DPIO_CMN_A_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200524 BIT_ULL(POWER_DOMAIN_PORT_DDI_A_LANES) | \
525 BIT_ULL(POWER_DOMAIN_AUX_A) | \
526 BIT_ULL(POWER_DOMAIN_INIT))
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +0200527#define GLK_DPIO_CMN_B_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200528 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
529 BIT_ULL(POWER_DOMAIN_AUX_B) | \
530 BIT_ULL(POWER_DOMAIN_INIT))
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +0200531#define GLK_DPIO_CMN_C_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200532 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
533 BIT_ULL(POWER_DOMAIN_AUX_C) | \
534 BIT_ULL(POWER_DOMAIN_INIT))
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +0200535#define GLK_DISPLAY_AUX_A_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200536 BIT_ULL(POWER_DOMAIN_AUX_A) | \
537 BIT_ULL(POWER_DOMAIN_INIT))
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +0200538#define GLK_DISPLAY_AUX_B_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200539 BIT_ULL(POWER_DOMAIN_AUX_B) | \
540 BIT_ULL(POWER_DOMAIN_INIT))
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +0200541#define GLK_DISPLAY_AUX_C_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200542 BIT_ULL(POWER_DOMAIN_AUX_C) | \
543 BIT_ULL(POWER_DOMAIN_INIT))
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +0200544#define GLK_DISPLAY_DC_OFF_POWER_DOMAINS ( \
545 GLK_DISPLAY_POWERWELL_2_POWER_DOMAINS | \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200546 BIT_ULL(POWER_DOMAIN_MODESET) | \
547 BIT_ULL(POWER_DOMAIN_AUX_A) | \
548 BIT_ULL(POWER_DOMAIN_INIT))
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +0200549
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -0700550#define CNL_DISPLAY_POWERWELL_2_POWER_DOMAINS ( \
551 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
552 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
553 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
554 BIT_ULL(POWER_DOMAIN_PIPE_C) | \
555 BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
556 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
557 BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
558 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
559 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
560 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_LANES) | \
561 BIT_ULL(POWER_DOMAIN_PORT_DDI_E_LANES) | \
562 BIT_ULL(POWER_DOMAIN_AUX_B) | \
563 BIT_ULL(POWER_DOMAIN_AUX_C) | \
564 BIT_ULL(POWER_DOMAIN_AUX_D) | \
565 BIT_ULL(POWER_DOMAIN_AUDIO) | \
566 BIT_ULL(POWER_DOMAIN_VGA) | \
567 BIT_ULL(POWER_DOMAIN_INIT))
568#define CNL_DISPLAY_DDI_A_IO_POWER_DOMAINS ( \
569 BIT_ULL(POWER_DOMAIN_PORT_DDI_A_IO) | \
570 BIT_ULL(POWER_DOMAIN_PORT_DDI_E_IO) | \
571 BIT_ULL(POWER_DOMAIN_INIT))
572#define CNL_DISPLAY_DDI_B_IO_POWER_DOMAINS ( \
573 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_IO) | \
574 BIT_ULL(POWER_DOMAIN_INIT))
575#define CNL_DISPLAY_DDI_C_IO_POWER_DOMAINS ( \
576 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_IO) | \
577 BIT_ULL(POWER_DOMAIN_INIT))
578#define CNL_DISPLAY_DDI_D_IO_POWER_DOMAINS ( \
579 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_IO) | \
580 BIT_ULL(POWER_DOMAIN_INIT))
581#define CNL_DISPLAY_AUX_A_POWER_DOMAINS ( \
582 BIT_ULL(POWER_DOMAIN_AUX_A) | \
583 BIT_ULL(POWER_DOMAIN_INIT))
584#define CNL_DISPLAY_AUX_B_POWER_DOMAINS ( \
585 BIT_ULL(POWER_DOMAIN_AUX_B) | \
586 BIT_ULL(POWER_DOMAIN_INIT))
587#define CNL_DISPLAY_AUX_C_POWER_DOMAINS ( \
588 BIT_ULL(POWER_DOMAIN_AUX_C) | \
589 BIT_ULL(POWER_DOMAIN_INIT))
590#define CNL_DISPLAY_AUX_D_POWER_DOMAINS ( \
591 BIT_ULL(POWER_DOMAIN_AUX_D) | \
592 BIT_ULL(POWER_DOMAIN_INIT))
593#define CNL_DISPLAY_DC_OFF_POWER_DOMAINS ( \
594 CNL_DISPLAY_POWERWELL_2_POWER_DOMAINS | \
595 BIT_ULL(POWER_DOMAIN_MODESET) | \
596 BIT_ULL(POWER_DOMAIN_AUX_A) | \
597 BIT_ULL(POWER_DOMAIN_INIT))
598
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530599static void assert_can_enable_dc9(struct drm_i915_private *dev_priv)
600{
Imre Deakbfcdabe2016-04-01 16:02:37 +0300601 WARN_ONCE((I915_READ(DC_STATE_EN) & DC_STATE_EN_DC9),
602 "DC9 already programmed to be enabled.\n");
603 WARN_ONCE(I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC5,
604 "DC5 still not disabled to enable DC9.\n");
Imre Deake8a3a2a2017-06-29 18:37:00 +0300605 WARN_ONCE(I915_READ(HSW_PWR_WELL_DRIVER) &
606 SKL_POWER_WELL_REQ(SKL_DISP_PW_2),
607 "Power well 2 on.\n");
Imre Deakbfcdabe2016-04-01 16:02:37 +0300608 WARN_ONCE(intel_irqs_enabled(dev_priv),
609 "Interrupts not disabled yet.\n");
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530610
611 /*
612 * TODO: check for the following to verify the conditions to enter DC9
613 * state are satisfied:
614 * 1] Check relevant display engine registers to verify if mode set
615 * disable sequence was followed.
616 * 2] Check if display uninitialize sequence is initialized.
617 */
618}
619
620static void assert_can_disable_dc9(struct drm_i915_private *dev_priv)
621{
Imre Deakbfcdabe2016-04-01 16:02:37 +0300622 WARN_ONCE(intel_irqs_enabled(dev_priv),
623 "Interrupts not disabled yet.\n");
624 WARN_ONCE(I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC5,
625 "DC5 still not disabled.\n");
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530626
627 /*
628 * TODO: check for the following to verify DC9 state was indeed
629 * entered before programming to disable it:
630 * 1] Check relevant display engine registers to verify if mode
631 * set disable sequence was followed.
632 * 2] Check if display uninitialize sequence is initialized.
633 */
634}
635
Mika Kuoppala779cb5d2016-02-18 17:58:09 +0200636static void gen9_write_dc_state(struct drm_i915_private *dev_priv,
637 u32 state)
638{
639 int rewrites = 0;
640 int rereads = 0;
641 u32 v;
642
643 I915_WRITE(DC_STATE_EN, state);
644
645 /* It has been observed that disabling the dc6 state sometimes
646 * doesn't stick and dmc keeps returning old value. Make sure
647 * the write really sticks enough times and also force rewrite until
648 * we are confident that state is exactly what we want.
649 */
650 do {
651 v = I915_READ(DC_STATE_EN);
652
653 if (v != state) {
654 I915_WRITE(DC_STATE_EN, state);
655 rewrites++;
656 rereads = 0;
657 } else if (rereads++ > 5) {
658 break;
659 }
660
661 } while (rewrites < 100);
662
663 if (v != state)
664 DRM_ERROR("Writing dc state to 0x%x failed, now 0x%x\n",
665 state, v);
666
667 /* Most of the times we need one retry, avoid spam */
668 if (rewrites > 1)
669 DRM_DEBUG_KMS("Rewrote dc state to 0x%x %d times\n",
670 state, rewrites);
671}
672
Imre Deakda2f41d2016-04-20 20:27:56 +0300673static u32 gen9_dc_mask(struct drm_i915_private *dev_priv)
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530674{
Imre Deakda2f41d2016-04-20 20:27:56 +0300675 u32 mask;
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530676
Imre Deak13ae3a02015-11-04 19:24:16 +0200677 mask = DC_STATE_EN_UPTO_DC5;
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200678 if (IS_GEN9_LP(dev_priv))
Imre Deak13ae3a02015-11-04 19:24:16 +0200679 mask |= DC_STATE_EN_DC9;
680 else
681 mask |= DC_STATE_EN_UPTO_DC6;
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530682
Imre Deakda2f41d2016-04-20 20:27:56 +0300683 return mask;
684}
685
686void gen9_sanitize_dc_state(struct drm_i915_private *dev_priv)
687{
688 u32 val;
689
690 val = I915_READ(DC_STATE_EN) & gen9_dc_mask(dev_priv);
691
692 DRM_DEBUG_KMS("Resetting DC state tracking from %02x to %02x\n",
693 dev_priv->csr.dc_state, val);
694 dev_priv->csr.dc_state = val;
695}
696
697static void gen9_set_dc_state(struct drm_i915_private *dev_priv, uint32_t state)
698{
699 uint32_t val;
700 uint32_t mask;
701
Imre Deaka37baf32016-02-29 22:49:03 +0200702 if (WARN_ON_ONCE(state & ~dev_priv->csr.allowed_dc_mask))
703 state &= dev_priv->csr.allowed_dc_mask;
Patrik Jakobsson443646c2015-11-16 15:01:06 +0100704
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530705 val = I915_READ(DC_STATE_EN);
Imre Deakda2f41d2016-04-20 20:27:56 +0300706 mask = gen9_dc_mask(dev_priv);
Imre Deak13ae3a02015-11-04 19:24:16 +0200707 DRM_DEBUG_KMS("Setting DC state from %02x to %02x\n",
708 val & mask, state);
Patrik Jakobsson832dba82016-02-18 17:21:11 +0200709
710 /* Check if DMC is ignoring our DC state requests */
711 if ((val & mask) != dev_priv->csr.dc_state)
712 DRM_ERROR("DC state mismatch (0x%x -> 0x%x)\n",
713 dev_priv->csr.dc_state, val & mask);
714
Imre Deak13ae3a02015-11-04 19:24:16 +0200715 val &= ~mask;
716 val |= state;
Mika Kuoppala779cb5d2016-02-18 17:58:09 +0200717
718 gen9_write_dc_state(dev_priv, val);
Patrik Jakobsson832dba82016-02-18 17:21:11 +0200719
720 dev_priv->csr.dc_state = val & mask;
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530721}
722
Imre Deak13ae3a02015-11-04 19:24:16 +0200723void bxt_enable_dc9(struct drm_i915_private *dev_priv)
724{
725 assert_can_enable_dc9(dev_priv);
726
727 DRM_DEBUG_KMS("Enabling DC9\n");
728
Imre Deak78597992016-06-16 16:37:20 +0300729 intel_power_sequencer_reset(dev_priv);
Imre Deak13ae3a02015-11-04 19:24:16 +0200730 gen9_set_dc_state(dev_priv, DC_STATE_EN_DC9);
731}
732
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530733void bxt_disable_dc9(struct drm_i915_private *dev_priv)
734{
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530735 assert_can_disable_dc9(dev_priv);
736
737 DRM_DEBUG_KMS("Disabling DC9\n");
738
Imre Deak13ae3a02015-11-04 19:24:16 +0200739 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
Imre Deak8090ba82016-08-10 14:07:33 +0300740
741 intel_pps_unlock_regs_wa(dev_priv);
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530742}
743
Daniel Vetteraf5fead2015-10-28 23:58:57 +0200744static void assert_csr_loaded(struct drm_i915_private *dev_priv)
745{
746 WARN_ONCE(!I915_READ(CSR_PROGRAM(0)),
747 "CSR program storage start is NULL\n");
748 WARN_ONCE(!I915_READ(CSR_SSP_BASE), "CSR SSP Base Not fine\n");
749 WARN_ONCE(!I915_READ(CSR_HTP_SKL), "CSR HTP Not fine\n");
750}
751
Suketu Shah5aefb232015-04-16 14:22:10 +0530752static void assert_can_enable_dc5(struct drm_i915_private *dev_priv)
Suketu Shahdc174302015-04-17 19:46:16 +0530753{
Suketu Shah5aefb232015-04-16 14:22:10 +0530754 bool pg2_enabled = intel_display_power_well_is_enabled(dev_priv,
755 SKL_DISP_PW_2);
756
Jesse Barnes6ff8ab02015-09-10 08:20:28 -0700757 WARN_ONCE(pg2_enabled, "PG2 not disabled to enable DC5.\n");
Suketu Shah5aefb232015-04-16 14:22:10 +0530758
Jesse Barnes6ff8ab02015-09-10 08:20:28 -0700759 WARN_ONCE((I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC5),
760 "DC5 already programmed to be enabled.\n");
Imre Deakc9b88462015-12-15 20:10:34 +0200761 assert_rpm_wakelock_held(dev_priv);
Suketu Shah5aefb232015-04-16 14:22:10 +0530762
763 assert_csr_loaded(dev_priv);
764}
765
Imre Deakf62c79b2016-04-20 20:27:57 +0300766void gen9_enable_dc5(struct drm_i915_private *dev_priv)
Suketu Shah5aefb232015-04-16 14:22:10 +0530767{
Suketu Shah5aefb232015-04-16 14:22:10 +0530768 assert_can_enable_dc5(dev_priv);
A.Sunil Kamath6b457d32015-04-16 14:22:09 +0530769
770 DRM_DEBUG_KMS("Enabling DC5\n");
771
Imre Deak13ae3a02015-11-04 19:24:16 +0200772 gen9_set_dc_state(dev_priv, DC_STATE_EN_UPTO_DC5);
Suketu Shahdc174302015-04-17 19:46:16 +0530773}
774
Suketu Shah93c7cb62015-04-16 14:22:13 +0530775static void assert_can_enable_dc6(struct drm_i915_private *dev_priv)
Suketu Shahf75a1982015-04-16 14:22:11 +0530776{
Jesse Barnes6ff8ab02015-09-10 08:20:28 -0700777 WARN_ONCE(I915_READ(UTIL_PIN_CTL) & UTIL_PIN_ENABLE,
778 "Backlight is not disabled.\n");
779 WARN_ONCE((I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC6),
780 "DC6 already programmed to be enabled.\n");
Suketu Shah93c7cb62015-04-16 14:22:13 +0530781
782 assert_csr_loaded(dev_priv);
783}
784
Animesh Manna0a9d2be2015-09-29 11:01:59 +0530785void skl_enable_dc6(struct drm_i915_private *dev_priv)
Suketu Shah93c7cb62015-04-16 14:22:13 +0530786{
Suketu Shah93c7cb62015-04-16 14:22:13 +0530787 assert_can_enable_dc6(dev_priv);
A.Sunil Kamath74b4f372015-04-16 14:22:12 +0530788
789 DRM_DEBUG_KMS("Enabling DC6\n");
790
Imre Deak13ae3a02015-11-04 19:24:16 +0200791 gen9_set_dc_state(dev_priv, DC_STATE_EN_UPTO_DC6);
792
Suketu Shahf75a1982015-04-16 14:22:11 +0530793}
794
Animesh Manna0a9d2be2015-09-29 11:01:59 +0530795void skl_disable_dc6(struct drm_i915_private *dev_priv)
Suketu Shahf75a1982015-04-16 14:22:11 +0530796{
A.Sunil Kamath74b4f372015-04-16 14:22:12 +0530797 DRM_DEBUG_KMS("Disabling DC6\n");
798
Imre Deak13ae3a02015-11-04 19:24:16 +0200799 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
Suketu Shahf75a1982015-04-16 14:22:11 +0530800}
801
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000802static void skl_set_power_well(struct drm_i915_private *dev_priv,
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +0200803 struct i915_power_well *power_well, bool enable)
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000804{
805 uint32_t tmp, fuse_status;
806 uint32_t req_mask, state_mask;
Damien Lespiau2a518352015-03-06 18:50:49 +0000807 bool is_enabled, enable_requested, check_fuse_status = false;
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000808
809 tmp = I915_READ(HSW_PWR_WELL_DRIVER);
810 fuse_status = I915_READ(SKL_FUSE_STATUS);
811
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +0300812 switch (power_well->id) {
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000813 case SKL_DISP_PW_1:
Chris Wilson117c1142016-06-30 15:33:33 +0100814 if (intel_wait_for_register(dev_priv,
815 SKL_FUSE_STATUS,
816 SKL_FUSE_PG0_DIST_STATUS,
817 SKL_FUSE_PG0_DIST_STATUS,
818 1)) {
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000819 DRM_ERROR("PG0 not enabled\n");
820 return;
821 }
822 break;
823 case SKL_DISP_PW_2:
824 if (!(fuse_status & SKL_FUSE_PG1_DIST_STATUS)) {
825 DRM_ERROR("PG1 in disabled state\n");
826 return;
827 }
828 break;
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +0200829 case SKL_DISP_PW_MISC_IO:
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -0700830 case SKL_DISP_PW_DDI_A_E: /* GLK_DISP_PW_DDI_A, CNL_DISP_PW_DDI_A */
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000831 case SKL_DISP_PW_DDI_B:
832 case SKL_DISP_PW_DDI_C:
833 case SKL_DISP_PW_DDI_D:
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -0700834 case GLK_DISP_PW_AUX_A: /* CNL_DISP_PW_AUX_A */
835 case GLK_DISP_PW_AUX_B: /* CNL_DISP_PW_AUX_B */
836 case GLK_DISP_PW_AUX_C: /* CNL_DISP_PW_AUX_C */
837 case CNL_DISP_PW_AUX_D:
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000838 break;
839 default:
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +0300840 WARN(1, "Unknown power well %lu\n", power_well->id);
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000841 return;
842 }
843
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +0300844 req_mask = SKL_POWER_WELL_REQ(power_well->id);
Damien Lespiau2a518352015-03-06 18:50:49 +0000845 enable_requested = tmp & req_mask;
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +0300846 state_mask = SKL_POWER_WELL_STATE(power_well->id);
Damien Lespiau2a518352015-03-06 18:50:49 +0000847 is_enabled = tmp & state_mask;
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000848
Ville Syrjäläaae8ba82016-02-19 20:47:30 +0200849 if (!enable && enable_requested)
850 skl_power_well_pre_disable(dev_priv, power_well);
851
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000852 if (enable) {
Damien Lespiau2a518352015-03-06 18:50:49 +0000853 if (!enable_requested) {
Suketu Shahdc174302015-04-17 19:46:16 +0530854 WARN((tmp & state_mask) &&
855 !I915_READ(HSW_PWR_WELL_BIOS),
856 "Invalid for power well status to be enabled, unless done by the BIOS, \
857 when request is to disable!\n");
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000858 I915_WRITE(HSW_PWR_WELL_DRIVER, tmp | req_mask);
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000859 }
860
Damien Lespiau2a518352015-03-06 18:50:49 +0000861 if (!is_enabled) {
Damien Lespiau510e6fd2015-03-06 18:50:50 +0000862 DRM_DEBUG_KMS("Enabling %s\n", power_well->name);
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000863 check_fuse_status = true;
864 }
Imre Deak42d93662017-06-29 18:37:01 +0300865
866 gen9_wait_for_power_well_enable(dev_priv, power_well);
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000867 } else {
Damien Lespiau2a518352015-03-06 18:50:49 +0000868 if (enable_requested) {
Imre Deak4a76f292015-11-04 19:24:15 +0200869 I915_WRITE(HSW_PWR_WELL_DRIVER, tmp & ~req_mask);
870 POSTING_READ(HSW_PWR_WELL_DRIVER);
871 DRM_DEBUG_KMS("Disabling %s\n", power_well->name);
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000872 }
Imre Deakc6782b72016-04-05 13:26:05 +0300873
Imre Deak42d93662017-06-29 18:37:01 +0300874 gen9_wait_for_power_well_disable(dev_priv, power_well);
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000875 }
876
877 if (check_fuse_status) {
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +0300878 if (power_well->id == SKL_DISP_PW_1) {
Chris Wilson8b00f552016-06-30 15:33:34 +0100879 if (intel_wait_for_register(dev_priv,
880 SKL_FUSE_STATUS,
881 SKL_FUSE_PG1_DIST_STATUS,
882 SKL_FUSE_PG1_DIST_STATUS,
883 1))
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000884 DRM_ERROR("PG1 distributing status timeout\n");
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +0300885 } else if (power_well->id == SKL_DISP_PW_2) {
Chris Wilson8b00f552016-06-30 15:33:34 +0100886 if (intel_wait_for_register(dev_priv,
887 SKL_FUSE_STATUS,
888 SKL_FUSE_PG2_DIST_STATUS,
889 SKL_FUSE_PG2_DIST_STATUS,
890 1))
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000891 DRM_ERROR("PG2 distributing status timeout\n");
892 }
893 }
Damien Lespiaud14c0342015-03-06 18:50:51 +0000894
895 if (enable && !is_enabled)
896 skl_power_well_post_enable(dev_priv, power_well);
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000897}
898
Daniel Vetter9c065a72014-09-30 10:56:38 +0200899static void hsw_power_well_sync_hw(struct drm_i915_private *dev_priv,
900 struct i915_power_well *power_well)
901{
Imre Deak16e84912017-02-17 17:39:45 +0200902 /* Take over the request bit if set by BIOS. */
903 if (I915_READ(HSW_PWR_WELL_BIOS) & HSW_PWR_WELL_ENABLE_REQUEST) {
904 if (!(I915_READ(HSW_PWR_WELL_DRIVER) &
905 HSW_PWR_WELL_ENABLE_REQUEST))
906 I915_WRITE(HSW_PWR_WELL_DRIVER,
907 HSW_PWR_WELL_ENABLE_REQUEST);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200908 I915_WRITE(HSW_PWR_WELL_BIOS, 0);
Imre Deak16e84912017-02-17 17:39:45 +0200909 }
Daniel Vetter9c065a72014-09-30 10:56:38 +0200910}
911
912static void hsw_power_well_enable(struct drm_i915_private *dev_priv,
913 struct i915_power_well *power_well)
914{
915 hsw_set_power_well(dev_priv, power_well, true);
916}
917
918static void hsw_power_well_disable(struct drm_i915_private *dev_priv,
919 struct i915_power_well *power_well)
920{
921 hsw_set_power_well(dev_priv, power_well, false);
922}
923
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000924static bool skl_power_well_enabled(struct drm_i915_private *dev_priv,
925 struct i915_power_well *power_well)
926{
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +0300927 uint32_t mask = SKL_POWER_WELL_REQ(power_well->id) |
928 SKL_POWER_WELL_STATE(power_well->id);
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000929
930 return (I915_READ(HSW_PWR_WELL_DRIVER) & mask) == mask;
931}
932
933static void skl_power_well_sync_hw(struct drm_i915_private *dev_priv,
934 struct i915_power_well *power_well)
935{
Imre Deak14544e12017-02-17 17:39:44 +0200936 uint32_t mask = SKL_POWER_WELL_REQ(power_well->id);
937 uint32_t bios_req = I915_READ(HSW_PWR_WELL_BIOS);
938
Imre Deak16e84912017-02-17 17:39:45 +0200939 /* Take over the request bit if set by BIOS. */
Imre Deak14544e12017-02-17 17:39:44 +0200940 if (bios_req & mask) {
Imre Deak16e84912017-02-17 17:39:45 +0200941 uint32_t drv_req = I915_READ(HSW_PWR_WELL_DRIVER);
942
943 if (!(drv_req & mask))
944 I915_WRITE(HSW_PWR_WELL_DRIVER, drv_req | mask);
Imre Deak14544e12017-02-17 17:39:44 +0200945 I915_WRITE(HSW_PWR_WELL_BIOS, bios_req & ~mask);
946 }
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000947}
948
949static void skl_power_well_enable(struct drm_i915_private *dev_priv,
950 struct i915_power_well *power_well)
951{
952 skl_set_power_well(dev_priv, power_well, true);
953}
954
955static void skl_power_well_disable(struct drm_i915_private *dev_priv,
956 struct i915_power_well *power_well)
957{
958 skl_set_power_well(dev_priv, power_well, false);
959}
960
Imre Deak9c8d0b82016-06-13 16:44:34 +0300961static void bxt_dpio_cmn_power_well_enable(struct drm_i915_private *dev_priv,
962 struct i915_power_well *power_well)
963{
Ander Conselvan de Oliveira362624c2016-10-06 19:22:15 +0300964 bxt_ddi_phy_init(dev_priv, power_well->data);
Imre Deak9c8d0b82016-06-13 16:44:34 +0300965}
966
967static void bxt_dpio_cmn_power_well_disable(struct drm_i915_private *dev_priv,
968 struct i915_power_well *power_well)
969{
Ander Conselvan de Oliveira362624c2016-10-06 19:22:15 +0300970 bxt_ddi_phy_uninit(dev_priv, power_well->data);
Imre Deak9c8d0b82016-06-13 16:44:34 +0300971}
972
973static bool bxt_dpio_cmn_power_well_enabled(struct drm_i915_private *dev_priv,
974 struct i915_power_well *power_well)
975{
Ander Conselvan de Oliveira362624c2016-10-06 19:22:15 +0300976 return bxt_ddi_phy_is_enabled(dev_priv, power_well->data);
Imre Deak9c8d0b82016-06-13 16:44:34 +0300977}
978
Imre Deak9c8d0b82016-06-13 16:44:34 +0300979static void bxt_verify_ddi_phy_power_wells(struct drm_i915_private *dev_priv)
980{
981 struct i915_power_well *power_well;
982
983 power_well = lookup_power_well(dev_priv, BXT_DPIO_CMN_A);
984 if (power_well->count > 0)
Ander Conselvan de Oliveira362624c2016-10-06 19:22:15 +0300985 bxt_ddi_phy_verify_state(dev_priv, power_well->data);
Imre Deak9c8d0b82016-06-13 16:44:34 +0300986
987 power_well = lookup_power_well(dev_priv, BXT_DPIO_CMN_BC);
988 if (power_well->count > 0)
Ander Conselvan de Oliveira362624c2016-10-06 19:22:15 +0300989 bxt_ddi_phy_verify_state(dev_priv, power_well->data);
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +0200990
991 if (IS_GEMINILAKE(dev_priv)) {
992 power_well = lookup_power_well(dev_priv, GLK_DPIO_CMN_C);
993 if (power_well->count > 0)
994 bxt_ddi_phy_verify_state(dev_priv, power_well->data);
995 }
Imre Deak9c8d0b82016-06-13 16:44:34 +0300996}
997
Patrik Jakobsson9f836f92015-11-16 16:20:01 +0100998static bool gen9_dc_off_power_well_enabled(struct drm_i915_private *dev_priv,
999 struct i915_power_well *power_well)
1000{
1001 return (I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC5_DC6_MASK) == 0;
1002}
1003
Ville Syrjälä18a80672016-05-16 16:59:40 +03001004static void gen9_assert_dbuf_enabled(struct drm_i915_private *dev_priv)
1005{
1006 u32 tmp = I915_READ(DBUF_CTL);
1007
1008 WARN((tmp & (DBUF_POWER_STATE | DBUF_POWER_REQUEST)) !=
1009 (DBUF_POWER_STATE | DBUF_POWER_REQUEST),
1010 "Unexpected DBuf power power state (0x%08x)\n", tmp);
1011}
1012
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01001013static void gen9_dc_off_power_well_enable(struct drm_i915_private *dev_priv,
1014 struct i915_power_well *power_well)
1015{
Ville Syrjälä49cd97a2017-02-07 20:33:45 +02001016 struct intel_cdclk_state cdclk_state = {};
1017
Imre Deak5b773eb2016-02-29 22:49:05 +02001018 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
Imre Deakadc7f042016-04-04 17:27:10 +03001019
Ville Syrjälä49cd97a2017-02-07 20:33:45 +02001020 dev_priv->display.get_cdclk(dev_priv, &cdclk_state);
1021 WARN_ON(!intel_cdclk_state_compare(&dev_priv->cdclk.hw, &cdclk_state));
Ville Syrjälä342be922016-05-13 23:41:39 +03001022
Ville Syrjälä18a80672016-05-16 16:59:40 +03001023 gen9_assert_dbuf_enabled(dev_priv);
1024
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02001025 if (IS_GEN9_LP(dev_priv))
Imre Deak9c8d0b82016-06-13 16:44:34 +03001026 bxt_verify_ddi_phy_power_wells(dev_priv);
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01001027}
1028
1029static void gen9_dc_off_power_well_disable(struct drm_i915_private *dev_priv,
1030 struct i915_power_well *power_well)
1031{
Imre Deakf74ed082016-04-18 14:48:21 +03001032 if (!dev_priv->csr.dmc_payload)
1033 return;
1034
Imre Deaka37baf32016-02-29 22:49:03 +02001035 if (dev_priv->csr.allowed_dc_mask & DC_STATE_EN_UPTO_DC6)
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01001036 skl_enable_dc6(dev_priv);
Imre Deaka37baf32016-02-29 22:49:03 +02001037 else if (dev_priv->csr.allowed_dc_mask & DC_STATE_EN_UPTO_DC5)
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01001038 gen9_enable_dc5(dev_priv);
1039}
1040
Imre Deak3c1b38e2017-02-17 17:39:42 +02001041static void i9xx_power_well_sync_hw_noop(struct drm_i915_private *dev_priv,
1042 struct i915_power_well *power_well)
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01001043{
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01001044}
1045
Daniel Vetter9c065a72014-09-30 10:56:38 +02001046static void i9xx_always_on_power_well_noop(struct drm_i915_private *dev_priv,
1047 struct i915_power_well *power_well)
1048{
1049}
1050
1051static bool i9xx_always_on_power_well_enabled(struct drm_i915_private *dev_priv,
1052 struct i915_power_well *power_well)
1053{
1054 return true;
1055}
1056
Ville Syrjälä2ee0da12017-06-01 17:36:16 +03001057static void i830_pipes_power_well_enable(struct drm_i915_private *dev_priv,
1058 struct i915_power_well *power_well)
1059{
1060 if ((I915_READ(PIPECONF(PIPE_A)) & PIPECONF_ENABLE) == 0)
1061 i830_enable_pipe(dev_priv, PIPE_A);
1062 if ((I915_READ(PIPECONF(PIPE_B)) & PIPECONF_ENABLE) == 0)
1063 i830_enable_pipe(dev_priv, PIPE_B);
1064}
1065
1066static void i830_pipes_power_well_disable(struct drm_i915_private *dev_priv,
1067 struct i915_power_well *power_well)
1068{
1069 i830_disable_pipe(dev_priv, PIPE_B);
1070 i830_disable_pipe(dev_priv, PIPE_A);
1071}
1072
1073static bool i830_pipes_power_well_enabled(struct drm_i915_private *dev_priv,
1074 struct i915_power_well *power_well)
1075{
1076 return I915_READ(PIPECONF(PIPE_A)) & PIPECONF_ENABLE &&
1077 I915_READ(PIPECONF(PIPE_B)) & PIPECONF_ENABLE;
1078}
1079
1080static void i830_pipes_power_well_sync_hw(struct drm_i915_private *dev_priv,
1081 struct i915_power_well *power_well)
1082{
1083 if (power_well->count > 0)
1084 i830_pipes_power_well_enable(dev_priv, power_well);
1085 else
1086 i830_pipes_power_well_disable(dev_priv, power_well);
1087}
1088
Daniel Vetter9c065a72014-09-30 10:56:38 +02001089static void vlv_set_power_well(struct drm_i915_private *dev_priv,
1090 struct i915_power_well *power_well, bool enable)
1091{
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001092 enum punit_power_well power_well_id = power_well->id;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001093 u32 mask;
1094 u32 state;
1095 u32 ctrl;
1096
1097 mask = PUNIT_PWRGT_MASK(power_well_id);
1098 state = enable ? PUNIT_PWRGT_PWR_ON(power_well_id) :
1099 PUNIT_PWRGT_PWR_GATE(power_well_id);
1100
1101 mutex_lock(&dev_priv->rps.hw_lock);
1102
1103#define COND \
1104 ((vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_STATUS) & mask) == state)
1105
1106 if (COND)
1107 goto out;
1108
1109 ctrl = vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_CTRL);
1110 ctrl &= ~mask;
1111 ctrl |= state;
1112 vlv_punit_write(dev_priv, PUNIT_REG_PWRGT_CTRL, ctrl);
1113
1114 if (wait_for(COND, 100))
Masanari Iida7e35ab82015-05-10 01:00:23 +09001115 DRM_ERROR("timeout setting power well state %08x (%08x)\n",
Daniel Vetter9c065a72014-09-30 10:56:38 +02001116 state,
1117 vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_CTRL));
1118
1119#undef COND
1120
1121out:
1122 mutex_unlock(&dev_priv->rps.hw_lock);
1123}
1124
Daniel Vetter9c065a72014-09-30 10:56:38 +02001125static void vlv_power_well_enable(struct drm_i915_private *dev_priv,
1126 struct i915_power_well *power_well)
1127{
1128 vlv_set_power_well(dev_priv, power_well, true);
1129}
1130
1131static void vlv_power_well_disable(struct drm_i915_private *dev_priv,
1132 struct i915_power_well *power_well)
1133{
1134 vlv_set_power_well(dev_priv, power_well, false);
1135}
1136
1137static bool vlv_power_well_enabled(struct drm_i915_private *dev_priv,
1138 struct i915_power_well *power_well)
1139{
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001140 int power_well_id = power_well->id;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001141 bool enabled = false;
1142 u32 mask;
1143 u32 state;
1144 u32 ctrl;
1145
1146 mask = PUNIT_PWRGT_MASK(power_well_id);
1147 ctrl = PUNIT_PWRGT_PWR_ON(power_well_id);
1148
1149 mutex_lock(&dev_priv->rps.hw_lock);
1150
1151 state = vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_STATUS) & mask;
1152 /*
1153 * We only ever set the power-on and power-gate states, anything
1154 * else is unexpected.
1155 */
1156 WARN_ON(state != PUNIT_PWRGT_PWR_ON(power_well_id) &&
1157 state != PUNIT_PWRGT_PWR_GATE(power_well_id));
1158 if (state == ctrl)
1159 enabled = true;
1160
1161 /*
1162 * A transient state at this point would mean some unexpected party
1163 * is poking at the power controls too.
1164 */
1165 ctrl = vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_CTRL) & mask;
1166 WARN_ON(ctrl != state);
1167
1168 mutex_unlock(&dev_priv->rps.hw_lock);
1169
1170 return enabled;
1171}
1172
Ville Syrjälä766078d2016-04-11 16:56:30 +03001173static void vlv_init_display_clock_gating(struct drm_i915_private *dev_priv)
1174{
Hans de Goede721d4842016-12-02 15:29:04 +01001175 u32 val;
1176
1177 /*
1178 * On driver load, a pipe may be active and driving a DSI display.
1179 * Preserve DPOUNIT_CLOCK_GATE_DISABLE to avoid the pipe getting stuck
1180 * (and never recovering) in this case. intel_dsi_post_disable() will
1181 * clear it when we turn off the display.
1182 */
1183 val = I915_READ(DSPCLK_GATE_D);
1184 val &= DPOUNIT_CLOCK_GATE_DISABLE;
1185 val |= VRHUNIT_CLOCK_GATE_DISABLE;
1186 I915_WRITE(DSPCLK_GATE_D, val);
Ville Syrjälä766078d2016-04-11 16:56:30 +03001187
1188 /*
1189 * Disable trickle feed and enable pnd deadline calculation
1190 */
1191 I915_WRITE(MI_ARB_VLV, MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE);
1192 I915_WRITE(CBR1_VLV, 0);
Ville Syrjälä19ab4ed2016-04-27 17:43:22 +03001193
1194 WARN_ON(dev_priv->rawclk_freq == 0);
1195
1196 I915_WRITE(RAWCLK_FREQ_VLV,
1197 DIV_ROUND_CLOSEST(dev_priv->rawclk_freq, 1000));
Ville Syrjälä766078d2016-04-11 16:56:30 +03001198}
1199
Ville Syrjälä2be7d542015-06-29 15:25:51 +03001200static void vlv_display_power_well_init(struct drm_i915_private *dev_priv)
Daniel Vetter9c065a72014-09-30 10:56:38 +02001201{
Lyude9504a892016-06-21 17:03:42 -04001202 struct intel_encoder *encoder;
Ville Syrjälä5a8fbb72015-06-29 15:25:53 +03001203 enum pipe pipe;
1204
1205 /*
1206 * Enable the CRI clock source so we can get at the
1207 * display and the reference clock for VGA
1208 * hotplug / manual detection. Supposedly DSI also
1209 * needs the ref clock up and running.
1210 *
1211 * CHV DPLL B/C have some issues if VGA mode is enabled.
1212 */
Tvrtko Ursulin801388c2016-11-16 08:55:44 +00001213 for_each_pipe(dev_priv, pipe) {
Ville Syrjälä5a8fbb72015-06-29 15:25:53 +03001214 u32 val = I915_READ(DPLL(pipe));
1215
1216 val |= DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
1217 if (pipe != PIPE_A)
1218 val |= DPLL_INTEGRATED_CRI_CLK_VLV;
1219
1220 I915_WRITE(DPLL(pipe), val);
1221 }
Daniel Vetter9c065a72014-09-30 10:56:38 +02001222
Ville Syrjälä766078d2016-04-11 16:56:30 +03001223 vlv_init_display_clock_gating(dev_priv);
1224
Daniel Vetter9c065a72014-09-30 10:56:38 +02001225 spin_lock_irq(&dev_priv->irq_lock);
1226 valleyview_enable_display_irqs(dev_priv);
1227 spin_unlock_irq(&dev_priv->irq_lock);
1228
1229 /*
1230 * During driver initialization/resume we can avoid restoring the
1231 * part of the HW/SW state that will be inited anyway explicitly.
1232 */
1233 if (dev_priv->power_domains.initializing)
1234 return;
1235
Daniel Vetterb9632912014-09-30 10:56:44 +02001236 intel_hpd_init(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001237
Lyude9504a892016-06-21 17:03:42 -04001238 /* Re-enable the ADPA, if we have one */
1239 for_each_intel_encoder(&dev_priv->drm, encoder) {
1240 if (encoder->type == INTEL_OUTPUT_ANALOG)
1241 intel_crt_reset(&encoder->base);
1242 }
1243
Tvrtko Ursulin29b74b72016-11-16 08:55:39 +00001244 i915_redisable_vga_power_on(dev_priv);
Imre Deak8090ba82016-08-10 14:07:33 +03001245
1246 intel_pps_unlock_regs_wa(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001247}
1248
Ville Syrjälä2be7d542015-06-29 15:25:51 +03001249static void vlv_display_power_well_deinit(struct drm_i915_private *dev_priv)
1250{
1251 spin_lock_irq(&dev_priv->irq_lock);
1252 valleyview_disable_display_irqs(dev_priv);
1253 spin_unlock_irq(&dev_priv->irq_lock);
1254
Ville Syrjälä2230fde2016-02-19 18:41:52 +02001255 /* make sure we're done processing display irqs */
Chris Wilson91c8a322016-07-05 10:40:23 +01001256 synchronize_irq(dev_priv->drm.irq);
Ville Syrjälä2230fde2016-02-19 18:41:52 +02001257
Imre Deak78597992016-06-16 16:37:20 +03001258 intel_power_sequencer_reset(dev_priv);
Lyude19625e82016-06-21 17:03:44 -04001259
Lyudeb64b5402016-10-26 12:36:09 -04001260 /* Prevent us from re-enabling polling on accident in late suspend */
1261 if (!dev_priv->drm.dev->power.is_suspended)
1262 intel_hpd_poll_init(dev_priv);
Ville Syrjälä2be7d542015-06-29 15:25:51 +03001263}
1264
1265static void vlv_display_power_well_enable(struct drm_i915_private *dev_priv,
1266 struct i915_power_well *power_well)
1267{
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001268 WARN_ON_ONCE(power_well->id != PUNIT_POWER_WELL_DISP2D);
Ville Syrjälä2be7d542015-06-29 15:25:51 +03001269
1270 vlv_set_power_well(dev_priv, power_well, true);
1271
1272 vlv_display_power_well_init(dev_priv);
1273}
1274
Daniel Vetter9c065a72014-09-30 10:56:38 +02001275static void vlv_display_power_well_disable(struct drm_i915_private *dev_priv,
1276 struct i915_power_well *power_well)
1277{
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001278 WARN_ON_ONCE(power_well->id != PUNIT_POWER_WELL_DISP2D);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001279
Ville Syrjälä2be7d542015-06-29 15:25:51 +03001280 vlv_display_power_well_deinit(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001281
1282 vlv_set_power_well(dev_priv, power_well, false);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001283}
1284
1285static void vlv_dpio_cmn_power_well_enable(struct drm_i915_private *dev_priv,
1286 struct i915_power_well *power_well)
1287{
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001288 WARN_ON_ONCE(power_well->id != PUNIT_POWER_WELL_DPIO_CMN_BC);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001289
Ville Syrjälä5a8fbb72015-06-29 15:25:53 +03001290 /* since ref/cri clock was enabled */
Daniel Vetter9c065a72014-09-30 10:56:38 +02001291 udelay(1); /* >10ns for cmnreset, >0ns for sidereset */
1292
1293 vlv_set_power_well(dev_priv, power_well, true);
1294
1295 /*
1296 * From VLV2A0_DP_eDP_DPIO_driver_vbios_notes_10.docx -
1297 * 6. De-assert cmn_reset/side_reset. Same as VLV X0.
1298 * a. GUnit 0x2110 bit[0] set to 1 (def 0)
1299 * b. The other bits such as sfr settings / modesel may all
1300 * be set to 0.
1301 *
1302 * This should only be done on init and resume from S3 with
1303 * both PLLs disabled, or we risk losing DPIO and PLL
1304 * synchronization.
1305 */
1306 I915_WRITE(DPIO_CTL, I915_READ(DPIO_CTL) | DPIO_CMNRST);
1307}
1308
1309static void vlv_dpio_cmn_power_well_disable(struct drm_i915_private *dev_priv,
1310 struct i915_power_well *power_well)
1311{
1312 enum pipe pipe;
1313
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001314 WARN_ON_ONCE(power_well->id != PUNIT_POWER_WELL_DPIO_CMN_BC);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001315
1316 for_each_pipe(dev_priv, pipe)
1317 assert_pll_disabled(dev_priv, pipe);
1318
1319 /* Assert common reset */
1320 I915_WRITE(DPIO_CTL, I915_READ(DPIO_CTL) & ~DPIO_CMNRST);
1321
1322 vlv_set_power_well(dev_priv, power_well, false);
1323}
1324
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001325#define POWER_DOMAIN_MASK (GENMASK_ULL(POWER_DOMAIN_NUM - 1, 0))
Ville Syrjälä30142272015-07-08 23:46:01 +03001326
1327static struct i915_power_well *lookup_power_well(struct drm_i915_private *dev_priv,
1328 int power_well_id)
1329{
1330 struct i915_power_domains *power_domains = &dev_priv->power_domains;
Ville Syrjälä30142272015-07-08 23:46:01 +03001331 int i;
1332
Imre Deakfc17f222015-11-04 19:24:11 +02001333 for (i = 0; i < power_domains->power_well_count; i++) {
1334 struct i915_power_well *power_well;
1335
1336 power_well = &power_domains->power_wells[i];
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001337 if (power_well->id == power_well_id)
Ville Syrjälä30142272015-07-08 23:46:01 +03001338 return power_well;
1339 }
1340
1341 return NULL;
1342}
1343
1344#define BITS_SET(val, bits) (((val) & (bits)) == (bits))
1345
1346static void assert_chv_phy_status(struct drm_i915_private *dev_priv)
1347{
1348 struct i915_power_well *cmn_bc =
1349 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_BC);
1350 struct i915_power_well *cmn_d =
1351 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_D);
1352 u32 phy_control = dev_priv->chv_phy_control;
1353 u32 phy_status = 0;
Ville Syrjälä3be60de2015-09-08 18:05:45 +03001354 u32 phy_status_mask = 0xffffffff;
Ville Syrjälä30142272015-07-08 23:46:01 +03001355
Ville Syrjälä3be60de2015-09-08 18:05:45 +03001356 /*
1357 * The BIOS can leave the PHY is some weird state
1358 * where it doesn't fully power down some parts.
1359 * Disable the asserts until the PHY has been fully
1360 * reset (ie. the power well has been disabled at
1361 * least once).
1362 */
1363 if (!dev_priv->chv_phy_assert[DPIO_PHY0])
1364 phy_status_mask &= ~(PHY_STATUS_CMN_LDO(DPIO_PHY0, DPIO_CH0) |
1365 PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH0, 0) |
1366 PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH0, 1) |
1367 PHY_STATUS_CMN_LDO(DPIO_PHY0, DPIO_CH1) |
1368 PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH1, 0) |
1369 PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH1, 1));
1370
1371 if (!dev_priv->chv_phy_assert[DPIO_PHY1])
1372 phy_status_mask &= ~(PHY_STATUS_CMN_LDO(DPIO_PHY1, DPIO_CH0) |
1373 PHY_STATUS_SPLINE_LDO(DPIO_PHY1, DPIO_CH0, 0) |
1374 PHY_STATUS_SPLINE_LDO(DPIO_PHY1, DPIO_CH0, 1));
1375
Ville Syrjälä30142272015-07-08 23:46:01 +03001376 if (cmn_bc->ops->is_enabled(dev_priv, cmn_bc)) {
1377 phy_status |= PHY_POWERGOOD(DPIO_PHY0);
1378
1379 /* this assumes override is only used to enable lanes */
1380 if ((phy_control & PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY0, DPIO_CH0)) == 0)
1381 phy_control |= PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH0);
1382
1383 if ((phy_control & PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY0, DPIO_CH1)) == 0)
1384 phy_control |= PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH1);
1385
1386 /* CL1 is on whenever anything is on in either channel */
1387 if (BITS_SET(phy_control,
1388 PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH0) |
1389 PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH1)))
1390 phy_status |= PHY_STATUS_CMN_LDO(DPIO_PHY0, DPIO_CH0);
1391
1392 /*
1393 * The DPLLB check accounts for the pipe B + port A usage
1394 * with CL2 powered up but all the lanes in the second channel
1395 * powered down.
1396 */
1397 if (BITS_SET(phy_control,
1398 PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH1)) &&
1399 (I915_READ(DPLL(PIPE_B)) & DPLL_VCO_ENABLE) == 0)
1400 phy_status |= PHY_STATUS_CMN_LDO(DPIO_PHY0, DPIO_CH1);
1401
1402 if (BITS_SET(phy_control,
1403 PHY_CH_POWER_DOWN_OVRD(0x3, DPIO_PHY0, DPIO_CH0)))
1404 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH0, 0);
1405 if (BITS_SET(phy_control,
1406 PHY_CH_POWER_DOWN_OVRD(0xc, DPIO_PHY0, DPIO_CH0)))
1407 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH0, 1);
1408
1409 if (BITS_SET(phy_control,
1410 PHY_CH_POWER_DOWN_OVRD(0x3, DPIO_PHY0, DPIO_CH1)))
1411 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH1, 0);
1412 if (BITS_SET(phy_control,
1413 PHY_CH_POWER_DOWN_OVRD(0xc, DPIO_PHY0, DPIO_CH1)))
1414 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH1, 1);
1415 }
1416
1417 if (cmn_d->ops->is_enabled(dev_priv, cmn_d)) {
1418 phy_status |= PHY_POWERGOOD(DPIO_PHY1);
1419
1420 /* this assumes override is only used to enable lanes */
1421 if ((phy_control & PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY1, DPIO_CH0)) == 0)
1422 phy_control |= PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY1, DPIO_CH0);
1423
1424 if (BITS_SET(phy_control,
1425 PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY1, DPIO_CH0)))
1426 phy_status |= PHY_STATUS_CMN_LDO(DPIO_PHY1, DPIO_CH0);
1427
1428 if (BITS_SET(phy_control,
1429 PHY_CH_POWER_DOWN_OVRD(0x3, DPIO_PHY1, DPIO_CH0)))
1430 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY1, DPIO_CH0, 0);
1431 if (BITS_SET(phy_control,
1432 PHY_CH_POWER_DOWN_OVRD(0xc, DPIO_PHY1, DPIO_CH0)))
1433 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY1, DPIO_CH0, 1);
1434 }
1435
Ville Syrjälä3be60de2015-09-08 18:05:45 +03001436 phy_status &= phy_status_mask;
1437
Ville Syrjälä30142272015-07-08 23:46:01 +03001438 /*
1439 * The PHY may be busy with some initial calibration and whatnot,
1440 * so the power state can take a while to actually change.
1441 */
Chris Wilson919fcd52016-06-30 15:33:35 +01001442 if (intel_wait_for_register(dev_priv,
1443 DISPLAY_PHY_STATUS,
1444 phy_status_mask,
1445 phy_status,
1446 10))
1447 DRM_ERROR("Unexpected PHY_STATUS 0x%08x, expected 0x%08x (PHY_CONTROL=0x%08x)\n",
1448 I915_READ(DISPLAY_PHY_STATUS) & phy_status_mask,
1449 phy_status, dev_priv->chv_phy_control);
Ville Syrjälä30142272015-07-08 23:46:01 +03001450}
1451
1452#undef BITS_SET
1453
Daniel Vetter9c065a72014-09-30 10:56:38 +02001454static void chv_dpio_cmn_power_well_enable(struct drm_i915_private *dev_priv,
1455 struct i915_power_well *power_well)
1456{
1457 enum dpio_phy phy;
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001458 enum pipe pipe;
1459 uint32_t tmp;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001460
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001461 WARN_ON_ONCE(power_well->id != PUNIT_POWER_WELL_DPIO_CMN_BC &&
1462 power_well->id != PUNIT_POWER_WELL_DPIO_CMN_D);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001463
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001464 if (power_well->id == PUNIT_POWER_WELL_DPIO_CMN_BC) {
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001465 pipe = PIPE_A;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001466 phy = DPIO_PHY0;
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001467 } else {
1468 pipe = PIPE_C;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001469 phy = DPIO_PHY1;
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001470 }
Ville Syrjälä5a8fbb72015-06-29 15:25:53 +03001471
1472 /* since ref/cri clock was enabled */
Daniel Vetter9c065a72014-09-30 10:56:38 +02001473 udelay(1); /* >10ns for cmnreset, >0ns for sidereset */
1474 vlv_set_power_well(dev_priv, power_well, true);
1475
1476 /* Poll for phypwrgood signal */
Chris Wilsonffebb832016-06-30 15:33:36 +01001477 if (intel_wait_for_register(dev_priv,
1478 DISPLAY_PHY_STATUS,
1479 PHY_POWERGOOD(phy),
1480 PHY_POWERGOOD(phy),
1481 1))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001482 DRM_ERROR("Display PHY %d is not power up\n", phy);
1483
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001484 mutex_lock(&dev_priv->sb_lock);
1485
1486 /* Enable dynamic power down */
1487 tmp = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW28);
Ville Syrjäläee279212015-07-08 23:45:57 +03001488 tmp |= DPIO_DYNPWRDOWNEN_CH0 | DPIO_CL1POWERDOWNEN |
1489 DPIO_SUS_CLK_CONFIG_GATE_CLKREQ;
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001490 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW28, tmp);
1491
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001492 if (power_well->id == PUNIT_POWER_WELL_DPIO_CMN_BC) {
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001493 tmp = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW6_CH1);
1494 tmp |= DPIO_DYNPWRDOWNEN_CH1;
1495 vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW6_CH1, tmp);
Ville Syrjälä3e288782015-07-08 23:45:58 +03001496 } else {
1497 /*
1498 * Force the non-existing CL2 off. BXT does this
1499 * too, so maybe it saves some power even though
1500 * CL2 doesn't exist?
1501 */
1502 tmp = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW30);
1503 tmp |= DPIO_CL2_LDOFUSE_PWRENB;
1504 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW30, tmp);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001505 }
1506
1507 mutex_unlock(&dev_priv->sb_lock);
1508
Ville Syrjälä70722462015-04-10 18:21:28 +03001509 dev_priv->chv_phy_control |= PHY_COM_LANE_RESET_DEASSERT(phy);
1510 I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001511
1512 DRM_DEBUG_KMS("Enabled DPIO PHY%d (PHY_CONTROL=0x%08x)\n",
1513 phy, dev_priv->chv_phy_control);
Ville Syrjälä30142272015-07-08 23:46:01 +03001514
1515 assert_chv_phy_status(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001516}
1517
1518static void chv_dpio_cmn_power_well_disable(struct drm_i915_private *dev_priv,
1519 struct i915_power_well *power_well)
1520{
1521 enum dpio_phy phy;
1522
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001523 WARN_ON_ONCE(power_well->id != PUNIT_POWER_WELL_DPIO_CMN_BC &&
1524 power_well->id != PUNIT_POWER_WELL_DPIO_CMN_D);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001525
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001526 if (power_well->id == PUNIT_POWER_WELL_DPIO_CMN_BC) {
Daniel Vetter9c065a72014-09-30 10:56:38 +02001527 phy = DPIO_PHY0;
1528 assert_pll_disabled(dev_priv, PIPE_A);
1529 assert_pll_disabled(dev_priv, PIPE_B);
1530 } else {
1531 phy = DPIO_PHY1;
1532 assert_pll_disabled(dev_priv, PIPE_C);
1533 }
1534
Ville Syrjälä70722462015-04-10 18:21:28 +03001535 dev_priv->chv_phy_control &= ~PHY_COM_LANE_RESET_DEASSERT(phy);
1536 I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001537
1538 vlv_set_power_well(dev_priv, power_well, false);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001539
1540 DRM_DEBUG_KMS("Disabled DPIO PHY%d (PHY_CONTROL=0x%08x)\n",
1541 phy, dev_priv->chv_phy_control);
Ville Syrjälä30142272015-07-08 23:46:01 +03001542
Ville Syrjälä3be60de2015-09-08 18:05:45 +03001543 /* PHY is fully reset now, so we can enable the PHY state asserts */
1544 dev_priv->chv_phy_assert[phy] = true;
1545
Ville Syrjälä30142272015-07-08 23:46:01 +03001546 assert_chv_phy_status(dev_priv);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001547}
1548
Ville Syrjälä6669e392015-07-08 23:46:00 +03001549static void assert_chv_phy_powergate(struct drm_i915_private *dev_priv, enum dpio_phy phy,
1550 enum dpio_channel ch, bool override, unsigned int mask)
1551{
1552 enum pipe pipe = phy == DPIO_PHY0 ? PIPE_A : PIPE_C;
1553 u32 reg, val, expected, actual;
1554
Ville Syrjälä3be60de2015-09-08 18:05:45 +03001555 /*
1556 * The BIOS can leave the PHY is some weird state
1557 * where it doesn't fully power down some parts.
1558 * Disable the asserts until the PHY has been fully
1559 * reset (ie. the power well has been disabled at
1560 * least once).
1561 */
1562 if (!dev_priv->chv_phy_assert[phy])
1563 return;
1564
Ville Syrjälä6669e392015-07-08 23:46:00 +03001565 if (ch == DPIO_CH0)
1566 reg = _CHV_CMN_DW0_CH0;
1567 else
1568 reg = _CHV_CMN_DW6_CH1;
1569
1570 mutex_lock(&dev_priv->sb_lock);
1571 val = vlv_dpio_read(dev_priv, pipe, reg);
1572 mutex_unlock(&dev_priv->sb_lock);
1573
1574 /*
1575 * This assumes !override is only used when the port is disabled.
1576 * All lanes should power down even without the override when
1577 * the port is disabled.
1578 */
1579 if (!override || mask == 0xf) {
1580 expected = DPIO_ALLDL_POWERDOWN | DPIO_ANYDL_POWERDOWN;
1581 /*
1582 * If CH1 common lane is not active anymore
1583 * (eg. for pipe B DPLL) the entire channel will
1584 * shut down, which causes the common lane registers
1585 * to read as 0. That means we can't actually check
1586 * the lane power down status bits, but as the entire
1587 * register reads as 0 it's a good indication that the
1588 * channel is indeed entirely powered down.
1589 */
1590 if (ch == DPIO_CH1 && val == 0)
1591 expected = 0;
1592 } else if (mask != 0x0) {
1593 expected = DPIO_ANYDL_POWERDOWN;
1594 } else {
1595 expected = 0;
1596 }
1597
1598 if (ch == DPIO_CH0)
1599 actual = val >> DPIO_ANYDL_POWERDOWN_SHIFT_CH0;
1600 else
1601 actual = val >> DPIO_ANYDL_POWERDOWN_SHIFT_CH1;
1602 actual &= DPIO_ALLDL_POWERDOWN | DPIO_ANYDL_POWERDOWN;
1603
1604 WARN(actual != expected,
1605 "Unexpected DPIO lane power down: all %d, any %d. Expected: all %d, any %d. (0x%x = 0x%08x)\n",
1606 !!(actual & DPIO_ALLDL_POWERDOWN), !!(actual & DPIO_ANYDL_POWERDOWN),
1607 !!(expected & DPIO_ALLDL_POWERDOWN), !!(expected & DPIO_ANYDL_POWERDOWN),
1608 reg, val);
1609}
1610
Ville Syrjäläb0b33842015-07-08 23:45:55 +03001611bool chv_phy_powergate_ch(struct drm_i915_private *dev_priv, enum dpio_phy phy,
1612 enum dpio_channel ch, bool override)
1613{
1614 struct i915_power_domains *power_domains = &dev_priv->power_domains;
1615 bool was_override;
1616
1617 mutex_lock(&power_domains->lock);
1618
1619 was_override = dev_priv->chv_phy_control & PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
1620
1621 if (override == was_override)
1622 goto out;
1623
1624 if (override)
1625 dev_priv->chv_phy_control |= PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
1626 else
1627 dev_priv->chv_phy_control &= ~PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
1628
1629 I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
1630
1631 DRM_DEBUG_KMS("Power gating DPIO PHY%d CH%d (DPIO_PHY_CONTROL=0x%08x)\n",
1632 phy, ch, dev_priv->chv_phy_control);
1633
Ville Syrjälä30142272015-07-08 23:46:01 +03001634 assert_chv_phy_status(dev_priv);
1635
Ville Syrjäläb0b33842015-07-08 23:45:55 +03001636out:
1637 mutex_unlock(&power_domains->lock);
1638
1639 return was_override;
1640}
1641
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001642void chv_phy_powergate_lanes(struct intel_encoder *encoder,
1643 bool override, unsigned int mask)
1644{
1645 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
1646 struct i915_power_domains *power_domains = &dev_priv->power_domains;
1647 enum dpio_phy phy = vlv_dport_to_phy(enc_to_dig_port(&encoder->base));
1648 enum dpio_channel ch = vlv_dport_to_channel(enc_to_dig_port(&encoder->base));
1649
1650 mutex_lock(&power_domains->lock);
1651
1652 dev_priv->chv_phy_control &= ~PHY_CH_POWER_DOWN_OVRD(0xf, phy, ch);
1653 dev_priv->chv_phy_control |= PHY_CH_POWER_DOWN_OVRD(mask, phy, ch);
1654
1655 if (override)
1656 dev_priv->chv_phy_control |= PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
1657 else
1658 dev_priv->chv_phy_control &= ~PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
1659
1660 I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
1661
1662 DRM_DEBUG_KMS("Power gating DPIO PHY%d CH%d lanes 0x%x (PHY_CONTROL=0x%08x)\n",
1663 phy, ch, mask, dev_priv->chv_phy_control);
1664
Ville Syrjälä30142272015-07-08 23:46:01 +03001665 assert_chv_phy_status(dev_priv);
1666
Ville Syrjälä6669e392015-07-08 23:46:00 +03001667 assert_chv_phy_powergate(dev_priv, phy, ch, override, mask);
1668
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001669 mutex_unlock(&power_domains->lock);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001670}
1671
1672static bool chv_pipe_power_well_enabled(struct drm_i915_private *dev_priv,
1673 struct i915_power_well *power_well)
1674{
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001675 enum pipe pipe = power_well->id;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001676 bool enabled;
1677 u32 state, ctrl;
1678
1679 mutex_lock(&dev_priv->rps.hw_lock);
1680
1681 state = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & DP_SSS_MASK(pipe);
1682 /*
1683 * We only ever set the power-on and power-gate states, anything
1684 * else is unexpected.
1685 */
1686 WARN_ON(state != DP_SSS_PWR_ON(pipe) && state != DP_SSS_PWR_GATE(pipe));
1687 enabled = state == DP_SSS_PWR_ON(pipe);
1688
1689 /*
1690 * A transient state at this point would mean some unexpected party
1691 * is poking at the power controls too.
1692 */
1693 ctrl = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & DP_SSC_MASK(pipe);
1694 WARN_ON(ctrl << 16 != state);
1695
1696 mutex_unlock(&dev_priv->rps.hw_lock);
1697
1698 return enabled;
1699}
1700
1701static void chv_set_pipe_power_well(struct drm_i915_private *dev_priv,
1702 struct i915_power_well *power_well,
1703 bool enable)
1704{
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001705 enum pipe pipe = power_well->id;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001706 u32 state;
1707 u32 ctrl;
1708
1709 state = enable ? DP_SSS_PWR_ON(pipe) : DP_SSS_PWR_GATE(pipe);
1710
1711 mutex_lock(&dev_priv->rps.hw_lock);
1712
1713#define COND \
1714 ((vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & DP_SSS_MASK(pipe)) == state)
1715
1716 if (COND)
1717 goto out;
1718
1719 ctrl = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ);
1720 ctrl &= ~DP_SSC_MASK(pipe);
1721 ctrl |= enable ? DP_SSC_PWR_ON(pipe) : DP_SSC_PWR_GATE(pipe);
1722 vlv_punit_write(dev_priv, PUNIT_REG_DSPFREQ, ctrl);
1723
1724 if (wait_for(COND, 100))
Masanari Iida7e35ab82015-05-10 01:00:23 +09001725 DRM_ERROR("timeout setting power well state %08x (%08x)\n",
Daniel Vetter9c065a72014-09-30 10:56:38 +02001726 state,
1727 vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ));
1728
1729#undef COND
1730
1731out:
1732 mutex_unlock(&dev_priv->rps.hw_lock);
1733}
1734
Daniel Vetter9c065a72014-09-30 10:56:38 +02001735static void chv_pipe_power_well_enable(struct drm_i915_private *dev_priv,
1736 struct i915_power_well *power_well)
1737{
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001738 WARN_ON_ONCE(power_well->id != PIPE_A);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001739
1740 chv_set_pipe_power_well(dev_priv, power_well, true);
Ville Syrjäläafd62752014-10-30 19:43:03 +02001741
Ville Syrjälä2be7d542015-06-29 15:25:51 +03001742 vlv_display_power_well_init(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001743}
1744
1745static void chv_pipe_power_well_disable(struct drm_i915_private *dev_priv,
1746 struct i915_power_well *power_well)
1747{
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001748 WARN_ON_ONCE(power_well->id != PIPE_A);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001749
Ville Syrjälä2be7d542015-06-29 15:25:51 +03001750 vlv_display_power_well_deinit(dev_priv);
Ville Syrjäläafd62752014-10-30 19:43:03 +02001751
Daniel Vetter9c065a72014-09-30 10:56:38 +02001752 chv_set_pipe_power_well(dev_priv, power_well, false);
1753}
1754
Imre Deak09731282016-02-17 14:17:42 +02001755static void
1756__intel_display_power_get_domain(struct drm_i915_private *dev_priv,
1757 enum intel_display_power_domain domain)
1758{
1759 struct i915_power_domains *power_domains = &dev_priv->power_domains;
1760 struct i915_power_well *power_well;
Imre Deak09731282016-02-17 14:17:42 +02001761
Imre Deak75ccb2e2017-02-17 17:39:43 +02001762 for_each_power_domain_well(dev_priv, power_well, BIT_ULL(domain))
Imre Deakb409ca92016-06-13 16:44:33 +03001763 intel_power_well_get(dev_priv, power_well);
Imre Deak09731282016-02-17 14:17:42 +02001764
1765 power_domains->domain_use_count[domain]++;
1766}
1767
Daniel Vettere4e76842014-09-30 10:56:42 +02001768/**
1769 * intel_display_power_get - grab a power domain reference
1770 * @dev_priv: i915 device instance
1771 * @domain: power domain to reference
1772 *
1773 * This function grabs a power domain reference for @domain and ensures that the
1774 * power domain and all its parents are powered up. Therefore users should only
1775 * grab a reference to the innermost power domain they need.
1776 *
1777 * Any power domain reference obtained by this function must have a symmetric
1778 * call to intel_display_power_put() to release the reference again.
1779 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02001780void intel_display_power_get(struct drm_i915_private *dev_priv,
1781 enum intel_display_power_domain domain)
1782{
Imre Deak09731282016-02-17 14:17:42 +02001783 struct i915_power_domains *power_domains = &dev_priv->power_domains;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001784
1785 intel_runtime_pm_get(dev_priv);
1786
Imre Deak09731282016-02-17 14:17:42 +02001787 mutex_lock(&power_domains->lock);
1788
1789 __intel_display_power_get_domain(dev_priv, domain);
1790
1791 mutex_unlock(&power_domains->lock);
1792}
1793
1794/**
1795 * intel_display_power_get_if_enabled - grab a reference for an enabled display power domain
1796 * @dev_priv: i915 device instance
1797 * @domain: power domain to reference
1798 *
1799 * This function grabs a power domain reference for @domain and ensures that the
1800 * power domain and all its parents are powered up. Therefore users should only
1801 * grab a reference to the innermost power domain they need.
1802 *
1803 * Any power domain reference obtained by this function must have a symmetric
1804 * call to intel_display_power_put() to release the reference again.
1805 */
1806bool intel_display_power_get_if_enabled(struct drm_i915_private *dev_priv,
1807 enum intel_display_power_domain domain)
1808{
1809 struct i915_power_domains *power_domains = &dev_priv->power_domains;
1810 bool is_enabled;
1811
1812 if (!intel_runtime_pm_get_if_in_use(dev_priv))
1813 return false;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001814
1815 mutex_lock(&power_domains->lock);
1816
Imre Deak09731282016-02-17 14:17:42 +02001817 if (__intel_display_power_is_enabled(dev_priv, domain)) {
1818 __intel_display_power_get_domain(dev_priv, domain);
1819 is_enabled = true;
1820 } else {
1821 is_enabled = false;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001822 }
1823
Daniel Vetter9c065a72014-09-30 10:56:38 +02001824 mutex_unlock(&power_domains->lock);
Imre Deak09731282016-02-17 14:17:42 +02001825
1826 if (!is_enabled)
1827 intel_runtime_pm_put(dev_priv);
1828
1829 return is_enabled;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001830}
1831
Daniel Vettere4e76842014-09-30 10:56:42 +02001832/**
1833 * intel_display_power_put - release a power domain reference
1834 * @dev_priv: i915 device instance
1835 * @domain: power domain to reference
1836 *
1837 * This function drops the power domain reference obtained by
1838 * intel_display_power_get() and might power down the corresponding hardware
1839 * block right away if this is the last reference.
1840 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02001841void intel_display_power_put(struct drm_i915_private *dev_priv,
1842 enum intel_display_power_domain domain)
1843{
1844 struct i915_power_domains *power_domains;
1845 struct i915_power_well *power_well;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001846
1847 power_domains = &dev_priv->power_domains;
1848
1849 mutex_lock(&power_domains->lock);
1850
Daniel Stone11c86db2015-11-20 15:55:34 +00001851 WARN(!power_domains->domain_use_count[domain],
1852 "Use count on domain %s is already zero\n",
1853 intel_display_power_domain_str(domain));
Daniel Vetter9c065a72014-09-30 10:56:38 +02001854 power_domains->domain_use_count[domain]--;
1855
Imre Deak75ccb2e2017-02-17 17:39:43 +02001856 for_each_power_domain_well_rev(dev_priv, power_well, BIT_ULL(domain))
Imre Deakb409ca92016-06-13 16:44:33 +03001857 intel_power_well_put(dev_priv, power_well);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001858
1859 mutex_unlock(&power_domains->lock);
1860
1861 intel_runtime_pm_put(dev_priv);
1862}
1863
Ville Syrjälä9d0996b2016-04-18 14:02:28 +03001864#define HSW_DISPLAY_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001865 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
1866 BIT_ULL(POWER_DOMAIN_PIPE_C) | \
1867 BIT_ULL(POWER_DOMAIN_PIPE_A_PANEL_FITTER) | \
1868 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1869 BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
1870 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
1871 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
1872 BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
1873 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1874 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1875 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_LANES) | \
1876 BIT_ULL(POWER_DOMAIN_PORT_CRT) | /* DDI E */ \
1877 BIT_ULL(POWER_DOMAIN_VGA) | \
1878 BIT_ULL(POWER_DOMAIN_AUDIO) | \
1879 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001880
Ville Syrjälä9d0996b2016-04-18 14:02:28 +03001881#define BDW_DISPLAY_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001882 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
1883 BIT_ULL(POWER_DOMAIN_PIPE_C) | \
1884 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1885 BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
1886 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
1887 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
1888 BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
1889 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1890 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1891 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_LANES) | \
1892 BIT_ULL(POWER_DOMAIN_PORT_CRT) | /* DDI E */ \
1893 BIT_ULL(POWER_DOMAIN_VGA) | \
1894 BIT_ULL(POWER_DOMAIN_AUDIO) | \
1895 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001896
Ville Syrjälä465ac0c2016-04-18 14:02:27 +03001897#define VLV_DISPLAY_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001898 BIT_ULL(POWER_DOMAIN_PIPE_A) | \
1899 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
1900 BIT_ULL(POWER_DOMAIN_PIPE_A_PANEL_FITTER) | \
1901 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1902 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
1903 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
1904 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1905 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1906 BIT_ULL(POWER_DOMAIN_PORT_DSI) | \
1907 BIT_ULL(POWER_DOMAIN_PORT_CRT) | \
1908 BIT_ULL(POWER_DOMAIN_VGA) | \
1909 BIT_ULL(POWER_DOMAIN_AUDIO) | \
1910 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1911 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1912 BIT_ULL(POWER_DOMAIN_GMBUS) | \
1913 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001914
1915#define VLV_DPIO_CMN_BC_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001916 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1917 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1918 BIT_ULL(POWER_DOMAIN_PORT_CRT) | \
1919 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1920 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1921 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001922
1923#define VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001924 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1925 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1926 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001927
1928#define VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001929 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1930 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1931 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001932
1933#define VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001934 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1935 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1936 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001937
1938#define VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001939 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1940 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1941 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001942
Ville Syrjälä465ac0c2016-04-18 14:02:27 +03001943#define CHV_DISPLAY_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001944 BIT_ULL(POWER_DOMAIN_PIPE_A) | \
1945 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
1946 BIT_ULL(POWER_DOMAIN_PIPE_C) | \
1947 BIT_ULL(POWER_DOMAIN_PIPE_A_PANEL_FITTER) | \
1948 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1949 BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
1950 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
1951 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
1952 BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
1953 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1954 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1955 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_LANES) | \
1956 BIT_ULL(POWER_DOMAIN_PORT_DSI) | \
1957 BIT_ULL(POWER_DOMAIN_VGA) | \
1958 BIT_ULL(POWER_DOMAIN_AUDIO) | \
1959 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1960 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1961 BIT_ULL(POWER_DOMAIN_AUX_D) | \
1962 BIT_ULL(POWER_DOMAIN_GMBUS) | \
1963 BIT_ULL(POWER_DOMAIN_INIT))
Ville Syrjälä465ac0c2016-04-18 14:02:27 +03001964
Daniel Vetter9c065a72014-09-30 10:56:38 +02001965#define CHV_DPIO_CMN_BC_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001966 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1967 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1968 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1969 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1970 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001971
1972#define CHV_DPIO_CMN_D_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001973 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_LANES) | \
1974 BIT_ULL(POWER_DOMAIN_AUX_D) | \
1975 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001976
Ville Syrjälä2ee0da12017-06-01 17:36:16 +03001977#define I830_PIPES_POWER_DOMAINS ( \
1978 BIT_ULL(POWER_DOMAIN_PIPE_A) | \
1979 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
1980 BIT_ULL(POWER_DOMAIN_PIPE_A_PANEL_FITTER) | \
1981 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1982 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
1983 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
1984 BIT_ULL(POWER_DOMAIN_INIT))
1985
Daniel Vetter9c065a72014-09-30 10:56:38 +02001986static const struct i915_power_well_ops i9xx_always_on_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02001987 .sync_hw = i9xx_power_well_sync_hw_noop,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001988 .enable = i9xx_always_on_power_well_noop,
1989 .disable = i9xx_always_on_power_well_noop,
1990 .is_enabled = i9xx_always_on_power_well_enabled,
1991};
1992
1993static const struct i915_power_well_ops chv_pipe_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02001994 .sync_hw = i9xx_power_well_sync_hw_noop,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001995 .enable = chv_pipe_power_well_enable,
1996 .disable = chv_pipe_power_well_disable,
1997 .is_enabled = chv_pipe_power_well_enabled,
1998};
1999
2000static const struct i915_power_well_ops chv_dpio_cmn_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02002001 .sync_hw = i9xx_power_well_sync_hw_noop,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002002 .enable = chv_dpio_cmn_power_well_enable,
2003 .disable = chv_dpio_cmn_power_well_disable,
2004 .is_enabled = vlv_power_well_enabled,
2005};
2006
2007static struct i915_power_well i9xx_always_on_power_well[] = {
2008 {
2009 .name = "always-on",
2010 .always_on = 1,
2011 .domains = POWER_DOMAIN_MASK,
2012 .ops = &i9xx_always_on_power_well_ops,
2013 },
2014};
2015
Ville Syrjälä2ee0da12017-06-01 17:36:16 +03002016static const struct i915_power_well_ops i830_pipes_power_well_ops = {
2017 .sync_hw = i830_pipes_power_well_sync_hw,
2018 .enable = i830_pipes_power_well_enable,
2019 .disable = i830_pipes_power_well_disable,
2020 .is_enabled = i830_pipes_power_well_enabled,
2021};
2022
2023static struct i915_power_well i830_power_wells[] = {
2024 {
2025 .name = "always-on",
2026 .always_on = 1,
2027 .domains = POWER_DOMAIN_MASK,
2028 .ops = &i9xx_always_on_power_well_ops,
2029 },
2030 {
2031 .name = "pipes",
2032 .domains = I830_PIPES_POWER_DOMAINS,
2033 .ops = &i830_pipes_power_well_ops,
2034 },
2035};
2036
Daniel Vetter9c065a72014-09-30 10:56:38 +02002037static const struct i915_power_well_ops hsw_power_well_ops = {
2038 .sync_hw = hsw_power_well_sync_hw,
2039 .enable = hsw_power_well_enable,
2040 .disable = hsw_power_well_disable,
2041 .is_enabled = hsw_power_well_enabled,
2042};
2043
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002044static const struct i915_power_well_ops skl_power_well_ops = {
2045 .sync_hw = skl_power_well_sync_hw,
2046 .enable = skl_power_well_enable,
2047 .disable = skl_power_well_disable,
2048 .is_enabled = skl_power_well_enabled,
2049};
2050
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01002051static const struct i915_power_well_ops gen9_dc_off_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02002052 .sync_hw = i9xx_power_well_sync_hw_noop,
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01002053 .enable = gen9_dc_off_power_well_enable,
2054 .disable = gen9_dc_off_power_well_disable,
2055 .is_enabled = gen9_dc_off_power_well_enabled,
2056};
2057
Imre Deak9c8d0b82016-06-13 16:44:34 +03002058static const struct i915_power_well_ops bxt_dpio_cmn_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02002059 .sync_hw = i9xx_power_well_sync_hw_noop,
Imre Deak9c8d0b82016-06-13 16:44:34 +03002060 .enable = bxt_dpio_cmn_power_well_enable,
2061 .disable = bxt_dpio_cmn_power_well_disable,
2062 .is_enabled = bxt_dpio_cmn_power_well_enabled,
2063};
2064
Daniel Vetter9c065a72014-09-30 10:56:38 +02002065static struct i915_power_well hsw_power_wells[] = {
2066 {
2067 .name = "always-on",
2068 .always_on = 1,
Ville Syrjälä998bd662016-04-18 14:02:26 +03002069 .domains = POWER_DOMAIN_MASK,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002070 .ops = &i9xx_always_on_power_well_ops,
2071 },
2072 {
2073 .name = "display",
2074 .domains = HSW_DISPLAY_POWER_DOMAINS,
2075 .ops = &hsw_power_well_ops,
2076 },
2077};
2078
2079static struct i915_power_well bdw_power_wells[] = {
2080 {
2081 .name = "always-on",
2082 .always_on = 1,
Ville Syrjälä998bd662016-04-18 14:02:26 +03002083 .domains = POWER_DOMAIN_MASK,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002084 .ops = &i9xx_always_on_power_well_ops,
2085 },
2086 {
2087 .name = "display",
2088 .domains = BDW_DISPLAY_POWER_DOMAINS,
2089 .ops = &hsw_power_well_ops,
2090 },
2091};
2092
2093static const struct i915_power_well_ops vlv_display_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02002094 .sync_hw = i9xx_power_well_sync_hw_noop,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002095 .enable = vlv_display_power_well_enable,
2096 .disable = vlv_display_power_well_disable,
2097 .is_enabled = vlv_power_well_enabled,
2098};
2099
2100static const struct i915_power_well_ops vlv_dpio_cmn_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_dpio_cmn_power_well_enable,
2103 .disable = vlv_dpio_cmn_power_well_disable,
2104 .is_enabled = vlv_power_well_enabled,
2105};
2106
2107static const struct i915_power_well_ops vlv_dpio_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_power_well_enable,
2110 .disable = vlv_power_well_disable,
2111 .is_enabled = vlv_power_well_enabled,
2112};
2113
2114static struct i915_power_well vlv_power_wells[] = {
2115 {
2116 .name = "always-on",
2117 .always_on = 1,
Ville Syrjälä998bd662016-04-18 14:02:26 +03002118 .domains = POWER_DOMAIN_MASK,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002119 .ops = &i9xx_always_on_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002120 .id = PUNIT_POWER_WELL_ALWAYS_ON,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002121 },
2122 {
2123 .name = "display",
2124 .domains = VLV_DISPLAY_POWER_DOMAINS,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002125 .id = PUNIT_POWER_WELL_DISP2D,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002126 .ops = &vlv_display_power_well_ops,
2127 },
2128 {
2129 .name = "dpio-tx-b-01",
2130 .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
2131 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
2132 VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
2133 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
2134 .ops = &vlv_dpio_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002135 .id = PUNIT_POWER_WELL_DPIO_TX_B_LANES_01,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002136 },
2137 {
2138 .name = "dpio-tx-b-23",
2139 .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
2140 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
2141 VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
2142 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
2143 .ops = &vlv_dpio_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002144 .id = PUNIT_POWER_WELL_DPIO_TX_B_LANES_23,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002145 },
2146 {
2147 .name = "dpio-tx-c-01",
2148 .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
2149 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
2150 VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
2151 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
2152 .ops = &vlv_dpio_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002153 .id = PUNIT_POWER_WELL_DPIO_TX_C_LANES_01,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002154 },
2155 {
2156 .name = "dpio-tx-c-23",
2157 .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
2158 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
2159 VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
2160 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
2161 .ops = &vlv_dpio_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002162 .id = PUNIT_POWER_WELL_DPIO_TX_C_LANES_23,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002163 },
2164 {
2165 .name = "dpio-common",
2166 .domains = VLV_DPIO_CMN_BC_POWER_DOMAINS,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002167 .id = PUNIT_POWER_WELL_DPIO_CMN_BC,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002168 .ops = &vlv_dpio_cmn_power_well_ops,
2169 },
2170};
2171
2172static struct i915_power_well chv_power_wells[] = {
2173 {
2174 .name = "always-on",
2175 .always_on = 1,
Ville Syrjälä998bd662016-04-18 14:02:26 +03002176 .domains = POWER_DOMAIN_MASK,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002177 .ops = &i9xx_always_on_power_well_ops,
2178 },
Daniel Vetter9c065a72014-09-30 10:56:38 +02002179 {
2180 .name = "display",
Ville Syrjäläbaa4e572014-10-27 16:07:32 +02002181 /*
Ville Syrjäläfde61e42015-05-26 20:22:39 +03002182 * Pipe A power well is the new disp2d well. Pipe B and C
2183 * power wells don't actually exist. Pipe A power well is
2184 * required for any pipe to work.
Ville Syrjäläbaa4e572014-10-27 16:07:32 +02002185 */
Ville Syrjälä465ac0c2016-04-18 14:02:27 +03002186 .domains = CHV_DISPLAY_POWER_DOMAINS,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002187 .id = PIPE_A,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002188 .ops = &chv_pipe_power_well_ops,
2189 },
Daniel Vetter9c065a72014-09-30 10:56:38 +02002190 {
2191 .name = "dpio-common-bc",
Ville Syrjälä71849b62015-04-10 18:21:29 +03002192 .domains = CHV_DPIO_CMN_BC_POWER_DOMAINS,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002193 .id = PUNIT_POWER_WELL_DPIO_CMN_BC,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002194 .ops = &chv_dpio_cmn_power_well_ops,
2195 },
2196 {
2197 .name = "dpio-common-d",
Ville Syrjälä71849b62015-04-10 18:21:29 +03002198 .domains = CHV_DPIO_CMN_D_POWER_DOMAINS,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002199 .id = PUNIT_POWER_WELL_DPIO_CMN_D,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002200 .ops = &chv_dpio_cmn_power_well_ops,
2201 },
Daniel Vetter9c065a72014-09-30 10:56:38 +02002202};
2203
Suketu Shah5aefb232015-04-16 14:22:10 +05302204bool intel_display_power_well_is_enabled(struct drm_i915_private *dev_priv,
2205 int power_well_id)
2206{
2207 struct i915_power_well *power_well;
2208 bool ret;
2209
2210 power_well = lookup_power_well(dev_priv, power_well_id);
2211 ret = power_well->ops->is_enabled(dev_priv, power_well);
2212
2213 return ret;
2214}
2215
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002216static struct i915_power_well skl_power_wells[] = {
2217 {
2218 .name = "always-on",
2219 .always_on = 1,
Ville Syrjälä998bd662016-04-18 14:02:26 +03002220 .domains = POWER_DOMAIN_MASK,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002221 .ops = &i9xx_always_on_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002222 .id = SKL_DISP_PW_ALWAYS_ON,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002223 },
2224 {
2225 .name = "power well 1",
Imre Deak4a76f292015-11-04 19:24:15 +02002226 /* Handled by the DMC firmware */
2227 .domains = 0,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002228 .ops = &skl_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002229 .id = SKL_DISP_PW_1,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002230 },
2231 {
2232 .name = "MISC IO power well",
Imre Deak4a76f292015-11-04 19:24:15 +02002233 /* Handled by the DMC firmware */
2234 .domains = 0,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002235 .ops = &skl_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002236 .id = SKL_DISP_PW_MISC_IO,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002237 },
2238 {
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01002239 .name = "DC off",
2240 .domains = SKL_DISPLAY_DC_OFF_POWER_DOMAINS,
2241 .ops = &gen9_dc_off_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002242 .id = SKL_DISP_PW_DC_OFF,
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01002243 },
2244 {
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002245 .name = "power well 2",
2246 .domains = SKL_DISPLAY_POWERWELL_2_POWER_DOMAINS,
2247 .ops = &skl_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002248 .id = SKL_DISP_PW_2,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002249 },
2250 {
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002251 .name = "DDI A/E IO power well",
2252 .domains = SKL_DISPLAY_DDI_IO_A_E_POWER_DOMAINS,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002253 .ops = &skl_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002254 .id = SKL_DISP_PW_DDI_A_E,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002255 },
2256 {
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002257 .name = "DDI B IO power well",
2258 .domains = SKL_DISPLAY_DDI_IO_B_POWER_DOMAINS,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002259 .ops = &skl_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002260 .id = SKL_DISP_PW_DDI_B,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002261 },
2262 {
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002263 .name = "DDI C IO power well",
2264 .domains = SKL_DISPLAY_DDI_IO_C_POWER_DOMAINS,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002265 .ops = &skl_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002266 .id = SKL_DISP_PW_DDI_C,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002267 },
2268 {
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002269 .name = "DDI D IO power well",
2270 .domains = SKL_DISPLAY_DDI_IO_D_POWER_DOMAINS,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002271 .ops = &skl_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002272 .id = SKL_DISP_PW_DDI_D,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002273 },
2274};
2275
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302276static struct i915_power_well bxt_power_wells[] = {
2277 {
2278 .name = "always-on",
2279 .always_on = 1,
Ville Syrjälä998bd662016-04-18 14:02:26 +03002280 .domains = POWER_DOMAIN_MASK,
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302281 .ops = &i9xx_always_on_power_well_ops,
2282 },
2283 {
2284 .name = "power well 1",
Imre Deakd7d7c9e2016-04-01 16:02:42 +03002285 .domains = 0,
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302286 .ops = &skl_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002287 .id = SKL_DISP_PW_1,
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302288 },
2289 {
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01002290 .name = "DC off",
2291 .domains = BXT_DISPLAY_DC_OFF_POWER_DOMAINS,
2292 .ops = &gen9_dc_off_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002293 .id = SKL_DISP_PW_DC_OFF,
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01002294 },
2295 {
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302296 .name = "power well 2",
2297 .domains = BXT_DISPLAY_POWERWELL_2_POWER_DOMAINS,
2298 .ops = &skl_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002299 .id = SKL_DISP_PW_2,
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01002300 },
Imre Deak9c8d0b82016-06-13 16:44:34 +03002301 {
2302 .name = "dpio-common-a",
2303 .domains = BXT_DPIO_CMN_A_POWER_DOMAINS,
2304 .ops = &bxt_dpio_cmn_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002305 .id = BXT_DPIO_CMN_A,
Ander Conselvan de Oliveira362624c2016-10-06 19:22:15 +03002306 .data = DPIO_PHY1,
Imre Deak9c8d0b82016-06-13 16:44:34 +03002307 },
2308 {
2309 .name = "dpio-common-bc",
2310 .domains = BXT_DPIO_CMN_BC_POWER_DOMAINS,
2311 .ops = &bxt_dpio_cmn_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002312 .id = BXT_DPIO_CMN_BC,
Ander Conselvan de Oliveira362624c2016-10-06 19:22:15 +03002313 .data = DPIO_PHY0,
Imre Deak9c8d0b82016-06-13 16:44:34 +03002314 },
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302315};
2316
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002317static struct i915_power_well glk_power_wells[] = {
2318 {
2319 .name = "always-on",
2320 .always_on = 1,
2321 .domains = POWER_DOMAIN_MASK,
2322 .ops = &i9xx_always_on_power_well_ops,
2323 },
2324 {
2325 .name = "power well 1",
2326 /* Handled by the DMC firmware */
2327 .domains = 0,
2328 .ops = &skl_power_well_ops,
2329 .id = SKL_DISP_PW_1,
2330 },
2331 {
2332 .name = "DC off",
2333 .domains = GLK_DISPLAY_DC_OFF_POWER_DOMAINS,
2334 .ops = &gen9_dc_off_power_well_ops,
2335 .id = SKL_DISP_PW_DC_OFF,
2336 },
2337 {
2338 .name = "power well 2",
2339 .domains = GLK_DISPLAY_POWERWELL_2_POWER_DOMAINS,
2340 .ops = &skl_power_well_ops,
2341 .id = SKL_DISP_PW_2,
2342 },
2343 {
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +02002344 .name = "dpio-common-a",
2345 .domains = GLK_DPIO_CMN_A_POWER_DOMAINS,
2346 .ops = &bxt_dpio_cmn_power_well_ops,
2347 .id = BXT_DPIO_CMN_A,
2348 .data = DPIO_PHY1,
2349 },
2350 {
2351 .name = "dpio-common-b",
2352 .domains = GLK_DPIO_CMN_B_POWER_DOMAINS,
2353 .ops = &bxt_dpio_cmn_power_well_ops,
2354 .id = BXT_DPIO_CMN_BC,
2355 .data = DPIO_PHY0,
2356 },
2357 {
2358 .name = "dpio-common-c",
2359 .domains = GLK_DPIO_CMN_C_POWER_DOMAINS,
2360 .ops = &bxt_dpio_cmn_power_well_ops,
2361 .id = GLK_DPIO_CMN_C,
2362 .data = DPIO_PHY2,
2363 },
2364 {
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002365 .name = "AUX A",
2366 .domains = GLK_DISPLAY_AUX_A_POWER_DOMAINS,
2367 .ops = &skl_power_well_ops,
2368 .id = GLK_DISP_PW_AUX_A,
2369 },
2370 {
2371 .name = "AUX B",
2372 .domains = GLK_DISPLAY_AUX_B_POWER_DOMAINS,
2373 .ops = &skl_power_well_ops,
2374 .id = GLK_DISP_PW_AUX_B,
2375 },
2376 {
2377 .name = "AUX C",
2378 .domains = GLK_DISPLAY_AUX_C_POWER_DOMAINS,
2379 .ops = &skl_power_well_ops,
2380 .id = GLK_DISP_PW_AUX_C,
2381 },
2382 {
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002383 .name = "DDI A IO power well",
2384 .domains = GLK_DISPLAY_DDI_IO_A_POWER_DOMAINS,
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002385 .ops = &skl_power_well_ops,
2386 .id = GLK_DISP_PW_DDI_A,
2387 },
2388 {
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002389 .name = "DDI B IO power well",
2390 .domains = GLK_DISPLAY_DDI_IO_B_POWER_DOMAINS,
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002391 .ops = &skl_power_well_ops,
2392 .id = SKL_DISP_PW_DDI_B,
2393 },
2394 {
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002395 .name = "DDI C IO power well",
2396 .domains = GLK_DISPLAY_DDI_IO_C_POWER_DOMAINS,
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002397 .ops = &skl_power_well_ops,
2398 .id = SKL_DISP_PW_DDI_C,
2399 },
2400};
2401
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002402static struct i915_power_well cnl_power_wells[] = {
2403 {
2404 .name = "always-on",
2405 .always_on = 1,
2406 .domains = POWER_DOMAIN_MASK,
2407 .ops = &i9xx_always_on_power_well_ops,
2408 },
2409 {
2410 .name = "power well 1",
2411 /* Handled by the DMC firmware */
2412 .domains = 0,
2413 .ops = &skl_power_well_ops,
2414 .id = SKL_DISP_PW_1,
2415 },
2416 {
2417 .name = "AUX A",
2418 .domains = CNL_DISPLAY_AUX_A_POWER_DOMAINS,
2419 .ops = &skl_power_well_ops,
2420 .id = CNL_DISP_PW_AUX_A,
2421 },
2422 {
2423 .name = "AUX B",
2424 .domains = CNL_DISPLAY_AUX_B_POWER_DOMAINS,
2425 .ops = &skl_power_well_ops,
2426 .id = CNL_DISP_PW_AUX_B,
2427 },
2428 {
2429 .name = "AUX C",
2430 .domains = CNL_DISPLAY_AUX_C_POWER_DOMAINS,
2431 .ops = &skl_power_well_ops,
2432 .id = CNL_DISP_PW_AUX_C,
2433 },
2434 {
2435 .name = "AUX D",
2436 .domains = CNL_DISPLAY_AUX_D_POWER_DOMAINS,
2437 .ops = &skl_power_well_ops,
2438 .id = CNL_DISP_PW_AUX_D,
2439 },
2440 {
2441 .name = "DC off",
2442 .domains = CNL_DISPLAY_DC_OFF_POWER_DOMAINS,
2443 .ops = &gen9_dc_off_power_well_ops,
2444 .id = SKL_DISP_PW_DC_OFF,
2445 },
2446 {
2447 .name = "power well 2",
2448 .domains = CNL_DISPLAY_POWERWELL_2_POWER_DOMAINS,
2449 .ops = &skl_power_well_ops,
2450 .id = SKL_DISP_PW_2,
2451 },
2452 {
2453 .name = "DDI A IO power well",
2454 .domains = CNL_DISPLAY_DDI_A_IO_POWER_DOMAINS,
2455 .ops = &skl_power_well_ops,
2456 .id = CNL_DISP_PW_DDI_A,
2457 },
2458 {
2459 .name = "DDI B IO power well",
2460 .domains = CNL_DISPLAY_DDI_B_IO_POWER_DOMAINS,
2461 .ops = &skl_power_well_ops,
2462 .id = SKL_DISP_PW_DDI_B,
2463 },
2464 {
2465 .name = "DDI C IO power well",
2466 .domains = CNL_DISPLAY_DDI_C_IO_POWER_DOMAINS,
2467 .ops = &skl_power_well_ops,
2468 .id = SKL_DISP_PW_DDI_C,
2469 },
2470 {
2471 .name = "DDI D IO power well",
2472 .domains = CNL_DISPLAY_DDI_D_IO_POWER_DOMAINS,
2473 .ops = &skl_power_well_ops,
2474 .id = SKL_DISP_PW_DDI_D,
2475 },
2476};
2477
Imre Deak1b0e3a02015-11-05 23:04:11 +02002478static int
2479sanitize_disable_power_well_option(const struct drm_i915_private *dev_priv,
2480 int disable_power_well)
2481{
2482 if (disable_power_well >= 0)
2483 return !!disable_power_well;
2484
Imre Deak1b0e3a02015-11-05 23:04:11 +02002485 return 1;
2486}
2487
Imre Deaka37baf32016-02-29 22:49:03 +02002488static uint32_t get_allowed_dc_mask(const struct drm_i915_private *dev_priv,
2489 int enable_dc)
2490{
2491 uint32_t mask;
2492 int requested_dc;
2493 int max_dc;
2494
Rodrigo Vivi6d6a8972017-07-06 13:45:08 -07002495 if (IS_GEN9_BC(dev_priv) || IS_CANNONLAKE(dev_priv)) {
Imre Deaka37baf32016-02-29 22:49:03 +02002496 max_dc = 2;
2497 mask = 0;
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02002498 } else if (IS_GEN9_LP(dev_priv)) {
Imre Deaka37baf32016-02-29 22:49:03 +02002499 max_dc = 1;
2500 /*
2501 * DC9 has a separate HW flow from the rest of the DC states,
2502 * not depending on the DMC firmware. It's needed by system
2503 * suspend/resume, so allow it unconditionally.
2504 */
2505 mask = DC_STATE_EN_DC9;
2506 } else {
2507 max_dc = 0;
2508 mask = 0;
2509 }
2510
Imre Deak66e2c4c2016-02-29 22:49:04 +02002511 if (!i915.disable_power_well)
2512 max_dc = 0;
2513
Imre Deaka37baf32016-02-29 22:49:03 +02002514 if (enable_dc >= 0 && enable_dc <= max_dc) {
2515 requested_dc = enable_dc;
2516 } else if (enable_dc == -1) {
2517 requested_dc = max_dc;
2518 } else if (enable_dc > max_dc && enable_dc <= 2) {
2519 DRM_DEBUG_KMS("Adjusting requested max DC state (%d->%d)\n",
2520 enable_dc, max_dc);
2521 requested_dc = max_dc;
2522 } else {
2523 DRM_ERROR("Unexpected value for enable_dc (%d)\n", enable_dc);
2524 requested_dc = max_dc;
2525 }
2526
2527 if (requested_dc > 1)
2528 mask |= DC_STATE_EN_UPTO_DC6;
2529 if (requested_dc > 0)
2530 mask |= DC_STATE_EN_UPTO_DC5;
2531
2532 DRM_DEBUG_KMS("Allowed DC state mask %02x\n", mask);
2533
2534 return mask;
2535}
2536
Daniel Vetter9c065a72014-09-30 10:56:38 +02002537#define set_power_wells(power_domains, __power_wells) ({ \
2538 (power_domains)->power_wells = (__power_wells); \
2539 (power_domains)->power_well_count = ARRAY_SIZE(__power_wells); \
2540})
2541
Daniel Vettere4e76842014-09-30 10:56:42 +02002542/**
2543 * intel_power_domains_init - initializes the power domain structures
2544 * @dev_priv: i915 device instance
2545 *
2546 * Initializes the power domain structures for @dev_priv depending upon the
2547 * supported platform.
2548 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02002549int intel_power_domains_init(struct drm_i915_private *dev_priv)
2550{
2551 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2552
Imre Deak1b0e3a02015-11-05 23:04:11 +02002553 i915.disable_power_well = sanitize_disable_power_well_option(dev_priv,
2554 i915.disable_power_well);
Imre Deaka37baf32016-02-29 22:49:03 +02002555 dev_priv->csr.allowed_dc_mask = get_allowed_dc_mask(dev_priv,
2556 i915.enable_dc);
Imre Deak1b0e3a02015-11-05 23:04:11 +02002557
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02002558 BUILD_BUG_ON(POWER_DOMAIN_NUM > 64);
Ville Syrjäläf0ab43e2015-11-09 16:48:19 +01002559
Daniel Vetter9c065a72014-09-30 10:56:38 +02002560 mutex_init(&power_domains->lock);
2561
2562 /*
2563 * The enabling order will be from lower to higher indexed wells,
2564 * the disabling order is reversed.
2565 */
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002566 if (IS_HASWELL(dev_priv)) {
Daniel Vetter9c065a72014-09-30 10:56:38 +02002567 set_power_wells(power_domains, hsw_power_wells);
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002568 } else if (IS_BROADWELL(dev_priv)) {
Daniel Vetter9c065a72014-09-30 10:56:38 +02002569 set_power_wells(power_domains, bdw_power_wells);
Rodrigo Vivib976dc52017-01-23 10:32:37 -08002570 } else if (IS_GEN9_BC(dev_priv)) {
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002571 set_power_wells(power_domains, skl_power_wells);
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002572 } else if (IS_CANNONLAKE(dev_priv)) {
2573 set_power_wells(power_domains, cnl_power_wells);
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002574 } else if (IS_BROXTON(dev_priv)) {
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302575 set_power_wells(power_domains, bxt_power_wells);
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002576 } else if (IS_GEMINILAKE(dev_priv)) {
2577 set_power_wells(power_domains, glk_power_wells);
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002578 } else if (IS_CHERRYVIEW(dev_priv)) {
Daniel Vetter9c065a72014-09-30 10:56:38 +02002579 set_power_wells(power_domains, chv_power_wells);
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002580 } else if (IS_VALLEYVIEW(dev_priv)) {
Daniel Vetter9c065a72014-09-30 10:56:38 +02002581 set_power_wells(power_domains, vlv_power_wells);
Ville Syrjälä2ee0da12017-06-01 17:36:16 +03002582 } else if (IS_I830(dev_priv)) {
2583 set_power_wells(power_domains, i830_power_wells);
Daniel Vetter9c065a72014-09-30 10:56:38 +02002584 } else {
2585 set_power_wells(power_domains, i9xx_always_on_power_well);
2586 }
2587
2588 return 0;
2589}
2590
Daniel Vettere4e76842014-09-30 10:56:42 +02002591/**
2592 * intel_power_domains_fini - finalizes the power domain structures
2593 * @dev_priv: i915 device instance
2594 *
2595 * Finalizes the power domain structures for @dev_priv depending upon the
2596 * supported platform. This function also disables runtime pm and ensures that
2597 * the device stays powered up so that the driver can be reloaded.
2598 */
Daniel Vetterf458ebb2014-09-30 10:56:39 +02002599void intel_power_domains_fini(struct drm_i915_private *dev_priv)
Daniel Vetter9c065a72014-09-30 10:56:38 +02002600{
David Weinehallc49d13e2016-08-22 13:32:42 +03002601 struct device *kdev = &dev_priv->drm.pdev->dev;
Imre Deak25b181b2015-12-17 13:44:56 +02002602
Imre Deakaabee1b2015-12-15 20:10:29 +02002603 /*
2604 * The i915.ko module is still not prepared to be loaded when
Daniel Vetterf458ebb2014-09-30 10:56:39 +02002605 * the power well is not enabled, so just enable it in case
Imre Deakaabee1b2015-12-15 20:10:29 +02002606 * we're going to unload/reload.
2607 * The following also reacquires the RPM reference the core passed
2608 * to the driver during loading, which is dropped in
2609 * intel_runtime_pm_enable(). We have to hand back the control of the
2610 * device to the core with this reference held.
2611 */
Daniel Vetterf458ebb2014-09-30 10:56:39 +02002612 intel_display_set_init_power(dev_priv, true);
Imre Deakd314cd42015-11-17 17:44:23 +02002613
2614 /* Remove the refcount we took to keep power well support disabled. */
2615 if (!i915.disable_power_well)
2616 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
Imre Deak25b181b2015-12-17 13:44:56 +02002617
2618 /*
2619 * Remove the refcount we took in intel_runtime_pm_enable() in case
2620 * the platform doesn't support runtime PM.
2621 */
2622 if (!HAS_RUNTIME_PM(dev_priv))
David Weinehallc49d13e2016-08-22 13:32:42 +03002623 pm_runtime_put(kdev);
Daniel Vetter9c065a72014-09-30 10:56:38 +02002624}
2625
Imre Deak30eade12015-11-04 19:24:13 +02002626static void intel_power_domains_sync_hw(struct drm_i915_private *dev_priv)
Daniel Vetter9c065a72014-09-30 10:56:38 +02002627{
2628 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2629 struct i915_power_well *power_well;
Daniel Vetter9c065a72014-09-30 10:56:38 +02002630
2631 mutex_lock(&power_domains->lock);
Imre Deak75ccb2e2017-02-17 17:39:43 +02002632 for_each_power_well(dev_priv, power_well) {
Daniel Vetter9c065a72014-09-30 10:56:38 +02002633 power_well->ops->sync_hw(dev_priv, power_well);
2634 power_well->hw_enabled = power_well->ops->is_enabled(dev_priv,
2635 power_well);
2636 }
2637 mutex_unlock(&power_domains->lock);
2638}
2639
Ville Syrjälä70c2c182016-05-13 23:41:30 +03002640static void gen9_dbuf_enable(struct drm_i915_private *dev_priv)
2641{
2642 I915_WRITE(DBUF_CTL, I915_READ(DBUF_CTL) | DBUF_POWER_REQUEST);
2643 POSTING_READ(DBUF_CTL);
2644
2645 udelay(10);
2646
2647 if (!(I915_READ(DBUF_CTL) & DBUF_POWER_STATE))
2648 DRM_ERROR("DBuf power enable timeout\n");
2649}
2650
2651static void gen9_dbuf_disable(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 disable timeout!\n");
2660}
2661
Imre Deak73dfc222015-11-17 17:33:53 +02002662static void skl_display_core_init(struct drm_i915_private *dev_priv,
Imre Deak443a93a2016-04-04 15:42:57 +03002663 bool resume)
Imre Deak73dfc222015-11-17 17:33:53 +02002664{
2665 struct i915_power_domains *power_domains = &dev_priv->power_domains;
Imre Deak443a93a2016-04-04 15:42:57 +03002666 struct i915_power_well *well;
Imre Deak73dfc222015-11-17 17:33:53 +02002667 uint32_t val;
2668
Imre Deakd26fa1d2015-11-04 19:24:17 +02002669 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
2670
Imre Deak73dfc222015-11-17 17:33:53 +02002671 /* enable PCH reset handshake */
2672 val = I915_READ(HSW_NDE_RSTWRN_OPT);
2673 I915_WRITE(HSW_NDE_RSTWRN_OPT, val | RESET_PCH_HANDSHAKE_ENABLE);
2674
2675 /* enable PG1 and Misc I/O */
2676 mutex_lock(&power_domains->lock);
Imre Deak443a93a2016-04-04 15:42:57 +03002677
2678 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
2679 intel_power_well_enable(dev_priv, well);
2680
2681 well = lookup_power_well(dev_priv, SKL_DISP_PW_MISC_IO);
2682 intel_power_well_enable(dev_priv, well);
2683
Imre Deak73dfc222015-11-17 17:33:53 +02002684 mutex_unlock(&power_domains->lock);
2685
Imre Deak73dfc222015-11-17 17:33:53 +02002686 skl_init_cdclk(dev_priv);
2687
Ville Syrjälä70c2c182016-05-13 23:41:30 +03002688 gen9_dbuf_enable(dev_priv);
2689
Ville Syrjälä9f7eb312016-05-13 23:41:29 +03002690 if (resume && dev_priv->csr.dmc_payload)
Imre Deak2abc5252016-03-04 21:57:41 +02002691 intel_csr_load_program(dev_priv);
Imre Deak73dfc222015-11-17 17:33:53 +02002692}
2693
2694static void skl_display_core_uninit(struct drm_i915_private *dev_priv)
2695{
2696 struct i915_power_domains *power_domains = &dev_priv->power_domains;
Imre Deak443a93a2016-04-04 15:42:57 +03002697 struct i915_power_well *well;
Imre Deak73dfc222015-11-17 17:33:53 +02002698
Imre Deakd26fa1d2015-11-04 19:24:17 +02002699 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
2700
Ville Syrjälä70c2c182016-05-13 23:41:30 +03002701 gen9_dbuf_disable(dev_priv);
2702
Imre Deak73dfc222015-11-17 17:33:53 +02002703 skl_uninit_cdclk(dev_priv);
2704
2705 /* The spec doesn't call for removing the reset handshake flag */
2706 /* disable PG1 and Misc I/O */
Imre Deak443a93a2016-04-04 15:42:57 +03002707
Imre Deak73dfc222015-11-17 17:33:53 +02002708 mutex_lock(&power_domains->lock);
Imre Deak443a93a2016-04-04 15:42:57 +03002709
Imre Deakedfda8e2017-06-29 18:36:59 +03002710 /*
2711 * BSpec says to keep the MISC IO power well enabled here, only
2712 * remove our request for power well 1.
Imre Deak42d93662017-06-29 18:37:01 +03002713 * Note that even though the driver's request is removed power well 1
2714 * may stay enabled after this due to DMC's own request on it.
Imre Deakedfda8e2017-06-29 18:36:59 +03002715 */
Imre Deak443a93a2016-04-04 15:42:57 +03002716 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
2717 intel_power_well_disable(dev_priv, well);
2718
Imre Deak73dfc222015-11-17 17:33:53 +02002719 mutex_unlock(&power_domains->lock);
Imre Deak846c6b22017-06-29 18:36:58 +03002720
2721 usleep_range(10, 30); /* 10 us delay per Bspec */
Imre Deak73dfc222015-11-17 17:33:53 +02002722}
2723
Imre Deakd7d7c9e2016-04-01 16:02:42 +03002724void bxt_display_core_init(struct drm_i915_private *dev_priv,
2725 bool resume)
2726{
2727 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2728 struct i915_power_well *well;
2729 uint32_t val;
2730
2731 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
2732
2733 /*
2734 * NDE_RSTWRN_OPT RST PCH Handshake En must always be 0b on BXT
2735 * or else the reset will hang because there is no PCH to respond.
2736 * Move the handshake programming to initialization sequence.
2737 * Previously was left up to BIOS.
2738 */
2739 val = I915_READ(HSW_NDE_RSTWRN_OPT);
2740 val &= ~RESET_PCH_HANDSHAKE_ENABLE;
2741 I915_WRITE(HSW_NDE_RSTWRN_OPT, val);
2742
2743 /* Enable PG1 */
2744 mutex_lock(&power_domains->lock);
2745
2746 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
2747 intel_power_well_enable(dev_priv, well);
2748
2749 mutex_unlock(&power_domains->lock);
2750
Imre Deak324513c2016-06-13 16:44:36 +03002751 bxt_init_cdclk(dev_priv);
Ville Syrjälä70c2c182016-05-13 23:41:30 +03002752
2753 gen9_dbuf_enable(dev_priv);
2754
Imre Deakd7d7c9e2016-04-01 16:02:42 +03002755 if (resume && dev_priv->csr.dmc_payload)
2756 intel_csr_load_program(dev_priv);
2757}
2758
2759void bxt_display_core_uninit(struct drm_i915_private *dev_priv)
2760{
2761 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2762 struct i915_power_well *well;
2763
2764 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
2765
Ville Syrjälä70c2c182016-05-13 23:41:30 +03002766 gen9_dbuf_disable(dev_priv);
2767
Imre Deak324513c2016-06-13 16:44:36 +03002768 bxt_uninit_cdclk(dev_priv);
Imre Deakd7d7c9e2016-04-01 16:02:42 +03002769
2770 /* The spec doesn't call for removing the reset handshake flag */
2771
Imre Deak42d93662017-06-29 18:37:01 +03002772 /*
2773 * Disable PW1 (PG1).
2774 * Note that even though the driver's request is removed power well 1
2775 * may stay enabled after this due to DMC's own request on it.
2776 */
Imre Deakd7d7c9e2016-04-01 16:02:42 +03002777 mutex_lock(&power_domains->lock);
2778
2779 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
2780 intel_power_well_disable(dev_priv, well);
2781
2782 mutex_unlock(&power_domains->lock);
Imre Deak846c6b22017-06-29 18:36:58 +03002783
2784 usleep_range(10, 30); /* 10 us delay per Bspec */
Imre Deakd7d7c9e2016-04-01 16:02:42 +03002785}
2786
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07002787#define CNL_PROCMON_IDX(val) \
2788 (((val) & (PROCESS_INFO_MASK | VOLTAGE_INFO_MASK)) >> VOLTAGE_INFO_SHIFT)
2789#define NUM_CNL_PROCMON \
2790 (CNL_PROCMON_IDX(VOLTAGE_INFO_MASK | PROCESS_INFO_MASK) + 1)
2791
2792static const struct cnl_procmon {
2793 u32 dw1, dw9, dw10;
2794} cnl_procmon_values[NUM_CNL_PROCMON] = {
2795 [CNL_PROCMON_IDX(VOLTAGE_INFO_0_85V | PROCESS_INFO_DOT_0)] =
2796 { .dw1 = 0x00 << 16, .dw9 = 0x62AB67BB, .dw10 = 0x51914F96, },
2797 [CNL_PROCMON_IDX(VOLTAGE_INFO_0_95V | PROCESS_INFO_DOT_0)] =
2798 { .dw1 = 0x00 << 16, .dw9 = 0x86E172C7, .dw10 = 0x77CA5EAB, },
2799 [CNL_PROCMON_IDX(VOLTAGE_INFO_0_95V | PROCESS_INFO_DOT_1)] =
2800 { .dw1 = 0x00 << 16, .dw9 = 0x93F87FE1, .dw10 = 0x8AE871C5, },
2801 [CNL_PROCMON_IDX(VOLTAGE_INFO_1_05V | PROCESS_INFO_DOT_0)] =
2802 { .dw1 = 0x00 << 16, .dw9 = 0x98FA82DD, .dw10 = 0x89E46DC1, },
2803 [CNL_PROCMON_IDX(VOLTAGE_INFO_1_05V | PROCESS_INFO_DOT_1)] =
2804 { .dw1 = 0x44 << 16, .dw9 = 0x9A00AB25, .dw10 = 0x8AE38FF1, },
2805};
2806
2807static void cnl_display_core_init(struct drm_i915_private *dev_priv, bool resume)
2808{
2809 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2810 const struct cnl_procmon *procmon;
2811 struct i915_power_well *well;
2812 u32 val;
2813
2814 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
2815
2816 /* 1. Enable PCH Reset Handshake */
2817 val = I915_READ(HSW_NDE_RSTWRN_OPT);
2818 val |= RESET_PCH_HANDSHAKE_ENABLE;
2819 I915_WRITE(HSW_NDE_RSTWRN_OPT, val);
2820
2821 /* 2. Enable Comp */
2822 val = I915_READ(CHICKEN_MISC_2);
2823 val &= ~COMP_PWR_DOWN;
2824 I915_WRITE(CHICKEN_MISC_2, val);
2825
2826 val = I915_READ(CNL_PORT_COMP_DW3);
2827 procmon = &cnl_procmon_values[CNL_PROCMON_IDX(val)];
2828
2829 WARN_ON(procmon->dw10 == 0);
2830
2831 val = I915_READ(CNL_PORT_COMP_DW1);
2832 val &= ~((0xff << 16) | 0xff);
2833 val |= procmon->dw1;
2834 I915_WRITE(CNL_PORT_COMP_DW1, val);
2835
2836 I915_WRITE(CNL_PORT_COMP_DW9, procmon->dw9);
2837 I915_WRITE(CNL_PORT_COMP_DW10, procmon->dw10);
2838
2839 val = I915_READ(CNL_PORT_COMP_DW0);
2840 val |= COMP_INIT;
2841 I915_WRITE(CNL_PORT_COMP_DW0, val);
2842
2843 /* 3. */
2844 val = I915_READ(CNL_PORT_CL1CM_DW5);
2845 val |= CL_POWER_DOWN_ENABLE;
2846 I915_WRITE(CNL_PORT_CL1CM_DW5, val);
2847
Imre Deakb38131f2017-06-29 18:37:02 +03002848 /*
2849 * 4. Enable Power Well 1 (PG1).
2850 * The AUX IO power wells will be enabled on demand.
2851 */
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07002852 mutex_lock(&power_domains->lock);
2853 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
2854 intel_power_well_enable(dev_priv, well);
2855 mutex_unlock(&power_domains->lock);
2856
2857 /* 5. Enable CD clock */
2858 cnl_init_cdclk(dev_priv);
2859
2860 /* 6. Enable DBUF */
2861 gen9_dbuf_enable(dev_priv);
2862}
2863
2864#undef CNL_PROCMON_IDX
2865#undef NUM_CNL_PROCMON
2866
2867static void cnl_display_core_uninit(struct drm_i915_private *dev_priv)
2868{
2869 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2870 struct i915_power_well *well;
2871 u32 val;
2872
2873 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
2874
2875 /* 1. Disable all display engine functions -> aready done */
2876
2877 /* 2. Disable DBUF */
2878 gen9_dbuf_disable(dev_priv);
2879
2880 /* 3. Disable CD clock */
2881 cnl_uninit_cdclk(dev_priv);
2882
Imre Deakb38131f2017-06-29 18:37:02 +03002883 /*
2884 * 4. Disable Power Well 1 (PG1).
2885 * The AUX IO power wells are toggled on demand, so they are already
2886 * disabled at this point.
2887 */
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07002888 mutex_lock(&power_domains->lock);
2889 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
2890 intel_power_well_disable(dev_priv, well);
2891 mutex_unlock(&power_domains->lock);
2892
Imre Deak846c6b22017-06-29 18:36:58 +03002893 usleep_range(10, 30); /* 10 us delay per Bspec */
2894
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07002895 /* 5. Disable Comp */
2896 val = I915_READ(CHICKEN_MISC_2);
2897 val |= COMP_PWR_DOWN;
2898 I915_WRITE(CHICKEN_MISC_2, val);
2899}
2900
Ville Syrjälä70722462015-04-10 18:21:28 +03002901static void chv_phy_control_init(struct drm_i915_private *dev_priv)
2902{
2903 struct i915_power_well *cmn_bc =
2904 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_BC);
2905 struct i915_power_well *cmn_d =
2906 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_D);
2907
2908 /*
2909 * DISPLAY_PHY_CONTROL can get corrupted if read. As a
2910 * workaround never ever read DISPLAY_PHY_CONTROL, and
2911 * instead maintain a shadow copy ourselves. Use the actual
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002912 * power well state and lane status to reconstruct the
2913 * expected initial value.
Ville Syrjälä70722462015-04-10 18:21:28 +03002914 */
2915 dev_priv->chv_phy_control =
Ville Syrjäläbc284542015-05-26 20:22:38 +03002916 PHY_LDO_SEQ_DELAY(PHY_LDO_DELAY_600NS, DPIO_PHY0) |
2917 PHY_LDO_SEQ_DELAY(PHY_LDO_DELAY_600NS, DPIO_PHY1) |
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002918 PHY_CH_POWER_MODE(PHY_CH_DEEP_PSR, DPIO_PHY0, DPIO_CH0) |
2919 PHY_CH_POWER_MODE(PHY_CH_DEEP_PSR, DPIO_PHY0, DPIO_CH1) |
2920 PHY_CH_POWER_MODE(PHY_CH_DEEP_PSR, DPIO_PHY1, DPIO_CH0);
2921
2922 /*
2923 * If all lanes are disabled we leave the override disabled
2924 * with all power down bits cleared to match the state we
2925 * would use after disabling the port. Otherwise enable the
2926 * override and set the lane powerdown bits accding to the
2927 * current lane status.
2928 */
2929 if (cmn_bc->ops->is_enabled(dev_priv, cmn_bc)) {
2930 uint32_t status = I915_READ(DPLL(PIPE_A));
2931 unsigned int mask;
2932
2933 mask = status & DPLL_PORTB_READY_MASK;
2934 if (mask == 0xf)
2935 mask = 0x0;
2936 else
2937 dev_priv->chv_phy_control |=
2938 PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY0, DPIO_CH0);
2939
2940 dev_priv->chv_phy_control |=
2941 PHY_CH_POWER_DOWN_OVRD(mask, DPIO_PHY0, DPIO_CH0);
2942
2943 mask = (status & DPLL_PORTC_READY_MASK) >> 4;
2944 if (mask == 0xf)
2945 mask = 0x0;
2946 else
2947 dev_priv->chv_phy_control |=
2948 PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY0, DPIO_CH1);
2949
2950 dev_priv->chv_phy_control |=
2951 PHY_CH_POWER_DOWN_OVRD(mask, DPIO_PHY0, DPIO_CH1);
2952
Ville Syrjälä70722462015-04-10 18:21:28 +03002953 dev_priv->chv_phy_control |= PHY_COM_LANE_RESET_DEASSERT(DPIO_PHY0);
Ville Syrjälä3be60de2015-09-08 18:05:45 +03002954
2955 dev_priv->chv_phy_assert[DPIO_PHY0] = false;
2956 } else {
2957 dev_priv->chv_phy_assert[DPIO_PHY0] = true;
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002958 }
2959
2960 if (cmn_d->ops->is_enabled(dev_priv, cmn_d)) {
2961 uint32_t status = I915_READ(DPIO_PHY_STATUS);
2962 unsigned int mask;
2963
2964 mask = status & DPLL_PORTD_READY_MASK;
2965
2966 if (mask == 0xf)
2967 mask = 0x0;
2968 else
2969 dev_priv->chv_phy_control |=
2970 PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY1, DPIO_CH0);
2971
2972 dev_priv->chv_phy_control |=
2973 PHY_CH_POWER_DOWN_OVRD(mask, DPIO_PHY1, DPIO_CH0);
2974
Ville Syrjälä70722462015-04-10 18:21:28 +03002975 dev_priv->chv_phy_control |= PHY_COM_LANE_RESET_DEASSERT(DPIO_PHY1);
Ville Syrjälä3be60de2015-09-08 18:05:45 +03002976
2977 dev_priv->chv_phy_assert[DPIO_PHY1] = false;
2978 } else {
2979 dev_priv->chv_phy_assert[DPIO_PHY1] = true;
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002980 }
2981
2982 I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
2983
2984 DRM_DEBUG_KMS("Initial PHY_CONTROL=0x%08x\n",
2985 dev_priv->chv_phy_control);
Ville Syrjälä70722462015-04-10 18:21:28 +03002986}
2987
Daniel Vetter9c065a72014-09-30 10:56:38 +02002988static void vlv_cmnlane_wa(struct drm_i915_private *dev_priv)
2989{
2990 struct i915_power_well *cmn =
2991 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_BC);
2992 struct i915_power_well *disp2d =
2993 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DISP2D);
2994
Daniel Vetter9c065a72014-09-30 10:56:38 +02002995 /* If the display might be already active skip this */
Ville Syrjälä5d93a6e2014-10-16 20:52:33 +03002996 if (cmn->ops->is_enabled(dev_priv, cmn) &&
2997 disp2d->ops->is_enabled(dev_priv, disp2d) &&
Daniel Vetter9c065a72014-09-30 10:56:38 +02002998 I915_READ(DPIO_CTL) & DPIO_CMNRST)
2999 return;
3000
3001 DRM_DEBUG_KMS("toggling display PHY side reset\n");
3002
3003 /* cmnlane needs DPLL registers */
3004 disp2d->ops->enable(dev_priv, disp2d);
3005
3006 /*
3007 * From VLV2A0_DP_eDP_HDMI_DPIO_driver_vbios_notes_11.docx:
3008 * Need to assert and de-assert PHY SB reset by gating the
3009 * common lane power, then un-gating it.
3010 * Simply ungating isn't enough to reset the PHY enough to get
3011 * ports and lanes running.
3012 */
3013 cmn->ops->disable(dev_priv, cmn);
3014}
3015
Daniel Vettere4e76842014-09-30 10:56:42 +02003016/**
3017 * intel_power_domains_init_hw - initialize hardware power domain state
3018 * @dev_priv: i915 device instance
Tvrtko Ursulin14bb2c12016-06-03 14:02:17 +01003019 * @resume: Called from resume code paths or not
Daniel Vettere4e76842014-09-30 10:56:42 +02003020 *
3021 * This function initializes the hardware power domain state and enables all
Imre Deak8d8c3862017-02-17 17:39:46 +02003022 * power wells belonging to the INIT power domain. Power wells in other
3023 * domains (and not in the INIT domain) are referenced or disabled during the
3024 * modeset state HW readout. After that the reference count of each power well
3025 * must match its HW enabled state, see intel_power_domains_verify_state().
Daniel Vettere4e76842014-09-30 10:56:42 +02003026 */
Imre Deak73dfc222015-11-17 17:33:53 +02003027void intel_power_domains_init_hw(struct drm_i915_private *dev_priv, bool resume)
Daniel Vetter9c065a72014-09-30 10:56:38 +02003028{
Daniel Vetter9c065a72014-09-30 10:56:38 +02003029 struct i915_power_domains *power_domains = &dev_priv->power_domains;
3030
3031 power_domains->initializing = true;
3032
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07003033 if (IS_CANNONLAKE(dev_priv)) {
3034 cnl_display_core_init(dev_priv, resume);
3035 } else if (IS_GEN9_BC(dev_priv)) {
Imre Deak73dfc222015-11-17 17:33:53 +02003036 skl_display_core_init(dev_priv, resume);
Ander Conselvan de Oliveirab817c442016-12-02 10:23:56 +02003037 } else if (IS_GEN9_LP(dev_priv)) {
Imre Deakd7d7c9e2016-04-01 16:02:42 +03003038 bxt_display_core_init(dev_priv, resume);
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01003039 } else if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä770effb2015-07-08 23:45:51 +03003040 mutex_lock(&power_domains->lock);
Ville Syrjälä70722462015-04-10 18:21:28 +03003041 chv_phy_control_init(dev_priv);
Ville Syrjälä770effb2015-07-08 23:45:51 +03003042 mutex_unlock(&power_domains->lock);
Tvrtko Ursulin11a914c2016-10-13 11:03:08 +01003043 } else if (IS_VALLEYVIEW(dev_priv)) {
Daniel Vetter9c065a72014-09-30 10:56:38 +02003044 mutex_lock(&power_domains->lock);
3045 vlv_cmnlane_wa(dev_priv);
3046 mutex_unlock(&power_domains->lock);
3047 }
3048
3049 /* For now, we need the power well to be always enabled. */
3050 intel_display_set_init_power(dev_priv, true);
Imre Deakd314cd42015-11-17 17:44:23 +02003051 /* Disable power support if the user asked so. */
3052 if (!i915.disable_power_well)
3053 intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
Imre Deak30eade12015-11-04 19:24:13 +02003054 intel_power_domains_sync_hw(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02003055 power_domains->initializing = false;
3056}
3057
Daniel Vettere4e76842014-09-30 10:56:42 +02003058/**
Imre Deak73dfc222015-11-17 17:33:53 +02003059 * intel_power_domains_suspend - suspend power domain state
3060 * @dev_priv: i915 device instance
3061 *
3062 * This function prepares the hardware power domain state before entering
3063 * system suspend. It must be paired with intel_power_domains_init_hw().
3064 */
3065void intel_power_domains_suspend(struct drm_i915_private *dev_priv)
3066{
Imre Deakd314cd42015-11-17 17:44:23 +02003067 /*
3068 * Even if power well support was disabled we still want to disable
3069 * power wells while we are system suspended.
3070 */
3071 if (!i915.disable_power_well)
3072 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
Imre Deak2622d792016-02-29 22:49:02 +02003073
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07003074 if (IS_CANNONLAKE(dev_priv))
3075 cnl_display_core_uninit(dev_priv);
3076 else if (IS_GEN9_BC(dev_priv))
Imre Deak2622d792016-02-29 22:49:02 +02003077 skl_display_core_uninit(dev_priv);
Ander Conselvan de Oliveirab817c442016-12-02 10:23:56 +02003078 else if (IS_GEN9_LP(dev_priv))
Imre Deakd7d7c9e2016-04-01 16:02:42 +03003079 bxt_display_core_uninit(dev_priv);
Imre Deak73dfc222015-11-17 17:33:53 +02003080}
3081
Imre Deak8d8c3862017-02-17 17:39:46 +02003082static void intel_power_domains_dump_info(struct drm_i915_private *dev_priv)
3083{
3084 struct i915_power_domains *power_domains = &dev_priv->power_domains;
3085 struct i915_power_well *power_well;
3086
3087 for_each_power_well(dev_priv, power_well) {
3088 enum intel_display_power_domain domain;
3089
3090 DRM_DEBUG_DRIVER("%-25s %d\n",
3091 power_well->name, power_well->count);
3092
3093 for_each_power_domain(domain, power_well->domains)
3094 DRM_DEBUG_DRIVER(" %-23s %d\n",
3095 intel_display_power_domain_str(domain),
3096 power_domains->domain_use_count[domain]);
3097 }
3098}
3099
3100/**
3101 * intel_power_domains_verify_state - verify the HW/SW state for all power wells
3102 * @dev_priv: i915 device instance
3103 *
3104 * Verify if the reference count of each power well matches its HW enabled
3105 * state and the total refcount of the domains it belongs to. This must be
3106 * called after modeset HW state sanitization, which is responsible for
3107 * acquiring reference counts for any power wells in use and disabling the
3108 * ones left on by BIOS but not required by any active output.
3109 */
3110void intel_power_domains_verify_state(struct drm_i915_private *dev_priv)
3111{
3112 struct i915_power_domains *power_domains = &dev_priv->power_domains;
3113 struct i915_power_well *power_well;
3114 bool dump_domain_info;
3115
3116 mutex_lock(&power_domains->lock);
3117
3118 dump_domain_info = false;
3119 for_each_power_well(dev_priv, power_well) {
3120 enum intel_display_power_domain domain;
3121 int domains_count;
3122 bool enabled;
3123
3124 /*
3125 * Power wells not belonging to any domain (like the MISC_IO
3126 * and PW1 power wells) are under FW control, so ignore them,
3127 * since their state can change asynchronously.
3128 */
3129 if (!power_well->domains)
3130 continue;
3131
3132 enabled = power_well->ops->is_enabled(dev_priv, power_well);
3133 if ((power_well->count || power_well->always_on) != enabled)
3134 DRM_ERROR("power well %s state mismatch (refcount %d/enabled %d)",
3135 power_well->name, power_well->count, enabled);
3136
3137 domains_count = 0;
3138 for_each_power_domain(domain, power_well->domains)
3139 domains_count += power_domains->domain_use_count[domain];
3140
3141 if (power_well->count != domains_count) {
3142 DRM_ERROR("power well %s refcount/domain refcount mismatch "
3143 "(refcount %d/domains refcount %d)\n",
3144 power_well->name, power_well->count,
3145 domains_count);
3146 dump_domain_info = true;
3147 }
3148 }
3149
3150 if (dump_domain_info) {
3151 static bool dumped;
3152
3153 if (!dumped) {
3154 intel_power_domains_dump_info(dev_priv);
3155 dumped = true;
3156 }
3157 }
3158
3159 mutex_unlock(&power_domains->lock);
3160}
3161
Imre Deak73dfc222015-11-17 17:33:53 +02003162/**
Daniel Vettere4e76842014-09-30 10:56:42 +02003163 * intel_runtime_pm_get - grab a runtime pm reference
3164 * @dev_priv: i915 device instance
3165 *
3166 * This function grabs a device-level runtime pm reference (mostly used for GEM
3167 * code to ensure the GTT or GT is on) and ensures that it is powered up.
3168 *
3169 * Any runtime pm reference obtained by this function must have a symmetric
3170 * call to intel_runtime_pm_put() to release the reference again.
3171 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02003172void intel_runtime_pm_get(struct drm_i915_private *dev_priv)
3173{
David Weinehall52a05c32016-08-22 13:32:44 +03003174 struct pci_dev *pdev = dev_priv->drm.pdev;
3175 struct device *kdev = &pdev->dev;
Imre Deakf5073822017-03-28 12:38:55 +03003176 int ret;
Daniel Vetter9c065a72014-09-30 10:56:38 +02003177
Imre Deakf5073822017-03-28 12:38:55 +03003178 ret = pm_runtime_get_sync(kdev);
3179 WARN_ONCE(ret < 0, "pm_runtime_get_sync() failed: %d\n", ret);
Imre Deak1f814da2015-12-16 02:52:19 +02003180
3181 atomic_inc(&dev_priv->pm.wakeref_count);
Imre Deakc9b88462015-12-15 20:10:34 +02003182 assert_rpm_wakelock_held(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02003183}
3184
Daniel Vettere4e76842014-09-30 10:56:42 +02003185/**
Imre Deak09731282016-02-17 14:17:42 +02003186 * intel_runtime_pm_get_if_in_use - grab a runtime pm reference if device in use
3187 * @dev_priv: i915 device instance
3188 *
3189 * This function grabs a device-level runtime pm reference if the device is
3190 * already in use and ensures that it is powered up.
3191 *
3192 * Any runtime pm reference obtained by this function must have a symmetric
3193 * call to intel_runtime_pm_put() to release the reference again.
3194 */
3195bool intel_runtime_pm_get_if_in_use(struct drm_i915_private *dev_priv)
3196{
David Weinehall52a05c32016-08-22 13:32:44 +03003197 struct pci_dev *pdev = dev_priv->drm.pdev;
3198 struct device *kdev = &pdev->dev;
Imre Deak09731282016-02-17 14:17:42 +02003199
Chris Wilson135dc792016-02-25 21:10:28 +00003200 if (IS_ENABLED(CONFIG_PM)) {
David Weinehallc49d13e2016-08-22 13:32:42 +03003201 int ret = pm_runtime_get_if_in_use(kdev);
Imre Deak09731282016-02-17 14:17:42 +02003202
Chris Wilson135dc792016-02-25 21:10:28 +00003203 /*
3204 * In cases runtime PM is disabled by the RPM core and we get
3205 * an -EINVAL return value we are not supposed to call this
3206 * function, since the power state is undefined. This applies
3207 * atm to the late/early system suspend/resume handlers.
3208 */
Imre Deakf5073822017-03-28 12:38:55 +03003209 WARN_ONCE(ret < 0,
3210 "pm_runtime_get_if_in_use() failed: %d\n", ret);
Chris Wilson135dc792016-02-25 21:10:28 +00003211 if (ret <= 0)
3212 return false;
3213 }
Imre Deak09731282016-02-17 14:17:42 +02003214
3215 atomic_inc(&dev_priv->pm.wakeref_count);
3216 assert_rpm_wakelock_held(dev_priv);
3217
3218 return true;
3219}
3220
3221/**
Daniel Vettere4e76842014-09-30 10:56:42 +02003222 * intel_runtime_pm_get_noresume - grab a runtime pm reference
3223 * @dev_priv: i915 device instance
3224 *
3225 * This function grabs a device-level runtime pm reference (mostly used for GEM
3226 * code to ensure the GTT or GT is on).
3227 *
3228 * It will _not_ power up the device but instead only check that it's powered
3229 * on. Therefore it is only valid to call this functions from contexts where
3230 * the device is known to be powered up and where trying to power it up would
3231 * result in hilarity and deadlocks. That pretty much means only the system
3232 * suspend/resume code where this is used to grab runtime pm references for
3233 * delayed setup down in work items.
3234 *
3235 * Any runtime pm reference obtained by this function must have a symmetric
3236 * call to intel_runtime_pm_put() to release the reference again.
3237 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02003238void intel_runtime_pm_get_noresume(struct drm_i915_private *dev_priv)
3239{
David Weinehall52a05c32016-08-22 13:32:44 +03003240 struct pci_dev *pdev = dev_priv->drm.pdev;
3241 struct device *kdev = &pdev->dev;
Daniel Vetter9c065a72014-09-30 10:56:38 +02003242
Imre Deakc9b88462015-12-15 20:10:34 +02003243 assert_rpm_wakelock_held(dev_priv);
David Weinehallc49d13e2016-08-22 13:32:42 +03003244 pm_runtime_get_noresume(kdev);
Imre Deak1f814da2015-12-16 02:52:19 +02003245
3246 atomic_inc(&dev_priv->pm.wakeref_count);
Daniel Vetter9c065a72014-09-30 10:56:38 +02003247}
3248
Daniel Vettere4e76842014-09-30 10:56:42 +02003249/**
3250 * intel_runtime_pm_put - release a runtime pm reference
3251 * @dev_priv: i915 device instance
3252 *
3253 * This function drops the device-level runtime pm reference obtained by
3254 * intel_runtime_pm_get() and might power down the corresponding
3255 * hardware block right away if this is the last reference.
3256 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02003257void intel_runtime_pm_put(struct drm_i915_private *dev_priv)
3258{
David Weinehall52a05c32016-08-22 13:32:44 +03003259 struct pci_dev *pdev = dev_priv->drm.pdev;
3260 struct device *kdev = &pdev->dev;
Daniel Vetter9c065a72014-09-30 10:56:38 +02003261
Imre Deak542db3c2015-12-15 20:10:36 +02003262 assert_rpm_wakelock_held(dev_priv);
Chris Wilson2eedfc72016-10-24 13:42:17 +01003263 atomic_dec(&dev_priv->pm.wakeref_count);
Imre Deak1f814da2015-12-16 02:52:19 +02003264
David Weinehallc49d13e2016-08-22 13:32:42 +03003265 pm_runtime_mark_last_busy(kdev);
3266 pm_runtime_put_autosuspend(kdev);
Daniel Vetter9c065a72014-09-30 10:56:38 +02003267}
3268
Daniel Vettere4e76842014-09-30 10:56:42 +02003269/**
3270 * intel_runtime_pm_enable - enable runtime pm
3271 * @dev_priv: i915 device instance
3272 *
3273 * This function enables runtime pm at the end of the driver load sequence.
3274 *
3275 * Note that this function does currently not enable runtime pm for the
3276 * subordinate display power domains. That is only done on the first modeset
3277 * using intel_display_set_init_power().
3278 */
Daniel Vetterf458ebb2014-09-30 10:56:39 +02003279void intel_runtime_pm_enable(struct drm_i915_private *dev_priv)
Daniel Vetter9c065a72014-09-30 10:56:38 +02003280{
David Weinehall52a05c32016-08-22 13:32:44 +03003281 struct pci_dev *pdev = dev_priv->drm.pdev;
David Weinehall52a05c32016-08-22 13:32:44 +03003282 struct device *kdev = &pdev->dev;
Daniel Vetter9c065a72014-09-30 10:56:38 +02003283
David Weinehallc49d13e2016-08-22 13:32:42 +03003284 pm_runtime_set_autosuspend_delay(kdev, 10000); /* 10s */
3285 pm_runtime_mark_last_busy(kdev);
Imre Deakcbc68dc2015-12-17 19:04:33 +02003286
Imre Deak25b181b2015-12-17 13:44:56 +02003287 /*
3288 * Take a permanent reference to disable the RPM functionality and drop
3289 * it only when unloading the driver. Use the low level get/put helpers,
3290 * so the driver's own RPM reference tracking asserts also work on
3291 * platforms without RPM support.
3292 */
Tvrtko Ursulin6772ffe2016-10-13 11:02:55 +01003293 if (!HAS_RUNTIME_PM(dev_priv)) {
Imre Deakf5073822017-03-28 12:38:55 +03003294 int ret;
3295
David Weinehallc49d13e2016-08-22 13:32:42 +03003296 pm_runtime_dont_use_autosuspend(kdev);
Imre Deakf5073822017-03-28 12:38:55 +03003297 ret = pm_runtime_get_sync(kdev);
3298 WARN(ret < 0, "pm_runtime_get_sync() failed: %d\n", ret);
Imre Deakcbc68dc2015-12-17 19:04:33 +02003299 } else {
David Weinehallc49d13e2016-08-22 13:32:42 +03003300 pm_runtime_use_autosuspend(kdev);
Imre Deakcbc68dc2015-12-17 19:04:33 +02003301 }
Daniel Vetter9c065a72014-09-30 10:56:38 +02003302
Imre Deakaabee1b2015-12-15 20:10:29 +02003303 /*
3304 * The core calls the driver load handler with an RPM reference held.
3305 * We drop that here and will reacquire it during unloading in
3306 * intel_power_domains_fini().
3307 */
David Weinehallc49d13e2016-08-22 13:32:42 +03003308 pm_runtime_put_autosuspend(kdev);
Daniel Vetter9c065a72014-09-30 10:56:38 +02003309}