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