blob: ffbf9779c26d403e53adc85767bfd855643898d6 [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 Shahdc174302015-04-17 19:46:16 +053052#define GEN9_ENABLE_DC5(dev) (IS_SKYLAKE(dev))
53
Daniel Vetter9c065a72014-09-30 10:56:38 +020054#define for_each_power_well(i, power_well, domain_mask, power_domains) \
55 for (i = 0; \
56 i < (power_domains)->power_well_count && \
57 ((power_well) = &(power_domains)->power_wells[i]); \
58 i++) \
59 if ((power_well)->domains & (domain_mask))
60
61#define for_each_power_well_rev(i, power_well, domain_mask, power_domains) \
62 for (i = (power_domains)->power_well_count - 1; \
63 i >= 0 && ((power_well) = &(power_domains)->power_wells[i]);\
64 i--) \
65 if ((power_well)->domains & (domain_mask))
66
Daniel Vettere4e76842014-09-30 10:56:42 +020067/*
Daniel Vetter9c065a72014-09-30 10:56:38 +020068 * We should only use the power well if we explicitly asked the hardware to
69 * enable it, so check if it's enabled and also check if we've requested it to
70 * be enabled.
71 */
72static bool hsw_power_well_enabled(struct drm_i915_private *dev_priv,
73 struct i915_power_well *power_well)
74{
75 return I915_READ(HSW_PWR_WELL_DRIVER) ==
76 (HSW_PWR_WELL_ENABLE_REQUEST | HSW_PWR_WELL_STATE_ENABLED);
77}
78
Daniel Vettere4e76842014-09-30 10:56:42 +020079/**
80 * __intel_display_power_is_enabled - unlocked check for a power domain
81 * @dev_priv: i915 device instance
82 * @domain: power domain to check
83 *
84 * This is the unlocked version of intel_display_power_is_enabled() and should
85 * only be used from error capture and recovery code where deadlocks are
86 * possible.
87 *
88 * Returns:
89 * True when the power domain is enabled, false otherwise.
90 */
Daniel Vetterf458ebb2014-09-30 10:56:39 +020091bool __intel_display_power_is_enabled(struct drm_i915_private *dev_priv,
92 enum intel_display_power_domain domain)
Daniel Vetter9c065a72014-09-30 10:56:38 +020093{
94 struct i915_power_domains *power_domains;
95 struct i915_power_well *power_well;
96 bool is_enabled;
97 int i;
98
99 if (dev_priv->pm.suspended)
100 return false;
101
102 power_domains = &dev_priv->power_domains;
103
104 is_enabled = true;
105
106 for_each_power_well_rev(i, power_well, BIT(domain), power_domains) {
107 if (power_well->always_on)
108 continue;
109
110 if (!power_well->hw_enabled) {
111 is_enabled = false;
112 break;
113 }
114 }
115
116 return is_enabled;
117}
118
Daniel Vettere4e76842014-09-30 10:56:42 +0200119/**
Damien Lespiauf61ccae2014-11-25 13:45:41 +0000120 * intel_display_power_is_enabled - check for a power domain
Daniel Vettere4e76842014-09-30 10:56:42 +0200121 * @dev_priv: i915 device instance
122 * @domain: power domain to check
123 *
124 * This function can be used to check the hw power domain state. It is mostly
125 * used in hardware state readout functions. Everywhere else code should rely
126 * upon explicit power domain reference counting to ensure that the hardware
127 * block is powered up before accessing it.
128 *
129 * Callers must hold the relevant modesetting locks to ensure that concurrent
130 * threads can't disable the power well while the caller tries to read a few
131 * registers.
132 *
133 * Returns:
134 * True when the power domain is enabled, false otherwise.
135 */
Daniel Vetterf458ebb2014-09-30 10:56:39 +0200136bool intel_display_power_is_enabled(struct drm_i915_private *dev_priv,
137 enum intel_display_power_domain domain)
Daniel Vetter9c065a72014-09-30 10:56:38 +0200138{
139 struct i915_power_domains *power_domains;
140 bool ret;
141
142 power_domains = &dev_priv->power_domains;
143
144 mutex_lock(&power_domains->lock);
Daniel Vetterf458ebb2014-09-30 10:56:39 +0200145 ret = __intel_display_power_is_enabled(dev_priv, domain);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200146 mutex_unlock(&power_domains->lock);
147
148 return ret;
149}
150
Daniel Vettere4e76842014-09-30 10:56:42 +0200151/**
152 * intel_display_set_init_power - set the initial power domain state
153 * @dev_priv: i915 device instance
154 * @enable: whether to enable or disable the initial power domain state
155 *
156 * For simplicity our driver load/unload and system suspend/resume code assumes
157 * that all power domains are always enabled. This functions controls the state
158 * of this little hack. While the initial power domain state is enabled runtime
159 * pm is effectively disabled.
160 */
Daniel Vetterd9bc89d92014-09-30 10:56:40 +0200161void intel_display_set_init_power(struct drm_i915_private *dev_priv,
162 bool enable)
163{
164 if (dev_priv->power_domains.init_power_on == enable)
165 return;
166
167 if (enable)
168 intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
169 else
170 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
171
172 dev_priv->power_domains.init_power_on = enable;
173}
174
Daniel Vetter9c065a72014-09-30 10:56:38 +0200175/*
176 * Starting with Haswell, we have a "Power Down Well" that can be turned off
177 * when not needed anymore. We have 4 registers that can request the power well
178 * to be enabled, and it will only be disabled if none of the registers is
179 * requesting it to be enabled.
180 */
181static void hsw_power_well_post_enable(struct drm_i915_private *dev_priv)
182{
183 struct drm_device *dev = dev_priv->dev;
184
185 /*
186 * After we re-enable the power well, if we touch VGA register 0x3d5
187 * we'll get unclaimed register interrupts. This stops after we write
188 * anything to the VGA MSR register. The vgacon module uses this
189 * register all the time, so if we unbind our driver and, as a
190 * consequence, bind vgacon, we'll get stuck in an infinite loop at
191 * console_unlock(). So make here we touch the VGA MSR register, making
192 * sure vgacon can keep working normally without triggering interrupts
193 * and error messages.
194 */
195 vga_get_uninterruptible(dev->pdev, VGA_RSRC_LEGACY_IO);
196 outb(inb(VGA_MSR_READ), VGA_MSR_WRITE);
197 vga_put(dev->pdev, VGA_RSRC_LEGACY_IO);
198
Damien Lespiau25400392015-03-06 18:50:52 +0000199 if (IS_BROADWELL(dev))
Damien Lespiau4c6c03b2015-03-06 18:50:48 +0000200 gen8_irq_power_well_post_enable(dev_priv,
201 1 << PIPE_C | 1 << PIPE_B);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200202}
203
Damien Lespiaud14c0342015-03-06 18:50:51 +0000204static void skl_power_well_post_enable(struct drm_i915_private *dev_priv,
205 struct i915_power_well *power_well)
206{
207 struct drm_device *dev = dev_priv->dev;
208
209 /*
210 * After we re-enable the power well, if we touch VGA register 0x3d5
211 * we'll get unclaimed register interrupts. This stops after we write
212 * anything to the VGA MSR register. The vgacon module uses this
213 * register all the time, so if we unbind our driver and, as a
214 * consequence, bind vgacon, we'll get stuck in an infinite loop at
215 * console_unlock(). So make here we touch the VGA MSR register, making
216 * sure vgacon can keep working normally without triggering interrupts
217 * and error messages.
218 */
219 if (power_well->data == SKL_DISP_PW_2) {
220 vga_get_uninterruptible(dev->pdev, VGA_RSRC_LEGACY_IO);
221 outb(inb(VGA_MSR_READ), VGA_MSR_WRITE);
222 vga_put(dev->pdev, VGA_RSRC_LEGACY_IO);
223
224 gen8_irq_power_well_post_enable(dev_priv,
225 1 << PIPE_C | 1 << PIPE_B);
226 }
227
Damien Lespiau1d2b9522015-03-06 18:50:53 +0000228 if (power_well->data == SKL_DISP_PW_1) {
229 intel_prepare_ddi(dev);
Damien Lespiaud14c0342015-03-06 18:50:51 +0000230 gen8_irq_power_well_post_enable(dev_priv, 1 << PIPE_A);
Damien Lespiau1d2b9522015-03-06 18:50:53 +0000231 }
Damien Lespiaud14c0342015-03-06 18:50:51 +0000232}
233
Daniel Vetter9c065a72014-09-30 10:56:38 +0200234static void hsw_set_power_well(struct drm_i915_private *dev_priv,
235 struct i915_power_well *power_well, bool enable)
236{
237 bool is_enabled, enable_requested;
238 uint32_t tmp;
239
240 tmp = I915_READ(HSW_PWR_WELL_DRIVER);
241 is_enabled = tmp & HSW_PWR_WELL_STATE_ENABLED;
242 enable_requested = tmp & HSW_PWR_WELL_ENABLE_REQUEST;
243
244 if (enable) {
245 if (!enable_requested)
246 I915_WRITE(HSW_PWR_WELL_DRIVER,
247 HSW_PWR_WELL_ENABLE_REQUEST);
248
249 if (!is_enabled) {
250 DRM_DEBUG_KMS("Enabling power well\n");
251 if (wait_for((I915_READ(HSW_PWR_WELL_DRIVER) &
252 HSW_PWR_WELL_STATE_ENABLED), 20))
253 DRM_ERROR("Timeout enabling power well\n");
Paulo Zanoni6d729bf2014-10-07 16:11:11 -0300254 hsw_power_well_post_enable(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200255 }
256
Daniel Vetter9c065a72014-09-30 10:56:38 +0200257 } else {
258 if (enable_requested) {
259 I915_WRITE(HSW_PWR_WELL_DRIVER, 0);
260 POSTING_READ(HSW_PWR_WELL_DRIVER);
261 DRM_DEBUG_KMS("Requesting to disable the power well\n");
262 }
263 }
264}
265
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000266#define SKL_DISPLAY_POWERWELL_2_POWER_DOMAINS ( \
267 BIT(POWER_DOMAIN_TRANSCODER_A) | \
268 BIT(POWER_DOMAIN_PIPE_B) | \
269 BIT(POWER_DOMAIN_TRANSCODER_B) | \
270 BIT(POWER_DOMAIN_PIPE_C) | \
271 BIT(POWER_DOMAIN_TRANSCODER_C) | \
272 BIT(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
273 BIT(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
274 BIT(POWER_DOMAIN_PORT_DDI_B_2_LANES) | \
275 BIT(POWER_DOMAIN_PORT_DDI_B_4_LANES) | \
276 BIT(POWER_DOMAIN_PORT_DDI_C_2_LANES) | \
277 BIT(POWER_DOMAIN_PORT_DDI_C_4_LANES) | \
278 BIT(POWER_DOMAIN_PORT_DDI_D_2_LANES) | \
279 BIT(POWER_DOMAIN_PORT_DDI_D_4_LANES) | \
280 BIT(POWER_DOMAIN_AUX_B) | \
281 BIT(POWER_DOMAIN_AUX_C) | \
282 BIT(POWER_DOMAIN_AUX_D) | \
283 BIT(POWER_DOMAIN_AUDIO) | \
284 BIT(POWER_DOMAIN_VGA) | \
285 BIT(POWER_DOMAIN_INIT))
286#define SKL_DISPLAY_POWERWELL_1_POWER_DOMAINS ( \
287 SKL_DISPLAY_POWERWELL_2_POWER_DOMAINS | \
288 BIT(POWER_DOMAIN_PLLS) | \
289 BIT(POWER_DOMAIN_PIPE_A) | \
290 BIT(POWER_DOMAIN_TRANSCODER_EDP) | \
291 BIT(POWER_DOMAIN_PIPE_A_PANEL_FITTER) | \
292 BIT(POWER_DOMAIN_PORT_DDI_A_2_LANES) | \
293 BIT(POWER_DOMAIN_PORT_DDI_A_4_LANES) | \
294 BIT(POWER_DOMAIN_AUX_A) | \
295 BIT(POWER_DOMAIN_INIT))
296#define SKL_DISPLAY_DDI_A_E_POWER_DOMAINS ( \
297 BIT(POWER_DOMAIN_PORT_DDI_A_2_LANES) | \
298 BIT(POWER_DOMAIN_PORT_DDI_A_4_LANES) | \
299 BIT(POWER_DOMAIN_INIT))
300#define SKL_DISPLAY_DDI_B_POWER_DOMAINS ( \
301 BIT(POWER_DOMAIN_PORT_DDI_B_2_LANES) | \
302 BIT(POWER_DOMAIN_PORT_DDI_B_4_LANES) | \
303 BIT(POWER_DOMAIN_INIT))
304#define SKL_DISPLAY_DDI_C_POWER_DOMAINS ( \
305 BIT(POWER_DOMAIN_PORT_DDI_C_2_LANES) | \
306 BIT(POWER_DOMAIN_PORT_DDI_C_4_LANES) | \
307 BIT(POWER_DOMAIN_INIT))
308#define SKL_DISPLAY_DDI_D_POWER_DOMAINS ( \
309 BIT(POWER_DOMAIN_PORT_DDI_D_2_LANES) | \
310 BIT(POWER_DOMAIN_PORT_DDI_D_4_LANES) | \
311 BIT(POWER_DOMAIN_INIT))
312#define SKL_DISPLAY_MISC_IO_POWER_DOMAINS ( \
313 SKL_DISPLAY_POWERWELL_1_POWER_DOMAINS)
314#define SKL_DISPLAY_ALWAYS_ON_POWER_DOMAINS ( \
315 (POWER_DOMAIN_MASK & ~(SKL_DISPLAY_POWERWELL_1_POWER_DOMAINS | \
316 SKL_DISPLAY_POWERWELL_2_POWER_DOMAINS | \
317 SKL_DISPLAY_DDI_A_E_POWER_DOMAINS | \
318 SKL_DISPLAY_DDI_B_POWER_DOMAINS | \
319 SKL_DISPLAY_DDI_C_POWER_DOMAINS | \
320 SKL_DISPLAY_DDI_D_POWER_DOMAINS | \
321 SKL_DISPLAY_MISC_IO_POWER_DOMAINS)) | \
322 BIT(POWER_DOMAIN_INIT))
323
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +0530324#define BXT_DISPLAY_POWERWELL_2_POWER_DOMAINS ( \
325 BIT(POWER_DOMAIN_TRANSCODER_A) | \
326 BIT(POWER_DOMAIN_PIPE_B) | \
327 BIT(POWER_DOMAIN_TRANSCODER_B) | \
328 BIT(POWER_DOMAIN_PIPE_C) | \
329 BIT(POWER_DOMAIN_TRANSCODER_C) | \
330 BIT(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
331 BIT(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
332 BIT(POWER_DOMAIN_PORT_DDI_B_2_LANES) | \
333 BIT(POWER_DOMAIN_PORT_DDI_B_4_LANES) | \
334 BIT(POWER_DOMAIN_PORT_DDI_C_2_LANES) | \
335 BIT(POWER_DOMAIN_PORT_DDI_C_4_LANES) | \
336 BIT(POWER_DOMAIN_AUX_B) | \
337 BIT(POWER_DOMAIN_AUX_C) | \
338 BIT(POWER_DOMAIN_AUDIO) | \
339 BIT(POWER_DOMAIN_VGA) | \
340 BIT(POWER_DOMAIN_INIT))
341#define BXT_DISPLAY_POWERWELL_1_POWER_DOMAINS ( \
342 BXT_DISPLAY_POWERWELL_2_POWER_DOMAINS | \
343 BIT(POWER_DOMAIN_PIPE_A) | \
344 BIT(POWER_DOMAIN_TRANSCODER_EDP) | \
345 BIT(POWER_DOMAIN_PIPE_A_PANEL_FITTER) | \
346 BIT(POWER_DOMAIN_PORT_DDI_A_2_LANES) | \
347 BIT(POWER_DOMAIN_PORT_DDI_A_4_LANES) | \
348 BIT(POWER_DOMAIN_AUX_A) | \
349 BIT(POWER_DOMAIN_PLLS) | \
350 BIT(POWER_DOMAIN_INIT))
351#define BXT_DISPLAY_ALWAYS_ON_POWER_DOMAINS ( \
352 (POWER_DOMAIN_MASK & ~(BXT_DISPLAY_POWERWELL_1_POWER_DOMAINS | \
353 BXT_DISPLAY_POWERWELL_2_POWER_DOMAINS)) | \
354 BIT(POWER_DOMAIN_INIT))
355
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530356static void assert_can_enable_dc9(struct drm_i915_private *dev_priv)
357{
358 struct drm_device *dev = dev_priv->dev;
359
360 WARN(!IS_BROXTON(dev), "Platform doesn't support DC9.\n");
361 WARN((I915_READ(DC_STATE_EN) & DC_STATE_EN_DC9),
362 "DC9 already programmed to be enabled.\n");
363 WARN(I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC5,
364 "DC5 still not disabled to enable DC9.\n");
365 WARN(I915_READ(HSW_PWR_WELL_DRIVER), "Power well on.\n");
366 WARN(intel_irqs_enabled(dev_priv), "Interrupts not disabled yet.\n");
367
368 /*
369 * TODO: check for the following to verify the conditions to enter DC9
370 * state are satisfied:
371 * 1] Check relevant display engine registers to verify if mode set
372 * disable sequence was followed.
373 * 2] Check if display uninitialize sequence is initialized.
374 */
375}
376
377static void assert_can_disable_dc9(struct drm_i915_private *dev_priv)
378{
379 WARN(intel_irqs_enabled(dev_priv), "Interrupts not disabled yet.\n");
380 WARN(!(I915_READ(DC_STATE_EN) & DC_STATE_EN_DC9),
381 "DC9 already programmed to be disabled.\n");
382 WARN(I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC5,
383 "DC5 still not disabled.\n");
384
385 /*
386 * TODO: check for the following to verify DC9 state was indeed
387 * entered before programming to disable it:
388 * 1] Check relevant display engine registers to verify if mode
389 * set disable sequence was followed.
390 * 2] Check if display uninitialize sequence is initialized.
391 */
392}
393
394void bxt_enable_dc9(struct drm_i915_private *dev_priv)
395{
396 uint32_t val;
397
398 assert_can_enable_dc9(dev_priv);
399
400 DRM_DEBUG_KMS("Enabling DC9\n");
401
402 val = I915_READ(DC_STATE_EN);
403 val |= DC_STATE_EN_DC9;
404 I915_WRITE(DC_STATE_EN, val);
405 POSTING_READ(DC_STATE_EN);
406}
407
408void bxt_disable_dc9(struct drm_i915_private *dev_priv)
409{
410 uint32_t val;
411
412 assert_can_disable_dc9(dev_priv);
413
414 DRM_DEBUG_KMS("Disabling DC9\n");
415
416 val = I915_READ(DC_STATE_EN);
417 val &= ~DC_STATE_EN_DC9;
418 I915_WRITE(DC_STATE_EN, val);
419 POSTING_READ(DC_STATE_EN);
420}
421
Suketu Shahdc174302015-04-17 19:46:16 +0530422static void gen9_enable_dc5(struct drm_i915_private *dev_priv)
423{
424 /* TODO: Implementation to be done. */
425}
426
427static void gen9_disable_dc5(struct drm_i915_private *dev_priv)
428{
429 /* TODO: Implementation to be done. */
430}
431
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000432static void skl_set_power_well(struct drm_i915_private *dev_priv,
433 struct i915_power_well *power_well, bool enable)
434{
Suketu Shahdc174302015-04-17 19:46:16 +0530435 struct drm_device *dev = dev_priv->dev;
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000436 uint32_t tmp, fuse_status;
437 uint32_t req_mask, state_mask;
Damien Lespiau2a518352015-03-06 18:50:49 +0000438 bool is_enabled, enable_requested, check_fuse_status = false;
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000439
440 tmp = I915_READ(HSW_PWR_WELL_DRIVER);
441 fuse_status = I915_READ(SKL_FUSE_STATUS);
442
443 switch (power_well->data) {
444 case SKL_DISP_PW_1:
445 if (wait_for((I915_READ(SKL_FUSE_STATUS) &
446 SKL_FUSE_PG0_DIST_STATUS), 1)) {
447 DRM_ERROR("PG0 not enabled\n");
448 return;
449 }
450 break;
451 case SKL_DISP_PW_2:
452 if (!(fuse_status & SKL_FUSE_PG1_DIST_STATUS)) {
453 DRM_ERROR("PG1 in disabled state\n");
454 return;
455 }
456 break;
457 case SKL_DISP_PW_DDI_A_E:
458 case SKL_DISP_PW_DDI_B:
459 case SKL_DISP_PW_DDI_C:
460 case SKL_DISP_PW_DDI_D:
461 case SKL_DISP_PW_MISC_IO:
462 break;
463 default:
464 WARN(1, "Unknown power well %lu\n", power_well->data);
465 return;
466 }
467
468 req_mask = SKL_POWER_WELL_REQ(power_well->data);
Damien Lespiau2a518352015-03-06 18:50:49 +0000469 enable_requested = tmp & req_mask;
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000470 state_mask = SKL_POWER_WELL_STATE(power_well->data);
Damien Lespiau2a518352015-03-06 18:50:49 +0000471 is_enabled = tmp & state_mask;
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000472
473 if (enable) {
Damien Lespiau2a518352015-03-06 18:50:49 +0000474 if (!enable_requested) {
Suketu Shahdc174302015-04-17 19:46:16 +0530475 WARN((tmp & state_mask) &&
476 !I915_READ(HSW_PWR_WELL_BIOS),
477 "Invalid for power well status to be enabled, unless done by the BIOS, \
478 when request is to disable!\n");
479 if (GEN9_ENABLE_DC5(dev) &&
480 power_well->data == SKL_DISP_PW_2)
481 gen9_disable_dc5(dev_priv);
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000482 I915_WRITE(HSW_PWR_WELL_DRIVER, tmp | req_mask);
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000483 }
484
Damien Lespiau2a518352015-03-06 18:50:49 +0000485 if (!is_enabled) {
Damien Lespiau510e6fd2015-03-06 18:50:50 +0000486 DRM_DEBUG_KMS("Enabling %s\n", power_well->name);
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000487 if (wait_for((I915_READ(HSW_PWR_WELL_DRIVER) &
488 state_mask), 1))
489 DRM_ERROR("%s enable timeout\n",
490 power_well->name);
491 check_fuse_status = true;
492 }
493 } else {
Damien Lespiau2a518352015-03-06 18:50:49 +0000494 if (enable_requested) {
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000495 I915_WRITE(HSW_PWR_WELL_DRIVER, tmp & ~req_mask);
496 POSTING_READ(HSW_PWR_WELL_DRIVER);
497 DRM_DEBUG_KMS("Disabling %s\n", power_well->name);
Suketu Shahdc174302015-04-17 19:46:16 +0530498
499 if (GEN9_ENABLE_DC5(dev) &&
500 power_well->data == SKL_DISP_PW_2) {
501 enum csr_state state;
502
503 wait_for((state = intel_csr_load_status_get(dev_priv)) !=
504 FW_UNINITIALIZED, 1000);
505 if (state != FW_LOADED)
506 DRM_ERROR("CSR firmware not ready (%d)\n",
507 state);
508 else
509 gen9_enable_dc5(dev_priv);
510 }
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000511 }
512 }
513
514 if (check_fuse_status) {
515 if (power_well->data == SKL_DISP_PW_1) {
516 if (wait_for((I915_READ(SKL_FUSE_STATUS) &
517 SKL_FUSE_PG1_DIST_STATUS), 1))
518 DRM_ERROR("PG1 distributing status timeout\n");
519 } else if (power_well->data == SKL_DISP_PW_2) {
520 if (wait_for((I915_READ(SKL_FUSE_STATUS) &
521 SKL_FUSE_PG2_DIST_STATUS), 1))
522 DRM_ERROR("PG2 distributing status timeout\n");
523 }
524 }
Damien Lespiaud14c0342015-03-06 18:50:51 +0000525
526 if (enable && !is_enabled)
527 skl_power_well_post_enable(dev_priv, power_well);
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000528}
529
Daniel Vetter9c065a72014-09-30 10:56:38 +0200530static void hsw_power_well_sync_hw(struct drm_i915_private *dev_priv,
531 struct i915_power_well *power_well)
532{
533 hsw_set_power_well(dev_priv, power_well, power_well->count > 0);
534
535 /*
536 * We're taking over the BIOS, so clear any requests made by it since
537 * the driver is in charge now.
538 */
539 if (I915_READ(HSW_PWR_WELL_BIOS) & HSW_PWR_WELL_ENABLE_REQUEST)
540 I915_WRITE(HSW_PWR_WELL_BIOS, 0);
541}
542
543static void hsw_power_well_enable(struct drm_i915_private *dev_priv,
544 struct i915_power_well *power_well)
545{
546 hsw_set_power_well(dev_priv, power_well, true);
547}
548
549static void hsw_power_well_disable(struct drm_i915_private *dev_priv,
550 struct i915_power_well *power_well)
551{
552 hsw_set_power_well(dev_priv, power_well, false);
553}
554
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000555static bool skl_power_well_enabled(struct drm_i915_private *dev_priv,
556 struct i915_power_well *power_well)
557{
558 uint32_t mask = SKL_POWER_WELL_REQ(power_well->data) |
559 SKL_POWER_WELL_STATE(power_well->data);
560
561 return (I915_READ(HSW_PWR_WELL_DRIVER) & mask) == mask;
562}
563
564static void skl_power_well_sync_hw(struct drm_i915_private *dev_priv,
565 struct i915_power_well *power_well)
566{
567 skl_set_power_well(dev_priv, power_well, power_well->count > 0);
568
569 /* Clear any request made by BIOS as driver is taking over */
570 I915_WRITE(HSW_PWR_WELL_BIOS, 0);
571}
572
573static void skl_power_well_enable(struct drm_i915_private *dev_priv,
574 struct i915_power_well *power_well)
575{
576 skl_set_power_well(dev_priv, power_well, true);
577}
578
579static void skl_power_well_disable(struct drm_i915_private *dev_priv,
580 struct i915_power_well *power_well)
581{
582 skl_set_power_well(dev_priv, power_well, false);
583}
584
Daniel Vetter9c065a72014-09-30 10:56:38 +0200585static void i9xx_always_on_power_well_noop(struct drm_i915_private *dev_priv,
586 struct i915_power_well *power_well)
587{
588}
589
590static bool i9xx_always_on_power_well_enabled(struct drm_i915_private *dev_priv,
591 struct i915_power_well *power_well)
592{
593 return true;
594}
595
596static void vlv_set_power_well(struct drm_i915_private *dev_priv,
597 struct i915_power_well *power_well, bool enable)
598{
599 enum punit_power_well power_well_id = power_well->data;
600 u32 mask;
601 u32 state;
602 u32 ctrl;
603
604 mask = PUNIT_PWRGT_MASK(power_well_id);
605 state = enable ? PUNIT_PWRGT_PWR_ON(power_well_id) :
606 PUNIT_PWRGT_PWR_GATE(power_well_id);
607
608 mutex_lock(&dev_priv->rps.hw_lock);
609
610#define COND \
611 ((vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_STATUS) & mask) == state)
612
613 if (COND)
614 goto out;
615
616 ctrl = vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_CTRL);
617 ctrl &= ~mask;
618 ctrl |= state;
619 vlv_punit_write(dev_priv, PUNIT_REG_PWRGT_CTRL, ctrl);
620
621 if (wait_for(COND, 100))
622 DRM_ERROR("timout setting power well state %08x (%08x)\n",
623 state,
624 vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_CTRL));
625
626#undef COND
627
628out:
629 mutex_unlock(&dev_priv->rps.hw_lock);
630}
631
632static void vlv_power_well_sync_hw(struct drm_i915_private *dev_priv,
633 struct i915_power_well *power_well)
634{
635 vlv_set_power_well(dev_priv, power_well, power_well->count > 0);
636}
637
638static void vlv_power_well_enable(struct drm_i915_private *dev_priv,
639 struct i915_power_well *power_well)
640{
641 vlv_set_power_well(dev_priv, power_well, true);
642}
643
644static void vlv_power_well_disable(struct drm_i915_private *dev_priv,
645 struct i915_power_well *power_well)
646{
647 vlv_set_power_well(dev_priv, power_well, false);
648}
649
650static bool vlv_power_well_enabled(struct drm_i915_private *dev_priv,
651 struct i915_power_well *power_well)
652{
653 int power_well_id = power_well->data;
654 bool enabled = false;
655 u32 mask;
656 u32 state;
657 u32 ctrl;
658
659 mask = PUNIT_PWRGT_MASK(power_well_id);
660 ctrl = PUNIT_PWRGT_PWR_ON(power_well_id);
661
662 mutex_lock(&dev_priv->rps.hw_lock);
663
664 state = vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_STATUS) & mask;
665 /*
666 * We only ever set the power-on and power-gate states, anything
667 * else is unexpected.
668 */
669 WARN_ON(state != PUNIT_PWRGT_PWR_ON(power_well_id) &&
670 state != PUNIT_PWRGT_PWR_GATE(power_well_id));
671 if (state == ctrl)
672 enabled = true;
673
674 /*
675 * A transient state at this point would mean some unexpected party
676 * is poking at the power controls too.
677 */
678 ctrl = vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_CTRL) & mask;
679 WARN_ON(ctrl != state);
680
681 mutex_unlock(&dev_priv->rps.hw_lock);
682
683 return enabled;
684}
685
686static void vlv_display_power_well_enable(struct drm_i915_private *dev_priv,
687 struct i915_power_well *power_well)
688{
689 WARN_ON_ONCE(power_well->data != PUNIT_POWER_WELL_DISP2D);
690
691 vlv_set_power_well(dev_priv, power_well, true);
692
693 spin_lock_irq(&dev_priv->irq_lock);
694 valleyview_enable_display_irqs(dev_priv);
695 spin_unlock_irq(&dev_priv->irq_lock);
696
697 /*
698 * During driver initialization/resume we can avoid restoring the
699 * part of the HW/SW state that will be inited anyway explicitly.
700 */
701 if (dev_priv->power_domains.initializing)
702 return;
703
Daniel Vetterb9632912014-09-30 10:56:44 +0200704 intel_hpd_init(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200705
706 i915_redisable_vga_power_on(dev_priv->dev);
707}
708
709static void vlv_display_power_well_disable(struct drm_i915_private *dev_priv,
710 struct i915_power_well *power_well)
711{
712 WARN_ON_ONCE(power_well->data != PUNIT_POWER_WELL_DISP2D);
713
714 spin_lock_irq(&dev_priv->irq_lock);
715 valleyview_disable_display_irqs(dev_priv);
716 spin_unlock_irq(&dev_priv->irq_lock);
717
718 vlv_set_power_well(dev_priv, power_well, false);
719
720 vlv_power_sequencer_reset(dev_priv);
721}
722
723static void vlv_dpio_cmn_power_well_enable(struct drm_i915_private *dev_priv,
724 struct i915_power_well *power_well)
725{
726 WARN_ON_ONCE(power_well->data != PUNIT_POWER_WELL_DPIO_CMN_BC);
727
728 /*
729 * Enable the CRI clock source so we can get at the
730 * display and the reference clock for VGA
731 * hotplug / manual detection.
732 */
733 I915_WRITE(DPLL(PIPE_B), I915_READ(DPLL(PIPE_B)) |
734 DPLL_REFA_CLK_ENABLE_VLV | DPLL_INTEGRATED_CRI_CLK_VLV);
735 udelay(1); /* >10ns for cmnreset, >0ns for sidereset */
736
737 vlv_set_power_well(dev_priv, power_well, true);
738
739 /*
740 * From VLV2A0_DP_eDP_DPIO_driver_vbios_notes_10.docx -
741 * 6. De-assert cmn_reset/side_reset. Same as VLV X0.
742 * a. GUnit 0x2110 bit[0] set to 1 (def 0)
743 * b. The other bits such as sfr settings / modesel may all
744 * be set to 0.
745 *
746 * This should only be done on init and resume from S3 with
747 * both PLLs disabled, or we risk losing DPIO and PLL
748 * synchronization.
749 */
750 I915_WRITE(DPIO_CTL, I915_READ(DPIO_CTL) | DPIO_CMNRST);
751}
752
753static void vlv_dpio_cmn_power_well_disable(struct drm_i915_private *dev_priv,
754 struct i915_power_well *power_well)
755{
756 enum pipe pipe;
757
758 WARN_ON_ONCE(power_well->data != PUNIT_POWER_WELL_DPIO_CMN_BC);
759
760 for_each_pipe(dev_priv, pipe)
761 assert_pll_disabled(dev_priv, pipe);
762
763 /* Assert common reset */
764 I915_WRITE(DPIO_CTL, I915_READ(DPIO_CTL) & ~DPIO_CMNRST);
765
766 vlv_set_power_well(dev_priv, power_well, false);
767}
768
769static void chv_dpio_cmn_power_well_enable(struct drm_i915_private *dev_priv,
770 struct i915_power_well *power_well)
771{
772 enum dpio_phy phy;
773
774 WARN_ON_ONCE(power_well->data != PUNIT_POWER_WELL_DPIO_CMN_BC &&
775 power_well->data != PUNIT_POWER_WELL_DPIO_CMN_D);
776
777 /*
778 * Enable the CRI clock source so we can get at the
779 * display and the reference clock for VGA
780 * hotplug / manual detection.
781 */
782 if (power_well->data == PUNIT_POWER_WELL_DPIO_CMN_BC) {
783 phy = DPIO_PHY0;
784 I915_WRITE(DPLL(PIPE_B), I915_READ(DPLL(PIPE_B)) |
785 DPLL_REFA_CLK_ENABLE_VLV);
786 I915_WRITE(DPLL(PIPE_B), I915_READ(DPLL(PIPE_B)) |
787 DPLL_REFA_CLK_ENABLE_VLV | DPLL_INTEGRATED_CRI_CLK_VLV);
788 } else {
789 phy = DPIO_PHY1;
790 I915_WRITE(DPLL(PIPE_C), I915_READ(DPLL(PIPE_C)) |
791 DPLL_REFA_CLK_ENABLE_VLV | DPLL_INTEGRATED_CRI_CLK_VLV);
792 }
793 udelay(1); /* >10ns for cmnreset, >0ns for sidereset */
794 vlv_set_power_well(dev_priv, power_well, true);
795
796 /* Poll for phypwrgood signal */
797 if (wait_for(I915_READ(DISPLAY_PHY_STATUS) & PHY_POWERGOOD(phy), 1))
798 DRM_ERROR("Display PHY %d is not power up\n", phy);
799
800 I915_WRITE(DISPLAY_PHY_CONTROL, I915_READ(DISPLAY_PHY_CONTROL) |
801 PHY_COM_LANE_RESET_DEASSERT(phy));
802}
803
804static void chv_dpio_cmn_power_well_disable(struct drm_i915_private *dev_priv,
805 struct i915_power_well *power_well)
806{
807 enum dpio_phy phy;
808
809 WARN_ON_ONCE(power_well->data != PUNIT_POWER_WELL_DPIO_CMN_BC &&
810 power_well->data != PUNIT_POWER_WELL_DPIO_CMN_D);
811
812 if (power_well->data == PUNIT_POWER_WELL_DPIO_CMN_BC) {
813 phy = DPIO_PHY0;
814 assert_pll_disabled(dev_priv, PIPE_A);
815 assert_pll_disabled(dev_priv, PIPE_B);
816 } else {
817 phy = DPIO_PHY1;
818 assert_pll_disabled(dev_priv, PIPE_C);
819 }
820
821 I915_WRITE(DISPLAY_PHY_CONTROL, I915_READ(DISPLAY_PHY_CONTROL) &
822 ~PHY_COM_LANE_RESET_DEASSERT(phy));
823
824 vlv_set_power_well(dev_priv, power_well, false);
825}
826
827static bool chv_pipe_power_well_enabled(struct drm_i915_private *dev_priv,
828 struct i915_power_well *power_well)
829{
830 enum pipe pipe = power_well->data;
831 bool enabled;
832 u32 state, ctrl;
833
834 mutex_lock(&dev_priv->rps.hw_lock);
835
836 state = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & DP_SSS_MASK(pipe);
837 /*
838 * We only ever set the power-on and power-gate states, anything
839 * else is unexpected.
840 */
841 WARN_ON(state != DP_SSS_PWR_ON(pipe) && state != DP_SSS_PWR_GATE(pipe));
842 enabled = state == DP_SSS_PWR_ON(pipe);
843
844 /*
845 * A transient state at this point would mean some unexpected party
846 * is poking at the power controls too.
847 */
848 ctrl = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & DP_SSC_MASK(pipe);
849 WARN_ON(ctrl << 16 != state);
850
851 mutex_unlock(&dev_priv->rps.hw_lock);
852
853 return enabled;
854}
855
856static void chv_set_pipe_power_well(struct drm_i915_private *dev_priv,
857 struct i915_power_well *power_well,
858 bool enable)
859{
860 enum pipe pipe = power_well->data;
861 u32 state;
862 u32 ctrl;
863
864 state = enable ? DP_SSS_PWR_ON(pipe) : DP_SSS_PWR_GATE(pipe);
865
866 mutex_lock(&dev_priv->rps.hw_lock);
867
868#define COND \
869 ((vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & DP_SSS_MASK(pipe)) == state)
870
871 if (COND)
872 goto out;
873
874 ctrl = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ);
875 ctrl &= ~DP_SSC_MASK(pipe);
876 ctrl |= enable ? DP_SSC_PWR_ON(pipe) : DP_SSC_PWR_GATE(pipe);
877 vlv_punit_write(dev_priv, PUNIT_REG_DSPFREQ, ctrl);
878
879 if (wait_for(COND, 100))
880 DRM_ERROR("timout setting power well state %08x (%08x)\n",
881 state,
882 vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ));
883
884#undef COND
885
886out:
887 mutex_unlock(&dev_priv->rps.hw_lock);
888}
889
890static void chv_pipe_power_well_sync_hw(struct drm_i915_private *dev_priv,
891 struct i915_power_well *power_well)
892{
893 chv_set_pipe_power_well(dev_priv, power_well, power_well->count > 0);
894}
895
896static void chv_pipe_power_well_enable(struct drm_i915_private *dev_priv,
897 struct i915_power_well *power_well)
898{
899 WARN_ON_ONCE(power_well->data != PIPE_A &&
900 power_well->data != PIPE_B &&
901 power_well->data != PIPE_C);
902
903 chv_set_pipe_power_well(dev_priv, power_well, true);
Ville Syrjäläafd62752014-10-30 19:43:03 +0200904
905 if (power_well->data == PIPE_A) {
906 spin_lock_irq(&dev_priv->irq_lock);
907 valleyview_enable_display_irqs(dev_priv);
908 spin_unlock_irq(&dev_priv->irq_lock);
909
910 /*
911 * During driver initialization/resume we can avoid restoring the
912 * part of the HW/SW state that will be inited anyway explicitly.
913 */
914 if (dev_priv->power_domains.initializing)
915 return;
916
917 intel_hpd_init(dev_priv);
918
919 i915_redisable_vga_power_on(dev_priv->dev);
920 }
Daniel Vetter9c065a72014-09-30 10:56:38 +0200921}
922
923static void chv_pipe_power_well_disable(struct drm_i915_private *dev_priv,
924 struct i915_power_well *power_well)
925{
926 WARN_ON_ONCE(power_well->data != PIPE_A &&
927 power_well->data != PIPE_B &&
928 power_well->data != PIPE_C);
929
Ville Syrjäläafd62752014-10-30 19:43:03 +0200930 if (power_well->data == PIPE_A) {
931 spin_lock_irq(&dev_priv->irq_lock);
932 valleyview_disable_display_irqs(dev_priv);
933 spin_unlock_irq(&dev_priv->irq_lock);
934 }
935
Daniel Vetter9c065a72014-09-30 10:56:38 +0200936 chv_set_pipe_power_well(dev_priv, power_well, false);
Ville Syrjäläbaa4e572014-10-27 16:07:32 +0200937
938 if (power_well->data == PIPE_A)
939 vlv_power_sequencer_reset(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200940}
941
Daniel Vettere4e76842014-09-30 10:56:42 +0200942/**
943 * intel_display_power_get - grab a power domain reference
944 * @dev_priv: i915 device instance
945 * @domain: power domain to reference
946 *
947 * This function grabs a power domain reference for @domain and ensures that the
948 * power domain and all its parents are powered up. Therefore users should only
949 * grab a reference to the innermost power domain they need.
950 *
951 * Any power domain reference obtained by this function must have a symmetric
952 * call to intel_display_power_put() to release the reference again.
953 */
Daniel Vetter9c065a72014-09-30 10:56:38 +0200954void intel_display_power_get(struct drm_i915_private *dev_priv,
955 enum intel_display_power_domain domain)
956{
957 struct i915_power_domains *power_domains;
958 struct i915_power_well *power_well;
959 int i;
960
961 intel_runtime_pm_get(dev_priv);
962
963 power_domains = &dev_priv->power_domains;
964
965 mutex_lock(&power_domains->lock);
966
967 for_each_power_well(i, power_well, BIT(domain), power_domains) {
968 if (!power_well->count++) {
969 DRM_DEBUG_KMS("enabling %s\n", power_well->name);
970 power_well->ops->enable(dev_priv, power_well);
971 power_well->hw_enabled = true;
972 }
Daniel Vetter9c065a72014-09-30 10:56:38 +0200973 }
974
975 power_domains->domain_use_count[domain]++;
976
977 mutex_unlock(&power_domains->lock);
978}
979
Daniel Vettere4e76842014-09-30 10:56:42 +0200980/**
981 * intel_display_power_put - release a power domain reference
982 * @dev_priv: i915 device instance
983 * @domain: power domain to reference
984 *
985 * This function drops the power domain reference obtained by
986 * intel_display_power_get() and might power down the corresponding hardware
987 * block right away if this is the last reference.
988 */
Daniel Vetter9c065a72014-09-30 10:56:38 +0200989void intel_display_power_put(struct drm_i915_private *dev_priv,
990 enum intel_display_power_domain domain)
991{
992 struct i915_power_domains *power_domains;
993 struct i915_power_well *power_well;
994 int i;
995
996 power_domains = &dev_priv->power_domains;
997
998 mutex_lock(&power_domains->lock);
999
1000 WARN_ON(!power_domains->domain_use_count[domain]);
1001 power_domains->domain_use_count[domain]--;
1002
1003 for_each_power_well_rev(i, power_well, BIT(domain), power_domains) {
1004 WARN_ON(!power_well->count);
1005
1006 if (!--power_well->count && i915.disable_power_well) {
1007 DRM_DEBUG_KMS("disabling %s\n", power_well->name);
1008 power_well->hw_enabled = false;
1009 power_well->ops->disable(dev_priv, power_well);
1010 }
Daniel Vetter9c065a72014-09-30 10:56:38 +02001011 }
1012
1013 mutex_unlock(&power_domains->lock);
1014
1015 intel_runtime_pm_put(dev_priv);
1016}
1017
1018#define POWER_DOMAIN_MASK (BIT(POWER_DOMAIN_NUM) - 1)
1019
1020#define HSW_ALWAYS_ON_POWER_DOMAINS ( \
1021 BIT(POWER_DOMAIN_PIPE_A) | \
1022 BIT(POWER_DOMAIN_TRANSCODER_EDP) | \
1023 BIT(POWER_DOMAIN_PORT_DDI_A_2_LANES) | \
1024 BIT(POWER_DOMAIN_PORT_DDI_A_4_LANES) | \
1025 BIT(POWER_DOMAIN_PORT_DDI_B_2_LANES) | \
1026 BIT(POWER_DOMAIN_PORT_DDI_B_4_LANES) | \
1027 BIT(POWER_DOMAIN_PORT_DDI_C_2_LANES) | \
1028 BIT(POWER_DOMAIN_PORT_DDI_C_4_LANES) | \
1029 BIT(POWER_DOMAIN_PORT_DDI_D_2_LANES) | \
1030 BIT(POWER_DOMAIN_PORT_DDI_D_4_LANES) | \
1031 BIT(POWER_DOMAIN_PORT_CRT) | \
1032 BIT(POWER_DOMAIN_PLLS) | \
Satheeshakrishna M14071212015-01-16 15:57:51 +00001033 BIT(POWER_DOMAIN_AUX_A) | \
1034 BIT(POWER_DOMAIN_AUX_B) | \
1035 BIT(POWER_DOMAIN_AUX_C) | \
1036 BIT(POWER_DOMAIN_AUX_D) | \
Daniel Vetter9c065a72014-09-30 10:56:38 +02001037 BIT(POWER_DOMAIN_INIT))
1038#define HSW_DISPLAY_POWER_DOMAINS ( \
1039 (POWER_DOMAIN_MASK & ~HSW_ALWAYS_ON_POWER_DOMAINS) | \
1040 BIT(POWER_DOMAIN_INIT))
1041
1042#define BDW_ALWAYS_ON_POWER_DOMAINS ( \
1043 HSW_ALWAYS_ON_POWER_DOMAINS | \
1044 BIT(POWER_DOMAIN_PIPE_A_PANEL_FITTER))
1045#define BDW_DISPLAY_POWER_DOMAINS ( \
1046 (POWER_DOMAIN_MASK & ~BDW_ALWAYS_ON_POWER_DOMAINS) | \
1047 BIT(POWER_DOMAIN_INIT))
1048
1049#define VLV_ALWAYS_ON_POWER_DOMAINS BIT(POWER_DOMAIN_INIT)
1050#define VLV_DISPLAY_POWER_DOMAINS POWER_DOMAIN_MASK
1051
1052#define VLV_DPIO_CMN_BC_POWER_DOMAINS ( \
1053 BIT(POWER_DOMAIN_PORT_DDI_B_2_LANES) | \
1054 BIT(POWER_DOMAIN_PORT_DDI_B_4_LANES) | \
1055 BIT(POWER_DOMAIN_PORT_DDI_C_2_LANES) | \
1056 BIT(POWER_DOMAIN_PORT_DDI_C_4_LANES) | \
1057 BIT(POWER_DOMAIN_PORT_CRT) | \
Satheeshakrishna M14071212015-01-16 15:57:51 +00001058 BIT(POWER_DOMAIN_AUX_B) | \
1059 BIT(POWER_DOMAIN_AUX_C) | \
Daniel Vetter9c065a72014-09-30 10:56:38 +02001060 BIT(POWER_DOMAIN_INIT))
1061
1062#define VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS ( \
1063 BIT(POWER_DOMAIN_PORT_DDI_B_2_LANES) | \
1064 BIT(POWER_DOMAIN_PORT_DDI_B_4_LANES) | \
Satheeshakrishna M14071212015-01-16 15:57:51 +00001065 BIT(POWER_DOMAIN_AUX_B) | \
Daniel Vetter9c065a72014-09-30 10:56:38 +02001066 BIT(POWER_DOMAIN_INIT))
1067
1068#define VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS ( \
1069 BIT(POWER_DOMAIN_PORT_DDI_B_4_LANES) | \
Satheeshakrishna M14071212015-01-16 15:57:51 +00001070 BIT(POWER_DOMAIN_AUX_B) | \
Daniel Vetter9c065a72014-09-30 10:56:38 +02001071 BIT(POWER_DOMAIN_INIT))
1072
1073#define VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS ( \
1074 BIT(POWER_DOMAIN_PORT_DDI_C_2_LANES) | \
1075 BIT(POWER_DOMAIN_PORT_DDI_C_4_LANES) | \
Satheeshakrishna M14071212015-01-16 15:57:51 +00001076 BIT(POWER_DOMAIN_AUX_C) | \
Daniel Vetter9c065a72014-09-30 10:56:38 +02001077 BIT(POWER_DOMAIN_INIT))
1078
1079#define VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS ( \
1080 BIT(POWER_DOMAIN_PORT_DDI_C_4_LANES) | \
Satheeshakrishna M14071212015-01-16 15:57:51 +00001081 BIT(POWER_DOMAIN_AUX_C) | \
Daniel Vetter9c065a72014-09-30 10:56:38 +02001082 BIT(POWER_DOMAIN_INIT))
1083
1084#define CHV_PIPE_A_POWER_DOMAINS ( \
1085 BIT(POWER_DOMAIN_PIPE_A) | \
1086 BIT(POWER_DOMAIN_INIT))
1087
1088#define CHV_PIPE_B_POWER_DOMAINS ( \
1089 BIT(POWER_DOMAIN_PIPE_B) | \
1090 BIT(POWER_DOMAIN_INIT))
1091
1092#define CHV_PIPE_C_POWER_DOMAINS ( \
1093 BIT(POWER_DOMAIN_PIPE_C) | \
1094 BIT(POWER_DOMAIN_INIT))
1095
1096#define CHV_DPIO_CMN_BC_POWER_DOMAINS ( \
1097 BIT(POWER_DOMAIN_PORT_DDI_B_2_LANES) | \
1098 BIT(POWER_DOMAIN_PORT_DDI_B_4_LANES) | \
1099 BIT(POWER_DOMAIN_PORT_DDI_C_2_LANES) | \
1100 BIT(POWER_DOMAIN_PORT_DDI_C_4_LANES) | \
Satheeshakrishna M14071212015-01-16 15:57:51 +00001101 BIT(POWER_DOMAIN_AUX_B) | \
1102 BIT(POWER_DOMAIN_AUX_C) | \
Daniel Vetter9c065a72014-09-30 10:56:38 +02001103 BIT(POWER_DOMAIN_INIT))
1104
1105#define CHV_DPIO_CMN_D_POWER_DOMAINS ( \
1106 BIT(POWER_DOMAIN_PORT_DDI_D_2_LANES) | \
1107 BIT(POWER_DOMAIN_PORT_DDI_D_4_LANES) | \
Satheeshakrishna M14071212015-01-16 15:57:51 +00001108 BIT(POWER_DOMAIN_AUX_D) | \
Daniel Vetter9c065a72014-09-30 10:56:38 +02001109 BIT(POWER_DOMAIN_INIT))
1110
1111#define CHV_DPIO_TX_D_LANES_01_POWER_DOMAINS ( \
1112 BIT(POWER_DOMAIN_PORT_DDI_D_2_LANES) | \
1113 BIT(POWER_DOMAIN_PORT_DDI_D_4_LANES) | \
Satheeshakrishna M14071212015-01-16 15:57:51 +00001114 BIT(POWER_DOMAIN_AUX_D) | \
Daniel Vetter9c065a72014-09-30 10:56:38 +02001115 BIT(POWER_DOMAIN_INIT))
1116
1117#define CHV_DPIO_TX_D_LANES_23_POWER_DOMAINS ( \
1118 BIT(POWER_DOMAIN_PORT_DDI_D_4_LANES) | \
Satheeshakrishna M14071212015-01-16 15:57:51 +00001119 BIT(POWER_DOMAIN_AUX_D) | \
Daniel Vetter9c065a72014-09-30 10:56:38 +02001120 BIT(POWER_DOMAIN_INIT))
1121
1122static const struct i915_power_well_ops i9xx_always_on_power_well_ops = {
1123 .sync_hw = i9xx_always_on_power_well_noop,
1124 .enable = i9xx_always_on_power_well_noop,
1125 .disable = i9xx_always_on_power_well_noop,
1126 .is_enabled = i9xx_always_on_power_well_enabled,
1127};
1128
1129static const struct i915_power_well_ops chv_pipe_power_well_ops = {
1130 .sync_hw = chv_pipe_power_well_sync_hw,
1131 .enable = chv_pipe_power_well_enable,
1132 .disable = chv_pipe_power_well_disable,
1133 .is_enabled = chv_pipe_power_well_enabled,
1134};
1135
1136static const struct i915_power_well_ops chv_dpio_cmn_power_well_ops = {
1137 .sync_hw = vlv_power_well_sync_hw,
1138 .enable = chv_dpio_cmn_power_well_enable,
1139 .disable = chv_dpio_cmn_power_well_disable,
1140 .is_enabled = vlv_power_well_enabled,
1141};
1142
1143static struct i915_power_well i9xx_always_on_power_well[] = {
1144 {
1145 .name = "always-on",
1146 .always_on = 1,
1147 .domains = POWER_DOMAIN_MASK,
1148 .ops = &i9xx_always_on_power_well_ops,
1149 },
1150};
1151
1152static const struct i915_power_well_ops hsw_power_well_ops = {
1153 .sync_hw = hsw_power_well_sync_hw,
1154 .enable = hsw_power_well_enable,
1155 .disable = hsw_power_well_disable,
1156 .is_enabled = hsw_power_well_enabled,
1157};
1158
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00001159static const struct i915_power_well_ops skl_power_well_ops = {
1160 .sync_hw = skl_power_well_sync_hw,
1161 .enable = skl_power_well_enable,
1162 .disable = skl_power_well_disable,
1163 .is_enabled = skl_power_well_enabled,
1164};
1165
Daniel Vetter9c065a72014-09-30 10:56:38 +02001166static struct i915_power_well hsw_power_wells[] = {
1167 {
1168 .name = "always-on",
1169 .always_on = 1,
1170 .domains = HSW_ALWAYS_ON_POWER_DOMAINS,
1171 .ops = &i9xx_always_on_power_well_ops,
1172 },
1173 {
1174 .name = "display",
1175 .domains = HSW_DISPLAY_POWER_DOMAINS,
1176 .ops = &hsw_power_well_ops,
1177 },
1178};
1179
1180static struct i915_power_well bdw_power_wells[] = {
1181 {
1182 .name = "always-on",
1183 .always_on = 1,
1184 .domains = BDW_ALWAYS_ON_POWER_DOMAINS,
1185 .ops = &i9xx_always_on_power_well_ops,
1186 },
1187 {
1188 .name = "display",
1189 .domains = BDW_DISPLAY_POWER_DOMAINS,
1190 .ops = &hsw_power_well_ops,
1191 },
1192};
1193
1194static const struct i915_power_well_ops vlv_display_power_well_ops = {
1195 .sync_hw = vlv_power_well_sync_hw,
1196 .enable = vlv_display_power_well_enable,
1197 .disable = vlv_display_power_well_disable,
1198 .is_enabled = vlv_power_well_enabled,
1199};
1200
1201static const struct i915_power_well_ops vlv_dpio_cmn_power_well_ops = {
1202 .sync_hw = vlv_power_well_sync_hw,
1203 .enable = vlv_dpio_cmn_power_well_enable,
1204 .disable = vlv_dpio_cmn_power_well_disable,
1205 .is_enabled = vlv_power_well_enabled,
1206};
1207
1208static const struct i915_power_well_ops vlv_dpio_power_well_ops = {
1209 .sync_hw = vlv_power_well_sync_hw,
1210 .enable = vlv_power_well_enable,
1211 .disable = vlv_power_well_disable,
1212 .is_enabled = vlv_power_well_enabled,
1213};
1214
1215static struct i915_power_well vlv_power_wells[] = {
1216 {
1217 .name = "always-on",
1218 .always_on = 1,
1219 .domains = VLV_ALWAYS_ON_POWER_DOMAINS,
1220 .ops = &i9xx_always_on_power_well_ops,
1221 },
1222 {
1223 .name = "display",
1224 .domains = VLV_DISPLAY_POWER_DOMAINS,
1225 .data = PUNIT_POWER_WELL_DISP2D,
1226 .ops = &vlv_display_power_well_ops,
1227 },
1228 {
1229 .name = "dpio-tx-b-01",
1230 .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
1231 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
1232 VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
1233 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
1234 .ops = &vlv_dpio_power_well_ops,
1235 .data = PUNIT_POWER_WELL_DPIO_TX_B_LANES_01,
1236 },
1237 {
1238 .name = "dpio-tx-b-23",
1239 .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
1240 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
1241 VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
1242 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
1243 .ops = &vlv_dpio_power_well_ops,
1244 .data = PUNIT_POWER_WELL_DPIO_TX_B_LANES_23,
1245 },
1246 {
1247 .name = "dpio-tx-c-01",
1248 .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
1249 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
1250 VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
1251 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
1252 .ops = &vlv_dpio_power_well_ops,
1253 .data = PUNIT_POWER_WELL_DPIO_TX_C_LANES_01,
1254 },
1255 {
1256 .name = "dpio-tx-c-23",
1257 .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
1258 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
1259 VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
1260 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
1261 .ops = &vlv_dpio_power_well_ops,
1262 .data = PUNIT_POWER_WELL_DPIO_TX_C_LANES_23,
1263 },
1264 {
1265 .name = "dpio-common",
1266 .domains = VLV_DPIO_CMN_BC_POWER_DOMAINS,
1267 .data = PUNIT_POWER_WELL_DPIO_CMN_BC,
1268 .ops = &vlv_dpio_cmn_power_well_ops,
1269 },
1270};
1271
1272static struct i915_power_well chv_power_wells[] = {
1273 {
1274 .name = "always-on",
1275 .always_on = 1,
1276 .domains = VLV_ALWAYS_ON_POWER_DOMAINS,
1277 .ops = &i9xx_always_on_power_well_ops,
1278 },
1279#if 0
1280 {
1281 .name = "display",
1282 .domains = VLV_DISPLAY_POWER_DOMAINS,
1283 .data = PUNIT_POWER_WELL_DISP2D,
1284 .ops = &vlv_display_power_well_ops,
1285 },
Ville Syrjäläbaa4e572014-10-27 16:07:32 +02001286#endif
Daniel Vetter9c065a72014-09-30 10:56:38 +02001287 {
1288 .name = "pipe-a",
Ville Syrjäläbaa4e572014-10-27 16:07:32 +02001289 /*
1290 * FIXME: pipe A power well seems to be the new disp2d well.
1291 * At least all registers seem to be housed there. Figure
1292 * out if this a a temporary situation in pre-production
1293 * hardware or a permanent state of affairs.
1294 */
1295 .domains = CHV_PIPE_A_POWER_DOMAINS | VLV_DISPLAY_POWER_DOMAINS,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001296 .data = PIPE_A,
1297 .ops = &chv_pipe_power_well_ops,
1298 },
Ville Syrjäläbaa4e572014-10-27 16:07:32 +02001299#if 0
Daniel Vetter9c065a72014-09-30 10:56:38 +02001300 {
1301 .name = "pipe-b",
1302 .domains = CHV_PIPE_B_POWER_DOMAINS,
1303 .data = PIPE_B,
1304 .ops = &chv_pipe_power_well_ops,
1305 },
1306 {
1307 .name = "pipe-c",
1308 .domains = CHV_PIPE_C_POWER_DOMAINS,
1309 .data = PIPE_C,
1310 .ops = &chv_pipe_power_well_ops,
1311 },
1312#endif
1313 {
1314 .name = "dpio-common-bc",
1315 /*
1316 * XXX: cmnreset for one PHY seems to disturb the other.
1317 * As a workaround keep both powered on at the same
1318 * time for now.
1319 */
1320 .domains = CHV_DPIO_CMN_BC_POWER_DOMAINS | CHV_DPIO_CMN_D_POWER_DOMAINS,
1321 .data = PUNIT_POWER_WELL_DPIO_CMN_BC,
1322 .ops = &chv_dpio_cmn_power_well_ops,
1323 },
1324 {
1325 .name = "dpio-common-d",
1326 /*
1327 * XXX: cmnreset for one PHY seems to disturb the other.
1328 * As a workaround keep both powered on at the same
1329 * time for now.
1330 */
1331 .domains = CHV_DPIO_CMN_BC_POWER_DOMAINS | CHV_DPIO_CMN_D_POWER_DOMAINS,
1332 .data = PUNIT_POWER_WELL_DPIO_CMN_D,
1333 .ops = &chv_dpio_cmn_power_well_ops,
1334 },
1335#if 0
1336 {
1337 .name = "dpio-tx-b-01",
1338 .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
1339 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS,
1340 .ops = &vlv_dpio_power_well_ops,
1341 .data = PUNIT_POWER_WELL_DPIO_TX_B_LANES_01,
1342 },
1343 {
1344 .name = "dpio-tx-b-23",
1345 .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
1346 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS,
1347 .ops = &vlv_dpio_power_well_ops,
1348 .data = PUNIT_POWER_WELL_DPIO_TX_B_LANES_23,
1349 },
1350 {
1351 .name = "dpio-tx-c-01",
1352 .domains = VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
1353 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
1354 .ops = &vlv_dpio_power_well_ops,
1355 .data = PUNIT_POWER_WELL_DPIO_TX_C_LANES_01,
1356 },
1357 {
1358 .name = "dpio-tx-c-23",
1359 .domains = VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
1360 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
1361 .ops = &vlv_dpio_power_well_ops,
1362 .data = PUNIT_POWER_WELL_DPIO_TX_C_LANES_23,
1363 },
1364 {
1365 .name = "dpio-tx-d-01",
1366 .domains = CHV_DPIO_TX_D_LANES_01_POWER_DOMAINS |
1367 CHV_DPIO_TX_D_LANES_23_POWER_DOMAINS,
1368 .ops = &vlv_dpio_power_well_ops,
1369 .data = PUNIT_POWER_WELL_DPIO_TX_D_LANES_01,
1370 },
1371 {
1372 .name = "dpio-tx-d-23",
1373 .domains = CHV_DPIO_TX_D_LANES_01_POWER_DOMAINS |
1374 CHV_DPIO_TX_D_LANES_23_POWER_DOMAINS,
1375 .ops = &vlv_dpio_power_well_ops,
1376 .data = PUNIT_POWER_WELL_DPIO_TX_D_LANES_23,
1377 },
1378#endif
1379};
1380
1381static struct i915_power_well *lookup_power_well(struct drm_i915_private *dev_priv,
1382 enum punit_power_well power_well_id)
1383{
1384 struct i915_power_domains *power_domains = &dev_priv->power_domains;
1385 struct i915_power_well *power_well;
1386 int i;
1387
1388 for_each_power_well(i, power_well, POWER_DOMAIN_MASK, power_domains) {
1389 if (power_well->data == power_well_id)
1390 return power_well;
1391 }
1392
1393 return NULL;
1394}
1395
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00001396static struct i915_power_well skl_power_wells[] = {
1397 {
1398 .name = "always-on",
1399 .always_on = 1,
1400 .domains = SKL_DISPLAY_ALWAYS_ON_POWER_DOMAINS,
1401 .ops = &i9xx_always_on_power_well_ops,
1402 },
1403 {
1404 .name = "power well 1",
1405 .domains = SKL_DISPLAY_POWERWELL_1_POWER_DOMAINS,
1406 .ops = &skl_power_well_ops,
1407 .data = SKL_DISP_PW_1,
1408 },
1409 {
1410 .name = "MISC IO power well",
1411 .domains = SKL_DISPLAY_MISC_IO_POWER_DOMAINS,
1412 .ops = &skl_power_well_ops,
1413 .data = SKL_DISP_PW_MISC_IO,
1414 },
1415 {
1416 .name = "power well 2",
1417 .domains = SKL_DISPLAY_POWERWELL_2_POWER_DOMAINS,
1418 .ops = &skl_power_well_ops,
1419 .data = SKL_DISP_PW_2,
1420 },
1421 {
1422 .name = "DDI A/E power well",
1423 .domains = SKL_DISPLAY_DDI_A_E_POWER_DOMAINS,
1424 .ops = &skl_power_well_ops,
1425 .data = SKL_DISP_PW_DDI_A_E,
1426 },
1427 {
1428 .name = "DDI B power well",
1429 .domains = SKL_DISPLAY_DDI_B_POWER_DOMAINS,
1430 .ops = &skl_power_well_ops,
1431 .data = SKL_DISP_PW_DDI_B,
1432 },
1433 {
1434 .name = "DDI C power well",
1435 .domains = SKL_DISPLAY_DDI_C_POWER_DOMAINS,
1436 .ops = &skl_power_well_ops,
1437 .data = SKL_DISP_PW_DDI_C,
1438 },
1439 {
1440 .name = "DDI D power well",
1441 .domains = SKL_DISPLAY_DDI_D_POWER_DOMAINS,
1442 .ops = &skl_power_well_ops,
1443 .data = SKL_DISP_PW_DDI_D,
1444 },
1445};
1446
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05301447static struct i915_power_well bxt_power_wells[] = {
1448 {
1449 .name = "always-on",
1450 .always_on = 1,
1451 .domains = BXT_DISPLAY_ALWAYS_ON_POWER_DOMAINS,
1452 .ops = &i9xx_always_on_power_well_ops,
1453 },
1454 {
1455 .name = "power well 1",
1456 .domains = BXT_DISPLAY_POWERWELL_1_POWER_DOMAINS,
1457 .ops = &skl_power_well_ops,
1458 .data = SKL_DISP_PW_1,
1459 },
1460 {
1461 .name = "power well 2",
1462 .domains = BXT_DISPLAY_POWERWELL_2_POWER_DOMAINS,
1463 .ops = &skl_power_well_ops,
1464 .data = SKL_DISP_PW_2,
1465 }
1466};
1467
Daniel Vetter9c065a72014-09-30 10:56:38 +02001468#define set_power_wells(power_domains, __power_wells) ({ \
1469 (power_domains)->power_wells = (__power_wells); \
1470 (power_domains)->power_well_count = ARRAY_SIZE(__power_wells); \
1471})
1472
Daniel Vettere4e76842014-09-30 10:56:42 +02001473/**
1474 * intel_power_domains_init - initializes the power domain structures
1475 * @dev_priv: i915 device instance
1476 *
1477 * Initializes the power domain structures for @dev_priv depending upon the
1478 * supported platform.
1479 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02001480int intel_power_domains_init(struct drm_i915_private *dev_priv)
1481{
1482 struct i915_power_domains *power_domains = &dev_priv->power_domains;
1483
1484 mutex_init(&power_domains->lock);
1485
1486 /*
1487 * The enabling order will be from lower to higher indexed wells,
1488 * the disabling order is reversed.
1489 */
1490 if (IS_HASWELL(dev_priv->dev)) {
1491 set_power_wells(power_domains, hsw_power_wells);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001492 } else if (IS_BROADWELL(dev_priv->dev)) {
1493 set_power_wells(power_domains, bdw_power_wells);
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00001494 } else if (IS_SKYLAKE(dev_priv->dev)) {
1495 set_power_wells(power_domains, skl_power_wells);
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05301496 } else if (IS_BROXTON(dev_priv->dev)) {
1497 set_power_wells(power_domains, bxt_power_wells);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001498 } else if (IS_CHERRYVIEW(dev_priv->dev)) {
1499 set_power_wells(power_domains, chv_power_wells);
1500 } else if (IS_VALLEYVIEW(dev_priv->dev)) {
1501 set_power_wells(power_domains, vlv_power_wells);
1502 } else {
1503 set_power_wells(power_domains, i9xx_always_on_power_well);
1504 }
1505
1506 return 0;
1507}
1508
Daniel Vetter41373cd2014-09-30 10:56:41 +02001509static void intel_runtime_pm_disable(struct drm_i915_private *dev_priv)
1510{
1511 struct drm_device *dev = dev_priv->dev;
1512 struct device *device = &dev->pdev->dev;
1513
1514 if (!HAS_RUNTIME_PM(dev))
1515 return;
1516
1517 if (!intel_enable_rc6(dev))
1518 return;
1519
1520 /* Make sure we're not suspended first. */
1521 pm_runtime_get_sync(device);
1522 pm_runtime_disable(device);
1523}
1524
Daniel Vettere4e76842014-09-30 10:56:42 +02001525/**
1526 * intel_power_domains_fini - finalizes the power domain structures
1527 * @dev_priv: i915 device instance
1528 *
1529 * Finalizes the power domain structures for @dev_priv depending upon the
1530 * supported platform. This function also disables runtime pm and ensures that
1531 * the device stays powered up so that the driver can be reloaded.
1532 */
Daniel Vetterf458ebb2014-09-30 10:56:39 +02001533void intel_power_domains_fini(struct drm_i915_private *dev_priv)
Daniel Vetter9c065a72014-09-30 10:56:38 +02001534{
Daniel Vetter41373cd2014-09-30 10:56:41 +02001535 intel_runtime_pm_disable(dev_priv);
1536
Daniel Vetterf458ebb2014-09-30 10:56:39 +02001537 /* The i915.ko module is still not prepared to be loaded when
1538 * the power well is not enabled, so just enable it in case
1539 * we're going to unload/reload. */
1540 intel_display_set_init_power(dev_priv, true);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001541}
1542
1543static void intel_power_domains_resume(struct drm_i915_private *dev_priv)
1544{
1545 struct i915_power_domains *power_domains = &dev_priv->power_domains;
1546 struct i915_power_well *power_well;
1547 int i;
1548
1549 mutex_lock(&power_domains->lock);
1550 for_each_power_well(i, power_well, POWER_DOMAIN_MASK, power_domains) {
1551 power_well->ops->sync_hw(dev_priv, power_well);
1552 power_well->hw_enabled = power_well->ops->is_enabled(dev_priv,
1553 power_well);
1554 }
1555 mutex_unlock(&power_domains->lock);
1556}
1557
1558static void vlv_cmnlane_wa(struct drm_i915_private *dev_priv)
1559{
1560 struct i915_power_well *cmn =
1561 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_BC);
1562 struct i915_power_well *disp2d =
1563 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DISP2D);
1564
Daniel Vetter9c065a72014-09-30 10:56:38 +02001565 /* If the display might be already active skip this */
Ville Syrjälä5d93a6e2014-10-16 20:52:33 +03001566 if (cmn->ops->is_enabled(dev_priv, cmn) &&
1567 disp2d->ops->is_enabled(dev_priv, disp2d) &&
Daniel Vetter9c065a72014-09-30 10:56:38 +02001568 I915_READ(DPIO_CTL) & DPIO_CMNRST)
1569 return;
1570
1571 DRM_DEBUG_KMS("toggling display PHY side reset\n");
1572
1573 /* cmnlane needs DPLL registers */
1574 disp2d->ops->enable(dev_priv, disp2d);
1575
1576 /*
1577 * From VLV2A0_DP_eDP_HDMI_DPIO_driver_vbios_notes_11.docx:
1578 * Need to assert and de-assert PHY SB reset by gating the
1579 * common lane power, then un-gating it.
1580 * Simply ungating isn't enough to reset the PHY enough to get
1581 * ports and lanes running.
1582 */
1583 cmn->ops->disable(dev_priv, cmn);
1584}
1585
Daniel Vettere4e76842014-09-30 10:56:42 +02001586/**
1587 * intel_power_domains_init_hw - initialize hardware power domain state
1588 * @dev_priv: i915 device instance
1589 *
1590 * This function initializes the hardware power domain state and enables all
1591 * power domains using intel_display_set_init_power().
1592 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02001593void intel_power_domains_init_hw(struct drm_i915_private *dev_priv)
1594{
1595 struct drm_device *dev = dev_priv->dev;
1596 struct i915_power_domains *power_domains = &dev_priv->power_domains;
1597
1598 power_domains->initializing = true;
1599
1600 if (IS_VALLEYVIEW(dev) && !IS_CHERRYVIEW(dev)) {
1601 mutex_lock(&power_domains->lock);
1602 vlv_cmnlane_wa(dev_priv);
1603 mutex_unlock(&power_domains->lock);
1604 }
1605
1606 /* For now, we need the power well to be always enabled. */
1607 intel_display_set_init_power(dev_priv, true);
1608 intel_power_domains_resume(dev_priv);
1609 power_domains->initializing = false;
1610}
1611
Daniel Vettere4e76842014-09-30 10:56:42 +02001612/**
Geert Uytterhoevenca2b1402015-03-09 21:21:08 +01001613 * intel_aux_display_runtime_get - grab an auxiliary power domain reference
Daniel Vettere4e76842014-09-30 10:56:42 +02001614 * @dev_priv: i915 device instance
1615 *
1616 * This function grabs a power domain reference for the auxiliary power domain
1617 * (for access to the GMBUS and DP AUX blocks) and ensures that it and all its
1618 * parents are powered up. Therefore users should only grab a reference to the
1619 * innermost power domain they need.
1620 *
1621 * Any power domain reference obtained by this function must have a symmetric
1622 * call to intel_aux_display_runtime_put() to release the reference again.
1623 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02001624void intel_aux_display_runtime_get(struct drm_i915_private *dev_priv)
1625{
1626 intel_runtime_pm_get(dev_priv);
1627}
1628
Daniel Vettere4e76842014-09-30 10:56:42 +02001629/**
Geert Uytterhoevenca2b1402015-03-09 21:21:08 +01001630 * intel_aux_display_runtime_put - release an auxiliary power domain reference
Daniel Vettere4e76842014-09-30 10:56:42 +02001631 * @dev_priv: i915 device instance
1632 *
Geert Uytterhoevenca2b1402015-03-09 21:21:08 +01001633 * This function drops the auxiliary power domain reference obtained by
Daniel Vettere4e76842014-09-30 10:56:42 +02001634 * intel_aux_display_runtime_get() and might power down the corresponding
1635 * hardware block right away if this is the last reference.
1636 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02001637void intel_aux_display_runtime_put(struct drm_i915_private *dev_priv)
1638{
1639 intel_runtime_pm_put(dev_priv);
1640}
1641
Daniel Vettere4e76842014-09-30 10:56:42 +02001642/**
1643 * intel_runtime_pm_get - grab a runtime pm reference
1644 * @dev_priv: i915 device instance
1645 *
1646 * This function grabs a device-level runtime pm reference (mostly used for GEM
1647 * code to ensure the GTT or GT is on) and ensures that it is powered up.
1648 *
1649 * Any runtime pm reference obtained by this function must have a symmetric
1650 * call to intel_runtime_pm_put() to release the reference again.
1651 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02001652void intel_runtime_pm_get(struct drm_i915_private *dev_priv)
1653{
1654 struct drm_device *dev = dev_priv->dev;
1655 struct device *device = &dev->pdev->dev;
1656
1657 if (!HAS_RUNTIME_PM(dev))
1658 return;
1659
1660 pm_runtime_get_sync(device);
1661 WARN(dev_priv->pm.suspended, "Device still suspended.\n");
1662}
1663
Daniel Vettere4e76842014-09-30 10:56:42 +02001664/**
1665 * intel_runtime_pm_get_noresume - grab a runtime pm reference
1666 * @dev_priv: i915 device instance
1667 *
1668 * This function grabs a device-level runtime pm reference (mostly used for GEM
1669 * code to ensure the GTT or GT is on).
1670 *
1671 * It will _not_ power up the device but instead only check that it's powered
1672 * on. Therefore it is only valid to call this functions from contexts where
1673 * the device is known to be powered up and where trying to power it up would
1674 * result in hilarity and deadlocks. That pretty much means only the system
1675 * suspend/resume code where this is used to grab runtime pm references for
1676 * delayed setup down in work items.
1677 *
1678 * Any runtime pm reference obtained by this function must have a symmetric
1679 * call to intel_runtime_pm_put() to release the reference again.
1680 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02001681void intel_runtime_pm_get_noresume(struct drm_i915_private *dev_priv)
1682{
1683 struct drm_device *dev = dev_priv->dev;
1684 struct device *device = &dev->pdev->dev;
1685
1686 if (!HAS_RUNTIME_PM(dev))
1687 return;
1688
1689 WARN(dev_priv->pm.suspended, "Getting nosync-ref while suspended.\n");
1690 pm_runtime_get_noresume(device);
1691}
1692
Daniel Vettere4e76842014-09-30 10:56:42 +02001693/**
1694 * intel_runtime_pm_put - release a runtime pm reference
1695 * @dev_priv: i915 device instance
1696 *
1697 * This function drops the device-level runtime pm reference obtained by
1698 * intel_runtime_pm_get() and might power down the corresponding
1699 * hardware block right away if this is the last reference.
1700 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02001701void intel_runtime_pm_put(struct drm_i915_private *dev_priv)
1702{
1703 struct drm_device *dev = dev_priv->dev;
1704 struct device *device = &dev->pdev->dev;
1705
1706 if (!HAS_RUNTIME_PM(dev))
1707 return;
1708
1709 pm_runtime_mark_last_busy(device);
1710 pm_runtime_put_autosuspend(device);
1711}
1712
Daniel Vettere4e76842014-09-30 10:56:42 +02001713/**
1714 * intel_runtime_pm_enable - enable runtime pm
1715 * @dev_priv: i915 device instance
1716 *
1717 * This function enables runtime pm at the end of the driver load sequence.
1718 *
1719 * Note that this function does currently not enable runtime pm for the
1720 * subordinate display power domains. That is only done on the first modeset
1721 * using intel_display_set_init_power().
1722 */
Daniel Vetterf458ebb2014-09-30 10:56:39 +02001723void intel_runtime_pm_enable(struct drm_i915_private *dev_priv)
Daniel Vetter9c065a72014-09-30 10:56:38 +02001724{
1725 struct drm_device *dev = dev_priv->dev;
1726 struct device *device = &dev->pdev->dev;
1727
1728 if (!HAS_RUNTIME_PM(dev))
1729 return;
1730
1731 pm_runtime_set_active(device);
1732
1733 /*
1734 * RPM depends on RC6 to save restore the GT HW context, so make RC6 a
1735 * requirement.
1736 */
1737 if (!intel_enable_rc6(dev)) {
1738 DRM_INFO("RC6 disabled, disabling runtime PM support\n");
1739 return;
1740 }
1741
1742 pm_runtime_set_autosuspend_delay(device, 10000); /* 10s */
1743 pm_runtime_mark_last_busy(device);
1744 pm_runtime_use_autosuspend(device);
1745
1746 pm_runtime_put_autosuspend(device);
1747}
1748