blob: 7991eff01662be6d3041c4b1191149e3b84b4551 [file] [log] [blame]
Daniel Vetter9c065a72014-09-30 10:56:38 +02001/*
2 * Copyright © 2012-2014 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 *
23 * Authors:
24 * Eugeni Dodonov <eugeni.dodonov@intel.com>
25 * Daniel Vetter <daniel.vetter@ffwll.ch>
26 *
27 */
28
29#include <linux/pm_runtime.h>
30#include <linux/vgaarb.h>
31
32#include "i915_drv.h"
33#include "intel_drv.h"
Daniel Vetter9c065a72014-09-30 10:56:38 +020034
Daniel Vettere4e76842014-09-30 10:56:42 +020035/**
36 * DOC: runtime pm
37 *
38 * The i915 driver supports dynamic enabling and disabling of entire hardware
39 * blocks at runtime. This is especially important on the display side where
40 * software is supposed to control many power gates manually on recent hardware,
41 * since on the GT side a lot of the power management is done by the hardware.
42 * But even there some manual control at the device level is required.
43 *
44 * Since i915 supports a diverse set of platforms with a unified codebase and
45 * hardware engineers just love to shuffle functionality around between power
46 * domains there's a sizeable amount of indirection required. This file provides
47 * generic functions to the driver for grabbing and releasing references for
48 * abstract power domains. It then maps those to the actual power wells
49 * present for a given platform.
50 */
51
Suketu Shahf75a1982015-04-16 14:22:11 +053052#define GEN9_ENABLE_DC5(dev) 0
53#define SKL_ENABLE_DC6(dev) IS_SKYLAKE(dev)
Suketu Shahdc174302015-04-17 19:46:16 +053054
Daniel Vetter9c065a72014-09-30 10:56:38 +020055#define for_each_power_well(i, power_well, domain_mask, power_domains) \
56 for (i = 0; \
57 i < (power_domains)->power_well_count && \
58 ((power_well) = &(power_domains)->power_wells[i]); \
59 i++) \
60 if ((power_well)->domains & (domain_mask))
61
62#define for_each_power_well_rev(i, power_well, domain_mask, power_domains) \
63 for (i = (power_domains)->power_well_count - 1; \
64 i >= 0 && ((power_well) = &(power_domains)->power_wells[i]);\
65 i--) \
66 if ((power_well)->domains & (domain_mask))
67
Suketu Shah5aefb232015-04-16 14:22:10 +053068bool intel_display_power_well_is_enabled(struct drm_i915_private *dev_priv,
69 int power_well_id);
70
Damien Lespiaue8ca9322015-07-30 18:20:26 -030071static void intel_power_well_enable(struct drm_i915_private *dev_priv,
72 struct i915_power_well *power_well)
73{
74 DRM_DEBUG_KMS("enabling %s\n", power_well->name);
75 power_well->ops->enable(dev_priv, power_well);
76 power_well->hw_enabled = true;
77}
78
Damien Lespiaudcddab32015-07-30 18:20:27 -030079static void intel_power_well_disable(struct drm_i915_private *dev_priv,
80 struct i915_power_well *power_well)
81{
82 DRM_DEBUG_KMS("disabling %s\n", power_well->name);
83 power_well->hw_enabled = false;
84 power_well->ops->disable(dev_priv, power_well);
85}
86
Daniel Vettere4e76842014-09-30 10:56:42 +020087/*
Daniel Vetter9c065a72014-09-30 10:56:38 +020088 * We should only use the power well if we explicitly asked the hardware to
89 * enable it, so check if it's enabled and also check if we've requested it to
90 * be enabled.
91 */
92static bool hsw_power_well_enabled(struct drm_i915_private *dev_priv,
93 struct i915_power_well *power_well)
94{
95 return I915_READ(HSW_PWR_WELL_DRIVER) ==
96 (HSW_PWR_WELL_ENABLE_REQUEST | HSW_PWR_WELL_STATE_ENABLED);
97}
98
Daniel Vettere4e76842014-09-30 10:56:42 +020099/**
100 * __intel_display_power_is_enabled - unlocked check for a power domain
101 * @dev_priv: i915 device instance
102 * @domain: power domain to check
103 *
104 * This is the unlocked version of intel_display_power_is_enabled() and should
105 * only be used from error capture and recovery code where deadlocks are
106 * possible.
107 *
108 * Returns:
109 * True when the power domain is enabled, false otherwise.
110 */
Daniel Vetterf458ebb2014-09-30 10:56:39 +0200111bool __intel_display_power_is_enabled(struct drm_i915_private *dev_priv,
112 enum intel_display_power_domain domain)
Daniel Vetter9c065a72014-09-30 10:56:38 +0200113{
114 struct i915_power_domains *power_domains;
115 struct i915_power_well *power_well;
116 bool is_enabled;
117 int i;
118
119 if (dev_priv->pm.suspended)
120 return false;
121
122 power_domains = &dev_priv->power_domains;
123
124 is_enabled = true;
125
126 for_each_power_well_rev(i, power_well, BIT(domain), power_domains) {
127 if (power_well->always_on)
128 continue;
129
130 if (!power_well->hw_enabled) {
131 is_enabled = false;
132 break;
133 }
134 }
135
136 return is_enabled;
137}
138
Daniel Vettere4e76842014-09-30 10:56:42 +0200139/**
Damien Lespiauf61ccae2014-11-25 13:45:41 +0000140 * intel_display_power_is_enabled - check for a power domain
Daniel Vettere4e76842014-09-30 10:56:42 +0200141 * @dev_priv: i915 device instance
142 * @domain: power domain to check
143 *
144 * This function can be used to check the hw power domain state. It is mostly
145 * used in hardware state readout functions. Everywhere else code should rely
146 * upon explicit power domain reference counting to ensure that the hardware
147 * block is powered up before accessing it.
148 *
149 * Callers must hold the relevant modesetting locks to ensure that concurrent
150 * threads can't disable the power well while the caller tries to read a few
151 * registers.
152 *
153 * Returns:
154 * True when the power domain is enabled, false otherwise.
155 */
Daniel Vetterf458ebb2014-09-30 10:56:39 +0200156bool intel_display_power_is_enabled(struct drm_i915_private *dev_priv,
157 enum intel_display_power_domain domain)
Daniel Vetter9c065a72014-09-30 10:56:38 +0200158{
159 struct i915_power_domains *power_domains;
160 bool ret;
161
162 power_domains = &dev_priv->power_domains;
163
164 mutex_lock(&power_domains->lock);
Daniel Vetterf458ebb2014-09-30 10:56:39 +0200165 ret = __intel_display_power_is_enabled(dev_priv, domain);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200166 mutex_unlock(&power_domains->lock);
167
168 return ret;
169}
170
Daniel Vettere4e76842014-09-30 10:56:42 +0200171/**
172 * intel_display_set_init_power - set the initial power domain state
173 * @dev_priv: i915 device instance
174 * @enable: whether to enable or disable the initial power domain state
175 *
176 * For simplicity our driver load/unload and system suspend/resume code assumes
177 * that all power domains are always enabled. This functions controls the state
178 * of this little hack. While the initial power domain state is enabled runtime
179 * pm is effectively disabled.
180 */
Daniel Vetterd9bc89d92014-09-30 10:56:40 +0200181void intel_display_set_init_power(struct drm_i915_private *dev_priv,
182 bool enable)
183{
184 if (dev_priv->power_domains.init_power_on == enable)
185 return;
186
187 if (enable)
188 intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
189 else
190 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
191
192 dev_priv->power_domains.init_power_on = enable;
193}
194
Daniel Vetter9c065a72014-09-30 10:56:38 +0200195/*
196 * Starting with Haswell, we have a "Power Down Well" that can be turned off
197 * when not needed anymore. We have 4 registers that can request the power well
198 * to be enabled, and it will only be disabled if none of the registers is
199 * requesting it to be enabled.
200 */
201static void hsw_power_well_post_enable(struct drm_i915_private *dev_priv)
202{
203 struct drm_device *dev = dev_priv->dev;
204
205 /*
206 * After we re-enable the power well, if we touch VGA register 0x3d5
207 * we'll get unclaimed register interrupts. This stops after we write
208 * anything to the VGA MSR register. The vgacon module uses this
209 * register all the time, so if we unbind our driver and, as a
210 * consequence, bind vgacon, we'll get stuck in an infinite loop at
211 * console_unlock(). So make here we touch the VGA MSR register, making
212 * sure vgacon can keep working normally without triggering interrupts
213 * and error messages.
214 */
215 vga_get_uninterruptible(dev->pdev, VGA_RSRC_LEGACY_IO);
216 outb(inb(VGA_MSR_READ), VGA_MSR_WRITE);
217 vga_put(dev->pdev, VGA_RSRC_LEGACY_IO);
218
Damien Lespiau25400392015-03-06 18:50:52 +0000219 if (IS_BROADWELL(dev))
Damien Lespiau4c6c03b2015-03-06 18:50:48 +0000220 gen8_irq_power_well_post_enable(dev_priv,
221 1 << PIPE_C | 1 << PIPE_B);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200222}
223
Damien Lespiaud14c0342015-03-06 18:50:51 +0000224static void skl_power_well_post_enable(struct drm_i915_private *dev_priv,
225 struct i915_power_well *power_well)
226{
227 struct drm_device *dev = dev_priv->dev;
228
229 /*
230 * After we re-enable the power well, if we touch VGA register 0x3d5
231 * we'll get unclaimed register interrupts. This stops after we write
232 * anything to the VGA MSR register. The vgacon module uses this
233 * register all the time, so if we unbind our driver and, as a
234 * consequence, bind vgacon, we'll get stuck in an infinite loop at
235 * console_unlock(). So make here we touch the VGA MSR register, making
236 * sure vgacon can keep working normally without triggering interrupts
237 * and error messages.
238 */
239 if (power_well->data == SKL_DISP_PW_2) {
240 vga_get_uninterruptible(dev->pdev, VGA_RSRC_LEGACY_IO);
241 outb(inb(VGA_MSR_READ), VGA_MSR_WRITE);
242 vga_put(dev->pdev, VGA_RSRC_LEGACY_IO);
243
244 gen8_irq_power_well_post_enable(dev_priv,
245 1 << PIPE_C | 1 << PIPE_B);
246 }
247
Damien Lespiau1d2b9522015-03-06 18:50:53 +0000248 if (power_well->data == SKL_DISP_PW_1) {
249 intel_prepare_ddi(dev);
Damien Lespiaud14c0342015-03-06 18:50:51 +0000250 gen8_irq_power_well_post_enable(dev_priv, 1 << PIPE_A);
Damien Lespiau1d2b9522015-03-06 18:50:53 +0000251 }
Damien Lespiaud14c0342015-03-06 18:50:51 +0000252}
253
Daniel Vetter9c065a72014-09-30 10:56:38 +0200254static void hsw_set_power_well(struct drm_i915_private *dev_priv,
255 struct i915_power_well *power_well, bool enable)
256{
257 bool is_enabled, enable_requested;
258 uint32_t tmp;
259
260 tmp = I915_READ(HSW_PWR_WELL_DRIVER);
261 is_enabled = tmp & HSW_PWR_WELL_STATE_ENABLED;
262 enable_requested = tmp & HSW_PWR_WELL_ENABLE_REQUEST;
263
264 if (enable) {
265 if (!enable_requested)
266 I915_WRITE(HSW_PWR_WELL_DRIVER,
267 HSW_PWR_WELL_ENABLE_REQUEST);
268
269 if (!is_enabled) {
270 DRM_DEBUG_KMS("Enabling power well\n");
271 if (wait_for((I915_READ(HSW_PWR_WELL_DRIVER) &
272 HSW_PWR_WELL_STATE_ENABLED), 20))
273 DRM_ERROR("Timeout enabling power well\n");
Paulo Zanoni6d729bf2014-10-07 16:11:11 -0300274 hsw_power_well_post_enable(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200275 }
276
Daniel Vetter9c065a72014-09-30 10:56:38 +0200277 } else {
278 if (enable_requested) {
279 I915_WRITE(HSW_PWR_WELL_DRIVER, 0);
280 POSTING_READ(HSW_PWR_WELL_DRIVER);
281 DRM_DEBUG_KMS("Requesting to disable the power well\n");
282 }
283 }
284}
285
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000286#define SKL_DISPLAY_POWERWELL_2_POWER_DOMAINS ( \
287 BIT(POWER_DOMAIN_TRANSCODER_A) | \
288 BIT(POWER_DOMAIN_PIPE_B) | \
289 BIT(POWER_DOMAIN_TRANSCODER_B) | \
290 BIT(POWER_DOMAIN_PIPE_C) | \
291 BIT(POWER_DOMAIN_TRANSCODER_C) | \
292 BIT(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
293 BIT(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
294 BIT(POWER_DOMAIN_PORT_DDI_B_2_LANES) | \
295 BIT(POWER_DOMAIN_PORT_DDI_B_4_LANES) | \
296 BIT(POWER_DOMAIN_PORT_DDI_C_2_LANES) | \
297 BIT(POWER_DOMAIN_PORT_DDI_C_4_LANES) | \
298 BIT(POWER_DOMAIN_PORT_DDI_D_2_LANES) | \
299 BIT(POWER_DOMAIN_PORT_DDI_D_4_LANES) | \
300 BIT(POWER_DOMAIN_AUX_B) | \
301 BIT(POWER_DOMAIN_AUX_C) | \
302 BIT(POWER_DOMAIN_AUX_D) | \
303 BIT(POWER_DOMAIN_AUDIO) | \
304 BIT(POWER_DOMAIN_VGA) | \
305 BIT(POWER_DOMAIN_INIT))
306#define SKL_DISPLAY_POWERWELL_1_POWER_DOMAINS ( \
307 SKL_DISPLAY_POWERWELL_2_POWER_DOMAINS | \
308 BIT(POWER_DOMAIN_PLLS) | \
309 BIT(POWER_DOMAIN_PIPE_A) | \
310 BIT(POWER_DOMAIN_TRANSCODER_EDP) | \
311 BIT(POWER_DOMAIN_PIPE_A_PANEL_FITTER) | \
312 BIT(POWER_DOMAIN_PORT_DDI_A_2_LANES) | \
313 BIT(POWER_DOMAIN_PORT_DDI_A_4_LANES) | \
314 BIT(POWER_DOMAIN_AUX_A) | \
315 BIT(POWER_DOMAIN_INIT))
316#define SKL_DISPLAY_DDI_A_E_POWER_DOMAINS ( \
317 BIT(POWER_DOMAIN_PORT_DDI_A_2_LANES) | \
318 BIT(POWER_DOMAIN_PORT_DDI_A_4_LANES) | \
319 BIT(POWER_DOMAIN_INIT))
320#define SKL_DISPLAY_DDI_B_POWER_DOMAINS ( \
321 BIT(POWER_DOMAIN_PORT_DDI_B_2_LANES) | \
322 BIT(POWER_DOMAIN_PORT_DDI_B_4_LANES) | \
323 BIT(POWER_DOMAIN_INIT))
324#define SKL_DISPLAY_DDI_C_POWER_DOMAINS ( \
325 BIT(POWER_DOMAIN_PORT_DDI_C_2_LANES) | \
326 BIT(POWER_DOMAIN_PORT_DDI_C_4_LANES) | \
327 BIT(POWER_DOMAIN_INIT))
328#define SKL_DISPLAY_DDI_D_POWER_DOMAINS ( \
329 BIT(POWER_DOMAIN_PORT_DDI_D_2_LANES) | \
330 BIT(POWER_DOMAIN_PORT_DDI_D_4_LANES) | \
331 BIT(POWER_DOMAIN_INIT))
332#define SKL_DISPLAY_MISC_IO_POWER_DOMAINS ( \
Damien Lespiauaeaa2122015-04-30 16:39:16 +0100333 SKL_DISPLAY_POWERWELL_1_POWER_DOMAINS | \
Damien Lespiau62227092015-04-30 16:39:20 +0100334 BIT(POWER_DOMAIN_PLLS) | \
Damien Lespiauaeaa2122015-04-30 16:39:16 +0100335 BIT(POWER_DOMAIN_INIT))
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000336#define SKL_DISPLAY_ALWAYS_ON_POWER_DOMAINS ( \
337 (POWER_DOMAIN_MASK & ~(SKL_DISPLAY_POWERWELL_1_POWER_DOMAINS | \
338 SKL_DISPLAY_POWERWELL_2_POWER_DOMAINS | \
339 SKL_DISPLAY_DDI_A_E_POWER_DOMAINS | \
340 SKL_DISPLAY_DDI_B_POWER_DOMAINS | \
341 SKL_DISPLAY_DDI_C_POWER_DOMAINS | \
342 SKL_DISPLAY_DDI_D_POWER_DOMAINS | \
343 SKL_DISPLAY_MISC_IO_POWER_DOMAINS)) | \
344 BIT(POWER_DOMAIN_INIT))
345
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +0530346#define BXT_DISPLAY_POWERWELL_2_POWER_DOMAINS ( \
347 BIT(POWER_DOMAIN_TRANSCODER_A) | \
348 BIT(POWER_DOMAIN_PIPE_B) | \
349 BIT(POWER_DOMAIN_TRANSCODER_B) | \
350 BIT(POWER_DOMAIN_PIPE_C) | \
351 BIT(POWER_DOMAIN_TRANSCODER_C) | \
352 BIT(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
353 BIT(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
354 BIT(POWER_DOMAIN_PORT_DDI_B_2_LANES) | \
355 BIT(POWER_DOMAIN_PORT_DDI_B_4_LANES) | \
356 BIT(POWER_DOMAIN_PORT_DDI_C_2_LANES) | \
357 BIT(POWER_DOMAIN_PORT_DDI_C_4_LANES) | \
358 BIT(POWER_DOMAIN_AUX_B) | \
359 BIT(POWER_DOMAIN_AUX_C) | \
360 BIT(POWER_DOMAIN_AUDIO) | \
361 BIT(POWER_DOMAIN_VGA) | \
362 BIT(POWER_DOMAIN_INIT))
363#define BXT_DISPLAY_POWERWELL_1_POWER_DOMAINS ( \
364 BXT_DISPLAY_POWERWELL_2_POWER_DOMAINS | \
365 BIT(POWER_DOMAIN_PIPE_A) | \
366 BIT(POWER_DOMAIN_TRANSCODER_EDP) | \
367 BIT(POWER_DOMAIN_PIPE_A_PANEL_FITTER) | \
368 BIT(POWER_DOMAIN_PORT_DDI_A_2_LANES) | \
369 BIT(POWER_DOMAIN_PORT_DDI_A_4_LANES) | \
370 BIT(POWER_DOMAIN_AUX_A) | \
371 BIT(POWER_DOMAIN_PLLS) | \
372 BIT(POWER_DOMAIN_INIT))
373#define BXT_DISPLAY_ALWAYS_ON_POWER_DOMAINS ( \
374 (POWER_DOMAIN_MASK & ~(BXT_DISPLAY_POWERWELL_1_POWER_DOMAINS | \
375 BXT_DISPLAY_POWERWELL_2_POWER_DOMAINS)) | \
376 BIT(POWER_DOMAIN_INIT))
377
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530378static void assert_can_enable_dc9(struct drm_i915_private *dev_priv)
379{
380 struct drm_device *dev = dev_priv->dev;
381
382 WARN(!IS_BROXTON(dev), "Platform doesn't support DC9.\n");
383 WARN((I915_READ(DC_STATE_EN) & DC_STATE_EN_DC9),
384 "DC9 already programmed to be enabled.\n");
385 WARN(I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC5,
386 "DC5 still not disabled to enable DC9.\n");
387 WARN(I915_READ(HSW_PWR_WELL_DRIVER), "Power well on.\n");
388 WARN(intel_irqs_enabled(dev_priv), "Interrupts not disabled yet.\n");
389
390 /*
391 * TODO: check for the following to verify the conditions to enter DC9
392 * state are satisfied:
393 * 1] Check relevant display engine registers to verify if mode set
394 * disable sequence was followed.
395 * 2] Check if display uninitialize sequence is initialized.
396 */
397}
398
399static void assert_can_disable_dc9(struct drm_i915_private *dev_priv)
400{
401 WARN(intel_irqs_enabled(dev_priv), "Interrupts not disabled yet.\n");
402 WARN(!(I915_READ(DC_STATE_EN) & DC_STATE_EN_DC9),
403 "DC9 already programmed to be disabled.\n");
404 WARN(I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC5,
405 "DC5 still not disabled.\n");
406
407 /*
408 * TODO: check for the following to verify DC9 state was indeed
409 * entered before programming to disable it:
410 * 1] Check relevant display engine registers to verify if mode
411 * set disable sequence was followed.
412 * 2] Check if display uninitialize sequence is initialized.
413 */
414}
415
416void bxt_enable_dc9(struct drm_i915_private *dev_priv)
417{
418 uint32_t val;
419
420 assert_can_enable_dc9(dev_priv);
421
422 DRM_DEBUG_KMS("Enabling DC9\n");
423
424 val = I915_READ(DC_STATE_EN);
425 val |= DC_STATE_EN_DC9;
426 I915_WRITE(DC_STATE_EN, val);
427 POSTING_READ(DC_STATE_EN);
428}
429
430void bxt_disable_dc9(struct drm_i915_private *dev_priv)
431{
432 uint32_t val;
433
434 assert_can_disable_dc9(dev_priv);
435
436 DRM_DEBUG_KMS("Disabling DC9\n");
437
438 val = I915_READ(DC_STATE_EN);
439 val &= ~DC_STATE_EN_DC9;
440 I915_WRITE(DC_STATE_EN, val);
441 POSTING_READ(DC_STATE_EN);
442}
443
A.Sunil Kamath6b457d32015-04-16 14:22:09 +0530444static void gen9_set_dc_state_debugmask_memory_up(
445 struct drm_i915_private *dev_priv)
446{
447 uint32_t val;
448
449 /* The below bit doesn't need to be cleared ever afterwards */
450 val = I915_READ(DC_STATE_DEBUG);
451 if (!(val & DC_STATE_DEBUG_MASK_MEMORY_UP)) {
452 val |= DC_STATE_DEBUG_MASK_MEMORY_UP;
453 I915_WRITE(DC_STATE_DEBUG, val);
454 POSTING_READ(DC_STATE_DEBUG);
455 }
456}
457
Suketu Shah5aefb232015-04-16 14:22:10 +0530458static void assert_can_enable_dc5(struct drm_i915_private *dev_priv)
Suketu Shahdc174302015-04-17 19:46:16 +0530459{
A.Sunil Kamath6b457d32015-04-16 14:22:09 +0530460 struct drm_device *dev = dev_priv->dev;
Suketu Shah5aefb232015-04-16 14:22:10 +0530461 bool pg2_enabled = intel_display_power_well_is_enabled(dev_priv,
462 SKL_DISP_PW_2);
463
464 WARN(!IS_SKYLAKE(dev), "Platform doesn't support DC5.\n");
465 WARN(!HAS_RUNTIME_PM(dev), "Runtime PM not enabled.\n");
466 WARN(pg2_enabled, "PG2 not disabled to enable DC5.\n");
467
468 WARN((I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC5),
469 "DC5 already programmed to be enabled.\n");
470 WARN(dev_priv->pm.suspended,
471 "DC5 cannot be enabled, if platform is runtime-suspended.\n");
472
473 assert_csr_loaded(dev_priv);
474}
475
476static void assert_can_disable_dc5(struct drm_i915_private *dev_priv)
477{
478 bool pg2_enabled = intel_display_power_well_is_enabled(dev_priv,
479 SKL_DISP_PW_2);
Suketu Shah93c7cb62015-04-16 14:22:13 +0530480 /*
481 * During initialization, the firmware may not be loaded yet.
482 * We still want to make sure that the DC enabling flag is cleared.
483 */
484 if (dev_priv->power_domains.initializing)
485 return;
Suketu Shah5aefb232015-04-16 14:22:10 +0530486
487 WARN(!pg2_enabled, "PG2 not enabled to disable DC5.\n");
488 WARN(dev_priv->pm.suspended,
489 "Disabling of DC5 while platform is runtime-suspended should never happen.\n");
490}
491
492static void gen9_enable_dc5(struct drm_i915_private *dev_priv)
493{
A.Sunil Kamath6b457d32015-04-16 14:22:09 +0530494 uint32_t val;
495
Suketu Shah5aefb232015-04-16 14:22:10 +0530496 assert_can_enable_dc5(dev_priv);
A.Sunil Kamath6b457d32015-04-16 14:22:09 +0530497
498 DRM_DEBUG_KMS("Enabling DC5\n");
499
500 gen9_set_dc_state_debugmask_memory_up(dev_priv);
501
502 val = I915_READ(DC_STATE_EN);
503 val &= ~DC_STATE_EN_UPTO_DC5_DC6_MASK;
504 val |= DC_STATE_EN_UPTO_DC5;
505 I915_WRITE(DC_STATE_EN, val);
506 POSTING_READ(DC_STATE_EN);
Suketu Shahdc174302015-04-17 19:46:16 +0530507}
508
509static void gen9_disable_dc5(struct drm_i915_private *dev_priv)
510{
A.Sunil Kamath6b457d32015-04-16 14:22:09 +0530511 uint32_t val;
512
Suketu Shah5aefb232015-04-16 14:22:10 +0530513 assert_can_disable_dc5(dev_priv);
A.Sunil Kamath6b457d32015-04-16 14:22:09 +0530514
515 DRM_DEBUG_KMS("Disabling DC5\n");
516
517 val = I915_READ(DC_STATE_EN);
518 val &= ~DC_STATE_EN_UPTO_DC5;
519 I915_WRITE(DC_STATE_EN, val);
520 POSTING_READ(DC_STATE_EN);
Suketu Shahdc174302015-04-17 19:46:16 +0530521}
522
Suketu Shah93c7cb62015-04-16 14:22:13 +0530523static void assert_can_enable_dc6(struct drm_i915_private *dev_priv)
Suketu Shahf75a1982015-04-16 14:22:11 +0530524{
A.Sunil Kamath74b4f372015-04-16 14:22:12 +0530525 struct drm_device *dev = dev_priv->dev;
Suketu Shah93c7cb62015-04-16 14:22:13 +0530526
527 WARN(!IS_SKYLAKE(dev), "Platform doesn't support DC6.\n");
528 WARN(!HAS_RUNTIME_PM(dev), "Runtime PM not enabled.\n");
529 WARN(I915_READ(UTIL_PIN_CTL) & UTIL_PIN_ENABLE,
530 "Backlight is not disabled.\n");
531 WARN((I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC6),
532 "DC6 already programmed to be enabled.\n");
533
534 assert_csr_loaded(dev_priv);
535}
536
537static void assert_can_disable_dc6(struct drm_i915_private *dev_priv)
538{
539 /*
540 * During initialization, the firmware may not be loaded yet.
541 * We still want to make sure that the DC enabling flag is cleared.
542 */
543 if (dev_priv->power_domains.initializing)
544 return;
545
546 assert_csr_loaded(dev_priv);
547 WARN(!(I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC6),
548 "DC6 already programmed to be disabled.\n");
549}
550
551static void skl_enable_dc6(struct drm_i915_private *dev_priv)
552{
A.Sunil Kamath74b4f372015-04-16 14:22:12 +0530553 uint32_t val;
554
Suketu Shah93c7cb62015-04-16 14:22:13 +0530555 assert_can_enable_dc6(dev_priv);
A.Sunil Kamath74b4f372015-04-16 14:22:12 +0530556
557 DRM_DEBUG_KMS("Enabling DC6\n");
558
559 gen9_set_dc_state_debugmask_memory_up(dev_priv);
560
561 val = I915_READ(DC_STATE_EN);
562 val &= ~DC_STATE_EN_UPTO_DC5_DC6_MASK;
563 val |= DC_STATE_EN_UPTO_DC6;
564 I915_WRITE(DC_STATE_EN, val);
565 POSTING_READ(DC_STATE_EN);
Suketu Shahf75a1982015-04-16 14:22:11 +0530566}
567
568static void skl_disable_dc6(struct drm_i915_private *dev_priv)
569{
A.Sunil Kamath74b4f372015-04-16 14:22:12 +0530570 uint32_t val;
571
Suketu Shah93c7cb62015-04-16 14:22:13 +0530572 assert_can_disable_dc6(dev_priv);
A.Sunil Kamath74b4f372015-04-16 14:22:12 +0530573
574 DRM_DEBUG_KMS("Disabling DC6\n");
575
576 val = I915_READ(DC_STATE_EN);
577 val &= ~DC_STATE_EN_UPTO_DC6;
578 I915_WRITE(DC_STATE_EN, val);
579 POSTING_READ(DC_STATE_EN);
Suketu Shahf75a1982015-04-16 14:22:11 +0530580}
581
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000582static void skl_set_power_well(struct drm_i915_private *dev_priv,
583 struct i915_power_well *power_well, bool enable)
584{
Suketu Shahdc174302015-04-17 19:46:16 +0530585 struct drm_device *dev = dev_priv->dev;
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000586 uint32_t tmp, fuse_status;
587 uint32_t req_mask, state_mask;
Damien Lespiau2a518352015-03-06 18:50:49 +0000588 bool is_enabled, enable_requested, check_fuse_status = false;
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000589
590 tmp = I915_READ(HSW_PWR_WELL_DRIVER);
591 fuse_status = I915_READ(SKL_FUSE_STATUS);
592
593 switch (power_well->data) {
594 case SKL_DISP_PW_1:
595 if (wait_for((I915_READ(SKL_FUSE_STATUS) &
596 SKL_FUSE_PG0_DIST_STATUS), 1)) {
597 DRM_ERROR("PG0 not enabled\n");
598 return;
599 }
600 break;
601 case SKL_DISP_PW_2:
602 if (!(fuse_status & SKL_FUSE_PG1_DIST_STATUS)) {
603 DRM_ERROR("PG1 in disabled state\n");
604 return;
605 }
606 break;
607 case SKL_DISP_PW_DDI_A_E:
608 case SKL_DISP_PW_DDI_B:
609 case SKL_DISP_PW_DDI_C:
610 case SKL_DISP_PW_DDI_D:
611 case SKL_DISP_PW_MISC_IO:
612 break;
613 default:
614 WARN(1, "Unknown power well %lu\n", power_well->data);
615 return;
616 }
617
618 req_mask = SKL_POWER_WELL_REQ(power_well->data);
Damien Lespiau2a518352015-03-06 18:50:49 +0000619 enable_requested = tmp & req_mask;
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000620 state_mask = SKL_POWER_WELL_STATE(power_well->data);
Damien Lespiau2a518352015-03-06 18:50:49 +0000621 is_enabled = tmp & state_mask;
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000622
623 if (enable) {
Damien Lespiau2a518352015-03-06 18:50:49 +0000624 if (!enable_requested) {
Suketu Shahdc174302015-04-17 19:46:16 +0530625 WARN((tmp & state_mask) &&
626 !I915_READ(HSW_PWR_WELL_BIOS),
627 "Invalid for power well status to be enabled, unless done by the BIOS, \
628 when request is to disable!\n");
Suketu Shahf75a1982015-04-16 14:22:11 +0530629 if ((GEN9_ENABLE_DC5(dev) || SKL_ENABLE_DC6(dev)) &&
630 power_well->data == SKL_DISP_PW_2) {
631 if (SKL_ENABLE_DC6(dev)) {
632 skl_disable_dc6(dev_priv);
633 /*
634 * DDI buffer programming unnecessary during driver-load/resume
635 * as it's already done during modeset initialization then.
636 * It's also invalid here as encoder list is still uninitialized.
637 */
638 if (!dev_priv->power_domains.initializing)
639 intel_prepare_ddi(dev);
640 } else {
641 gen9_disable_dc5(dev_priv);
642 }
643 }
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000644 I915_WRITE(HSW_PWR_WELL_DRIVER, tmp | req_mask);
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000645 }
646
Damien Lespiau2a518352015-03-06 18:50:49 +0000647 if (!is_enabled) {
Damien Lespiau510e6fd2015-03-06 18:50:50 +0000648 DRM_DEBUG_KMS("Enabling %s\n", power_well->name);
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000649 if (wait_for((I915_READ(HSW_PWR_WELL_DRIVER) &
650 state_mask), 1))
651 DRM_ERROR("%s enable timeout\n",
652 power_well->name);
653 check_fuse_status = true;
654 }
655 } else {
Damien Lespiau2a518352015-03-06 18:50:49 +0000656 if (enable_requested) {
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000657 I915_WRITE(HSW_PWR_WELL_DRIVER, tmp & ~req_mask);
658 POSTING_READ(HSW_PWR_WELL_DRIVER);
659 DRM_DEBUG_KMS("Disabling %s\n", power_well->name);
Suketu Shahdc174302015-04-17 19:46:16 +0530660
Suketu Shahf75a1982015-04-16 14:22:11 +0530661 if ((GEN9_ENABLE_DC5(dev) || SKL_ENABLE_DC6(dev)) &&
Suketu Shahdc174302015-04-17 19:46:16 +0530662 power_well->data == SKL_DISP_PW_2) {
663 enum csr_state state;
Suketu Shahf75a1982015-04-16 14:22:11 +0530664 /* TODO: wait for a completion event or
665 * similar here instead of busy
666 * waiting using wait_for function.
667 */
Suketu Shahdc174302015-04-17 19:46:16 +0530668 wait_for((state = intel_csr_load_status_get(dev_priv)) !=
669 FW_UNINITIALIZED, 1000);
670 if (state != FW_LOADED)
671 DRM_ERROR("CSR firmware not ready (%d)\n",
672 state);
673 else
Suketu Shahf75a1982015-04-16 14:22:11 +0530674 if (SKL_ENABLE_DC6(dev))
675 skl_enable_dc6(dev_priv);
676 else
677 gen9_enable_dc5(dev_priv);
Suketu Shahdc174302015-04-17 19:46:16 +0530678 }
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000679 }
680 }
681
682 if (check_fuse_status) {
683 if (power_well->data == SKL_DISP_PW_1) {
684 if (wait_for((I915_READ(SKL_FUSE_STATUS) &
685 SKL_FUSE_PG1_DIST_STATUS), 1))
686 DRM_ERROR("PG1 distributing status timeout\n");
687 } else if (power_well->data == SKL_DISP_PW_2) {
688 if (wait_for((I915_READ(SKL_FUSE_STATUS) &
689 SKL_FUSE_PG2_DIST_STATUS), 1))
690 DRM_ERROR("PG2 distributing status timeout\n");
691 }
692 }
Damien Lespiaud14c0342015-03-06 18:50:51 +0000693
694 if (enable && !is_enabled)
695 skl_power_well_post_enable(dev_priv, power_well);
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000696}
697
Daniel Vetter9c065a72014-09-30 10:56:38 +0200698static void hsw_power_well_sync_hw(struct drm_i915_private *dev_priv,
699 struct i915_power_well *power_well)
700{
701 hsw_set_power_well(dev_priv, power_well, power_well->count > 0);
702
703 /*
704 * We're taking over the BIOS, so clear any requests made by it since
705 * the driver is in charge now.
706 */
707 if (I915_READ(HSW_PWR_WELL_BIOS) & HSW_PWR_WELL_ENABLE_REQUEST)
708 I915_WRITE(HSW_PWR_WELL_BIOS, 0);
709}
710
711static void hsw_power_well_enable(struct drm_i915_private *dev_priv,
712 struct i915_power_well *power_well)
713{
714 hsw_set_power_well(dev_priv, power_well, true);
715}
716
717static void hsw_power_well_disable(struct drm_i915_private *dev_priv,
718 struct i915_power_well *power_well)
719{
720 hsw_set_power_well(dev_priv, power_well, false);
721}
722
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000723static bool skl_power_well_enabled(struct drm_i915_private *dev_priv,
724 struct i915_power_well *power_well)
725{
726 uint32_t mask = SKL_POWER_WELL_REQ(power_well->data) |
727 SKL_POWER_WELL_STATE(power_well->data);
728
729 return (I915_READ(HSW_PWR_WELL_DRIVER) & mask) == mask;
730}
731
732static void skl_power_well_sync_hw(struct drm_i915_private *dev_priv,
733 struct i915_power_well *power_well)
734{
735 skl_set_power_well(dev_priv, power_well, power_well->count > 0);
736
737 /* Clear any request made by BIOS as driver is taking over */
738 I915_WRITE(HSW_PWR_WELL_BIOS, 0);
739}
740
741static void skl_power_well_enable(struct drm_i915_private *dev_priv,
742 struct i915_power_well *power_well)
743{
744 skl_set_power_well(dev_priv, power_well, true);
745}
746
747static void skl_power_well_disable(struct drm_i915_private *dev_priv,
748 struct i915_power_well *power_well)
749{
750 skl_set_power_well(dev_priv, power_well, false);
751}
752
Daniel Vetter9c065a72014-09-30 10:56:38 +0200753static void i9xx_always_on_power_well_noop(struct drm_i915_private *dev_priv,
754 struct i915_power_well *power_well)
755{
756}
757
758static bool i9xx_always_on_power_well_enabled(struct drm_i915_private *dev_priv,
759 struct i915_power_well *power_well)
760{
761 return true;
762}
763
764static void vlv_set_power_well(struct drm_i915_private *dev_priv,
765 struct i915_power_well *power_well, bool enable)
766{
767 enum punit_power_well power_well_id = power_well->data;
768 u32 mask;
769 u32 state;
770 u32 ctrl;
771
772 mask = PUNIT_PWRGT_MASK(power_well_id);
773 state = enable ? PUNIT_PWRGT_PWR_ON(power_well_id) :
774 PUNIT_PWRGT_PWR_GATE(power_well_id);
775
776 mutex_lock(&dev_priv->rps.hw_lock);
777
778#define COND \
779 ((vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_STATUS) & mask) == state)
780
781 if (COND)
782 goto out;
783
784 ctrl = vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_CTRL);
785 ctrl &= ~mask;
786 ctrl |= state;
787 vlv_punit_write(dev_priv, PUNIT_REG_PWRGT_CTRL, ctrl);
788
789 if (wait_for(COND, 100))
Masanari Iida7e35ab82015-05-10 01:00:23 +0900790 DRM_ERROR("timeout setting power well state %08x (%08x)\n",
Daniel Vetter9c065a72014-09-30 10:56:38 +0200791 state,
792 vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_CTRL));
793
794#undef COND
795
796out:
797 mutex_unlock(&dev_priv->rps.hw_lock);
798}
799
800static void vlv_power_well_sync_hw(struct drm_i915_private *dev_priv,
801 struct i915_power_well *power_well)
802{
803 vlv_set_power_well(dev_priv, power_well, power_well->count > 0);
804}
805
806static void vlv_power_well_enable(struct drm_i915_private *dev_priv,
807 struct i915_power_well *power_well)
808{
809 vlv_set_power_well(dev_priv, power_well, true);
810}
811
812static void vlv_power_well_disable(struct drm_i915_private *dev_priv,
813 struct i915_power_well *power_well)
814{
815 vlv_set_power_well(dev_priv, power_well, false);
816}
817
818static bool vlv_power_well_enabled(struct drm_i915_private *dev_priv,
819 struct i915_power_well *power_well)
820{
821 int power_well_id = power_well->data;
822 bool enabled = false;
823 u32 mask;
824 u32 state;
825 u32 ctrl;
826
827 mask = PUNIT_PWRGT_MASK(power_well_id);
828 ctrl = PUNIT_PWRGT_PWR_ON(power_well_id);
829
830 mutex_lock(&dev_priv->rps.hw_lock);
831
832 state = vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_STATUS) & mask;
833 /*
834 * We only ever set the power-on and power-gate states, anything
835 * else is unexpected.
836 */
837 WARN_ON(state != PUNIT_PWRGT_PWR_ON(power_well_id) &&
838 state != PUNIT_PWRGT_PWR_GATE(power_well_id));
839 if (state == ctrl)
840 enabled = true;
841
842 /*
843 * A transient state at this point would mean some unexpected party
844 * is poking at the power controls too.
845 */
846 ctrl = vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_CTRL) & mask;
847 WARN_ON(ctrl != state);
848
849 mutex_unlock(&dev_priv->rps.hw_lock);
850
851 return enabled;
852}
853
Ville Syrjälä2be7d542015-06-29 15:25:51 +0300854static void vlv_display_power_well_init(struct drm_i915_private *dev_priv)
Daniel Vetter9c065a72014-09-30 10:56:38 +0200855{
Ville Syrjälä5a8fbb72015-06-29 15:25:53 +0300856 enum pipe pipe;
857
858 /*
859 * Enable the CRI clock source so we can get at the
860 * display and the reference clock for VGA
861 * hotplug / manual detection. Supposedly DSI also
862 * needs the ref clock up and running.
863 *
864 * CHV DPLL B/C have some issues if VGA mode is enabled.
865 */
866 for_each_pipe(dev_priv->dev, pipe) {
867 u32 val = I915_READ(DPLL(pipe));
868
869 val |= DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
870 if (pipe != PIPE_A)
871 val |= DPLL_INTEGRATED_CRI_CLK_VLV;
872
873 I915_WRITE(DPLL(pipe), val);
874 }
Daniel Vetter9c065a72014-09-30 10:56:38 +0200875
876 spin_lock_irq(&dev_priv->irq_lock);
877 valleyview_enable_display_irqs(dev_priv);
878 spin_unlock_irq(&dev_priv->irq_lock);
879
880 /*
881 * During driver initialization/resume we can avoid restoring the
882 * part of the HW/SW state that will be inited anyway explicitly.
883 */
884 if (dev_priv->power_domains.initializing)
885 return;
886
Daniel Vetterb9632912014-09-30 10:56:44 +0200887 intel_hpd_init(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200888
889 i915_redisable_vga_power_on(dev_priv->dev);
890}
891
Ville Syrjälä2be7d542015-06-29 15:25:51 +0300892static void vlv_display_power_well_deinit(struct drm_i915_private *dev_priv)
893{
894 spin_lock_irq(&dev_priv->irq_lock);
895 valleyview_disable_display_irqs(dev_priv);
896 spin_unlock_irq(&dev_priv->irq_lock);
897
898 vlv_power_sequencer_reset(dev_priv);
899}
900
901static void vlv_display_power_well_enable(struct drm_i915_private *dev_priv,
902 struct i915_power_well *power_well)
903{
904 WARN_ON_ONCE(power_well->data != PUNIT_POWER_WELL_DISP2D);
905
906 vlv_set_power_well(dev_priv, power_well, true);
907
908 vlv_display_power_well_init(dev_priv);
909}
910
Daniel Vetter9c065a72014-09-30 10:56:38 +0200911static void vlv_display_power_well_disable(struct drm_i915_private *dev_priv,
912 struct i915_power_well *power_well)
913{
914 WARN_ON_ONCE(power_well->data != PUNIT_POWER_WELL_DISP2D);
915
Ville Syrjälä2be7d542015-06-29 15:25:51 +0300916 vlv_display_power_well_deinit(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200917
918 vlv_set_power_well(dev_priv, power_well, false);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200919}
920
921static void vlv_dpio_cmn_power_well_enable(struct drm_i915_private *dev_priv,
922 struct i915_power_well *power_well)
923{
924 WARN_ON_ONCE(power_well->data != PUNIT_POWER_WELL_DPIO_CMN_BC);
925
Ville Syrjälä5a8fbb72015-06-29 15:25:53 +0300926 /* since ref/cri clock was enabled */
Daniel Vetter9c065a72014-09-30 10:56:38 +0200927 udelay(1); /* >10ns for cmnreset, >0ns for sidereset */
928
929 vlv_set_power_well(dev_priv, power_well, true);
930
931 /*
932 * From VLV2A0_DP_eDP_DPIO_driver_vbios_notes_10.docx -
933 * 6. De-assert cmn_reset/side_reset. Same as VLV X0.
934 * a. GUnit 0x2110 bit[0] set to 1 (def 0)
935 * b. The other bits such as sfr settings / modesel may all
936 * be set to 0.
937 *
938 * This should only be done on init and resume from S3 with
939 * both PLLs disabled, or we risk losing DPIO and PLL
940 * synchronization.
941 */
942 I915_WRITE(DPIO_CTL, I915_READ(DPIO_CTL) | DPIO_CMNRST);
943}
944
945static void vlv_dpio_cmn_power_well_disable(struct drm_i915_private *dev_priv,
946 struct i915_power_well *power_well)
947{
948 enum pipe pipe;
949
950 WARN_ON_ONCE(power_well->data != PUNIT_POWER_WELL_DPIO_CMN_BC);
951
952 for_each_pipe(dev_priv, pipe)
953 assert_pll_disabled(dev_priv, pipe);
954
955 /* Assert common reset */
956 I915_WRITE(DPIO_CTL, I915_READ(DPIO_CTL) & ~DPIO_CMNRST);
957
958 vlv_set_power_well(dev_priv, power_well, false);
959}
960
961static void chv_dpio_cmn_power_well_enable(struct drm_i915_private *dev_priv,
962 struct i915_power_well *power_well)
963{
964 enum dpio_phy phy;
Ville Syrjäläe0fce782015-07-08 23:45:54 +0300965 enum pipe pipe;
966 uint32_t tmp;
Daniel Vetter9c065a72014-09-30 10:56:38 +0200967
968 WARN_ON_ONCE(power_well->data != PUNIT_POWER_WELL_DPIO_CMN_BC &&
969 power_well->data != PUNIT_POWER_WELL_DPIO_CMN_D);
970
Ville Syrjäläe0fce782015-07-08 23:45:54 +0300971 if (power_well->data == PUNIT_POWER_WELL_DPIO_CMN_BC) {
972 pipe = PIPE_A;
Daniel Vetter9c065a72014-09-30 10:56:38 +0200973 phy = DPIO_PHY0;
Ville Syrjäläe0fce782015-07-08 23:45:54 +0300974 } else {
975 pipe = PIPE_C;
Daniel Vetter9c065a72014-09-30 10:56:38 +0200976 phy = DPIO_PHY1;
Ville Syrjäläe0fce782015-07-08 23:45:54 +0300977 }
Ville Syrjälä5a8fbb72015-06-29 15:25:53 +0300978
979 /* since ref/cri clock was enabled */
Daniel Vetter9c065a72014-09-30 10:56:38 +0200980 udelay(1); /* >10ns for cmnreset, >0ns for sidereset */
981 vlv_set_power_well(dev_priv, power_well, true);
982
983 /* Poll for phypwrgood signal */
984 if (wait_for(I915_READ(DISPLAY_PHY_STATUS) & PHY_POWERGOOD(phy), 1))
985 DRM_ERROR("Display PHY %d is not power up\n", phy);
986
Ville Syrjäläe0fce782015-07-08 23:45:54 +0300987 mutex_lock(&dev_priv->sb_lock);
988
989 /* Enable dynamic power down */
990 tmp = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW28);
Ville Syrjäläee279212015-07-08 23:45:57 +0300991 tmp |= DPIO_DYNPWRDOWNEN_CH0 | DPIO_CL1POWERDOWNEN |
992 DPIO_SUS_CLK_CONFIG_GATE_CLKREQ;
Ville Syrjäläe0fce782015-07-08 23:45:54 +0300993 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW28, tmp);
994
995 if (power_well->data == PUNIT_POWER_WELL_DPIO_CMN_BC) {
996 tmp = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW6_CH1);
997 tmp |= DPIO_DYNPWRDOWNEN_CH1;
998 vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW6_CH1, tmp);
Ville Syrjälä3e288782015-07-08 23:45:58 +0300999 } else {
1000 /*
1001 * Force the non-existing CL2 off. BXT does this
1002 * too, so maybe it saves some power even though
1003 * CL2 doesn't exist?
1004 */
1005 tmp = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW30);
1006 tmp |= DPIO_CL2_LDOFUSE_PWRENB;
1007 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW30, tmp);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001008 }
1009
1010 mutex_unlock(&dev_priv->sb_lock);
1011
Ville Syrjälä70722462015-04-10 18:21:28 +03001012 dev_priv->chv_phy_control |= PHY_COM_LANE_RESET_DEASSERT(phy);
1013 I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001014
1015 DRM_DEBUG_KMS("Enabled DPIO PHY%d (PHY_CONTROL=0x%08x)\n",
1016 phy, dev_priv->chv_phy_control);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001017}
1018
1019static void chv_dpio_cmn_power_well_disable(struct drm_i915_private *dev_priv,
1020 struct i915_power_well *power_well)
1021{
1022 enum dpio_phy phy;
1023
1024 WARN_ON_ONCE(power_well->data != PUNIT_POWER_WELL_DPIO_CMN_BC &&
1025 power_well->data != PUNIT_POWER_WELL_DPIO_CMN_D);
1026
1027 if (power_well->data == PUNIT_POWER_WELL_DPIO_CMN_BC) {
1028 phy = DPIO_PHY0;
1029 assert_pll_disabled(dev_priv, PIPE_A);
1030 assert_pll_disabled(dev_priv, PIPE_B);
1031 } else {
1032 phy = DPIO_PHY1;
1033 assert_pll_disabled(dev_priv, PIPE_C);
1034 }
1035
Ville Syrjälä70722462015-04-10 18:21:28 +03001036 dev_priv->chv_phy_control &= ~PHY_COM_LANE_RESET_DEASSERT(phy);
1037 I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001038
1039 vlv_set_power_well(dev_priv, power_well, false);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001040
1041 DRM_DEBUG_KMS("Disabled DPIO PHY%d (PHY_CONTROL=0x%08x)\n",
1042 phy, dev_priv->chv_phy_control);
1043}
1044
Ville Syrjälä6669e392015-07-08 23:46:00 +03001045static void assert_chv_phy_powergate(struct drm_i915_private *dev_priv, enum dpio_phy phy,
1046 enum dpio_channel ch, bool override, unsigned int mask)
1047{
1048 enum pipe pipe = phy == DPIO_PHY0 ? PIPE_A : PIPE_C;
1049 u32 reg, val, expected, actual;
1050
1051 if (ch == DPIO_CH0)
1052 reg = _CHV_CMN_DW0_CH0;
1053 else
1054 reg = _CHV_CMN_DW6_CH1;
1055
1056 mutex_lock(&dev_priv->sb_lock);
1057 val = vlv_dpio_read(dev_priv, pipe, reg);
1058 mutex_unlock(&dev_priv->sb_lock);
1059
1060 /*
1061 * This assumes !override is only used when the port is disabled.
1062 * All lanes should power down even without the override when
1063 * the port is disabled.
1064 */
1065 if (!override || mask == 0xf) {
1066 expected = DPIO_ALLDL_POWERDOWN | DPIO_ANYDL_POWERDOWN;
1067 /*
1068 * If CH1 common lane is not active anymore
1069 * (eg. for pipe B DPLL) the entire channel will
1070 * shut down, which causes the common lane registers
1071 * to read as 0. That means we can't actually check
1072 * the lane power down status bits, but as the entire
1073 * register reads as 0 it's a good indication that the
1074 * channel is indeed entirely powered down.
1075 */
1076 if (ch == DPIO_CH1 && val == 0)
1077 expected = 0;
1078 } else if (mask != 0x0) {
1079 expected = DPIO_ANYDL_POWERDOWN;
1080 } else {
1081 expected = 0;
1082 }
1083
1084 if (ch == DPIO_CH0)
1085 actual = val >> DPIO_ANYDL_POWERDOWN_SHIFT_CH0;
1086 else
1087 actual = val >> DPIO_ANYDL_POWERDOWN_SHIFT_CH1;
1088 actual &= DPIO_ALLDL_POWERDOWN | DPIO_ANYDL_POWERDOWN;
1089
1090 WARN(actual != expected,
1091 "Unexpected DPIO lane power down: all %d, any %d. Expected: all %d, any %d. (0x%x = 0x%08x)\n",
1092 !!(actual & DPIO_ALLDL_POWERDOWN), !!(actual & DPIO_ANYDL_POWERDOWN),
1093 !!(expected & DPIO_ALLDL_POWERDOWN), !!(expected & DPIO_ANYDL_POWERDOWN),
1094 reg, val);
1095}
1096
Ville Syrjäläb0b33842015-07-08 23:45:55 +03001097bool chv_phy_powergate_ch(struct drm_i915_private *dev_priv, enum dpio_phy phy,
1098 enum dpio_channel ch, bool override)
1099{
1100 struct i915_power_domains *power_domains = &dev_priv->power_domains;
1101 bool was_override;
1102
1103 mutex_lock(&power_domains->lock);
1104
1105 was_override = dev_priv->chv_phy_control & PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
1106
1107 if (override == was_override)
1108 goto out;
1109
1110 if (override)
1111 dev_priv->chv_phy_control |= PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
1112 else
1113 dev_priv->chv_phy_control &= ~PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
1114
1115 I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
1116
1117 DRM_DEBUG_KMS("Power gating DPIO PHY%d CH%d (DPIO_PHY_CONTROL=0x%08x)\n",
1118 phy, ch, dev_priv->chv_phy_control);
1119
1120out:
1121 mutex_unlock(&power_domains->lock);
1122
1123 return was_override;
1124}
1125
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001126void chv_phy_powergate_lanes(struct intel_encoder *encoder,
1127 bool override, unsigned int mask)
1128{
1129 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
1130 struct i915_power_domains *power_domains = &dev_priv->power_domains;
1131 enum dpio_phy phy = vlv_dport_to_phy(enc_to_dig_port(&encoder->base));
1132 enum dpio_channel ch = vlv_dport_to_channel(enc_to_dig_port(&encoder->base));
1133
1134 mutex_lock(&power_domains->lock);
1135
1136 dev_priv->chv_phy_control &= ~PHY_CH_POWER_DOWN_OVRD(0xf, phy, ch);
1137 dev_priv->chv_phy_control |= PHY_CH_POWER_DOWN_OVRD(mask, phy, ch);
1138
1139 if (override)
1140 dev_priv->chv_phy_control |= PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
1141 else
1142 dev_priv->chv_phy_control &= ~PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
1143
1144 I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
1145
1146 DRM_DEBUG_KMS("Power gating DPIO PHY%d CH%d lanes 0x%x (PHY_CONTROL=0x%08x)\n",
1147 phy, ch, mask, dev_priv->chv_phy_control);
1148
Ville Syrjälä6669e392015-07-08 23:46:00 +03001149 assert_chv_phy_powergate(dev_priv, phy, ch, override, mask);
1150
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001151 mutex_unlock(&power_domains->lock);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001152}
1153
1154static bool chv_pipe_power_well_enabled(struct drm_i915_private *dev_priv,
1155 struct i915_power_well *power_well)
1156{
1157 enum pipe pipe = power_well->data;
1158 bool enabled;
1159 u32 state, ctrl;
1160
1161 mutex_lock(&dev_priv->rps.hw_lock);
1162
1163 state = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & DP_SSS_MASK(pipe);
1164 /*
1165 * We only ever set the power-on and power-gate states, anything
1166 * else is unexpected.
1167 */
1168 WARN_ON(state != DP_SSS_PWR_ON(pipe) && state != DP_SSS_PWR_GATE(pipe));
1169 enabled = state == DP_SSS_PWR_ON(pipe);
1170
1171 /*
1172 * A transient state at this point would mean some unexpected party
1173 * is poking at the power controls too.
1174 */
1175 ctrl = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & DP_SSC_MASK(pipe);
1176 WARN_ON(ctrl << 16 != state);
1177
1178 mutex_unlock(&dev_priv->rps.hw_lock);
1179
1180 return enabled;
1181}
1182
1183static void chv_set_pipe_power_well(struct drm_i915_private *dev_priv,
1184 struct i915_power_well *power_well,
1185 bool enable)
1186{
1187 enum pipe pipe = power_well->data;
1188 u32 state;
1189 u32 ctrl;
1190
1191 state = enable ? DP_SSS_PWR_ON(pipe) : DP_SSS_PWR_GATE(pipe);
1192
1193 mutex_lock(&dev_priv->rps.hw_lock);
1194
1195#define COND \
1196 ((vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & DP_SSS_MASK(pipe)) == state)
1197
1198 if (COND)
1199 goto out;
1200
1201 ctrl = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ);
1202 ctrl &= ~DP_SSC_MASK(pipe);
1203 ctrl |= enable ? DP_SSC_PWR_ON(pipe) : DP_SSC_PWR_GATE(pipe);
1204 vlv_punit_write(dev_priv, PUNIT_REG_DSPFREQ, ctrl);
1205
1206 if (wait_for(COND, 100))
Masanari Iida7e35ab82015-05-10 01:00:23 +09001207 DRM_ERROR("timeout setting power well state %08x (%08x)\n",
Daniel Vetter9c065a72014-09-30 10:56:38 +02001208 state,
1209 vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ));
1210
1211#undef COND
1212
1213out:
1214 mutex_unlock(&dev_priv->rps.hw_lock);
1215}
1216
1217static void chv_pipe_power_well_sync_hw(struct drm_i915_private *dev_priv,
1218 struct i915_power_well *power_well)
1219{
Ville Syrjälä8fcd5cd2015-06-29 15:25:50 +03001220 WARN_ON_ONCE(power_well->data != PIPE_A);
1221
Daniel Vetter9c065a72014-09-30 10:56:38 +02001222 chv_set_pipe_power_well(dev_priv, power_well, power_well->count > 0);
1223}
1224
1225static void chv_pipe_power_well_enable(struct drm_i915_private *dev_priv,
1226 struct i915_power_well *power_well)
1227{
Ville Syrjälä8fcd5cd2015-06-29 15:25:50 +03001228 WARN_ON_ONCE(power_well->data != PIPE_A);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001229
1230 chv_set_pipe_power_well(dev_priv, power_well, true);
Ville Syrjäläafd62752014-10-30 19:43:03 +02001231
Ville Syrjälä2be7d542015-06-29 15:25:51 +03001232 vlv_display_power_well_init(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001233}
1234
1235static void chv_pipe_power_well_disable(struct drm_i915_private *dev_priv,
1236 struct i915_power_well *power_well)
1237{
Ville Syrjälä8fcd5cd2015-06-29 15:25:50 +03001238 WARN_ON_ONCE(power_well->data != PIPE_A);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001239
Ville Syrjälä2be7d542015-06-29 15:25:51 +03001240 vlv_display_power_well_deinit(dev_priv);
Ville Syrjäläafd62752014-10-30 19:43:03 +02001241
Daniel Vetter9c065a72014-09-30 10:56:38 +02001242 chv_set_pipe_power_well(dev_priv, power_well, false);
1243}
1244
Daniel Vettere4e76842014-09-30 10:56:42 +02001245/**
1246 * intel_display_power_get - grab a power domain reference
1247 * @dev_priv: i915 device instance
1248 * @domain: power domain to reference
1249 *
1250 * This function grabs a power domain reference for @domain and ensures that the
1251 * power domain and all its parents are powered up. Therefore users should only
1252 * grab a reference to the innermost power domain they need.
1253 *
1254 * Any power domain reference obtained by this function must have a symmetric
1255 * call to intel_display_power_put() to release the reference again.
1256 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02001257void intel_display_power_get(struct drm_i915_private *dev_priv,
1258 enum intel_display_power_domain domain)
1259{
1260 struct i915_power_domains *power_domains;
1261 struct i915_power_well *power_well;
1262 int i;
1263
1264 intel_runtime_pm_get(dev_priv);
1265
1266 power_domains = &dev_priv->power_domains;
1267
1268 mutex_lock(&power_domains->lock);
1269
1270 for_each_power_well(i, power_well, BIT(domain), power_domains) {
Damien Lespiaue8ca9322015-07-30 18:20:26 -03001271 if (!power_well->count++)
1272 intel_power_well_enable(dev_priv, power_well);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001273 }
1274
1275 power_domains->domain_use_count[domain]++;
1276
1277 mutex_unlock(&power_domains->lock);
1278}
1279
Daniel Vettere4e76842014-09-30 10:56:42 +02001280/**
1281 * intel_display_power_put - release a power domain reference
1282 * @dev_priv: i915 device instance
1283 * @domain: power domain to reference
1284 *
1285 * This function drops the power domain reference obtained by
1286 * intel_display_power_get() and might power down the corresponding hardware
1287 * block right away if this is the last reference.
1288 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02001289void intel_display_power_put(struct drm_i915_private *dev_priv,
1290 enum intel_display_power_domain domain)
1291{
1292 struct i915_power_domains *power_domains;
1293 struct i915_power_well *power_well;
1294 int i;
1295
1296 power_domains = &dev_priv->power_domains;
1297
1298 mutex_lock(&power_domains->lock);
1299
1300 WARN_ON(!power_domains->domain_use_count[domain]);
1301 power_domains->domain_use_count[domain]--;
1302
1303 for_each_power_well_rev(i, power_well, BIT(domain), power_domains) {
1304 WARN_ON(!power_well->count);
1305
Damien Lespiaudcddab32015-07-30 18:20:27 -03001306 if (!--power_well->count && i915.disable_power_well)
1307 intel_power_well_disable(dev_priv, power_well);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001308 }
1309
1310 mutex_unlock(&power_domains->lock);
1311
1312 intel_runtime_pm_put(dev_priv);
1313}
1314
1315#define POWER_DOMAIN_MASK (BIT(POWER_DOMAIN_NUM) - 1)
1316
1317#define HSW_ALWAYS_ON_POWER_DOMAINS ( \
1318 BIT(POWER_DOMAIN_PIPE_A) | \
1319 BIT(POWER_DOMAIN_TRANSCODER_EDP) | \
1320 BIT(POWER_DOMAIN_PORT_DDI_A_2_LANES) | \
1321 BIT(POWER_DOMAIN_PORT_DDI_A_4_LANES) | \
1322 BIT(POWER_DOMAIN_PORT_DDI_B_2_LANES) | \
1323 BIT(POWER_DOMAIN_PORT_DDI_B_4_LANES) | \
1324 BIT(POWER_DOMAIN_PORT_DDI_C_2_LANES) | \
1325 BIT(POWER_DOMAIN_PORT_DDI_C_4_LANES) | \
1326 BIT(POWER_DOMAIN_PORT_DDI_D_2_LANES) | \
1327 BIT(POWER_DOMAIN_PORT_DDI_D_4_LANES) | \
1328 BIT(POWER_DOMAIN_PORT_CRT) | \
1329 BIT(POWER_DOMAIN_PLLS) | \
Satheeshakrishna M14071212015-01-16 15:57:51 +00001330 BIT(POWER_DOMAIN_AUX_A) | \
1331 BIT(POWER_DOMAIN_AUX_B) | \
1332 BIT(POWER_DOMAIN_AUX_C) | \
1333 BIT(POWER_DOMAIN_AUX_D) | \
Daniel Vetter9c065a72014-09-30 10:56:38 +02001334 BIT(POWER_DOMAIN_INIT))
1335#define HSW_DISPLAY_POWER_DOMAINS ( \
1336 (POWER_DOMAIN_MASK & ~HSW_ALWAYS_ON_POWER_DOMAINS) | \
1337 BIT(POWER_DOMAIN_INIT))
1338
1339#define BDW_ALWAYS_ON_POWER_DOMAINS ( \
1340 HSW_ALWAYS_ON_POWER_DOMAINS | \
1341 BIT(POWER_DOMAIN_PIPE_A_PANEL_FITTER))
1342#define BDW_DISPLAY_POWER_DOMAINS ( \
1343 (POWER_DOMAIN_MASK & ~BDW_ALWAYS_ON_POWER_DOMAINS) | \
1344 BIT(POWER_DOMAIN_INIT))
1345
1346#define VLV_ALWAYS_ON_POWER_DOMAINS BIT(POWER_DOMAIN_INIT)
1347#define VLV_DISPLAY_POWER_DOMAINS POWER_DOMAIN_MASK
1348
1349#define VLV_DPIO_CMN_BC_POWER_DOMAINS ( \
1350 BIT(POWER_DOMAIN_PORT_DDI_B_2_LANES) | \
1351 BIT(POWER_DOMAIN_PORT_DDI_B_4_LANES) | \
1352 BIT(POWER_DOMAIN_PORT_DDI_C_2_LANES) | \
1353 BIT(POWER_DOMAIN_PORT_DDI_C_4_LANES) | \
1354 BIT(POWER_DOMAIN_PORT_CRT) | \
Satheeshakrishna M14071212015-01-16 15:57:51 +00001355 BIT(POWER_DOMAIN_AUX_B) | \
1356 BIT(POWER_DOMAIN_AUX_C) | \
Daniel Vetter9c065a72014-09-30 10:56:38 +02001357 BIT(POWER_DOMAIN_INIT))
1358
1359#define VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS ( \
1360 BIT(POWER_DOMAIN_PORT_DDI_B_2_LANES) | \
1361 BIT(POWER_DOMAIN_PORT_DDI_B_4_LANES) | \
Satheeshakrishna M14071212015-01-16 15:57:51 +00001362 BIT(POWER_DOMAIN_AUX_B) | \
Daniel Vetter9c065a72014-09-30 10:56:38 +02001363 BIT(POWER_DOMAIN_INIT))
1364
1365#define VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS ( \
1366 BIT(POWER_DOMAIN_PORT_DDI_B_4_LANES) | \
Satheeshakrishna M14071212015-01-16 15:57:51 +00001367 BIT(POWER_DOMAIN_AUX_B) | \
Daniel Vetter9c065a72014-09-30 10:56:38 +02001368 BIT(POWER_DOMAIN_INIT))
1369
1370#define VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS ( \
1371 BIT(POWER_DOMAIN_PORT_DDI_C_2_LANES) | \
1372 BIT(POWER_DOMAIN_PORT_DDI_C_4_LANES) | \
Satheeshakrishna M14071212015-01-16 15:57:51 +00001373 BIT(POWER_DOMAIN_AUX_C) | \
Daniel Vetter9c065a72014-09-30 10:56:38 +02001374 BIT(POWER_DOMAIN_INIT))
1375
1376#define VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS ( \
1377 BIT(POWER_DOMAIN_PORT_DDI_C_4_LANES) | \
Satheeshakrishna M14071212015-01-16 15:57:51 +00001378 BIT(POWER_DOMAIN_AUX_C) | \
Daniel Vetter9c065a72014-09-30 10:56:38 +02001379 BIT(POWER_DOMAIN_INIT))
1380
Daniel Vetter9c065a72014-09-30 10:56:38 +02001381#define CHV_DPIO_CMN_BC_POWER_DOMAINS ( \
1382 BIT(POWER_DOMAIN_PORT_DDI_B_2_LANES) | \
1383 BIT(POWER_DOMAIN_PORT_DDI_B_4_LANES) | \
1384 BIT(POWER_DOMAIN_PORT_DDI_C_2_LANES) | \
1385 BIT(POWER_DOMAIN_PORT_DDI_C_4_LANES) | \
Satheeshakrishna M14071212015-01-16 15:57:51 +00001386 BIT(POWER_DOMAIN_AUX_B) | \
1387 BIT(POWER_DOMAIN_AUX_C) | \
Daniel Vetter9c065a72014-09-30 10:56:38 +02001388 BIT(POWER_DOMAIN_INIT))
1389
1390#define CHV_DPIO_CMN_D_POWER_DOMAINS ( \
1391 BIT(POWER_DOMAIN_PORT_DDI_D_2_LANES) | \
1392 BIT(POWER_DOMAIN_PORT_DDI_D_4_LANES) | \
Satheeshakrishna M14071212015-01-16 15:57:51 +00001393 BIT(POWER_DOMAIN_AUX_D) | \
Daniel Vetter9c065a72014-09-30 10:56:38 +02001394 BIT(POWER_DOMAIN_INIT))
1395
Daniel Vetter9c065a72014-09-30 10:56:38 +02001396static const struct i915_power_well_ops i9xx_always_on_power_well_ops = {
1397 .sync_hw = i9xx_always_on_power_well_noop,
1398 .enable = i9xx_always_on_power_well_noop,
1399 .disable = i9xx_always_on_power_well_noop,
1400 .is_enabled = i9xx_always_on_power_well_enabled,
1401};
1402
1403static const struct i915_power_well_ops chv_pipe_power_well_ops = {
1404 .sync_hw = chv_pipe_power_well_sync_hw,
1405 .enable = chv_pipe_power_well_enable,
1406 .disable = chv_pipe_power_well_disable,
1407 .is_enabled = chv_pipe_power_well_enabled,
1408};
1409
1410static const struct i915_power_well_ops chv_dpio_cmn_power_well_ops = {
1411 .sync_hw = vlv_power_well_sync_hw,
1412 .enable = chv_dpio_cmn_power_well_enable,
1413 .disable = chv_dpio_cmn_power_well_disable,
1414 .is_enabled = vlv_power_well_enabled,
1415};
1416
1417static struct i915_power_well i9xx_always_on_power_well[] = {
1418 {
1419 .name = "always-on",
1420 .always_on = 1,
1421 .domains = POWER_DOMAIN_MASK,
1422 .ops = &i9xx_always_on_power_well_ops,
1423 },
1424};
1425
1426static const struct i915_power_well_ops hsw_power_well_ops = {
1427 .sync_hw = hsw_power_well_sync_hw,
1428 .enable = hsw_power_well_enable,
1429 .disable = hsw_power_well_disable,
1430 .is_enabled = hsw_power_well_enabled,
1431};
1432
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00001433static const struct i915_power_well_ops skl_power_well_ops = {
1434 .sync_hw = skl_power_well_sync_hw,
1435 .enable = skl_power_well_enable,
1436 .disable = skl_power_well_disable,
1437 .is_enabled = skl_power_well_enabled,
1438};
1439
Daniel Vetter9c065a72014-09-30 10:56:38 +02001440static struct i915_power_well hsw_power_wells[] = {
1441 {
1442 .name = "always-on",
1443 .always_on = 1,
1444 .domains = HSW_ALWAYS_ON_POWER_DOMAINS,
1445 .ops = &i9xx_always_on_power_well_ops,
1446 },
1447 {
1448 .name = "display",
1449 .domains = HSW_DISPLAY_POWER_DOMAINS,
1450 .ops = &hsw_power_well_ops,
1451 },
1452};
1453
1454static struct i915_power_well bdw_power_wells[] = {
1455 {
1456 .name = "always-on",
1457 .always_on = 1,
1458 .domains = BDW_ALWAYS_ON_POWER_DOMAINS,
1459 .ops = &i9xx_always_on_power_well_ops,
1460 },
1461 {
1462 .name = "display",
1463 .domains = BDW_DISPLAY_POWER_DOMAINS,
1464 .ops = &hsw_power_well_ops,
1465 },
1466};
1467
1468static const struct i915_power_well_ops vlv_display_power_well_ops = {
1469 .sync_hw = vlv_power_well_sync_hw,
1470 .enable = vlv_display_power_well_enable,
1471 .disable = vlv_display_power_well_disable,
1472 .is_enabled = vlv_power_well_enabled,
1473};
1474
1475static const struct i915_power_well_ops vlv_dpio_cmn_power_well_ops = {
1476 .sync_hw = vlv_power_well_sync_hw,
1477 .enable = vlv_dpio_cmn_power_well_enable,
1478 .disable = vlv_dpio_cmn_power_well_disable,
1479 .is_enabled = vlv_power_well_enabled,
1480};
1481
1482static const struct i915_power_well_ops vlv_dpio_power_well_ops = {
1483 .sync_hw = vlv_power_well_sync_hw,
1484 .enable = vlv_power_well_enable,
1485 .disable = vlv_power_well_disable,
1486 .is_enabled = vlv_power_well_enabled,
1487};
1488
1489static struct i915_power_well vlv_power_wells[] = {
1490 {
1491 .name = "always-on",
1492 .always_on = 1,
1493 .domains = VLV_ALWAYS_ON_POWER_DOMAINS,
1494 .ops = &i9xx_always_on_power_well_ops,
1495 },
1496 {
1497 .name = "display",
1498 .domains = VLV_DISPLAY_POWER_DOMAINS,
1499 .data = PUNIT_POWER_WELL_DISP2D,
1500 .ops = &vlv_display_power_well_ops,
1501 },
1502 {
1503 .name = "dpio-tx-b-01",
1504 .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
1505 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
1506 VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
1507 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
1508 .ops = &vlv_dpio_power_well_ops,
1509 .data = PUNIT_POWER_WELL_DPIO_TX_B_LANES_01,
1510 },
1511 {
1512 .name = "dpio-tx-b-23",
1513 .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
1514 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
1515 VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
1516 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
1517 .ops = &vlv_dpio_power_well_ops,
1518 .data = PUNIT_POWER_WELL_DPIO_TX_B_LANES_23,
1519 },
1520 {
1521 .name = "dpio-tx-c-01",
1522 .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
1523 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
1524 VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
1525 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
1526 .ops = &vlv_dpio_power_well_ops,
1527 .data = PUNIT_POWER_WELL_DPIO_TX_C_LANES_01,
1528 },
1529 {
1530 .name = "dpio-tx-c-23",
1531 .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
1532 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
1533 VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
1534 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
1535 .ops = &vlv_dpio_power_well_ops,
1536 .data = PUNIT_POWER_WELL_DPIO_TX_C_LANES_23,
1537 },
1538 {
1539 .name = "dpio-common",
1540 .domains = VLV_DPIO_CMN_BC_POWER_DOMAINS,
1541 .data = PUNIT_POWER_WELL_DPIO_CMN_BC,
1542 .ops = &vlv_dpio_cmn_power_well_ops,
1543 },
1544};
1545
1546static struct i915_power_well chv_power_wells[] = {
1547 {
1548 .name = "always-on",
1549 .always_on = 1,
1550 .domains = VLV_ALWAYS_ON_POWER_DOMAINS,
1551 .ops = &i9xx_always_on_power_well_ops,
1552 },
Daniel Vetter9c065a72014-09-30 10:56:38 +02001553 {
1554 .name = "display",
Ville Syrjäläbaa4e572014-10-27 16:07:32 +02001555 /*
Ville Syrjäläfde61e42015-05-26 20:22:39 +03001556 * Pipe A power well is the new disp2d well. Pipe B and C
1557 * power wells don't actually exist. Pipe A power well is
1558 * required for any pipe to work.
Ville Syrjäläbaa4e572014-10-27 16:07:32 +02001559 */
Ville Syrjäläfde61e42015-05-26 20:22:39 +03001560 .domains = VLV_DISPLAY_POWER_DOMAINS,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001561 .data = PIPE_A,
1562 .ops = &chv_pipe_power_well_ops,
1563 },
Daniel Vetter9c065a72014-09-30 10:56:38 +02001564 {
1565 .name = "dpio-common-bc",
Ville Syrjälä71849b62015-04-10 18:21:29 +03001566 .domains = CHV_DPIO_CMN_BC_POWER_DOMAINS,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001567 .data = PUNIT_POWER_WELL_DPIO_CMN_BC,
1568 .ops = &chv_dpio_cmn_power_well_ops,
1569 },
1570 {
1571 .name = "dpio-common-d",
Ville Syrjälä71849b62015-04-10 18:21:29 +03001572 .domains = CHV_DPIO_CMN_D_POWER_DOMAINS,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001573 .data = PUNIT_POWER_WELL_DPIO_CMN_D,
1574 .ops = &chv_dpio_cmn_power_well_ops,
1575 },
Daniel Vetter9c065a72014-09-30 10:56:38 +02001576};
1577
1578static struct i915_power_well *lookup_power_well(struct drm_i915_private *dev_priv,
Suketu Shah5aefb232015-04-16 14:22:10 +05301579 int power_well_id)
Daniel Vetter9c065a72014-09-30 10:56:38 +02001580{
1581 struct i915_power_domains *power_domains = &dev_priv->power_domains;
1582 struct i915_power_well *power_well;
1583 int i;
1584
1585 for_each_power_well(i, power_well, POWER_DOMAIN_MASK, power_domains) {
1586 if (power_well->data == power_well_id)
1587 return power_well;
1588 }
1589
1590 return NULL;
1591}
1592
Suketu Shah5aefb232015-04-16 14:22:10 +05301593bool intel_display_power_well_is_enabled(struct drm_i915_private *dev_priv,
1594 int power_well_id)
1595{
1596 struct i915_power_well *power_well;
1597 bool ret;
1598
1599 power_well = lookup_power_well(dev_priv, power_well_id);
1600 ret = power_well->ops->is_enabled(dev_priv, power_well);
1601
1602 return ret;
1603}
1604
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00001605static struct i915_power_well skl_power_wells[] = {
1606 {
1607 .name = "always-on",
1608 .always_on = 1,
1609 .domains = SKL_DISPLAY_ALWAYS_ON_POWER_DOMAINS,
1610 .ops = &i9xx_always_on_power_well_ops,
1611 },
1612 {
1613 .name = "power well 1",
1614 .domains = SKL_DISPLAY_POWERWELL_1_POWER_DOMAINS,
1615 .ops = &skl_power_well_ops,
1616 .data = SKL_DISP_PW_1,
1617 },
1618 {
1619 .name = "MISC IO power well",
1620 .domains = SKL_DISPLAY_MISC_IO_POWER_DOMAINS,
1621 .ops = &skl_power_well_ops,
1622 .data = SKL_DISP_PW_MISC_IO,
1623 },
1624 {
1625 .name = "power well 2",
1626 .domains = SKL_DISPLAY_POWERWELL_2_POWER_DOMAINS,
1627 .ops = &skl_power_well_ops,
1628 .data = SKL_DISP_PW_2,
1629 },
1630 {
1631 .name = "DDI A/E power well",
1632 .domains = SKL_DISPLAY_DDI_A_E_POWER_DOMAINS,
1633 .ops = &skl_power_well_ops,
1634 .data = SKL_DISP_PW_DDI_A_E,
1635 },
1636 {
1637 .name = "DDI B power well",
1638 .domains = SKL_DISPLAY_DDI_B_POWER_DOMAINS,
1639 .ops = &skl_power_well_ops,
1640 .data = SKL_DISP_PW_DDI_B,
1641 },
1642 {
1643 .name = "DDI C power well",
1644 .domains = SKL_DISPLAY_DDI_C_POWER_DOMAINS,
1645 .ops = &skl_power_well_ops,
1646 .data = SKL_DISP_PW_DDI_C,
1647 },
1648 {
1649 .name = "DDI D power well",
1650 .domains = SKL_DISPLAY_DDI_D_POWER_DOMAINS,
1651 .ops = &skl_power_well_ops,
1652 .data = SKL_DISP_PW_DDI_D,
1653 },
1654};
1655
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05301656static struct i915_power_well bxt_power_wells[] = {
1657 {
1658 .name = "always-on",
1659 .always_on = 1,
1660 .domains = BXT_DISPLAY_ALWAYS_ON_POWER_DOMAINS,
1661 .ops = &i9xx_always_on_power_well_ops,
1662 },
1663 {
1664 .name = "power well 1",
1665 .domains = BXT_DISPLAY_POWERWELL_1_POWER_DOMAINS,
1666 .ops = &skl_power_well_ops,
1667 .data = SKL_DISP_PW_1,
1668 },
1669 {
1670 .name = "power well 2",
1671 .domains = BXT_DISPLAY_POWERWELL_2_POWER_DOMAINS,
1672 .ops = &skl_power_well_ops,
1673 .data = SKL_DISP_PW_2,
1674 }
1675};
1676
Daniel Vetter9c065a72014-09-30 10:56:38 +02001677#define set_power_wells(power_domains, __power_wells) ({ \
1678 (power_domains)->power_wells = (__power_wells); \
1679 (power_domains)->power_well_count = ARRAY_SIZE(__power_wells); \
1680})
1681
Daniel Vettere4e76842014-09-30 10:56:42 +02001682/**
1683 * intel_power_domains_init - initializes the power domain structures
1684 * @dev_priv: i915 device instance
1685 *
1686 * Initializes the power domain structures for @dev_priv depending upon the
1687 * supported platform.
1688 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02001689int intel_power_domains_init(struct drm_i915_private *dev_priv)
1690{
1691 struct i915_power_domains *power_domains = &dev_priv->power_domains;
1692
1693 mutex_init(&power_domains->lock);
1694
1695 /*
1696 * The enabling order will be from lower to higher indexed wells,
1697 * the disabling order is reversed.
1698 */
1699 if (IS_HASWELL(dev_priv->dev)) {
1700 set_power_wells(power_domains, hsw_power_wells);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001701 } else if (IS_BROADWELL(dev_priv->dev)) {
1702 set_power_wells(power_domains, bdw_power_wells);
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00001703 } else if (IS_SKYLAKE(dev_priv->dev)) {
1704 set_power_wells(power_domains, skl_power_wells);
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05301705 } else if (IS_BROXTON(dev_priv->dev)) {
1706 set_power_wells(power_domains, bxt_power_wells);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001707 } else if (IS_CHERRYVIEW(dev_priv->dev)) {
1708 set_power_wells(power_domains, chv_power_wells);
1709 } else if (IS_VALLEYVIEW(dev_priv->dev)) {
1710 set_power_wells(power_domains, vlv_power_wells);
1711 } else {
1712 set_power_wells(power_domains, i9xx_always_on_power_well);
1713 }
1714
1715 return 0;
1716}
1717
Daniel Vetter41373cd2014-09-30 10:56:41 +02001718static void intel_runtime_pm_disable(struct drm_i915_private *dev_priv)
1719{
1720 struct drm_device *dev = dev_priv->dev;
1721 struct device *device = &dev->pdev->dev;
1722
1723 if (!HAS_RUNTIME_PM(dev))
1724 return;
1725
1726 if (!intel_enable_rc6(dev))
1727 return;
1728
1729 /* Make sure we're not suspended first. */
1730 pm_runtime_get_sync(device);
1731 pm_runtime_disable(device);
1732}
1733
Daniel Vettere4e76842014-09-30 10:56:42 +02001734/**
1735 * intel_power_domains_fini - finalizes the power domain structures
1736 * @dev_priv: i915 device instance
1737 *
1738 * Finalizes the power domain structures for @dev_priv depending upon the
1739 * supported platform. This function also disables runtime pm and ensures that
1740 * the device stays powered up so that the driver can be reloaded.
1741 */
Daniel Vetterf458ebb2014-09-30 10:56:39 +02001742void intel_power_domains_fini(struct drm_i915_private *dev_priv)
Daniel Vetter9c065a72014-09-30 10:56:38 +02001743{
Daniel Vetter41373cd2014-09-30 10:56:41 +02001744 intel_runtime_pm_disable(dev_priv);
1745
Daniel Vetterf458ebb2014-09-30 10:56:39 +02001746 /* The i915.ko module is still not prepared to be loaded when
1747 * the power well is not enabled, so just enable it in case
1748 * we're going to unload/reload. */
1749 intel_display_set_init_power(dev_priv, true);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001750}
1751
1752static void intel_power_domains_resume(struct drm_i915_private *dev_priv)
1753{
1754 struct i915_power_domains *power_domains = &dev_priv->power_domains;
1755 struct i915_power_well *power_well;
1756 int i;
1757
1758 mutex_lock(&power_domains->lock);
1759 for_each_power_well(i, power_well, POWER_DOMAIN_MASK, power_domains) {
1760 power_well->ops->sync_hw(dev_priv, power_well);
1761 power_well->hw_enabled = power_well->ops->is_enabled(dev_priv,
1762 power_well);
1763 }
1764 mutex_unlock(&power_domains->lock);
1765}
1766
Ville Syrjälä70722462015-04-10 18:21:28 +03001767static void chv_phy_control_init(struct drm_i915_private *dev_priv)
1768{
1769 struct i915_power_well *cmn_bc =
1770 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_BC);
1771 struct i915_power_well *cmn_d =
1772 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_D);
1773
1774 /*
1775 * DISPLAY_PHY_CONTROL can get corrupted if read. As a
1776 * workaround never ever read DISPLAY_PHY_CONTROL, and
1777 * instead maintain a shadow copy ourselves. Use the actual
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001778 * power well state and lane status to reconstruct the
1779 * expected initial value.
Ville Syrjälä70722462015-04-10 18:21:28 +03001780 */
1781 dev_priv->chv_phy_control =
Ville Syrjäläbc284542015-05-26 20:22:38 +03001782 PHY_LDO_SEQ_DELAY(PHY_LDO_DELAY_600NS, DPIO_PHY0) |
1783 PHY_LDO_SEQ_DELAY(PHY_LDO_DELAY_600NS, DPIO_PHY1) |
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001784 PHY_CH_POWER_MODE(PHY_CH_DEEP_PSR, DPIO_PHY0, DPIO_CH0) |
1785 PHY_CH_POWER_MODE(PHY_CH_DEEP_PSR, DPIO_PHY0, DPIO_CH1) |
1786 PHY_CH_POWER_MODE(PHY_CH_DEEP_PSR, DPIO_PHY1, DPIO_CH0);
1787
1788 /*
1789 * If all lanes are disabled we leave the override disabled
1790 * with all power down bits cleared to match the state we
1791 * would use after disabling the port. Otherwise enable the
1792 * override and set the lane powerdown bits accding to the
1793 * current lane status.
1794 */
1795 if (cmn_bc->ops->is_enabled(dev_priv, cmn_bc)) {
1796 uint32_t status = I915_READ(DPLL(PIPE_A));
1797 unsigned int mask;
1798
1799 mask = status & DPLL_PORTB_READY_MASK;
1800 if (mask == 0xf)
1801 mask = 0x0;
1802 else
1803 dev_priv->chv_phy_control |=
1804 PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY0, DPIO_CH0);
1805
1806 dev_priv->chv_phy_control |=
1807 PHY_CH_POWER_DOWN_OVRD(mask, DPIO_PHY0, DPIO_CH0);
1808
1809 mask = (status & DPLL_PORTC_READY_MASK) >> 4;
1810 if (mask == 0xf)
1811 mask = 0x0;
1812 else
1813 dev_priv->chv_phy_control |=
1814 PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY0, DPIO_CH1);
1815
1816 dev_priv->chv_phy_control |=
1817 PHY_CH_POWER_DOWN_OVRD(mask, DPIO_PHY0, DPIO_CH1);
1818
Ville Syrjälä70722462015-04-10 18:21:28 +03001819 dev_priv->chv_phy_control |= PHY_COM_LANE_RESET_DEASSERT(DPIO_PHY0);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001820 }
1821
1822 if (cmn_d->ops->is_enabled(dev_priv, cmn_d)) {
1823 uint32_t status = I915_READ(DPIO_PHY_STATUS);
1824 unsigned int mask;
1825
1826 mask = status & DPLL_PORTD_READY_MASK;
1827
1828 if (mask == 0xf)
1829 mask = 0x0;
1830 else
1831 dev_priv->chv_phy_control |=
1832 PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY1, DPIO_CH0);
1833
1834 dev_priv->chv_phy_control |=
1835 PHY_CH_POWER_DOWN_OVRD(mask, DPIO_PHY1, DPIO_CH0);
1836
Ville Syrjälä70722462015-04-10 18:21:28 +03001837 dev_priv->chv_phy_control |= PHY_COM_LANE_RESET_DEASSERT(DPIO_PHY1);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001838 }
1839
1840 I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
1841
1842 DRM_DEBUG_KMS("Initial PHY_CONTROL=0x%08x\n",
1843 dev_priv->chv_phy_control);
Ville Syrjälä70722462015-04-10 18:21:28 +03001844}
1845
Daniel Vetter9c065a72014-09-30 10:56:38 +02001846static void vlv_cmnlane_wa(struct drm_i915_private *dev_priv)
1847{
1848 struct i915_power_well *cmn =
1849 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_BC);
1850 struct i915_power_well *disp2d =
1851 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DISP2D);
1852
Daniel Vetter9c065a72014-09-30 10:56:38 +02001853 /* If the display might be already active skip this */
Ville Syrjälä5d93a6e2014-10-16 20:52:33 +03001854 if (cmn->ops->is_enabled(dev_priv, cmn) &&
1855 disp2d->ops->is_enabled(dev_priv, disp2d) &&
Daniel Vetter9c065a72014-09-30 10:56:38 +02001856 I915_READ(DPIO_CTL) & DPIO_CMNRST)
1857 return;
1858
1859 DRM_DEBUG_KMS("toggling display PHY side reset\n");
1860
1861 /* cmnlane needs DPLL registers */
1862 disp2d->ops->enable(dev_priv, disp2d);
1863
1864 /*
1865 * From VLV2A0_DP_eDP_HDMI_DPIO_driver_vbios_notes_11.docx:
1866 * Need to assert and de-assert PHY SB reset by gating the
1867 * common lane power, then un-gating it.
1868 * Simply ungating isn't enough to reset the PHY enough to get
1869 * ports and lanes running.
1870 */
1871 cmn->ops->disable(dev_priv, cmn);
1872}
1873
Daniel Vettere4e76842014-09-30 10:56:42 +02001874/**
1875 * intel_power_domains_init_hw - initialize hardware power domain state
1876 * @dev_priv: i915 device instance
1877 *
1878 * This function initializes the hardware power domain state and enables all
1879 * power domains using intel_display_set_init_power().
1880 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02001881void intel_power_domains_init_hw(struct drm_i915_private *dev_priv)
1882{
1883 struct drm_device *dev = dev_priv->dev;
1884 struct i915_power_domains *power_domains = &dev_priv->power_domains;
1885
1886 power_domains->initializing = true;
1887
Ville Syrjälä70722462015-04-10 18:21:28 +03001888 if (IS_CHERRYVIEW(dev)) {
Ville Syrjälä770effb2015-07-08 23:45:51 +03001889 mutex_lock(&power_domains->lock);
Ville Syrjälä70722462015-04-10 18:21:28 +03001890 chv_phy_control_init(dev_priv);
Ville Syrjälä770effb2015-07-08 23:45:51 +03001891 mutex_unlock(&power_domains->lock);
Ville Syrjälä70722462015-04-10 18:21:28 +03001892 } else if (IS_VALLEYVIEW(dev)) {
Daniel Vetter9c065a72014-09-30 10:56:38 +02001893 mutex_lock(&power_domains->lock);
1894 vlv_cmnlane_wa(dev_priv);
1895 mutex_unlock(&power_domains->lock);
1896 }
1897
1898 /* For now, we need the power well to be always enabled. */
1899 intel_display_set_init_power(dev_priv, true);
1900 intel_power_domains_resume(dev_priv);
1901 power_domains->initializing = false;
1902}
1903
Daniel Vettere4e76842014-09-30 10:56:42 +02001904/**
Geert Uytterhoevenca2b1402015-03-09 21:21:08 +01001905 * intel_aux_display_runtime_get - grab an auxiliary power domain reference
Daniel Vettere4e76842014-09-30 10:56:42 +02001906 * @dev_priv: i915 device instance
1907 *
1908 * This function grabs a power domain reference for the auxiliary power domain
1909 * (for access to the GMBUS and DP AUX blocks) and ensures that it and all its
1910 * parents are powered up. Therefore users should only grab a reference to the
1911 * innermost power domain they need.
1912 *
1913 * Any power domain reference obtained by this function must have a symmetric
1914 * call to intel_aux_display_runtime_put() to release the reference again.
1915 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02001916void intel_aux_display_runtime_get(struct drm_i915_private *dev_priv)
1917{
1918 intel_runtime_pm_get(dev_priv);
1919}
1920
Daniel Vettere4e76842014-09-30 10:56:42 +02001921/**
Geert Uytterhoevenca2b1402015-03-09 21:21:08 +01001922 * intel_aux_display_runtime_put - release an auxiliary power domain reference
Daniel Vettere4e76842014-09-30 10:56:42 +02001923 * @dev_priv: i915 device instance
1924 *
Geert Uytterhoevenca2b1402015-03-09 21:21:08 +01001925 * This function drops the auxiliary power domain reference obtained by
Daniel Vettere4e76842014-09-30 10:56:42 +02001926 * intel_aux_display_runtime_get() and might power down the corresponding
1927 * hardware block right away if this is the last reference.
1928 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02001929void intel_aux_display_runtime_put(struct drm_i915_private *dev_priv)
1930{
1931 intel_runtime_pm_put(dev_priv);
1932}
1933
Daniel Vettere4e76842014-09-30 10:56:42 +02001934/**
1935 * intel_runtime_pm_get - grab a runtime pm reference
1936 * @dev_priv: i915 device instance
1937 *
1938 * This function grabs a device-level runtime pm reference (mostly used for GEM
1939 * code to ensure the GTT or GT is on) and ensures that it is powered up.
1940 *
1941 * Any runtime pm reference obtained by this function must have a symmetric
1942 * call to intel_runtime_pm_put() to release the reference again.
1943 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02001944void intel_runtime_pm_get(struct drm_i915_private *dev_priv)
1945{
1946 struct drm_device *dev = dev_priv->dev;
1947 struct device *device = &dev->pdev->dev;
1948
1949 if (!HAS_RUNTIME_PM(dev))
1950 return;
1951
1952 pm_runtime_get_sync(device);
1953 WARN(dev_priv->pm.suspended, "Device still suspended.\n");
1954}
1955
Daniel Vettere4e76842014-09-30 10:56:42 +02001956/**
1957 * intel_runtime_pm_get_noresume - grab a runtime pm reference
1958 * @dev_priv: i915 device instance
1959 *
1960 * This function grabs a device-level runtime pm reference (mostly used for GEM
1961 * code to ensure the GTT or GT is on).
1962 *
1963 * It will _not_ power up the device but instead only check that it's powered
1964 * on. Therefore it is only valid to call this functions from contexts where
1965 * the device is known to be powered up and where trying to power it up would
1966 * result in hilarity and deadlocks. That pretty much means only the system
1967 * suspend/resume code where this is used to grab runtime pm references for
1968 * delayed setup down in work items.
1969 *
1970 * Any runtime pm reference obtained by this function must have a symmetric
1971 * call to intel_runtime_pm_put() to release the reference again.
1972 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02001973void intel_runtime_pm_get_noresume(struct drm_i915_private *dev_priv)
1974{
1975 struct drm_device *dev = dev_priv->dev;
1976 struct device *device = &dev->pdev->dev;
1977
1978 if (!HAS_RUNTIME_PM(dev))
1979 return;
1980
1981 WARN(dev_priv->pm.suspended, "Getting nosync-ref while suspended.\n");
1982 pm_runtime_get_noresume(device);
1983}
1984
Daniel Vettere4e76842014-09-30 10:56:42 +02001985/**
1986 * intel_runtime_pm_put - release a runtime pm reference
1987 * @dev_priv: i915 device instance
1988 *
1989 * This function drops the device-level runtime pm reference obtained by
1990 * intel_runtime_pm_get() and might power down the corresponding
1991 * hardware block right away if this is the last reference.
1992 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02001993void intel_runtime_pm_put(struct drm_i915_private *dev_priv)
1994{
1995 struct drm_device *dev = dev_priv->dev;
1996 struct device *device = &dev->pdev->dev;
1997
1998 if (!HAS_RUNTIME_PM(dev))
1999 return;
2000
2001 pm_runtime_mark_last_busy(device);
2002 pm_runtime_put_autosuspend(device);
2003}
2004
Daniel Vettere4e76842014-09-30 10:56:42 +02002005/**
2006 * intel_runtime_pm_enable - enable runtime pm
2007 * @dev_priv: i915 device instance
2008 *
2009 * This function enables runtime pm at the end of the driver load sequence.
2010 *
2011 * Note that this function does currently not enable runtime pm for the
2012 * subordinate display power domains. That is only done on the first modeset
2013 * using intel_display_set_init_power().
2014 */
Daniel Vetterf458ebb2014-09-30 10:56:39 +02002015void intel_runtime_pm_enable(struct drm_i915_private *dev_priv)
Daniel Vetter9c065a72014-09-30 10:56:38 +02002016{
2017 struct drm_device *dev = dev_priv->dev;
2018 struct device *device = &dev->pdev->dev;
2019
2020 if (!HAS_RUNTIME_PM(dev))
2021 return;
2022
2023 pm_runtime_set_active(device);
2024
2025 /*
2026 * RPM depends on RC6 to save restore the GT HW context, so make RC6 a
2027 * requirement.
2028 */
2029 if (!intel_enable_rc6(dev)) {
2030 DRM_INFO("RC6 disabled, disabling runtime PM support\n");
2031 return;
2032 }
2033
2034 pm_runtime_set_autosuspend_delay(device, 10000); /* 10s */
2035 pm_runtime_mark_last_busy(device);
2036 pm_runtime_use_autosuspend(device);
2037
2038 pm_runtime_put_autosuspend(device);
2039}
2040