blob: 2969787201ef8f5fcb0dabf8935ef854bf43d911 [file] [log] [blame]
Daniel Vetter9c065a72014-09-30 10:56:38 +02001/*
2 * Copyright © 2012-2014 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 *
23 * Authors:
24 * Eugeni Dodonov <eugeni.dodonov@intel.com>
25 * Daniel Vetter <daniel.vetter@ffwll.ch>
26 *
27 */
28
29#include <linux/pm_runtime.h>
30#include <linux/vgaarb.h>
31
32#include "i915_drv.h"
33#include "intel_drv.h"
Daniel Vetter9c065a72014-09-30 10:56:38 +020034
Daniel Vettere4e76842014-09-30 10:56:42 +020035/**
36 * DOC: runtime pm
37 *
38 * The i915 driver supports dynamic enabling and disabling of entire hardware
39 * blocks at runtime. This is especially important on the display side where
40 * software is supposed to control many power gates manually on recent hardware,
41 * since on the GT side a lot of the power management is done by the hardware.
42 * But even there some manual control at the device level is required.
43 *
44 * Since i915 supports a diverse set of platforms with a unified codebase and
45 * hardware engineers just love to shuffle functionality around between power
46 * domains there's a sizeable amount of indirection required. This file provides
47 * generic functions to the driver for grabbing and releasing references for
48 * abstract power domains. It then maps those to the actual power wells
49 * present for a given platform.
50 */
51
Suketu Shah5aefb232015-04-16 14:22:10 +053052bool intel_display_power_well_is_enabled(struct drm_i915_private *dev_priv,
Imre Deak438b8dc2017-07-11 23:42:30 +030053 enum i915_power_well_id power_well_id);
Suketu Shah5aefb232015-04-16 14:22:10 +053054
Imre Deak9c8d0b82016-06-13 16:44:34 +030055static struct i915_power_well *
Imre Deak438b8dc2017-07-11 23:42:30 +030056lookup_power_well(struct drm_i915_private *dev_priv,
57 enum i915_power_well_id power_well_id);
Imre Deak9c8d0b82016-06-13 16:44:34 +030058
Daniel Stone9895ad02015-11-20 15:55:33 +000059const char *
60intel_display_power_domain_str(enum intel_display_power_domain domain)
61{
62 switch (domain) {
63 case POWER_DOMAIN_PIPE_A:
64 return "PIPE_A";
65 case POWER_DOMAIN_PIPE_B:
66 return "PIPE_B";
67 case POWER_DOMAIN_PIPE_C:
68 return "PIPE_C";
69 case POWER_DOMAIN_PIPE_A_PANEL_FITTER:
70 return "PIPE_A_PANEL_FITTER";
71 case POWER_DOMAIN_PIPE_B_PANEL_FITTER:
72 return "PIPE_B_PANEL_FITTER";
73 case POWER_DOMAIN_PIPE_C_PANEL_FITTER:
74 return "PIPE_C_PANEL_FITTER";
75 case POWER_DOMAIN_TRANSCODER_A:
76 return "TRANSCODER_A";
77 case POWER_DOMAIN_TRANSCODER_B:
78 return "TRANSCODER_B";
79 case POWER_DOMAIN_TRANSCODER_C:
80 return "TRANSCODER_C";
81 case POWER_DOMAIN_TRANSCODER_EDP:
82 return "TRANSCODER_EDP";
Jani Nikula4d1de972016-03-18 17:05:42 +020083 case POWER_DOMAIN_TRANSCODER_DSI_A:
84 return "TRANSCODER_DSI_A";
85 case POWER_DOMAIN_TRANSCODER_DSI_C:
86 return "TRANSCODER_DSI_C";
Daniel Stone9895ad02015-11-20 15:55:33 +000087 case POWER_DOMAIN_PORT_DDI_A_LANES:
88 return "PORT_DDI_A_LANES";
89 case POWER_DOMAIN_PORT_DDI_B_LANES:
90 return "PORT_DDI_B_LANES";
91 case POWER_DOMAIN_PORT_DDI_C_LANES:
92 return "PORT_DDI_C_LANES";
93 case POWER_DOMAIN_PORT_DDI_D_LANES:
94 return "PORT_DDI_D_LANES";
95 case POWER_DOMAIN_PORT_DDI_E_LANES:
96 return "PORT_DDI_E_LANES";
Rodrigo Vivi9787e832018-01-29 15:22:22 -080097 case POWER_DOMAIN_PORT_DDI_F_LANES:
98 return "PORT_DDI_F_LANES";
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +020099 case POWER_DOMAIN_PORT_DDI_A_IO:
100 return "PORT_DDI_A_IO";
101 case POWER_DOMAIN_PORT_DDI_B_IO:
102 return "PORT_DDI_B_IO";
103 case POWER_DOMAIN_PORT_DDI_C_IO:
104 return "PORT_DDI_C_IO";
105 case POWER_DOMAIN_PORT_DDI_D_IO:
106 return "PORT_DDI_D_IO";
107 case POWER_DOMAIN_PORT_DDI_E_IO:
108 return "PORT_DDI_E_IO";
Rodrigo Vivi9787e832018-01-29 15:22:22 -0800109 case POWER_DOMAIN_PORT_DDI_F_IO:
110 return "PORT_DDI_F_IO";
Daniel Stone9895ad02015-11-20 15:55:33 +0000111 case POWER_DOMAIN_PORT_DSI:
112 return "PORT_DSI";
113 case POWER_DOMAIN_PORT_CRT:
114 return "PORT_CRT";
115 case POWER_DOMAIN_PORT_OTHER:
116 return "PORT_OTHER";
117 case POWER_DOMAIN_VGA:
118 return "VGA";
119 case POWER_DOMAIN_AUDIO:
120 return "AUDIO";
121 case POWER_DOMAIN_PLLS:
122 return "PLLS";
123 case POWER_DOMAIN_AUX_A:
124 return "AUX_A";
125 case POWER_DOMAIN_AUX_B:
126 return "AUX_B";
127 case POWER_DOMAIN_AUX_C:
128 return "AUX_C";
129 case POWER_DOMAIN_AUX_D:
130 return "AUX_D";
James Ausmusbb187e92018-06-11 17:25:12 -0700131 case POWER_DOMAIN_AUX_E:
132 return "AUX_E";
Rodrigo Vivia324fca2018-01-29 15:22:15 -0800133 case POWER_DOMAIN_AUX_F:
134 return "AUX_F";
Dhinakaran Pandiyanb891d5e2018-02-23 14:15:15 -0800135 case POWER_DOMAIN_AUX_IO_A:
136 return "AUX_IO_A";
Daniel Stone9895ad02015-11-20 15:55:33 +0000137 case POWER_DOMAIN_GMBUS:
138 return "GMBUS";
139 case POWER_DOMAIN_INIT:
140 return "INIT";
141 case POWER_DOMAIN_MODESET:
142 return "MODESET";
Tvrtko Ursulinb6876372017-12-05 13:28:54 +0000143 case POWER_DOMAIN_GT_IRQ:
144 return "GT_IRQ";
Daniel Stone9895ad02015-11-20 15:55:33 +0000145 default:
146 MISSING_CASE(domain);
147 return "?";
148 }
149}
150
Damien Lespiaue8ca9322015-07-30 18:20:26 -0300151static void intel_power_well_enable(struct drm_i915_private *dev_priv,
152 struct i915_power_well *power_well)
153{
154 DRM_DEBUG_KMS("enabling %s\n", power_well->name);
155 power_well->ops->enable(dev_priv, power_well);
156 power_well->hw_enabled = true;
157}
158
Damien Lespiaudcddab32015-07-30 18:20:27 -0300159static void intel_power_well_disable(struct drm_i915_private *dev_priv,
160 struct i915_power_well *power_well)
161{
162 DRM_DEBUG_KMS("disabling %s\n", power_well->name);
163 power_well->hw_enabled = false;
164 power_well->ops->disable(dev_priv, power_well);
165}
166
Imre Deakb409ca92016-06-13 16:44:33 +0300167static void intel_power_well_get(struct drm_i915_private *dev_priv,
168 struct i915_power_well *power_well)
169{
170 if (!power_well->count++)
171 intel_power_well_enable(dev_priv, power_well);
172}
173
174static void intel_power_well_put(struct drm_i915_private *dev_priv,
175 struct i915_power_well *power_well)
176{
177 WARN(!power_well->count, "Use count on power well %s is already zero",
178 power_well->name);
179
180 if (!--power_well->count)
181 intel_power_well_disable(dev_priv, power_well);
182}
183
Daniel Vettere4e76842014-09-30 10:56:42 +0200184/**
185 * __intel_display_power_is_enabled - unlocked check for a power domain
186 * @dev_priv: i915 device instance
187 * @domain: power domain to check
188 *
189 * This is the unlocked version of intel_display_power_is_enabled() and should
190 * only be used from error capture and recovery code where deadlocks are
191 * possible.
192 *
193 * Returns:
194 * True when the power domain is enabled, false otherwise.
195 */
Daniel Vetterf458ebb2014-09-30 10:56:39 +0200196bool __intel_display_power_is_enabled(struct drm_i915_private *dev_priv,
197 enum intel_display_power_domain domain)
Daniel Vetter9c065a72014-09-30 10:56:38 +0200198{
Daniel Vetter9c065a72014-09-30 10:56:38 +0200199 struct i915_power_well *power_well;
200 bool is_enabled;
Daniel Vetter9c065a72014-09-30 10:56:38 +0200201
Sagar Arun Kamblead1443f2017-10-10 22:30:04 +0100202 if (dev_priv->runtime_pm.suspended)
Daniel Vetter9c065a72014-09-30 10:56:38 +0200203 return false;
204
Daniel Vetter9c065a72014-09-30 10:56:38 +0200205 is_enabled = true;
206
Imre Deak75ccb2e2017-02-17 17:39:43 +0200207 for_each_power_domain_well_rev(dev_priv, power_well, BIT_ULL(domain)) {
Daniel Vetter9c065a72014-09-30 10:56:38 +0200208 if (power_well->always_on)
209 continue;
210
211 if (!power_well->hw_enabled) {
212 is_enabled = false;
213 break;
214 }
215 }
216
217 return is_enabled;
218}
219
Daniel Vettere4e76842014-09-30 10:56:42 +0200220/**
Damien Lespiauf61ccae2014-11-25 13:45:41 +0000221 * intel_display_power_is_enabled - check for a power domain
Daniel Vettere4e76842014-09-30 10:56:42 +0200222 * @dev_priv: i915 device instance
223 * @domain: power domain to check
224 *
225 * This function can be used to check the hw power domain state. It is mostly
226 * used in hardware state readout functions. Everywhere else code should rely
227 * upon explicit power domain reference counting to ensure that the hardware
228 * block is powered up before accessing it.
229 *
230 * Callers must hold the relevant modesetting locks to ensure that concurrent
231 * threads can't disable the power well while the caller tries to read a few
232 * registers.
233 *
234 * Returns:
235 * True when the power domain is enabled, false otherwise.
236 */
Daniel Vetterf458ebb2014-09-30 10:56:39 +0200237bool intel_display_power_is_enabled(struct drm_i915_private *dev_priv,
238 enum intel_display_power_domain domain)
Daniel Vetter9c065a72014-09-30 10:56:38 +0200239{
240 struct i915_power_domains *power_domains;
241 bool ret;
242
243 power_domains = &dev_priv->power_domains;
244
245 mutex_lock(&power_domains->lock);
Daniel Vetterf458ebb2014-09-30 10:56:39 +0200246 ret = __intel_display_power_is_enabled(dev_priv, domain);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200247 mutex_unlock(&power_domains->lock);
248
249 return ret;
250}
251
Daniel Vettere4e76842014-09-30 10:56:42 +0200252/**
253 * intel_display_set_init_power - set the initial power domain state
254 * @dev_priv: i915 device instance
255 * @enable: whether to enable or disable the initial power domain state
256 *
257 * For simplicity our driver load/unload and system suspend/resume code assumes
258 * that all power domains are always enabled. This functions controls the state
259 * of this little hack. While the initial power domain state is enabled runtime
260 * pm is effectively disabled.
261 */
Daniel Vetterd9bc89d92014-09-30 10:56:40 +0200262void intel_display_set_init_power(struct drm_i915_private *dev_priv,
263 bool enable)
264{
265 if (dev_priv->power_domains.init_power_on == enable)
266 return;
267
268 if (enable)
269 intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
270 else
271 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
272
273 dev_priv->power_domains.init_power_on = enable;
274}
275
Daniel Vetter9c065a72014-09-30 10:56:38 +0200276/*
277 * Starting with Haswell, we have a "Power Down Well" that can be turned off
278 * when not needed anymore. We have 4 registers that can request the power well
279 * to be enabled, and it will only be disabled if none of the registers is
280 * requesting it to be enabled.
281 */
Imre Deak001bd2c2017-07-12 18:54:13 +0300282static void hsw_power_well_post_enable(struct drm_i915_private *dev_priv,
283 u8 irq_pipe_mask, bool has_vga)
Daniel Vetter9c065a72014-09-30 10:56:38 +0200284{
David Weinehall52a05c32016-08-22 13:32:44 +0300285 struct pci_dev *pdev = dev_priv->drm.pdev;
Daniel Vetter9c065a72014-09-30 10:56:38 +0200286
287 /*
288 * After we re-enable the power well, if we touch VGA register 0x3d5
289 * we'll get unclaimed register interrupts. This stops after we write
290 * anything to the VGA MSR register. The vgacon module uses this
291 * register all the time, so if we unbind our driver and, as a
292 * consequence, bind vgacon, we'll get stuck in an infinite loop at
293 * console_unlock(). So make here we touch the VGA MSR register, making
294 * sure vgacon can keep working normally without triggering interrupts
295 * and error messages.
296 */
Imre Deak001bd2c2017-07-12 18:54:13 +0300297 if (has_vga) {
298 vga_get_uninterruptible(pdev, VGA_RSRC_LEGACY_IO);
299 outb(inb(VGA_MSR_READ), VGA_MSR_WRITE);
300 vga_put(pdev, VGA_RSRC_LEGACY_IO);
301 }
Daniel Vetter9c065a72014-09-30 10:56:38 +0200302
Imre Deak001bd2c2017-07-12 18:54:13 +0300303 if (irq_pipe_mask)
304 gen8_irq_power_well_post_enable(dev_priv, irq_pipe_mask);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200305}
306
Imre Deak001bd2c2017-07-12 18:54:13 +0300307static void hsw_power_well_pre_disable(struct drm_i915_private *dev_priv,
308 u8 irq_pipe_mask)
Ville Syrjäläaae8ba82016-02-19 20:47:30 +0200309{
Imre Deak001bd2c2017-07-12 18:54:13 +0300310 if (irq_pipe_mask)
311 gen8_irq_power_well_pre_disable(dev_priv, irq_pipe_mask);
Ville Syrjäläaae8ba82016-02-19 20:47:30 +0200312}
313
Ville Syrjäläaae8ba82016-02-19 20:47:30 +0200314
Imre Deak76347c02017-07-06 17:40:36 +0300315static void hsw_wait_for_power_well_enable(struct drm_i915_private *dev_priv,
316 struct i915_power_well *power_well)
Imre Deak42d93662017-06-29 18:37:01 +0300317{
Imre Deak438b8dc2017-07-11 23:42:30 +0300318 enum i915_power_well_id id = power_well->id;
Imre Deak42d93662017-06-29 18:37:01 +0300319
320 /* Timeout for PW1:10 us, AUX:not specified, other PWs:20 us. */
321 WARN_ON(intel_wait_for_register(dev_priv,
Imre Deak9c3a16c2017-08-14 18:15:30 +0300322 HSW_PWR_WELL_CTL_DRIVER(id),
Imre Deak1af474f2017-07-06 17:40:34 +0300323 HSW_PWR_WELL_CTL_STATE(id),
324 HSW_PWR_WELL_CTL_STATE(id),
Imre Deak42d93662017-06-29 18:37:01 +0300325 1));
326}
327
Imre Deak76347c02017-07-06 17:40:36 +0300328static u32 hsw_power_well_requesters(struct drm_i915_private *dev_priv,
329 enum i915_power_well_id id)
Imre Deak42d93662017-06-29 18:37:01 +0300330{
Imre Deak1af474f2017-07-06 17:40:34 +0300331 u32 req_mask = HSW_PWR_WELL_CTL_REQ(id);
Imre Deak42d93662017-06-29 18:37:01 +0300332 u32 ret;
333
Imre Deak9c3a16c2017-08-14 18:15:30 +0300334 ret = I915_READ(HSW_PWR_WELL_CTL_BIOS(id)) & req_mask ? 1 : 0;
335 ret |= I915_READ(HSW_PWR_WELL_CTL_DRIVER(id)) & req_mask ? 2 : 0;
336 ret |= I915_READ(HSW_PWR_WELL_CTL_KVMR) & req_mask ? 4 : 0;
337 ret |= I915_READ(HSW_PWR_WELL_CTL_DEBUG(id)) & req_mask ? 8 : 0;
Imre Deak42d93662017-06-29 18:37:01 +0300338
339 return ret;
340}
341
Imre Deak76347c02017-07-06 17:40:36 +0300342static void hsw_wait_for_power_well_disable(struct drm_i915_private *dev_priv,
343 struct i915_power_well *power_well)
Imre Deak42d93662017-06-29 18:37:01 +0300344{
Imre Deak438b8dc2017-07-11 23:42:30 +0300345 enum i915_power_well_id id = power_well->id;
Imre Deak42d93662017-06-29 18:37:01 +0300346 bool disabled;
347 u32 reqs;
348
349 /*
350 * Bspec doesn't require waiting for PWs to get disabled, but still do
351 * this for paranoia. The known cases where a PW will be forced on:
352 * - a KVMR request on any power well via the KVMR request register
353 * - a DMC request on PW1 and MISC_IO power wells via the BIOS and
354 * DEBUG request registers
355 * Skip the wait in case any of the request bits are set and print a
356 * diagnostic message.
357 */
Imre Deak9c3a16c2017-08-14 18:15:30 +0300358 wait_for((disabled = !(I915_READ(HSW_PWR_WELL_CTL_DRIVER(id)) &
Imre Deak1af474f2017-07-06 17:40:34 +0300359 HSW_PWR_WELL_CTL_STATE(id))) ||
Imre Deak76347c02017-07-06 17:40:36 +0300360 (reqs = hsw_power_well_requesters(dev_priv, id)), 1);
Imre Deak42d93662017-06-29 18:37:01 +0300361 if (disabled)
362 return;
363
364 DRM_DEBUG_KMS("%s forced on (bios:%d driver:%d kvmr:%d debug:%d)\n",
365 power_well->name,
366 !!(reqs & 1), !!(reqs & 2), !!(reqs & 4), !!(reqs & 8));
367}
368
Imre Deakb2891eb2017-07-11 23:42:35 +0300369static void gen9_wait_for_power_well_fuses(struct drm_i915_private *dev_priv,
370 enum skl_power_gate pg)
371{
372 /* Timeout 5us for PG#0, for other PGs 1us */
373 WARN_ON(intel_wait_for_register(dev_priv, SKL_FUSE_STATUS,
374 SKL_FUSE_PG_DIST_STATUS(pg),
375 SKL_FUSE_PG_DIST_STATUS(pg), 1));
376}
377
Imre Deakec46d482017-07-06 17:40:33 +0300378static void hsw_power_well_enable(struct drm_i915_private *dev_priv,
379 struct i915_power_well *power_well)
Daniel Vetter9c065a72014-09-30 10:56:38 +0200380{
Imre Deak1af474f2017-07-06 17:40:34 +0300381 enum i915_power_well_id id = power_well->id;
Imre Deakb2891eb2017-07-11 23:42:35 +0300382 bool wait_fuses = power_well->hsw.has_fuses;
Chris Wilson320671f2017-10-02 11:04:16 +0100383 enum skl_power_gate uninitialized_var(pg);
Imre Deak1af474f2017-07-06 17:40:34 +0300384 u32 val;
385
Imre Deakb2891eb2017-07-11 23:42:35 +0300386 if (wait_fuses) {
387 pg = SKL_PW_TO_PG(id);
388 /*
389 * For PW1 we have to wait both for the PW0/PG0 fuse state
390 * before enabling the power well and PW1/PG1's own fuse
391 * state after the enabling. For all other power wells with
392 * fuses we only have to wait for that PW/PG's fuse state
393 * after the enabling.
394 */
395 if (pg == SKL_PG1)
396 gen9_wait_for_power_well_fuses(dev_priv, SKL_PG0);
397 }
398
Imre Deak9c3a16c2017-08-14 18:15:30 +0300399 val = I915_READ(HSW_PWR_WELL_CTL_DRIVER(id));
400 I915_WRITE(HSW_PWR_WELL_CTL_DRIVER(id), val | HSW_PWR_WELL_CTL_REQ(id));
Imre Deak76347c02017-07-06 17:40:36 +0300401 hsw_wait_for_power_well_enable(dev_priv, power_well);
Imre Deak001bd2c2017-07-12 18:54:13 +0300402
Lucas De Marchiddd39e42017-11-28 14:05:53 -0800403 /* Display WA #1178: cnl */
404 if (IS_CANNONLAKE(dev_priv) &&
405 (id == CNL_DISP_PW_AUX_B || id == CNL_DISP_PW_AUX_C ||
Rodrigo Vivib1ae6a82018-01-29 15:22:16 -0800406 id == CNL_DISP_PW_AUX_D || id == CNL_DISP_PW_AUX_F)) {
Lucas De Marchiddd39e42017-11-28 14:05:53 -0800407 val = I915_READ(CNL_AUX_ANAOVRD1(id));
408 val |= CNL_AUX_ANAOVRD1_ENABLE | CNL_AUX_ANAOVRD1_LDO_BYPASS;
409 I915_WRITE(CNL_AUX_ANAOVRD1(id), val);
410 }
411
Imre Deakb2891eb2017-07-11 23:42:35 +0300412 if (wait_fuses)
413 gen9_wait_for_power_well_fuses(dev_priv, pg);
414
Imre Deak001bd2c2017-07-12 18:54:13 +0300415 hsw_power_well_post_enable(dev_priv, power_well->hsw.irq_pipe_mask,
416 power_well->hsw.has_vga);
Imre Deakec46d482017-07-06 17:40:33 +0300417}
Daniel Vetter9c065a72014-09-30 10:56:38 +0200418
Imre Deakec46d482017-07-06 17:40:33 +0300419static void hsw_power_well_disable(struct drm_i915_private *dev_priv,
420 struct i915_power_well *power_well)
421{
Imre Deak1af474f2017-07-06 17:40:34 +0300422 enum i915_power_well_id id = power_well->id;
423 u32 val;
424
Imre Deak001bd2c2017-07-12 18:54:13 +0300425 hsw_power_well_pre_disable(dev_priv, power_well->hsw.irq_pipe_mask);
426
Imre Deak9c3a16c2017-08-14 18:15:30 +0300427 val = I915_READ(HSW_PWR_WELL_CTL_DRIVER(id));
428 I915_WRITE(HSW_PWR_WELL_CTL_DRIVER(id),
429 val & ~HSW_PWR_WELL_CTL_REQ(id));
Imre Deak76347c02017-07-06 17:40:36 +0300430 hsw_wait_for_power_well_disable(dev_priv, power_well);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200431}
432
Imre Deakd42539b2017-07-06 17:40:39 +0300433/*
434 * We should only use the power well if we explicitly asked the hardware to
435 * enable it, so check if it's enabled and also check if we've requested it to
436 * be enabled.
437 */
438static bool hsw_power_well_enabled(struct drm_i915_private *dev_priv,
439 struct i915_power_well *power_well)
440{
441 enum i915_power_well_id id = power_well->id;
442 u32 mask = HSW_PWR_WELL_CTL_REQ(id) | HSW_PWR_WELL_CTL_STATE(id);
443
Imre Deak9c3a16c2017-08-14 18:15:30 +0300444 return (I915_READ(HSW_PWR_WELL_CTL_DRIVER(id)) & mask) == mask;
Imre Deakd42539b2017-07-06 17:40:39 +0300445}
446
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530447static void assert_can_enable_dc9(struct drm_i915_private *dev_priv)
448{
Imre Deak9c3a16c2017-08-14 18:15:30 +0300449 enum i915_power_well_id id = SKL_DISP_PW_2;
450
Imre Deakbfcdabe2016-04-01 16:02:37 +0300451 WARN_ONCE((I915_READ(DC_STATE_EN) & DC_STATE_EN_DC9),
452 "DC9 already programmed to be enabled.\n");
453 WARN_ONCE(I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC5,
454 "DC5 still not disabled to enable DC9.\n");
Imre Deak9c3a16c2017-08-14 18:15:30 +0300455 WARN_ONCE(I915_READ(HSW_PWR_WELL_CTL_DRIVER(id)) &
456 HSW_PWR_WELL_CTL_REQ(id),
Imre Deake8a3a2a2017-06-29 18:37:00 +0300457 "Power well 2 on.\n");
Imre Deakbfcdabe2016-04-01 16:02:37 +0300458 WARN_ONCE(intel_irqs_enabled(dev_priv),
459 "Interrupts not disabled yet.\n");
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530460
461 /*
462 * TODO: check for the following to verify the conditions to enter DC9
463 * state are satisfied:
464 * 1] Check relevant display engine registers to verify if mode set
465 * disable sequence was followed.
466 * 2] Check if display uninitialize sequence is initialized.
467 */
468}
469
470static void assert_can_disable_dc9(struct drm_i915_private *dev_priv)
471{
Imre Deakbfcdabe2016-04-01 16:02:37 +0300472 WARN_ONCE(intel_irqs_enabled(dev_priv),
473 "Interrupts not disabled yet.\n");
474 WARN_ONCE(I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC5,
475 "DC5 still not disabled.\n");
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530476
477 /*
478 * TODO: check for the following to verify DC9 state was indeed
479 * entered before programming to disable it:
480 * 1] Check relevant display engine registers to verify if mode
481 * set disable sequence was followed.
482 * 2] Check if display uninitialize sequence is initialized.
483 */
484}
485
Mika Kuoppala779cb5d2016-02-18 17:58:09 +0200486static void gen9_write_dc_state(struct drm_i915_private *dev_priv,
487 u32 state)
488{
489 int rewrites = 0;
490 int rereads = 0;
491 u32 v;
492
493 I915_WRITE(DC_STATE_EN, state);
494
495 /* It has been observed that disabling the dc6 state sometimes
496 * doesn't stick and dmc keeps returning old value. Make sure
497 * the write really sticks enough times and also force rewrite until
498 * we are confident that state is exactly what we want.
499 */
500 do {
501 v = I915_READ(DC_STATE_EN);
502
503 if (v != state) {
504 I915_WRITE(DC_STATE_EN, state);
505 rewrites++;
506 rereads = 0;
507 } else if (rereads++ > 5) {
508 break;
509 }
510
511 } while (rewrites < 100);
512
513 if (v != state)
514 DRM_ERROR("Writing dc state to 0x%x failed, now 0x%x\n",
515 state, v);
516
517 /* Most of the times we need one retry, avoid spam */
518 if (rewrites > 1)
519 DRM_DEBUG_KMS("Rewrote dc state to 0x%x %d times\n",
520 state, rewrites);
521}
522
Imre Deakda2f41d2016-04-20 20:27:56 +0300523static u32 gen9_dc_mask(struct drm_i915_private *dev_priv)
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530524{
Imre Deakda2f41d2016-04-20 20:27:56 +0300525 u32 mask;
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530526
Imre Deak13ae3a02015-11-04 19:24:16 +0200527 mask = DC_STATE_EN_UPTO_DC5;
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200528 if (IS_GEN9_LP(dev_priv))
Imre Deak13ae3a02015-11-04 19:24:16 +0200529 mask |= DC_STATE_EN_DC9;
530 else
531 mask |= DC_STATE_EN_UPTO_DC6;
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530532
Imre Deakda2f41d2016-04-20 20:27:56 +0300533 return mask;
534}
535
536void gen9_sanitize_dc_state(struct drm_i915_private *dev_priv)
537{
538 u32 val;
539
540 val = I915_READ(DC_STATE_EN) & gen9_dc_mask(dev_priv);
541
542 DRM_DEBUG_KMS("Resetting DC state tracking from %02x to %02x\n",
543 dev_priv->csr.dc_state, val);
544 dev_priv->csr.dc_state = val;
545}
546
Imre Deak13e15922018-04-17 14:31:47 +0300547/**
548 * gen9_set_dc_state - set target display C power state
549 * @dev_priv: i915 device instance
550 * @state: target DC power state
551 * - DC_STATE_DISABLE
552 * - DC_STATE_EN_UPTO_DC5
553 * - DC_STATE_EN_UPTO_DC6
554 * - DC_STATE_EN_DC9
555 *
556 * Signal to DMC firmware/HW the target DC power state passed in @state.
557 * DMC/HW can turn off individual display clocks and power rails when entering
558 * a deeper DC power state (higher in number) and turns these back when exiting
559 * that state to a shallower power state (lower in number). The HW will decide
560 * when to actually enter a given state on an on-demand basis, for instance
561 * depending on the active state of display pipes. The state of display
562 * registers backed by affected power rails are saved/restored as needed.
563 *
564 * Based on the above enabling a deeper DC power state is asynchronous wrt.
565 * enabling it. Disabling a deeper power state is synchronous: for instance
566 * setting %DC_STATE_DISABLE won't complete until all HW resources are turned
567 * back on and register state is restored. This is guaranteed by the MMIO write
568 * to DC_STATE_EN blocking until the state is restored.
569 */
Imre Deakda2f41d2016-04-20 20:27:56 +0300570static void gen9_set_dc_state(struct drm_i915_private *dev_priv, uint32_t state)
571{
572 uint32_t val;
573 uint32_t mask;
574
Imre Deaka37baf32016-02-29 22:49:03 +0200575 if (WARN_ON_ONCE(state & ~dev_priv->csr.allowed_dc_mask))
576 state &= dev_priv->csr.allowed_dc_mask;
Patrik Jakobsson443646c2015-11-16 15:01:06 +0100577
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530578 val = I915_READ(DC_STATE_EN);
Imre Deakda2f41d2016-04-20 20:27:56 +0300579 mask = gen9_dc_mask(dev_priv);
Imre Deak13ae3a02015-11-04 19:24:16 +0200580 DRM_DEBUG_KMS("Setting DC state from %02x to %02x\n",
581 val & mask, state);
Patrik Jakobsson832dba82016-02-18 17:21:11 +0200582
583 /* Check if DMC is ignoring our DC state requests */
584 if ((val & mask) != dev_priv->csr.dc_state)
585 DRM_ERROR("DC state mismatch (0x%x -> 0x%x)\n",
586 dev_priv->csr.dc_state, val & mask);
587
Imre Deak13ae3a02015-11-04 19:24:16 +0200588 val &= ~mask;
589 val |= state;
Mika Kuoppala779cb5d2016-02-18 17:58:09 +0200590
591 gen9_write_dc_state(dev_priv, val);
Patrik Jakobsson832dba82016-02-18 17:21:11 +0200592
593 dev_priv->csr.dc_state = val & mask;
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530594}
595
Imre Deak13ae3a02015-11-04 19:24:16 +0200596void bxt_enable_dc9(struct drm_i915_private *dev_priv)
597{
598 assert_can_enable_dc9(dev_priv);
599
600 DRM_DEBUG_KMS("Enabling DC9\n");
601
Imre Deak78597992016-06-16 16:37:20 +0300602 intel_power_sequencer_reset(dev_priv);
Imre Deak13ae3a02015-11-04 19:24:16 +0200603 gen9_set_dc_state(dev_priv, DC_STATE_EN_DC9);
604}
605
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530606void bxt_disable_dc9(struct drm_i915_private *dev_priv)
607{
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530608 assert_can_disable_dc9(dev_priv);
609
610 DRM_DEBUG_KMS("Disabling DC9\n");
611
Imre Deak13ae3a02015-11-04 19:24:16 +0200612 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
Imre Deak8090ba82016-08-10 14:07:33 +0300613
614 intel_pps_unlock_regs_wa(dev_priv);
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530615}
616
Daniel Vetteraf5fead2015-10-28 23:58:57 +0200617static void assert_csr_loaded(struct drm_i915_private *dev_priv)
618{
619 WARN_ONCE(!I915_READ(CSR_PROGRAM(0)),
620 "CSR program storage start is NULL\n");
621 WARN_ONCE(!I915_READ(CSR_SSP_BASE), "CSR SSP Base Not fine\n");
622 WARN_ONCE(!I915_READ(CSR_HTP_SKL), "CSR HTP Not fine\n");
623}
624
Suketu Shah5aefb232015-04-16 14:22:10 +0530625static void assert_can_enable_dc5(struct drm_i915_private *dev_priv)
Suketu Shahdc174302015-04-17 19:46:16 +0530626{
Suketu Shah5aefb232015-04-16 14:22:10 +0530627 bool pg2_enabled = intel_display_power_well_is_enabled(dev_priv,
628 SKL_DISP_PW_2);
629
Jesse Barnes6ff8ab02015-09-10 08:20:28 -0700630 WARN_ONCE(pg2_enabled, "PG2 not disabled to enable DC5.\n");
Suketu Shah5aefb232015-04-16 14:22:10 +0530631
Jesse Barnes6ff8ab02015-09-10 08:20:28 -0700632 WARN_ONCE((I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC5),
633 "DC5 already programmed to be enabled.\n");
Imre Deakc9b88462015-12-15 20:10:34 +0200634 assert_rpm_wakelock_held(dev_priv);
Suketu Shah5aefb232015-04-16 14:22:10 +0530635
636 assert_csr_loaded(dev_priv);
637}
638
Imre Deakf62c79b2016-04-20 20:27:57 +0300639void gen9_enable_dc5(struct drm_i915_private *dev_priv)
Suketu Shah5aefb232015-04-16 14:22:10 +0530640{
Suketu Shah5aefb232015-04-16 14:22:10 +0530641 assert_can_enable_dc5(dev_priv);
A.Sunil Kamath6b457d32015-04-16 14:22:09 +0530642
643 DRM_DEBUG_KMS("Enabling DC5\n");
644
Lucas De Marchi53421c22017-12-04 15:22:10 -0800645 /* Wa Display #1183: skl,kbl,cfl */
646 if (IS_GEN9_BC(dev_priv))
647 I915_WRITE(GEN8_CHICKEN_DCPR_1, I915_READ(GEN8_CHICKEN_DCPR_1) |
648 SKL_SELECT_ALTERNATE_DC_EXIT);
649
Imre Deak13ae3a02015-11-04 19:24:16 +0200650 gen9_set_dc_state(dev_priv, DC_STATE_EN_UPTO_DC5);
Suketu Shahdc174302015-04-17 19:46:16 +0530651}
652
Suketu Shah93c7cb62015-04-16 14:22:13 +0530653static void assert_can_enable_dc6(struct drm_i915_private *dev_priv)
Suketu Shahf75a1982015-04-16 14:22:11 +0530654{
Jesse Barnes6ff8ab02015-09-10 08:20:28 -0700655 WARN_ONCE(I915_READ(UTIL_PIN_CTL) & UTIL_PIN_ENABLE,
656 "Backlight is not disabled.\n");
657 WARN_ONCE((I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC6),
658 "DC6 already programmed to be enabled.\n");
Suketu Shah93c7cb62015-04-16 14:22:13 +0530659
660 assert_csr_loaded(dev_priv);
661}
662
Daniel Vetterc4c25252018-04-17 12:02:25 +0200663static void skl_enable_dc6(struct drm_i915_private *dev_priv)
Suketu Shah93c7cb62015-04-16 14:22:13 +0530664{
Suketu Shah93c7cb62015-04-16 14:22:13 +0530665 assert_can_enable_dc6(dev_priv);
A.Sunil Kamath74b4f372015-04-16 14:22:12 +0530666
667 DRM_DEBUG_KMS("Enabling DC6\n");
668
Imre Deakb49be662018-04-19 18:51:09 +0300669 /* Wa Display #1183: skl,kbl,cfl */
670 if (IS_GEN9_BC(dev_priv))
671 I915_WRITE(GEN8_CHICKEN_DCPR_1, I915_READ(GEN8_CHICKEN_DCPR_1) |
672 SKL_SELECT_ALTERNATE_DC_EXIT);
Imre Deak13ae3a02015-11-04 19:24:16 +0200673
Imre Deakb49be662018-04-19 18:51:09 +0300674 gen9_set_dc_state(dev_priv, DC_STATE_EN_UPTO_DC6);
Suketu Shahf75a1982015-04-16 14:22:11 +0530675}
676
Daniel Vetter9c065a72014-09-30 10:56:38 +0200677static void hsw_power_well_sync_hw(struct drm_i915_private *dev_priv,
678 struct i915_power_well *power_well)
679{
Imre Deak1af474f2017-07-06 17:40:34 +0300680 enum i915_power_well_id id = power_well->id;
681 u32 mask = HSW_PWR_WELL_CTL_REQ(id);
Imre Deak9c3a16c2017-08-14 18:15:30 +0300682 u32 bios_req = I915_READ(HSW_PWR_WELL_CTL_BIOS(id));
Imre Deak1af474f2017-07-06 17:40:34 +0300683
Imre Deak16e84912017-02-17 17:39:45 +0200684 /* Take over the request bit if set by BIOS. */
Imre Deak1af474f2017-07-06 17:40:34 +0300685 if (bios_req & mask) {
Imre Deak9c3a16c2017-08-14 18:15:30 +0300686 u32 drv_req = I915_READ(HSW_PWR_WELL_CTL_DRIVER(id));
Imre Deak1af474f2017-07-06 17:40:34 +0300687
688 if (!(drv_req & mask))
Imre Deak9c3a16c2017-08-14 18:15:30 +0300689 I915_WRITE(HSW_PWR_WELL_CTL_DRIVER(id), drv_req | mask);
690 I915_WRITE(HSW_PWR_WELL_CTL_BIOS(id), bios_req & ~mask);
Imre Deak16e84912017-02-17 17:39:45 +0200691 }
Daniel Vetter9c065a72014-09-30 10:56:38 +0200692}
693
Imre Deak9c8d0b82016-06-13 16:44:34 +0300694static void bxt_dpio_cmn_power_well_enable(struct drm_i915_private *dev_priv,
695 struct i915_power_well *power_well)
696{
Imre Deakb5565a22017-07-06 17:40:29 +0300697 bxt_ddi_phy_init(dev_priv, power_well->bxt.phy);
Imre Deak9c8d0b82016-06-13 16:44:34 +0300698}
699
700static void bxt_dpio_cmn_power_well_disable(struct drm_i915_private *dev_priv,
701 struct i915_power_well *power_well)
702{
Imre Deakb5565a22017-07-06 17:40:29 +0300703 bxt_ddi_phy_uninit(dev_priv, power_well->bxt.phy);
Imre Deak9c8d0b82016-06-13 16:44:34 +0300704}
705
706static bool bxt_dpio_cmn_power_well_enabled(struct drm_i915_private *dev_priv,
707 struct i915_power_well *power_well)
708{
Imre Deakb5565a22017-07-06 17:40:29 +0300709 return bxt_ddi_phy_is_enabled(dev_priv, power_well->bxt.phy);
Imre Deak9c8d0b82016-06-13 16:44:34 +0300710}
711
Imre Deak9c8d0b82016-06-13 16:44:34 +0300712static void bxt_verify_ddi_phy_power_wells(struct drm_i915_private *dev_priv)
713{
714 struct i915_power_well *power_well;
715
716 power_well = lookup_power_well(dev_priv, BXT_DPIO_CMN_A);
717 if (power_well->count > 0)
Imre Deakb5565a22017-07-06 17:40:29 +0300718 bxt_ddi_phy_verify_state(dev_priv, power_well->bxt.phy);
Imre Deak9c8d0b82016-06-13 16:44:34 +0300719
720 power_well = lookup_power_well(dev_priv, BXT_DPIO_CMN_BC);
721 if (power_well->count > 0)
Imre Deakb5565a22017-07-06 17:40:29 +0300722 bxt_ddi_phy_verify_state(dev_priv, power_well->bxt.phy);
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +0200723
724 if (IS_GEMINILAKE(dev_priv)) {
725 power_well = lookup_power_well(dev_priv, GLK_DPIO_CMN_C);
726 if (power_well->count > 0)
Imre Deakb5565a22017-07-06 17:40:29 +0300727 bxt_ddi_phy_verify_state(dev_priv, power_well->bxt.phy);
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +0200728 }
Imre Deak9c8d0b82016-06-13 16:44:34 +0300729}
730
Patrik Jakobsson9f836f92015-11-16 16:20:01 +0100731static bool gen9_dc_off_power_well_enabled(struct drm_i915_private *dev_priv,
732 struct i915_power_well *power_well)
733{
734 return (I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC5_DC6_MASK) == 0;
735}
736
Ville Syrjälä18a80672016-05-16 16:59:40 +0300737static void gen9_assert_dbuf_enabled(struct drm_i915_private *dev_priv)
738{
739 u32 tmp = I915_READ(DBUF_CTL);
740
741 WARN((tmp & (DBUF_POWER_STATE | DBUF_POWER_REQUEST)) !=
742 (DBUF_POWER_STATE | DBUF_POWER_REQUEST),
743 "Unexpected DBuf power power state (0x%08x)\n", tmp);
744}
745
Patrik Jakobsson9f836f92015-11-16 16:20:01 +0100746static void gen9_dc_off_power_well_enable(struct drm_i915_private *dev_priv,
747 struct i915_power_well *power_well)
748{
Ville Syrjälä49cd97a2017-02-07 20:33:45 +0200749 struct intel_cdclk_state cdclk_state = {};
750
Imre Deak5b773eb2016-02-29 22:49:05 +0200751 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
Imre Deakadc7f042016-04-04 17:27:10 +0300752
Ville Syrjälä49cd97a2017-02-07 20:33:45 +0200753 dev_priv->display.get_cdclk(dev_priv, &cdclk_state);
Ville Syrjälä64600bd2017-10-24 12:52:08 +0300754 /* Can't read out voltage_level so can't use intel_cdclk_changed() */
755 WARN_ON(intel_cdclk_needs_modeset(&dev_priv->cdclk.hw, &cdclk_state));
Ville Syrjälä342be922016-05-13 23:41:39 +0300756
Ville Syrjälä18a80672016-05-16 16:59:40 +0300757 gen9_assert_dbuf_enabled(dev_priv);
758
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200759 if (IS_GEN9_LP(dev_priv))
Imre Deak9c8d0b82016-06-13 16:44:34 +0300760 bxt_verify_ddi_phy_power_wells(dev_priv);
Patrik Jakobsson9f836f92015-11-16 16:20:01 +0100761}
762
763static void gen9_dc_off_power_well_disable(struct drm_i915_private *dev_priv,
764 struct i915_power_well *power_well)
765{
Imre Deakf74ed082016-04-18 14:48:21 +0300766 if (!dev_priv->csr.dmc_payload)
767 return;
768
Imre Deaka37baf32016-02-29 22:49:03 +0200769 if (dev_priv->csr.allowed_dc_mask & DC_STATE_EN_UPTO_DC6)
Patrik Jakobsson9f836f92015-11-16 16:20:01 +0100770 skl_enable_dc6(dev_priv);
Imre Deaka37baf32016-02-29 22:49:03 +0200771 else if (dev_priv->csr.allowed_dc_mask & DC_STATE_EN_UPTO_DC5)
Patrik Jakobsson9f836f92015-11-16 16:20:01 +0100772 gen9_enable_dc5(dev_priv);
773}
774
Imre Deak3c1b38e2017-02-17 17:39:42 +0200775static void i9xx_power_well_sync_hw_noop(struct drm_i915_private *dev_priv,
776 struct i915_power_well *power_well)
Patrik Jakobsson9f836f92015-11-16 16:20:01 +0100777{
Patrik Jakobsson9f836f92015-11-16 16:20:01 +0100778}
779
Daniel Vetter9c065a72014-09-30 10:56:38 +0200780static void i9xx_always_on_power_well_noop(struct drm_i915_private *dev_priv,
781 struct i915_power_well *power_well)
782{
783}
784
785static bool i9xx_always_on_power_well_enabled(struct drm_i915_private *dev_priv,
786 struct i915_power_well *power_well)
787{
788 return true;
789}
790
Ville Syrjälä2ee0da12017-06-01 17:36:16 +0300791static void i830_pipes_power_well_enable(struct drm_i915_private *dev_priv,
792 struct i915_power_well *power_well)
793{
794 if ((I915_READ(PIPECONF(PIPE_A)) & PIPECONF_ENABLE) == 0)
795 i830_enable_pipe(dev_priv, PIPE_A);
796 if ((I915_READ(PIPECONF(PIPE_B)) & PIPECONF_ENABLE) == 0)
797 i830_enable_pipe(dev_priv, PIPE_B);
798}
799
800static void i830_pipes_power_well_disable(struct drm_i915_private *dev_priv,
801 struct i915_power_well *power_well)
802{
803 i830_disable_pipe(dev_priv, PIPE_B);
804 i830_disable_pipe(dev_priv, PIPE_A);
805}
806
807static bool i830_pipes_power_well_enabled(struct drm_i915_private *dev_priv,
808 struct i915_power_well *power_well)
809{
810 return I915_READ(PIPECONF(PIPE_A)) & PIPECONF_ENABLE &&
811 I915_READ(PIPECONF(PIPE_B)) & PIPECONF_ENABLE;
812}
813
814static void i830_pipes_power_well_sync_hw(struct drm_i915_private *dev_priv,
815 struct i915_power_well *power_well)
816{
817 if (power_well->count > 0)
818 i830_pipes_power_well_enable(dev_priv, power_well);
819 else
820 i830_pipes_power_well_disable(dev_priv, power_well);
821}
822
Daniel Vetter9c065a72014-09-30 10:56:38 +0200823static void vlv_set_power_well(struct drm_i915_private *dev_priv,
824 struct i915_power_well *power_well, bool enable)
825{
Imre Deak438b8dc2017-07-11 23:42:30 +0300826 enum i915_power_well_id power_well_id = power_well->id;
Daniel Vetter9c065a72014-09-30 10:56:38 +0200827 u32 mask;
828 u32 state;
829 u32 ctrl;
830
831 mask = PUNIT_PWRGT_MASK(power_well_id);
832 state = enable ? PUNIT_PWRGT_PWR_ON(power_well_id) :
833 PUNIT_PWRGT_PWR_GATE(power_well_id);
834
Sagar Arun Kamble9f817502017-10-10 22:30:05 +0100835 mutex_lock(&dev_priv->pcu_lock);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200836
837#define COND \
838 ((vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_STATUS) & mask) == state)
839
840 if (COND)
841 goto out;
842
843 ctrl = vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_CTRL);
844 ctrl &= ~mask;
845 ctrl |= state;
846 vlv_punit_write(dev_priv, PUNIT_REG_PWRGT_CTRL, ctrl);
847
848 if (wait_for(COND, 100))
Masanari Iida7e35ab82015-05-10 01:00:23 +0900849 DRM_ERROR("timeout setting power well state %08x (%08x)\n",
Daniel Vetter9c065a72014-09-30 10:56:38 +0200850 state,
851 vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_CTRL));
852
853#undef COND
854
855out:
Sagar Arun Kamble9f817502017-10-10 22:30:05 +0100856 mutex_unlock(&dev_priv->pcu_lock);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200857}
858
Daniel Vetter9c065a72014-09-30 10:56:38 +0200859static void vlv_power_well_enable(struct drm_i915_private *dev_priv,
860 struct i915_power_well *power_well)
861{
862 vlv_set_power_well(dev_priv, power_well, true);
863}
864
865static void vlv_power_well_disable(struct drm_i915_private *dev_priv,
866 struct i915_power_well *power_well)
867{
868 vlv_set_power_well(dev_priv, power_well, false);
869}
870
871static bool vlv_power_well_enabled(struct drm_i915_private *dev_priv,
872 struct i915_power_well *power_well)
873{
Imre Deak438b8dc2017-07-11 23:42:30 +0300874 enum i915_power_well_id power_well_id = power_well->id;
Daniel Vetter9c065a72014-09-30 10:56:38 +0200875 bool enabled = false;
876 u32 mask;
877 u32 state;
878 u32 ctrl;
879
880 mask = PUNIT_PWRGT_MASK(power_well_id);
881 ctrl = PUNIT_PWRGT_PWR_ON(power_well_id);
882
Sagar Arun Kamble9f817502017-10-10 22:30:05 +0100883 mutex_lock(&dev_priv->pcu_lock);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200884
885 state = vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_STATUS) & mask;
886 /*
887 * We only ever set the power-on and power-gate states, anything
888 * else is unexpected.
889 */
890 WARN_ON(state != PUNIT_PWRGT_PWR_ON(power_well_id) &&
891 state != PUNIT_PWRGT_PWR_GATE(power_well_id));
892 if (state == ctrl)
893 enabled = true;
894
895 /*
896 * A transient state at this point would mean some unexpected party
897 * is poking at the power controls too.
898 */
899 ctrl = vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_CTRL) & mask;
900 WARN_ON(ctrl != state);
901
Sagar Arun Kamble9f817502017-10-10 22:30:05 +0100902 mutex_unlock(&dev_priv->pcu_lock);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200903
904 return enabled;
905}
906
Ville Syrjälä766078d2016-04-11 16:56:30 +0300907static void vlv_init_display_clock_gating(struct drm_i915_private *dev_priv)
908{
Hans de Goede721d4842016-12-02 15:29:04 +0100909 u32 val;
910
911 /*
912 * On driver load, a pipe may be active and driving a DSI display.
913 * Preserve DPOUNIT_CLOCK_GATE_DISABLE to avoid the pipe getting stuck
914 * (and never recovering) in this case. intel_dsi_post_disable() will
915 * clear it when we turn off the display.
916 */
917 val = I915_READ(DSPCLK_GATE_D);
918 val &= DPOUNIT_CLOCK_GATE_DISABLE;
919 val |= VRHUNIT_CLOCK_GATE_DISABLE;
920 I915_WRITE(DSPCLK_GATE_D, val);
Ville Syrjälä766078d2016-04-11 16:56:30 +0300921
922 /*
923 * Disable trickle feed and enable pnd deadline calculation
924 */
925 I915_WRITE(MI_ARB_VLV, MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE);
926 I915_WRITE(CBR1_VLV, 0);
Ville Syrjälä19ab4ed2016-04-27 17:43:22 +0300927
928 WARN_ON(dev_priv->rawclk_freq == 0);
929
930 I915_WRITE(RAWCLK_FREQ_VLV,
931 DIV_ROUND_CLOSEST(dev_priv->rawclk_freq, 1000));
Ville Syrjälä766078d2016-04-11 16:56:30 +0300932}
933
Ville Syrjälä2be7d542015-06-29 15:25:51 +0300934static void vlv_display_power_well_init(struct drm_i915_private *dev_priv)
Daniel Vetter9c065a72014-09-30 10:56:38 +0200935{
Lyude9504a892016-06-21 17:03:42 -0400936 struct intel_encoder *encoder;
Ville Syrjälä5a8fbb72015-06-29 15:25:53 +0300937 enum pipe pipe;
938
939 /*
940 * Enable the CRI clock source so we can get at the
941 * display and the reference clock for VGA
942 * hotplug / manual detection. Supposedly DSI also
943 * needs the ref clock up and running.
944 *
945 * CHV DPLL B/C have some issues if VGA mode is enabled.
946 */
Tvrtko Ursulin801388c2016-11-16 08:55:44 +0000947 for_each_pipe(dev_priv, pipe) {
Ville Syrjälä5a8fbb72015-06-29 15:25:53 +0300948 u32 val = I915_READ(DPLL(pipe));
949
950 val |= DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
951 if (pipe != PIPE_A)
952 val |= DPLL_INTEGRATED_CRI_CLK_VLV;
953
954 I915_WRITE(DPLL(pipe), val);
955 }
Daniel Vetter9c065a72014-09-30 10:56:38 +0200956
Ville Syrjälä766078d2016-04-11 16:56:30 +0300957 vlv_init_display_clock_gating(dev_priv);
958
Daniel Vetter9c065a72014-09-30 10:56:38 +0200959 spin_lock_irq(&dev_priv->irq_lock);
960 valleyview_enable_display_irqs(dev_priv);
961 spin_unlock_irq(&dev_priv->irq_lock);
962
963 /*
964 * During driver initialization/resume we can avoid restoring the
965 * part of the HW/SW state that will be inited anyway explicitly.
966 */
967 if (dev_priv->power_domains.initializing)
968 return;
969
Daniel Vetterb9632912014-09-30 10:56:44 +0200970 intel_hpd_init(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200971
Lyude9504a892016-06-21 17:03:42 -0400972 /* Re-enable the ADPA, if we have one */
973 for_each_intel_encoder(&dev_priv->drm, encoder) {
974 if (encoder->type == INTEL_OUTPUT_ANALOG)
975 intel_crt_reset(&encoder->base);
976 }
977
Tvrtko Ursulin29b74b72016-11-16 08:55:39 +0000978 i915_redisable_vga_power_on(dev_priv);
Imre Deak8090ba82016-08-10 14:07:33 +0300979
980 intel_pps_unlock_regs_wa(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200981}
982
Ville Syrjälä2be7d542015-06-29 15:25:51 +0300983static void vlv_display_power_well_deinit(struct drm_i915_private *dev_priv)
984{
985 spin_lock_irq(&dev_priv->irq_lock);
986 valleyview_disable_display_irqs(dev_priv);
987 spin_unlock_irq(&dev_priv->irq_lock);
988
Ville Syrjälä2230fde2016-02-19 18:41:52 +0200989 /* make sure we're done processing display irqs */
Chris Wilson91c8a322016-07-05 10:40:23 +0100990 synchronize_irq(dev_priv->drm.irq);
Ville Syrjälä2230fde2016-02-19 18:41:52 +0200991
Imre Deak78597992016-06-16 16:37:20 +0300992 intel_power_sequencer_reset(dev_priv);
Lyude19625e82016-06-21 17:03:44 -0400993
Lyudeb64b5402016-10-26 12:36:09 -0400994 /* Prevent us from re-enabling polling on accident in late suspend */
995 if (!dev_priv->drm.dev->power.is_suspended)
996 intel_hpd_poll_init(dev_priv);
Ville Syrjälä2be7d542015-06-29 15:25:51 +0300997}
998
999static void vlv_display_power_well_enable(struct drm_i915_private *dev_priv,
1000 struct i915_power_well *power_well)
1001{
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001002 WARN_ON_ONCE(power_well->id != PUNIT_POWER_WELL_DISP2D);
Ville Syrjälä2be7d542015-06-29 15:25:51 +03001003
1004 vlv_set_power_well(dev_priv, power_well, true);
1005
1006 vlv_display_power_well_init(dev_priv);
1007}
1008
Daniel Vetter9c065a72014-09-30 10:56:38 +02001009static void vlv_display_power_well_disable(struct drm_i915_private *dev_priv,
1010 struct i915_power_well *power_well)
1011{
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001012 WARN_ON_ONCE(power_well->id != PUNIT_POWER_WELL_DISP2D);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001013
Ville Syrjälä2be7d542015-06-29 15:25:51 +03001014 vlv_display_power_well_deinit(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001015
1016 vlv_set_power_well(dev_priv, power_well, false);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001017}
1018
1019static void vlv_dpio_cmn_power_well_enable(struct drm_i915_private *dev_priv,
1020 struct i915_power_well *power_well)
1021{
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001022 WARN_ON_ONCE(power_well->id != PUNIT_POWER_WELL_DPIO_CMN_BC);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001023
Ville Syrjälä5a8fbb72015-06-29 15:25:53 +03001024 /* since ref/cri clock was enabled */
Daniel Vetter9c065a72014-09-30 10:56:38 +02001025 udelay(1); /* >10ns for cmnreset, >0ns for sidereset */
1026
1027 vlv_set_power_well(dev_priv, power_well, true);
1028
1029 /*
1030 * From VLV2A0_DP_eDP_DPIO_driver_vbios_notes_10.docx -
1031 * 6. De-assert cmn_reset/side_reset. Same as VLV X0.
1032 * a. GUnit 0x2110 bit[0] set to 1 (def 0)
1033 * b. The other bits such as sfr settings / modesel may all
1034 * be set to 0.
1035 *
1036 * This should only be done on init and resume from S3 with
1037 * both PLLs disabled, or we risk losing DPIO and PLL
1038 * synchronization.
1039 */
1040 I915_WRITE(DPIO_CTL, I915_READ(DPIO_CTL) | DPIO_CMNRST);
1041}
1042
1043static void vlv_dpio_cmn_power_well_disable(struct drm_i915_private *dev_priv,
1044 struct i915_power_well *power_well)
1045{
1046 enum pipe pipe;
1047
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001048 WARN_ON_ONCE(power_well->id != PUNIT_POWER_WELL_DPIO_CMN_BC);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001049
1050 for_each_pipe(dev_priv, pipe)
1051 assert_pll_disabled(dev_priv, pipe);
1052
1053 /* Assert common reset */
1054 I915_WRITE(DPIO_CTL, I915_READ(DPIO_CTL) & ~DPIO_CMNRST);
1055
1056 vlv_set_power_well(dev_priv, power_well, false);
1057}
1058
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001059#define POWER_DOMAIN_MASK (GENMASK_ULL(POWER_DOMAIN_NUM - 1, 0))
Ville Syrjälä30142272015-07-08 23:46:01 +03001060
Imre Deak438b8dc2017-07-11 23:42:30 +03001061static struct i915_power_well *
1062lookup_power_well(struct drm_i915_private *dev_priv,
1063 enum i915_power_well_id power_well_id)
Ville Syrjälä30142272015-07-08 23:46:01 +03001064{
1065 struct i915_power_domains *power_domains = &dev_priv->power_domains;
Ville Syrjälä30142272015-07-08 23:46:01 +03001066 int i;
1067
Imre Deakfc17f222015-11-04 19:24:11 +02001068 for (i = 0; i < power_domains->power_well_count; i++) {
1069 struct i915_power_well *power_well;
1070
1071 power_well = &power_domains->power_wells[i];
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001072 if (power_well->id == power_well_id)
Ville Syrjälä30142272015-07-08 23:46:01 +03001073 return power_well;
1074 }
1075
1076 return NULL;
1077}
1078
1079#define BITS_SET(val, bits) (((val) & (bits)) == (bits))
1080
1081static void assert_chv_phy_status(struct drm_i915_private *dev_priv)
1082{
1083 struct i915_power_well *cmn_bc =
1084 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_BC);
1085 struct i915_power_well *cmn_d =
1086 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_D);
1087 u32 phy_control = dev_priv->chv_phy_control;
1088 u32 phy_status = 0;
Ville Syrjälä3be60de2015-09-08 18:05:45 +03001089 u32 phy_status_mask = 0xffffffff;
Ville Syrjälä30142272015-07-08 23:46:01 +03001090
Ville Syrjälä3be60de2015-09-08 18:05:45 +03001091 /*
1092 * The BIOS can leave the PHY is some weird state
1093 * where it doesn't fully power down some parts.
1094 * Disable the asserts until the PHY has been fully
1095 * reset (ie. the power well has been disabled at
1096 * least once).
1097 */
1098 if (!dev_priv->chv_phy_assert[DPIO_PHY0])
1099 phy_status_mask &= ~(PHY_STATUS_CMN_LDO(DPIO_PHY0, DPIO_CH0) |
1100 PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH0, 0) |
1101 PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH0, 1) |
1102 PHY_STATUS_CMN_LDO(DPIO_PHY0, DPIO_CH1) |
1103 PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH1, 0) |
1104 PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH1, 1));
1105
1106 if (!dev_priv->chv_phy_assert[DPIO_PHY1])
1107 phy_status_mask &= ~(PHY_STATUS_CMN_LDO(DPIO_PHY1, DPIO_CH0) |
1108 PHY_STATUS_SPLINE_LDO(DPIO_PHY1, DPIO_CH0, 0) |
1109 PHY_STATUS_SPLINE_LDO(DPIO_PHY1, DPIO_CH0, 1));
1110
Ville Syrjälä30142272015-07-08 23:46:01 +03001111 if (cmn_bc->ops->is_enabled(dev_priv, cmn_bc)) {
1112 phy_status |= PHY_POWERGOOD(DPIO_PHY0);
1113
1114 /* this assumes override is only used to enable lanes */
1115 if ((phy_control & PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY0, DPIO_CH0)) == 0)
1116 phy_control |= PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH0);
1117
1118 if ((phy_control & PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY0, DPIO_CH1)) == 0)
1119 phy_control |= PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH1);
1120
1121 /* CL1 is on whenever anything is on in either channel */
1122 if (BITS_SET(phy_control,
1123 PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH0) |
1124 PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH1)))
1125 phy_status |= PHY_STATUS_CMN_LDO(DPIO_PHY0, DPIO_CH0);
1126
1127 /*
1128 * The DPLLB check accounts for the pipe B + port A usage
1129 * with CL2 powered up but all the lanes in the second channel
1130 * powered down.
1131 */
1132 if (BITS_SET(phy_control,
1133 PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH1)) &&
1134 (I915_READ(DPLL(PIPE_B)) & DPLL_VCO_ENABLE) == 0)
1135 phy_status |= PHY_STATUS_CMN_LDO(DPIO_PHY0, DPIO_CH1);
1136
1137 if (BITS_SET(phy_control,
1138 PHY_CH_POWER_DOWN_OVRD(0x3, DPIO_PHY0, DPIO_CH0)))
1139 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH0, 0);
1140 if (BITS_SET(phy_control,
1141 PHY_CH_POWER_DOWN_OVRD(0xc, DPIO_PHY0, DPIO_CH0)))
1142 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH0, 1);
1143
1144 if (BITS_SET(phy_control,
1145 PHY_CH_POWER_DOWN_OVRD(0x3, DPIO_PHY0, DPIO_CH1)))
1146 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH1, 0);
1147 if (BITS_SET(phy_control,
1148 PHY_CH_POWER_DOWN_OVRD(0xc, DPIO_PHY0, DPIO_CH1)))
1149 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH1, 1);
1150 }
1151
1152 if (cmn_d->ops->is_enabled(dev_priv, cmn_d)) {
1153 phy_status |= PHY_POWERGOOD(DPIO_PHY1);
1154
1155 /* this assumes override is only used to enable lanes */
1156 if ((phy_control & PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY1, DPIO_CH0)) == 0)
1157 phy_control |= PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY1, DPIO_CH0);
1158
1159 if (BITS_SET(phy_control,
1160 PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY1, DPIO_CH0)))
1161 phy_status |= PHY_STATUS_CMN_LDO(DPIO_PHY1, DPIO_CH0);
1162
1163 if (BITS_SET(phy_control,
1164 PHY_CH_POWER_DOWN_OVRD(0x3, DPIO_PHY1, DPIO_CH0)))
1165 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY1, DPIO_CH0, 0);
1166 if (BITS_SET(phy_control,
1167 PHY_CH_POWER_DOWN_OVRD(0xc, DPIO_PHY1, DPIO_CH0)))
1168 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY1, DPIO_CH0, 1);
1169 }
1170
Ville Syrjälä3be60de2015-09-08 18:05:45 +03001171 phy_status &= phy_status_mask;
1172
Ville Syrjälä30142272015-07-08 23:46:01 +03001173 /*
1174 * The PHY may be busy with some initial calibration and whatnot,
1175 * so the power state can take a while to actually change.
1176 */
Chris Wilson919fcd52016-06-30 15:33:35 +01001177 if (intel_wait_for_register(dev_priv,
1178 DISPLAY_PHY_STATUS,
1179 phy_status_mask,
1180 phy_status,
1181 10))
1182 DRM_ERROR("Unexpected PHY_STATUS 0x%08x, expected 0x%08x (PHY_CONTROL=0x%08x)\n",
1183 I915_READ(DISPLAY_PHY_STATUS) & phy_status_mask,
1184 phy_status, dev_priv->chv_phy_control);
Ville Syrjälä30142272015-07-08 23:46:01 +03001185}
1186
1187#undef BITS_SET
1188
Daniel Vetter9c065a72014-09-30 10:56:38 +02001189static void chv_dpio_cmn_power_well_enable(struct drm_i915_private *dev_priv,
1190 struct i915_power_well *power_well)
1191{
1192 enum dpio_phy phy;
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001193 enum pipe pipe;
1194 uint32_t tmp;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001195
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001196 WARN_ON_ONCE(power_well->id != PUNIT_POWER_WELL_DPIO_CMN_BC &&
1197 power_well->id != PUNIT_POWER_WELL_DPIO_CMN_D);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001198
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001199 if (power_well->id == PUNIT_POWER_WELL_DPIO_CMN_BC) {
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001200 pipe = PIPE_A;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001201 phy = DPIO_PHY0;
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001202 } else {
1203 pipe = PIPE_C;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001204 phy = DPIO_PHY1;
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001205 }
Ville Syrjälä5a8fbb72015-06-29 15:25:53 +03001206
1207 /* since ref/cri clock was enabled */
Daniel Vetter9c065a72014-09-30 10:56:38 +02001208 udelay(1); /* >10ns for cmnreset, >0ns for sidereset */
1209 vlv_set_power_well(dev_priv, power_well, true);
1210
1211 /* Poll for phypwrgood signal */
Chris Wilsonffebb832016-06-30 15:33:36 +01001212 if (intel_wait_for_register(dev_priv,
1213 DISPLAY_PHY_STATUS,
1214 PHY_POWERGOOD(phy),
1215 PHY_POWERGOOD(phy),
1216 1))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001217 DRM_ERROR("Display PHY %d is not power up\n", phy);
1218
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001219 mutex_lock(&dev_priv->sb_lock);
1220
1221 /* Enable dynamic power down */
1222 tmp = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW28);
Ville Syrjäläee279212015-07-08 23:45:57 +03001223 tmp |= DPIO_DYNPWRDOWNEN_CH0 | DPIO_CL1POWERDOWNEN |
1224 DPIO_SUS_CLK_CONFIG_GATE_CLKREQ;
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001225 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW28, tmp);
1226
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001227 if (power_well->id == PUNIT_POWER_WELL_DPIO_CMN_BC) {
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001228 tmp = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW6_CH1);
1229 tmp |= DPIO_DYNPWRDOWNEN_CH1;
1230 vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW6_CH1, tmp);
Ville Syrjälä3e288782015-07-08 23:45:58 +03001231 } else {
1232 /*
1233 * Force the non-existing CL2 off. BXT does this
1234 * too, so maybe it saves some power even though
1235 * CL2 doesn't exist?
1236 */
1237 tmp = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW30);
1238 tmp |= DPIO_CL2_LDOFUSE_PWRENB;
1239 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW30, tmp);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001240 }
1241
1242 mutex_unlock(&dev_priv->sb_lock);
1243
Ville Syrjälä70722462015-04-10 18:21:28 +03001244 dev_priv->chv_phy_control |= PHY_COM_LANE_RESET_DEASSERT(phy);
1245 I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001246
1247 DRM_DEBUG_KMS("Enabled DPIO PHY%d (PHY_CONTROL=0x%08x)\n",
1248 phy, dev_priv->chv_phy_control);
Ville Syrjälä30142272015-07-08 23:46:01 +03001249
1250 assert_chv_phy_status(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001251}
1252
1253static void chv_dpio_cmn_power_well_disable(struct drm_i915_private *dev_priv,
1254 struct i915_power_well *power_well)
1255{
1256 enum dpio_phy phy;
1257
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001258 WARN_ON_ONCE(power_well->id != PUNIT_POWER_WELL_DPIO_CMN_BC &&
1259 power_well->id != PUNIT_POWER_WELL_DPIO_CMN_D);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001260
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001261 if (power_well->id == PUNIT_POWER_WELL_DPIO_CMN_BC) {
Daniel Vetter9c065a72014-09-30 10:56:38 +02001262 phy = DPIO_PHY0;
1263 assert_pll_disabled(dev_priv, PIPE_A);
1264 assert_pll_disabled(dev_priv, PIPE_B);
1265 } else {
1266 phy = DPIO_PHY1;
1267 assert_pll_disabled(dev_priv, PIPE_C);
1268 }
1269
Ville Syrjälä70722462015-04-10 18:21:28 +03001270 dev_priv->chv_phy_control &= ~PHY_COM_LANE_RESET_DEASSERT(phy);
1271 I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001272
1273 vlv_set_power_well(dev_priv, power_well, false);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001274
1275 DRM_DEBUG_KMS("Disabled DPIO PHY%d (PHY_CONTROL=0x%08x)\n",
1276 phy, dev_priv->chv_phy_control);
Ville Syrjälä30142272015-07-08 23:46:01 +03001277
Ville Syrjälä3be60de2015-09-08 18:05:45 +03001278 /* PHY is fully reset now, so we can enable the PHY state asserts */
1279 dev_priv->chv_phy_assert[phy] = true;
1280
Ville Syrjälä30142272015-07-08 23:46:01 +03001281 assert_chv_phy_status(dev_priv);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001282}
1283
Ville Syrjälä6669e392015-07-08 23:46:00 +03001284static void assert_chv_phy_powergate(struct drm_i915_private *dev_priv, enum dpio_phy phy,
1285 enum dpio_channel ch, bool override, unsigned int mask)
1286{
1287 enum pipe pipe = phy == DPIO_PHY0 ? PIPE_A : PIPE_C;
1288 u32 reg, val, expected, actual;
1289
Ville Syrjälä3be60de2015-09-08 18:05:45 +03001290 /*
1291 * The BIOS can leave the PHY is some weird state
1292 * where it doesn't fully power down some parts.
1293 * Disable the asserts until the PHY has been fully
1294 * reset (ie. the power well has been disabled at
1295 * least once).
1296 */
1297 if (!dev_priv->chv_phy_assert[phy])
1298 return;
1299
Ville Syrjälä6669e392015-07-08 23:46:00 +03001300 if (ch == DPIO_CH0)
1301 reg = _CHV_CMN_DW0_CH0;
1302 else
1303 reg = _CHV_CMN_DW6_CH1;
1304
1305 mutex_lock(&dev_priv->sb_lock);
1306 val = vlv_dpio_read(dev_priv, pipe, reg);
1307 mutex_unlock(&dev_priv->sb_lock);
1308
1309 /*
1310 * This assumes !override is only used when the port is disabled.
1311 * All lanes should power down even without the override when
1312 * the port is disabled.
1313 */
1314 if (!override || mask == 0xf) {
1315 expected = DPIO_ALLDL_POWERDOWN | DPIO_ANYDL_POWERDOWN;
1316 /*
1317 * If CH1 common lane is not active anymore
1318 * (eg. for pipe B DPLL) the entire channel will
1319 * shut down, which causes the common lane registers
1320 * to read as 0. That means we can't actually check
1321 * the lane power down status bits, but as the entire
1322 * register reads as 0 it's a good indication that the
1323 * channel is indeed entirely powered down.
1324 */
1325 if (ch == DPIO_CH1 && val == 0)
1326 expected = 0;
1327 } else if (mask != 0x0) {
1328 expected = DPIO_ANYDL_POWERDOWN;
1329 } else {
1330 expected = 0;
1331 }
1332
1333 if (ch == DPIO_CH0)
1334 actual = val >> DPIO_ANYDL_POWERDOWN_SHIFT_CH0;
1335 else
1336 actual = val >> DPIO_ANYDL_POWERDOWN_SHIFT_CH1;
1337 actual &= DPIO_ALLDL_POWERDOWN | DPIO_ANYDL_POWERDOWN;
1338
1339 WARN(actual != expected,
1340 "Unexpected DPIO lane power down: all %d, any %d. Expected: all %d, any %d. (0x%x = 0x%08x)\n",
1341 !!(actual & DPIO_ALLDL_POWERDOWN), !!(actual & DPIO_ANYDL_POWERDOWN),
1342 !!(expected & DPIO_ALLDL_POWERDOWN), !!(expected & DPIO_ANYDL_POWERDOWN),
1343 reg, val);
1344}
1345
Ville Syrjäläb0b33842015-07-08 23:45:55 +03001346bool chv_phy_powergate_ch(struct drm_i915_private *dev_priv, enum dpio_phy phy,
1347 enum dpio_channel ch, bool override)
1348{
1349 struct i915_power_domains *power_domains = &dev_priv->power_domains;
1350 bool was_override;
1351
1352 mutex_lock(&power_domains->lock);
1353
1354 was_override = dev_priv->chv_phy_control & PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
1355
1356 if (override == was_override)
1357 goto out;
1358
1359 if (override)
1360 dev_priv->chv_phy_control |= PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
1361 else
1362 dev_priv->chv_phy_control &= ~PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
1363
1364 I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
1365
1366 DRM_DEBUG_KMS("Power gating DPIO PHY%d CH%d (DPIO_PHY_CONTROL=0x%08x)\n",
1367 phy, ch, dev_priv->chv_phy_control);
1368
Ville Syrjälä30142272015-07-08 23:46:01 +03001369 assert_chv_phy_status(dev_priv);
1370
Ville Syrjäläb0b33842015-07-08 23:45:55 +03001371out:
1372 mutex_unlock(&power_domains->lock);
1373
1374 return was_override;
1375}
1376
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001377void chv_phy_powergate_lanes(struct intel_encoder *encoder,
1378 bool override, unsigned int mask)
1379{
1380 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
1381 struct i915_power_domains *power_domains = &dev_priv->power_domains;
1382 enum dpio_phy phy = vlv_dport_to_phy(enc_to_dig_port(&encoder->base));
1383 enum dpio_channel ch = vlv_dport_to_channel(enc_to_dig_port(&encoder->base));
1384
1385 mutex_lock(&power_domains->lock);
1386
1387 dev_priv->chv_phy_control &= ~PHY_CH_POWER_DOWN_OVRD(0xf, phy, ch);
1388 dev_priv->chv_phy_control |= PHY_CH_POWER_DOWN_OVRD(mask, phy, ch);
1389
1390 if (override)
1391 dev_priv->chv_phy_control |= PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
1392 else
1393 dev_priv->chv_phy_control &= ~PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
1394
1395 I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
1396
1397 DRM_DEBUG_KMS("Power gating DPIO PHY%d CH%d lanes 0x%x (PHY_CONTROL=0x%08x)\n",
1398 phy, ch, mask, dev_priv->chv_phy_control);
1399
Ville Syrjälä30142272015-07-08 23:46:01 +03001400 assert_chv_phy_status(dev_priv);
1401
Ville Syrjälä6669e392015-07-08 23:46:00 +03001402 assert_chv_phy_powergate(dev_priv, phy, ch, override, mask);
1403
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001404 mutex_unlock(&power_domains->lock);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001405}
1406
1407static bool chv_pipe_power_well_enabled(struct drm_i915_private *dev_priv,
1408 struct i915_power_well *power_well)
1409{
Imre Deakf49193c2017-07-06 17:40:23 +03001410 enum pipe pipe = PIPE_A;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001411 bool enabled;
1412 u32 state, ctrl;
1413
Sagar Arun Kamble9f817502017-10-10 22:30:05 +01001414 mutex_lock(&dev_priv->pcu_lock);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001415
1416 state = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & DP_SSS_MASK(pipe);
1417 /*
1418 * We only ever set the power-on and power-gate states, anything
1419 * else is unexpected.
1420 */
1421 WARN_ON(state != DP_SSS_PWR_ON(pipe) && state != DP_SSS_PWR_GATE(pipe));
1422 enabled = state == DP_SSS_PWR_ON(pipe);
1423
1424 /*
1425 * A transient state at this point would mean some unexpected party
1426 * is poking at the power controls too.
1427 */
1428 ctrl = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & DP_SSC_MASK(pipe);
1429 WARN_ON(ctrl << 16 != state);
1430
Sagar Arun Kamble9f817502017-10-10 22:30:05 +01001431 mutex_unlock(&dev_priv->pcu_lock);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001432
1433 return enabled;
1434}
1435
1436static void chv_set_pipe_power_well(struct drm_i915_private *dev_priv,
1437 struct i915_power_well *power_well,
1438 bool enable)
1439{
Imre Deakf49193c2017-07-06 17:40:23 +03001440 enum pipe pipe = PIPE_A;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001441 u32 state;
1442 u32 ctrl;
1443
1444 state = enable ? DP_SSS_PWR_ON(pipe) : DP_SSS_PWR_GATE(pipe);
1445
Sagar Arun Kamble9f817502017-10-10 22:30:05 +01001446 mutex_lock(&dev_priv->pcu_lock);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001447
1448#define COND \
1449 ((vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & DP_SSS_MASK(pipe)) == state)
1450
1451 if (COND)
1452 goto out;
1453
1454 ctrl = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ);
1455 ctrl &= ~DP_SSC_MASK(pipe);
1456 ctrl |= enable ? DP_SSC_PWR_ON(pipe) : DP_SSC_PWR_GATE(pipe);
1457 vlv_punit_write(dev_priv, PUNIT_REG_DSPFREQ, ctrl);
1458
1459 if (wait_for(COND, 100))
Masanari Iida7e35ab82015-05-10 01:00:23 +09001460 DRM_ERROR("timeout setting power well state %08x (%08x)\n",
Daniel Vetter9c065a72014-09-30 10:56:38 +02001461 state,
1462 vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ));
1463
1464#undef COND
1465
1466out:
Sagar Arun Kamble9f817502017-10-10 22:30:05 +01001467 mutex_unlock(&dev_priv->pcu_lock);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001468}
1469
Daniel Vetter9c065a72014-09-30 10:56:38 +02001470static void chv_pipe_power_well_enable(struct drm_i915_private *dev_priv,
1471 struct i915_power_well *power_well)
1472{
Imre Deakf49193c2017-07-06 17:40:23 +03001473 WARN_ON_ONCE(power_well->id != CHV_DISP_PW_PIPE_A);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001474
1475 chv_set_pipe_power_well(dev_priv, power_well, true);
Ville Syrjäläafd62752014-10-30 19:43:03 +02001476
Ville Syrjälä2be7d542015-06-29 15:25:51 +03001477 vlv_display_power_well_init(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001478}
1479
1480static void chv_pipe_power_well_disable(struct drm_i915_private *dev_priv,
1481 struct i915_power_well *power_well)
1482{
Imre Deakf49193c2017-07-06 17:40:23 +03001483 WARN_ON_ONCE(power_well->id != CHV_DISP_PW_PIPE_A);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001484
Ville Syrjälä2be7d542015-06-29 15:25:51 +03001485 vlv_display_power_well_deinit(dev_priv);
Ville Syrjäläafd62752014-10-30 19:43:03 +02001486
Daniel Vetter9c065a72014-09-30 10:56:38 +02001487 chv_set_pipe_power_well(dev_priv, power_well, false);
1488}
1489
Imre Deak09731282016-02-17 14:17:42 +02001490static void
1491__intel_display_power_get_domain(struct drm_i915_private *dev_priv,
1492 enum intel_display_power_domain domain)
1493{
1494 struct i915_power_domains *power_domains = &dev_priv->power_domains;
1495 struct i915_power_well *power_well;
Imre Deak09731282016-02-17 14:17:42 +02001496
Imre Deak75ccb2e2017-02-17 17:39:43 +02001497 for_each_power_domain_well(dev_priv, power_well, BIT_ULL(domain))
Imre Deakb409ca92016-06-13 16:44:33 +03001498 intel_power_well_get(dev_priv, power_well);
Imre Deak09731282016-02-17 14:17:42 +02001499
1500 power_domains->domain_use_count[domain]++;
1501}
1502
Daniel Vettere4e76842014-09-30 10:56:42 +02001503/**
1504 * intel_display_power_get - grab a power domain reference
1505 * @dev_priv: i915 device instance
1506 * @domain: power domain to reference
1507 *
1508 * This function grabs a power domain reference for @domain and ensures that the
1509 * power domain and all its parents are powered up. Therefore users should only
1510 * grab a reference to the innermost power domain they need.
1511 *
1512 * Any power domain reference obtained by this function must have a symmetric
1513 * call to intel_display_power_put() to release the reference again.
1514 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02001515void intel_display_power_get(struct drm_i915_private *dev_priv,
1516 enum intel_display_power_domain domain)
1517{
Imre Deak09731282016-02-17 14:17:42 +02001518 struct i915_power_domains *power_domains = &dev_priv->power_domains;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001519
1520 intel_runtime_pm_get(dev_priv);
1521
Imre Deak09731282016-02-17 14:17:42 +02001522 mutex_lock(&power_domains->lock);
1523
1524 __intel_display_power_get_domain(dev_priv, domain);
1525
1526 mutex_unlock(&power_domains->lock);
1527}
1528
1529/**
1530 * intel_display_power_get_if_enabled - grab a reference for an enabled display power domain
1531 * @dev_priv: i915 device instance
1532 * @domain: power domain to reference
1533 *
1534 * This function grabs a power domain reference for @domain and ensures that the
1535 * power domain and all its parents are powered up. Therefore users should only
1536 * grab a reference to the innermost power domain they need.
1537 *
1538 * Any power domain reference obtained by this function must have a symmetric
1539 * call to intel_display_power_put() to release the reference again.
1540 */
1541bool intel_display_power_get_if_enabled(struct drm_i915_private *dev_priv,
1542 enum intel_display_power_domain domain)
1543{
1544 struct i915_power_domains *power_domains = &dev_priv->power_domains;
1545 bool is_enabled;
1546
1547 if (!intel_runtime_pm_get_if_in_use(dev_priv))
1548 return false;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001549
1550 mutex_lock(&power_domains->lock);
1551
Imre Deak09731282016-02-17 14:17:42 +02001552 if (__intel_display_power_is_enabled(dev_priv, domain)) {
1553 __intel_display_power_get_domain(dev_priv, domain);
1554 is_enabled = true;
1555 } else {
1556 is_enabled = false;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001557 }
1558
Daniel Vetter9c065a72014-09-30 10:56:38 +02001559 mutex_unlock(&power_domains->lock);
Imre Deak09731282016-02-17 14:17:42 +02001560
1561 if (!is_enabled)
1562 intel_runtime_pm_put(dev_priv);
1563
1564 return is_enabled;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001565}
1566
Daniel Vettere4e76842014-09-30 10:56:42 +02001567/**
1568 * intel_display_power_put - release a power domain reference
1569 * @dev_priv: i915 device instance
1570 * @domain: power domain to reference
1571 *
1572 * This function drops the power domain reference obtained by
1573 * intel_display_power_get() and might power down the corresponding hardware
1574 * block right away if this is the last reference.
1575 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02001576void intel_display_power_put(struct drm_i915_private *dev_priv,
1577 enum intel_display_power_domain domain)
1578{
1579 struct i915_power_domains *power_domains;
1580 struct i915_power_well *power_well;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001581
1582 power_domains = &dev_priv->power_domains;
1583
1584 mutex_lock(&power_domains->lock);
1585
Daniel Stone11c86db2015-11-20 15:55:34 +00001586 WARN(!power_domains->domain_use_count[domain],
1587 "Use count on domain %s is already zero\n",
1588 intel_display_power_domain_str(domain));
Daniel Vetter9c065a72014-09-30 10:56:38 +02001589 power_domains->domain_use_count[domain]--;
1590
Imre Deak75ccb2e2017-02-17 17:39:43 +02001591 for_each_power_domain_well_rev(dev_priv, power_well, BIT_ULL(domain))
Imre Deakb409ca92016-06-13 16:44:33 +03001592 intel_power_well_put(dev_priv, power_well);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001593
1594 mutex_unlock(&power_domains->lock);
1595
1596 intel_runtime_pm_put(dev_priv);
1597}
1598
Imre Deak965a79a2017-07-06 17:40:40 +03001599#define I830_PIPES_POWER_DOMAINS ( \
1600 BIT_ULL(POWER_DOMAIN_PIPE_A) | \
1601 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
1602 BIT_ULL(POWER_DOMAIN_PIPE_A_PANEL_FITTER) | \
1603 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1604 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
1605 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001606 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001607
Ville Syrjälä465ac0c2016-04-18 14:02:27 +03001608#define VLV_DISPLAY_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001609 BIT_ULL(POWER_DOMAIN_PIPE_A) | \
1610 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
1611 BIT_ULL(POWER_DOMAIN_PIPE_A_PANEL_FITTER) | \
1612 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1613 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
1614 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
1615 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1616 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1617 BIT_ULL(POWER_DOMAIN_PORT_DSI) | \
1618 BIT_ULL(POWER_DOMAIN_PORT_CRT) | \
1619 BIT_ULL(POWER_DOMAIN_VGA) | \
1620 BIT_ULL(POWER_DOMAIN_AUDIO) | \
1621 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1622 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1623 BIT_ULL(POWER_DOMAIN_GMBUS) | \
1624 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001625
1626#define VLV_DPIO_CMN_BC_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001627 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1628 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1629 BIT_ULL(POWER_DOMAIN_PORT_CRT) | \
1630 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1631 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1632 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001633
1634#define VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001635 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1636 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1637 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001638
1639#define VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001640 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1641 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1642 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001643
1644#define VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001645 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1646 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1647 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001648
1649#define VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001650 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1651 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1652 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001653
Ville Syrjälä465ac0c2016-04-18 14:02:27 +03001654#define CHV_DISPLAY_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001655 BIT_ULL(POWER_DOMAIN_PIPE_A) | \
1656 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
1657 BIT_ULL(POWER_DOMAIN_PIPE_C) | \
1658 BIT_ULL(POWER_DOMAIN_PIPE_A_PANEL_FITTER) | \
1659 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1660 BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
1661 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
1662 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
1663 BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
1664 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1665 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1666 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_LANES) | \
1667 BIT_ULL(POWER_DOMAIN_PORT_DSI) | \
1668 BIT_ULL(POWER_DOMAIN_VGA) | \
1669 BIT_ULL(POWER_DOMAIN_AUDIO) | \
1670 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1671 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1672 BIT_ULL(POWER_DOMAIN_AUX_D) | \
1673 BIT_ULL(POWER_DOMAIN_GMBUS) | \
1674 BIT_ULL(POWER_DOMAIN_INIT))
Ville Syrjälä465ac0c2016-04-18 14:02:27 +03001675
Daniel Vetter9c065a72014-09-30 10:56:38 +02001676#define CHV_DPIO_CMN_BC_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001677 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1678 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1679 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1680 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1681 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001682
1683#define CHV_DPIO_CMN_D_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001684 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_LANES) | \
1685 BIT_ULL(POWER_DOMAIN_AUX_D) | \
1686 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001687
Imre Deak965a79a2017-07-06 17:40:40 +03001688#define HSW_DISPLAY_POWER_DOMAINS ( \
1689 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
1690 BIT_ULL(POWER_DOMAIN_PIPE_C) | \
1691 BIT_ULL(POWER_DOMAIN_PIPE_A_PANEL_FITTER) | \
1692 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1693 BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
1694 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
1695 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
1696 BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
1697 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1698 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1699 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_LANES) | \
1700 BIT_ULL(POWER_DOMAIN_PORT_CRT) | /* DDI E */ \
1701 BIT_ULL(POWER_DOMAIN_VGA) | \
1702 BIT_ULL(POWER_DOMAIN_AUDIO) | \
1703 BIT_ULL(POWER_DOMAIN_INIT))
1704
1705#define BDW_DISPLAY_POWER_DOMAINS ( \
1706 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
1707 BIT_ULL(POWER_DOMAIN_PIPE_C) | \
1708 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1709 BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
1710 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
1711 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
1712 BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
1713 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1714 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1715 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_LANES) | \
1716 BIT_ULL(POWER_DOMAIN_PORT_CRT) | /* DDI E */ \
1717 BIT_ULL(POWER_DOMAIN_VGA) | \
1718 BIT_ULL(POWER_DOMAIN_AUDIO) | \
1719 BIT_ULL(POWER_DOMAIN_INIT))
1720
1721#define SKL_DISPLAY_POWERWELL_2_POWER_DOMAINS ( \
1722 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
1723 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
1724 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
1725 BIT_ULL(POWER_DOMAIN_PIPE_C) | \
1726 BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
1727 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1728 BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
1729 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1730 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1731 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_LANES) | \
1732 BIT_ULL(POWER_DOMAIN_PORT_DDI_E_LANES) | \
1733 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1734 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1735 BIT_ULL(POWER_DOMAIN_AUX_D) | \
1736 BIT_ULL(POWER_DOMAIN_AUDIO) | \
1737 BIT_ULL(POWER_DOMAIN_VGA) | \
1738 BIT_ULL(POWER_DOMAIN_INIT))
1739#define SKL_DISPLAY_DDI_IO_A_E_POWER_DOMAINS ( \
1740 BIT_ULL(POWER_DOMAIN_PORT_DDI_A_IO) | \
1741 BIT_ULL(POWER_DOMAIN_PORT_DDI_E_IO) | \
1742 BIT_ULL(POWER_DOMAIN_INIT))
1743#define SKL_DISPLAY_DDI_IO_B_POWER_DOMAINS ( \
1744 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_IO) | \
1745 BIT_ULL(POWER_DOMAIN_INIT))
1746#define SKL_DISPLAY_DDI_IO_C_POWER_DOMAINS ( \
1747 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_IO) | \
1748 BIT_ULL(POWER_DOMAIN_INIT))
1749#define SKL_DISPLAY_DDI_IO_D_POWER_DOMAINS ( \
1750 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_IO) | \
1751 BIT_ULL(POWER_DOMAIN_INIT))
1752#define SKL_DISPLAY_DC_OFF_POWER_DOMAINS ( \
1753 SKL_DISPLAY_POWERWELL_2_POWER_DOMAINS | \
Tvrtko Ursulinb6876372017-12-05 13:28:54 +00001754 BIT_ULL(POWER_DOMAIN_GT_IRQ) | \
Imre Deak965a79a2017-07-06 17:40:40 +03001755 BIT_ULL(POWER_DOMAIN_MODESET) | \
1756 BIT_ULL(POWER_DOMAIN_AUX_A) | \
1757 BIT_ULL(POWER_DOMAIN_INIT))
1758
1759#define BXT_DISPLAY_POWERWELL_2_POWER_DOMAINS ( \
1760 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
1761 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
1762 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
1763 BIT_ULL(POWER_DOMAIN_PIPE_C) | \
1764 BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
1765 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1766 BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
1767 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1768 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1769 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1770 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1771 BIT_ULL(POWER_DOMAIN_AUDIO) | \
1772 BIT_ULL(POWER_DOMAIN_VGA) | \
Imre Deak965a79a2017-07-06 17:40:40 +03001773 BIT_ULL(POWER_DOMAIN_INIT))
1774#define BXT_DISPLAY_DC_OFF_POWER_DOMAINS ( \
1775 BXT_DISPLAY_POWERWELL_2_POWER_DOMAINS | \
Tvrtko Ursulinb6876372017-12-05 13:28:54 +00001776 BIT_ULL(POWER_DOMAIN_GT_IRQ) | \
Imre Deak965a79a2017-07-06 17:40:40 +03001777 BIT_ULL(POWER_DOMAIN_MODESET) | \
1778 BIT_ULL(POWER_DOMAIN_AUX_A) | \
Ville Syrjälä54c105d2017-12-08 23:37:37 +02001779 BIT_ULL(POWER_DOMAIN_GMBUS) | \
Imre Deak965a79a2017-07-06 17:40:40 +03001780 BIT_ULL(POWER_DOMAIN_INIT))
1781#define BXT_DPIO_CMN_A_POWER_DOMAINS ( \
1782 BIT_ULL(POWER_DOMAIN_PORT_DDI_A_LANES) | \
1783 BIT_ULL(POWER_DOMAIN_AUX_A) | \
1784 BIT_ULL(POWER_DOMAIN_INIT))
1785#define BXT_DPIO_CMN_BC_POWER_DOMAINS ( \
1786 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1787 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1788 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1789 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1790 BIT_ULL(POWER_DOMAIN_INIT))
1791
1792#define GLK_DISPLAY_POWERWELL_2_POWER_DOMAINS ( \
1793 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
1794 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
1795 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
1796 BIT_ULL(POWER_DOMAIN_PIPE_C) | \
1797 BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
1798 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1799 BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
1800 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1801 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1802 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1803 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1804 BIT_ULL(POWER_DOMAIN_AUDIO) | \
1805 BIT_ULL(POWER_DOMAIN_VGA) | \
1806 BIT_ULL(POWER_DOMAIN_INIT))
1807#define GLK_DISPLAY_DDI_IO_A_POWER_DOMAINS ( \
1808 BIT_ULL(POWER_DOMAIN_PORT_DDI_A_IO))
1809#define GLK_DISPLAY_DDI_IO_B_POWER_DOMAINS ( \
1810 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_IO))
1811#define GLK_DISPLAY_DDI_IO_C_POWER_DOMAINS ( \
1812 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_IO))
1813#define GLK_DPIO_CMN_A_POWER_DOMAINS ( \
1814 BIT_ULL(POWER_DOMAIN_PORT_DDI_A_LANES) | \
1815 BIT_ULL(POWER_DOMAIN_AUX_A) | \
1816 BIT_ULL(POWER_DOMAIN_INIT))
1817#define GLK_DPIO_CMN_B_POWER_DOMAINS ( \
1818 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1819 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1820 BIT_ULL(POWER_DOMAIN_INIT))
1821#define GLK_DPIO_CMN_C_POWER_DOMAINS ( \
1822 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1823 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1824 BIT_ULL(POWER_DOMAIN_INIT))
1825#define GLK_DISPLAY_AUX_A_POWER_DOMAINS ( \
1826 BIT_ULL(POWER_DOMAIN_AUX_A) | \
Imre Deak52528052018-06-21 21:44:49 +03001827 BIT_ULL(POWER_DOMAIN_AUX_IO_A) | \
Imre Deak965a79a2017-07-06 17:40:40 +03001828 BIT_ULL(POWER_DOMAIN_INIT))
1829#define GLK_DISPLAY_AUX_B_POWER_DOMAINS ( \
1830 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1831 BIT_ULL(POWER_DOMAIN_INIT))
1832#define GLK_DISPLAY_AUX_C_POWER_DOMAINS ( \
1833 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1834 BIT_ULL(POWER_DOMAIN_INIT))
1835#define GLK_DISPLAY_DC_OFF_POWER_DOMAINS ( \
1836 GLK_DISPLAY_POWERWELL_2_POWER_DOMAINS | \
Tvrtko Ursulinb6876372017-12-05 13:28:54 +00001837 BIT_ULL(POWER_DOMAIN_GT_IRQ) | \
Imre Deak965a79a2017-07-06 17:40:40 +03001838 BIT_ULL(POWER_DOMAIN_MODESET) | \
1839 BIT_ULL(POWER_DOMAIN_AUX_A) | \
Ville Syrjälä156961a2017-12-08 23:37:36 +02001840 BIT_ULL(POWER_DOMAIN_GMBUS) | \
Imre Deak965a79a2017-07-06 17:40:40 +03001841 BIT_ULL(POWER_DOMAIN_INIT))
1842
1843#define CNL_DISPLAY_POWERWELL_2_POWER_DOMAINS ( \
1844 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
1845 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
1846 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
1847 BIT_ULL(POWER_DOMAIN_PIPE_C) | \
1848 BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
1849 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1850 BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
1851 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1852 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1853 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_LANES) | \
Rodrigo Vivi9787e832018-01-29 15:22:22 -08001854 BIT_ULL(POWER_DOMAIN_PORT_DDI_F_LANES) | \
Imre Deak965a79a2017-07-06 17:40:40 +03001855 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1856 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1857 BIT_ULL(POWER_DOMAIN_AUX_D) | \
Rodrigo Vivia324fca2018-01-29 15:22:15 -08001858 BIT_ULL(POWER_DOMAIN_AUX_F) | \
Imre Deak965a79a2017-07-06 17:40:40 +03001859 BIT_ULL(POWER_DOMAIN_AUDIO) | \
1860 BIT_ULL(POWER_DOMAIN_VGA) | \
1861 BIT_ULL(POWER_DOMAIN_INIT))
1862#define CNL_DISPLAY_DDI_A_IO_POWER_DOMAINS ( \
1863 BIT_ULL(POWER_DOMAIN_PORT_DDI_A_IO) | \
Imre Deak965a79a2017-07-06 17:40:40 +03001864 BIT_ULL(POWER_DOMAIN_INIT))
1865#define CNL_DISPLAY_DDI_B_IO_POWER_DOMAINS ( \
1866 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_IO) | \
1867 BIT_ULL(POWER_DOMAIN_INIT))
1868#define CNL_DISPLAY_DDI_C_IO_POWER_DOMAINS ( \
1869 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_IO) | \
1870 BIT_ULL(POWER_DOMAIN_INIT))
1871#define CNL_DISPLAY_DDI_D_IO_POWER_DOMAINS ( \
1872 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_IO) | \
1873 BIT_ULL(POWER_DOMAIN_INIT))
1874#define CNL_DISPLAY_AUX_A_POWER_DOMAINS ( \
1875 BIT_ULL(POWER_DOMAIN_AUX_A) | \
Dhinakaran Pandiyanb891d5e2018-02-23 14:15:15 -08001876 BIT_ULL(POWER_DOMAIN_AUX_IO_A) | \
Imre Deak965a79a2017-07-06 17:40:40 +03001877 BIT_ULL(POWER_DOMAIN_INIT))
1878#define CNL_DISPLAY_AUX_B_POWER_DOMAINS ( \
1879 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1880 BIT_ULL(POWER_DOMAIN_INIT))
1881#define CNL_DISPLAY_AUX_C_POWER_DOMAINS ( \
1882 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1883 BIT_ULL(POWER_DOMAIN_INIT))
1884#define CNL_DISPLAY_AUX_D_POWER_DOMAINS ( \
1885 BIT_ULL(POWER_DOMAIN_AUX_D) | \
1886 BIT_ULL(POWER_DOMAIN_INIT))
Rodrigo Vivia324fca2018-01-29 15:22:15 -08001887#define CNL_DISPLAY_AUX_F_POWER_DOMAINS ( \
1888 BIT_ULL(POWER_DOMAIN_AUX_F) | \
1889 BIT_ULL(POWER_DOMAIN_INIT))
Rodrigo Vivi9787e832018-01-29 15:22:22 -08001890#define CNL_DISPLAY_DDI_F_IO_POWER_DOMAINS ( \
1891 BIT_ULL(POWER_DOMAIN_PORT_DDI_F_IO) | \
1892 BIT_ULL(POWER_DOMAIN_INIT))
Imre Deak965a79a2017-07-06 17:40:40 +03001893#define CNL_DISPLAY_DC_OFF_POWER_DOMAINS ( \
1894 CNL_DISPLAY_POWERWELL_2_POWER_DOMAINS | \
Tvrtko Ursulin6e7a3f52018-01-11 08:24:17 +00001895 BIT_ULL(POWER_DOMAIN_GT_IRQ) | \
Imre Deak965a79a2017-07-06 17:40:40 +03001896 BIT_ULL(POWER_DOMAIN_MODESET) | \
1897 BIT_ULL(POWER_DOMAIN_AUX_A) | \
Ville Syrjälä2ee0da12017-06-01 17:36:16 +03001898 BIT_ULL(POWER_DOMAIN_INIT))
1899
Daniel Vetter9c065a72014-09-30 10:56:38 +02001900static const struct i915_power_well_ops i9xx_always_on_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02001901 .sync_hw = i9xx_power_well_sync_hw_noop,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001902 .enable = i9xx_always_on_power_well_noop,
1903 .disable = i9xx_always_on_power_well_noop,
1904 .is_enabled = i9xx_always_on_power_well_enabled,
1905};
1906
1907static const struct i915_power_well_ops chv_pipe_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02001908 .sync_hw = i9xx_power_well_sync_hw_noop,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001909 .enable = chv_pipe_power_well_enable,
1910 .disable = chv_pipe_power_well_disable,
1911 .is_enabled = chv_pipe_power_well_enabled,
1912};
1913
1914static const struct i915_power_well_ops chv_dpio_cmn_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02001915 .sync_hw = i9xx_power_well_sync_hw_noop,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001916 .enable = chv_dpio_cmn_power_well_enable,
1917 .disable = chv_dpio_cmn_power_well_disable,
1918 .is_enabled = vlv_power_well_enabled,
1919};
1920
1921static struct i915_power_well i9xx_always_on_power_well[] = {
1922 {
1923 .name = "always-on",
1924 .always_on = 1,
1925 .domains = POWER_DOMAIN_MASK,
1926 .ops = &i9xx_always_on_power_well_ops,
Imre Deak029d80d2017-07-06 17:40:25 +03001927 .id = I915_DISP_PW_ALWAYS_ON,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001928 },
1929};
1930
Ville Syrjälä2ee0da12017-06-01 17:36:16 +03001931static const struct i915_power_well_ops i830_pipes_power_well_ops = {
1932 .sync_hw = i830_pipes_power_well_sync_hw,
1933 .enable = i830_pipes_power_well_enable,
1934 .disable = i830_pipes_power_well_disable,
1935 .is_enabled = i830_pipes_power_well_enabled,
1936};
1937
1938static struct i915_power_well i830_power_wells[] = {
1939 {
1940 .name = "always-on",
1941 .always_on = 1,
1942 .domains = POWER_DOMAIN_MASK,
1943 .ops = &i9xx_always_on_power_well_ops,
Imre Deak029d80d2017-07-06 17:40:25 +03001944 .id = I915_DISP_PW_ALWAYS_ON,
Ville Syrjälä2ee0da12017-06-01 17:36:16 +03001945 },
1946 {
1947 .name = "pipes",
1948 .domains = I830_PIPES_POWER_DOMAINS,
1949 .ops = &i830_pipes_power_well_ops,
Imre Deak120b56a2017-07-11 23:42:31 +03001950 .id = I830_DISP_PW_PIPES,
Ville Syrjälä2ee0da12017-06-01 17:36:16 +03001951 },
1952};
1953
Daniel Vetter9c065a72014-09-30 10:56:38 +02001954static const struct i915_power_well_ops hsw_power_well_ops = {
1955 .sync_hw = hsw_power_well_sync_hw,
1956 .enable = hsw_power_well_enable,
1957 .disable = hsw_power_well_disable,
1958 .is_enabled = hsw_power_well_enabled,
1959};
1960
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01001961static const struct i915_power_well_ops gen9_dc_off_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02001962 .sync_hw = i9xx_power_well_sync_hw_noop,
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01001963 .enable = gen9_dc_off_power_well_enable,
1964 .disable = gen9_dc_off_power_well_disable,
1965 .is_enabled = gen9_dc_off_power_well_enabled,
1966};
1967
Imre Deak9c8d0b82016-06-13 16:44:34 +03001968static const struct i915_power_well_ops bxt_dpio_cmn_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02001969 .sync_hw = i9xx_power_well_sync_hw_noop,
Imre Deak9c8d0b82016-06-13 16:44:34 +03001970 .enable = bxt_dpio_cmn_power_well_enable,
1971 .disable = bxt_dpio_cmn_power_well_disable,
1972 .is_enabled = bxt_dpio_cmn_power_well_enabled,
1973};
1974
Daniel Vetter9c065a72014-09-30 10:56:38 +02001975static struct i915_power_well hsw_power_wells[] = {
1976 {
1977 .name = "always-on",
1978 .always_on = 1,
Ville Syrjälä998bd662016-04-18 14:02:26 +03001979 .domains = POWER_DOMAIN_MASK,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001980 .ops = &i9xx_always_on_power_well_ops,
Imre Deak029d80d2017-07-06 17:40:25 +03001981 .id = I915_DISP_PW_ALWAYS_ON,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001982 },
1983 {
1984 .name = "display",
1985 .domains = HSW_DISPLAY_POWER_DOMAINS,
1986 .ops = &hsw_power_well_ops,
Imre Deakfb9248e2017-07-11 23:42:32 +03001987 .id = HSW_DISP_PW_GLOBAL,
Imre Deak0a445942017-08-14 18:15:29 +03001988 {
1989 .hsw.has_vga = true,
1990 },
Daniel Vetter9c065a72014-09-30 10:56:38 +02001991 },
1992};
1993
1994static struct i915_power_well bdw_power_wells[] = {
1995 {
1996 .name = "always-on",
1997 .always_on = 1,
Ville Syrjälä998bd662016-04-18 14:02:26 +03001998 .domains = POWER_DOMAIN_MASK,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001999 .ops = &i9xx_always_on_power_well_ops,
Imre Deak029d80d2017-07-06 17:40:25 +03002000 .id = I915_DISP_PW_ALWAYS_ON,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002001 },
2002 {
2003 .name = "display",
2004 .domains = BDW_DISPLAY_POWER_DOMAINS,
2005 .ops = &hsw_power_well_ops,
Imre Deakfb9248e2017-07-11 23:42:32 +03002006 .id = HSW_DISP_PW_GLOBAL,
Imre Deak0a445942017-08-14 18:15:29 +03002007 {
2008 .hsw.irq_pipe_mask = BIT(PIPE_B) | BIT(PIPE_C),
2009 .hsw.has_vga = true,
2010 },
Daniel Vetter9c065a72014-09-30 10:56:38 +02002011 },
2012};
2013
2014static const struct i915_power_well_ops vlv_display_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02002015 .sync_hw = i9xx_power_well_sync_hw_noop,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002016 .enable = vlv_display_power_well_enable,
2017 .disable = vlv_display_power_well_disable,
2018 .is_enabled = vlv_power_well_enabled,
2019};
2020
2021static const struct i915_power_well_ops vlv_dpio_cmn_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02002022 .sync_hw = i9xx_power_well_sync_hw_noop,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002023 .enable = vlv_dpio_cmn_power_well_enable,
2024 .disable = vlv_dpio_cmn_power_well_disable,
2025 .is_enabled = vlv_power_well_enabled,
2026};
2027
2028static const struct i915_power_well_ops vlv_dpio_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02002029 .sync_hw = i9xx_power_well_sync_hw_noop,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002030 .enable = vlv_power_well_enable,
2031 .disable = vlv_power_well_disable,
2032 .is_enabled = vlv_power_well_enabled,
2033};
2034
2035static struct i915_power_well vlv_power_wells[] = {
2036 {
2037 .name = "always-on",
2038 .always_on = 1,
Ville Syrjälä998bd662016-04-18 14:02:26 +03002039 .domains = POWER_DOMAIN_MASK,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002040 .ops = &i9xx_always_on_power_well_ops,
Imre Deak438b8dc2017-07-11 23:42:30 +03002041 .id = I915_DISP_PW_ALWAYS_ON,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002042 },
2043 {
2044 .name = "display",
2045 .domains = VLV_DISPLAY_POWER_DOMAINS,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002046 .id = PUNIT_POWER_WELL_DISP2D,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002047 .ops = &vlv_display_power_well_ops,
2048 },
2049 {
2050 .name = "dpio-tx-b-01",
2051 .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
2052 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
2053 VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
2054 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
2055 .ops = &vlv_dpio_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002056 .id = PUNIT_POWER_WELL_DPIO_TX_B_LANES_01,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002057 },
2058 {
2059 .name = "dpio-tx-b-23",
2060 .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
2061 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
2062 VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
2063 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
2064 .ops = &vlv_dpio_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002065 .id = PUNIT_POWER_WELL_DPIO_TX_B_LANES_23,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002066 },
2067 {
2068 .name = "dpio-tx-c-01",
2069 .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
2070 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
2071 VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
2072 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
2073 .ops = &vlv_dpio_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002074 .id = PUNIT_POWER_WELL_DPIO_TX_C_LANES_01,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002075 },
2076 {
2077 .name = "dpio-tx-c-23",
2078 .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
2079 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
2080 VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
2081 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
2082 .ops = &vlv_dpio_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002083 .id = PUNIT_POWER_WELL_DPIO_TX_C_LANES_23,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002084 },
2085 {
2086 .name = "dpio-common",
2087 .domains = VLV_DPIO_CMN_BC_POWER_DOMAINS,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002088 .id = PUNIT_POWER_WELL_DPIO_CMN_BC,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002089 .ops = &vlv_dpio_cmn_power_well_ops,
2090 },
2091};
2092
2093static struct i915_power_well chv_power_wells[] = {
2094 {
2095 .name = "always-on",
2096 .always_on = 1,
Ville Syrjälä998bd662016-04-18 14:02:26 +03002097 .domains = POWER_DOMAIN_MASK,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002098 .ops = &i9xx_always_on_power_well_ops,
Imre Deak029d80d2017-07-06 17:40:25 +03002099 .id = I915_DISP_PW_ALWAYS_ON,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002100 },
Daniel Vetter9c065a72014-09-30 10:56:38 +02002101 {
2102 .name = "display",
Ville Syrjäläbaa4e572014-10-27 16:07:32 +02002103 /*
Ville Syrjäläfde61e42015-05-26 20:22:39 +03002104 * Pipe A power well is the new disp2d well. Pipe B and C
2105 * power wells don't actually exist. Pipe A power well is
2106 * required for any pipe to work.
Ville Syrjäläbaa4e572014-10-27 16:07:32 +02002107 */
Ville Syrjälä465ac0c2016-04-18 14:02:27 +03002108 .domains = CHV_DISPLAY_POWER_DOMAINS,
Imre Deakf49193c2017-07-06 17:40:23 +03002109 .id = CHV_DISP_PW_PIPE_A,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002110 .ops = &chv_pipe_power_well_ops,
2111 },
Daniel Vetter9c065a72014-09-30 10:56:38 +02002112 {
2113 .name = "dpio-common-bc",
Ville Syrjälä71849b62015-04-10 18:21:29 +03002114 .domains = CHV_DPIO_CMN_BC_POWER_DOMAINS,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002115 .id = PUNIT_POWER_WELL_DPIO_CMN_BC,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002116 .ops = &chv_dpio_cmn_power_well_ops,
2117 },
2118 {
2119 .name = "dpio-common-d",
Ville Syrjälä71849b62015-04-10 18:21:29 +03002120 .domains = CHV_DPIO_CMN_D_POWER_DOMAINS,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002121 .id = PUNIT_POWER_WELL_DPIO_CMN_D,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002122 .ops = &chv_dpio_cmn_power_well_ops,
2123 },
Daniel Vetter9c065a72014-09-30 10:56:38 +02002124};
2125
Suketu Shah5aefb232015-04-16 14:22:10 +05302126bool intel_display_power_well_is_enabled(struct drm_i915_private *dev_priv,
Imre Deak438b8dc2017-07-11 23:42:30 +03002127 enum i915_power_well_id power_well_id)
Suketu Shah5aefb232015-04-16 14:22:10 +05302128{
2129 struct i915_power_well *power_well;
2130 bool ret;
2131
2132 power_well = lookup_power_well(dev_priv, power_well_id);
2133 ret = power_well->ops->is_enabled(dev_priv, power_well);
2134
2135 return ret;
2136}
2137
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002138static struct i915_power_well skl_power_wells[] = {
2139 {
2140 .name = "always-on",
2141 .always_on = 1,
Ville Syrjälä998bd662016-04-18 14:02:26 +03002142 .domains = POWER_DOMAIN_MASK,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002143 .ops = &i9xx_always_on_power_well_ops,
Imre Deak438b8dc2017-07-11 23:42:30 +03002144 .id = I915_DISP_PW_ALWAYS_ON,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002145 },
2146 {
2147 .name = "power well 1",
Imre Deak4a76f292015-11-04 19:24:15 +02002148 /* Handled by the DMC firmware */
2149 .domains = 0,
Imre Deak4196b912017-07-11 23:42:36 +03002150 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002151 .id = SKL_DISP_PW_1,
Imre Deak0a445942017-08-14 18:15:29 +03002152 {
2153 .hsw.has_fuses = true,
2154 },
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002155 },
2156 {
2157 .name = "MISC IO power well",
Imre Deak4a76f292015-11-04 19:24:15 +02002158 /* Handled by the DMC firmware */
2159 .domains = 0,
Imre Deak4196b912017-07-11 23:42:36 +03002160 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002161 .id = SKL_DISP_PW_MISC_IO,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002162 },
2163 {
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01002164 .name = "DC off",
2165 .domains = SKL_DISPLAY_DC_OFF_POWER_DOMAINS,
2166 .ops = &gen9_dc_off_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002167 .id = SKL_DISP_PW_DC_OFF,
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01002168 },
2169 {
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002170 .name = "power well 2",
2171 .domains = SKL_DISPLAY_POWERWELL_2_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002172 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002173 .id = SKL_DISP_PW_2,
Imre Deak0a445942017-08-14 18:15:29 +03002174 {
2175 .hsw.irq_pipe_mask = BIT(PIPE_B) | BIT(PIPE_C),
2176 .hsw.has_vga = true,
2177 .hsw.has_fuses = true,
2178 },
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002179 },
2180 {
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002181 .name = "DDI A/E IO power well",
2182 .domains = SKL_DISPLAY_DDI_IO_A_E_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002183 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002184 .id = SKL_DISP_PW_DDI_A_E,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002185 },
2186 {
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002187 .name = "DDI B IO power well",
2188 .domains = SKL_DISPLAY_DDI_IO_B_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002189 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002190 .id = SKL_DISP_PW_DDI_B,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002191 },
2192 {
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002193 .name = "DDI C IO power well",
2194 .domains = SKL_DISPLAY_DDI_IO_C_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002195 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002196 .id = SKL_DISP_PW_DDI_C,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002197 },
2198 {
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002199 .name = "DDI D IO power well",
2200 .domains = SKL_DISPLAY_DDI_IO_D_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002201 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002202 .id = SKL_DISP_PW_DDI_D,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002203 },
2204};
2205
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302206static struct i915_power_well bxt_power_wells[] = {
2207 {
2208 .name = "always-on",
2209 .always_on = 1,
Ville Syrjälä998bd662016-04-18 14:02:26 +03002210 .domains = POWER_DOMAIN_MASK,
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302211 .ops = &i9xx_always_on_power_well_ops,
Imre Deak029d80d2017-07-06 17:40:25 +03002212 .id = I915_DISP_PW_ALWAYS_ON,
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302213 },
2214 {
2215 .name = "power well 1",
Imre Deakd7d7c9e2016-04-01 16:02:42 +03002216 .domains = 0,
Imre Deak4196b912017-07-11 23:42:36 +03002217 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002218 .id = SKL_DISP_PW_1,
Imre Deak0a445942017-08-14 18:15:29 +03002219 {
2220 .hsw.has_fuses = true,
2221 },
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302222 },
2223 {
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01002224 .name = "DC off",
2225 .domains = BXT_DISPLAY_DC_OFF_POWER_DOMAINS,
2226 .ops = &gen9_dc_off_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002227 .id = SKL_DISP_PW_DC_OFF,
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01002228 },
2229 {
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302230 .name = "power well 2",
2231 .domains = BXT_DISPLAY_POWERWELL_2_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002232 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002233 .id = SKL_DISP_PW_2,
Imre Deak0a445942017-08-14 18:15:29 +03002234 {
2235 .hsw.irq_pipe_mask = BIT(PIPE_B) | BIT(PIPE_C),
2236 .hsw.has_vga = true,
2237 .hsw.has_fuses = true,
2238 },
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01002239 },
Imre Deak9c8d0b82016-06-13 16:44:34 +03002240 {
2241 .name = "dpio-common-a",
2242 .domains = BXT_DPIO_CMN_A_POWER_DOMAINS,
2243 .ops = &bxt_dpio_cmn_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002244 .id = BXT_DPIO_CMN_A,
Imre Deak0a445942017-08-14 18:15:29 +03002245 {
2246 .bxt.phy = DPIO_PHY1,
2247 },
Imre Deak9c8d0b82016-06-13 16:44:34 +03002248 },
2249 {
2250 .name = "dpio-common-bc",
2251 .domains = BXT_DPIO_CMN_BC_POWER_DOMAINS,
2252 .ops = &bxt_dpio_cmn_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002253 .id = BXT_DPIO_CMN_BC,
Imre Deak0a445942017-08-14 18:15:29 +03002254 {
2255 .bxt.phy = DPIO_PHY0,
2256 },
Imre Deak9c8d0b82016-06-13 16:44:34 +03002257 },
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302258};
2259
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002260static struct i915_power_well glk_power_wells[] = {
2261 {
2262 .name = "always-on",
2263 .always_on = 1,
2264 .domains = POWER_DOMAIN_MASK,
2265 .ops = &i9xx_always_on_power_well_ops,
Imre Deak029d80d2017-07-06 17:40:25 +03002266 .id = I915_DISP_PW_ALWAYS_ON,
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002267 },
2268 {
2269 .name = "power well 1",
2270 /* Handled by the DMC firmware */
2271 .domains = 0,
Imre Deak4196b912017-07-11 23:42:36 +03002272 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002273 .id = SKL_DISP_PW_1,
Imre Deak0a445942017-08-14 18:15:29 +03002274 {
2275 .hsw.has_fuses = true,
2276 },
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002277 },
2278 {
2279 .name = "DC off",
2280 .domains = GLK_DISPLAY_DC_OFF_POWER_DOMAINS,
2281 .ops = &gen9_dc_off_power_well_ops,
2282 .id = SKL_DISP_PW_DC_OFF,
2283 },
2284 {
2285 .name = "power well 2",
2286 .domains = GLK_DISPLAY_POWERWELL_2_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002287 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002288 .id = SKL_DISP_PW_2,
Imre Deak0a445942017-08-14 18:15:29 +03002289 {
2290 .hsw.irq_pipe_mask = BIT(PIPE_B) | BIT(PIPE_C),
2291 .hsw.has_vga = true,
2292 .hsw.has_fuses = true,
2293 },
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002294 },
2295 {
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +02002296 .name = "dpio-common-a",
2297 .domains = GLK_DPIO_CMN_A_POWER_DOMAINS,
2298 .ops = &bxt_dpio_cmn_power_well_ops,
2299 .id = BXT_DPIO_CMN_A,
Imre Deak0a445942017-08-14 18:15:29 +03002300 {
2301 .bxt.phy = DPIO_PHY1,
2302 },
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +02002303 },
2304 {
2305 .name = "dpio-common-b",
2306 .domains = GLK_DPIO_CMN_B_POWER_DOMAINS,
2307 .ops = &bxt_dpio_cmn_power_well_ops,
2308 .id = BXT_DPIO_CMN_BC,
Imre Deak0a445942017-08-14 18:15:29 +03002309 {
2310 .bxt.phy = DPIO_PHY0,
2311 },
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +02002312 },
2313 {
2314 .name = "dpio-common-c",
2315 .domains = GLK_DPIO_CMN_C_POWER_DOMAINS,
2316 .ops = &bxt_dpio_cmn_power_well_ops,
2317 .id = GLK_DPIO_CMN_C,
Imre Deak0a445942017-08-14 18:15:29 +03002318 {
2319 .bxt.phy = DPIO_PHY2,
2320 },
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +02002321 },
2322 {
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002323 .name = "AUX A",
2324 .domains = GLK_DISPLAY_AUX_A_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002325 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002326 .id = GLK_DISP_PW_AUX_A,
2327 },
2328 {
2329 .name = "AUX B",
2330 .domains = GLK_DISPLAY_AUX_B_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002331 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002332 .id = GLK_DISP_PW_AUX_B,
2333 },
2334 {
2335 .name = "AUX C",
2336 .domains = GLK_DISPLAY_AUX_C_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002337 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002338 .id = GLK_DISP_PW_AUX_C,
2339 },
2340 {
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002341 .name = "DDI A IO power well",
2342 .domains = GLK_DISPLAY_DDI_IO_A_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002343 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002344 .id = GLK_DISP_PW_DDI_A,
2345 },
2346 {
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002347 .name = "DDI B IO power well",
2348 .domains = GLK_DISPLAY_DDI_IO_B_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002349 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002350 .id = SKL_DISP_PW_DDI_B,
2351 },
2352 {
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002353 .name = "DDI C IO power well",
2354 .domains = GLK_DISPLAY_DDI_IO_C_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002355 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002356 .id = SKL_DISP_PW_DDI_C,
2357 },
2358};
2359
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002360static struct i915_power_well cnl_power_wells[] = {
2361 {
2362 .name = "always-on",
2363 .always_on = 1,
2364 .domains = POWER_DOMAIN_MASK,
2365 .ops = &i9xx_always_on_power_well_ops,
Imre Deak029d80d2017-07-06 17:40:25 +03002366 .id = I915_DISP_PW_ALWAYS_ON,
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002367 },
2368 {
2369 .name = "power well 1",
2370 /* Handled by the DMC firmware */
2371 .domains = 0,
Imre Deak4196b912017-07-11 23:42:36 +03002372 .ops = &hsw_power_well_ops,
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002373 .id = SKL_DISP_PW_1,
Imre Deak0a445942017-08-14 18:15:29 +03002374 {
2375 .hsw.has_fuses = true,
2376 },
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002377 },
2378 {
2379 .name = "AUX A",
2380 .domains = CNL_DISPLAY_AUX_A_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002381 .ops = &hsw_power_well_ops,
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002382 .id = CNL_DISP_PW_AUX_A,
2383 },
2384 {
2385 .name = "AUX B",
2386 .domains = CNL_DISPLAY_AUX_B_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002387 .ops = &hsw_power_well_ops,
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002388 .id = CNL_DISP_PW_AUX_B,
2389 },
2390 {
2391 .name = "AUX C",
2392 .domains = CNL_DISPLAY_AUX_C_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002393 .ops = &hsw_power_well_ops,
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002394 .id = CNL_DISP_PW_AUX_C,
2395 },
2396 {
2397 .name = "AUX D",
2398 .domains = CNL_DISPLAY_AUX_D_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002399 .ops = &hsw_power_well_ops,
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002400 .id = CNL_DISP_PW_AUX_D,
2401 },
2402 {
2403 .name = "DC off",
2404 .domains = CNL_DISPLAY_DC_OFF_POWER_DOMAINS,
2405 .ops = &gen9_dc_off_power_well_ops,
2406 .id = SKL_DISP_PW_DC_OFF,
2407 },
2408 {
2409 .name = "power well 2",
2410 .domains = CNL_DISPLAY_POWERWELL_2_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002411 .ops = &hsw_power_well_ops,
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002412 .id = SKL_DISP_PW_2,
Imre Deak0a445942017-08-14 18:15:29 +03002413 {
2414 .hsw.irq_pipe_mask = BIT(PIPE_B) | BIT(PIPE_C),
2415 .hsw.has_vga = true,
2416 .hsw.has_fuses = true,
2417 },
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002418 },
2419 {
2420 .name = "DDI A IO power well",
2421 .domains = CNL_DISPLAY_DDI_A_IO_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002422 .ops = &hsw_power_well_ops,
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002423 .id = CNL_DISP_PW_DDI_A,
2424 },
2425 {
2426 .name = "DDI B IO power well",
2427 .domains = CNL_DISPLAY_DDI_B_IO_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002428 .ops = &hsw_power_well_ops,
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002429 .id = SKL_DISP_PW_DDI_B,
2430 },
2431 {
2432 .name = "DDI C IO power well",
2433 .domains = CNL_DISPLAY_DDI_C_IO_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002434 .ops = &hsw_power_well_ops,
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002435 .id = SKL_DISP_PW_DDI_C,
2436 },
2437 {
2438 .name = "DDI D IO power well",
2439 .domains = CNL_DISPLAY_DDI_D_IO_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002440 .ops = &hsw_power_well_ops,
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002441 .id = SKL_DISP_PW_DDI_D,
2442 },
Rodrigo Vivia324fca2018-01-29 15:22:15 -08002443 {
Rodrigo Vivi9787e832018-01-29 15:22:22 -08002444 .name = "DDI F IO power well",
2445 .domains = CNL_DISPLAY_DDI_F_IO_POWER_DOMAINS,
2446 .ops = &hsw_power_well_ops,
2447 .id = CNL_DISP_PW_DDI_F,
2448 },
2449 {
Rodrigo Vivia324fca2018-01-29 15:22:15 -08002450 .name = "AUX F",
2451 .domains = CNL_DISPLAY_AUX_F_POWER_DOMAINS,
2452 .ops = &hsw_power_well_ops,
2453 .id = CNL_DISP_PW_AUX_F,
2454 },
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002455};
2456
Imre Deak1b0e3a02015-11-05 23:04:11 +02002457static int
2458sanitize_disable_power_well_option(const struct drm_i915_private *dev_priv,
2459 int disable_power_well)
2460{
2461 if (disable_power_well >= 0)
2462 return !!disable_power_well;
2463
Imre Deak1b0e3a02015-11-05 23:04:11 +02002464 return 1;
2465}
2466
Imre Deaka37baf32016-02-29 22:49:03 +02002467static uint32_t get_allowed_dc_mask(const struct drm_i915_private *dev_priv,
2468 int enable_dc)
2469{
2470 uint32_t mask;
2471 int requested_dc;
2472 int max_dc;
2473
Rodrigo Vivi6d6a8972017-07-06 13:45:08 -07002474 if (IS_GEN9_BC(dev_priv) || IS_CANNONLAKE(dev_priv)) {
Imre Deaka37baf32016-02-29 22:49:03 +02002475 max_dc = 2;
2476 mask = 0;
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02002477 } else if (IS_GEN9_LP(dev_priv)) {
Imre Deaka37baf32016-02-29 22:49:03 +02002478 max_dc = 1;
2479 /*
2480 * DC9 has a separate HW flow from the rest of the DC states,
2481 * not depending on the DMC firmware. It's needed by system
2482 * suspend/resume, so allow it unconditionally.
2483 */
2484 mask = DC_STATE_EN_DC9;
2485 } else {
2486 max_dc = 0;
2487 mask = 0;
2488 }
2489
Michal Wajdeczko4f044a82017-09-19 19:38:44 +00002490 if (!i915_modparams.disable_power_well)
Imre Deak66e2c4c2016-02-29 22:49:04 +02002491 max_dc = 0;
2492
Imre Deaka37baf32016-02-29 22:49:03 +02002493 if (enable_dc >= 0 && enable_dc <= max_dc) {
2494 requested_dc = enable_dc;
2495 } else if (enable_dc == -1) {
2496 requested_dc = max_dc;
2497 } else if (enable_dc > max_dc && enable_dc <= 2) {
2498 DRM_DEBUG_KMS("Adjusting requested max DC state (%d->%d)\n",
2499 enable_dc, max_dc);
2500 requested_dc = max_dc;
2501 } else {
2502 DRM_ERROR("Unexpected value for enable_dc (%d)\n", enable_dc);
2503 requested_dc = max_dc;
2504 }
2505
2506 if (requested_dc > 1)
2507 mask |= DC_STATE_EN_UPTO_DC6;
2508 if (requested_dc > 0)
2509 mask |= DC_STATE_EN_UPTO_DC5;
2510
2511 DRM_DEBUG_KMS("Allowed DC state mask %02x\n", mask);
2512
2513 return mask;
2514}
2515
Imre Deak21792c62017-07-11 23:42:33 +03002516static void assert_power_well_ids_unique(struct drm_i915_private *dev_priv)
2517{
2518 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2519 u64 power_well_ids;
2520 int i;
2521
2522 power_well_ids = 0;
2523 for (i = 0; i < power_domains->power_well_count; i++) {
2524 enum i915_power_well_id id = power_domains->power_wells[i].id;
2525
2526 WARN_ON(id >= sizeof(power_well_ids) * 8);
2527 WARN_ON(power_well_ids & BIT_ULL(id));
2528 power_well_ids |= BIT_ULL(id);
2529 }
2530}
2531
Daniel Vetter9c065a72014-09-30 10:56:38 +02002532#define set_power_wells(power_domains, __power_wells) ({ \
2533 (power_domains)->power_wells = (__power_wells); \
2534 (power_domains)->power_well_count = ARRAY_SIZE(__power_wells); \
2535})
2536
Daniel Vettere4e76842014-09-30 10:56:42 +02002537/**
2538 * intel_power_domains_init - initializes the power domain structures
2539 * @dev_priv: i915 device instance
2540 *
2541 * Initializes the power domain structures for @dev_priv depending upon the
2542 * supported platform.
2543 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02002544int intel_power_domains_init(struct drm_i915_private *dev_priv)
2545{
2546 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2547
Michal Wajdeczko4f044a82017-09-19 19:38:44 +00002548 i915_modparams.disable_power_well =
2549 sanitize_disable_power_well_option(dev_priv,
2550 i915_modparams.disable_power_well);
2551 dev_priv->csr.allowed_dc_mask =
2552 get_allowed_dc_mask(dev_priv, i915_modparams.enable_dc);
Imre Deak1b0e3a02015-11-05 23:04:11 +02002553
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02002554 BUILD_BUG_ON(POWER_DOMAIN_NUM > 64);
Ville Syrjäläf0ab43e2015-11-09 16:48:19 +01002555
Daniel Vetter9c065a72014-09-30 10:56:38 +02002556 mutex_init(&power_domains->lock);
2557
2558 /*
2559 * The enabling order will be from lower to higher indexed wells,
2560 * the disabling order is reversed.
2561 */
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002562 if (IS_HASWELL(dev_priv)) {
Daniel Vetter9c065a72014-09-30 10:56:38 +02002563 set_power_wells(power_domains, hsw_power_wells);
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002564 } else if (IS_BROADWELL(dev_priv)) {
Daniel Vetter9c065a72014-09-30 10:56:38 +02002565 set_power_wells(power_domains, bdw_power_wells);
Rodrigo Vivib976dc52017-01-23 10:32:37 -08002566 } else if (IS_GEN9_BC(dev_priv)) {
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002567 set_power_wells(power_domains, skl_power_wells);
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002568 } else if (IS_CANNONLAKE(dev_priv)) {
2569 set_power_wells(power_domains, cnl_power_wells);
Rodrigo Vivia324fca2018-01-29 15:22:15 -08002570
2571 /*
Rodrigo Vivi9787e832018-01-29 15:22:22 -08002572 * DDI and Aux IO are getting enabled for all ports
Rodrigo Vivia324fca2018-01-29 15:22:15 -08002573 * regardless the presence or use. So, in order to avoid
Rodrigo Vivi9787e832018-01-29 15:22:22 -08002574 * timeouts, lets remove them from the list
Rodrigo Vivia324fca2018-01-29 15:22:15 -08002575 * for the SKUs without port F.
2576 */
2577 if (!IS_CNL_WITH_PORT_F(dev_priv))
Rodrigo Vivi9787e832018-01-29 15:22:22 -08002578 power_domains->power_well_count -= 2;
Rodrigo Vivia324fca2018-01-29 15:22:15 -08002579
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002580 } else if (IS_BROXTON(dev_priv)) {
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302581 set_power_wells(power_domains, bxt_power_wells);
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002582 } else if (IS_GEMINILAKE(dev_priv)) {
2583 set_power_wells(power_domains, glk_power_wells);
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002584 } else if (IS_CHERRYVIEW(dev_priv)) {
Daniel Vetter9c065a72014-09-30 10:56:38 +02002585 set_power_wells(power_domains, chv_power_wells);
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002586 } else if (IS_VALLEYVIEW(dev_priv)) {
Daniel Vetter9c065a72014-09-30 10:56:38 +02002587 set_power_wells(power_domains, vlv_power_wells);
Ville Syrjälä2ee0da12017-06-01 17:36:16 +03002588 } else if (IS_I830(dev_priv)) {
2589 set_power_wells(power_domains, i830_power_wells);
Daniel Vetter9c065a72014-09-30 10:56:38 +02002590 } else {
2591 set_power_wells(power_domains, i9xx_always_on_power_well);
2592 }
2593
Imre Deak21792c62017-07-11 23:42:33 +03002594 assert_power_well_ids_unique(dev_priv);
2595
Daniel Vetter9c065a72014-09-30 10:56:38 +02002596 return 0;
2597}
2598
Daniel Vettere4e76842014-09-30 10:56:42 +02002599/**
2600 * intel_power_domains_fini - finalizes the power domain structures
2601 * @dev_priv: i915 device instance
2602 *
2603 * Finalizes the power domain structures for @dev_priv depending upon the
2604 * supported platform. This function also disables runtime pm and ensures that
2605 * the device stays powered up so that the driver can be reloaded.
2606 */
Daniel Vetterf458ebb2014-09-30 10:56:39 +02002607void intel_power_domains_fini(struct drm_i915_private *dev_priv)
Daniel Vetter9c065a72014-09-30 10:56:38 +02002608{
David Weinehallc49d13e2016-08-22 13:32:42 +03002609 struct device *kdev = &dev_priv->drm.pdev->dev;
Imre Deak25b181b2015-12-17 13:44:56 +02002610
Imre Deakaabee1b2015-12-15 20:10:29 +02002611 /*
2612 * The i915.ko module is still not prepared to be loaded when
Daniel Vetterf458ebb2014-09-30 10:56:39 +02002613 * the power well is not enabled, so just enable it in case
Imre Deakaabee1b2015-12-15 20:10:29 +02002614 * we're going to unload/reload.
2615 * The following also reacquires the RPM reference the core passed
2616 * to the driver during loading, which is dropped in
2617 * intel_runtime_pm_enable(). We have to hand back the control of the
2618 * device to the core with this reference held.
2619 */
Daniel Vetterf458ebb2014-09-30 10:56:39 +02002620 intel_display_set_init_power(dev_priv, true);
Imre Deakd314cd42015-11-17 17:44:23 +02002621
2622 /* Remove the refcount we took to keep power well support disabled. */
Michal Wajdeczko4f044a82017-09-19 19:38:44 +00002623 if (!i915_modparams.disable_power_well)
Imre Deakd314cd42015-11-17 17:44:23 +02002624 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
Imre Deak25b181b2015-12-17 13:44:56 +02002625
2626 /*
2627 * Remove the refcount we took in intel_runtime_pm_enable() in case
2628 * the platform doesn't support runtime PM.
2629 */
2630 if (!HAS_RUNTIME_PM(dev_priv))
David Weinehallc49d13e2016-08-22 13:32:42 +03002631 pm_runtime_put(kdev);
Daniel Vetter9c065a72014-09-30 10:56:38 +02002632}
2633
Imre Deak30eade12015-11-04 19:24:13 +02002634static void intel_power_domains_sync_hw(struct drm_i915_private *dev_priv)
Daniel Vetter9c065a72014-09-30 10:56:38 +02002635{
2636 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2637 struct i915_power_well *power_well;
Daniel Vetter9c065a72014-09-30 10:56:38 +02002638
2639 mutex_lock(&power_domains->lock);
Imre Deak75ccb2e2017-02-17 17:39:43 +02002640 for_each_power_well(dev_priv, power_well) {
Daniel Vetter9c065a72014-09-30 10:56:38 +02002641 power_well->ops->sync_hw(dev_priv, power_well);
2642 power_well->hw_enabled = power_well->ops->is_enabled(dev_priv,
2643 power_well);
2644 }
2645 mutex_unlock(&power_domains->lock);
2646}
2647
Mahesh Kumaraa9664f2018-04-26 19:55:16 +05302648static inline
2649bool intel_dbuf_slice_set(struct drm_i915_private *dev_priv,
2650 i915_reg_t reg, bool enable)
Ville Syrjälä70c2c182016-05-13 23:41:30 +03002651{
Mahesh Kumaraa9664f2018-04-26 19:55:16 +05302652 u32 val, status;
Ville Syrjälä70c2c182016-05-13 23:41:30 +03002653
Mahesh Kumaraa9664f2018-04-26 19:55:16 +05302654 val = I915_READ(reg);
2655 val = enable ? (val | DBUF_POWER_REQUEST) : (val & ~DBUF_POWER_REQUEST);
2656 I915_WRITE(reg, val);
2657 POSTING_READ(reg);
Ville Syrjälä70c2c182016-05-13 23:41:30 +03002658 udelay(10);
2659
Mahesh Kumaraa9664f2018-04-26 19:55:16 +05302660 status = I915_READ(reg) & DBUF_POWER_STATE;
2661 if ((enable && !status) || (!enable && status)) {
2662 DRM_ERROR("DBus power %s timeout!\n",
2663 enable ? "enable" : "disable");
2664 return false;
2665 }
2666 return true;
2667}
2668
2669static void gen9_dbuf_enable(struct drm_i915_private *dev_priv)
2670{
2671 intel_dbuf_slice_set(dev_priv, DBUF_CTL, true);
Ville Syrjälä70c2c182016-05-13 23:41:30 +03002672}
2673
2674static void gen9_dbuf_disable(struct drm_i915_private *dev_priv)
2675{
Mahesh Kumaraa9664f2018-04-26 19:55:16 +05302676 intel_dbuf_slice_set(dev_priv, DBUF_CTL, false);
Ville Syrjälä70c2c182016-05-13 23:41:30 +03002677}
2678
Mahesh Kumaraa9664f2018-04-26 19:55:16 +05302679static u8 intel_dbuf_max_slices(struct drm_i915_private *dev_priv)
2680{
2681 if (INTEL_GEN(dev_priv) < 11)
2682 return 1;
2683 return 2;
2684}
2685
2686void icl_dbuf_slices_update(struct drm_i915_private *dev_priv,
2687 u8 req_slices)
2688{
2689 u8 hw_enabled_slices = dev_priv->wm.skl_hw.ddb.enabled_slices;
2690 u32 val;
2691 bool ret;
2692
2693 if (req_slices > intel_dbuf_max_slices(dev_priv)) {
2694 DRM_ERROR("Invalid number of dbuf slices requested\n");
2695 return;
2696 }
2697
2698 if (req_slices == hw_enabled_slices || req_slices == 0)
2699 return;
2700
2701 val = I915_READ(DBUF_CTL_S2);
2702 if (req_slices > hw_enabled_slices)
2703 ret = intel_dbuf_slice_set(dev_priv, DBUF_CTL_S2, true);
2704 else
2705 ret = intel_dbuf_slice_set(dev_priv, DBUF_CTL_S2, false);
2706
2707 if (ret)
2708 dev_priv->wm.skl_hw.ddb.enabled_slices = req_slices;
2709}
2710
Mahesh Kumar746edf82018-02-05 13:40:44 -02002711static void icl_dbuf_enable(struct drm_i915_private *dev_priv)
2712{
2713 I915_WRITE(DBUF_CTL_S1, I915_READ(DBUF_CTL_S1) | DBUF_POWER_REQUEST);
2714 I915_WRITE(DBUF_CTL_S2, I915_READ(DBUF_CTL_S2) | DBUF_POWER_REQUEST);
2715 POSTING_READ(DBUF_CTL_S2);
2716
2717 udelay(10);
2718
2719 if (!(I915_READ(DBUF_CTL_S1) & DBUF_POWER_STATE) ||
2720 !(I915_READ(DBUF_CTL_S2) & DBUF_POWER_STATE))
2721 DRM_ERROR("DBuf power enable timeout\n");
Mahesh Kumar74bd8002018-04-26 19:55:15 +05302722 else
2723 dev_priv->wm.skl_hw.ddb.enabled_slices = 2;
Mahesh Kumar746edf82018-02-05 13:40:44 -02002724}
2725
2726static void icl_dbuf_disable(struct drm_i915_private *dev_priv)
2727{
2728 I915_WRITE(DBUF_CTL_S1, I915_READ(DBUF_CTL_S1) & ~DBUF_POWER_REQUEST);
2729 I915_WRITE(DBUF_CTL_S2, I915_READ(DBUF_CTL_S2) & ~DBUF_POWER_REQUEST);
2730 POSTING_READ(DBUF_CTL_S2);
2731
2732 udelay(10);
2733
2734 if ((I915_READ(DBUF_CTL_S1) & DBUF_POWER_STATE) ||
2735 (I915_READ(DBUF_CTL_S2) & DBUF_POWER_STATE))
2736 DRM_ERROR("DBuf power disable timeout!\n");
Mahesh Kumar74bd8002018-04-26 19:55:15 +05302737 else
2738 dev_priv->wm.skl_hw.ddb.enabled_slices = 0;
Mahesh Kumar746edf82018-02-05 13:40:44 -02002739}
2740
Mahesh Kumar4cb45852018-02-05 13:40:45 -02002741static void icl_mbus_init(struct drm_i915_private *dev_priv)
2742{
2743 uint32_t val;
2744
2745 val = MBUS_ABOX_BT_CREDIT_POOL1(16) |
2746 MBUS_ABOX_BT_CREDIT_POOL2(16) |
2747 MBUS_ABOX_B_CREDIT(1) |
2748 MBUS_ABOX_BW_CREDIT(1);
2749
2750 I915_WRITE(MBUS_ABOX_CTL, val);
2751}
2752
Imre Deak73dfc222015-11-17 17:33:53 +02002753static void skl_display_core_init(struct drm_i915_private *dev_priv,
Imre Deak443a93a2016-04-04 15:42:57 +03002754 bool resume)
Imre Deak73dfc222015-11-17 17:33:53 +02002755{
2756 struct i915_power_domains *power_domains = &dev_priv->power_domains;
Imre Deak443a93a2016-04-04 15:42:57 +03002757 struct i915_power_well *well;
Imre Deak73dfc222015-11-17 17:33:53 +02002758 uint32_t val;
2759
Imre Deakd26fa1d2015-11-04 19:24:17 +02002760 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
2761
Imre Deak73dfc222015-11-17 17:33:53 +02002762 /* enable PCH reset handshake */
2763 val = I915_READ(HSW_NDE_RSTWRN_OPT);
2764 I915_WRITE(HSW_NDE_RSTWRN_OPT, val | RESET_PCH_HANDSHAKE_ENABLE);
2765
2766 /* enable PG1 and Misc I/O */
2767 mutex_lock(&power_domains->lock);
Imre Deak443a93a2016-04-04 15:42:57 +03002768
2769 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
2770 intel_power_well_enable(dev_priv, well);
2771
2772 well = lookup_power_well(dev_priv, SKL_DISP_PW_MISC_IO);
2773 intel_power_well_enable(dev_priv, well);
2774
Imre Deak73dfc222015-11-17 17:33:53 +02002775 mutex_unlock(&power_domains->lock);
2776
Imre Deak73dfc222015-11-17 17:33:53 +02002777 skl_init_cdclk(dev_priv);
2778
Ville Syrjälä70c2c182016-05-13 23:41:30 +03002779 gen9_dbuf_enable(dev_priv);
2780
Ville Syrjälä9f7eb312016-05-13 23:41:29 +03002781 if (resume && dev_priv->csr.dmc_payload)
Imre Deak2abc5252016-03-04 21:57:41 +02002782 intel_csr_load_program(dev_priv);
Imre Deak73dfc222015-11-17 17:33:53 +02002783}
2784
2785static void skl_display_core_uninit(struct drm_i915_private *dev_priv)
2786{
2787 struct i915_power_domains *power_domains = &dev_priv->power_domains;
Imre Deak443a93a2016-04-04 15:42:57 +03002788 struct i915_power_well *well;
Imre Deak73dfc222015-11-17 17:33:53 +02002789
Imre Deakd26fa1d2015-11-04 19:24:17 +02002790 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
2791
Ville Syrjälä70c2c182016-05-13 23:41:30 +03002792 gen9_dbuf_disable(dev_priv);
2793
Imre Deak73dfc222015-11-17 17:33:53 +02002794 skl_uninit_cdclk(dev_priv);
2795
2796 /* The spec doesn't call for removing the reset handshake flag */
2797 /* disable PG1 and Misc I/O */
Imre Deak443a93a2016-04-04 15:42:57 +03002798
Imre Deak73dfc222015-11-17 17:33:53 +02002799 mutex_lock(&power_domains->lock);
Imre Deak443a93a2016-04-04 15:42:57 +03002800
Imre Deakedfda8e2017-06-29 18:36:59 +03002801 /*
2802 * BSpec says to keep the MISC IO power well enabled here, only
2803 * remove our request for power well 1.
Imre Deak42d93662017-06-29 18:37:01 +03002804 * Note that even though the driver's request is removed power well 1
2805 * may stay enabled after this due to DMC's own request on it.
Imre Deakedfda8e2017-06-29 18:36:59 +03002806 */
Imre Deak443a93a2016-04-04 15:42:57 +03002807 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
2808 intel_power_well_disable(dev_priv, well);
2809
Imre Deak73dfc222015-11-17 17:33:53 +02002810 mutex_unlock(&power_domains->lock);
Imre Deak846c6b22017-06-29 18:36:58 +03002811
2812 usleep_range(10, 30); /* 10 us delay per Bspec */
Imre Deak73dfc222015-11-17 17:33:53 +02002813}
2814
Imre Deakd7d7c9e2016-04-01 16:02:42 +03002815void bxt_display_core_init(struct drm_i915_private *dev_priv,
2816 bool resume)
2817{
2818 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2819 struct i915_power_well *well;
2820 uint32_t val;
2821
2822 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
2823
2824 /*
2825 * NDE_RSTWRN_OPT RST PCH Handshake En must always be 0b on BXT
2826 * or else the reset will hang because there is no PCH to respond.
2827 * Move the handshake programming to initialization sequence.
2828 * Previously was left up to BIOS.
2829 */
2830 val = I915_READ(HSW_NDE_RSTWRN_OPT);
2831 val &= ~RESET_PCH_HANDSHAKE_ENABLE;
2832 I915_WRITE(HSW_NDE_RSTWRN_OPT, val);
2833
2834 /* Enable PG1 */
2835 mutex_lock(&power_domains->lock);
2836
2837 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
2838 intel_power_well_enable(dev_priv, well);
2839
2840 mutex_unlock(&power_domains->lock);
2841
Imre Deak324513c2016-06-13 16:44:36 +03002842 bxt_init_cdclk(dev_priv);
Ville Syrjälä70c2c182016-05-13 23:41:30 +03002843
2844 gen9_dbuf_enable(dev_priv);
2845
Imre Deakd7d7c9e2016-04-01 16:02:42 +03002846 if (resume && dev_priv->csr.dmc_payload)
2847 intel_csr_load_program(dev_priv);
2848}
2849
2850void bxt_display_core_uninit(struct drm_i915_private *dev_priv)
2851{
2852 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2853 struct i915_power_well *well;
2854
2855 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
2856
Ville Syrjälä70c2c182016-05-13 23:41:30 +03002857 gen9_dbuf_disable(dev_priv);
2858
Imre Deak324513c2016-06-13 16:44:36 +03002859 bxt_uninit_cdclk(dev_priv);
Imre Deakd7d7c9e2016-04-01 16:02:42 +03002860
2861 /* The spec doesn't call for removing the reset handshake flag */
2862
Imre Deak42d93662017-06-29 18:37:01 +03002863 /*
2864 * Disable PW1 (PG1).
2865 * Note that even though the driver's request is removed power well 1
2866 * may stay enabled after this due to DMC's own request on it.
2867 */
Imre Deakd7d7c9e2016-04-01 16:02:42 +03002868 mutex_lock(&power_domains->lock);
2869
2870 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
2871 intel_power_well_disable(dev_priv, well);
2872
2873 mutex_unlock(&power_domains->lock);
Imre Deak846c6b22017-06-29 18:36:58 +03002874
2875 usleep_range(10, 30); /* 10 us delay per Bspec */
Imre Deakd7d7c9e2016-04-01 16:02:42 +03002876}
2877
Paulo Zanonie0b8acf2017-08-21 17:03:55 -07002878enum {
2879 PROCMON_0_85V_DOT_0,
2880 PROCMON_0_95V_DOT_0,
2881 PROCMON_0_95V_DOT_1,
2882 PROCMON_1_05V_DOT_0,
2883 PROCMON_1_05V_DOT_1,
2884};
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07002885
2886static const struct cnl_procmon {
2887 u32 dw1, dw9, dw10;
Paulo Zanonie0b8acf2017-08-21 17:03:55 -07002888} cnl_procmon_values[] = {
2889 [PROCMON_0_85V_DOT_0] =
2890 { .dw1 = 0x00000000, .dw9 = 0x62AB67BB, .dw10 = 0x51914F96, },
2891 [PROCMON_0_95V_DOT_0] =
2892 { .dw1 = 0x00000000, .dw9 = 0x86E172C7, .dw10 = 0x77CA5EAB, },
2893 [PROCMON_0_95V_DOT_1] =
2894 { .dw1 = 0x00000000, .dw9 = 0x93F87FE1, .dw10 = 0x8AE871C5, },
2895 [PROCMON_1_05V_DOT_0] =
2896 { .dw1 = 0x00000000, .dw9 = 0x98FA82DD, .dw10 = 0x89E46DC1, },
2897 [PROCMON_1_05V_DOT_1] =
2898 { .dw1 = 0x00440000, .dw9 = 0x9A00AB25, .dw10 = 0x8AE38FF1, },
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07002899};
2900
Paulo Zanoni62d4a5e2018-02-05 13:40:41 -02002901/*
2902 * CNL has just one set of registers, while ICL has two sets: one for port A and
2903 * the other for port B. The CNL registers are equivalent to the ICL port A
2904 * registers, that's why we call the ICL macros even though the function has CNL
2905 * on its name.
2906 */
2907static void cnl_set_procmon_ref_values(struct drm_i915_private *dev_priv,
2908 enum port port)
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07002909{
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07002910 const struct cnl_procmon *procmon;
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07002911 u32 val;
2912
Paulo Zanoni62d4a5e2018-02-05 13:40:41 -02002913 val = I915_READ(ICL_PORT_COMP_DW3(port));
Paulo Zanonie0b8acf2017-08-21 17:03:55 -07002914 switch (val & (PROCESS_INFO_MASK | VOLTAGE_INFO_MASK)) {
2915 default:
2916 MISSING_CASE(val);
2917 case VOLTAGE_INFO_0_85V | PROCESS_INFO_DOT_0:
2918 procmon = &cnl_procmon_values[PROCMON_0_85V_DOT_0];
2919 break;
2920 case VOLTAGE_INFO_0_95V | PROCESS_INFO_DOT_0:
2921 procmon = &cnl_procmon_values[PROCMON_0_95V_DOT_0];
2922 break;
2923 case VOLTAGE_INFO_0_95V | PROCESS_INFO_DOT_1:
2924 procmon = &cnl_procmon_values[PROCMON_0_95V_DOT_1];
2925 break;
2926 case VOLTAGE_INFO_1_05V | PROCESS_INFO_DOT_0:
2927 procmon = &cnl_procmon_values[PROCMON_1_05V_DOT_0];
2928 break;
2929 case VOLTAGE_INFO_1_05V | PROCESS_INFO_DOT_1:
2930 procmon = &cnl_procmon_values[PROCMON_1_05V_DOT_1];
2931 break;
2932 }
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07002933
Paulo Zanoni62d4a5e2018-02-05 13:40:41 -02002934 val = I915_READ(ICL_PORT_COMP_DW1(port));
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07002935 val &= ~((0xff << 16) | 0xff);
2936 val |= procmon->dw1;
Paulo Zanoni62d4a5e2018-02-05 13:40:41 -02002937 I915_WRITE(ICL_PORT_COMP_DW1(port), val);
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07002938
Paulo Zanoni62d4a5e2018-02-05 13:40:41 -02002939 I915_WRITE(ICL_PORT_COMP_DW9(port), procmon->dw9);
2940 I915_WRITE(ICL_PORT_COMP_DW10(port), procmon->dw10);
Paulo Zanoniade5ee72017-08-21 17:03:56 -07002941}
2942
2943static void cnl_display_core_init(struct drm_i915_private *dev_priv, bool resume)
2944{
2945 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2946 struct i915_power_well *well;
2947 u32 val;
2948
2949 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
2950
2951 /* 1. Enable PCH Reset Handshake */
2952 val = I915_READ(HSW_NDE_RSTWRN_OPT);
2953 val |= RESET_PCH_HANDSHAKE_ENABLE;
2954 I915_WRITE(HSW_NDE_RSTWRN_OPT, val);
2955
2956 /* 2. Enable Comp */
2957 val = I915_READ(CHICKEN_MISC_2);
2958 val &= ~CNL_COMP_PWR_DOWN;
2959 I915_WRITE(CHICKEN_MISC_2, val);
2960
Paulo Zanoni62d4a5e2018-02-05 13:40:41 -02002961 /* Dummy PORT_A to get the correct CNL register from the ICL macro */
2962 cnl_set_procmon_ref_values(dev_priv, PORT_A);
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07002963
2964 val = I915_READ(CNL_PORT_COMP_DW0);
2965 val |= COMP_INIT;
2966 I915_WRITE(CNL_PORT_COMP_DW0, val);
2967
2968 /* 3. */
2969 val = I915_READ(CNL_PORT_CL1CM_DW5);
2970 val |= CL_POWER_DOWN_ENABLE;
2971 I915_WRITE(CNL_PORT_CL1CM_DW5, val);
2972
Imre Deakb38131f2017-06-29 18:37:02 +03002973 /*
2974 * 4. Enable Power Well 1 (PG1).
2975 * The AUX IO power wells will be enabled on demand.
2976 */
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07002977 mutex_lock(&power_domains->lock);
2978 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
2979 intel_power_well_enable(dev_priv, well);
2980 mutex_unlock(&power_domains->lock);
2981
2982 /* 5. Enable CD clock */
2983 cnl_init_cdclk(dev_priv);
2984
2985 /* 6. Enable DBUF */
2986 gen9_dbuf_enable(dev_priv);
Imre Deak57522c42017-10-03 12:51:58 +03002987
2988 if (resume && dev_priv->csr.dmc_payload)
2989 intel_csr_load_program(dev_priv);
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07002990}
2991
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07002992static void cnl_display_core_uninit(struct drm_i915_private *dev_priv)
2993{
2994 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2995 struct i915_power_well *well;
2996 u32 val;
2997
2998 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
2999
3000 /* 1. Disable all display engine functions -> aready done */
3001
3002 /* 2. Disable DBUF */
3003 gen9_dbuf_disable(dev_priv);
3004
3005 /* 3. Disable CD clock */
3006 cnl_uninit_cdclk(dev_priv);
3007
Imre Deakb38131f2017-06-29 18:37:02 +03003008 /*
3009 * 4. Disable Power Well 1 (PG1).
3010 * The AUX IO power wells are toggled on demand, so they are already
3011 * disabled at this point.
3012 */
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07003013 mutex_lock(&power_domains->lock);
3014 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
3015 intel_power_well_disable(dev_priv, well);
3016 mutex_unlock(&power_domains->lock);
3017
Imre Deak846c6b22017-06-29 18:36:58 +03003018 usleep_range(10, 30); /* 10 us delay per Bspec */
3019
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07003020 /* 5. Disable Comp */
3021 val = I915_READ(CHICKEN_MISC_2);
Paulo Zanoni746a5172017-07-14 14:52:28 -03003022 val |= CNL_COMP_PWR_DOWN;
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07003023 I915_WRITE(CHICKEN_MISC_2, val);
3024}
3025
Paulo Zanoniad186f32018-02-05 13:40:43 -02003026static void icl_display_core_init(struct drm_i915_private *dev_priv,
3027 bool resume)
3028{
3029 enum port port;
3030 u32 val;
3031
3032 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
3033
3034 /* 1. Enable PCH reset handshake. */
3035 val = I915_READ(HSW_NDE_RSTWRN_OPT);
3036 val |= RESET_PCH_HANDSHAKE_ENABLE;
3037 I915_WRITE(HSW_NDE_RSTWRN_OPT, val);
3038
3039 for (port = PORT_A; port <= PORT_B; port++) {
3040 /* 2. Enable DDI combo PHY comp. */
3041 val = I915_READ(ICL_PHY_MISC(port));
3042 val &= ~ICL_PHY_MISC_DE_IO_COMP_PWR_DOWN;
3043 I915_WRITE(ICL_PHY_MISC(port), val);
3044
3045 cnl_set_procmon_ref_values(dev_priv, port);
3046
3047 val = I915_READ(ICL_PORT_COMP_DW0(port));
3048 val |= COMP_INIT;
3049 I915_WRITE(ICL_PORT_COMP_DW0(port), val);
3050
3051 /* 3. Set power down enable. */
3052 val = I915_READ(ICL_PORT_CL_DW5(port));
3053 val |= CL_POWER_DOWN_ENABLE;
3054 I915_WRITE(ICL_PORT_CL_DW5(port), val);
3055 }
3056
3057 /* 4. Enable power well 1 (PG1) and aux IO power. */
3058 /* FIXME: ICL power wells code not here yet. */
3059
3060 /* 5. Enable CDCLK. */
3061 icl_init_cdclk(dev_priv);
3062
3063 /* 6. Enable DBUF. */
Mahesh Kumar746edf82018-02-05 13:40:44 -02003064 icl_dbuf_enable(dev_priv);
Paulo Zanoniad186f32018-02-05 13:40:43 -02003065
3066 /* 7. Setup MBUS. */
Mahesh Kumar4cb45852018-02-05 13:40:45 -02003067 icl_mbus_init(dev_priv);
Paulo Zanoniad186f32018-02-05 13:40:43 -02003068
3069 /* 8. CHICKEN_DCPR_1 */
3070 I915_WRITE(GEN8_CHICKEN_DCPR_1, I915_READ(GEN8_CHICKEN_DCPR_1) |
3071 CNL_DDI_CLOCK_REG_ACCESS_ON);
3072}
3073
3074static void icl_display_core_uninit(struct drm_i915_private *dev_priv)
3075{
3076 enum port port;
3077 u32 val;
3078
3079 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
3080
3081 /* 1. Disable all display engine functions -> aready done */
3082
3083 /* 2. Disable DBUF */
Mahesh Kumar746edf82018-02-05 13:40:44 -02003084 icl_dbuf_disable(dev_priv);
Paulo Zanoniad186f32018-02-05 13:40:43 -02003085
3086 /* 3. Disable CD clock */
3087 icl_uninit_cdclk(dev_priv);
3088
3089 /* 4. Disable Power Well 1 (PG1) and Aux IO Power */
3090 /* FIXME: ICL power wells code not here yet. */
3091
3092 /* 5. Disable Comp */
3093 for (port = PORT_A; port <= PORT_B; port++) {
3094 val = I915_READ(ICL_PHY_MISC(port));
3095 val |= ICL_PHY_MISC_DE_IO_COMP_PWR_DOWN;
3096 I915_WRITE(ICL_PHY_MISC(port), val);
3097 }
3098}
3099
Ville Syrjälä70722462015-04-10 18:21:28 +03003100static void chv_phy_control_init(struct drm_i915_private *dev_priv)
3101{
3102 struct i915_power_well *cmn_bc =
3103 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_BC);
3104 struct i915_power_well *cmn_d =
3105 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_D);
3106
3107 /*
3108 * DISPLAY_PHY_CONTROL can get corrupted if read. As a
3109 * workaround never ever read DISPLAY_PHY_CONTROL, and
3110 * instead maintain a shadow copy ourselves. Use the actual
Ville Syrjäläe0fce782015-07-08 23:45:54 +03003111 * power well state and lane status to reconstruct the
3112 * expected initial value.
Ville Syrjälä70722462015-04-10 18:21:28 +03003113 */
3114 dev_priv->chv_phy_control =
Ville Syrjäläbc284542015-05-26 20:22:38 +03003115 PHY_LDO_SEQ_DELAY(PHY_LDO_DELAY_600NS, DPIO_PHY0) |
3116 PHY_LDO_SEQ_DELAY(PHY_LDO_DELAY_600NS, DPIO_PHY1) |
Ville Syrjäläe0fce782015-07-08 23:45:54 +03003117 PHY_CH_POWER_MODE(PHY_CH_DEEP_PSR, DPIO_PHY0, DPIO_CH0) |
3118 PHY_CH_POWER_MODE(PHY_CH_DEEP_PSR, DPIO_PHY0, DPIO_CH1) |
3119 PHY_CH_POWER_MODE(PHY_CH_DEEP_PSR, DPIO_PHY1, DPIO_CH0);
3120
3121 /*
3122 * If all lanes are disabled we leave the override disabled
3123 * with all power down bits cleared to match the state we
3124 * would use after disabling the port. Otherwise enable the
3125 * override and set the lane powerdown bits accding to the
3126 * current lane status.
3127 */
3128 if (cmn_bc->ops->is_enabled(dev_priv, cmn_bc)) {
3129 uint32_t status = I915_READ(DPLL(PIPE_A));
3130 unsigned int mask;
3131
3132 mask = status & DPLL_PORTB_READY_MASK;
3133 if (mask == 0xf)
3134 mask = 0x0;
3135 else
3136 dev_priv->chv_phy_control |=
3137 PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY0, DPIO_CH0);
3138
3139 dev_priv->chv_phy_control |=
3140 PHY_CH_POWER_DOWN_OVRD(mask, DPIO_PHY0, DPIO_CH0);
3141
3142 mask = (status & DPLL_PORTC_READY_MASK) >> 4;
3143 if (mask == 0xf)
3144 mask = 0x0;
3145 else
3146 dev_priv->chv_phy_control |=
3147 PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY0, DPIO_CH1);
3148
3149 dev_priv->chv_phy_control |=
3150 PHY_CH_POWER_DOWN_OVRD(mask, DPIO_PHY0, DPIO_CH1);
3151
Ville Syrjälä70722462015-04-10 18:21:28 +03003152 dev_priv->chv_phy_control |= PHY_COM_LANE_RESET_DEASSERT(DPIO_PHY0);
Ville Syrjälä3be60de2015-09-08 18:05:45 +03003153
3154 dev_priv->chv_phy_assert[DPIO_PHY0] = false;
3155 } else {
3156 dev_priv->chv_phy_assert[DPIO_PHY0] = true;
Ville Syrjäläe0fce782015-07-08 23:45:54 +03003157 }
3158
3159 if (cmn_d->ops->is_enabled(dev_priv, cmn_d)) {
3160 uint32_t status = I915_READ(DPIO_PHY_STATUS);
3161 unsigned int mask;
3162
3163 mask = status & DPLL_PORTD_READY_MASK;
3164
3165 if (mask == 0xf)
3166 mask = 0x0;
3167 else
3168 dev_priv->chv_phy_control |=
3169 PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY1, DPIO_CH0);
3170
3171 dev_priv->chv_phy_control |=
3172 PHY_CH_POWER_DOWN_OVRD(mask, DPIO_PHY1, DPIO_CH0);
3173
Ville Syrjälä70722462015-04-10 18:21:28 +03003174 dev_priv->chv_phy_control |= PHY_COM_LANE_RESET_DEASSERT(DPIO_PHY1);
Ville Syrjälä3be60de2015-09-08 18:05:45 +03003175
3176 dev_priv->chv_phy_assert[DPIO_PHY1] = false;
3177 } else {
3178 dev_priv->chv_phy_assert[DPIO_PHY1] = true;
Ville Syrjäläe0fce782015-07-08 23:45:54 +03003179 }
3180
3181 I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
3182
3183 DRM_DEBUG_KMS("Initial PHY_CONTROL=0x%08x\n",
3184 dev_priv->chv_phy_control);
Ville Syrjälä70722462015-04-10 18:21:28 +03003185}
3186
Daniel Vetter9c065a72014-09-30 10:56:38 +02003187static void vlv_cmnlane_wa(struct drm_i915_private *dev_priv)
3188{
3189 struct i915_power_well *cmn =
3190 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_BC);
3191 struct i915_power_well *disp2d =
3192 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DISP2D);
3193
Daniel Vetter9c065a72014-09-30 10:56:38 +02003194 /* If the display might be already active skip this */
Ville Syrjälä5d93a6e2014-10-16 20:52:33 +03003195 if (cmn->ops->is_enabled(dev_priv, cmn) &&
3196 disp2d->ops->is_enabled(dev_priv, disp2d) &&
Daniel Vetter9c065a72014-09-30 10:56:38 +02003197 I915_READ(DPIO_CTL) & DPIO_CMNRST)
3198 return;
3199
3200 DRM_DEBUG_KMS("toggling display PHY side reset\n");
3201
3202 /* cmnlane needs DPLL registers */
3203 disp2d->ops->enable(dev_priv, disp2d);
3204
3205 /*
3206 * From VLV2A0_DP_eDP_HDMI_DPIO_driver_vbios_notes_11.docx:
3207 * Need to assert and de-assert PHY SB reset by gating the
3208 * common lane power, then un-gating it.
3209 * Simply ungating isn't enough to reset the PHY enough to get
3210 * ports and lanes running.
3211 */
3212 cmn->ops->disable(dev_priv, cmn);
3213}
3214
Daniel Vettere4e76842014-09-30 10:56:42 +02003215/**
3216 * intel_power_domains_init_hw - initialize hardware power domain state
3217 * @dev_priv: i915 device instance
Tvrtko Ursulin14bb2c12016-06-03 14:02:17 +01003218 * @resume: Called from resume code paths or not
Daniel Vettere4e76842014-09-30 10:56:42 +02003219 *
3220 * This function initializes the hardware power domain state and enables all
Imre Deak8d8c3862017-02-17 17:39:46 +02003221 * power wells belonging to the INIT power domain. Power wells in other
3222 * domains (and not in the INIT domain) are referenced or disabled during the
3223 * modeset state HW readout. After that the reference count of each power well
3224 * must match its HW enabled state, see intel_power_domains_verify_state().
Daniel Vettere4e76842014-09-30 10:56:42 +02003225 */
Imre Deak73dfc222015-11-17 17:33:53 +02003226void intel_power_domains_init_hw(struct drm_i915_private *dev_priv, bool resume)
Daniel Vetter9c065a72014-09-30 10:56:38 +02003227{
Daniel Vetter9c065a72014-09-30 10:56:38 +02003228 struct i915_power_domains *power_domains = &dev_priv->power_domains;
3229
3230 power_domains->initializing = true;
3231
Paulo Zanoniad186f32018-02-05 13:40:43 -02003232 if (IS_ICELAKE(dev_priv)) {
3233 icl_display_core_init(dev_priv, resume);
3234 } else if (IS_CANNONLAKE(dev_priv)) {
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07003235 cnl_display_core_init(dev_priv, resume);
3236 } else if (IS_GEN9_BC(dev_priv)) {
Imre Deak73dfc222015-11-17 17:33:53 +02003237 skl_display_core_init(dev_priv, resume);
Ander Conselvan de Oliveirab817c442016-12-02 10:23:56 +02003238 } else if (IS_GEN9_LP(dev_priv)) {
Imre Deakd7d7c9e2016-04-01 16:02:42 +03003239 bxt_display_core_init(dev_priv, resume);
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01003240 } else if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä770effb2015-07-08 23:45:51 +03003241 mutex_lock(&power_domains->lock);
Ville Syrjälä70722462015-04-10 18:21:28 +03003242 chv_phy_control_init(dev_priv);
Ville Syrjälä770effb2015-07-08 23:45:51 +03003243 mutex_unlock(&power_domains->lock);
Tvrtko Ursulin11a914c2016-10-13 11:03:08 +01003244 } else if (IS_VALLEYVIEW(dev_priv)) {
Daniel Vetter9c065a72014-09-30 10:56:38 +02003245 mutex_lock(&power_domains->lock);
3246 vlv_cmnlane_wa(dev_priv);
3247 mutex_unlock(&power_domains->lock);
3248 }
3249
3250 /* For now, we need the power well to be always enabled. */
3251 intel_display_set_init_power(dev_priv, true);
Imre Deakd314cd42015-11-17 17:44:23 +02003252 /* Disable power support if the user asked so. */
Michal Wajdeczko4f044a82017-09-19 19:38:44 +00003253 if (!i915_modparams.disable_power_well)
Imre Deakd314cd42015-11-17 17:44:23 +02003254 intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
Imre Deak30eade12015-11-04 19:24:13 +02003255 intel_power_domains_sync_hw(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02003256 power_domains->initializing = false;
3257}
3258
Daniel Vettere4e76842014-09-30 10:56:42 +02003259/**
Imre Deak73dfc222015-11-17 17:33:53 +02003260 * intel_power_domains_suspend - suspend power domain state
3261 * @dev_priv: i915 device instance
3262 *
3263 * This function prepares the hardware power domain state before entering
3264 * system suspend. It must be paired with intel_power_domains_init_hw().
3265 */
3266void intel_power_domains_suspend(struct drm_i915_private *dev_priv)
3267{
Imre Deakd314cd42015-11-17 17:44:23 +02003268 /*
3269 * Even if power well support was disabled we still want to disable
3270 * power wells while we are system suspended.
3271 */
Michal Wajdeczko4f044a82017-09-19 19:38:44 +00003272 if (!i915_modparams.disable_power_well)
Imre Deakd314cd42015-11-17 17:44:23 +02003273 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
Imre Deak2622d792016-02-29 22:49:02 +02003274
Paulo Zanoniad186f32018-02-05 13:40:43 -02003275 if (IS_ICELAKE(dev_priv))
3276 icl_display_core_uninit(dev_priv);
3277 else if (IS_CANNONLAKE(dev_priv))
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07003278 cnl_display_core_uninit(dev_priv);
3279 else if (IS_GEN9_BC(dev_priv))
Imre Deak2622d792016-02-29 22:49:02 +02003280 skl_display_core_uninit(dev_priv);
Ander Conselvan de Oliveirab817c442016-12-02 10:23:56 +02003281 else if (IS_GEN9_LP(dev_priv))
Imre Deakd7d7c9e2016-04-01 16:02:42 +03003282 bxt_display_core_uninit(dev_priv);
Imre Deak73dfc222015-11-17 17:33:53 +02003283}
3284
Imre Deak8d8c3862017-02-17 17:39:46 +02003285static void intel_power_domains_dump_info(struct drm_i915_private *dev_priv)
3286{
3287 struct i915_power_domains *power_domains = &dev_priv->power_domains;
3288 struct i915_power_well *power_well;
3289
3290 for_each_power_well(dev_priv, power_well) {
3291 enum intel_display_power_domain domain;
3292
3293 DRM_DEBUG_DRIVER("%-25s %d\n",
3294 power_well->name, power_well->count);
3295
3296 for_each_power_domain(domain, power_well->domains)
3297 DRM_DEBUG_DRIVER(" %-23s %d\n",
3298 intel_display_power_domain_str(domain),
3299 power_domains->domain_use_count[domain]);
3300 }
3301}
3302
3303/**
3304 * intel_power_domains_verify_state - verify the HW/SW state for all power wells
3305 * @dev_priv: i915 device instance
3306 *
3307 * Verify if the reference count of each power well matches its HW enabled
3308 * state and the total refcount of the domains it belongs to. This must be
3309 * called after modeset HW state sanitization, which is responsible for
3310 * acquiring reference counts for any power wells in use and disabling the
3311 * ones left on by BIOS but not required by any active output.
3312 */
3313void intel_power_domains_verify_state(struct drm_i915_private *dev_priv)
3314{
3315 struct i915_power_domains *power_domains = &dev_priv->power_domains;
3316 struct i915_power_well *power_well;
3317 bool dump_domain_info;
3318
3319 mutex_lock(&power_domains->lock);
3320
3321 dump_domain_info = false;
3322 for_each_power_well(dev_priv, power_well) {
3323 enum intel_display_power_domain domain;
3324 int domains_count;
3325 bool enabled;
3326
3327 /*
3328 * Power wells not belonging to any domain (like the MISC_IO
3329 * and PW1 power wells) are under FW control, so ignore them,
3330 * since their state can change asynchronously.
3331 */
3332 if (!power_well->domains)
3333 continue;
3334
3335 enabled = power_well->ops->is_enabled(dev_priv, power_well);
3336 if ((power_well->count || power_well->always_on) != enabled)
3337 DRM_ERROR("power well %s state mismatch (refcount %d/enabled %d)",
3338 power_well->name, power_well->count, enabled);
3339
3340 domains_count = 0;
3341 for_each_power_domain(domain, power_well->domains)
3342 domains_count += power_domains->domain_use_count[domain];
3343
3344 if (power_well->count != domains_count) {
3345 DRM_ERROR("power well %s refcount/domain refcount mismatch "
3346 "(refcount %d/domains refcount %d)\n",
3347 power_well->name, power_well->count,
3348 domains_count);
3349 dump_domain_info = true;
3350 }
3351 }
3352
3353 if (dump_domain_info) {
3354 static bool dumped;
3355
3356 if (!dumped) {
3357 intel_power_domains_dump_info(dev_priv);
3358 dumped = true;
3359 }
3360 }
3361
3362 mutex_unlock(&power_domains->lock);
3363}
3364
Imre Deak73dfc222015-11-17 17:33:53 +02003365/**
Daniel Vettere4e76842014-09-30 10:56:42 +02003366 * intel_runtime_pm_get - grab a runtime pm reference
3367 * @dev_priv: i915 device instance
3368 *
3369 * This function grabs a device-level runtime pm reference (mostly used for GEM
3370 * code to ensure the GTT or GT is on) and ensures that it is powered up.
3371 *
3372 * Any runtime pm reference obtained by this function must have a symmetric
3373 * call to intel_runtime_pm_put() to release the reference again.
3374 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02003375void intel_runtime_pm_get(struct drm_i915_private *dev_priv)
3376{
David Weinehall52a05c32016-08-22 13:32:44 +03003377 struct pci_dev *pdev = dev_priv->drm.pdev;
3378 struct device *kdev = &pdev->dev;
Imre Deakf5073822017-03-28 12:38:55 +03003379 int ret;
Daniel Vetter9c065a72014-09-30 10:56:38 +02003380
Imre Deakf5073822017-03-28 12:38:55 +03003381 ret = pm_runtime_get_sync(kdev);
3382 WARN_ONCE(ret < 0, "pm_runtime_get_sync() failed: %d\n", ret);
Imre Deak1f814da2015-12-16 02:52:19 +02003383
Sagar Arun Kamblead1443f2017-10-10 22:30:04 +01003384 atomic_inc(&dev_priv->runtime_pm.wakeref_count);
Imre Deakc9b88462015-12-15 20:10:34 +02003385 assert_rpm_wakelock_held(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02003386}
3387
Daniel Vettere4e76842014-09-30 10:56:42 +02003388/**
Imre Deak09731282016-02-17 14:17:42 +02003389 * intel_runtime_pm_get_if_in_use - grab a runtime pm reference if device in use
3390 * @dev_priv: i915 device instance
3391 *
3392 * This function grabs a device-level runtime pm reference if the device is
Chris Wilsonacb79142018-02-19 12:50:46 +00003393 * already in use and ensures that it is powered up. It is illegal to try
3394 * and access the HW should intel_runtime_pm_get_if_in_use() report failure.
Imre Deak09731282016-02-17 14:17:42 +02003395 *
3396 * Any runtime pm reference obtained by this function must have a symmetric
3397 * call to intel_runtime_pm_put() to release the reference again.
Chris Wilsonacb79142018-02-19 12:50:46 +00003398 *
3399 * Returns: True if the wakeref was acquired, or False otherwise.
Imre Deak09731282016-02-17 14:17:42 +02003400 */
3401bool intel_runtime_pm_get_if_in_use(struct drm_i915_private *dev_priv)
3402{
Chris Wilson135dc792016-02-25 21:10:28 +00003403 if (IS_ENABLED(CONFIG_PM)) {
Chris Wilsonacb79142018-02-19 12:50:46 +00003404 struct pci_dev *pdev = dev_priv->drm.pdev;
3405 struct device *kdev = &pdev->dev;
Imre Deak09731282016-02-17 14:17:42 +02003406
Chris Wilson135dc792016-02-25 21:10:28 +00003407 /*
3408 * In cases runtime PM is disabled by the RPM core and we get
3409 * an -EINVAL return value we are not supposed to call this
3410 * function, since the power state is undefined. This applies
3411 * atm to the late/early system suspend/resume handlers.
3412 */
Chris Wilsonacb79142018-02-19 12:50:46 +00003413 if (pm_runtime_get_if_in_use(kdev) <= 0)
Chris Wilson135dc792016-02-25 21:10:28 +00003414 return false;
3415 }
Imre Deak09731282016-02-17 14:17:42 +02003416
Sagar Arun Kamblead1443f2017-10-10 22:30:04 +01003417 atomic_inc(&dev_priv->runtime_pm.wakeref_count);
Imre Deak09731282016-02-17 14:17:42 +02003418 assert_rpm_wakelock_held(dev_priv);
3419
3420 return true;
3421}
3422
3423/**
Daniel Vettere4e76842014-09-30 10:56:42 +02003424 * intel_runtime_pm_get_noresume - grab a runtime pm reference
3425 * @dev_priv: i915 device instance
3426 *
3427 * This function grabs a device-level runtime pm reference (mostly used for GEM
3428 * code to ensure the GTT or GT is on).
3429 *
3430 * It will _not_ power up the device but instead only check that it's powered
3431 * on. Therefore it is only valid to call this functions from contexts where
3432 * the device is known to be powered up and where trying to power it up would
3433 * result in hilarity and deadlocks. That pretty much means only the system
3434 * suspend/resume code where this is used to grab runtime pm references for
3435 * delayed setup down in work items.
3436 *
3437 * Any runtime pm reference obtained by this function must have a symmetric
3438 * call to intel_runtime_pm_put() to release the reference again.
3439 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02003440void intel_runtime_pm_get_noresume(struct drm_i915_private *dev_priv)
3441{
David Weinehall52a05c32016-08-22 13:32:44 +03003442 struct pci_dev *pdev = dev_priv->drm.pdev;
3443 struct device *kdev = &pdev->dev;
Daniel Vetter9c065a72014-09-30 10:56:38 +02003444
Imre Deakc9b88462015-12-15 20:10:34 +02003445 assert_rpm_wakelock_held(dev_priv);
David Weinehallc49d13e2016-08-22 13:32:42 +03003446 pm_runtime_get_noresume(kdev);
Imre Deak1f814da2015-12-16 02:52:19 +02003447
Sagar Arun Kamblead1443f2017-10-10 22:30:04 +01003448 atomic_inc(&dev_priv->runtime_pm.wakeref_count);
Daniel Vetter9c065a72014-09-30 10:56:38 +02003449}
3450
Daniel Vettere4e76842014-09-30 10:56:42 +02003451/**
3452 * intel_runtime_pm_put - release a runtime pm reference
3453 * @dev_priv: i915 device instance
3454 *
3455 * This function drops the device-level runtime pm reference obtained by
3456 * intel_runtime_pm_get() and might power down the corresponding
3457 * hardware block right away if this is the last reference.
3458 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02003459void intel_runtime_pm_put(struct drm_i915_private *dev_priv)
3460{
David Weinehall52a05c32016-08-22 13:32:44 +03003461 struct pci_dev *pdev = dev_priv->drm.pdev;
3462 struct device *kdev = &pdev->dev;
Daniel Vetter9c065a72014-09-30 10:56:38 +02003463
Imre Deak542db3c2015-12-15 20:10:36 +02003464 assert_rpm_wakelock_held(dev_priv);
Sagar Arun Kamblead1443f2017-10-10 22:30:04 +01003465 atomic_dec(&dev_priv->runtime_pm.wakeref_count);
Imre Deak1f814da2015-12-16 02:52:19 +02003466
David Weinehallc49d13e2016-08-22 13:32:42 +03003467 pm_runtime_mark_last_busy(kdev);
3468 pm_runtime_put_autosuspend(kdev);
Daniel Vetter9c065a72014-09-30 10:56:38 +02003469}
3470
Daniel Vettere4e76842014-09-30 10:56:42 +02003471/**
3472 * intel_runtime_pm_enable - enable runtime pm
3473 * @dev_priv: i915 device instance
3474 *
3475 * This function enables runtime pm at the end of the driver load sequence.
3476 *
3477 * Note that this function does currently not enable runtime pm for the
3478 * subordinate display power domains. That is only done on the first modeset
3479 * using intel_display_set_init_power().
3480 */
Daniel Vetterf458ebb2014-09-30 10:56:39 +02003481void intel_runtime_pm_enable(struct drm_i915_private *dev_priv)
Daniel Vetter9c065a72014-09-30 10:56:38 +02003482{
David Weinehall52a05c32016-08-22 13:32:44 +03003483 struct pci_dev *pdev = dev_priv->drm.pdev;
David Weinehall52a05c32016-08-22 13:32:44 +03003484 struct device *kdev = &pdev->dev;
Daniel Vetter9c065a72014-09-30 10:56:38 +02003485
David Weinehallc49d13e2016-08-22 13:32:42 +03003486 pm_runtime_set_autosuspend_delay(kdev, 10000); /* 10s */
3487 pm_runtime_mark_last_busy(kdev);
Imre Deakcbc68dc2015-12-17 19:04:33 +02003488
Imre Deak25b181b2015-12-17 13:44:56 +02003489 /*
3490 * Take a permanent reference to disable the RPM functionality and drop
3491 * it only when unloading the driver. Use the low level get/put helpers,
3492 * so the driver's own RPM reference tracking asserts also work on
3493 * platforms without RPM support.
3494 */
Tvrtko Ursulin6772ffe2016-10-13 11:02:55 +01003495 if (!HAS_RUNTIME_PM(dev_priv)) {
Imre Deakf5073822017-03-28 12:38:55 +03003496 int ret;
3497
David Weinehallc49d13e2016-08-22 13:32:42 +03003498 pm_runtime_dont_use_autosuspend(kdev);
Imre Deakf5073822017-03-28 12:38:55 +03003499 ret = pm_runtime_get_sync(kdev);
3500 WARN(ret < 0, "pm_runtime_get_sync() failed: %d\n", ret);
Imre Deakcbc68dc2015-12-17 19:04:33 +02003501 } else {
David Weinehallc49d13e2016-08-22 13:32:42 +03003502 pm_runtime_use_autosuspend(kdev);
Imre Deakcbc68dc2015-12-17 19:04:33 +02003503 }
Daniel Vetter9c065a72014-09-30 10:56:38 +02003504
Imre Deakaabee1b2015-12-15 20:10:29 +02003505 /*
3506 * The core calls the driver load handler with an RPM reference held.
3507 * We drop that here and will reacquire it during unloading in
3508 * intel_power_domains_fini().
3509 */
David Weinehallc49d13e2016-08-22 13:32:42 +03003510 pm_runtime_put_autosuspend(kdev);
Daniel Vetter9c065a72014-09-30 10:56:38 +02003511}