blob: d41a7b0a4c844493febc5e6a6f410d41a8db2dbf [file] [log] [blame]
Daniel Vetter9c065a72014-09-30 10:56:38 +02001/*
2 * Copyright © 2012-2014 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 *
23 * Authors:
24 * Eugeni Dodonov <eugeni.dodonov@intel.com>
25 * Daniel Vetter <daniel.vetter@ffwll.ch>
26 *
27 */
28
29#include <linux/pm_runtime.h>
30#include <linux/vgaarb.h>
31
32#include "i915_drv.h"
33#include "intel_drv.h"
Daniel Vetter9c065a72014-09-30 10:56:38 +020034
Daniel Vettere4e76842014-09-30 10:56:42 +020035/**
36 * DOC: runtime pm
37 *
38 * The i915 driver supports dynamic enabling and disabling of entire hardware
39 * blocks at runtime. This is especially important on the display side where
40 * software is supposed to control many power gates manually on recent hardware,
41 * since on the GT side a lot of the power management is done by the hardware.
42 * But even there some manual control at the device level is required.
43 *
44 * Since i915 supports a diverse set of platforms with a unified codebase and
45 * hardware engineers just love to shuffle functionality around between power
46 * domains there's a sizeable amount of indirection required. This file provides
47 * generic functions to the driver for grabbing and releasing references for
48 * abstract power domains. It then maps those to the actual power wells
49 * present for a given platform.
50 */
51
Suketu Shahf75a1982015-04-16 14:22:11 +053052#define GEN9_ENABLE_DC5(dev) 0
53#define SKL_ENABLE_DC6(dev) IS_SKYLAKE(dev)
Suketu Shahdc174302015-04-17 19:46:16 +053054
Daniel Vetter9c065a72014-09-30 10:56:38 +020055#define for_each_power_well(i, power_well, domain_mask, power_domains) \
56 for (i = 0; \
57 i < (power_domains)->power_well_count && \
58 ((power_well) = &(power_domains)->power_wells[i]); \
59 i++) \
60 if ((power_well)->domains & (domain_mask))
61
62#define for_each_power_well_rev(i, power_well, domain_mask, power_domains) \
63 for (i = (power_domains)->power_well_count - 1; \
64 i >= 0 && ((power_well) = &(power_domains)->power_wells[i]);\
65 i--) \
66 if ((power_well)->domains & (domain_mask))
67
Suketu Shah5aefb232015-04-16 14:22:10 +053068bool intel_display_power_well_is_enabled(struct drm_i915_private *dev_priv,
69 int power_well_id);
70
Damien Lespiaue8ca9322015-07-30 18:20:26 -030071static void intel_power_well_enable(struct drm_i915_private *dev_priv,
72 struct i915_power_well *power_well)
73{
74 DRM_DEBUG_KMS("enabling %s\n", power_well->name);
75 power_well->ops->enable(dev_priv, power_well);
76 power_well->hw_enabled = true;
77}
78
Damien Lespiaudcddab32015-07-30 18:20:27 -030079static void intel_power_well_disable(struct drm_i915_private *dev_priv,
80 struct i915_power_well *power_well)
81{
82 DRM_DEBUG_KMS("disabling %s\n", power_well->name);
83 power_well->hw_enabled = false;
84 power_well->ops->disable(dev_priv, power_well);
85}
86
Daniel Vettere4e76842014-09-30 10:56:42 +020087/*
Daniel Vetter9c065a72014-09-30 10:56:38 +020088 * We should only use the power well if we explicitly asked the hardware to
89 * enable it, so check if it's enabled and also check if we've requested it to
90 * be enabled.
91 */
92static bool hsw_power_well_enabled(struct drm_i915_private *dev_priv,
93 struct i915_power_well *power_well)
94{
95 return I915_READ(HSW_PWR_WELL_DRIVER) ==
96 (HSW_PWR_WELL_ENABLE_REQUEST | HSW_PWR_WELL_STATE_ENABLED);
97}
98
Daniel Vettere4e76842014-09-30 10:56:42 +020099/**
100 * __intel_display_power_is_enabled - unlocked check for a power domain
101 * @dev_priv: i915 device instance
102 * @domain: power domain to check
103 *
104 * This is the unlocked version of intel_display_power_is_enabled() and should
105 * only be used from error capture and recovery code where deadlocks are
106 * possible.
107 *
108 * Returns:
109 * True when the power domain is enabled, false otherwise.
110 */
Daniel Vetterf458ebb2014-09-30 10:56:39 +0200111bool __intel_display_power_is_enabled(struct drm_i915_private *dev_priv,
112 enum intel_display_power_domain domain)
Daniel Vetter9c065a72014-09-30 10:56:38 +0200113{
114 struct i915_power_domains *power_domains;
115 struct i915_power_well *power_well;
116 bool is_enabled;
117 int i;
118
119 if (dev_priv->pm.suspended)
120 return false;
121
122 power_domains = &dev_priv->power_domains;
123
124 is_enabled = true;
125
126 for_each_power_well_rev(i, power_well, BIT(domain), power_domains) {
127 if (power_well->always_on)
128 continue;
129
130 if (!power_well->hw_enabled) {
131 is_enabled = false;
132 break;
133 }
134 }
135
136 return is_enabled;
137}
138
Daniel Vettere4e76842014-09-30 10:56:42 +0200139/**
Damien Lespiauf61ccae2014-11-25 13:45:41 +0000140 * intel_display_power_is_enabled - check for a power domain
Daniel Vettere4e76842014-09-30 10:56:42 +0200141 * @dev_priv: i915 device instance
142 * @domain: power domain to check
143 *
144 * This function can be used to check the hw power domain state. It is mostly
145 * used in hardware state readout functions. Everywhere else code should rely
146 * upon explicit power domain reference counting to ensure that the hardware
147 * block is powered up before accessing it.
148 *
149 * Callers must hold the relevant modesetting locks to ensure that concurrent
150 * threads can't disable the power well while the caller tries to read a few
151 * registers.
152 *
153 * Returns:
154 * True when the power domain is enabled, false otherwise.
155 */
Daniel Vetterf458ebb2014-09-30 10:56:39 +0200156bool intel_display_power_is_enabled(struct drm_i915_private *dev_priv,
157 enum intel_display_power_domain domain)
Daniel Vetter9c065a72014-09-30 10:56:38 +0200158{
159 struct i915_power_domains *power_domains;
160 bool ret;
161
162 power_domains = &dev_priv->power_domains;
163
164 mutex_lock(&power_domains->lock);
Daniel Vetterf458ebb2014-09-30 10:56:39 +0200165 ret = __intel_display_power_is_enabled(dev_priv, domain);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200166 mutex_unlock(&power_domains->lock);
167
168 return ret;
169}
170
Daniel Vettere4e76842014-09-30 10:56:42 +0200171/**
172 * intel_display_set_init_power - set the initial power domain state
173 * @dev_priv: i915 device instance
174 * @enable: whether to enable or disable the initial power domain state
175 *
176 * For simplicity our driver load/unload and system suspend/resume code assumes
177 * that all power domains are always enabled. This functions controls the state
178 * of this little hack. While the initial power domain state is enabled runtime
179 * pm is effectively disabled.
180 */
Daniel Vetterd9bc89d92014-09-30 10:56:40 +0200181void intel_display_set_init_power(struct drm_i915_private *dev_priv,
182 bool enable)
183{
184 if (dev_priv->power_domains.init_power_on == enable)
185 return;
186
187 if (enable)
188 intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
189 else
190 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
191
192 dev_priv->power_domains.init_power_on = enable;
193}
194
Daniel Vetter9c065a72014-09-30 10:56:38 +0200195/*
196 * Starting with Haswell, we have a "Power Down Well" that can be turned off
197 * when not needed anymore. We have 4 registers that can request the power well
198 * to be enabled, and it will only be disabled if none of the registers is
199 * requesting it to be enabled.
200 */
201static void hsw_power_well_post_enable(struct drm_i915_private *dev_priv)
202{
203 struct drm_device *dev = dev_priv->dev;
204
205 /*
206 * After we re-enable the power well, if we touch VGA register 0x3d5
207 * we'll get unclaimed register interrupts. This stops after we write
208 * anything to the VGA MSR register. The vgacon module uses this
209 * register all the time, so if we unbind our driver and, as a
210 * consequence, bind vgacon, we'll get stuck in an infinite loop at
211 * console_unlock(). So make here we touch the VGA MSR register, making
212 * sure vgacon can keep working normally without triggering interrupts
213 * and error messages.
214 */
215 vga_get_uninterruptible(dev->pdev, VGA_RSRC_LEGACY_IO);
216 outb(inb(VGA_MSR_READ), VGA_MSR_WRITE);
217 vga_put(dev->pdev, VGA_RSRC_LEGACY_IO);
218
Damien Lespiau25400392015-03-06 18:50:52 +0000219 if (IS_BROADWELL(dev))
Damien Lespiau4c6c03b2015-03-06 18:50:48 +0000220 gen8_irq_power_well_post_enable(dev_priv,
221 1 << PIPE_C | 1 << PIPE_B);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200222}
223
Damien Lespiaud14c0342015-03-06 18:50:51 +0000224static void skl_power_well_post_enable(struct drm_i915_private *dev_priv,
225 struct i915_power_well *power_well)
226{
227 struct drm_device *dev = dev_priv->dev;
228
229 /*
230 * After we re-enable the power well, if we touch VGA register 0x3d5
231 * we'll get unclaimed register interrupts. This stops after we write
232 * anything to the VGA MSR register. The vgacon module uses this
233 * register all the time, so if we unbind our driver and, as a
234 * consequence, bind vgacon, we'll get stuck in an infinite loop at
235 * console_unlock(). So make here we touch the VGA MSR register, making
236 * sure vgacon can keep working normally without triggering interrupts
237 * and error messages.
238 */
239 if (power_well->data == SKL_DISP_PW_2) {
240 vga_get_uninterruptible(dev->pdev, VGA_RSRC_LEGACY_IO);
241 outb(inb(VGA_MSR_READ), VGA_MSR_WRITE);
242 vga_put(dev->pdev, VGA_RSRC_LEGACY_IO);
243
244 gen8_irq_power_well_post_enable(dev_priv,
245 1 << PIPE_C | 1 << PIPE_B);
246 }
Damien Lespiaud14c0342015-03-06 18:50:51 +0000247}
248
Daniel Vetter9c065a72014-09-30 10:56:38 +0200249static void hsw_set_power_well(struct drm_i915_private *dev_priv,
250 struct i915_power_well *power_well, bool enable)
251{
252 bool is_enabled, enable_requested;
253 uint32_t tmp;
254
255 tmp = I915_READ(HSW_PWR_WELL_DRIVER);
256 is_enabled = tmp & HSW_PWR_WELL_STATE_ENABLED;
257 enable_requested = tmp & HSW_PWR_WELL_ENABLE_REQUEST;
258
259 if (enable) {
260 if (!enable_requested)
261 I915_WRITE(HSW_PWR_WELL_DRIVER,
262 HSW_PWR_WELL_ENABLE_REQUEST);
263
264 if (!is_enabled) {
265 DRM_DEBUG_KMS("Enabling power well\n");
266 if (wait_for((I915_READ(HSW_PWR_WELL_DRIVER) &
267 HSW_PWR_WELL_STATE_ENABLED), 20))
268 DRM_ERROR("Timeout enabling power well\n");
Paulo Zanoni6d729bf2014-10-07 16:11:11 -0300269 hsw_power_well_post_enable(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200270 }
271
Daniel Vetter9c065a72014-09-30 10:56:38 +0200272 } else {
273 if (enable_requested) {
274 I915_WRITE(HSW_PWR_WELL_DRIVER, 0);
275 POSTING_READ(HSW_PWR_WELL_DRIVER);
276 DRM_DEBUG_KMS("Requesting to disable the power well\n");
277 }
278 }
279}
280
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000281#define SKL_DISPLAY_POWERWELL_2_POWER_DOMAINS ( \
282 BIT(POWER_DOMAIN_TRANSCODER_A) | \
283 BIT(POWER_DOMAIN_PIPE_B) | \
284 BIT(POWER_DOMAIN_TRANSCODER_B) | \
285 BIT(POWER_DOMAIN_PIPE_C) | \
286 BIT(POWER_DOMAIN_TRANSCODER_C) | \
287 BIT(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
288 BIT(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
Patrik Jakobsson6331a702015-11-09 16:48:21 +0100289 BIT(POWER_DOMAIN_PORT_DDI_B_LANES) | \
290 BIT(POWER_DOMAIN_PORT_DDI_C_LANES) | \
291 BIT(POWER_DOMAIN_PORT_DDI_D_LANES) | \
292 BIT(POWER_DOMAIN_PORT_DDI_E_LANES) | \
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000293 BIT(POWER_DOMAIN_AUX_B) | \
294 BIT(POWER_DOMAIN_AUX_C) | \
295 BIT(POWER_DOMAIN_AUX_D) | \
296 BIT(POWER_DOMAIN_AUDIO) | \
297 BIT(POWER_DOMAIN_VGA) | \
298 BIT(POWER_DOMAIN_INIT))
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000299#define SKL_DISPLAY_DDI_A_E_POWER_DOMAINS ( \
Patrik Jakobsson6331a702015-11-09 16:48:21 +0100300 BIT(POWER_DOMAIN_PORT_DDI_A_LANES) | \
301 BIT(POWER_DOMAIN_PORT_DDI_E_LANES) | \
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000302 BIT(POWER_DOMAIN_INIT))
303#define SKL_DISPLAY_DDI_B_POWER_DOMAINS ( \
Patrik Jakobsson6331a702015-11-09 16:48:21 +0100304 BIT(POWER_DOMAIN_PORT_DDI_B_LANES) | \
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000305 BIT(POWER_DOMAIN_INIT))
306#define SKL_DISPLAY_DDI_C_POWER_DOMAINS ( \
Patrik Jakobsson6331a702015-11-09 16:48:21 +0100307 BIT(POWER_DOMAIN_PORT_DDI_C_LANES) | \
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000308 BIT(POWER_DOMAIN_INIT))
309#define SKL_DISPLAY_DDI_D_POWER_DOMAINS ( \
Patrik Jakobsson6331a702015-11-09 16:48:21 +0100310 BIT(POWER_DOMAIN_PORT_DDI_D_LANES) | \
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000311 BIT(POWER_DOMAIN_INIT))
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000312#define SKL_DISPLAY_ALWAYS_ON_POWER_DOMAINS ( \
Imre Deak4a76f292015-11-04 19:24:15 +0200313 (POWER_DOMAIN_MASK & ~( \
Ville Syrjäläedd993f2015-11-09 16:48:20 +0100314 SKL_DISPLAY_POWERWELL_2_POWER_DOMAINS)) | \
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000315 BIT(POWER_DOMAIN_INIT))
316
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +0530317#define BXT_DISPLAY_POWERWELL_2_POWER_DOMAINS ( \
318 BIT(POWER_DOMAIN_TRANSCODER_A) | \
319 BIT(POWER_DOMAIN_PIPE_B) | \
320 BIT(POWER_DOMAIN_TRANSCODER_B) | \
321 BIT(POWER_DOMAIN_PIPE_C) | \
322 BIT(POWER_DOMAIN_TRANSCODER_C) | \
323 BIT(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
324 BIT(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
Patrik Jakobsson6331a702015-11-09 16:48:21 +0100325 BIT(POWER_DOMAIN_PORT_DDI_B_LANES) | \
326 BIT(POWER_DOMAIN_PORT_DDI_C_LANES) | \
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +0530327 BIT(POWER_DOMAIN_AUX_B) | \
328 BIT(POWER_DOMAIN_AUX_C) | \
329 BIT(POWER_DOMAIN_AUDIO) | \
330 BIT(POWER_DOMAIN_VGA) | \
Ville Syrjäläf0ab43e2015-11-09 16:48:19 +0100331 BIT(POWER_DOMAIN_GMBUS) | \
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +0530332 BIT(POWER_DOMAIN_INIT))
333#define BXT_DISPLAY_POWERWELL_1_POWER_DOMAINS ( \
334 BXT_DISPLAY_POWERWELL_2_POWER_DOMAINS | \
335 BIT(POWER_DOMAIN_PIPE_A) | \
336 BIT(POWER_DOMAIN_TRANSCODER_EDP) | \
337 BIT(POWER_DOMAIN_PIPE_A_PANEL_FITTER) | \
Patrik Jakobsson6331a702015-11-09 16:48:21 +0100338 BIT(POWER_DOMAIN_PORT_DDI_A_LANES) | \
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +0530339 BIT(POWER_DOMAIN_AUX_A) | \
340 BIT(POWER_DOMAIN_PLLS) | \
341 BIT(POWER_DOMAIN_INIT))
342#define BXT_DISPLAY_ALWAYS_ON_POWER_DOMAINS ( \
343 (POWER_DOMAIN_MASK & ~(BXT_DISPLAY_POWERWELL_1_POWER_DOMAINS | \
344 BXT_DISPLAY_POWERWELL_2_POWER_DOMAINS)) | \
345 BIT(POWER_DOMAIN_INIT))
346
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530347static void assert_can_enable_dc9(struct drm_i915_private *dev_priv)
348{
349 struct drm_device *dev = dev_priv->dev;
350
351 WARN(!IS_BROXTON(dev), "Platform doesn't support DC9.\n");
352 WARN((I915_READ(DC_STATE_EN) & DC_STATE_EN_DC9),
353 "DC9 already programmed to be enabled.\n");
354 WARN(I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC5,
355 "DC5 still not disabled to enable DC9.\n");
356 WARN(I915_READ(HSW_PWR_WELL_DRIVER), "Power well on.\n");
357 WARN(intel_irqs_enabled(dev_priv), "Interrupts not disabled yet.\n");
358
359 /*
360 * TODO: check for the following to verify the conditions to enter DC9
361 * state are satisfied:
362 * 1] Check relevant display engine registers to verify if mode set
363 * disable sequence was followed.
364 * 2] Check if display uninitialize sequence is initialized.
365 */
366}
367
368static void assert_can_disable_dc9(struct drm_i915_private *dev_priv)
369{
370 WARN(intel_irqs_enabled(dev_priv), "Interrupts not disabled yet.\n");
371 WARN(!(I915_READ(DC_STATE_EN) & DC_STATE_EN_DC9),
372 "DC9 already programmed to be disabled.\n");
373 WARN(I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC5,
374 "DC5 still not disabled.\n");
375
376 /*
377 * TODO: check for the following to verify DC9 state was indeed
378 * entered before programming to disable it:
379 * 1] Check relevant display engine registers to verify if mode
380 * set disable sequence was followed.
381 * 2] Check if display uninitialize sequence is initialized.
382 */
383}
384
Patrik Jakobsson4deccbb2015-11-09 16:48:17 +0100385static void gen9_set_dc_state_debugmask_memory_up(
386 struct drm_i915_private *dev_priv)
387{
388 uint32_t val;
389
390 /* The below bit doesn't need to be cleared ever afterwards */
391 val = I915_READ(DC_STATE_DEBUG);
392 if (!(val & DC_STATE_DEBUG_MASK_MEMORY_UP)) {
393 val |= DC_STATE_DEBUG_MASK_MEMORY_UP;
394 I915_WRITE(DC_STATE_DEBUG, val);
395 POSTING_READ(DC_STATE_DEBUG);
396 }
397}
398
Imre Deak13ae3a02015-11-04 19:24:16 +0200399static void gen9_set_dc_state(struct drm_i915_private *dev_priv, uint32_t state)
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530400{
401 uint32_t val;
Imre Deak13ae3a02015-11-04 19:24:16 +0200402 uint32_t mask;
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530403
Imre Deak13ae3a02015-11-04 19:24:16 +0200404 mask = DC_STATE_EN_UPTO_DC5;
405 if (IS_BROXTON(dev_priv))
406 mask |= DC_STATE_EN_DC9;
407 else
408 mask |= DC_STATE_EN_UPTO_DC6;
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530409
Imre Deak13ae3a02015-11-04 19:24:16 +0200410 WARN_ON_ONCE(state & ~mask);
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530411
Patrik Jakobsson4deccbb2015-11-09 16:48:17 +0100412 if (state & DC_STATE_EN_UPTO_DC5_DC6_MASK)
413 gen9_set_dc_state_debugmask_memory_up(dev_priv);
414
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530415 val = I915_READ(DC_STATE_EN);
Imre Deak13ae3a02015-11-04 19:24:16 +0200416 DRM_DEBUG_KMS("Setting DC state from %02x to %02x\n",
417 val & mask, state);
418 val &= ~mask;
419 val |= state;
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530420 I915_WRITE(DC_STATE_EN, val);
421 POSTING_READ(DC_STATE_EN);
422}
423
Imre Deak13ae3a02015-11-04 19:24:16 +0200424void bxt_enable_dc9(struct drm_i915_private *dev_priv)
425{
426 assert_can_enable_dc9(dev_priv);
427
428 DRM_DEBUG_KMS("Enabling DC9\n");
429
430 gen9_set_dc_state(dev_priv, DC_STATE_EN_DC9);
431}
432
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530433void bxt_disable_dc9(struct drm_i915_private *dev_priv)
434{
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530435 assert_can_disable_dc9(dev_priv);
436
437 DRM_DEBUG_KMS("Disabling DC9\n");
438
Imre Deak13ae3a02015-11-04 19:24:16 +0200439 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530440}
441
Daniel Vetteraf5fead2015-10-28 23:58:57 +0200442static void assert_csr_loaded(struct drm_i915_private *dev_priv)
443{
444 WARN_ONCE(!I915_READ(CSR_PROGRAM(0)),
445 "CSR program storage start is NULL\n");
446 WARN_ONCE(!I915_READ(CSR_SSP_BASE), "CSR SSP Base Not fine\n");
447 WARN_ONCE(!I915_READ(CSR_HTP_SKL), "CSR HTP Not fine\n");
448}
449
Suketu Shah5aefb232015-04-16 14:22:10 +0530450static void assert_can_enable_dc5(struct drm_i915_private *dev_priv)
Suketu Shahdc174302015-04-17 19:46:16 +0530451{
A.Sunil Kamath6b457d32015-04-16 14:22:09 +0530452 struct drm_device *dev = dev_priv->dev;
Suketu Shah5aefb232015-04-16 14:22:10 +0530453 bool pg2_enabled = intel_display_power_well_is_enabled(dev_priv,
454 SKL_DISP_PW_2);
455
Jesse Barnes6ff8ab02015-09-10 08:20:28 -0700456 WARN_ONCE(!IS_SKYLAKE(dev), "Platform doesn't support DC5.\n");
457 WARN_ONCE(!HAS_RUNTIME_PM(dev), "Runtime PM not enabled.\n");
458 WARN_ONCE(pg2_enabled, "PG2 not disabled to enable DC5.\n");
Suketu Shah5aefb232015-04-16 14:22:10 +0530459
Jesse Barnes6ff8ab02015-09-10 08:20:28 -0700460 WARN_ONCE((I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC5),
461 "DC5 already programmed to be enabled.\n");
462 WARN_ONCE(dev_priv->pm.suspended,
463 "DC5 cannot be enabled, if platform is runtime-suspended.\n");
Suketu Shah5aefb232015-04-16 14:22:10 +0530464
465 assert_csr_loaded(dev_priv);
466}
467
468static void assert_can_disable_dc5(struct drm_i915_private *dev_priv)
469{
470 bool pg2_enabled = intel_display_power_well_is_enabled(dev_priv,
471 SKL_DISP_PW_2);
Suketu Shah93c7cb62015-04-16 14:22:13 +0530472 /*
473 * During initialization, the firmware may not be loaded yet.
474 * We still want to make sure that the DC enabling flag is cleared.
475 */
476 if (dev_priv->power_domains.initializing)
477 return;
Suketu Shah5aefb232015-04-16 14:22:10 +0530478
Jesse Barnes6ff8ab02015-09-10 08:20:28 -0700479 WARN_ONCE(!pg2_enabled, "PG2 not enabled to disable DC5.\n");
480 WARN_ONCE(dev_priv->pm.suspended,
Suketu Shah5aefb232015-04-16 14:22:10 +0530481 "Disabling of DC5 while platform is runtime-suspended should never happen.\n");
482}
483
484static void gen9_enable_dc5(struct drm_i915_private *dev_priv)
485{
Suketu Shah5aefb232015-04-16 14:22:10 +0530486 assert_can_enable_dc5(dev_priv);
A.Sunil Kamath6b457d32015-04-16 14:22:09 +0530487
488 DRM_DEBUG_KMS("Enabling DC5\n");
489
Imre Deak13ae3a02015-11-04 19:24:16 +0200490 gen9_set_dc_state(dev_priv, DC_STATE_EN_UPTO_DC5);
Suketu Shahdc174302015-04-17 19:46:16 +0530491}
492
493static void gen9_disable_dc5(struct drm_i915_private *dev_priv)
494{
Suketu Shah5aefb232015-04-16 14:22:10 +0530495 assert_can_disable_dc5(dev_priv);
A.Sunil Kamath6b457d32015-04-16 14:22:09 +0530496
497 DRM_DEBUG_KMS("Disabling DC5\n");
498
Imre Deak13ae3a02015-11-04 19:24:16 +0200499 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
Suketu Shahdc174302015-04-17 19:46:16 +0530500}
501
Suketu Shah93c7cb62015-04-16 14:22:13 +0530502static void assert_can_enable_dc6(struct drm_i915_private *dev_priv)
Suketu Shahf75a1982015-04-16 14:22:11 +0530503{
A.Sunil Kamath74b4f372015-04-16 14:22:12 +0530504 struct drm_device *dev = dev_priv->dev;
Suketu Shah93c7cb62015-04-16 14:22:13 +0530505
Jesse Barnes6ff8ab02015-09-10 08:20:28 -0700506 WARN_ONCE(!IS_SKYLAKE(dev), "Platform doesn't support DC6.\n");
507 WARN_ONCE(!HAS_RUNTIME_PM(dev), "Runtime PM not enabled.\n");
508 WARN_ONCE(I915_READ(UTIL_PIN_CTL) & UTIL_PIN_ENABLE,
509 "Backlight is not disabled.\n");
510 WARN_ONCE((I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC6),
511 "DC6 already programmed to be enabled.\n");
Suketu Shah93c7cb62015-04-16 14:22:13 +0530512
513 assert_csr_loaded(dev_priv);
514}
515
516static void assert_can_disable_dc6(struct drm_i915_private *dev_priv)
517{
518 /*
519 * During initialization, the firmware may not be loaded yet.
520 * We still want to make sure that the DC enabling flag is cleared.
521 */
522 if (dev_priv->power_domains.initializing)
523 return;
524
Jesse Barnes6ff8ab02015-09-10 08:20:28 -0700525 WARN_ONCE(!(I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC6),
526 "DC6 already programmed to be disabled.\n");
Suketu Shah93c7cb62015-04-16 14:22:13 +0530527}
528
Animesh Manna0a9d2be2015-09-29 11:01:59 +0530529void skl_enable_dc6(struct drm_i915_private *dev_priv)
Suketu Shah93c7cb62015-04-16 14:22:13 +0530530{
Suketu Shah93c7cb62015-04-16 14:22:13 +0530531 assert_can_enable_dc6(dev_priv);
A.Sunil Kamath74b4f372015-04-16 14:22:12 +0530532
533 DRM_DEBUG_KMS("Enabling DC6\n");
534
Imre Deak13ae3a02015-11-04 19:24:16 +0200535 gen9_set_dc_state(dev_priv, DC_STATE_EN_UPTO_DC6);
536
Suketu Shahf75a1982015-04-16 14:22:11 +0530537}
538
Animesh Manna0a9d2be2015-09-29 11:01:59 +0530539void skl_disable_dc6(struct drm_i915_private *dev_priv)
Suketu Shahf75a1982015-04-16 14:22:11 +0530540{
Suketu Shah93c7cb62015-04-16 14:22:13 +0530541 assert_can_disable_dc6(dev_priv);
A.Sunil Kamath74b4f372015-04-16 14:22:12 +0530542
543 DRM_DEBUG_KMS("Disabling DC6\n");
544
Imre Deak13ae3a02015-11-04 19:24:16 +0200545 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
Suketu Shahf75a1982015-04-16 14:22:11 +0530546}
547
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000548static void skl_set_power_well(struct drm_i915_private *dev_priv,
549 struct i915_power_well *power_well, bool enable)
550{
Suketu Shahdc174302015-04-17 19:46:16 +0530551 struct drm_device *dev = dev_priv->dev;
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000552 uint32_t tmp, fuse_status;
553 uint32_t req_mask, state_mask;
Damien Lespiau2a518352015-03-06 18:50:49 +0000554 bool is_enabled, enable_requested, check_fuse_status = false;
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000555
556 tmp = I915_READ(HSW_PWR_WELL_DRIVER);
557 fuse_status = I915_READ(SKL_FUSE_STATUS);
558
559 switch (power_well->data) {
560 case SKL_DISP_PW_1:
561 if (wait_for((I915_READ(SKL_FUSE_STATUS) &
562 SKL_FUSE_PG0_DIST_STATUS), 1)) {
563 DRM_ERROR("PG0 not enabled\n");
564 return;
565 }
566 break;
567 case SKL_DISP_PW_2:
568 if (!(fuse_status & SKL_FUSE_PG1_DIST_STATUS)) {
569 DRM_ERROR("PG1 in disabled state\n");
570 return;
571 }
572 break;
573 case SKL_DISP_PW_DDI_A_E:
574 case SKL_DISP_PW_DDI_B:
575 case SKL_DISP_PW_DDI_C:
576 case SKL_DISP_PW_DDI_D:
577 case SKL_DISP_PW_MISC_IO:
578 break;
579 default:
580 WARN(1, "Unknown power well %lu\n", power_well->data);
581 return;
582 }
583
584 req_mask = SKL_POWER_WELL_REQ(power_well->data);
Damien Lespiau2a518352015-03-06 18:50:49 +0000585 enable_requested = tmp & req_mask;
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000586 state_mask = SKL_POWER_WELL_STATE(power_well->data);
Damien Lespiau2a518352015-03-06 18:50:49 +0000587 is_enabled = tmp & state_mask;
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000588
589 if (enable) {
Damien Lespiau2a518352015-03-06 18:50:49 +0000590 if (!enable_requested) {
Suketu Shahdc174302015-04-17 19:46:16 +0530591 WARN((tmp & state_mask) &&
592 !I915_READ(HSW_PWR_WELL_BIOS),
593 "Invalid for power well status to be enabled, unless done by the BIOS, \
594 when request is to disable!\n");
Animesh Manna0a9d2be2015-09-29 11:01:59 +0530595 if (power_well->data == SKL_DISP_PW_2) {
596 if (GEN9_ENABLE_DC5(dev))
597 gen9_disable_dc5(dev_priv);
Suketu Shahf75a1982015-04-16 14:22:11 +0530598 if (SKL_ENABLE_DC6(dev)) {
Suketu Shahf75a1982015-04-16 14:22:11 +0530599 /*
600 * DDI buffer programming unnecessary during driver-load/resume
601 * as it's already done during modeset initialization then.
602 * It's also invalid here as encoder list is still uninitialized.
603 */
604 if (!dev_priv->power_domains.initializing)
605 intel_prepare_ddi(dev);
Suketu Shahf75a1982015-04-16 14:22:11 +0530606 }
607 }
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000608 I915_WRITE(HSW_PWR_WELL_DRIVER, tmp | req_mask);
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000609 }
610
Damien Lespiau2a518352015-03-06 18:50:49 +0000611 if (!is_enabled) {
Damien Lespiau510e6fd2015-03-06 18:50:50 +0000612 DRM_DEBUG_KMS("Enabling %s\n", power_well->name);
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000613 if (wait_for((I915_READ(HSW_PWR_WELL_DRIVER) &
614 state_mask), 1))
615 DRM_ERROR("%s enable timeout\n",
616 power_well->name);
617 check_fuse_status = true;
618 }
619 } else {
Damien Lespiau2a518352015-03-06 18:50:49 +0000620 if (enable_requested) {
Imre Deak4a76f292015-11-04 19:24:15 +0200621 I915_WRITE(HSW_PWR_WELL_DRIVER, tmp & ~req_mask);
622 POSTING_READ(HSW_PWR_WELL_DRIVER);
623 DRM_DEBUG_KMS("Disabling %s\n", power_well->name);
Suketu Shahdc174302015-04-17 19:46:16 +0530624
Animesh Manna0a9d2be2015-09-29 11:01:59 +0530625 if (GEN9_ENABLE_DC5(dev) &&
Daniel Vetter414b7992015-11-12 17:10:37 +0200626 power_well->data == SKL_DISP_PW_2)
Animesh Manna0a9d2be2015-09-29 11:01:59 +0530627 gen9_enable_dc5(dev_priv);
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000628 }
629 }
630
631 if (check_fuse_status) {
632 if (power_well->data == SKL_DISP_PW_1) {
633 if (wait_for((I915_READ(SKL_FUSE_STATUS) &
634 SKL_FUSE_PG1_DIST_STATUS), 1))
635 DRM_ERROR("PG1 distributing status timeout\n");
636 } else if (power_well->data == SKL_DISP_PW_2) {
637 if (wait_for((I915_READ(SKL_FUSE_STATUS) &
638 SKL_FUSE_PG2_DIST_STATUS), 1))
639 DRM_ERROR("PG2 distributing status timeout\n");
640 }
641 }
Damien Lespiaud14c0342015-03-06 18:50:51 +0000642
643 if (enable && !is_enabled)
644 skl_power_well_post_enable(dev_priv, power_well);
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000645}
646
Daniel Vetter9c065a72014-09-30 10:56:38 +0200647static void hsw_power_well_sync_hw(struct drm_i915_private *dev_priv,
648 struct i915_power_well *power_well)
649{
650 hsw_set_power_well(dev_priv, power_well, power_well->count > 0);
651
652 /*
653 * We're taking over the BIOS, so clear any requests made by it since
654 * the driver is in charge now.
655 */
656 if (I915_READ(HSW_PWR_WELL_BIOS) & HSW_PWR_WELL_ENABLE_REQUEST)
657 I915_WRITE(HSW_PWR_WELL_BIOS, 0);
658}
659
660static void hsw_power_well_enable(struct drm_i915_private *dev_priv,
661 struct i915_power_well *power_well)
662{
663 hsw_set_power_well(dev_priv, power_well, true);
664}
665
666static void hsw_power_well_disable(struct drm_i915_private *dev_priv,
667 struct i915_power_well *power_well)
668{
669 hsw_set_power_well(dev_priv, power_well, false);
670}
671
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000672static bool skl_power_well_enabled(struct drm_i915_private *dev_priv,
673 struct i915_power_well *power_well)
674{
675 uint32_t mask = SKL_POWER_WELL_REQ(power_well->data) |
676 SKL_POWER_WELL_STATE(power_well->data);
677
678 return (I915_READ(HSW_PWR_WELL_DRIVER) & mask) == mask;
679}
680
681static void skl_power_well_sync_hw(struct drm_i915_private *dev_priv,
682 struct i915_power_well *power_well)
683{
684 skl_set_power_well(dev_priv, power_well, power_well->count > 0);
685
686 /* Clear any request made by BIOS as driver is taking over */
687 I915_WRITE(HSW_PWR_WELL_BIOS, 0);
688}
689
690static void skl_power_well_enable(struct drm_i915_private *dev_priv,
691 struct i915_power_well *power_well)
692{
693 skl_set_power_well(dev_priv, power_well, true);
694}
695
696static void skl_power_well_disable(struct drm_i915_private *dev_priv,
697 struct i915_power_well *power_well)
698{
699 skl_set_power_well(dev_priv, power_well, false);
700}
701
Daniel Vetter9c065a72014-09-30 10:56:38 +0200702static void i9xx_always_on_power_well_noop(struct drm_i915_private *dev_priv,
703 struct i915_power_well *power_well)
704{
705}
706
707static bool i9xx_always_on_power_well_enabled(struct drm_i915_private *dev_priv,
708 struct i915_power_well *power_well)
709{
710 return true;
711}
712
713static void vlv_set_power_well(struct drm_i915_private *dev_priv,
714 struct i915_power_well *power_well, bool enable)
715{
716 enum punit_power_well power_well_id = power_well->data;
717 u32 mask;
718 u32 state;
719 u32 ctrl;
720
721 mask = PUNIT_PWRGT_MASK(power_well_id);
722 state = enable ? PUNIT_PWRGT_PWR_ON(power_well_id) :
723 PUNIT_PWRGT_PWR_GATE(power_well_id);
724
725 mutex_lock(&dev_priv->rps.hw_lock);
726
727#define COND \
728 ((vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_STATUS) & mask) == state)
729
730 if (COND)
731 goto out;
732
733 ctrl = vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_CTRL);
734 ctrl &= ~mask;
735 ctrl |= state;
736 vlv_punit_write(dev_priv, PUNIT_REG_PWRGT_CTRL, ctrl);
737
738 if (wait_for(COND, 100))
Masanari Iida7e35ab82015-05-10 01:00:23 +0900739 DRM_ERROR("timeout setting power well state %08x (%08x)\n",
Daniel Vetter9c065a72014-09-30 10:56:38 +0200740 state,
741 vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_CTRL));
742
743#undef COND
744
745out:
746 mutex_unlock(&dev_priv->rps.hw_lock);
747}
748
749static void vlv_power_well_sync_hw(struct drm_i915_private *dev_priv,
750 struct i915_power_well *power_well)
751{
752 vlv_set_power_well(dev_priv, power_well, power_well->count > 0);
753}
754
755static void vlv_power_well_enable(struct drm_i915_private *dev_priv,
756 struct i915_power_well *power_well)
757{
758 vlv_set_power_well(dev_priv, power_well, true);
759}
760
761static void vlv_power_well_disable(struct drm_i915_private *dev_priv,
762 struct i915_power_well *power_well)
763{
764 vlv_set_power_well(dev_priv, power_well, false);
765}
766
767static bool vlv_power_well_enabled(struct drm_i915_private *dev_priv,
768 struct i915_power_well *power_well)
769{
770 int power_well_id = power_well->data;
771 bool enabled = false;
772 u32 mask;
773 u32 state;
774 u32 ctrl;
775
776 mask = PUNIT_PWRGT_MASK(power_well_id);
777 ctrl = PUNIT_PWRGT_PWR_ON(power_well_id);
778
779 mutex_lock(&dev_priv->rps.hw_lock);
780
781 state = vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_STATUS) & mask;
782 /*
783 * We only ever set the power-on and power-gate states, anything
784 * else is unexpected.
785 */
786 WARN_ON(state != PUNIT_PWRGT_PWR_ON(power_well_id) &&
787 state != PUNIT_PWRGT_PWR_GATE(power_well_id));
788 if (state == ctrl)
789 enabled = true;
790
791 /*
792 * A transient state at this point would mean some unexpected party
793 * is poking at the power controls too.
794 */
795 ctrl = vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_CTRL) & mask;
796 WARN_ON(ctrl != state);
797
798 mutex_unlock(&dev_priv->rps.hw_lock);
799
800 return enabled;
801}
802
Ville Syrjälä2be7d542015-06-29 15:25:51 +0300803static void vlv_display_power_well_init(struct drm_i915_private *dev_priv)
Daniel Vetter9c065a72014-09-30 10:56:38 +0200804{
Ville Syrjälä5a8fbb72015-06-29 15:25:53 +0300805 enum pipe pipe;
806
807 /*
808 * Enable the CRI clock source so we can get at the
809 * display and the reference clock for VGA
810 * hotplug / manual detection. Supposedly DSI also
811 * needs the ref clock up and running.
812 *
813 * CHV DPLL B/C have some issues if VGA mode is enabled.
814 */
815 for_each_pipe(dev_priv->dev, pipe) {
816 u32 val = I915_READ(DPLL(pipe));
817
818 val |= DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
819 if (pipe != PIPE_A)
820 val |= DPLL_INTEGRATED_CRI_CLK_VLV;
821
822 I915_WRITE(DPLL(pipe), val);
823 }
Daniel Vetter9c065a72014-09-30 10:56:38 +0200824
825 spin_lock_irq(&dev_priv->irq_lock);
826 valleyview_enable_display_irqs(dev_priv);
827 spin_unlock_irq(&dev_priv->irq_lock);
828
829 /*
830 * During driver initialization/resume we can avoid restoring the
831 * part of the HW/SW state that will be inited anyway explicitly.
832 */
833 if (dev_priv->power_domains.initializing)
834 return;
835
Daniel Vetterb9632912014-09-30 10:56:44 +0200836 intel_hpd_init(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200837
838 i915_redisable_vga_power_on(dev_priv->dev);
839}
840
Ville Syrjälä2be7d542015-06-29 15:25:51 +0300841static void vlv_display_power_well_deinit(struct drm_i915_private *dev_priv)
842{
843 spin_lock_irq(&dev_priv->irq_lock);
844 valleyview_disable_display_irqs(dev_priv);
845 spin_unlock_irq(&dev_priv->irq_lock);
846
847 vlv_power_sequencer_reset(dev_priv);
848}
849
850static void vlv_display_power_well_enable(struct drm_i915_private *dev_priv,
851 struct i915_power_well *power_well)
852{
853 WARN_ON_ONCE(power_well->data != PUNIT_POWER_WELL_DISP2D);
854
855 vlv_set_power_well(dev_priv, power_well, true);
856
857 vlv_display_power_well_init(dev_priv);
858}
859
Daniel Vetter9c065a72014-09-30 10:56:38 +0200860static void vlv_display_power_well_disable(struct drm_i915_private *dev_priv,
861 struct i915_power_well *power_well)
862{
863 WARN_ON_ONCE(power_well->data != PUNIT_POWER_WELL_DISP2D);
864
Ville Syrjälä2be7d542015-06-29 15:25:51 +0300865 vlv_display_power_well_deinit(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200866
867 vlv_set_power_well(dev_priv, power_well, false);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200868}
869
870static void vlv_dpio_cmn_power_well_enable(struct drm_i915_private *dev_priv,
871 struct i915_power_well *power_well)
872{
873 WARN_ON_ONCE(power_well->data != PUNIT_POWER_WELL_DPIO_CMN_BC);
874
Ville Syrjälä5a8fbb72015-06-29 15:25:53 +0300875 /* since ref/cri clock was enabled */
Daniel Vetter9c065a72014-09-30 10:56:38 +0200876 udelay(1); /* >10ns for cmnreset, >0ns for sidereset */
877
878 vlv_set_power_well(dev_priv, power_well, true);
879
880 /*
881 * From VLV2A0_DP_eDP_DPIO_driver_vbios_notes_10.docx -
882 * 6. De-assert cmn_reset/side_reset. Same as VLV X0.
883 * a. GUnit 0x2110 bit[0] set to 1 (def 0)
884 * b. The other bits such as sfr settings / modesel may all
885 * be set to 0.
886 *
887 * This should only be done on init and resume from S3 with
888 * both PLLs disabled, or we risk losing DPIO and PLL
889 * synchronization.
890 */
891 I915_WRITE(DPIO_CTL, I915_READ(DPIO_CTL) | DPIO_CMNRST);
892}
893
894static void vlv_dpio_cmn_power_well_disable(struct drm_i915_private *dev_priv,
895 struct i915_power_well *power_well)
896{
897 enum pipe pipe;
898
899 WARN_ON_ONCE(power_well->data != PUNIT_POWER_WELL_DPIO_CMN_BC);
900
901 for_each_pipe(dev_priv, pipe)
902 assert_pll_disabled(dev_priv, pipe);
903
904 /* Assert common reset */
905 I915_WRITE(DPIO_CTL, I915_READ(DPIO_CTL) & ~DPIO_CMNRST);
906
907 vlv_set_power_well(dev_priv, power_well, false);
908}
909
Ville Syrjälä30142272015-07-08 23:46:01 +0300910#define POWER_DOMAIN_MASK (BIT(POWER_DOMAIN_NUM) - 1)
911
912static struct i915_power_well *lookup_power_well(struct drm_i915_private *dev_priv,
913 int power_well_id)
914{
915 struct i915_power_domains *power_domains = &dev_priv->power_domains;
Ville Syrjälä30142272015-07-08 23:46:01 +0300916 int i;
917
Imre Deakfc17f222015-11-04 19:24:11 +0200918 for (i = 0; i < power_domains->power_well_count; i++) {
919 struct i915_power_well *power_well;
920
921 power_well = &power_domains->power_wells[i];
Ville Syrjälä30142272015-07-08 23:46:01 +0300922 if (power_well->data == power_well_id)
923 return power_well;
924 }
925
926 return NULL;
927}
928
929#define BITS_SET(val, bits) (((val) & (bits)) == (bits))
930
931static void assert_chv_phy_status(struct drm_i915_private *dev_priv)
932{
933 struct i915_power_well *cmn_bc =
934 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_BC);
935 struct i915_power_well *cmn_d =
936 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_D);
937 u32 phy_control = dev_priv->chv_phy_control;
938 u32 phy_status = 0;
Ville Syrjälä3be60de2015-09-08 18:05:45 +0300939 u32 phy_status_mask = 0xffffffff;
Ville Syrjälä30142272015-07-08 23:46:01 +0300940 u32 tmp;
941
Ville Syrjälä3be60de2015-09-08 18:05:45 +0300942 /*
943 * The BIOS can leave the PHY is some weird state
944 * where it doesn't fully power down some parts.
945 * Disable the asserts until the PHY has been fully
946 * reset (ie. the power well has been disabled at
947 * least once).
948 */
949 if (!dev_priv->chv_phy_assert[DPIO_PHY0])
950 phy_status_mask &= ~(PHY_STATUS_CMN_LDO(DPIO_PHY0, DPIO_CH0) |
951 PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH0, 0) |
952 PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH0, 1) |
953 PHY_STATUS_CMN_LDO(DPIO_PHY0, DPIO_CH1) |
954 PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH1, 0) |
955 PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH1, 1));
956
957 if (!dev_priv->chv_phy_assert[DPIO_PHY1])
958 phy_status_mask &= ~(PHY_STATUS_CMN_LDO(DPIO_PHY1, DPIO_CH0) |
959 PHY_STATUS_SPLINE_LDO(DPIO_PHY1, DPIO_CH0, 0) |
960 PHY_STATUS_SPLINE_LDO(DPIO_PHY1, DPIO_CH0, 1));
961
Ville Syrjälä30142272015-07-08 23:46:01 +0300962 if (cmn_bc->ops->is_enabled(dev_priv, cmn_bc)) {
963 phy_status |= PHY_POWERGOOD(DPIO_PHY0);
964
965 /* this assumes override is only used to enable lanes */
966 if ((phy_control & PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY0, DPIO_CH0)) == 0)
967 phy_control |= PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH0);
968
969 if ((phy_control & PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY0, DPIO_CH1)) == 0)
970 phy_control |= PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH1);
971
972 /* CL1 is on whenever anything is on in either channel */
973 if (BITS_SET(phy_control,
974 PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH0) |
975 PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH1)))
976 phy_status |= PHY_STATUS_CMN_LDO(DPIO_PHY0, DPIO_CH0);
977
978 /*
979 * The DPLLB check accounts for the pipe B + port A usage
980 * with CL2 powered up but all the lanes in the second channel
981 * powered down.
982 */
983 if (BITS_SET(phy_control,
984 PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH1)) &&
985 (I915_READ(DPLL(PIPE_B)) & DPLL_VCO_ENABLE) == 0)
986 phy_status |= PHY_STATUS_CMN_LDO(DPIO_PHY0, DPIO_CH1);
987
988 if (BITS_SET(phy_control,
989 PHY_CH_POWER_DOWN_OVRD(0x3, DPIO_PHY0, DPIO_CH0)))
990 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH0, 0);
991 if (BITS_SET(phy_control,
992 PHY_CH_POWER_DOWN_OVRD(0xc, DPIO_PHY0, DPIO_CH0)))
993 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH0, 1);
994
995 if (BITS_SET(phy_control,
996 PHY_CH_POWER_DOWN_OVRD(0x3, DPIO_PHY0, DPIO_CH1)))
997 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH1, 0);
998 if (BITS_SET(phy_control,
999 PHY_CH_POWER_DOWN_OVRD(0xc, DPIO_PHY0, DPIO_CH1)))
1000 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH1, 1);
1001 }
1002
1003 if (cmn_d->ops->is_enabled(dev_priv, cmn_d)) {
1004 phy_status |= PHY_POWERGOOD(DPIO_PHY1);
1005
1006 /* this assumes override is only used to enable lanes */
1007 if ((phy_control & PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY1, DPIO_CH0)) == 0)
1008 phy_control |= PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY1, DPIO_CH0);
1009
1010 if (BITS_SET(phy_control,
1011 PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY1, DPIO_CH0)))
1012 phy_status |= PHY_STATUS_CMN_LDO(DPIO_PHY1, DPIO_CH0);
1013
1014 if (BITS_SET(phy_control,
1015 PHY_CH_POWER_DOWN_OVRD(0x3, DPIO_PHY1, DPIO_CH0)))
1016 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY1, DPIO_CH0, 0);
1017 if (BITS_SET(phy_control,
1018 PHY_CH_POWER_DOWN_OVRD(0xc, DPIO_PHY1, DPIO_CH0)))
1019 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY1, DPIO_CH0, 1);
1020 }
1021
Ville Syrjälä3be60de2015-09-08 18:05:45 +03001022 phy_status &= phy_status_mask;
1023
Ville Syrjälä30142272015-07-08 23:46:01 +03001024 /*
1025 * The PHY may be busy with some initial calibration and whatnot,
1026 * so the power state can take a while to actually change.
1027 */
Ville Syrjälä3be60de2015-09-08 18:05:45 +03001028 if (wait_for((tmp = I915_READ(DISPLAY_PHY_STATUS) & phy_status_mask) == phy_status, 10))
Ville Syrjälä30142272015-07-08 23:46:01 +03001029 WARN(phy_status != tmp,
1030 "Unexpected PHY_STATUS 0x%08x, expected 0x%08x (PHY_CONTROL=0x%08x)\n",
1031 tmp, phy_status, dev_priv->chv_phy_control);
1032}
1033
1034#undef BITS_SET
1035
Daniel Vetter9c065a72014-09-30 10:56:38 +02001036static void chv_dpio_cmn_power_well_enable(struct drm_i915_private *dev_priv,
1037 struct i915_power_well *power_well)
1038{
1039 enum dpio_phy phy;
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001040 enum pipe pipe;
1041 uint32_t tmp;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001042
1043 WARN_ON_ONCE(power_well->data != PUNIT_POWER_WELL_DPIO_CMN_BC &&
1044 power_well->data != PUNIT_POWER_WELL_DPIO_CMN_D);
1045
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001046 if (power_well->data == PUNIT_POWER_WELL_DPIO_CMN_BC) {
1047 pipe = PIPE_A;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001048 phy = DPIO_PHY0;
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001049 } else {
1050 pipe = PIPE_C;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001051 phy = DPIO_PHY1;
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001052 }
Ville Syrjälä5a8fbb72015-06-29 15:25:53 +03001053
1054 /* since ref/cri clock was enabled */
Daniel Vetter9c065a72014-09-30 10:56:38 +02001055 udelay(1); /* >10ns for cmnreset, >0ns for sidereset */
1056 vlv_set_power_well(dev_priv, power_well, true);
1057
1058 /* Poll for phypwrgood signal */
1059 if (wait_for(I915_READ(DISPLAY_PHY_STATUS) & PHY_POWERGOOD(phy), 1))
1060 DRM_ERROR("Display PHY %d is not power up\n", phy);
1061
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001062 mutex_lock(&dev_priv->sb_lock);
1063
1064 /* Enable dynamic power down */
1065 tmp = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW28);
Ville Syrjäläee279212015-07-08 23:45:57 +03001066 tmp |= DPIO_DYNPWRDOWNEN_CH0 | DPIO_CL1POWERDOWNEN |
1067 DPIO_SUS_CLK_CONFIG_GATE_CLKREQ;
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001068 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW28, tmp);
1069
1070 if (power_well->data == PUNIT_POWER_WELL_DPIO_CMN_BC) {
1071 tmp = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW6_CH1);
1072 tmp |= DPIO_DYNPWRDOWNEN_CH1;
1073 vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW6_CH1, tmp);
Ville Syrjälä3e288782015-07-08 23:45:58 +03001074 } else {
1075 /*
1076 * Force the non-existing CL2 off. BXT does this
1077 * too, so maybe it saves some power even though
1078 * CL2 doesn't exist?
1079 */
1080 tmp = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW30);
1081 tmp |= DPIO_CL2_LDOFUSE_PWRENB;
1082 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW30, tmp);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001083 }
1084
1085 mutex_unlock(&dev_priv->sb_lock);
1086
Ville Syrjälä70722462015-04-10 18:21:28 +03001087 dev_priv->chv_phy_control |= PHY_COM_LANE_RESET_DEASSERT(phy);
1088 I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001089
1090 DRM_DEBUG_KMS("Enabled DPIO PHY%d (PHY_CONTROL=0x%08x)\n",
1091 phy, dev_priv->chv_phy_control);
Ville Syrjälä30142272015-07-08 23:46:01 +03001092
1093 assert_chv_phy_status(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001094}
1095
1096static void chv_dpio_cmn_power_well_disable(struct drm_i915_private *dev_priv,
1097 struct i915_power_well *power_well)
1098{
1099 enum dpio_phy phy;
1100
1101 WARN_ON_ONCE(power_well->data != PUNIT_POWER_WELL_DPIO_CMN_BC &&
1102 power_well->data != PUNIT_POWER_WELL_DPIO_CMN_D);
1103
1104 if (power_well->data == PUNIT_POWER_WELL_DPIO_CMN_BC) {
1105 phy = DPIO_PHY0;
1106 assert_pll_disabled(dev_priv, PIPE_A);
1107 assert_pll_disabled(dev_priv, PIPE_B);
1108 } else {
1109 phy = DPIO_PHY1;
1110 assert_pll_disabled(dev_priv, PIPE_C);
1111 }
1112
Ville Syrjälä70722462015-04-10 18:21:28 +03001113 dev_priv->chv_phy_control &= ~PHY_COM_LANE_RESET_DEASSERT(phy);
1114 I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001115
1116 vlv_set_power_well(dev_priv, power_well, false);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001117
1118 DRM_DEBUG_KMS("Disabled DPIO PHY%d (PHY_CONTROL=0x%08x)\n",
1119 phy, dev_priv->chv_phy_control);
Ville Syrjälä30142272015-07-08 23:46:01 +03001120
Ville Syrjälä3be60de2015-09-08 18:05:45 +03001121 /* PHY is fully reset now, so we can enable the PHY state asserts */
1122 dev_priv->chv_phy_assert[phy] = true;
1123
Ville Syrjälä30142272015-07-08 23:46:01 +03001124 assert_chv_phy_status(dev_priv);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001125}
1126
Ville Syrjälä6669e392015-07-08 23:46:00 +03001127static void assert_chv_phy_powergate(struct drm_i915_private *dev_priv, enum dpio_phy phy,
1128 enum dpio_channel ch, bool override, unsigned int mask)
1129{
1130 enum pipe pipe = phy == DPIO_PHY0 ? PIPE_A : PIPE_C;
1131 u32 reg, val, expected, actual;
1132
Ville Syrjälä3be60de2015-09-08 18:05:45 +03001133 /*
1134 * The BIOS can leave the PHY is some weird state
1135 * where it doesn't fully power down some parts.
1136 * Disable the asserts until the PHY has been fully
1137 * reset (ie. the power well has been disabled at
1138 * least once).
1139 */
1140 if (!dev_priv->chv_phy_assert[phy])
1141 return;
1142
Ville Syrjälä6669e392015-07-08 23:46:00 +03001143 if (ch == DPIO_CH0)
1144 reg = _CHV_CMN_DW0_CH0;
1145 else
1146 reg = _CHV_CMN_DW6_CH1;
1147
1148 mutex_lock(&dev_priv->sb_lock);
1149 val = vlv_dpio_read(dev_priv, pipe, reg);
1150 mutex_unlock(&dev_priv->sb_lock);
1151
1152 /*
1153 * This assumes !override is only used when the port is disabled.
1154 * All lanes should power down even without the override when
1155 * the port is disabled.
1156 */
1157 if (!override || mask == 0xf) {
1158 expected = DPIO_ALLDL_POWERDOWN | DPIO_ANYDL_POWERDOWN;
1159 /*
1160 * If CH1 common lane is not active anymore
1161 * (eg. for pipe B DPLL) the entire channel will
1162 * shut down, which causes the common lane registers
1163 * to read as 0. That means we can't actually check
1164 * the lane power down status bits, but as the entire
1165 * register reads as 0 it's a good indication that the
1166 * channel is indeed entirely powered down.
1167 */
1168 if (ch == DPIO_CH1 && val == 0)
1169 expected = 0;
1170 } else if (mask != 0x0) {
1171 expected = DPIO_ANYDL_POWERDOWN;
1172 } else {
1173 expected = 0;
1174 }
1175
1176 if (ch == DPIO_CH0)
1177 actual = val >> DPIO_ANYDL_POWERDOWN_SHIFT_CH0;
1178 else
1179 actual = val >> DPIO_ANYDL_POWERDOWN_SHIFT_CH1;
1180 actual &= DPIO_ALLDL_POWERDOWN | DPIO_ANYDL_POWERDOWN;
1181
1182 WARN(actual != expected,
1183 "Unexpected DPIO lane power down: all %d, any %d. Expected: all %d, any %d. (0x%x = 0x%08x)\n",
1184 !!(actual & DPIO_ALLDL_POWERDOWN), !!(actual & DPIO_ANYDL_POWERDOWN),
1185 !!(expected & DPIO_ALLDL_POWERDOWN), !!(expected & DPIO_ANYDL_POWERDOWN),
1186 reg, val);
1187}
1188
Ville Syrjäläb0b33842015-07-08 23:45:55 +03001189bool chv_phy_powergate_ch(struct drm_i915_private *dev_priv, enum dpio_phy phy,
1190 enum dpio_channel ch, bool override)
1191{
1192 struct i915_power_domains *power_domains = &dev_priv->power_domains;
1193 bool was_override;
1194
1195 mutex_lock(&power_domains->lock);
1196
1197 was_override = dev_priv->chv_phy_control & PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
1198
1199 if (override == was_override)
1200 goto out;
1201
1202 if (override)
1203 dev_priv->chv_phy_control |= PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
1204 else
1205 dev_priv->chv_phy_control &= ~PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
1206
1207 I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
1208
1209 DRM_DEBUG_KMS("Power gating DPIO PHY%d CH%d (DPIO_PHY_CONTROL=0x%08x)\n",
1210 phy, ch, dev_priv->chv_phy_control);
1211
Ville Syrjälä30142272015-07-08 23:46:01 +03001212 assert_chv_phy_status(dev_priv);
1213
Ville Syrjäläb0b33842015-07-08 23:45:55 +03001214out:
1215 mutex_unlock(&power_domains->lock);
1216
1217 return was_override;
1218}
1219
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001220void chv_phy_powergate_lanes(struct intel_encoder *encoder,
1221 bool override, unsigned int mask)
1222{
1223 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
1224 struct i915_power_domains *power_domains = &dev_priv->power_domains;
1225 enum dpio_phy phy = vlv_dport_to_phy(enc_to_dig_port(&encoder->base));
1226 enum dpio_channel ch = vlv_dport_to_channel(enc_to_dig_port(&encoder->base));
1227
1228 mutex_lock(&power_domains->lock);
1229
1230 dev_priv->chv_phy_control &= ~PHY_CH_POWER_DOWN_OVRD(0xf, phy, ch);
1231 dev_priv->chv_phy_control |= PHY_CH_POWER_DOWN_OVRD(mask, phy, ch);
1232
1233 if (override)
1234 dev_priv->chv_phy_control |= PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
1235 else
1236 dev_priv->chv_phy_control &= ~PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
1237
1238 I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
1239
1240 DRM_DEBUG_KMS("Power gating DPIO PHY%d CH%d lanes 0x%x (PHY_CONTROL=0x%08x)\n",
1241 phy, ch, mask, dev_priv->chv_phy_control);
1242
Ville Syrjälä30142272015-07-08 23:46:01 +03001243 assert_chv_phy_status(dev_priv);
1244
Ville Syrjälä6669e392015-07-08 23:46:00 +03001245 assert_chv_phy_powergate(dev_priv, phy, ch, override, mask);
1246
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001247 mutex_unlock(&power_domains->lock);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001248}
1249
1250static bool chv_pipe_power_well_enabled(struct drm_i915_private *dev_priv,
1251 struct i915_power_well *power_well)
1252{
1253 enum pipe pipe = power_well->data;
1254 bool enabled;
1255 u32 state, ctrl;
1256
1257 mutex_lock(&dev_priv->rps.hw_lock);
1258
1259 state = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & DP_SSS_MASK(pipe);
1260 /*
1261 * We only ever set the power-on and power-gate states, anything
1262 * else is unexpected.
1263 */
1264 WARN_ON(state != DP_SSS_PWR_ON(pipe) && state != DP_SSS_PWR_GATE(pipe));
1265 enabled = state == DP_SSS_PWR_ON(pipe);
1266
1267 /*
1268 * A transient state at this point would mean some unexpected party
1269 * is poking at the power controls too.
1270 */
1271 ctrl = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & DP_SSC_MASK(pipe);
1272 WARN_ON(ctrl << 16 != state);
1273
1274 mutex_unlock(&dev_priv->rps.hw_lock);
1275
1276 return enabled;
1277}
1278
1279static void chv_set_pipe_power_well(struct drm_i915_private *dev_priv,
1280 struct i915_power_well *power_well,
1281 bool enable)
1282{
1283 enum pipe pipe = power_well->data;
1284 u32 state;
1285 u32 ctrl;
1286
1287 state = enable ? DP_SSS_PWR_ON(pipe) : DP_SSS_PWR_GATE(pipe);
1288
1289 mutex_lock(&dev_priv->rps.hw_lock);
1290
1291#define COND \
1292 ((vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & DP_SSS_MASK(pipe)) == state)
1293
1294 if (COND)
1295 goto out;
1296
1297 ctrl = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ);
1298 ctrl &= ~DP_SSC_MASK(pipe);
1299 ctrl |= enable ? DP_SSC_PWR_ON(pipe) : DP_SSC_PWR_GATE(pipe);
1300 vlv_punit_write(dev_priv, PUNIT_REG_DSPFREQ, ctrl);
1301
1302 if (wait_for(COND, 100))
Masanari Iida7e35ab82015-05-10 01:00:23 +09001303 DRM_ERROR("timeout setting power well state %08x (%08x)\n",
Daniel Vetter9c065a72014-09-30 10:56:38 +02001304 state,
1305 vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ));
1306
1307#undef COND
1308
1309out:
1310 mutex_unlock(&dev_priv->rps.hw_lock);
1311}
1312
1313static void chv_pipe_power_well_sync_hw(struct drm_i915_private *dev_priv,
1314 struct i915_power_well *power_well)
1315{
Ville Syrjälä8fcd5cd2015-06-29 15:25:50 +03001316 WARN_ON_ONCE(power_well->data != PIPE_A);
1317
Daniel Vetter9c065a72014-09-30 10:56:38 +02001318 chv_set_pipe_power_well(dev_priv, power_well, power_well->count > 0);
1319}
1320
1321static void chv_pipe_power_well_enable(struct drm_i915_private *dev_priv,
1322 struct i915_power_well *power_well)
1323{
Ville Syrjälä8fcd5cd2015-06-29 15:25:50 +03001324 WARN_ON_ONCE(power_well->data != PIPE_A);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001325
1326 chv_set_pipe_power_well(dev_priv, power_well, true);
Ville Syrjäläafd62752014-10-30 19:43:03 +02001327
Ville Syrjälä2be7d542015-06-29 15:25:51 +03001328 vlv_display_power_well_init(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001329}
1330
1331static void chv_pipe_power_well_disable(struct drm_i915_private *dev_priv,
1332 struct i915_power_well *power_well)
1333{
Ville Syrjälä8fcd5cd2015-06-29 15:25:50 +03001334 WARN_ON_ONCE(power_well->data != PIPE_A);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001335
Ville Syrjälä2be7d542015-06-29 15:25:51 +03001336 vlv_display_power_well_deinit(dev_priv);
Ville Syrjäläafd62752014-10-30 19:43:03 +02001337
Daniel Vetter9c065a72014-09-30 10:56:38 +02001338 chv_set_pipe_power_well(dev_priv, power_well, false);
1339}
1340
Daniel Vettere4e76842014-09-30 10:56:42 +02001341/**
1342 * intel_display_power_get - grab a power domain reference
1343 * @dev_priv: i915 device instance
1344 * @domain: power domain to reference
1345 *
1346 * This function grabs a power domain reference for @domain and ensures that the
1347 * power domain and all its parents are powered up. Therefore users should only
1348 * grab a reference to the innermost power domain they need.
1349 *
1350 * Any power domain reference obtained by this function must have a symmetric
1351 * call to intel_display_power_put() to release the reference again.
1352 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02001353void intel_display_power_get(struct drm_i915_private *dev_priv,
1354 enum intel_display_power_domain domain)
1355{
1356 struct i915_power_domains *power_domains;
1357 struct i915_power_well *power_well;
1358 int i;
1359
1360 intel_runtime_pm_get(dev_priv);
1361
1362 power_domains = &dev_priv->power_domains;
1363
1364 mutex_lock(&power_domains->lock);
1365
1366 for_each_power_well(i, power_well, BIT(domain), power_domains) {
Damien Lespiaue8ca9322015-07-30 18:20:26 -03001367 if (!power_well->count++)
1368 intel_power_well_enable(dev_priv, power_well);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001369 }
1370
1371 power_domains->domain_use_count[domain]++;
1372
1373 mutex_unlock(&power_domains->lock);
1374}
1375
Daniel Vettere4e76842014-09-30 10:56:42 +02001376/**
1377 * intel_display_power_put - release a power domain reference
1378 * @dev_priv: i915 device instance
1379 * @domain: power domain to reference
1380 *
1381 * This function drops the power domain reference obtained by
1382 * intel_display_power_get() and might power down the corresponding hardware
1383 * block right away if this is the last reference.
1384 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02001385void intel_display_power_put(struct drm_i915_private *dev_priv,
1386 enum intel_display_power_domain domain)
1387{
1388 struct i915_power_domains *power_domains;
1389 struct i915_power_well *power_well;
1390 int i;
1391
1392 power_domains = &dev_priv->power_domains;
1393
1394 mutex_lock(&power_domains->lock);
1395
1396 WARN_ON(!power_domains->domain_use_count[domain]);
1397 power_domains->domain_use_count[domain]--;
1398
1399 for_each_power_well_rev(i, power_well, BIT(domain), power_domains) {
1400 WARN_ON(!power_well->count);
1401
Imre Deakd314cd42015-11-17 17:44:23 +02001402 if (!--power_well->count)
Damien Lespiaudcddab32015-07-30 18:20:27 -03001403 intel_power_well_disable(dev_priv, power_well);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001404 }
1405
1406 mutex_unlock(&power_domains->lock);
1407
1408 intel_runtime_pm_put(dev_priv);
1409}
1410
Daniel Vetter9c065a72014-09-30 10:56:38 +02001411#define HSW_ALWAYS_ON_POWER_DOMAINS ( \
1412 BIT(POWER_DOMAIN_PIPE_A) | \
1413 BIT(POWER_DOMAIN_TRANSCODER_EDP) | \
Patrik Jakobsson6331a702015-11-09 16:48:21 +01001414 BIT(POWER_DOMAIN_PORT_DDI_A_LANES) | \
1415 BIT(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1416 BIT(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1417 BIT(POWER_DOMAIN_PORT_DDI_D_LANES) | \
Daniel Vetter9c065a72014-09-30 10:56:38 +02001418 BIT(POWER_DOMAIN_PORT_CRT) | \
1419 BIT(POWER_DOMAIN_PLLS) | \
Satheeshakrishna M14071212015-01-16 15:57:51 +00001420 BIT(POWER_DOMAIN_AUX_A) | \
1421 BIT(POWER_DOMAIN_AUX_B) | \
1422 BIT(POWER_DOMAIN_AUX_C) | \
1423 BIT(POWER_DOMAIN_AUX_D) | \
Ville Syrjäläf0ab43e2015-11-09 16:48:19 +01001424 BIT(POWER_DOMAIN_GMBUS) | \
Daniel Vetter9c065a72014-09-30 10:56:38 +02001425 BIT(POWER_DOMAIN_INIT))
1426#define HSW_DISPLAY_POWER_DOMAINS ( \
1427 (POWER_DOMAIN_MASK & ~HSW_ALWAYS_ON_POWER_DOMAINS) | \
1428 BIT(POWER_DOMAIN_INIT))
1429
1430#define BDW_ALWAYS_ON_POWER_DOMAINS ( \
1431 HSW_ALWAYS_ON_POWER_DOMAINS | \
1432 BIT(POWER_DOMAIN_PIPE_A_PANEL_FITTER))
1433#define BDW_DISPLAY_POWER_DOMAINS ( \
1434 (POWER_DOMAIN_MASK & ~BDW_ALWAYS_ON_POWER_DOMAINS) | \
1435 BIT(POWER_DOMAIN_INIT))
1436
1437#define VLV_ALWAYS_ON_POWER_DOMAINS BIT(POWER_DOMAIN_INIT)
1438#define VLV_DISPLAY_POWER_DOMAINS POWER_DOMAIN_MASK
1439
1440#define VLV_DPIO_CMN_BC_POWER_DOMAINS ( \
Patrik Jakobsson6331a702015-11-09 16:48:21 +01001441 BIT(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1442 BIT(POWER_DOMAIN_PORT_DDI_C_LANES) | \
Daniel Vetter9c065a72014-09-30 10:56:38 +02001443 BIT(POWER_DOMAIN_PORT_CRT) | \
Satheeshakrishna M14071212015-01-16 15:57:51 +00001444 BIT(POWER_DOMAIN_AUX_B) | \
1445 BIT(POWER_DOMAIN_AUX_C) | \
Daniel Vetter9c065a72014-09-30 10:56:38 +02001446 BIT(POWER_DOMAIN_INIT))
1447
1448#define VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS ( \
Patrik Jakobsson6331a702015-11-09 16:48:21 +01001449 BIT(POWER_DOMAIN_PORT_DDI_B_LANES) | \
Satheeshakrishna M14071212015-01-16 15:57:51 +00001450 BIT(POWER_DOMAIN_AUX_B) | \
Daniel Vetter9c065a72014-09-30 10:56:38 +02001451 BIT(POWER_DOMAIN_INIT))
1452
1453#define VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS ( \
Patrik Jakobsson6331a702015-11-09 16:48:21 +01001454 BIT(POWER_DOMAIN_PORT_DDI_B_LANES) | \
Satheeshakrishna M14071212015-01-16 15:57:51 +00001455 BIT(POWER_DOMAIN_AUX_B) | \
Daniel Vetter9c065a72014-09-30 10:56:38 +02001456 BIT(POWER_DOMAIN_INIT))
1457
1458#define VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS ( \
Patrik Jakobsson6331a702015-11-09 16:48:21 +01001459 BIT(POWER_DOMAIN_PORT_DDI_C_LANES) | \
Satheeshakrishna M14071212015-01-16 15:57:51 +00001460 BIT(POWER_DOMAIN_AUX_C) | \
Daniel Vetter9c065a72014-09-30 10:56:38 +02001461 BIT(POWER_DOMAIN_INIT))
1462
1463#define VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS ( \
Patrik Jakobsson6331a702015-11-09 16:48:21 +01001464 BIT(POWER_DOMAIN_PORT_DDI_C_LANES) | \
Satheeshakrishna M14071212015-01-16 15:57:51 +00001465 BIT(POWER_DOMAIN_AUX_C) | \
Daniel Vetter9c065a72014-09-30 10:56:38 +02001466 BIT(POWER_DOMAIN_INIT))
1467
Daniel Vetter9c065a72014-09-30 10:56:38 +02001468#define CHV_DPIO_CMN_BC_POWER_DOMAINS ( \
Patrik Jakobsson6331a702015-11-09 16:48:21 +01001469 BIT(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1470 BIT(POWER_DOMAIN_PORT_DDI_C_LANES) | \
Satheeshakrishna M14071212015-01-16 15:57:51 +00001471 BIT(POWER_DOMAIN_AUX_B) | \
1472 BIT(POWER_DOMAIN_AUX_C) | \
Daniel Vetter9c065a72014-09-30 10:56:38 +02001473 BIT(POWER_DOMAIN_INIT))
1474
1475#define CHV_DPIO_CMN_D_POWER_DOMAINS ( \
Patrik Jakobsson6331a702015-11-09 16:48:21 +01001476 BIT(POWER_DOMAIN_PORT_DDI_D_LANES) | \
Satheeshakrishna M14071212015-01-16 15:57:51 +00001477 BIT(POWER_DOMAIN_AUX_D) | \
Daniel Vetter9c065a72014-09-30 10:56:38 +02001478 BIT(POWER_DOMAIN_INIT))
1479
Daniel Vetter9c065a72014-09-30 10:56:38 +02001480static const struct i915_power_well_ops i9xx_always_on_power_well_ops = {
1481 .sync_hw = i9xx_always_on_power_well_noop,
1482 .enable = i9xx_always_on_power_well_noop,
1483 .disable = i9xx_always_on_power_well_noop,
1484 .is_enabled = i9xx_always_on_power_well_enabled,
1485};
1486
1487static const struct i915_power_well_ops chv_pipe_power_well_ops = {
1488 .sync_hw = chv_pipe_power_well_sync_hw,
1489 .enable = chv_pipe_power_well_enable,
1490 .disable = chv_pipe_power_well_disable,
1491 .is_enabled = chv_pipe_power_well_enabled,
1492};
1493
1494static const struct i915_power_well_ops chv_dpio_cmn_power_well_ops = {
1495 .sync_hw = vlv_power_well_sync_hw,
1496 .enable = chv_dpio_cmn_power_well_enable,
1497 .disable = chv_dpio_cmn_power_well_disable,
1498 .is_enabled = vlv_power_well_enabled,
1499};
1500
1501static struct i915_power_well i9xx_always_on_power_well[] = {
1502 {
1503 .name = "always-on",
1504 .always_on = 1,
1505 .domains = POWER_DOMAIN_MASK,
1506 .ops = &i9xx_always_on_power_well_ops,
1507 },
1508};
1509
1510static const struct i915_power_well_ops hsw_power_well_ops = {
1511 .sync_hw = hsw_power_well_sync_hw,
1512 .enable = hsw_power_well_enable,
1513 .disable = hsw_power_well_disable,
1514 .is_enabled = hsw_power_well_enabled,
1515};
1516
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00001517static const struct i915_power_well_ops skl_power_well_ops = {
1518 .sync_hw = skl_power_well_sync_hw,
1519 .enable = skl_power_well_enable,
1520 .disable = skl_power_well_disable,
1521 .is_enabled = skl_power_well_enabled,
1522};
1523
Daniel Vetter9c065a72014-09-30 10:56:38 +02001524static struct i915_power_well hsw_power_wells[] = {
1525 {
1526 .name = "always-on",
1527 .always_on = 1,
1528 .domains = HSW_ALWAYS_ON_POWER_DOMAINS,
1529 .ops = &i9xx_always_on_power_well_ops,
1530 },
1531 {
1532 .name = "display",
1533 .domains = HSW_DISPLAY_POWER_DOMAINS,
1534 .ops = &hsw_power_well_ops,
1535 },
1536};
1537
1538static struct i915_power_well bdw_power_wells[] = {
1539 {
1540 .name = "always-on",
1541 .always_on = 1,
1542 .domains = BDW_ALWAYS_ON_POWER_DOMAINS,
1543 .ops = &i9xx_always_on_power_well_ops,
1544 },
1545 {
1546 .name = "display",
1547 .domains = BDW_DISPLAY_POWER_DOMAINS,
1548 .ops = &hsw_power_well_ops,
1549 },
1550};
1551
1552static const struct i915_power_well_ops vlv_display_power_well_ops = {
1553 .sync_hw = vlv_power_well_sync_hw,
1554 .enable = vlv_display_power_well_enable,
1555 .disable = vlv_display_power_well_disable,
1556 .is_enabled = vlv_power_well_enabled,
1557};
1558
1559static const struct i915_power_well_ops vlv_dpio_cmn_power_well_ops = {
1560 .sync_hw = vlv_power_well_sync_hw,
1561 .enable = vlv_dpio_cmn_power_well_enable,
1562 .disable = vlv_dpio_cmn_power_well_disable,
1563 .is_enabled = vlv_power_well_enabled,
1564};
1565
1566static const struct i915_power_well_ops vlv_dpio_power_well_ops = {
1567 .sync_hw = vlv_power_well_sync_hw,
1568 .enable = vlv_power_well_enable,
1569 .disable = vlv_power_well_disable,
1570 .is_enabled = vlv_power_well_enabled,
1571};
1572
1573static struct i915_power_well vlv_power_wells[] = {
1574 {
1575 .name = "always-on",
1576 .always_on = 1,
1577 .domains = VLV_ALWAYS_ON_POWER_DOMAINS,
1578 .ops = &i9xx_always_on_power_well_ops,
Imre Deak56fcfd62015-11-04 19:24:10 +02001579 .data = PUNIT_POWER_WELL_ALWAYS_ON,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001580 },
1581 {
1582 .name = "display",
1583 .domains = VLV_DISPLAY_POWER_DOMAINS,
1584 .data = PUNIT_POWER_WELL_DISP2D,
1585 .ops = &vlv_display_power_well_ops,
1586 },
1587 {
1588 .name = "dpio-tx-b-01",
1589 .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
1590 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
1591 VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
1592 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
1593 .ops = &vlv_dpio_power_well_ops,
1594 .data = PUNIT_POWER_WELL_DPIO_TX_B_LANES_01,
1595 },
1596 {
1597 .name = "dpio-tx-b-23",
1598 .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
1599 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
1600 VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
1601 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
1602 .ops = &vlv_dpio_power_well_ops,
1603 .data = PUNIT_POWER_WELL_DPIO_TX_B_LANES_23,
1604 },
1605 {
1606 .name = "dpio-tx-c-01",
1607 .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
1608 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
1609 VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
1610 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
1611 .ops = &vlv_dpio_power_well_ops,
1612 .data = PUNIT_POWER_WELL_DPIO_TX_C_LANES_01,
1613 },
1614 {
1615 .name = "dpio-tx-c-23",
1616 .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
1617 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
1618 VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
1619 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
1620 .ops = &vlv_dpio_power_well_ops,
1621 .data = PUNIT_POWER_WELL_DPIO_TX_C_LANES_23,
1622 },
1623 {
1624 .name = "dpio-common",
1625 .domains = VLV_DPIO_CMN_BC_POWER_DOMAINS,
1626 .data = PUNIT_POWER_WELL_DPIO_CMN_BC,
1627 .ops = &vlv_dpio_cmn_power_well_ops,
1628 },
1629};
1630
1631static struct i915_power_well chv_power_wells[] = {
1632 {
1633 .name = "always-on",
1634 .always_on = 1,
1635 .domains = VLV_ALWAYS_ON_POWER_DOMAINS,
1636 .ops = &i9xx_always_on_power_well_ops,
1637 },
Daniel Vetter9c065a72014-09-30 10:56:38 +02001638 {
1639 .name = "display",
Ville Syrjäläbaa4e572014-10-27 16:07:32 +02001640 /*
Ville Syrjäläfde61e42015-05-26 20:22:39 +03001641 * Pipe A power well is the new disp2d well. Pipe B and C
1642 * power wells don't actually exist. Pipe A power well is
1643 * required for any pipe to work.
Ville Syrjäläbaa4e572014-10-27 16:07:32 +02001644 */
Ville Syrjäläfde61e42015-05-26 20:22:39 +03001645 .domains = VLV_DISPLAY_POWER_DOMAINS,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001646 .data = PIPE_A,
1647 .ops = &chv_pipe_power_well_ops,
1648 },
Daniel Vetter9c065a72014-09-30 10:56:38 +02001649 {
1650 .name = "dpio-common-bc",
Ville Syrjälä71849b62015-04-10 18:21:29 +03001651 .domains = CHV_DPIO_CMN_BC_POWER_DOMAINS,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001652 .data = PUNIT_POWER_WELL_DPIO_CMN_BC,
1653 .ops = &chv_dpio_cmn_power_well_ops,
1654 },
1655 {
1656 .name = "dpio-common-d",
Ville Syrjälä71849b62015-04-10 18:21:29 +03001657 .domains = CHV_DPIO_CMN_D_POWER_DOMAINS,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001658 .data = PUNIT_POWER_WELL_DPIO_CMN_D,
1659 .ops = &chv_dpio_cmn_power_well_ops,
1660 },
Daniel Vetter9c065a72014-09-30 10:56:38 +02001661};
1662
Suketu Shah5aefb232015-04-16 14:22:10 +05301663bool intel_display_power_well_is_enabled(struct drm_i915_private *dev_priv,
1664 int power_well_id)
1665{
1666 struct i915_power_well *power_well;
1667 bool ret;
1668
1669 power_well = lookup_power_well(dev_priv, power_well_id);
1670 ret = power_well->ops->is_enabled(dev_priv, power_well);
1671
1672 return ret;
1673}
1674
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00001675static struct i915_power_well skl_power_wells[] = {
1676 {
1677 .name = "always-on",
1678 .always_on = 1,
1679 .domains = SKL_DISPLAY_ALWAYS_ON_POWER_DOMAINS,
1680 .ops = &i9xx_always_on_power_well_ops,
Imre Deak56fcfd62015-11-04 19:24:10 +02001681 .data = SKL_DISP_PW_ALWAYS_ON,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00001682 },
1683 {
1684 .name = "power well 1",
Imre Deak4a76f292015-11-04 19:24:15 +02001685 /* Handled by the DMC firmware */
1686 .domains = 0,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00001687 .ops = &skl_power_well_ops,
1688 .data = SKL_DISP_PW_1,
1689 },
1690 {
1691 .name = "MISC IO power well",
Imre Deak4a76f292015-11-04 19:24:15 +02001692 /* Handled by the DMC firmware */
1693 .domains = 0,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00001694 .ops = &skl_power_well_ops,
1695 .data = SKL_DISP_PW_MISC_IO,
1696 },
1697 {
1698 .name = "power well 2",
1699 .domains = SKL_DISPLAY_POWERWELL_2_POWER_DOMAINS,
1700 .ops = &skl_power_well_ops,
1701 .data = SKL_DISP_PW_2,
1702 },
1703 {
1704 .name = "DDI A/E power well",
1705 .domains = SKL_DISPLAY_DDI_A_E_POWER_DOMAINS,
1706 .ops = &skl_power_well_ops,
1707 .data = SKL_DISP_PW_DDI_A_E,
1708 },
1709 {
1710 .name = "DDI B power well",
1711 .domains = SKL_DISPLAY_DDI_B_POWER_DOMAINS,
1712 .ops = &skl_power_well_ops,
1713 .data = SKL_DISP_PW_DDI_B,
1714 },
1715 {
1716 .name = "DDI C power well",
1717 .domains = SKL_DISPLAY_DDI_C_POWER_DOMAINS,
1718 .ops = &skl_power_well_ops,
1719 .data = SKL_DISP_PW_DDI_C,
1720 },
1721 {
1722 .name = "DDI D power well",
1723 .domains = SKL_DISPLAY_DDI_D_POWER_DOMAINS,
1724 .ops = &skl_power_well_ops,
1725 .data = SKL_DISP_PW_DDI_D,
1726 },
1727};
1728
Damien Lespiau2f693e22015-11-04 19:24:12 +02001729void skl_pw1_misc_io_init(struct drm_i915_private *dev_priv)
1730{
1731 struct i915_power_well *well;
1732
1733 if (!IS_SKYLAKE(dev_priv))
1734 return;
1735
1736 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
1737 intel_power_well_enable(dev_priv, well);
1738
1739 well = lookup_power_well(dev_priv, SKL_DISP_PW_MISC_IO);
1740 intel_power_well_enable(dev_priv, well);
1741}
1742
1743void skl_pw1_misc_io_fini(struct drm_i915_private *dev_priv)
1744{
1745 struct i915_power_well *well;
1746
1747 if (!IS_SKYLAKE(dev_priv))
1748 return;
1749
1750 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
1751 intel_power_well_disable(dev_priv, well);
1752
1753 well = lookup_power_well(dev_priv, SKL_DISP_PW_MISC_IO);
1754 intel_power_well_disable(dev_priv, well);
1755}
1756
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05301757static struct i915_power_well bxt_power_wells[] = {
1758 {
1759 .name = "always-on",
1760 .always_on = 1,
1761 .domains = BXT_DISPLAY_ALWAYS_ON_POWER_DOMAINS,
1762 .ops = &i9xx_always_on_power_well_ops,
1763 },
1764 {
1765 .name = "power well 1",
1766 .domains = BXT_DISPLAY_POWERWELL_1_POWER_DOMAINS,
1767 .ops = &skl_power_well_ops,
1768 .data = SKL_DISP_PW_1,
1769 },
1770 {
1771 .name = "power well 2",
1772 .domains = BXT_DISPLAY_POWERWELL_2_POWER_DOMAINS,
1773 .ops = &skl_power_well_ops,
1774 .data = SKL_DISP_PW_2,
1775 }
1776};
1777
Daniel Vetter9c065a72014-09-30 10:56:38 +02001778#define set_power_wells(power_domains, __power_wells) ({ \
1779 (power_domains)->power_wells = (__power_wells); \
1780 (power_domains)->power_well_count = ARRAY_SIZE(__power_wells); \
1781})
1782
Daniel Vettere4e76842014-09-30 10:56:42 +02001783/**
1784 * intel_power_domains_init - initializes the power domain structures
1785 * @dev_priv: i915 device instance
1786 *
1787 * Initializes the power domain structures for @dev_priv depending upon the
1788 * supported platform.
1789 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02001790int intel_power_domains_init(struct drm_i915_private *dev_priv)
1791{
1792 struct i915_power_domains *power_domains = &dev_priv->power_domains;
1793
Ville Syrjäläf0ab43e2015-11-09 16:48:19 +01001794 BUILD_BUG_ON(POWER_DOMAIN_NUM > 31);
1795
Daniel Vetter9c065a72014-09-30 10:56:38 +02001796 mutex_init(&power_domains->lock);
1797
1798 /*
1799 * The enabling order will be from lower to higher indexed wells,
1800 * the disabling order is reversed.
1801 */
1802 if (IS_HASWELL(dev_priv->dev)) {
1803 set_power_wells(power_domains, hsw_power_wells);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001804 } else if (IS_BROADWELL(dev_priv->dev)) {
1805 set_power_wells(power_domains, bdw_power_wells);
Rodrigo Vivief11bdb2015-10-28 04:16:45 -07001806 } else if (IS_SKYLAKE(dev_priv->dev) || IS_KABYLAKE(dev_priv->dev)) {
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00001807 set_power_wells(power_domains, skl_power_wells);
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05301808 } else if (IS_BROXTON(dev_priv->dev)) {
1809 set_power_wells(power_domains, bxt_power_wells);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001810 } else if (IS_CHERRYVIEW(dev_priv->dev)) {
1811 set_power_wells(power_domains, chv_power_wells);
1812 } else if (IS_VALLEYVIEW(dev_priv->dev)) {
1813 set_power_wells(power_domains, vlv_power_wells);
1814 } else {
1815 set_power_wells(power_domains, i9xx_always_on_power_well);
1816 }
1817
1818 return 0;
1819}
1820
Daniel Vettere4e76842014-09-30 10:56:42 +02001821/**
1822 * intel_power_domains_fini - finalizes the power domain structures
1823 * @dev_priv: i915 device instance
1824 *
1825 * Finalizes the power domain structures for @dev_priv depending upon the
1826 * supported platform. This function also disables runtime pm and ensures that
1827 * the device stays powered up so that the driver can be reloaded.
1828 */
Daniel Vetterf458ebb2014-09-30 10:56:39 +02001829void intel_power_domains_fini(struct drm_i915_private *dev_priv)
Daniel Vetter9c065a72014-09-30 10:56:38 +02001830{
Daniel Vetterf458ebb2014-09-30 10:56:39 +02001831 /* The i915.ko module is still not prepared to be loaded when
1832 * the power well is not enabled, so just enable it in case
1833 * we're going to unload/reload. */
1834 intel_display_set_init_power(dev_priv, true);
Imre Deakd314cd42015-11-17 17:44:23 +02001835
1836 /* Remove the refcount we took to keep power well support disabled. */
1837 if (!i915.disable_power_well)
1838 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001839}
1840
Imre Deak30eade12015-11-04 19:24:13 +02001841static void intel_power_domains_sync_hw(struct drm_i915_private *dev_priv)
Daniel Vetter9c065a72014-09-30 10:56:38 +02001842{
1843 struct i915_power_domains *power_domains = &dev_priv->power_domains;
1844 struct i915_power_well *power_well;
1845 int i;
1846
1847 mutex_lock(&power_domains->lock);
1848 for_each_power_well(i, power_well, POWER_DOMAIN_MASK, power_domains) {
1849 power_well->ops->sync_hw(dev_priv, power_well);
1850 power_well->hw_enabled = power_well->ops->is_enabled(dev_priv,
1851 power_well);
1852 }
1853 mutex_unlock(&power_domains->lock);
1854}
1855
Imre Deak73dfc222015-11-17 17:33:53 +02001856static void skl_display_core_init(struct drm_i915_private *dev_priv,
1857 bool resume)
1858{
1859 struct i915_power_domains *power_domains = &dev_priv->power_domains;
1860 uint32_t val;
1861
Imre Deakd26fa1d2015-11-04 19:24:17 +02001862 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
1863
Imre Deak73dfc222015-11-17 17:33:53 +02001864 /* enable PCH reset handshake */
1865 val = I915_READ(HSW_NDE_RSTWRN_OPT);
1866 I915_WRITE(HSW_NDE_RSTWRN_OPT, val | RESET_PCH_HANDSHAKE_ENABLE);
1867
1868 /* enable PG1 and Misc I/O */
1869 mutex_lock(&power_domains->lock);
1870 skl_pw1_misc_io_init(dev_priv);
1871 mutex_unlock(&power_domains->lock);
1872
1873 if (!resume)
1874 return;
1875
1876 skl_init_cdclk(dev_priv);
1877
1878 if (dev_priv->csr.dmc_payload)
1879 intel_csr_load_program(dev_priv);
1880}
1881
1882static void skl_display_core_uninit(struct drm_i915_private *dev_priv)
1883{
1884 struct i915_power_domains *power_domains = &dev_priv->power_domains;
1885
Imre Deakd26fa1d2015-11-04 19:24:17 +02001886 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
1887
Imre Deak73dfc222015-11-17 17:33:53 +02001888 skl_uninit_cdclk(dev_priv);
1889
1890 /* The spec doesn't call for removing the reset handshake flag */
1891 /* disable PG1 and Misc I/O */
1892 mutex_lock(&power_domains->lock);
1893 skl_pw1_misc_io_fini(dev_priv);
1894 mutex_unlock(&power_domains->lock);
1895}
1896
Ville Syrjälä70722462015-04-10 18:21:28 +03001897static void chv_phy_control_init(struct drm_i915_private *dev_priv)
1898{
1899 struct i915_power_well *cmn_bc =
1900 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_BC);
1901 struct i915_power_well *cmn_d =
1902 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_D);
1903
1904 /*
1905 * DISPLAY_PHY_CONTROL can get corrupted if read. As a
1906 * workaround never ever read DISPLAY_PHY_CONTROL, and
1907 * instead maintain a shadow copy ourselves. Use the actual
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001908 * power well state and lane status to reconstruct the
1909 * expected initial value.
Ville Syrjälä70722462015-04-10 18:21:28 +03001910 */
1911 dev_priv->chv_phy_control =
Ville Syrjäläbc284542015-05-26 20:22:38 +03001912 PHY_LDO_SEQ_DELAY(PHY_LDO_DELAY_600NS, DPIO_PHY0) |
1913 PHY_LDO_SEQ_DELAY(PHY_LDO_DELAY_600NS, DPIO_PHY1) |
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001914 PHY_CH_POWER_MODE(PHY_CH_DEEP_PSR, DPIO_PHY0, DPIO_CH0) |
1915 PHY_CH_POWER_MODE(PHY_CH_DEEP_PSR, DPIO_PHY0, DPIO_CH1) |
1916 PHY_CH_POWER_MODE(PHY_CH_DEEP_PSR, DPIO_PHY1, DPIO_CH0);
1917
1918 /*
1919 * If all lanes are disabled we leave the override disabled
1920 * with all power down bits cleared to match the state we
1921 * would use after disabling the port. Otherwise enable the
1922 * override and set the lane powerdown bits accding to the
1923 * current lane status.
1924 */
1925 if (cmn_bc->ops->is_enabled(dev_priv, cmn_bc)) {
1926 uint32_t status = I915_READ(DPLL(PIPE_A));
1927 unsigned int mask;
1928
1929 mask = status & DPLL_PORTB_READY_MASK;
1930 if (mask == 0xf)
1931 mask = 0x0;
1932 else
1933 dev_priv->chv_phy_control |=
1934 PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY0, DPIO_CH0);
1935
1936 dev_priv->chv_phy_control |=
1937 PHY_CH_POWER_DOWN_OVRD(mask, DPIO_PHY0, DPIO_CH0);
1938
1939 mask = (status & DPLL_PORTC_READY_MASK) >> 4;
1940 if (mask == 0xf)
1941 mask = 0x0;
1942 else
1943 dev_priv->chv_phy_control |=
1944 PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY0, DPIO_CH1);
1945
1946 dev_priv->chv_phy_control |=
1947 PHY_CH_POWER_DOWN_OVRD(mask, DPIO_PHY0, DPIO_CH1);
1948
Ville Syrjälä70722462015-04-10 18:21:28 +03001949 dev_priv->chv_phy_control |= PHY_COM_LANE_RESET_DEASSERT(DPIO_PHY0);
Ville Syrjälä3be60de2015-09-08 18:05:45 +03001950
1951 dev_priv->chv_phy_assert[DPIO_PHY0] = false;
1952 } else {
1953 dev_priv->chv_phy_assert[DPIO_PHY0] = true;
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001954 }
1955
1956 if (cmn_d->ops->is_enabled(dev_priv, cmn_d)) {
1957 uint32_t status = I915_READ(DPIO_PHY_STATUS);
1958 unsigned int mask;
1959
1960 mask = status & DPLL_PORTD_READY_MASK;
1961
1962 if (mask == 0xf)
1963 mask = 0x0;
1964 else
1965 dev_priv->chv_phy_control |=
1966 PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY1, DPIO_CH0);
1967
1968 dev_priv->chv_phy_control |=
1969 PHY_CH_POWER_DOWN_OVRD(mask, DPIO_PHY1, DPIO_CH0);
1970
Ville Syrjälä70722462015-04-10 18:21:28 +03001971 dev_priv->chv_phy_control |= PHY_COM_LANE_RESET_DEASSERT(DPIO_PHY1);
Ville Syrjälä3be60de2015-09-08 18:05:45 +03001972
1973 dev_priv->chv_phy_assert[DPIO_PHY1] = false;
1974 } else {
1975 dev_priv->chv_phy_assert[DPIO_PHY1] = true;
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001976 }
1977
1978 I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
1979
1980 DRM_DEBUG_KMS("Initial PHY_CONTROL=0x%08x\n",
1981 dev_priv->chv_phy_control);
Ville Syrjälä70722462015-04-10 18:21:28 +03001982}
1983
Daniel Vetter9c065a72014-09-30 10:56:38 +02001984static void vlv_cmnlane_wa(struct drm_i915_private *dev_priv)
1985{
1986 struct i915_power_well *cmn =
1987 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_BC);
1988 struct i915_power_well *disp2d =
1989 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DISP2D);
1990
Daniel Vetter9c065a72014-09-30 10:56:38 +02001991 /* If the display might be already active skip this */
Ville Syrjälä5d93a6e2014-10-16 20:52:33 +03001992 if (cmn->ops->is_enabled(dev_priv, cmn) &&
1993 disp2d->ops->is_enabled(dev_priv, disp2d) &&
Daniel Vetter9c065a72014-09-30 10:56:38 +02001994 I915_READ(DPIO_CTL) & DPIO_CMNRST)
1995 return;
1996
1997 DRM_DEBUG_KMS("toggling display PHY side reset\n");
1998
1999 /* cmnlane needs DPLL registers */
2000 disp2d->ops->enable(dev_priv, disp2d);
2001
2002 /*
2003 * From VLV2A0_DP_eDP_HDMI_DPIO_driver_vbios_notes_11.docx:
2004 * Need to assert and de-assert PHY SB reset by gating the
2005 * common lane power, then un-gating it.
2006 * Simply ungating isn't enough to reset the PHY enough to get
2007 * ports and lanes running.
2008 */
2009 cmn->ops->disable(dev_priv, cmn);
2010}
2011
Daniel Vettere4e76842014-09-30 10:56:42 +02002012/**
2013 * intel_power_domains_init_hw - initialize hardware power domain state
2014 * @dev_priv: i915 device instance
2015 *
2016 * This function initializes the hardware power domain state and enables all
2017 * power domains using intel_display_set_init_power().
2018 */
Imre Deak73dfc222015-11-17 17:33:53 +02002019void intel_power_domains_init_hw(struct drm_i915_private *dev_priv, bool resume)
Daniel Vetter9c065a72014-09-30 10:56:38 +02002020{
2021 struct drm_device *dev = dev_priv->dev;
2022 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2023
2024 power_domains->initializing = true;
2025
Imre Deak73dfc222015-11-17 17:33:53 +02002026 if (IS_SKYLAKE(dev) || IS_KABYLAKE(dev)) {
2027 skl_display_core_init(dev_priv, resume);
2028 } else if (IS_CHERRYVIEW(dev)) {
Ville Syrjälä770effb2015-07-08 23:45:51 +03002029 mutex_lock(&power_domains->lock);
Ville Syrjälä70722462015-04-10 18:21:28 +03002030 chv_phy_control_init(dev_priv);
Ville Syrjälä770effb2015-07-08 23:45:51 +03002031 mutex_unlock(&power_domains->lock);
Ville Syrjälä70722462015-04-10 18:21:28 +03002032 } else if (IS_VALLEYVIEW(dev)) {
Daniel Vetter9c065a72014-09-30 10:56:38 +02002033 mutex_lock(&power_domains->lock);
2034 vlv_cmnlane_wa(dev_priv);
2035 mutex_unlock(&power_domains->lock);
2036 }
2037
2038 /* For now, we need the power well to be always enabled. */
2039 intel_display_set_init_power(dev_priv, true);
Imre Deakd314cd42015-11-17 17:44:23 +02002040 /* Disable power support if the user asked so. */
2041 if (!i915.disable_power_well)
2042 intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
Imre Deak30eade12015-11-04 19:24:13 +02002043 intel_power_domains_sync_hw(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02002044 power_domains->initializing = false;
2045}
2046
Daniel Vettere4e76842014-09-30 10:56:42 +02002047/**
Imre Deak73dfc222015-11-17 17:33:53 +02002048 * intel_power_domains_suspend - suspend power domain state
2049 * @dev_priv: i915 device instance
2050 *
2051 * This function prepares the hardware power domain state before entering
2052 * system suspend. It must be paired with intel_power_domains_init_hw().
2053 */
2054void intel_power_domains_suspend(struct drm_i915_private *dev_priv)
2055{
2056 if (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv))
2057 skl_display_core_uninit(dev_priv);
Imre Deakd314cd42015-11-17 17:44:23 +02002058
2059 /*
2060 * Even if power well support was disabled we still want to disable
2061 * power wells while we are system suspended.
2062 */
2063 if (!i915.disable_power_well)
2064 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
Imre Deak73dfc222015-11-17 17:33:53 +02002065}
2066
2067/**
Daniel Vettere4e76842014-09-30 10:56:42 +02002068 * intel_runtime_pm_get - grab a runtime pm reference
2069 * @dev_priv: i915 device instance
2070 *
2071 * This function grabs a device-level runtime pm reference (mostly used for GEM
2072 * code to ensure the GTT or GT is on) and ensures that it is powered up.
2073 *
2074 * Any runtime pm reference obtained by this function must have a symmetric
2075 * call to intel_runtime_pm_put() to release the reference again.
2076 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02002077void intel_runtime_pm_get(struct drm_i915_private *dev_priv)
2078{
2079 struct drm_device *dev = dev_priv->dev;
2080 struct device *device = &dev->pdev->dev;
2081
2082 if (!HAS_RUNTIME_PM(dev))
2083 return;
2084
2085 pm_runtime_get_sync(device);
2086 WARN(dev_priv->pm.suspended, "Device still suspended.\n");
2087}
2088
Daniel Vettere4e76842014-09-30 10:56:42 +02002089/**
2090 * intel_runtime_pm_get_noresume - grab a runtime pm reference
2091 * @dev_priv: i915 device instance
2092 *
2093 * This function grabs a device-level runtime pm reference (mostly used for GEM
2094 * code to ensure the GTT or GT is on).
2095 *
2096 * It will _not_ power up the device but instead only check that it's powered
2097 * on. Therefore it is only valid to call this functions from contexts where
2098 * the device is known to be powered up and where trying to power it up would
2099 * result in hilarity and deadlocks. That pretty much means only the system
2100 * suspend/resume code where this is used to grab runtime pm references for
2101 * delayed setup down in work items.
2102 *
2103 * Any runtime pm reference obtained by this function must have a symmetric
2104 * call to intel_runtime_pm_put() to release the reference again.
2105 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02002106void intel_runtime_pm_get_noresume(struct drm_i915_private *dev_priv)
2107{
2108 struct drm_device *dev = dev_priv->dev;
2109 struct device *device = &dev->pdev->dev;
2110
2111 if (!HAS_RUNTIME_PM(dev))
2112 return;
2113
2114 WARN(dev_priv->pm.suspended, "Getting nosync-ref while suspended.\n");
2115 pm_runtime_get_noresume(device);
2116}
2117
Daniel Vettere4e76842014-09-30 10:56:42 +02002118/**
2119 * intel_runtime_pm_put - release a runtime pm reference
2120 * @dev_priv: i915 device instance
2121 *
2122 * This function drops the device-level runtime pm reference obtained by
2123 * intel_runtime_pm_get() and might power down the corresponding
2124 * hardware block right away if this is the last reference.
2125 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02002126void intel_runtime_pm_put(struct drm_i915_private *dev_priv)
2127{
2128 struct drm_device *dev = dev_priv->dev;
2129 struct device *device = &dev->pdev->dev;
2130
2131 if (!HAS_RUNTIME_PM(dev))
2132 return;
2133
2134 pm_runtime_mark_last_busy(device);
2135 pm_runtime_put_autosuspend(device);
2136}
2137
Daniel Vettere4e76842014-09-30 10:56:42 +02002138/**
2139 * intel_runtime_pm_enable - enable runtime pm
2140 * @dev_priv: i915 device instance
2141 *
2142 * This function enables runtime pm at the end of the driver load sequence.
2143 *
2144 * Note that this function does currently not enable runtime pm for the
2145 * subordinate display power domains. That is only done on the first modeset
2146 * using intel_display_set_init_power().
2147 */
Daniel Vetterf458ebb2014-09-30 10:56:39 +02002148void intel_runtime_pm_enable(struct drm_i915_private *dev_priv)
Daniel Vetter9c065a72014-09-30 10:56:38 +02002149{
2150 struct drm_device *dev = dev_priv->dev;
2151 struct device *device = &dev->pdev->dev;
2152
2153 if (!HAS_RUNTIME_PM(dev))
2154 return;
2155
Daniel Vetter9c065a72014-09-30 10:56:38 +02002156 /*
2157 * RPM depends on RC6 to save restore the GT HW context, so make RC6 a
2158 * requirement.
2159 */
2160 if (!intel_enable_rc6(dev)) {
2161 DRM_INFO("RC6 disabled, disabling runtime PM support\n");
2162 return;
2163 }
2164
2165 pm_runtime_set_autosuspend_delay(device, 10000); /* 10s */
2166 pm_runtime_mark_last_busy(device);
2167 pm_runtime_use_autosuspend(device);
2168
2169 pm_runtime_put_autosuspend(device);
2170}
2171