blob: 10978cb87700a5001e3f97c436685c37eb86b026 [file] [log] [blame]
Daniel Vetter9c065a72014-09-30 10:56:38 +02001/*
2 * Copyright © 2012-2014 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 *
23 * Authors:
24 * Eugeni Dodonov <eugeni.dodonov@intel.com>
25 * Daniel Vetter <daniel.vetter@ffwll.ch>
26 *
27 */
28
29#include <linux/pm_runtime.h>
30#include <linux/vgaarb.h>
31
32#include "i915_drv.h"
33#include "intel_drv.h"
Daniel Vetter9c065a72014-09-30 10:56:38 +020034
Daniel Vettere4e76842014-09-30 10:56:42 +020035/**
36 * DOC: runtime pm
37 *
38 * The i915 driver supports dynamic enabling and disabling of entire hardware
39 * blocks at runtime. This is especially important on the display side where
40 * software is supposed to control many power gates manually on recent hardware,
41 * since on the GT side a lot of the power management is done by the hardware.
42 * But even there some manual control at the device level is required.
43 *
44 * Since i915 supports a diverse set of platforms with a unified codebase and
45 * hardware engineers just love to shuffle functionality around between power
46 * domains there's a sizeable amount of indirection required. This file provides
47 * generic functions to the driver for grabbing and releasing references for
48 * abstract power domains. It then maps those to the actual power wells
49 * present for a given platform.
50 */
51
Daniel Vetter9c065a72014-09-30 10:56:38 +020052#define for_each_power_well(i, power_well, domain_mask, power_domains) \
53 for (i = 0; \
54 i < (power_domains)->power_well_count && \
55 ((power_well) = &(power_domains)->power_wells[i]); \
56 i++) \
Jani Nikula95150bd2015-11-24 21:21:56 +020057 for_each_if ((power_well)->domains & (domain_mask))
Daniel Vetter9c065a72014-09-30 10:56:38 +020058
59#define for_each_power_well_rev(i, power_well, domain_mask, power_domains) \
60 for (i = (power_domains)->power_well_count - 1; \
61 i >= 0 && ((power_well) = &(power_domains)->power_wells[i]);\
62 i--) \
Jani Nikula95150bd2015-11-24 21:21:56 +020063 for_each_if ((power_well)->domains & (domain_mask))
Daniel Vetter9c065a72014-09-30 10:56:38 +020064
Suketu Shah5aefb232015-04-16 14:22:10 +053065bool intel_display_power_well_is_enabled(struct drm_i915_private *dev_priv,
66 int power_well_id);
67
Daniel Stone9895ad02015-11-20 15:55:33 +000068const char *
69intel_display_power_domain_str(enum intel_display_power_domain domain)
70{
71 switch (domain) {
72 case POWER_DOMAIN_PIPE_A:
73 return "PIPE_A";
74 case POWER_DOMAIN_PIPE_B:
75 return "PIPE_B";
76 case POWER_DOMAIN_PIPE_C:
77 return "PIPE_C";
78 case POWER_DOMAIN_PIPE_A_PANEL_FITTER:
79 return "PIPE_A_PANEL_FITTER";
80 case POWER_DOMAIN_PIPE_B_PANEL_FITTER:
81 return "PIPE_B_PANEL_FITTER";
82 case POWER_DOMAIN_PIPE_C_PANEL_FITTER:
83 return "PIPE_C_PANEL_FITTER";
84 case POWER_DOMAIN_TRANSCODER_A:
85 return "TRANSCODER_A";
86 case POWER_DOMAIN_TRANSCODER_B:
87 return "TRANSCODER_B";
88 case POWER_DOMAIN_TRANSCODER_C:
89 return "TRANSCODER_C";
90 case POWER_DOMAIN_TRANSCODER_EDP:
91 return "TRANSCODER_EDP";
Jani Nikula4d1de972016-03-18 17:05:42 +020092 case POWER_DOMAIN_TRANSCODER_DSI_A:
93 return "TRANSCODER_DSI_A";
94 case POWER_DOMAIN_TRANSCODER_DSI_C:
95 return "TRANSCODER_DSI_C";
Daniel Stone9895ad02015-11-20 15:55:33 +000096 case POWER_DOMAIN_PORT_DDI_A_LANES:
97 return "PORT_DDI_A_LANES";
98 case POWER_DOMAIN_PORT_DDI_B_LANES:
99 return "PORT_DDI_B_LANES";
100 case POWER_DOMAIN_PORT_DDI_C_LANES:
101 return "PORT_DDI_C_LANES";
102 case POWER_DOMAIN_PORT_DDI_D_LANES:
103 return "PORT_DDI_D_LANES";
104 case POWER_DOMAIN_PORT_DDI_E_LANES:
105 return "PORT_DDI_E_LANES";
106 case POWER_DOMAIN_PORT_DSI:
107 return "PORT_DSI";
108 case POWER_DOMAIN_PORT_CRT:
109 return "PORT_CRT";
110 case POWER_DOMAIN_PORT_OTHER:
111 return "PORT_OTHER";
112 case POWER_DOMAIN_VGA:
113 return "VGA";
114 case POWER_DOMAIN_AUDIO:
115 return "AUDIO";
116 case POWER_DOMAIN_PLLS:
117 return "PLLS";
118 case POWER_DOMAIN_AUX_A:
119 return "AUX_A";
120 case POWER_DOMAIN_AUX_B:
121 return "AUX_B";
122 case POWER_DOMAIN_AUX_C:
123 return "AUX_C";
124 case POWER_DOMAIN_AUX_D:
125 return "AUX_D";
126 case POWER_DOMAIN_GMBUS:
127 return "GMBUS";
128 case POWER_DOMAIN_INIT:
129 return "INIT";
130 case POWER_DOMAIN_MODESET:
131 return "MODESET";
132 default:
133 MISSING_CASE(domain);
134 return "?";
135 }
136}
137
Damien Lespiaue8ca9322015-07-30 18:20:26 -0300138static void intel_power_well_enable(struct drm_i915_private *dev_priv,
139 struct i915_power_well *power_well)
140{
141 DRM_DEBUG_KMS("enabling %s\n", power_well->name);
142 power_well->ops->enable(dev_priv, power_well);
143 power_well->hw_enabled = true;
144}
145
Damien Lespiaudcddab32015-07-30 18:20:27 -0300146static void intel_power_well_disable(struct drm_i915_private *dev_priv,
147 struct i915_power_well *power_well)
148{
149 DRM_DEBUG_KMS("disabling %s\n", power_well->name);
150 power_well->hw_enabled = false;
151 power_well->ops->disable(dev_priv, power_well);
152}
153
Imre Deakb409ca92016-06-13 16:44:33 +0300154static void intel_power_well_get(struct drm_i915_private *dev_priv,
155 struct i915_power_well *power_well)
156{
157 if (!power_well->count++)
158 intel_power_well_enable(dev_priv, power_well);
159}
160
161static void intel_power_well_put(struct drm_i915_private *dev_priv,
162 struct i915_power_well *power_well)
163{
164 WARN(!power_well->count, "Use count on power well %s is already zero",
165 power_well->name);
166
167 if (!--power_well->count)
168 intel_power_well_disable(dev_priv, power_well);
169}
170
Daniel Vettere4e76842014-09-30 10:56:42 +0200171/*
Daniel Vetter9c065a72014-09-30 10:56:38 +0200172 * We should only use the power well if we explicitly asked the hardware to
173 * enable it, so check if it's enabled and also check if we've requested it to
174 * be enabled.
175 */
176static bool hsw_power_well_enabled(struct drm_i915_private *dev_priv,
177 struct i915_power_well *power_well)
178{
179 return I915_READ(HSW_PWR_WELL_DRIVER) ==
180 (HSW_PWR_WELL_ENABLE_REQUEST | HSW_PWR_WELL_STATE_ENABLED);
181}
182
Daniel Vettere4e76842014-09-30 10:56:42 +0200183/**
184 * __intel_display_power_is_enabled - unlocked check for a power domain
185 * @dev_priv: i915 device instance
186 * @domain: power domain to check
187 *
188 * This is the unlocked version of intel_display_power_is_enabled() and should
189 * only be used from error capture and recovery code where deadlocks are
190 * possible.
191 *
192 * Returns:
193 * True when the power domain is enabled, false otherwise.
194 */
Daniel Vetterf458ebb2014-09-30 10:56:39 +0200195bool __intel_display_power_is_enabled(struct drm_i915_private *dev_priv,
196 enum intel_display_power_domain domain)
Daniel Vetter9c065a72014-09-30 10:56:38 +0200197{
198 struct i915_power_domains *power_domains;
199 struct i915_power_well *power_well;
200 bool is_enabled;
201 int i;
202
203 if (dev_priv->pm.suspended)
204 return false;
205
206 power_domains = &dev_priv->power_domains;
207
208 is_enabled = true;
209
210 for_each_power_well_rev(i, power_well, BIT(domain), power_domains) {
211 if (power_well->always_on)
212 continue;
213
214 if (!power_well->hw_enabled) {
215 is_enabled = false;
216 break;
217 }
218 }
219
220 return is_enabled;
221}
222
Daniel Vettere4e76842014-09-30 10:56:42 +0200223/**
Damien Lespiauf61ccae2014-11-25 13:45:41 +0000224 * intel_display_power_is_enabled - check for a power domain
Daniel Vettere4e76842014-09-30 10:56:42 +0200225 * @dev_priv: i915 device instance
226 * @domain: power domain to check
227 *
228 * This function can be used to check the hw power domain state. It is mostly
229 * used in hardware state readout functions. Everywhere else code should rely
230 * upon explicit power domain reference counting to ensure that the hardware
231 * block is powered up before accessing it.
232 *
233 * Callers must hold the relevant modesetting locks to ensure that concurrent
234 * threads can't disable the power well while the caller tries to read a few
235 * registers.
236 *
237 * Returns:
238 * True when the power domain is enabled, false otherwise.
239 */
Daniel Vetterf458ebb2014-09-30 10:56:39 +0200240bool intel_display_power_is_enabled(struct drm_i915_private *dev_priv,
241 enum intel_display_power_domain domain)
Daniel Vetter9c065a72014-09-30 10:56:38 +0200242{
243 struct i915_power_domains *power_domains;
244 bool ret;
245
246 power_domains = &dev_priv->power_domains;
247
248 mutex_lock(&power_domains->lock);
Daniel Vetterf458ebb2014-09-30 10:56:39 +0200249 ret = __intel_display_power_is_enabled(dev_priv, domain);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200250 mutex_unlock(&power_domains->lock);
251
252 return ret;
253}
254
Daniel Vettere4e76842014-09-30 10:56:42 +0200255/**
256 * intel_display_set_init_power - set the initial power domain state
257 * @dev_priv: i915 device instance
258 * @enable: whether to enable or disable the initial power domain state
259 *
260 * For simplicity our driver load/unload and system suspend/resume code assumes
261 * that all power domains are always enabled. This functions controls the state
262 * of this little hack. While the initial power domain state is enabled runtime
263 * pm is effectively disabled.
264 */
Daniel Vetterd9bc89d92014-09-30 10:56:40 +0200265void intel_display_set_init_power(struct drm_i915_private *dev_priv,
266 bool enable)
267{
268 if (dev_priv->power_domains.init_power_on == enable)
269 return;
270
271 if (enable)
272 intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
273 else
274 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
275
276 dev_priv->power_domains.init_power_on = enable;
277}
278
Daniel Vetter9c065a72014-09-30 10:56:38 +0200279/*
280 * Starting with Haswell, we have a "Power Down Well" that can be turned off
281 * when not needed anymore. We have 4 registers that can request the power well
282 * to be enabled, and it will only be disabled if none of the registers is
283 * requesting it to be enabled.
284 */
285static void hsw_power_well_post_enable(struct drm_i915_private *dev_priv)
286{
287 struct drm_device *dev = dev_priv->dev;
288
289 /*
290 * After we re-enable the power well, if we touch VGA register 0x3d5
291 * we'll get unclaimed register interrupts. This stops after we write
292 * anything to the VGA MSR register. The vgacon module uses this
293 * register all the time, so if we unbind our driver and, as a
294 * consequence, bind vgacon, we'll get stuck in an infinite loop at
295 * console_unlock(). So make here we touch the VGA MSR register, making
296 * sure vgacon can keep working normally without triggering interrupts
297 * and error messages.
298 */
299 vga_get_uninterruptible(dev->pdev, VGA_RSRC_LEGACY_IO);
300 outb(inb(VGA_MSR_READ), VGA_MSR_WRITE);
301 vga_put(dev->pdev, VGA_RSRC_LEGACY_IO);
302
Damien Lespiau25400392015-03-06 18:50:52 +0000303 if (IS_BROADWELL(dev))
Damien Lespiau4c6c03b2015-03-06 18:50:48 +0000304 gen8_irq_power_well_post_enable(dev_priv,
305 1 << PIPE_C | 1 << PIPE_B);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200306}
307
Ville Syrjäläaae8ba82016-02-19 20:47:30 +0200308static void hsw_power_well_pre_disable(struct drm_i915_private *dev_priv)
309{
310 if (IS_BROADWELL(dev_priv))
311 gen8_irq_power_well_pre_disable(dev_priv,
312 1 << PIPE_C | 1 << PIPE_B);
313}
314
Damien Lespiaud14c0342015-03-06 18:50:51 +0000315static void skl_power_well_post_enable(struct drm_i915_private *dev_priv,
316 struct i915_power_well *power_well)
317{
318 struct drm_device *dev = dev_priv->dev;
319
320 /*
321 * After we re-enable the power well, if we touch VGA register 0x3d5
322 * we'll get unclaimed register interrupts. This stops after we write
323 * anything to the VGA MSR register. The vgacon module uses this
324 * register all the time, so if we unbind our driver and, as a
325 * consequence, bind vgacon, we'll get stuck in an infinite loop at
326 * console_unlock(). So make here we touch the VGA MSR register, making
327 * sure vgacon can keep working normally without triggering interrupts
328 * and error messages.
329 */
330 if (power_well->data == SKL_DISP_PW_2) {
331 vga_get_uninterruptible(dev->pdev, VGA_RSRC_LEGACY_IO);
332 outb(inb(VGA_MSR_READ), VGA_MSR_WRITE);
333 vga_put(dev->pdev, VGA_RSRC_LEGACY_IO);
334
335 gen8_irq_power_well_post_enable(dev_priv,
336 1 << PIPE_C | 1 << PIPE_B);
337 }
Damien Lespiaud14c0342015-03-06 18:50:51 +0000338}
339
Ville Syrjäläaae8ba82016-02-19 20:47:30 +0200340static void skl_power_well_pre_disable(struct drm_i915_private *dev_priv,
341 struct i915_power_well *power_well)
342{
343 if (power_well->data == SKL_DISP_PW_2)
344 gen8_irq_power_well_pre_disable(dev_priv,
345 1 << PIPE_C | 1 << PIPE_B);
346}
347
Daniel Vetter9c065a72014-09-30 10:56:38 +0200348static void hsw_set_power_well(struct drm_i915_private *dev_priv,
349 struct i915_power_well *power_well, bool enable)
350{
351 bool is_enabled, enable_requested;
352 uint32_t tmp;
353
354 tmp = I915_READ(HSW_PWR_WELL_DRIVER);
355 is_enabled = tmp & HSW_PWR_WELL_STATE_ENABLED;
356 enable_requested = tmp & HSW_PWR_WELL_ENABLE_REQUEST;
357
358 if (enable) {
359 if (!enable_requested)
360 I915_WRITE(HSW_PWR_WELL_DRIVER,
361 HSW_PWR_WELL_ENABLE_REQUEST);
362
363 if (!is_enabled) {
364 DRM_DEBUG_KMS("Enabling power well\n");
365 if (wait_for((I915_READ(HSW_PWR_WELL_DRIVER) &
366 HSW_PWR_WELL_STATE_ENABLED), 20))
367 DRM_ERROR("Timeout enabling power well\n");
Paulo Zanoni6d729bf2014-10-07 16:11:11 -0300368 hsw_power_well_post_enable(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200369 }
370
Daniel Vetter9c065a72014-09-30 10:56:38 +0200371 } else {
372 if (enable_requested) {
Ville Syrjäläaae8ba82016-02-19 20:47:30 +0200373 hsw_power_well_pre_disable(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200374 I915_WRITE(HSW_PWR_WELL_DRIVER, 0);
375 POSTING_READ(HSW_PWR_WELL_DRIVER);
376 DRM_DEBUG_KMS("Requesting to disable the power well\n");
377 }
378 }
379}
380
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000381#define SKL_DISPLAY_POWERWELL_2_POWER_DOMAINS ( \
382 BIT(POWER_DOMAIN_TRANSCODER_A) | \
383 BIT(POWER_DOMAIN_PIPE_B) | \
384 BIT(POWER_DOMAIN_TRANSCODER_B) | \
385 BIT(POWER_DOMAIN_PIPE_C) | \
386 BIT(POWER_DOMAIN_TRANSCODER_C) | \
387 BIT(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
388 BIT(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
Patrik Jakobsson6331a702015-11-09 16:48:21 +0100389 BIT(POWER_DOMAIN_PORT_DDI_B_LANES) | \
390 BIT(POWER_DOMAIN_PORT_DDI_C_LANES) | \
391 BIT(POWER_DOMAIN_PORT_DDI_D_LANES) | \
392 BIT(POWER_DOMAIN_PORT_DDI_E_LANES) | \
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000393 BIT(POWER_DOMAIN_AUX_B) | \
394 BIT(POWER_DOMAIN_AUX_C) | \
395 BIT(POWER_DOMAIN_AUX_D) | \
396 BIT(POWER_DOMAIN_AUDIO) | \
397 BIT(POWER_DOMAIN_VGA) | \
398 BIT(POWER_DOMAIN_INIT))
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000399#define SKL_DISPLAY_DDI_A_E_POWER_DOMAINS ( \
Patrik Jakobsson6331a702015-11-09 16:48:21 +0100400 BIT(POWER_DOMAIN_PORT_DDI_A_LANES) | \
401 BIT(POWER_DOMAIN_PORT_DDI_E_LANES) | \
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000402 BIT(POWER_DOMAIN_INIT))
403#define SKL_DISPLAY_DDI_B_POWER_DOMAINS ( \
Patrik Jakobsson6331a702015-11-09 16:48:21 +0100404 BIT(POWER_DOMAIN_PORT_DDI_B_LANES) | \
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000405 BIT(POWER_DOMAIN_INIT))
406#define SKL_DISPLAY_DDI_C_POWER_DOMAINS ( \
Patrik Jakobsson6331a702015-11-09 16:48:21 +0100407 BIT(POWER_DOMAIN_PORT_DDI_C_LANES) | \
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000408 BIT(POWER_DOMAIN_INIT))
409#define SKL_DISPLAY_DDI_D_POWER_DOMAINS ( \
Patrik Jakobsson6331a702015-11-09 16:48:21 +0100410 BIT(POWER_DOMAIN_PORT_DDI_D_LANES) | \
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000411 BIT(POWER_DOMAIN_INIT))
Patrik Jakobsson9f836f92015-11-16 16:20:01 +0100412#define SKL_DISPLAY_DC_OFF_POWER_DOMAINS ( \
413 SKL_DISPLAY_POWERWELL_2_POWER_DOMAINS | \
414 BIT(POWER_DOMAIN_MODESET) | \
415 BIT(POWER_DOMAIN_AUX_A) | \
416 BIT(POWER_DOMAIN_INIT))
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000417
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +0530418#define BXT_DISPLAY_POWERWELL_2_POWER_DOMAINS ( \
419 BIT(POWER_DOMAIN_TRANSCODER_A) | \
420 BIT(POWER_DOMAIN_PIPE_B) | \
421 BIT(POWER_DOMAIN_TRANSCODER_B) | \
422 BIT(POWER_DOMAIN_PIPE_C) | \
423 BIT(POWER_DOMAIN_TRANSCODER_C) | \
424 BIT(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
425 BIT(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
Patrik Jakobsson6331a702015-11-09 16:48:21 +0100426 BIT(POWER_DOMAIN_PORT_DDI_B_LANES) | \
427 BIT(POWER_DOMAIN_PORT_DDI_C_LANES) | \
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +0530428 BIT(POWER_DOMAIN_AUX_B) | \
429 BIT(POWER_DOMAIN_AUX_C) | \
430 BIT(POWER_DOMAIN_AUDIO) | \
431 BIT(POWER_DOMAIN_VGA) | \
Ville Syrjäläf0ab43e2015-11-09 16:48:19 +0100432 BIT(POWER_DOMAIN_GMBUS) | \
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +0530433 BIT(POWER_DOMAIN_INIT))
Patrik Jakobsson9f836f92015-11-16 16:20:01 +0100434#define BXT_DISPLAY_DC_OFF_POWER_DOMAINS ( \
435 BXT_DISPLAY_POWERWELL_2_POWER_DOMAINS | \
436 BIT(POWER_DOMAIN_MODESET) | \
437 BIT(POWER_DOMAIN_AUX_A) | \
438 BIT(POWER_DOMAIN_INIT))
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +0530439
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530440static void assert_can_enable_dc9(struct drm_i915_private *dev_priv)
441{
Imre Deakbfcdabe2016-04-01 16:02:37 +0300442 WARN_ONCE((I915_READ(DC_STATE_EN) & DC_STATE_EN_DC9),
443 "DC9 already programmed to be enabled.\n");
444 WARN_ONCE(I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC5,
445 "DC5 still not disabled to enable DC9.\n");
446 WARN_ONCE(I915_READ(HSW_PWR_WELL_DRIVER), "Power well on.\n");
447 WARN_ONCE(intel_irqs_enabled(dev_priv),
448 "Interrupts not disabled yet.\n");
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530449
450 /*
451 * TODO: check for the following to verify the conditions to enter DC9
452 * state are satisfied:
453 * 1] Check relevant display engine registers to verify if mode set
454 * disable sequence was followed.
455 * 2] Check if display uninitialize sequence is initialized.
456 */
457}
458
459static void assert_can_disable_dc9(struct drm_i915_private *dev_priv)
460{
Imre Deakbfcdabe2016-04-01 16:02:37 +0300461 WARN_ONCE(intel_irqs_enabled(dev_priv),
462 "Interrupts not disabled yet.\n");
463 WARN_ONCE(I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC5,
464 "DC5 still not disabled.\n");
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530465
466 /*
467 * TODO: check for the following to verify DC9 state was indeed
468 * entered before programming to disable it:
469 * 1] Check relevant display engine registers to verify if mode
470 * set disable sequence was followed.
471 * 2] Check if display uninitialize sequence is initialized.
472 */
473}
474
Mika Kuoppala779cb5d2016-02-18 17:58:09 +0200475static void gen9_write_dc_state(struct drm_i915_private *dev_priv,
476 u32 state)
477{
478 int rewrites = 0;
479 int rereads = 0;
480 u32 v;
481
482 I915_WRITE(DC_STATE_EN, state);
483
484 /* It has been observed that disabling the dc6 state sometimes
485 * doesn't stick and dmc keeps returning old value. Make sure
486 * the write really sticks enough times and also force rewrite until
487 * we are confident that state is exactly what we want.
488 */
489 do {
490 v = I915_READ(DC_STATE_EN);
491
492 if (v != state) {
493 I915_WRITE(DC_STATE_EN, state);
494 rewrites++;
495 rereads = 0;
496 } else if (rereads++ > 5) {
497 break;
498 }
499
500 } while (rewrites < 100);
501
502 if (v != state)
503 DRM_ERROR("Writing dc state to 0x%x failed, now 0x%x\n",
504 state, v);
505
506 /* Most of the times we need one retry, avoid spam */
507 if (rewrites > 1)
508 DRM_DEBUG_KMS("Rewrote dc state to 0x%x %d times\n",
509 state, rewrites);
510}
511
Imre Deakda2f41d2016-04-20 20:27:56 +0300512static u32 gen9_dc_mask(struct drm_i915_private *dev_priv)
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530513{
Imre Deakda2f41d2016-04-20 20:27:56 +0300514 u32 mask;
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530515
Imre Deak13ae3a02015-11-04 19:24:16 +0200516 mask = DC_STATE_EN_UPTO_DC5;
517 if (IS_BROXTON(dev_priv))
518 mask |= DC_STATE_EN_DC9;
519 else
520 mask |= DC_STATE_EN_UPTO_DC6;
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530521
Imre Deakda2f41d2016-04-20 20:27:56 +0300522 return mask;
523}
524
525void gen9_sanitize_dc_state(struct drm_i915_private *dev_priv)
526{
527 u32 val;
528
529 val = I915_READ(DC_STATE_EN) & gen9_dc_mask(dev_priv);
530
531 DRM_DEBUG_KMS("Resetting DC state tracking from %02x to %02x\n",
532 dev_priv->csr.dc_state, val);
533 dev_priv->csr.dc_state = val;
534}
535
536static void gen9_set_dc_state(struct drm_i915_private *dev_priv, uint32_t state)
537{
538 uint32_t val;
539 uint32_t mask;
540
Imre Deaka37baf32016-02-29 22:49:03 +0200541 if (WARN_ON_ONCE(state & ~dev_priv->csr.allowed_dc_mask))
542 state &= dev_priv->csr.allowed_dc_mask;
Patrik Jakobsson443646c2015-11-16 15:01:06 +0100543
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530544 val = I915_READ(DC_STATE_EN);
Imre Deakda2f41d2016-04-20 20:27:56 +0300545 mask = gen9_dc_mask(dev_priv);
Imre Deak13ae3a02015-11-04 19:24:16 +0200546 DRM_DEBUG_KMS("Setting DC state from %02x to %02x\n",
547 val & mask, state);
Patrik Jakobsson832dba82016-02-18 17:21:11 +0200548
549 /* Check if DMC is ignoring our DC state requests */
550 if ((val & mask) != dev_priv->csr.dc_state)
551 DRM_ERROR("DC state mismatch (0x%x -> 0x%x)\n",
552 dev_priv->csr.dc_state, val & mask);
553
Imre Deak13ae3a02015-11-04 19:24:16 +0200554 val &= ~mask;
555 val |= state;
Mika Kuoppala779cb5d2016-02-18 17:58:09 +0200556
557 gen9_write_dc_state(dev_priv, val);
Patrik Jakobsson832dba82016-02-18 17:21:11 +0200558
559 dev_priv->csr.dc_state = val & mask;
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530560}
561
Imre Deak13ae3a02015-11-04 19:24:16 +0200562void bxt_enable_dc9(struct drm_i915_private *dev_priv)
563{
564 assert_can_enable_dc9(dev_priv);
565
566 DRM_DEBUG_KMS("Enabling DC9\n");
567
568 gen9_set_dc_state(dev_priv, DC_STATE_EN_DC9);
569}
570
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530571void bxt_disable_dc9(struct drm_i915_private *dev_priv)
572{
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530573 assert_can_disable_dc9(dev_priv);
574
575 DRM_DEBUG_KMS("Disabling DC9\n");
576
Imre Deak13ae3a02015-11-04 19:24:16 +0200577 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530578}
579
Daniel Vetteraf5fead2015-10-28 23:58:57 +0200580static void assert_csr_loaded(struct drm_i915_private *dev_priv)
581{
582 WARN_ONCE(!I915_READ(CSR_PROGRAM(0)),
583 "CSR program storage start is NULL\n");
584 WARN_ONCE(!I915_READ(CSR_SSP_BASE), "CSR SSP Base Not fine\n");
585 WARN_ONCE(!I915_READ(CSR_HTP_SKL), "CSR HTP Not fine\n");
586}
587
Suketu Shah5aefb232015-04-16 14:22:10 +0530588static void assert_can_enable_dc5(struct drm_i915_private *dev_priv)
Suketu Shahdc174302015-04-17 19:46:16 +0530589{
Suketu Shah5aefb232015-04-16 14:22:10 +0530590 bool pg2_enabled = intel_display_power_well_is_enabled(dev_priv,
591 SKL_DISP_PW_2);
592
Jesse Barnes6ff8ab02015-09-10 08:20:28 -0700593 WARN_ONCE(pg2_enabled, "PG2 not disabled to enable DC5.\n");
Suketu Shah5aefb232015-04-16 14:22:10 +0530594
Jesse Barnes6ff8ab02015-09-10 08:20:28 -0700595 WARN_ONCE((I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC5),
596 "DC5 already programmed to be enabled.\n");
Imre Deakc9b88462015-12-15 20:10:34 +0200597 assert_rpm_wakelock_held(dev_priv);
Suketu Shah5aefb232015-04-16 14:22:10 +0530598
599 assert_csr_loaded(dev_priv);
600}
601
Imre Deakf62c79b2016-04-20 20:27:57 +0300602void gen9_enable_dc5(struct drm_i915_private *dev_priv)
Suketu Shah5aefb232015-04-16 14:22:10 +0530603{
Suketu Shah5aefb232015-04-16 14:22:10 +0530604 assert_can_enable_dc5(dev_priv);
A.Sunil Kamath6b457d32015-04-16 14:22:09 +0530605
606 DRM_DEBUG_KMS("Enabling DC5\n");
607
Imre Deak13ae3a02015-11-04 19:24:16 +0200608 gen9_set_dc_state(dev_priv, DC_STATE_EN_UPTO_DC5);
Suketu Shahdc174302015-04-17 19:46:16 +0530609}
610
Suketu Shah93c7cb62015-04-16 14:22:13 +0530611static void assert_can_enable_dc6(struct drm_i915_private *dev_priv)
Suketu Shahf75a1982015-04-16 14:22:11 +0530612{
Jesse Barnes6ff8ab02015-09-10 08:20:28 -0700613 WARN_ONCE(I915_READ(UTIL_PIN_CTL) & UTIL_PIN_ENABLE,
614 "Backlight is not disabled.\n");
615 WARN_ONCE((I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC6),
616 "DC6 already programmed to be enabled.\n");
Suketu Shah93c7cb62015-04-16 14:22:13 +0530617
618 assert_csr_loaded(dev_priv);
619}
620
Animesh Manna0a9d2be2015-09-29 11:01:59 +0530621void skl_enable_dc6(struct drm_i915_private *dev_priv)
Suketu Shah93c7cb62015-04-16 14:22:13 +0530622{
Suketu Shah93c7cb62015-04-16 14:22:13 +0530623 assert_can_enable_dc6(dev_priv);
A.Sunil Kamath74b4f372015-04-16 14:22:12 +0530624
625 DRM_DEBUG_KMS("Enabling DC6\n");
626
Imre Deak13ae3a02015-11-04 19:24:16 +0200627 gen9_set_dc_state(dev_priv, DC_STATE_EN_UPTO_DC6);
628
Suketu Shahf75a1982015-04-16 14:22:11 +0530629}
630
Animesh Manna0a9d2be2015-09-29 11:01:59 +0530631void skl_disable_dc6(struct drm_i915_private *dev_priv)
Suketu Shahf75a1982015-04-16 14:22:11 +0530632{
A.Sunil Kamath74b4f372015-04-16 14:22:12 +0530633 DRM_DEBUG_KMS("Disabling DC6\n");
634
Imre Deak13ae3a02015-11-04 19:24:16 +0200635 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
Suketu Shahf75a1982015-04-16 14:22:11 +0530636}
637
Imre Deakc6782b72016-04-05 13:26:05 +0300638static void
639gen9_sanitize_power_well_requests(struct drm_i915_private *dev_priv,
640 struct i915_power_well *power_well)
641{
642 enum skl_disp_power_wells power_well_id = power_well->data;
643 u32 val;
644 u32 mask;
645
646 mask = SKL_POWER_WELL_REQ(power_well_id);
647
648 val = I915_READ(HSW_PWR_WELL_KVMR);
649 if (WARN_ONCE(val & mask, "Clearing unexpected KVMR request for %s\n",
650 power_well->name))
651 I915_WRITE(HSW_PWR_WELL_KVMR, val & ~mask);
652
653 val = I915_READ(HSW_PWR_WELL_BIOS);
654 val |= I915_READ(HSW_PWR_WELL_DEBUG);
655
656 if (!(val & mask))
657 return;
658
659 /*
660 * DMC is known to force on the request bits for power well 1 on SKL
661 * and BXT and the misc IO power well on SKL but we don't expect any
662 * other request bits to be set, so WARN for those.
663 */
664 if (power_well_id == SKL_DISP_PW_1 ||
Imre Deak80dbe992016-04-19 13:00:36 +0300665 ((IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv)) &&
666 power_well_id == SKL_DISP_PW_MISC_IO))
Imre Deakc6782b72016-04-05 13:26:05 +0300667 DRM_DEBUG_DRIVER("Clearing auxiliary requests for %s forced on "
668 "by DMC\n", power_well->name);
669 else
670 WARN_ONCE(1, "Clearing unexpected auxiliary requests for %s\n",
671 power_well->name);
672
673 I915_WRITE(HSW_PWR_WELL_BIOS, val & ~mask);
674 I915_WRITE(HSW_PWR_WELL_DEBUG, val & ~mask);
675}
676
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000677static void skl_set_power_well(struct drm_i915_private *dev_priv,
678 struct i915_power_well *power_well, bool enable)
679{
680 uint32_t tmp, fuse_status;
681 uint32_t req_mask, state_mask;
Damien Lespiau2a518352015-03-06 18:50:49 +0000682 bool is_enabled, enable_requested, check_fuse_status = false;
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000683
684 tmp = I915_READ(HSW_PWR_WELL_DRIVER);
685 fuse_status = I915_READ(SKL_FUSE_STATUS);
686
687 switch (power_well->data) {
688 case SKL_DISP_PW_1:
689 if (wait_for((I915_READ(SKL_FUSE_STATUS) &
690 SKL_FUSE_PG0_DIST_STATUS), 1)) {
691 DRM_ERROR("PG0 not enabled\n");
692 return;
693 }
694 break;
695 case SKL_DISP_PW_2:
696 if (!(fuse_status & SKL_FUSE_PG1_DIST_STATUS)) {
697 DRM_ERROR("PG1 in disabled state\n");
698 return;
699 }
700 break;
701 case SKL_DISP_PW_DDI_A_E:
702 case SKL_DISP_PW_DDI_B:
703 case SKL_DISP_PW_DDI_C:
704 case SKL_DISP_PW_DDI_D:
705 case SKL_DISP_PW_MISC_IO:
706 break;
707 default:
708 WARN(1, "Unknown power well %lu\n", power_well->data);
709 return;
710 }
711
712 req_mask = SKL_POWER_WELL_REQ(power_well->data);
Damien Lespiau2a518352015-03-06 18:50:49 +0000713 enable_requested = tmp & req_mask;
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000714 state_mask = SKL_POWER_WELL_STATE(power_well->data);
Damien Lespiau2a518352015-03-06 18:50:49 +0000715 is_enabled = tmp & state_mask;
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000716
Ville Syrjäläaae8ba82016-02-19 20:47:30 +0200717 if (!enable && enable_requested)
718 skl_power_well_pre_disable(dev_priv, power_well);
719
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000720 if (enable) {
Damien Lespiau2a518352015-03-06 18:50:49 +0000721 if (!enable_requested) {
Suketu Shahdc174302015-04-17 19:46:16 +0530722 WARN((tmp & state_mask) &&
723 !I915_READ(HSW_PWR_WELL_BIOS),
724 "Invalid for power well status to be enabled, unless done by the BIOS, \
725 when request is to disable!\n");
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000726 I915_WRITE(HSW_PWR_WELL_DRIVER, tmp | req_mask);
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000727 }
728
Damien Lespiau2a518352015-03-06 18:50:49 +0000729 if (!is_enabled) {
Damien Lespiau510e6fd2015-03-06 18:50:50 +0000730 DRM_DEBUG_KMS("Enabling %s\n", power_well->name);
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000731 check_fuse_status = true;
732 }
733 } else {
Damien Lespiau2a518352015-03-06 18:50:49 +0000734 if (enable_requested) {
Imre Deak4a76f292015-11-04 19:24:15 +0200735 I915_WRITE(HSW_PWR_WELL_DRIVER, tmp & ~req_mask);
736 POSTING_READ(HSW_PWR_WELL_DRIVER);
737 DRM_DEBUG_KMS("Disabling %s\n", power_well->name);
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000738 }
Imre Deakc6782b72016-04-05 13:26:05 +0300739
Imre Deak5f304c82016-04-15 22:32:58 +0300740 if (IS_GEN9(dev_priv))
Imre Deakc6782b72016-04-05 13:26:05 +0300741 gen9_sanitize_power_well_requests(dev_priv, power_well);
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000742 }
743
Imre Deak1d963af2016-04-01 16:02:36 +0300744 if (wait_for(!!(I915_READ(HSW_PWR_WELL_DRIVER) & state_mask) == enable,
745 1))
746 DRM_ERROR("%s %s timeout\n",
747 power_well->name, enable ? "enable" : "disable");
748
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000749 if (check_fuse_status) {
750 if (power_well->data == SKL_DISP_PW_1) {
751 if (wait_for((I915_READ(SKL_FUSE_STATUS) &
752 SKL_FUSE_PG1_DIST_STATUS), 1))
753 DRM_ERROR("PG1 distributing status timeout\n");
754 } else if (power_well->data == SKL_DISP_PW_2) {
755 if (wait_for((I915_READ(SKL_FUSE_STATUS) &
756 SKL_FUSE_PG2_DIST_STATUS), 1))
757 DRM_ERROR("PG2 distributing status timeout\n");
758 }
759 }
Damien Lespiaud14c0342015-03-06 18:50:51 +0000760
761 if (enable && !is_enabled)
762 skl_power_well_post_enable(dev_priv, power_well);
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000763}
764
Daniel Vetter9c065a72014-09-30 10:56:38 +0200765static void hsw_power_well_sync_hw(struct drm_i915_private *dev_priv,
766 struct i915_power_well *power_well)
767{
768 hsw_set_power_well(dev_priv, power_well, power_well->count > 0);
769
770 /*
771 * We're taking over the BIOS, so clear any requests made by it since
772 * the driver is in charge now.
773 */
774 if (I915_READ(HSW_PWR_WELL_BIOS) & HSW_PWR_WELL_ENABLE_REQUEST)
775 I915_WRITE(HSW_PWR_WELL_BIOS, 0);
776}
777
778static void hsw_power_well_enable(struct drm_i915_private *dev_priv,
779 struct i915_power_well *power_well)
780{
781 hsw_set_power_well(dev_priv, power_well, true);
782}
783
784static void hsw_power_well_disable(struct drm_i915_private *dev_priv,
785 struct i915_power_well *power_well)
786{
787 hsw_set_power_well(dev_priv, power_well, false);
788}
789
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000790static bool skl_power_well_enabled(struct drm_i915_private *dev_priv,
791 struct i915_power_well *power_well)
792{
793 uint32_t mask = SKL_POWER_WELL_REQ(power_well->data) |
794 SKL_POWER_WELL_STATE(power_well->data);
795
796 return (I915_READ(HSW_PWR_WELL_DRIVER) & mask) == mask;
797}
798
799static void skl_power_well_sync_hw(struct drm_i915_private *dev_priv,
800 struct i915_power_well *power_well)
801{
802 skl_set_power_well(dev_priv, power_well, power_well->count > 0);
803
804 /* Clear any request made by BIOS as driver is taking over */
805 I915_WRITE(HSW_PWR_WELL_BIOS, 0);
806}
807
808static void skl_power_well_enable(struct drm_i915_private *dev_priv,
809 struct i915_power_well *power_well)
810{
811 skl_set_power_well(dev_priv, power_well, true);
812}
813
814static void skl_power_well_disable(struct drm_i915_private *dev_priv,
815 struct i915_power_well *power_well)
816{
817 skl_set_power_well(dev_priv, power_well, false);
818}
819
Patrik Jakobsson9f836f92015-11-16 16:20:01 +0100820static bool gen9_dc_off_power_well_enabled(struct drm_i915_private *dev_priv,
821 struct i915_power_well *power_well)
822{
823 return (I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC5_DC6_MASK) == 0;
824}
825
Ville Syrjälä18a80672016-05-16 16:59:40 +0300826static void gen9_assert_dbuf_enabled(struct drm_i915_private *dev_priv)
827{
828 u32 tmp = I915_READ(DBUF_CTL);
829
830 WARN((tmp & (DBUF_POWER_STATE | DBUF_POWER_REQUEST)) !=
831 (DBUF_POWER_STATE | DBUF_POWER_REQUEST),
832 "Unexpected DBuf power power state (0x%08x)\n", tmp);
833}
834
Patrik Jakobsson9f836f92015-11-16 16:20:01 +0100835static void gen9_dc_off_power_well_enable(struct drm_i915_private *dev_priv,
836 struct i915_power_well *power_well)
837{
Imre Deak5b773eb2016-02-29 22:49:05 +0200838 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
Imre Deakadc7f042016-04-04 17:27:10 +0300839
Ville Syrjälä342be922016-05-13 23:41:39 +0300840 WARN_ON(dev_priv->cdclk_freq !=
841 dev_priv->display.get_display_clock_speed(dev_priv->dev));
842
Ville Syrjälä18a80672016-05-16 16:59:40 +0300843 gen9_assert_dbuf_enabled(dev_priv);
844
Ville Syrjälä342be922016-05-13 23:41:39 +0300845 if (IS_BROXTON(dev_priv))
Imre Deakadc7f042016-04-04 17:27:10 +0300846 broxton_ddi_phy_verify_state(dev_priv);
Patrik Jakobsson9f836f92015-11-16 16:20:01 +0100847}
848
849static void gen9_dc_off_power_well_disable(struct drm_i915_private *dev_priv,
850 struct i915_power_well *power_well)
851{
Imre Deakf74ed082016-04-18 14:48:21 +0300852 if (!dev_priv->csr.dmc_payload)
853 return;
854
Imre Deaka37baf32016-02-29 22:49:03 +0200855 if (dev_priv->csr.allowed_dc_mask & DC_STATE_EN_UPTO_DC6)
Patrik Jakobsson9f836f92015-11-16 16:20:01 +0100856 skl_enable_dc6(dev_priv);
Imre Deaka37baf32016-02-29 22:49:03 +0200857 else if (dev_priv->csr.allowed_dc_mask & DC_STATE_EN_UPTO_DC5)
Patrik Jakobsson9f836f92015-11-16 16:20:01 +0100858 gen9_enable_dc5(dev_priv);
859}
860
861static void gen9_dc_off_power_well_sync_hw(struct drm_i915_private *dev_priv,
862 struct i915_power_well *power_well)
863{
Imre Deaka37baf32016-02-29 22:49:03 +0200864 if (power_well->count > 0)
865 gen9_dc_off_power_well_enable(dev_priv, power_well);
866 else
867 gen9_dc_off_power_well_disable(dev_priv, power_well);
Patrik Jakobsson9f836f92015-11-16 16:20:01 +0100868}
869
Daniel Vetter9c065a72014-09-30 10:56:38 +0200870static void i9xx_always_on_power_well_noop(struct drm_i915_private *dev_priv,
871 struct i915_power_well *power_well)
872{
873}
874
875static bool i9xx_always_on_power_well_enabled(struct drm_i915_private *dev_priv,
876 struct i915_power_well *power_well)
877{
878 return true;
879}
880
881static void vlv_set_power_well(struct drm_i915_private *dev_priv,
882 struct i915_power_well *power_well, bool enable)
883{
884 enum punit_power_well power_well_id = power_well->data;
885 u32 mask;
886 u32 state;
887 u32 ctrl;
888
889 mask = PUNIT_PWRGT_MASK(power_well_id);
890 state = enable ? PUNIT_PWRGT_PWR_ON(power_well_id) :
891 PUNIT_PWRGT_PWR_GATE(power_well_id);
892
893 mutex_lock(&dev_priv->rps.hw_lock);
894
895#define COND \
896 ((vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_STATUS) & mask) == state)
897
898 if (COND)
899 goto out;
900
901 ctrl = vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_CTRL);
902 ctrl &= ~mask;
903 ctrl |= state;
904 vlv_punit_write(dev_priv, PUNIT_REG_PWRGT_CTRL, ctrl);
905
906 if (wait_for(COND, 100))
Masanari Iida7e35ab82015-05-10 01:00:23 +0900907 DRM_ERROR("timeout setting power well state %08x (%08x)\n",
Daniel Vetter9c065a72014-09-30 10:56:38 +0200908 state,
909 vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_CTRL));
910
911#undef COND
912
913out:
914 mutex_unlock(&dev_priv->rps.hw_lock);
915}
916
917static void vlv_power_well_sync_hw(struct drm_i915_private *dev_priv,
918 struct i915_power_well *power_well)
919{
920 vlv_set_power_well(dev_priv, power_well, power_well->count > 0);
921}
922
923static void vlv_power_well_enable(struct drm_i915_private *dev_priv,
924 struct i915_power_well *power_well)
925{
926 vlv_set_power_well(dev_priv, power_well, true);
927}
928
929static void vlv_power_well_disable(struct drm_i915_private *dev_priv,
930 struct i915_power_well *power_well)
931{
932 vlv_set_power_well(dev_priv, power_well, false);
933}
934
935static bool vlv_power_well_enabled(struct drm_i915_private *dev_priv,
936 struct i915_power_well *power_well)
937{
938 int power_well_id = power_well->data;
939 bool enabled = false;
940 u32 mask;
941 u32 state;
942 u32 ctrl;
943
944 mask = PUNIT_PWRGT_MASK(power_well_id);
945 ctrl = PUNIT_PWRGT_PWR_ON(power_well_id);
946
947 mutex_lock(&dev_priv->rps.hw_lock);
948
949 state = vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_STATUS) & mask;
950 /*
951 * We only ever set the power-on and power-gate states, anything
952 * else is unexpected.
953 */
954 WARN_ON(state != PUNIT_PWRGT_PWR_ON(power_well_id) &&
955 state != PUNIT_PWRGT_PWR_GATE(power_well_id));
956 if (state == ctrl)
957 enabled = true;
958
959 /*
960 * A transient state at this point would mean some unexpected party
961 * is poking at the power controls too.
962 */
963 ctrl = vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_CTRL) & mask;
964 WARN_ON(ctrl != state);
965
966 mutex_unlock(&dev_priv->rps.hw_lock);
967
968 return enabled;
969}
970
Ville Syrjälä766078d2016-04-11 16:56:30 +0300971static void vlv_init_display_clock_gating(struct drm_i915_private *dev_priv)
972{
973 I915_WRITE(DSPCLK_GATE_D, VRHUNIT_CLOCK_GATE_DISABLE);
974
975 /*
976 * Disable trickle feed and enable pnd deadline calculation
977 */
978 I915_WRITE(MI_ARB_VLV, MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE);
979 I915_WRITE(CBR1_VLV, 0);
Ville Syrjälä19ab4ed2016-04-27 17:43:22 +0300980
981 WARN_ON(dev_priv->rawclk_freq == 0);
982
983 I915_WRITE(RAWCLK_FREQ_VLV,
984 DIV_ROUND_CLOSEST(dev_priv->rawclk_freq, 1000));
Ville Syrjälä766078d2016-04-11 16:56:30 +0300985}
986
Ville Syrjälä2be7d542015-06-29 15:25:51 +0300987static void vlv_display_power_well_init(struct drm_i915_private *dev_priv)
Daniel Vetter9c065a72014-09-30 10:56:38 +0200988{
Ville Syrjälä5a8fbb72015-06-29 15:25:53 +0300989 enum pipe pipe;
990
991 /*
992 * Enable the CRI clock source so we can get at the
993 * display and the reference clock for VGA
994 * hotplug / manual detection. Supposedly DSI also
995 * needs the ref clock up and running.
996 *
997 * CHV DPLL B/C have some issues if VGA mode is enabled.
998 */
999 for_each_pipe(dev_priv->dev, pipe) {
1000 u32 val = I915_READ(DPLL(pipe));
1001
1002 val |= DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
1003 if (pipe != PIPE_A)
1004 val |= DPLL_INTEGRATED_CRI_CLK_VLV;
1005
1006 I915_WRITE(DPLL(pipe), val);
1007 }
Daniel Vetter9c065a72014-09-30 10:56:38 +02001008
Ville Syrjälä766078d2016-04-11 16:56:30 +03001009 vlv_init_display_clock_gating(dev_priv);
1010
Daniel Vetter9c065a72014-09-30 10:56:38 +02001011 spin_lock_irq(&dev_priv->irq_lock);
1012 valleyview_enable_display_irqs(dev_priv);
1013 spin_unlock_irq(&dev_priv->irq_lock);
1014
1015 /*
1016 * During driver initialization/resume we can avoid restoring the
1017 * part of the HW/SW state that will be inited anyway explicitly.
1018 */
1019 if (dev_priv->power_domains.initializing)
1020 return;
1021
Daniel Vetterb9632912014-09-30 10:56:44 +02001022 intel_hpd_init(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001023
1024 i915_redisable_vga_power_on(dev_priv->dev);
1025}
1026
Ville Syrjälä2be7d542015-06-29 15:25:51 +03001027static void vlv_display_power_well_deinit(struct drm_i915_private *dev_priv)
1028{
1029 spin_lock_irq(&dev_priv->irq_lock);
1030 valleyview_disable_display_irqs(dev_priv);
1031 spin_unlock_irq(&dev_priv->irq_lock);
1032
Ville Syrjälä2230fde2016-02-19 18:41:52 +02001033 /* make sure we're done processing display irqs */
1034 synchronize_irq(dev_priv->dev->irq);
1035
Ville Syrjälä2be7d542015-06-29 15:25:51 +03001036 vlv_power_sequencer_reset(dev_priv);
1037}
1038
1039static void vlv_display_power_well_enable(struct drm_i915_private *dev_priv,
1040 struct i915_power_well *power_well)
1041{
1042 WARN_ON_ONCE(power_well->data != PUNIT_POWER_WELL_DISP2D);
1043
1044 vlv_set_power_well(dev_priv, power_well, true);
1045
1046 vlv_display_power_well_init(dev_priv);
1047}
1048
Daniel Vetter9c065a72014-09-30 10:56:38 +02001049static void vlv_display_power_well_disable(struct drm_i915_private *dev_priv,
1050 struct i915_power_well *power_well)
1051{
1052 WARN_ON_ONCE(power_well->data != PUNIT_POWER_WELL_DISP2D);
1053
Ville Syrjälä2be7d542015-06-29 15:25:51 +03001054 vlv_display_power_well_deinit(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001055
1056 vlv_set_power_well(dev_priv, power_well, false);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001057}
1058
1059static void vlv_dpio_cmn_power_well_enable(struct drm_i915_private *dev_priv,
1060 struct i915_power_well *power_well)
1061{
1062 WARN_ON_ONCE(power_well->data != PUNIT_POWER_WELL_DPIO_CMN_BC);
1063
Ville Syrjälä5a8fbb72015-06-29 15:25:53 +03001064 /* since ref/cri clock was enabled */
Daniel Vetter9c065a72014-09-30 10:56:38 +02001065 udelay(1); /* >10ns for cmnreset, >0ns for sidereset */
1066
1067 vlv_set_power_well(dev_priv, power_well, true);
1068
1069 /*
1070 * From VLV2A0_DP_eDP_DPIO_driver_vbios_notes_10.docx -
1071 * 6. De-assert cmn_reset/side_reset. Same as VLV X0.
1072 * a. GUnit 0x2110 bit[0] set to 1 (def 0)
1073 * b. The other bits such as sfr settings / modesel may all
1074 * be set to 0.
1075 *
1076 * This should only be done on init and resume from S3 with
1077 * both PLLs disabled, or we risk losing DPIO and PLL
1078 * synchronization.
1079 */
1080 I915_WRITE(DPIO_CTL, I915_READ(DPIO_CTL) | DPIO_CMNRST);
1081}
1082
1083static void vlv_dpio_cmn_power_well_disable(struct drm_i915_private *dev_priv,
1084 struct i915_power_well *power_well)
1085{
1086 enum pipe pipe;
1087
1088 WARN_ON_ONCE(power_well->data != PUNIT_POWER_WELL_DPIO_CMN_BC);
1089
1090 for_each_pipe(dev_priv, pipe)
1091 assert_pll_disabled(dev_priv, pipe);
1092
1093 /* Assert common reset */
1094 I915_WRITE(DPIO_CTL, I915_READ(DPIO_CTL) & ~DPIO_CMNRST);
1095
1096 vlv_set_power_well(dev_priv, power_well, false);
1097}
1098
Ville Syrjälä30142272015-07-08 23:46:01 +03001099#define POWER_DOMAIN_MASK (BIT(POWER_DOMAIN_NUM) - 1)
1100
1101static struct i915_power_well *lookup_power_well(struct drm_i915_private *dev_priv,
1102 int power_well_id)
1103{
1104 struct i915_power_domains *power_domains = &dev_priv->power_domains;
Ville Syrjälä30142272015-07-08 23:46:01 +03001105 int i;
1106
Imre Deakfc17f222015-11-04 19:24:11 +02001107 for (i = 0; i < power_domains->power_well_count; i++) {
1108 struct i915_power_well *power_well;
1109
1110 power_well = &power_domains->power_wells[i];
Ville Syrjälä30142272015-07-08 23:46:01 +03001111 if (power_well->data == power_well_id)
1112 return power_well;
1113 }
1114
1115 return NULL;
1116}
1117
1118#define BITS_SET(val, bits) (((val) & (bits)) == (bits))
1119
1120static void assert_chv_phy_status(struct drm_i915_private *dev_priv)
1121{
1122 struct i915_power_well *cmn_bc =
1123 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_BC);
1124 struct i915_power_well *cmn_d =
1125 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_D);
1126 u32 phy_control = dev_priv->chv_phy_control;
1127 u32 phy_status = 0;
Ville Syrjälä3be60de2015-09-08 18:05:45 +03001128 u32 phy_status_mask = 0xffffffff;
Ville Syrjälä30142272015-07-08 23:46:01 +03001129 u32 tmp;
1130
Ville Syrjälä3be60de2015-09-08 18:05:45 +03001131 /*
1132 * The BIOS can leave the PHY is some weird state
1133 * where it doesn't fully power down some parts.
1134 * Disable the asserts until the PHY has been fully
1135 * reset (ie. the power well has been disabled at
1136 * least once).
1137 */
1138 if (!dev_priv->chv_phy_assert[DPIO_PHY0])
1139 phy_status_mask &= ~(PHY_STATUS_CMN_LDO(DPIO_PHY0, DPIO_CH0) |
1140 PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH0, 0) |
1141 PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH0, 1) |
1142 PHY_STATUS_CMN_LDO(DPIO_PHY0, DPIO_CH1) |
1143 PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH1, 0) |
1144 PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH1, 1));
1145
1146 if (!dev_priv->chv_phy_assert[DPIO_PHY1])
1147 phy_status_mask &= ~(PHY_STATUS_CMN_LDO(DPIO_PHY1, DPIO_CH0) |
1148 PHY_STATUS_SPLINE_LDO(DPIO_PHY1, DPIO_CH0, 0) |
1149 PHY_STATUS_SPLINE_LDO(DPIO_PHY1, DPIO_CH0, 1));
1150
Ville Syrjälä30142272015-07-08 23:46:01 +03001151 if (cmn_bc->ops->is_enabled(dev_priv, cmn_bc)) {
1152 phy_status |= PHY_POWERGOOD(DPIO_PHY0);
1153
1154 /* this assumes override is only used to enable lanes */
1155 if ((phy_control & PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY0, DPIO_CH0)) == 0)
1156 phy_control |= PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH0);
1157
1158 if ((phy_control & PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY0, DPIO_CH1)) == 0)
1159 phy_control |= PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH1);
1160
1161 /* CL1 is on whenever anything is on in either channel */
1162 if (BITS_SET(phy_control,
1163 PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH0) |
1164 PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH1)))
1165 phy_status |= PHY_STATUS_CMN_LDO(DPIO_PHY0, DPIO_CH0);
1166
1167 /*
1168 * The DPLLB check accounts for the pipe B + port A usage
1169 * with CL2 powered up but all the lanes in the second channel
1170 * powered down.
1171 */
1172 if (BITS_SET(phy_control,
1173 PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH1)) &&
1174 (I915_READ(DPLL(PIPE_B)) & DPLL_VCO_ENABLE) == 0)
1175 phy_status |= PHY_STATUS_CMN_LDO(DPIO_PHY0, DPIO_CH1);
1176
1177 if (BITS_SET(phy_control,
1178 PHY_CH_POWER_DOWN_OVRD(0x3, DPIO_PHY0, DPIO_CH0)))
1179 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH0, 0);
1180 if (BITS_SET(phy_control,
1181 PHY_CH_POWER_DOWN_OVRD(0xc, DPIO_PHY0, DPIO_CH0)))
1182 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH0, 1);
1183
1184 if (BITS_SET(phy_control,
1185 PHY_CH_POWER_DOWN_OVRD(0x3, DPIO_PHY0, DPIO_CH1)))
1186 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH1, 0);
1187 if (BITS_SET(phy_control,
1188 PHY_CH_POWER_DOWN_OVRD(0xc, DPIO_PHY0, DPIO_CH1)))
1189 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH1, 1);
1190 }
1191
1192 if (cmn_d->ops->is_enabled(dev_priv, cmn_d)) {
1193 phy_status |= PHY_POWERGOOD(DPIO_PHY1);
1194
1195 /* this assumes override is only used to enable lanes */
1196 if ((phy_control & PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY1, DPIO_CH0)) == 0)
1197 phy_control |= PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY1, DPIO_CH0);
1198
1199 if (BITS_SET(phy_control,
1200 PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY1, DPIO_CH0)))
1201 phy_status |= PHY_STATUS_CMN_LDO(DPIO_PHY1, DPIO_CH0);
1202
1203 if (BITS_SET(phy_control,
1204 PHY_CH_POWER_DOWN_OVRD(0x3, DPIO_PHY1, DPIO_CH0)))
1205 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY1, DPIO_CH0, 0);
1206 if (BITS_SET(phy_control,
1207 PHY_CH_POWER_DOWN_OVRD(0xc, DPIO_PHY1, DPIO_CH0)))
1208 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY1, DPIO_CH0, 1);
1209 }
1210
Ville Syrjälä3be60de2015-09-08 18:05:45 +03001211 phy_status &= phy_status_mask;
1212
Ville Syrjälä30142272015-07-08 23:46:01 +03001213 /*
1214 * The PHY may be busy with some initial calibration and whatnot,
1215 * so the power state can take a while to actually change.
1216 */
Ville Syrjälä3be60de2015-09-08 18:05:45 +03001217 if (wait_for((tmp = I915_READ(DISPLAY_PHY_STATUS) & phy_status_mask) == phy_status, 10))
Ville Syrjälä30142272015-07-08 23:46:01 +03001218 WARN(phy_status != tmp,
1219 "Unexpected PHY_STATUS 0x%08x, expected 0x%08x (PHY_CONTROL=0x%08x)\n",
1220 tmp, phy_status, dev_priv->chv_phy_control);
1221}
1222
1223#undef BITS_SET
1224
Daniel Vetter9c065a72014-09-30 10:56:38 +02001225static void chv_dpio_cmn_power_well_enable(struct drm_i915_private *dev_priv,
1226 struct i915_power_well *power_well)
1227{
1228 enum dpio_phy phy;
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001229 enum pipe pipe;
1230 uint32_t tmp;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001231
1232 WARN_ON_ONCE(power_well->data != PUNIT_POWER_WELL_DPIO_CMN_BC &&
1233 power_well->data != PUNIT_POWER_WELL_DPIO_CMN_D);
1234
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001235 if (power_well->data == PUNIT_POWER_WELL_DPIO_CMN_BC) {
1236 pipe = PIPE_A;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001237 phy = DPIO_PHY0;
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001238 } else {
1239 pipe = PIPE_C;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001240 phy = DPIO_PHY1;
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001241 }
Ville Syrjälä5a8fbb72015-06-29 15:25:53 +03001242
1243 /* since ref/cri clock was enabled */
Daniel Vetter9c065a72014-09-30 10:56:38 +02001244 udelay(1); /* >10ns for cmnreset, >0ns for sidereset */
1245 vlv_set_power_well(dev_priv, power_well, true);
1246
1247 /* Poll for phypwrgood signal */
1248 if (wait_for(I915_READ(DISPLAY_PHY_STATUS) & PHY_POWERGOOD(phy), 1))
1249 DRM_ERROR("Display PHY %d is not power up\n", phy);
1250
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001251 mutex_lock(&dev_priv->sb_lock);
1252
1253 /* Enable dynamic power down */
1254 tmp = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW28);
Ville Syrjäläee279212015-07-08 23:45:57 +03001255 tmp |= DPIO_DYNPWRDOWNEN_CH0 | DPIO_CL1POWERDOWNEN |
1256 DPIO_SUS_CLK_CONFIG_GATE_CLKREQ;
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001257 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW28, tmp);
1258
1259 if (power_well->data == PUNIT_POWER_WELL_DPIO_CMN_BC) {
1260 tmp = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW6_CH1);
1261 tmp |= DPIO_DYNPWRDOWNEN_CH1;
1262 vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW6_CH1, tmp);
Ville Syrjälä3e288782015-07-08 23:45:58 +03001263 } else {
1264 /*
1265 * Force the non-existing CL2 off. BXT does this
1266 * too, so maybe it saves some power even though
1267 * CL2 doesn't exist?
1268 */
1269 tmp = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW30);
1270 tmp |= DPIO_CL2_LDOFUSE_PWRENB;
1271 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW30, tmp);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001272 }
1273
1274 mutex_unlock(&dev_priv->sb_lock);
1275
Ville Syrjälä70722462015-04-10 18:21:28 +03001276 dev_priv->chv_phy_control |= PHY_COM_LANE_RESET_DEASSERT(phy);
1277 I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001278
1279 DRM_DEBUG_KMS("Enabled DPIO PHY%d (PHY_CONTROL=0x%08x)\n",
1280 phy, dev_priv->chv_phy_control);
Ville Syrjälä30142272015-07-08 23:46:01 +03001281
1282 assert_chv_phy_status(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001283}
1284
1285static void chv_dpio_cmn_power_well_disable(struct drm_i915_private *dev_priv,
1286 struct i915_power_well *power_well)
1287{
1288 enum dpio_phy phy;
1289
1290 WARN_ON_ONCE(power_well->data != PUNIT_POWER_WELL_DPIO_CMN_BC &&
1291 power_well->data != PUNIT_POWER_WELL_DPIO_CMN_D);
1292
1293 if (power_well->data == PUNIT_POWER_WELL_DPIO_CMN_BC) {
1294 phy = DPIO_PHY0;
1295 assert_pll_disabled(dev_priv, PIPE_A);
1296 assert_pll_disabled(dev_priv, PIPE_B);
1297 } else {
1298 phy = DPIO_PHY1;
1299 assert_pll_disabled(dev_priv, PIPE_C);
1300 }
1301
Ville Syrjälä70722462015-04-10 18:21:28 +03001302 dev_priv->chv_phy_control &= ~PHY_COM_LANE_RESET_DEASSERT(phy);
1303 I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001304
1305 vlv_set_power_well(dev_priv, power_well, false);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001306
1307 DRM_DEBUG_KMS("Disabled DPIO PHY%d (PHY_CONTROL=0x%08x)\n",
1308 phy, dev_priv->chv_phy_control);
Ville Syrjälä30142272015-07-08 23:46:01 +03001309
Ville Syrjälä3be60de2015-09-08 18:05:45 +03001310 /* PHY is fully reset now, so we can enable the PHY state asserts */
1311 dev_priv->chv_phy_assert[phy] = true;
1312
Ville Syrjälä30142272015-07-08 23:46:01 +03001313 assert_chv_phy_status(dev_priv);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001314}
1315
Ville Syrjälä6669e392015-07-08 23:46:00 +03001316static void assert_chv_phy_powergate(struct drm_i915_private *dev_priv, enum dpio_phy phy,
1317 enum dpio_channel ch, bool override, unsigned int mask)
1318{
1319 enum pipe pipe = phy == DPIO_PHY0 ? PIPE_A : PIPE_C;
1320 u32 reg, val, expected, actual;
1321
Ville Syrjälä3be60de2015-09-08 18:05:45 +03001322 /*
1323 * The BIOS can leave the PHY is some weird state
1324 * where it doesn't fully power down some parts.
1325 * Disable the asserts until the PHY has been fully
1326 * reset (ie. the power well has been disabled at
1327 * least once).
1328 */
1329 if (!dev_priv->chv_phy_assert[phy])
1330 return;
1331
Ville Syrjälä6669e392015-07-08 23:46:00 +03001332 if (ch == DPIO_CH0)
1333 reg = _CHV_CMN_DW0_CH0;
1334 else
1335 reg = _CHV_CMN_DW6_CH1;
1336
1337 mutex_lock(&dev_priv->sb_lock);
1338 val = vlv_dpio_read(dev_priv, pipe, reg);
1339 mutex_unlock(&dev_priv->sb_lock);
1340
1341 /*
1342 * This assumes !override is only used when the port is disabled.
1343 * All lanes should power down even without the override when
1344 * the port is disabled.
1345 */
1346 if (!override || mask == 0xf) {
1347 expected = DPIO_ALLDL_POWERDOWN | DPIO_ANYDL_POWERDOWN;
1348 /*
1349 * If CH1 common lane is not active anymore
1350 * (eg. for pipe B DPLL) the entire channel will
1351 * shut down, which causes the common lane registers
1352 * to read as 0. That means we can't actually check
1353 * the lane power down status bits, but as the entire
1354 * register reads as 0 it's a good indication that the
1355 * channel is indeed entirely powered down.
1356 */
1357 if (ch == DPIO_CH1 && val == 0)
1358 expected = 0;
1359 } else if (mask != 0x0) {
1360 expected = DPIO_ANYDL_POWERDOWN;
1361 } else {
1362 expected = 0;
1363 }
1364
1365 if (ch == DPIO_CH0)
1366 actual = val >> DPIO_ANYDL_POWERDOWN_SHIFT_CH0;
1367 else
1368 actual = val >> DPIO_ANYDL_POWERDOWN_SHIFT_CH1;
1369 actual &= DPIO_ALLDL_POWERDOWN | DPIO_ANYDL_POWERDOWN;
1370
1371 WARN(actual != expected,
1372 "Unexpected DPIO lane power down: all %d, any %d. Expected: all %d, any %d. (0x%x = 0x%08x)\n",
1373 !!(actual & DPIO_ALLDL_POWERDOWN), !!(actual & DPIO_ANYDL_POWERDOWN),
1374 !!(expected & DPIO_ALLDL_POWERDOWN), !!(expected & DPIO_ANYDL_POWERDOWN),
1375 reg, val);
1376}
1377
Ville Syrjäläb0b33842015-07-08 23:45:55 +03001378bool chv_phy_powergate_ch(struct drm_i915_private *dev_priv, enum dpio_phy phy,
1379 enum dpio_channel ch, bool override)
1380{
1381 struct i915_power_domains *power_domains = &dev_priv->power_domains;
1382 bool was_override;
1383
1384 mutex_lock(&power_domains->lock);
1385
1386 was_override = dev_priv->chv_phy_control & PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
1387
1388 if (override == was_override)
1389 goto out;
1390
1391 if (override)
1392 dev_priv->chv_phy_control |= PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
1393 else
1394 dev_priv->chv_phy_control &= ~PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
1395
1396 I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
1397
1398 DRM_DEBUG_KMS("Power gating DPIO PHY%d CH%d (DPIO_PHY_CONTROL=0x%08x)\n",
1399 phy, ch, dev_priv->chv_phy_control);
1400
Ville Syrjälä30142272015-07-08 23:46:01 +03001401 assert_chv_phy_status(dev_priv);
1402
Ville Syrjäläb0b33842015-07-08 23:45:55 +03001403out:
1404 mutex_unlock(&power_domains->lock);
1405
1406 return was_override;
1407}
1408
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001409void chv_phy_powergate_lanes(struct intel_encoder *encoder,
1410 bool override, unsigned int mask)
1411{
1412 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
1413 struct i915_power_domains *power_domains = &dev_priv->power_domains;
1414 enum dpio_phy phy = vlv_dport_to_phy(enc_to_dig_port(&encoder->base));
1415 enum dpio_channel ch = vlv_dport_to_channel(enc_to_dig_port(&encoder->base));
1416
1417 mutex_lock(&power_domains->lock);
1418
1419 dev_priv->chv_phy_control &= ~PHY_CH_POWER_DOWN_OVRD(0xf, phy, ch);
1420 dev_priv->chv_phy_control |= PHY_CH_POWER_DOWN_OVRD(mask, phy, ch);
1421
1422 if (override)
1423 dev_priv->chv_phy_control |= PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
1424 else
1425 dev_priv->chv_phy_control &= ~PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
1426
1427 I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
1428
1429 DRM_DEBUG_KMS("Power gating DPIO PHY%d CH%d lanes 0x%x (PHY_CONTROL=0x%08x)\n",
1430 phy, ch, mask, dev_priv->chv_phy_control);
1431
Ville Syrjälä30142272015-07-08 23:46:01 +03001432 assert_chv_phy_status(dev_priv);
1433
Ville Syrjälä6669e392015-07-08 23:46:00 +03001434 assert_chv_phy_powergate(dev_priv, phy, ch, override, mask);
1435
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001436 mutex_unlock(&power_domains->lock);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001437}
1438
1439static bool chv_pipe_power_well_enabled(struct drm_i915_private *dev_priv,
1440 struct i915_power_well *power_well)
1441{
1442 enum pipe pipe = power_well->data;
1443 bool enabled;
1444 u32 state, ctrl;
1445
1446 mutex_lock(&dev_priv->rps.hw_lock);
1447
1448 state = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & DP_SSS_MASK(pipe);
1449 /*
1450 * We only ever set the power-on and power-gate states, anything
1451 * else is unexpected.
1452 */
1453 WARN_ON(state != DP_SSS_PWR_ON(pipe) && state != DP_SSS_PWR_GATE(pipe));
1454 enabled = state == DP_SSS_PWR_ON(pipe);
1455
1456 /*
1457 * A transient state at this point would mean some unexpected party
1458 * is poking at the power controls too.
1459 */
1460 ctrl = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & DP_SSC_MASK(pipe);
1461 WARN_ON(ctrl << 16 != state);
1462
1463 mutex_unlock(&dev_priv->rps.hw_lock);
1464
1465 return enabled;
1466}
1467
1468static void chv_set_pipe_power_well(struct drm_i915_private *dev_priv,
1469 struct i915_power_well *power_well,
1470 bool enable)
1471{
1472 enum pipe pipe = power_well->data;
1473 u32 state;
1474 u32 ctrl;
1475
1476 state = enable ? DP_SSS_PWR_ON(pipe) : DP_SSS_PWR_GATE(pipe);
1477
1478 mutex_lock(&dev_priv->rps.hw_lock);
1479
1480#define COND \
1481 ((vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & DP_SSS_MASK(pipe)) == state)
1482
1483 if (COND)
1484 goto out;
1485
1486 ctrl = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ);
1487 ctrl &= ~DP_SSC_MASK(pipe);
1488 ctrl |= enable ? DP_SSC_PWR_ON(pipe) : DP_SSC_PWR_GATE(pipe);
1489 vlv_punit_write(dev_priv, PUNIT_REG_DSPFREQ, ctrl);
1490
1491 if (wait_for(COND, 100))
Masanari Iida7e35ab82015-05-10 01:00:23 +09001492 DRM_ERROR("timeout setting power well state %08x (%08x)\n",
Daniel Vetter9c065a72014-09-30 10:56:38 +02001493 state,
1494 vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ));
1495
1496#undef COND
1497
1498out:
1499 mutex_unlock(&dev_priv->rps.hw_lock);
1500}
1501
1502static void chv_pipe_power_well_sync_hw(struct drm_i915_private *dev_priv,
1503 struct i915_power_well *power_well)
1504{
Ville Syrjälä8fcd5cd2015-06-29 15:25:50 +03001505 WARN_ON_ONCE(power_well->data != PIPE_A);
1506
Daniel Vetter9c065a72014-09-30 10:56:38 +02001507 chv_set_pipe_power_well(dev_priv, power_well, power_well->count > 0);
1508}
1509
1510static void chv_pipe_power_well_enable(struct drm_i915_private *dev_priv,
1511 struct i915_power_well *power_well)
1512{
Ville Syrjälä8fcd5cd2015-06-29 15:25:50 +03001513 WARN_ON_ONCE(power_well->data != PIPE_A);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001514
1515 chv_set_pipe_power_well(dev_priv, power_well, true);
Ville Syrjäläafd62752014-10-30 19:43:03 +02001516
Ville Syrjälä2be7d542015-06-29 15:25:51 +03001517 vlv_display_power_well_init(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001518}
1519
1520static void chv_pipe_power_well_disable(struct drm_i915_private *dev_priv,
1521 struct i915_power_well *power_well)
1522{
Ville Syrjälä8fcd5cd2015-06-29 15:25:50 +03001523 WARN_ON_ONCE(power_well->data != PIPE_A);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001524
Ville Syrjälä2be7d542015-06-29 15:25:51 +03001525 vlv_display_power_well_deinit(dev_priv);
Ville Syrjäläafd62752014-10-30 19:43:03 +02001526
Daniel Vetter9c065a72014-09-30 10:56:38 +02001527 chv_set_pipe_power_well(dev_priv, power_well, false);
1528}
1529
Imre Deak09731282016-02-17 14:17:42 +02001530static void
1531__intel_display_power_get_domain(struct drm_i915_private *dev_priv,
1532 enum intel_display_power_domain domain)
1533{
1534 struct i915_power_domains *power_domains = &dev_priv->power_domains;
1535 struct i915_power_well *power_well;
1536 int i;
1537
Imre Deakb409ca92016-06-13 16:44:33 +03001538 for_each_power_well(i, power_well, BIT(domain), power_domains)
1539 intel_power_well_get(dev_priv, power_well);
Imre Deak09731282016-02-17 14:17:42 +02001540
1541 power_domains->domain_use_count[domain]++;
1542}
1543
Daniel Vettere4e76842014-09-30 10:56:42 +02001544/**
1545 * intel_display_power_get - grab a power domain reference
1546 * @dev_priv: i915 device instance
1547 * @domain: power domain to reference
1548 *
1549 * This function grabs a power domain reference for @domain and ensures that the
1550 * power domain and all its parents are powered up. Therefore users should only
1551 * grab a reference to the innermost power domain they need.
1552 *
1553 * Any power domain reference obtained by this function must have a symmetric
1554 * call to intel_display_power_put() to release the reference again.
1555 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02001556void intel_display_power_get(struct drm_i915_private *dev_priv,
1557 enum intel_display_power_domain domain)
1558{
Imre Deak09731282016-02-17 14:17:42 +02001559 struct i915_power_domains *power_domains = &dev_priv->power_domains;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001560
1561 intel_runtime_pm_get(dev_priv);
1562
Imre Deak09731282016-02-17 14:17:42 +02001563 mutex_lock(&power_domains->lock);
1564
1565 __intel_display_power_get_domain(dev_priv, domain);
1566
1567 mutex_unlock(&power_domains->lock);
1568}
1569
1570/**
1571 * intel_display_power_get_if_enabled - grab a reference for an enabled display power domain
1572 * @dev_priv: i915 device instance
1573 * @domain: power domain to reference
1574 *
1575 * This function grabs a power domain reference for @domain and ensures that the
1576 * power domain and all its parents are powered up. Therefore users should only
1577 * grab a reference to the innermost power domain they need.
1578 *
1579 * Any power domain reference obtained by this function must have a symmetric
1580 * call to intel_display_power_put() to release the reference again.
1581 */
1582bool intel_display_power_get_if_enabled(struct drm_i915_private *dev_priv,
1583 enum intel_display_power_domain domain)
1584{
1585 struct i915_power_domains *power_domains = &dev_priv->power_domains;
1586 bool is_enabled;
1587
1588 if (!intel_runtime_pm_get_if_in_use(dev_priv))
1589 return false;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001590
1591 mutex_lock(&power_domains->lock);
1592
Imre Deak09731282016-02-17 14:17:42 +02001593 if (__intel_display_power_is_enabled(dev_priv, domain)) {
1594 __intel_display_power_get_domain(dev_priv, domain);
1595 is_enabled = true;
1596 } else {
1597 is_enabled = false;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001598 }
1599
Daniel Vetter9c065a72014-09-30 10:56:38 +02001600 mutex_unlock(&power_domains->lock);
Imre Deak09731282016-02-17 14:17:42 +02001601
1602 if (!is_enabled)
1603 intel_runtime_pm_put(dev_priv);
1604
1605 return is_enabled;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001606}
1607
Daniel Vettere4e76842014-09-30 10:56:42 +02001608/**
1609 * intel_display_power_put - release a power domain reference
1610 * @dev_priv: i915 device instance
1611 * @domain: power domain to reference
1612 *
1613 * This function drops the power domain reference obtained by
1614 * intel_display_power_get() and might power down the corresponding hardware
1615 * block right away if this is the last reference.
1616 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02001617void intel_display_power_put(struct drm_i915_private *dev_priv,
1618 enum intel_display_power_domain domain)
1619{
1620 struct i915_power_domains *power_domains;
1621 struct i915_power_well *power_well;
1622 int i;
1623
1624 power_domains = &dev_priv->power_domains;
1625
1626 mutex_lock(&power_domains->lock);
1627
Daniel Stone11c86db2015-11-20 15:55:34 +00001628 WARN(!power_domains->domain_use_count[domain],
1629 "Use count on domain %s is already zero\n",
1630 intel_display_power_domain_str(domain));
Daniel Vetter9c065a72014-09-30 10:56:38 +02001631 power_domains->domain_use_count[domain]--;
1632
Imre Deakb409ca92016-06-13 16:44:33 +03001633 for_each_power_well_rev(i, power_well, BIT(domain), power_domains)
1634 intel_power_well_put(dev_priv, power_well);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001635
1636 mutex_unlock(&power_domains->lock);
1637
1638 intel_runtime_pm_put(dev_priv);
1639}
1640
Ville Syrjälä9d0996b2016-04-18 14:02:28 +03001641#define HSW_DISPLAY_POWER_DOMAINS ( \
1642 BIT(POWER_DOMAIN_PIPE_B) | \
1643 BIT(POWER_DOMAIN_PIPE_C) | \
1644 BIT(POWER_DOMAIN_PIPE_A_PANEL_FITTER) | \
1645 BIT(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1646 BIT(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
1647 BIT(POWER_DOMAIN_TRANSCODER_A) | \
1648 BIT(POWER_DOMAIN_TRANSCODER_B) | \
1649 BIT(POWER_DOMAIN_TRANSCODER_C) | \
Patrik Jakobsson6331a702015-11-09 16:48:21 +01001650 BIT(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1651 BIT(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1652 BIT(POWER_DOMAIN_PORT_DDI_D_LANES) | \
Ville Syrjälä9d0996b2016-04-18 14:02:28 +03001653 BIT(POWER_DOMAIN_PORT_CRT) | /* DDI E */ \
1654 BIT(POWER_DOMAIN_VGA) | \
1655 BIT(POWER_DOMAIN_AUDIO) | \
Daniel Vetter9c065a72014-09-30 10:56:38 +02001656 BIT(POWER_DOMAIN_INIT))
1657
Ville Syrjälä9d0996b2016-04-18 14:02:28 +03001658#define BDW_DISPLAY_POWER_DOMAINS ( \
1659 BIT(POWER_DOMAIN_PIPE_B) | \
1660 BIT(POWER_DOMAIN_PIPE_C) | \
1661 BIT(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1662 BIT(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
1663 BIT(POWER_DOMAIN_TRANSCODER_A) | \
1664 BIT(POWER_DOMAIN_TRANSCODER_B) | \
1665 BIT(POWER_DOMAIN_TRANSCODER_C) | \
1666 BIT(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1667 BIT(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1668 BIT(POWER_DOMAIN_PORT_DDI_D_LANES) | \
1669 BIT(POWER_DOMAIN_PORT_CRT) | /* DDI E */ \
1670 BIT(POWER_DOMAIN_VGA) | \
1671 BIT(POWER_DOMAIN_AUDIO) | \
Daniel Vetter9c065a72014-09-30 10:56:38 +02001672 BIT(POWER_DOMAIN_INIT))
1673
Ville Syrjälä465ac0c2016-04-18 14:02:27 +03001674#define VLV_DISPLAY_POWER_DOMAINS ( \
1675 BIT(POWER_DOMAIN_PIPE_A) | \
1676 BIT(POWER_DOMAIN_PIPE_B) | \
1677 BIT(POWER_DOMAIN_PIPE_A_PANEL_FITTER) | \
1678 BIT(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1679 BIT(POWER_DOMAIN_TRANSCODER_A) | \
1680 BIT(POWER_DOMAIN_TRANSCODER_B) | \
1681 BIT(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1682 BIT(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1683 BIT(POWER_DOMAIN_PORT_DSI) | \
1684 BIT(POWER_DOMAIN_PORT_CRT) | \
1685 BIT(POWER_DOMAIN_VGA) | \
1686 BIT(POWER_DOMAIN_AUDIO) | \
1687 BIT(POWER_DOMAIN_AUX_B) | \
1688 BIT(POWER_DOMAIN_AUX_C) | \
1689 BIT(POWER_DOMAIN_GMBUS) | \
1690 BIT(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001691
1692#define VLV_DPIO_CMN_BC_POWER_DOMAINS ( \
Patrik Jakobsson6331a702015-11-09 16:48:21 +01001693 BIT(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1694 BIT(POWER_DOMAIN_PORT_DDI_C_LANES) | \
Daniel Vetter9c065a72014-09-30 10:56:38 +02001695 BIT(POWER_DOMAIN_PORT_CRT) | \
Satheeshakrishna M14071212015-01-16 15:57:51 +00001696 BIT(POWER_DOMAIN_AUX_B) | \
1697 BIT(POWER_DOMAIN_AUX_C) | \
Daniel Vetter9c065a72014-09-30 10:56:38 +02001698 BIT(POWER_DOMAIN_INIT))
1699
1700#define VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS ( \
Patrik Jakobsson6331a702015-11-09 16:48:21 +01001701 BIT(POWER_DOMAIN_PORT_DDI_B_LANES) | \
Satheeshakrishna M14071212015-01-16 15:57:51 +00001702 BIT(POWER_DOMAIN_AUX_B) | \
Daniel Vetter9c065a72014-09-30 10:56:38 +02001703 BIT(POWER_DOMAIN_INIT))
1704
1705#define VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS ( \
Patrik Jakobsson6331a702015-11-09 16:48:21 +01001706 BIT(POWER_DOMAIN_PORT_DDI_B_LANES) | \
Satheeshakrishna M14071212015-01-16 15:57:51 +00001707 BIT(POWER_DOMAIN_AUX_B) | \
Daniel Vetter9c065a72014-09-30 10:56:38 +02001708 BIT(POWER_DOMAIN_INIT))
1709
1710#define VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS ( \
Patrik Jakobsson6331a702015-11-09 16:48:21 +01001711 BIT(POWER_DOMAIN_PORT_DDI_C_LANES) | \
Satheeshakrishna M14071212015-01-16 15:57:51 +00001712 BIT(POWER_DOMAIN_AUX_C) | \
Daniel Vetter9c065a72014-09-30 10:56:38 +02001713 BIT(POWER_DOMAIN_INIT))
1714
1715#define VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS ( \
Patrik Jakobsson6331a702015-11-09 16:48:21 +01001716 BIT(POWER_DOMAIN_PORT_DDI_C_LANES) | \
Satheeshakrishna M14071212015-01-16 15:57:51 +00001717 BIT(POWER_DOMAIN_AUX_C) | \
Daniel Vetter9c065a72014-09-30 10:56:38 +02001718 BIT(POWER_DOMAIN_INIT))
1719
Ville Syrjälä465ac0c2016-04-18 14:02:27 +03001720#define CHV_DISPLAY_POWER_DOMAINS ( \
1721 BIT(POWER_DOMAIN_PIPE_A) | \
1722 BIT(POWER_DOMAIN_PIPE_B) | \
1723 BIT(POWER_DOMAIN_PIPE_C) | \
1724 BIT(POWER_DOMAIN_PIPE_A_PANEL_FITTER) | \
1725 BIT(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1726 BIT(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
1727 BIT(POWER_DOMAIN_TRANSCODER_A) | \
1728 BIT(POWER_DOMAIN_TRANSCODER_B) | \
1729 BIT(POWER_DOMAIN_TRANSCODER_C) | \
1730 BIT(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1731 BIT(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1732 BIT(POWER_DOMAIN_PORT_DDI_D_LANES) | \
1733 BIT(POWER_DOMAIN_PORT_DSI) | \
1734 BIT(POWER_DOMAIN_VGA) | \
1735 BIT(POWER_DOMAIN_AUDIO) | \
1736 BIT(POWER_DOMAIN_AUX_B) | \
1737 BIT(POWER_DOMAIN_AUX_C) | \
1738 BIT(POWER_DOMAIN_AUX_D) | \
1739 BIT(POWER_DOMAIN_GMBUS) | \
1740 BIT(POWER_DOMAIN_INIT))
1741
Daniel Vetter9c065a72014-09-30 10:56:38 +02001742#define CHV_DPIO_CMN_BC_POWER_DOMAINS ( \
Patrik Jakobsson6331a702015-11-09 16:48:21 +01001743 BIT(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1744 BIT(POWER_DOMAIN_PORT_DDI_C_LANES) | \
Satheeshakrishna M14071212015-01-16 15:57:51 +00001745 BIT(POWER_DOMAIN_AUX_B) | \
1746 BIT(POWER_DOMAIN_AUX_C) | \
Daniel Vetter9c065a72014-09-30 10:56:38 +02001747 BIT(POWER_DOMAIN_INIT))
1748
1749#define CHV_DPIO_CMN_D_POWER_DOMAINS ( \
Patrik Jakobsson6331a702015-11-09 16:48:21 +01001750 BIT(POWER_DOMAIN_PORT_DDI_D_LANES) | \
Satheeshakrishna M14071212015-01-16 15:57:51 +00001751 BIT(POWER_DOMAIN_AUX_D) | \
Daniel Vetter9c065a72014-09-30 10:56:38 +02001752 BIT(POWER_DOMAIN_INIT))
1753
Daniel Vetter9c065a72014-09-30 10:56:38 +02001754static const struct i915_power_well_ops i9xx_always_on_power_well_ops = {
1755 .sync_hw = i9xx_always_on_power_well_noop,
1756 .enable = i9xx_always_on_power_well_noop,
1757 .disable = i9xx_always_on_power_well_noop,
1758 .is_enabled = i9xx_always_on_power_well_enabled,
1759};
1760
1761static const struct i915_power_well_ops chv_pipe_power_well_ops = {
1762 .sync_hw = chv_pipe_power_well_sync_hw,
1763 .enable = chv_pipe_power_well_enable,
1764 .disable = chv_pipe_power_well_disable,
1765 .is_enabled = chv_pipe_power_well_enabled,
1766};
1767
1768static const struct i915_power_well_ops chv_dpio_cmn_power_well_ops = {
1769 .sync_hw = vlv_power_well_sync_hw,
1770 .enable = chv_dpio_cmn_power_well_enable,
1771 .disable = chv_dpio_cmn_power_well_disable,
1772 .is_enabled = vlv_power_well_enabled,
1773};
1774
1775static struct i915_power_well i9xx_always_on_power_well[] = {
1776 {
1777 .name = "always-on",
1778 .always_on = 1,
1779 .domains = POWER_DOMAIN_MASK,
1780 .ops = &i9xx_always_on_power_well_ops,
1781 },
1782};
1783
1784static const struct i915_power_well_ops hsw_power_well_ops = {
1785 .sync_hw = hsw_power_well_sync_hw,
1786 .enable = hsw_power_well_enable,
1787 .disable = hsw_power_well_disable,
1788 .is_enabled = hsw_power_well_enabled,
1789};
1790
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00001791static const struct i915_power_well_ops skl_power_well_ops = {
1792 .sync_hw = skl_power_well_sync_hw,
1793 .enable = skl_power_well_enable,
1794 .disable = skl_power_well_disable,
1795 .is_enabled = skl_power_well_enabled,
1796};
1797
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01001798static const struct i915_power_well_ops gen9_dc_off_power_well_ops = {
1799 .sync_hw = gen9_dc_off_power_well_sync_hw,
1800 .enable = gen9_dc_off_power_well_enable,
1801 .disable = gen9_dc_off_power_well_disable,
1802 .is_enabled = gen9_dc_off_power_well_enabled,
1803};
1804
Daniel Vetter9c065a72014-09-30 10:56:38 +02001805static struct i915_power_well hsw_power_wells[] = {
1806 {
1807 .name = "always-on",
1808 .always_on = 1,
Ville Syrjälä998bd662016-04-18 14:02:26 +03001809 .domains = POWER_DOMAIN_MASK,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001810 .ops = &i9xx_always_on_power_well_ops,
1811 },
1812 {
1813 .name = "display",
1814 .domains = HSW_DISPLAY_POWER_DOMAINS,
1815 .ops = &hsw_power_well_ops,
1816 },
1817};
1818
1819static struct i915_power_well bdw_power_wells[] = {
1820 {
1821 .name = "always-on",
1822 .always_on = 1,
Ville Syrjälä998bd662016-04-18 14:02:26 +03001823 .domains = POWER_DOMAIN_MASK,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001824 .ops = &i9xx_always_on_power_well_ops,
1825 },
1826 {
1827 .name = "display",
1828 .domains = BDW_DISPLAY_POWER_DOMAINS,
1829 .ops = &hsw_power_well_ops,
1830 },
1831};
1832
1833static const struct i915_power_well_ops vlv_display_power_well_ops = {
1834 .sync_hw = vlv_power_well_sync_hw,
1835 .enable = vlv_display_power_well_enable,
1836 .disable = vlv_display_power_well_disable,
1837 .is_enabled = vlv_power_well_enabled,
1838};
1839
1840static const struct i915_power_well_ops vlv_dpio_cmn_power_well_ops = {
1841 .sync_hw = vlv_power_well_sync_hw,
1842 .enable = vlv_dpio_cmn_power_well_enable,
1843 .disable = vlv_dpio_cmn_power_well_disable,
1844 .is_enabled = vlv_power_well_enabled,
1845};
1846
1847static const struct i915_power_well_ops vlv_dpio_power_well_ops = {
1848 .sync_hw = vlv_power_well_sync_hw,
1849 .enable = vlv_power_well_enable,
1850 .disable = vlv_power_well_disable,
1851 .is_enabled = vlv_power_well_enabled,
1852};
1853
1854static struct i915_power_well vlv_power_wells[] = {
1855 {
1856 .name = "always-on",
1857 .always_on = 1,
Ville Syrjälä998bd662016-04-18 14:02:26 +03001858 .domains = POWER_DOMAIN_MASK,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001859 .ops = &i9xx_always_on_power_well_ops,
Imre Deak56fcfd62015-11-04 19:24:10 +02001860 .data = PUNIT_POWER_WELL_ALWAYS_ON,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001861 },
1862 {
1863 .name = "display",
1864 .domains = VLV_DISPLAY_POWER_DOMAINS,
1865 .data = PUNIT_POWER_WELL_DISP2D,
1866 .ops = &vlv_display_power_well_ops,
1867 },
1868 {
1869 .name = "dpio-tx-b-01",
1870 .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
1871 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
1872 VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
1873 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
1874 .ops = &vlv_dpio_power_well_ops,
1875 .data = PUNIT_POWER_WELL_DPIO_TX_B_LANES_01,
1876 },
1877 {
1878 .name = "dpio-tx-b-23",
1879 .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
1880 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
1881 VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
1882 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
1883 .ops = &vlv_dpio_power_well_ops,
1884 .data = PUNIT_POWER_WELL_DPIO_TX_B_LANES_23,
1885 },
1886 {
1887 .name = "dpio-tx-c-01",
1888 .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
1889 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
1890 VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
1891 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
1892 .ops = &vlv_dpio_power_well_ops,
1893 .data = PUNIT_POWER_WELL_DPIO_TX_C_LANES_01,
1894 },
1895 {
1896 .name = "dpio-tx-c-23",
1897 .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
1898 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
1899 VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
1900 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
1901 .ops = &vlv_dpio_power_well_ops,
1902 .data = PUNIT_POWER_WELL_DPIO_TX_C_LANES_23,
1903 },
1904 {
1905 .name = "dpio-common",
1906 .domains = VLV_DPIO_CMN_BC_POWER_DOMAINS,
1907 .data = PUNIT_POWER_WELL_DPIO_CMN_BC,
1908 .ops = &vlv_dpio_cmn_power_well_ops,
1909 },
1910};
1911
1912static struct i915_power_well chv_power_wells[] = {
1913 {
1914 .name = "always-on",
1915 .always_on = 1,
Ville Syrjälä998bd662016-04-18 14:02:26 +03001916 .domains = POWER_DOMAIN_MASK,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001917 .ops = &i9xx_always_on_power_well_ops,
1918 },
Daniel Vetter9c065a72014-09-30 10:56:38 +02001919 {
1920 .name = "display",
Ville Syrjäläbaa4e572014-10-27 16:07:32 +02001921 /*
Ville Syrjäläfde61e42015-05-26 20:22:39 +03001922 * Pipe A power well is the new disp2d well. Pipe B and C
1923 * power wells don't actually exist. Pipe A power well is
1924 * required for any pipe to work.
Ville Syrjäläbaa4e572014-10-27 16:07:32 +02001925 */
Ville Syrjälä465ac0c2016-04-18 14:02:27 +03001926 .domains = CHV_DISPLAY_POWER_DOMAINS,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001927 .data = PIPE_A,
1928 .ops = &chv_pipe_power_well_ops,
1929 },
Daniel Vetter9c065a72014-09-30 10:56:38 +02001930 {
1931 .name = "dpio-common-bc",
Ville Syrjälä71849b62015-04-10 18:21:29 +03001932 .domains = CHV_DPIO_CMN_BC_POWER_DOMAINS,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001933 .data = PUNIT_POWER_WELL_DPIO_CMN_BC,
1934 .ops = &chv_dpio_cmn_power_well_ops,
1935 },
1936 {
1937 .name = "dpio-common-d",
Ville Syrjälä71849b62015-04-10 18:21:29 +03001938 .domains = CHV_DPIO_CMN_D_POWER_DOMAINS,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001939 .data = PUNIT_POWER_WELL_DPIO_CMN_D,
1940 .ops = &chv_dpio_cmn_power_well_ops,
1941 },
Daniel Vetter9c065a72014-09-30 10:56:38 +02001942};
1943
Suketu Shah5aefb232015-04-16 14:22:10 +05301944bool intel_display_power_well_is_enabled(struct drm_i915_private *dev_priv,
1945 int power_well_id)
1946{
1947 struct i915_power_well *power_well;
1948 bool ret;
1949
1950 power_well = lookup_power_well(dev_priv, power_well_id);
1951 ret = power_well->ops->is_enabled(dev_priv, power_well);
1952
1953 return ret;
1954}
1955
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00001956static struct i915_power_well skl_power_wells[] = {
1957 {
1958 .name = "always-on",
1959 .always_on = 1,
Ville Syrjälä998bd662016-04-18 14:02:26 +03001960 .domains = POWER_DOMAIN_MASK,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00001961 .ops = &i9xx_always_on_power_well_ops,
Imre Deak56fcfd62015-11-04 19:24:10 +02001962 .data = SKL_DISP_PW_ALWAYS_ON,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00001963 },
1964 {
1965 .name = "power well 1",
Imre Deak4a76f292015-11-04 19:24:15 +02001966 /* Handled by the DMC firmware */
1967 .domains = 0,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00001968 .ops = &skl_power_well_ops,
1969 .data = SKL_DISP_PW_1,
1970 },
1971 {
1972 .name = "MISC IO power well",
Imre Deak4a76f292015-11-04 19:24:15 +02001973 /* Handled by the DMC firmware */
1974 .domains = 0,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00001975 .ops = &skl_power_well_ops,
1976 .data = SKL_DISP_PW_MISC_IO,
1977 },
1978 {
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01001979 .name = "DC off",
1980 .domains = SKL_DISPLAY_DC_OFF_POWER_DOMAINS,
1981 .ops = &gen9_dc_off_power_well_ops,
1982 .data = SKL_DISP_PW_DC_OFF,
1983 },
1984 {
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00001985 .name = "power well 2",
1986 .domains = SKL_DISPLAY_POWERWELL_2_POWER_DOMAINS,
1987 .ops = &skl_power_well_ops,
1988 .data = SKL_DISP_PW_2,
1989 },
1990 {
1991 .name = "DDI A/E power well",
1992 .domains = SKL_DISPLAY_DDI_A_E_POWER_DOMAINS,
1993 .ops = &skl_power_well_ops,
1994 .data = SKL_DISP_PW_DDI_A_E,
1995 },
1996 {
1997 .name = "DDI B power well",
1998 .domains = SKL_DISPLAY_DDI_B_POWER_DOMAINS,
1999 .ops = &skl_power_well_ops,
2000 .data = SKL_DISP_PW_DDI_B,
2001 },
2002 {
2003 .name = "DDI C power well",
2004 .domains = SKL_DISPLAY_DDI_C_POWER_DOMAINS,
2005 .ops = &skl_power_well_ops,
2006 .data = SKL_DISP_PW_DDI_C,
2007 },
2008 {
2009 .name = "DDI D power well",
2010 .domains = SKL_DISPLAY_DDI_D_POWER_DOMAINS,
2011 .ops = &skl_power_well_ops,
2012 .data = SKL_DISP_PW_DDI_D,
2013 },
2014};
2015
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302016static struct i915_power_well bxt_power_wells[] = {
2017 {
2018 .name = "always-on",
2019 .always_on = 1,
Ville Syrjälä998bd662016-04-18 14:02:26 +03002020 .domains = POWER_DOMAIN_MASK,
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302021 .ops = &i9xx_always_on_power_well_ops,
2022 },
2023 {
2024 .name = "power well 1",
Imre Deakd7d7c9e2016-04-01 16:02:42 +03002025 .domains = 0,
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302026 .ops = &skl_power_well_ops,
2027 .data = SKL_DISP_PW_1,
2028 },
2029 {
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01002030 .name = "DC off",
2031 .domains = BXT_DISPLAY_DC_OFF_POWER_DOMAINS,
2032 .ops = &gen9_dc_off_power_well_ops,
2033 .data = SKL_DISP_PW_DC_OFF,
2034 },
2035 {
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302036 .name = "power well 2",
2037 .domains = BXT_DISPLAY_POWERWELL_2_POWER_DOMAINS,
2038 .ops = &skl_power_well_ops,
2039 .data = SKL_DISP_PW_2,
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01002040 },
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302041};
2042
Imre Deak1b0e3a02015-11-05 23:04:11 +02002043static int
2044sanitize_disable_power_well_option(const struct drm_i915_private *dev_priv,
2045 int disable_power_well)
2046{
2047 if (disable_power_well >= 0)
2048 return !!disable_power_well;
2049
Imre Deak1b0e3a02015-11-05 23:04:11 +02002050 return 1;
2051}
2052
Imre Deaka37baf32016-02-29 22:49:03 +02002053static uint32_t get_allowed_dc_mask(const struct drm_i915_private *dev_priv,
2054 int enable_dc)
2055{
2056 uint32_t mask;
2057 int requested_dc;
2058 int max_dc;
2059
2060 if (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv)) {
2061 max_dc = 2;
2062 mask = 0;
2063 } else if (IS_BROXTON(dev_priv)) {
2064 max_dc = 1;
2065 /*
2066 * DC9 has a separate HW flow from the rest of the DC states,
2067 * not depending on the DMC firmware. It's needed by system
2068 * suspend/resume, so allow it unconditionally.
2069 */
2070 mask = DC_STATE_EN_DC9;
2071 } else {
2072 max_dc = 0;
2073 mask = 0;
2074 }
2075
Imre Deak66e2c4c2016-02-29 22:49:04 +02002076 if (!i915.disable_power_well)
2077 max_dc = 0;
2078
Imre Deaka37baf32016-02-29 22:49:03 +02002079 if (enable_dc >= 0 && enable_dc <= max_dc) {
2080 requested_dc = enable_dc;
2081 } else if (enable_dc == -1) {
2082 requested_dc = max_dc;
2083 } else if (enable_dc > max_dc && enable_dc <= 2) {
2084 DRM_DEBUG_KMS("Adjusting requested max DC state (%d->%d)\n",
2085 enable_dc, max_dc);
2086 requested_dc = max_dc;
2087 } else {
2088 DRM_ERROR("Unexpected value for enable_dc (%d)\n", enable_dc);
2089 requested_dc = max_dc;
2090 }
2091
2092 if (requested_dc > 1)
2093 mask |= DC_STATE_EN_UPTO_DC6;
2094 if (requested_dc > 0)
2095 mask |= DC_STATE_EN_UPTO_DC5;
2096
2097 DRM_DEBUG_KMS("Allowed DC state mask %02x\n", mask);
2098
2099 return mask;
2100}
2101
Daniel Vetter9c065a72014-09-30 10:56:38 +02002102#define set_power_wells(power_domains, __power_wells) ({ \
2103 (power_domains)->power_wells = (__power_wells); \
2104 (power_domains)->power_well_count = ARRAY_SIZE(__power_wells); \
2105})
2106
Daniel Vettere4e76842014-09-30 10:56:42 +02002107/**
2108 * intel_power_domains_init - initializes the power domain structures
2109 * @dev_priv: i915 device instance
2110 *
2111 * Initializes the power domain structures for @dev_priv depending upon the
2112 * supported platform.
2113 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02002114int intel_power_domains_init(struct drm_i915_private *dev_priv)
2115{
2116 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2117
Imre Deak1b0e3a02015-11-05 23:04:11 +02002118 i915.disable_power_well = sanitize_disable_power_well_option(dev_priv,
2119 i915.disable_power_well);
Imre Deaka37baf32016-02-29 22:49:03 +02002120 dev_priv->csr.allowed_dc_mask = get_allowed_dc_mask(dev_priv,
2121 i915.enable_dc);
Imre Deak1b0e3a02015-11-05 23:04:11 +02002122
Ville Syrjäläf0ab43e2015-11-09 16:48:19 +01002123 BUILD_BUG_ON(POWER_DOMAIN_NUM > 31);
2124
Daniel Vetter9c065a72014-09-30 10:56:38 +02002125 mutex_init(&power_domains->lock);
2126
2127 /*
2128 * The enabling order will be from lower to higher indexed wells,
2129 * the disabling order is reversed.
2130 */
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002131 if (IS_HASWELL(dev_priv)) {
Daniel Vetter9c065a72014-09-30 10:56:38 +02002132 set_power_wells(power_domains, hsw_power_wells);
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002133 } else if (IS_BROADWELL(dev_priv)) {
Daniel Vetter9c065a72014-09-30 10:56:38 +02002134 set_power_wells(power_domains, bdw_power_wells);
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002135 } else if (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv)) {
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002136 set_power_wells(power_domains, skl_power_wells);
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002137 } else if (IS_BROXTON(dev_priv)) {
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302138 set_power_wells(power_domains, bxt_power_wells);
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002139 } else if (IS_CHERRYVIEW(dev_priv)) {
Daniel Vetter9c065a72014-09-30 10:56:38 +02002140 set_power_wells(power_domains, chv_power_wells);
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002141 } else if (IS_VALLEYVIEW(dev_priv)) {
Daniel Vetter9c065a72014-09-30 10:56:38 +02002142 set_power_wells(power_domains, vlv_power_wells);
2143 } else {
2144 set_power_wells(power_domains, i9xx_always_on_power_well);
2145 }
2146
2147 return 0;
2148}
2149
Daniel Vettere4e76842014-09-30 10:56:42 +02002150/**
2151 * intel_power_domains_fini - finalizes the power domain structures
2152 * @dev_priv: i915 device instance
2153 *
2154 * Finalizes the power domain structures for @dev_priv depending upon the
2155 * supported platform. This function also disables runtime pm and ensures that
2156 * the device stays powered up so that the driver can be reloaded.
2157 */
Daniel Vetterf458ebb2014-09-30 10:56:39 +02002158void intel_power_domains_fini(struct drm_i915_private *dev_priv)
Daniel Vetter9c065a72014-09-30 10:56:38 +02002159{
Imre Deak25b181b2015-12-17 13:44:56 +02002160 struct device *device = &dev_priv->dev->pdev->dev;
2161
Imre Deakaabee1b2015-12-15 20:10:29 +02002162 /*
2163 * The i915.ko module is still not prepared to be loaded when
Daniel Vetterf458ebb2014-09-30 10:56:39 +02002164 * the power well is not enabled, so just enable it in case
Imre Deakaabee1b2015-12-15 20:10:29 +02002165 * we're going to unload/reload.
2166 * The following also reacquires the RPM reference the core passed
2167 * to the driver during loading, which is dropped in
2168 * intel_runtime_pm_enable(). We have to hand back the control of the
2169 * device to the core with this reference held.
2170 */
Daniel Vetterf458ebb2014-09-30 10:56:39 +02002171 intel_display_set_init_power(dev_priv, true);
Imre Deakd314cd42015-11-17 17:44:23 +02002172
2173 /* Remove the refcount we took to keep power well support disabled. */
2174 if (!i915.disable_power_well)
2175 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
Imre Deak25b181b2015-12-17 13:44:56 +02002176
2177 /*
2178 * Remove the refcount we took in intel_runtime_pm_enable() in case
2179 * the platform doesn't support runtime PM.
2180 */
2181 if (!HAS_RUNTIME_PM(dev_priv))
2182 pm_runtime_put(device);
Daniel Vetter9c065a72014-09-30 10:56:38 +02002183}
2184
Imre Deak30eade12015-11-04 19:24:13 +02002185static void intel_power_domains_sync_hw(struct drm_i915_private *dev_priv)
Daniel Vetter9c065a72014-09-30 10:56:38 +02002186{
2187 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2188 struct i915_power_well *power_well;
2189 int i;
2190
2191 mutex_lock(&power_domains->lock);
2192 for_each_power_well(i, power_well, POWER_DOMAIN_MASK, power_domains) {
2193 power_well->ops->sync_hw(dev_priv, power_well);
2194 power_well->hw_enabled = power_well->ops->is_enabled(dev_priv,
2195 power_well);
2196 }
2197 mutex_unlock(&power_domains->lock);
2198}
2199
Ville Syrjälä70c2c182016-05-13 23:41:30 +03002200static void gen9_dbuf_enable(struct drm_i915_private *dev_priv)
2201{
2202 I915_WRITE(DBUF_CTL, I915_READ(DBUF_CTL) | DBUF_POWER_REQUEST);
2203 POSTING_READ(DBUF_CTL);
2204
2205 udelay(10);
2206
2207 if (!(I915_READ(DBUF_CTL) & DBUF_POWER_STATE))
2208 DRM_ERROR("DBuf power enable timeout\n");
2209}
2210
2211static void gen9_dbuf_disable(struct drm_i915_private *dev_priv)
2212{
2213 I915_WRITE(DBUF_CTL, I915_READ(DBUF_CTL) & ~DBUF_POWER_REQUEST);
2214 POSTING_READ(DBUF_CTL);
2215
2216 udelay(10);
2217
2218 if (I915_READ(DBUF_CTL) & DBUF_POWER_STATE)
2219 DRM_ERROR("DBuf power disable timeout!\n");
2220}
2221
Imre Deak73dfc222015-11-17 17:33:53 +02002222static void skl_display_core_init(struct drm_i915_private *dev_priv,
Imre Deak443a93a2016-04-04 15:42:57 +03002223 bool resume)
Imre Deak73dfc222015-11-17 17:33:53 +02002224{
2225 struct i915_power_domains *power_domains = &dev_priv->power_domains;
Imre Deak443a93a2016-04-04 15:42:57 +03002226 struct i915_power_well *well;
Imre Deak73dfc222015-11-17 17:33:53 +02002227 uint32_t val;
2228
Imre Deakd26fa1d2015-11-04 19:24:17 +02002229 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
2230
Imre Deak73dfc222015-11-17 17:33:53 +02002231 /* enable PCH reset handshake */
2232 val = I915_READ(HSW_NDE_RSTWRN_OPT);
2233 I915_WRITE(HSW_NDE_RSTWRN_OPT, val | RESET_PCH_HANDSHAKE_ENABLE);
2234
2235 /* enable PG1 and Misc I/O */
2236 mutex_lock(&power_domains->lock);
Imre Deak443a93a2016-04-04 15:42:57 +03002237
2238 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
2239 intel_power_well_enable(dev_priv, well);
2240
2241 well = lookup_power_well(dev_priv, SKL_DISP_PW_MISC_IO);
2242 intel_power_well_enable(dev_priv, well);
2243
Imre Deak73dfc222015-11-17 17:33:53 +02002244 mutex_unlock(&power_domains->lock);
2245
Imre Deak73dfc222015-11-17 17:33:53 +02002246 skl_init_cdclk(dev_priv);
2247
Ville Syrjälä70c2c182016-05-13 23:41:30 +03002248 gen9_dbuf_enable(dev_priv);
2249
Ville Syrjälä9f7eb312016-05-13 23:41:29 +03002250 if (resume && dev_priv->csr.dmc_payload)
Imre Deak2abc5252016-03-04 21:57:41 +02002251 intel_csr_load_program(dev_priv);
Imre Deak73dfc222015-11-17 17:33:53 +02002252}
2253
2254static void skl_display_core_uninit(struct drm_i915_private *dev_priv)
2255{
2256 struct i915_power_domains *power_domains = &dev_priv->power_domains;
Imre Deak443a93a2016-04-04 15:42:57 +03002257 struct i915_power_well *well;
Imre Deak73dfc222015-11-17 17:33:53 +02002258
Imre Deakd26fa1d2015-11-04 19:24:17 +02002259 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
2260
Ville Syrjälä70c2c182016-05-13 23:41:30 +03002261 gen9_dbuf_disable(dev_priv);
2262
Imre Deak73dfc222015-11-17 17:33:53 +02002263 skl_uninit_cdclk(dev_priv);
2264
2265 /* The spec doesn't call for removing the reset handshake flag */
2266 /* disable PG1 and Misc I/O */
Imre Deak443a93a2016-04-04 15:42:57 +03002267
Imre Deak73dfc222015-11-17 17:33:53 +02002268 mutex_lock(&power_domains->lock);
Imre Deak443a93a2016-04-04 15:42:57 +03002269
2270 well = lookup_power_well(dev_priv, SKL_DISP_PW_MISC_IO);
2271 intel_power_well_disable(dev_priv, well);
2272
2273 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
2274 intel_power_well_disable(dev_priv, well);
2275
Imre Deak73dfc222015-11-17 17:33:53 +02002276 mutex_unlock(&power_domains->lock);
2277}
2278
Imre Deakd7d7c9e2016-04-01 16:02:42 +03002279void bxt_display_core_init(struct drm_i915_private *dev_priv,
2280 bool resume)
2281{
2282 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2283 struct i915_power_well *well;
2284 uint32_t val;
2285
2286 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
2287
2288 /*
2289 * NDE_RSTWRN_OPT RST PCH Handshake En must always be 0b on BXT
2290 * or else the reset will hang because there is no PCH to respond.
2291 * Move the handshake programming to initialization sequence.
2292 * Previously was left up to BIOS.
2293 */
2294 val = I915_READ(HSW_NDE_RSTWRN_OPT);
2295 val &= ~RESET_PCH_HANDSHAKE_ENABLE;
2296 I915_WRITE(HSW_NDE_RSTWRN_OPT, val);
2297
2298 /* Enable PG1 */
2299 mutex_lock(&power_domains->lock);
2300
2301 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
2302 intel_power_well_enable(dev_priv, well);
2303
2304 mutex_unlock(&power_domains->lock);
2305
2306 broxton_init_cdclk(dev_priv);
Ville Syrjälä70c2c182016-05-13 23:41:30 +03002307
2308 gen9_dbuf_enable(dev_priv);
2309
Imre Deakd7d7c9e2016-04-01 16:02:42 +03002310 broxton_ddi_phy_init(dev_priv);
2311
Imre Deakadc7f042016-04-04 17:27:10 +03002312 broxton_ddi_phy_verify_state(dev_priv);
2313
Imre Deakd7d7c9e2016-04-01 16:02:42 +03002314 if (resume && dev_priv->csr.dmc_payload)
2315 intel_csr_load_program(dev_priv);
2316}
2317
2318void bxt_display_core_uninit(struct drm_i915_private *dev_priv)
2319{
2320 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2321 struct i915_power_well *well;
2322
2323 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
2324
2325 broxton_ddi_phy_uninit(dev_priv);
Ville Syrjälä70c2c182016-05-13 23:41:30 +03002326
2327 gen9_dbuf_disable(dev_priv);
2328
Imre Deakd7d7c9e2016-04-01 16:02:42 +03002329 broxton_uninit_cdclk(dev_priv);
2330
2331 /* The spec doesn't call for removing the reset handshake flag */
2332
2333 /* Disable PG1 */
2334 mutex_lock(&power_domains->lock);
2335
2336 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
2337 intel_power_well_disable(dev_priv, well);
2338
2339 mutex_unlock(&power_domains->lock);
2340}
2341
Ville Syrjälä70722462015-04-10 18:21:28 +03002342static void chv_phy_control_init(struct drm_i915_private *dev_priv)
2343{
2344 struct i915_power_well *cmn_bc =
2345 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_BC);
2346 struct i915_power_well *cmn_d =
2347 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_D);
2348
2349 /*
2350 * DISPLAY_PHY_CONTROL can get corrupted if read. As a
2351 * workaround never ever read DISPLAY_PHY_CONTROL, and
2352 * instead maintain a shadow copy ourselves. Use the actual
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002353 * power well state and lane status to reconstruct the
2354 * expected initial value.
Ville Syrjälä70722462015-04-10 18:21:28 +03002355 */
2356 dev_priv->chv_phy_control =
Ville Syrjäläbc284542015-05-26 20:22:38 +03002357 PHY_LDO_SEQ_DELAY(PHY_LDO_DELAY_600NS, DPIO_PHY0) |
2358 PHY_LDO_SEQ_DELAY(PHY_LDO_DELAY_600NS, DPIO_PHY1) |
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002359 PHY_CH_POWER_MODE(PHY_CH_DEEP_PSR, DPIO_PHY0, DPIO_CH0) |
2360 PHY_CH_POWER_MODE(PHY_CH_DEEP_PSR, DPIO_PHY0, DPIO_CH1) |
2361 PHY_CH_POWER_MODE(PHY_CH_DEEP_PSR, DPIO_PHY1, DPIO_CH0);
2362
2363 /*
2364 * If all lanes are disabled we leave the override disabled
2365 * with all power down bits cleared to match the state we
2366 * would use after disabling the port. Otherwise enable the
2367 * override and set the lane powerdown bits accding to the
2368 * current lane status.
2369 */
2370 if (cmn_bc->ops->is_enabled(dev_priv, cmn_bc)) {
2371 uint32_t status = I915_READ(DPLL(PIPE_A));
2372 unsigned int mask;
2373
2374 mask = status & DPLL_PORTB_READY_MASK;
2375 if (mask == 0xf)
2376 mask = 0x0;
2377 else
2378 dev_priv->chv_phy_control |=
2379 PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY0, DPIO_CH0);
2380
2381 dev_priv->chv_phy_control |=
2382 PHY_CH_POWER_DOWN_OVRD(mask, DPIO_PHY0, DPIO_CH0);
2383
2384 mask = (status & DPLL_PORTC_READY_MASK) >> 4;
2385 if (mask == 0xf)
2386 mask = 0x0;
2387 else
2388 dev_priv->chv_phy_control |=
2389 PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY0, DPIO_CH1);
2390
2391 dev_priv->chv_phy_control |=
2392 PHY_CH_POWER_DOWN_OVRD(mask, DPIO_PHY0, DPIO_CH1);
2393
Ville Syrjälä70722462015-04-10 18:21:28 +03002394 dev_priv->chv_phy_control |= PHY_COM_LANE_RESET_DEASSERT(DPIO_PHY0);
Ville Syrjälä3be60de2015-09-08 18:05:45 +03002395
2396 dev_priv->chv_phy_assert[DPIO_PHY0] = false;
2397 } else {
2398 dev_priv->chv_phy_assert[DPIO_PHY0] = true;
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002399 }
2400
2401 if (cmn_d->ops->is_enabled(dev_priv, cmn_d)) {
2402 uint32_t status = I915_READ(DPIO_PHY_STATUS);
2403 unsigned int mask;
2404
2405 mask = status & DPLL_PORTD_READY_MASK;
2406
2407 if (mask == 0xf)
2408 mask = 0x0;
2409 else
2410 dev_priv->chv_phy_control |=
2411 PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY1, DPIO_CH0);
2412
2413 dev_priv->chv_phy_control |=
2414 PHY_CH_POWER_DOWN_OVRD(mask, DPIO_PHY1, DPIO_CH0);
2415
Ville Syrjälä70722462015-04-10 18:21:28 +03002416 dev_priv->chv_phy_control |= PHY_COM_LANE_RESET_DEASSERT(DPIO_PHY1);
Ville Syrjälä3be60de2015-09-08 18:05:45 +03002417
2418 dev_priv->chv_phy_assert[DPIO_PHY1] = false;
2419 } else {
2420 dev_priv->chv_phy_assert[DPIO_PHY1] = true;
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002421 }
2422
2423 I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
2424
2425 DRM_DEBUG_KMS("Initial PHY_CONTROL=0x%08x\n",
2426 dev_priv->chv_phy_control);
Ville Syrjälä70722462015-04-10 18:21:28 +03002427}
2428
Daniel Vetter9c065a72014-09-30 10:56:38 +02002429static void vlv_cmnlane_wa(struct drm_i915_private *dev_priv)
2430{
2431 struct i915_power_well *cmn =
2432 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_BC);
2433 struct i915_power_well *disp2d =
2434 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DISP2D);
2435
Daniel Vetter9c065a72014-09-30 10:56:38 +02002436 /* If the display might be already active skip this */
Ville Syrjälä5d93a6e2014-10-16 20:52:33 +03002437 if (cmn->ops->is_enabled(dev_priv, cmn) &&
2438 disp2d->ops->is_enabled(dev_priv, disp2d) &&
Daniel Vetter9c065a72014-09-30 10:56:38 +02002439 I915_READ(DPIO_CTL) & DPIO_CMNRST)
2440 return;
2441
2442 DRM_DEBUG_KMS("toggling display PHY side reset\n");
2443
2444 /* cmnlane needs DPLL registers */
2445 disp2d->ops->enable(dev_priv, disp2d);
2446
2447 /*
2448 * From VLV2A0_DP_eDP_HDMI_DPIO_driver_vbios_notes_11.docx:
2449 * Need to assert and de-assert PHY SB reset by gating the
2450 * common lane power, then un-gating it.
2451 * Simply ungating isn't enough to reset the PHY enough to get
2452 * ports and lanes running.
2453 */
2454 cmn->ops->disable(dev_priv, cmn);
2455}
2456
Daniel Vettere4e76842014-09-30 10:56:42 +02002457/**
2458 * intel_power_domains_init_hw - initialize hardware power domain state
2459 * @dev_priv: i915 device instance
Tvrtko Ursulin14bb2c12016-06-03 14:02:17 +01002460 * @resume: Called from resume code paths or not
Daniel Vettere4e76842014-09-30 10:56:42 +02002461 *
2462 * This function initializes the hardware power domain state and enables all
2463 * power domains using intel_display_set_init_power().
2464 */
Imre Deak73dfc222015-11-17 17:33:53 +02002465void intel_power_domains_init_hw(struct drm_i915_private *dev_priv, bool resume)
Daniel Vetter9c065a72014-09-30 10:56:38 +02002466{
2467 struct drm_device *dev = dev_priv->dev;
2468 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2469
2470 power_domains->initializing = true;
2471
Imre Deak73dfc222015-11-17 17:33:53 +02002472 if (IS_SKYLAKE(dev) || IS_KABYLAKE(dev)) {
2473 skl_display_core_init(dev_priv, resume);
Imre Deakd7d7c9e2016-04-01 16:02:42 +03002474 } else if (IS_BROXTON(dev)) {
2475 bxt_display_core_init(dev_priv, resume);
Imre Deak73dfc222015-11-17 17:33:53 +02002476 } else if (IS_CHERRYVIEW(dev)) {
Ville Syrjälä770effb2015-07-08 23:45:51 +03002477 mutex_lock(&power_domains->lock);
Ville Syrjälä70722462015-04-10 18:21:28 +03002478 chv_phy_control_init(dev_priv);
Ville Syrjälä770effb2015-07-08 23:45:51 +03002479 mutex_unlock(&power_domains->lock);
Ville Syrjälä70722462015-04-10 18:21:28 +03002480 } else if (IS_VALLEYVIEW(dev)) {
Daniel Vetter9c065a72014-09-30 10:56:38 +02002481 mutex_lock(&power_domains->lock);
2482 vlv_cmnlane_wa(dev_priv);
2483 mutex_unlock(&power_domains->lock);
2484 }
2485
2486 /* For now, we need the power well to be always enabled. */
2487 intel_display_set_init_power(dev_priv, true);
Imre Deakd314cd42015-11-17 17:44:23 +02002488 /* Disable power support if the user asked so. */
2489 if (!i915.disable_power_well)
2490 intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
Imre Deak30eade12015-11-04 19:24:13 +02002491 intel_power_domains_sync_hw(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02002492 power_domains->initializing = false;
2493}
2494
Daniel Vettere4e76842014-09-30 10:56:42 +02002495/**
Imre Deak73dfc222015-11-17 17:33:53 +02002496 * intel_power_domains_suspend - suspend power domain state
2497 * @dev_priv: i915 device instance
2498 *
2499 * This function prepares the hardware power domain state before entering
2500 * system suspend. It must be paired with intel_power_domains_init_hw().
2501 */
2502void intel_power_domains_suspend(struct drm_i915_private *dev_priv)
2503{
Imre Deakd314cd42015-11-17 17:44:23 +02002504 /*
2505 * Even if power well support was disabled we still want to disable
2506 * power wells while we are system suspended.
2507 */
2508 if (!i915.disable_power_well)
2509 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
Imre Deak2622d792016-02-29 22:49:02 +02002510
2511 if (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv))
2512 skl_display_core_uninit(dev_priv);
Imre Deakd7d7c9e2016-04-01 16:02:42 +03002513 else if (IS_BROXTON(dev_priv))
2514 bxt_display_core_uninit(dev_priv);
Imre Deak73dfc222015-11-17 17:33:53 +02002515}
2516
2517/**
Daniel Vettere4e76842014-09-30 10:56:42 +02002518 * intel_runtime_pm_get - grab a runtime pm reference
2519 * @dev_priv: i915 device instance
2520 *
2521 * This function grabs a device-level runtime pm reference (mostly used for GEM
2522 * code to ensure the GTT or GT is on) and ensures that it is powered up.
2523 *
2524 * Any runtime pm reference obtained by this function must have a symmetric
2525 * call to intel_runtime_pm_put() to release the reference again.
2526 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02002527void intel_runtime_pm_get(struct drm_i915_private *dev_priv)
2528{
2529 struct drm_device *dev = dev_priv->dev;
2530 struct device *device = &dev->pdev->dev;
2531
Daniel Vetter9c065a72014-09-30 10:56:38 +02002532 pm_runtime_get_sync(device);
Imre Deak1f814da2015-12-16 02:52:19 +02002533
2534 atomic_inc(&dev_priv->pm.wakeref_count);
Imre Deakc9b88462015-12-15 20:10:34 +02002535 assert_rpm_wakelock_held(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02002536}
2537
Daniel Vettere4e76842014-09-30 10:56:42 +02002538/**
Imre Deak09731282016-02-17 14:17:42 +02002539 * intel_runtime_pm_get_if_in_use - grab a runtime pm reference if device in use
2540 * @dev_priv: i915 device instance
2541 *
2542 * This function grabs a device-level runtime pm reference if the device is
2543 * already in use and ensures that it is powered up.
2544 *
2545 * Any runtime pm reference obtained by this function must have a symmetric
2546 * call to intel_runtime_pm_put() to release the reference again.
2547 */
2548bool intel_runtime_pm_get_if_in_use(struct drm_i915_private *dev_priv)
2549{
2550 struct drm_device *dev = dev_priv->dev;
2551 struct device *device = &dev->pdev->dev;
Imre Deak09731282016-02-17 14:17:42 +02002552
Chris Wilson135dc792016-02-25 21:10:28 +00002553 if (IS_ENABLED(CONFIG_PM)) {
2554 int ret = pm_runtime_get_if_in_use(device);
Imre Deak09731282016-02-17 14:17:42 +02002555
Chris Wilson135dc792016-02-25 21:10:28 +00002556 /*
2557 * In cases runtime PM is disabled by the RPM core and we get
2558 * an -EINVAL return value we are not supposed to call this
2559 * function, since the power state is undefined. This applies
2560 * atm to the late/early system suspend/resume handlers.
2561 */
2562 WARN_ON_ONCE(ret < 0);
2563 if (ret <= 0)
2564 return false;
2565 }
Imre Deak09731282016-02-17 14:17:42 +02002566
2567 atomic_inc(&dev_priv->pm.wakeref_count);
2568 assert_rpm_wakelock_held(dev_priv);
2569
2570 return true;
2571}
2572
2573/**
Daniel Vettere4e76842014-09-30 10:56:42 +02002574 * intel_runtime_pm_get_noresume - grab a runtime pm reference
2575 * @dev_priv: i915 device instance
2576 *
2577 * This function grabs a device-level runtime pm reference (mostly used for GEM
2578 * code to ensure the GTT or GT is on).
2579 *
2580 * It will _not_ power up the device but instead only check that it's powered
2581 * on. Therefore it is only valid to call this functions from contexts where
2582 * the device is known to be powered up and where trying to power it up would
2583 * result in hilarity and deadlocks. That pretty much means only the system
2584 * suspend/resume code where this is used to grab runtime pm references for
2585 * delayed setup down in work items.
2586 *
2587 * Any runtime pm reference obtained by this function must have a symmetric
2588 * call to intel_runtime_pm_put() to release the reference again.
2589 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02002590void intel_runtime_pm_get_noresume(struct drm_i915_private *dev_priv)
2591{
2592 struct drm_device *dev = dev_priv->dev;
2593 struct device *device = &dev->pdev->dev;
2594
Imre Deakc9b88462015-12-15 20:10:34 +02002595 assert_rpm_wakelock_held(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02002596 pm_runtime_get_noresume(device);
Imre Deak1f814da2015-12-16 02:52:19 +02002597
2598 atomic_inc(&dev_priv->pm.wakeref_count);
Daniel Vetter9c065a72014-09-30 10:56:38 +02002599}
2600
Daniel Vettere4e76842014-09-30 10:56:42 +02002601/**
2602 * intel_runtime_pm_put - release a runtime pm reference
2603 * @dev_priv: i915 device instance
2604 *
2605 * This function drops the device-level runtime pm reference obtained by
2606 * intel_runtime_pm_get() and might power down the corresponding
2607 * hardware block right away if this is the last reference.
2608 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02002609void intel_runtime_pm_put(struct drm_i915_private *dev_priv)
2610{
2611 struct drm_device *dev = dev_priv->dev;
2612 struct device *device = &dev->pdev->dev;
2613
Imre Deak542db3c2015-12-15 20:10:36 +02002614 assert_rpm_wakelock_held(dev_priv);
Imre Deak2b19efe2015-12-15 20:10:37 +02002615 if (atomic_dec_and_test(&dev_priv->pm.wakeref_count))
2616 atomic_inc(&dev_priv->pm.atomic_seq);
Imre Deak1f814da2015-12-16 02:52:19 +02002617
Daniel Vetter9c065a72014-09-30 10:56:38 +02002618 pm_runtime_mark_last_busy(device);
2619 pm_runtime_put_autosuspend(device);
2620}
2621
Daniel Vettere4e76842014-09-30 10:56:42 +02002622/**
2623 * intel_runtime_pm_enable - enable runtime pm
2624 * @dev_priv: i915 device instance
2625 *
2626 * This function enables runtime pm at the end of the driver load sequence.
2627 *
2628 * Note that this function does currently not enable runtime pm for the
2629 * subordinate display power domains. That is only done on the first modeset
2630 * using intel_display_set_init_power().
2631 */
Daniel Vetterf458ebb2014-09-30 10:56:39 +02002632void intel_runtime_pm_enable(struct drm_i915_private *dev_priv)
Daniel Vetter9c065a72014-09-30 10:56:38 +02002633{
2634 struct drm_device *dev = dev_priv->dev;
2635 struct device *device = &dev->pdev->dev;
2636
Imre Deakcbc68dc2015-12-17 19:04:33 +02002637 pm_runtime_set_autosuspend_delay(device, 10000); /* 10s */
2638 pm_runtime_mark_last_busy(device);
2639
Imre Deak25b181b2015-12-17 13:44:56 +02002640 /*
2641 * Take a permanent reference to disable the RPM functionality and drop
2642 * it only when unloading the driver. Use the low level get/put helpers,
2643 * so the driver's own RPM reference tracking asserts also work on
2644 * platforms without RPM support.
2645 */
Imre Deakcbc68dc2015-12-17 19:04:33 +02002646 if (!HAS_RUNTIME_PM(dev)) {
2647 pm_runtime_dont_use_autosuspend(device);
Imre Deak25b181b2015-12-17 13:44:56 +02002648 pm_runtime_get_sync(device);
Imre Deakcbc68dc2015-12-17 19:04:33 +02002649 } else {
2650 pm_runtime_use_autosuspend(device);
2651 }
Daniel Vetter9c065a72014-09-30 10:56:38 +02002652
Imre Deakaabee1b2015-12-15 20:10:29 +02002653 /*
2654 * The core calls the driver load handler with an RPM reference held.
2655 * We drop that here and will reacquire it during unloading in
2656 * intel_power_domains_fini().
2657 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02002658 pm_runtime_put_autosuspend(device);
2659}
2660