blob: 0f64bc12f308068d4f3b70678cd882dffcba1056 [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
Daniel Vetter9c065a72014-09-30 10:56:38 +020052#define for_each_power_well(i, power_well, domain_mask, power_domains) \
53 for (i = 0; \
54 i < (power_domains)->power_well_count && \
55 ((power_well) = &(power_domains)->power_wells[i]); \
56 i++) \
Jani Nikula95150bd2015-11-24 21:21:56 +020057 for_each_if ((power_well)->domains & (domain_mask))
Daniel Vetter9c065a72014-09-30 10:56:38 +020058
59#define for_each_power_well_rev(i, power_well, domain_mask, power_domains) \
60 for (i = (power_domains)->power_well_count - 1; \
61 i >= 0 && ((power_well) = &(power_domains)->power_wells[i]);\
62 i--) \
Jani Nikula95150bd2015-11-24 21:21:56 +020063 for_each_if ((power_well)->domains & (domain_mask))
Daniel Vetter9c065a72014-09-30 10:56:38 +020064
Suketu Shah5aefb232015-04-16 14:22:10 +053065bool intel_display_power_well_is_enabled(struct drm_i915_private *dev_priv,
66 int power_well_id);
67
Imre Deak9c8d0b82016-06-13 16:44:34 +030068static struct i915_power_well *
69lookup_power_well(struct drm_i915_private *dev_priv, int power_well_id);
70
Daniel Stone9895ad02015-11-20 15:55:33 +000071const char *
72intel_display_power_domain_str(enum intel_display_power_domain domain)
73{
74 switch (domain) {
75 case POWER_DOMAIN_PIPE_A:
76 return "PIPE_A";
77 case POWER_DOMAIN_PIPE_B:
78 return "PIPE_B";
79 case POWER_DOMAIN_PIPE_C:
80 return "PIPE_C";
81 case POWER_DOMAIN_PIPE_A_PANEL_FITTER:
82 return "PIPE_A_PANEL_FITTER";
83 case POWER_DOMAIN_PIPE_B_PANEL_FITTER:
84 return "PIPE_B_PANEL_FITTER";
85 case POWER_DOMAIN_PIPE_C_PANEL_FITTER:
86 return "PIPE_C_PANEL_FITTER";
87 case POWER_DOMAIN_TRANSCODER_A:
88 return "TRANSCODER_A";
89 case POWER_DOMAIN_TRANSCODER_B:
90 return "TRANSCODER_B";
91 case POWER_DOMAIN_TRANSCODER_C:
92 return "TRANSCODER_C";
93 case POWER_DOMAIN_TRANSCODER_EDP:
94 return "TRANSCODER_EDP";
Jani Nikula4d1de972016-03-18 17:05:42 +020095 case POWER_DOMAIN_TRANSCODER_DSI_A:
96 return "TRANSCODER_DSI_A";
97 case POWER_DOMAIN_TRANSCODER_DSI_C:
98 return "TRANSCODER_DSI_C";
Daniel Stone9895ad02015-11-20 15:55:33 +000099 case POWER_DOMAIN_PORT_DDI_A_LANES:
100 return "PORT_DDI_A_LANES";
101 case POWER_DOMAIN_PORT_DDI_B_LANES:
102 return "PORT_DDI_B_LANES";
103 case POWER_DOMAIN_PORT_DDI_C_LANES:
104 return "PORT_DDI_C_LANES";
105 case POWER_DOMAIN_PORT_DDI_D_LANES:
106 return "PORT_DDI_D_LANES";
107 case POWER_DOMAIN_PORT_DDI_E_LANES:
108 return "PORT_DDI_E_LANES";
109 case POWER_DOMAIN_PORT_DSI:
110 return "PORT_DSI";
111 case POWER_DOMAIN_PORT_CRT:
112 return "PORT_CRT";
113 case POWER_DOMAIN_PORT_OTHER:
114 return "PORT_OTHER";
115 case POWER_DOMAIN_VGA:
116 return "VGA";
117 case POWER_DOMAIN_AUDIO:
118 return "AUDIO";
119 case POWER_DOMAIN_PLLS:
120 return "PLLS";
121 case POWER_DOMAIN_AUX_A:
122 return "AUX_A";
123 case POWER_DOMAIN_AUX_B:
124 return "AUX_B";
125 case POWER_DOMAIN_AUX_C:
126 return "AUX_C";
127 case POWER_DOMAIN_AUX_D:
128 return "AUX_D";
129 case POWER_DOMAIN_GMBUS:
130 return "GMBUS";
131 case POWER_DOMAIN_INIT:
132 return "INIT";
133 case POWER_DOMAIN_MODESET:
134 return "MODESET";
135 default:
136 MISSING_CASE(domain);
137 return "?";
138 }
139}
140
Damien Lespiaue8ca9322015-07-30 18:20:26 -0300141static void intel_power_well_enable(struct drm_i915_private *dev_priv,
142 struct i915_power_well *power_well)
143{
144 DRM_DEBUG_KMS("enabling %s\n", power_well->name);
145 power_well->ops->enable(dev_priv, power_well);
146 power_well->hw_enabled = true;
147}
148
Damien Lespiaudcddab32015-07-30 18:20:27 -0300149static void intel_power_well_disable(struct drm_i915_private *dev_priv,
150 struct i915_power_well *power_well)
151{
152 DRM_DEBUG_KMS("disabling %s\n", power_well->name);
153 power_well->hw_enabled = false;
154 power_well->ops->disable(dev_priv, power_well);
155}
156
Imre Deakb409ca92016-06-13 16:44:33 +0300157static void intel_power_well_get(struct drm_i915_private *dev_priv,
158 struct i915_power_well *power_well)
159{
160 if (!power_well->count++)
161 intel_power_well_enable(dev_priv, power_well);
162}
163
164static void intel_power_well_put(struct drm_i915_private *dev_priv,
165 struct i915_power_well *power_well)
166{
167 WARN(!power_well->count, "Use count on power well %s is already zero",
168 power_well->name);
169
170 if (!--power_well->count)
171 intel_power_well_disable(dev_priv, power_well);
172}
173
Daniel Vettere4e76842014-09-30 10:56:42 +0200174/*
Daniel Vetter9c065a72014-09-30 10:56:38 +0200175 * We should only use the power well if we explicitly asked the hardware to
176 * enable it, so check if it's enabled and also check if we've requested it to
177 * be enabled.
178 */
179static bool hsw_power_well_enabled(struct drm_i915_private *dev_priv,
180 struct i915_power_well *power_well)
181{
182 return I915_READ(HSW_PWR_WELL_DRIVER) ==
183 (HSW_PWR_WELL_ENABLE_REQUEST | HSW_PWR_WELL_STATE_ENABLED);
184}
185
Daniel Vettere4e76842014-09-30 10:56:42 +0200186/**
187 * __intel_display_power_is_enabled - unlocked check for a power domain
188 * @dev_priv: i915 device instance
189 * @domain: power domain to check
190 *
191 * This is the unlocked version of intel_display_power_is_enabled() and should
192 * only be used from error capture and recovery code where deadlocks are
193 * possible.
194 *
195 * Returns:
196 * True when the power domain is enabled, false otherwise.
197 */
Daniel Vetterf458ebb2014-09-30 10:56:39 +0200198bool __intel_display_power_is_enabled(struct drm_i915_private *dev_priv,
199 enum intel_display_power_domain domain)
Daniel Vetter9c065a72014-09-30 10:56:38 +0200200{
201 struct i915_power_domains *power_domains;
202 struct i915_power_well *power_well;
203 bool is_enabled;
204 int i;
205
206 if (dev_priv->pm.suspended)
207 return false;
208
209 power_domains = &dev_priv->power_domains;
210
211 is_enabled = true;
212
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200213 for_each_power_well_rev(i, power_well, BIT_ULL(domain), power_domains) {
Daniel Vetter9c065a72014-09-30 10:56:38 +0200214 if (power_well->always_on)
215 continue;
216
217 if (!power_well->hw_enabled) {
218 is_enabled = false;
219 break;
220 }
221 }
222
223 return is_enabled;
224}
225
Daniel Vettere4e76842014-09-30 10:56:42 +0200226/**
Damien Lespiauf61ccae2014-11-25 13:45:41 +0000227 * intel_display_power_is_enabled - check for a power domain
Daniel Vettere4e76842014-09-30 10:56:42 +0200228 * @dev_priv: i915 device instance
229 * @domain: power domain to check
230 *
231 * This function can be used to check the hw power domain state. It is mostly
232 * used in hardware state readout functions. Everywhere else code should rely
233 * upon explicit power domain reference counting to ensure that the hardware
234 * block is powered up before accessing it.
235 *
236 * Callers must hold the relevant modesetting locks to ensure that concurrent
237 * threads can't disable the power well while the caller tries to read a few
238 * registers.
239 *
240 * Returns:
241 * True when the power domain is enabled, false otherwise.
242 */
Daniel Vetterf458ebb2014-09-30 10:56:39 +0200243bool intel_display_power_is_enabled(struct drm_i915_private *dev_priv,
244 enum intel_display_power_domain domain)
Daniel Vetter9c065a72014-09-30 10:56:38 +0200245{
246 struct i915_power_domains *power_domains;
247 bool ret;
248
249 power_domains = &dev_priv->power_domains;
250
251 mutex_lock(&power_domains->lock);
Daniel Vetterf458ebb2014-09-30 10:56:39 +0200252 ret = __intel_display_power_is_enabled(dev_priv, domain);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200253 mutex_unlock(&power_domains->lock);
254
255 return ret;
256}
257
Daniel Vettere4e76842014-09-30 10:56:42 +0200258/**
259 * intel_display_set_init_power - set the initial power domain state
260 * @dev_priv: i915 device instance
261 * @enable: whether to enable or disable the initial power domain state
262 *
263 * For simplicity our driver load/unload and system suspend/resume code assumes
264 * that all power domains are always enabled. This functions controls the state
265 * of this little hack. While the initial power domain state is enabled runtime
266 * pm is effectively disabled.
267 */
Daniel Vetterd9bc89d92014-09-30 10:56:40 +0200268void intel_display_set_init_power(struct drm_i915_private *dev_priv,
269 bool enable)
270{
271 if (dev_priv->power_domains.init_power_on == enable)
272 return;
273
274 if (enable)
275 intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
276 else
277 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
278
279 dev_priv->power_domains.init_power_on = enable;
280}
281
Daniel Vetter9c065a72014-09-30 10:56:38 +0200282/*
283 * Starting with Haswell, we have a "Power Down Well" that can be turned off
284 * when not needed anymore. We have 4 registers that can request the power well
285 * to be enabled, and it will only be disabled if none of the registers is
286 * requesting it to be enabled.
287 */
288static void hsw_power_well_post_enable(struct drm_i915_private *dev_priv)
289{
David Weinehall52a05c32016-08-22 13:32:44 +0300290 struct pci_dev *pdev = dev_priv->drm.pdev;
Daniel Vetter9c065a72014-09-30 10:56:38 +0200291
292 /*
293 * After we re-enable the power well, if we touch VGA register 0x3d5
294 * we'll get unclaimed register interrupts. This stops after we write
295 * anything to the VGA MSR register. The vgacon module uses this
296 * register all the time, so if we unbind our driver and, as a
297 * consequence, bind vgacon, we'll get stuck in an infinite loop at
298 * console_unlock(). So make here we touch the VGA MSR register, making
299 * sure vgacon can keep working normally without triggering interrupts
300 * and error messages.
301 */
David Weinehall52a05c32016-08-22 13:32:44 +0300302 vga_get_uninterruptible(pdev, VGA_RSRC_LEGACY_IO);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200303 outb(inb(VGA_MSR_READ), VGA_MSR_WRITE);
David Weinehall52a05c32016-08-22 13:32:44 +0300304 vga_put(pdev, VGA_RSRC_LEGACY_IO);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200305
Tvrtko Ursulin86527442016-10-13 11:03:00 +0100306 if (IS_BROADWELL(dev_priv))
Damien Lespiau4c6c03b2015-03-06 18:50:48 +0000307 gen8_irq_power_well_post_enable(dev_priv,
308 1 << PIPE_C | 1 << PIPE_B);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200309}
310
Ville Syrjäläaae8ba82016-02-19 20:47:30 +0200311static void hsw_power_well_pre_disable(struct drm_i915_private *dev_priv)
312{
313 if (IS_BROADWELL(dev_priv))
314 gen8_irq_power_well_pre_disable(dev_priv,
315 1 << PIPE_C | 1 << PIPE_B);
316}
317
Damien Lespiaud14c0342015-03-06 18:50:51 +0000318static void skl_power_well_post_enable(struct drm_i915_private *dev_priv,
319 struct i915_power_well *power_well)
320{
David Weinehall52a05c32016-08-22 13:32:44 +0300321 struct pci_dev *pdev = dev_priv->drm.pdev;
Damien Lespiaud14c0342015-03-06 18:50:51 +0000322
323 /*
324 * After we re-enable the power well, if we touch VGA register 0x3d5
325 * we'll get unclaimed register interrupts. This stops after we write
326 * anything to the VGA MSR register. The vgacon module uses this
327 * register all the time, so if we unbind our driver and, as a
328 * consequence, bind vgacon, we'll get stuck in an infinite loop at
329 * console_unlock(). So make here we touch the VGA MSR register, making
330 * sure vgacon can keep working normally without triggering interrupts
331 * and error messages.
332 */
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +0300333 if (power_well->id == SKL_DISP_PW_2) {
David Weinehall52a05c32016-08-22 13:32:44 +0300334 vga_get_uninterruptible(pdev, VGA_RSRC_LEGACY_IO);
Damien Lespiaud14c0342015-03-06 18:50:51 +0000335 outb(inb(VGA_MSR_READ), VGA_MSR_WRITE);
David Weinehall52a05c32016-08-22 13:32:44 +0300336 vga_put(pdev, VGA_RSRC_LEGACY_IO);
Damien Lespiaud14c0342015-03-06 18:50:51 +0000337
338 gen8_irq_power_well_post_enable(dev_priv,
339 1 << PIPE_C | 1 << PIPE_B);
340 }
Damien Lespiaud14c0342015-03-06 18:50:51 +0000341}
342
Ville Syrjäläaae8ba82016-02-19 20:47:30 +0200343static void skl_power_well_pre_disable(struct drm_i915_private *dev_priv,
344 struct i915_power_well *power_well)
345{
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +0300346 if (power_well->id == SKL_DISP_PW_2)
Ville Syrjäläaae8ba82016-02-19 20:47:30 +0200347 gen8_irq_power_well_pre_disable(dev_priv,
348 1 << PIPE_C | 1 << PIPE_B);
349}
350
Daniel Vetter9c065a72014-09-30 10:56:38 +0200351static void hsw_set_power_well(struct drm_i915_private *dev_priv,
352 struct i915_power_well *power_well, bool enable)
353{
354 bool is_enabled, enable_requested;
355 uint32_t tmp;
356
357 tmp = I915_READ(HSW_PWR_WELL_DRIVER);
358 is_enabled = tmp & HSW_PWR_WELL_STATE_ENABLED;
359 enable_requested = tmp & HSW_PWR_WELL_ENABLE_REQUEST;
360
361 if (enable) {
362 if (!enable_requested)
363 I915_WRITE(HSW_PWR_WELL_DRIVER,
364 HSW_PWR_WELL_ENABLE_REQUEST);
365
366 if (!is_enabled) {
367 DRM_DEBUG_KMS("Enabling power well\n");
Chris Wilson2c2ccc32016-06-30 15:33:32 +0100368 if (intel_wait_for_register(dev_priv,
369 HSW_PWR_WELL_DRIVER,
370 HSW_PWR_WELL_STATE_ENABLED,
371 HSW_PWR_WELL_STATE_ENABLED,
372 20))
Daniel Vetter9c065a72014-09-30 10:56:38 +0200373 DRM_ERROR("Timeout enabling power well\n");
Paulo Zanoni6d729bf2014-10-07 16:11:11 -0300374 hsw_power_well_post_enable(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200375 }
376
Daniel Vetter9c065a72014-09-30 10:56:38 +0200377 } else {
378 if (enable_requested) {
Ville Syrjäläaae8ba82016-02-19 20:47:30 +0200379 hsw_power_well_pre_disable(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200380 I915_WRITE(HSW_PWR_WELL_DRIVER, 0);
381 POSTING_READ(HSW_PWR_WELL_DRIVER);
382 DRM_DEBUG_KMS("Requesting to disable the power well\n");
383 }
384 }
385}
386
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000387#define SKL_DISPLAY_POWERWELL_2_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200388 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
389 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
390 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
391 BIT_ULL(POWER_DOMAIN_PIPE_C) | \
392 BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
393 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
394 BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
395 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
396 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
397 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_LANES) | \
398 BIT_ULL(POWER_DOMAIN_PORT_DDI_E_LANES) | \
399 BIT_ULL(POWER_DOMAIN_AUX_B) | \
400 BIT_ULL(POWER_DOMAIN_AUX_C) | \
401 BIT_ULL(POWER_DOMAIN_AUX_D) | \
402 BIT_ULL(POWER_DOMAIN_AUDIO) | \
403 BIT_ULL(POWER_DOMAIN_VGA) | \
404 BIT_ULL(POWER_DOMAIN_INIT))
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000405#define SKL_DISPLAY_DDI_A_E_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200406 BIT_ULL(POWER_DOMAIN_PORT_DDI_A_LANES) | \
407 BIT_ULL(POWER_DOMAIN_PORT_DDI_E_LANES) | \
408 BIT_ULL(POWER_DOMAIN_INIT))
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000409#define SKL_DISPLAY_DDI_B_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200410 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
411 BIT_ULL(POWER_DOMAIN_INIT))
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000412#define SKL_DISPLAY_DDI_C_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200413 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
414 BIT_ULL(POWER_DOMAIN_INIT))
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000415#define SKL_DISPLAY_DDI_D_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200416 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_LANES) | \
417 BIT_ULL(POWER_DOMAIN_INIT))
Patrik Jakobsson9f836f92015-11-16 16:20:01 +0100418#define SKL_DISPLAY_DC_OFF_POWER_DOMAINS ( \
419 SKL_DISPLAY_POWERWELL_2_POWER_DOMAINS | \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200420 BIT_ULL(POWER_DOMAIN_MODESET) | \
421 BIT_ULL(POWER_DOMAIN_AUX_A) | \
422 BIT_ULL(POWER_DOMAIN_INIT))
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000423
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +0530424#define BXT_DISPLAY_POWERWELL_2_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200425 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
426 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
427 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
428 BIT_ULL(POWER_DOMAIN_PIPE_C) | \
429 BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
430 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
431 BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
432 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
433 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
434 BIT_ULL(POWER_DOMAIN_AUX_B) | \
435 BIT_ULL(POWER_DOMAIN_AUX_C) | \
436 BIT_ULL(POWER_DOMAIN_AUDIO) | \
437 BIT_ULL(POWER_DOMAIN_VGA) | \
438 BIT_ULL(POWER_DOMAIN_GMBUS) | \
439 BIT_ULL(POWER_DOMAIN_INIT))
Patrik Jakobsson9f836f92015-11-16 16:20:01 +0100440#define BXT_DISPLAY_DC_OFF_POWER_DOMAINS ( \
441 BXT_DISPLAY_POWERWELL_2_POWER_DOMAINS | \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200442 BIT_ULL(POWER_DOMAIN_MODESET) | \
443 BIT_ULL(POWER_DOMAIN_AUX_A) | \
444 BIT_ULL(POWER_DOMAIN_INIT))
Imre Deak9c8d0b82016-06-13 16:44:34 +0300445#define BXT_DPIO_CMN_A_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200446 BIT_ULL(POWER_DOMAIN_PORT_DDI_A_LANES) | \
447 BIT_ULL(POWER_DOMAIN_AUX_A) | \
448 BIT_ULL(POWER_DOMAIN_INIT))
Imre Deak9c8d0b82016-06-13 16:44:34 +0300449#define BXT_DPIO_CMN_BC_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200450 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
451 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
452 BIT_ULL(POWER_DOMAIN_AUX_B) | \
453 BIT_ULL(POWER_DOMAIN_AUX_C) | \
454 BIT_ULL(POWER_DOMAIN_INIT))
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +0530455
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +0200456#define GLK_DISPLAY_POWERWELL_2_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200457 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
458 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
459 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
460 BIT_ULL(POWER_DOMAIN_PIPE_C) | \
461 BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
462 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
463 BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
464 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
465 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
466 BIT_ULL(POWER_DOMAIN_AUX_B) | \
467 BIT_ULL(POWER_DOMAIN_AUX_C) | \
468 BIT_ULL(POWER_DOMAIN_AUDIO) | \
469 BIT_ULL(POWER_DOMAIN_VGA) | \
470 BIT_ULL(POWER_DOMAIN_INIT))
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +0200471#define GLK_DISPLAY_DDI_A_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200472 BIT_ULL(POWER_DOMAIN_PORT_DDI_A_LANES) | \
473 BIT_ULL(POWER_DOMAIN_INIT))
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +0200474#define GLK_DISPLAY_DDI_B_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200475 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
476 BIT_ULL(POWER_DOMAIN_INIT))
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +0200477#define GLK_DISPLAY_DDI_C_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200478 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
479 BIT_ULL(POWER_DOMAIN_INIT))
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +0200480#define GLK_DPIO_CMN_A_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200481 BIT_ULL(POWER_DOMAIN_PORT_DDI_A_LANES) | \
482 BIT_ULL(POWER_DOMAIN_AUX_A) | \
483 BIT_ULL(POWER_DOMAIN_INIT))
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +0200484#define GLK_DPIO_CMN_B_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200485 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
486 BIT_ULL(POWER_DOMAIN_AUX_B) | \
487 BIT_ULL(POWER_DOMAIN_INIT))
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +0200488#define GLK_DPIO_CMN_C_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200489 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
490 BIT_ULL(POWER_DOMAIN_AUX_C) | \
491 BIT_ULL(POWER_DOMAIN_INIT))
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +0200492#define GLK_DISPLAY_AUX_A_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200493 BIT_ULL(POWER_DOMAIN_AUX_A) | \
494 BIT_ULL(POWER_DOMAIN_INIT))
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +0200495#define GLK_DISPLAY_AUX_B_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200496 BIT_ULL(POWER_DOMAIN_AUX_B) | \
497 BIT_ULL(POWER_DOMAIN_INIT))
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +0200498#define GLK_DISPLAY_AUX_C_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200499 BIT_ULL(POWER_DOMAIN_AUX_C) | \
500 BIT_ULL(POWER_DOMAIN_INIT))
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +0200501#define GLK_DISPLAY_DC_OFF_POWER_DOMAINS ( \
502 GLK_DISPLAY_POWERWELL_2_POWER_DOMAINS | \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200503 BIT_ULL(POWER_DOMAIN_MODESET) | \
504 BIT_ULL(POWER_DOMAIN_AUX_A) | \
505 BIT_ULL(POWER_DOMAIN_INIT))
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +0200506
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530507static void assert_can_enable_dc9(struct drm_i915_private *dev_priv)
508{
Imre Deakbfcdabe2016-04-01 16:02:37 +0300509 WARN_ONCE((I915_READ(DC_STATE_EN) & DC_STATE_EN_DC9),
510 "DC9 already programmed to be enabled.\n");
511 WARN_ONCE(I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC5,
512 "DC5 still not disabled to enable DC9.\n");
513 WARN_ONCE(I915_READ(HSW_PWR_WELL_DRIVER), "Power well on.\n");
514 WARN_ONCE(intel_irqs_enabled(dev_priv),
515 "Interrupts not disabled yet.\n");
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530516
517 /*
518 * TODO: check for the following to verify the conditions to enter DC9
519 * state are satisfied:
520 * 1] Check relevant display engine registers to verify if mode set
521 * disable sequence was followed.
522 * 2] Check if display uninitialize sequence is initialized.
523 */
524}
525
526static void assert_can_disable_dc9(struct drm_i915_private *dev_priv)
527{
Imre Deakbfcdabe2016-04-01 16:02:37 +0300528 WARN_ONCE(intel_irqs_enabled(dev_priv),
529 "Interrupts not disabled yet.\n");
530 WARN_ONCE(I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC5,
531 "DC5 still not disabled.\n");
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530532
533 /*
534 * TODO: check for the following to verify DC9 state was indeed
535 * entered before programming to disable it:
536 * 1] Check relevant display engine registers to verify if mode
537 * set disable sequence was followed.
538 * 2] Check if display uninitialize sequence is initialized.
539 */
540}
541
Mika Kuoppala779cb5d2016-02-18 17:58:09 +0200542static void gen9_write_dc_state(struct drm_i915_private *dev_priv,
543 u32 state)
544{
545 int rewrites = 0;
546 int rereads = 0;
547 u32 v;
548
549 I915_WRITE(DC_STATE_EN, state);
550
551 /* It has been observed that disabling the dc6 state sometimes
552 * doesn't stick and dmc keeps returning old value. Make sure
553 * the write really sticks enough times and also force rewrite until
554 * we are confident that state is exactly what we want.
555 */
556 do {
557 v = I915_READ(DC_STATE_EN);
558
559 if (v != state) {
560 I915_WRITE(DC_STATE_EN, state);
561 rewrites++;
562 rereads = 0;
563 } else if (rereads++ > 5) {
564 break;
565 }
566
567 } while (rewrites < 100);
568
569 if (v != state)
570 DRM_ERROR("Writing dc state to 0x%x failed, now 0x%x\n",
571 state, v);
572
573 /* Most of the times we need one retry, avoid spam */
574 if (rewrites > 1)
575 DRM_DEBUG_KMS("Rewrote dc state to 0x%x %d times\n",
576 state, rewrites);
577}
578
Imre Deakda2f41d2016-04-20 20:27:56 +0300579static u32 gen9_dc_mask(struct drm_i915_private *dev_priv)
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530580{
Imre Deakda2f41d2016-04-20 20:27:56 +0300581 u32 mask;
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530582
Imre Deak13ae3a02015-11-04 19:24:16 +0200583 mask = DC_STATE_EN_UPTO_DC5;
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200584 if (IS_GEN9_LP(dev_priv))
Imre Deak13ae3a02015-11-04 19:24:16 +0200585 mask |= DC_STATE_EN_DC9;
586 else
587 mask |= DC_STATE_EN_UPTO_DC6;
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530588
Imre Deakda2f41d2016-04-20 20:27:56 +0300589 return mask;
590}
591
592void gen9_sanitize_dc_state(struct drm_i915_private *dev_priv)
593{
594 u32 val;
595
596 val = I915_READ(DC_STATE_EN) & gen9_dc_mask(dev_priv);
597
598 DRM_DEBUG_KMS("Resetting DC state tracking from %02x to %02x\n",
599 dev_priv->csr.dc_state, val);
600 dev_priv->csr.dc_state = val;
601}
602
603static void gen9_set_dc_state(struct drm_i915_private *dev_priv, uint32_t state)
604{
605 uint32_t val;
606 uint32_t mask;
607
Imre Deaka37baf32016-02-29 22:49:03 +0200608 if (WARN_ON_ONCE(state & ~dev_priv->csr.allowed_dc_mask))
609 state &= dev_priv->csr.allowed_dc_mask;
Patrik Jakobsson443646c2015-11-16 15:01:06 +0100610
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530611 val = I915_READ(DC_STATE_EN);
Imre Deakda2f41d2016-04-20 20:27:56 +0300612 mask = gen9_dc_mask(dev_priv);
Imre Deak13ae3a02015-11-04 19:24:16 +0200613 DRM_DEBUG_KMS("Setting DC state from %02x to %02x\n",
614 val & mask, state);
Patrik Jakobsson832dba82016-02-18 17:21:11 +0200615
616 /* Check if DMC is ignoring our DC state requests */
617 if ((val & mask) != dev_priv->csr.dc_state)
618 DRM_ERROR("DC state mismatch (0x%x -> 0x%x)\n",
619 dev_priv->csr.dc_state, val & mask);
620
Imre Deak13ae3a02015-11-04 19:24:16 +0200621 val &= ~mask;
622 val |= state;
Mika Kuoppala779cb5d2016-02-18 17:58:09 +0200623
624 gen9_write_dc_state(dev_priv, val);
Patrik Jakobsson832dba82016-02-18 17:21:11 +0200625
626 dev_priv->csr.dc_state = val & mask;
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530627}
628
Imre Deak13ae3a02015-11-04 19:24:16 +0200629void bxt_enable_dc9(struct drm_i915_private *dev_priv)
630{
631 assert_can_enable_dc9(dev_priv);
632
633 DRM_DEBUG_KMS("Enabling DC9\n");
634
Imre Deak78597992016-06-16 16:37:20 +0300635 intel_power_sequencer_reset(dev_priv);
Imre Deak13ae3a02015-11-04 19:24:16 +0200636 gen9_set_dc_state(dev_priv, DC_STATE_EN_DC9);
637}
638
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530639void bxt_disable_dc9(struct drm_i915_private *dev_priv)
640{
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530641 assert_can_disable_dc9(dev_priv);
642
643 DRM_DEBUG_KMS("Disabling DC9\n");
644
Imre Deak13ae3a02015-11-04 19:24:16 +0200645 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
Imre Deak8090ba82016-08-10 14:07:33 +0300646
647 intel_pps_unlock_regs_wa(dev_priv);
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530648}
649
Daniel Vetteraf5fead2015-10-28 23:58:57 +0200650static void assert_csr_loaded(struct drm_i915_private *dev_priv)
651{
652 WARN_ONCE(!I915_READ(CSR_PROGRAM(0)),
653 "CSR program storage start is NULL\n");
654 WARN_ONCE(!I915_READ(CSR_SSP_BASE), "CSR SSP Base Not fine\n");
655 WARN_ONCE(!I915_READ(CSR_HTP_SKL), "CSR HTP Not fine\n");
656}
657
Suketu Shah5aefb232015-04-16 14:22:10 +0530658static void assert_can_enable_dc5(struct drm_i915_private *dev_priv)
Suketu Shahdc174302015-04-17 19:46:16 +0530659{
Suketu Shah5aefb232015-04-16 14:22:10 +0530660 bool pg2_enabled = intel_display_power_well_is_enabled(dev_priv,
661 SKL_DISP_PW_2);
662
Jesse Barnes6ff8ab02015-09-10 08:20:28 -0700663 WARN_ONCE(pg2_enabled, "PG2 not disabled to enable DC5.\n");
Suketu Shah5aefb232015-04-16 14:22:10 +0530664
Jesse Barnes6ff8ab02015-09-10 08:20:28 -0700665 WARN_ONCE((I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC5),
666 "DC5 already programmed to be enabled.\n");
Imre Deakc9b88462015-12-15 20:10:34 +0200667 assert_rpm_wakelock_held(dev_priv);
Suketu Shah5aefb232015-04-16 14:22:10 +0530668
669 assert_csr_loaded(dev_priv);
670}
671
Imre Deakf62c79b2016-04-20 20:27:57 +0300672void gen9_enable_dc5(struct drm_i915_private *dev_priv)
Suketu Shah5aefb232015-04-16 14:22:10 +0530673{
Suketu Shah5aefb232015-04-16 14:22:10 +0530674 assert_can_enable_dc5(dev_priv);
A.Sunil Kamath6b457d32015-04-16 14:22:09 +0530675
676 DRM_DEBUG_KMS("Enabling DC5\n");
677
Imre Deak13ae3a02015-11-04 19:24:16 +0200678 gen9_set_dc_state(dev_priv, DC_STATE_EN_UPTO_DC5);
Suketu Shahdc174302015-04-17 19:46:16 +0530679}
680
Suketu Shah93c7cb62015-04-16 14:22:13 +0530681static void assert_can_enable_dc6(struct drm_i915_private *dev_priv)
Suketu Shahf75a1982015-04-16 14:22:11 +0530682{
Jesse Barnes6ff8ab02015-09-10 08:20:28 -0700683 WARN_ONCE(I915_READ(UTIL_PIN_CTL) & UTIL_PIN_ENABLE,
684 "Backlight is not disabled.\n");
685 WARN_ONCE((I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC6),
686 "DC6 already programmed to be enabled.\n");
Suketu Shah93c7cb62015-04-16 14:22:13 +0530687
688 assert_csr_loaded(dev_priv);
689}
690
Animesh Manna0a9d2be2015-09-29 11:01:59 +0530691void skl_enable_dc6(struct drm_i915_private *dev_priv)
Suketu Shah93c7cb62015-04-16 14:22:13 +0530692{
Suketu Shah93c7cb62015-04-16 14:22:13 +0530693 assert_can_enable_dc6(dev_priv);
A.Sunil Kamath74b4f372015-04-16 14:22:12 +0530694
695 DRM_DEBUG_KMS("Enabling DC6\n");
696
Imre Deak13ae3a02015-11-04 19:24:16 +0200697 gen9_set_dc_state(dev_priv, DC_STATE_EN_UPTO_DC6);
698
Suketu Shahf75a1982015-04-16 14:22:11 +0530699}
700
Animesh Manna0a9d2be2015-09-29 11:01:59 +0530701void skl_disable_dc6(struct drm_i915_private *dev_priv)
Suketu Shahf75a1982015-04-16 14:22:11 +0530702{
A.Sunil Kamath74b4f372015-04-16 14:22:12 +0530703 DRM_DEBUG_KMS("Disabling DC6\n");
704
Imre Deak13ae3a02015-11-04 19:24:16 +0200705 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
Suketu Shahf75a1982015-04-16 14:22:11 +0530706}
707
Imre Deakc6782b72016-04-05 13:26:05 +0300708static void
709gen9_sanitize_power_well_requests(struct drm_i915_private *dev_priv,
710 struct i915_power_well *power_well)
711{
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +0300712 enum skl_disp_power_wells power_well_id = power_well->id;
Imre Deakc6782b72016-04-05 13:26:05 +0300713 u32 val;
714 u32 mask;
715
716 mask = SKL_POWER_WELL_REQ(power_well_id);
717
718 val = I915_READ(HSW_PWR_WELL_KVMR);
719 if (WARN_ONCE(val & mask, "Clearing unexpected KVMR request for %s\n",
720 power_well->name))
721 I915_WRITE(HSW_PWR_WELL_KVMR, val & ~mask);
722
723 val = I915_READ(HSW_PWR_WELL_BIOS);
724 val |= I915_READ(HSW_PWR_WELL_DEBUG);
725
726 if (!(val & mask))
727 return;
728
729 /*
730 * DMC is known to force on the request bits for power well 1 on SKL
731 * and BXT and the misc IO power well on SKL but we don't expect any
732 * other request bits to be set, so WARN for those.
733 */
734 if (power_well_id == SKL_DISP_PW_1 ||
Rodrigo Vivib976dc52017-01-23 10:32:37 -0800735 (IS_GEN9_BC(dev_priv) &&
Imre Deak80dbe992016-04-19 13:00:36 +0300736 power_well_id == SKL_DISP_PW_MISC_IO))
Imre Deakc6782b72016-04-05 13:26:05 +0300737 DRM_DEBUG_DRIVER("Clearing auxiliary requests for %s forced on "
738 "by DMC\n", power_well->name);
739 else
740 WARN_ONCE(1, "Clearing unexpected auxiliary requests for %s\n",
741 power_well->name);
742
743 I915_WRITE(HSW_PWR_WELL_BIOS, val & ~mask);
744 I915_WRITE(HSW_PWR_WELL_DEBUG, val & ~mask);
745}
746
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000747static void skl_set_power_well(struct drm_i915_private *dev_priv,
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +0200748 struct i915_power_well *power_well, bool enable)
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000749{
750 uint32_t tmp, fuse_status;
751 uint32_t req_mask, state_mask;
Damien Lespiau2a518352015-03-06 18:50:49 +0000752 bool is_enabled, enable_requested, check_fuse_status = false;
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000753
754 tmp = I915_READ(HSW_PWR_WELL_DRIVER);
755 fuse_status = I915_READ(SKL_FUSE_STATUS);
756
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +0300757 switch (power_well->id) {
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000758 case SKL_DISP_PW_1:
Chris Wilson117c1142016-06-30 15:33:33 +0100759 if (intel_wait_for_register(dev_priv,
760 SKL_FUSE_STATUS,
761 SKL_FUSE_PG0_DIST_STATUS,
762 SKL_FUSE_PG0_DIST_STATUS,
763 1)) {
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000764 DRM_ERROR("PG0 not enabled\n");
765 return;
766 }
767 break;
768 case SKL_DISP_PW_2:
769 if (!(fuse_status & SKL_FUSE_PG1_DIST_STATUS)) {
770 DRM_ERROR("PG1 in disabled state\n");
771 return;
772 }
773 break;
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +0200774 case SKL_DISP_PW_MISC_IO:
775 case SKL_DISP_PW_DDI_A_E: /* GLK_DISP_PW_DDI_A */
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000776 case SKL_DISP_PW_DDI_B:
777 case SKL_DISP_PW_DDI_C:
778 case SKL_DISP_PW_DDI_D:
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +0200779 case GLK_DISP_PW_AUX_A:
780 case GLK_DISP_PW_AUX_B:
781 case GLK_DISP_PW_AUX_C:
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000782 break;
783 default:
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +0300784 WARN(1, "Unknown power well %lu\n", power_well->id);
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000785 return;
786 }
787
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +0300788 req_mask = SKL_POWER_WELL_REQ(power_well->id);
Damien Lespiau2a518352015-03-06 18:50:49 +0000789 enable_requested = tmp & req_mask;
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +0300790 state_mask = SKL_POWER_WELL_STATE(power_well->id);
Damien Lespiau2a518352015-03-06 18:50:49 +0000791 is_enabled = tmp & state_mask;
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000792
Ville Syrjäläaae8ba82016-02-19 20:47:30 +0200793 if (!enable && enable_requested)
794 skl_power_well_pre_disable(dev_priv, power_well);
795
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000796 if (enable) {
Damien Lespiau2a518352015-03-06 18:50:49 +0000797 if (!enable_requested) {
Suketu Shahdc174302015-04-17 19:46:16 +0530798 WARN((tmp & state_mask) &&
799 !I915_READ(HSW_PWR_WELL_BIOS),
800 "Invalid for power well status to be enabled, unless done by the BIOS, \
801 when request is to disable!\n");
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000802 I915_WRITE(HSW_PWR_WELL_DRIVER, tmp | req_mask);
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000803 }
804
Damien Lespiau2a518352015-03-06 18:50:49 +0000805 if (!is_enabled) {
Damien Lespiau510e6fd2015-03-06 18:50:50 +0000806 DRM_DEBUG_KMS("Enabling %s\n", power_well->name);
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000807 check_fuse_status = true;
808 }
809 } else {
Damien Lespiau2a518352015-03-06 18:50:49 +0000810 if (enable_requested) {
Imre Deak4a76f292015-11-04 19:24:15 +0200811 I915_WRITE(HSW_PWR_WELL_DRIVER, tmp & ~req_mask);
812 POSTING_READ(HSW_PWR_WELL_DRIVER);
813 DRM_DEBUG_KMS("Disabling %s\n", power_well->name);
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000814 }
Imre Deakc6782b72016-04-05 13:26:05 +0300815
Imre Deak5f304c82016-04-15 22:32:58 +0300816 if (IS_GEN9(dev_priv))
Imre Deakc6782b72016-04-05 13:26:05 +0300817 gen9_sanitize_power_well_requests(dev_priv, power_well);
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000818 }
819
Imre Deak1d963af2016-04-01 16:02:36 +0300820 if (wait_for(!!(I915_READ(HSW_PWR_WELL_DRIVER) & state_mask) == enable,
821 1))
822 DRM_ERROR("%s %s timeout\n",
823 power_well->name, enable ? "enable" : "disable");
824
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000825 if (check_fuse_status) {
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +0300826 if (power_well->id == SKL_DISP_PW_1) {
Chris Wilson8b00f552016-06-30 15:33:34 +0100827 if (intel_wait_for_register(dev_priv,
828 SKL_FUSE_STATUS,
829 SKL_FUSE_PG1_DIST_STATUS,
830 SKL_FUSE_PG1_DIST_STATUS,
831 1))
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000832 DRM_ERROR("PG1 distributing status timeout\n");
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +0300833 } else if (power_well->id == SKL_DISP_PW_2) {
Chris Wilson8b00f552016-06-30 15:33:34 +0100834 if (intel_wait_for_register(dev_priv,
835 SKL_FUSE_STATUS,
836 SKL_FUSE_PG2_DIST_STATUS,
837 SKL_FUSE_PG2_DIST_STATUS,
838 1))
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000839 DRM_ERROR("PG2 distributing status timeout\n");
840 }
841 }
Damien Lespiaud14c0342015-03-06 18:50:51 +0000842
843 if (enable && !is_enabled)
844 skl_power_well_post_enable(dev_priv, power_well);
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000845}
846
Daniel Vetter9c065a72014-09-30 10:56:38 +0200847static void hsw_power_well_sync_hw(struct drm_i915_private *dev_priv,
848 struct i915_power_well *power_well)
849{
Daniel Vetter9c065a72014-09-30 10:56:38 +0200850 /*
851 * We're taking over the BIOS, so clear any requests made by it since
852 * the driver is in charge now.
853 */
854 if (I915_READ(HSW_PWR_WELL_BIOS) & HSW_PWR_WELL_ENABLE_REQUEST)
855 I915_WRITE(HSW_PWR_WELL_BIOS, 0);
856}
857
858static void hsw_power_well_enable(struct drm_i915_private *dev_priv,
859 struct i915_power_well *power_well)
860{
861 hsw_set_power_well(dev_priv, power_well, true);
862}
863
864static void hsw_power_well_disable(struct drm_i915_private *dev_priv,
865 struct i915_power_well *power_well)
866{
867 hsw_set_power_well(dev_priv, power_well, false);
868}
869
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000870static bool skl_power_well_enabled(struct drm_i915_private *dev_priv,
871 struct i915_power_well *power_well)
872{
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +0300873 uint32_t mask = SKL_POWER_WELL_REQ(power_well->id) |
874 SKL_POWER_WELL_STATE(power_well->id);
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000875
876 return (I915_READ(HSW_PWR_WELL_DRIVER) & mask) == mask;
877}
878
879static void skl_power_well_sync_hw(struct drm_i915_private *dev_priv,
880 struct i915_power_well *power_well)
881{
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000882 /* Clear any request made by BIOS as driver is taking over */
883 I915_WRITE(HSW_PWR_WELL_BIOS, 0);
884}
885
886static void skl_power_well_enable(struct drm_i915_private *dev_priv,
887 struct i915_power_well *power_well)
888{
889 skl_set_power_well(dev_priv, power_well, true);
890}
891
892static void skl_power_well_disable(struct drm_i915_private *dev_priv,
893 struct i915_power_well *power_well)
894{
895 skl_set_power_well(dev_priv, power_well, false);
896}
897
Imre Deak9c8d0b82016-06-13 16:44:34 +0300898static void bxt_dpio_cmn_power_well_enable(struct drm_i915_private *dev_priv,
899 struct i915_power_well *power_well)
900{
Ander Conselvan de Oliveira362624c2016-10-06 19:22:15 +0300901 bxt_ddi_phy_init(dev_priv, power_well->data);
Imre Deak9c8d0b82016-06-13 16:44:34 +0300902}
903
904static void bxt_dpio_cmn_power_well_disable(struct drm_i915_private *dev_priv,
905 struct i915_power_well *power_well)
906{
Ander Conselvan de Oliveira362624c2016-10-06 19:22:15 +0300907 bxt_ddi_phy_uninit(dev_priv, power_well->data);
Imre Deak9c8d0b82016-06-13 16:44:34 +0300908}
909
910static bool bxt_dpio_cmn_power_well_enabled(struct drm_i915_private *dev_priv,
911 struct i915_power_well *power_well)
912{
Ander Conselvan de Oliveira362624c2016-10-06 19:22:15 +0300913 return bxt_ddi_phy_is_enabled(dev_priv, power_well->data);
Imre Deak9c8d0b82016-06-13 16:44:34 +0300914}
915
Imre Deak9c8d0b82016-06-13 16:44:34 +0300916static void bxt_verify_ddi_phy_power_wells(struct drm_i915_private *dev_priv)
917{
918 struct i915_power_well *power_well;
919
920 power_well = lookup_power_well(dev_priv, BXT_DPIO_CMN_A);
921 if (power_well->count > 0)
Ander Conselvan de Oliveira362624c2016-10-06 19:22:15 +0300922 bxt_ddi_phy_verify_state(dev_priv, power_well->data);
Imre Deak9c8d0b82016-06-13 16:44:34 +0300923
924 power_well = lookup_power_well(dev_priv, BXT_DPIO_CMN_BC);
925 if (power_well->count > 0)
Ander Conselvan de Oliveira362624c2016-10-06 19:22:15 +0300926 bxt_ddi_phy_verify_state(dev_priv, power_well->data);
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +0200927
928 if (IS_GEMINILAKE(dev_priv)) {
929 power_well = lookup_power_well(dev_priv, GLK_DPIO_CMN_C);
930 if (power_well->count > 0)
931 bxt_ddi_phy_verify_state(dev_priv, power_well->data);
932 }
Imre Deak9c8d0b82016-06-13 16:44:34 +0300933}
934
Patrik Jakobsson9f836f92015-11-16 16:20:01 +0100935static bool gen9_dc_off_power_well_enabled(struct drm_i915_private *dev_priv,
936 struct i915_power_well *power_well)
937{
938 return (I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC5_DC6_MASK) == 0;
939}
940
Ville Syrjälä18a80672016-05-16 16:59:40 +0300941static void gen9_assert_dbuf_enabled(struct drm_i915_private *dev_priv)
942{
943 u32 tmp = I915_READ(DBUF_CTL);
944
945 WARN((tmp & (DBUF_POWER_STATE | DBUF_POWER_REQUEST)) !=
946 (DBUF_POWER_STATE | DBUF_POWER_REQUEST),
947 "Unexpected DBuf power power state (0x%08x)\n", tmp);
948}
949
Patrik Jakobsson9f836f92015-11-16 16:20:01 +0100950static void gen9_dc_off_power_well_enable(struct drm_i915_private *dev_priv,
951 struct i915_power_well *power_well)
952{
Ville Syrjälä49cd97a2017-02-07 20:33:45 +0200953 struct intel_cdclk_state cdclk_state = {};
954
Imre Deak5b773eb2016-02-29 22:49:05 +0200955 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
Imre Deakadc7f042016-04-04 17:27:10 +0300956
Ville Syrjälä49cd97a2017-02-07 20:33:45 +0200957 dev_priv->display.get_cdclk(dev_priv, &cdclk_state);
958 WARN_ON(!intel_cdclk_state_compare(&dev_priv->cdclk.hw, &cdclk_state));
Ville Syrjälä342be922016-05-13 23:41:39 +0300959
Ville Syrjälä18a80672016-05-16 16:59:40 +0300960 gen9_assert_dbuf_enabled(dev_priv);
961
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200962 if (IS_GEN9_LP(dev_priv))
Imre Deak9c8d0b82016-06-13 16:44:34 +0300963 bxt_verify_ddi_phy_power_wells(dev_priv);
Patrik Jakobsson9f836f92015-11-16 16:20:01 +0100964}
965
966static void gen9_dc_off_power_well_disable(struct drm_i915_private *dev_priv,
967 struct i915_power_well *power_well)
968{
Imre Deakf74ed082016-04-18 14:48:21 +0300969 if (!dev_priv->csr.dmc_payload)
970 return;
971
Imre Deaka37baf32016-02-29 22:49:03 +0200972 if (dev_priv->csr.allowed_dc_mask & DC_STATE_EN_UPTO_DC6)
Patrik Jakobsson9f836f92015-11-16 16:20:01 +0100973 skl_enable_dc6(dev_priv);
Imre Deaka37baf32016-02-29 22:49:03 +0200974 else if (dev_priv->csr.allowed_dc_mask & DC_STATE_EN_UPTO_DC5)
Patrik Jakobsson9f836f92015-11-16 16:20:01 +0100975 gen9_enable_dc5(dev_priv);
976}
977
Imre Deak3c1b38e2017-02-17 17:39:42 +0200978static void i9xx_power_well_sync_hw_noop(struct drm_i915_private *dev_priv,
979 struct i915_power_well *power_well)
Patrik Jakobsson9f836f92015-11-16 16:20:01 +0100980{
Patrik Jakobsson9f836f92015-11-16 16:20:01 +0100981}
982
Daniel Vetter9c065a72014-09-30 10:56:38 +0200983static void i9xx_always_on_power_well_noop(struct drm_i915_private *dev_priv,
984 struct i915_power_well *power_well)
985{
986}
987
988static bool i9xx_always_on_power_well_enabled(struct drm_i915_private *dev_priv,
989 struct i915_power_well *power_well)
990{
991 return true;
992}
993
994static void vlv_set_power_well(struct drm_i915_private *dev_priv,
995 struct i915_power_well *power_well, bool enable)
996{
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +0300997 enum punit_power_well power_well_id = power_well->id;
Daniel Vetter9c065a72014-09-30 10:56:38 +0200998 u32 mask;
999 u32 state;
1000 u32 ctrl;
1001
1002 mask = PUNIT_PWRGT_MASK(power_well_id);
1003 state = enable ? PUNIT_PWRGT_PWR_ON(power_well_id) :
1004 PUNIT_PWRGT_PWR_GATE(power_well_id);
1005
1006 mutex_lock(&dev_priv->rps.hw_lock);
1007
1008#define COND \
1009 ((vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_STATUS) & mask) == state)
1010
1011 if (COND)
1012 goto out;
1013
1014 ctrl = vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_CTRL);
1015 ctrl &= ~mask;
1016 ctrl |= state;
1017 vlv_punit_write(dev_priv, PUNIT_REG_PWRGT_CTRL, ctrl);
1018
1019 if (wait_for(COND, 100))
Masanari Iida7e35ab82015-05-10 01:00:23 +09001020 DRM_ERROR("timeout setting power well state %08x (%08x)\n",
Daniel Vetter9c065a72014-09-30 10:56:38 +02001021 state,
1022 vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_CTRL));
1023
1024#undef COND
1025
1026out:
1027 mutex_unlock(&dev_priv->rps.hw_lock);
1028}
1029
Daniel Vetter9c065a72014-09-30 10:56:38 +02001030static void vlv_power_well_enable(struct drm_i915_private *dev_priv,
1031 struct i915_power_well *power_well)
1032{
1033 vlv_set_power_well(dev_priv, power_well, true);
1034}
1035
1036static void vlv_power_well_disable(struct drm_i915_private *dev_priv,
1037 struct i915_power_well *power_well)
1038{
1039 vlv_set_power_well(dev_priv, power_well, false);
1040}
1041
1042static bool vlv_power_well_enabled(struct drm_i915_private *dev_priv,
1043 struct i915_power_well *power_well)
1044{
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001045 int power_well_id = power_well->id;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001046 bool enabled = false;
1047 u32 mask;
1048 u32 state;
1049 u32 ctrl;
1050
1051 mask = PUNIT_PWRGT_MASK(power_well_id);
1052 ctrl = PUNIT_PWRGT_PWR_ON(power_well_id);
1053
1054 mutex_lock(&dev_priv->rps.hw_lock);
1055
1056 state = vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_STATUS) & mask;
1057 /*
1058 * We only ever set the power-on and power-gate states, anything
1059 * else is unexpected.
1060 */
1061 WARN_ON(state != PUNIT_PWRGT_PWR_ON(power_well_id) &&
1062 state != PUNIT_PWRGT_PWR_GATE(power_well_id));
1063 if (state == ctrl)
1064 enabled = true;
1065
1066 /*
1067 * A transient state at this point would mean some unexpected party
1068 * is poking at the power controls too.
1069 */
1070 ctrl = vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_CTRL) & mask;
1071 WARN_ON(ctrl != state);
1072
1073 mutex_unlock(&dev_priv->rps.hw_lock);
1074
1075 return enabled;
1076}
1077
Ville Syrjälä766078d2016-04-11 16:56:30 +03001078static void vlv_init_display_clock_gating(struct drm_i915_private *dev_priv)
1079{
Hans de Goede721d4842016-12-02 15:29:04 +01001080 u32 val;
1081
1082 /*
1083 * On driver load, a pipe may be active and driving a DSI display.
1084 * Preserve DPOUNIT_CLOCK_GATE_DISABLE to avoid the pipe getting stuck
1085 * (and never recovering) in this case. intel_dsi_post_disable() will
1086 * clear it when we turn off the display.
1087 */
1088 val = I915_READ(DSPCLK_GATE_D);
1089 val &= DPOUNIT_CLOCK_GATE_DISABLE;
1090 val |= VRHUNIT_CLOCK_GATE_DISABLE;
1091 I915_WRITE(DSPCLK_GATE_D, val);
Ville Syrjälä766078d2016-04-11 16:56:30 +03001092
1093 /*
1094 * Disable trickle feed and enable pnd deadline calculation
1095 */
1096 I915_WRITE(MI_ARB_VLV, MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE);
1097 I915_WRITE(CBR1_VLV, 0);
Ville Syrjälä19ab4ed2016-04-27 17:43:22 +03001098
1099 WARN_ON(dev_priv->rawclk_freq == 0);
1100
1101 I915_WRITE(RAWCLK_FREQ_VLV,
1102 DIV_ROUND_CLOSEST(dev_priv->rawclk_freq, 1000));
Ville Syrjälä766078d2016-04-11 16:56:30 +03001103}
1104
Ville Syrjälä2be7d542015-06-29 15:25:51 +03001105static void vlv_display_power_well_init(struct drm_i915_private *dev_priv)
Daniel Vetter9c065a72014-09-30 10:56:38 +02001106{
Lyude9504a892016-06-21 17:03:42 -04001107 struct intel_encoder *encoder;
Ville Syrjälä5a8fbb72015-06-29 15:25:53 +03001108 enum pipe pipe;
1109
1110 /*
1111 * Enable the CRI clock source so we can get at the
1112 * display and the reference clock for VGA
1113 * hotplug / manual detection. Supposedly DSI also
1114 * needs the ref clock up and running.
1115 *
1116 * CHV DPLL B/C have some issues if VGA mode is enabled.
1117 */
Tvrtko Ursulin801388c2016-11-16 08:55:44 +00001118 for_each_pipe(dev_priv, pipe) {
Ville Syrjälä5a8fbb72015-06-29 15:25:53 +03001119 u32 val = I915_READ(DPLL(pipe));
1120
1121 val |= DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
1122 if (pipe != PIPE_A)
1123 val |= DPLL_INTEGRATED_CRI_CLK_VLV;
1124
1125 I915_WRITE(DPLL(pipe), val);
1126 }
Daniel Vetter9c065a72014-09-30 10:56:38 +02001127
Ville Syrjälä766078d2016-04-11 16:56:30 +03001128 vlv_init_display_clock_gating(dev_priv);
1129
Daniel Vetter9c065a72014-09-30 10:56:38 +02001130 spin_lock_irq(&dev_priv->irq_lock);
1131 valleyview_enable_display_irqs(dev_priv);
1132 spin_unlock_irq(&dev_priv->irq_lock);
1133
1134 /*
1135 * During driver initialization/resume we can avoid restoring the
1136 * part of the HW/SW state that will be inited anyway explicitly.
1137 */
1138 if (dev_priv->power_domains.initializing)
1139 return;
1140
Daniel Vetterb9632912014-09-30 10:56:44 +02001141 intel_hpd_init(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001142
Lyude9504a892016-06-21 17:03:42 -04001143 /* Re-enable the ADPA, if we have one */
1144 for_each_intel_encoder(&dev_priv->drm, encoder) {
1145 if (encoder->type == INTEL_OUTPUT_ANALOG)
1146 intel_crt_reset(&encoder->base);
1147 }
1148
Tvrtko Ursulin29b74b72016-11-16 08:55:39 +00001149 i915_redisable_vga_power_on(dev_priv);
Imre Deak8090ba82016-08-10 14:07:33 +03001150
1151 intel_pps_unlock_regs_wa(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001152}
1153
Ville Syrjälä2be7d542015-06-29 15:25:51 +03001154static void vlv_display_power_well_deinit(struct drm_i915_private *dev_priv)
1155{
1156 spin_lock_irq(&dev_priv->irq_lock);
1157 valleyview_disable_display_irqs(dev_priv);
1158 spin_unlock_irq(&dev_priv->irq_lock);
1159
Ville Syrjälä2230fde2016-02-19 18:41:52 +02001160 /* make sure we're done processing display irqs */
Chris Wilson91c8a322016-07-05 10:40:23 +01001161 synchronize_irq(dev_priv->drm.irq);
Ville Syrjälä2230fde2016-02-19 18:41:52 +02001162
Imre Deak78597992016-06-16 16:37:20 +03001163 intel_power_sequencer_reset(dev_priv);
Lyude19625e82016-06-21 17:03:44 -04001164
Lyudeb64b5402016-10-26 12:36:09 -04001165 /* Prevent us from re-enabling polling on accident in late suspend */
1166 if (!dev_priv->drm.dev->power.is_suspended)
1167 intel_hpd_poll_init(dev_priv);
Ville Syrjälä2be7d542015-06-29 15:25:51 +03001168}
1169
1170static void vlv_display_power_well_enable(struct drm_i915_private *dev_priv,
1171 struct i915_power_well *power_well)
1172{
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001173 WARN_ON_ONCE(power_well->id != PUNIT_POWER_WELL_DISP2D);
Ville Syrjälä2be7d542015-06-29 15:25:51 +03001174
1175 vlv_set_power_well(dev_priv, power_well, true);
1176
1177 vlv_display_power_well_init(dev_priv);
1178}
1179
Daniel Vetter9c065a72014-09-30 10:56:38 +02001180static void vlv_display_power_well_disable(struct drm_i915_private *dev_priv,
1181 struct i915_power_well *power_well)
1182{
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001183 WARN_ON_ONCE(power_well->id != PUNIT_POWER_WELL_DISP2D);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001184
Ville Syrjälä2be7d542015-06-29 15:25:51 +03001185 vlv_display_power_well_deinit(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001186
1187 vlv_set_power_well(dev_priv, power_well, false);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001188}
1189
1190static void vlv_dpio_cmn_power_well_enable(struct drm_i915_private *dev_priv,
1191 struct i915_power_well *power_well)
1192{
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001193 WARN_ON_ONCE(power_well->id != PUNIT_POWER_WELL_DPIO_CMN_BC);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001194
Ville Syrjälä5a8fbb72015-06-29 15:25:53 +03001195 /* since ref/cri clock was enabled */
Daniel Vetter9c065a72014-09-30 10:56:38 +02001196 udelay(1); /* >10ns for cmnreset, >0ns for sidereset */
1197
1198 vlv_set_power_well(dev_priv, power_well, true);
1199
1200 /*
1201 * From VLV2A0_DP_eDP_DPIO_driver_vbios_notes_10.docx -
1202 * 6. De-assert cmn_reset/side_reset. Same as VLV X0.
1203 * a. GUnit 0x2110 bit[0] set to 1 (def 0)
1204 * b. The other bits such as sfr settings / modesel may all
1205 * be set to 0.
1206 *
1207 * This should only be done on init and resume from S3 with
1208 * both PLLs disabled, or we risk losing DPIO and PLL
1209 * synchronization.
1210 */
1211 I915_WRITE(DPIO_CTL, I915_READ(DPIO_CTL) | DPIO_CMNRST);
1212}
1213
1214static void vlv_dpio_cmn_power_well_disable(struct drm_i915_private *dev_priv,
1215 struct i915_power_well *power_well)
1216{
1217 enum pipe pipe;
1218
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001219 WARN_ON_ONCE(power_well->id != PUNIT_POWER_WELL_DPIO_CMN_BC);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001220
1221 for_each_pipe(dev_priv, pipe)
1222 assert_pll_disabled(dev_priv, pipe);
1223
1224 /* Assert common reset */
1225 I915_WRITE(DPIO_CTL, I915_READ(DPIO_CTL) & ~DPIO_CMNRST);
1226
1227 vlv_set_power_well(dev_priv, power_well, false);
1228}
1229
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001230#define POWER_DOMAIN_MASK (GENMASK_ULL(POWER_DOMAIN_NUM - 1, 0))
Ville Syrjälä30142272015-07-08 23:46:01 +03001231
1232static struct i915_power_well *lookup_power_well(struct drm_i915_private *dev_priv,
1233 int power_well_id)
1234{
1235 struct i915_power_domains *power_domains = &dev_priv->power_domains;
Ville Syrjälä30142272015-07-08 23:46:01 +03001236 int i;
1237
Imre Deakfc17f222015-11-04 19:24:11 +02001238 for (i = 0; i < power_domains->power_well_count; i++) {
1239 struct i915_power_well *power_well;
1240
1241 power_well = &power_domains->power_wells[i];
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001242 if (power_well->id == power_well_id)
Ville Syrjälä30142272015-07-08 23:46:01 +03001243 return power_well;
1244 }
1245
1246 return NULL;
1247}
1248
1249#define BITS_SET(val, bits) (((val) & (bits)) == (bits))
1250
1251static void assert_chv_phy_status(struct drm_i915_private *dev_priv)
1252{
1253 struct i915_power_well *cmn_bc =
1254 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_BC);
1255 struct i915_power_well *cmn_d =
1256 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_D);
1257 u32 phy_control = dev_priv->chv_phy_control;
1258 u32 phy_status = 0;
Ville Syrjälä3be60de2015-09-08 18:05:45 +03001259 u32 phy_status_mask = 0xffffffff;
Ville Syrjälä30142272015-07-08 23:46:01 +03001260
Ville Syrjälä3be60de2015-09-08 18:05:45 +03001261 /*
1262 * The BIOS can leave the PHY is some weird state
1263 * where it doesn't fully power down some parts.
1264 * Disable the asserts until the PHY has been fully
1265 * reset (ie. the power well has been disabled at
1266 * least once).
1267 */
1268 if (!dev_priv->chv_phy_assert[DPIO_PHY0])
1269 phy_status_mask &= ~(PHY_STATUS_CMN_LDO(DPIO_PHY0, DPIO_CH0) |
1270 PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH0, 0) |
1271 PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH0, 1) |
1272 PHY_STATUS_CMN_LDO(DPIO_PHY0, DPIO_CH1) |
1273 PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH1, 0) |
1274 PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH1, 1));
1275
1276 if (!dev_priv->chv_phy_assert[DPIO_PHY1])
1277 phy_status_mask &= ~(PHY_STATUS_CMN_LDO(DPIO_PHY1, DPIO_CH0) |
1278 PHY_STATUS_SPLINE_LDO(DPIO_PHY1, DPIO_CH0, 0) |
1279 PHY_STATUS_SPLINE_LDO(DPIO_PHY1, DPIO_CH0, 1));
1280
Ville Syrjälä30142272015-07-08 23:46:01 +03001281 if (cmn_bc->ops->is_enabled(dev_priv, cmn_bc)) {
1282 phy_status |= PHY_POWERGOOD(DPIO_PHY0);
1283
1284 /* this assumes override is only used to enable lanes */
1285 if ((phy_control & PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY0, DPIO_CH0)) == 0)
1286 phy_control |= PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH0);
1287
1288 if ((phy_control & PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY0, DPIO_CH1)) == 0)
1289 phy_control |= PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH1);
1290
1291 /* CL1 is on whenever anything is on in either channel */
1292 if (BITS_SET(phy_control,
1293 PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH0) |
1294 PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH1)))
1295 phy_status |= PHY_STATUS_CMN_LDO(DPIO_PHY0, DPIO_CH0);
1296
1297 /*
1298 * The DPLLB check accounts for the pipe B + port A usage
1299 * with CL2 powered up but all the lanes in the second channel
1300 * powered down.
1301 */
1302 if (BITS_SET(phy_control,
1303 PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH1)) &&
1304 (I915_READ(DPLL(PIPE_B)) & DPLL_VCO_ENABLE) == 0)
1305 phy_status |= PHY_STATUS_CMN_LDO(DPIO_PHY0, DPIO_CH1);
1306
1307 if (BITS_SET(phy_control,
1308 PHY_CH_POWER_DOWN_OVRD(0x3, DPIO_PHY0, DPIO_CH0)))
1309 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH0, 0);
1310 if (BITS_SET(phy_control,
1311 PHY_CH_POWER_DOWN_OVRD(0xc, DPIO_PHY0, DPIO_CH0)))
1312 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH0, 1);
1313
1314 if (BITS_SET(phy_control,
1315 PHY_CH_POWER_DOWN_OVRD(0x3, DPIO_PHY0, DPIO_CH1)))
1316 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH1, 0);
1317 if (BITS_SET(phy_control,
1318 PHY_CH_POWER_DOWN_OVRD(0xc, DPIO_PHY0, DPIO_CH1)))
1319 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH1, 1);
1320 }
1321
1322 if (cmn_d->ops->is_enabled(dev_priv, cmn_d)) {
1323 phy_status |= PHY_POWERGOOD(DPIO_PHY1);
1324
1325 /* this assumes override is only used to enable lanes */
1326 if ((phy_control & PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY1, DPIO_CH0)) == 0)
1327 phy_control |= PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY1, DPIO_CH0);
1328
1329 if (BITS_SET(phy_control,
1330 PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY1, DPIO_CH0)))
1331 phy_status |= PHY_STATUS_CMN_LDO(DPIO_PHY1, DPIO_CH0);
1332
1333 if (BITS_SET(phy_control,
1334 PHY_CH_POWER_DOWN_OVRD(0x3, DPIO_PHY1, DPIO_CH0)))
1335 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY1, DPIO_CH0, 0);
1336 if (BITS_SET(phy_control,
1337 PHY_CH_POWER_DOWN_OVRD(0xc, DPIO_PHY1, DPIO_CH0)))
1338 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY1, DPIO_CH0, 1);
1339 }
1340
Ville Syrjälä3be60de2015-09-08 18:05:45 +03001341 phy_status &= phy_status_mask;
1342
Ville Syrjälä30142272015-07-08 23:46:01 +03001343 /*
1344 * The PHY may be busy with some initial calibration and whatnot,
1345 * so the power state can take a while to actually change.
1346 */
Chris Wilson919fcd52016-06-30 15:33:35 +01001347 if (intel_wait_for_register(dev_priv,
1348 DISPLAY_PHY_STATUS,
1349 phy_status_mask,
1350 phy_status,
1351 10))
1352 DRM_ERROR("Unexpected PHY_STATUS 0x%08x, expected 0x%08x (PHY_CONTROL=0x%08x)\n",
1353 I915_READ(DISPLAY_PHY_STATUS) & phy_status_mask,
1354 phy_status, dev_priv->chv_phy_control);
Ville Syrjälä30142272015-07-08 23:46:01 +03001355}
1356
1357#undef BITS_SET
1358
Daniel Vetter9c065a72014-09-30 10:56:38 +02001359static void chv_dpio_cmn_power_well_enable(struct drm_i915_private *dev_priv,
1360 struct i915_power_well *power_well)
1361{
1362 enum dpio_phy phy;
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001363 enum pipe pipe;
1364 uint32_t tmp;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001365
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001366 WARN_ON_ONCE(power_well->id != PUNIT_POWER_WELL_DPIO_CMN_BC &&
1367 power_well->id != PUNIT_POWER_WELL_DPIO_CMN_D);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001368
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001369 if (power_well->id == PUNIT_POWER_WELL_DPIO_CMN_BC) {
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001370 pipe = PIPE_A;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001371 phy = DPIO_PHY0;
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001372 } else {
1373 pipe = PIPE_C;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001374 phy = DPIO_PHY1;
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001375 }
Ville Syrjälä5a8fbb72015-06-29 15:25:53 +03001376
1377 /* since ref/cri clock was enabled */
Daniel Vetter9c065a72014-09-30 10:56:38 +02001378 udelay(1); /* >10ns for cmnreset, >0ns for sidereset */
1379 vlv_set_power_well(dev_priv, power_well, true);
1380
1381 /* Poll for phypwrgood signal */
Chris Wilsonffebb832016-06-30 15:33:36 +01001382 if (intel_wait_for_register(dev_priv,
1383 DISPLAY_PHY_STATUS,
1384 PHY_POWERGOOD(phy),
1385 PHY_POWERGOOD(phy),
1386 1))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001387 DRM_ERROR("Display PHY %d is not power up\n", phy);
1388
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001389 mutex_lock(&dev_priv->sb_lock);
1390
1391 /* Enable dynamic power down */
1392 tmp = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW28);
Ville Syrjäläee279212015-07-08 23:45:57 +03001393 tmp |= DPIO_DYNPWRDOWNEN_CH0 | DPIO_CL1POWERDOWNEN |
1394 DPIO_SUS_CLK_CONFIG_GATE_CLKREQ;
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001395 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW28, tmp);
1396
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001397 if (power_well->id == PUNIT_POWER_WELL_DPIO_CMN_BC) {
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001398 tmp = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW6_CH1);
1399 tmp |= DPIO_DYNPWRDOWNEN_CH1;
1400 vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW6_CH1, tmp);
Ville Syrjälä3e288782015-07-08 23:45:58 +03001401 } else {
1402 /*
1403 * Force the non-existing CL2 off. BXT does this
1404 * too, so maybe it saves some power even though
1405 * CL2 doesn't exist?
1406 */
1407 tmp = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW30);
1408 tmp |= DPIO_CL2_LDOFUSE_PWRENB;
1409 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW30, tmp);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001410 }
1411
1412 mutex_unlock(&dev_priv->sb_lock);
1413
Ville Syrjälä70722462015-04-10 18:21:28 +03001414 dev_priv->chv_phy_control |= PHY_COM_LANE_RESET_DEASSERT(phy);
1415 I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001416
1417 DRM_DEBUG_KMS("Enabled DPIO PHY%d (PHY_CONTROL=0x%08x)\n",
1418 phy, dev_priv->chv_phy_control);
Ville Syrjälä30142272015-07-08 23:46:01 +03001419
1420 assert_chv_phy_status(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001421}
1422
1423static void chv_dpio_cmn_power_well_disable(struct drm_i915_private *dev_priv,
1424 struct i915_power_well *power_well)
1425{
1426 enum dpio_phy phy;
1427
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001428 WARN_ON_ONCE(power_well->id != PUNIT_POWER_WELL_DPIO_CMN_BC &&
1429 power_well->id != PUNIT_POWER_WELL_DPIO_CMN_D);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001430
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001431 if (power_well->id == PUNIT_POWER_WELL_DPIO_CMN_BC) {
Daniel Vetter9c065a72014-09-30 10:56:38 +02001432 phy = DPIO_PHY0;
1433 assert_pll_disabled(dev_priv, PIPE_A);
1434 assert_pll_disabled(dev_priv, PIPE_B);
1435 } else {
1436 phy = DPIO_PHY1;
1437 assert_pll_disabled(dev_priv, PIPE_C);
1438 }
1439
Ville Syrjälä70722462015-04-10 18:21:28 +03001440 dev_priv->chv_phy_control &= ~PHY_COM_LANE_RESET_DEASSERT(phy);
1441 I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001442
1443 vlv_set_power_well(dev_priv, power_well, false);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001444
1445 DRM_DEBUG_KMS("Disabled DPIO PHY%d (PHY_CONTROL=0x%08x)\n",
1446 phy, dev_priv->chv_phy_control);
Ville Syrjälä30142272015-07-08 23:46:01 +03001447
Ville Syrjälä3be60de2015-09-08 18:05:45 +03001448 /* PHY is fully reset now, so we can enable the PHY state asserts */
1449 dev_priv->chv_phy_assert[phy] = true;
1450
Ville Syrjälä30142272015-07-08 23:46:01 +03001451 assert_chv_phy_status(dev_priv);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001452}
1453
Ville Syrjälä6669e392015-07-08 23:46:00 +03001454static void assert_chv_phy_powergate(struct drm_i915_private *dev_priv, enum dpio_phy phy,
1455 enum dpio_channel ch, bool override, unsigned int mask)
1456{
1457 enum pipe pipe = phy == DPIO_PHY0 ? PIPE_A : PIPE_C;
1458 u32 reg, val, expected, actual;
1459
Ville Syrjälä3be60de2015-09-08 18:05:45 +03001460 /*
1461 * The BIOS can leave the PHY is some weird state
1462 * where it doesn't fully power down some parts.
1463 * Disable the asserts until the PHY has been fully
1464 * reset (ie. the power well has been disabled at
1465 * least once).
1466 */
1467 if (!dev_priv->chv_phy_assert[phy])
1468 return;
1469
Ville Syrjälä6669e392015-07-08 23:46:00 +03001470 if (ch == DPIO_CH0)
1471 reg = _CHV_CMN_DW0_CH0;
1472 else
1473 reg = _CHV_CMN_DW6_CH1;
1474
1475 mutex_lock(&dev_priv->sb_lock);
1476 val = vlv_dpio_read(dev_priv, pipe, reg);
1477 mutex_unlock(&dev_priv->sb_lock);
1478
1479 /*
1480 * This assumes !override is only used when the port is disabled.
1481 * All lanes should power down even without the override when
1482 * the port is disabled.
1483 */
1484 if (!override || mask == 0xf) {
1485 expected = DPIO_ALLDL_POWERDOWN | DPIO_ANYDL_POWERDOWN;
1486 /*
1487 * If CH1 common lane is not active anymore
1488 * (eg. for pipe B DPLL) the entire channel will
1489 * shut down, which causes the common lane registers
1490 * to read as 0. That means we can't actually check
1491 * the lane power down status bits, but as the entire
1492 * register reads as 0 it's a good indication that the
1493 * channel is indeed entirely powered down.
1494 */
1495 if (ch == DPIO_CH1 && val == 0)
1496 expected = 0;
1497 } else if (mask != 0x0) {
1498 expected = DPIO_ANYDL_POWERDOWN;
1499 } else {
1500 expected = 0;
1501 }
1502
1503 if (ch == DPIO_CH0)
1504 actual = val >> DPIO_ANYDL_POWERDOWN_SHIFT_CH0;
1505 else
1506 actual = val >> DPIO_ANYDL_POWERDOWN_SHIFT_CH1;
1507 actual &= DPIO_ALLDL_POWERDOWN | DPIO_ANYDL_POWERDOWN;
1508
1509 WARN(actual != expected,
1510 "Unexpected DPIO lane power down: all %d, any %d. Expected: all %d, any %d. (0x%x = 0x%08x)\n",
1511 !!(actual & DPIO_ALLDL_POWERDOWN), !!(actual & DPIO_ANYDL_POWERDOWN),
1512 !!(expected & DPIO_ALLDL_POWERDOWN), !!(expected & DPIO_ANYDL_POWERDOWN),
1513 reg, val);
1514}
1515
Ville Syrjäläb0b33842015-07-08 23:45:55 +03001516bool chv_phy_powergate_ch(struct drm_i915_private *dev_priv, enum dpio_phy phy,
1517 enum dpio_channel ch, bool override)
1518{
1519 struct i915_power_domains *power_domains = &dev_priv->power_domains;
1520 bool was_override;
1521
1522 mutex_lock(&power_domains->lock);
1523
1524 was_override = dev_priv->chv_phy_control & PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
1525
1526 if (override == was_override)
1527 goto out;
1528
1529 if (override)
1530 dev_priv->chv_phy_control |= PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
1531 else
1532 dev_priv->chv_phy_control &= ~PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
1533
1534 I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
1535
1536 DRM_DEBUG_KMS("Power gating DPIO PHY%d CH%d (DPIO_PHY_CONTROL=0x%08x)\n",
1537 phy, ch, dev_priv->chv_phy_control);
1538
Ville Syrjälä30142272015-07-08 23:46:01 +03001539 assert_chv_phy_status(dev_priv);
1540
Ville Syrjäläb0b33842015-07-08 23:45:55 +03001541out:
1542 mutex_unlock(&power_domains->lock);
1543
1544 return was_override;
1545}
1546
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001547void chv_phy_powergate_lanes(struct intel_encoder *encoder,
1548 bool override, unsigned int mask)
1549{
1550 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
1551 struct i915_power_domains *power_domains = &dev_priv->power_domains;
1552 enum dpio_phy phy = vlv_dport_to_phy(enc_to_dig_port(&encoder->base));
1553 enum dpio_channel ch = vlv_dport_to_channel(enc_to_dig_port(&encoder->base));
1554
1555 mutex_lock(&power_domains->lock);
1556
1557 dev_priv->chv_phy_control &= ~PHY_CH_POWER_DOWN_OVRD(0xf, phy, ch);
1558 dev_priv->chv_phy_control |= PHY_CH_POWER_DOWN_OVRD(mask, phy, ch);
1559
1560 if (override)
1561 dev_priv->chv_phy_control |= PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
1562 else
1563 dev_priv->chv_phy_control &= ~PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
1564
1565 I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
1566
1567 DRM_DEBUG_KMS("Power gating DPIO PHY%d CH%d lanes 0x%x (PHY_CONTROL=0x%08x)\n",
1568 phy, ch, mask, dev_priv->chv_phy_control);
1569
Ville Syrjälä30142272015-07-08 23:46:01 +03001570 assert_chv_phy_status(dev_priv);
1571
Ville Syrjälä6669e392015-07-08 23:46:00 +03001572 assert_chv_phy_powergate(dev_priv, phy, ch, override, mask);
1573
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001574 mutex_unlock(&power_domains->lock);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001575}
1576
1577static bool chv_pipe_power_well_enabled(struct drm_i915_private *dev_priv,
1578 struct i915_power_well *power_well)
1579{
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001580 enum pipe pipe = power_well->id;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001581 bool enabled;
1582 u32 state, ctrl;
1583
1584 mutex_lock(&dev_priv->rps.hw_lock);
1585
1586 state = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & DP_SSS_MASK(pipe);
1587 /*
1588 * We only ever set the power-on and power-gate states, anything
1589 * else is unexpected.
1590 */
1591 WARN_ON(state != DP_SSS_PWR_ON(pipe) && state != DP_SSS_PWR_GATE(pipe));
1592 enabled = state == DP_SSS_PWR_ON(pipe);
1593
1594 /*
1595 * A transient state at this point would mean some unexpected party
1596 * is poking at the power controls too.
1597 */
1598 ctrl = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & DP_SSC_MASK(pipe);
1599 WARN_ON(ctrl << 16 != state);
1600
1601 mutex_unlock(&dev_priv->rps.hw_lock);
1602
1603 return enabled;
1604}
1605
1606static void chv_set_pipe_power_well(struct drm_i915_private *dev_priv,
1607 struct i915_power_well *power_well,
1608 bool enable)
1609{
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001610 enum pipe pipe = power_well->id;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001611 u32 state;
1612 u32 ctrl;
1613
1614 state = enable ? DP_SSS_PWR_ON(pipe) : DP_SSS_PWR_GATE(pipe);
1615
1616 mutex_lock(&dev_priv->rps.hw_lock);
1617
1618#define COND \
1619 ((vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & DP_SSS_MASK(pipe)) == state)
1620
1621 if (COND)
1622 goto out;
1623
1624 ctrl = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ);
1625 ctrl &= ~DP_SSC_MASK(pipe);
1626 ctrl |= enable ? DP_SSC_PWR_ON(pipe) : DP_SSC_PWR_GATE(pipe);
1627 vlv_punit_write(dev_priv, PUNIT_REG_DSPFREQ, ctrl);
1628
1629 if (wait_for(COND, 100))
Masanari Iida7e35ab82015-05-10 01:00:23 +09001630 DRM_ERROR("timeout setting power well state %08x (%08x)\n",
Daniel Vetter9c065a72014-09-30 10:56:38 +02001631 state,
1632 vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ));
1633
1634#undef COND
1635
1636out:
1637 mutex_unlock(&dev_priv->rps.hw_lock);
1638}
1639
Daniel Vetter9c065a72014-09-30 10:56:38 +02001640static void chv_pipe_power_well_enable(struct drm_i915_private *dev_priv,
1641 struct i915_power_well *power_well)
1642{
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001643 WARN_ON_ONCE(power_well->id != PIPE_A);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001644
1645 chv_set_pipe_power_well(dev_priv, power_well, true);
Ville Syrjäläafd62752014-10-30 19:43:03 +02001646
Ville Syrjälä2be7d542015-06-29 15:25:51 +03001647 vlv_display_power_well_init(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001648}
1649
1650static void chv_pipe_power_well_disable(struct drm_i915_private *dev_priv,
1651 struct i915_power_well *power_well)
1652{
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001653 WARN_ON_ONCE(power_well->id != PIPE_A);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001654
Ville Syrjälä2be7d542015-06-29 15:25:51 +03001655 vlv_display_power_well_deinit(dev_priv);
Ville Syrjäläafd62752014-10-30 19:43:03 +02001656
Daniel Vetter9c065a72014-09-30 10:56:38 +02001657 chv_set_pipe_power_well(dev_priv, power_well, false);
1658}
1659
Imre Deak09731282016-02-17 14:17:42 +02001660static void
1661__intel_display_power_get_domain(struct drm_i915_private *dev_priv,
1662 enum intel_display_power_domain domain)
1663{
1664 struct i915_power_domains *power_domains = &dev_priv->power_domains;
1665 struct i915_power_well *power_well;
1666 int i;
1667
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001668 for_each_power_well(i, power_well, BIT_ULL(domain), power_domains)
Imre Deakb409ca92016-06-13 16:44:33 +03001669 intel_power_well_get(dev_priv, power_well);
Imre Deak09731282016-02-17 14:17:42 +02001670
1671 power_domains->domain_use_count[domain]++;
1672}
1673
Daniel Vettere4e76842014-09-30 10:56:42 +02001674/**
1675 * intel_display_power_get - grab a power domain reference
1676 * @dev_priv: i915 device instance
1677 * @domain: power domain to reference
1678 *
1679 * This function grabs a power domain reference for @domain and ensures that the
1680 * power domain and all its parents are powered up. Therefore users should only
1681 * grab a reference to the innermost power domain they need.
1682 *
1683 * Any power domain reference obtained by this function must have a symmetric
1684 * call to intel_display_power_put() to release the reference again.
1685 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02001686void intel_display_power_get(struct drm_i915_private *dev_priv,
1687 enum intel_display_power_domain domain)
1688{
Imre Deak09731282016-02-17 14:17:42 +02001689 struct i915_power_domains *power_domains = &dev_priv->power_domains;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001690
1691 intel_runtime_pm_get(dev_priv);
1692
Imre Deak09731282016-02-17 14:17:42 +02001693 mutex_lock(&power_domains->lock);
1694
1695 __intel_display_power_get_domain(dev_priv, domain);
1696
1697 mutex_unlock(&power_domains->lock);
1698}
1699
1700/**
1701 * intel_display_power_get_if_enabled - grab a reference for an enabled display power domain
1702 * @dev_priv: i915 device instance
1703 * @domain: power domain to reference
1704 *
1705 * This function grabs a power domain reference for @domain and ensures that the
1706 * power domain and all its parents are powered up. Therefore users should only
1707 * grab a reference to the innermost power domain they need.
1708 *
1709 * Any power domain reference obtained by this function must have a symmetric
1710 * call to intel_display_power_put() to release the reference again.
1711 */
1712bool intel_display_power_get_if_enabled(struct drm_i915_private *dev_priv,
1713 enum intel_display_power_domain domain)
1714{
1715 struct i915_power_domains *power_domains = &dev_priv->power_domains;
1716 bool is_enabled;
1717
1718 if (!intel_runtime_pm_get_if_in_use(dev_priv))
1719 return false;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001720
1721 mutex_lock(&power_domains->lock);
1722
Imre Deak09731282016-02-17 14:17:42 +02001723 if (__intel_display_power_is_enabled(dev_priv, domain)) {
1724 __intel_display_power_get_domain(dev_priv, domain);
1725 is_enabled = true;
1726 } else {
1727 is_enabled = false;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001728 }
1729
Daniel Vetter9c065a72014-09-30 10:56:38 +02001730 mutex_unlock(&power_domains->lock);
Imre Deak09731282016-02-17 14:17:42 +02001731
1732 if (!is_enabled)
1733 intel_runtime_pm_put(dev_priv);
1734
1735 return is_enabled;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001736}
1737
Daniel Vettere4e76842014-09-30 10:56:42 +02001738/**
1739 * intel_display_power_put - release a power domain reference
1740 * @dev_priv: i915 device instance
1741 * @domain: power domain to reference
1742 *
1743 * This function drops the power domain reference obtained by
1744 * intel_display_power_get() and might power down the corresponding hardware
1745 * block right away if this is the last reference.
1746 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02001747void intel_display_power_put(struct drm_i915_private *dev_priv,
1748 enum intel_display_power_domain domain)
1749{
1750 struct i915_power_domains *power_domains;
1751 struct i915_power_well *power_well;
1752 int i;
1753
1754 power_domains = &dev_priv->power_domains;
1755
1756 mutex_lock(&power_domains->lock);
1757
Daniel Stone11c86db2015-11-20 15:55:34 +00001758 WARN(!power_domains->domain_use_count[domain],
1759 "Use count on domain %s is already zero\n",
1760 intel_display_power_domain_str(domain));
Daniel Vetter9c065a72014-09-30 10:56:38 +02001761 power_domains->domain_use_count[domain]--;
1762
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001763 for_each_power_well_rev(i, power_well, BIT_ULL(domain), power_domains)
Imre Deakb409ca92016-06-13 16:44:33 +03001764 intel_power_well_put(dev_priv, power_well);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001765
1766 mutex_unlock(&power_domains->lock);
1767
1768 intel_runtime_pm_put(dev_priv);
1769}
1770
Ville Syrjälä9d0996b2016-04-18 14:02:28 +03001771#define HSW_DISPLAY_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001772 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
1773 BIT_ULL(POWER_DOMAIN_PIPE_C) | \
1774 BIT_ULL(POWER_DOMAIN_PIPE_A_PANEL_FITTER) | \
1775 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1776 BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
1777 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
1778 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
1779 BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
1780 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1781 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1782 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_LANES) | \
1783 BIT_ULL(POWER_DOMAIN_PORT_CRT) | /* DDI E */ \
1784 BIT_ULL(POWER_DOMAIN_VGA) | \
1785 BIT_ULL(POWER_DOMAIN_AUDIO) | \
1786 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001787
Ville Syrjälä9d0996b2016-04-18 14:02:28 +03001788#define BDW_DISPLAY_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001789 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
1790 BIT_ULL(POWER_DOMAIN_PIPE_C) | \
1791 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1792 BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
1793 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
1794 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
1795 BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
1796 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1797 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1798 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_LANES) | \
1799 BIT_ULL(POWER_DOMAIN_PORT_CRT) | /* DDI E */ \
1800 BIT_ULL(POWER_DOMAIN_VGA) | \
1801 BIT_ULL(POWER_DOMAIN_AUDIO) | \
1802 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001803
Ville Syrjälä465ac0c2016-04-18 14:02:27 +03001804#define VLV_DISPLAY_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001805 BIT_ULL(POWER_DOMAIN_PIPE_A) | \
1806 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
1807 BIT_ULL(POWER_DOMAIN_PIPE_A_PANEL_FITTER) | \
1808 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1809 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
1810 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
1811 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1812 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1813 BIT_ULL(POWER_DOMAIN_PORT_DSI) | \
1814 BIT_ULL(POWER_DOMAIN_PORT_CRT) | \
1815 BIT_ULL(POWER_DOMAIN_VGA) | \
1816 BIT_ULL(POWER_DOMAIN_AUDIO) | \
1817 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1818 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1819 BIT_ULL(POWER_DOMAIN_GMBUS) | \
1820 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001821
1822#define VLV_DPIO_CMN_BC_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001823 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1824 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1825 BIT_ULL(POWER_DOMAIN_PORT_CRT) | \
1826 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1827 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1828 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001829
1830#define VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001831 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1832 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1833 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001834
1835#define VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001836 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1837 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1838 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001839
1840#define VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001841 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1842 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1843 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001844
1845#define VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001846 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1847 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1848 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001849
Ville Syrjälä465ac0c2016-04-18 14:02:27 +03001850#define CHV_DISPLAY_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001851 BIT_ULL(POWER_DOMAIN_PIPE_A) | \
1852 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
1853 BIT_ULL(POWER_DOMAIN_PIPE_C) | \
1854 BIT_ULL(POWER_DOMAIN_PIPE_A_PANEL_FITTER) | \
1855 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1856 BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
1857 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
1858 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
1859 BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
1860 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1861 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1862 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_LANES) | \
1863 BIT_ULL(POWER_DOMAIN_PORT_DSI) | \
1864 BIT_ULL(POWER_DOMAIN_VGA) | \
1865 BIT_ULL(POWER_DOMAIN_AUDIO) | \
1866 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1867 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1868 BIT_ULL(POWER_DOMAIN_AUX_D) | \
1869 BIT_ULL(POWER_DOMAIN_GMBUS) | \
1870 BIT_ULL(POWER_DOMAIN_INIT))
Ville Syrjälä465ac0c2016-04-18 14:02:27 +03001871
Daniel Vetter9c065a72014-09-30 10:56:38 +02001872#define CHV_DPIO_CMN_BC_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001873 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1874 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1875 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1876 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1877 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001878
1879#define CHV_DPIO_CMN_D_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001880 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_LANES) | \
1881 BIT_ULL(POWER_DOMAIN_AUX_D) | \
1882 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001883
Daniel Vetter9c065a72014-09-30 10:56:38 +02001884static const struct i915_power_well_ops i9xx_always_on_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02001885 .sync_hw = i9xx_power_well_sync_hw_noop,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001886 .enable = i9xx_always_on_power_well_noop,
1887 .disable = i9xx_always_on_power_well_noop,
1888 .is_enabled = i9xx_always_on_power_well_enabled,
1889};
1890
1891static const struct i915_power_well_ops chv_pipe_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02001892 .sync_hw = i9xx_power_well_sync_hw_noop,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001893 .enable = chv_pipe_power_well_enable,
1894 .disable = chv_pipe_power_well_disable,
1895 .is_enabled = chv_pipe_power_well_enabled,
1896};
1897
1898static const struct i915_power_well_ops chv_dpio_cmn_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02001899 .sync_hw = i9xx_power_well_sync_hw_noop,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001900 .enable = chv_dpio_cmn_power_well_enable,
1901 .disable = chv_dpio_cmn_power_well_disable,
1902 .is_enabled = vlv_power_well_enabled,
1903};
1904
1905static struct i915_power_well i9xx_always_on_power_well[] = {
1906 {
1907 .name = "always-on",
1908 .always_on = 1,
1909 .domains = POWER_DOMAIN_MASK,
1910 .ops = &i9xx_always_on_power_well_ops,
1911 },
1912};
1913
1914static const struct i915_power_well_ops hsw_power_well_ops = {
1915 .sync_hw = hsw_power_well_sync_hw,
1916 .enable = hsw_power_well_enable,
1917 .disable = hsw_power_well_disable,
1918 .is_enabled = hsw_power_well_enabled,
1919};
1920
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00001921static const struct i915_power_well_ops skl_power_well_ops = {
1922 .sync_hw = skl_power_well_sync_hw,
1923 .enable = skl_power_well_enable,
1924 .disable = skl_power_well_disable,
1925 .is_enabled = skl_power_well_enabled,
1926};
1927
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01001928static const struct i915_power_well_ops gen9_dc_off_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02001929 .sync_hw = i9xx_power_well_sync_hw_noop,
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01001930 .enable = gen9_dc_off_power_well_enable,
1931 .disable = gen9_dc_off_power_well_disable,
1932 .is_enabled = gen9_dc_off_power_well_enabled,
1933};
1934
Imre Deak9c8d0b82016-06-13 16:44:34 +03001935static const struct i915_power_well_ops bxt_dpio_cmn_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02001936 .sync_hw = i9xx_power_well_sync_hw_noop,
Imre Deak9c8d0b82016-06-13 16:44:34 +03001937 .enable = bxt_dpio_cmn_power_well_enable,
1938 .disable = bxt_dpio_cmn_power_well_disable,
1939 .is_enabled = bxt_dpio_cmn_power_well_enabled,
1940};
1941
Daniel Vetter9c065a72014-09-30 10:56:38 +02001942static struct i915_power_well hsw_power_wells[] = {
1943 {
1944 .name = "always-on",
1945 .always_on = 1,
Ville Syrjälä998bd662016-04-18 14:02:26 +03001946 .domains = POWER_DOMAIN_MASK,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001947 .ops = &i9xx_always_on_power_well_ops,
1948 },
1949 {
1950 .name = "display",
1951 .domains = HSW_DISPLAY_POWER_DOMAINS,
1952 .ops = &hsw_power_well_ops,
1953 },
1954};
1955
1956static struct i915_power_well bdw_power_wells[] = {
1957 {
1958 .name = "always-on",
1959 .always_on = 1,
Ville Syrjälä998bd662016-04-18 14:02:26 +03001960 .domains = POWER_DOMAIN_MASK,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001961 .ops = &i9xx_always_on_power_well_ops,
1962 },
1963 {
1964 .name = "display",
1965 .domains = BDW_DISPLAY_POWER_DOMAINS,
1966 .ops = &hsw_power_well_ops,
1967 },
1968};
1969
1970static const struct i915_power_well_ops vlv_display_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02001971 .sync_hw = i9xx_power_well_sync_hw_noop,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001972 .enable = vlv_display_power_well_enable,
1973 .disable = vlv_display_power_well_disable,
1974 .is_enabled = vlv_power_well_enabled,
1975};
1976
1977static const struct i915_power_well_ops vlv_dpio_cmn_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02001978 .sync_hw = i9xx_power_well_sync_hw_noop,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001979 .enable = vlv_dpio_cmn_power_well_enable,
1980 .disable = vlv_dpio_cmn_power_well_disable,
1981 .is_enabled = vlv_power_well_enabled,
1982};
1983
1984static const struct i915_power_well_ops vlv_dpio_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02001985 .sync_hw = i9xx_power_well_sync_hw_noop,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001986 .enable = vlv_power_well_enable,
1987 .disable = vlv_power_well_disable,
1988 .is_enabled = vlv_power_well_enabled,
1989};
1990
1991static struct i915_power_well vlv_power_wells[] = {
1992 {
1993 .name = "always-on",
1994 .always_on = 1,
Ville Syrjälä998bd662016-04-18 14:02:26 +03001995 .domains = POWER_DOMAIN_MASK,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001996 .ops = &i9xx_always_on_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001997 .id = PUNIT_POWER_WELL_ALWAYS_ON,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001998 },
1999 {
2000 .name = "display",
2001 .domains = VLV_DISPLAY_POWER_DOMAINS,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002002 .id = PUNIT_POWER_WELL_DISP2D,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002003 .ops = &vlv_display_power_well_ops,
2004 },
2005 {
2006 .name = "dpio-tx-b-01",
2007 .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
2008 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
2009 VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
2010 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
2011 .ops = &vlv_dpio_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002012 .id = PUNIT_POWER_WELL_DPIO_TX_B_LANES_01,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002013 },
2014 {
2015 .name = "dpio-tx-b-23",
2016 .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
2017 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
2018 VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
2019 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
2020 .ops = &vlv_dpio_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002021 .id = PUNIT_POWER_WELL_DPIO_TX_B_LANES_23,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002022 },
2023 {
2024 .name = "dpio-tx-c-01",
2025 .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
2026 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
2027 VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
2028 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
2029 .ops = &vlv_dpio_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002030 .id = PUNIT_POWER_WELL_DPIO_TX_C_LANES_01,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002031 },
2032 {
2033 .name = "dpio-tx-c-23",
2034 .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
2035 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
2036 VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
2037 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
2038 .ops = &vlv_dpio_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002039 .id = PUNIT_POWER_WELL_DPIO_TX_C_LANES_23,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002040 },
2041 {
2042 .name = "dpio-common",
2043 .domains = VLV_DPIO_CMN_BC_POWER_DOMAINS,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002044 .id = PUNIT_POWER_WELL_DPIO_CMN_BC,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002045 .ops = &vlv_dpio_cmn_power_well_ops,
2046 },
2047};
2048
2049static struct i915_power_well chv_power_wells[] = {
2050 {
2051 .name = "always-on",
2052 .always_on = 1,
Ville Syrjälä998bd662016-04-18 14:02:26 +03002053 .domains = POWER_DOMAIN_MASK,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002054 .ops = &i9xx_always_on_power_well_ops,
2055 },
Daniel Vetter9c065a72014-09-30 10:56:38 +02002056 {
2057 .name = "display",
Ville Syrjäläbaa4e572014-10-27 16:07:32 +02002058 /*
Ville Syrjäläfde61e42015-05-26 20:22:39 +03002059 * Pipe A power well is the new disp2d well. Pipe B and C
2060 * power wells don't actually exist. Pipe A power well is
2061 * required for any pipe to work.
Ville Syrjäläbaa4e572014-10-27 16:07:32 +02002062 */
Ville Syrjälä465ac0c2016-04-18 14:02:27 +03002063 .domains = CHV_DISPLAY_POWER_DOMAINS,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002064 .id = PIPE_A,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002065 .ops = &chv_pipe_power_well_ops,
2066 },
Daniel Vetter9c065a72014-09-30 10:56:38 +02002067 {
2068 .name = "dpio-common-bc",
Ville Syrjälä71849b62015-04-10 18:21:29 +03002069 .domains = CHV_DPIO_CMN_BC_POWER_DOMAINS,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002070 .id = PUNIT_POWER_WELL_DPIO_CMN_BC,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002071 .ops = &chv_dpio_cmn_power_well_ops,
2072 },
2073 {
2074 .name = "dpio-common-d",
Ville Syrjälä71849b62015-04-10 18:21:29 +03002075 .domains = CHV_DPIO_CMN_D_POWER_DOMAINS,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002076 .id = PUNIT_POWER_WELL_DPIO_CMN_D,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002077 .ops = &chv_dpio_cmn_power_well_ops,
2078 },
Daniel Vetter9c065a72014-09-30 10:56:38 +02002079};
2080
Suketu Shah5aefb232015-04-16 14:22:10 +05302081bool intel_display_power_well_is_enabled(struct drm_i915_private *dev_priv,
2082 int power_well_id)
2083{
2084 struct i915_power_well *power_well;
2085 bool ret;
2086
2087 power_well = lookup_power_well(dev_priv, power_well_id);
2088 ret = power_well->ops->is_enabled(dev_priv, power_well);
2089
2090 return ret;
2091}
2092
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002093static struct i915_power_well skl_power_wells[] = {
2094 {
2095 .name = "always-on",
2096 .always_on = 1,
Ville Syrjälä998bd662016-04-18 14:02:26 +03002097 .domains = POWER_DOMAIN_MASK,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002098 .ops = &i9xx_always_on_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002099 .id = SKL_DISP_PW_ALWAYS_ON,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002100 },
2101 {
2102 .name = "power well 1",
Imre Deak4a76f292015-11-04 19:24:15 +02002103 /* Handled by the DMC firmware */
2104 .domains = 0,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002105 .ops = &skl_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002106 .id = SKL_DISP_PW_1,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002107 },
2108 {
2109 .name = "MISC IO power well",
Imre Deak4a76f292015-11-04 19:24:15 +02002110 /* Handled by the DMC firmware */
2111 .domains = 0,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002112 .ops = &skl_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002113 .id = SKL_DISP_PW_MISC_IO,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002114 },
2115 {
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01002116 .name = "DC off",
2117 .domains = SKL_DISPLAY_DC_OFF_POWER_DOMAINS,
2118 .ops = &gen9_dc_off_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002119 .id = SKL_DISP_PW_DC_OFF,
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01002120 },
2121 {
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002122 .name = "power well 2",
2123 .domains = SKL_DISPLAY_POWERWELL_2_POWER_DOMAINS,
2124 .ops = &skl_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002125 .id = SKL_DISP_PW_2,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002126 },
2127 {
2128 .name = "DDI A/E power well",
2129 .domains = SKL_DISPLAY_DDI_A_E_POWER_DOMAINS,
2130 .ops = &skl_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002131 .id = SKL_DISP_PW_DDI_A_E,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002132 },
2133 {
2134 .name = "DDI B power well",
2135 .domains = SKL_DISPLAY_DDI_B_POWER_DOMAINS,
2136 .ops = &skl_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002137 .id = SKL_DISP_PW_DDI_B,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002138 },
2139 {
2140 .name = "DDI C power well",
2141 .domains = SKL_DISPLAY_DDI_C_POWER_DOMAINS,
2142 .ops = &skl_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002143 .id = SKL_DISP_PW_DDI_C,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002144 },
2145 {
2146 .name = "DDI D power well",
2147 .domains = SKL_DISPLAY_DDI_D_POWER_DOMAINS,
2148 .ops = &skl_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002149 .id = SKL_DISP_PW_DDI_D,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002150 },
2151};
2152
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302153static struct i915_power_well bxt_power_wells[] = {
2154 {
2155 .name = "always-on",
2156 .always_on = 1,
Ville Syrjälä998bd662016-04-18 14:02:26 +03002157 .domains = POWER_DOMAIN_MASK,
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302158 .ops = &i9xx_always_on_power_well_ops,
2159 },
2160 {
2161 .name = "power well 1",
Imre Deakd7d7c9e2016-04-01 16:02:42 +03002162 .domains = 0,
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302163 .ops = &skl_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002164 .id = SKL_DISP_PW_1,
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302165 },
2166 {
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01002167 .name = "DC off",
2168 .domains = BXT_DISPLAY_DC_OFF_POWER_DOMAINS,
2169 .ops = &gen9_dc_off_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002170 .id = SKL_DISP_PW_DC_OFF,
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01002171 },
2172 {
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302173 .name = "power well 2",
2174 .domains = BXT_DISPLAY_POWERWELL_2_POWER_DOMAINS,
2175 .ops = &skl_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002176 .id = SKL_DISP_PW_2,
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01002177 },
Imre Deak9c8d0b82016-06-13 16:44:34 +03002178 {
2179 .name = "dpio-common-a",
2180 .domains = BXT_DPIO_CMN_A_POWER_DOMAINS,
2181 .ops = &bxt_dpio_cmn_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002182 .id = BXT_DPIO_CMN_A,
Ander Conselvan de Oliveira362624c2016-10-06 19:22:15 +03002183 .data = DPIO_PHY1,
Imre Deak9c8d0b82016-06-13 16:44:34 +03002184 },
2185 {
2186 .name = "dpio-common-bc",
2187 .domains = BXT_DPIO_CMN_BC_POWER_DOMAINS,
2188 .ops = &bxt_dpio_cmn_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002189 .id = BXT_DPIO_CMN_BC,
Ander Conselvan de Oliveira362624c2016-10-06 19:22:15 +03002190 .data = DPIO_PHY0,
Imre Deak9c8d0b82016-06-13 16:44:34 +03002191 },
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302192};
2193
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002194static struct i915_power_well glk_power_wells[] = {
2195 {
2196 .name = "always-on",
2197 .always_on = 1,
2198 .domains = POWER_DOMAIN_MASK,
2199 .ops = &i9xx_always_on_power_well_ops,
2200 },
2201 {
2202 .name = "power well 1",
2203 /* Handled by the DMC firmware */
2204 .domains = 0,
2205 .ops = &skl_power_well_ops,
2206 .id = SKL_DISP_PW_1,
2207 },
2208 {
2209 .name = "DC off",
2210 .domains = GLK_DISPLAY_DC_OFF_POWER_DOMAINS,
2211 .ops = &gen9_dc_off_power_well_ops,
2212 .id = SKL_DISP_PW_DC_OFF,
2213 },
2214 {
2215 .name = "power well 2",
2216 .domains = GLK_DISPLAY_POWERWELL_2_POWER_DOMAINS,
2217 .ops = &skl_power_well_ops,
2218 .id = SKL_DISP_PW_2,
2219 },
2220 {
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +02002221 .name = "dpio-common-a",
2222 .domains = GLK_DPIO_CMN_A_POWER_DOMAINS,
2223 .ops = &bxt_dpio_cmn_power_well_ops,
2224 .id = BXT_DPIO_CMN_A,
2225 .data = DPIO_PHY1,
2226 },
2227 {
2228 .name = "dpio-common-b",
2229 .domains = GLK_DPIO_CMN_B_POWER_DOMAINS,
2230 .ops = &bxt_dpio_cmn_power_well_ops,
2231 .id = BXT_DPIO_CMN_BC,
2232 .data = DPIO_PHY0,
2233 },
2234 {
2235 .name = "dpio-common-c",
2236 .domains = GLK_DPIO_CMN_C_POWER_DOMAINS,
2237 .ops = &bxt_dpio_cmn_power_well_ops,
2238 .id = GLK_DPIO_CMN_C,
2239 .data = DPIO_PHY2,
2240 },
2241 {
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002242 .name = "AUX A",
2243 .domains = GLK_DISPLAY_AUX_A_POWER_DOMAINS,
2244 .ops = &skl_power_well_ops,
2245 .id = GLK_DISP_PW_AUX_A,
2246 },
2247 {
2248 .name = "AUX B",
2249 .domains = GLK_DISPLAY_AUX_B_POWER_DOMAINS,
2250 .ops = &skl_power_well_ops,
2251 .id = GLK_DISP_PW_AUX_B,
2252 },
2253 {
2254 .name = "AUX C",
2255 .domains = GLK_DISPLAY_AUX_C_POWER_DOMAINS,
2256 .ops = &skl_power_well_ops,
2257 .id = GLK_DISP_PW_AUX_C,
2258 },
2259 {
2260 .name = "DDI A power well",
2261 .domains = GLK_DISPLAY_DDI_A_POWER_DOMAINS,
2262 .ops = &skl_power_well_ops,
2263 .id = GLK_DISP_PW_DDI_A,
2264 },
2265 {
2266 .name = "DDI B power well",
2267 .domains = GLK_DISPLAY_DDI_B_POWER_DOMAINS,
2268 .ops = &skl_power_well_ops,
2269 .id = SKL_DISP_PW_DDI_B,
2270 },
2271 {
2272 .name = "DDI C power well",
2273 .domains = GLK_DISPLAY_DDI_C_POWER_DOMAINS,
2274 .ops = &skl_power_well_ops,
2275 .id = SKL_DISP_PW_DDI_C,
2276 },
2277};
2278
Imre Deak1b0e3a02015-11-05 23:04:11 +02002279static int
2280sanitize_disable_power_well_option(const struct drm_i915_private *dev_priv,
2281 int disable_power_well)
2282{
2283 if (disable_power_well >= 0)
2284 return !!disable_power_well;
2285
Imre Deak1b0e3a02015-11-05 23:04:11 +02002286 return 1;
2287}
2288
Imre Deaka37baf32016-02-29 22:49:03 +02002289static uint32_t get_allowed_dc_mask(const struct drm_i915_private *dev_priv,
2290 int enable_dc)
2291{
2292 uint32_t mask;
2293 int requested_dc;
2294 int max_dc;
2295
Rodrigo Vivib976dc52017-01-23 10:32:37 -08002296 if (IS_GEN9_BC(dev_priv)) {
Imre Deaka37baf32016-02-29 22:49:03 +02002297 max_dc = 2;
2298 mask = 0;
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02002299 } else if (IS_GEN9_LP(dev_priv)) {
Imre Deaka37baf32016-02-29 22:49:03 +02002300 max_dc = 1;
2301 /*
2302 * DC9 has a separate HW flow from the rest of the DC states,
2303 * not depending on the DMC firmware. It's needed by system
2304 * suspend/resume, so allow it unconditionally.
2305 */
2306 mask = DC_STATE_EN_DC9;
2307 } else {
2308 max_dc = 0;
2309 mask = 0;
2310 }
2311
Imre Deak66e2c4c2016-02-29 22:49:04 +02002312 if (!i915.disable_power_well)
2313 max_dc = 0;
2314
Imre Deaka37baf32016-02-29 22:49:03 +02002315 if (enable_dc >= 0 && enable_dc <= max_dc) {
2316 requested_dc = enable_dc;
2317 } else if (enable_dc == -1) {
2318 requested_dc = max_dc;
2319 } else if (enable_dc > max_dc && enable_dc <= 2) {
2320 DRM_DEBUG_KMS("Adjusting requested max DC state (%d->%d)\n",
2321 enable_dc, max_dc);
2322 requested_dc = max_dc;
2323 } else {
2324 DRM_ERROR("Unexpected value for enable_dc (%d)\n", enable_dc);
2325 requested_dc = max_dc;
2326 }
2327
2328 if (requested_dc > 1)
2329 mask |= DC_STATE_EN_UPTO_DC6;
2330 if (requested_dc > 0)
2331 mask |= DC_STATE_EN_UPTO_DC5;
2332
2333 DRM_DEBUG_KMS("Allowed DC state mask %02x\n", mask);
2334
2335 return mask;
2336}
2337
Daniel Vetter9c065a72014-09-30 10:56:38 +02002338#define set_power_wells(power_domains, __power_wells) ({ \
2339 (power_domains)->power_wells = (__power_wells); \
2340 (power_domains)->power_well_count = ARRAY_SIZE(__power_wells); \
2341})
2342
Daniel Vettere4e76842014-09-30 10:56:42 +02002343/**
2344 * intel_power_domains_init - initializes the power domain structures
2345 * @dev_priv: i915 device instance
2346 *
2347 * Initializes the power domain structures for @dev_priv depending upon the
2348 * supported platform.
2349 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02002350int intel_power_domains_init(struct drm_i915_private *dev_priv)
2351{
2352 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2353
Imre Deak1b0e3a02015-11-05 23:04:11 +02002354 i915.disable_power_well = sanitize_disable_power_well_option(dev_priv,
2355 i915.disable_power_well);
Imre Deaka37baf32016-02-29 22:49:03 +02002356 dev_priv->csr.allowed_dc_mask = get_allowed_dc_mask(dev_priv,
2357 i915.enable_dc);
Imre Deak1b0e3a02015-11-05 23:04:11 +02002358
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02002359 BUILD_BUG_ON(POWER_DOMAIN_NUM > 64);
Ville Syrjäläf0ab43e2015-11-09 16:48:19 +01002360
Daniel Vetter9c065a72014-09-30 10:56:38 +02002361 mutex_init(&power_domains->lock);
2362
2363 /*
2364 * The enabling order will be from lower to higher indexed wells,
2365 * the disabling order is reversed.
2366 */
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002367 if (IS_HASWELL(dev_priv)) {
Daniel Vetter9c065a72014-09-30 10:56:38 +02002368 set_power_wells(power_domains, hsw_power_wells);
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002369 } else if (IS_BROADWELL(dev_priv)) {
Daniel Vetter9c065a72014-09-30 10:56:38 +02002370 set_power_wells(power_domains, bdw_power_wells);
Rodrigo Vivib976dc52017-01-23 10:32:37 -08002371 } else if (IS_GEN9_BC(dev_priv)) {
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002372 set_power_wells(power_domains, skl_power_wells);
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002373 } else if (IS_BROXTON(dev_priv)) {
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302374 set_power_wells(power_domains, bxt_power_wells);
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002375 } else if (IS_GEMINILAKE(dev_priv)) {
2376 set_power_wells(power_domains, glk_power_wells);
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002377 } else if (IS_CHERRYVIEW(dev_priv)) {
Daniel Vetter9c065a72014-09-30 10:56:38 +02002378 set_power_wells(power_domains, chv_power_wells);
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002379 } else if (IS_VALLEYVIEW(dev_priv)) {
Daniel Vetter9c065a72014-09-30 10:56:38 +02002380 set_power_wells(power_domains, vlv_power_wells);
2381 } else {
2382 set_power_wells(power_domains, i9xx_always_on_power_well);
2383 }
2384
2385 return 0;
2386}
2387
Daniel Vettere4e76842014-09-30 10:56:42 +02002388/**
2389 * intel_power_domains_fini - finalizes the power domain structures
2390 * @dev_priv: i915 device instance
2391 *
2392 * Finalizes the power domain structures for @dev_priv depending upon the
2393 * supported platform. This function also disables runtime pm and ensures that
2394 * the device stays powered up so that the driver can be reloaded.
2395 */
Daniel Vetterf458ebb2014-09-30 10:56:39 +02002396void intel_power_domains_fini(struct drm_i915_private *dev_priv)
Daniel Vetter9c065a72014-09-30 10:56:38 +02002397{
David Weinehallc49d13e2016-08-22 13:32:42 +03002398 struct device *kdev = &dev_priv->drm.pdev->dev;
Imre Deak25b181b2015-12-17 13:44:56 +02002399
Imre Deakaabee1b2015-12-15 20:10:29 +02002400 /*
2401 * The i915.ko module is still not prepared to be loaded when
Daniel Vetterf458ebb2014-09-30 10:56:39 +02002402 * the power well is not enabled, so just enable it in case
Imre Deakaabee1b2015-12-15 20:10:29 +02002403 * we're going to unload/reload.
2404 * The following also reacquires the RPM reference the core passed
2405 * to the driver during loading, which is dropped in
2406 * intel_runtime_pm_enable(). We have to hand back the control of the
2407 * device to the core with this reference held.
2408 */
Daniel Vetterf458ebb2014-09-30 10:56:39 +02002409 intel_display_set_init_power(dev_priv, true);
Imre Deakd314cd42015-11-17 17:44:23 +02002410
2411 /* Remove the refcount we took to keep power well support disabled. */
2412 if (!i915.disable_power_well)
2413 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
Imre Deak25b181b2015-12-17 13:44:56 +02002414
2415 /*
2416 * Remove the refcount we took in intel_runtime_pm_enable() in case
2417 * the platform doesn't support runtime PM.
2418 */
2419 if (!HAS_RUNTIME_PM(dev_priv))
David Weinehallc49d13e2016-08-22 13:32:42 +03002420 pm_runtime_put(kdev);
Daniel Vetter9c065a72014-09-30 10:56:38 +02002421}
2422
Imre Deak30eade12015-11-04 19:24:13 +02002423static void intel_power_domains_sync_hw(struct drm_i915_private *dev_priv)
Daniel Vetter9c065a72014-09-30 10:56:38 +02002424{
2425 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2426 struct i915_power_well *power_well;
2427 int i;
2428
2429 mutex_lock(&power_domains->lock);
2430 for_each_power_well(i, power_well, POWER_DOMAIN_MASK, power_domains) {
2431 power_well->ops->sync_hw(dev_priv, power_well);
2432 power_well->hw_enabled = power_well->ops->is_enabled(dev_priv,
2433 power_well);
2434 }
2435 mutex_unlock(&power_domains->lock);
2436}
2437
Ville Syrjälä70c2c182016-05-13 23:41:30 +03002438static void gen9_dbuf_enable(struct drm_i915_private *dev_priv)
2439{
2440 I915_WRITE(DBUF_CTL, I915_READ(DBUF_CTL) | DBUF_POWER_REQUEST);
2441 POSTING_READ(DBUF_CTL);
2442
2443 udelay(10);
2444
2445 if (!(I915_READ(DBUF_CTL) & DBUF_POWER_STATE))
2446 DRM_ERROR("DBuf power enable timeout\n");
2447}
2448
2449static void gen9_dbuf_disable(struct drm_i915_private *dev_priv)
2450{
2451 I915_WRITE(DBUF_CTL, I915_READ(DBUF_CTL) & ~DBUF_POWER_REQUEST);
2452 POSTING_READ(DBUF_CTL);
2453
2454 udelay(10);
2455
2456 if (I915_READ(DBUF_CTL) & DBUF_POWER_STATE)
2457 DRM_ERROR("DBuf power disable timeout!\n");
2458}
2459
Imre Deak73dfc222015-11-17 17:33:53 +02002460static void skl_display_core_init(struct drm_i915_private *dev_priv,
Imre Deak443a93a2016-04-04 15:42:57 +03002461 bool resume)
Imre Deak73dfc222015-11-17 17:33:53 +02002462{
2463 struct i915_power_domains *power_domains = &dev_priv->power_domains;
Imre Deak443a93a2016-04-04 15:42:57 +03002464 struct i915_power_well *well;
Imre Deak73dfc222015-11-17 17:33:53 +02002465 uint32_t val;
2466
Imre Deakd26fa1d2015-11-04 19:24:17 +02002467 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
2468
Imre Deak73dfc222015-11-17 17:33:53 +02002469 /* enable PCH reset handshake */
2470 val = I915_READ(HSW_NDE_RSTWRN_OPT);
2471 I915_WRITE(HSW_NDE_RSTWRN_OPT, val | RESET_PCH_HANDSHAKE_ENABLE);
2472
2473 /* enable PG1 and Misc I/O */
2474 mutex_lock(&power_domains->lock);
Imre Deak443a93a2016-04-04 15:42:57 +03002475
2476 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
2477 intel_power_well_enable(dev_priv, well);
2478
2479 well = lookup_power_well(dev_priv, SKL_DISP_PW_MISC_IO);
2480 intel_power_well_enable(dev_priv, well);
2481
Imre Deak73dfc222015-11-17 17:33:53 +02002482 mutex_unlock(&power_domains->lock);
2483
Imre Deak73dfc222015-11-17 17:33:53 +02002484 skl_init_cdclk(dev_priv);
2485
Ville Syrjälä70c2c182016-05-13 23:41:30 +03002486 gen9_dbuf_enable(dev_priv);
2487
Ville Syrjälä9f7eb312016-05-13 23:41:29 +03002488 if (resume && dev_priv->csr.dmc_payload)
Imre Deak2abc5252016-03-04 21:57:41 +02002489 intel_csr_load_program(dev_priv);
Imre Deak73dfc222015-11-17 17:33:53 +02002490}
2491
2492static void skl_display_core_uninit(struct drm_i915_private *dev_priv)
2493{
2494 struct i915_power_domains *power_domains = &dev_priv->power_domains;
Imre Deak443a93a2016-04-04 15:42:57 +03002495 struct i915_power_well *well;
Imre Deak73dfc222015-11-17 17:33:53 +02002496
Imre Deakd26fa1d2015-11-04 19:24:17 +02002497 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
2498
Ville Syrjälä70c2c182016-05-13 23:41:30 +03002499 gen9_dbuf_disable(dev_priv);
2500
Imre Deak73dfc222015-11-17 17:33:53 +02002501 skl_uninit_cdclk(dev_priv);
2502
2503 /* The spec doesn't call for removing the reset handshake flag */
2504 /* disable PG1 and Misc I/O */
Imre Deak443a93a2016-04-04 15:42:57 +03002505
Imre Deak73dfc222015-11-17 17:33:53 +02002506 mutex_lock(&power_domains->lock);
Imre Deak443a93a2016-04-04 15:42:57 +03002507
2508 well = lookup_power_well(dev_priv, SKL_DISP_PW_MISC_IO);
2509 intel_power_well_disable(dev_priv, well);
2510
2511 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
2512 intel_power_well_disable(dev_priv, well);
2513
Imre Deak73dfc222015-11-17 17:33:53 +02002514 mutex_unlock(&power_domains->lock);
2515}
2516
Imre Deakd7d7c9e2016-04-01 16:02:42 +03002517void bxt_display_core_init(struct drm_i915_private *dev_priv,
2518 bool resume)
2519{
2520 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2521 struct i915_power_well *well;
2522 uint32_t val;
2523
2524 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
2525
2526 /*
2527 * NDE_RSTWRN_OPT RST PCH Handshake En must always be 0b on BXT
2528 * or else the reset will hang because there is no PCH to respond.
2529 * Move the handshake programming to initialization sequence.
2530 * Previously was left up to BIOS.
2531 */
2532 val = I915_READ(HSW_NDE_RSTWRN_OPT);
2533 val &= ~RESET_PCH_HANDSHAKE_ENABLE;
2534 I915_WRITE(HSW_NDE_RSTWRN_OPT, val);
2535
2536 /* Enable PG1 */
2537 mutex_lock(&power_domains->lock);
2538
2539 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
2540 intel_power_well_enable(dev_priv, well);
2541
2542 mutex_unlock(&power_domains->lock);
2543
Imre Deak324513c2016-06-13 16:44:36 +03002544 bxt_init_cdclk(dev_priv);
Ville Syrjälä70c2c182016-05-13 23:41:30 +03002545
2546 gen9_dbuf_enable(dev_priv);
2547
Imre Deakd7d7c9e2016-04-01 16:02:42 +03002548 if (resume && dev_priv->csr.dmc_payload)
2549 intel_csr_load_program(dev_priv);
2550}
2551
2552void bxt_display_core_uninit(struct drm_i915_private *dev_priv)
2553{
2554 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2555 struct i915_power_well *well;
2556
2557 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
2558
Ville Syrjälä70c2c182016-05-13 23:41:30 +03002559 gen9_dbuf_disable(dev_priv);
2560
Imre Deak324513c2016-06-13 16:44:36 +03002561 bxt_uninit_cdclk(dev_priv);
Imre Deakd7d7c9e2016-04-01 16:02:42 +03002562
2563 /* The spec doesn't call for removing the reset handshake flag */
2564
2565 /* Disable PG1 */
2566 mutex_lock(&power_domains->lock);
2567
2568 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
2569 intel_power_well_disable(dev_priv, well);
2570
2571 mutex_unlock(&power_domains->lock);
2572}
2573
Ville Syrjälä70722462015-04-10 18:21:28 +03002574static void chv_phy_control_init(struct drm_i915_private *dev_priv)
2575{
2576 struct i915_power_well *cmn_bc =
2577 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_BC);
2578 struct i915_power_well *cmn_d =
2579 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_D);
2580
2581 /*
2582 * DISPLAY_PHY_CONTROL can get corrupted if read. As a
2583 * workaround never ever read DISPLAY_PHY_CONTROL, and
2584 * instead maintain a shadow copy ourselves. Use the actual
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002585 * power well state and lane status to reconstruct the
2586 * expected initial value.
Ville Syrjälä70722462015-04-10 18:21:28 +03002587 */
2588 dev_priv->chv_phy_control =
Ville Syrjäläbc284542015-05-26 20:22:38 +03002589 PHY_LDO_SEQ_DELAY(PHY_LDO_DELAY_600NS, DPIO_PHY0) |
2590 PHY_LDO_SEQ_DELAY(PHY_LDO_DELAY_600NS, DPIO_PHY1) |
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002591 PHY_CH_POWER_MODE(PHY_CH_DEEP_PSR, DPIO_PHY0, DPIO_CH0) |
2592 PHY_CH_POWER_MODE(PHY_CH_DEEP_PSR, DPIO_PHY0, DPIO_CH1) |
2593 PHY_CH_POWER_MODE(PHY_CH_DEEP_PSR, DPIO_PHY1, DPIO_CH0);
2594
2595 /*
2596 * If all lanes are disabled we leave the override disabled
2597 * with all power down bits cleared to match the state we
2598 * would use after disabling the port. Otherwise enable the
2599 * override and set the lane powerdown bits accding to the
2600 * current lane status.
2601 */
2602 if (cmn_bc->ops->is_enabled(dev_priv, cmn_bc)) {
2603 uint32_t status = I915_READ(DPLL(PIPE_A));
2604 unsigned int mask;
2605
2606 mask = status & DPLL_PORTB_READY_MASK;
2607 if (mask == 0xf)
2608 mask = 0x0;
2609 else
2610 dev_priv->chv_phy_control |=
2611 PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY0, DPIO_CH0);
2612
2613 dev_priv->chv_phy_control |=
2614 PHY_CH_POWER_DOWN_OVRD(mask, DPIO_PHY0, DPIO_CH0);
2615
2616 mask = (status & DPLL_PORTC_READY_MASK) >> 4;
2617 if (mask == 0xf)
2618 mask = 0x0;
2619 else
2620 dev_priv->chv_phy_control |=
2621 PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY0, DPIO_CH1);
2622
2623 dev_priv->chv_phy_control |=
2624 PHY_CH_POWER_DOWN_OVRD(mask, DPIO_PHY0, DPIO_CH1);
2625
Ville Syrjälä70722462015-04-10 18:21:28 +03002626 dev_priv->chv_phy_control |= PHY_COM_LANE_RESET_DEASSERT(DPIO_PHY0);
Ville Syrjälä3be60de2015-09-08 18:05:45 +03002627
2628 dev_priv->chv_phy_assert[DPIO_PHY0] = false;
2629 } else {
2630 dev_priv->chv_phy_assert[DPIO_PHY0] = true;
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002631 }
2632
2633 if (cmn_d->ops->is_enabled(dev_priv, cmn_d)) {
2634 uint32_t status = I915_READ(DPIO_PHY_STATUS);
2635 unsigned int mask;
2636
2637 mask = status & DPLL_PORTD_READY_MASK;
2638
2639 if (mask == 0xf)
2640 mask = 0x0;
2641 else
2642 dev_priv->chv_phy_control |=
2643 PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY1, DPIO_CH0);
2644
2645 dev_priv->chv_phy_control |=
2646 PHY_CH_POWER_DOWN_OVRD(mask, DPIO_PHY1, DPIO_CH0);
2647
Ville Syrjälä70722462015-04-10 18:21:28 +03002648 dev_priv->chv_phy_control |= PHY_COM_LANE_RESET_DEASSERT(DPIO_PHY1);
Ville Syrjälä3be60de2015-09-08 18:05:45 +03002649
2650 dev_priv->chv_phy_assert[DPIO_PHY1] = false;
2651 } else {
2652 dev_priv->chv_phy_assert[DPIO_PHY1] = true;
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002653 }
2654
2655 I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
2656
2657 DRM_DEBUG_KMS("Initial PHY_CONTROL=0x%08x\n",
2658 dev_priv->chv_phy_control);
Ville Syrjälä70722462015-04-10 18:21:28 +03002659}
2660
Daniel Vetter9c065a72014-09-30 10:56:38 +02002661static void vlv_cmnlane_wa(struct drm_i915_private *dev_priv)
2662{
2663 struct i915_power_well *cmn =
2664 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_BC);
2665 struct i915_power_well *disp2d =
2666 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DISP2D);
2667
Daniel Vetter9c065a72014-09-30 10:56:38 +02002668 /* If the display might be already active skip this */
Ville Syrjälä5d93a6e2014-10-16 20:52:33 +03002669 if (cmn->ops->is_enabled(dev_priv, cmn) &&
2670 disp2d->ops->is_enabled(dev_priv, disp2d) &&
Daniel Vetter9c065a72014-09-30 10:56:38 +02002671 I915_READ(DPIO_CTL) & DPIO_CMNRST)
2672 return;
2673
2674 DRM_DEBUG_KMS("toggling display PHY side reset\n");
2675
2676 /* cmnlane needs DPLL registers */
2677 disp2d->ops->enable(dev_priv, disp2d);
2678
2679 /*
2680 * From VLV2A0_DP_eDP_HDMI_DPIO_driver_vbios_notes_11.docx:
2681 * Need to assert and de-assert PHY SB reset by gating the
2682 * common lane power, then un-gating it.
2683 * Simply ungating isn't enough to reset the PHY enough to get
2684 * ports and lanes running.
2685 */
2686 cmn->ops->disable(dev_priv, cmn);
2687}
2688
Daniel Vettere4e76842014-09-30 10:56:42 +02002689/**
2690 * intel_power_domains_init_hw - initialize hardware power domain state
2691 * @dev_priv: i915 device instance
Tvrtko Ursulin14bb2c12016-06-03 14:02:17 +01002692 * @resume: Called from resume code paths or not
Daniel Vettere4e76842014-09-30 10:56:42 +02002693 *
2694 * This function initializes the hardware power domain state and enables all
2695 * power domains using intel_display_set_init_power().
2696 */
Imre Deak73dfc222015-11-17 17:33:53 +02002697void intel_power_domains_init_hw(struct drm_i915_private *dev_priv, bool resume)
Daniel Vetter9c065a72014-09-30 10:56:38 +02002698{
Daniel Vetter9c065a72014-09-30 10:56:38 +02002699 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2700
2701 power_domains->initializing = true;
2702
Rodrigo Vivib976dc52017-01-23 10:32:37 -08002703 if (IS_GEN9_BC(dev_priv)) {
Imre Deak73dfc222015-11-17 17:33:53 +02002704 skl_display_core_init(dev_priv, resume);
Ander Conselvan de Oliveirab817c442016-12-02 10:23:56 +02002705 } else if (IS_GEN9_LP(dev_priv)) {
Imre Deakd7d7c9e2016-04-01 16:02:42 +03002706 bxt_display_core_init(dev_priv, resume);
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002707 } else if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä770effb2015-07-08 23:45:51 +03002708 mutex_lock(&power_domains->lock);
Ville Syrjälä70722462015-04-10 18:21:28 +03002709 chv_phy_control_init(dev_priv);
Ville Syrjälä770effb2015-07-08 23:45:51 +03002710 mutex_unlock(&power_domains->lock);
Tvrtko Ursulin11a914c2016-10-13 11:03:08 +01002711 } else if (IS_VALLEYVIEW(dev_priv)) {
Daniel Vetter9c065a72014-09-30 10:56:38 +02002712 mutex_lock(&power_domains->lock);
2713 vlv_cmnlane_wa(dev_priv);
2714 mutex_unlock(&power_domains->lock);
2715 }
2716
2717 /* For now, we need the power well to be always enabled. */
2718 intel_display_set_init_power(dev_priv, true);
Imre Deakd314cd42015-11-17 17:44:23 +02002719 /* Disable power support if the user asked so. */
2720 if (!i915.disable_power_well)
2721 intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
Imre Deak30eade12015-11-04 19:24:13 +02002722 intel_power_domains_sync_hw(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02002723 power_domains->initializing = false;
2724}
2725
Daniel Vettere4e76842014-09-30 10:56:42 +02002726/**
Imre Deak73dfc222015-11-17 17:33:53 +02002727 * intel_power_domains_suspend - suspend power domain state
2728 * @dev_priv: i915 device instance
2729 *
2730 * This function prepares the hardware power domain state before entering
2731 * system suspend. It must be paired with intel_power_domains_init_hw().
2732 */
2733void intel_power_domains_suspend(struct drm_i915_private *dev_priv)
2734{
Imre Deakd314cd42015-11-17 17:44:23 +02002735 /*
2736 * Even if power well support was disabled we still want to disable
2737 * power wells while we are system suspended.
2738 */
2739 if (!i915.disable_power_well)
2740 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
Imre Deak2622d792016-02-29 22:49:02 +02002741
Rodrigo Vivib976dc52017-01-23 10:32:37 -08002742 if (IS_GEN9_BC(dev_priv))
Imre Deak2622d792016-02-29 22:49:02 +02002743 skl_display_core_uninit(dev_priv);
Ander Conselvan de Oliveirab817c442016-12-02 10:23:56 +02002744 else if (IS_GEN9_LP(dev_priv))
Imre Deakd7d7c9e2016-04-01 16:02:42 +03002745 bxt_display_core_uninit(dev_priv);
Imre Deak73dfc222015-11-17 17:33:53 +02002746}
2747
2748/**
Daniel Vettere4e76842014-09-30 10:56:42 +02002749 * intel_runtime_pm_get - grab a runtime pm reference
2750 * @dev_priv: i915 device instance
2751 *
2752 * This function grabs a device-level runtime pm reference (mostly used for GEM
2753 * code to ensure the GTT or GT is on) and ensures that it is powered up.
2754 *
2755 * Any runtime pm reference obtained by this function must have a symmetric
2756 * call to intel_runtime_pm_put() to release the reference again.
2757 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02002758void intel_runtime_pm_get(struct drm_i915_private *dev_priv)
2759{
David Weinehall52a05c32016-08-22 13:32:44 +03002760 struct pci_dev *pdev = dev_priv->drm.pdev;
2761 struct device *kdev = &pdev->dev;
Daniel Vetter9c065a72014-09-30 10:56:38 +02002762
David Weinehallc49d13e2016-08-22 13:32:42 +03002763 pm_runtime_get_sync(kdev);
Imre Deak1f814da2015-12-16 02:52:19 +02002764
2765 atomic_inc(&dev_priv->pm.wakeref_count);
Imre Deakc9b88462015-12-15 20:10:34 +02002766 assert_rpm_wakelock_held(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02002767}
2768
Daniel Vettere4e76842014-09-30 10:56:42 +02002769/**
Imre Deak09731282016-02-17 14:17:42 +02002770 * intel_runtime_pm_get_if_in_use - grab a runtime pm reference if device in use
2771 * @dev_priv: i915 device instance
2772 *
2773 * This function grabs a device-level runtime pm reference if the device is
2774 * already in use and ensures that it is powered up.
2775 *
2776 * Any runtime pm reference obtained by this function must have a symmetric
2777 * call to intel_runtime_pm_put() to release the reference again.
2778 */
2779bool intel_runtime_pm_get_if_in_use(struct drm_i915_private *dev_priv)
2780{
David Weinehall52a05c32016-08-22 13:32:44 +03002781 struct pci_dev *pdev = dev_priv->drm.pdev;
2782 struct device *kdev = &pdev->dev;
Imre Deak09731282016-02-17 14:17:42 +02002783
Chris Wilson135dc792016-02-25 21:10:28 +00002784 if (IS_ENABLED(CONFIG_PM)) {
David Weinehallc49d13e2016-08-22 13:32:42 +03002785 int ret = pm_runtime_get_if_in_use(kdev);
Imre Deak09731282016-02-17 14:17:42 +02002786
Chris Wilson135dc792016-02-25 21:10:28 +00002787 /*
2788 * In cases runtime PM is disabled by the RPM core and we get
2789 * an -EINVAL return value we are not supposed to call this
2790 * function, since the power state is undefined. This applies
2791 * atm to the late/early system suspend/resume handlers.
2792 */
2793 WARN_ON_ONCE(ret < 0);
2794 if (ret <= 0)
2795 return false;
2796 }
Imre Deak09731282016-02-17 14:17:42 +02002797
2798 atomic_inc(&dev_priv->pm.wakeref_count);
2799 assert_rpm_wakelock_held(dev_priv);
2800
2801 return true;
2802}
2803
2804/**
Daniel Vettere4e76842014-09-30 10:56:42 +02002805 * intel_runtime_pm_get_noresume - grab a runtime pm reference
2806 * @dev_priv: i915 device instance
2807 *
2808 * This function grabs a device-level runtime pm reference (mostly used for GEM
2809 * code to ensure the GTT or GT is on).
2810 *
2811 * It will _not_ power up the device but instead only check that it's powered
2812 * on. Therefore it is only valid to call this functions from contexts where
2813 * the device is known to be powered up and where trying to power it up would
2814 * result in hilarity and deadlocks. That pretty much means only the system
2815 * suspend/resume code where this is used to grab runtime pm references for
2816 * delayed setup down in work items.
2817 *
2818 * Any runtime pm reference obtained by this function must have a symmetric
2819 * call to intel_runtime_pm_put() to release the reference again.
2820 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02002821void intel_runtime_pm_get_noresume(struct drm_i915_private *dev_priv)
2822{
David Weinehall52a05c32016-08-22 13:32:44 +03002823 struct pci_dev *pdev = dev_priv->drm.pdev;
2824 struct device *kdev = &pdev->dev;
Daniel Vetter9c065a72014-09-30 10:56:38 +02002825
Imre Deakc9b88462015-12-15 20:10:34 +02002826 assert_rpm_wakelock_held(dev_priv);
David Weinehallc49d13e2016-08-22 13:32:42 +03002827 pm_runtime_get_noresume(kdev);
Imre Deak1f814da2015-12-16 02:52:19 +02002828
2829 atomic_inc(&dev_priv->pm.wakeref_count);
Daniel Vetter9c065a72014-09-30 10:56:38 +02002830}
2831
Daniel Vettere4e76842014-09-30 10:56:42 +02002832/**
2833 * intel_runtime_pm_put - release a runtime pm reference
2834 * @dev_priv: i915 device instance
2835 *
2836 * This function drops the device-level runtime pm reference obtained by
2837 * intel_runtime_pm_get() and might power down the corresponding
2838 * hardware block right away if this is the last reference.
2839 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02002840void intel_runtime_pm_put(struct drm_i915_private *dev_priv)
2841{
David Weinehall52a05c32016-08-22 13:32:44 +03002842 struct pci_dev *pdev = dev_priv->drm.pdev;
2843 struct device *kdev = &pdev->dev;
Daniel Vetter9c065a72014-09-30 10:56:38 +02002844
Imre Deak542db3c2015-12-15 20:10:36 +02002845 assert_rpm_wakelock_held(dev_priv);
Chris Wilson2eedfc72016-10-24 13:42:17 +01002846 atomic_dec(&dev_priv->pm.wakeref_count);
Imre Deak1f814da2015-12-16 02:52:19 +02002847
David Weinehallc49d13e2016-08-22 13:32:42 +03002848 pm_runtime_mark_last_busy(kdev);
2849 pm_runtime_put_autosuspend(kdev);
Daniel Vetter9c065a72014-09-30 10:56:38 +02002850}
2851
Daniel Vettere4e76842014-09-30 10:56:42 +02002852/**
2853 * intel_runtime_pm_enable - enable runtime pm
2854 * @dev_priv: i915 device instance
2855 *
2856 * This function enables runtime pm at the end of the driver load sequence.
2857 *
2858 * Note that this function does currently not enable runtime pm for the
2859 * subordinate display power domains. That is only done on the first modeset
2860 * using intel_display_set_init_power().
2861 */
Daniel Vetterf458ebb2014-09-30 10:56:39 +02002862void intel_runtime_pm_enable(struct drm_i915_private *dev_priv)
Daniel Vetter9c065a72014-09-30 10:56:38 +02002863{
David Weinehall52a05c32016-08-22 13:32:44 +03002864 struct pci_dev *pdev = dev_priv->drm.pdev;
David Weinehall52a05c32016-08-22 13:32:44 +03002865 struct device *kdev = &pdev->dev;
Daniel Vetter9c065a72014-09-30 10:56:38 +02002866
David Weinehallc49d13e2016-08-22 13:32:42 +03002867 pm_runtime_set_autosuspend_delay(kdev, 10000); /* 10s */
2868 pm_runtime_mark_last_busy(kdev);
Imre Deakcbc68dc2015-12-17 19:04:33 +02002869
Imre Deak25b181b2015-12-17 13:44:56 +02002870 /*
2871 * Take a permanent reference to disable the RPM functionality and drop
2872 * it only when unloading the driver. Use the low level get/put helpers,
2873 * so the driver's own RPM reference tracking asserts also work on
2874 * platforms without RPM support.
2875 */
Tvrtko Ursulin6772ffe2016-10-13 11:02:55 +01002876 if (!HAS_RUNTIME_PM(dev_priv)) {
David Weinehallc49d13e2016-08-22 13:32:42 +03002877 pm_runtime_dont_use_autosuspend(kdev);
2878 pm_runtime_get_sync(kdev);
Imre Deakcbc68dc2015-12-17 19:04:33 +02002879 } else {
David Weinehallc49d13e2016-08-22 13:32:42 +03002880 pm_runtime_use_autosuspend(kdev);
Imre Deakcbc68dc2015-12-17 19:04:33 +02002881 }
Daniel Vetter9c065a72014-09-30 10:56:38 +02002882
Imre Deakaabee1b2015-12-15 20:10:29 +02002883 /*
2884 * The core calls the driver load handler with an RPM reference held.
2885 * We drop that here and will reacquire it during unloading in
2886 * intel_power_domains_fini().
2887 */
David Weinehallc49d13e2016-08-22 13:32:42 +03002888 pm_runtime_put_autosuspend(kdev);
Daniel Vetter9c065a72014-09-30 10:56:38 +02002889}