blob: 95034a06d4ad3dd38c09edf998394321806dc025 [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++) \
Jani Nikula95150bd2015-11-24 21:21:56 +020057 for_each_if ((power_well)->domains & (domain_mask))
Daniel Vetter9c065a72014-09-30 10:56:38 +020058
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--) \
Jani Nikula95150bd2015-11-24 21:21:56 +020063 for_each_if ((power_well)->domains & (domain_mask))
Daniel Vetter9c065a72014-09-30 10:56:38 +020064
Suketu Shah5aefb232015-04-16 14:22:10 +053065bool intel_display_power_well_is_enabled(struct drm_i915_private *dev_priv,
66 int power_well_id);
67
Imre Deak9c8d0b82016-06-13 16:44:34 +030068static struct i915_power_well *
69lookup_power_well(struct drm_i915_private *dev_priv, int power_well_id);
70
Daniel Stone9895ad02015-11-20 15:55:33 +000071const char *
72intel_display_power_domain_str(enum intel_display_power_domain domain)
73{
74 switch (domain) {
75 case POWER_DOMAIN_PIPE_A:
76 return "PIPE_A";
77 case POWER_DOMAIN_PIPE_B:
78 return "PIPE_B";
79 case POWER_DOMAIN_PIPE_C:
80 return "PIPE_C";
81 case POWER_DOMAIN_PIPE_A_PANEL_FITTER:
82 return "PIPE_A_PANEL_FITTER";
83 case POWER_DOMAIN_PIPE_B_PANEL_FITTER:
84 return "PIPE_B_PANEL_FITTER";
85 case POWER_DOMAIN_PIPE_C_PANEL_FITTER:
86 return "PIPE_C_PANEL_FITTER";
87 case POWER_DOMAIN_TRANSCODER_A:
88 return "TRANSCODER_A";
89 case POWER_DOMAIN_TRANSCODER_B:
90 return "TRANSCODER_B";
91 case POWER_DOMAIN_TRANSCODER_C:
92 return "TRANSCODER_C";
93 case POWER_DOMAIN_TRANSCODER_EDP:
94 return "TRANSCODER_EDP";
Jani Nikula4d1de972016-03-18 17:05:42 +020095 case POWER_DOMAIN_TRANSCODER_DSI_A:
96 return "TRANSCODER_DSI_A";
97 case POWER_DOMAIN_TRANSCODER_DSI_C:
98 return "TRANSCODER_DSI_C";
Daniel Stone9895ad02015-11-20 15:55:33 +000099 case POWER_DOMAIN_PORT_DDI_A_LANES:
100 return "PORT_DDI_A_LANES";
101 case POWER_DOMAIN_PORT_DDI_B_LANES:
102 return "PORT_DDI_B_LANES";
103 case POWER_DOMAIN_PORT_DDI_C_LANES:
104 return "PORT_DDI_C_LANES";
105 case POWER_DOMAIN_PORT_DDI_D_LANES:
106 return "PORT_DDI_D_LANES";
107 case POWER_DOMAIN_PORT_DDI_E_LANES:
108 return "PORT_DDI_E_LANES";
109 case POWER_DOMAIN_PORT_DSI:
110 return "PORT_DSI";
111 case POWER_DOMAIN_PORT_CRT:
112 return "PORT_CRT";
113 case POWER_DOMAIN_PORT_OTHER:
114 return "PORT_OTHER";
115 case POWER_DOMAIN_VGA:
116 return "VGA";
117 case POWER_DOMAIN_AUDIO:
118 return "AUDIO";
119 case POWER_DOMAIN_PLLS:
120 return "PLLS";
121 case POWER_DOMAIN_AUX_A:
122 return "AUX_A";
123 case POWER_DOMAIN_AUX_B:
124 return "AUX_B";
125 case POWER_DOMAIN_AUX_C:
126 return "AUX_C";
127 case POWER_DOMAIN_AUX_D:
128 return "AUX_D";
129 case POWER_DOMAIN_GMBUS:
130 return "GMBUS";
131 case POWER_DOMAIN_INIT:
132 return "INIT";
133 case POWER_DOMAIN_MODESET:
134 return "MODESET";
135 default:
136 MISSING_CASE(domain);
137 return "?";
138 }
139}
140
Damien Lespiaue8ca9322015-07-30 18:20:26 -0300141static void intel_power_well_enable(struct drm_i915_private *dev_priv,
142 struct i915_power_well *power_well)
143{
144 DRM_DEBUG_KMS("enabling %s\n", power_well->name);
145 power_well->ops->enable(dev_priv, power_well);
146 power_well->hw_enabled = true;
147}
148
Damien Lespiaudcddab32015-07-30 18:20:27 -0300149static void intel_power_well_disable(struct drm_i915_private *dev_priv,
150 struct i915_power_well *power_well)
151{
152 DRM_DEBUG_KMS("disabling %s\n", power_well->name);
153 power_well->hw_enabled = false;
154 power_well->ops->disable(dev_priv, power_well);
155}
156
Imre Deakb409ca92016-06-13 16:44:33 +0300157static void intel_power_well_get(struct drm_i915_private *dev_priv,
158 struct i915_power_well *power_well)
159{
160 if (!power_well->count++)
161 intel_power_well_enable(dev_priv, power_well);
162}
163
164static void intel_power_well_put(struct drm_i915_private *dev_priv,
165 struct i915_power_well *power_well)
166{
167 WARN(!power_well->count, "Use count on power well %s is already zero",
168 power_well->name);
169
170 if (!--power_well->count)
171 intel_power_well_disable(dev_priv, power_well);
172}
173
Daniel Vettere4e76842014-09-30 10:56:42 +0200174/*
Daniel Vetter9c065a72014-09-30 10:56:38 +0200175 * We should only use the power well if we explicitly asked the hardware to
176 * enable it, so check if it's enabled and also check if we've requested it to
177 * be enabled.
178 */
179static bool hsw_power_well_enabled(struct drm_i915_private *dev_priv,
180 struct i915_power_well *power_well)
181{
182 return I915_READ(HSW_PWR_WELL_DRIVER) ==
183 (HSW_PWR_WELL_ENABLE_REQUEST | HSW_PWR_WELL_STATE_ENABLED);
184}
185
Daniel Vettere4e76842014-09-30 10:56:42 +0200186/**
187 * __intel_display_power_is_enabled - unlocked check for a power domain
188 * @dev_priv: i915 device instance
189 * @domain: power domain to check
190 *
191 * This is the unlocked version of intel_display_power_is_enabled() and should
192 * only be used from error capture and recovery code where deadlocks are
193 * possible.
194 *
195 * Returns:
196 * True when the power domain is enabled, false otherwise.
197 */
Daniel Vetterf458ebb2014-09-30 10:56:39 +0200198bool __intel_display_power_is_enabled(struct drm_i915_private *dev_priv,
199 enum intel_display_power_domain domain)
Daniel Vetter9c065a72014-09-30 10:56:38 +0200200{
201 struct i915_power_domains *power_domains;
202 struct i915_power_well *power_well;
203 bool is_enabled;
204 int i;
205
206 if (dev_priv->pm.suspended)
207 return false;
208
209 power_domains = &dev_priv->power_domains;
210
211 is_enabled = true;
212
213 for_each_power_well_rev(i, power_well, BIT(domain), power_domains) {
214 if (power_well->always_on)
215 continue;
216
217 if (!power_well->hw_enabled) {
218 is_enabled = false;
219 break;
220 }
221 }
222
223 return is_enabled;
224}
225
Daniel Vettere4e76842014-09-30 10:56:42 +0200226/**
Damien Lespiauf61ccae2014-11-25 13:45:41 +0000227 * intel_display_power_is_enabled - check for a power domain
Daniel Vettere4e76842014-09-30 10:56:42 +0200228 * @dev_priv: i915 device instance
229 * @domain: power domain to check
230 *
231 * This function can be used to check the hw power domain state. It is mostly
232 * used in hardware state readout functions. Everywhere else code should rely
233 * upon explicit power domain reference counting to ensure that the hardware
234 * block is powered up before accessing it.
235 *
236 * Callers must hold the relevant modesetting locks to ensure that concurrent
237 * threads can't disable the power well while the caller tries to read a few
238 * registers.
239 *
240 * Returns:
241 * True when the power domain is enabled, false otherwise.
242 */
Daniel Vetterf458ebb2014-09-30 10:56:39 +0200243bool intel_display_power_is_enabled(struct drm_i915_private *dev_priv,
244 enum intel_display_power_domain domain)
Daniel Vetter9c065a72014-09-30 10:56:38 +0200245{
246 struct i915_power_domains *power_domains;
247 bool ret;
248
249 power_domains = &dev_priv->power_domains;
250
251 mutex_lock(&power_domains->lock);
Daniel Vetterf458ebb2014-09-30 10:56:39 +0200252 ret = __intel_display_power_is_enabled(dev_priv, domain);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200253 mutex_unlock(&power_domains->lock);
254
255 return ret;
256}
257
Daniel Vettere4e76842014-09-30 10:56:42 +0200258/**
259 * intel_display_set_init_power - set the initial power domain state
260 * @dev_priv: i915 device instance
261 * @enable: whether to enable or disable the initial power domain state
262 *
263 * For simplicity our driver load/unload and system suspend/resume code assumes
264 * that all power domains are always enabled. This functions controls the state
265 * of this little hack. While the initial power domain state is enabled runtime
266 * pm is effectively disabled.
267 */
Daniel Vetterd9bc89d92014-09-30 10:56:40 +0200268void intel_display_set_init_power(struct drm_i915_private *dev_priv,
269 bool enable)
270{
271 if (dev_priv->power_domains.init_power_on == enable)
272 return;
273
274 if (enable)
275 intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
276 else
277 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
278
279 dev_priv->power_domains.init_power_on = enable;
280}
281
Daniel Vetter9c065a72014-09-30 10:56:38 +0200282/*
283 * Starting with Haswell, we have a "Power Down Well" that can be turned off
284 * when not needed anymore. We have 4 registers that can request the power well
285 * to be enabled, and it will only be disabled if none of the registers is
286 * requesting it to be enabled.
287 */
288static void hsw_power_well_post_enable(struct drm_i915_private *dev_priv)
289{
David Weinehall52a05c32016-08-22 13:32:44 +0300290 struct pci_dev *pdev = dev_priv->drm.pdev;
Daniel Vetter9c065a72014-09-30 10:56:38 +0200291
292 /*
293 * After we re-enable the power well, if we touch VGA register 0x3d5
294 * we'll get unclaimed register interrupts. This stops after we write
295 * anything to the VGA MSR register. The vgacon module uses this
296 * register all the time, so if we unbind our driver and, as a
297 * consequence, bind vgacon, we'll get stuck in an infinite loop at
298 * console_unlock(). So make here we touch the VGA MSR register, making
299 * sure vgacon can keep working normally without triggering interrupts
300 * and error messages.
301 */
David Weinehall52a05c32016-08-22 13:32:44 +0300302 vga_get_uninterruptible(pdev, VGA_RSRC_LEGACY_IO);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200303 outb(inb(VGA_MSR_READ), VGA_MSR_WRITE);
David Weinehall52a05c32016-08-22 13:32:44 +0300304 vga_put(pdev, VGA_RSRC_LEGACY_IO);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200305
Tvrtko Ursulin86527442016-10-13 11:03:00 +0100306 if (IS_BROADWELL(dev_priv))
Damien Lespiau4c6c03b2015-03-06 18:50:48 +0000307 gen8_irq_power_well_post_enable(dev_priv,
308 1 << PIPE_C | 1 << PIPE_B);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200309}
310
Ville Syrjäläaae8ba82016-02-19 20:47:30 +0200311static void hsw_power_well_pre_disable(struct drm_i915_private *dev_priv)
312{
313 if (IS_BROADWELL(dev_priv))
314 gen8_irq_power_well_pre_disable(dev_priv,
315 1 << PIPE_C | 1 << PIPE_B);
316}
317
Damien Lespiaud14c0342015-03-06 18:50:51 +0000318static void skl_power_well_post_enable(struct drm_i915_private *dev_priv,
319 struct i915_power_well *power_well)
320{
David Weinehall52a05c32016-08-22 13:32:44 +0300321 struct pci_dev *pdev = dev_priv->drm.pdev;
Damien Lespiaud14c0342015-03-06 18:50:51 +0000322
323 /*
324 * After we re-enable the power well, if we touch VGA register 0x3d5
325 * we'll get unclaimed register interrupts. This stops after we write
326 * anything to the VGA MSR register. The vgacon module uses this
327 * register all the time, so if we unbind our driver and, as a
328 * consequence, bind vgacon, we'll get stuck in an infinite loop at
329 * console_unlock(). So make here we touch the VGA MSR register, making
330 * sure vgacon can keep working normally without triggering interrupts
331 * and error messages.
332 */
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +0300333 if (power_well->id == SKL_DISP_PW_2) {
David Weinehall52a05c32016-08-22 13:32:44 +0300334 vga_get_uninterruptible(pdev, VGA_RSRC_LEGACY_IO);
Damien Lespiaud14c0342015-03-06 18:50:51 +0000335 outb(inb(VGA_MSR_READ), VGA_MSR_WRITE);
David Weinehall52a05c32016-08-22 13:32:44 +0300336 vga_put(pdev, VGA_RSRC_LEGACY_IO);
Damien Lespiaud14c0342015-03-06 18:50:51 +0000337
338 gen8_irq_power_well_post_enable(dev_priv,
339 1 << PIPE_C | 1 << PIPE_B);
340 }
Damien Lespiaud14c0342015-03-06 18:50:51 +0000341}
342
Ville Syrjäläaae8ba82016-02-19 20:47:30 +0200343static void skl_power_well_pre_disable(struct drm_i915_private *dev_priv,
344 struct i915_power_well *power_well)
345{
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +0300346 if (power_well->id == SKL_DISP_PW_2)
Ville Syrjäläaae8ba82016-02-19 20:47:30 +0200347 gen8_irq_power_well_pre_disable(dev_priv,
348 1 << PIPE_C | 1 << PIPE_B);
349}
350
Daniel Vetter9c065a72014-09-30 10:56:38 +0200351static void hsw_set_power_well(struct drm_i915_private *dev_priv,
352 struct i915_power_well *power_well, bool enable)
353{
354 bool is_enabled, enable_requested;
355 uint32_t tmp;
356
357 tmp = I915_READ(HSW_PWR_WELL_DRIVER);
358 is_enabled = tmp & HSW_PWR_WELL_STATE_ENABLED;
359 enable_requested = tmp & HSW_PWR_WELL_ENABLE_REQUEST;
360
361 if (enable) {
362 if (!enable_requested)
363 I915_WRITE(HSW_PWR_WELL_DRIVER,
364 HSW_PWR_WELL_ENABLE_REQUEST);
365
366 if (!is_enabled) {
367 DRM_DEBUG_KMS("Enabling power well\n");
Chris Wilson2c2ccc32016-06-30 15:33:32 +0100368 if (intel_wait_for_register(dev_priv,
369 HSW_PWR_WELL_DRIVER,
370 HSW_PWR_WELL_STATE_ENABLED,
371 HSW_PWR_WELL_STATE_ENABLED,
372 20))
Daniel Vetter9c065a72014-09-30 10:56:38 +0200373 DRM_ERROR("Timeout enabling power well\n");
Paulo Zanoni6d729bf2014-10-07 16:11:11 -0300374 hsw_power_well_post_enable(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200375 }
376
Daniel Vetter9c065a72014-09-30 10:56:38 +0200377 } else {
378 if (enable_requested) {
Ville Syrjäläaae8ba82016-02-19 20:47:30 +0200379 hsw_power_well_pre_disable(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200380 I915_WRITE(HSW_PWR_WELL_DRIVER, 0);
381 POSTING_READ(HSW_PWR_WELL_DRIVER);
382 DRM_DEBUG_KMS("Requesting to disable the power well\n");
383 }
384 }
385}
386
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000387#define SKL_DISPLAY_POWERWELL_2_POWER_DOMAINS ( \
388 BIT(POWER_DOMAIN_TRANSCODER_A) | \
389 BIT(POWER_DOMAIN_PIPE_B) | \
390 BIT(POWER_DOMAIN_TRANSCODER_B) | \
391 BIT(POWER_DOMAIN_PIPE_C) | \
392 BIT(POWER_DOMAIN_TRANSCODER_C) | \
393 BIT(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
394 BIT(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
Patrik Jakobsson6331a702015-11-09 16:48:21 +0100395 BIT(POWER_DOMAIN_PORT_DDI_B_LANES) | \
396 BIT(POWER_DOMAIN_PORT_DDI_C_LANES) | \
397 BIT(POWER_DOMAIN_PORT_DDI_D_LANES) | \
398 BIT(POWER_DOMAIN_PORT_DDI_E_LANES) | \
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000399 BIT(POWER_DOMAIN_AUX_B) | \
400 BIT(POWER_DOMAIN_AUX_C) | \
401 BIT(POWER_DOMAIN_AUX_D) | \
402 BIT(POWER_DOMAIN_AUDIO) | \
403 BIT(POWER_DOMAIN_VGA) | \
404 BIT(POWER_DOMAIN_INIT))
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000405#define SKL_DISPLAY_DDI_A_E_POWER_DOMAINS ( \
Patrik Jakobsson6331a702015-11-09 16:48:21 +0100406 BIT(POWER_DOMAIN_PORT_DDI_A_LANES) | \
407 BIT(POWER_DOMAIN_PORT_DDI_E_LANES) | \
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000408 BIT(POWER_DOMAIN_INIT))
409#define SKL_DISPLAY_DDI_B_POWER_DOMAINS ( \
Patrik Jakobsson6331a702015-11-09 16:48:21 +0100410 BIT(POWER_DOMAIN_PORT_DDI_B_LANES) | \
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000411 BIT(POWER_DOMAIN_INIT))
412#define SKL_DISPLAY_DDI_C_POWER_DOMAINS ( \
Patrik Jakobsson6331a702015-11-09 16:48:21 +0100413 BIT(POWER_DOMAIN_PORT_DDI_C_LANES) | \
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000414 BIT(POWER_DOMAIN_INIT))
415#define SKL_DISPLAY_DDI_D_POWER_DOMAINS ( \
Patrik Jakobsson6331a702015-11-09 16:48:21 +0100416 BIT(POWER_DOMAIN_PORT_DDI_D_LANES) | \
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000417 BIT(POWER_DOMAIN_INIT))
Patrik Jakobsson9f836f92015-11-16 16:20:01 +0100418#define SKL_DISPLAY_DC_OFF_POWER_DOMAINS ( \
419 SKL_DISPLAY_POWERWELL_2_POWER_DOMAINS | \
420 BIT(POWER_DOMAIN_MODESET) | \
421 BIT(POWER_DOMAIN_AUX_A) | \
422 BIT(POWER_DOMAIN_INIT))
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000423
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +0530424#define BXT_DISPLAY_POWERWELL_2_POWER_DOMAINS ( \
425 BIT(POWER_DOMAIN_TRANSCODER_A) | \
426 BIT(POWER_DOMAIN_PIPE_B) | \
427 BIT(POWER_DOMAIN_TRANSCODER_B) | \
428 BIT(POWER_DOMAIN_PIPE_C) | \
429 BIT(POWER_DOMAIN_TRANSCODER_C) | \
430 BIT(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
431 BIT(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
Patrik Jakobsson6331a702015-11-09 16:48:21 +0100432 BIT(POWER_DOMAIN_PORT_DDI_B_LANES) | \
433 BIT(POWER_DOMAIN_PORT_DDI_C_LANES) | \
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +0530434 BIT(POWER_DOMAIN_AUX_B) | \
435 BIT(POWER_DOMAIN_AUX_C) | \
436 BIT(POWER_DOMAIN_AUDIO) | \
437 BIT(POWER_DOMAIN_VGA) | \
Ville Syrjäläf0ab43e2015-11-09 16:48:19 +0100438 BIT(POWER_DOMAIN_GMBUS) | \
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +0530439 BIT(POWER_DOMAIN_INIT))
Patrik Jakobsson9f836f92015-11-16 16:20:01 +0100440#define BXT_DISPLAY_DC_OFF_POWER_DOMAINS ( \
441 BXT_DISPLAY_POWERWELL_2_POWER_DOMAINS | \
442 BIT(POWER_DOMAIN_MODESET) | \
443 BIT(POWER_DOMAIN_AUX_A) | \
444 BIT(POWER_DOMAIN_INIT))
Imre Deak9c8d0b82016-06-13 16:44:34 +0300445#define BXT_DPIO_CMN_A_POWER_DOMAINS ( \
446 BIT(POWER_DOMAIN_PORT_DDI_A_LANES) | \
447 BIT(POWER_DOMAIN_AUX_A) | \
448 BIT(POWER_DOMAIN_INIT))
449#define BXT_DPIO_CMN_BC_POWER_DOMAINS ( \
450 BIT(POWER_DOMAIN_PORT_DDI_B_LANES) | \
451 BIT(POWER_DOMAIN_PORT_DDI_C_LANES) | \
452 BIT(POWER_DOMAIN_AUX_B) | \
453 BIT(POWER_DOMAIN_AUX_C) | \
454 BIT(POWER_DOMAIN_INIT))
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +0530455
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530456static void assert_can_enable_dc9(struct drm_i915_private *dev_priv)
457{
Imre Deakbfcdabe2016-04-01 16:02:37 +0300458 WARN_ONCE((I915_READ(DC_STATE_EN) & DC_STATE_EN_DC9),
459 "DC9 already programmed to be enabled.\n");
460 WARN_ONCE(I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC5,
461 "DC5 still not disabled to enable DC9.\n");
462 WARN_ONCE(I915_READ(HSW_PWR_WELL_DRIVER), "Power well on.\n");
463 WARN_ONCE(intel_irqs_enabled(dev_priv),
464 "Interrupts not disabled yet.\n");
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530465
466 /*
467 * TODO: check for the following to verify the conditions to enter DC9
468 * state are satisfied:
469 * 1] Check relevant display engine registers to verify if mode set
470 * disable sequence was followed.
471 * 2] Check if display uninitialize sequence is initialized.
472 */
473}
474
475static void assert_can_disable_dc9(struct drm_i915_private *dev_priv)
476{
Imre Deakbfcdabe2016-04-01 16:02:37 +0300477 WARN_ONCE(intel_irqs_enabled(dev_priv),
478 "Interrupts not disabled yet.\n");
479 WARN_ONCE(I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC5,
480 "DC5 still not disabled.\n");
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530481
482 /*
483 * TODO: check for the following to verify DC9 state was indeed
484 * entered before programming to disable it:
485 * 1] Check relevant display engine registers to verify if mode
486 * set disable sequence was followed.
487 * 2] Check if display uninitialize sequence is initialized.
488 */
489}
490
Mika Kuoppala779cb5d2016-02-18 17:58:09 +0200491static void gen9_write_dc_state(struct drm_i915_private *dev_priv,
492 u32 state)
493{
494 int rewrites = 0;
495 int rereads = 0;
496 u32 v;
497
498 I915_WRITE(DC_STATE_EN, state);
499
500 /* It has been observed that disabling the dc6 state sometimes
501 * doesn't stick and dmc keeps returning old value. Make sure
502 * the write really sticks enough times and also force rewrite until
503 * we are confident that state is exactly what we want.
504 */
505 do {
506 v = I915_READ(DC_STATE_EN);
507
508 if (v != state) {
509 I915_WRITE(DC_STATE_EN, state);
510 rewrites++;
511 rereads = 0;
512 } else if (rereads++ > 5) {
513 break;
514 }
515
516 } while (rewrites < 100);
517
518 if (v != state)
519 DRM_ERROR("Writing dc state to 0x%x failed, now 0x%x\n",
520 state, v);
521
522 /* Most of the times we need one retry, avoid spam */
523 if (rewrites > 1)
524 DRM_DEBUG_KMS("Rewrote dc state to 0x%x %d times\n",
525 state, rewrites);
526}
527
Imre Deakda2f41d2016-04-20 20:27:56 +0300528static u32 gen9_dc_mask(struct drm_i915_private *dev_priv)
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530529{
Imre Deakda2f41d2016-04-20 20:27:56 +0300530 u32 mask;
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530531
Imre Deak13ae3a02015-11-04 19:24:16 +0200532 mask = DC_STATE_EN_UPTO_DC5;
533 if (IS_BROXTON(dev_priv))
534 mask |= DC_STATE_EN_DC9;
535 else
536 mask |= DC_STATE_EN_UPTO_DC6;
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530537
Imre Deakda2f41d2016-04-20 20:27:56 +0300538 return mask;
539}
540
541void gen9_sanitize_dc_state(struct drm_i915_private *dev_priv)
542{
543 u32 val;
544
545 val = I915_READ(DC_STATE_EN) & gen9_dc_mask(dev_priv);
546
547 DRM_DEBUG_KMS("Resetting DC state tracking from %02x to %02x\n",
548 dev_priv->csr.dc_state, val);
549 dev_priv->csr.dc_state = val;
550}
551
552static void gen9_set_dc_state(struct drm_i915_private *dev_priv, uint32_t state)
553{
554 uint32_t val;
555 uint32_t mask;
556
Imre Deaka37baf32016-02-29 22:49:03 +0200557 if (WARN_ON_ONCE(state & ~dev_priv->csr.allowed_dc_mask))
558 state &= dev_priv->csr.allowed_dc_mask;
Patrik Jakobsson443646c2015-11-16 15:01:06 +0100559
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530560 val = I915_READ(DC_STATE_EN);
Imre Deakda2f41d2016-04-20 20:27:56 +0300561 mask = gen9_dc_mask(dev_priv);
Imre Deak13ae3a02015-11-04 19:24:16 +0200562 DRM_DEBUG_KMS("Setting DC state from %02x to %02x\n",
563 val & mask, state);
Patrik Jakobsson832dba82016-02-18 17:21:11 +0200564
565 /* Check if DMC is ignoring our DC state requests */
566 if ((val & mask) != dev_priv->csr.dc_state)
567 DRM_ERROR("DC state mismatch (0x%x -> 0x%x)\n",
568 dev_priv->csr.dc_state, val & mask);
569
Imre Deak13ae3a02015-11-04 19:24:16 +0200570 val &= ~mask;
571 val |= state;
Mika Kuoppala779cb5d2016-02-18 17:58:09 +0200572
573 gen9_write_dc_state(dev_priv, val);
Patrik Jakobsson832dba82016-02-18 17:21:11 +0200574
575 dev_priv->csr.dc_state = val & mask;
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530576}
577
Imre Deak13ae3a02015-11-04 19:24:16 +0200578void bxt_enable_dc9(struct drm_i915_private *dev_priv)
579{
580 assert_can_enable_dc9(dev_priv);
581
582 DRM_DEBUG_KMS("Enabling DC9\n");
583
Imre Deak78597992016-06-16 16:37:20 +0300584 intel_power_sequencer_reset(dev_priv);
Imre Deak13ae3a02015-11-04 19:24:16 +0200585 gen9_set_dc_state(dev_priv, DC_STATE_EN_DC9);
586}
587
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530588void bxt_disable_dc9(struct drm_i915_private *dev_priv)
589{
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530590 assert_can_disable_dc9(dev_priv);
591
592 DRM_DEBUG_KMS("Disabling DC9\n");
593
Imre Deak13ae3a02015-11-04 19:24:16 +0200594 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
Imre Deak8090ba82016-08-10 14:07:33 +0300595
596 intel_pps_unlock_regs_wa(dev_priv);
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530597}
598
Daniel Vetteraf5fead2015-10-28 23:58:57 +0200599static void assert_csr_loaded(struct drm_i915_private *dev_priv)
600{
601 WARN_ONCE(!I915_READ(CSR_PROGRAM(0)),
602 "CSR program storage start is NULL\n");
603 WARN_ONCE(!I915_READ(CSR_SSP_BASE), "CSR SSP Base Not fine\n");
604 WARN_ONCE(!I915_READ(CSR_HTP_SKL), "CSR HTP Not fine\n");
605}
606
Suketu Shah5aefb232015-04-16 14:22:10 +0530607static void assert_can_enable_dc5(struct drm_i915_private *dev_priv)
Suketu Shahdc174302015-04-17 19:46:16 +0530608{
Suketu Shah5aefb232015-04-16 14:22:10 +0530609 bool pg2_enabled = intel_display_power_well_is_enabled(dev_priv,
610 SKL_DISP_PW_2);
611
Jesse Barnes6ff8ab02015-09-10 08:20:28 -0700612 WARN_ONCE(pg2_enabled, "PG2 not disabled to enable DC5.\n");
Suketu Shah5aefb232015-04-16 14:22:10 +0530613
Jesse Barnes6ff8ab02015-09-10 08:20:28 -0700614 WARN_ONCE((I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC5),
615 "DC5 already programmed to be enabled.\n");
Imre Deakc9b88462015-12-15 20:10:34 +0200616 assert_rpm_wakelock_held(dev_priv);
Suketu Shah5aefb232015-04-16 14:22:10 +0530617
618 assert_csr_loaded(dev_priv);
619}
620
Imre Deakf62c79b2016-04-20 20:27:57 +0300621void gen9_enable_dc5(struct drm_i915_private *dev_priv)
Suketu Shah5aefb232015-04-16 14:22:10 +0530622{
Suketu Shah5aefb232015-04-16 14:22:10 +0530623 assert_can_enable_dc5(dev_priv);
A.Sunil Kamath6b457d32015-04-16 14:22:09 +0530624
625 DRM_DEBUG_KMS("Enabling DC5\n");
626
Imre Deak13ae3a02015-11-04 19:24:16 +0200627 gen9_set_dc_state(dev_priv, DC_STATE_EN_UPTO_DC5);
Suketu Shahdc174302015-04-17 19:46:16 +0530628}
629
Suketu Shah93c7cb62015-04-16 14:22:13 +0530630static void assert_can_enable_dc6(struct drm_i915_private *dev_priv)
Suketu Shahf75a1982015-04-16 14:22:11 +0530631{
Jesse Barnes6ff8ab02015-09-10 08:20:28 -0700632 WARN_ONCE(I915_READ(UTIL_PIN_CTL) & UTIL_PIN_ENABLE,
633 "Backlight is not disabled.\n");
634 WARN_ONCE((I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC6),
635 "DC6 already programmed to be enabled.\n");
Suketu Shah93c7cb62015-04-16 14:22:13 +0530636
637 assert_csr_loaded(dev_priv);
638}
639
Animesh Manna0a9d2be2015-09-29 11:01:59 +0530640void skl_enable_dc6(struct drm_i915_private *dev_priv)
Suketu Shah93c7cb62015-04-16 14:22:13 +0530641{
Suketu Shah93c7cb62015-04-16 14:22:13 +0530642 assert_can_enable_dc6(dev_priv);
A.Sunil Kamath74b4f372015-04-16 14:22:12 +0530643
644 DRM_DEBUG_KMS("Enabling DC6\n");
645
Imre Deak13ae3a02015-11-04 19:24:16 +0200646 gen9_set_dc_state(dev_priv, DC_STATE_EN_UPTO_DC6);
647
Suketu Shahf75a1982015-04-16 14:22:11 +0530648}
649
Animesh Manna0a9d2be2015-09-29 11:01:59 +0530650void skl_disable_dc6(struct drm_i915_private *dev_priv)
Suketu Shahf75a1982015-04-16 14:22:11 +0530651{
A.Sunil Kamath74b4f372015-04-16 14:22:12 +0530652 DRM_DEBUG_KMS("Disabling DC6\n");
653
Imre Deak13ae3a02015-11-04 19:24:16 +0200654 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
Suketu Shahf75a1982015-04-16 14:22:11 +0530655}
656
Imre Deakc6782b72016-04-05 13:26:05 +0300657static void
658gen9_sanitize_power_well_requests(struct drm_i915_private *dev_priv,
659 struct i915_power_well *power_well)
660{
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +0300661 enum skl_disp_power_wells power_well_id = power_well->id;
Imre Deakc6782b72016-04-05 13:26:05 +0300662 u32 val;
663 u32 mask;
664
665 mask = SKL_POWER_WELL_REQ(power_well_id);
666
667 val = I915_READ(HSW_PWR_WELL_KVMR);
668 if (WARN_ONCE(val & mask, "Clearing unexpected KVMR request for %s\n",
669 power_well->name))
670 I915_WRITE(HSW_PWR_WELL_KVMR, val & ~mask);
671
672 val = I915_READ(HSW_PWR_WELL_BIOS);
673 val |= I915_READ(HSW_PWR_WELL_DEBUG);
674
675 if (!(val & mask))
676 return;
677
678 /*
679 * DMC is known to force on the request bits for power well 1 on SKL
680 * and BXT and the misc IO power well on SKL but we don't expect any
681 * other request bits to be set, so WARN for those.
682 */
683 if (power_well_id == SKL_DISP_PW_1 ||
Imre Deak80dbe992016-04-19 13:00:36 +0300684 ((IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv)) &&
685 power_well_id == SKL_DISP_PW_MISC_IO))
Imre Deakc6782b72016-04-05 13:26:05 +0300686 DRM_DEBUG_DRIVER("Clearing auxiliary requests for %s forced on "
687 "by DMC\n", power_well->name);
688 else
689 WARN_ONCE(1, "Clearing unexpected auxiliary requests for %s\n",
690 power_well->name);
691
692 I915_WRITE(HSW_PWR_WELL_BIOS, val & ~mask);
693 I915_WRITE(HSW_PWR_WELL_DEBUG, val & ~mask);
694}
695
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000696static void skl_set_power_well(struct drm_i915_private *dev_priv,
697 struct i915_power_well *power_well, bool enable)
698{
699 uint32_t tmp, fuse_status;
700 uint32_t req_mask, state_mask;
Damien Lespiau2a518352015-03-06 18:50:49 +0000701 bool is_enabled, enable_requested, check_fuse_status = false;
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000702
703 tmp = I915_READ(HSW_PWR_WELL_DRIVER);
704 fuse_status = I915_READ(SKL_FUSE_STATUS);
705
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +0300706 switch (power_well->id) {
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000707 case SKL_DISP_PW_1:
Chris Wilson117c1142016-06-30 15:33:33 +0100708 if (intel_wait_for_register(dev_priv,
709 SKL_FUSE_STATUS,
710 SKL_FUSE_PG0_DIST_STATUS,
711 SKL_FUSE_PG0_DIST_STATUS,
712 1)) {
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000713 DRM_ERROR("PG0 not enabled\n");
714 return;
715 }
716 break;
717 case SKL_DISP_PW_2:
718 if (!(fuse_status & SKL_FUSE_PG1_DIST_STATUS)) {
719 DRM_ERROR("PG1 in disabled state\n");
720 return;
721 }
722 break;
723 case SKL_DISP_PW_DDI_A_E:
724 case SKL_DISP_PW_DDI_B:
725 case SKL_DISP_PW_DDI_C:
726 case SKL_DISP_PW_DDI_D:
727 case SKL_DISP_PW_MISC_IO:
728 break;
729 default:
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +0300730 WARN(1, "Unknown power well %lu\n", power_well->id);
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000731 return;
732 }
733
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +0300734 req_mask = SKL_POWER_WELL_REQ(power_well->id);
Damien Lespiau2a518352015-03-06 18:50:49 +0000735 enable_requested = tmp & req_mask;
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +0300736 state_mask = SKL_POWER_WELL_STATE(power_well->id);
Damien Lespiau2a518352015-03-06 18:50:49 +0000737 is_enabled = tmp & state_mask;
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000738
Ville Syrjäläaae8ba82016-02-19 20:47:30 +0200739 if (!enable && enable_requested)
740 skl_power_well_pre_disable(dev_priv, power_well);
741
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000742 if (enable) {
Damien Lespiau2a518352015-03-06 18:50:49 +0000743 if (!enable_requested) {
Suketu Shahdc174302015-04-17 19:46:16 +0530744 WARN((tmp & state_mask) &&
745 !I915_READ(HSW_PWR_WELL_BIOS),
746 "Invalid for power well status to be enabled, unless done by the BIOS, \
747 when request is to disable!\n");
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000748 I915_WRITE(HSW_PWR_WELL_DRIVER, tmp | req_mask);
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000749 }
750
Damien Lespiau2a518352015-03-06 18:50:49 +0000751 if (!is_enabled) {
Damien Lespiau510e6fd2015-03-06 18:50:50 +0000752 DRM_DEBUG_KMS("Enabling %s\n", power_well->name);
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000753 check_fuse_status = true;
754 }
755 } else {
Damien Lespiau2a518352015-03-06 18:50:49 +0000756 if (enable_requested) {
Imre Deak4a76f292015-11-04 19:24:15 +0200757 I915_WRITE(HSW_PWR_WELL_DRIVER, tmp & ~req_mask);
758 POSTING_READ(HSW_PWR_WELL_DRIVER);
759 DRM_DEBUG_KMS("Disabling %s\n", power_well->name);
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000760 }
Imre Deakc6782b72016-04-05 13:26:05 +0300761
Imre Deak5f304c82016-04-15 22:32:58 +0300762 if (IS_GEN9(dev_priv))
Imre Deakc6782b72016-04-05 13:26:05 +0300763 gen9_sanitize_power_well_requests(dev_priv, power_well);
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000764 }
765
Imre Deak1d963af2016-04-01 16:02:36 +0300766 if (wait_for(!!(I915_READ(HSW_PWR_WELL_DRIVER) & state_mask) == enable,
767 1))
768 DRM_ERROR("%s %s timeout\n",
769 power_well->name, enable ? "enable" : "disable");
770
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000771 if (check_fuse_status) {
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +0300772 if (power_well->id == SKL_DISP_PW_1) {
Chris Wilson8b00f552016-06-30 15:33:34 +0100773 if (intel_wait_for_register(dev_priv,
774 SKL_FUSE_STATUS,
775 SKL_FUSE_PG1_DIST_STATUS,
776 SKL_FUSE_PG1_DIST_STATUS,
777 1))
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000778 DRM_ERROR("PG1 distributing status timeout\n");
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +0300779 } else if (power_well->id == SKL_DISP_PW_2) {
Chris Wilson8b00f552016-06-30 15:33:34 +0100780 if (intel_wait_for_register(dev_priv,
781 SKL_FUSE_STATUS,
782 SKL_FUSE_PG2_DIST_STATUS,
783 SKL_FUSE_PG2_DIST_STATUS,
784 1))
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000785 DRM_ERROR("PG2 distributing status timeout\n");
786 }
787 }
Damien Lespiaud14c0342015-03-06 18:50:51 +0000788
789 if (enable && !is_enabled)
790 skl_power_well_post_enable(dev_priv, power_well);
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000791}
792
Daniel Vetter9c065a72014-09-30 10:56:38 +0200793static void hsw_power_well_sync_hw(struct drm_i915_private *dev_priv,
794 struct i915_power_well *power_well)
795{
796 hsw_set_power_well(dev_priv, power_well, power_well->count > 0);
797
798 /*
799 * We're taking over the BIOS, so clear any requests made by it since
800 * the driver is in charge now.
801 */
802 if (I915_READ(HSW_PWR_WELL_BIOS) & HSW_PWR_WELL_ENABLE_REQUEST)
803 I915_WRITE(HSW_PWR_WELL_BIOS, 0);
804}
805
806static void hsw_power_well_enable(struct drm_i915_private *dev_priv,
807 struct i915_power_well *power_well)
808{
809 hsw_set_power_well(dev_priv, power_well, true);
810}
811
812static void hsw_power_well_disable(struct drm_i915_private *dev_priv,
813 struct i915_power_well *power_well)
814{
815 hsw_set_power_well(dev_priv, power_well, false);
816}
817
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000818static bool skl_power_well_enabled(struct drm_i915_private *dev_priv,
819 struct i915_power_well *power_well)
820{
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +0300821 uint32_t mask = SKL_POWER_WELL_REQ(power_well->id) |
822 SKL_POWER_WELL_STATE(power_well->id);
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000823
824 return (I915_READ(HSW_PWR_WELL_DRIVER) & mask) == mask;
825}
826
827static void skl_power_well_sync_hw(struct drm_i915_private *dev_priv,
828 struct i915_power_well *power_well)
829{
830 skl_set_power_well(dev_priv, power_well, power_well->count > 0);
831
832 /* Clear any request made by BIOS as driver is taking over */
833 I915_WRITE(HSW_PWR_WELL_BIOS, 0);
834}
835
836static void skl_power_well_enable(struct drm_i915_private *dev_priv,
837 struct i915_power_well *power_well)
838{
839 skl_set_power_well(dev_priv, power_well, true);
840}
841
842static void skl_power_well_disable(struct drm_i915_private *dev_priv,
843 struct i915_power_well *power_well)
844{
845 skl_set_power_well(dev_priv, power_well, false);
846}
847
Imre Deak9c8d0b82016-06-13 16:44:34 +0300848static void bxt_dpio_cmn_power_well_enable(struct drm_i915_private *dev_priv,
849 struct i915_power_well *power_well)
850{
Ander Conselvan de Oliveira362624c2016-10-06 19:22:15 +0300851 bxt_ddi_phy_init(dev_priv, power_well->data);
Imre Deak9c8d0b82016-06-13 16:44:34 +0300852}
853
854static void bxt_dpio_cmn_power_well_disable(struct drm_i915_private *dev_priv,
855 struct i915_power_well *power_well)
856{
Ander Conselvan de Oliveira362624c2016-10-06 19:22:15 +0300857 bxt_ddi_phy_uninit(dev_priv, power_well->data);
Imre Deak9c8d0b82016-06-13 16:44:34 +0300858}
859
860static bool bxt_dpio_cmn_power_well_enabled(struct drm_i915_private *dev_priv,
861 struct i915_power_well *power_well)
862{
Ander Conselvan de Oliveira362624c2016-10-06 19:22:15 +0300863 return bxt_ddi_phy_is_enabled(dev_priv, power_well->data);
Imre Deak9c8d0b82016-06-13 16:44:34 +0300864}
865
866static void bxt_dpio_cmn_power_well_sync_hw(struct drm_i915_private *dev_priv,
867 struct i915_power_well *power_well)
868{
869 if (power_well->count > 0)
870 bxt_dpio_cmn_power_well_enable(dev_priv, power_well);
871 else
872 bxt_dpio_cmn_power_well_disable(dev_priv, power_well);
873}
874
875
876static void bxt_verify_ddi_phy_power_wells(struct drm_i915_private *dev_priv)
877{
878 struct i915_power_well *power_well;
879
880 power_well = lookup_power_well(dev_priv, BXT_DPIO_CMN_A);
881 if (power_well->count > 0)
Ander Conselvan de Oliveira362624c2016-10-06 19:22:15 +0300882 bxt_ddi_phy_verify_state(dev_priv, power_well->data);
Imre Deak9c8d0b82016-06-13 16:44:34 +0300883
884 power_well = lookup_power_well(dev_priv, BXT_DPIO_CMN_BC);
885 if (power_well->count > 0)
Ander Conselvan de Oliveira362624c2016-10-06 19:22:15 +0300886 bxt_ddi_phy_verify_state(dev_priv, power_well->data);
Imre Deak9c8d0b82016-06-13 16:44:34 +0300887}
888
Patrik Jakobsson9f836f92015-11-16 16:20:01 +0100889static bool gen9_dc_off_power_well_enabled(struct drm_i915_private *dev_priv,
890 struct i915_power_well *power_well)
891{
892 return (I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC5_DC6_MASK) == 0;
893}
894
Ville Syrjälä18a80672016-05-16 16:59:40 +0300895static void gen9_assert_dbuf_enabled(struct drm_i915_private *dev_priv)
896{
897 u32 tmp = I915_READ(DBUF_CTL);
898
899 WARN((tmp & (DBUF_POWER_STATE | DBUF_POWER_REQUEST)) !=
900 (DBUF_POWER_STATE | DBUF_POWER_REQUEST),
901 "Unexpected DBuf power power state (0x%08x)\n", tmp);
902}
903
Patrik Jakobsson9f836f92015-11-16 16:20:01 +0100904static void gen9_dc_off_power_well_enable(struct drm_i915_private *dev_priv,
905 struct i915_power_well *power_well)
906{
Imre Deak5b773eb2016-02-29 22:49:05 +0200907 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
Imre Deakadc7f042016-04-04 17:27:10 +0300908
Ville Syrjälä342be922016-05-13 23:41:39 +0300909 WARN_ON(dev_priv->cdclk_freq !=
Chris Wilson91c8a322016-07-05 10:40:23 +0100910 dev_priv->display.get_display_clock_speed(&dev_priv->drm));
Ville Syrjälä342be922016-05-13 23:41:39 +0300911
Ville Syrjälä18a80672016-05-16 16:59:40 +0300912 gen9_assert_dbuf_enabled(dev_priv);
913
Ville Syrjälä342be922016-05-13 23:41:39 +0300914 if (IS_BROXTON(dev_priv))
Imre Deak9c8d0b82016-06-13 16:44:34 +0300915 bxt_verify_ddi_phy_power_wells(dev_priv);
Patrik Jakobsson9f836f92015-11-16 16:20:01 +0100916}
917
918static void gen9_dc_off_power_well_disable(struct drm_i915_private *dev_priv,
919 struct i915_power_well *power_well)
920{
Imre Deakf74ed082016-04-18 14:48:21 +0300921 if (!dev_priv->csr.dmc_payload)
922 return;
923
Imre Deaka37baf32016-02-29 22:49:03 +0200924 if (dev_priv->csr.allowed_dc_mask & DC_STATE_EN_UPTO_DC6)
Patrik Jakobsson9f836f92015-11-16 16:20:01 +0100925 skl_enable_dc6(dev_priv);
Imre Deaka37baf32016-02-29 22:49:03 +0200926 else if (dev_priv->csr.allowed_dc_mask & DC_STATE_EN_UPTO_DC5)
Patrik Jakobsson9f836f92015-11-16 16:20:01 +0100927 gen9_enable_dc5(dev_priv);
928}
929
930static void gen9_dc_off_power_well_sync_hw(struct drm_i915_private *dev_priv,
931 struct i915_power_well *power_well)
932{
Imre Deaka37baf32016-02-29 22:49:03 +0200933 if (power_well->count > 0)
934 gen9_dc_off_power_well_enable(dev_priv, power_well);
935 else
936 gen9_dc_off_power_well_disable(dev_priv, power_well);
Patrik Jakobsson9f836f92015-11-16 16:20:01 +0100937}
938
Daniel Vetter9c065a72014-09-30 10:56:38 +0200939static void i9xx_always_on_power_well_noop(struct drm_i915_private *dev_priv,
940 struct i915_power_well *power_well)
941{
942}
943
944static bool i9xx_always_on_power_well_enabled(struct drm_i915_private *dev_priv,
945 struct i915_power_well *power_well)
946{
947 return true;
948}
949
950static void vlv_set_power_well(struct drm_i915_private *dev_priv,
951 struct i915_power_well *power_well, bool enable)
952{
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +0300953 enum punit_power_well power_well_id = power_well->id;
Daniel Vetter9c065a72014-09-30 10:56:38 +0200954 u32 mask;
955 u32 state;
956 u32 ctrl;
957
958 mask = PUNIT_PWRGT_MASK(power_well_id);
959 state = enable ? PUNIT_PWRGT_PWR_ON(power_well_id) :
960 PUNIT_PWRGT_PWR_GATE(power_well_id);
961
962 mutex_lock(&dev_priv->rps.hw_lock);
963
964#define COND \
965 ((vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_STATUS) & mask) == state)
966
967 if (COND)
968 goto out;
969
970 ctrl = vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_CTRL);
971 ctrl &= ~mask;
972 ctrl |= state;
973 vlv_punit_write(dev_priv, PUNIT_REG_PWRGT_CTRL, ctrl);
974
975 if (wait_for(COND, 100))
Masanari Iida7e35ab82015-05-10 01:00:23 +0900976 DRM_ERROR("timeout setting power well state %08x (%08x)\n",
Daniel Vetter9c065a72014-09-30 10:56:38 +0200977 state,
978 vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_CTRL));
979
980#undef COND
981
982out:
983 mutex_unlock(&dev_priv->rps.hw_lock);
984}
985
986static void vlv_power_well_sync_hw(struct drm_i915_private *dev_priv,
987 struct i915_power_well *power_well)
988{
989 vlv_set_power_well(dev_priv, power_well, power_well->count > 0);
990}
991
992static void vlv_power_well_enable(struct drm_i915_private *dev_priv,
993 struct i915_power_well *power_well)
994{
995 vlv_set_power_well(dev_priv, power_well, true);
996}
997
998static void vlv_power_well_disable(struct drm_i915_private *dev_priv,
999 struct i915_power_well *power_well)
1000{
1001 vlv_set_power_well(dev_priv, power_well, false);
1002}
1003
1004static bool vlv_power_well_enabled(struct drm_i915_private *dev_priv,
1005 struct i915_power_well *power_well)
1006{
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001007 int power_well_id = power_well->id;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001008 bool enabled = false;
1009 u32 mask;
1010 u32 state;
1011 u32 ctrl;
1012
1013 mask = PUNIT_PWRGT_MASK(power_well_id);
1014 ctrl = PUNIT_PWRGT_PWR_ON(power_well_id);
1015
1016 mutex_lock(&dev_priv->rps.hw_lock);
1017
1018 state = vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_STATUS) & mask;
1019 /*
1020 * We only ever set the power-on and power-gate states, anything
1021 * else is unexpected.
1022 */
1023 WARN_ON(state != PUNIT_PWRGT_PWR_ON(power_well_id) &&
1024 state != PUNIT_PWRGT_PWR_GATE(power_well_id));
1025 if (state == ctrl)
1026 enabled = true;
1027
1028 /*
1029 * A transient state at this point would mean some unexpected party
1030 * is poking at the power controls too.
1031 */
1032 ctrl = vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_CTRL) & mask;
1033 WARN_ON(ctrl != state);
1034
1035 mutex_unlock(&dev_priv->rps.hw_lock);
1036
1037 return enabled;
1038}
1039
Ville Syrjälä766078d2016-04-11 16:56:30 +03001040static void vlv_init_display_clock_gating(struct drm_i915_private *dev_priv)
1041{
1042 I915_WRITE(DSPCLK_GATE_D, VRHUNIT_CLOCK_GATE_DISABLE);
1043
1044 /*
1045 * Disable trickle feed and enable pnd deadline calculation
1046 */
1047 I915_WRITE(MI_ARB_VLV, MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE);
1048 I915_WRITE(CBR1_VLV, 0);
Ville Syrjälä19ab4ed2016-04-27 17:43:22 +03001049
1050 WARN_ON(dev_priv->rawclk_freq == 0);
1051
1052 I915_WRITE(RAWCLK_FREQ_VLV,
1053 DIV_ROUND_CLOSEST(dev_priv->rawclk_freq, 1000));
Ville Syrjälä766078d2016-04-11 16:56:30 +03001054}
1055
Ville Syrjälä2be7d542015-06-29 15:25:51 +03001056static void vlv_display_power_well_init(struct drm_i915_private *dev_priv)
Daniel Vetter9c065a72014-09-30 10:56:38 +02001057{
Lyude9504a892016-06-21 17:03:42 -04001058 struct intel_encoder *encoder;
Ville Syrjälä5a8fbb72015-06-29 15:25:53 +03001059 enum pipe pipe;
1060
1061 /*
1062 * Enable the CRI clock source so we can get at the
1063 * display and the reference clock for VGA
1064 * hotplug / manual detection. Supposedly DSI also
1065 * needs the ref clock up and running.
1066 *
1067 * CHV DPLL B/C have some issues if VGA mode is enabled.
1068 */
Chris Wilson91c8a322016-07-05 10:40:23 +01001069 for_each_pipe(&dev_priv->drm, pipe) {
Ville Syrjälä5a8fbb72015-06-29 15:25:53 +03001070 u32 val = I915_READ(DPLL(pipe));
1071
1072 val |= DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
1073 if (pipe != PIPE_A)
1074 val |= DPLL_INTEGRATED_CRI_CLK_VLV;
1075
1076 I915_WRITE(DPLL(pipe), val);
1077 }
Daniel Vetter9c065a72014-09-30 10:56:38 +02001078
Ville Syrjälä766078d2016-04-11 16:56:30 +03001079 vlv_init_display_clock_gating(dev_priv);
1080
Daniel Vetter9c065a72014-09-30 10:56:38 +02001081 spin_lock_irq(&dev_priv->irq_lock);
1082 valleyview_enable_display_irqs(dev_priv);
1083 spin_unlock_irq(&dev_priv->irq_lock);
1084
1085 /*
1086 * During driver initialization/resume we can avoid restoring the
1087 * part of the HW/SW state that will be inited anyway explicitly.
1088 */
1089 if (dev_priv->power_domains.initializing)
1090 return;
1091
Daniel Vetterb9632912014-09-30 10:56:44 +02001092 intel_hpd_init(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001093
Lyude9504a892016-06-21 17:03:42 -04001094 /* Re-enable the ADPA, if we have one */
1095 for_each_intel_encoder(&dev_priv->drm, encoder) {
1096 if (encoder->type == INTEL_OUTPUT_ANALOG)
1097 intel_crt_reset(&encoder->base);
1098 }
1099
Chris Wilson91c8a322016-07-05 10:40:23 +01001100 i915_redisable_vga_power_on(&dev_priv->drm);
Imre Deak8090ba82016-08-10 14:07:33 +03001101
1102 intel_pps_unlock_regs_wa(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001103}
1104
Ville Syrjälä2be7d542015-06-29 15:25:51 +03001105static void vlv_display_power_well_deinit(struct drm_i915_private *dev_priv)
1106{
1107 spin_lock_irq(&dev_priv->irq_lock);
1108 valleyview_disable_display_irqs(dev_priv);
1109 spin_unlock_irq(&dev_priv->irq_lock);
1110
Ville Syrjälä2230fde2016-02-19 18:41:52 +02001111 /* make sure we're done processing display irqs */
Chris Wilson91c8a322016-07-05 10:40:23 +01001112 synchronize_irq(dev_priv->drm.irq);
Ville Syrjälä2230fde2016-02-19 18:41:52 +02001113
Imre Deak78597992016-06-16 16:37:20 +03001114 intel_power_sequencer_reset(dev_priv);
Lyude19625e82016-06-21 17:03:44 -04001115
1116 intel_hpd_poll_init(dev_priv);
Ville Syrjälä2be7d542015-06-29 15:25:51 +03001117}
1118
1119static void vlv_display_power_well_enable(struct drm_i915_private *dev_priv,
1120 struct i915_power_well *power_well)
1121{
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001122 WARN_ON_ONCE(power_well->id != PUNIT_POWER_WELL_DISP2D);
Ville Syrjälä2be7d542015-06-29 15:25:51 +03001123
1124 vlv_set_power_well(dev_priv, power_well, true);
1125
1126 vlv_display_power_well_init(dev_priv);
1127}
1128
Daniel Vetter9c065a72014-09-30 10:56:38 +02001129static void vlv_display_power_well_disable(struct drm_i915_private *dev_priv,
1130 struct i915_power_well *power_well)
1131{
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001132 WARN_ON_ONCE(power_well->id != PUNIT_POWER_WELL_DISP2D);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001133
Ville Syrjälä2be7d542015-06-29 15:25:51 +03001134 vlv_display_power_well_deinit(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001135
1136 vlv_set_power_well(dev_priv, power_well, false);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001137}
1138
1139static void vlv_dpio_cmn_power_well_enable(struct drm_i915_private *dev_priv,
1140 struct i915_power_well *power_well)
1141{
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001142 WARN_ON_ONCE(power_well->id != PUNIT_POWER_WELL_DPIO_CMN_BC);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001143
Ville Syrjälä5a8fbb72015-06-29 15:25:53 +03001144 /* since ref/cri clock was enabled */
Daniel Vetter9c065a72014-09-30 10:56:38 +02001145 udelay(1); /* >10ns for cmnreset, >0ns for sidereset */
1146
1147 vlv_set_power_well(dev_priv, power_well, true);
1148
1149 /*
1150 * From VLV2A0_DP_eDP_DPIO_driver_vbios_notes_10.docx -
1151 * 6. De-assert cmn_reset/side_reset. Same as VLV X0.
1152 * a. GUnit 0x2110 bit[0] set to 1 (def 0)
1153 * b. The other bits such as sfr settings / modesel may all
1154 * be set to 0.
1155 *
1156 * This should only be done on init and resume from S3 with
1157 * both PLLs disabled, or we risk losing DPIO and PLL
1158 * synchronization.
1159 */
1160 I915_WRITE(DPIO_CTL, I915_READ(DPIO_CTL) | DPIO_CMNRST);
1161}
1162
1163static void vlv_dpio_cmn_power_well_disable(struct drm_i915_private *dev_priv,
1164 struct i915_power_well *power_well)
1165{
1166 enum pipe pipe;
1167
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001168 WARN_ON_ONCE(power_well->id != PUNIT_POWER_WELL_DPIO_CMN_BC);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001169
1170 for_each_pipe(dev_priv, pipe)
1171 assert_pll_disabled(dev_priv, pipe);
1172
1173 /* Assert common reset */
1174 I915_WRITE(DPIO_CTL, I915_READ(DPIO_CTL) & ~DPIO_CMNRST);
1175
1176 vlv_set_power_well(dev_priv, power_well, false);
1177}
1178
Ville Syrjälä30142272015-07-08 23:46:01 +03001179#define POWER_DOMAIN_MASK (BIT(POWER_DOMAIN_NUM) - 1)
1180
1181static struct i915_power_well *lookup_power_well(struct drm_i915_private *dev_priv,
1182 int power_well_id)
1183{
1184 struct i915_power_domains *power_domains = &dev_priv->power_domains;
Ville Syrjälä30142272015-07-08 23:46:01 +03001185 int i;
1186
Imre Deakfc17f222015-11-04 19:24:11 +02001187 for (i = 0; i < power_domains->power_well_count; i++) {
1188 struct i915_power_well *power_well;
1189
1190 power_well = &power_domains->power_wells[i];
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001191 if (power_well->id == power_well_id)
Ville Syrjälä30142272015-07-08 23:46:01 +03001192 return power_well;
1193 }
1194
1195 return NULL;
1196}
1197
1198#define BITS_SET(val, bits) (((val) & (bits)) == (bits))
1199
1200static void assert_chv_phy_status(struct drm_i915_private *dev_priv)
1201{
1202 struct i915_power_well *cmn_bc =
1203 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_BC);
1204 struct i915_power_well *cmn_d =
1205 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_D);
1206 u32 phy_control = dev_priv->chv_phy_control;
1207 u32 phy_status = 0;
Ville Syrjälä3be60de2015-09-08 18:05:45 +03001208 u32 phy_status_mask = 0xffffffff;
Ville Syrjälä30142272015-07-08 23:46:01 +03001209
Ville Syrjälä3be60de2015-09-08 18:05:45 +03001210 /*
1211 * The BIOS can leave the PHY is some weird state
1212 * where it doesn't fully power down some parts.
1213 * Disable the asserts until the PHY has been fully
1214 * reset (ie. the power well has been disabled at
1215 * least once).
1216 */
1217 if (!dev_priv->chv_phy_assert[DPIO_PHY0])
1218 phy_status_mask &= ~(PHY_STATUS_CMN_LDO(DPIO_PHY0, DPIO_CH0) |
1219 PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH0, 0) |
1220 PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH0, 1) |
1221 PHY_STATUS_CMN_LDO(DPIO_PHY0, DPIO_CH1) |
1222 PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH1, 0) |
1223 PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH1, 1));
1224
1225 if (!dev_priv->chv_phy_assert[DPIO_PHY1])
1226 phy_status_mask &= ~(PHY_STATUS_CMN_LDO(DPIO_PHY1, DPIO_CH0) |
1227 PHY_STATUS_SPLINE_LDO(DPIO_PHY1, DPIO_CH0, 0) |
1228 PHY_STATUS_SPLINE_LDO(DPIO_PHY1, DPIO_CH0, 1));
1229
Ville Syrjälä30142272015-07-08 23:46:01 +03001230 if (cmn_bc->ops->is_enabled(dev_priv, cmn_bc)) {
1231 phy_status |= PHY_POWERGOOD(DPIO_PHY0);
1232
1233 /* this assumes override is only used to enable lanes */
1234 if ((phy_control & PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY0, DPIO_CH0)) == 0)
1235 phy_control |= PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH0);
1236
1237 if ((phy_control & PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY0, DPIO_CH1)) == 0)
1238 phy_control |= PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH1);
1239
1240 /* CL1 is on whenever anything is on in either channel */
1241 if (BITS_SET(phy_control,
1242 PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH0) |
1243 PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH1)))
1244 phy_status |= PHY_STATUS_CMN_LDO(DPIO_PHY0, DPIO_CH0);
1245
1246 /*
1247 * The DPLLB check accounts for the pipe B + port A usage
1248 * with CL2 powered up but all the lanes in the second channel
1249 * powered down.
1250 */
1251 if (BITS_SET(phy_control,
1252 PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH1)) &&
1253 (I915_READ(DPLL(PIPE_B)) & DPLL_VCO_ENABLE) == 0)
1254 phy_status |= PHY_STATUS_CMN_LDO(DPIO_PHY0, DPIO_CH1);
1255
1256 if (BITS_SET(phy_control,
1257 PHY_CH_POWER_DOWN_OVRD(0x3, DPIO_PHY0, DPIO_CH0)))
1258 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH0, 0);
1259 if (BITS_SET(phy_control,
1260 PHY_CH_POWER_DOWN_OVRD(0xc, DPIO_PHY0, DPIO_CH0)))
1261 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH0, 1);
1262
1263 if (BITS_SET(phy_control,
1264 PHY_CH_POWER_DOWN_OVRD(0x3, DPIO_PHY0, DPIO_CH1)))
1265 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH1, 0);
1266 if (BITS_SET(phy_control,
1267 PHY_CH_POWER_DOWN_OVRD(0xc, DPIO_PHY0, DPIO_CH1)))
1268 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH1, 1);
1269 }
1270
1271 if (cmn_d->ops->is_enabled(dev_priv, cmn_d)) {
1272 phy_status |= PHY_POWERGOOD(DPIO_PHY1);
1273
1274 /* this assumes override is only used to enable lanes */
1275 if ((phy_control & PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY1, DPIO_CH0)) == 0)
1276 phy_control |= PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY1, DPIO_CH0);
1277
1278 if (BITS_SET(phy_control,
1279 PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY1, DPIO_CH0)))
1280 phy_status |= PHY_STATUS_CMN_LDO(DPIO_PHY1, DPIO_CH0);
1281
1282 if (BITS_SET(phy_control,
1283 PHY_CH_POWER_DOWN_OVRD(0x3, DPIO_PHY1, DPIO_CH0)))
1284 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY1, DPIO_CH0, 0);
1285 if (BITS_SET(phy_control,
1286 PHY_CH_POWER_DOWN_OVRD(0xc, DPIO_PHY1, DPIO_CH0)))
1287 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY1, DPIO_CH0, 1);
1288 }
1289
Ville Syrjälä3be60de2015-09-08 18:05:45 +03001290 phy_status &= phy_status_mask;
1291
Ville Syrjälä30142272015-07-08 23:46:01 +03001292 /*
1293 * The PHY may be busy with some initial calibration and whatnot,
1294 * so the power state can take a while to actually change.
1295 */
Chris Wilson919fcd52016-06-30 15:33:35 +01001296 if (intel_wait_for_register(dev_priv,
1297 DISPLAY_PHY_STATUS,
1298 phy_status_mask,
1299 phy_status,
1300 10))
1301 DRM_ERROR("Unexpected PHY_STATUS 0x%08x, expected 0x%08x (PHY_CONTROL=0x%08x)\n",
1302 I915_READ(DISPLAY_PHY_STATUS) & phy_status_mask,
1303 phy_status, dev_priv->chv_phy_control);
Ville Syrjälä30142272015-07-08 23:46:01 +03001304}
1305
1306#undef BITS_SET
1307
Daniel Vetter9c065a72014-09-30 10:56:38 +02001308static void chv_dpio_cmn_power_well_enable(struct drm_i915_private *dev_priv,
1309 struct i915_power_well *power_well)
1310{
1311 enum dpio_phy phy;
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001312 enum pipe pipe;
1313 uint32_t tmp;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001314
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001315 WARN_ON_ONCE(power_well->id != PUNIT_POWER_WELL_DPIO_CMN_BC &&
1316 power_well->id != PUNIT_POWER_WELL_DPIO_CMN_D);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001317
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001318 if (power_well->id == PUNIT_POWER_WELL_DPIO_CMN_BC) {
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001319 pipe = PIPE_A;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001320 phy = DPIO_PHY0;
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001321 } else {
1322 pipe = PIPE_C;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001323 phy = DPIO_PHY1;
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001324 }
Ville Syrjälä5a8fbb72015-06-29 15:25:53 +03001325
1326 /* since ref/cri clock was enabled */
Daniel Vetter9c065a72014-09-30 10:56:38 +02001327 udelay(1); /* >10ns for cmnreset, >0ns for sidereset */
1328 vlv_set_power_well(dev_priv, power_well, true);
1329
1330 /* Poll for phypwrgood signal */
Chris Wilsonffebb832016-06-30 15:33:36 +01001331 if (intel_wait_for_register(dev_priv,
1332 DISPLAY_PHY_STATUS,
1333 PHY_POWERGOOD(phy),
1334 PHY_POWERGOOD(phy),
1335 1))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001336 DRM_ERROR("Display PHY %d is not power up\n", phy);
1337
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001338 mutex_lock(&dev_priv->sb_lock);
1339
1340 /* Enable dynamic power down */
1341 tmp = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW28);
Ville Syrjäläee279212015-07-08 23:45:57 +03001342 tmp |= DPIO_DYNPWRDOWNEN_CH0 | DPIO_CL1POWERDOWNEN |
1343 DPIO_SUS_CLK_CONFIG_GATE_CLKREQ;
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001344 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW28, tmp);
1345
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001346 if (power_well->id == PUNIT_POWER_WELL_DPIO_CMN_BC) {
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001347 tmp = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW6_CH1);
1348 tmp |= DPIO_DYNPWRDOWNEN_CH1;
1349 vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW6_CH1, tmp);
Ville Syrjälä3e288782015-07-08 23:45:58 +03001350 } else {
1351 /*
1352 * Force the non-existing CL2 off. BXT does this
1353 * too, so maybe it saves some power even though
1354 * CL2 doesn't exist?
1355 */
1356 tmp = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW30);
1357 tmp |= DPIO_CL2_LDOFUSE_PWRENB;
1358 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW30, tmp);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001359 }
1360
1361 mutex_unlock(&dev_priv->sb_lock);
1362
Ville Syrjälä70722462015-04-10 18:21:28 +03001363 dev_priv->chv_phy_control |= PHY_COM_LANE_RESET_DEASSERT(phy);
1364 I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001365
1366 DRM_DEBUG_KMS("Enabled DPIO PHY%d (PHY_CONTROL=0x%08x)\n",
1367 phy, dev_priv->chv_phy_control);
Ville Syrjälä30142272015-07-08 23:46:01 +03001368
1369 assert_chv_phy_status(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001370}
1371
1372static void chv_dpio_cmn_power_well_disable(struct drm_i915_private *dev_priv,
1373 struct i915_power_well *power_well)
1374{
1375 enum dpio_phy phy;
1376
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001377 WARN_ON_ONCE(power_well->id != PUNIT_POWER_WELL_DPIO_CMN_BC &&
1378 power_well->id != PUNIT_POWER_WELL_DPIO_CMN_D);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001379
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001380 if (power_well->id == PUNIT_POWER_WELL_DPIO_CMN_BC) {
Daniel Vetter9c065a72014-09-30 10:56:38 +02001381 phy = DPIO_PHY0;
1382 assert_pll_disabled(dev_priv, PIPE_A);
1383 assert_pll_disabled(dev_priv, PIPE_B);
1384 } else {
1385 phy = DPIO_PHY1;
1386 assert_pll_disabled(dev_priv, PIPE_C);
1387 }
1388
Ville Syrjälä70722462015-04-10 18:21:28 +03001389 dev_priv->chv_phy_control &= ~PHY_COM_LANE_RESET_DEASSERT(phy);
1390 I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001391
1392 vlv_set_power_well(dev_priv, power_well, false);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001393
1394 DRM_DEBUG_KMS("Disabled DPIO PHY%d (PHY_CONTROL=0x%08x)\n",
1395 phy, dev_priv->chv_phy_control);
Ville Syrjälä30142272015-07-08 23:46:01 +03001396
Ville Syrjälä3be60de2015-09-08 18:05:45 +03001397 /* PHY is fully reset now, so we can enable the PHY state asserts */
1398 dev_priv->chv_phy_assert[phy] = true;
1399
Ville Syrjälä30142272015-07-08 23:46:01 +03001400 assert_chv_phy_status(dev_priv);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001401}
1402
Ville Syrjälä6669e392015-07-08 23:46:00 +03001403static void assert_chv_phy_powergate(struct drm_i915_private *dev_priv, enum dpio_phy phy,
1404 enum dpio_channel ch, bool override, unsigned int mask)
1405{
1406 enum pipe pipe = phy == DPIO_PHY0 ? PIPE_A : PIPE_C;
1407 u32 reg, val, expected, actual;
1408
Ville Syrjälä3be60de2015-09-08 18:05:45 +03001409 /*
1410 * The BIOS can leave the PHY is some weird state
1411 * where it doesn't fully power down some parts.
1412 * Disable the asserts until the PHY has been fully
1413 * reset (ie. the power well has been disabled at
1414 * least once).
1415 */
1416 if (!dev_priv->chv_phy_assert[phy])
1417 return;
1418
Ville Syrjälä6669e392015-07-08 23:46:00 +03001419 if (ch == DPIO_CH0)
1420 reg = _CHV_CMN_DW0_CH0;
1421 else
1422 reg = _CHV_CMN_DW6_CH1;
1423
1424 mutex_lock(&dev_priv->sb_lock);
1425 val = vlv_dpio_read(dev_priv, pipe, reg);
1426 mutex_unlock(&dev_priv->sb_lock);
1427
1428 /*
1429 * This assumes !override is only used when the port is disabled.
1430 * All lanes should power down even without the override when
1431 * the port is disabled.
1432 */
1433 if (!override || mask == 0xf) {
1434 expected = DPIO_ALLDL_POWERDOWN | DPIO_ANYDL_POWERDOWN;
1435 /*
1436 * If CH1 common lane is not active anymore
1437 * (eg. for pipe B DPLL) the entire channel will
1438 * shut down, which causes the common lane registers
1439 * to read as 0. That means we can't actually check
1440 * the lane power down status bits, but as the entire
1441 * register reads as 0 it's a good indication that the
1442 * channel is indeed entirely powered down.
1443 */
1444 if (ch == DPIO_CH1 && val == 0)
1445 expected = 0;
1446 } else if (mask != 0x0) {
1447 expected = DPIO_ANYDL_POWERDOWN;
1448 } else {
1449 expected = 0;
1450 }
1451
1452 if (ch == DPIO_CH0)
1453 actual = val >> DPIO_ANYDL_POWERDOWN_SHIFT_CH0;
1454 else
1455 actual = val >> DPIO_ANYDL_POWERDOWN_SHIFT_CH1;
1456 actual &= DPIO_ALLDL_POWERDOWN | DPIO_ANYDL_POWERDOWN;
1457
1458 WARN(actual != expected,
1459 "Unexpected DPIO lane power down: all %d, any %d. Expected: all %d, any %d. (0x%x = 0x%08x)\n",
1460 !!(actual & DPIO_ALLDL_POWERDOWN), !!(actual & DPIO_ANYDL_POWERDOWN),
1461 !!(expected & DPIO_ALLDL_POWERDOWN), !!(expected & DPIO_ANYDL_POWERDOWN),
1462 reg, val);
1463}
1464
Ville Syrjäläb0b33842015-07-08 23:45:55 +03001465bool chv_phy_powergate_ch(struct drm_i915_private *dev_priv, enum dpio_phy phy,
1466 enum dpio_channel ch, bool override)
1467{
1468 struct i915_power_domains *power_domains = &dev_priv->power_domains;
1469 bool was_override;
1470
1471 mutex_lock(&power_domains->lock);
1472
1473 was_override = dev_priv->chv_phy_control & PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
1474
1475 if (override == was_override)
1476 goto out;
1477
1478 if (override)
1479 dev_priv->chv_phy_control |= PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
1480 else
1481 dev_priv->chv_phy_control &= ~PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
1482
1483 I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
1484
1485 DRM_DEBUG_KMS("Power gating DPIO PHY%d CH%d (DPIO_PHY_CONTROL=0x%08x)\n",
1486 phy, ch, dev_priv->chv_phy_control);
1487
Ville Syrjälä30142272015-07-08 23:46:01 +03001488 assert_chv_phy_status(dev_priv);
1489
Ville Syrjäläb0b33842015-07-08 23:45:55 +03001490out:
1491 mutex_unlock(&power_domains->lock);
1492
1493 return was_override;
1494}
1495
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001496void chv_phy_powergate_lanes(struct intel_encoder *encoder,
1497 bool override, unsigned int mask)
1498{
1499 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
1500 struct i915_power_domains *power_domains = &dev_priv->power_domains;
1501 enum dpio_phy phy = vlv_dport_to_phy(enc_to_dig_port(&encoder->base));
1502 enum dpio_channel ch = vlv_dport_to_channel(enc_to_dig_port(&encoder->base));
1503
1504 mutex_lock(&power_domains->lock);
1505
1506 dev_priv->chv_phy_control &= ~PHY_CH_POWER_DOWN_OVRD(0xf, phy, ch);
1507 dev_priv->chv_phy_control |= PHY_CH_POWER_DOWN_OVRD(mask, phy, ch);
1508
1509 if (override)
1510 dev_priv->chv_phy_control |= PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
1511 else
1512 dev_priv->chv_phy_control &= ~PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
1513
1514 I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
1515
1516 DRM_DEBUG_KMS("Power gating DPIO PHY%d CH%d lanes 0x%x (PHY_CONTROL=0x%08x)\n",
1517 phy, ch, mask, dev_priv->chv_phy_control);
1518
Ville Syrjälä30142272015-07-08 23:46:01 +03001519 assert_chv_phy_status(dev_priv);
1520
Ville Syrjälä6669e392015-07-08 23:46:00 +03001521 assert_chv_phy_powergate(dev_priv, phy, ch, override, mask);
1522
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001523 mutex_unlock(&power_domains->lock);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001524}
1525
1526static bool chv_pipe_power_well_enabled(struct drm_i915_private *dev_priv,
1527 struct i915_power_well *power_well)
1528{
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001529 enum pipe pipe = power_well->id;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001530 bool enabled;
1531 u32 state, ctrl;
1532
1533 mutex_lock(&dev_priv->rps.hw_lock);
1534
1535 state = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & DP_SSS_MASK(pipe);
1536 /*
1537 * We only ever set the power-on and power-gate states, anything
1538 * else is unexpected.
1539 */
1540 WARN_ON(state != DP_SSS_PWR_ON(pipe) && state != DP_SSS_PWR_GATE(pipe));
1541 enabled = state == DP_SSS_PWR_ON(pipe);
1542
1543 /*
1544 * A transient state at this point would mean some unexpected party
1545 * is poking at the power controls too.
1546 */
1547 ctrl = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & DP_SSC_MASK(pipe);
1548 WARN_ON(ctrl << 16 != state);
1549
1550 mutex_unlock(&dev_priv->rps.hw_lock);
1551
1552 return enabled;
1553}
1554
1555static void chv_set_pipe_power_well(struct drm_i915_private *dev_priv,
1556 struct i915_power_well *power_well,
1557 bool enable)
1558{
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001559 enum pipe pipe = power_well->id;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001560 u32 state;
1561 u32 ctrl;
1562
1563 state = enable ? DP_SSS_PWR_ON(pipe) : DP_SSS_PWR_GATE(pipe);
1564
1565 mutex_lock(&dev_priv->rps.hw_lock);
1566
1567#define COND \
1568 ((vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & DP_SSS_MASK(pipe)) == state)
1569
1570 if (COND)
1571 goto out;
1572
1573 ctrl = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ);
1574 ctrl &= ~DP_SSC_MASK(pipe);
1575 ctrl |= enable ? DP_SSC_PWR_ON(pipe) : DP_SSC_PWR_GATE(pipe);
1576 vlv_punit_write(dev_priv, PUNIT_REG_DSPFREQ, ctrl);
1577
1578 if (wait_for(COND, 100))
Masanari Iida7e35ab82015-05-10 01:00:23 +09001579 DRM_ERROR("timeout setting power well state %08x (%08x)\n",
Daniel Vetter9c065a72014-09-30 10:56:38 +02001580 state,
1581 vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ));
1582
1583#undef COND
1584
1585out:
1586 mutex_unlock(&dev_priv->rps.hw_lock);
1587}
1588
1589static void chv_pipe_power_well_sync_hw(struct drm_i915_private *dev_priv,
1590 struct i915_power_well *power_well)
1591{
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001592 WARN_ON_ONCE(power_well->id != PIPE_A);
Ville Syrjälä8fcd5cd2015-06-29 15:25:50 +03001593
Daniel Vetter9c065a72014-09-30 10:56:38 +02001594 chv_set_pipe_power_well(dev_priv, power_well, power_well->count > 0);
1595}
1596
1597static void chv_pipe_power_well_enable(struct drm_i915_private *dev_priv,
1598 struct i915_power_well *power_well)
1599{
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001600 WARN_ON_ONCE(power_well->id != PIPE_A);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001601
1602 chv_set_pipe_power_well(dev_priv, power_well, true);
Ville Syrjäläafd62752014-10-30 19:43:03 +02001603
Ville Syrjälä2be7d542015-06-29 15:25:51 +03001604 vlv_display_power_well_init(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001605}
1606
1607static void chv_pipe_power_well_disable(struct drm_i915_private *dev_priv,
1608 struct i915_power_well *power_well)
1609{
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001610 WARN_ON_ONCE(power_well->id != PIPE_A);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001611
Ville Syrjälä2be7d542015-06-29 15:25:51 +03001612 vlv_display_power_well_deinit(dev_priv);
Ville Syrjäläafd62752014-10-30 19:43:03 +02001613
Daniel Vetter9c065a72014-09-30 10:56:38 +02001614 chv_set_pipe_power_well(dev_priv, power_well, false);
1615}
1616
Imre Deak09731282016-02-17 14:17:42 +02001617static void
1618__intel_display_power_get_domain(struct drm_i915_private *dev_priv,
1619 enum intel_display_power_domain domain)
1620{
1621 struct i915_power_domains *power_domains = &dev_priv->power_domains;
1622 struct i915_power_well *power_well;
1623 int i;
1624
Imre Deakb409ca92016-06-13 16:44:33 +03001625 for_each_power_well(i, power_well, BIT(domain), power_domains)
1626 intel_power_well_get(dev_priv, power_well);
Imre Deak09731282016-02-17 14:17:42 +02001627
1628 power_domains->domain_use_count[domain]++;
1629}
1630
Daniel Vettere4e76842014-09-30 10:56:42 +02001631/**
1632 * intel_display_power_get - grab a power domain reference
1633 * @dev_priv: i915 device instance
1634 * @domain: power domain to reference
1635 *
1636 * This function grabs a power domain reference for @domain and ensures that the
1637 * power domain and all its parents are powered up. Therefore users should only
1638 * grab a reference to the innermost power domain they need.
1639 *
1640 * Any power domain reference obtained by this function must have a symmetric
1641 * call to intel_display_power_put() to release the reference again.
1642 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02001643void intel_display_power_get(struct drm_i915_private *dev_priv,
1644 enum intel_display_power_domain domain)
1645{
Imre Deak09731282016-02-17 14:17:42 +02001646 struct i915_power_domains *power_domains = &dev_priv->power_domains;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001647
1648 intel_runtime_pm_get(dev_priv);
1649
Imre Deak09731282016-02-17 14:17:42 +02001650 mutex_lock(&power_domains->lock);
1651
1652 __intel_display_power_get_domain(dev_priv, domain);
1653
1654 mutex_unlock(&power_domains->lock);
1655}
1656
1657/**
1658 * intel_display_power_get_if_enabled - grab a reference for an enabled display power domain
1659 * @dev_priv: i915 device instance
1660 * @domain: power domain to reference
1661 *
1662 * This function grabs a power domain reference for @domain and ensures that the
1663 * power domain and all its parents are powered up. Therefore users should only
1664 * grab a reference to the innermost power domain they need.
1665 *
1666 * Any power domain reference obtained by this function must have a symmetric
1667 * call to intel_display_power_put() to release the reference again.
1668 */
1669bool intel_display_power_get_if_enabled(struct drm_i915_private *dev_priv,
1670 enum intel_display_power_domain domain)
1671{
1672 struct i915_power_domains *power_domains = &dev_priv->power_domains;
1673 bool is_enabled;
1674
1675 if (!intel_runtime_pm_get_if_in_use(dev_priv))
1676 return false;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001677
1678 mutex_lock(&power_domains->lock);
1679
Imre Deak09731282016-02-17 14:17:42 +02001680 if (__intel_display_power_is_enabled(dev_priv, domain)) {
1681 __intel_display_power_get_domain(dev_priv, domain);
1682 is_enabled = true;
1683 } else {
1684 is_enabled = false;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001685 }
1686
Daniel Vetter9c065a72014-09-30 10:56:38 +02001687 mutex_unlock(&power_domains->lock);
Imre Deak09731282016-02-17 14:17:42 +02001688
1689 if (!is_enabled)
1690 intel_runtime_pm_put(dev_priv);
1691
1692 return is_enabled;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001693}
1694
Daniel Vettere4e76842014-09-30 10:56:42 +02001695/**
1696 * intel_display_power_put - release a power domain reference
1697 * @dev_priv: i915 device instance
1698 * @domain: power domain to reference
1699 *
1700 * This function drops the power domain reference obtained by
1701 * intel_display_power_get() and might power down the corresponding hardware
1702 * block right away if this is the last reference.
1703 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02001704void intel_display_power_put(struct drm_i915_private *dev_priv,
1705 enum intel_display_power_domain domain)
1706{
1707 struct i915_power_domains *power_domains;
1708 struct i915_power_well *power_well;
1709 int i;
1710
1711 power_domains = &dev_priv->power_domains;
1712
1713 mutex_lock(&power_domains->lock);
1714
Daniel Stone11c86db2015-11-20 15:55:34 +00001715 WARN(!power_domains->domain_use_count[domain],
1716 "Use count on domain %s is already zero\n",
1717 intel_display_power_domain_str(domain));
Daniel Vetter9c065a72014-09-30 10:56:38 +02001718 power_domains->domain_use_count[domain]--;
1719
Imre Deakb409ca92016-06-13 16:44:33 +03001720 for_each_power_well_rev(i, power_well, BIT(domain), power_domains)
1721 intel_power_well_put(dev_priv, power_well);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001722
1723 mutex_unlock(&power_domains->lock);
1724
1725 intel_runtime_pm_put(dev_priv);
1726}
1727
Ville Syrjälä9d0996b2016-04-18 14:02:28 +03001728#define HSW_DISPLAY_POWER_DOMAINS ( \
1729 BIT(POWER_DOMAIN_PIPE_B) | \
1730 BIT(POWER_DOMAIN_PIPE_C) | \
1731 BIT(POWER_DOMAIN_PIPE_A_PANEL_FITTER) | \
1732 BIT(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1733 BIT(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
1734 BIT(POWER_DOMAIN_TRANSCODER_A) | \
1735 BIT(POWER_DOMAIN_TRANSCODER_B) | \
1736 BIT(POWER_DOMAIN_TRANSCODER_C) | \
Patrik Jakobsson6331a702015-11-09 16:48:21 +01001737 BIT(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1738 BIT(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1739 BIT(POWER_DOMAIN_PORT_DDI_D_LANES) | \
Ville Syrjälä9d0996b2016-04-18 14:02:28 +03001740 BIT(POWER_DOMAIN_PORT_CRT) | /* DDI E */ \
1741 BIT(POWER_DOMAIN_VGA) | \
1742 BIT(POWER_DOMAIN_AUDIO) | \
Daniel Vetter9c065a72014-09-30 10:56:38 +02001743 BIT(POWER_DOMAIN_INIT))
1744
Ville Syrjälä9d0996b2016-04-18 14:02:28 +03001745#define BDW_DISPLAY_POWER_DOMAINS ( \
1746 BIT(POWER_DOMAIN_PIPE_B) | \
1747 BIT(POWER_DOMAIN_PIPE_C) | \
1748 BIT(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1749 BIT(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
1750 BIT(POWER_DOMAIN_TRANSCODER_A) | \
1751 BIT(POWER_DOMAIN_TRANSCODER_B) | \
1752 BIT(POWER_DOMAIN_TRANSCODER_C) | \
1753 BIT(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1754 BIT(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1755 BIT(POWER_DOMAIN_PORT_DDI_D_LANES) | \
1756 BIT(POWER_DOMAIN_PORT_CRT) | /* DDI E */ \
1757 BIT(POWER_DOMAIN_VGA) | \
1758 BIT(POWER_DOMAIN_AUDIO) | \
Daniel Vetter9c065a72014-09-30 10:56:38 +02001759 BIT(POWER_DOMAIN_INIT))
1760
Ville Syrjälä465ac0c2016-04-18 14:02:27 +03001761#define VLV_DISPLAY_POWER_DOMAINS ( \
1762 BIT(POWER_DOMAIN_PIPE_A) | \
1763 BIT(POWER_DOMAIN_PIPE_B) | \
1764 BIT(POWER_DOMAIN_PIPE_A_PANEL_FITTER) | \
1765 BIT(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1766 BIT(POWER_DOMAIN_TRANSCODER_A) | \
1767 BIT(POWER_DOMAIN_TRANSCODER_B) | \
1768 BIT(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1769 BIT(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1770 BIT(POWER_DOMAIN_PORT_DSI) | \
1771 BIT(POWER_DOMAIN_PORT_CRT) | \
1772 BIT(POWER_DOMAIN_VGA) | \
1773 BIT(POWER_DOMAIN_AUDIO) | \
1774 BIT(POWER_DOMAIN_AUX_B) | \
1775 BIT(POWER_DOMAIN_AUX_C) | \
1776 BIT(POWER_DOMAIN_GMBUS) | \
1777 BIT(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001778
1779#define VLV_DPIO_CMN_BC_POWER_DOMAINS ( \
Patrik Jakobsson6331a702015-11-09 16:48:21 +01001780 BIT(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1781 BIT(POWER_DOMAIN_PORT_DDI_C_LANES) | \
Daniel Vetter9c065a72014-09-30 10:56:38 +02001782 BIT(POWER_DOMAIN_PORT_CRT) | \
Satheeshakrishna M14071212015-01-16 15:57:51 +00001783 BIT(POWER_DOMAIN_AUX_B) | \
1784 BIT(POWER_DOMAIN_AUX_C) | \
Daniel Vetter9c065a72014-09-30 10:56:38 +02001785 BIT(POWER_DOMAIN_INIT))
1786
1787#define VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS ( \
Patrik Jakobsson6331a702015-11-09 16:48:21 +01001788 BIT(POWER_DOMAIN_PORT_DDI_B_LANES) | \
Satheeshakrishna M14071212015-01-16 15:57:51 +00001789 BIT(POWER_DOMAIN_AUX_B) | \
Daniel Vetter9c065a72014-09-30 10:56:38 +02001790 BIT(POWER_DOMAIN_INIT))
1791
1792#define VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS ( \
Patrik Jakobsson6331a702015-11-09 16:48:21 +01001793 BIT(POWER_DOMAIN_PORT_DDI_B_LANES) | \
Satheeshakrishna M14071212015-01-16 15:57:51 +00001794 BIT(POWER_DOMAIN_AUX_B) | \
Daniel Vetter9c065a72014-09-30 10:56:38 +02001795 BIT(POWER_DOMAIN_INIT))
1796
1797#define VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS ( \
Patrik Jakobsson6331a702015-11-09 16:48:21 +01001798 BIT(POWER_DOMAIN_PORT_DDI_C_LANES) | \
Satheeshakrishna M14071212015-01-16 15:57:51 +00001799 BIT(POWER_DOMAIN_AUX_C) | \
Daniel Vetter9c065a72014-09-30 10:56:38 +02001800 BIT(POWER_DOMAIN_INIT))
1801
1802#define VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS ( \
Patrik Jakobsson6331a702015-11-09 16:48:21 +01001803 BIT(POWER_DOMAIN_PORT_DDI_C_LANES) | \
Satheeshakrishna M14071212015-01-16 15:57:51 +00001804 BIT(POWER_DOMAIN_AUX_C) | \
Daniel Vetter9c065a72014-09-30 10:56:38 +02001805 BIT(POWER_DOMAIN_INIT))
1806
Ville Syrjälä465ac0c2016-04-18 14:02:27 +03001807#define CHV_DISPLAY_POWER_DOMAINS ( \
1808 BIT(POWER_DOMAIN_PIPE_A) | \
1809 BIT(POWER_DOMAIN_PIPE_B) | \
1810 BIT(POWER_DOMAIN_PIPE_C) | \
1811 BIT(POWER_DOMAIN_PIPE_A_PANEL_FITTER) | \
1812 BIT(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1813 BIT(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
1814 BIT(POWER_DOMAIN_TRANSCODER_A) | \
1815 BIT(POWER_DOMAIN_TRANSCODER_B) | \
1816 BIT(POWER_DOMAIN_TRANSCODER_C) | \
1817 BIT(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1818 BIT(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1819 BIT(POWER_DOMAIN_PORT_DDI_D_LANES) | \
1820 BIT(POWER_DOMAIN_PORT_DSI) | \
1821 BIT(POWER_DOMAIN_VGA) | \
1822 BIT(POWER_DOMAIN_AUDIO) | \
1823 BIT(POWER_DOMAIN_AUX_B) | \
1824 BIT(POWER_DOMAIN_AUX_C) | \
1825 BIT(POWER_DOMAIN_AUX_D) | \
1826 BIT(POWER_DOMAIN_GMBUS) | \
1827 BIT(POWER_DOMAIN_INIT))
1828
Daniel Vetter9c065a72014-09-30 10:56:38 +02001829#define CHV_DPIO_CMN_BC_POWER_DOMAINS ( \
Patrik Jakobsson6331a702015-11-09 16:48:21 +01001830 BIT(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1831 BIT(POWER_DOMAIN_PORT_DDI_C_LANES) | \
Satheeshakrishna M14071212015-01-16 15:57:51 +00001832 BIT(POWER_DOMAIN_AUX_B) | \
1833 BIT(POWER_DOMAIN_AUX_C) | \
Daniel Vetter9c065a72014-09-30 10:56:38 +02001834 BIT(POWER_DOMAIN_INIT))
1835
1836#define CHV_DPIO_CMN_D_POWER_DOMAINS ( \
Patrik Jakobsson6331a702015-11-09 16:48:21 +01001837 BIT(POWER_DOMAIN_PORT_DDI_D_LANES) | \
Satheeshakrishna M14071212015-01-16 15:57:51 +00001838 BIT(POWER_DOMAIN_AUX_D) | \
Daniel Vetter9c065a72014-09-30 10:56:38 +02001839 BIT(POWER_DOMAIN_INIT))
1840
Daniel Vetter9c065a72014-09-30 10:56:38 +02001841static const struct i915_power_well_ops i9xx_always_on_power_well_ops = {
1842 .sync_hw = i9xx_always_on_power_well_noop,
1843 .enable = i9xx_always_on_power_well_noop,
1844 .disable = i9xx_always_on_power_well_noop,
1845 .is_enabled = i9xx_always_on_power_well_enabled,
1846};
1847
1848static const struct i915_power_well_ops chv_pipe_power_well_ops = {
1849 .sync_hw = chv_pipe_power_well_sync_hw,
1850 .enable = chv_pipe_power_well_enable,
1851 .disable = chv_pipe_power_well_disable,
1852 .is_enabled = chv_pipe_power_well_enabled,
1853};
1854
1855static const struct i915_power_well_ops chv_dpio_cmn_power_well_ops = {
1856 .sync_hw = vlv_power_well_sync_hw,
1857 .enable = chv_dpio_cmn_power_well_enable,
1858 .disable = chv_dpio_cmn_power_well_disable,
1859 .is_enabled = vlv_power_well_enabled,
1860};
1861
1862static struct i915_power_well i9xx_always_on_power_well[] = {
1863 {
1864 .name = "always-on",
1865 .always_on = 1,
1866 .domains = POWER_DOMAIN_MASK,
1867 .ops = &i9xx_always_on_power_well_ops,
1868 },
1869};
1870
1871static const struct i915_power_well_ops hsw_power_well_ops = {
1872 .sync_hw = hsw_power_well_sync_hw,
1873 .enable = hsw_power_well_enable,
1874 .disable = hsw_power_well_disable,
1875 .is_enabled = hsw_power_well_enabled,
1876};
1877
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00001878static const struct i915_power_well_ops skl_power_well_ops = {
1879 .sync_hw = skl_power_well_sync_hw,
1880 .enable = skl_power_well_enable,
1881 .disable = skl_power_well_disable,
1882 .is_enabled = skl_power_well_enabled,
1883};
1884
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01001885static const struct i915_power_well_ops gen9_dc_off_power_well_ops = {
1886 .sync_hw = gen9_dc_off_power_well_sync_hw,
1887 .enable = gen9_dc_off_power_well_enable,
1888 .disable = gen9_dc_off_power_well_disable,
1889 .is_enabled = gen9_dc_off_power_well_enabled,
1890};
1891
Imre Deak9c8d0b82016-06-13 16:44:34 +03001892static const struct i915_power_well_ops bxt_dpio_cmn_power_well_ops = {
1893 .sync_hw = bxt_dpio_cmn_power_well_sync_hw,
1894 .enable = bxt_dpio_cmn_power_well_enable,
1895 .disable = bxt_dpio_cmn_power_well_disable,
1896 .is_enabled = bxt_dpio_cmn_power_well_enabled,
1897};
1898
Daniel Vetter9c065a72014-09-30 10:56:38 +02001899static struct i915_power_well hsw_power_wells[] = {
1900 {
1901 .name = "always-on",
1902 .always_on = 1,
Ville Syrjälä998bd662016-04-18 14:02:26 +03001903 .domains = POWER_DOMAIN_MASK,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001904 .ops = &i9xx_always_on_power_well_ops,
1905 },
1906 {
1907 .name = "display",
1908 .domains = HSW_DISPLAY_POWER_DOMAINS,
1909 .ops = &hsw_power_well_ops,
1910 },
1911};
1912
1913static struct i915_power_well bdw_power_wells[] = {
1914 {
1915 .name = "always-on",
1916 .always_on = 1,
Ville Syrjälä998bd662016-04-18 14:02:26 +03001917 .domains = POWER_DOMAIN_MASK,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001918 .ops = &i9xx_always_on_power_well_ops,
1919 },
1920 {
1921 .name = "display",
1922 .domains = BDW_DISPLAY_POWER_DOMAINS,
1923 .ops = &hsw_power_well_ops,
1924 },
1925};
1926
1927static const struct i915_power_well_ops vlv_display_power_well_ops = {
1928 .sync_hw = vlv_power_well_sync_hw,
1929 .enable = vlv_display_power_well_enable,
1930 .disable = vlv_display_power_well_disable,
1931 .is_enabled = vlv_power_well_enabled,
1932};
1933
1934static const struct i915_power_well_ops vlv_dpio_cmn_power_well_ops = {
1935 .sync_hw = vlv_power_well_sync_hw,
1936 .enable = vlv_dpio_cmn_power_well_enable,
1937 .disable = vlv_dpio_cmn_power_well_disable,
1938 .is_enabled = vlv_power_well_enabled,
1939};
1940
1941static const struct i915_power_well_ops vlv_dpio_power_well_ops = {
1942 .sync_hw = vlv_power_well_sync_hw,
1943 .enable = vlv_power_well_enable,
1944 .disable = vlv_power_well_disable,
1945 .is_enabled = vlv_power_well_enabled,
1946};
1947
1948static struct i915_power_well vlv_power_wells[] = {
1949 {
1950 .name = "always-on",
1951 .always_on = 1,
Ville Syrjälä998bd662016-04-18 14:02:26 +03001952 .domains = POWER_DOMAIN_MASK,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001953 .ops = &i9xx_always_on_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001954 .id = PUNIT_POWER_WELL_ALWAYS_ON,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001955 },
1956 {
1957 .name = "display",
1958 .domains = VLV_DISPLAY_POWER_DOMAINS,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001959 .id = PUNIT_POWER_WELL_DISP2D,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001960 .ops = &vlv_display_power_well_ops,
1961 },
1962 {
1963 .name = "dpio-tx-b-01",
1964 .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
1965 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
1966 VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
1967 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
1968 .ops = &vlv_dpio_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001969 .id = PUNIT_POWER_WELL_DPIO_TX_B_LANES_01,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001970 },
1971 {
1972 .name = "dpio-tx-b-23",
1973 .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
1974 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
1975 VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
1976 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
1977 .ops = &vlv_dpio_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001978 .id = PUNIT_POWER_WELL_DPIO_TX_B_LANES_23,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001979 },
1980 {
1981 .name = "dpio-tx-c-01",
1982 .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
1983 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
1984 VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
1985 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
1986 .ops = &vlv_dpio_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001987 .id = PUNIT_POWER_WELL_DPIO_TX_C_LANES_01,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001988 },
1989 {
1990 .name = "dpio-tx-c-23",
1991 .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
1992 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
1993 VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
1994 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
1995 .ops = &vlv_dpio_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001996 .id = PUNIT_POWER_WELL_DPIO_TX_C_LANES_23,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001997 },
1998 {
1999 .name = "dpio-common",
2000 .domains = VLV_DPIO_CMN_BC_POWER_DOMAINS,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002001 .id = PUNIT_POWER_WELL_DPIO_CMN_BC,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002002 .ops = &vlv_dpio_cmn_power_well_ops,
2003 },
2004};
2005
2006static struct i915_power_well chv_power_wells[] = {
2007 {
2008 .name = "always-on",
2009 .always_on = 1,
Ville Syrjälä998bd662016-04-18 14:02:26 +03002010 .domains = POWER_DOMAIN_MASK,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002011 .ops = &i9xx_always_on_power_well_ops,
2012 },
Daniel Vetter9c065a72014-09-30 10:56:38 +02002013 {
2014 .name = "display",
Ville Syrjäläbaa4e572014-10-27 16:07:32 +02002015 /*
Ville Syrjäläfde61e42015-05-26 20:22:39 +03002016 * Pipe A power well is the new disp2d well. Pipe B and C
2017 * power wells don't actually exist. Pipe A power well is
2018 * required for any pipe to work.
Ville Syrjäläbaa4e572014-10-27 16:07:32 +02002019 */
Ville Syrjälä465ac0c2016-04-18 14:02:27 +03002020 .domains = CHV_DISPLAY_POWER_DOMAINS,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002021 .id = PIPE_A,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002022 .ops = &chv_pipe_power_well_ops,
2023 },
Daniel Vetter9c065a72014-09-30 10:56:38 +02002024 {
2025 .name = "dpio-common-bc",
Ville Syrjälä71849b62015-04-10 18:21:29 +03002026 .domains = CHV_DPIO_CMN_BC_POWER_DOMAINS,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002027 .id = PUNIT_POWER_WELL_DPIO_CMN_BC,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002028 .ops = &chv_dpio_cmn_power_well_ops,
2029 },
2030 {
2031 .name = "dpio-common-d",
Ville Syrjälä71849b62015-04-10 18:21:29 +03002032 .domains = CHV_DPIO_CMN_D_POWER_DOMAINS,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002033 .id = PUNIT_POWER_WELL_DPIO_CMN_D,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002034 .ops = &chv_dpio_cmn_power_well_ops,
2035 },
Daniel Vetter9c065a72014-09-30 10:56:38 +02002036};
2037
Suketu Shah5aefb232015-04-16 14:22:10 +05302038bool intel_display_power_well_is_enabled(struct drm_i915_private *dev_priv,
2039 int power_well_id)
2040{
2041 struct i915_power_well *power_well;
2042 bool ret;
2043
2044 power_well = lookup_power_well(dev_priv, power_well_id);
2045 ret = power_well->ops->is_enabled(dev_priv, power_well);
2046
2047 return ret;
2048}
2049
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002050static struct i915_power_well skl_power_wells[] = {
2051 {
2052 .name = "always-on",
2053 .always_on = 1,
Ville Syrjälä998bd662016-04-18 14:02:26 +03002054 .domains = POWER_DOMAIN_MASK,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002055 .ops = &i9xx_always_on_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002056 .id = SKL_DISP_PW_ALWAYS_ON,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002057 },
2058 {
2059 .name = "power well 1",
Imre Deak4a76f292015-11-04 19:24:15 +02002060 /* Handled by the DMC firmware */
2061 .domains = 0,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002062 .ops = &skl_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002063 .id = SKL_DISP_PW_1,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002064 },
2065 {
2066 .name = "MISC IO power well",
Imre Deak4a76f292015-11-04 19:24:15 +02002067 /* Handled by the DMC firmware */
2068 .domains = 0,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002069 .ops = &skl_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002070 .id = SKL_DISP_PW_MISC_IO,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002071 },
2072 {
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01002073 .name = "DC off",
2074 .domains = SKL_DISPLAY_DC_OFF_POWER_DOMAINS,
2075 .ops = &gen9_dc_off_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002076 .id = SKL_DISP_PW_DC_OFF,
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01002077 },
2078 {
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002079 .name = "power well 2",
2080 .domains = SKL_DISPLAY_POWERWELL_2_POWER_DOMAINS,
2081 .ops = &skl_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002082 .id = SKL_DISP_PW_2,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002083 },
2084 {
2085 .name = "DDI A/E power well",
2086 .domains = SKL_DISPLAY_DDI_A_E_POWER_DOMAINS,
2087 .ops = &skl_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002088 .id = SKL_DISP_PW_DDI_A_E,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002089 },
2090 {
2091 .name = "DDI B power well",
2092 .domains = SKL_DISPLAY_DDI_B_POWER_DOMAINS,
2093 .ops = &skl_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002094 .id = SKL_DISP_PW_DDI_B,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002095 },
2096 {
2097 .name = "DDI C power well",
2098 .domains = SKL_DISPLAY_DDI_C_POWER_DOMAINS,
2099 .ops = &skl_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002100 .id = SKL_DISP_PW_DDI_C,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002101 },
2102 {
2103 .name = "DDI D power well",
2104 .domains = SKL_DISPLAY_DDI_D_POWER_DOMAINS,
2105 .ops = &skl_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002106 .id = SKL_DISP_PW_DDI_D,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002107 },
2108};
2109
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302110static struct i915_power_well bxt_power_wells[] = {
2111 {
2112 .name = "always-on",
2113 .always_on = 1,
Ville Syrjälä998bd662016-04-18 14:02:26 +03002114 .domains = POWER_DOMAIN_MASK,
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302115 .ops = &i9xx_always_on_power_well_ops,
2116 },
2117 {
2118 .name = "power well 1",
Imre Deakd7d7c9e2016-04-01 16:02:42 +03002119 .domains = 0,
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302120 .ops = &skl_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002121 .id = SKL_DISP_PW_1,
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302122 },
2123 {
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01002124 .name = "DC off",
2125 .domains = BXT_DISPLAY_DC_OFF_POWER_DOMAINS,
2126 .ops = &gen9_dc_off_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002127 .id = SKL_DISP_PW_DC_OFF,
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01002128 },
2129 {
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302130 .name = "power well 2",
2131 .domains = BXT_DISPLAY_POWERWELL_2_POWER_DOMAINS,
2132 .ops = &skl_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002133 .id = SKL_DISP_PW_2,
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01002134 },
Imre Deak9c8d0b82016-06-13 16:44:34 +03002135 {
2136 .name = "dpio-common-a",
2137 .domains = BXT_DPIO_CMN_A_POWER_DOMAINS,
2138 .ops = &bxt_dpio_cmn_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002139 .id = BXT_DPIO_CMN_A,
Ander Conselvan de Oliveira362624c2016-10-06 19:22:15 +03002140 .data = DPIO_PHY1,
Imre Deak9c8d0b82016-06-13 16:44:34 +03002141 },
2142 {
2143 .name = "dpio-common-bc",
2144 .domains = BXT_DPIO_CMN_BC_POWER_DOMAINS,
2145 .ops = &bxt_dpio_cmn_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002146 .id = BXT_DPIO_CMN_BC,
Ander Conselvan de Oliveira362624c2016-10-06 19:22:15 +03002147 .data = DPIO_PHY0,
Imre Deak9c8d0b82016-06-13 16:44:34 +03002148 },
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302149};
2150
Imre Deak1b0e3a02015-11-05 23:04:11 +02002151static int
2152sanitize_disable_power_well_option(const struct drm_i915_private *dev_priv,
2153 int disable_power_well)
2154{
2155 if (disable_power_well >= 0)
2156 return !!disable_power_well;
2157
Imre Deak1b0e3a02015-11-05 23:04:11 +02002158 return 1;
2159}
2160
Imre Deaka37baf32016-02-29 22:49:03 +02002161static uint32_t get_allowed_dc_mask(const struct drm_i915_private *dev_priv,
2162 int enable_dc)
2163{
2164 uint32_t mask;
2165 int requested_dc;
2166 int max_dc;
2167
2168 if (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv)) {
2169 max_dc = 2;
2170 mask = 0;
2171 } else if (IS_BROXTON(dev_priv)) {
2172 max_dc = 1;
2173 /*
2174 * DC9 has a separate HW flow from the rest of the DC states,
2175 * not depending on the DMC firmware. It's needed by system
2176 * suspend/resume, so allow it unconditionally.
2177 */
2178 mask = DC_STATE_EN_DC9;
2179 } else {
2180 max_dc = 0;
2181 mask = 0;
2182 }
2183
Imre Deak66e2c4c2016-02-29 22:49:04 +02002184 if (!i915.disable_power_well)
2185 max_dc = 0;
2186
Imre Deaka37baf32016-02-29 22:49:03 +02002187 if (enable_dc >= 0 && enable_dc <= max_dc) {
2188 requested_dc = enable_dc;
2189 } else if (enable_dc == -1) {
2190 requested_dc = max_dc;
2191 } else if (enable_dc > max_dc && enable_dc <= 2) {
2192 DRM_DEBUG_KMS("Adjusting requested max DC state (%d->%d)\n",
2193 enable_dc, max_dc);
2194 requested_dc = max_dc;
2195 } else {
2196 DRM_ERROR("Unexpected value for enable_dc (%d)\n", enable_dc);
2197 requested_dc = max_dc;
2198 }
2199
2200 if (requested_dc > 1)
2201 mask |= DC_STATE_EN_UPTO_DC6;
2202 if (requested_dc > 0)
2203 mask |= DC_STATE_EN_UPTO_DC5;
2204
2205 DRM_DEBUG_KMS("Allowed DC state mask %02x\n", mask);
2206
2207 return mask;
2208}
2209
Daniel Vetter9c065a72014-09-30 10:56:38 +02002210#define set_power_wells(power_domains, __power_wells) ({ \
2211 (power_domains)->power_wells = (__power_wells); \
2212 (power_domains)->power_well_count = ARRAY_SIZE(__power_wells); \
2213})
2214
Daniel Vettere4e76842014-09-30 10:56:42 +02002215/**
2216 * intel_power_domains_init - initializes the power domain structures
2217 * @dev_priv: i915 device instance
2218 *
2219 * Initializes the power domain structures for @dev_priv depending upon the
2220 * supported platform.
2221 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02002222int intel_power_domains_init(struct drm_i915_private *dev_priv)
2223{
2224 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2225
Imre Deak1b0e3a02015-11-05 23:04:11 +02002226 i915.disable_power_well = sanitize_disable_power_well_option(dev_priv,
2227 i915.disable_power_well);
Imre Deaka37baf32016-02-29 22:49:03 +02002228 dev_priv->csr.allowed_dc_mask = get_allowed_dc_mask(dev_priv,
2229 i915.enable_dc);
Imre Deak1b0e3a02015-11-05 23:04:11 +02002230
Ville Syrjäläf0ab43e2015-11-09 16:48:19 +01002231 BUILD_BUG_ON(POWER_DOMAIN_NUM > 31);
2232
Daniel Vetter9c065a72014-09-30 10:56:38 +02002233 mutex_init(&power_domains->lock);
2234
2235 /*
2236 * The enabling order will be from lower to higher indexed wells,
2237 * the disabling order is reversed.
2238 */
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002239 if (IS_HASWELL(dev_priv)) {
Daniel Vetter9c065a72014-09-30 10:56:38 +02002240 set_power_wells(power_domains, hsw_power_wells);
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002241 } else if (IS_BROADWELL(dev_priv)) {
Daniel Vetter9c065a72014-09-30 10:56:38 +02002242 set_power_wells(power_domains, bdw_power_wells);
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002243 } else if (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv)) {
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002244 set_power_wells(power_domains, skl_power_wells);
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002245 } else if (IS_BROXTON(dev_priv)) {
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302246 set_power_wells(power_domains, bxt_power_wells);
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002247 } else if (IS_CHERRYVIEW(dev_priv)) {
Daniel Vetter9c065a72014-09-30 10:56:38 +02002248 set_power_wells(power_domains, chv_power_wells);
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002249 } else if (IS_VALLEYVIEW(dev_priv)) {
Daniel Vetter9c065a72014-09-30 10:56:38 +02002250 set_power_wells(power_domains, vlv_power_wells);
2251 } else {
2252 set_power_wells(power_domains, i9xx_always_on_power_well);
2253 }
2254
2255 return 0;
2256}
2257
Daniel Vettere4e76842014-09-30 10:56:42 +02002258/**
2259 * intel_power_domains_fini - finalizes the power domain structures
2260 * @dev_priv: i915 device instance
2261 *
2262 * Finalizes the power domain structures for @dev_priv depending upon the
2263 * supported platform. This function also disables runtime pm and ensures that
2264 * the device stays powered up so that the driver can be reloaded.
2265 */
Daniel Vetterf458ebb2014-09-30 10:56:39 +02002266void intel_power_domains_fini(struct drm_i915_private *dev_priv)
Daniel Vetter9c065a72014-09-30 10:56:38 +02002267{
David Weinehallc49d13e2016-08-22 13:32:42 +03002268 struct device *kdev = &dev_priv->drm.pdev->dev;
Imre Deak25b181b2015-12-17 13:44:56 +02002269
Imre Deakaabee1b2015-12-15 20:10:29 +02002270 /*
2271 * The i915.ko module is still not prepared to be loaded when
Daniel Vetterf458ebb2014-09-30 10:56:39 +02002272 * the power well is not enabled, so just enable it in case
Imre Deakaabee1b2015-12-15 20:10:29 +02002273 * we're going to unload/reload.
2274 * The following also reacquires the RPM reference the core passed
2275 * to the driver during loading, which is dropped in
2276 * intel_runtime_pm_enable(). We have to hand back the control of the
2277 * device to the core with this reference held.
2278 */
Daniel Vetterf458ebb2014-09-30 10:56:39 +02002279 intel_display_set_init_power(dev_priv, true);
Imre Deakd314cd42015-11-17 17:44:23 +02002280
2281 /* Remove the refcount we took to keep power well support disabled. */
2282 if (!i915.disable_power_well)
2283 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
Imre Deak25b181b2015-12-17 13:44:56 +02002284
2285 /*
2286 * Remove the refcount we took in intel_runtime_pm_enable() in case
2287 * the platform doesn't support runtime PM.
2288 */
2289 if (!HAS_RUNTIME_PM(dev_priv))
David Weinehallc49d13e2016-08-22 13:32:42 +03002290 pm_runtime_put(kdev);
Daniel Vetter9c065a72014-09-30 10:56:38 +02002291}
2292
Imre Deak30eade12015-11-04 19:24:13 +02002293static void intel_power_domains_sync_hw(struct drm_i915_private *dev_priv)
Daniel Vetter9c065a72014-09-30 10:56:38 +02002294{
2295 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2296 struct i915_power_well *power_well;
2297 int i;
2298
2299 mutex_lock(&power_domains->lock);
2300 for_each_power_well(i, power_well, POWER_DOMAIN_MASK, power_domains) {
2301 power_well->ops->sync_hw(dev_priv, power_well);
2302 power_well->hw_enabled = power_well->ops->is_enabled(dev_priv,
2303 power_well);
2304 }
2305 mutex_unlock(&power_domains->lock);
2306}
2307
Ville Syrjälä70c2c182016-05-13 23:41:30 +03002308static void gen9_dbuf_enable(struct drm_i915_private *dev_priv)
2309{
2310 I915_WRITE(DBUF_CTL, I915_READ(DBUF_CTL) | DBUF_POWER_REQUEST);
2311 POSTING_READ(DBUF_CTL);
2312
2313 udelay(10);
2314
2315 if (!(I915_READ(DBUF_CTL) & DBUF_POWER_STATE))
2316 DRM_ERROR("DBuf power enable timeout\n");
2317}
2318
2319static void gen9_dbuf_disable(struct drm_i915_private *dev_priv)
2320{
2321 I915_WRITE(DBUF_CTL, I915_READ(DBUF_CTL) & ~DBUF_POWER_REQUEST);
2322 POSTING_READ(DBUF_CTL);
2323
2324 udelay(10);
2325
2326 if (I915_READ(DBUF_CTL) & DBUF_POWER_STATE)
2327 DRM_ERROR("DBuf power disable timeout!\n");
2328}
2329
Imre Deak73dfc222015-11-17 17:33:53 +02002330static void skl_display_core_init(struct drm_i915_private *dev_priv,
Imre Deak443a93a2016-04-04 15:42:57 +03002331 bool resume)
Imre Deak73dfc222015-11-17 17:33:53 +02002332{
2333 struct i915_power_domains *power_domains = &dev_priv->power_domains;
Imre Deak443a93a2016-04-04 15:42:57 +03002334 struct i915_power_well *well;
Imre Deak73dfc222015-11-17 17:33:53 +02002335 uint32_t val;
2336
Imre Deakd26fa1d2015-11-04 19:24:17 +02002337 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
2338
Imre Deak73dfc222015-11-17 17:33:53 +02002339 /* enable PCH reset handshake */
2340 val = I915_READ(HSW_NDE_RSTWRN_OPT);
2341 I915_WRITE(HSW_NDE_RSTWRN_OPT, val | RESET_PCH_HANDSHAKE_ENABLE);
2342
2343 /* enable PG1 and Misc I/O */
2344 mutex_lock(&power_domains->lock);
Imre Deak443a93a2016-04-04 15:42:57 +03002345
2346 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
2347 intel_power_well_enable(dev_priv, well);
2348
2349 well = lookup_power_well(dev_priv, SKL_DISP_PW_MISC_IO);
2350 intel_power_well_enable(dev_priv, well);
2351
Imre Deak73dfc222015-11-17 17:33:53 +02002352 mutex_unlock(&power_domains->lock);
2353
Imre Deak73dfc222015-11-17 17:33:53 +02002354 skl_init_cdclk(dev_priv);
2355
Ville Syrjälä70c2c182016-05-13 23:41:30 +03002356 gen9_dbuf_enable(dev_priv);
2357
Ville Syrjälä9f7eb312016-05-13 23:41:29 +03002358 if (resume && dev_priv->csr.dmc_payload)
Imre Deak2abc5252016-03-04 21:57:41 +02002359 intel_csr_load_program(dev_priv);
Imre Deak73dfc222015-11-17 17:33:53 +02002360}
2361
2362static void skl_display_core_uninit(struct drm_i915_private *dev_priv)
2363{
2364 struct i915_power_domains *power_domains = &dev_priv->power_domains;
Imre Deak443a93a2016-04-04 15:42:57 +03002365 struct i915_power_well *well;
Imre Deak73dfc222015-11-17 17:33:53 +02002366
Imre Deakd26fa1d2015-11-04 19:24:17 +02002367 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
2368
Ville Syrjälä70c2c182016-05-13 23:41:30 +03002369 gen9_dbuf_disable(dev_priv);
2370
Imre Deak73dfc222015-11-17 17:33:53 +02002371 skl_uninit_cdclk(dev_priv);
2372
2373 /* The spec doesn't call for removing the reset handshake flag */
2374 /* disable PG1 and Misc I/O */
Imre Deak443a93a2016-04-04 15:42:57 +03002375
Imre Deak73dfc222015-11-17 17:33:53 +02002376 mutex_lock(&power_domains->lock);
Imre Deak443a93a2016-04-04 15:42:57 +03002377
2378 well = lookup_power_well(dev_priv, SKL_DISP_PW_MISC_IO);
2379 intel_power_well_disable(dev_priv, well);
2380
2381 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
2382 intel_power_well_disable(dev_priv, well);
2383
Imre Deak73dfc222015-11-17 17:33:53 +02002384 mutex_unlock(&power_domains->lock);
2385}
2386
Imre Deakd7d7c9e2016-04-01 16:02:42 +03002387void bxt_display_core_init(struct drm_i915_private *dev_priv,
2388 bool resume)
2389{
2390 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2391 struct i915_power_well *well;
2392 uint32_t val;
2393
2394 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
2395
2396 /*
2397 * NDE_RSTWRN_OPT RST PCH Handshake En must always be 0b on BXT
2398 * or else the reset will hang because there is no PCH to respond.
2399 * Move the handshake programming to initialization sequence.
2400 * Previously was left up to BIOS.
2401 */
2402 val = I915_READ(HSW_NDE_RSTWRN_OPT);
2403 val &= ~RESET_PCH_HANDSHAKE_ENABLE;
2404 I915_WRITE(HSW_NDE_RSTWRN_OPT, val);
2405
2406 /* Enable PG1 */
2407 mutex_lock(&power_domains->lock);
2408
2409 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
2410 intel_power_well_enable(dev_priv, well);
2411
2412 mutex_unlock(&power_domains->lock);
2413
Imre Deak324513c2016-06-13 16:44:36 +03002414 bxt_init_cdclk(dev_priv);
Ville Syrjälä70c2c182016-05-13 23:41:30 +03002415
2416 gen9_dbuf_enable(dev_priv);
2417
Imre Deakd7d7c9e2016-04-01 16:02:42 +03002418 if (resume && dev_priv->csr.dmc_payload)
2419 intel_csr_load_program(dev_priv);
2420}
2421
2422void bxt_display_core_uninit(struct drm_i915_private *dev_priv)
2423{
2424 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2425 struct i915_power_well *well;
2426
2427 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
2428
Ville Syrjälä70c2c182016-05-13 23:41:30 +03002429 gen9_dbuf_disable(dev_priv);
2430
Imre Deak324513c2016-06-13 16:44:36 +03002431 bxt_uninit_cdclk(dev_priv);
Imre Deakd7d7c9e2016-04-01 16:02:42 +03002432
2433 /* The spec doesn't call for removing the reset handshake flag */
2434
2435 /* Disable PG1 */
2436 mutex_lock(&power_domains->lock);
2437
2438 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
2439 intel_power_well_disable(dev_priv, well);
2440
2441 mutex_unlock(&power_domains->lock);
2442}
2443
Ville Syrjälä70722462015-04-10 18:21:28 +03002444static void chv_phy_control_init(struct drm_i915_private *dev_priv)
2445{
2446 struct i915_power_well *cmn_bc =
2447 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_BC);
2448 struct i915_power_well *cmn_d =
2449 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_D);
2450
2451 /*
2452 * DISPLAY_PHY_CONTROL can get corrupted if read. As a
2453 * workaround never ever read DISPLAY_PHY_CONTROL, and
2454 * instead maintain a shadow copy ourselves. Use the actual
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002455 * power well state and lane status to reconstruct the
2456 * expected initial value.
Ville Syrjälä70722462015-04-10 18:21:28 +03002457 */
2458 dev_priv->chv_phy_control =
Ville Syrjäläbc284542015-05-26 20:22:38 +03002459 PHY_LDO_SEQ_DELAY(PHY_LDO_DELAY_600NS, DPIO_PHY0) |
2460 PHY_LDO_SEQ_DELAY(PHY_LDO_DELAY_600NS, DPIO_PHY1) |
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002461 PHY_CH_POWER_MODE(PHY_CH_DEEP_PSR, DPIO_PHY0, DPIO_CH0) |
2462 PHY_CH_POWER_MODE(PHY_CH_DEEP_PSR, DPIO_PHY0, DPIO_CH1) |
2463 PHY_CH_POWER_MODE(PHY_CH_DEEP_PSR, DPIO_PHY1, DPIO_CH0);
2464
2465 /*
2466 * If all lanes are disabled we leave the override disabled
2467 * with all power down bits cleared to match the state we
2468 * would use after disabling the port. Otherwise enable the
2469 * override and set the lane powerdown bits accding to the
2470 * current lane status.
2471 */
2472 if (cmn_bc->ops->is_enabled(dev_priv, cmn_bc)) {
2473 uint32_t status = I915_READ(DPLL(PIPE_A));
2474 unsigned int mask;
2475
2476 mask = status & DPLL_PORTB_READY_MASK;
2477 if (mask == 0xf)
2478 mask = 0x0;
2479 else
2480 dev_priv->chv_phy_control |=
2481 PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY0, DPIO_CH0);
2482
2483 dev_priv->chv_phy_control |=
2484 PHY_CH_POWER_DOWN_OVRD(mask, DPIO_PHY0, DPIO_CH0);
2485
2486 mask = (status & DPLL_PORTC_READY_MASK) >> 4;
2487 if (mask == 0xf)
2488 mask = 0x0;
2489 else
2490 dev_priv->chv_phy_control |=
2491 PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY0, DPIO_CH1);
2492
2493 dev_priv->chv_phy_control |=
2494 PHY_CH_POWER_DOWN_OVRD(mask, DPIO_PHY0, DPIO_CH1);
2495
Ville Syrjälä70722462015-04-10 18:21:28 +03002496 dev_priv->chv_phy_control |= PHY_COM_LANE_RESET_DEASSERT(DPIO_PHY0);
Ville Syrjälä3be60de2015-09-08 18:05:45 +03002497
2498 dev_priv->chv_phy_assert[DPIO_PHY0] = false;
2499 } else {
2500 dev_priv->chv_phy_assert[DPIO_PHY0] = true;
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002501 }
2502
2503 if (cmn_d->ops->is_enabled(dev_priv, cmn_d)) {
2504 uint32_t status = I915_READ(DPIO_PHY_STATUS);
2505 unsigned int mask;
2506
2507 mask = status & DPLL_PORTD_READY_MASK;
2508
2509 if (mask == 0xf)
2510 mask = 0x0;
2511 else
2512 dev_priv->chv_phy_control |=
2513 PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY1, DPIO_CH0);
2514
2515 dev_priv->chv_phy_control |=
2516 PHY_CH_POWER_DOWN_OVRD(mask, DPIO_PHY1, DPIO_CH0);
2517
Ville Syrjälä70722462015-04-10 18:21:28 +03002518 dev_priv->chv_phy_control |= PHY_COM_LANE_RESET_DEASSERT(DPIO_PHY1);
Ville Syrjälä3be60de2015-09-08 18:05:45 +03002519
2520 dev_priv->chv_phy_assert[DPIO_PHY1] = false;
2521 } else {
2522 dev_priv->chv_phy_assert[DPIO_PHY1] = true;
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002523 }
2524
2525 I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
2526
2527 DRM_DEBUG_KMS("Initial PHY_CONTROL=0x%08x\n",
2528 dev_priv->chv_phy_control);
Ville Syrjälä70722462015-04-10 18:21:28 +03002529}
2530
Daniel Vetter9c065a72014-09-30 10:56:38 +02002531static void vlv_cmnlane_wa(struct drm_i915_private *dev_priv)
2532{
2533 struct i915_power_well *cmn =
2534 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_BC);
2535 struct i915_power_well *disp2d =
2536 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DISP2D);
2537
Daniel Vetter9c065a72014-09-30 10:56:38 +02002538 /* If the display might be already active skip this */
Ville Syrjälä5d93a6e2014-10-16 20:52:33 +03002539 if (cmn->ops->is_enabled(dev_priv, cmn) &&
2540 disp2d->ops->is_enabled(dev_priv, disp2d) &&
Daniel Vetter9c065a72014-09-30 10:56:38 +02002541 I915_READ(DPIO_CTL) & DPIO_CMNRST)
2542 return;
2543
2544 DRM_DEBUG_KMS("toggling display PHY side reset\n");
2545
2546 /* cmnlane needs DPLL registers */
2547 disp2d->ops->enable(dev_priv, disp2d);
2548
2549 /*
2550 * From VLV2A0_DP_eDP_HDMI_DPIO_driver_vbios_notes_11.docx:
2551 * Need to assert and de-assert PHY SB reset by gating the
2552 * common lane power, then un-gating it.
2553 * Simply ungating isn't enough to reset the PHY enough to get
2554 * ports and lanes running.
2555 */
2556 cmn->ops->disable(dev_priv, cmn);
2557}
2558
Daniel Vettere4e76842014-09-30 10:56:42 +02002559/**
2560 * intel_power_domains_init_hw - initialize hardware power domain state
2561 * @dev_priv: i915 device instance
Tvrtko Ursulin14bb2c12016-06-03 14:02:17 +01002562 * @resume: Called from resume code paths or not
Daniel Vettere4e76842014-09-30 10:56:42 +02002563 *
2564 * This function initializes the hardware power domain state and enables all
2565 * power domains using intel_display_set_init_power().
2566 */
Imre Deak73dfc222015-11-17 17:33:53 +02002567void intel_power_domains_init_hw(struct drm_i915_private *dev_priv, bool resume)
Daniel Vetter9c065a72014-09-30 10:56:38 +02002568{
Daniel Vetter9c065a72014-09-30 10:56:38 +02002569 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2570
2571 power_domains->initializing = true;
2572
Tvrtko Ursulin08537232016-10-13 11:03:02 +01002573 if (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv)) {
Imre Deak73dfc222015-11-17 17:33:53 +02002574 skl_display_core_init(dev_priv, resume);
Tvrtko Ursuline2d214a2016-10-13 11:03:04 +01002575 } else if (IS_BROXTON(dev_priv)) {
Imre Deakd7d7c9e2016-04-01 16:02:42 +03002576 bxt_display_core_init(dev_priv, resume);
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002577 } else if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä770effb2015-07-08 23:45:51 +03002578 mutex_lock(&power_domains->lock);
Ville Syrjälä70722462015-04-10 18:21:28 +03002579 chv_phy_control_init(dev_priv);
Ville Syrjälä770effb2015-07-08 23:45:51 +03002580 mutex_unlock(&power_domains->lock);
Tvrtko Ursulin11a914c2016-10-13 11:03:08 +01002581 } else if (IS_VALLEYVIEW(dev_priv)) {
Daniel Vetter9c065a72014-09-30 10:56:38 +02002582 mutex_lock(&power_domains->lock);
2583 vlv_cmnlane_wa(dev_priv);
2584 mutex_unlock(&power_domains->lock);
2585 }
2586
2587 /* For now, we need the power well to be always enabled. */
2588 intel_display_set_init_power(dev_priv, true);
Imre Deakd314cd42015-11-17 17:44:23 +02002589 /* Disable power support if the user asked so. */
2590 if (!i915.disable_power_well)
2591 intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
Imre Deak30eade12015-11-04 19:24:13 +02002592 intel_power_domains_sync_hw(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02002593 power_domains->initializing = false;
2594}
2595
Daniel Vettere4e76842014-09-30 10:56:42 +02002596/**
Imre Deak73dfc222015-11-17 17:33:53 +02002597 * intel_power_domains_suspend - suspend power domain state
2598 * @dev_priv: i915 device instance
2599 *
2600 * This function prepares the hardware power domain state before entering
2601 * system suspend. It must be paired with intel_power_domains_init_hw().
2602 */
2603void intel_power_domains_suspend(struct drm_i915_private *dev_priv)
2604{
Imre Deakd314cd42015-11-17 17:44:23 +02002605 /*
2606 * Even if power well support was disabled we still want to disable
2607 * power wells while we are system suspended.
2608 */
2609 if (!i915.disable_power_well)
2610 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
Imre Deak2622d792016-02-29 22:49:02 +02002611
2612 if (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv))
2613 skl_display_core_uninit(dev_priv);
Imre Deakd7d7c9e2016-04-01 16:02:42 +03002614 else if (IS_BROXTON(dev_priv))
2615 bxt_display_core_uninit(dev_priv);
Imre Deak73dfc222015-11-17 17:33:53 +02002616}
2617
2618/**
Daniel Vettere4e76842014-09-30 10:56:42 +02002619 * intel_runtime_pm_get - grab a runtime pm reference
2620 * @dev_priv: i915 device instance
2621 *
2622 * This function grabs a device-level runtime pm reference (mostly used for GEM
2623 * code to ensure the GTT or GT is on) and ensures that it is powered up.
2624 *
2625 * Any runtime pm reference obtained by this function must have a symmetric
2626 * call to intel_runtime_pm_put() to release the reference again.
2627 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02002628void intel_runtime_pm_get(struct drm_i915_private *dev_priv)
2629{
David Weinehall52a05c32016-08-22 13:32:44 +03002630 struct pci_dev *pdev = dev_priv->drm.pdev;
2631 struct device *kdev = &pdev->dev;
Daniel Vetter9c065a72014-09-30 10:56:38 +02002632
David Weinehallc49d13e2016-08-22 13:32:42 +03002633 pm_runtime_get_sync(kdev);
Imre Deak1f814da2015-12-16 02:52:19 +02002634
2635 atomic_inc(&dev_priv->pm.wakeref_count);
Imre Deakc9b88462015-12-15 20:10:34 +02002636 assert_rpm_wakelock_held(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02002637}
2638
Daniel Vettere4e76842014-09-30 10:56:42 +02002639/**
Imre Deak09731282016-02-17 14:17:42 +02002640 * intel_runtime_pm_get_if_in_use - grab a runtime pm reference if device in use
2641 * @dev_priv: i915 device instance
2642 *
2643 * This function grabs a device-level runtime pm reference if the device is
2644 * already in use and ensures that it is powered up.
2645 *
2646 * Any runtime pm reference obtained by this function must have a symmetric
2647 * call to intel_runtime_pm_put() to release the reference again.
2648 */
2649bool intel_runtime_pm_get_if_in_use(struct drm_i915_private *dev_priv)
2650{
David Weinehall52a05c32016-08-22 13:32:44 +03002651 struct pci_dev *pdev = dev_priv->drm.pdev;
2652 struct device *kdev = &pdev->dev;
Imre Deak09731282016-02-17 14:17:42 +02002653
Chris Wilson135dc792016-02-25 21:10:28 +00002654 if (IS_ENABLED(CONFIG_PM)) {
David Weinehallc49d13e2016-08-22 13:32:42 +03002655 int ret = pm_runtime_get_if_in_use(kdev);
Imre Deak09731282016-02-17 14:17:42 +02002656
Chris Wilson135dc792016-02-25 21:10:28 +00002657 /*
2658 * In cases runtime PM is disabled by the RPM core and we get
2659 * an -EINVAL return value we are not supposed to call this
2660 * function, since the power state is undefined. This applies
2661 * atm to the late/early system suspend/resume handlers.
2662 */
2663 WARN_ON_ONCE(ret < 0);
2664 if (ret <= 0)
2665 return false;
2666 }
Imre Deak09731282016-02-17 14:17:42 +02002667
2668 atomic_inc(&dev_priv->pm.wakeref_count);
2669 assert_rpm_wakelock_held(dev_priv);
2670
2671 return true;
2672}
2673
2674/**
Daniel Vettere4e76842014-09-30 10:56:42 +02002675 * intel_runtime_pm_get_noresume - grab a runtime pm reference
2676 * @dev_priv: i915 device instance
2677 *
2678 * This function grabs a device-level runtime pm reference (mostly used for GEM
2679 * code to ensure the GTT or GT is on).
2680 *
2681 * It will _not_ power up the device but instead only check that it's powered
2682 * on. Therefore it is only valid to call this functions from contexts where
2683 * the device is known to be powered up and where trying to power it up would
2684 * result in hilarity and deadlocks. That pretty much means only the system
2685 * suspend/resume code where this is used to grab runtime pm references for
2686 * delayed setup down in work items.
2687 *
2688 * Any runtime pm reference obtained by this function must have a symmetric
2689 * call to intel_runtime_pm_put() to release the reference again.
2690 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02002691void intel_runtime_pm_get_noresume(struct drm_i915_private *dev_priv)
2692{
David Weinehall52a05c32016-08-22 13:32:44 +03002693 struct pci_dev *pdev = dev_priv->drm.pdev;
2694 struct device *kdev = &pdev->dev;
Daniel Vetter9c065a72014-09-30 10:56:38 +02002695
Imre Deakc9b88462015-12-15 20:10:34 +02002696 assert_rpm_wakelock_held(dev_priv);
David Weinehallc49d13e2016-08-22 13:32:42 +03002697 pm_runtime_get_noresume(kdev);
Imre Deak1f814da2015-12-16 02:52:19 +02002698
2699 atomic_inc(&dev_priv->pm.wakeref_count);
Daniel Vetter9c065a72014-09-30 10:56:38 +02002700}
2701
Daniel Vettere4e76842014-09-30 10:56:42 +02002702/**
2703 * intel_runtime_pm_put - release a runtime pm reference
2704 * @dev_priv: i915 device instance
2705 *
2706 * This function drops the device-level runtime pm reference obtained by
2707 * intel_runtime_pm_get() and might power down the corresponding
2708 * hardware block right away if this is the last reference.
2709 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02002710void intel_runtime_pm_put(struct drm_i915_private *dev_priv)
2711{
David Weinehall52a05c32016-08-22 13:32:44 +03002712 struct pci_dev *pdev = dev_priv->drm.pdev;
2713 struct device *kdev = &pdev->dev;
Daniel Vetter9c065a72014-09-30 10:56:38 +02002714
Imre Deak542db3c2015-12-15 20:10:36 +02002715 assert_rpm_wakelock_held(dev_priv);
Chris Wilson2eedfc72016-10-24 13:42:17 +01002716 atomic_dec(&dev_priv->pm.wakeref_count);
Imre Deak1f814da2015-12-16 02:52:19 +02002717
David Weinehallc49d13e2016-08-22 13:32:42 +03002718 pm_runtime_mark_last_busy(kdev);
2719 pm_runtime_put_autosuspend(kdev);
Daniel Vetter9c065a72014-09-30 10:56:38 +02002720}
2721
Daniel Vettere4e76842014-09-30 10:56:42 +02002722/**
2723 * intel_runtime_pm_enable - enable runtime pm
2724 * @dev_priv: i915 device instance
2725 *
2726 * This function enables runtime pm at the end of the driver load sequence.
2727 *
2728 * Note that this function does currently not enable runtime pm for the
2729 * subordinate display power domains. That is only done on the first modeset
2730 * using intel_display_set_init_power().
2731 */
Daniel Vetterf458ebb2014-09-30 10:56:39 +02002732void intel_runtime_pm_enable(struct drm_i915_private *dev_priv)
Daniel Vetter9c065a72014-09-30 10:56:38 +02002733{
David Weinehall52a05c32016-08-22 13:32:44 +03002734 struct pci_dev *pdev = dev_priv->drm.pdev;
David Weinehall52a05c32016-08-22 13:32:44 +03002735 struct device *kdev = &pdev->dev;
Daniel Vetter9c065a72014-09-30 10:56:38 +02002736
David Weinehallc49d13e2016-08-22 13:32:42 +03002737 pm_runtime_set_autosuspend_delay(kdev, 10000); /* 10s */
2738 pm_runtime_mark_last_busy(kdev);
Imre Deakcbc68dc2015-12-17 19:04:33 +02002739
Imre Deak25b181b2015-12-17 13:44:56 +02002740 /*
2741 * Take a permanent reference to disable the RPM functionality and drop
2742 * it only when unloading the driver. Use the low level get/put helpers,
2743 * so the driver's own RPM reference tracking asserts also work on
2744 * platforms without RPM support.
2745 */
Tvrtko Ursulin6772ffe2016-10-13 11:02:55 +01002746 if (!HAS_RUNTIME_PM(dev_priv)) {
David Weinehallc49d13e2016-08-22 13:32:42 +03002747 pm_runtime_dont_use_autosuspend(kdev);
2748 pm_runtime_get_sync(kdev);
Imre Deakcbc68dc2015-12-17 19:04:33 +02002749 } else {
David Weinehallc49d13e2016-08-22 13:32:42 +03002750 pm_runtime_use_autosuspend(kdev);
Imre Deakcbc68dc2015-12-17 19:04:33 +02002751 }
Daniel Vetter9c065a72014-09-30 10:56:38 +02002752
Imre Deakaabee1b2015-12-15 20:10:29 +02002753 /*
2754 * The core calls the driver load handler with an RPM reference held.
2755 * We drop that here and will reacquire it during unloading in
2756 * intel_power_domains_fini().
2757 */
David Weinehallc49d13e2016-08-22 13:32:42 +03002758 pm_runtime_put_autosuspend(kdev);
Daniel Vetter9c065a72014-09-30 10:56:38 +02002759}