blob: 5892c0011421d7a2bb00728500a8bb0afa1dc18f [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 }
247
Damien Lespiau1d2b9522015-03-06 18:50:53 +0000248 if (power_well->data == SKL_DISP_PW_1) {
249 intel_prepare_ddi(dev);
Damien Lespiaud14c0342015-03-06 18:50:51 +0000250 gen8_irq_power_well_post_enable(dev_priv, 1 << PIPE_A);
Damien Lespiau1d2b9522015-03-06 18:50:53 +0000251 }
Damien Lespiaud14c0342015-03-06 18:50:51 +0000252}
253
Daniel Vetter9c065a72014-09-30 10:56:38 +0200254static void hsw_set_power_well(struct drm_i915_private *dev_priv,
255 struct i915_power_well *power_well, bool enable)
256{
257 bool is_enabled, enable_requested;
258 uint32_t tmp;
259
260 tmp = I915_READ(HSW_PWR_WELL_DRIVER);
261 is_enabled = tmp & HSW_PWR_WELL_STATE_ENABLED;
262 enable_requested = tmp & HSW_PWR_WELL_ENABLE_REQUEST;
263
264 if (enable) {
265 if (!enable_requested)
266 I915_WRITE(HSW_PWR_WELL_DRIVER,
267 HSW_PWR_WELL_ENABLE_REQUEST);
268
269 if (!is_enabled) {
270 DRM_DEBUG_KMS("Enabling power well\n");
271 if (wait_for((I915_READ(HSW_PWR_WELL_DRIVER) &
272 HSW_PWR_WELL_STATE_ENABLED), 20))
273 DRM_ERROR("Timeout enabling power well\n");
Paulo Zanoni6d729bf2014-10-07 16:11:11 -0300274 hsw_power_well_post_enable(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200275 }
276
Daniel Vetter9c065a72014-09-30 10:56:38 +0200277 } else {
278 if (enable_requested) {
279 I915_WRITE(HSW_PWR_WELL_DRIVER, 0);
280 POSTING_READ(HSW_PWR_WELL_DRIVER);
281 DRM_DEBUG_KMS("Requesting to disable the power well\n");
282 }
283 }
284}
285
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000286#define SKL_DISPLAY_POWERWELL_2_POWER_DOMAINS ( \
287 BIT(POWER_DOMAIN_TRANSCODER_A) | \
288 BIT(POWER_DOMAIN_PIPE_B) | \
289 BIT(POWER_DOMAIN_TRANSCODER_B) | \
290 BIT(POWER_DOMAIN_PIPE_C) | \
291 BIT(POWER_DOMAIN_TRANSCODER_C) | \
292 BIT(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
293 BIT(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
294 BIT(POWER_DOMAIN_PORT_DDI_B_2_LANES) | \
295 BIT(POWER_DOMAIN_PORT_DDI_B_4_LANES) | \
296 BIT(POWER_DOMAIN_PORT_DDI_C_2_LANES) | \
297 BIT(POWER_DOMAIN_PORT_DDI_C_4_LANES) | \
298 BIT(POWER_DOMAIN_PORT_DDI_D_2_LANES) | \
299 BIT(POWER_DOMAIN_PORT_DDI_D_4_LANES) | \
Xiong Zhangd8e19f92015-08-13 18:00:12 +0800300 BIT(POWER_DOMAIN_PORT_DDI_E_2_LANES) | \
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000301 BIT(POWER_DOMAIN_AUX_B) | \
302 BIT(POWER_DOMAIN_AUX_C) | \
303 BIT(POWER_DOMAIN_AUX_D) | \
304 BIT(POWER_DOMAIN_AUDIO) | \
305 BIT(POWER_DOMAIN_VGA) | \
306 BIT(POWER_DOMAIN_INIT))
307#define SKL_DISPLAY_POWERWELL_1_POWER_DOMAINS ( \
308 SKL_DISPLAY_POWERWELL_2_POWER_DOMAINS | \
309 BIT(POWER_DOMAIN_PLLS) | \
310 BIT(POWER_DOMAIN_PIPE_A) | \
311 BIT(POWER_DOMAIN_TRANSCODER_EDP) | \
312 BIT(POWER_DOMAIN_PIPE_A_PANEL_FITTER) | \
313 BIT(POWER_DOMAIN_PORT_DDI_A_2_LANES) | \
314 BIT(POWER_DOMAIN_PORT_DDI_A_4_LANES) | \
315 BIT(POWER_DOMAIN_AUX_A) | \
316 BIT(POWER_DOMAIN_INIT))
317#define SKL_DISPLAY_DDI_A_E_POWER_DOMAINS ( \
318 BIT(POWER_DOMAIN_PORT_DDI_A_2_LANES) | \
319 BIT(POWER_DOMAIN_PORT_DDI_A_4_LANES) | \
Xiong Zhangd8e19f92015-08-13 18:00:12 +0800320 BIT(POWER_DOMAIN_PORT_DDI_E_2_LANES) | \
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000321 BIT(POWER_DOMAIN_INIT))
322#define SKL_DISPLAY_DDI_B_POWER_DOMAINS ( \
323 BIT(POWER_DOMAIN_PORT_DDI_B_2_LANES) | \
324 BIT(POWER_DOMAIN_PORT_DDI_B_4_LANES) | \
325 BIT(POWER_DOMAIN_INIT))
326#define SKL_DISPLAY_DDI_C_POWER_DOMAINS ( \
327 BIT(POWER_DOMAIN_PORT_DDI_C_2_LANES) | \
328 BIT(POWER_DOMAIN_PORT_DDI_C_4_LANES) | \
329 BIT(POWER_DOMAIN_INIT))
330#define SKL_DISPLAY_DDI_D_POWER_DOMAINS ( \
331 BIT(POWER_DOMAIN_PORT_DDI_D_2_LANES) | \
332 BIT(POWER_DOMAIN_PORT_DDI_D_4_LANES) | \
333 BIT(POWER_DOMAIN_INIT))
334#define SKL_DISPLAY_MISC_IO_POWER_DOMAINS ( \
Damien Lespiauaeaa2122015-04-30 16:39:16 +0100335 SKL_DISPLAY_POWERWELL_1_POWER_DOMAINS | \
Damien Lespiau62227092015-04-30 16:39:20 +0100336 BIT(POWER_DOMAIN_PLLS) | \
Damien Lespiauaeaa2122015-04-30 16:39:16 +0100337 BIT(POWER_DOMAIN_INIT))
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000338#define SKL_DISPLAY_ALWAYS_ON_POWER_DOMAINS ( \
339 (POWER_DOMAIN_MASK & ~(SKL_DISPLAY_POWERWELL_1_POWER_DOMAINS | \
340 SKL_DISPLAY_POWERWELL_2_POWER_DOMAINS | \
341 SKL_DISPLAY_DDI_A_E_POWER_DOMAINS | \
342 SKL_DISPLAY_DDI_B_POWER_DOMAINS | \
343 SKL_DISPLAY_DDI_C_POWER_DOMAINS | \
344 SKL_DISPLAY_DDI_D_POWER_DOMAINS | \
345 SKL_DISPLAY_MISC_IO_POWER_DOMAINS)) | \
346 BIT(POWER_DOMAIN_INIT))
347
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +0530348#define BXT_DISPLAY_POWERWELL_2_POWER_DOMAINS ( \
349 BIT(POWER_DOMAIN_TRANSCODER_A) | \
350 BIT(POWER_DOMAIN_PIPE_B) | \
351 BIT(POWER_DOMAIN_TRANSCODER_B) | \
352 BIT(POWER_DOMAIN_PIPE_C) | \
353 BIT(POWER_DOMAIN_TRANSCODER_C) | \
354 BIT(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
355 BIT(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
356 BIT(POWER_DOMAIN_PORT_DDI_B_2_LANES) | \
357 BIT(POWER_DOMAIN_PORT_DDI_B_4_LANES) | \
358 BIT(POWER_DOMAIN_PORT_DDI_C_2_LANES) | \
359 BIT(POWER_DOMAIN_PORT_DDI_C_4_LANES) | \
360 BIT(POWER_DOMAIN_AUX_B) | \
361 BIT(POWER_DOMAIN_AUX_C) | \
362 BIT(POWER_DOMAIN_AUDIO) | \
363 BIT(POWER_DOMAIN_VGA) | \
364 BIT(POWER_DOMAIN_INIT))
365#define BXT_DISPLAY_POWERWELL_1_POWER_DOMAINS ( \
366 BXT_DISPLAY_POWERWELL_2_POWER_DOMAINS | \
367 BIT(POWER_DOMAIN_PIPE_A) | \
368 BIT(POWER_DOMAIN_TRANSCODER_EDP) | \
369 BIT(POWER_DOMAIN_PIPE_A_PANEL_FITTER) | \
370 BIT(POWER_DOMAIN_PORT_DDI_A_2_LANES) | \
371 BIT(POWER_DOMAIN_PORT_DDI_A_4_LANES) | \
372 BIT(POWER_DOMAIN_AUX_A) | \
373 BIT(POWER_DOMAIN_PLLS) | \
374 BIT(POWER_DOMAIN_INIT))
375#define BXT_DISPLAY_ALWAYS_ON_POWER_DOMAINS ( \
376 (POWER_DOMAIN_MASK & ~(BXT_DISPLAY_POWERWELL_1_POWER_DOMAINS | \
377 BXT_DISPLAY_POWERWELL_2_POWER_DOMAINS)) | \
378 BIT(POWER_DOMAIN_INIT))
379
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530380static void assert_can_enable_dc9(struct drm_i915_private *dev_priv)
381{
382 struct drm_device *dev = dev_priv->dev;
383
384 WARN(!IS_BROXTON(dev), "Platform doesn't support DC9.\n");
385 WARN((I915_READ(DC_STATE_EN) & DC_STATE_EN_DC9),
386 "DC9 already programmed to be enabled.\n");
387 WARN(I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC5,
388 "DC5 still not disabled to enable DC9.\n");
389 WARN(I915_READ(HSW_PWR_WELL_DRIVER), "Power well on.\n");
390 WARN(intel_irqs_enabled(dev_priv), "Interrupts not disabled yet.\n");
391
392 /*
393 * TODO: check for the following to verify the conditions to enter DC9
394 * state are satisfied:
395 * 1] Check relevant display engine registers to verify if mode set
396 * disable sequence was followed.
397 * 2] Check if display uninitialize sequence is initialized.
398 */
399}
400
401static void assert_can_disable_dc9(struct drm_i915_private *dev_priv)
402{
403 WARN(intel_irqs_enabled(dev_priv), "Interrupts not disabled yet.\n");
404 WARN(!(I915_READ(DC_STATE_EN) & DC_STATE_EN_DC9),
405 "DC9 already programmed to be disabled.\n");
406 WARN(I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC5,
407 "DC5 still not disabled.\n");
408
409 /*
410 * TODO: check for the following to verify DC9 state was indeed
411 * entered before programming to disable it:
412 * 1] Check relevant display engine registers to verify if mode
413 * set disable sequence was followed.
414 * 2] Check if display uninitialize sequence is initialized.
415 */
416}
417
418void bxt_enable_dc9(struct drm_i915_private *dev_priv)
419{
420 uint32_t val;
421
422 assert_can_enable_dc9(dev_priv);
423
424 DRM_DEBUG_KMS("Enabling DC9\n");
425
426 val = I915_READ(DC_STATE_EN);
427 val |= DC_STATE_EN_DC9;
428 I915_WRITE(DC_STATE_EN, val);
429 POSTING_READ(DC_STATE_EN);
430}
431
432void bxt_disable_dc9(struct drm_i915_private *dev_priv)
433{
434 uint32_t val;
435
436 assert_can_disable_dc9(dev_priv);
437
438 DRM_DEBUG_KMS("Disabling DC9\n");
439
440 val = I915_READ(DC_STATE_EN);
441 val &= ~DC_STATE_EN_DC9;
442 I915_WRITE(DC_STATE_EN, val);
443 POSTING_READ(DC_STATE_EN);
444}
445
A.Sunil Kamath6b457d32015-04-16 14:22:09 +0530446static void gen9_set_dc_state_debugmask_memory_up(
447 struct drm_i915_private *dev_priv)
448{
449 uint32_t val;
450
451 /* The below bit doesn't need to be cleared ever afterwards */
452 val = I915_READ(DC_STATE_DEBUG);
453 if (!(val & DC_STATE_DEBUG_MASK_MEMORY_UP)) {
454 val |= DC_STATE_DEBUG_MASK_MEMORY_UP;
455 I915_WRITE(DC_STATE_DEBUG, val);
456 POSTING_READ(DC_STATE_DEBUG);
457 }
458}
459
Suketu Shah5aefb232015-04-16 14:22:10 +0530460static void assert_can_enable_dc5(struct drm_i915_private *dev_priv)
Suketu Shahdc174302015-04-17 19:46:16 +0530461{
A.Sunil Kamath6b457d32015-04-16 14:22:09 +0530462 struct drm_device *dev = dev_priv->dev;
Suketu Shah5aefb232015-04-16 14:22:10 +0530463 bool pg2_enabled = intel_display_power_well_is_enabled(dev_priv,
464 SKL_DISP_PW_2);
465
Jesse Barnes6ff8ab02015-09-10 08:20:28 -0700466 WARN_ONCE(!IS_SKYLAKE(dev), "Platform doesn't support DC5.\n");
467 WARN_ONCE(!HAS_RUNTIME_PM(dev), "Runtime PM not enabled.\n");
468 WARN_ONCE(pg2_enabled, "PG2 not disabled to enable DC5.\n");
Suketu Shah5aefb232015-04-16 14:22:10 +0530469
Jesse Barnes6ff8ab02015-09-10 08:20:28 -0700470 WARN_ONCE((I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC5),
471 "DC5 already programmed to be enabled.\n");
472 WARN_ONCE(dev_priv->pm.suspended,
473 "DC5 cannot be enabled, if platform is runtime-suspended.\n");
Suketu Shah5aefb232015-04-16 14:22:10 +0530474
475 assert_csr_loaded(dev_priv);
476}
477
478static void assert_can_disable_dc5(struct drm_i915_private *dev_priv)
479{
480 bool pg2_enabled = intel_display_power_well_is_enabled(dev_priv,
481 SKL_DISP_PW_2);
Suketu Shah93c7cb62015-04-16 14:22:13 +0530482 /*
483 * During initialization, the firmware may not be loaded yet.
484 * We still want to make sure that the DC enabling flag is cleared.
485 */
486 if (dev_priv->power_domains.initializing)
487 return;
Suketu Shah5aefb232015-04-16 14:22:10 +0530488
Jesse Barnes6ff8ab02015-09-10 08:20:28 -0700489 WARN_ONCE(!pg2_enabled, "PG2 not enabled to disable DC5.\n");
490 WARN_ONCE(dev_priv->pm.suspended,
Suketu Shah5aefb232015-04-16 14:22:10 +0530491 "Disabling of DC5 while platform is runtime-suspended should never happen.\n");
492}
493
494static void gen9_enable_dc5(struct drm_i915_private *dev_priv)
495{
A.Sunil Kamath6b457d32015-04-16 14:22:09 +0530496 uint32_t val;
497
Suketu Shah5aefb232015-04-16 14:22:10 +0530498 assert_can_enable_dc5(dev_priv);
A.Sunil Kamath6b457d32015-04-16 14:22:09 +0530499
500 DRM_DEBUG_KMS("Enabling DC5\n");
501
502 gen9_set_dc_state_debugmask_memory_up(dev_priv);
503
504 val = I915_READ(DC_STATE_EN);
505 val &= ~DC_STATE_EN_UPTO_DC5_DC6_MASK;
506 val |= DC_STATE_EN_UPTO_DC5;
507 I915_WRITE(DC_STATE_EN, val);
508 POSTING_READ(DC_STATE_EN);
Suketu Shahdc174302015-04-17 19:46:16 +0530509}
510
511static void gen9_disable_dc5(struct drm_i915_private *dev_priv)
512{
A.Sunil Kamath6b457d32015-04-16 14:22:09 +0530513 uint32_t val;
514
Suketu Shah5aefb232015-04-16 14:22:10 +0530515 assert_can_disable_dc5(dev_priv);
A.Sunil Kamath6b457d32015-04-16 14:22:09 +0530516
517 DRM_DEBUG_KMS("Disabling DC5\n");
518
519 val = I915_READ(DC_STATE_EN);
520 val &= ~DC_STATE_EN_UPTO_DC5;
521 I915_WRITE(DC_STATE_EN, val);
522 POSTING_READ(DC_STATE_EN);
Suketu Shahdc174302015-04-17 19:46:16 +0530523}
524
Suketu Shah93c7cb62015-04-16 14:22:13 +0530525static void assert_can_enable_dc6(struct drm_i915_private *dev_priv)
Suketu Shahf75a1982015-04-16 14:22:11 +0530526{
A.Sunil Kamath74b4f372015-04-16 14:22:12 +0530527 struct drm_device *dev = dev_priv->dev;
Suketu Shah93c7cb62015-04-16 14:22:13 +0530528
Jesse Barnes6ff8ab02015-09-10 08:20:28 -0700529 WARN_ONCE(!IS_SKYLAKE(dev), "Platform doesn't support DC6.\n");
530 WARN_ONCE(!HAS_RUNTIME_PM(dev), "Runtime PM not enabled.\n");
531 WARN_ONCE(I915_READ(UTIL_PIN_CTL) & UTIL_PIN_ENABLE,
532 "Backlight is not disabled.\n");
533 WARN_ONCE((I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC6),
534 "DC6 already programmed to be enabled.\n");
Suketu Shah93c7cb62015-04-16 14:22:13 +0530535
536 assert_csr_loaded(dev_priv);
537}
538
539static void assert_can_disable_dc6(struct drm_i915_private *dev_priv)
540{
541 /*
542 * During initialization, the firmware may not be loaded yet.
543 * We still want to make sure that the DC enabling flag is cleared.
544 */
545 if (dev_priv->power_domains.initializing)
546 return;
547
548 assert_csr_loaded(dev_priv);
Jesse Barnes6ff8ab02015-09-10 08:20:28 -0700549 WARN_ONCE(!(I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC6),
550 "DC6 already programmed to be disabled.\n");
Suketu Shah93c7cb62015-04-16 14:22:13 +0530551}
552
Animesh Manna0a9d2be2015-09-29 11:01:59 +0530553void skl_enable_dc6(struct drm_i915_private *dev_priv)
Suketu Shah93c7cb62015-04-16 14:22:13 +0530554{
A.Sunil Kamath74b4f372015-04-16 14:22:12 +0530555 uint32_t val;
556
Suketu Shah93c7cb62015-04-16 14:22:13 +0530557 assert_can_enable_dc6(dev_priv);
A.Sunil Kamath74b4f372015-04-16 14:22:12 +0530558
559 DRM_DEBUG_KMS("Enabling DC6\n");
560
561 gen9_set_dc_state_debugmask_memory_up(dev_priv);
562
563 val = I915_READ(DC_STATE_EN);
564 val &= ~DC_STATE_EN_UPTO_DC5_DC6_MASK;
565 val |= DC_STATE_EN_UPTO_DC6;
566 I915_WRITE(DC_STATE_EN, val);
567 POSTING_READ(DC_STATE_EN);
Suketu Shahf75a1982015-04-16 14:22:11 +0530568}
569
Animesh Manna0a9d2be2015-09-29 11:01:59 +0530570void skl_disable_dc6(struct drm_i915_private *dev_priv)
Suketu Shahf75a1982015-04-16 14:22:11 +0530571{
A.Sunil Kamath74b4f372015-04-16 14:22:12 +0530572 uint32_t val;
573
Suketu Shah93c7cb62015-04-16 14:22:13 +0530574 assert_can_disable_dc6(dev_priv);
A.Sunil Kamath74b4f372015-04-16 14:22:12 +0530575
576 DRM_DEBUG_KMS("Disabling DC6\n");
577
578 val = I915_READ(DC_STATE_EN);
579 val &= ~DC_STATE_EN_UPTO_DC6;
580 I915_WRITE(DC_STATE_EN, val);
581 POSTING_READ(DC_STATE_EN);
Suketu Shahf75a1982015-04-16 14:22:11 +0530582}
583
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000584static void skl_set_power_well(struct drm_i915_private *dev_priv,
585 struct i915_power_well *power_well, bool enable)
586{
Suketu Shahdc174302015-04-17 19:46:16 +0530587 struct drm_device *dev = dev_priv->dev;
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000588 uint32_t tmp, fuse_status;
589 uint32_t req_mask, state_mask;
Damien Lespiau2a518352015-03-06 18:50:49 +0000590 bool is_enabled, enable_requested, check_fuse_status = false;
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000591
592 tmp = I915_READ(HSW_PWR_WELL_DRIVER);
593 fuse_status = I915_READ(SKL_FUSE_STATUS);
594
595 switch (power_well->data) {
596 case SKL_DISP_PW_1:
597 if (wait_for((I915_READ(SKL_FUSE_STATUS) &
598 SKL_FUSE_PG0_DIST_STATUS), 1)) {
599 DRM_ERROR("PG0 not enabled\n");
600 return;
601 }
602 break;
603 case SKL_DISP_PW_2:
604 if (!(fuse_status & SKL_FUSE_PG1_DIST_STATUS)) {
605 DRM_ERROR("PG1 in disabled state\n");
606 return;
607 }
608 break;
609 case SKL_DISP_PW_DDI_A_E:
610 case SKL_DISP_PW_DDI_B:
611 case SKL_DISP_PW_DDI_C:
612 case SKL_DISP_PW_DDI_D:
613 case SKL_DISP_PW_MISC_IO:
614 break;
615 default:
616 WARN(1, "Unknown power well %lu\n", power_well->data);
617 return;
618 }
619
620 req_mask = SKL_POWER_WELL_REQ(power_well->data);
Damien Lespiau2a518352015-03-06 18:50:49 +0000621 enable_requested = tmp & req_mask;
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000622 state_mask = SKL_POWER_WELL_STATE(power_well->data);
Damien Lespiau2a518352015-03-06 18:50:49 +0000623 is_enabled = tmp & state_mask;
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000624
625 if (enable) {
Damien Lespiau2a518352015-03-06 18:50:49 +0000626 if (!enable_requested) {
Suketu Shahdc174302015-04-17 19:46:16 +0530627 WARN((tmp & state_mask) &&
628 !I915_READ(HSW_PWR_WELL_BIOS),
629 "Invalid for power well status to be enabled, unless done by the BIOS, \
630 when request is to disable!\n");
Animesh Manna0a9d2be2015-09-29 11:01:59 +0530631 if (power_well->data == SKL_DISP_PW_2) {
632 if (GEN9_ENABLE_DC5(dev))
633 gen9_disable_dc5(dev_priv);
Suketu Shahf75a1982015-04-16 14:22:11 +0530634 if (SKL_ENABLE_DC6(dev)) {
Suketu Shahf75a1982015-04-16 14:22:11 +0530635 /*
636 * DDI buffer programming unnecessary during driver-load/resume
637 * as it's already done during modeset initialization then.
638 * It's also invalid here as encoder list is still uninitialized.
639 */
640 if (!dev_priv->power_domains.initializing)
641 intel_prepare_ddi(dev);
Suketu Shahf75a1982015-04-16 14:22:11 +0530642 }
643 }
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000644 I915_WRITE(HSW_PWR_WELL_DRIVER, tmp | req_mask);
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000645 }
646
Damien Lespiau2a518352015-03-06 18:50:49 +0000647 if (!is_enabled) {
Damien Lespiau510e6fd2015-03-06 18:50:50 +0000648 DRM_DEBUG_KMS("Enabling %s\n", power_well->name);
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000649 if (wait_for((I915_READ(HSW_PWR_WELL_DRIVER) &
650 state_mask), 1))
651 DRM_ERROR("%s enable timeout\n",
652 power_well->name);
653 check_fuse_status = true;
654 }
655 } else {
Damien Lespiau2a518352015-03-06 18:50:49 +0000656 if (enable_requested) {
Animesh Manna08aef7c2015-08-26 01:36:09 +0530657 if (IS_SKYLAKE(dev) &&
658 (power_well->data == SKL_DISP_PW_1) &&
659 (intel_csr_load_status_get(dev_priv) == FW_LOADED))
660 DRM_DEBUG_KMS("Not Disabling PW1, dmc will handle\n");
661 else {
662 I915_WRITE(HSW_PWR_WELL_DRIVER, tmp & ~req_mask);
663 POSTING_READ(HSW_PWR_WELL_DRIVER);
664 DRM_DEBUG_KMS("Disabling %s\n", power_well->name);
665 }
Suketu Shahdc174302015-04-17 19:46:16 +0530666
Animesh Manna0a9d2be2015-09-29 11:01:59 +0530667 if (GEN9_ENABLE_DC5(dev) &&
Suketu Shahdc174302015-04-17 19:46:16 +0530668 power_well->data == SKL_DISP_PW_2) {
669 enum csr_state state;
Suketu Shahf75a1982015-04-16 14:22:11 +0530670 /* TODO: wait for a completion event or
671 * similar here instead of busy
672 * waiting using wait_for function.
673 */
Suketu Shahdc174302015-04-17 19:46:16 +0530674 wait_for((state = intel_csr_load_status_get(dev_priv)) !=
675 FW_UNINITIALIZED, 1000);
676 if (state != FW_LOADED)
Jesse Barnes6ff8ab02015-09-10 08:20:28 -0700677 DRM_DEBUG("CSR firmware not ready (%d)\n",
Suketu Shahdc174302015-04-17 19:46:16 +0530678 state);
679 else
Animesh Manna0a9d2be2015-09-29 11:01:59 +0530680 gen9_enable_dc5(dev_priv);
Suketu Shahdc174302015-04-17 19:46:16 +0530681 }
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000682 }
683 }
684
685 if (check_fuse_status) {
686 if (power_well->data == SKL_DISP_PW_1) {
687 if (wait_for((I915_READ(SKL_FUSE_STATUS) &
688 SKL_FUSE_PG1_DIST_STATUS), 1))
689 DRM_ERROR("PG1 distributing status timeout\n");
690 } else if (power_well->data == SKL_DISP_PW_2) {
691 if (wait_for((I915_READ(SKL_FUSE_STATUS) &
692 SKL_FUSE_PG2_DIST_STATUS), 1))
693 DRM_ERROR("PG2 distributing status timeout\n");
694 }
695 }
Damien Lespiaud14c0342015-03-06 18:50:51 +0000696
697 if (enable && !is_enabled)
698 skl_power_well_post_enable(dev_priv, power_well);
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000699}
700
Daniel Vetter9c065a72014-09-30 10:56:38 +0200701static void hsw_power_well_sync_hw(struct drm_i915_private *dev_priv,
702 struct i915_power_well *power_well)
703{
704 hsw_set_power_well(dev_priv, power_well, power_well->count > 0);
705
706 /*
707 * We're taking over the BIOS, so clear any requests made by it since
708 * the driver is in charge now.
709 */
710 if (I915_READ(HSW_PWR_WELL_BIOS) & HSW_PWR_WELL_ENABLE_REQUEST)
711 I915_WRITE(HSW_PWR_WELL_BIOS, 0);
712}
713
714static void hsw_power_well_enable(struct drm_i915_private *dev_priv,
715 struct i915_power_well *power_well)
716{
717 hsw_set_power_well(dev_priv, power_well, true);
718}
719
720static void hsw_power_well_disable(struct drm_i915_private *dev_priv,
721 struct i915_power_well *power_well)
722{
723 hsw_set_power_well(dev_priv, power_well, false);
724}
725
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000726static bool skl_power_well_enabled(struct drm_i915_private *dev_priv,
727 struct i915_power_well *power_well)
728{
729 uint32_t mask = SKL_POWER_WELL_REQ(power_well->data) |
730 SKL_POWER_WELL_STATE(power_well->data);
731
732 return (I915_READ(HSW_PWR_WELL_DRIVER) & mask) == mask;
733}
734
735static void skl_power_well_sync_hw(struct drm_i915_private *dev_priv,
736 struct i915_power_well *power_well)
737{
738 skl_set_power_well(dev_priv, power_well, power_well->count > 0);
739
740 /* Clear any request made by BIOS as driver is taking over */
741 I915_WRITE(HSW_PWR_WELL_BIOS, 0);
742}
743
744static void skl_power_well_enable(struct drm_i915_private *dev_priv,
745 struct i915_power_well *power_well)
746{
747 skl_set_power_well(dev_priv, power_well, true);
748}
749
750static void skl_power_well_disable(struct drm_i915_private *dev_priv,
751 struct i915_power_well *power_well)
752{
753 skl_set_power_well(dev_priv, power_well, false);
754}
755
Daniel Vetter9c065a72014-09-30 10:56:38 +0200756static void i9xx_always_on_power_well_noop(struct drm_i915_private *dev_priv,
757 struct i915_power_well *power_well)
758{
759}
760
761static bool i9xx_always_on_power_well_enabled(struct drm_i915_private *dev_priv,
762 struct i915_power_well *power_well)
763{
764 return true;
765}
766
767static void vlv_set_power_well(struct drm_i915_private *dev_priv,
768 struct i915_power_well *power_well, bool enable)
769{
770 enum punit_power_well power_well_id = power_well->data;
771 u32 mask;
772 u32 state;
773 u32 ctrl;
774
775 mask = PUNIT_PWRGT_MASK(power_well_id);
776 state = enable ? PUNIT_PWRGT_PWR_ON(power_well_id) :
777 PUNIT_PWRGT_PWR_GATE(power_well_id);
778
779 mutex_lock(&dev_priv->rps.hw_lock);
780
781#define COND \
782 ((vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_STATUS) & mask) == state)
783
784 if (COND)
785 goto out;
786
787 ctrl = vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_CTRL);
788 ctrl &= ~mask;
789 ctrl |= state;
790 vlv_punit_write(dev_priv, PUNIT_REG_PWRGT_CTRL, ctrl);
791
792 if (wait_for(COND, 100))
Masanari Iida7e35ab82015-05-10 01:00:23 +0900793 DRM_ERROR("timeout setting power well state %08x (%08x)\n",
Daniel Vetter9c065a72014-09-30 10:56:38 +0200794 state,
795 vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_CTRL));
796
797#undef COND
798
799out:
800 mutex_unlock(&dev_priv->rps.hw_lock);
801}
802
803static void vlv_power_well_sync_hw(struct drm_i915_private *dev_priv,
804 struct i915_power_well *power_well)
805{
806 vlv_set_power_well(dev_priv, power_well, power_well->count > 0);
807}
808
809static void vlv_power_well_enable(struct drm_i915_private *dev_priv,
810 struct i915_power_well *power_well)
811{
812 vlv_set_power_well(dev_priv, power_well, true);
813}
814
815static void vlv_power_well_disable(struct drm_i915_private *dev_priv,
816 struct i915_power_well *power_well)
817{
818 vlv_set_power_well(dev_priv, power_well, false);
819}
820
821static bool vlv_power_well_enabled(struct drm_i915_private *dev_priv,
822 struct i915_power_well *power_well)
823{
824 int power_well_id = power_well->data;
825 bool enabled = false;
826 u32 mask;
827 u32 state;
828 u32 ctrl;
829
830 mask = PUNIT_PWRGT_MASK(power_well_id);
831 ctrl = PUNIT_PWRGT_PWR_ON(power_well_id);
832
833 mutex_lock(&dev_priv->rps.hw_lock);
834
835 state = vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_STATUS) & mask;
836 /*
837 * We only ever set the power-on and power-gate states, anything
838 * else is unexpected.
839 */
840 WARN_ON(state != PUNIT_PWRGT_PWR_ON(power_well_id) &&
841 state != PUNIT_PWRGT_PWR_GATE(power_well_id));
842 if (state == ctrl)
843 enabled = true;
844
845 /*
846 * A transient state at this point would mean some unexpected party
847 * is poking at the power controls too.
848 */
849 ctrl = vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_CTRL) & mask;
850 WARN_ON(ctrl != state);
851
852 mutex_unlock(&dev_priv->rps.hw_lock);
853
854 return enabled;
855}
856
Ville Syrjälä2be7d542015-06-29 15:25:51 +0300857static void vlv_display_power_well_init(struct drm_i915_private *dev_priv)
Daniel Vetter9c065a72014-09-30 10:56:38 +0200858{
Ville Syrjälä5a8fbb72015-06-29 15:25:53 +0300859 enum pipe pipe;
860
861 /*
862 * Enable the CRI clock source so we can get at the
863 * display and the reference clock for VGA
864 * hotplug / manual detection. Supposedly DSI also
865 * needs the ref clock up and running.
866 *
867 * CHV DPLL B/C have some issues if VGA mode is enabled.
868 */
869 for_each_pipe(dev_priv->dev, pipe) {
870 u32 val = I915_READ(DPLL(pipe));
871
872 val |= DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
873 if (pipe != PIPE_A)
874 val |= DPLL_INTEGRATED_CRI_CLK_VLV;
875
876 I915_WRITE(DPLL(pipe), val);
877 }
Daniel Vetter9c065a72014-09-30 10:56:38 +0200878
879 spin_lock_irq(&dev_priv->irq_lock);
880 valleyview_enable_display_irqs(dev_priv);
881 spin_unlock_irq(&dev_priv->irq_lock);
882
883 /*
884 * During driver initialization/resume we can avoid restoring the
885 * part of the HW/SW state that will be inited anyway explicitly.
886 */
887 if (dev_priv->power_domains.initializing)
888 return;
889
Daniel Vetterb9632912014-09-30 10:56:44 +0200890 intel_hpd_init(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200891
892 i915_redisable_vga_power_on(dev_priv->dev);
893}
894
Ville Syrjälä2be7d542015-06-29 15:25:51 +0300895static void vlv_display_power_well_deinit(struct drm_i915_private *dev_priv)
896{
897 spin_lock_irq(&dev_priv->irq_lock);
898 valleyview_disable_display_irqs(dev_priv);
899 spin_unlock_irq(&dev_priv->irq_lock);
900
901 vlv_power_sequencer_reset(dev_priv);
902}
903
904static void vlv_display_power_well_enable(struct drm_i915_private *dev_priv,
905 struct i915_power_well *power_well)
906{
907 WARN_ON_ONCE(power_well->data != PUNIT_POWER_WELL_DISP2D);
908
909 vlv_set_power_well(dev_priv, power_well, true);
910
911 vlv_display_power_well_init(dev_priv);
912}
913
Daniel Vetter9c065a72014-09-30 10:56:38 +0200914static void vlv_display_power_well_disable(struct drm_i915_private *dev_priv,
915 struct i915_power_well *power_well)
916{
917 WARN_ON_ONCE(power_well->data != PUNIT_POWER_WELL_DISP2D);
918
Ville Syrjälä2be7d542015-06-29 15:25:51 +0300919 vlv_display_power_well_deinit(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200920
921 vlv_set_power_well(dev_priv, power_well, false);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200922}
923
924static void vlv_dpio_cmn_power_well_enable(struct drm_i915_private *dev_priv,
925 struct i915_power_well *power_well)
926{
927 WARN_ON_ONCE(power_well->data != PUNIT_POWER_WELL_DPIO_CMN_BC);
928
Ville Syrjälä5a8fbb72015-06-29 15:25:53 +0300929 /* since ref/cri clock was enabled */
Daniel Vetter9c065a72014-09-30 10:56:38 +0200930 udelay(1); /* >10ns for cmnreset, >0ns for sidereset */
931
932 vlv_set_power_well(dev_priv, power_well, true);
933
934 /*
935 * From VLV2A0_DP_eDP_DPIO_driver_vbios_notes_10.docx -
936 * 6. De-assert cmn_reset/side_reset. Same as VLV X0.
937 * a. GUnit 0x2110 bit[0] set to 1 (def 0)
938 * b. The other bits such as sfr settings / modesel may all
939 * be set to 0.
940 *
941 * This should only be done on init and resume from S3 with
942 * both PLLs disabled, or we risk losing DPIO and PLL
943 * synchronization.
944 */
945 I915_WRITE(DPIO_CTL, I915_READ(DPIO_CTL) | DPIO_CMNRST);
946}
947
948static void vlv_dpio_cmn_power_well_disable(struct drm_i915_private *dev_priv,
949 struct i915_power_well *power_well)
950{
951 enum pipe pipe;
952
953 WARN_ON_ONCE(power_well->data != PUNIT_POWER_WELL_DPIO_CMN_BC);
954
955 for_each_pipe(dev_priv, pipe)
956 assert_pll_disabled(dev_priv, pipe);
957
958 /* Assert common reset */
959 I915_WRITE(DPIO_CTL, I915_READ(DPIO_CTL) & ~DPIO_CMNRST);
960
961 vlv_set_power_well(dev_priv, power_well, false);
962}
963
Ville Syrjälä30142272015-07-08 23:46:01 +0300964#define POWER_DOMAIN_MASK (BIT(POWER_DOMAIN_NUM) - 1)
965
966static struct i915_power_well *lookup_power_well(struct drm_i915_private *dev_priv,
967 int power_well_id)
968{
969 struct i915_power_domains *power_domains = &dev_priv->power_domains;
970 struct i915_power_well *power_well;
971 int i;
972
973 for_each_power_well(i, power_well, POWER_DOMAIN_MASK, power_domains) {
974 if (power_well->data == power_well_id)
975 return power_well;
976 }
977
978 return NULL;
979}
980
981#define BITS_SET(val, bits) (((val) & (bits)) == (bits))
982
983static void assert_chv_phy_status(struct drm_i915_private *dev_priv)
984{
985 struct i915_power_well *cmn_bc =
986 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_BC);
987 struct i915_power_well *cmn_d =
988 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_D);
989 u32 phy_control = dev_priv->chv_phy_control;
990 u32 phy_status = 0;
Ville Syrjälä3be60de2015-09-08 18:05:45 +0300991 u32 phy_status_mask = 0xffffffff;
Ville Syrjälä30142272015-07-08 23:46:01 +0300992 u32 tmp;
993
Ville Syrjälä3be60de2015-09-08 18:05:45 +0300994 /*
995 * The BIOS can leave the PHY is some weird state
996 * where it doesn't fully power down some parts.
997 * Disable the asserts until the PHY has been fully
998 * reset (ie. the power well has been disabled at
999 * least once).
1000 */
1001 if (!dev_priv->chv_phy_assert[DPIO_PHY0])
1002 phy_status_mask &= ~(PHY_STATUS_CMN_LDO(DPIO_PHY0, DPIO_CH0) |
1003 PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH0, 0) |
1004 PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH0, 1) |
1005 PHY_STATUS_CMN_LDO(DPIO_PHY0, DPIO_CH1) |
1006 PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH1, 0) |
1007 PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH1, 1));
1008
1009 if (!dev_priv->chv_phy_assert[DPIO_PHY1])
1010 phy_status_mask &= ~(PHY_STATUS_CMN_LDO(DPIO_PHY1, DPIO_CH0) |
1011 PHY_STATUS_SPLINE_LDO(DPIO_PHY1, DPIO_CH0, 0) |
1012 PHY_STATUS_SPLINE_LDO(DPIO_PHY1, DPIO_CH0, 1));
1013
Ville Syrjälä30142272015-07-08 23:46:01 +03001014 if (cmn_bc->ops->is_enabled(dev_priv, cmn_bc)) {
1015 phy_status |= PHY_POWERGOOD(DPIO_PHY0);
1016
1017 /* this assumes override is only used to enable lanes */
1018 if ((phy_control & PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY0, DPIO_CH0)) == 0)
1019 phy_control |= PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH0);
1020
1021 if ((phy_control & PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY0, DPIO_CH1)) == 0)
1022 phy_control |= PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH1);
1023
1024 /* CL1 is on whenever anything is on in either channel */
1025 if (BITS_SET(phy_control,
1026 PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH0) |
1027 PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH1)))
1028 phy_status |= PHY_STATUS_CMN_LDO(DPIO_PHY0, DPIO_CH0);
1029
1030 /*
1031 * The DPLLB check accounts for the pipe B + port A usage
1032 * with CL2 powered up but all the lanes in the second channel
1033 * powered down.
1034 */
1035 if (BITS_SET(phy_control,
1036 PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH1)) &&
1037 (I915_READ(DPLL(PIPE_B)) & DPLL_VCO_ENABLE) == 0)
1038 phy_status |= PHY_STATUS_CMN_LDO(DPIO_PHY0, DPIO_CH1);
1039
1040 if (BITS_SET(phy_control,
1041 PHY_CH_POWER_DOWN_OVRD(0x3, DPIO_PHY0, DPIO_CH0)))
1042 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH0, 0);
1043 if (BITS_SET(phy_control,
1044 PHY_CH_POWER_DOWN_OVRD(0xc, DPIO_PHY0, DPIO_CH0)))
1045 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH0, 1);
1046
1047 if (BITS_SET(phy_control,
1048 PHY_CH_POWER_DOWN_OVRD(0x3, DPIO_PHY0, DPIO_CH1)))
1049 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH1, 0);
1050 if (BITS_SET(phy_control,
1051 PHY_CH_POWER_DOWN_OVRD(0xc, DPIO_PHY0, DPIO_CH1)))
1052 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH1, 1);
1053 }
1054
1055 if (cmn_d->ops->is_enabled(dev_priv, cmn_d)) {
1056 phy_status |= PHY_POWERGOOD(DPIO_PHY1);
1057
1058 /* this assumes override is only used to enable lanes */
1059 if ((phy_control & PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY1, DPIO_CH0)) == 0)
1060 phy_control |= PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY1, DPIO_CH0);
1061
1062 if (BITS_SET(phy_control,
1063 PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY1, DPIO_CH0)))
1064 phy_status |= PHY_STATUS_CMN_LDO(DPIO_PHY1, DPIO_CH0);
1065
1066 if (BITS_SET(phy_control,
1067 PHY_CH_POWER_DOWN_OVRD(0x3, DPIO_PHY1, DPIO_CH0)))
1068 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY1, DPIO_CH0, 0);
1069 if (BITS_SET(phy_control,
1070 PHY_CH_POWER_DOWN_OVRD(0xc, DPIO_PHY1, DPIO_CH0)))
1071 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY1, DPIO_CH0, 1);
1072 }
1073
Ville Syrjälä3be60de2015-09-08 18:05:45 +03001074 phy_status &= phy_status_mask;
1075
Ville Syrjälä30142272015-07-08 23:46:01 +03001076 /*
1077 * The PHY may be busy with some initial calibration and whatnot,
1078 * so the power state can take a while to actually change.
1079 */
Ville Syrjälä3be60de2015-09-08 18:05:45 +03001080 if (wait_for((tmp = I915_READ(DISPLAY_PHY_STATUS) & phy_status_mask) == phy_status, 10))
Ville Syrjälä30142272015-07-08 23:46:01 +03001081 WARN(phy_status != tmp,
1082 "Unexpected PHY_STATUS 0x%08x, expected 0x%08x (PHY_CONTROL=0x%08x)\n",
1083 tmp, phy_status, dev_priv->chv_phy_control);
1084}
1085
1086#undef BITS_SET
1087
Daniel Vetter9c065a72014-09-30 10:56:38 +02001088static void chv_dpio_cmn_power_well_enable(struct drm_i915_private *dev_priv,
1089 struct i915_power_well *power_well)
1090{
1091 enum dpio_phy phy;
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001092 enum pipe pipe;
1093 uint32_t tmp;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001094
1095 WARN_ON_ONCE(power_well->data != PUNIT_POWER_WELL_DPIO_CMN_BC &&
1096 power_well->data != PUNIT_POWER_WELL_DPIO_CMN_D);
1097
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001098 if (power_well->data == PUNIT_POWER_WELL_DPIO_CMN_BC) {
1099 pipe = PIPE_A;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001100 phy = DPIO_PHY0;
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001101 } else {
1102 pipe = PIPE_C;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001103 phy = DPIO_PHY1;
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001104 }
Ville Syrjälä5a8fbb72015-06-29 15:25:53 +03001105
1106 /* since ref/cri clock was enabled */
Daniel Vetter9c065a72014-09-30 10:56:38 +02001107 udelay(1); /* >10ns for cmnreset, >0ns for sidereset */
1108 vlv_set_power_well(dev_priv, power_well, true);
1109
1110 /* Poll for phypwrgood signal */
1111 if (wait_for(I915_READ(DISPLAY_PHY_STATUS) & PHY_POWERGOOD(phy), 1))
1112 DRM_ERROR("Display PHY %d is not power up\n", phy);
1113
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001114 mutex_lock(&dev_priv->sb_lock);
1115
1116 /* Enable dynamic power down */
1117 tmp = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW28);
Ville Syrjäläee279212015-07-08 23:45:57 +03001118 tmp |= DPIO_DYNPWRDOWNEN_CH0 | DPIO_CL1POWERDOWNEN |
1119 DPIO_SUS_CLK_CONFIG_GATE_CLKREQ;
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001120 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW28, tmp);
1121
1122 if (power_well->data == PUNIT_POWER_WELL_DPIO_CMN_BC) {
1123 tmp = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW6_CH1);
1124 tmp |= DPIO_DYNPWRDOWNEN_CH1;
1125 vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW6_CH1, tmp);
Ville Syrjälä3e288782015-07-08 23:45:58 +03001126 } else {
1127 /*
1128 * Force the non-existing CL2 off. BXT does this
1129 * too, so maybe it saves some power even though
1130 * CL2 doesn't exist?
1131 */
1132 tmp = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW30);
1133 tmp |= DPIO_CL2_LDOFUSE_PWRENB;
1134 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW30, tmp);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001135 }
1136
1137 mutex_unlock(&dev_priv->sb_lock);
1138
Ville Syrjälä70722462015-04-10 18:21:28 +03001139 dev_priv->chv_phy_control |= PHY_COM_LANE_RESET_DEASSERT(phy);
1140 I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001141
1142 DRM_DEBUG_KMS("Enabled DPIO PHY%d (PHY_CONTROL=0x%08x)\n",
1143 phy, dev_priv->chv_phy_control);
Ville Syrjälä30142272015-07-08 23:46:01 +03001144
1145 assert_chv_phy_status(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001146}
1147
1148static void chv_dpio_cmn_power_well_disable(struct drm_i915_private *dev_priv,
1149 struct i915_power_well *power_well)
1150{
1151 enum dpio_phy phy;
1152
1153 WARN_ON_ONCE(power_well->data != PUNIT_POWER_WELL_DPIO_CMN_BC &&
1154 power_well->data != PUNIT_POWER_WELL_DPIO_CMN_D);
1155
1156 if (power_well->data == PUNIT_POWER_WELL_DPIO_CMN_BC) {
1157 phy = DPIO_PHY0;
1158 assert_pll_disabled(dev_priv, PIPE_A);
1159 assert_pll_disabled(dev_priv, PIPE_B);
1160 } else {
1161 phy = DPIO_PHY1;
1162 assert_pll_disabled(dev_priv, PIPE_C);
1163 }
1164
Ville Syrjälä70722462015-04-10 18:21:28 +03001165 dev_priv->chv_phy_control &= ~PHY_COM_LANE_RESET_DEASSERT(phy);
1166 I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001167
1168 vlv_set_power_well(dev_priv, power_well, false);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001169
1170 DRM_DEBUG_KMS("Disabled DPIO PHY%d (PHY_CONTROL=0x%08x)\n",
1171 phy, dev_priv->chv_phy_control);
Ville Syrjälä30142272015-07-08 23:46:01 +03001172
Ville Syrjälä3be60de2015-09-08 18:05:45 +03001173 /* PHY is fully reset now, so we can enable the PHY state asserts */
1174 dev_priv->chv_phy_assert[phy] = true;
1175
Ville Syrjälä30142272015-07-08 23:46:01 +03001176 assert_chv_phy_status(dev_priv);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001177}
1178
Ville Syrjälä6669e392015-07-08 23:46:00 +03001179static void assert_chv_phy_powergate(struct drm_i915_private *dev_priv, enum dpio_phy phy,
1180 enum dpio_channel ch, bool override, unsigned int mask)
1181{
1182 enum pipe pipe = phy == DPIO_PHY0 ? PIPE_A : PIPE_C;
1183 u32 reg, val, expected, actual;
1184
Ville Syrjälä3be60de2015-09-08 18:05:45 +03001185 /*
1186 * The BIOS can leave the PHY is some weird state
1187 * where it doesn't fully power down some parts.
1188 * Disable the asserts until the PHY has been fully
1189 * reset (ie. the power well has been disabled at
1190 * least once).
1191 */
1192 if (!dev_priv->chv_phy_assert[phy])
1193 return;
1194
Ville Syrjälä6669e392015-07-08 23:46:00 +03001195 if (ch == DPIO_CH0)
1196 reg = _CHV_CMN_DW0_CH0;
1197 else
1198 reg = _CHV_CMN_DW6_CH1;
1199
1200 mutex_lock(&dev_priv->sb_lock);
1201 val = vlv_dpio_read(dev_priv, pipe, reg);
1202 mutex_unlock(&dev_priv->sb_lock);
1203
1204 /*
1205 * This assumes !override is only used when the port is disabled.
1206 * All lanes should power down even without the override when
1207 * the port is disabled.
1208 */
1209 if (!override || mask == 0xf) {
1210 expected = DPIO_ALLDL_POWERDOWN | DPIO_ANYDL_POWERDOWN;
1211 /*
1212 * If CH1 common lane is not active anymore
1213 * (eg. for pipe B DPLL) the entire channel will
1214 * shut down, which causes the common lane registers
1215 * to read as 0. That means we can't actually check
1216 * the lane power down status bits, but as the entire
1217 * register reads as 0 it's a good indication that the
1218 * channel is indeed entirely powered down.
1219 */
1220 if (ch == DPIO_CH1 && val == 0)
1221 expected = 0;
1222 } else if (mask != 0x0) {
1223 expected = DPIO_ANYDL_POWERDOWN;
1224 } else {
1225 expected = 0;
1226 }
1227
1228 if (ch == DPIO_CH0)
1229 actual = val >> DPIO_ANYDL_POWERDOWN_SHIFT_CH0;
1230 else
1231 actual = val >> DPIO_ANYDL_POWERDOWN_SHIFT_CH1;
1232 actual &= DPIO_ALLDL_POWERDOWN | DPIO_ANYDL_POWERDOWN;
1233
1234 WARN(actual != expected,
1235 "Unexpected DPIO lane power down: all %d, any %d. Expected: all %d, any %d. (0x%x = 0x%08x)\n",
1236 !!(actual & DPIO_ALLDL_POWERDOWN), !!(actual & DPIO_ANYDL_POWERDOWN),
1237 !!(expected & DPIO_ALLDL_POWERDOWN), !!(expected & DPIO_ANYDL_POWERDOWN),
1238 reg, val);
1239}
1240
Ville Syrjäläb0b33842015-07-08 23:45:55 +03001241bool chv_phy_powergate_ch(struct drm_i915_private *dev_priv, enum dpio_phy phy,
1242 enum dpio_channel ch, bool override)
1243{
1244 struct i915_power_domains *power_domains = &dev_priv->power_domains;
1245 bool was_override;
1246
1247 mutex_lock(&power_domains->lock);
1248
1249 was_override = dev_priv->chv_phy_control & PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
1250
1251 if (override == was_override)
1252 goto out;
1253
1254 if (override)
1255 dev_priv->chv_phy_control |= PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
1256 else
1257 dev_priv->chv_phy_control &= ~PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
1258
1259 I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
1260
1261 DRM_DEBUG_KMS("Power gating DPIO PHY%d CH%d (DPIO_PHY_CONTROL=0x%08x)\n",
1262 phy, ch, dev_priv->chv_phy_control);
1263
Ville Syrjälä30142272015-07-08 23:46:01 +03001264 assert_chv_phy_status(dev_priv);
1265
Ville Syrjäläb0b33842015-07-08 23:45:55 +03001266out:
1267 mutex_unlock(&power_domains->lock);
1268
1269 return was_override;
1270}
1271
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001272void chv_phy_powergate_lanes(struct intel_encoder *encoder,
1273 bool override, unsigned int mask)
1274{
1275 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
1276 struct i915_power_domains *power_domains = &dev_priv->power_domains;
1277 enum dpio_phy phy = vlv_dport_to_phy(enc_to_dig_port(&encoder->base));
1278 enum dpio_channel ch = vlv_dport_to_channel(enc_to_dig_port(&encoder->base));
1279
1280 mutex_lock(&power_domains->lock);
1281
1282 dev_priv->chv_phy_control &= ~PHY_CH_POWER_DOWN_OVRD(0xf, phy, ch);
1283 dev_priv->chv_phy_control |= PHY_CH_POWER_DOWN_OVRD(mask, phy, ch);
1284
1285 if (override)
1286 dev_priv->chv_phy_control |= PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
1287 else
1288 dev_priv->chv_phy_control &= ~PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
1289
1290 I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
1291
1292 DRM_DEBUG_KMS("Power gating DPIO PHY%d CH%d lanes 0x%x (PHY_CONTROL=0x%08x)\n",
1293 phy, ch, mask, dev_priv->chv_phy_control);
1294
Ville Syrjälä30142272015-07-08 23:46:01 +03001295 assert_chv_phy_status(dev_priv);
1296
Ville Syrjälä6669e392015-07-08 23:46:00 +03001297 assert_chv_phy_powergate(dev_priv, phy, ch, override, mask);
1298
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001299 mutex_unlock(&power_domains->lock);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001300}
1301
1302static bool chv_pipe_power_well_enabled(struct drm_i915_private *dev_priv,
1303 struct i915_power_well *power_well)
1304{
1305 enum pipe pipe = power_well->data;
1306 bool enabled;
1307 u32 state, ctrl;
1308
1309 mutex_lock(&dev_priv->rps.hw_lock);
1310
1311 state = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & DP_SSS_MASK(pipe);
1312 /*
1313 * We only ever set the power-on and power-gate states, anything
1314 * else is unexpected.
1315 */
1316 WARN_ON(state != DP_SSS_PWR_ON(pipe) && state != DP_SSS_PWR_GATE(pipe));
1317 enabled = state == DP_SSS_PWR_ON(pipe);
1318
1319 /*
1320 * A transient state at this point would mean some unexpected party
1321 * is poking at the power controls too.
1322 */
1323 ctrl = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & DP_SSC_MASK(pipe);
1324 WARN_ON(ctrl << 16 != state);
1325
1326 mutex_unlock(&dev_priv->rps.hw_lock);
1327
1328 return enabled;
1329}
1330
1331static void chv_set_pipe_power_well(struct drm_i915_private *dev_priv,
1332 struct i915_power_well *power_well,
1333 bool enable)
1334{
1335 enum pipe pipe = power_well->data;
1336 u32 state;
1337 u32 ctrl;
1338
1339 state = enable ? DP_SSS_PWR_ON(pipe) : DP_SSS_PWR_GATE(pipe);
1340
1341 mutex_lock(&dev_priv->rps.hw_lock);
1342
1343#define COND \
1344 ((vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & DP_SSS_MASK(pipe)) == state)
1345
1346 if (COND)
1347 goto out;
1348
1349 ctrl = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ);
1350 ctrl &= ~DP_SSC_MASK(pipe);
1351 ctrl |= enable ? DP_SSC_PWR_ON(pipe) : DP_SSC_PWR_GATE(pipe);
1352 vlv_punit_write(dev_priv, PUNIT_REG_DSPFREQ, ctrl);
1353
1354 if (wait_for(COND, 100))
Masanari Iida7e35ab82015-05-10 01:00:23 +09001355 DRM_ERROR("timeout setting power well state %08x (%08x)\n",
Daniel Vetter9c065a72014-09-30 10:56:38 +02001356 state,
1357 vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ));
1358
1359#undef COND
1360
1361out:
1362 mutex_unlock(&dev_priv->rps.hw_lock);
1363}
1364
1365static void chv_pipe_power_well_sync_hw(struct drm_i915_private *dev_priv,
1366 struct i915_power_well *power_well)
1367{
Ville Syrjälä8fcd5cd2015-06-29 15:25:50 +03001368 WARN_ON_ONCE(power_well->data != PIPE_A);
1369
Daniel Vetter9c065a72014-09-30 10:56:38 +02001370 chv_set_pipe_power_well(dev_priv, power_well, power_well->count > 0);
1371}
1372
1373static void chv_pipe_power_well_enable(struct drm_i915_private *dev_priv,
1374 struct i915_power_well *power_well)
1375{
Ville Syrjälä8fcd5cd2015-06-29 15:25:50 +03001376 WARN_ON_ONCE(power_well->data != PIPE_A);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001377
1378 chv_set_pipe_power_well(dev_priv, power_well, true);
Ville Syrjäläafd62752014-10-30 19:43:03 +02001379
Ville Syrjälä2be7d542015-06-29 15:25:51 +03001380 vlv_display_power_well_init(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001381}
1382
1383static void chv_pipe_power_well_disable(struct drm_i915_private *dev_priv,
1384 struct i915_power_well *power_well)
1385{
Ville Syrjälä8fcd5cd2015-06-29 15:25:50 +03001386 WARN_ON_ONCE(power_well->data != PIPE_A);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001387
Ville Syrjälä2be7d542015-06-29 15:25:51 +03001388 vlv_display_power_well_deinit(dev_priv);
Ville Syrjäläafd62752014-10-30 19:43:03 +02001389
Daniel Vetter9c065a72014-09-30 10:56:38 +02001390 chv_set_pipe_power_well(dev_priv, power_well, false);
1391}
1392
Daniel Vettere4e76842014-09-30 10:56:42 +02001393/**
1394 * intel_display_power_get - grab a power domain reference
1395 * @dev_priv: i915 device instance
1396 * @domain: power domain to reference
1397 *
1398 * This function grabs a power domain reference for @domain and ensures that the
1399 * power domain and all its parents are powered up. Therefore users should only
1400 * grab a reference to the innermost power domain they need.
1401 *
1402 * Any power domain reference obtained by this function must have a symmetric
1403 * call to intel_display_power_put() to release the reference again.
1404 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02001405void intel_display_power_get(struct drm_i915_private *dev_priv,
1406 enum intel_display_power_domain domain)
1407{
1408 struct i915_power_domains *power_domains;
1409 struct i915_power_well *power_well;
1410 int i;
1411
1412 intel_runtime_pm_get(dev_priv);
1413
1414 power_domains = &dev_priv->power_domains;
1415
1416 mutex_lock(&power_domains->lock);
1417
1418 for_each_power_well(i, power_well, BIT(domain), power_domains) {
Damien Lespiaue8ca9322015-07-30 18:20:26 -03001419 if (!power_well->count++)
1420 intel_power_well_enable(dev_priv, power_well);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001421 }
1422
1423 power_domains->domain_use_count[domain]++;
1424
1425 mutex_unlock(&power_domains->lock);
1426}
1427
Daniel Vettere4e76842014-09-30 10:56:42 +02001428/**
1429 * intel_display_power_put - release a power domain reference
1430 * @dev_priv: i915 device instance
1431 * @domain: power domain to reference
1432 *
1433 * This function drops the power domain reference obtained by
1434 * intel_display_power_get() and might power down the corresponding hardware
1435 * block right away if this is the last reference.
1436 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02001437void intel_display_power_put(struct drm_i915_private *dev_priv,
1438 enum intel_display_power_domain domain)
1439{
1440 struct i915_power_domains *power_domains;
1441 struct i915_power_well *power_well;
1442 int i;
1443
1444 power_domains = &dev_priv->power_domains;
1445
1446 mutex_lock(&power_domains->lock);
1447
1448 WARN_ON(!power_domains->domain_use_count[domain]);
1449 power_domains->domain_use_count[domain]--;
1450
1451 for_each_power_well_rev(i, power_well, BIT(domain), power_domains) {
1452 WARN_ON(!power_well->count);
1453
Damien Lespiaudcddab32015-07-30 18:20:27 -03001454 if (!--power_well->count && i915.disable_power_well)
1455 intel_power_well_disable(dev_priv, power_well);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001456 }
1457
1458 mutex_unlock(&power_domains->lock);
1459
1460 intel_runtime_pm_put(dev_priv);
1461}
1462
Daniel Vetter9c065a72014-09-30 10:56:38 +02001463#define HSW_ALWAYS_ON_POWER_DOMAINS ( \
1464 BIT(POWER_DOMAIN_PIPE_A) | \
1465 BIT(POWER_DOMAIN_TRANSCODER_EDP) | \
1466 BIT(POWER_DOMAIN_PORT_DDI_A_2_LANES) | \
1467 BIT(POWER_DOMAIN_PORT_DDI_A_4_LANES) | \
1468 BIT(POWER_DOMAIN_PORT_DDI_B_2_LANES) | \
1469 BIT(POWER_DOMAIN_PORT_DDI_B_4_LANES) | \
1470 BIT(POWER_DOMAIN_PORT_DDI_C_2_LANES) | \
1471 BIT(POWER_DOMAIN_PORT_DDI_C_4_LANES) | \
1472 BIT(POWER_DOMAIN_PORT_DDI_D_2_LANES) | \
1473 BIT(POWER_DOMAIN_PORT_DDI_D_4_LANES) | \
1474 BIT(POWER_DOMAIN_PORT_CRT) | \
1475 BIT(POWER_DOMAIN_PLLS) | \
Satheeshakrishna M14071212015-01-16 15:57:51 +00001476 BIT(POWER_DOMAIN_AUX_A) | \
1477 BIT(POWER_DOMAIN_AUX_B) | \
1478 BIT(POWER_DOMAIN_AUX_C) | \
1479 BIT(POWER_DOMAIN_AUX_D) | \
Daniel Vetter9c065a72014-09-30 10:56:38 +02001480 BIT(POWER_DOMAIN_INIT))
1481#define HSW_DISPLAY_POWER_DOMAINS ( \
1482 (POWER_DOMAIN_MASK & ~HSW_ALWAYS_ON_POWER_DOMAINS) | \
1483 BIT(POWER_DOMAIN_INIT))
1484
1485#define BDW_ALWAYS_ON_POWER_DOMAINS ( \
1486 HSW_ALWAYS_ON_POWER_DOMAINS | \
1487 BIT(POWER_DOMAIN_PIPE_A_PANEL_FITTER))
1488#define BDW_DISPLAY_POWER_DOMAINS ( \
1489 (POWER_DOMAIN_MASK & ~BDW_ALWAYS_ON_POWER_DOMAINS) | \
1490 BIT(POWER_DOMAIN_INIT))
1491
1492#define VLV_ALWAYS_ON_POWER_DOMAINS BIT(POWER_DOMAIN_INIT)
1493#define VLV_DISPLAY_POWER_DOMAINS POWER_DOMAIN_MASK
1494
1495#define VLV_DPIO_CMN_BC_POWER_DOMAINS ( \
1496 BIT(POWER_DOMAIN_PORT_DDI_B_2_LANES) | \
1497 BIT(POWER_DOMAIN_PORT_DDI_B_4_LANES) | \
1498 BIT(POWER_DOMAIN_PORT_DDI_C_2_LANES) | \
1499 BIT(POWER_DOMAIN_PORT_DDI_C_4_LANES) | \
1500 BIT(POWER_DOMAIN_PORT_CRT) | \
Satheeshakrishna M14071212015-01-16 15:57:51 +00001501 BIT(POWER_DOMAIN_AUX_B) | \
1502 BIT(POWER_DOMAIN_AUX_C) | \
Daniel Vetter9c065a72014-09-30 10:56:38 +02001503 BIT(POWER_DOMAIN_INIT))
1504
1505#define VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS ( \
1506 BIT(POWER_DOMAIN_PORT_DDI_B_2_LANES) | \
1507 BIT(POWER_DOMAIN_PORT_DDI_B_4_LANES) | \
Satheeshakrishna M14071212015-01-16 15:57:51 +00001508 BIT(POWER_DOMAIN_AUX_B) | \
Daniel Vetter9c065a72014-09-30 10:56:38 +02001509 BIT(POWER_DOMAIN_INIT))
1510
1511#define VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS ( \
1512 BIT(POWER_DOMAIN_PORT_DDI_B_4_LANES) | \
Satheeshakrishna M14071212015-01-16 15:57:51 +00001513 BIT(POWER_DOMAIN_AUX_B) | \
Daniel Vetter9c065a72014-09-30 10:56:38 +02001514 BIT(POWER_DOMAIN_INIT))
1515
1516#define VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS ( \
1517 BIT(POWER_DOMAIN_PORT_DDI_C_2_LANES) | \
1518 BIT(POWER_DOMAIN_PORT_DDI_C_4_LANES) | \
Satheeshakrishna M14071212015-01-16 15:57:51 +00001519 BIT(POWER_DOMAIN_AUX_C) | \
Daniel Vetter9c065a72014-09-30 10:56:38 +02001520 BIT(POWER_DOMAIN_INIT))
1521
1522#define VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS ( \
1523 BIT(POWER_DOMAIN_PORT_DDI_C_4_LANES) | \
Satheeshakrishna M14071212015-01-16 15:57:51 +00001524 BIT(POWER_DOMAIN_AUX_C) | \
Daniel Vetter9c065a72014-09-30 10:56:38 +02001525 BIT(POWER_DOMAIN_INIT))
1526
Daniel Vetter9c065a72014-09-30 10:56:38 +02001527#define CHV_DPIO_CMN_BC_POWER_DOMAINS ( \
1528 BIT(POWER_DOMAIN_PORT_DDI_B_2_LANES) | \
1529 BIT(POWER_DOMAIN_PORT_DDI_B_4_LANES) | \
1530 BIT(POWER_DOMAIN_PORT_DDI_C_2_LANES) | \
1531 BIT(POWER_DOMAIN_PORT_DDI_C_4_LANES) | \
Satheeshakrishna M14071212015-01-16 15:57:51 +00001532 BIT(POWER_DOMAIN_AUX_B) | \
1533 BIT(POWER_DOMAIN_AUX_C) | \
Daniel Vetter9c065a72014-09-30 10:56:38 +02001534 BIT(POWER_DOMAIN_INIT))
1535
1536#define CHV_DPIO_CMN_D_POWER_DOMAINS ( \
1537 BIT(POWER_DOMAIN_PORT_DDI_D_2_LANES) | \
1538 BIT(POWER_DOMAIN_PORT_DDI_D_4_LANES) | \
Satheeshakrishna M14071212015-01-16 15:57:51 +00001539 BIT(POWER_DOMAIN_AUX_D) | \
Daniel Vetter9c065a72014-09-30 10:56:38 +02001540 BIT(POWER_DOMAIN_INIT))
1541
Daniel Vetter9c065a72014-09-30 10:56:38 +02001542static const struct i915_power_well_ops i9xx_always_on_power_well_ops = {
1543 .sync_hw = i9xx_always_on_power_well_noop,
1544 .enable = i9xx_always_on_power_well_noop,
1545 .disable = i9xx_always_on_power_well_noop,
1546 .is_enabled = i9xx_always_on_power_well_enabled,
1547};
1548
1549static const struct i915_power_well_ops chv_pipe_power_well_ops = {
1550 .sync_hw = chv_pipe_power_well_sync_hw,
1551 .enable = chv_pipe_power_well_enable,
1552 .disable = chv_pipe_power_well_disable,
1553 .is_enabled = chv_pipe_power_well_enabled,
1554};
1555
1556static const struct i915_power_well_ops chv_dpio_cmn_power_well_ops = {
1557 .sync_hw = vlv_power_well_sync_hw,
1558 .enable = chv_dpio_cmn_power_well_enable,
1559 .disable = chv_dpio_cmn_power_well_disable,
1560 .is_enabled = vlv_power_well_enabled,
1561};
1562
1563static struct i915_power_well i9xx_always_on_power_well[] = {
1564 {
1565 .name = "always-on",
1566 .always_on = 1,
1567 .domains = POWER_DOMAIN_MASK,
1568 .ops = &i9xx_always_on_power_well_ops,
1569 },
1570};
1571
1572static const struct i915_power_well_ops hsw_power_well_ops = {
1573 .sync_hw = hsw_power_well_sync_hw,
1574 .enable = hsw_power_well_enable,
1575 .disable = hsw_power_well_disable,
1576 .is_enabled = hsw_power_well_enabled,
1577};
1578
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00001579static const struct i915_power_well_ops skl_power_well_ops = {
1580 .sync_hw = skl_power_well_sync_hw,
1581 .enable = skl_power_well_enable,
1582 .disable = skl_power_well_disable,
1583 .is_enabled = skl_power_well_enabled,
1584};
1585
Daniel Vetter9c065a72014-09-30 10:56:38 +02001586static struct i915_power_well hsw_power_wells[] = {
1587 {
1588 .name = "always-on",
1589 .always_on = 1,
1590 .domains = HSW_ALWAYS_ON_POWER_DOMAINS,
1591 .ops = &i9xx_always_on_power_well_ops,
1592 },
1593 {
1594 .name = "display",
1595 .domains = HSW_DISPLAY_POWER_DOMAINS,
1596 .ops = &hsw_power_well_ops,
1597 },
1598};
1599
1600static struct i915_power_well bdw_power_wells[] = {
1601 {
1602 .name = "always-on",
1603 .always_on = 1,
1604 .domains = BDW_ALWAYS_ON_POWER_DOMAINS,
1605 .ops = &i9xx_always_on_power_well_ops,
1606 },
1607 {
1608 .name = "display",
1609 .domains = BDW_DISPLAY_POWER_DOMAINS,
1610 .ops = &hsw_power_well_ops,
1611 },
1612};
1613
1614static const struct i915_power_well_ops vlv_display_power_well_ops = {
1615 .sync_hw = vlv_power_well_sync_hw,
1616 .enable = vlv_display_power_well_enable,
1617 .disable = vlv_display_power_well_disable,
1618 .is_enabled = vlv_power_well_enabled,
1619};
1620
1621static const struct i915_power_well_ops vlv_dpio_cmn_power_well_ops = {
1622 .sync_hw = vlv_power_well_sync_hw,
1623 .enable = vlv_dpio_cmn_power_well_enable,
1624 .disable = vlv_dpio_cmn_power_well_disable,
1625 .is_enabled = vlv_power_well_enabled,
1626};
1627
1628static const struct i915_power_well_ops vlv_dpio_power_well_ops = {
1629 .sync_hw = vlv_power_well_sync_hw,
1630 .enable = vlv_power_well_enable,
1631 .disable = vlv_power_well_disable,
1632 .is_enabled = vlv_power_well_enabled,
1633};
1634
1635static struct i915_power_well vlv_power_wells[] = {
1636 {
1637 .name = "always-on",
1638 .always_on = 1,
1639 .domains = VLV_ALWAYS_ON_POWER_DOMAINS,
1640 .ops = &i9xx_always_on_power_well_ops,
1641 },
1642 {
1643 .name = "display",
1644 .domains = VLV_DISPLAY_POWER_DOMAINS,
1645 .data = PUNIT_POWER_WELL_DISP2D,
1646 .ops = &vlv_display_power_well_ops,
1647 },
1648 {
1649 .name = "dpio-tx-b-01",
1650 .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
1651 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
1652 VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
1653 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
1654 .ops = &vlv_dpio_power_well_ops,
1655 .data = PUNIT_POWER_WELL_DPIO_TX_B_LANES_01,
1656 },
1657 {
1658 .name = "dpio-tx-b-23",
1659 .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
1660 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
1661 VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
1662 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
1663 .ops = &vlv_dpio_power_well_ops,
1664 .data = PUNIT_POWER_WELL_DPIO_TX_B_LANES_23,
1665 },
1666 {
1667 .name = "dpio-tx-c-01",
1668 .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
1669 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
1670 VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
1671 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
1672 .ops = &vlv_dpio_power_well_ops,
1673 .data = PUNIT_POWER_WELL_DPIO_TX_C_LANES_01,
1674 },
1675 {
1676 .name = "dpio-tx-c-23",
1677 .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
1678 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
1679 VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
1680 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
1681 .ops = &vlv_dpio_power_well_ops,
1682 .data = PUNIT_POWER_WELL_DPIO_TX_C_LANES_23,
1683 },
1684 {
1685 .name = "dpio-common",
1686 .domains = VLV_DPIO_CMN_BC_POWER_DOMAINS,
1687 .data = PUNIT_POWER_WELL_DPIO_CMN_BC,
1688 .ops = &vlv_dpio_cmn_power_well_ops,
1689 },
1690};
1691
1692static struct i915_power_well chv_power_wells[] = {
1693 {
1694 .name = "always-on",
1695 .always_on = 1,
1696 .domains = VLV_ALWAYS_ON_POWER_DOMAINS,
1697 .ops = &i9xx_always_on_power_well_ops,
1698 },
Daniel Vetter9c065a72014-09-30 10:56:38 +02001699 {
1700 .name = "display",
Ville Syrjäläbaa4e572014-10-27 16:07:32 +02001701 /*
Ville Syrjäläfde61e42015-05-26 20:22:39 +03001702 * Pipe A power well is the new disp2d well. Pipe B and C
1703 * power wells don't actually exist. Pipe A power well is
1704 * required for any pipe to work.
Ville Syrjäläbaa4e572014-10-27 16:07:32 +02001705 */
Ville Syrjäläfde61e42015-05-26 20:22:39 +03001706 .domains = VLV_DISPLAY_POWER_DOMAINS,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001707 .data = PIPE_A,
1708 .ops = &chv_pipe_power_well_ops,
1709 },
Daniel Vetter9c065a72014-09-30 10:56:38 +02001710 {
1711 .name = "dpio-common-bc",
Ville Syrjälä71849b62015-04-10 18:21:29 +03001712 .domains = CHV_DPIO_CMN_BC_POWER_DOMAINS,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001713 .data = PUNIT_POWER_WELL_DPIO_CMN_BC,
1714 .ops = &chv_dpio_cmn_power_well_ops,
1715 },
1716 {
1717 .name = "dpio-common-d",
Ville Syrjälä71849b62015-04-10 18:21:29 +03001718 .domains = CHV_DPIO_CMN_D_POWER_DOMAINS,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001719 .data = PUNIT_POWER_WELL_DPIO_CMN_D,
1720 .ops = &chv_dpio_cmn_power_well_ops,
1721 },
Daniel Vetter9c065a72014-09-30 10:56:38 +02001722};
1723
Suketu Shah5aefb232015-04-16 14:22:10 +05301724bool intel_display_power_well_is_enabled(struct drm_i915_private *dev_priv,
1725 int power_well_id)
1726{
1727 struct i915_power_well *power_well;
1728 bool ret;
1729
1730 power_well = lookup_power_well(dev_priv, power_well_id);
1731 ret = power_well->ops->is_enabled(dev_priv, power_well);
1732
1733 return ret;
1734}
1735
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00001736static struct i915_power_well skl_power_wells[] = {
1737 {
1738 .name = "always-on",
1739 .always_on = 1,
1740 .domains = SKL_DISPLAY_ALWAYS_ON_POWER_DOMAINS,
1741 .ops = &i9xx_always_on_power_well_ops,
1742 },
1743 {
1744 .name = "power well 1",
1745 .domains = SKL_DISPLAY_POWERWELL_1_POWER_DOMAINS,
1746 .ops = &skl_power_well_ops,
1747 .data = SKL_DISP_PW_1,
1748 },
1749 {
1750 .name = "MISC IO power well",
1751 .domains = SKL_DISPLAY_MISC_IO_POWER_DOMAINS,
1752 .ops = &skl_power_well_ops,
1753 .data = SKL_DISP_PW_MISC_IO,
1754 },
1755 {
1756 .name = "power well 2",
1757 .domains = SKL_DISPLAY_POWERWELL_2_POWER_DOMAINS,
1758 .ops = &skl_power_well_ops,
1759 .data = SKL_DISP_PW_2,
1760 },
1761 {
1762 .name = "DDI A/E power well",
1763 .domains = SKL_DISPLAY_DDI_A_E_POWER_DOMAINS,
1764 .ops = &skl_power_well_ops,
1765 .data = SKL_DISP_PW_DDI_A_E,
1766 },
1767 {
1768 .name = "DDI B power well",
1769 .domains = SKL_DISPLAY_DDI_B_POWER_DOMAINS,
1770 .ops = &skl_power_well_ops,
1771 .data = SKL_DISP_PW_DDI_B,
1772 },
1773 {
1774 .name = "DDI C power well",
1775 .domains = SKL_DISPLAY_DDI_C_POWER_DOMAINS,
1776 .ops = &skl_power_well_ops,
1777 .data = SKL_DISP_PW_DDI_C,
1778 },
1779 {
1780 .name = "DDI D power well",
1781 .domains = SKL_DISPLAY_DDI_D_POWER_DOMAINS,
1782 .ops = &skl_power_well_ops,
1783 .data = SKL_DISP_PW_DDI_D,
1784 },
1785};
1786
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05301787static struct i915_power_well bxt_power_wells[] = {
1788 {
1789 .name = "always-on",
1790 .always_on = 1,
1791 .domains = BXT_DISPLAY_ALWAYS_ON_POWER_DOMAINS,
1792 .ops = &i9xx_always_on_power_well_ops,
1793 },
1794 {
1795 .name = "power well 1",
1796 .domains = BXT_DISPLAY_POWERWELL_1_POWER_DOMAINS,
1797 .ops = &skl_power_well_ops,
1798 .data = SKL_DISP_PW_1,
1799 },
1800 {
1801 .name = "power well 2",
1802 .domains = BXT_DISPLAY_POWERWELL_2_POWER_DOMAINS,
1803 .ops = &skl_power_well_ops,
1804 .data = SKL_DISP_PW_2,
1805 }
1806};
1807
Daniel Vetter9c065a72014-09-30 10:56:38 +02001808#define set_power_wells(power_domains, __power_wells) ({ \
1809 (power_domains)->power_wells = (__power_wells); \
1810 (power_domains)->power_well_count = ARRAY_SIZE(__power_wells); \
1811})
1812
Daniel Vettere4e76842014-09-30 10:56:42 +02001813/**
1814 * intel_power_domains_init - initializes the power domain structures
1815 * @dev_priv: i915 device instance
1816 *
1817 * Initializes the power domain structures for @dev_priv depending upon the
1818 * supported platform.
1819 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02001820int intel_power_domains_init(struct drm_i915_private *dev_priv)
1821{
1822 struct i915_power_domains *power_domains = &dev_priv->power_domains;
1823
1824 mutex_init(&power_domains->lock);
1825
1826 /*
1827 * The enabling order will be from lower to higher indexed wells,
1828 * the disabling order is reversed.
1829 */
1830 if (IS_HASWELL(dev_priv->dev)) {
1831 set_power_wells(power_domains, hsw_power_wells);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001832 } else if (IS_BROADWELL(dev_priv->dev)) {
1833 set_power_wells(power_domains, bdw_power_wells);
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00001834 } else if (IS_SKYLAKE(dev_priv->dev)) {
1835 set_power_wells(power_domains, skl_power_wells);
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05301836 } else if (IS_BROXTON(dev_priv->dev)) {
1837 set_power_wells(power_domains, bxt_power_wells);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001838 } else if (IS_CHERRYVIEW(dev_priv->dev)) {
1839 set_power_wells(power_domains, chv_power_wells);
1840 } else if (IS_VALLEYVIEW(dev_priv->dev)) {
1841 set_power_wells(power_domains, vlv_power_wells);
1842 } else {
1843 set_power_wells(power_domains, i9xx_always_on_power_well);
1844 }
1845
1846 return 0;
1847}
1848
Daniel Vetter41373cd2014-09-30 10:56:41 +02001849static void intel_runtime_pm_disable(struct drm_i915_private *dev_priv)
1850{
1851 struct drm_device *dev = dev_priv->dev;
1852 struct device *device = &dev->pdev->dev;
1853
1854 if (!HAS_RUNTIME_PM(dev))
1855 return;
1856
1857 if (!intel_enable_rc6(dev))
1858 return;
1859
1860 /* Make sure we're not suspended first. */
1861 pm_runtime_get_sync(device);
Daniel Vetter41373cd2014-09-30 10:56:41 +02001862}
1863
Daniel Vettere4e76842014-09-30 10:56:42 +02001864/**
1865 * intel_power_domains_fini - finalizes the power domain structures
1866 * @dev_priv: i915 device instance
1867 *
1868 * Finalizes the power domain structures for @dev_priv depending upon the
1869 * supported platform. This function also disables runtime pm and ensures that
1870 * the device stays powered up so that the driver can be reloaded.
1871 */
Daniel Vetterf458ebb2014-09-30 10:56:39 +02001872void intel_power_domains_fini(struct drm_i915_private *dev_priv)
Daniel Vetter9c065a72014-09-30 10:56:38 +02001873{
Daniel Vetter41373cd2014-09-30 10:56:41 +02001874 intel_runtime_pm_disable(dev_priv);
1875
Daniel Vetterf458ebb2014-09-30 10:56:39 +02001876 /* The i915.ko module is still not prepared to be loaded when
1877 * the power well is not enabled, so just enable it in case
1878 * we're going to unload/reload. */
1879 intel_display_set_init_power(dev_priv, true);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001880}
1881
1882static void intel_power_domains_resume(struct drm_i915_private *dev_priv)
1883{
1884 struct i915_power_domains *power_domains = &dev_priv->power_domains;
1885 struct i915_power_well *power_well;
1886 int i;
1887
1888 mutex_lock(&power_domains->lock);
1889 for_each_power_well(i, power_well, POWER_DOMAIN_MASK, power_domains) {
1890 power_well->ops->sync_hw(dev_priv, power_well);
1891 power_well->hw_enabled = power_well->ops->is_enabled(dev_priv,
1892 power_well);
1893 }
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 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02002019void intel_power_domains_init_hw(struct drm_i915_private *dev_priv)
2020{
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
Ville Syrjälä70722462015-04-10 18:21:28 +03002026 if (IS_CHERRYVIEW(dev)) {
Ville Syrjälä770effb2015-07-08 23:45:51 +03002027 mutex_lock(&power_domains->lock);
Ville Syrjälä70722462015-04-10 18:21:28 +03002028 chv_phy_control_init(dev_priv);
Ville Syrjälä770effb2015-07-08 23:45:51 +03002029 mutex_unlock(&power_domains->lock);
Ville Syrjälä70722462015-04-10 18:21:28 +03002030 } else if (IS_VALLEYVIEW(dev)) {
Daniel Vetter9c065a72014-09-30 10:56:38 +02002031 mutex_lock(&power_domains->lock);
2032 vlv_cmnlane_wa(dev_priv);
2033 mutex_unlock(&power_domains->lock);
2034 }
2035
2036 /* For now, we need the power well to be always enabled. */
2037 intel_display_set_init_power(dev_priv, true);
2038 intel_power_domains_resume(dev_priv);
2039 power_domains->initializing = false;
2040}
2041
Daniel Vettere4e76842014-09-30 10:56:42 +02002042/**
Geert Uytterhoevenca2b1402015-03-09 21:21:08 +01002043 * intel_aux_display_runtime_get - grab an auxiliary power domain reference
Daniel Vettere4e76842014-09-30 10:56:42 +02002044 * @dev_priv: i915 device instance
2045 *
2046 * This function grabs a power domain reference for the auxiliary power domain
2047 * (for access to the GMBUS and DP AUX blocks) and ensures that it and all its
2048 * parents are powered up. Therefore users should only grab a reference to the
2049 * innermost power domain they need.
2050 *
2051 * Any power domain reference obtained by this function must have a symmetric
2052 * call to intel_aux_display_runtime_put() to release the reference again.
2053 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02002054void intel_aux_display_runtime_get(struct drm_i915_private *dev_priv)
2055{
2056 intel_runtime_pm_get(dev_priv);
2057}
2058
Daniel Vettere4e76842014-09-30 10:56:42 +02002059/**
Geert Uytterhoevenca2b1402015-03-09 21:21:08 +01002060 * intel_aux_display_runtime_put - release an auxiliary power domain reference
Daniel Vettere4e76842014-09-30 10:56:42 +02002061 * @dev_priv: i915 device instance
2062 *
Geert Uytterhoevenca2b1402015-03-09 21:21:08 +01002063 * This function drops the auxiliary power domain reference obtained by
Daniel Vettere4e76842014-09-30 10:56:42 +02002064 * intel_aux_display_runtime_get() and might power down the corresponding
2065 * hardware block right away if this is the last reference.
2066 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02002067void intel_aux_display_runtime_put(struct drm_i915_private *dev_priv)
2068{
2069 intel_runtime_pm_put(dev_priv);
2070}
2071
Daniel Vettere4e76842014-09-30 10:56:42 +02002072/**
2073 * intel_runtime_pm_get - grab a runtime pm reference
2074 * @dev_priv: i915 device instance
2075 *
2076 * This function grabs a device-level runtime pm reference (mostly used for GEM
2077 * code to ensure the GTT or GT is on) and ensures that it is powered up.
2078 *
2079 * Any runtime pm reference obtained by this function must have a symmetric
2080 * call to intel_runtime_pm_put() to release the reference again.
2081 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02002082void intel_runtime_pm_get(struct drm_i915_private *dev_priv)
2083{
2084 struct drm_device *dev = dev_priv->dev;
2085 struct device *device = &dev->pdev->dev;
2086
2087 if (!HAS_RUNTIME_PM(dev))
2088 return;
2089
2090 pm_runtime_get_sync(device);
2091 WARN(dev_priv->pm.suspended, "Device still suspended.\n");
2092}
2093
Daniel Vettere4e76842014-09-30 10:56:42 +02002094/**
2095 * intel_runtime_pm_get_noresume - grab a runtime pm reference
2096 * @dev_priv: i915 device instance
2097 *
2098 * This function grabs a device-level runtime pm reference (mostly used for GEM
2099 * code to ensure the GTT or GT is on).
2100 *
2101 * It will _not_ power up the device but instead only check that it's powered
2102 * on. Therefore it is only valid to call this functions from contexts where
2103 * the device is known to be powered up and where trying to power it up would
2104 * result in hilarity and deadlocks. That pretty much means only the system
2105 * suspend/resume code where this is used to grab runtime pm references for
2106 * delayed setup down in work items.
2107 *
2108 * Any runtime pm reference obtained by this function must have a symmetric
2109 * call to intel_runtime_pm_put() to release the reference again.
2110 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02002111void intel_runtime_pm_get_noresume(struct drm_i915_private *dev_priv)
2112{
2113 struct drm_device *dev = dev_priv->dev;
2114 struct device *device = &dev->pdev->dev;
2115
2116 if (!HAS_RUNTIME_PM(dev))
2117 return;
2118
2119 WARN(dev_priv->pm.suspended, "Getting nosync-ref while suspended.\n");
2120 pm_runtime_get_noresume(device);
2121}
2122
Daniel Vettere4e76842014-09-30 10:56:42 +02002123/**
2124 * intel_runtime_pm_put - release a runtime pm reference
2125 * @dev_priv: i915 device instance
2126 *
2127 * This function drops the device-level runtime pm reference obtained by
2128 * intel_runtime_pm_get() and might power down the corresponding
2129 * hardware block right away if this is the last reference.
2130 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02002131void intel_runtime_pm_put(struct drm_i915_private *dev_priv)
2132{
2133 struct drm_device *dev = dev_priv->dev;
2134 struct device *device = &dev->pdev->dev;
2135
2136 if (!HAS_RUNTIME_PM(dev))
2137 return;
2138
2139 pm_runtime_mark_last_busy(device);
2140 pm_runtime_put_autosuspend(device);
2141}
2142
Daniel Vettere4e76842014-09-30 10:56:42 +02002143/**
2144 * intel_runtime_pm_enable - enable runtime pm
2145 * @dev_priv: i915 device instance
2146 *
2147 * This function enables runtime pm at the end of the driver load sequence.
2148 *
2149 * Note that this function does currently not enable runtime pm for the
2150 * subordinate display power domains. That is only done on the first modeset
2151 * using intel_display_set_init_power().
2152 */
Daniel Vetterf458ebb2014-09-30 10:56:39 +02002153void intel_runtime_pm_enable(struct drm_i915_private *dev_priv)
Daniel Vetter9c065a72014-09-30 10:56:38 +02002154{
2155 struct drm_device *dev = dev_priv->dev;
2156 struct device *device = &dev->pdev->dev;
2157
2158 if (!HAS_RUNTIME_PM(dev))
2159 return;
2160
Daniel Vetter9c065a72014-09-30 10:56:38 +02002161 /*
2162 * RPM depends on RC6 to save restore the GT HW context, so make RC6 a
2163 * requirement.
2164 */
2165 if (!intel_enable_rc6(dev)) {
2166 DRM_INFO("RC6 disabled, disabling runtime PM support\n");
2167 return;
2168 }
2169
2170 pm_runtime_set_autosuspend_delay(device, 10000); /* 10s */
2171 pm_runtime_mark_last_busy(device);
2172 pm_runtime_use_autosuspend(device);
2173
2174 pm_runtime_put_autosuspend(device);
2175}
2176