blob: 6b52258152b7b53cbb54c9fd9886e8ffc4aafff0 [file] [log] [blame]
Daniel Vetter9c065a72014-09-30 10:56:38 +02001/*
2 * Copyright © 2012-2014 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 *
23 * Authors:
24 * Eugeni Dodonov <eugeni.dodonov@intel.com>
25 * Daniel Vetter <daniel.vetter@ffwll.ch>
26 *
27 */
28
29#include <linux/pm_runtime.h>
30#include <linux/vgaarb.h>
31
32#include "i915_drv.h"
33#include "intel_drv.h"
Daniel Vetter9c065a72014-09-30 10:56:38 +020034
Daniel Vettere4e76842014-09-30 10:56:42 +020035/**
36 * DOC: runtime pm
37 *
38 * The i915 driver supports dynamic enabling and disabling of entire hardware
39 * blocks at runtime. This is especially important on the display side where
40 * software is supposed to control many power gates manually on recent hardware,
41 * since on the GT side a lot of the power management is done by the hardware.
42 * But even there some manual control at the device level is required.
43 *
44 * Since i915 supports a diverse set of platforms with a unified codebase and
45 * hardware engineers just love to shuffle functionality around between power
46 * domains there's a sizeable amount of indirection required. This file provides
47 * generic functions to the driver for grabbing and releasing references for
48 * abstract power domains. It then maps those to the actual power wells
49 * present for a given platform.
50 */
51
Suketu Shah5aefb232015-04-16 14:22:10 +053052bool intel_display_power_well_is_enabled(struct drm_i915_private *dev_priv,
53 int power_well_id);
54
Imre Deak9c8d0b82016-06-13 16:44:34 +030055static struct i915_power_well *
56lookup_power_well(struct drm_i915_private *dev_priv, int power_well_id);
57
Daniel Stone9895ad02015-11-20 15:55:33 +000058const char *
59intel_display_power_domain_str(enum intel_display_power_domain domain)
60{
61 switch (domain) {
62 case POWER_DOMAIN_PIPE_A:
63 return "PIPE_A";
64 case POWER_DOMAIN_PIPE_B:
65 return "PIPE_B";
66 case POWER_DOMAIN_PIPE_C:
67 return "PIPE_C";
68 case POWER_DOMAIN_PIPE_A_PANEL_FITTER:
69 return "PIPE_A_PANEL_FITTER";
70 case POWER_DOMAIN_PIPE_B_PANEL_FITTER:
71 return "PIPE_B_PANEL_FITTER";
72 case POWER_DOMAIN_PIPE_C_PANEL_FITTER:
73 return "PIPE_C_PANEL_FITTER";
74 case POWER_DOMAIN_TRANSCODER_A:
75 return "TRANSCODER_A";
76 case POWER_DOMAIN_TRANSCODER_B:
77 return "TRANSCODER_B";
78 case POWER_DOMAIN_TRANSCODER_C:
79 return "TRANSCODER_C";
80 case POWER_DOMAIN_TRANSCODER_EDP:
81 return "TRANSCODER_EDP";
Jani Nikula4d1de972016-03-18 17:05:42 +020082 case POWER_DOMAIN_TRANSCODER_DSI_A:
83 return "TRANSCODER_DSI_A";
84 case POWER_DOMAIN_TRANSCODER_DSI_C:
85 return "TRANSCODER_DSI_C";
Daniel Stone9895ad02015-11-20 15:55:33 +000086 case POWER_DOMAIN_PORT_DDI_A_LANES:
87 return "PORT_DDI_A_LANES";
88 case POWER_DOMAIN_PORT_DDI_B_LANES:
89 return "PORT_DDI_B_LANES";
90 case POWER_DOMAIN_PORT_DDI_C_LANES:
91 return "PORT_DDI_C_LANES";
92 case POWER_DOMAIN_PORT_DDI_D_LANES:
93 return "PORT_DDI_D_LANES";
94 case POWER_DOMAIN_PORT_DDI_E_LANES:
95 return "PORT_DDI_E_LANES";
96 case POWER_DOMAIN_PORT_DSI:
97 return "PORT_DSI";
98 case POWER_DOMAIN_PORT_CRT:
99 return "PORT_CRT";
100 case POWER_DOMAIN_PORT_OTHER:
101 return "PORT_OTHER";
102 case POWER_DOMAIN_VGA:
103 return "VGA";
104 case POWER_DOMAIN_AUDIO:
105 return "AUDIO";
106 case POWER_DOMAIN_PLLS:
107 return "PLLS";
108 case POWER_DOMAIN_AUX_A:
109 return "AUX_A";
110 case POWER_DOMAIN_AUX_B:
111 return "AUX_B";
112 case POWER_DOMAIN_AUX_C:
113 return "AUX_C";
114 case POWER_DOMAIN_AUX_D:
115 return "AUX_D";
116 case POWER_DOMAIN_GMBUS:
117 return "GMBUS";
118 case POWER_DOMAIN_INIT:
119 return "INIT";
120 case POWER_DOMAIN_MODESET:
121 return "MODESET";
122 default:
123 MISSING_CASE(domain);
124 return "?";
125 }
126}
127
Damien Lespiaue8ca9322015-07-30 18:20:26 -0300128static void intel_power_well_enable(struct drm_i915_private *dev_priv,
129 struct i915_power_well *power_well)
130{
131 DRM_DEBUG_KMS("enabling %s\n", power_well->name);
132 power_well->ops->enable(dev_priv, power_well);
133 power_well->hw_enabled = true;
134}
135
Damien Lespiaudcddab32015-07-30 18:20:27 -0300136static void intel_power_well_disable(struct drm_i915_private *dev_priv,
137 struct i915_power_well *power_well)
138{
139 DRM_DEBUG_KMS("disabling %s\n", power_well->name);
140 power_well->hw_enabled = false;
141 power_well->ops->disable(dev_priv, power_well);
142}
143
Imre Deakb409ca92016-06-13 16:44:33 +0300144static void intel_power_well_get(struct drm_i915_private *dev_priv,
145 struct i915_power_well *power_well)
146{
147 if (!power_well->count++)
148 intel_power_well_enable(dev_priv, power_well);
149}
150
151static void intel_power_well_put(struct drm_i915_private *dev_priv,
152 struct i915_power_well *power_well)
153{
154 WARN(!power_well->count, "Use count on power well %s is already zero",
155 power_well->name);
156
157 if (!--power_well->count)
158 intel_power_well_disable(dev_priv, power_well);
159}
160
Daniel Vettere4e76842014-09-30 10:56:42 +0200161/*
Daniel Vetter9c065a72014-09-30 10:56:38 +0200162 * We should only use the power well if we explicitly asked the hardware to
163 * enable it, so check if it's enabled and also check if we've requested it to
164 * be enabled.
165 */
166static bool hsw_power_well_enabled(struct drm_i915_private *dev_priv,
167 struct i915_power_well *power_well)
168{
169 return I915_READ(HSW_PWR_WELL_DRIVER) ==
170 (HSW_PWR_WELL_ENABLE_REQUEST | HSW_PWR_WELL_STATE_ENABLED);
171}
172
Daniel Vettere4e76842014-09-30 10:56:42 +0200173/**
174 * __intel_display_power_is_enabled - unlocked check for a power domain
175 * @dev_priv: i915 device instance
176 * @domain: power domain to check
177 *
178 * This is the unlocked version of intel_display_power_is_enabled() and should
179 * only be used from error capture and recovery code where deadlocks are
180 * possible.
181 *
182 * Returns:
183 * True when the power domain is enabled, false otherwise.
184 */
Daniel Vetterf458ebb2014-09-30 10:56:39 +0200185bool __intel_display_power_is_enabled(struct drm_i915_private *dev_priv,
186 enum intel_display_power_domain domain)
Daniel Vetter9c065a72014-09-30 10:56:38 +0200187{
Daniel Vetter9c065a72014-09-30 10:56:38 +0200188 struct i915_power_well *power_well;
189 bool is_enabled;
Daniel Vetter9c065a72014-09-30 10:56:38 +0200190
191 if (dev_priv->pm.suspended)
192 return false;
193
Daniel Vetter9c065a72014-09-30 10:56:38 +0200194 is_enabled = true;
195
Imre Deak75ccb2e2017-02-17 17:39:43 +0200196 for_each_power_domain_well_rev(dev_priv, power_well, BIT_ULL(domain)) {
Daniel Vetter9c065a72014-09-30 10:56:38 +0200197 if (power_well->always_on)
198 continue;
199
200 if (!power_well->hw_enabled) {
201 is_enabled = false;
202 break;
203 }
204 }
205
206 return is_enabled;
207}
208
Daniel Vettere4e76842014-09-30 10:56:42 +0200209/**
Damien Lespiauf61ccae2014-11-25 13:45:41 +0000210 * intel_display_power_is_enabled - check for a power domain
Daniel Vettere4e76842014-09-30 10:56:42 +0200211 * @dev_priv: i915 device instance
212 * @domain: power domain to check
213 *
214 * This function can be used to check the hw power domain state. It is mostly
215 * used in hardware state readout functions. Everywhere else code should rely
216 * upon explicit power domain reference counting to ensure that the hardware
217 * block is powered up before accessing it.
218 *
219 * Callers must hold the relevant modesetting locks to ensure that concurrent
220 * threads can't disable the power well while the caller tries to read a few
221 * registers.
222 *
223 * Returns:
224 * True when the power domain is enabled, false otherwise.
225 */
Daniel Vetterf458ebb2014-09-30 10:56:39 +0200226bool intel_display_power_is_enabled(struct drm_i915_private *dev_priv,
227 enum intel_display_power_domain domain)
Daniel Vetter9c065a72014-09-30 10:56:38 +0200228{
229 struct i915_power_domains *power_domains;
230 bool ret;
231
232 power_domains = &dev_priv->power_domains;
233
234 mutex_lock(&power_domains->lock);
Daniel Vetterf458ebb2014-09-30 10:56:39 +0200235 ret = __intel_display_power_is_enabled(dev_priv, domain);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200236 mutex_unlock(&power_domains->lock);
237
238 return ret;
239}
240
Daniel Vettere4e76842014-09-30 10:56:42 +0200241/**
242 * intel_display_set_init_power - set the initial power domain state
243 * @dev_priv: i915 device instance
244 * @enable: whether to enable or disable the initial power domain state
245 *
246 * For simplicity our driver load/unload and system suspend/resume code assumes
247 * that all power domains are always enabled. This functions controls the state
248 * of this little hack. While the initial power domain state is enabled runtime
249 * pm is effectively disabled.
250 */
Daniel Vetterd9bc89d92014-09-30 10:56:40 +0200251void intel_display_set_init_power(struct drm_i915_private *dev_priv,
252 bool enable)
253{
254 if (dev_priv->power_domains.init_power_on == enable)
255 return;
256
257 if (enable)
258 intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
259 else
260 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
261
262 dev_priv->power_domains.init_power_on = enable;
263}
264
Daniel Vetter9c065a72014-09-30 10:56:38 +0200265/*
266 * Starting with Haswell, we have a "Power Down Well" that can be turned off
267 * when not needed anymore. We have 4 registers that can request the power well
268 * to be enabled, and it will only be disabled if none of the registers is
269 * requesting it to be enabled.
270 */
271static void hsw_power_well_post_enable(struct drm_i915_private *dev_priv)
272{
David Weinehall52a05c32016-08-22 13:32:44 +0300273 struct pci_dev *pdev = dev_priv->drm.pdev;
Daniel Vetter9c065a72014-09-30 10:56:38 +0200274
275 /*
276 * After we re-enable the power well, if we touch VGA register 0x3d5
277 * we'll get unclaimed register interrupts. This stops after we write
278 * anything to the VGA MSR register. The vgacon module uses this
279 * register all the time, so if we unbind our driver and, as a
280 * consequence, bind vgacon, we'll get stuck in an infinite loop at
281 * console_unlock(). So make here we touch the VGA MSR register, making
282 * sure vgacon can keep working normally without triggering interrupts
283 * and error messages.
284 */
David Weinehall52a05c32016-08-22 13:32:44 +0300285 vga_get_uninterruptible(pdev, VGA_RSRC_LEGACY_IO);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200286 outb(inb(VGA_MSR_READ), VGA_MSR_WRITE);
David Weinehall52a05c32016-08-22 13:32:44 +0300287 vga_put(pdev, VGA_RSRC_LEGACY_IO);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200288
Tvrtko Ursulin86527442016-10-13 11:03:00 +0100289 if (IS_BROADWELL(dev_priv))
Damien Lespiau4c6c03b2015-03-06 18:50:48 +0000290 gen8_irq_power_well_post_enable(dev_priv,
291 1 << PIPE_C | 1 << PIPE_B);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200292}
293
Ville Syrjäläaae8ba82016-02-19 20:47:30 +0200294static void hsw_power_well_pre_disable(struct drm_i915_private *dev_priv)
295{
296 if (IS_BROADWELL(dev_priv))
297 gen8_irq_power_well_pre_disable(dev_priv,
298 1 << PIPE_C | 1 << PIPE_B);
299}
300
Damien Lespiaud14c0342015-03-06 18:50:51 +0000301static void skl_power_well_post_enable(struct drm_i915_private *dev_priv,
302 struct i915_power_well *power_well)
303{
David Weinehall52a05c32016-08-22 13:32:44 +0300304 struct pci_dev *pdev = dev_priv->drm.pdev;
Damien Lespiaud14c0342015-03-06 18:50:51 +0000305
306 /*
307 * After we re-enable the power well, if we touch VGA register 0x3d5
308 * we'll get unclaimed register interrupts. This stops after we write
309 * anything to the VGA MSR register. The vgacon module uses this
310 * register all the time, so if we unbind our driver and, as a
311 * consequence, bind vgacon, we'll get stuck in an infinite loop at
312 * console_unlock(). So make here we touch the VGA MSR register, making
313 * sure vgacon can keep working normally without triggering interrupts
314 * and error messages.
315 */
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +0300316 if (power_well->id == SKL_DISP_PW_2) {
David Weinehall52a05c32016-08-22 13:32:44 +0300317 vga_get_uninterruptible(pdev, VGA_RSRC_LEGACY_IO);
Damien Lespiaud14c0342015-03-06 18:50:51 +0000318 outb(inb(VGA_MSR_READ), VGA_MSR_WRITE);
David Weinehall52a05c32016-08-22 13:32:44 +0300319 vga_put(pdev, VGA_RSRC_LEGACY_IO);
Damien Lespiaud14c0342015-03-06 18:50:51 +0000320
321 gen8_irq_power_well_post_enable(dev_priv,
322 1 << PIPE_C | 1 << PIPE_B);
323 }
Damien Lespiaud14c0342015-03-06 18:50:51 +0000324}
325
Ville Syrjäläaae8ba82016-02-19 20:47:30 +0200326static void skl_power_well_pre_disable(struct drm_i915_private *dev_priv,
327 struct i915_power_well *power_well)
328{
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +0300329 if (power_well->id == SKL_DISP_PW_2)
Ville Syrjäläaae8ba82016-02-19 20:47:30 +0200330 gen8_irq_power_well_pre_disable(dev_priv,
331 1 << PIPE_C | 1 << PIPE_B);
332}
333
Daniel Vetter9c065a72014-09-30 10:56:38 +0200334static void hsw_set_power_well(struct drm_i915_private *dev_priv,
335 struct i915_power_well *power_well, bool enable)
336{
337 bool is_enabled, enable_requested;
338 uint32_t tmp;
339
340 tmp = I915_READ(HSW_PWR_WELL_DRIVER);
341 is_enabled = tmp & HSW_PWR_WELL_STATE_ENABLED;
342 enable_requested = tmp & HSW_PWR_WELL_ENABLE_REQUEST;
343
344 if (enable) {
345 if (!enable_requested)
346 I915_WRITE(HSW_PWR_WELL_DRIVER,
347 HSW_PWR_WELL_ENABLE_REQUEST);
348
349 if (!is_enabled) {
350 DRM_DEBUG_KMS("Enabling power well\n");
Chris Wilson2c2ccc32016-06-30 15:33:32 +0100351 if (intel_wait_for_register(dev_priv,
352 HSW_PWR_WELL_DRIVER,
353 HSW_PWR_WELL_STATE_ENABLED,
354 HSW_PWR_WELL_STATE_ENABLED,
355 20))
Daniel Vetter9c065a72014-09-30 10:56:38 +0200356 DRM_ERROR("Timeout enabling power well\n");
Paulo Zanoni6d729bf2014-10-07 16:11:11 -0300357 hsw_power_well_post_enable(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200358 }
359
Daniel Vetter9c065a72014-09-30 10:56:38 +0200360 } else {
361 if (enable_requested) {
Ville Syrjäläaae8ba82016-02-19 20:47:30 +0200362 hsw_power_well_pre_disable(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200363 I915_WRITE(HSW_PWR_WELL_DRIVER, 0);
364 POSTING_READ(HSW_PWR_WELL_DRIVER);
365 DRM_DEBUG_KMS("Requesting to disable the power well\n");
366 }
367 }
368}
369
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000370#define SKL_DISPLAY_POWERWELL_2_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200371 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
372 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
373 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
374 BIT_ULL(POWER_DOMAIN_PIPE_C) | \
375 BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
376 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
377 BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
378 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
379 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
380 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_LANES) | \
381 BIT_ULL(POWER_DOMAIN_PORT_DDI_E_LANES) | \
382 BIT_ULL(POWER_DOMAIN_AUX_B) | \
383 BIT_ULL(POWER_DOMAIN_AUX_C) | \
384 BIT_ULL(POWER_DOMAIN_AUX_D) | \
385 BIT_ULL(POWER_DOMAIN_AUDIO) | \
386 BIT_ULL(POWER_DOMAIN_VGA) | \
387 BIT_ULL(POWER_DOMAIN_INIT))
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000388#define SKL_DISPLAY_DDI_A_E_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200389 BIT_ULL(POWER_DOMAIN_PORT_DDI_A_LANES) | \
390 BIT_ULL(POWER_DOMAIN_PORT_DDI_E_LANES) | \
391 BIT_ULL(POWER_DOMAIN_INIT))
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000392#define SKL_DISPLAY_DDI_B_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200393 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
394 BIT_ULL(POWER_DOMAIN_INIT))
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000395#define SKL_DISPLAY_DDI_C_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200396 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
397 BIT_ULL(POWER_DOMAIN_INIT))
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000398#define SKL_DISPLAY_DDI_D_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200399 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_LANES) | \
400 BIT_ULL(POWER_DOMAIN_INIT))
Patrik Jakobsson9f836f92015-11-16 16:20:01 +0100401#define SKL_DISPLAY_DC_OFF_POWER_DOMAINS ( \
402 SKL_DISPLAY_POWERWELL_2_POWER_DOMAINS | \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200403 BIT_ULL(POWER_DOMAIN_MODESET) | \
404 BIT_ULL(POWER_DOMAIN_AUX_A) | \
405 BIT_ULL(POWER_DOMAIN_INIT))
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000406
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +0530407#define BXT_DISPLAY_POWERWELL_2_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200408 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
409 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
410 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
411 BIT_ULL(POWER_DOMAIN_PIPE_C) | \
412 BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
413 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
414 BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
415 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
416 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
417 BIT_ULL(POWER_DOMAIN_AUX_B) | \
418 BIT_ULL(POWER_DOMAIN_AUX_C) | \
419 BIT_ULL(POWER_DOMAIN_AUDIO) | \
420 BIT_ULL(POWER_DOMAIN_VGA) | \
421 BIT_ULL(POWER_DOMAIN_GMBUS) | \
422 BIT_ULL(POWER_DOMAIN_INIT))
Patrik Jakobsson9f836f92015-11-16 16:20:01 +0100423#define BXT_DISPLAY_DC_OFF_POWER_DOMAINS ( \
424 BXT_DISPLAY_POWERWELL_2_POWER_DOMAINS | \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200425 BIT_ULL(POWER_DOMAIN_MODESET) | \
426 BIT_ULL(POWER_DOMAIN_AUX_A) | \
427 BIT_ULL(POWER_DOMAIN_INIT))
Imre Deak9c8d0b82016-06-13 16:44:34 +0300428#define BXT_DPIO_CMN_A_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200429 BIT_ULL(POWER_DOMAIN_PORT_DDI_A_LANES) | \
430 BIT_ULL(POWER_DOMAIN_AUX_A) | \
431 BIT_ULL(POWER_DOMAIN_INIT))
Imre Deak9c8d0b82016-06-13 16:44:34 +0300432#define BXT_DPIO_CMN_BC_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200433 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
434 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
435 BIT_ULL(POWER_DOMAIN_AUX_B) | \
436 BIT_ULL(POWER_DOMAIN_AUX_C) | \
437 BIT_ULL(POWER_DOMAIN_INIT))
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +0530438
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +0200439#define GLK_DISPLAY_POWERWELL_2_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200440 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
441 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
442 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
443 BIT_ULL(POWER_DOMAIN_PIPE_C) | \
444 BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
445 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
446 BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
447 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
448 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
449 BIT_ULL(POWER_DOMAIN_AUX_B) | \
450 BIT_ULL(POWER_DOMAIN_AUX_C) | \
451 BIT_ULL(POWER_DOMAIN_AUDIO) | \
452 BIT_ULL(POWER_DOMAIN_VGA) | \
453 BIT_ULL(POWER_DOMAIN_INIT))
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +0200454#define GLK_DISPLAY_DDI_A_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200455 BIT_ULL(POWER_DOMAIN_PORT_DDI_A_LANES) | \
456 BIT_ULL(POWER_DOMAIN_INIT))
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +0200457#define GLK_DISPLAY_DDI_B_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200458 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
459 BIT_ULL(POWER_DOMAIN_INIT))
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +0200460#define GLK_DISPLAY_DDI_C_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200461 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
462 BIT_ULL(POWER_DOMAIN_INIT))
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +0200463#define GLK_DPIO_CMN_A_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200464 BIT_ULL(POWER_DOMAIN_PORT_DDI_A_LANES) | \
465 BIT_ULL(POWER_DOMAIN_AUX_A) | \
466 BIT_ULL(POWER_DOMAIN_INIT))
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +0200467#define GLK_DPIO_CMN_B_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200468 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
469 BIT_ULL(POWER_DOMAIN_AUX_B) | \
470 BIT_ULL(POWER_DOMAIN_INIT))
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +0200471#define GLK_DPIO_CMN_C_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200472 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
473 BIT_ULL(POWER_DOMAIN_AUX_C) | \
474 BIT_ULL(POWER_DOMAIN_INIT))
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +0200475#define GLK_DISPLAY_AUX_A_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200476 BIT_ULL(POWER_DOMAIN_AUX_A) | \
477 BIT_ULL(POWER_DOMAIN_INIT))
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +0200478#define GLK_DISPLAY_AUX_B_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200479 BIT_ULL(POWER_DOMAIN_AUX_B) | \
480 BIT_ULL(POWER_DOMAIN_INIT))
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +0200481#define GLK_DISPLAY_AUX_C_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200482 BIT_ULL(POWER_DOMAIN_AUX_C) | \
483 BIT_ULL(POWER_DOMAIN_INIT))
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +0200484#define GLK_DISPLAY_DC_OFF_POWER_DOMAINS ( \
485 GLK_DISPLAY_POWERWELL_2_POWER_DOMAINS | \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200486 BIT_ULL(POWER_DOMAIN_MODESET) | \
487 BIT_ULL(POWER_DOMAIN_AUX_A) | \
488 BIT_ULL(POWER_DOMAIN_INIT))
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +0200489
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530490static void assert_can_enable_dc9(struct drm_i915_private *dev_priv)
491{
Imre Deakbfcdabe2016-04-01 16:02:37 +0300492 WARN_ONCE((I915_READ(DC_STATE_EN) & DC_STATE_EN_DC9),
493 "DC9 already programmed to be enabled.\n");
494 WARN_ONCE(I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC5,
495 "DC5 still not disabled to enable DC9.\n");
496 WARN_ONCE(I915_READ(HSW_PWR_WELL_DRIVER), "Power well on.\n");
497 WARN_ONCE(intel_irqs_enabled(dev_priv),
498 "Interrupts not disabled yet.\n");
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530499
500 /*
501 * TODO: check for the following to verify the conditions to enter DC9
502 * state are satisfied:
503 * 1] Check relevant display engine registers to verify if mode set
504 * disable sequence was followed.
505 * 2] Check if display uninitialize sequence is initialized.
506 */
507}
508
509static void assert_can_disable_dc9(struct drm_i915_private *dev_priv)
510{
Imre Deakbfcdabe2016-04-01 16:02:37 +0300511 WARN_ONCE(intel_irqs_enabled(dev_priv),
512 "Interrupts not disabled yet.\n");
513 WARN_ONCE(I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC5,
514 "DC5 still not disabled.\n");
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530515
516 /*
517 * TODO: check for the following to verify DC9 state was indeed
518 * entered before programming to disable it:
519 * 1] Check relevant display engine registers to verify if mode
520 * set disable sequence was followed.
521 * 2] Check if display uninitialize sequence is initialized.
522 */
523}
524
Mika Kuoppala779cb5d2016-02-18 17:58:09 +0200525static void gen9_write_dc_state(struct drm_i915_private *dev_priv,
526 u32 state)
527{
528 int rewrites = 0;
529 int rereads = 0;
530 u32 v;
531
532 I915_WRITE(DC_STATE_EN, state);
533
534 /* It has been observed that disabling the dc6 state sometimes
535 * doesn't stick and dmc keeps returning old value. Make sure
536 * the write really sticks enough times and also force rewrite until
537 * we are confident that state is exactly what we want.
538 */
539 do {
540 v = I915_READ(DC_STATE_EN);
541
542 if (v != state) {
543 I915_WRITE(DC_STATE_EN, state);
544 rewrites++;
545 rereads = 0;
546 } else if (rereads++ > 5) {
547 break;
548 }
549
550 } while (rewrites < 100);
551
552 if (v != state)
553 DRM_ERROR("Writing dc state to 0x%x failed, now 0x%x\n",
554 state, v);
555
556 /* Most of the times we need one retry, avoid spam */
557 if (rewrites > 1)
558 DRM_DEBUG_KMS("Rewrote dc state to 0x%x %d times\n",
559 state, rewrites);
560}
561
Imre Deakda2f41d2016-04-20 20:27:56 +0300562static u32 gen9_dc_mask(struct drm_i915_private *dev_priv)
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530563{
Imre Deakda2f41d2016-04-20 20:27:56 +0300564 u32 mask;
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530565
Imre Deak13ae3a02015-11-04 19:24:16 +0200566 mask = DC_STATE_EN_UPTO_DC5;
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200567 if (IS_GEN9_LP(dev_priv))
Imre Deak13ae3a02015-11-04 19:24:16 +0200568 mask |= DC_STATE_EN_DC9;
569 else
570 mask |= DC_STATE_EN_UPTO_DC6;
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530571
Imre Deakda2f41d2016-04-20 20:27:56 +0300572 return mask;
573}
574
575void gen9_sanitize_dc_state(struct drm_i915_private *dev_priv)
576{
577 u32 val;
578
579 val = I915_READ(DC_STATE_EN) & gen9_dc_mask(dev_priv);
580
581 DRM_DEBUG_KMS("Resetting DC state tracking from %02x to %02x\n",
582 dev_priv->csr.dc_state, val);
583 dev_priv->csr.dc_state = val;
584}
585
586static void gen9_set_dc_state(struct drm_i915_private *dev_priv, uint32_t state)
587{
588 uint32_t val;
589 uint32_t mask;
590
Imre Deaka37baf32016-02-29 22:49:03 +0200591 if (WARN_ON_ONCE(state & ~dev_priv->csr.allowed_dc_mask))
592 state &= dev_priv->csr.allowed_dc_mask;
Patrik Jakobsson443646c2015-11-16 15:01:06 +0100593
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530594 val = I915_READ(DC_STATE_EN);
Imre Deakda2f41d2016-04-20 20:27:56 +0300595 mask = gen9_dc_mask(dev_priv);
Imre Deak13ae3a02015-11-04 19:24:16 +0200596 DRM_DEBUG_KMS("Setting DC state from %02x to %02x\n",
597 val & mask, state);
Patrik Jakobsson832dba82016-02-18 17:21:11 +0200598
599 /* Check if DMC is ignoring our DC state requests */
600 if ((val & mask) != dev_priv->csr.dc_state)
601 DRM_ERROR("DC state mismatch (0x%x -> 0x%x)\n",
602 dev_priv->csr.dc_state, val & mask);
603
Imre Deak13ae3a02015-11-04 19:24:16 +0200604 val &= ~mask;
605 val |= state;
Mika Kuoppala779cb5d2016-02-18 17:58:09 +0200606
607 gen9_write_dc_state(dev_priv, val);
Patrik Jakobsson832dba82016-02-18 17:21:11 +0200608
609 dev_priv->csr.dc_state = val & mask;
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530610}
611
Imre Deak13ae3a02015-11-04 19:24:16 +0200612void bxt_enable_dc9(struct drm_i915_private *dev_priv)
613{
614 assert_can_enable_dc9(dev_priv);
615
616 DRM_DEBUG_KMS("Enabling DC9\n");
617
Imre Deak78597992016-06-16 16:37:20 +0300618 intel_power_sequencer_reset(dev_priv);
Imre Deak13ae3a02015-11-04 19:24:16 +0200619 gen9_set_dc_state(dev_priv, DC_STATE_EN_DC9);
620}
621
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530622void bxt_disable_dc9(struct drm_i915_private *dev_priv)
623{
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530624 assert_can_disable_dc9(dev_priv);
625
626 DRM_DEBUG_KMS("Disabling DC9\n");
627
Imre Deak13ae3a02015-11-04 19:24:16 +0200628 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
Imre Deak8090ba82016-08-10 14:07:33 +0300629
630 intel_pps_unlock_regs_wa(dev_priv);
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530631}
632
Daniel Vetteraf5fead2015-10-28 23:58:57 +0200633static void assert_csr_loaded(struct drm_i915_private *dev_priv)
634{
635 WARN_ONCE(!I915_READ(CSR_PROGRAM(0)),
636 "CSR program storage start is NULL\n");
637 WARN_ONCE(!I915_READ(CSR_SSP_BASE), "CSR SSP Base Not fine\n");
638 WARN_ONCE(!I915_READ(CSR_HTP_SKL), "CSR HTP Not fine\n");
639}
640
Suketu Shah5aefb232015-04-16 14:22:10 +0530641static void assert_can_enable_dc5(struct drm_i915_private *dev_priv)
Suketu Shahdc174302015-04-17 19:46:16 +0530642{
Suketu Shah5aefb232015-04-16 14:22:10 +0530643 bool pg2_enabled = intel_display_power_well_is_enabled(dev_priv,
644 SKL_DISP_PW_2);
645
Jesse Barnes6ff8ab02015-09-10 08:20:28 -0700646 WARN_ONCE(pg2_enabled, "PG2 not disabled to enable DC5.\n");
Suketu Shah5aefb232015-04-16 14:22:10 +0530647
Jesse Barnes6ff8ab02015-09-10 08:20:28 -0700648 WARN_ONCE((I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC5),
649 "DC5 already programmed to be enabled.\n");
Imre Deakc9b88462015-12-15 20:10:34 +0200650 assert_rpm_wakelock_held(dev_priv);
Suketu Shah5aefb232015-04-16 14:22:10 +0530651
652 assert_csr_loaded(dev_priv);
653}
654
Imre Deakf62c79b2016-04-20 20:27:57 +0300655void gen9_enable_dc5(struct drm_i915_private *dev_priv)
Suketu Shah5aefb232015-04-16 14:22:10 +0530656{
Suketu Shah5aefb232015-04-16 14:22:10 +0530657 assert_can_enable_dc5(dev_priv);
A.Sunil Kamath6b457d32015-04-16 14:22:09 +0530658
659 DRM_DEBUG_KMS("Enabling DC5\n");
660
Imre Deak13ae3a02015-11-04 19:24:16 +0200661 gen9_set_dc_state(dev_priv, DC_STATE_EN_UPTO_DC5);
Suketu Shahdc174302015-04-17 19:46:16 +0530662}
663
Suketu Shah93c7cb62015-04-16 14:22:13 +0530664static void assert_can_enable_dc6(struct drm_i915_private *dev_priv)
Suketu Shahf75a1982015-04-16 14:22:11 +0530665{
Jesse Barnes6ff8ab02015-09-10 08:20:28 -0700666 WARN_ONCE(I915_READ(UTIL_PIN_CTL) & UTIL_PIN_ENABLE,
667 "Backlight is not disabled.\n");
668 WARN_ONCE((I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC6),
669 "DC6 already programmed to be enabled.\n");
Suketu Shah93c7cb62015-04-16 14:22:13 +0530670
671 assert_csr_loaded(dev_priv);
672}
673
Animesh Manna0a9d2be2015-09-29 11:01:59 +0530674void skl_enable_dc6(struct drm_i915_private *dev_priv)
Suketu Shah93c7cb62015-04-16 14:22:13 +0530675{
Suketu Shah93c7cb62015-04-16 14:22:13 +0530676 assert_can_enable_dc6(dev_priv);
A.Sunil Kamath74b4f372015-04-16 14:22:12 +0530677
678 DRM_DEBUG_KMS("Enabling DC6\n");
679
Imre Deak13ae3a02015-11-04 19:24:16 +0200680 gen9_set_dc_state(dev_priv, DC_STATE_EN_UPTO_DC6);
681
Suketu Shahf75a1982015-04-16 14:22:11 +0530682}
683
Animesh Manna0a9d2be2015-09-29 11:01:59 +0530684void skl_disable_dc6(struct drm_i915_private *dev_priv)
Suketu Shahf75a1982015-04-16 14:22:11 +0530685{
A.Sunil Kamath74b4f372015-04-16 14:22:12 +0530686 DRM_DEBUG_KMS("Disabling DC6\n");
687
Imre Deak13ae3a02015-11-04 19:24:16 +0200688 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
Suketu Shahf75a1982015-04-16 14:22:11 +0530689}
690
Imre Deakc6782b72016-04-05 13:26:05 +0300691static void
692gen9_sanitize_power_well_requests(struct drm_i915_private *dev_priv,
693 struct i915_power_well *power_well)
694{
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +0300695 enum skl_disp_power_wells power_well_id = power_well->id;
Imre Deakc6782b72016-04-05 13:26:05 +0300696 u32 val;
697 u32 mask;
698
699 mask = SKL_POWER_WELL_REQ(power_well_id);
700
701 val = I915_READ(HSW_PWR_WELL_KVMR);
702 if (WARN_ONCE(val & mask, "Clearing unexpected KVMR request for %s\n",
703 power_well->name))
704 I915_WRITE(HSW_PWR_WELL_KVMR, val & ~mask);
705
706 val = I915_READ(HSW_PWR_WELL_BIOS);
707 val |= I915_READ(HSW_PWR_WELL_DEBUG);
708
709 if (!(val & mask))
710 return;
711
712 /*
713 * DMC is known to force on the request bits for power well 1 on SKL
714 * and BXT and the misc IO power well on SKL but we don't expect any
715 * other request bits to be set, so WARN for those.
716 */
717 if (power_well_id == SKL_DISP_PW_1 ||
Rodrigo Vivib976dc52017-01-23 10:32:37 -0800718 (IS_GEN9_BC(dev_priv) &&
Imre Deak80dbe992016-04-19 13:00:36 +0300719 power_well_id == SKL_DISP_PW_MISC_IO))
Imre Deakc6782b72016-04-05 13:26:05 +0300720 DRM_DEBUG_DRIVER("Clearing auxiliary requests for %s forced on "
721 "by DMC\n", power_well->name);
722 else
723 WARN_ONCE(1, "Clearing unexpected auxiliary requests for %s\n",
724 power_well->name);
725
726 I915_WRITE(HSW_PWR_WELL_BIOS, val & ~mask);
727 I915_WRITE(HSW_PWR_WELL_DEBUG, val & ~mask);
728}
729
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000730static void skl_set_power_well(struct drm_i915_private *dev_priv,
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +0200731 struct i915_power_well *power_well, bool enable)
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000732{
733 uint32_t tmp, fuse_status;
734 uint32_t req_mask, state_mask;
Damien Lespiau2a518352015-03-06 18:50:49 +0000735 bool is_enabled, enable_requested, check_fuse_status = false;
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000736
737 tmp = I915_READ(HSW_PWR_WELL_DRIVER);
738 fuse_status = I915_READ(SKL_FUSE_STATUS);
739
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +0300740 switch (power_well->id) {
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000741 case SKL_DISP_PW_1:
Chris Wilson117c1142016-06-30 15:33:33 +0100742 if (intel_wait_for_register(dev_priv,
743 SKL_FUSE_STATUS,
744 SKL_FUSE_PG0_DIST_STATUS,
745 SKL_FUSE_PG0_DIST_STATUS,
746 1)) {
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000747 DRM_ERROR("PG0 not enabled\n");
748 return;
749 }
750 break;
751 case SKL_DISP_PW_2:
752 if (!(fuse_status & SKL_FUSE_PG1_DIST_STATUS)) {
753 DRM_ERROR("PG1 in disabled state\n");
754 return;
755 }
756 break;
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +0200757 case SKL_DISP_PW_MISC_IO:
758 case SKL_DISP_PW_DDI_A_E: /* GLK_DISP_PW_DDI_A */
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000759 case SKL_DISP_PW_DDI_B:
760 case SKL_DISP_PW_DDI_C:
761 case SKL_DISP_PW_DDI_D:
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +0200762 case GLK_DISP_PW_AUX_A:
763 case GLK_DISP_PW_AUX_B:
764 case GLK_DISP_PW_AUX_C:
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000765 break;
766 default:
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +0300767 WARN(1, "Unknown power well %lu\n", power_well->id);
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000768 return;
769 }
770
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +0300771 req_mask = SKL_POWER_WELL_REQ(power_well->id);
Damien Lespiau2a518352015-03-06 18:50:49 +0000772 enable_requested = tmp & req_mask;
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +0300773 state_mask = SKL_POWER_WELL_STATE(power_well->id);
Damien Lespiau2a518352015-03-06 18:50:49 +0000774 is_enabled = tmp & state_mask;
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000775
Ville Syrjäläaae8ba82016-02-19 20:47:30 +0200776 if (!enable && enable_requested)
777 skl_power_well_pre_disable(dev_priv, power_well);
778
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000779 if (enable) {
Damien Lespiau2a518352015-03-06 18:50:49 +0000780 if (!enable_requested) {
Suketu Shahdc174302015-04-17 19:46:16 +0530781 WARN((tmp & state_mask) &&
782 !I915_READ(HSW_PWR_WELL_BIOS),
783 "Invalid for power well status to be enabled, unless done by the BIOS, \
784 when request is to disable!\n");
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000785 I915_WRITE(HSW_PWR_WELL_DRIVER, tmp | req_mask);
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000786 }
787
Damien Lespiau2a518352015-03-06 18:50:49 +0000788 if (!is_enabled) {
Damien Lespiau510e6fd2015-03-06 18:50:50 +0000789 DRM_DEBUG_KMS("Enabling %s\n", power_well->name);
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000790 check_fuse_status = true;
791 }
792 } else {
Damien Lespiau2a518352015-03-06 18:50:49 +0000793 if (enable_requested) {
Imre Deak4a76f292015-11-04 19:24:15 +0200794 I915_WRITE(HSW_PWR_WELL_DRIVER, tmp & ~req_mask);
795 POSTING_READ(HSW_PWR_WELL_DRIVER);
796 DRM_DEBUG_KMS("Disabling %s\n", power_well->name);
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000797 }
Imre Deakc6782b72016-04-05 13:26:05 +0300798
Imre Deak5f304c82016-04-15 22:32:58 +0300799 if (IS_GEN9(dev_priv))
Imre Deakc6782b72016-04-05 13:26:05 +0300800 gen9_sanitize_power_well_requests(dev_priv, power_well);
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000801 }
802
Imre Deak1d963af2016-04-01 16:02:36 +0300803 if (wait_for(!!(I915_READ(HSW_PWR_WELL_DRIVER) & state_mask) == enable,
804 1))
805 DRM_ERROR("%s %s timeout\n",
806 power_well->name, enable ? "enable" : "disable");
807
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000808 if (check_fuse_status) {
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +0300809 if (power_well->id == SKL_DISP_PW_1) {
Chris Wilson8b00f552016-06-30 15:33:34 +0100810 if (intel_wait_for_register(dev_priv,
811 SKL_FUSE_STATUS,
812 SKL_FUSE_PG1_DIST_STATUS,
813 SKL_FUSE_PG1_DIST_STATUS,
814 1))
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000815 DRM_ERROR("PG1 distributing status timeout\n");
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +0300816 } else if (power_well->id == SKL_DISP_PW_2) {
Chris Wilson8b00f552016-06-30 15:33:34 +0100817 if (intel_wait_for_register(dev_priv,
818 SKL_FUSE_STATUS,
819 SKL_FUSE_PG2_DIST_STATUS,
820 SKL_FUSE_PG2_DIST_STATUS,
821 1))
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000822 DRM_ERROR("PG2 distributing status timeout\n");
823 }
824 }
Damien Lespiaud14c0342015-03-06 18:50:51 +0000825
826 if (enable && !is_enabled)
827 skl_power_well_post_enable(dev_priv, power_well);
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000828}
829
Daniel Vetter9c065a72014-09-30 10:56:38 +0200830static void hsw_power_well_sync_hw(struct drm_i915_private *dev_priv,
831 struct i915_power_well *power_well)
832{
Imre Deak16e84912017-02-17 17:39:45 +0200833 /* Take over the request bit if set by BIOS. */
834 if (I915_READ(HSW_PWR_WELL_BIOS) & HSW_PWR_WELL_ENABLE_REQUEST) {
835 if (!(I915_READ(HSW_PWR_WELL_DRIVER) &
836 HSW_PWR_WELL_ENABLE_REQUEST))
837 I915_WRITE(HSW_PWR_WELL_DRIVER,
838 HSW_PWR_WELL_ENABLE_REQUEST);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200839 I915_WRITE(HSW_PWR_WELL_BIOS, 0);
Imre Deak16e84912017-02-17 17:39:45 +0200840 }
Daniel Vetter9c065a72014-09-30 10:56:38 +0200841}
842
843static void hsw_power_well_enable(struct drm_i915_private *dev_priv,
844 struct i915_power_well *power_well)
845{
846 hsw_set_power_well(dev_priv, power_well, true);
847}
848
849static void hsw_power_well_disable(struct drm_i915_private *dev_priv,
850 struct i915_power_well *power_well)
851{
852 hsw_set_power_well(dev_priv, power_well, false);
853}
854
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000855static bool skl_power_well_enabled(struct drm_i915_private *dev_priv,
856 struct i915_power_well *power_well)
857{
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +0300858 uint32_t mask = SKL_POWER_WELL_REQ(power_well->id) |
859 SKL_POWER_WELL_STATE(power_well->id);
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000860
861 return (I915_READ(HSW_PWR_WELL_DRIVER) & mask) == mask;
862}
863
864static void skl_power_well_sync_hw(struct drm_i915_private *dev_priv,
865 struct i915_power_well *power_well)
866{
Imre Deak14544e12017-02-17 17:39:44 +0200867 uint32_t mask = SKL_POWER_WELL_REQ(power_well->id);
868 uint32_t bios_req = I915_READ(HSW_PWR_WELL_BIOS);
869
Imre Deak16e84912017-02-17 17:39:45 +0200870 /* Take over the request bit if set by BIOS. */
Imre Deak14544e12017-02-17 17:39:44 +0200871 if (bios_req & mask) {
Imre Deak16e84912017-02-17 17:39:45 +0200872 uint32_t drv_req = I915_READ(HSW_PWR_WELL_DRIVER);
873
874 if (!(drv_req & mask))
875 I915_WRITE(HSW_PWR_WELL_DRIVER, drv_req | mask);
Imre Deak14544e12017-02-17 17:39:44 +0200876 I915_WRITE(HSW_PWR_WELL_BIOS, bios_req & ~mask);
877 }
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000878}
879
880static void skl_power_well_enable(struct drm_i915_private *dev_priv,
881 struct i915_power_well *power_well)
882{
883 skl_set_power_well(dev_priv, power_well, true);
884}
885
886static void skl_power_well_disable(struct drm_i915_private *dev_priv,
887 struct i915_power_well *power_well)
888{
889 skl_set_power_well(dev_priv, power_well, false);
890}
891
Imre Deak9c8d0b82016-06-13 16:44:34 +0300892static void bxt_dpio_cmn_power_well_enable(struct drm_i915_private *dev_priv,
893 struct i915_power_well *power_well)
894{
Ander Conselvan de Oliveira362624c2016-10-06 19:22:15 +0300895 bxt_ddi_phy_init(dev_priv, power_well->data);
Imre Deak9c8d0b82016-06-13 16:44:34 +0300896}
897
898static void bxt_dpio_cmn_power_well_disable(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_uninit(dev_priv, power_well->data);
Imre Deak9c8d0b82016-06-13 16:44:34 +0300902}
903
904static bool bxt_dpio_cmn_power_well_enabled(struct drm_i915_private *dev_priv,
905 struct i915_power_well *power_well)
906{
Ander Conselvan de Oliveira362624c2016-10-06 19:22:15 +0300907 return bxt_ddi_phy_is_enabled(dev_priv, power_well->data);
Imre Deak9c8d0b82016-06-13 16:44:34 +0300908}
909
Imre Deak9c8d0b82016-06-13 16:44:34 +0300910static void bxt_verify_ddi_phy_power_wells(struct drm_i915_private *dev_priv)
911{
912 struct i915_power_well *power_well;
913
914 power_well = lookup_power_well(dev_priv, BXT_DPIO_CMN_A);
915 if (power_well->count > 0)
Ander Conselvan de Oliveira362624c2016-10-06 19:22:15 +0300916 bxt_ddi_phy_verify_state(dev_priv, power_well->data);
Imre Deak9c8d0b82016-06-13 16:44:34 +0300917
918 power_well = lookup_power_well(dev_priv, BXT_DPIO_CMN_BC);
919 if (power_well->count > 0)
Ander Conselvan de Oliveira362624c2016-10-06 19:22:15 +0300920 bxt_ddi_phy_verify_state(dev_priv, power_well->data);
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +0200921
922 if (IS_GEMINILAKE(dev_priv)) {
923 power_well = lookup_power_well(dev_priv, GLK_DPIO_CMN_C);
924 if (power_well->count > 0)
925 bxt_ddi_phy_verify_state(dev_priv, power_well->data);
926 }
Imre Deak9c8d0b82016-06-13 16:44:34 +0300927}
928
Patrik Jakobsson9f836f92015-11-16 16:20:01 +0100929static bool gen9_dc_off_power_well_enabled(struct drm_i915_private *dev_priv,
930 struct i915_power_well *power_well)
931{
932 return (I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC5_DC6_MASK) == 0;
933}
934
Ville Syrjälä18a80672016-05-16 16:59:40 +0300935static void gen9_assert_dbuf_enabled(struct drm_i915_private *dev_priv)
936{
937 u32 tmp = I915_READ(DBUF_CTL);
938
939 WARN((tmp & (DBUF_POWER_STATE | DBUF_POWER_REQUEST)) !=
940 (DBUF_POWER_STATE | DBUF_POWER_REQUEST),
941 "Unexpected DBuf power power state (0x%08x)\n", tmp);
942}
943
Patrik Jakobsson9f836f92015-11-16 16:20:01 +0100944static void gen9_dc_off_power_well_enable(struct drm_i915_private *dev_priv,
945 struct i915_power_well *power_well)
946{
Ville Syrjälä49cd97a2017-02-07 20:33:45 +0200947 struct intel_cdclk_state cdclk_state = {};
948
Imre Deak5b773eb2016-02-29 22:49:05 +0200949 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
Imre Deakadc7f042016-04-04 17:27:10 +0300950
Ville Syrjälä49cd97a2017-02-07 20:33:45 +0200951 dev_priv->display.get_cdclk(dev_priv, &cdclk_state);
952 WARN_ON(!intel_cdclk_state_compare(&dev_priv->cdclk.hw, &cdclk_state));
Ville Syrjälä342be922016-05-13 23:41:39 +0300953
Ville Syrjälä18a80672016-05-16 16:59:40 +0300954 gen9_assert_dbuf_enabled(dev_priv);
955
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200956 if (IS_GEN9_LP(dev_priv))
Imre Deak9c8d0b82016-06-13 16:44:34 +0300957 bxt_verify_ddi_phy_power_wells(dev_priv);
Patrik Jakobsson9f836f92015-11-16 16:20:01 +0100958}
959
960static void gen9_dc_off_power_well_disable(struct drm_i915_private *dev_priv,
961 struct i915_power_well *power_well)
962{
Imre Deakf74ed082016-04-18 14:48:21 +0300963 if (!dev_priv->csr.dmc_payload)
964 return;
965
Imre Deaka37baf32016-02-29 22:49:03 +0200966 if (dev_priv->csr.allowed_dc_mask & DC_STATE_EN_UPTO_DC6)
Patrik Jakobsson9f836f92015-11-16 16:20:01 +0100967 skl_enable_dc6(dev_priv);
Imre Deaka37baf32016-02-29 22:49:03 +0200968 else if (dev_priv->csr.allowed_dc_mask & DC_STATE_EN_UPTO_DC5)
Patrik Jakobsson9f836f92015-11-16 16:20:01 +0100969 gen9_enable_dc5(dev_priv);
970}
971
Imre Deak3c1b38e2017-02-17 17:39:42 +0200972static void i9xx_power_well_sync_hw_noop(struct drm_i915_private *dev_priv,
973 struct i915_power_well *power_well)
Patrik Jakobsson9f836f92015-11-16 16:20:01 +0100974{
Patrik Jakobsson9f836f92015-11-16 16:20:01 +0100975}
976
Daniel Vetter9c065a72014-09-30 10:56:38 +0200977static void i9xx_always_on_power_well_noop(struct drm_i915_private *dev_priv,
978 struct i915_power_well *power_well)
979{
980}
981
982static bool i9xx_always_on_power_well_enabled(struct drm_i915_private *dev_priv,
983 struct i915_power_well *power_well)
984{
985 return true;
986}
987
988static void vlv_set_power_well(struct drm_i915_private *dev_priv,
989 struct i915_power_well *power_well, bool enable)
990{
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +0300991 enum punit_power_well power_well_id = power_well->id;
Daniel Vetter9c065a72014-09-30 10:56:38 +0200992 u32 mask;
993 u32 state;
994 u32 ctrl;
995
996 mask = PUNIT_PWRGT_MASK(power_well_id);
997 state = enable ? PUNIT_PWRGT_PWR_ON(power_well_id) :
998 PUNIT_PWRGT_PWR_GATE(power_well_id);
999
1000 mutex_lock(&dev_priv->rps.hw_lock);
1001
1002#define COND \
1003 ((vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_STATUS) & mask) == state)
1004
1005 if (COND)
1006 goto out;
1007
1008 ctrl = vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_CTRL);
1009 ctrl &= ~mask;
1010 ctrl |= state;
1011 vlv_punit_write(dev_priv, PUNIT_REG_PWRGT_CTRL, ctrl);
1012
1013 if (wait_for(COND, 100))
Masanari Iida7e35ab82015-05-10 01:00:23 +09001014 DRM_ERROR("timeout setting power well state %08x (%08x)\n",
Daniel Vetter9c065a72014-09-30 10:56:38 +02001015 state,
1016 vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_CTRL));
1017
1018#undef COND
1019
1020out:
1021 mutex_unlock(&dev_priv->rps.hw_lock);
1022}
1023
Daniel Vetter9c065a72014-09-30 10:56:38 +02001024static void vlv_power_well_enable(struct drm_i915_private *dev_priv,
1025 struct i915_power_well *power_well)
1026{
1027 vlv_set_power_well(dev_priv, power_well, true);
1028}
1029
1030static void vlv_power_well_disable(struct drm_i915_private *dev_priv,
1031 struct i915_power_well *power_well)
1032{
1033 vlv_set_power_well(dev_priv, power_well, false);
1034}
1035
1036static bool vlv_power_well_enabled(struct drm_i915_private *dev_priv,
1037 struct i915_power_well *power_well)
1038{
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001039 int power_well_id = power_well->id;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001040 bool enabled = false;
1041 u32 mask;
1042 u32 state;
1043 u32 ctrl;
1044
1045 mask = PUNIT_PWRGT_MASK(power_well_id);
1046 ctrl = PUNIT_PWRGT_PWR_ON(power_well_id);
1047
1048 mutex_lock(&dev_priv->rps.hw_lock);
1049
1050 state = vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_STATUS) & mask;
1051 /*
1052 * We only ever set the power-on and power-gate states, anything
1053 * else is unexpected.
1054 */
1055 WARN_ON(state != PUNIT_PWRGT_PWR_ON(power_well_id) &&
1056 state != PUNIT_PWRGT_PWR_GATE(power_well_id));
1057 if (state == ctrl)
1058 enabled = true;
1059
1060 /*
1061 * A transient state at this point would mean some unexpected party
1062 * is poking at the power controls too.
1063 */
1064 ctrl = vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_CTRL) & mask;
1065 WARN_ON(ctrl != state);
1066
1067 mutex_unlock(&dev_priv->rps.hw_lock);
1068
1069 return enabled;
1070}
1071
Ville Syrjälä766078d2016-04-11 16:56:30 +03001072static void vlv_init_display_clock_gating(struct drm_i915_private *dev_priv)
1073{
Hans de Goede721d4842016-12-02 15:29:04 +01001074 u32 val;
1075
1076 /*
1077 * On driver load, a pipe may be active and driving a DSI display.
1078 * Preserve DPOUNIT_CLOCK_GATE_DISABLE to avoid the pipe getting stuck
1079 * (and never recovering) in this case. intel_dsi_post_disable() will
1080 * clear it when we turn off the display.
1081 */
1082 val = I915_READ(DSPCLK_GATE_D);
1083 val &= DPOUNIT_CLOCK_GATE_DISABLE;
1084 val |= VRHUNIT_CLOCK_GATE_DISABLE;
1085 I915_WRITE(DSPCLK_GATE_D, val);
Ville Syrjälä766078d2016-04-11 16:56:30 +03001086
1087 /*
1088 * Disable trickle feed and enable pnd deadline calculation
1089 */
1090 I915_WRITE(MI_ARB_VLV, MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE);
1091 I915_WRITE(CBR1_VLV, 0);
Ville Syrjälä19ab4ed2016-04-27 17:43:22 +03001092
1093 WARN_ON(dev_priv->rawclk_freq == 0);
1094
1095 I915_WRITE(RAWCLK_FREQ_VLV,
1096 DIV_ROUND_CLOSEST(dev_priv->rawclk_freq, 1000));
Ville Syrjälä766078d2016-04-11 16:56:30 +03001097}
1098
Ville Syrjälä2be7d542015-06-29 15:25:51 +03001099static void vlv_display_power_well_init(struct drm_i915_private *dev_priv)
Daniel Vetter9c065a72014-09-30 10:56:38 +02001100{
Lyude9504a892016-06-21 17:03:42 -04001101 struct intel_encoder *encoder;
Ville Syrjälä5a8fbb72015-06-29 15:25:53 +03001102 enum pipe pipe;
1103
1104 /*
1105 * Enable the CRI clock source so we can get at the
1106 * display and the reference clock for VGA
1107 * hotplug / manual detection. Supposedly DSI also
1108 * needs the ref clock up and running.
1109 *
1110 * CHV DPLL B/C have some issues if VGA mode is enabled.
1111 */
Tvrtko Ursulin801388c2016-11-16 08:55:44 +00001112 for_each_pipe(dev_priv, pipe) {
Ville Syrjälä5a8fbb72015-06-29 15:25:53 +03001113 u32 val = I915_READ(DPLL(pipe));
1114
1115 val |= DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
1116 if (pipe != PIPE_A)
1117 val |= DPLL_INTEGRATED_CRI_CLK_VLV;
1118
1119 I915_WRITE(DPLL(pipe), val);
1120 }
Daniel Vetter9c065a72014-09-30 10:56:38 +02001121
Ville Syrjälä766078d2016-04-11 16:56:30 +03001122 vlv_init_display_clock_gating(dev_priv);
1123
Daniel Vetter9c065a72014-09-30 10:56:38 +02001124 spin_lock_irq(&dev_priv->irq_lock);
1125 valleyview_enable_display_irqs(dev_priv);
1126 spin_unlock_irq(&dev_priv->irq_lock);
1127
1128 /*
1129 * During driver initialization/resume we can avoid restoring the
1130 * part of the HW/SW state that will be inited anyway explicitly.
1131 */
1132 if (dev_priv->power_domains.initializing)
1133 return;
1134
Daniel Vetterb9632912014-09-30 10:56:44 +02001135 intel_hpd_init(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001136
Lyude9504a892016-06-21 17:03:42 -04001137 /* Re-enable the ADPA, if we have one */
1138 for_each_intel_encoder(&dev_priv->drm, encoder) {
1139 if (encoder->type == INTEL_OUTPUT_ANALOG)
1140 intel_crt_reset(&encoder->base);
1141 }
1142
Tvrtko Ursulin29b74b72016-11-16 08:55:39 +00001143 i915_redisable_vga_power_on(dev_priv);
Imre Deak8090ba82016-08-10 14:07:33 +03001144
1145 intel_pps_unlock_regs_wa(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001146}
1147
Ville Syrjälä2be7d542015-06-29 15:25:51 +03001148static void vlv_display_power_well_deinit(struct drm_i915_private *dev_priv)
1149{
1150 spin_lock_irq(&dev_priv->irq_lock);
1151 valleyview_disable_display_irqs(dev_priv);
1152 spin_unlock_irq(&dev_priv->irq_lock);
1153
Ville Syrjälä2230fde2016-02-19 18:41:52 +02001154 /* make sure we're done processing display irqs */
Chris Wilson91c8a322016-07-05 10:40:23 +01001155 synchronize_irq(dev_priv->drm.irq);
Ville Syrjälä2230fde2016-02-19 18:41:52 +02001156
Imre Deak78597992016-06-16 16:37:20 +03001157 intel_power_sequencer_reset(dev_priv);
Lyude19625e82016-06-21 17:03:44 -04001158
Lyudeb64b5402016-10-26 12:36:09 -04001159 /* Prevent us from re-enabling polling on accident in late suspend */
1160 if (!dev_priv->drm.dev->power.is_suspended)
1161 intel_hpd_poll_init(dev_priv);
Ville Syrjälä2be7d542015-06-29 15:25:51 +03001162}
1163
1164static void vlv_display_power_well_enable(struct drm_i915_private *dev_priv,
1165 struct i915_power_well *power_well)
1166{
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001167 WARN_ON_ONCE(power_well->id != PUNIT_POWER_WELL_DISP2D);
Ville Syrjälä2be7d542015-06-29 15:25:51 +03001168
1169 vlv_set_power_well(dev_priv, power_well, true);
1170
1171 vlv_display_power_well_init(dev_priv);
1172}
1173
Daniel Vetter9c065a72014-09-30 10:56:38 +02001174static void vlv_display_power_well_disable(struct drm_i915_private *dev_priv,
1175 struct i915_power_well *power_well)
1176{
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001177 WARN_ON_ONCE(power_well->id != PUNIT_POWER_WELL_DISP2D);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001178
Ville Syrjälä2be7d542015-06-29 15:25:51 +03001179 vlv_display_power_well_deinit(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001180
1181 vlv_set_power_well(dev_priv, power_well, false);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001182}
1183
1184static void vlv_dpio_cmn_power_well_enable(struct drm_i915_private *dev_priv,
1185 struct i915_power_well *power_well)
1186{
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001187 WARN_ON_ONCE(power_well->id != PUNIT_POWER_WELL_DPIO_CMN_BC);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001188
Ville Syrjälä5a8fbb72015-06-29 15:25:53 +03001189 /* since ref/cri clock was enabled */
Daniel Vetter9c065a72014-09-30 10:56:38 +02001190 udelay(1); /* >10ns for cmnreset, >0ns for sidereset */
1191
1192 vlv_set_power_well(dev_priv, power_well, true);
1193
1194 /*
1195 * From VLV2A0_DP_eDP_DPIO_driver_vbios_notes_10.docx -
1196 * 6. De-assert cmn_reset/side_reset. Same as VLV X0.
1197 * a. GUnit 0x2110 bit[0] set to 1 (def 0)
1198 * b. The other bits such as sfr settings / modesel may all
1199 * be set to 0.
1200 *
1201 * This should only be done on init and resume from S3 with
1202 * both PLLs disabled, or we risk losing DPIO and PLL
1203 * synchronization.
1204 */
1205 I915_WRITE(DPIO_CTL, I915_READ(DPIO_CTL) | DPIO_CMNRST);
1206}
1207
1208static void vlv_dpio_cmn_power_well_disable(struct drm_i915_private *dev_priv,
1209 struct i915_power_well *power_well)
1210{
1211 enum pipe pipe;
1212
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001213 WARN_ON_ONCE(power_well->id != PUNIT_POWER_WELL_DPIO_CMN_BC);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001214
1215 for_each_pipe(dev_priv, pipe)
1216 assert_pll_disabled(dev_priv, pipe);
1217
1218 /* Assert common reset */
1219 I915_WRITE(DPIO_CTL, I915_READ(DPIO_CTL) & ~DPIO_CMNRST);
1220
1221 vlv_set_power_well(dev_priv, power_well, false);
1222}
1223
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001224#define POWER_DOMAIN_MASK (GENMASK_ULL(POWER_DOMAIN_NUM - 1, 0))
Ville Syrjälä30142272015-07-08 23:46:01 +03001225
1226static struct i915_power_well *lookup_power_well(struct drm_i915_private *dev_priv,
1227 int power_well_id)
1228{
1229 struct i915_power_domains *power_domains = &dev_priv->power_domains;
Ville Syrjälä30142272015-07-08 23:46:01 +03001230 int i;
1231
Imre Deakfc17f222015-11-04 19:24:11 +02001232 for (i = 0; i < power_domains->power_well_count; i++) {
1233 struct i915_power_well *power_well;
1234
1235 power_well = &power_domains->power_wells[i];
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001236 if (power_well->id == power_well_id)
Ville Syrjälä30142272015-07-08 23:46:01 +03001237 return power_well;
1238 }
1239
1240 return NULL;
1241}
1242
1243#define BITS_SET(val, bits) (((val) & (bits)) == (bits))
1244
1245static void assert_chv_phy_status(struct drm_i915_private *dev_priv)
1246{
1247 struct i915_power_well *cmn_bc =
1248 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_BC);
1249 struct i915_power_well *cmn_d =
1250 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_D);
1251 u32 phy_control = dev_priv->chv_phy_control;
1252 u32 phy_status = 0;
Ville Syrjälä3be60de2015-09-08 18:05:45 +03001253 u32 phy_status_mask = 0xffffffff;
Ville Syrjälä30142272015-07-08 23:46:01 +03001254
Ville Syrjälä3be60de2015-09-08 18:05:45 +03001255 /*
1256 * The BIOS can leave the PHY is some weird state
1257 * where it doesn't fully power down some parts.
1258 * Disable the asserts until the PHY has been fully
1259 * reset (ie. the power well has been disabled at
1260 * least once).
1261 */
1262 if (!dev_priv->chv_phy_assert[DPIO_PHY0])
1263 phy_status_mask &= ~(PHY_STATUS_CMN_LDO(DPIO_PHY0, DPIO_CH0) |
1264 PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH0, 0) |
1265 PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH0, 1) |
1266 PHY_STATUS_CMN_LDO(DPIO_PHY0, DPIO_CH1) |
1267 PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH1, 0) |
1268 PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH1, 1));
1269
1270 if (!dev_priv->chv_phy_assert[DPIO_PHY1])
1271 phy_status_mask &= ~(PHY_STATUS_CMN_LDO(DPIO_PHY1, DPIO_CH0) |
1272 PHY_STATUS_SPLINE_LDO(DPIO_PHY1, DPIO_CH0, 0) |
1273 PHY_STATUS_SPLINE_LDO(DPIO_PHY1, DPIO_CH0, 1));
1274
Ville Syrjälä30142272015-07-08 23:46:01 +03001275 if (cmn_bc->ops->is_enabled(dev_priv, cmn_bc)) {
1276 phy_status |= PHY_POWERGOOD(DPIO_PHY0);
1277
1278 /* this assumes override is only used to enable lanes */
1279 if ((phy_control & PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY0, DPIO_CH0)) == 0)
1280 phy_control |= PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH0);
1281
1282 if ((phy_control & PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY0, DPIO_CH1)) == 0)
1283 phy_control |= PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH1);
1284
1285 /* CL1 is on whenever anything is on in either channel */
1286 if (BITS_SET(phy_control,
1287 PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH0) |
1288 PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH1)))
1289 phy_status |= PHY_STATUS_CMN_LDO(DPIO_PHY0, DPIO_CH0);
1290
1291 /*
1292 * The DPLLB check accounts for the pipe B + port A usage
1293 * with CL2 powered up but all the lanes in the second channel
1294 * powered down.
1295 */
1296 if (BITS_SET(phy_control,
1297 PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH1)) &&
1298 (I915_READ(DPLL(PIPE_B)) & DPLL_VCO_ENABLE) == 0)
1299 phy_status |= PHY_STATUS_CMN_LDO(DPIO_PHY0, DPIO_CH1);
1300
1301 if (BITS_SET(phy_control,
1302 PHY_CH_POWER_DOWN_OVRD(0x3, DPIO_PHY0, DPIO_CH0)))
1303 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH0, 0);
1304 if (BITS_SET(phy_control,
1305 PHY_CH_POWER_DOWN_OVRD(0xc, DPIO_PHY0, DPIO_CH0)))
1306 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH0, 1);
1307
1308 if (BITS_SET(phy_control,
1309 PHY_CH_POWER_DOWN_OVRD(0x3, DPIO_PHY0, DPIO_CH1)))
1310 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH1, 0);
1311 if (BITS_SET(phy_control,
1312 PHY_CH_POWER_DOWN_OVRD(0xc, DPIO_PHY0, DPIO_CH1)))
1313 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH1, 1);
1314 }
1315
1316 if (cmn_d->ops->is_enabled(dev_priv, cmn_d)) {
1317 phy_status |= PHY_POWERGOOD(DPIO_PHY1);
1318
1319 /* this assumes override is only used to enable lanes */
1320 if ((phy_control & PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY1, DPIO_CH0)) == 0)
1321 phy_control |= PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY1, DPIO_CH0);
1322
1323 if (BITS_SET(phy_control,
1324 PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY1, DPIO_CH0)))
1325 phy_status |= PHY_STATUS_CMN_LDO(DPIO_PHY1, DPIO_CH0);
1326
1327 if (BITS_SET(phy_control,
1328 PHY_CH_POWER_DOWN_OVRD(0x3, DPIO_PHY1, DPIO_CH0)))
1329 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY1, DPIO_CH0, 0);
1330 if (BITS_SET(phy_control,
1331 PHY_CH_POWER_DOWN_OVRD(0xc, DPIO_PHY1, DPIO_CH0)))
1332 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY1, DPIO_CH0, 1);
1333 }
1334
Ville Syrjälä3be60de2015-09-08 18:05:45 +03001335 phy_status &= phy_status_mask;
1336
Ville Syrjälä30142272015-07-08 23:46:01 +03001337 /*
1338 * The PHY may be busy with some initial calibration and whatnot,
1339 * so the power state can take a while to actually change.
1340 */
Chris Wilson919fcd52016-06-30 15:33:35 +01001341 if (intel_wait_for_register(dev_priv,
1342 DISPLAY_PHY_STATUS,
1343 phy_status_mask,
1344 phy_status,
1345 10))
1346 DRM_ERROR("Unexpected PHY_STATUS 0x%08x, expected 0x%08x (PHY_CONTROL=0x%08x)\n",
1347 I915_READ(DISPLAY_PHY_STATUS) & phy_status_mask,
1348 phy_status, dev_priv->chv_phy_control);
Ville Syrjälä30142272015-07-08 23:46:01 +03001349}
1350
1351#undef BITS_SET
1352
Daniel Vetter9c065a72014-09-30 10:56:38 +02001353static void chv_dpio_cmn_power_well_enable(struct drm_i915_private *dev_priv,
1354 struct i915_power_well *power_well)
1355{
1356 enum dpio_phy phy;
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001357 enum pipe pipe;
1358 uint32_t tmp;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001359
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001360 WARN_ON_ONCE(power_well->id != PUNIT_POWER_WELL_DPIO_CMN_BC &&
1361 power_well->id != PUNIT_POWER_WELL_DPIO_CMN_D);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001362
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001363 if (power_well->id == PUNIT_POWER_WELL_DPIO_CMN_BC) {
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001364 pipe = PIPE_A;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001365 phy = DPIO_PHY0;
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001366 } else {
1367 pipe = PIPE_C;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001368 phy = DPIO_PHY1;
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001369 }
Ville Syrjälä5a8fbb72015-06-29 15:25:53 +03001370
1371 /* since ref/cri clock was enabled */
Daniel Vetter9c065a72014-09-30 10:56:38 +02001372 udelay(1); /* >10ns for cmnreset, >0ns for sidereset */
1373 vlv_set_power_well(dev_priv, power_well, true);
1374
1375 /* Poll for phypwrgood signal */
Chris Wilsonffebb832016-06-30 15:33:36 +01001376 if (intel_wait_for_register(dev_priv,
1377 DISPLAY_PHY_STATUS,
1378 PHY_POWERGOOD(phy),
1379 PHY_POWERGOOD(phy),
1380 1))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001381 DRM_ERROR("Display PHY %d is not power up\n", phy);
1382
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001383 mutex_lock(&dev_priv->sb_lock);
1384
1385 /* Enable dynamic power down */
1386 tmp = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW28);
Ville Syrjäläee279212015-07-08 23:45:57 +03001387 tmp |= DPIO_DYNPWRDOWNEN_CH0 | DPIO_CL1POWERDOWNEN |
1388 DPIO_SUS_CLK_CONFIG_GATE_CLKREQ;
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001389 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW28, tmp);
1390
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001391 if (power_well->id == PUNIT_POWER_WELL_DPIO_CMN_BC) {
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001392 tmp = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW6_CH1);
1393 tmp |= DPIO_DYNPWRDOWNEN_CH1;
1394 vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW6_CH1, tmp);
Ville Syrjälä3e288782015-07-08 23:45:58 +03001395 } else {
1396 /*
1397 * Force the non-existing CL2 off. BXT does this
1398 * too, so maybe it saves some power even though
1399 * CL2 doesn't exist?
1400 */
1401 tmp = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW30);
1402 tmp |= DPIO_CL2_LDOFUSE_PWRENB;
1403 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW30, tmp);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001404 }
1405
1406 mutex_unlock(&dev_priv->sb_lock);
1407
Ville Syrjälä70722462015-04-10 18:21:28 +03001408 dev_priv->chv_phy_control |= PHY_COM_LANE_RESET_DEASSERT(phy);
1409 I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001410
1411 DRM_DEBUG_KMS("Enabled DPIO PHY%d (PHY_CONTROL=0x%08x)\n",
1412 phy, dev_priv->chv_phy_control);
Ville Syrjälä30142272015-07-08 23:46:01 +03001413
1414 assert_chv_phy_status(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001415}
1416
1417static void chv_dpio_cmn_power_well_disable(struct drm_i915_private *dev_priv,
1418 struct i915_power_well *power_well)
1419{
1420 enum dpio_phy phy;
1421
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001422 WARN_ON_ONCE(power_well->id != PUNIT_POWER_WELL_DPIO_CMN_BC &&
1423 power_well->id != PUNIT_POWER_WELL_DPIO_CMN_D);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001424
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001425 if (power_well->id == PUNIT_POWER_WELL_DPIO_CMN_BC) {
Daniel Vetter9c065a72014-09-30 10:56:38 +02001426 phy = DPIO_PHY0;
1427 assert_pll_disabled(dev_priv, PIPE_A);
1428 assert_pll_disabled(dev_priv, PIPE_B);
1429 } else {
1430 phy = DPIO_PHY1;
1431 assert_pll_disabled(dev_priv, PIPE_C);
1432 }
1433
Ville Syrjälä70722462015-04-10 18:21:28 +03001434 dev_priv->chv_phy_control &= ~PHY_COM_LANE_RESET_DEASSERT(phy);
1435 I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001436
1437 vlv_set_power_well(dev_priv, power_well, false);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001438
1439 DRM_DEBUG_KMS("Disabled DPIO PHY%d (PHY_CONTROL=0x%08x)\n",
1440 phy, dev_priv->chv_phy_control);
Ville Syrjälä30142272015-07-08 23:46:01 +03001441
Ville Syrjälä3be60de2015-09-08 18:05:45 +03001442 /* PHY is fully reset now, so we can enable the PHY state asserts */
1443 dev_priv->chv_phy_assert[phy] = true;
1444
Ville Syrjälä30142272015-07-08 23:46:01 +03001445 assert_chv_phy_status(dev_priv);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001446}
1447
Ville Syrjälä6669e392015-07-08 23:46:00 +03001448static void assert_chv_phy_powergate(struct drm_i915_private *dev_priv, enum dpio_phy phy,
1449 enum dpio_channel ch, bool override, unsigned int mask)
1450{
1451 enum pipe pipe = phy == DPIO_PHY0 ? PIPE_A : PIPE_C;
1452 u32 reg, val, expected, actual;
1453
Ville Syrjälä3be60de2015-09-08 18:05:45 +03001454 /*
1455 * The BIOS can leave the PHY is some weird state
1456 * where it doesn't fully power down some parts.
1457 * Disable the asserts until the PHY has been fully
1458 * reset (ie. the power well has been disabled at
1459 * least once).
1460 */
1461 if (!dev_priv->chv_phy_assert[phy])
1462 return;
1463
Ville Syrjälä6669e392015-07-08 23:46:00 +03001464 if (ch == DPIO_CH0)
1465 reg = _CHV_CMN_DW0_CH0;
1466 else
1467 reg = _CHV_CMN_DW6_CH1;
1468
1469 mutex_lock(&dev_priv->sb_lock);
1470 val = vlv_dpio_read(dev_priv, pipe, reg);
1471 mutex_unlock(&dev_priv->sb_lock);
1472
1473 /*
1474 * This assumes !override is only used when the port is disabled.
1475 * All lanes should power down even without the override when
1476 * the port is disabled.
1477 */
1478 if (!override || mask == 0xf) {
1479 expected = DPIO_ALLDL_POWERDOWN | DPIO_ANYDL_POWERDOWN;
1480 /*
1481 * If CH1 common lane is not active anymore
1482 * (eg. for pipe B DPLL) the entire channel will
1483 * shut down, which causes the common lane registers
1484 * to read as 0. That means we can't actually check
1485 * the lane power down status bits, but as the entire
1486 * register reads as 0 it's a good indication that the
1487 * channel is indeed entirely powered down.
1488 */
1489 if (ch == DPIO_CH1 && val == 0)
1490 expected = 0;
1491 } else if (mask != 0x0) {
1492 expected = DPIO_ANYDL_POWERDOWN;
1493 } else {
1494 expected = 0;
1495 }
1496
1497 if (ch == DPIO_CH0)
1498 actual = val >> DPIO_ANYDL_POWERDOWN_SHIFT_CH0;
1499 else
1500 actual = val >> DPIO_ANYDL_POWERDOWN_SHIFT_CH1;
1501 actual &= DPIO_ALLDL_POWERDOWN | DPIO_ANYDL_POWERDOWN;
1502
1503 WARN(actual != expected,
1504 "Unexpected DPIO lane power down: all %d, any %d. Expected: all %d, any %d. (0x%x = 0x%08x)\n",
1505 !!(actual & DPIO_ALLDL_POWERDOWN), !!(actual & DPIO_ANYDL_POWERDOWN),
1506 !!(expected & DPIO_ALLDL_POWERDOWN), !!(expected & DPIO_ANYDL_POWERDOWN),
1507 reg, val);
1508}
1509
Ville Syrjäläb0b33842015-07-08 23:45:55 +03001510bool chv_phy_powergate_ch(struct drm_i915_private *dev_priv, enum dpio_phy phy,
1511 enum dpio_channel ch, bool override)
1512{
1513 struct i915_power_domains *power_domains = &dev_priv->power_domains;
1514 bool was_override;
1515
1516 mutex_lock(&power_domains->lock);
1517
1518 was_override = dev_priv->chv_phy_control & PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
1519
1520 if (override == was_override)
1521 goto out;
1522
1523 if (override)
1524 dev_priv->chv_phy_control |= PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
1525 else
1526 dev_priv->chv_phy_control &= ~PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
1527
1528 I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
1529
1530 DRM_DEBUG_KMS("Power gating DPIO PHY%d CH%d (DPIO_PHY_CONTROL=0x%08x)\n",
1531 phy, ch, dev_priv->chv_phy_control);
1532
Ville Syrjälä30142272015-07-08 23:46:01 +03001533 assert_chv_phy_status(dev_priv);
1534
Ville Syrjäläb0b33842015-07-08 23:45:55 +03001535out:
1536 mutex_unlock(&power_domains->lock);
1537
1538 return was_override;
1539}
1540
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001541void chv_phy_powergate_lanes(struct intel_encoder *encoder,
1542 bool override, unsigned int mask)
1543{
1544 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
1545 struct i915_power_domains *power_domains = &dev_priv->power_domains;
1546 enum dpio_phy phy = vlv_dport_to_phy(enc_to_dig_port(&encoder->base));
1547 enum dpio_channel ch = vlv_dport_to_channel(enc_to_dig_port(&encoder->base));
1548
1549 mutex_lock(&power_domains->lock);
1550
1551 dev_priv->chv_phy_control &= ~PHY_CH_POWER_DOWN_OVRD(0xf, phy, ch);
1552 dev_priv->chv_phy_control |= PHY_CH_POWER_DOWN_OVRD(mask, phy, ch);
1553
1554 if (override)
1555 dev_priv->chv_phy_control |= PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
1556 else
1557 dev_priv->chv_phy_control &= ~PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
1558
1559 I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
1560
1561 DRM_DEBUG_KMS("Power gating DPIO PHY%d CH%d lanes 0x%x (PHY_CONTROL=0x%08x)\n",
1562 phy, ch, mask, dev_priv->chv_phy_control);
1563
Ville Syrjälä30142272015-07-08 23:46:01 +03001564 assert_chv_phy_status(dev_priv);
1565
Ville Syrjälä6669e392015-07-08 23:46:00 +03001566 assert_chv_phy_powergate(dev_priv, phy, ch, override, mask);
1567
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001568 mutex_unlock(&power_domains->lock);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001569}
1570
1571static bool chv_pipe_power_well_enabled(struct drm_i915_private *dev_priv,
1572 struct i915_power_well *power_well)
1573{
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001574 enum pipe pipe = power_well->id;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001575 bool enabled;
1576 u32 state, ctrl;
1577
1578 mutex_lock(&dev_priv->rps.hw_lock);
1579
1580 state = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & DP_SSS_MASK(pipe);
1581 /*
1582 * We only ever set the power-on and power-gate states, anything
1583 * else is unexpected.
1584 */
1585 WARN_ON(state != DP_SSS_PWR_ON(pipe) && state != DP_SSS_PWR_GATE(pipe));
1586 enabled = state == DP_SSS_PWR_ON(pipe);
1587
1588 /*
1589 * A transient state at this point would mean some unexpected party
1590 * is poking at the power controls too.
1591 */
1592 ctrl = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & DP_SSC_MASK(pipe);
1593 WARN_ON(ctrl << 16 != state);
1594
1595 mutex_unlock(&dev_priv->rps.hw_lock);
1596
1597 return enabled;
1598}
1599
1600static void chv_set_pipe_power_well(struct drm_i915_private *dev_priv,
1601 struct i915_power_well *power_well,
1602 bool enable)
1603{
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001604 enum pipe pipe = power_well->id;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001605 u32 state;
1606 u32 ctrl;
1607
1608 state = enable ? DP_SSS_PWR_ON(pipe) : DP_SSS_PWR_GATE(pipe);
1609
1610 mutex_lock(&dev_priv->rps.hw_lock);
1611
1612#define COND \
1613 ((vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & DP_SSS_MASK(pipe)) == state)
1614
1615 if (COND)
1616 goto out;
1617
1618 ctrl = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ);
1619 ctrl &= ~DP_SSC_MASK(pipe);
1620 ctrl |= enable ? DP_SSC_PWR_ON(pipe) : DP_SSC_PWR_GATE(pipe);
1621 vlv_punit_write(dev_priv, PUNIT_REG_DSPFREQ, ctrl);
1622
1623 if (wait_for(COND, 100))
Masanari Iida7e35ab82015-05-10 01:00:23 +09001624 DRM_ERROR("timeout setting power well state %08x (%08x)\n",
Daniel Vetter9c065a72014-09-30 10:56:38 +02001625 state,
1626 vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ));
1627
1628#undef COND
1629
1630out:
1631 mutex_unlock(&dev_priv->rps.hw_lock);
1632}
1633
Daniel Vetter9c065a72014-09-30 10:56:38 +02001634static void chv_pipe_power_well_enable(struct drm_i915_private *dev_priv,
1635 struct i915_power_well *power_well)
1636{
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001637 WARN_ON_ONCE(power_well->id != PIPE_A);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001638
1639 chv_set_pipe_power_well(dev_priv, power_well, true);
Ville Syrjäläafd62752014-10-30 19:43:03 +02001640
Ville Syrjälä2be7d542015-06-29 15:25:51 +03001641 vlv_display_power_well_init(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001642}
1643
1644static void chv_pipe_power_well_disable(struct drm_i915_private *dev_priv,
1645 struct i915_power_well *power_well)
1646{
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001647 WARN_ON_ONCE(power_well->id != PIPE_A);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001648
Ville Syrjälä2be7d542015-06-29 15:25:51 +03001649 vlv_display_power_well_deinit(dev_priv);
Ville Syrjäläafd62752014-10-30 19:43:03 +02001650
Daniel Vetter9c065a72014-09-30 10:56:38 +02001651 chv_set_pipe_power_well(dev_priv, power_well, false);
1652}
1653
Imre Deak09731282016-02-17 14:17:42 +02001654static void
1655__intel_display_power_get_domain(struct drm_i915_private *dev_priv,
1656 enum intel_display_power_domain domain)
1657{
1658 struct i915_power_domains *power_domains = &dev_priv->power_domains;
1659 struct i915_power_well *power_well;
Imre Deak09731282016-02-17 14:17:42 +02001660
Imre Deak75ccb2e2017-02-17 17:39:43 +02001661 for_each_power_domain_well(dev_priv, power_well, BIT_ULL(domain))
Imre Deakb409ca92016-06-13 16:44:33 +03001662 intel_power_well_get(dev_priv, power_well);
Imre Deak09731282016-02-17 14:17:42 +02001663
1664 power_domains->domain_use_count[domain]++;
1665}
1666
Daniel Vettere4e76842014-09-30 10:56:42 +02001667/**
1668 * intel_display_power_get - grab a power domain reference
1669 * @dev_priv: i915 device instance
1670 * @domain: power domain to reference
1671 *
1672 * This function grabs a power domain reference for @domain and ensures that the
1673 * power domain and all its parents are powered up. Therefore users should only
1674 * grab a reference to the innermost power domain they need.
1675 *
1676 * Any power domain reference obtained by this function must have a symmetric
1677 * call to intel_display_power_put() to release the reference again.
1678 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02001679void intel_display_power_get(struct drm_i915_private *dev_priv,
1680 enum intel_display_power_domain domain)
1681{
Imre Deak09731282016-02-17 14:17:42 +02001682 struct i915_power_domains *power_domains = &dev_priv->power_domains;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001683
1684 intel_runtime_pm_get(dev_priv);
1685
Imre Deak09731282016-02-17 14:17:42 +02001686 mutex_lock(&power_domains->lock);
1687
1688 __intel_display_power_get_domain(dev_priv, domain);
1689
1690 mutex_unlock(&power_domains->lock);
1691}
1692
1693/**
1694 * intel_display_power_get_if_enabled - grab a reference for an enabled display power domain
1695 * @dev_priv: i915 device instance
1696 * @domain: power domain to reference
1697 *
1698 * This function grabs a power domain reference for @domain and ensures that the
1699 * power domain and all its parents are powered up. Therefore users should only
1700 * grab a reference to the innermost power domain they need.
1701 *
1702 * Any power domain reference obtained by this function must have a symmetric
1703 * call to intel_display_power_put() to release the reference again.
1704 */
1705bool intel_display_power_get_if_enabled(struct drm_i915_private *dev_priv,
1706 enum intel_display_power_domain domain)
1707{
1708 struct i915_power_domains *power_domains = &dev_priv->power_domains;
1709 bool is_enabled;
1710
1711 if (!intel_runtime_pm_get_if_in_use(dev_priv))
1712 return false;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001713
1714 mutex_lock(&power_domains->lock);
1715
Imre Deak09731282016-02-17 14:17:42 +02001716 if (__intel_display_power_is_enabled(dev_priv, domain)) {
1717 __intel_display_power_get_domain(dev_priv, domain);
1718 is_enabled = true;
1719 } else {
1720 is_enabled = false;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001721 }
1722
Daniel Vetter9c065a72014-09-30 10:56:38 +02001723 mutex_unlock(&power_domains->lock);
Imre Deak09731282016-02-17 14:17:42 +02001724
1725 if (!is_enabled)
1726 intel_runtime_pm_put(dev_priv);
1727
1728 return is_enabled;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001729}
1730
Daniel Vettere4e76842014-09-30 10:56:42 +02001731/**
1732 * intel_display_power_put - release a power domain reference
1733 * @dev_priv: i915 device instance
1734 * @domain: power domain to reference
1735 *
1736 * This function drops the power domain reference obtained by
1737 * intel_display_power_get() and might power down the corresponding hardware
1738 * block right away if this is the last reference.
1739 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02001740void intel_display_power_put(struct drm_i915_private *dev_priv,
1741 enum intel_display_power_domain domain)
1742{
1743 struct i915_power_domains *power_domains;
1744 struct i915_power_well *power_well;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001745
1746 power_domains = &dev_priv->power_domains;
1747
1748 mutex_lock(&power_domains->lock);
1749
Daniel Stone11c86db2015-11-20 15:55:34 +00001750 WARN(!power_domains->domain_use_count[domain],
1751 "Use count on domain %s is already zero\n",
1752 intel_display_power_domain_str(domain));
Daniel Vetter9c065a72014-09-30 10:56:38 +02001753 power_domains->domain_use_count[domain]--;
1754
Imre Deak75ccb2e2017-02-17 17:39:43 +02001755 for_each_power_domain_well_rev(dev_priv, power_well, BIT_ULL(domain))
Imre Deakb409ca92016-06-13 16:44:33 +03001756 intel_power_well_put(dev_priv, power_well);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001757
1758 mutex_unlock(&power_domains->lock);
1759
1760 intel_runtime_pm_put(dev_priv);
1761}
1762
Ville Syrjälä9d0996b2016-04-18 14:02:28 +03001763#define HSW_DISPLAY_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001764 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
1765 BIT_ULL(POWER_DOMAIN_PIPE_C) | \
1766 BIT_ULL(POWER_DOMAIN_PIPE_A_PANEL_FITTER) | \
1767 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1768 BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
1769 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
1770 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
1771 BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
1772 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1773 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1774 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_LANES) | \
1775 BIT_ULL(POWER_DOMAIN_PORT_CRT) | /* DDI E */ \
1776 BIT_ULL(POWER_DOMAIN_VGA) | \
1777 BIT_ULL(POWER_DOMAIN_AUDIO) | \
1778 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001779
Ville Syrjälä9d0996b2016-04-18 14:02:28 +03001780#define BDW_DISPLAY_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001781 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
1782 BIT_ULL(POWER_DOMAIN_PIPE_C) | \
1783 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1784 BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
1785 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
1786 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
1787 BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
1788 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1789 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1790 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_LANES) | \
1791 BIT_ULL(POWER_DOMAIN_PORT_CRT) | /* DDI E */ \
1792 BIT_ULL(POWER_DOMAIN_VGA) | \
1793 BIT_ULL(POWER_DOMAIN_AUDIO) | \
1794 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001795
Ville Syrjälä465ac0c2016-04-18 14:02:27 +03001796#define VLV_DISPLAY_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001797 BIT_ULL(POWER_DOMAIN_PIPE_A) | \
1798 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
1799 BIT_ULL(POWER_DOMAIN_PIPE_A_PANEL_FITTER) | \
1800 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1801 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
1802 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
1803 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1804 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1805 BIT_ULL(POWER_DOMAIN_PORT_DSI) | \
1806 BIT_ULL(POWER_DOMAIN_PORT_CRT) | \
1807 BIT_ULL(POWER_DOMAIN_VGA) | \
1808 BIT_ULL(POWER_DOMAIN_AUDIO) | \
1809 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1810 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1811 BIT_ULL(POWER_DOMAIN_GMBUS) | \
1812 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001813
1814#define VLV_DPIO_CMN_BC_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001815 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1816 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1817 BIT_ULL(POWER_DOMAIN_PORT_CRT) | \
1818 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1819 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1820 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001821
1822#define VLV_DPIO_TX_B_LANES_01_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_AUX_B) | \
1825 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001826
1827#define VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001828 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1829 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1830 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001831
1832#define VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001833 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1834 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1835 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001836
1837#define VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001838 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1839 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1840 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001841
Ville Syrjälä465ac0c2016-04-18 14:02:27 +03001842#define CHV_DISPLAY_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001843 BIT_ULL(POWER_DOMAIN_PIPE_A) | \
1844 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
1845 BIT_ULL(POWER_DOMAIN_PIPE_C) | \
1846 BIT_ULL(POWER_DOMAIN_PIPE_A_PANEL_FITTER) | \
1847 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1848 BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
1849 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
1850 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
1851 BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
1852 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1853 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1854 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_LANES) | \
1855 BIT_ULL(POWER_DOMAIN_PORT_DSI) | \
1856 BIT_ULL(POWER_DOMAIN_VGA) | \
1857 BIT_ULL(POWER_DOMAIN_AUDIO) | \
1858 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1859 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1860 BIT_ULL(POWER_DOMAIN_AUX_D) | \
1861 BIT_ULL(POWER_DOMAIN_GMBUS) | \
1862 BIT_ULL(POWER_DOMAIN_INIT))
Ville Syrjälä465ac0c2016-04-18 14:02:27 +03001863
Daniel Vetter9c065a72014-09-30 10:56:38 +02001864#define CHV_DPIO_CMN_BC_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001865 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1866 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1867 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1868 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1869 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001870
1871#define CHV_DPIO_CMN_D_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001872 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_LANES) | \
1873 BIT_ULL(POWER_DOMAIN_AUX_D) | \
1874 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001875
Daniel Vetter9c065a72014-09-30 10:56:38 +02001876static const struct i915_power_well_ops i9xx_always_on_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02001877 .sync_hw = i9xx_power_well_sync_hw_noop,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001878 .enable = i9xx_always_on_power_well_noop,
1879 .disable = i9xx_always_on_power_well_noop,
1880 .is_enabled = i9xx_always_on_power_well_enabled,
1881};
1882
1883static const struct i915_power_well_ops chv_pipe_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02001884 .sync_hw = i9xx_power_well_sync_hw_noop,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001885 .enable = chv_pipe_power_well_enable,
1886 .disable = chv_pipe_power_well_disable,
1887 .is_enabled = chv_pipe_power_well_enabled,
1888};
1889
1890static const struct i915_power_well_ops chv_dpio_cmn_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02001891 .sync_hw = i9xx_power_well_sync_hw_noop,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001892 .enable = chv_dpio_cmn_power_well_enable,
1893 .disable = chv_dpio_cmn_power_well_disable,
1894 .is_enabled = vlv_power_well_enabled,
1895};
1896
1897static struct i915_power_well i9xx_always_on_power_well[] = {
1898 {
1899 .name = "always-on",
1900 .always_on = 1,
1901 .domains = POWER_DOMAIN_MASK,
1902 .ops = &i9xx_always_on_power_well_ops,
1903 },
1904};
1905
1906static const struct i915_power_well_ops hsw_power_well_ops = {
1907 .sync_hw = hsw_power_well_sync_hw,
1908 .enable = hsw_power_well_enable,
1909 .disable = hsw_power_well_disable,
1910 .is_enabled = hsw_power_well_enabled,
1911};
1912
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00001913static const struct i915_power_well_ops skl_power_well_ops = {
1914 .sync_hw = skl_power_well_sync_hw,
1915 .enable = skl_power_well_enable,
1916 .disable = skl_power_well_disable,
1917 .is_enabled = skl_power_well_enabled,
1918};
1919
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01001920static const struct i915_power_well_ops gen9_dc_off_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02001921 .sync_hw = i9xx_power_well_sync_hw_noop,
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01001922 .enable = gen9_dc_off_power_well_enable,
1923 .disable = gen9_dc_off_power_well_disable,
1924 .is_enabled = gen9_dc_off_power_well_enabled,
1925};
1926
Imre Deak9c8d0b82016-06-13 16:44:34 +03001927static const struct i915_power_well_ops bxt_dpio_cmn_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02001928 .sync_hw = i9xx_power_well_sync_hw_noop,
Imre Deak9c8d0b82016-06-13 16:44:34 +03001929 .enable = bxt_dpio_cmn_power_well_enable,
1930 .disable = bxt_dpio_cmn_power_well_disable,
1931 .is_enabled = bxt_dpio_cmn_power_well_enabled,
1932};
1933
Daniel Vetter9c065a72014-09-30 10:56:38 +02001934static struct i915_power_well hsw_power_wells[] = {
1935 {
1936 .name = "always-on",
1937 .always_on = 1,
Ville Syrjälä998bd662016-04-18 14:02:26 +03001938 .domains = POWER_DOMAIN_MASK,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001939 .ops = &i9xx_always_on_power_well_ops,
1940 },
1941 {
1942 .name = "display",
1943 .domains = HSW_DISPLAY_POWER_DOMAINS,
1944 .ops = &hsw_power_well_ops,
1945 },
1946};
1947
1948static struct i915_power_well bdw_power_wells[] = {
1949 {
1950 .name = "always-on",
1951 .always_on = 1,
Ville Syrjälä998bd662016-04-18 14:02:26 +03001952 .domains = POWER_DOMAIN_MASK,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001953 .ops = &i9xx_always_on_power_well_ops,
1954 },
1955 {
1956 .name = "display",
1957 .domains = BDW_DISPLAY_POWER_DOMAINS,
1958 .ops = &hsw_power_well_ops,
1959 },
1960};
1961
1962static const struct i915_power_well_ops vlv_display_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02001963 .sync_hw = i9xx_power_well_sync_hw_noop,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001964 .enable = vlv_display_power_well_enable,
1965 .disable = vlv_display_power_well_disable,
1966 .is_enabled = vlv_power_well_enabled,
1967};
1968
1969static const struct i915_power_well_ops vlv_dpio_cmn_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02001970 .sync_hw = i9xx_power_well_sync_hw_noop,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001971 .enable = vlv_dpio_cmn_power_well_enable,
1972 .disable = vlv_dpio_cmn_power_well_disable,
1973 .is_enabled = vlv_power_well_enabled,
1974};
1975
1976static const struct i915_power_well_ops vlv_dpio_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02001977 .sync_hw = i9xx_power_well_sync_hw_noop,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001978 .enable = vlv_power_well_enable,
1979 .disable = vlv_power_well_disable,
1980 .is_enabled = vlv_power_well_enabled,
1981};
1982
1983static struct i915_power_well vlv_power_wells[] = {
1984 {
1985 .name = "always-on",
1986 .always_on = 1,
Ville Syrjälä998bd662016-04-18 14:02:26 +03001987 .domains = POWER_DOMAIN_MASK,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001988 .ops = &i9xx_always_on_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001989 .id = PUNIT_POWER_WELL_ALWAYS_ON,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001990 },
1991 {
1992 .name = "display",
1993 .domains = VLV_DISPLAY_POWER_DOMAINS,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001994 .id = PUNIT_POWER_WELL_DISP2D,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001995 .ops = &vlv_display_power_well_ops,
1996 },
1997 {
1998 .name = "dpio-tx-b-01",
1999 .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
2000 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
2001 VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
2002 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
2003 .ops = &vlv_dpio_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002004 .id = PUNIT_POWER_WELL_DPIO_TX_B_LANES_01,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002005 },
2006 {
2007 .name = "dpio-tx-b-23",
2008 .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
2009 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
2010 VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
2011 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
2012 .ops = &vlv_dpio_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002013 .id = PUNIT_POWER_WELL_DPIO_TX_B_LANES_23,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002014 },
2015 {
2016 .name = "dpio-tx-c-01",
2017 .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
2018 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
2019 VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
2020 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
2021 .ops = &vlv_dpio_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002022 .id = PUNIT_POWER_WELL_DPIO_TX_C_LANES_01,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002023 },
2024 {
2025 .name = "dpio-tx-c-23",
2026 .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
2027 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
2028 VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
2029 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
2030 .ops = &vlv_dpio_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002031 .id = PUNIT_POWER_WELL_DPIO_TX_C_LANES_23,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002032 },
2033 {
2034 .name = "dpio-common",
2035 .domains = VLV_DPIO_CMN_BC_POWER_DOMAINS,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002036 .id = PUNIT_POWER_WELL_DPIO_CMN_BC,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002037 .ops = &vlv_dpio_cmn_power_well_ops,
2038 },
2039};
2040
2041static struct i915_power_well chv_power_wells[] = {
2042 {
2043 .name = "always-on",
2044 .always_on = 1,
Ville Syrjälä998bd662016-04-18 14:02:26 +03002045 .domains = POWER_DOMAIN_MASK,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002046 .ops = &i9xx_always_on_power_well_ops,
2047 },
Daniel Vetter9c065a72014-09-30 10:56:38 +02002048 {
2049 .name = "display",
Ville Syrjäläbaa4e572014-10-27 16:07:32 +02002050 /*
Ville Syrjäläfde61e42015-05-26 20:22:39 +03002051 * Pipe A power well is the new disp2d well. Pipe B and C
2052 * power wells don't actually exist. Pipe A power well is
2053 * required for any pipe to work.
Ville Syrjäläbaa4e572014-10-27 16:07:32 +02002054 */
Ville Syrjälä465ac0c2016-04-18 14:02:27 +03002055 .domains = CHV_DISPLAY_POWER_DOMAINS,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002056 .id = PIPE_A,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002057 .ops = &chv_pipe_power_well_ops,
2058 },
Daniel Vetter9c065a72014-09-30 10:56:38 +02002059 {
2060 .name = "dpio-common-bc",
Ville Syrjälä71849b62015-04-10 18:21:29 +03002061 .domains = CHV_DPIO_CMN_BC_POWER_DOMAINS,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002062 .id = PUNIT_POWER_WELL_DPIO_CMN_BC,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002063 .ops = &chv_dpio_cmn_power_well_ops,
2064 },
2065 {
2066 .name = "dpio-common-d",
Ville Syrjälä71849b62015-04-10 18:21:29 +03002067 .domains = CHV_DPIO_CMN_D_POWER_DOMAINS,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002068 .id = PUNIT_POWER_WELL_DPIO_CMN_D,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002069 .ops = &chv_dpio_cmn_power_well_ops,
2070 },
Daniel Vetter9c065a72014-09-30 10:56:38 +02002071};
2072
Suketu Shah5aefb232015-04-16 14:22:10 +05302073bool intel_display_power_well_is_enabled(struct drm_i915_private *dev_priv,
2074 int power_well_id)
2075{
2076 struct i915_power_well *power_well;
2077 bool ret;
2078
2079 power_well = lookup_power_well(dev_priv, power_well_id);
2080 ret = power_well->ops->is_enabled(dev_priv, power_well);
2081
2082 return ret;
2083}
2084
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002085static struct i915_power_well skl_power_wells[] = {
2086 {
2087 .name = "always-on",
2088 .always_on = 1,
Ville Syrjälä998bd662016-04-18 14:02:26 +03002089 .domains = POWER_DOMAIN_MASK,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002090 .ops = &i9xx_always_on_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002091 .id = SKL_DISP_PW_ALWAYS_ON,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002092 },
2093 {
2094 .name = "power well 1",
Imre Deak4a76f292015-11-04 19:24:15 +02002095 /* Handled by the DMC firmware */
2096 .domains = 0,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002097 .ops = &skl_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002098 .id = SKL_DISP_PW_1,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002099 },
2100 {
2101 .name = "MISC IO power well",
Imre Deak4a76f292015-11-04 19:24:15 +02002102 /* Handled by the DMC firmware */
2103 .domains = 0,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002104 .ops = &skl_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002105 .id = SKL_DISP_PW_MISC_IO,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002106 },
2107 {
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01002108 .name = "DC off",
2109 .domains = SKL_DISPLAY_DC_OFF_POWER_DOMAINS,
2110 .ops = &gen9_dc_off_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002111 .id = SKL_DISP_PW_DC_OFF,
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01002112 },
2113 {
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002114 .name = "power well 2",
2115 .domains = SKL_DISPLAY_POWERWELL_2_POWER_DOMAINS,
2116 .ops = &skl_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002117 .id = SKL_DISP_PW_2,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002118 },
2119 {
2120 .name = "DDI A/E power well",
2121 .domains = SKL_DISPLAY_DDI_A_E_POWER_DOMAINS,
2122 .ops = &skl_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002123 .id = SKL_DISP_PW_DDI_A_E,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002124 },
2125 {
2126 .name = "DDI B power well",
2127 .domains = SKL_DISPLAY_DDI_B_POWER_DOMAINS,
2128 .ops = &skl_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002129 .id = SKL_DISP_PW_DDI_B,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002130 },
2131 {
2132 .name = "DDI C power well",
2133 .domains = SKL_DISPLAY_DDI_C_POWER_DOMAINS,
2134 .ops = &skl_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002135 .id = SKL_DISP_PW_DDI_C,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002136 },
2137 {
2138 .name = "DDI D power well",
2139 .domains = SKL_DISPLAY_DDI_D_POWER_DOMAINS,
2140 .ops = &skl_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002141 .id = SKL_DISP_PW_DDI_D,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002142 },
2143};
2144
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302145static struct i915_power_well bxt_power_wells[] = {
2146 {
2147 .name = "always-on",
2148 .always_on = 1,
Ville Syrjälä998bd662016-04-18 14:02:26 +03002149 .domains = POWER_DOMAIN_MASK,
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302150 .ops = &i9xx_always_on_power_well_ops,
2151 },
2152 {
2153 .name = "power well 1",
Imre Deakd7d7c9e2016-04-01 16:02:42 +03002154 .domains = 0,
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302155 .ops = &skl_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002156 .id = SKL_DISP_PW_1,
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302157 },
2158 {
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01002159 .name = "DC off",
2160 .domains = BXT_DISPLAY_DC_OFF_POWER_DOMAINS,
2161 .ops = &gen9_dc_off_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002162 .id = SKL_DISP_PW_DC_OFF,
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01002163 },
2164 {
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302165 .name = "power well 2",
2166 .domains = BXT_DISPLAY_POWERWELL_2_POWER_DOMAINS,
2167 .ops = &skl_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002168 .id = SKL_DISP_PW_2,
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01002169 },
Imre Deak9c8d0b82016-06-13 16:44:34 +03002170 {
2171 .name = "dpio-common-a",
2172 .domains = BXT_DPIO_CMN_A_POWER_DOMAINS,
2173 .ops = &bxt_dpio_cmn_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002174 .id = BXT_DPIO_CMN_A,
Ander Conselvan de Oliveira362624c2016-10-06 19:22:15 +03002175 .data = DPIO_PHY1,
Imre Deak9c8d0b82016-06-13 16:44:34 +03002176 },
2177 {
2178 .name = "dpio-common-bc",
2179 .domains = BXT_DPIO_CMN_BC_POWER_DOMAINS,
2180 .ops = &bxt_dpio_cmn_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002181 .id = BXT_DPIO_CMN_BC,
Ander Conselvan de Oliveira362624c2016-10-06 19:22:15 +03002182 .data = DPIO_PHY0,
Imre Deak9c8d0b82016-06-13 16:44:34 +03002183 },
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302184};
2185
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002186static struct i915_power_well glk_power_wells[] = {
2187 {
2188 .name = "always-on",
2189 .always_on = 1,
2190 .domains = POWER_DOMAIN_MASK,
2191 .ops = &i9xx_always_on_power_well_ops,
2192 },
2193 {
2194 .name = "power well 1",
2195 /* Handled by the DMC firmware */
2196 .domains = 0,
2197 .ops = &skl_power_well_ops,
2198 .id = SKL_DISP_PW_1,
2199 },
2200 {
2201 .name = "DC off",
2202 .domains = GLK_DISPLAY_DC_OFF_POWER_DOMAINS,
2203 .ops = &gen9_dc_off_power_well_ops,
2204 .id = SKL_DISP_PW_DC_OFF,
2205 },
2206 {
2207 .name = "power well 2",
2208 .domains = GLK_DISPLAY_POWERWELL_2_POWER_DOMAINS,
2209 .ops = &skl_power_well_ops,
2210 .id = SKL_DISP_PW_2,
2211 },
2212 {
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +02002213 .name = "dpio-common-a",
2214 .domains = GLK_DPIO_CMN_A_POWER_DOMAINS,
2215 .ops = &bxt_dpio_cmn_power_well_ops,
2216 .id = BXT_DPIO_CMN_A,
2217 .data = DPIO_PHY1,
2218 },
2219 {
2220 .name = "dpio-common-b",
2221 .domains = GLK_DPIO_CMN_B_POWER_DOMAINS,
2222 .ops = &bxt_dpio_cmn_power_well_ops,
2223 .id = BXT_DPIO_CMN_BC,
2224 .data = DPIO_PHY0,
2225 },
2226 {
2227 .name = "dpio-common-c",
2228 .domains = GLK_DPIO_CMN_C_POWER_DOMAINS,
2229 .ops = &bxt_dpio_cmn_power_well_ops,
2230 .id = GLK_DPIO_CMN_C,
2231 .data = DPIO_PHY2,
2232 },
2233 {
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002234 .name = "AUX A",
2235 .domains = GLK_DISPLAY_AUX_A_POWER_DOMAINS,
2236 .ops = &skl_power_well_ops,
2237 .id = GLK_DISP_PW_AUX_A,
2238 },
2239 {
2240 .name = "AUX B",
2241 .domains = GLK_DISPLAY_AUX_B_POWER_DOMAINS,
2242 .ops = &skl_power_well_ops,
2243 .id = GLK_DISP_PW_AUX_B,
2244 },
2245 {
2246 .name = "AUX C",
2247 .domains = GLK_DISPLAY_AUX_C_POWER_DOMAINS,
2248 .ops = &skl_power_well_ops,
2249 .id = GLK_DISP_PW_AUX_C,
2250 },
2251 {
2252 .name = "DDI A power well",
2253 .domains = GLK_DISPLAY_DDI_A_POWER_DOMAINS,
2254 .ops = &skl_power_well_ops,
2255 .id = GLK_DISP_PW_DDI_A,
2256 },
2257 {
2258 .name = "DDI B power well",
2259 .domains = GLK_DISPLAY_DDI_B_POWER_DOMAINS,
2260 .ops = &skl_power_well_ops,
2261 .id = SKL_DISP_PW_DDI_B,
2262 },
2263 {
2264 .name = "DDI C power well",
2265 .domains = GLK_DISPLAY_DDI_C_POWER_DOMAINS,
2266 .ops = &skl_power_well_ops,
2267 .id = SKL_DISP_PW_DDI_C,
2268 },
2269};
2270
Imre Deak1b0e3a02015-11-05 23:04:11 +02002271static int
2272sanitize_disable_power_well_option(const struct drm_i915_private *dev_priv,
2273 int disable_power_well)
2274{
2275 if (disable_power_well >= 0)
2276 return !!disable_power_well;
2277
Imre Deak1b0e3a02015-11-05 23:04:11 +02002278 return 1;
2279}
2280
Imre Deaka37baf32016-02-29 22:49:03 +02002281static uint32_t get_allowed_dc_mask(const struct drm_i915_private *dev_priv,
2282 int enable_dc)
2283{
2284 uint32_t mask;
2285 int requested_dc;
2286 int max_dc;
2287
Rodrigo Vivib976dc52017-01-23 10:32:37 -08002288 if (IS_GEN9_BC(dev_priv)) {
Imre Deaka37baf32016-02-29 22:49:03 +02002289 max_dc = 2;
2290 mask = 0;
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02002291 } else if (IS_GEN9_LP(dev_priv)) {
Imre Deaka37baf32016-02-29 22:49:03 +02002292 max_dc = 1;
2293 /*
2294 * DC9 has a separate HW flow from the rest of the DC states,
2295 * not depending on the DMC firmware. It's needed by system
2296 * suspend/resume, so allow it unconditionally.
2297 */
2298 mask = DC_STATE_EN_DC9;
2299 } else {
2300 max_dc = 0;
2301 mask = 0;
2302 }
2303
Imre Deak66e2c4c2016-02-29 22:49:04 +02002304 if (!i915.disable_power_well)
2305 max_dc = 0;
2306
Imre Deaka37baf32016-02-29 22:49:03 +02002307 if (enable_dc >= 0 && enable_dc <= max_dc) {
2308 requested_dc = enable_dc;
2309 } else if (enable_dc == -1) {
2310 requested_dc = max_dc;
2311 } else if (enable_dc > max_dc && enable_dc <= 2) {
2312 DRM_DEBUG_KMS("Adjusting requested max DC state (%d->%d)\n",
2313 enable_dc, max_dc);
2314 requested_dc = max_dc;
2315 } else {
2316 DRM_ERROR("Unexpected value for enable_dc (%d)\n", enable_dc);
2317 requested_dc = max_dc;
2318 }
2319
2320 if (requested_dc > 1)
2321 mask |= DC_STATE_EN_UPTO_DC6;
2322 if (requested_dc > 0)
2323 mask |= DC_STATE_EN_UPTO_DC5;
2324
2325 DRM_DEBUG_KMS("Allowed DC state mask %02x\n", mask);
2326
2327 return mask;
2328}
2329
Daniel Vetter9c065a72014-09-30 10:56:38 +02002330#define set_power_wells(power_domains, __power_wells) ({ \
2331 (power_domains)->power_wells = (__power_wells); \
2332 (power_domains)->power_well_count = ARRAY_SIZE(__power_wells); \
2333})
2334
Daniel Vettere4e76842014-09-30 10:56:42 +02002335/**
2336 * intel_power_domains_init - initializes the power domain structures
2337 * @dev_priv: i915 device instance
2338 *
2339 * Initializes the power domain structures for @dev_priv depending upon the
2340 * supported platform.
2341 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02002342int intel_power_domains_init(struct drm_i915_private *dev_priv)
2343{
2344 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2345
Imre Deak1b0e3a02015-11-05 23:04:11 +02002346 i915.disable_power_well = sanitize_disable_power_well_option(dev_priv,
2347 i915.disable_power_well);
Imre Deaka37baf32016-02-29 22:49:03 +02002348 dev_priv->csr.allowed_dc_mask = get_allowed_dc_mask(dev_priv,
2349 i915.enable_dc);
Imre Deak1b0e3a02015-11-05 23:04:11 +02002350
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02002351 BUILD_BUG_ON(POWER_DOMAIN_NUM > 64);
Ville Syrjäläf0ab43e2015-11-09 16:48:19 +01002352
Daniel Vetter9c065a72014-09-30 10:56:38 +02002353 mutex_init(&power_domains->lock);
2354
2355 /*
2356 * The enabling order will be from lower to higher indexed wells,
2357 * the disabling order is reversed.
2358 */
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002359 if (IS_HASWELL(dev_priv)) {
Daniel Vetter9c065a72014-09-30 10:56:38 +02002360 set_power_wells(power_domains, hsw_power_wells);
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002361 } else if (IS_BROADWELL(dev_priv)) {
Daniel Vetter9c065a72014-09-30 10:56:38 +02002362 set_power_wells(power_domains, bdw_power_wells);
Rodrigo Vivib976dc52017-01-23 10:32:37 -08002363 } else if (IS_GEN9_BC(dev_priv)) {
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002364 set_power_wells(power_domains, skl_power_wells);
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002365 } else if (IS_BROXTON(dev_priv)) {
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302366 set_power_wells(power_domains, bxt_power_wells);
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002367 } else if (IS_GEMINILAKE(dev_priv)) {
2368 set_power_wells(power_domains, glk_power_wells);
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002369 } else if (IS_CHERRYVIEW(dev_priv)) {
Daniel Vetter9c065a72014-09-30 10:56:38 +02002370 set_power_wells(power_domains, chv_power_wells);
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002371 } else if (IS_VALLEYVIEW(dev_priv)) {
Daniel Vetter9c065a72014-09-30 10:56:38 +02002372 set_power_wells(power_domains, vlv_power_wells);
2373 } else {
2374 set_power_wells(power_domains, i9xx_always_on_power_well);
2375 }
2376
2377 return 0;
2378}
2379
Daniel Vettere4e76842014-09-30 10:56:42 +02002380/**
2381 * intel_power_domains_fini - finalizes the power domain structures
2382 * @dev_priv: i915 device instance
2383 *
2384 * Finalizes the power domain structures for @dev_priv depending upon the
2385 * supported platform. This function also disables runtime pm and ensures that
2386 * the device stays powered up so that the driver can be reloaded.
2387 */
Daniel Vetterf458ebb2014-09-30 10:56:39 +02002388void intel_power_domains_fini(struct drm_i915_private *dev_priv)
Daniel Vetter9c065a72014-09-30 10:56:38 +02002389{
David Weinehallc49d13e2016-08-22 13:32:42 +03002390 struct device *kdev = &dev_priv->drm.pdev->dev;
Imre Deak25b181b2015-12-17 13:44:56 +02002391
Imre Deakaabee1b2015-12-15 20:10:29 +02002392 /*
2393 * The i915.ko module is still not prepared to be loaded when
Daniel Vetterf458ebb2014-09-30 10:56:39 +02002394 * the power well is not enabled, so just enable it in case
Imre Deakaabee1b2015-12-15 20:10:29 +02002395 * we're going to unload/reload.
2396 * The following also reacquires the RPM reference the core passed
2397 * to the driver during loading, which is dropped in
2398 * intel_runtime_pm_enable(). We have to hand back the control of the
2399 * device to the core with this reference held.
2400 */
Daniel Vetterf458ebb2014-09-30 10:56:39 +02002401 intel_display_set_init_power(dev_priv, true);
Imre Deakd314cd42015-11-17 17:44:23 +02002402
2403 /* Remove the refcount we took to keep power well support disabled. */
2404 if (!i915.disable_power_well)
2405 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
Imre Deak25b181b2015-12-17 13:44:56 +02002406
2407 /*
2408 * Remove the refcount we took in intel_runtime_pm_enable() in case
2409 * the platform doesn't support runtime PM.
2410 */
2411 if (!HAS_RUNTIME_PM(dev_priv))
David Weinehallc49d13e2016-08-22 13:32:42 +03002412 pm_runtime_put(kdev);
Daniel Vetter9c065a72014-09-30 10:56:38 +02002413}
2414
Imre Deak30eade12015-11-04 19:24:13 +02002415static void intel_power_domains_sync_hw(struct drm_i915_private *dev_priv)
Daniel Vetter9c065a72014-09-30 10:56:38 +02002416{
2417 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2418 struct i915_power_well *power_well;
Daniel Vetter9c065a72014-09-30 10:56:38 +02002419
2420 mutex_lock(&power_domains->lock);
Imre Deak75ccb2e2017-02-17 17:39:43 +02002421 for_each_power_well(dev_priv, power_well) {
Daniel Vetter9c065a72014-09-30 10:56:38 +02002422 power_well->ops->sync_hw(dev_priv, power_well);
2423 power_well->hw_enabled = power_well->ops->is_enabled(dev_priv,
2424 power_well);
2425 }
2426 mutex_unlock(&power_domains->lock);
2427}
2428
Ville Syrjälä70c2c182016-05-13 23:41:30 +03002429static void gen9_dbuf_enable(struct drm_i915_private *dev_priv)
2430{
2431 I915_WRITE(DBUF_CTL, I915_READ(DBUF_CTL) | DBUF_POWER_REQUEST);
2432 POSTING_READ(DBUF_CTL);
2433
2434 udelay(10);
2435
2436 if (!(I915_READ(DBUF_CTL) & DBUF_POWER_STATE))
2437 DRM_ERROR("DBuf power enable timeout\n");
2438}
2439
2440static void gen9_dbuf_disable(struct drm_i915_private *dev_priv)
2441{
2442 I915_WRITE(DBUF_CTL, I915_READ(DBUF_CTL) & ~DBUF_POWER_REQUEST);
2443 POSTING_READ(DBUF_CTL);
2444
2445 udelay(10);
2446
2447 if (I915_READ(DBUF_CTL) & DBUF_POWER_STATE)
2448 DRM_ERROR("DBuf power disable timeout!\n");
2449}
2450
Imre Deak73dfc222015-11-17 17:33:53 +02002451static void skl_display_core_init(struct drm_i915_private *dev_priv,
Imre Deak443a93a2016-04-04 15:42:57 +03002452 bool resume)
Imre Deak73dfc222015-11-17 17:33:53 +02002453{
2454 struct i915_power_domains *power_domains = &dev_priv->power_domains;
Imre Deak443a93a2016-04-04 15:42:57 +03002455 struct i915_power_well *well;
Imre Deak73dfc222015-11-17 17:33:53 +02002456 uint32_t val;
2457
Imre Deakd26fa1d2015-11-04 19:24:17 +02002458 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
2459
Imre Deak73dfc222015-11-17 17:33:53 +02002460 /* enable PCH reset handshake */
2461 val = I915_READ(HSW_NDE_RSTWRN_OPT);
2462 I915_WRITE(HSW_NDE_RSTWRN_OPT, val | RESET_PCH_HANDSHAKE_ENABLE);
2463
2464 /* enable PG1 and Misc I/O */
2465 mutex_lock(&power_domains->lock);
Imre Deak443a93a2016-04-04 15:42:57 +03002466
2467 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
2468 intel_power_well_enable(dev_priv, well);
2469
2470 well = lookup_power_well(dev_priv, SKL_DISP_PW_MISC_IO);
2471 intel_power_well_enable(dev_priv, well);
2472
Imre Deak73dfc222015-11-17 17:33:53 +02002473 mutex_unlock(&power_domains->lock);
2474
Imre Deak73dfc222015-11-17 17:33:53 +02002475 skl_init_cdclk(dev_priv);
2476
Ville Syrjälä70c2c182016-05-13 23:41:30 +03002477 gen9_dbuf_enable(dev_priv);
2478
Ville Syrjälä9f7eb312016-05-13 23:41:29 +03002479 if (resume && dev_priv->csr.dmc_payload)
Imre Deak2abc5252016-03-04 21:57:41 +02002480 intel_csr_load_program(dev_priv);
Imre Deak73dfc222015-11-17 17:33:53 +02002481}
2482
2483static void skl_display_core_uninit(struct drm_i915_private *dev_priv)
2484{
2485 struct i915_power_domains *power_domains = &dev_priv->power_domains;
Imre Deak443a93a2016-04-04 15:42:57 +03002486 struct i915_power_well *well;
Imre Deak73dfc222015-11-17 17:33:53 +02002487
Imre Deakd26fa1d2015-11-04 19:24:17 +02002488 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
2489
Ville Syrjälä70c2c182016-05-13 23:41:30 +03002490 gen9_dbuf_disable(dev_priv);
2491
Imre Deak73dfc222015-11-17 17:33:53 +02002492 skl_uninit_cdclk(dev_priv);
2493
2494 /* The spec doesn't call for removing the reset handshake flag */
2495 /* disable PG1 and Misc I/O */
Imre Deak443a93a2016-04-04 15:42:57 +03002496
Imre Deak73dfc222015-11-17 17:33:53 +02002497 mutex_lock(&power_domains->lock);
Imre Deak443a93a2016-04-04 15:42:57 +03002498
2499 well = lookup_power_well(dev_priv, SKL_DISP_PW_MISC_IO);
2500 intel_power_well_disable(dev_priv, well);
2501
2502 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
2503 intel_power_well_disable(dev_priv, well);
2504
Imre Deak73dfc222015-11-17 17:33:53 +02002505 mutex_unlock(&power_domains->lock);
2506}
2507
Imre Deakd7d7c9e2016-04-01 16:02:42 +03002508void bxt_display_core_init(struct drm_i915_private *dev_priv,
2509 bool resume)
2510{
2511 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2512 struct i915_power_well *well;
2513 uint32_t val;
2514
2515 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
2516
2517 /*
2518 * NDE_RSTWRN_OPT RST PCH Handshake En must always be 0b on BXT
2519 * or else the reset will hang because there is no PCH to respond.
2520 * Move the handshake programming to initialization sequence.
2521 * Previously was left up to BIOS.
2522 */
2523 val = I915_READ(HSW_NDE_RSTWRN_OPT);
2524 val &= ~RESET_PCH_HANDSHAKE_ENABLE;
2525 I915_WRITE(HSW_NDE_RSTWRN_OPT, val);
2526
2527 /* Enable PG1 */
2528 mutex_lock(&power_domains->lock);
2529
2530 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
2531 intel_power_well_enable(dev_priv, well);
2532
2533 mutex_unlock(&power_domains->lock);
2534
Imre Deak324513c2016-06-13 16:44:36 +03002535 bxt_init_cdclk(dev_priv);
Ville Syrjälä70c2c182016-05-13 23:41:30 +03002536
2537 gen9_dbuf_enable(dev_priv);
2538
Imre Deakd7d7c9e2016-04-01 16:02:42 +03002539 if (resume && dev_priv->csr.dmc_payload)
2540 intel_csr_load_program(dev_priv);
2541}
2542
2543void bxt_display_core_uninit(struct drm_i915_private *dev_priv)
2544{
2545 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2546 struct i915_power_well *well;
2547
2548 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
2549
Ville Syrjälä70c2c182016-05-13 23:41:30 +03002550 gen9_dbuf_disable(dev_priv);
2551
Imre Deak324513c2016-06-13 16:44:36 +03002552 bxt_uninit_cdclk(dev_priv);
Imre Deakd7d7c9e2016-04-01 16:02:42 +03002553
2554 /* The spec doesn't call for removing the reset handshake flag */
2555
2556 /* Disable PG1 */
2557 mutex_lock(&power_domains->lock);
2558
2559 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
2560 intel_power_well_disable(dev_priv, well);
2561
2562 mutex_unlock(&power_domains->lock);
2563}
2564
Ville Syrjälä70722462015-04-10 18:21:28 +03002565static void chv_phy_control_init(struct drm_i915_private *dev_priv)
2566{
2567 struct i915_power_well *cmn_bc =
2568 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_BC);
2569 struct i915_power_well *cmn_d =
2570 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_D);
2571
2572 /*
2573 * DISPLAY_PHY_CONTROL can get corrupted if read. As a
2574 * workaround never ever read DISPLAY_PHY_CONTROL, and
2575 * instead maintain a shadow copy ourselves. Use the actual
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002576 * power well state and lane status to reconstruct the
2577 * expected initial value.
Ville Syrjälä70722462015-04-10 18:21:28 +03002578 */
2579 dev_priv->chv_phy_control =
Ville Syrjäläbc284542015-05-26 20:22:38 +03002580 PHY_LDO_SEQ_DELAY(PHY_LDO_DELAY_600NS, DPIO_PHY0) |
2581 PHY_LDO_SEQ_DELAY(PHY_LDO_DELAY_600NS, DPIO_PHY1) |
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002582 PHY_CH_POWER_MODE(PHY_CH_DEEP_PSR, DPIO_PHY0, DPIO_CH0) |
2583 PHY_CH_POWER_MODE(PHY_CH_DEEP_PSR, DPIO_PHY0, DPIO_CH1) |
2584 PHY_CH_POWER_MODE(PHY_CH_DEEP_PSR, DPIO_PHY1, DPIO_CH0);
2585
2586 /*
2587 * If all lanes are disabled we leave the override disabled
2588 * with all power down bits cleared to match the state we
2589 * would use after disabling the port. Otherwise enable the
2590 * override and set the lane powerdown bits accding to the
2591 * current lane status.
2592 */
2593 if (cmn_bc->ops->is_enabled(dev_priv, cmn_bc)) {
2594 uint32_t status = I915_READ(DPLL(PIPE_A));
2595 unsigned int mask;
2596
2597 mask = status & DPLL_PORTB_READY_MASK;
2598 if (mask == 0xf)
2599 mask = 0x0;
2600 else
2601 dev_priv->chv_phy_control |=
2602 PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY0, DPIO_CH0);
2603
2604 dev_priv->chv_phy_control |=
2605 PHY_CH_POWER_DOWN_OVRD(mask, DPIO_PHY0, DPIO_CH0);
2606
2607 mask = (status & DPLL_PORTC_READY_MASK) >> 4;
2608 if (mask == 0xf)
2609 mask = 0x0;
2610 else
2611 dev_priv->chv_phy_control |=
2612 PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY0, DPIO_CH1);
2613
2614 dev_priv->chv_phy_control |=
2615 PHY_CH_POWER_DOWN_OVRD(mask, DPIO_PHY0, DPIO_CH1);
2616
Ville Syrjälä70722462015-04-10 18:21:28 +03002617 dev_priv->chv_phy_control |= PHY_COM_LANE_RESET_DEASSERT(DPIO_PHY0);
Ville Syrjälä3be60de2015-09-08 18:05:45 +03002618
2619 dev_priv->chv_phy_assert[DPIO_PHY0] = false;
2620 } else {
2621 dev_priv->chv_phy_assert[DPIO_PHY0] = true;
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002622 }
2623
2624 if (cmn_d->ops->is_enabled(dev_priv, cmn_d)) {
2625 uint32_t status = I915_READ(DPIO_PHY_STATUS);
2626 unsigned int mask;
2627
2628 mask = status & DPLL_PORTD_READY_MASK;
2629
2630 if (mask == 0xf)
2631 mask = 0x0;
2632 else
2633 dev_priv->chv_phy_control |=
2634 PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY1, DPIO_CH0);
2635
2636 dev_priv->chv_phy_control |=
2637 PHY_CH_POWER_DOWN_OVRD(mask, DPIO_PHY1, DPIO_CH0);
2638
Ville Syrjälä70722462015-04-10 18:21:28 +03002639 dev_priv->chv_phy_control |= PHY_COM_LANE_RESET_DEASSERT(DPIO_PHY1);
Ville Syrjälä3be60de2015-09-08 18:05:45 +03002640
2641 dev_priv->chv_phy_assert[DPIO_PHY1] = false;
2642 } else {
2643 dev_priv->chv_phy_assert[DPIO_PHY1] = true;
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002644 }
2645
2646 I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
2647
2648 DRM_DEBUG_KMS("Initial PHY_CONTROL=0x%08x\n",
2649 dev_priv->chv_phy_control);
Ville Syrjälä70722462015-04-10 18:21:28 +03002650}
2651
Daniel Vetter9c065a72014-09-30 10:56:38 +02002652static void vlv_cmnlane_wa(struct drm_i915_private *dev_priv)
2653{
2654 struct i915_power_well *cmn =
2655 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_BC);
2656 struct i915_power_well *disp2d =
2657 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DISP2D);
2658
Daniel Vetter9c065a72014-09-30 10:56:38 +02002659 /* If the display might be already active skip this */
Ville Syrjälä5d93a6e2014-10-16 20:52:33 +03002660 if (cmn->ops->is_enabled(dev_priv, cmn) &&
2661 disp2d->ops->is_enabled(dev_priv, disp2d) &&
Daniel Vetter9c065a72014-09-30 10:56:38 +02002662 I915_READ(DPIO_CTL) & DPIO_CMNRST)
2663 return;
2664
2665 DRM_DEBUG_KMS("toggling display PHY side reset\n");
2666
2667 /* cmnlane needs DPLL registers */
2668 disp2d->ops->enable(dev_priv, disp2d);
2669
2670 /*
2671 * From VLV2A0_DP_eDP_HDMI_DPIO_driver_vbios_notes_11.docx:
2672 * Need to assert and de-assert PHY SB reset by gating the
2673 * common lane power, then un-gating it.
2674 * Simply ungating isn't enough to reset the PHY enough to get
2675 * ports and lanes running.
2676 */
2677 cmn->ops->disable(dev_priv, cmn);
2678}
2679
Daniel Vettere4e76842014-09-30 10:56:42 +02002680/**
2681 * intel_power_domains_init_hw - initialize hardware power domain state
2682 * @dev_priv: i915 device instance
Tvrtko Ursulin14bb2c12016-06-03 14:02:17 +01002683 * @resume: Called from resume code paths or not
Daniel Vettere4e76842014-09-30 10:56:42 +02002684 *
2685 * This function initializes the hardware power domain state and enables all
Imre Deak8d8c3862017-02-17 17:39:46 +02002686 * power wells belonging to the INIT power domain. Power wells in other
2687 * domains (and not in the INIT domain) are referenced or disabled during the
2688 * modeset state HW readout. After that the reference count of each power well
2689 * must match its HW enabled state, see intel_power_domains_verify_state().
Daniel Vettere4e76842014-09-30 10:56:42 +02002690 */
Imre Deak73dfc222015-11-17 17:33:53 +02002691void intel_power_domains_init_hw(struct drm_i915_private *dev_priv, bool resume)
Daniel Vetter9c065a72014-09-30 10:56:38 +02002692{
Daniel Vetter9c065a72014-09-30 10:56:38 +02002693 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2694
2695 power_domains->initializing = true;
2696
Rodrigo Vivib976dc52017-01-23 10:32:37 -08002697 if (IS_GEN9_BC(dev_priv)) {
Imre Deak73dfc222015-11-17 17:33:53 +02002698 skl_display_core_init(dev_priv, resume);
Ander Conselvan de Oliveirab817c442016-12-02 10:23:56 +02002699 } else if (IS_GEN9_LP(dev_priv)) {
Imre Deakd7d7c9e2016-04-01 16:02:42 +03002700 bxt_display_core_init(dev_priv, resume);
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002701 } else if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä770effb2015-07-08 23:45:51 +03002702 mutex_lock(&power_domains->lock);
Ville Syrjälä70722462015-04-10 18:21:28 +03002703 chv_phy_control_init(dev_priv);
Ville Syrjälä770effb2015-07-08 23:45:51 +03002704 mutex_unlock(&power_domains->lock);
Tvrtko Ursulin11a914c2016-10-13 11:03:08 +01002705 } else if (IS_VALLEYVIEW(dev_priv)) {
Daniel Vetter9c065a72014-09-30 10:56:38 +02002706 mutex_lock(&power_domains->lock);
2707 vlv_cmnlane_wa(dev_priv);
2708 mutex_unlock(&power_domains->lock);
2709 }
2710
2711 /* For now, we need the power well to be always enabled. */
2712 intel_display_set_init_power(dev_priv, true);
Imre Deakd314cd42015-11-17 17:44:23 +02002713 /* Disable power support if the user asked so. */
2714 if (!i915.disable_power_well)
2715 intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
Imre Deak30eade12015-11-04 19:24:13 +02002716 intel_power_domains_sync_hw(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02002717 power_domains->initializing = false;
2718}
2719
Daniel Vettere4e76842014-09-30 10:56:42 +02002720/**
Imre Deak73dfc222015-11-17 17:33:53 +02002721 * intel_power_domains_suspend - suspend power domain state
2722 * @dev_priv: i915 device instance
2723 *
2724 * This function prepares the hardware power domain state before entering
2725 * system suspend. It must be paired with intel_power_domains_init_hw().
2726 */
2727void intel_power_domains_suspend(struct drm_i915_private *dev_priv)
2728{
Imre Deakd314cd42015-11-17 17:44:23 +02002729 /*
2730 * Even if power well support was disabled we still want to disable
2731 * power wells while we are system suspended.
2732 */
2733 if (!i915.disable_power_well)
2734 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
Imre Deak2622d792016-02-29 22:49:02 +02002735
Rodrigo Vivib976dc52017-01-23 10:32:37 -08002736 if (IS_GEN9_BC(dev_priv))
Imre Deak2622d792016-02-29 22:49:02 +02002737 skl_display_core_uninit(dev_priv);
Ander Conselvan de Oliveirab817c442016-12-02 10:23:56 +02002738 else if (IS_GEN9_LP(dev_priv))
Imre Deakd7d7c9e2016-04-01 16:02:42 +03002739 bxt_display_core_uninit(dev_priv);
Imre Deak73dfc222015-11-17 17:33:53 +02002740}
2741
Imre Deak8d8c3862017-02-17 17:39:46 +02002742static void intel_power_domains_dump_info(struct drm_i915_private *dev_priv)
2743{
2744 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2745 struct i915_power_well *power_well;
2746
2747 for_each_power_well(dev_priv, power_well) {
2748 enum intel_display_power_domain domain;
2749
2750 DRM_DEBUG_DRIVER("%-25s %d\n",
2751 power_well->name, power_well->count);
2752
2753 for_each_power_domain(domain, power_well->domains)
2754 DRM_DEBUG_DRIVER(" %-23s %d\n",
2755 intel_display_power_domain_str(domain),
2756 power_domains->domain_use_count[domain]);
2757 }
2758}
2759
2760/**
2761 * intel_power_domains_verify_state - verify the HW/SW state for all power wells
2762 * @dev_priv: i915 device instance
2763 *
2764 * Verify if the reference count of each power well matches its HW enabled
2765 * state and the total refcount of the domains it belongs to. This must be
2766 * called after modeset HW state sanitization, which is responsible for
2767 * acquiring reference counts for any power wells in use and disabling the
2768 * ones left on by BIOS but not required by any active output.
2769 */
2770void intel_power_domains_verify_state(struct drm_i915_private *dev_priv)
2771{
2772 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2773 struct i915_power_well *power_well;
2774 bool dump_domain_info;
2775
2776 mutex_lock(&power_domains->lock);
2777
2778 dump_domain_info = false;
2779 for_each_power_well(dev_priv, power_well) {
2780 enum intel_display_power_domain domain;
2781 int domains_count;
2782 bool enabled;
2783
2784 /*
2785 * Power wells not belonging to any domain (like the MISC_IO
2786 * and PW1 power wells) are under FW control, so ignore them,
2787 * since their state can change asynchronously.
2788 */
2789 if (!power_well->domains)
2790 continue;
2791
2792 enabled = power_well->ops->is_enabled(dev_priv, power_well);
2793 if ((power_well->count || power_well->always_on) != enabled)
2794 DRM_ERROR("power well %s state mismatch (refcount %d/enabled %d)",
2795 power_well->name, power_well->count, enabled);
2796
2797 domains_count = 0;
2798 for_each_power_domain(domain, power_well->domains)
2799 domains_count += power_domains->domain_use_count[domain];
2800
2801 if (power_well->count != domains_count) {
2802 DRM_ERROR("power well %s refcount/domain refcount mismatch "
2803 "(refcount %d/domains refcount %d)\n",
2804 power_well->name, power_well->count,
2805 domains_count);
2806 dump_domain_info = true;
2807 }
2808 }
2809
2810 if (dump_domain_info) {
2811 static bool dumped;
2812
2813 if (!dumped) {
2814 intel_power_domains_dump_info(dev_priv);
2815 dumped = true;
2816 }
2817 }
2818
2819 mutex_unlock(&power_domains->lock);
2820}
2821
Imre Deak73dfc222015-11-17 17:33:53 +02002822/**
Daniel Vettere4e76842014-09-30 10:56:42 +02002823 * intel_runtime_pm_get - grab a runtime pm reference
2824 * @dev_priv: i915 device instance
2825 *
2826 * This function grabs a device-level runtime pm reference (mostly used for GEM
2827 * code to ensure the GTT or GT is on) and ensures that it is powered up.
2828 *
2829 * Any runtime pm reference obtained by this function must have a symmetric
2830 * call to intel_runtime_pm_put() to release the reference again.
2831 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02002832void intel_runtime_pm_get(struct drm_i915_private *dev_priv)
2833{
David Weinehall52a05c32016-08-22 13:32:44 +03002834 struct pci_dev *pdev = dev_priv->drm.pdev;
2835 struct device *kdev = &pdev->dev;
Daniel Vetter9c065a72014-09-30 10:56:38 +02002836
David Weinehallc49d13e2016-08-22 13:32:42 +03002837 pm_runtime_get_sync(kdev);
Imre Deak1f814da2015-12-16 02:52:19 +02002838
2839 atomic_inc(&dev_priv->pm.wakeref_count);
Imre Deakc9b88462015-12-15 20:10:34 +02002840 assert_rpm_wakelock_held(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02002841}
2842
Daniel Vettere4e76842014-09-30 10:56:42 +02002843/**
Imre Deak09731282016-02-17 14:17:42 +02002844 * intel_runtime_pm_get_if_in_use - grab a runtime pm reference if device in use
2845 * @dev_priv: i915 device instance
2846 *
2847 * This function grabs a device-level runtime pm reference if the device is
2848 * already in use and ensures that it is powered up.
2849 *
2850 * Any runtime pm reference obtained by this function must have a symmetric
2851 * call to intel_runtime_pm_put() to release the reference again.
2852 */
2853bool intel_runtime_pm_get_if_in_use(struct drm_i915_private *dev_priv)
2854{
David Weinehall52a05c32016-08-22 13:32:44 +03002855 struct pci_dev *pdev = dev_priv->drm.pdev;
2856 struct device *kdev = &pdev->dev;
Imre Deak09731282016-02-17 14:17:42 +02002857
Chris Wilson135dc792016-02-25 21:10:28 +00002858 if (IS_ENABLED(CONFIG_PM)) {
David Weinehallc49d13e2016-08-22 13:32:42 +03002859 int ret = pm_runtime_get_if_in_use(kdev);
Imre Deak09731282016-02-17 14:17:42 +02002860
Chris Wilson135dc792016-02-25 21:10:28 +00002861 /*
2862 * In cases runtime PM is disabled by the RPM core and we get
2863 * an -EINVAL return value we are not supposed to call this
2864 * function, since the power state is undefined. This applies
2865 * atm to the late/early system suspend/resume handlers.
2866 */
2867 WARN_ON_ONCE(ret < 0);
2868 if (ret <= 0)
2869 return false;
2870 }
Imre Deak09731282016-02-17 14:17:42 +02002871
2872 atomic_inc(&dev_priv->pm.wakeref_count);
2873 assert_rpm_wakelock_held(dev_priv);
2874
2875 return true;
2876}
2877
2878/**
Daniel Vettere4e76842014-09-30 10:56:42 +02002879 * intel_runtime_pm_get_noresume - grab a runtime pm reference
2880 * @dev_priv: i915 device instance
2881 *
2882 * This function grabs a device-level runtime pm reference (mostly used for GEM
2883 * code to ensure the GTT or GT is on).
2884 *
2885 * It will _not_ power up the device but instead only check that it's powered
2886 * on. Therefore it is only valid to call this functions from contexts where
2887 * the device is known to be powered up and where trying to power it up would
2888 * result in hilarity and deadlocks. That pretty much means only the system
2889 * suspend/resume code where this is used to grab runtime pm references for
2890 * delayed setup down in work items.
2891 *
2892 * Any runtime pm reference obtained by this function must have a symmetric
2893 * call to intel_runtime_pm_put() to release the reference again.
2894 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02002895void intel_runtime_pm_get_noresume(struct drm_i915_private *dev_priv)
2896{
David Weinehall52a05c32016-08-22 13:32:44 +03002897 struct pci_dev *pdev = dev_priv->drm.pdev;
2898 struct device *kdev = &pdev->dev;
Daniel Vetter9c065a72014-09-30 10:56:38 +02002899
Imre Deakc9b88462015-12-15 20:10:34 +02002900 assert_rpm_wakelock_held(dev_priv);
David Weinehallc49d13e2016-08-22 13:32:42 +03002901 pm_runtime_get_noresume(kdev);
Imre Deak1f814da2015-12-16 02:52:19 +02002902
2903 atomic_inc(&dev_priv->pm.wakeref_count);
Daniel Vetter9c065a72014-09-30 10:56:38 +02002904}
2905
Daniel Vettere4e76842014-09-30 10:56:42 +02002906/**
2907 * intel_runtime_pm_put - release a runtime pm reference
2908 * @dev_priv: i915 device instance
2909 *
2910 * This function drops the device-level runtime pm reference obtained by
2911 * intel_runtime_pm_get() and might power down the corresponding
2912 * hardware block right away if this is the last reference.
2913 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02002914void intel_runtime_pm_put(struct drm_i915_private *dev_priv)
2915{
David Weinehall52a05c32016-08-22 13:32:44 +03002916 struct pci_dev *pdev = dev_priv->drm.pdev;
2917 struct device *kdev = &pdev->dev;
Daniel Vetter9c065a72014-09-30 10:56:38 +02002918
Imre Deak542db3c2015-12-15 20:10:36 +02002919 assert_rpm_wakelock_held(dev_priv);
Chris Wilson2eedfc72016-10-24 13:42:17 +01002920 atomic_dec(&dev_priv->pm.wakeref_count);
Imre Deak1f814da2015-12-16 02:52:19 +02002921
David Weinehallc49d13e2016-08-22 13:32:42 +03002922 pm_runtime_mark_last_busy(kdev);
2923 pm_runtime_put_autosuspend(kdev);
Daniel Vetter9c065a72014-09-30 10:56:38 +02002924}
2925
Daniel Vettere4e76842014-09-30 10:56:42 +02002926/**
2927 * intel_runtime_pm_enable - enable runtime pm
2928 * @dev_priv: i915 device instance
2929 *
2930 * This function enables runtime pm at the end of the driver load sequence.
2931 *
2932 * Note that this function does currently not enable runtime pm for the
2933 * subordinate display power domains. That is only done on the first modeset
2934 * using intel_display_set_init_power().
2935 */
Daniel Vetterf458ebb2014-09-30 10:56:39 +02002936void intel_runtime_pm_enable(struct drm_i915_private *dev_priv)
Daniel Vetter9c065a72014-09-30 10:56:38 +02002937{
David Weinehall52a05c32016-08-22 13:32:44 +03002938 struct pci_dev *pdev = dev_priv->drm.pdev;
David Weinehall52a05c32016-08-22 13:32:44 +03002939 struct device *kdev = &pdev->dev;
Daniel Vetter9c065a72014-09-30 10:56:38 +02002940
David Weinehallc49d13e2016-08-22 13:32:42 +03002941 pm_runtime_set_autosuspend_delay(kdev, 10000); /* 10s */
2942 pm_runtime_mark_last_busy(kdev);
Imre Deakcbc68dc2015-12-17 19:04:33 +02002943
Imre Deak25b181b2015-12-17 13:44:56 +02002944 /*
2945 * Take a permanent reference to disable the RPM functionality and drop
2946 * it only when unloading the driver. Use the low level get/put helpers,
2947 * so the driver's own RPM reference tracking asserts also work on
2948 * platforms without RPM support.
2949 */
Tvrtko Ursulin6772ffe2016-10-13 11:02:55 +01002950 if (!HAS_RUNTIME_PM(dev_priv)) {
David Weinehallc49d13e2016-08-22 13:32:42 +03002951 pm_runtime_dont_use_autosuspend(kdev);
2952 pm_runtime_get_sync(kdev);
Imre Deakcbc68dc2015-12-17 19:04:33 +02002953 } else {
David Weinehallc49d13e2016-08-22 13:32:42 +03002954 pm_runtime_use_autosuspend(kdev);
Imre Deakcbc68dc2015-12-17 19:04:33 +02002955 }
Daniel Vetter9c065a72014-09-30 10:56:38 +02002956
Imre Deakaabee1b2015-12-15 20:10:29 +02002957 /*
2958 * The core calls the driver load handler with an RPM reference held.
2959 * We drop that here and will reacquire it during unloading in
2960 * intel_power_domains_fini().
2961 */
David Weinehallc49d13e2016-08-22 13:32:42 +03002962 pm_runtime_put_autosuspend(kdev);
Daniel Vetter9c065a72014-09-30 10:56:38 +02002963}