blob: 87a449cf5475128c2334f6bc72f78e11a2e78e9d [file] [log] [blame]
Daniel Vetter9c065a72014-09-30 10:56:38 +02001/*
2 * Copyright © 2012-2014 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 *
23 * Authors:
24 * Eugeni Dodonov <eugeni.dodonov@intel.com>
25 * Daniel Vetter <daniel.vetter@ffwll.ch>
26 *
27 */
28
29#include <linux/pm_runtime.h>
30#include <linux/vgaarb.h>
31
32#include "i915_drv.h"
33#include "intel_drv.h"
Daniel Vetter9c065a72014-09-30 10:56:38 +020034
Daniel Vettere4e76842014-09-30 10:56:42 +020035/**
36 * DOC: runtime pm
37 *
38 * The i915 driver supports dynamic enabling and disabling of entire hardware
39 * blocks at runtime. This is especially important on the display side where
40 * software is supposed to control many power gates manually on recent hardware,
41 * since on the GT side a lot of the power management is done by the hardware.
42 * But even there some manual control at the device level is required.
43 *
44 * Since i915 supports a diverse set of platforms with a unified codebase and
45 * hardware engineers just love to shuffle functionality around between power
46 * domains there's a sizeable amount of indirection required. This file provides
47 * generic functions to the driver for grabbing and releasing references for
48 * abstract power domains. It then maps those to the actual power wells
49 * present for a given platform.
50 */
51
Daniel Vetter9c065a72014-09-30 10:56:38 +020052#define for_each_power_well(i, power_well, domain_mask, power_domains) \
53 for (i = 0; \
54 i < (power_domains)->power_well_count && \
55 ((power_well) = &(power_domains)->power_wells[i]); \
56 i++) \
57 if ((power_well)->domains & (domain_mask))
58
59#define for_each_power_well_rev(i, power_well, domain_mask, power_domains) \
60 for (i = (power_domains)->power_well_count - 1; \
61 i >= 0 && ((power_well) = &(power_domains)->power_wells[i]);\
62 i--) \
63 if ((power_well)->domains & (domain_mask))
64
Daniel Vettere4e76842014-09-30 10:56:42 +020065/*
Daniel Vetter9c065a72014-09-30 10:56:38 +020066 * We should only use the power well if we explicitly asked the hardware to
67 * enable it, so check if it's enabled and also check if we've requested it to
68 * be enabled.
69 */
70static bool hsw_power_well_enabled(struct drm_i915_private *dev_priv,
71 struct i915_power_well *power_well)
72{
73 return I915_READ(HSW_PWR_WELL_DRIVER) ==
74 (HSW_PWR_WELL_ENABLE_REQUEST | HSW_PWR_WELL_STATE_ENABLED);
75}
76
Daniel Vettere4e76842014-09-30 10:56:42 +020077/**
78 * __intel_display_power_is_enabled - unlocked check for a power domain
79 * @dev_priv: i915 device instance
80 * @domain: power domain to check
81 *
82 * This is the unlocked version of intel_display_power_is_enabled() and should
83 * only be used from error capture and recovery code where deadlocks are
84 * possible.
85 *
86 * Returns:
87 * True when the power domain is enabled, false otherwise.
88 */
Daniel Vetterf458ebb2014-09-30 10:56:39 +020089bool __intel_display_power_is_enabled(struct drm_i915_private *dev_priv,
90 enum intel_display_power_domain domain)
Daniel Vetter9c065a72014-09-30 10:56:38 +020091{
92 struct i915_power_domains *power_domains;
93 struct i915_power_well *power_well;
94 bool is_enabled;
95 int i;
96
97 if (dev_priv->pm.suspended)
98 return false;
99
100 power_domains = &dev_priv->power_domains;
101
102 is_enabled = true;
103
104 for_each_power_well_rev(i, power_well, BIT(domain), power_domains) {
105 if (power_well->always_on)
106 continue;
107
108 if (!power_well->hw_enabled) {
109 is_enabled = false;
110 break;
111 }
112 }
113
114 return is_enabled;
115}
116
Daniel Vettere4e76842014-09-30 10:56:42 +0200117/**
Damien Lespiauf61ccae2014-11-25 13:45:41 +0000118 * intel_display_power_is_enabled - check for a power domain
Daniel Vettere4e76842014-09-30 10:56:42 +0200119 * @dev_priv: i915 device instance
120 * @domain: power domain to check
121 *
122 * This function can be used to check the hw power domain state. It is mostly
123 * used in hardware state readout functions. Everywhere else code should rely
124 * upon explicit power domain reference counting to ensure that the hardware
125 * block is powered up before accessing it.
126 *
127 * Callers must hold the relevant modesetting locks to ensure that concurrent
128 * threads can't disable the power well while the caller tries to read a few
129 * registers.
130 *
131 * Returns:
132 * True when the power domain is enabled, false otherwise.
133 */
Daniel Vetterf458ebb2014-09-30 10:56:39 +0200134bool intel_display_power_is_enabled(struct drm_i915_private *dev_priv,
135 enum intel_display_power_domain domain)
Daniel Vetter9c065a72014-09-30 10:56:38 +0200136{
137 struct i915_power_domains *power_domains;
138 bool ret;
139
140 power_domains = &dev_priv->power_domains;
141
142 mutex_lock(&power_domains->lock);
Daniel Vetterf458ebb2014-09-30 10:56:39 +0200143 ret = __intel_display_power_is_enabled(dev_priv, domain);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200144 mutex_unlock(&power_domains->lock);
145
146 return ret;
147}
148
Daniel Vettere4e76842014-09-30 10:56:42 +0200149/**
150 * intel_display_set_init_power - set the initial power domain state
151 * @dev_priv: i915 device instance
152 * @enable: whether to enable or disable the initial power domain state
153 *
154 * For simplicity our driver load/unload and system suspend/resume code assumes
155 * that all power domains are always enabled. This functions controls the state
156 * of this little hack. While the initial power domain state is enabled runtime
157 * pm is effectively disabled.
158 */
Daniel Vetterd9bc89d92014-09-30 10:56:40 +0200159void intel_display_set_init_power(struct drm_i915_private *dev_priv,
160 bool enable)
161{
162 if (dev_priv->power_domains.init_power_on == enable)
163 return;
164
165 if (enable)
166 intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
167 else
168 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
169
170 dev_priv->power_domains.init_power_on = enable;
171}
172
Daniel Vetter9c065a72014-09-30 10:56:38 +0200173/*
174 * Starting with Haswell, we have a "Power Down Well" that can be turned off
175 * when not needed anymore. We have 4 registers that can request the power well
176 * to be enabled, and it will only be disabled if none of the registers is
177 * requesting it to be enabled.
178 */
179static void hsw_power_well_post_enable(struct drm_i915_private *dev_priv)
180{
181 struct drm_device *dev = dev_priv->dev;
182
183 /*
184 * After we re-enable the power well, if we touch VGA register 0x3d5
185 * we'll get unclaimed register interrupts. This stops after we write
186 * anything to the VGA MSR register. The vgacon module uses this
187 * register all the time, so if we unbind our driver and, as a
188 * consequence, bind vgacon, we'll get stuck in an infinite loop at
189 * console_unlock(). So make here we touch the VGA MSR register, making
190 * sure vgacon can keep working normally without triggering interrupts
191 * and error messages.
192 */
193 vga_get_uninterruptible(dev->pdev, VGA_RSRC_LEGACY_IO);
194 outb(inb(VGA_MSR_READ), VGA_MSR_WRITE);
195 vga_put(dev->pdev, VGA_RSRC_LEGACY_IO);
196
197 if (IS_BROADWELL(dev) || (INTEL_INFO(dev)->gen >= 9))
Damien Lespiau4c6c03b2015-03-06 18:50:48 +0000198 gen8_irq_power_well_post_enable(dev_priv,
199 1 << PIPE_C | 1 << PIPE_B);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200200}
201
Damien Lespiaud14c0342015-03-06 18:50:51 +0000202static void skl_power_well_post_enable(struct drm_i915_private *dev_priv,
203 struct i915_power_well *power_well)
204{
205 struct drm_device *dev = dev_priv->dev;
206
207 /*
208 * After we re-enable the power well, if we touch VGA register 0x3d5
209 * we'll get unclaimed register interrupts. This stops after we write
210 * anything to the VGA MSR register. The vgacon module uses this
211 * register all the time, so if we unbind our driver and, as a
212 * consequence, bind vgacon, we'll get stuck in an infinite loop at
213 * console_unlock(). So make here we touch the VGA MSR register, making
214 * sure vgacon can keep working normally without triggering interrupts
215 * and error messages.
216 */
217 if (power_well->data == SKL_DISP_PW_2) {
218 vga_get_uninterruptible(dev->pdev, VGA_RSRC_LEGACY_IO);
219 outb(inb(VGA_MSR_READ), VGA_MSR_WRITE);
220 vga_put(dev->pdev, VGA_RSRC_LEGACY_IO);
221
222 gen8_irq_power_well_post_enable(dev_priv,
223 1 << PIPE_C | 1 << PIPE_B);
224 }
225
226 if (power_well->data == SKL_DISP_PW_1)
227 gen8_irq_power_well_post_enable(dev_priv, 1 << PIPE_A);
228}
229
Daniel Vetter9c065a72014-09-30 10:56:38 +0200230static void hsw_set_power_well(struct drm_i915_private *dev_priv,
231 struct i915_power_well *power_well, bool enable)
232{
233 bool is_enabled, enable_requested;
234 uint32_t tmp;
235
236 tmp = I915_READ(HSW_PWR_WELL_DRIVER);
237 is_enabled = tmp & HSW_PWR_WELL_STATE_ENABLED;
238 enable_requested = tmp & HSW_PWR_WELL_ENABLE_REQUEST;
239
240 if (enable) {
241 if (!enable_requested)
242 I915_WRITE(HSW_PWR_WELL_DRIVER,
243 HSW_PWR_WELL_ENABLE_REQUEST);
244
245 if (!is_enabled) {
246 DRM_DEBUG_KMS("Enabling power well\n");
247 if (wait_for((I915_READ(HSW_PWR_WELL_DRIVER) &
248 HSW_PWR_WELL_STATE_ENABLED), 20))
249 DRM_ERROR("Timeout enabling power well\n");
Paulo Zanoni6d729bf2014-10-07 16:11:11 -0300250 hsw_power_well_post_enable(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200251 }
252
Daniel Vetter9c065a72014-09-30 10:56:38 +0200253 } else {
254 if (enable_requested) {
255 I915_WRITE(HSW_PWR_WELL_DRIVER, 0);
256 POSTING_READ(HSW_PWR_WELL_DRIVER);
257 DRM_DEBUG_KMS("Requesting to disable the power well\n");
258 }
259 }
260}
261
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000262#define SKL_DISPLAY_POWERWELL_2_POWER_DOMAINS ( \
263 BIT(POWER_DOMAIN_TRANSCODER_A) | \
264 BIT(POWER_DOMAIN_PIPE_B) | \
265 BIT(POWER_DOMAIN_TRANSCODER_B) | \
266 BIT(POWER_DOMAIN_PIPE_C) | \
267 BIT(POWER_DOMAIN_TRANSCODER_C) | \
268 BIT(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
269 BIT(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
270 BIT(POWER_DOMAIN_PORT_DDI_B_2_LANES) | \
271 BIT(POWER_DOMAIN_PORT_DDI_B_4_LANES) | \
272 BIT(POWER_DOMAIN_PORT_DDI_C_2_LANES) | \
273 BIT(POWER_DOMAIN_PORT_DDI_C_4_LANES) | \
274 BIT(POWER_DOMAIN_PORT_DDI_D_2_LANES) | \
275 BIT(POWER_DOMAIN_PORT_DDI_D_4_LANES) | \
276 BIT(POWER_DOMAIN_AUX_B) | \
277 BIT(POWER_DOMAIN_AUX_C) | \
278 BIT(POWER_DOMAIN_AUX_D) | \
279 BIT(POWER_DOMAIN_AUDIO) | \
280 BIT(POWER_DOMAIN_VGA) | \
281 BIT(POWER_DOMAIN_INIT))
282#define SKL_DISPLAY_POWERWELL_1_POWER_DOMAINS ( \
283 SKL_DISPLAY_POWERWELL_2_POWER_DOMAINS | \
284 BIT(POWER_DOMAIN_PLLS) | \
285 BIT(POWER_DOMAIN_PIPE_A) | \
286 BIT(POWER_DOMAIN_TRANSCODER_EDP) | \
287 BIT(POWER_DOMAIN_PIPE_A_PANEL_FITTER) | \
288 BIT(POWER_DOMAIN_PORT_DDI_A_2_LANES) | \
289 BIT(POWER_DOMAIN_PORT_DDI_A_4_LANES) | \
290 BIT(POWER_DOMAIN_AUX_A) | \
291 BIT(POWER_DOMAIN_INIT))
292#define SKL_DISPLAY_DDI_A_E_POWER_DOMAINS ( \
293 BIT(POWER_DOMAIN_PORT_DDI_A_2_LANES) | \
294 BIT(POWER_DOMAIN_PORT_DDI_A_4_LANES) | \
295 BIT(POWER_DOMAIN_INIT))
296#define SKL_DISPLAY_DDI_B_POWER_DOMAINS ( \
297 BIT(POWER_DOMAIN_PORT_DDI_B_2_LANES) | \
298 BIT(POWER_DOMAIN_PORT_DDI_B_4_LANES) | \
299 BIT(POWER_DOMAIN_INIT))
300#define SKL_DISPLAY_DDI_C_POWER_DOMAINS ( \
301 BIT(POWER_DOMAIN_PORT_DDI_C_2_LANES) | \
302 BIT(POWER_DOMAIN_PORT_DDI_C_4_LANES) | \
303 BIT(POWER_DOMAIN_INIT))
304#define SKL_DISPLAY_DDI_D_POWER_DOMAINS ( \
305 BIT(POWER_DOMAIN_PORT_DDI_D_2_LANES) | \
306 BIT(POWER_DOMAIN_PORT_DDI_D_4_LANES) | \
307 BIT(POWER_DOMAIN_INIT))
308#define SKL_DISPLAY_MISC_IO_POWER_DOMAINS ( \
309 SKL_DISPLAY_POWERWELL_1_POWER_DOMAINS)
310#define SKL_DISPLAY_ALWAYS_ON_POWER_DOMAINS ( \
311 (POWER_DOMAIN_MASK & ~(SKL_DISPLAY_POWERWELL_1_POWER_DOMAINS | \
312 SKL_DISPLAY_POWERWELL_2_POWER_DOMAINS | \
313 SKL_DISPLAY_DDI_A_E_POWER_DOMAINS | \
314 SKL_DISPLAY_DDI_B_POWER_DOMAINS | \
315 SKL_DISPLAY_DDI_C_POWER_DOMAINS | \
316 SKL_DISPLAY_DDI_D_POWER_DOMAINS | \
317 SKL_DISPLAY_MISC_IO_POWER_DOMAINS)) | \
318 BIT(POWER_DOMAIN_INIT))
319
320static void skl_set_power_well(struct drm_i915_private *dev_priv,
321 struct i915_power_well *power_well, bool enable)
322{
323 uint32_t tmp, fuse_status;
324 uint32_t req_mask, state_mask;
Damien Lespiau2a518352015-03-06 18:50:49 +0000325 bool is_enabled, enable_requested, check_fuse_status = false;
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000326
327 tmp = I915_READ(HSW_PWR_WELL_DRIVER);
328 fuse_status = I915_READ(SKL_FUSE_STATUS);
329
330 switch (power_well->data) {
331 case SKL_DISP_PW_1:
332 if (wait_for((I915_READ(SKL_FUSE_STATUS) &
333 SKL_FUSE_PG0_DIST_STATUS), 1)) {
334 DRM_ERROR("PG0 not enabled\n");
335 return;
336 }
337 break;
338 case SKL_DISP_PW_2:
339 if (!(fuse_status & SKL_FUSE_PG1_DIST_STATUS)) {
340 DRM_ERROR("PG1 in disabled state\n");
341 return;
342 }
343 break;
344 case SKL_DISP_PW_DDI_A_E:
345 case SKL_DISP_PW_DDI_B:
346 case SKL_DISP_PW_DDI_C:
347 case SKL_DISP_PW_DDI_D:
348 case SKL_DISP_PW_MISC_IO:
349 break;
350 default:
351 WARN(1, "Unknown power well %lu\n", power_well->data);
352 return;
353 }
354
355 req_mask = SKL_POWER_WELL_REQ(power_well->data);
Damien Lespiau2a518352015-03-06 18:50:49 +0000356 enable_requested = tmp & req_mask;
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000357 state_mask = SKL_POWER_WELL_STATE(power_well->data);
Damien Lespiau2a518352015-03-06 18:50:49 +0000358 is_enabled = tmp & state_mask;
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000359
360 if (enable) {
Damien Lespiau2a518352015-03-06 18:50:49 +0000361 if (!enable_requested) {
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000362 I915_WRITE(HSW_PWR_WELL_DRIVER, tmp | req_mask);
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000363 }
364
Damien Lespiau2a518352015-03-06 18:50:49 +0000365 if (!is_enabled) {
Damien Lespiau510e6fd2015-03-06 18:50:50 +0000366 DRM_DEBUG_KMS("Enabling %s\n", power_well->name);
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000367 if (wait_for((I915_READ(HSW_PWR_WELL_DRIVER) &
368 state_mask), 1))
369 DRM_ERROR("%s enable timeout\n",
370 power_well->name);
371 check_fuse_status = true;
372 }
373 } else {
Damien Lespiau2a518352015-03-06 18:50:49 +0000374 if (enable_requested) {
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000375 I915_WRITE(HSW_PWR_WELL_DRIVER, tmp & ~req_mask);
376 POSTING_READ(HSW_PWR_WELL_DRIVER);
377 DRM_DEBUG_KMS("Disabling %s\n", power_well->name);
378 }
379 }
380
381 if (check_fuse_status) {
382 if (power_well->data == SKL_DISP_PW_1) {
383 if (wait_for((I915_READ(SKL_FUSE_STATUS) &
384 SKL_FUSE_PG1_DIST_STATUS), 1))
385 DRM_ERROR("PG1 distributing status timeout\n");
386 } else if (power_well->data == SKL_DISP_PW_2) {
387 if (wait_for((I915_READ(SKL_FUSE_STATUS) &
388 SKL_FUSE_PG2_DIST_STATUS), 1))
389 DRM_ERROR("PG2 distributing status timeout\n");
390 }
391 }
Damien Lespiaud14c0342015-03-06 18:50:51 +0000392
393 if (enable && !is_enabled)
394 skl_power_well_post_enable(dev_priv, power_well);
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000395}
396
Daniel Vetter9c065a72014-09-30 10:56:38 +0200397static void hsw_power_well_sync_hw(struct drm_i915_private *dev_priv,
398 struct i915_power_well *power_well)
399{
400 hsw_set_power_well(dev_priv, power_well, power_well->count > 0);
401
402 /*
403 * We're taking over the BIOS, so clear any requests made by it since
404 * the driver is in charge now.
405 */
406 if (I915_READ(HSW_PWR_WELL_BIOS) & HSW_PWR_WELL_ENABLE_REQUEST)
407 I915_WRITE(HSW_PWR_WELL_BIOS, 0);
408}
409
410static void hsw_power_well_enable(struct drm_i915_private *dev_priv,
411 struct i915_power_well *power_well)
412{
413 hsw_set_power_well(dev_priv, power_well, true);
414}
415
416static void hsw_power_well_disable(struct drm_i915_private *dev_priv,
417 struct i915_power_well *power_well)
418{
419 hsw_set_power_well(dev_priv, power_well, false);
420}
421
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000422static bool skl_power_well_enabled(struct drm_i915_private *dev_priv,
423 struct i915_power_well *power_well)
424{
425 uint32_t mask = SKL_POWER_WELL_REQ(power_well->data) |
426 SKL_POWER_WELL_STATE(power_well->data);
427
428 return (I915_READ(HSW_PWR_WELL_DRIVER) & mask) == mask;
429}
430
431static void skl_power_well_sync_hw(struct drm_i915_private *dev_priv,
432 struct i915_power_well *power_well)
433{
434 skl_set_power_well(dev_priv, power_well, power_well->count > 0);
435
436 /* Clear any request made by BIOS as driver is taking over */
437 I915_WRITE(HSW_PWR_WELL_BIOS, 0);
438}
439
440static void skl_power_well_enable(struct drm_i915_private *dev_priv,
441 struct i915_power_well *power_well)
442{
443 skl_set_power_well(dev_priv, power_well, true);
444}
445
446static void skl_power_well_disable(struct drm_i915_private *dev_priv,
447 struct i915_power_well *power_well)
448{
449 skl_set_power_well(dev_priv, power_well, false);
450}
451
Daniel Vetter9c065a72014-09-30 10:56:38 +0200452static void i9xx_always_on_power_well_noop(struct drm_i915_private *dev_priv,
453 struct i915_power_well *power_well)
454{
455}
456
457static bool i9xx_always_on_power_well_enabled(struct drm_i915_private *dev_priv,
458 struct i915_power_well *power_well)
459{
460 return true;
461}
462
463static void vlv_set_power_well(struct drm_i915_private *dev_priv,
464 struct i915_power_well *power_well, bool enable)
465{
466 enum punit_power_well power_well_id = power_well->data;
467 u32 mask;
468 u32 state;
469 u32 ctrl;
470
471 mask = PUNIT_PWRGT_MASK(power_well_id);
472 state = enable ? PUNIT_PWRGT_PWR_ON(power_well_id) :
473 PUNIT_PWRGT_PWR_GATE(power_well_id);
474
475 mutex_lock(&dev_priv->rps.hw_lock);
476
477#define COND \
478 ((vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_STATUS) & mask) == state)
479
480 if (COND)
481 goto out;
482
483 ctrl = vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_CTRL);
484 ctrl &= ~mask;
485 ctrl |= state;
486 vlv_punit_write(dev_priv, PUNIT_REG_PWRGT_CTRL, ctrl);
487
488 if (wait_for(COND, 100))
489 DRM_ERROR("timout setting power well state %08x (%08x)\n",
490 state,
491 vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_CTRL));
492
493#undef COND
494
495out:
496 mutex_unlock(&dev_priv->rps.hw_lock);
497}
498
499static void vlv_power_well_sync_hw(struct drm_i915_private *dev_priv,
500 struct i915_power_well *power_well)
501{
502 vlv_set_power_well(dev_priv, power_well, power_well->count > 0);
503}
504
505static void vlv_power_well_enable(struct drm_i915_private *dev_priv,
506 struct i915_power_well *power_well)
507{
508 vlv_set_power_well(dev_priv, power_well, true);
509}
510
511static void vlv_power_well_disable(struct drm_i915_private *dev_priv,
512 struct i915_power_well *power_well)
513{
514 vlv_set_power_well(dev_priv, power_well, false);
515}
516
517static bool vlv_power_well_enabled(struct drm_i915_private *dev_priv,
518 struct i915_power_well *power_well)
519{
520 int power_well_id = power_well->data;
521 bool enabled = false;
522 u32 mask;
523 u32 state;
524 u32 ctrl;
525
526 mask = PUNIT_PWRGT_MASK(power_well_id);
527 ctrl = PUNIT_PWRGT_PWR_ON(power_well_id);
528
529 mutex_lock(&dev_priv->rps.hw_lock);
530
531 state = vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_STATUS) & mask;
532 /*
533 * We only ever set the power-on and power-gate states, anything
534 * else is unexpected.
535 */
536 WARN_ON(state != PUNIT_PWRGT_PWR_ON(power_well_id) &&
537 state != PUNIT_PWRGT_PWR_GATE(power_well_id));
538 if (state == ctrl)
539 enabled = true;
540
541 /*
542 * A transient state at this point would mean some unexpected party
543 * is poking at the power controls too.
544 */
545 ctrl = vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_CTRL) & mask;
546 WARN_ON(ctrl != state);
547
548 mutex_unlock(&dev_priv->rps.hw_lock);
549
550 return enabled;
551}
552
553static void vlv_display_power_well_enable(struct drm_i915_private *dev_priv,
554 struct i915_power_well *power_well)
555{
556 WARN_ON_ONCE(power_well->data != PUNIT_POWER_WELL_DISP2D);
557
558 vlv_set_power_well(dev_priv, power_well, true);
559
560 spin_lock_irq(&dev_priv->irq_lock);
561 valleyview_enable_display_irqs(dev_priv);
562 spin_unlock_irq(&dev_priv->irq_lock);
563
564 /*
565 * During driver initialization/resume we can avoid restoring the
566 * part of the HW/SW state that will be inited anyway explicitly.
567 */
568 if (dev_priv->power_domains.initializing)
569 return;
570
Daniel Vetterb9632912014-09-30 10:56:44 +0200571 intel_hpd_init(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200572
573 i915_redisable_vga_power_on(dev_priv->dev);
574}
575
576static void vlv_display_power_well_disable(struct drm_i915_private *dev_priv,
577 struct i915_power_well *power_well)
578{
579 WARN_ON_ONCE(power_well->data != PUNIT_POWER_WELL_DISP2D);
580
581 spin_lock_irq(&dev_priv->irq_lock);
582 valleyview_disable_display_irqs(dev_priv);
583 spin_unlock_irq(&dev_priv->irq_lock);
584
585 vlv_set_power_well(dev_priv, power_well, false);
586
587 vlv_power_sequencer_reset(dev_priv);
588}
589
590static void vlv_dpio_cmn_power_well_enable(struct drm_i915_private *dev_priv,
591 struct i915_power_well *power_well)
592{
593 WARN_ON_ONCE(power_well->data != PUNIT_POWER_WELL_DPIO_CMN_BC);
594
595 /*
596 * Enable the CRI clock source so we can get at the
597 * display and the reference clock for VGA
598 * hotplug / manual detection.
599 */
600 I915_WRITE(DPLL(PIPE_B), I915_READ(DPLL(PIPE_B)) |
601 DPLL_REFA_CLK_ENABLE_VLV | DPLL_INTEGRATED_CRI_CLK_VLV);
602 udelay(1); /* >10ns for cmnreset, >0ns for sidereset */
603
604 vlv_set_power_well(dev_priv, power_well, true);
605
606 /*
607 * From VLV2A0_DP_eDP_DPIO_driver_vbios_notes_10.docx -
608 * 6. De-assert cmn_reset/side_reset. Same as VLV X0.
609 * a. GUnit 0x2110 bit[0] set to 1 (def 0)
610 * b. The other bits such as sfr settings / modesel may all
611 * be set to 0.
612 *
613 * This should only be done on init and resume from S3 with
614 * both PLLs disabled, or we risk losing DPIO and PLL
615 * synchronization.
616 */
617 I915_WRITE(DPIO_CTL, I915_READ(DPIO_CTL) | DPIO_CMNRST);
618}
619
620static void vlv_dpio_cmn_power_well_disable(struct drm_i915_private *dev_priv,
621 struct i915_power_well *power_well)
622{
623 enum pipe pipe;
624
625 WARN_ON_ONCE(power_well->data != PUNIT_POWER_WELL_DPIO_CMN_BC);
626
627 for_each_pipe(dev_priv, pipe)
628 assert_pll_disabled(dev_priv, pipe);
629
630 /* Assert common reset */
631 I915_WRITE(DPIO_CTL, I915_READ(DPIO_CTL) & ~DPIO_CMNRST);
632
633 vlv_set_power_well(dev_priv, power_well, false);
634}
635
636static void chv_dpio_cmn_power_well_enable(struct drm_i915_private *dev_priv,
637 struct i915_power_well *power_well)
638{
639 enum dpio_phy phy;
640
641 WARN_ON_ONCE(power_well->data != PUNIT_POWER_WELL_DPIO_CMN_BC &&
642 power_well->data != PUNIT_POWER_WELL_DPIO_CMN_D);
643
644 /*
645 * Enable the CRI clock source so we can get at the
646 * display and the reference clock for VGA
647 * hotplug / manual detection.
648 */
649 if (power_well->data == PUNIT_POWER_WELL_DPIO_CMN_BC) {
650 phy = DPIO_PHY0;
651 I915_WRITE(DPLL(PIPE_B), I915_READ(DPLL(PIPE_B)) |
652 DPLL_REFA_CLK_ENABLE_VLV);
653 I915_WRITE(DPLL(PIPE_B), I915_READ(DPLL(PIPE_B)) |
654 DPLL_REFA_CLK_ENABLE_VLV | DPLL_INTEGRATED_CRI_CLK_VLV);
655 } else {
656 phy = DPIO_PHY1;
657 I915_WRITE(DPLL(PIPE_C), I915_READ(DPLL(PIPE_C)) |
658 DPLL_REFA_CLK_ENABLE_VLV | DPLL_INTEGRATED_CRI_CLK_VLV);
659 }
660 udelay(1); /* >10ns for cmnreset, >0ns for sidereset */
661 vlv_set_power_well(dev_priv, power_well, true);
662
663 /* Poll for phypwrgood signal */
664 if (wait_for(I915_READ(DISPLAY_PHY_STATUS) & PHY_POWERGOOD(phy), 1))
665 DRM_ERROR("Display PHY %d is not power up\n", phy);
666
667 I915_WRITE(DISPLAY_PHY_CONTROL, I915_READ(DISPLAY_PHY_CONTROL) |
668 PHY_COM_LANE_RESET_DEASSERT(phy));
669}
670
671static void chv_dpio_cmn_power_well_disable(struct drm_i915_private *dev_priv,
672 struct i915_power_well *power_well)
673{
674 enum dpio_phy phy;
675
676 WARN_ON_ONCE(power_well->data != PUNIT_POWER_WELL_DPIO_CMN_BC &&
677 power_well->data != PUNIT_POWER_WELL_DPIO_CMN_D);
678
679 if (power_well->data == PUNIT_POWER_WELL_DPIO_CMN_BC) {
680 phy = DPIO_PHY0;
681 assert_pll_disabled(dev_priv, PIPE_A);
682 assert_pll_disabled(dev_priv, PIPE_B);
683 } else {
684 phy = DPIO_PHY1;
685 assert_pll_disabled(dev_priv, PIPE_C);
686 }
687
688 I915_WRITE(DISPLAY_PHY_CONTROL, I915_READ(DISPLAY_PHY_CONTROL) &
689 ~PHY_COM_LANE_RESET_DEASSERT(phy));
690
691 vlv_set_power_well(dev_priv, power_well, false);
692}
693
694static bool chv_pipe_power_well_enabled(struct drm_i915_private *dev_priv,
695 struct i915_power_well *power_well)
696{
697 enum pipe pipe = power_well->data;
698 bool enabled;
699 u32 state, ctrl;
700
701 mutex_lock(&dev_priv->rps.hw_lock);
702
703 state = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & DP_SSS_MASK(pipe);
704 /*
705 * We only ever set the power-on and power-gate states, anything
706 * else is unexpected.
707 */
708 WARN_ON(state != DP_SSS_PWR_ON(pipe) && state != DP_SSS_PWR_GATE(pipe));
709 enabled = state == DP_SSS_PWR_ON(pipe);
710
711 /*
712 * A transient state at this point would mean some unexpected party
713 * is poking at the power controls too.
714 */
715 ctrl = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & DP_SSC_MASK(pipe);
716 WARN_ON(ctrl << 16 != state);
717
718 mutex_unlock(&dev_priv->rps.hw_lock);
719
720 return enabled;
721}
722
723static void chv_set_pipe_power_well(struct drm_i915_private *dev_priv,
724 struct i915_power_well *power_well,
725 bool enable)
726{
727 enum pipe pipe = power_well->data;
728 u32 state;
729 u32 ctrl;
730
731 state = enable ? DP_SSS_PWR_ON(pipe) : DP_SSS_PWR_GATE(pipe);
732
733 mutex_lock(&dev_priv->rps.hw_lock);
734
735#define COND \
736 ((vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & DP_SSS_MASK(pipe)) == state)
737
738 if (COND)
739 goto out;
740
741 ctrl = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ);
742 ctrl &= ~DP_SSC_MASK(pipe);
743 ctrl |= enable ? DP_SSC_PWR_ON(pipe) : DP_SSC_PWR_GATE(pipe);
744 vlv_punit_write(dev_priv, PUNIT_REG_DSPFREQ, ctrl);
745
746 if (wait_for(COND, 100))
747 DRM_ERROR("timout setting power well state %08x (%08x)\n",
748 state,
749 vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ));
750
751#undef COND
752
753out:
754 mutex_unlock(&dev_priv->rps.hw_lock);
755}
756
757static void chv_pipe_power_well_sync_hw(struct drm_i915_private *dev_priv,
758 struct i915_power_well *power_well)
759{
760 chv_set_pipe_power_well(dev_priv, power_well, power_well->count > 0);
761}
762
763static void chv_pipe_power_well_enable(struct drm_i915_private *dev_priv,
764 struct i915_power_well *power_well)
765{
766 WARN_ON_ONCE(power_well->data != PIPE_A &&
767 power_well->data != PIPE_B &&
768 power_well->data != PIPE_C);
769
770 chv_set_pipe_power_well(dev_priv, power_well, true);
Ville Syrjäläafd62752014-10-30 19:43:03 +0200771
772 if (power_well->data == PIPE_A) {
773 spin_lock_irq(&dev_priv->irq_lock);
774 valleyview_enable_display_irqs(dev_priv);
775 spin_unlock_irq(&dev_priv->irq_lock);
776
777 /*
778 * During driver initialization/resume we can avoid restoring the
779 * part of the HW/SW state that will be inited anyway explicitly.
780 */
781 if (dev_priv->power_domains.initializing)
782 return;
783
784 intel_hpd_init(dev_priv);
785
786 i915_redisable_vga_power_on(dev_priv->dev);
787 }
Daniel Vetter9c065a72014-09-30 10:56:38 +0200788}
789
790static void chv_pipe_power_well_disable(struct drm_i915_private *dev_priv,
791 struct i915_power_well *power_well)
792{
793 WARN_ON_ONCE(power_well->data != PIPE_A &&
794 power_well->data != PIPE_B &&
795 power_well->data != PIPE_C);
796
Ville Syrjäläafd62752014-10-30 19:43:03 +0200797 if (power_well->data == PIPE_A) {
798 spin_lock_irq(&dev_priv->irq_lock);
799 valleyview_disable_display_irqs(dev_priv);
800 spin_unlock_irq(&dev_priv->irq_lock);
801 }
802
Daniel Vetter9c065a72014-09-30 10:56:38 +0200803 chv_set_pipe_power_well(dev_priv, power_well, false);
Ville Syrjäläbaa4e572014-10-27 16:07:32 +0200804
805 if (power_well->data == PIPE_A)
806 vlv_power_sequencer_reset(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200807}
808
Daniel Vettere4e76842014-09-30 10:56:42 +0200809/**
810 * intel_display_power_get - grab a power domain reference
811 * @dev_priv: i915 device instance
812 * @domain: power domain to reference
813 *
814 * This function grabs a power domain reference for @domain and ensures that the
815 * power domain and all its parents are powered up. Therefore users should only
816 * grab a reference to the innermost power domain they need.
817 *
818 * Any power domain reference obtained by this function must have a symmetric
819 * call to intel_display_power_put() to release the reference again.
820 */
Daniel Vetter9c065a72014-09-30 10:56:38 +0200821void intel_display_power_get(struct drm_i915_private *dev_priv,
822 enum intel_display_power_domain domain)
823{
824 struct i915_power_domains *power_domains;
825 struct i915_power_well *power_well;
826 int i;
827
828 intel_runtime_pm_get(dev_priv);
829
830 power_domains = &dev_priv->power_domains;
831
832 mutex_lock(&power_domains->lock);
833
834 for_each_power_well(i, power_well, BIT(domain), power_domains) {
835 if (!power_well->count++) {
836 DRM_DEBUG_KMS("enabling %s\n", power_well->name);
837 power_well->ops->enable(dev_priv, power_well);
838 power_well->hw_enabled = true;
839 }
Daniel Vetter9c065a72014-09-30 10:56:38 +0200840 }
841
842 power_domains->domain_use_count[domain]++;
843
844 mutex_unlock(&power_domains->lock);
845}
846
Daniel Vettere4e76842014-09-30 10:56:42 +0200847/**
848 * intel_display_power_put - release a power domain reference
849 * @dev_priv: i915 device instance
850 * @domain: power domain to reference
851 *
852 * This function drops the power domain reference obtained by
853 * intel_display_power_get() and might power down the corresponding hardware
854 * block right away if this is the last reference.
855 */
Daniel Vetter9c065a72014-09-30 10:56:38 +0200856void intel_display_power_put(struct drm_i915_private *dev_priv,
857 enum intel_display_power_domain domain)
858{
859 struct i915_power_domains *power_domains;
860 struct i915_power_well *power_well;
861 int i;
862
863 power_domains = &dev_priv->power_domains;
864
865 mutex_lock(&power_domains->lock);
866
867 WARN_ON(!power_domains->domain_use_count[domain]);
868 power_domains->domain_use_count[domain]--;
869
870 for_each_power_well_rev(i, power_well, BIT(domain), power_domains) {
871 WARN_ON(!power_well->count);
872
873 if (!--power_well->count && i915.disable_power_well) {
874 DRM_DEBUG_KMS("disabling %s\n", power_well->name);
875 power_well->hw_enabled = false;
876 power_well->ops->disable(dev_priv, power_well);
877 }
Daniel Vetter9c065a72014-09-30 10:56:38 +0200878 }
879
880 mutex_unlock(&power_domains->lock);
881
882 intel_runtime_pm_put(dev_priv);
883}
884
885#define POWER_DOMAIN_MASK (BIT(POWER_DOMAIN_NUM) - 1)
886
887#define HSW_ALWAYS_ON_POWER_DOMAINS ( \
888 BIT(POWER_DOMAIN_PIPE_A) | \
889 BIT(POWER_DOMAIN_TRANSCODER_EDP) | \
890 BIT(POWER_DOMAIN_PORT_DDI_A_2_LANES) | \
891 BIT(POWER_DOMAIN_PORT_DDI_A_4_LANES) | \
892 BIT(POWER_DOMAIN_PORT_DDI_B_2_LANES) | \
893 BIT(POWER_DOMAIN_PORT_DDI_B_4_LANES) | \
894 BIT(POWER_DOMAIN_PORT_DDI_C_2_LANES) | \
895 BIT(POWER_DOMAIN_PORT_DDI_C_4_LANES) | \
896 BIT(POWER_DOMAIN_PORT_DDI_D_2_LANES) | \
897 BIT(POWER_DOMAIN_PORT_DDI_D_4_LANES) | \
898 BIT(POWER_DOMAIN_PORT_CRT) | \
899 BIT(POWER_DOMAIN_PLLS) | \
Satheeshakrishna M14071212015-01-16 15:57:51 +0000900 BIT(POWER_DOMAIN_AUX_A) | \
901 BIT(POWER_DOMAIN_AUX_B) | \
902 BIT(POWER_DOMAIN_AUX_C) | \
903 BIT(POWER_DOMAIN_AUX_D) | \
Daniel Vetter9c065a72014-09-30 10:56:38 +0200904 BIT(POWER_DOMAIN_INIT))
905#define HSW_DISPLAY_POWER_DOMAINS ( \
906 (POWER_DOMAIN_MASK & ~HSW_ALWAYS_ON_POWER_DOMAINS) | \
907 BIT(POWER_DOMAIN_INIT))
908
909#define BDW_ALWAYS_ON_POWER_DOMAINS ( \
910 HSW_ALWAYS_ON_POWER_DOMAINS | \
911 BIT(POWER_DOMAIN_PIPE_A_PANEL_FITTER))
912#define BDW_DISPLAY_POWER_DOMAINS ( \
913 (POWER_DOMAIN_MASK & ~BDW_ALWAYS_ON_POWER_DOMAINS) | \
914 BIT(POWER_DOMAIN_INIT))
915
916#define VLV_ALWAYS_ON_POWER_DOMAINS BIT(POWER_DOMAIN_INIT)
917#define VLV_DISPLAY_POWER_DOMAINS POWER_DOMAIN_MASK
918
919#define VLV_DPIO_CMN_BC_POWER_DOMAINS ( \
920 BIT(POWER_DOMAIN_PORT_DDI_B_2_LANES) | \
921 BIT(POWER_DOMAIN_PORT_DDI_B_4_LANES) | \
922 BIT(POWER_DOMAIN_PORT_DDI_C_2_LANES) | \
923 BIT(POWER_DOMAIN_PORT_DDI_C_4_LANES) | \
924 BIT(POWER_DOMAIN_PORT_CRT) | \
Satheeshakrishna M14071212015-01-16 15:57:51 +0000925 BIT(POWER_DOMAIN_AUX_B) | \
926 BIT(POWER_DOMAIN_AUX_C) | \
Daniel Vetter9c065a72014-09-30 10:56:38 +0200927 BIT(POWER_DOMAIN_INIT))
928
929#define VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS ( \
930 BIT(POWER_DOMAIN_PORT_DDI_B_2_LANES) | \
931 BIT(POWER_DOMAIN_PORT_DDI_B_4_LANES) | \
Satheeshakrishna M14071212015-01-16 15:57:51 +0000932 BIT(POWER_DOMAIN_AUX_B) | \
Daniel Vetter9c065a72014-09-30 10:56:38 +0200933 BIT(POWER_DOMAIN_INIT))
934
935#define VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS ( \
936 BIT(POWER_DOMAIN_PORT_DDI_B_4_LANES) | \
Satheeshakrishna M14071212015-01-16 15:57:51 +0000937 BIT(POWER_DOMAIN_AUX_B) | \
Daniel Vetter9c065a72014-09-30 10:56:38 +0200938 BIT(POWER_DOMAIN_INIT))
939
940#define VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS ( \
941 BIT(POWER_DOMAIN_PORT_DDI_C_2_LANES) | \
942 BIT(POWER_DOMAIN_PORT_DDI_C_4_LANES) | \
Satheeshakrishna M14071212015-01-16 15:57:51 +0000943 BIT(POWER_DOMAIN_AUX_C) | \
Daniel Vetter9c065a72014-09-30 10:56:38 +0200944 BIT(POWER_DOMAIN_INIT))
945
946#define VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS ( \
947 BIT(POWER_DOMAIN_PORT_DDI_C_4_LANES) | \
Satheeshakrishna M14071212015-01-16 15:57:51 +0000948 BIT(POWER_DOMAIN_AUX_C) | \
Daniel Vetter9c065a72014-09-30 10:56:38 +0200949 BIT(POWER_DOMAIN_INIT))
950
951#define CHV_PIPE_A_POWER_DOMAINS ( \
952 BIT(POWER_DOMAIN_PIPE_A) | \
953 BIT(POWER_DOMAIN_INIT))
954
955#define CHV_PIPE_B_POWER_DOMAINS ( \
956 BIT(POWER_DOMAIN_PIPE_B) | \
957 BIT(POWER_DOMAIN_INIT))
958
959#define CHV_PIPE_C_POWER_DOMAINS ( \
960 BIT(POWER_DOMAIN_PIPE_C) | \
961 BIT(POWER_DOMAIN_INIT))
962
963#define CHV_DPIO_CMN_BC_POWER_DOMAINS ( \
964 BIT(POWER_DOMAIN_PORT_DDI_B_2_LANES) | \
965 BIT(POWER_DOMAIN_PORT_DDI_B_4_LANES) | \
966 BIT(POWER_DOMAIN_PORT_DDI_C_2_LANES) | \
967 BIT(POWER_DOMAIN_PORT_DDI_C_4_LANES) | \
Satheeshakrishna M14071212015-01-16 15:57:51 +0000968 BIT(POWER_DOMAIN_AUX_B) | \
969 BIT(POWER_DOMAIN_AUX_C) | \
Daniel Vetter9c065a72014-09-30 10:56:38 +0200970 BIT(POWER_DOMAIN_INIT))
971
972#define CHV_DPIO_CMN_D_POWER_DOMAINS ( \
973 BIT(POWER_DOMAIN_PORT_DDI_D_2_LANES) | \
974 BIT(POWER_DOMAIN_PORT_DDI_D_4_LANES) | \
Satheeshakrishna M14071212015-01-16 15:57:51 +0000975 BIT(POWER_DOMAIN_AUX_D) | \
Daniel Vetter9c065a72014-09-30 10:56:38 +0200976 BIT(POWER_DOMAIN_INIT))
977
978#define CHV_DPIO_TX_D_LANES_01_POWER_DOMAINS ( \
979 BIT(POWER_DOMAIN_PORT_DDI_D_2_LANES) | \
980 BIT(POWER_DOMAIN_PORT_DDI_D_4_LANES) | \
Satheeshakrishna M14071212015-01-16 15:57:51 +0000981 BIT(POWER_DOMAIN_AUX_D) | \
Daniel Vetter9c065a72014-09-30 10:56:38 +0200982 BIT(POWER_DOMAIN_INIT))
983
984#define CHV_DPIO_TX_D_LANES_23_POWER_DOMAINS ( \
985 BIT(POWER_DOMAIN_PORT_DDI_D_4_LANES) | \
Satheeshakrishna M14071212015-01-16 15:57:51 +0000986 BIT(POWER_DOMAIN_AUX_D) | \
Daniel Vetter9c065a72014-09-30 10:56:38 +0200987 BIT(POWER_DOMAIN_INIT))
988
989static const struct i915_power_well_ops i9xx_always_on_power_well_ops = {
990 .sync_hw = i9xx_always_on_power_well_noop,
991 .enable = i9xx_always_on_power_well_noop,
992 .disable = i9xx_always_on_power_well_noop,
993 .is_enabled = i9xx_always_on_power_well_enabled,
994};
995
996static const struct i915_power_well_ops chv_pipe_power_well_ops = {
997 .sync_hw = chv_pipe_power_well_sync_hw,
998 .enable = chv_pipe_power_well_enable,
999 .disable = chv_pipe_power_well_disable,
1000 .is_enabled = chv_pipe_power_well_enabled,
1001};
1002
1003static const struct i915_power_well_ops chv_dpio_cmn_power_well_ops = {
1004 .sync_hw = vlv_power_well_sync_hw,
1005 .enable = chv_dpio_cmn_power_well_enable,
1006 .disable = chv_dpio_cmn_power_well_disable,
1007 .is_enabled = vlv_power_well_enabled,
1008};
1009
1010static struct i915_power_well i9xx_always_on_power_well[] = {
1011 {
1012 .name = "always-on",
1013 .always_on = 1,
1014 .domains = POWER_DOMAIN_MASK,
1015 .ops = &i9xx_always_on_power_well_ops,
1016 },
1017};
1018
1019static const struct i915_power_well_ops hsw_power_well_ops = {
1020 .sync_hw = hsw_power_well_sync_hw,
1021 .enable = hsw_power_well_enable,
1022 .disable = hsw_power_well_disable,
1023 .is_enabled = hsw_power_well_enabled,
1024};
1025
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00001026static const struct i915_power_well_ops skl_power_well_ops = {
1027 .sync_hw = skl_power_well_sync_hw,
1028 .enable = skl_power_well_enable,
1029 .disable = skl_power_well_disable,
1030 .is_enabled = skl_power_well_enabled,
1031};
1032
Daniel Vetter9c065a72014-09-30 10:56:38 +02001033static struct i915_power_well hsw_power_wells[] = {
1034 {
1035 .name = "always-on",
1036 .always_on = 1,
1037 .domains = HSW_ALWAYS_ON_POWER_DOMAINS,
1038 .ops = &i9xx_always_on_power_well_ops,
1039 },
1040 {
1041 .name = "display",
1042 .domains = HSW_DISPLAY_POWER_DOMAINS,
1043 .ops = &hsw_power_well_ops,
1044 },
1045};
1046
1047static struct i915_power_well bdw_power_wells[] = {
1048 {
1049 .name = "always-on",
1050 .always_on = 1,
1051 .domains = BDW_ALWAYS_ON_POWER_DOMAINS,
1052 .ops = &i9xx_always_on_power_well_ops,
1053 },
1054 {
1055 .name = "display",
1056 .domains = BDW_DISPLAY_POWER_DOMAINS,
1057 .ops = &hsw_power_well_ops,
1058 },
1059};
1060
1061static const struct i915_power_well_ops vlv_display_power_well_ops = {
1062 .sync_hw = vlv_power_well_sync_hw,
1063 .enable = vlv_display_power_well_enable,
1064 .disable = vlv_display_power_well_disable,
1065 .is_enabled = vlv_power_well_enabled,
1066};
1067
1068static const struct i915_power_well_ops vlv_dpio_cmn_power_well_ops = {
1069 .sync_hw = vlv_power_well_sync_hw,
1070 .enable = vlv_dpio_cmn_power_well_enable,
1071 .disable = vlv_dpio_cmn_power_well_disable,
1072 .is_enabled = vlv_power_well_enabled,
1073};
1074
1075static const struct i915_power_well_ops vlv_dpio_power_well_ops = {
1076 .sync_hw = vlv_power_well_sync_hw,
1077 .enable = vlv_power_well_enable,
1078 .disable = vlv_power_well_disable,
1079 .is_enabled = vlv_power_well_enabled,
1080};
1081
1082static struct i915_power_well vlv_power_wells[] = {
1083 {
1084 .name = "always-on",
1085 .always_on = 1,
1086 .domains = VLV_ALWAYS_ON_POWER_DOMAINS,
1087 .ops = &i9xx_always_on_power_well_ops,
1088 },
1089 {
1090 .name = "display",
1091 .domains = VLV_DISPLAY_POWER_DOMAINS,
1092 .data = PUNIT_POWER_WELL_DISP2D,
1093 .ops = &vlv_display_power_well_ops,
1094 },
1095 {
1096 .name = "dpio-tx-b-01",
1097 .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
1098 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
1099 VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
1100 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
1101 .ops = &vlv_dpio_power_well_ops,
1102 .data = PUNIT_POWER_WELL_DPIO_TX_B_LANES_01,
1103 },
1104 {
1105 .name = "dpio-tx-b-23",
1106 .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
1107 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
1108 VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
1109 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
1110 .ops = &vlv_dpio_power_well_ops,
1111 .data = PUNIT_POWER_WELL_DPIO_TX_B_LANES_23,
1112 },
1113 {
1114 .name = "dpio-tx-c-01",
1115 .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
1116 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
1117 VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
1118 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
1119 .ops = &vlv_dpio_power_well_ops,
1120 .data = PUNIT_POWER_WELL_DPIO_TX_C_LANES_01,
1121 },
1122 {
1123 .name = "dpio-tx-c-23",
1124 .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
1125 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
1126 VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
1127 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
1128 .ops = &vlv_dpio_power_well_ops,
1129 .data = PUNIT_POWER_WELL_DPIO_TX_C_LANES_23,
1130 },
1131 {
1132 .name = "dpio-common",
1133 .domains = VLV_DPIO_CMN_BC_POWER_DOMAINS,
1134 .data = PUNIT_POWER_WELL_DPIO_CMN_BC,
1135 .ops = &vlv_dpio_cmn_power_well_ops,
1136 },
1137};
1138
1139static struct i915_power_well chv_power_wells[] = {
1140 {
1141 .name = "always-on",
1142 .always_on = 1,
1143 .domains = VLV_ALWAYS_ON_POWER_DOMAINS,
1144 .ops = &i9xx_always_on_power_well_ops,
1145 },
1146#if 0
1147 {
1148 .name = "display",
1149 .domains = VLV_DISPLAY_POWER_DOMAINS,
1150 .data = PUNIT_POWER_WELL_DISP2D,
1151 .ops = &vlv_display_power_well_ops,
1152 },
Ville Syrjäläbaa4e572014-10-27 16:07:32 +02001153#endif
Daniel Vetter9c065a72014-09-30 10:56:38 +02001154 {
1155 .name = "pipe-a",
Ville Syrjäläbaa4e572014-10-27 16:07:32 +02001156 /*
1157 * FIXME: pipe A power well seems to be the new disp2d well.
1158 * At least all registers seem to be housed there. Figure
1159 * out if this a a temporary situation in pre-production
1160 * hardware or a permanent state of affairs.
1161 */
1162 .domains = CHV_PIPE_A_POWER_DOMAINS | VLV_DISPLAY_POWER_DOMAINS,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001163 .data = PIPE_A,
1164 .ops = &chv_pipe_power_well_ops,
1165 },
Ville Syrjäläbaa4e572014-10-27 16:07:32 +02001166#if 0
Daniel Vetter9c065a72014-09-30 10:56:38 +02001167 {
1168 .name = "pipe-b",
1169 .domains = CHV_PIPE_B_POWER_DOMAINS,
1170 .data = PIPE_B,
1171 .ops = &chv_pipe_power_well_ops,
1172 },
1173 {
1174 .name = "pipe-c",
1175 .domains = CHV_PIPE_C_POWER_DOMAINS,
1176 .data = PIPE_C,
1177 .ops = &chv_pipe_power_well_ops,
1178 },
1179#endif
1180 {
1181 .name = "dpio-common-bc",
1182 /*
1183 * XXX: cmnreset for one PHY seems to disturb the other.
1184 * As a workaround keep both powered on at the same
1185 * time for now.
1186 */
1187 .domains = CHV_DPIO_CMN_BC_POWER_DOMAINS | CHV_DPIO_CMN_D_POWER_DOMAINS,
1188 .data = PUNIT_POWER_WELL_DPIO_CMN_BC,
1189 .ops = &chv_dpio_cmn_power_well_ops,
1190 },
1191 {
1192 .name = "dpio-common-d",
1193 /*
1194 * XXX: cmnreset for one PHY seems to disturb the other.
1195 * As a workaround keep both powered on at the same
1196 * time for now.
1197 */
1198 .domains = CHV_DPIO_CMN_BC_POWER_DOMAINS | CHV_DPIO_CMN_D_POWER_DOMAINS,
1199 .data = PUNIT_POWER_WELL_DPIO_CMN_D,
1200 .ops = &chv_dpio_cmn_power_well_ops,
1201 },
1202#if 0
1203 {
1204 .name = "dpio-tx-b-01",
1205 .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
1206 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS,
1207 .ops = &vlv_dpio_power_well_ops,
1208 .data = PUNIT_POWER_WELL_DPIO_TX_B_LANES_01,
1209 },
1210 {
1211 .name = "dpio-tx-b-23",
1212 .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
1213 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS,
1214 .ops = &vlv_dpio_power_well_ops,
1215 .data = PUNIT_POWER_WELL_DPIO_TX_B_LANES_23,
1216 },
1217 {
1218 .name = "dpio-tx-c-01",
1219 .domains = VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
1220 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
1221 .ops = &vlv_dpio_power_well_ops,
1222 .data = PUNIT_POWER_WELL_DPIO_TX_C_LANES_01,
1223 },
1224 {
1225 .name = "dpio-tx-c-23",
1226 .domains = VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
1227 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
1228 .ops = &vlv_dpio_power_well_ops,
1229 .data = PUNIT_POWER_WELL_DPIO_TX_C_LANES_23,
1230 },
1231 {
1232 .name = "dpio-tx-d-01",
1233 .domains = CHV_DPIO_TX_D_LANES_01_POWER_DOMAINS |
1234 CHV_DPIO_TX_D_LANES_23_POWER_DOMAINS,
1235 .ops = &vlv_dpio_power_well_ops,
1236 .data = PUNIT_POWER_WELL_DPIO_TX_D_LANES_01,
1237 },
1238 {
1239 .name = "dpio-tx-d-23",
1240 .domains = CHV_DPIO_TX_D_LANES_01_POWER_DOMAINS |
1241 CHV_DPIO_TX_D_LANES_23_POWER_DOMAINS,
1242 .ops = &vlv_dpio_power_well_ops,
1243 .data = PUNIT_POWER_WELL_DPIO_TX_D_LANES_23,
1244 },
1245#endif
1246};
1247
1248static struct i915_power_well *lookup_power_well(struct drm_i915_private *dev_priv,
1249 enum punit_power_well power_well_id)
1250{
1251 struct i915_power_domains *power_domains = &dev_priv->power_domains;
1252 struct i915_power_well *power_well;
1253 int i;
1254
1255 for_each_power_well(i, power_well, POWER_DOMAIN_MASK, power_domains) {
1256 if (power_well->data == power_well_id)
1257 return power_well;
1258 }
1259
1260 return NULL;
1261}
1262
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00001263static struct i915_power_well skl_power_wells[] = {
1264 {
1265 .name = "always-on",
1266 .always_on = 1,
1267 .domains = SKL_DISPLAY_ALWAYS_ON_POWER_DOMAINS,
1268 .ops = &i9xx_always_on_power_well_ops,
1269 },
1270 {
1271 .name = "power well 1",
1272 .domains = SKL_DISPLAY_POWERWELL_1_POWER_DOMAINS,
1273 .ops = &skl_power_well_ops,
1274 .data = SKL_DISP_PW_1,
1275 },
1276 {
1277 .name = "MISC IO power well",
1278 .domains = SKL_DISPLAY_MISC_IO_POWER_DOMAINS,
1279 .ops = &skl_power_well_ops,
1280 .data = SKL_DISP_PW_MISC_IO,
1281 },
1282 {
1283 .name = "power well 2",
1284 .domains = SKL_DISPLAY_POWERWELL_2_POWER_DOMAINS,
1285 .ops = &skl_power_well_ops,
1286 .data = SKL_DISP_PW_2,
1287 },
1288 {
1289 .name = "DDI A/E power well",
1290 .domains = SKL_DISPLAY_DDI_A_E_POWER_DOMAINS,
1291 .ops = &skl_power_well_ops,
1292 .data = SKL_DISP_PW_DDI_A_E,
1293 },
1294 {
1295 .name = "DDI B power well",
1296 .domains = SKL_DISPLAY_DDI_B_POWER_DOMAINS,
1297 .ops = &skl_power_well_ops,
1298 .data = SKL_DISP_PW_DDI_B,
1299 },
1300 {
1301 .name = "DDI C power well",
1302 .domains = SKL_DISPLAY_DDI_C_POWER_DOMAINS,
1303 .ops = &skl_power_well_ops,
1304 .data = SKL_DISP_PW_DDI_C,
1305 },
1306 {
1307 .name = "DDI D power well",
1308 .domains = SKL_DISPLAY_DDI_D_POWER_DOMAINS,
1309 .ops = &skl_power_well_ops,
1310 .data = SKL_DISP_PW_DDI_D,
1311 },
1312};
1313
Daniel Vetter9c065a72014-09-30 10:56:38 +02001314#define set_power_wells(power_domains, __power_wells) ({ \
1315 (power_domains)->power_wells = (__power_wells); \
1316 (power_domains)->power_well_count = ARRAY_SIZE(__power_wells); \
1317})
1318
Daniel Vettere4e76842014-09-30 10:56:42 +02001319/**
1320 * intel_power_domains_init - initializes the power domain structures
1321 * @dev_priv: i915 device instance
1322 *
1323 * Initializes the power domain structures for @dev_priv depending upon the
1324 * supported platform.
1325 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02001326int intel_power_domains_init(struct drm_i915_private *dev_priv)
1327{
1328 struct i915_power_domains *power_domains = &dev_priv->power_domains;
1329
1330 mutex_init(&power_domains->lock);
1331
1332 /*
1333 * The enabling order will be from lower to higher indexed wells,
1334 * the disabling order is reversed.
1335 */
1336 if (IS_HASWELL(dev_priv->dev)) {
1337 set_power_wells(power_domains, hsw_power_wells);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001338 } else if (IS_BROADWELL(dev_priv->dev)) {
1339 set_power_wells(power_domains, bdw_power_wells);
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00001340 } else if (IS_SKYLAKE(dev_priv->dev)) {
1341 set_power_wells(power_domains, skl_power_wells);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001342 } else if (IS_CHERRYVIEW(dev_priv->dev)) {
1343 set_power_wells(power_domains, chv_power_wells);
1344 } else if (IS_VALLEYVIEW(dev_priv->dev)) {
1345 set_power_wells(power_domains, vlv_power_wells);
1346 } else {
1347 set_power_wells(power_domains, i9xx_always_on_power_well);
1348 }
1349
1350 return 0;
1351}
1352
Daniel Vetter41373cd2014-09-30 10:56:41 +02001353static void intel_runtime_pm_disable(struct drm_i915_private *dev_priv)
1354{
1355 struct drm_device *dev = dev_priv->dev;
1356 struct device *device = &dev->pdev->dev;
1357
1358 if (!HAS_RUNTIME_PM(dev))
1359 return;
1360
1361 if (!intel_enable_rc6(dev))
1362 return;
1363
1364 /* Make sure we're not suspended first. */
1365 pm_runtime_get_sync(device);
1366 pm_runtime_disable(device);
1367}
1368
Daniel Vettere4e76842014-09-30 10:56:42 +02001369/**
1370 * intel_power_domains_fini - finalizes the power domain structures
1371 * @dev_priv: i915 device instance
1372 *
1373 * Finalizes the power domain structures for @dev_priv depending upon the
1374 * supported platform. This function also disables runtime pm and ensures that
1375 * the device stays powered up so that the driver can be reloaded.
1376 */
Daniel Vetterf458ebb2014-09-30 10:56:39 +02001377void intel_power_domains_fini(struct drm_i915_private *dev_priv)
Daniel Vetter9c065a72014-09-30 10:56:38 +02001378{
Daniel Vetter41373cd2014-09-30 10:56:41 +02001379 intel_runtime_pm_disable(dev_priv);
1380
Daniel Vetterf458ebb2014-09-30 10:56:39 +02001381 /* The i915.ko module is still not prepared to be loaded when
1382 * the power well is not enabled, so just enable it in case
1383 * we're going to unload/reload. */
1384 intel_display_set_init_power(dev_priv, true);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001385}
1386
1387static void intel_power_domains_resume(struct drm_i915_private *dev_priv)
1388{
1389 struct i915_power_domains *power_domains = &dev_priv->power_domains;
1390 struct i915_power_well *power_well;
1391 int i;
1392
1393 mutex_lock(&power_domains->lock);
1394 for_each_power_well(i, power_well, POWER_DOMAIN_MASK, power_domains) {
1395 power_well->ops->sync_hw(dev_priv, power_well);
1396 power_well->hw_enabled = power_well->ops->is_enabled(dev_priv,
1397 power_well);
1398 }
1399 mutex_unlock(&power_domains->lock);
1400}
1401
1402static void vlv_cmnlane_wa(struct drm_i915_private *dev_priv)
1403{
1404 struct i915_power_well *cmn =
1405 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_BC);
1406 struct i915_power_well *disp2d =
1407 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DISP2D);
1408
Daniel Vetter9c065a72014-09-30 10:56:38 +02001409 /* If the display might be already active skip this */
Ville Syrjälä5d93a6e2014-10-16 20:52:33 +03001410 if (cmn->ops->is_enabled(dev_priv, cmn) &&
1411 disp2d->ops->is_enabled(dev_priv, disp2d) &&
Daniel Vetter9c065a72014-09-30 10:56:38 +02001412 I915_READ(DPIO_CTL) & DPIO_CMNRST)
1413 return;
1414
1415 DRM_DEBUG_KMS("toggling display PHY side reset\n");
1416
1417 /* cmnlane needs DPLL registers */
1418 disp2d->ops->enable(dev_priv, disp2d);
1419
1420 /*
1421 * From VLV2A0_DP_eDP_HDMI_DPIO_driver_vbios_notes_11.docx:
1422 * Need to assert and de-assert PHY SB reset by gating the
1423 * common lane power, then un-gating it.
1424 * Simply ungating isn't enough to reset the PHY enough to get
1425 * ports and lanes running.
1426 */
1427 cmn->ops->disable(dev_priv, cmn);
1428}
1429
Daniel Vettere4e76842014-09-30 10:56:42 +02001430/**
1431 * intel_power_domains_init_hw - initialize hardware power domain state
1432 * @dev_priv: i915 device instance
1433 *
1434 * This function initializes the hardware power domain state and enables all
1435 * power domains using intel_display_set_init_power().
1436 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02001437void intel_power_domains_init_hw(struct drm_i915_private *dev_priv)
1438{
1439 struct drm_device *dev = dev_priv->dev;
1440 struct i915_power_domains *power_domains = &dev_priv->power_domains;
1441
1442 power_domains->initializing = true;
1443
1444 if (IS_VALLEYVIEW(dev) && !IS_CHERRYVIEW(dev)) {
1445 mutex_lock(&power_domains->lock);
1446 vlv_cmnlane_wa(dev_priv);
1447 mutex_unlock(&power_domains->lock);
1448 }
1449
1450 /* For now, we need the power well to be always enabled. */
1451 intel_display_set_init_power(dev_priv, true);
1452 intel_power_domains_resume(dev_priv);
1453 power_domains->initializing = false;
1454}
1455
Daniel Vettere4e76842014-09-30 10:56:42 +02001456/**
1457 * intel_aux_display_runtime_get - grab an auxilliary power domain reference
1458 * @dev_priv: i915 device instance
1459 *
1460 * This function grabs a power domain reference for the auxiliary power domain
1461 * (for access to the GMBUS and DP AUX blocks) and ensures that it and all its
1462 * parents are powered up. Therefore users should only grab a reference to the
1463 * innermost power domain they need.
1464 *
1465 * Any power domain reference obtained by this function must have a symmetric
1466 * call to intel_aux_display_runtime_put() to release the reference again.
1467 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02001468void intel_aux_display_runtime_get(struct drm_i915_private *dev_priv)
1469{
1470 intel_runtime_pm_get(dev_priv);
1471}
1472
Daniel Vettere4e76842014-09-30 10:56:42 +02001473/**
1474 * intel_aux_display_runtime_put - release an auxilliary power domain reference
1475 * @dev_priv: i915 device instance
1476 *
1477 * This function drops the auxilliary power domain reference obtained by
1478 * intel_aux_display_runtime_get() and might power down the corresponding
1479 * hardware block right away if this is the last reference.
1480 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02001481void intel_aux_display_runtime_put(struct drm_i915_private *dev_priv)
1482{
1483 intel_runtime_pm_put(dev_priv);
1484}
1485
Daniel Vettere4e76842014-09-30 10:56:42 +02001486/**
1487 * intel_runtime_pm_get - grab a runtime pm reference
1488 * @dev_priv: i915 device instance
1489 *
1490 * This function grabs a device-level runtime pm reference (mostly used for GEM
1491 * code to ensure the GTT or GT is on) and ensures that it is powered up.
1492 *
1493 * Any runtime pm reference obtained by this function must have a symmetric
1494 * call to intel_runtime_pm_put() to release the reference again.
1495 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02001496void intel_runtime_pm_get(struct drm_i915_private *dev_priv)
1497{
1498 struct drm_device *dev = dev_priv->dev;
1499 struct device *device = &dev->pdev->dev;
1500
1501 if (!HAS_RUNTIME_PM(dev))
1502 return;
1503
1504 pm_runtime_get_sync(device);
1505 WARN(dev_priv->pm.suspended, "Device still suspended.\n");
1506}
1507
Daniel Vettere4e76842014-09-30 10:56:42 +02001508/**
1509 * intel_runtime_pm_get_noresume - grab a runtime pm reference
1510 * @dev_priv: i915 device instance
1511 *
1512 * This function grabs a device-level runtime pm reference (mostly used for GEM
1513 * code to ensure the GTT or GT is on).
1514 *
1515 * It will _not_ power up the device but instead only check that it's powered
1516 * on. Therefore it is only valid to call this functions from contexts where
1517 * the device is known to be powered up and where trying to power it up would
1518 * result in hilarity and deadlocks. That pretty much means only the system
1519 * suspend/resume code where this is used to grab runtime pm references for
1520 * delayed setup down in work items.
1521 *
1522 * Any runtime pm reference obtained by this function must have a symmetric
1523 * call to intel_runtime_pm_put() to release the reference again.
1524 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02001525void intel_runtime_pm_get_noresume(struct drm_i915_private *dev_priv)
1526{
1527 struct drm_device *dev = dev_priv->dev;
1528 struct device *device = &dev->pdev->dev;
1529
1530 if (!HAS_RUNTIME_PM(dev))
1531 return;
1532
1533 WARN(dev_priv->pm.suspended, "Getting nosync-ref while suspended.\n");
1534 pm_runtime_get_noresume(device);
1535}
1536
Daniel Vettere4e76842014-09-30 10:56:42 +02001537/**
1538 * intel_runtime_pm_put - release a runtime pm reference
1539 * @dev_priv: i915 device instance
1540 *
1541 * This function drops the device-level runtime pm reference obtained by
1542 * intel_runtime_pm_get() and might power down the corresponding
1543 * hardware block right away if this is the last reference.
1544 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02001545void intel_runtime_pm_put(struct drm_i915_private *dev_priv)
1546{
1547 struct drm_device *dev = dev_priv->dev;
1548 struct device *device = &dev->pdev->dev;
1549
1550 if (!HAS_RUNTIME_PM(dev))
1551 return;
1552
1553 pm_runtime_mark_last_busy(device);
1554 pm_runtime_put_autosuspend(device);
1555}
1556
Daniel Vettere4e76842014-09-30 10:56:42 +02001557/**
1558 * intel_runtime_pm_enable - enable runtime pm
1559 * @dev_priv: i915 device instance
1560 *
1561 * This function enables runtime pm at the end of the driver load sequence.
1562 *
1563 * Note that this function does currently not enable runtime pm for the
1564 * subordinate display power domains. That is only done on the first modeset
1565 * using intel_display_set_init_power().
1566 */
Daniel Vetterf458ebb2014-09-30 10:56:39 +02001567void intel_runtime_pm_enable(struct drm_i915_private *dev_priv)
Daniel Vetter9c065a72014-09-30 10:56:38 +02001568{
1569 struct drm_device *dev = dev_priv->dev;
1570 struct device *device = &dev->pdev->dev;
1571
1572 if (!HAS_RUNTIME_PM(dev))
1573 return;
1574
1575 pm_runtime_set_active(device);
1576
1577 /*
1578 * RPM depends on RC6 to save restore the GT HW context, so make RC6 a
1579 * requirement.
1580 */
1581 if (!intel_enable_rc6(dev)) {
1582 DRM_INFO("RC6 disabled, disabling runtime PM support\n");
1583 return;
1584 }
1585
1586 pm_runtime_set_autosuspend_delay(device, 10000); /* 10s */
1587 pm_runtime_mark_last_busy(device);
1588 pm_runtime_use_autosuspend(device);
1589
1590 pm_runtime_put_autosuspend(device);
1591}
1592