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 | |
Daniel Vetter | 9c065a7 | 2014-09-30 10:56:38 +0200 | [diff] [blame] | 52 | #define for_each_power_well(i, power_well, domain_mask, power_domains) \ |
| 53 | for (i = 0; \ |
| 54 | i < (power_domains)->power_well_count && \ |
| 55 | ((power_well) = &(power_domains)->power_wells[i]); \ |
| 56 | i++) \ |
Jani Nikula | 95150bd | 2015-11-24 21:21:56 +0200 | [diff] [blame] | 57 | for_each_if ((power_well)->domains & (domain_mask)) |
Daniel Vetter | 9c065a7 | 2014-09-30 10:56:38 +0200 | [diff] [blame] | 58 | |
| 59 | #define for_each_power_well_rev(i, power_well, domain_mask, power_domains) \ |
| 60 | for (i = (power_domains)->power_well_count - 1; \ |
| 61 | i >= 0 && ((power_well) = &(power_domains)->power_wells[i]);\ |
| 62 | i--) \ |
Jani Nikula | 95150bd | 2015-11-24 21:21:56 +0200 | [diff] [blame] | 63 | for_each_if ((power_well)->domains & (domain_mask)) |
Daniel Vetter | 9c065a7 | 2014-09-30 10:56:38 +0200 | [diff] [blame] | 64 | |
Suketu Shah | 5aefb23 | 2015-04-16 14:22:10 +0530 | [diff] [blame] | 65 | bool intel_display_power_well_is_enabled(struct drm_i915_private *dev_priv, |
| 66 | int power_well_id); |
| 67 | |
Imre Deak | 9c8d0b8 | 2016-06-13 16:44:34 +0300 | [diff] [blame] | 68 | static struct i915_power_well * |
| 69 | lookup_power_well(struct drm_i915_private *dev_priv, int power_well_id); |
| 70 | |
Daniel Stone | 9895ad0 | 2015-11-20 15:55:33 +0000 | [diff] [blame] | 71 | const char * |
| 72 | intel_display_power_domain_str(enum intel_display_power_domain domain) |
| 73 | { |
| 74 | switch (domain) { |
| 75 | case POWER_DOMAIN_PIPE_A: |
| 76 | return "PIPE_A"; |
| 77 | case POWER_DOMAIN_PIPE_B: |
| 78 | return "PIPE_B"; |
| 79 | case POWER_DOMAIN_PIPE_C: |
| 80 | return "PIPE_C"; |
| 81 | case POWER_DOMAIN_PIPE_A_PANEL_FITTER: |
| 82 | return "PIPE_A_PANEL_FITTER"; |
| 83 | case POWER_DOMAIN_PIPE_B_PANEL_FITTER: |
| 84 | return "PIPE_B_PANEL_FITTER"; |
| 85 | case POWER_DOMAIN_PIPE_C_PANEL_FITTER: |
| 86 | return "PIPE_C_PANEL_FITTER"; |
| 87 | case POWER_DOMAIN_TRANSCODER_A: |
| 88 | return "TRANSCODER_A"; |
| 89 | case POWER_DOMAIN_TRANSCODER_B: |
| 90 | return "TRANSCODER_B"; |
| 91 | case POWER_DOMAIN_TRANSCODER_C: |
| 92 | return "TRANSCODER_C"; |
| 93 | case POWER_DOMAIN_TRANSCODER_EDP: |
| 94 | return "TRANSCODER_EDP"; |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 95 | case POWER_DOMAIN_TRANSCODER_DSI_A: |
| 96 | return "TRANSCODER_DSI_A"; |
| 97 | case POWER_DOMAIN_TRANSCODER_DSI_C: |
| 98 | return "TRANSCODER_DSI_C"; |
Daniel Stone | 9895ad0 | 2015-11-20 15:55:33 +0000 | [diff] [blame] | 99 | case POWER_DOMAIN_PORT_DDI_A_LANES: |
| 100 | return "PORT_DDI_A_LANES"; |
| 101 | case POWER_DOMAIN_PORT_DDI_B_LANES: |
| 102 | return "PORT_DDI_B_LANES"; |
| 103 | case POWER_DOMAIN_PORT_DDI_C_LANES: |
| 104 | return "PORT_DDI_C_LANES"; |
| 105 | case POWER_DOMAIN_PORT_DDI_D_LANES: |
| 106 | return "PORT_DDI_D_LANES"; |
| 107 | case POWER_DOMAIN_PORT_DDI_E_LANES: |
| 108 | return "PORT_DDI_E_LANES"; |
| 109 | case POWER_DOMAIN_PORT_DSI: |
| 110 | return "PORT_DSI"; |
| 111 | case POWER_DOMAIN_PORT_CRT: |
| 112 | return "PORT_CRT"; |
| 113 | case POWER_DOMAIN_PORT_OTHER: |
| 114 | return "PORT_OTHER"; |
| 115 | case POWER_DOMAIN_VGA: |
| 116 | return "VGA"; |
| 117 | case POWER_DOMAIN_AUDIO: |
| 118 | return "AUDIO"; |
| 119 | case POWER_DOMAIN_PLLS: |
| 120 | return "PLLS"; |
| 121 | case POWER_DOMAIN_AUX_A: |
| 122 | return "AUX_A"; |
| 123 | case POWER_DOMAIN_AUX_B: |
| 124 | return "AUX_B"; |
| 125 | case POWER_DOMAIN_AUX_C: |
| 126 | return "AUX_C"; |
| 127 | case POWER_DOMAIN_AUX_D: |
| 128 | return "AUX_D"; |
| 129 | case POWER_DOMAIN_GMBUS: |
| 130 | return "GMBUS"; |
| 131 | case POWER_DOMAIN_INIT: |
| 132 | return "INIT"; |
| 133 | case POWER_DOMAIN_MODESET: |
| 134 | return "MODESET"; |
| 135 | default: |
| 136 | MISSING_CASE(domain); |
| 137 | return "?"; |
| 138 | } |
| 139 | } |
| 140 | |
Damien Lespiau | e8ca932 | 2015-07-30 18:20:26 -0300 | [diff] [blame] | 141 | static void intel_power_well_enable(struct drm_i915_private *dev_priv, |
| 142 | struct i915_power_well *power_well) |
| 143 | { |
| 144 | DRM_DEBUG_KMS("enabling %s\n", power_well->name); |
| 145 | power_well->ops->enable(dev_priv, power_well); |
| 146 | power_well->hw_enabled = true; |
| 147 | } |
| 148 | |
Damien Lespiau | dcddab3 | 2015-07-30 18:20:27 -0300 | [diff] [blame] | 149 | static void intel_power_well_disable(struct drm_i915_private *dev_priv, |
| 150 | struct i915_power_well *power_well) |
| 151 | { |
| 152 | DRM_DEBUG_KMS("disabling %s\n", power_well->name); |
| 153 | power_well->hw_enabled = false; |
| 154 | power_well->ops->disable(dev_priv, power_well); |
| 155 | } |
| 156 | |
Imre Deak | b409ca9 | 2016-06-13 16:44:33 +0300 | [diff] [blame] | 157 | static void intel_power_well_get(struct drm_i915_private *dev_priv, |
| 158 | struct i915_power_well *power_well) |
| 159 | { |
| 160 | if (!power_well->count++) |
| 161 | intel_power_well_enable(dev_priv, power_well); |
| 162 | } |
| 163 | |
| 164 | static void intel_power_well_put(struct drm_i915_private *dev_priv, |
| 165 | struct i915_power_well *power_well) |
| 166 | { |
| 167 | WARN(!power_well->count, "Use count on power well %s is already zero", |
| 168 | power_well->name); |
| 169 | |
| 170 | if (!--power_well->count) |
| 171 | intel_power_well_disable(dev_priv, power_well); |
| 172 | } |
| 173 | |
Daniel Vetter | e4e7684 | 2014-09-30 10:56:42 +0200 | [diff] [blame] | 174 | /* |
Daniel Vetter | 9c065a7 | 2014-09-30 10:56:38 +0200 | [diff] [blame] | 175 | * We should only use the power well if we explicitly asked the hardware to |
| 176 | * enable it, so check if it's enabled and also check if we've requested it to |
| 177 | * be enabled. |
| 178 | */ |
| 179 | static bool hsw_power_well_enabled(struct drm_i915_private *dev_priv, |
| 180 | struct i915_power_well *power_well) |
| 181 | { |
| 182 | return I915_READ(HSW_PWR_WELL_DRIVER) == |
| 183 | (HSW_PWR_WELL_ENABLE_REQUEST | HSW_PWR_WELL_STATE_ENABLED); |
| 184 | } |
| 185 | |
Daniel Vetter | e4e7684 | 2014-09-30 10:56:42 +0200 | [diff] [blame] | 186 | /** |
| 187 | * __intel_display_power_is_enabled - unlocked check for a power domain |
| 188 | * @dev_priv: i915 device instance |
| 189 | * @domain: power domain to check |
| 190 | * |
| 191 | * This is the unlocked version of intel_display_power_is_enabled() and should |
| 192 | * only be used from error capture and recovery code where deadlocks are |
| 193 | * possible. |
| 194 | * |
| 195 | * Returns: |
| 196 | * True when the power domain is enabled, false otherwise. |
| 197 | */ |
Daniel Vetter | f458ebb | 2014-09-30 10:56:39 +0200 | [diff] [blame] | 198 | bool __intel_display_power_is_enabled(struct drm_i915_private *dev_priv, |
| 199 | enum intel_display_power_domain domain) |
Daniel Vetter | 9c065a7 | 2014-09-30 10:56:38 +0200 | [diff] [blame] | 200 | { |
| 201 | struct i915_power_domains *power_domains; |
| 202 | struct i915_power_well *power_well; |
| 203 | bool is_enabled; |
| 204 | int i; |
| 205 | |
| 206 | if (dev_priv->pm.suspended) |
| 207 | return false; |
| 208 | |
| 209 | power_domains = &dev_priv->power_domains; |
| 210 | |
| 211 | is_enabled = true; |
| 212 | |
| 213 | for_each_power_well_rev(i, power_well, BIT(domain), power_domains) { |
| 214 | if (power_well->always_on) |
| 215 | continue; |
| 216 | |
| 217 | if (!power_well->hw_enabled) { |
| 218 | is_enabled = false; |
| 219 | break; |
| 220 | } |
| 221 | } |
| 222 | |
| 223 | return is_enabled; |
| 224 | } |
| 225 | |
Daniel Vetter | e4e7684 | 2014-09-30 10:56:42 +0200 | [diff] [blame] | 226 | /** |
Damien Lespiau | f61ccae | 2014-11-25 13:45:41 +0000 | [diff] [blame] | 227 | * intel_display_power_is_enabled - check for a power domain |
Daniel Vetter | e4e7684 | 2014-09-30 10:56:42 +0200 | [diff] [blame] | 228 | * @dev_priv: i915 device instance |
| 229 | * @domain: power domain to check |
| 230 | * |
| 231 | * This function can be used to check the hw power domain state. It is mostly |
| 232 | * used in hardware state readout functions. Everywhere else code should rely |
| 233 | * upon explicit power domain reference counting to ensure that the hardware |
| 234 | * block is powered up before accessing it. |
| 235 | * |
| 236 | * Callers must hold the relevant modesetting locks to ensure that concurrent |
| 237 | * threads can't disable the power well while the caller tries to read a few |
| 238 | * registers. |
| 239 | * |
| 240 | * Returns: |
| 241 | * True when the power domain is enabled, false otherwise. |
| 242 | */ |
Daniel Vetter | f458ebb | 2014-09-30 10:56:39 +0200 | [diff] [blame] | 243 | bool intel_display_power_is_enabled(struct drm_i915_private *dev_priv, |
| 244 | enum intel_display_power_domain domain) |
Daniel Vetter | 9c065a7 | 2014-09-30 10:56:38 +0200 | [diff] [blame] | 245 | { |
| 246 | struct i915_power_domains *power_domains; |
| 247 | bool ret; |
| 248 | |
| 249 | power_domains = &dev_priv->power_domains; |
| 250 | |
| 251 | mutex_lock(&power_domains->lock); |
Daniel Vetter | f458ebb | 2014-09-30 10:56:39 +0200 | [diff] [blame] | 252 | ret = __intel_display_power_is_enabled(dev_priv, domain); |
Daniel Vetter | 9c065a7 | 2014-09-30 10:56:38 +0200 | [diff] [blame] | 253 | mutex_unlock(&power_domains->lock); |
| 254 | |
| 255 | return ret; |
| 256 | } |
| 257 | |
Daniel Vetter | e4e7684 | 2014-09-30 10:56:42 +0200 | [diff] [blame] | 258 | /** |
| 259 | * intel_display_set_init_power - set the initial power domain state |
| 260 | * @dev_priv: i915 device instance |
| 261 | * @enable: whether to enable or disable the initial power domain state |
| 262 | * |
| 263 | * For simplicity our driver load/unload and system suspend/resume code assumes |
| 264 | * that all power domains are always enabled. This functions controls the state |
| 265 | * of this little hack. While the initial power domain state is enabled runtime |
| 266 | * pm is effectively disabled. |
| 267 | */ |
Daniel Vetter | d9bc89d9 | 2014-09-30 10:56:40 +0200 | [diff] [blame] | 268 | void intel_display_set_init_power(struct drm_i915_private *dev_priv, |
| 269 | bool enable) |
| 270 | { |
| 271 | if (dev_priv->power_domains.init_power_on == enable) |
| 272 | return; |
| 273 | |
| 274 | if (enable) |
| 275 | intel_display_power_get(dev_priv, POWER_DOMAIN_INIT); |
| 276 | else |
| 277 | intel_display_power_put(dev_priv, POWER_DOMAIN_INIT); |
| 278 | |
| 279 | dev_priv->power_domains.init_power_on = enable; |
| 280 | } |
| 281 | |
Daniel Vetter | 9c065a7 | 2014-09-30 10:56:38 +0200 | [diff] [blame] | 282 | /* |
| 283 | * Starting with Haswell, we have a "Power Down Well" that can be turned off |
| 284 | * when not needed anymore. We have 4 registers that can request the power well |
| 285 | * to be enabled, and it will only be disabled if none of the registers is |
| 286 | * requesting it to be enabled. |
| 287 | */ |
| 288 | static void hsw_power_well_post_enable(struct drm_i915_private *dev_priv) |
| 289 | { |
David Weinehall | 52a05c3 | 2016-08-22 13:32:44 +0300 | [diff] [blame] | 290 | struct pci_dev *pdev = dev_priv->drm.pdev; |
Daniel Vetter | 9c065a7 | 2014-09-30 10:56:38 +0200 | [diff] [blame] | 291 | |
| 292 | /* |
| 293 | * After we re-enable the power well, if we touch VGA register 0x3d5 |
| 294 | * we'll get unclaimed register interrupts. This stops after we write |
| 295 | * anything to the VGA MSR register. The vgacon module uses this |
| 296 | * register all the time, so if we unbind our driver and, as a |
| 297 | * consequence, bind vgacon, we'll get stuck in an infinite loop at |
| 298 | * console_unlock(). So make here we touch the VGA MSR register, making |
| 299 | * sure vgacon can keep working normally without triggering interrupts |
| 300 | * and error messages. |
| 301 | */ |
David Weinehall | 52a05c3 | 2016-08-22 13:32:44 +0300 | [diff] [blame] | 302 | vga_get_uninterruptible(pdev, VGA_RSRC_LEGACY_IO); |
Daniel Vetter | 9c065a7 | 2014-09-30 10:56:38 +0200 | [diff] [blame] | 303 | outb(inb(VGA_MSR_READ), VGA_MSR_WRITE); |
David Weinehall | 52a05c3 | 2016-08-22 13:32:44 +0300 | [diff] [blame] | 304 | vga_put(pdev, VGA_RSRC_LEGACY_IO); |
Daniel Vetter | 9c065a7 | 2014-09-30 10:56:38 +0200 | [diff] [blame] | 305 | |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 306 | if (IS_BROADWELL(dev_priv)) |
Damien Lespiau | 4c6c03b | 2015-03-06 18:50:48 +0000 | [diff] [blame] | 307 | gen8_irq_power_well_post_enable(dev_priv, |
| 308 | 1 << PIPE_C | 1 << PIPE_B); |
Daniel Vetter | 9c065a7 | 2014-09-30 10:56:38 +0200 | [diff] [blame] | 309 | } |
| 310 | |
Ville Syrjälä | aae8ba8 | 2016-02-19 20:47:30 +0200 | [diff] [blame] | 311 | static void hsw_power_well_pre_disable(struct drm_i915_private *dev_priv) |
| 312 | { |
| 313 | if (IS_BROADWELL(dev_priv)) |
| 314 | gen8_irq_power_well_pre_disable(dev_priv, |
| 315 | 1 << PIPE_C | 1 << PIPE_B); |
| 316 | } |
| 317 | |
Damien Lespiau | d14c034 | 2015-03-06 18:50:51 +0000 | [diff] [blame] | 318 | static void skl_power_well_post_enable(struct drm_i915_private *dev_priv, |
| 319 | struct i915_power_well *power_well) |
| 320 | { |
David Weinehall | 52a05c3 | 2016-08-22 13:32:44 +0300 | [diff] [blame] | 321 | struct pci_dev *pdev = dev_priv->drm.pdev; |
Damien Lespiau | d14c034 | 2015-03-06 18:50:51 +0000 | [diff] [blame] | 322 | |
| 323 | /* |
| 324 | * After we re-enable the power well, if we touch VGA register 0x3d5 |
| 325 | * we'll get unclaimed register interrupts. This stops after we write |
| 326 | * anything to the VGA MSR register. The vgacon module uses this |
| 327 | * register all the time, so if we unbind our driver and, as a |
| 328 | * consequence, bind vgacon, we'll get stuck in an infinite loop at |
| 329 | * console_unlock(). So make here we touch the VGA MSR register, making |
| 330 | * sure vgacon can keep working normally without triggering interrupts |
| 331 | * and error messages. |
| 332 | */ |
Ander Conselvan de Oliveira | 01c3faa | 2016-10-06 19:22:14 +0300 | [diff] [blame] | 333 | if (power_well->id == SKL_DISP_PW_2) { |
David Weinehall | 52a05c3 | 2016-08-22 13:32:44 +0300 | [diff] [blame] | 334 | vga_get_uninterruptible(pdev, VGA_RSRC_LEGACY_IO); |
Damien Lespiau | d14c034 | 2015-03-06 18:50:51 +0000 | [diff] [blame] | 335 | outb(inb(VGA_MSR_READ), VGA_MSR_WRITE); |
David Weinehall | 52a05c3 | 2016-08-22 13:32:44 +0300 | [diff] [blame] | 336 | vga_put(pdev, VGA_RSRC_LEGACY_IO); |
Damien Lespiau | d14c034 | 2015-03-06 18:50:51 +0000 | [diff] [blame] | 337 | |
| 338 | gen8_irq_power_well_post_enable(dev_priv, |
| 339 | 1 << PIPE_C | 1 << PIPE_B); |
| 340 | } |
Damien Lespiau | d14c034 | 2015-03-06 18:50:51 +0000 | [diff] [blame] | 341 | } |
| 342 | |
Ville Syrjälä | aae8ba8 | 2016-02-19 20:47:30 +0200 | [diff] [blame] | 343 | static void skl_power_well_pre_disable(struct drm_i915_private *dev_priv, |
| 344 | struct i915_power_well *power_well) |
| 345 | { |
Ander Conselvan de Oliveira | 01c3faa | 2016-10-06 19:22:14 +0300 | [diff] [blame] | 346 | if (power_well->id == SKL_DISP_PW_2) |
Ville Syrjälä | aae8ba8 | 2016-02-19 20:47:30 +0200 | [diff] [blame] | 347 | gen8_irq_power_well_pre_disable(dev_priv, |
| 348 | 1 << PIPE_C | 1 << PIPE_B); |
| 349 | } |
| 350 | |
Daniel Vetter | 9c065a7 | 2014-09-30 10:56:38 +0200 | [diff] [blame] | 351 | static void hsw_set_power_well(struct drm_i915_private *dev_priv, |
| 352 | struct i915_power_well *power_well, bool enable) |
| 353 | { |
| 354 | bool is_enabled, enable_requested; |
| 355 | uint32_t tmp; |
| 356 | |
| 357 | tmp = I915_READ(HSW_PWR_WELL_DRIVER); |
| 358 | is_enabled = tmp & HSW_PWR_WELL_STATE_ENABLED; |
| 359 | enable_requested = tmp & HSW_PWR_WELL_ENABLE_REQUEST; |
| 360 | |
| 361 | if (enable) { |
| 362 | if (!enable_requested) |
| 363 | I915_WRITE(HSW_PWR_WELL_DRIVER, |
| 364 | HSW_PWR_WELL_ENABLE_REQUEST); |
| 365 | |
| 366 | if (!is_enabled) { |
| 367 | DRM_DEBUG_KMS("Enabling power well\n"); |
Chris Wilson | 2c2ccc3 | 2016-06-30 15:33:32 +0100 | [diff] [blame] | 368 | if (intel_wait_for_register(dev_priv, |
| 369 | HSW_PWR_WELL_DRIVER, |
| 370 | HSW_PWR_WELL_STATE_ENABLED, |
| 371 | HSW_PWR_WELL_STATE_ENABLED, |
| 372 | 20)) |
Daniel Vetter | 9c065a7 | 2014-09-30 10:56:38 +0200 | [diff] [blame] | 373 | DRM_ERROR("Timeout enabling power well\n"); |
Paulo Zanoni | 6d729bf | 2014-10-07 16:11:11 -0300 | [diff] [blame] | 374 | hsw_power_well_post_enable(dev_priv); |
Daniel Vetter | 9c065a7 | 2014-09-30 10:56:38 +0200 | [diff] [blame] | 375 | } |
| 376 | |
Daniel Vetter | 9c065a7 | 2014-09-30 10:56:38 +0200 | [diff] [blame] | 377 | } else { |
| 378 | if (enable_requested) { |
Ville Syrjälä | aae8ba8 | 2016-02-19 20:47:30 +0200 | [diff] [blame] | 379 | hsw_power_well_pre_disable(dev_priv); |
Daniel Vetter | 9c065a7 | 2014-09-30 10:56:38 +0200 | [diff] [blame] | 380 | I915_WRITE(HSW_PWR_WELL_DRIVER, 0); |
| 381 | POSTING_READ(HSW_PWR_WELL_DRIVER); |
| 382 | DRM_DEBUG_KMS("Requesting to disable the power well\n"); |
| 383 | } |
| 384 | } |
| 385 | } |
| 386 | |
Satheeshakrishna M | 94dd513 | 2015-02-04 13:57:44 +0000 | [diff] [blame] | 387 | #define SKL_DISPLAY_POWERWELL_2_POWER_DOMAINS ( \ |
| 388 | BIT(POWER_DOMAIN_TRANSCODER_A) | \ |
| 389 | BIT(POWER_DOMAIN_PIPE_B) | \ |
| 390 | BIT(POWER_DOMAIN_TRANSCODER_B) | \ |
| 391 | BIT(POWER_DOMAIN_PIPE_C) | \ |
| 392 | BIT(POWER_DOMAIN_TRANSCODER_C) | \ |
| 393 | BIT(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \ |
| 394 | BIT(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \ |
Patrik Jakobsson | 6331a70 | 2015-11-09 16:48:21 +0100 | [diff] [blame] | 395 | BIT(POWER_DOMAIN_PORT_DDI_B_LANES) | \ |
| 396 | BIT(POWER_DOMAIN_PORT_DDI_C_LANES) | \ |
| 397 | BIT(POWER_DOMAIN_PORT_DDI_D_LANES) | \ |
| 398 | BIT(POWER_DOMAIN_PORT_DDI_E_LANES) | \ |
Satheeshakrishna M | 94dd513 | 2015-02-04 13:57:44 +0000 | [diff] [blame] | 399 | BIT(POWER_DOMAIN_AUX_B) | \ |
| 400 | BIT(POWER_DOMAIN_AUX_C) | \ |
| 401 | BIT(POWER_DOMAIN_AUX_D) | \ |
| 402 | BIT(POWER_DOMAIN_AUDIO) | \ |
| 403 | BIT(POWER_DOMAIN_VGA) | \ |
| 404 | BIT(POWER_DOMAIN_INIT)) |
Satheeshakrishna M | 94dd513 | 2015-02-04 13:57:44 +0000 | [diff] [blame] | 405 | #define SKL_DISPLAY_DDI_A_E_POWER_DOMAINS ( \ |
Patrik Jakobsson | 6331a70 | 2015-11-09 16:48:21 +0100 | [diff] [blame] | 406 | BIT(POWER_DOMAIN_PORT_DDI_A_LANES) | \ |
| 407 | BIT(POWER_DOMAIN_PORT_DDI_E_LANES) | \ |
Satheeshakrishna M | 94dd513 | 2015-02-04 13:57:44 +0000 | [diff] [blame] | 408 | BIT(POWER_DOMAIN_INIT)) |
| 409 | #define SKL_DISPLAY_DDI_B_POWER_DOMAINS ( \ |
Patrik Jakobsson | 6331a70 | 2015-11-09 16:48:21 +0100 | [diff] [blame] | 410 | BIT(POWER_DOMAIN_PORT_DDI_B_LANES) | \ |
Satheeshakrishna M | 94dd513 | 2015-02-04 13:57:44 +0000 | [diff] [blame] | 411 | BIT(POWER_DOMAIN_INIT)) |
| 412 | #define SKL_DISPLAY_DDI_C_POWER_DOMAINS ( \ |
Patrik Jakobsson | 6331a70 | 2015-11-09 16:48:21 +0100 | [diff] [blame] | 413 | BIT(POWER_DOMAIN_PORT_DDI_C_LANES) | \ |
Satheeshakrishna M | 94dd513 | 2015-02-04 13:57:44 +0000 | [diff] [blame] | 414 | BIT(POWER_DOMAIN_INIT)) |
| 415 | #define SKL_DISPLAY_DDI_D_POWER_DOMAINS ( \ |
Patrik Jakobsson | 6331a70 | 2015-11-09 16:48:21 +0100 | [diff] [blame] | 416 | BIT(POWER_DOMAIN_PORT_DDI_D_LANES) | \ |
Satheeshakrishna M | 94dd513 | 2015-02-04 13:57:44 +0000 | [diff] [blame] | 417 | BIT(POWER_DOMAIN_INIT)) |
Patrik Jakobsson | 9f836f9 | 2015-11-16 16:20:01 +0100 | [diff] [blame] | 418 | #define SKL_DISPLAY_DC_OFF_POWER_DOMAINS ( \ |
| 419 | SKL_DISPLAY_POWERWELL_2_POWER_DOMAINS | \ |
| 420 | BIT(POWER_DOMAIN_MODESET) | \ |
| 421 | BIT(POWER_DOMAIN_AUX_A) | \ |
| 422 | BIT(POWER_DOMAIN_INIT)) |
Satheeshakrishna M | 94dd513 | 2015-02-04 13:57:44 +0000 | [diff] [blame] | 423 | |
Satheeshakrishna M | 0b4a2a3 | 2014-07-11 14:51:13 +0530 | [diff] [blame] | 424 | #define BXT_DISPLAY_POWERWELL_2_POWER_DOMAINS ( \ |
| 425 | BIT(POWER_DOMAIN_TRANSCODER_A) | \ |
| 426 | BIT(POWER_DOMAIN_PIPE_B) | \ |
| 427 | BIT(POWER_DOMAIN_TRANSCODER_B) | \ |
| 428 | BIT(POWER_DOMAIN_PIPE_C) | \ |
| 429 | BIT(POWER_DOMAIN_TRANSCODER_C) | \ |
| 430 | BIT(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \ |
| 431 | BIT(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \ |
Patrik Jakobsson | 6331a70 | 2015-11-09 16:48:21 +0100 | [diff] [blame] | 432 | BIT(POWER_DOMAIN_PORT_DDI_B_LANES) | \ |
| 433 | BIT(POWER_DOMAIN_PORT_DDI_C_LANES) | \ |
Satheeshakrishna M | 0b4a2a3 | 2014-07-11 14:51:13 +0530 | [diff] [blame] | 434 | BIT(POWER_DOMAIN_AUX_B) | \ |
| 435 | BIT(POWER_DOMAIN_AUX_C) | \ |
| 436 | BIT(POWER_DOMAIN_AUDIO) | \ |
| 437 | BIT(POWER_DOMAIN_VGA) | \ |
Ville Syrjälä | f0ab43e | 2015-11-09 16:48:19 +0100 | [diff] [blame] | 438 | BIT(POWER_DOMAIN_GMBUS) | \ |
Satheeshakrishna M | 0b4a2a3 | 2014-07-11 14:51:13 +0530 | [diff] [blame] | 439 | BIT(POWER_DOMAIN_INIT)) |
Patrik Jakobsson | 9f836f9 | 2015-11-16 16:20:01 +0100 | [diff] [blame] | 440 | #define BXT_DISPLAY_DC_OFF_POWER_DOMAINS ( \ |
| 441 | BXT_DISPLAY_POWERWELL_2_POWER_DOMAINS | \ |
| 442 | BIT(POWER_DOMAIN_MODESET) | \ |
| 443 | BIT(POWER_DOMAIN_AUX_A) | \ |
| 444 | BIT(POWER_DOMAIN_INIT)) |
Imre Deak | 9c8d0b8 | 2016-06-13 16:44:34 +0300 | [diff] [blame] | 445 | #define BXT_DPIO_CMN_A_POWER_DOMAINS ( \ |
| 446 | BIT(POWER_DOMAIN_PORT_DDI_A_LANES) | \ |
| 447 | BIT(POWER_DOMAIN_AUX_A) | \ |
| 448 | BIT(POWER_DOMAIN_INIT)) |
| 449 | #define BXT_DPIO_CMN_BC_POWER_DOMAINS ( \ |
| 450 | BIT(POWER_DOMAIN_PORT_DDI_B_LANES) | \ |
| 451 | BIT(POWER_DOMAIN_PORT_DDI_C_LANES) | \ |
| 452 | BIT(POWER_DOMAIN_AUX_B) | \ |
| 453 | BIT(POWER_DOMAIN_AUX_C) | \ |
| 454 | BIT(POWER_DOMAIN_INIT)) |
Satheeshakrishna M | 0b4a2a3 | 2014-07-11 14:51:13 +0530 | [diff] [blame] | 455 | |
Ander Conselvan de Oliveira | 0d03926 | 2016-12-02 10:23:50 +0200 | [diff] [blame] | 456 | #define GLK_DISPLAY_POWERWELL_2_POWER_DOMAINS ( \ |
| 457 | BIT(POWER_DOMAIN_TRANSCODER_A) | \ |
| 458 | BIT(POWER_DOMAIN_PIPE_B) | \ |
| 459 | BIT(POWER_DOMAIN_TRANSCODER_B) | \ |
| 460 | BIT(POWER_DOMAIN_PIPE_C) | \ |
| 461 | BIT(POWER_DOMAIN_TRANSCODER_C) | \ |
| 462 | BIT(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \ |
| 463 | BIT(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \ |
| 464 | BIT(POWER_DOMAIN_PORT_DDI_B_LANES) | \ |
| 465 | BIT(POWER_DOMAIN_PORT_DDI_C_LANES) | \ |
| 466 | BIT(POWER_DOMAIN_AUX_B) | \ |
| 467 | BIT(POWER_DOMAIN_AUX_C) | \ |
| 468 | BIT(POWER_DOMAIN_AUDIO) | \ |
| 469 | BIT(POWER_DOMAIN_VGA) | \ |
| 470 | BIT(POWER_DOMAIN_INIT)) |
| 471 | #define GLK_DISPLAY_DDI_A_POWER_DOMAINS ( \ |
| 472 | BIT(POWER_DOMAIN_PORT_DDI_A_LANES) | \ |
| 473 | BIT(POWER_DOMAIN_INIT)) |
| 474 | #define GLK_DISPLAY_DDI_B_POWER_DOMAINS ( \ |
| 475 | BIT(POWER_DOMAIN_PORT_DDI_B_LANES) | \ |
| 476 | BIT(POWER_DOMAIN_INIT)) |
| 477 | #define GLK_DISPLAY_DDI_C_POWER_DOMAINS ( \ |
| 478 | BIT(POWER_DOMAIN_PORT_DDI_C_LANES) | \ |
| 479 | BIT(POWER_DOMAIN_INIT)) |
Ander Conselvan de Oliveira | 0a116ce | 2016-12-02 10:23:51 +0200 | [diff] [blame] | 480 | #define GLK_DPIO_CMN_A_POWER_DOMAINS ( \ |
| 481 | BIT(POWER_DOMAIN_PORT_DDI_A_LANES) | \ |
| 482 | BIT(POWER_DOMAIN_AUX_A) | \ |
| 483 | BIT(POWER_DOMAIN_INIT)) |
| 484 | #define GLK_DPIO_CMN_B_POWER_DOMAINS ( \ |
| 485 | BIT(POWER_DOMAIN_PORT_DDI_B_LANES) | \ |
| 486 | BIT(POWER_DOMAIN_AUX_B) | \ |
| 487 | BIT(POWER_DOMAIN_INIT)) |
| 488 | #define GLK_DPIO_CMN_C_POWER_DOMAINS ( \ |
| 489 | BIT(POWER_DOMAIN_PORT_DDI_C_LANES) | \ |
| 490 | BIT(POWER_DOMAIN_AUX_C) | \ |
| 491 | BIT(POWER_DOMAIN_INIT)) |
Ander Conselvan de Oliveira | 0d03926 | 2016-12-02 10:23:50 +0200 | [diff] [blame] | 492 | #define GLK_DISPLAY_AUX_A_POWER_DOMAINS ( \ |
| 493 | BIT(POWER_DOMAIN_AUX_A) | \ |
| 494 | BIT(POWER_DOMAIN_INIT)) |
| 495 | #define GLK_DISPLAY_AUX_B_POWER_DOMAINS ( \ |
| 496 | BIT(POWER_DOMAIN_AUX_B) | \ |
| 497 | BIT(POWER_DOMAIN_INIT)) |
| 498 | #define GLK_DISPLAY_AUX_C_POWER_DOMAINS ( \ |
| 499 | BIT(POWER_DOMAIN_AUX_C) | \ |
| 500 | BIT(POWER_DOMAIN_INIT)) |
| 501 | #define GLK_DISPLAY_DC_OFF_POWER_DOMAINS ( \ |
| 502 | GLK_DISPLAY_POWERWELL_2_POWER_DOMAINS | \ |
| 503 | BIT(POWER_DOMAIN_MODESET) | \ |
| 504 | BIT(POWER_DOMAIN_AUX_A) | \ |
| 505 | BIT(POWER_DOMAIN_INIT)) |
| 506 | |
A.Sunil Kamath | 664326f | 2014-11-24 13:37:44 +0530 | [diff] [blame] | 507 | static void assert_can_enable_dc9(struct drm_i915_private *dev_priv) |
| 508 | { |
Imre Deak | bfcdabe | 2016-04-01 16:02:37 +0300 | [diff] [blame] | 509 | WARN_ONCE((I915_READ(DC_STATE_EN) & DC_STATE_EN_DC9), |
| 510 | "DC9 already programmed to be enabled.\n"); |
| 511 | WARN_ONCE(I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC5, |
| 512 | "DC5 still not disabled to enable DC9.\n"); |
| 513 | WARN_ONCE(I915_READ(HSW_PWR_WELL_DRIVER), "Power well on.\n"); |
| 514 | WARN_ONCE(intel_irqs_enabled(dev_priv), |
| 515 | "Interrupts not disabled yet.\n"); |
A.Sunil Kamath | 664326f | 2014-11-24 13:37:44 +0530 | [diff] [blame] | 516 | |
| 517 | /* |
| 518 | * TODO: check for the following to verify the conditions to enter DC9 |
| 519 | * state are satisfied: |
| 520 | * 1] Check relevant display engine registers to verify if mode set |
| 521 | * disable sequence was followed. |
| 522 | * 2] Check if display uninitialize sequence is initialized. |
| 523 | */ |
| 524 | } |
| 525 | |
| 526 | static void assert_can_disable_dc9(struct drm_i915_private *dev_priv) |
| 527 | { |
Imre Deak | bfcdabe | 2016-04-01 16:02:37 +0300 | [diff] [blame] | 528 | WARN_ONCE(intel_irqs_enabled(dev_priv), |
| 529 | "Interrupts not disabled yet.\n"); |
| 530 | WARN_ONCE(I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC5, |
| 531 | "DC5 still not disabled.\n"); |
A.Sunil Kamath | 664326f | 2014-11-24 13:37:44 +0530 | [diff] [blame] | 532 | |
| 533 | /* |
| 534 | * TODO: check for the following to verify DC9 state was indeed |
| 535 | * entered before programming to disable it: |
| 536 | * 1] Check relevant display engine registers to verify if mode |
| 537 | * set disable sequence was followed. |
| 538 | * 2] Check if display uninitialize sequence is initialized. |
| 539 | */ |
| 540 | } |
| 541 | |
Mika Kuoppala | 779cb5d | 2016-02-18 17:58:09 +0200 | [diff] [blame] | 542 | static void gen9_write_dc_state(struct drm_i915_private *dev_priv, |
| 543 | u32 state) |
| 544 | { |
| 545 | int rewrites = 0; |
| 546 | int rereads = 0; |
| 547 | u32 v; |
| 548 | |
| 549 | I915_WRITE(DC_STATE_EN, state); |
| 550 | |
| 551 | /* It has been observed that disabling the dc6 state sometimes |
| 552 | * doesn't stick and dmc keeps returning old value. Make sure |
| 553 | * the write really sticks enough times and also force rewrite until |
| 554 | * we are confident that state is exactly what we want. |
| 555 | */ |
| 556 | do { |
| 557 | v = I915_READ(DC_STATE_EN); |
| 558 | |
| 559 | if (v != state) { |
| 560 | I915_WRITE(DC_STATE_EN, state); |
| 561 | rewrites++; |
| 562 | rereads = 0; |
| 563 | } else if (rereads++ > 5) { |
| 564 | break; |
| 565 | } |
| 566 | |
| 567 | } while (rewrites < 100); |
| 568 | |
| 569 | if (v != state) |
| 570 | DRM_ERROR("Writing dc state to 0x%x failed, now 0x%x\n", |
| 571 | state, v); |
| 572 | |
| 573 | /* Most of the times we need one retry, avoid spam */ |
| 574 | if (rewrites > 1) |
| 575 | DRM_DEBUG_KMS("Rewrote dc state to 0x%x %d times\n", |
| 576 | state, rewrites); |
| 577 | } |
| 578 | |
Imre Deak | da2f41d | 2016-04-20 20:27:56 +0300 | [diff] [blame] | 579 | static u32 gen9_dc_mask(struct drm_i915_private *dev_priv) |
A.Sunil Kamath | 664326f | 2014-11-24 13:37:44 +0530 | [diff] [blame] | 580 | { |
Imre Deak | da2f41d | 2016-04-20 20:27:56 +0300 | [diff] [blame] | 581 | u32 mask; |
A.Sunil Kamath | 664326f | 2014-11-24 13:37:44 +0530 | [diff] [blame] | 582 | |
Imre Deak | 13ae3a0 | 2015-11-04 19:24:16 +0200 | [diff] [blame] | 583 | mask = DC_STATE_EN_UPTO_DC5; |
Ander Conselvan de Oliveira | cc3f90f | 2016-12-02 10:23:49 +0200 | [diff] [blame] | 584 | if (IS_GEN9_LP(dev_priv)) |
Imre Deak | 13ae3a0 | 2015-11-04 19:24:16 +0200 | [diff] [blame] | 585 | mask |= DC_STATE_EN_DC9; |
| 586 | else |
| 587 | mask |= DC_STATE_EN_UPTO_DC6; |
A.Sunil Kamath | 664326f | 2014-11-24 13:37:44 +0530 | [diff] [blame] | 588 | |
Imre Deak | da2f41d | 2016-04-20 20:27:56 +0300 | [diff] [blame] | 589 | return mask; |
| 590 | } |
| 591 | |
| 592 | void gen9_sanitize_dc_state(struct drm_i915_private *dev_priv) |
| 593 | { |
| 594 | u32 val; |
| 595 | |
| 596 | val = I915_READ(DC_STATE_EN) & gen9_dc_mask(dev_priv); |
| 597 | |
| 598 | DRM_DEBUG_KMS("Resetting DC state tracking from %02x to %02x\n", |
| 599 | dev_priv->csr.dc_state, val); |
| 600 | dev_priv->csr.dc_state = val; |
| 601 | } |
| 602 | |
| 603 | static void gen9_set_dc_state(struct drm_i915_private *dev_priv, uint32_t state) |
| 604 | { |
| 605 | uint32_t val; |
| 606 | uint32_t mask; |
| 607 | |
Imre Deak | a37baf3 | 2016-02-29 22:49:03 +0200 | [diff] [blame] | 608 | if (WARN_ON_ONCE(state & ~dev_priv->csr.allowed_dc_mask)) |
| 609 | state &= dev_priv->csr.allowed_dc_mask; |
Patrik Jakobsson | 443646c | 2015-11-16 15:01:06 +0100 | [diff] [blame] | 610 | |
A.Sunil Kamath | 664326f | 2014-11-24 13:37:44 +0530 | [diff] [blame] | 611 | val = I915_READ(DC_STATE_EN); |
Imre Deak | da2f41d | 2016-04-20 20:27:56 +0300 | [diff] [blame] | 612 | mask = gen9_dc_mask(dev_priv); |
Imre Deak | 13ae3a0 | 2015-11-04 19:24:16 +0200 | [diff] [blame] | 613 | DRM_DEBUG_KMS("Setting DC state from %02x to %02x\n", |
| 614 | val & mask, state); |
Patrik Jakobsson | 832dba8 | 2016-02-18 17:21:11 +0200 | [diff] [blame] | 615 | |
| 616 | /* Check if DMC is ignoring our DC state requests */ |
| 617 | if ((val & mask) != dev_priv->csr.dc_state) |
| 618 | DRM_ERROR("DC state mismatch (0x%x -> 0x%x)\n", |
| 619 | dev_priv->csr.dc_state, val & mask); |
| 620 | |
Imre Deak | 13ae3a0 | 2015-11-04 19:24:16 +0200 | [diff] [blame] | 621 | val &= ~mask; |
| 622 | val |= state; |
Mika Kuoppala | 779cb5d | 2016-02-18 17:58:09 +0200 | [diff] [blame] | 623 | |
| 624 | gen9_write_dc_state(dev_priv, val); |
Patrik Jakobsson | 832dba8 | 2016-02-18 17:21:11 +0200 | [diff] [blame] | 625 | |
| 626 | dev_priv->csr.dc_state = val & mask; |
A.Sunil Kamath | 664326f | 2014-11-24 13:37:44 +0530 | [diff] [blame] | 627 | } |
| 628 | |
Imre Deak | 13ae3a0 | 2015-11-04 19:24:16 +0200 | [diff] [blame] | 629 | void bxt_enable_dc9(struct drm_i915_private *dev_priv) |
| 630 | { |
| 631 | assert_can_enable_dc9(dev_priv); |
| 632 | |
| 633 | DRM_DEBUG_KMS("Enabling DC9\n"); |
| 634 | |
Imre Deak | 7859799 | 2016-06-16 16:37:20 +0300 | [diff] [blame] | 635 | intel_power_sequencer_reset(dev_priv); |
Imre Deak | 13ae3a0 | 2015-11-04 19:24:16 +0200 | [diff] [blame] | 636 | gen9_set_dc_state(dev_priv, DC_STATE_EN_DC9); |
| 637 | } |
| 638 | |
A.Sunil Kamath | 664326f | 2014-11-24 13:37:44 +0530 | [diff] [blame] | 639 | void bxt_disable_dc9(struct drm_i915_private *dev_priv) |
| 640 | { |
A.Sunil Kamath | 664326f | 2014-11-24 13:37:44 +0530 | [diff] [blame] | 641 | assert_can_disable_dc9(dev_priv); |
| 642 | |
| 643 | DRM_DEBUG_KMS("Disabling DC9\n"); |
| 644 | |
Imre Deak | 13ae3a0 | 2015-11-04 19:24:16 +0200 | [diff] [blame] | 645 | gen9_set_dc_state(dev_priv, DC_STATE_DISABLE); |
Imre Deak | 8090ba8 | 2016-08-10 14:07:33 +0300 | [diff] [blame] | 646 | |
| 647 | intel_pps_unlock_regs_wa(dev_priv); |
A.Sunil Kamath | 664326f | 2014-11-24 13:37:44 +0530 | [diff] [blame] | 648 | } |
| 649 | |
Daniel Vetter | af5fead | 2015-10-28 23:58:57 +0200 | [diff] [blame] | 650 | static void assert_csr_loaded(struct drm_i915_private *dev_priv) |
| 651 | { |
| 652 | WARN_ONCE(!I915_READ(CSR_PROGRAM(0)), |
| 653 | "CSR program storage start is NULL\n"); |
| 654 | WARN_ONCE(!I915_READ(CSR_SSP_BASE), "CSR SSP Base Not fine\n"); |
| 655 | WARN_ONCE(!I915_READ(CSR_HTP_SKL), "CSR HTP Not fine\n"); |
| 656 | } |
| 657 | |
Suketu Shah | 5aefb23 | 2015-04-16 14:22:10 +0530 | [diff] [blame] | 658 | static void assert_can_enable_dc5(struct drm_i915_private *dev_priv) |
Suketu Shah | dc17430 | 2015-04-17 19:46:16 +0530 | [diff] [blame] | 659 | { |
Suketu Shah | 5aefb23 | 2015-04-16 14:22:10 +0530 | [diff] [blame] | 660 | bool pg2_enabled = intel_display_power_well_is_enabled(dev_priv, |
| 661 | SKL_DISP_PW_2); |
| 662 | |
Jesse Barnes | 6ff8ab0 | 2015-09-10 08:20:28 -0700 | [diff] [blame] | 663 | WARN_ONCE(pg2_enabled, "PG2 not disabled to enable DC5.\n"); |
Suketu Shah | 5aefb23 | 2015-04-16 14:22:10 +0530 | [diff] [blame] | 664 | |
Jesse Barnes | 6ff8ab0 | 2015-09-10 08:20:28 -0700 | [diff] [blame] | 665 | WARN_ONCE((I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC5), |
| 666 | "DC5 already programmed to be enabled.\n"); |
Imre Deak | c9b8846 | 2015-12-15 20:10:34 +0200 | [diff] [blame] | 667 | assert_rpm_wakelock_held(dev_priv); |
Suketu Shah | 5aefb23 | 2015-04-16 14:22:10 +0530 | [diff] [blame] | 668 | |
| 669 | assert_csr_loaded(dev_priv); |
| 670 | } |
| 671 | |
Imre Deak | f62c79b | 2016-04-20 20:27:57 +0300 | [diff] [blame] | 672 | void gen9_enable_dc5(struct drm_i915_private *dev_priv) |
Suketu Shah | 5aefb23 | 2015-04-16 14:22:10 +0530 | [diff] [blame] | 673 | { |
Suketu Shah | 5aefb23 | 2015-04-16 14:22:10 +0530 | [diff] [blame] | 674 | assert_can_enable_dc5(dev_priv); |
A.Sunil Kamath | 6b457d3 | 2015-04-16 14:22:09 +0530 | [diff] [blame] | 675 | |
| 676 | DRM_DEBUG_KMS("Enabling DC5\n"); |
| 677 | |
Imre Deak | 13ae3a0 | 2015-11-04 19:24:16 +0200 | [diff] [blame] | 678 | gen9_set_dc_state(dev_priv, DC_STATE_EN_UPTO_DC5); |
Suketu Shah | dc17430 | 2015-04-17 19:46:16 +0530 | [diff] [blame] | 679 | } |
| 680 | |
Suketu Shah | 93c7cb6 | 2015-04-16 14:22:13 +0530 | [diff] [blame] | 681 | static void assert_can_enable_dc6(struct drm_i915_private *dev_priv) |
Suketu Shah | f75a198 | 2015-04-16 14:22:11 +0530 | [diff] [blame] | 682 | { |
Jesse Barnes | 6ff8ab0 | 2015-09-10 08:20:28 -0700 | [diff] [blame] | 683 | WARN_ONCE(I915_READ(UTIL_PIN_CTL) & UTIL_PIN_ENABLE, |
| 684 | "Backlight is not disabled.\n"); |
| 685 | WARN_ONCE((I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC6), |
| 686 | "DC6 already programmed to be enabled.\n"); |
Suketu Shah | 93c7cb6 | 2015-04-16 14:22:13 +0530 | [diff] [blame] | 687 | |
| 688 | assert_csr_loaded(dev_priv); |
| 689 | } |
| 690 | |
Animesh Manna | 0a9d2be | 2015-09-29 11:01:59 +0530 | [diff] [blame] | 691 | void skl_enable_dc6(struct drm_i915_private *dev_priv) |
Suketu Shah | 93c7cb6 | 2015-04-16 14:22:13 +0530 | [diff] [blame] | 692 | { |
Suketu Shah | 93c7cb6 | 2015-04-16 14:22:13 +0530 | [diff] [blame] | 693 | assert_can_enable_dc6(dev_priv); |
A.Sunil Kamath | 74b4f37 | 2015-04-16 14:22:12 +0530 | [diff] [blame] | 694 | |
| 695 | DRM_DEBUG_KMS("Enabling DC6\n"); |
| 696 | |
Imre Deak | 13ae3a0 | 2015-11-04 19:24:16 +0200 | [diff] [blame] | 697 | gen9_set_dc_state(dev_priv, DC_STATE_EN_UPTO_DC6); |
| 698 | |
Suketu Shah | f75a198 | 2015-04-16 14:22:11 +0530 | [diff] [blame] | 699 | } |
| 700 | |
Animesh Manna | 0a9d2be | 2015-09-29 11:01:59 +0530 | [diff] [blame] | 701 | void skl_disable_dc6(struct drm_i915_private *dev_priv) |
Suketu Shah | f75a198 | 2015-04-16 14:22:11 +0530 | [diff] [blame] | 702 | { |
A.Sunil Kamath | 74b4f37 | 2015-04-16 14:22:12 +0530 | [diff] [blame] | 703 | DRM_DEBUG_KMS("Disabling DC6\n"); |
| 704 | |
Imre Deak | 13ae3a0 | 2015-11-04 19:24:16 +0200 | [diff] [blame] | 705 | gen9_set_dc_state(dev_priv, DC_STATE_DISABLE); |
Suketu Shah | f75a198 | 2015-04-16 14:22:11 +0530 | [diff] [blame] | 706 | } |
| 707 | |
Imre Deak | c6782b7 | 2016-04-05 13:26:05 +0300 | [diff] [blame] | 708 | static void |
| 709 | gen9_sanitize_power_well_requests(struct drm_i915_private *dev_priv, |
| 710 | struct i915_power_well *power_well) |
| 711 | { |
Ander Conselvan de Oliveira | 01c3faa | 2016-10-06 19:22:14 +0300 | [diff] [blame] | 712 | enum skl_disp_power_wells power_well_id = power_well->id; |
Imre Deak | c6782b7 | 2016-04-05 13:26:05 +0300 | [diff] [blame] | 713 | u32 val; |
| 714 | u32 mask; |
| 715 | |
| 716 | mask = SKL_POWER_WELL_REQ(power_well_id); |
| 717 | |
| 718 | val = I915_READ(HSW_PWR_WELL_KVMR); |
| 719 | if (WARN_ONCE(val & mask, "Clearing unexpected KVMR request for %s\n", |
| 720 | power_well->name)) |
| 721 | I915_WRITE(HSW_PWR_WELL_KVMR, val & ~mask); |
| 722 | |
| 723 | val = I915_READ(HSW_PWR_WELL_BIOS); |
| 724 | val |= I915_READ(HSW_PWR_WELL_DEBUG); |
| 725 | |
| 726 | if (!(val & mask)) |
| 727 | return; |
| 728 | |
| 729 | /* |
| 730 | * DMC is known to force on the request bits for power well 1 on SKL |
| 731 | * and BXT and the misc IO power well on SKL but we don't expect any |
| 732 | * other request bits to be set, so WARN for those. |
| 733 | */ |
| 734 | if (power_well_id == SKL_DISP_PW_1 || |
Imre Deak | 80dbe99 | 2016-04-19 13:00:36 +0300 | [diff] [blame] | 735 | ((IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv)) && |
| 736 | power_well_id == SKL_DISP_PW_MISC_IO)) |
Imre Deak | c6782b7 | 2016-04-05 13:26:05 +0300 | [diff] [blame] | 737 | DRM_DEBUG_DRIVER("Clearing auxiliary requests for %s forced on " |
| 738 | "by DMC\n", power_well->name); |
| 739 | else |
| 740 | WARN_ONCE(1, "Clearing unexpected auxiliary requests for %s\n", |
| 741 | power_well->name); |
| 742 | |
| 743 | I915_WRITE(HSW_PWR_WELL_BIOS, val & ~mask); |
| 744 | I915_WRITE(HSW_PWR_WELL_DEBUG, val & ~mask); |
| 745 | } |
| 746 | |
Satheeshakrishna M | 94dd513 | 2015-02-04 13:57:44 +0000 | [diff] [blame] | 747 | static void skl_set_power_well(struct drm_i915_private *dev_priv, |
Ander Conselvan de Oliveira | 0d03926 | 2016-12-02 10:23:50 +0200 | [diff] [blame] | 748 | struct i915_power_well *power_well, bool enable) |
Satheeshakrishna M | 94dd513 | 2015-02-04 13:57:44 +0000 | [diff] [blame] | 749 | { |
| 750 | uint32_t tmp, fuse_status; |
| 751 | uint32_t req_mask, state_mask; |
Damien Lespiau | 2a51835 | 2015-03-06 18:50:49 +0000 | [diff] [blame] | 752 | bool is_enabled, enable_requested, check_fuse_status = false; |
Satheeshakrishna M | 94dd513 | 2015-02-04 13:57:44 +0000 | [diff] [blame] | 753 | |
| 754 | tmp = I915_READ(HSW_PWR_WELL_DRIVER); |
| 755 | fuse_status = I915_READ(SKL_FUSE_STATUS); |
| 756 | |
Ander Conselvan de Oliveira | 01c3faa | 2016-10-06 19:22:14 +0300 | [diff] [blame] | 757 | switch (power_well->id) { |
Satheeshakrishna M | 94dd513 | 2015-02-04 13:57:44 +0000 | [diff] [blame] | 758 | case SKL_DISP_PW_1: |
Chris Wilson | 117c114 | 2016-06-30 15:33:33 +0100 | [diff] [blame] | 759 | if (intel_wait_for_register(dev_priv, |
| 760 | SKL_FUSE_STATUS, |
| 761 | SKL_FUSE_PG0_DIST_STATUS, |
| 762 | SKL_FUSE_PG0_DIST_STATUS, |
| 763 | 1)) { |
Satheeshakrishna M | 94dd513 | 2015-02-04 13:57:44 +0000 | [diff] [blame] | 764 | DRM_ERROR("PG0 not enabled\n"); |
| 765 | return; |
| 766 | } |
| 767 | break; |
| 768 | case SKL_DISP_PW_2: |
| 769 | if (!(fuse_status & SKL_FUSE_PG1_DIST_STATUS)) { |
| 770 | DRM_ERROR("PG1 in disabled state\n"); |
| 771 | return; |
| 772 | } |
| 773 | break; |
Ander Conselvan de Oliveira | 0d03926 | 2016-12-02 10:23:50 +0200 | [diff] [blame] | 774 | case SKL_DISP_PW_MISC_IO: |
| 775 | case SKL_DISP_PW_DDI_A_E: /* GLK_DISP_PW_DDI_A */ |
Satheeshakrishna M | 94dd513 | 2015-02-04 13:57:44 +0000 | [diff] [blame] | 776 | case SKL_DISP_PW_DDI_B: |
| 777 | case SKL_DISP_PW_DDI_C: |
| 778 | case SKL_DISP_PW_DDI_D: |
Ander Conselvan de Oliveira | 0d03926 | 2016-12-02 10:23:50 +0200 | [diff] [blame] | 779 | case GLK_DISP_PW_AUX_A: |
| 780 | case GLK_DISP_PW_AUX_B: |
| 781 | case GLK_DISP_PW_AUX_C: |
Satheeshakrishna M | 94dd513 | 2015-02-04 13:57:44 +0000 | [diff] [blame] | 782 | break; |
| 783 | default: |
Ander Conselvan de Oliveira | 01c3faa | 2016-10-06 19:22:14 +0300 | [diff] [blame] | 784 | WARN(1, "Unknown power well %lu\n", power_well->id); |
Satheeshakrishna M | 94dd513 | 2015-02-04 13:57:44 +0000 | [diff] [blame] | 785 | return; |
| 786 | } |
| 787 | |
Ander Conselvan de Oliveira | 01c3faa | 2016-10-06 19:22:14 +0300 | [diff] [blame] | 788 | req_mask = SKL_POWER_WELL_REQ(power_well->id); |
Damien Lespiau | 2a51835 | 2015-03-06 18:50:49 +0000 | [diff] [blame] | 789 | enable_requested = tmp & req_mask; |
Ander Conselvan de Oliveira | 01c3faa | 2016-10-06 19:22:14 +0300 | [diff] [blame] | 790 | state_mask = SKL_POWER_WELL_STATE(power_well->id); |
Damien Lespiau | 2a51835 | 2015-03-06 18:50:49 +0000 | [diff] [blame] | 791 | is_enabled = tmp & state_mask; |
Satheeshakrishna M | 94dd513 | 2015-02-04 13:57:44 +0000 | [diff] [blame] | 792 | |
Ville Syrjälä | aae8ba8 | 2016-02-19 20:47:30 +0200 | [diff] [blame] | 793 | if (!enable && enable_requested) |
| 794 | skl_power_well_pre_disable(dev_priv, power_well); |
| 795 | |
Satheeshakrishna M | 94dd513 | 2015-02-04 13:57:44 +0000 | [diff] [blame] | 796 | if (enable) { |
Damien Lespiau | 2a51835 | 2015-03-06 18:50:49 +0000 | [diff] [blame] | 797 | if (!enable_requested) { |
Suketu Shah | dc17430 | 2015-04-17 19:46:16 +0530 | [diff] [blame] | 798 | WARN((tmp & state_mask) && |
| 799 | !I915_READ(HSW_PWR_WELL_BIOS), |
| 800 | "Invalid for power well status to be enabled, unless done by the BIOS, \ |
| 801 | when request is to disable!\n"); |
Satheeshakrishna M | 94dd513 | 2015-02-04 13:57:44 +0000 | [diff] [blame] | 802 | I915_WRITE(HSW_PWR_WELL_DRIVER, tmp | req_mask); |
Satheeshakrishna M | 94dd513 | 2015-02-04 13:57:44 +0000 | [diff] [blame] | 803 | } |
| 804 | |
Damien Lespiau | 2a51835 | 2015-03-06 18:50:49 +0000 | [diff] [blame] | 805 | if (!is_enabled) { |
Damien Lespiau | 510e6fd | 2015-03-06 18:50:50 +0000 | [diff] [blame] | 806 | DRM_DEBUG_KMS("Enabling %s\n", power_well->name); |
Satheeshakrishna M | 94dd513 | 2015-02-04 13:57:44 +0000 | [diff] [blame] | 807 | check_fuse_status = true; |
| 808 | } |
| 809 | } else { |
Damien Lespiau | 2a51835 | 2015-03-06 18:50:49 +0000 | [diff] [blame] | 810 | if (enable_requested) { |
Imre Deak | 4a76f29 | 2015-11-04 19:24:15 +0200 | [diff] [blame] | 811 | I915_WRITE(HSW_PWR_WELL_DRIVER, tmp & ~req_mask); |
| 812 | POSTING_READ(HSW_PWR_WELL_DRIVER); |
| 813 | DRM_DEBUG_KMS("Disabling %s\n", power_well->name); |
Satheeshakrishna M | 94dd513 | 2015-02-04 13:57:44 +0000 | [diff] [blame] | 814 | } |
Imre Deak | c6782b7 | 2016-04-05 13:26:05 +0300 | [diff] [blame] | 815 | |
Imre Deak | 5f304c8 | 2016-04-15 22:32:58 +0300 | [diff] [blame] | 816 | if (IS_GEN9(dev_priv)) |
Imre Deak | c6782b7 | 2016-04-05 13:26:05 +0300 | [diff] [blame] | 817 | gen9_sanitize_power_well_requests(dev_priv, power_well); |
Satheeshakrishna M | 94dd513 | 2015-02-04 13:57:44 +0000 | [diff] [blame] | 818 | } |
| 819 | |
Imre Deak | 1d963af | 2016-04-01 16:02:36 +0300 | [diff] [blame] | 820 | if (wait_for(!!(I915_READ(HSW_PWR_WELL_DRIVER) & state_mask) == enable, |
| 821 | 1)) |
| 822 | DRM_ERROR("%s %s timeout\n", |
| 823 | power_well->name, enable ? "enable" : "disable"); |
| 824 | |
Satheeshakrishna M | 94dd513 | 2015-02-04 13:57:44 +0000 | [diff] [blame] | 825 | if (check_fuse_status) { |
Ander Conselvan de Oliveira | 01c3faa | 2016-10-06 19:22:14 +0300 | [diff] [blame] | 826 | if (power_well->id == SKL_DISP_PW_1) { |
Chris Wilson | 8b00f55 | 2016-06-30 15:33:34 +0100 | [diff] [blame] | 827 | if (intel_wait_for_register(dev_priv, |
| 828 | SKL_FUSE_STATUS, |
| 829 | SKL_FUSE_PG1_DIST_STATUS, |
| 830 | SKL_FUSE_PG1_DIST_STATUS, |
| 831 | 1)) |
Satheeshakrishna M | 94dd513 | 2015-02-04 13:57:44 +0000 | [diff] [blame] | 832 | DRM_ERROR("PG1 distributing status timeout\n"); |
Ander Conselvan de Oliveira | 01c3faa | 2016-10-06 19:22:14 +0300 | [diff] [blame] | 833 | } else if (power_well->id == SKL_DISP_PW_2) { |
Chris Wilson | 8b00f55 | 2016-06-30 15:33:34 +0100 | [diff] [blame] | 834 | if (intel_wait_for_register(dev_priv, |
| 835 | SKL_FUSE_STATUS, |
| 836 | SKL_FUSE_PG2_DIST_STATUS, |
| 837 | SKL_FUSE_PG2_DIST_STATUS, |
| 838 | 1)) |
Satheeshakrishna M | 94dd513 | 2015-02-04 13:57:44 +0000 | [diff] [blame] | 839 | DRM_ERROR("PG2 distributing status timeout\n"); |
| 840 | } |
| 841 | } |
Damien Lespiau | d14c034 | 2015-03-06 18:50:51 +0000 | [diff] [blame] | 842 | |
| 843 | if (enable && !is_enabled) |
| 844 | skl_power_well_post_enable(dev_priv, power_well); |
Satheeshakrishna M | 94dd513 | 2015-02-04 13:57:44 +0000 | [diff] [blame] | 845 | } |
| 846 | |
Daniel Vetter | 9c065a7 | 2014-09-30 10:56:38 +0200 | [diff] [blame] | 847 | static void hsw_power_well_sync_hw(struct drm_i915_private *dev_priv, |
| 848 | struct i915_power_well *power_well) |
| 849 | { |
| 850 | hsw_set_power_well(dev_priv, power_well, power_well->count > 0); |
| 851 | |
| 852 | /* |
| 853 | * We're taking over the BIOS, so clear any requests made by it since |
| 854 | * the driver is in charge now. |
| 855 | */ |
| 856 | if (I915_READ(HSW_PWR_WELL_BIOS) & HSW_PWR_WELL_ENABLE_REQUEST) |
| 857 | I915_WRITE(HSW_PWR_WELL_BIOS, 0); |
| 858 | } |
| 859 | |
| 860 | static void hsw_power_well_enable(struct drm_i915_private *dev_priv, |
| 861 | struct i915_power_well *power_well) |
| 862 | { |
| 863 | hsw_set_power_well(dev_priv, power_well, true); |
| 864 | } |
| 865 | |
| 866 | static void hsw_power_well_disable(struct drm_i915_private *dev_priv, |
| 867 | struct i915_power_well *power_well) |
| 868 | { |
| 869 | hsw_set_power_well(dev_priv, power_well, false); |
| 870 | } |
| 871 | |
Satheeshakrishna M | 94dd513 | 2015-02-04 13:57:44 +0000 | [diff] [blame] | 872 | static bool skl_power_well_enabled(struct drm_i915_private *dev_priv, |
| 873 | struct i915_power_well *power_well) |
| 874 | { |
Ander Conselvan de Oliveira | 01c3faa | 2016-10-06 19:22:14 +0300 | [diff] [blame] | 875 | uint32_t mask = SKL_POWER_WELL_REQ(power_well->id) | |
| 876 | SKL_POWER_WELL_STATE(power_well->id); |
Satheeshakrishna M | 94dd513 | 2015-02-04 13:57:44 +0000 | [diff] [blame] | 877 | |
| 878 | return (I915_READ(HSW_PWR_WELL_DRIVER) & mask) == mask; |
| 879 | } |
| 880 | |
| 881 | static void skl_power_well_sync_hw(struct drm_i915_private *dev_priv, |
| 882 | struct i915_power_well *power_well) |
| 883 | { |
| 884 | skl_set_power_well(dev_priv, power_well, power_well->count > 0); |
| 885 | |
| 886 | /* Clear any request made by BIOS as driver is taking over */ |
| 887 | I915_WRITE(HSW_PWR_WELL_BIOS, 0); |
| 888 | } |
| 889 | |
| 890 | static void skl_power_well_enable(struct drm_i915_private *dev_priv, |
| 891 | struct i915_power_well *power_well) |
| 892 | { |
| 893 | skl_set_power_well(dev_priv, power_well, true); |
| 894 | } |
| 895 | |
| 896 | static void skl_power_well_disable(struct drm_i915_private *dev_priv, |
| 897 | struct i915_power_well *power_well) |
| 898 | { |
| 899 | skl_set_power_well(dev_priv, power_well, false); |
| 900 | } |
| 901 | |
Imre Deak | 9c8d0b8 | 2016-06-13 16:44:34 +0300 | [diff] [blame] | 902 | static void bxt_dpio_cmn_power_well_enable(struct drm_i915_private *dev_priv, |
| 903 | struct i915_power_well *power_well) |
| 904 | { |
Ander Conselvan de Oliveira | 362624c | 2016-10-06 19:22:15 +0300 | [diff] [blame] | 905 | bxt_ddi_phy_init(dev_priv, power_well->data); |
Imre Deak | 9c8d0b8 | 2016-06-13 16:44:34 +0300 | [diff] [blame] | 906 | } |
| 907 | |
| 908 | static void bxt_dpio_cmn_power_well_disable(struct drm_i915_private *dev_priv, |
| 909 | struct i915_power_well *power_well) |
| 910 | { |
Ander Conselvan de Oliveira | 362624c | 2016-10-06 19:22:15 +0300 | [diff] [blame] | 911 | bxt_ddi_phy_uninit(dev_priv, power_well->data); |
Imre Deak | 9c8d0b8 | 2016-06-13 16:44:34 +0300 | [diff] [blame] | 912 | } |
| 913 | |
| 914 | static bool bxt_dpio_cmn_power_well_enabled(struct drm_i915_private *dev_priv, |
| 915 | struct i915_power_well *power_well) |
| 916 | { |
Ander Conselvan de Oliveira | 362624c | 2016-10-06 19:22:15 +0300 | [diff] [blame] | 917 | return bxt_ddi_phy_is_enabled(dev_priv, power_well->data); |
Imre Deak | 9c8d0b8 | 2016-06-13 16:44:34 +0300 | [diff] [blame] | 918 | } |
| 919 | |
| 920 | static void bxt_dpio_cmn_power_well_sync_hw(struct drm_i915_private *dev_priv, |
| 921 | struct i915_power_well *power_well) |
| 922 | { |
| 923 | if (power_well->count > 0) |
| 924 | bxt_dpio_cmn_power_well_enable(dev_priv, power_well); |
| 925 | else |
| 926 | bxt_dpio_cmn_power_well_disable(dev_priv, power_well); |
| 927 | } |
| 928 | |
| 929 | |
| 930 | static void bxt_verify_ddi_phy_power_wells(struct drm_i915_private *dev_priv) |
| 931 | { |
| 932 | struct i915_power_well *power_well; |
| 933 | |
| 934 | power_well = lookup_power_well(dev_priv, BXT_DPIO_CMN_A); |
| 935 | if (power_well->count > 0) |
Ander Conselvan de Oliveira | 362624c | 2016-10-06 19:22:15 +0300 | [diff] [blame] | 936 | bxt_ddi_phy_verify_state(dev_priv, power_well->data); |
Imre Deak | 9c8d0b8 | 2016-06-13 16:44:34 +0300 | [diff] [blame] | 937 | |
| 938 | power_well = lookup_power_well(dev_priv, BXT_DPIO_CMN_BC); |
| 939 | if (power_well->count > 0) |
Ander Conselvan de Oliveira | 362624c | 2016-10-06 19:22:15 +0300 | [diff] [blame] | 940 | bxt_ddi_phy_verify_state(dev_priv, power_well->data); |
Ander Conselvan de Oliveira | 0a116ce | 2016-12-02 10:23:51 +0200 | [diff] [blame] | 941 | |
| 942 | if (IS_GEMINILAKE(dev_priv)) { |
| 943 | power_well = lookup_power_well(dev_priv, GLK_DPIO_CMN_C); |
| 944 | if (power_well->count > 0) |
| 945 | bxt_ddi_phy_verify_state(dev_priv, power_well->data); |
| 946 | } |
Imre Deak | 9c8d0b8 | 2016-06-13 16:44:34 +0300 | [diff] [blame] | 947 | } |
| 948 | |
Patrik Jakobsson | 9f836f9 | 2015-11-16 16:20:01 +0100 | [diff] [blame] | 949 | static bool gen9_dc_off_power_well_enabled(struct drm_i915_private *dev_priv, |
| 950 | struct i915_power_well *power_well) |
| 951 | { |
| 952 | return (I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC5_DC6_MASK) == 0; |
| 953 | } |
| 954 | |
Ville Syrjälä | 18a8067 | 2016-05-16 16:59:40 +0300 | [diff] [blame] | 955 | static void gen9_assert_dbuf_enabled(struct drm_i915_private *dev_priv) |
| 956 | { |
| 957 | u32 tmp = I915_READ(DBUF_CTL); |
| 958 | |
| 959 | WARN((tmp & (DBUF_POWER_STATE | DBUF_POWER_REQUEST)) != |
| 960 | (DBUF_POWER_STATE | DBUF_POWER_REQUEST), |
| 961 | "Unexpected DBuf power power state (0x%08x)\n", tmp); |
| 962 | } |
| 963 | |
Patrik Jakobsson | 9f836f9 | 2015-11-16 16:20:01 +0100 | [diff] [blame] | 964 | static void gen9_dc_off_power_well_enable(struct drm_i915_private *dev_priv, |
| 965 | struct i915_power_well *power_well) |
| 966 | { |
Imre Deak | 5b773eb | 2016-02-29 22:49:05 +0200 | [diff] [blame] | 967 | gen9_set_dc_state(dev_priv, DC_STATE_DISABLE); |
Imre Deak | adc7f04 | 2016-04-04 17:27:10 +0300 | [diff] [blame] | 968 | |
Ville Syrjälä | 342be92 | 2016-05-13 23:41:39 +0300 | [diff] [blame] | 969 | WARN_ON(dev_priv->cdclk_freq != |
Ville Syrjälä | 1353c4f | 2016-10-31 22:37:13 +0200 | [diff] [blame] | 970 | dev_priv->display.get_display_clock_speed(dev_priv)); |
Ville Syrjälä | 342be92 | 2016-05-13 23:41:39 +0300 | [diff] [blame] | 971 | |
Ville Syrjälä | 18a8067 | 2016-05-16 16:59:40 +0300 | [diff] [blame] | 972 | gen9_assert_dbuf_enabled(dev_priv); |
| 973 | |
Ander Conselvan de Oliveira | cc3f90f | 2016-12-02 10:23:49 +0200 | [diff] [blame] | 974 | if (IS_GEN9_LP(dev_priv)) |
Imre Deak | 9c8d0b8 | 2016-06-13 16:44:34 +0300 | [diff] [blame] | 975 | bxt_verify_ddi_phy_power_wells(dev_priv); |
Patrik Jakobsson | 9f836f9 | 2015-11-16 16:20:01 +0100 | [diff] [blame] | 976 | } |
| 977 | |
| 978 | static void gen9_dc_off_power_well_disable(struct drm_i915_private *dev_priv, |
| 979 | struct i915_power_well *power_well) |
| 980 | { |
Imre Deak | f74ed08 | 2016-04-18 14:48:21 +0300 | [diff] [blame] | 981 | if (!dev_priv->csr.dmc_payload) |
| 982 | return; |
| 983 | |
Imre Deak | a37baf3 | 2016-02-29 22:49:03 +0200 | [diff] [blame] | 984 | if (dev_priv->csr.allowed_dc_mask & DC_STATE_EN_UPTO_DC6) |
Patrik Jakobsson | 9f836f9 | 2015-11-16 16:20:01 +0100 | [diff] [blame] | 985 | skl_enable_dc6(dev_priv); |
Imre Deak | a37baf3 | 2016-02-29 22:49:03 +0200 | [diff] [blame] | 986 | else if (dev_priv->csr.allowed_dc_mask & DC_STATE_EN_UPTO_DC5) |
Patrik Jakobsson | 9f836f9 | 2015-11-16 16:20:01 +0100 | [diff] [blame] | 987 | gen9_enable_dc5(dev_priv); |
| 988 | } |
| 989 | |
| 990 | static void gen9_dc_off_power_well_sync_hw(struct drm_i915_private *dev_priv, |
| 991 | struct i915_power_well *power_well) |
| 992 | { |
Imre Deak | a37baf3 | 2016-02-29 22:49:03 +0200 | [diff] [blame] | 993 | if (power_well->count > 0) |
| 994 | gen9_dc_off_power_well_enable(dev_priv, power_well); |
| 995 | else |
| 996 | gen9_dc_off_power_well_disable(dev_priv, power_well); |
Patrik Jakobsson | 9f836f9 | 2015-11-16 16:20:01 +0100 | [diff] [blame] | 997 | } |
| 998 | |
Daniel Vetter | 9c065a7 | 2014-09-30 10:56:38 +0200 | [diff] [blame] | 999 | static void i9xx_always_on_power_well_noop(struct drm_i915_private *dev_priv, |
| 1000 | struct i915_power_well *power_well) |
| 1001 | { |
| 1002 | } |
| 1003 | |
| 1004 | static bool i9xx_always_on_power_well_enabled(struct drm_i915_private *dev_priv, |
| 1005 | struct i915_power_well *power_well) |
| 1006 | { |
| 1007 | return true; |
| 1008 | } |
| 1009 | |
| 1010 | static void vlv_set_power_well(struct drm_i915_private *dev_priv, |
| 1011 | struct i915_power_well *power_well, bool enable) |
| 1012 | { |
Ander Conselvan de Oliveira | 01c3faa | 2016-10-06 19:22:14 +0300 | [diff] [blame] | 1013 | enum punit_power_well power_well_id = power_well->id; |
Daniel Vetter | 9c065a7 | 2014-09-30 10:56:38 +0200 | [diff] [blame] | 1014 | u32 mask; |
| 1015 | u32 state; |
| 1016 | u32 ctrl; |
| 1017 | |
| 1018 | mask = PUNIT_PWRGT_MASK(power_well_id); |
| 1019 | state = enable ? PUNIT_PWRGT_PWR_ON(power_well_id) : |
| 1020 | PUNIT_PWRGT_PWR_GATE(power_well_id); |
| 1021 | |
| 1022 | mutex_lock(&dev_priv->rps.hw_lock); |
| 1023 | |
| 1024 | #define COND \ |
| 1025 | ((vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_STATUS) & mask) == state) |
| 1026 | |
| 1027 | if (COND) |
| 1028 | goto out; |
| 1029 | |
| 1030 | ctrl = vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_CTRL); |
| 1031 | ctrl &= ~mask; |
| 1032 | ctrl |= state; |
| 1033 | vlv_punit_write(dev_priv, PUNIT_REG_PWRGT_CTRL, ctrl); |
| 1034 | |
| 1035 | if (wait_for(COND, 100)) |
Masanari Iida | 7e35ab8 | 2015-05-10 01:00:23 +0900 | [diff] [blame] | 1036 | DRM_ERROR("timeout setting power well state %08x (%08x)\n", |
Daniel Vetter | 9c065a7 | 2014-09-30 10:56:38 +0200 | [diff] [blame] | 1037 | state, |
| 1038 | vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_CTRL)); |
| 1039 | |
| 1040 | #undef COND |
| 1041 | |
| 1042 | out: |
| 1043 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 1044 | } |
| 1045 | |
| 1046 | static void vlv_power_well_sync_hw(struct drm_i915_private *dev_priv, |
| 1047 | struct i915_power_well *power_well) |
| 1048 | { |
| 1049 | vlv_set_power_well(dev_priv, power_well, power_well->count > 0); |
| 1050 | } |
| 1051 | |
| 1052 | static void vlv_power_well_enable(struct drm_i915_private *dev_priv, |
| 1053 | struct i915_power_well *power_well) |
| 1054 | { |
| 1055 | vlv_set_power_well(dev_priv, power_well, true); |
| 1056 | } |
| 1057 | |
| 1058 | static void vlv_power_well_disable(struct drm_i915_private *dev_priv, |
| 1059 | struct i915_power_well *power_well) |
| 1060 | { |
| 1061 | vlv_set_power_well(dev_priv, power_well, false); |
| 1062 | } |
| 1063 | |
| 1064 | static bool vlv_power_well_enabled(struct drm_i915_private *dev_priv, |
| 1065 | struct i915_power_well *power_well) |
| 1066 | { |
Ander Conselvan de Oliveira | 01c3faa | 2016-10-06 19:22:14 +0300 | [diff] [blame] | 1067 | int power_well_id = power_well->id; |
Daniel Vetter | 9c065a7 | 2014-09-30 10:56:38 +0200 | [diff] [blame] | 1068 | bool enabled = false; |
| 1069 | u32 mask; |
| 1070 | u32 state; |
| 1071 | u32 ctrl; |
| 1072 | |
| 1073 | mask = PUNIT_PWRGT_MASK(power_well_id); |
| 1074 | ctrl = PUNIT_PWRGT_PWR_ON(power_well_id); |
| 1075 | |
| 1076 | mutex_lock(&dev_priv->rps.hw_lock); |
| 1077 | |
| 1078 | state = vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_STATUS) & mask; |
| 1079 | /* |
| 1080 | * We only ever set the power-on and power-gate states, anything |
| 1081 | * else is unexpected. |
| 1082 | */ |
| 1083 | WARN_ON(state != PUNIT_PWRGT_PWR_ON(power_well_id) && |
| 1084 | state != PUNIT_PWRGT_PWR_GATE(power_well_id)); |
| 1085 | if (state == ctrl) |
| 1086 | enabled = true; |
| 1087 | |
| 1088 | /* |
| 1089 | * A transient state at this point would mean some unexpected party |
| 1090 | * is poking at the power controls too. |
| 1091 | */ |
| 1092 | ctrl = vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_CTRL) & mask; |
| 1093 | WARN_ON(ctrl != state); |
| 1094 | |
| 1095 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 1096 | |
| 1097 | return enabled; |
| 1098 | } |
| 1099 | |
Ville Syrjälä | 766078d | 2016-04-11 16:56:30 +0300 | [diff] [blame] | 1100 | static void vlv_init_display_clock_gating(struct drm_i915_private *dev_priv) |
| 1101 | { |
| 1102 | I915_WRITE(DSPCLK_GATE_D, VRHUNIT_CLOCK_GATE_DISABLE); |
| 1103 | |
| 1104 | /* |
| 1105 | * Disable trickle feed and enable pnd deadline calculation |
| 1106 | */ |
| 1107 | I915_WRITE(MI_ARB_VLV, MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE); |
| 1108 | I915_WRITE(CBR1_VLV, 0); |
Ville Syrjälä | 19ab4ed | 2016-04-27 17:43:22 +0300 | [diff] [blame] | 1109 | |
| 1110 | WARN_ON(dev_priv->rawclk_freq == 0); |
| 1111 | |
| 1112 | I915_WRITE(RAWCLK_FREQ_VLV, |
| 1113 | DIV_ROUND_CLOSEST(dev_priv->rawclk_freq, 1000)); |
Ville Syrjälä | 766078d | 2016-04-11 16:56:30 +0300 | [diff] [blame] | 1114 | } |
| 1115 | |
Ville Syrjälä | 2be7d54 | 2015-06-29 15:25:51 +0300 | [diff] [blame] | 1116 | static void vlv_display_power_well_init(struct drm_i915_private *dev_priv) |
Daniel Vetter | 9c065a7 | 2014-09-30 10:56:38 +0200 | [diff] [blame] | 1117 | { |
Lyude | 9504a89 | 2016-06-21 17:03:42 -0400 | [diff] [blame] | 1118 | struct intel_encoder *encoder; |
Ville Syrjälä | 5a8fbb7 | 2015-06-29 15:25:53 +0300 | [diff] [blame] | 1119 | enum pipe pipe; |
| 1120 | |
| 1121 | /* |
| 1122 | * Enable the CRI clock source so we can get at the |
| 1123 | * display and the reference clock for VGA |
| 1124 | * hotplug / manual detection. Supposedly DSI also |
| 1125 | * needs the ref clock up and running. |
| 1126 | * |
| 1127 | * CHV DPLL B/C have some issues if VGA mode is enabled. |
| 1128 | */ |
Tvrtko Ursulin | 801388c | 2016-11-16 08:55:44 +0000 | [diff] [blame] | 1129 | for_each_pipe(dev_priv, pipe) { |
Ville Syrjälä | 5a8fbb7 | 2015-06-29 15:25:53 +0300 | [diff] [blame] | 1130 | u32 val = I915_READ(DPLL(pipe)); |
| 1131 | |
| 1132 | val |= DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS; |
| 1133 | if (pipe != PIPE_A) |
| 1134 | val |= DPLL_INTEGRATED_CRI_CLK_VLV; |
| 1135 | |
| 1136 | I915_WRITE(DPLL(pipe), val); |
| 1137 | } |
Daniel Vetter | 9c065a7 | 2014-09-30 10:56:38 +0200 | [diff] [blame] | 1138 | |
Ville Syrjälä | 766078d | 2016-04-11 16:56:30 +0300 | [diff] [blame] | 1139 | vlv_init_display_clock_gating(dev_priv); |
| 1140 | |
Daniel Vetter | 9c065a7 | 2014-09-30 10:56:38 +0200 | [diff] [blame] | 1141 | spin_lock_irq(&dev_priv->irq_lock); |
| 1142 | valleyview_enable_display_irqs(dev_priv); |
| 1143 | spin_unlock_irq(&dev_priv->irq_lock); |
| 1144 | |
| 1145 | /* |
| 1146 | * During driver initialization/resume we can avoid restoring the |
| 1147 | * part of the HW/SW state that will be inited anyway explicitly. |
| 1148 | */ |
| 1149 | if (dev_priv->power_domains.initializing) |
| 1150 | return; |
| 1151 | |
Daniel Vetter | b963291 | 2014-09-30 10:56:44 +0200 | [diff] [blame] | 1152 | intel_hpd_init(dev_priv); |
Daniel Vetter | 9c065a7 | 2014-09-30 10:56:38 +0200 | [diff] [blame] | 1153 | |
Lyude | 9504a89 | 2016-06-21 17:03:42 -0400 | [diff] [blame] | 1154 | /* Re-enable the ADPA, if we have one */ |
| 1155 | for_each_intel_encoder(&dev_priv->drm, encoder) { |
| 1156 | if (encoder->type == INTEL_OUTPUT_ANALOG) |
| 1157 | intel_crt_reset(&encoder->base); |
| 1158 | } |
| 1159 | |
Tvrtko Ursulin | 29b74b7 | 2016-11-16 08:55:39 +0000 | [diff] [blame] | 1160 | i915_redisable_vga_power_on(dev_priv); |
Imre Deak | 8090ba8 | 2016-08-10 14:07:33 +0300 | [diff] [blame] | 1161 | |
| 1162 | intel_pps_unlock_regs_wa(dev_priv); |
Daniel Vetter | 9c065a7 | 2014-09-30 10:56:38 +0200 | [diff] [blame] | 1163 | } |
| 1164 | |
Ville Syrjälä | 2be7d54 | 2015-06-29 15:25:51 +0300 | [diff] [blame] | 1165 | static void vlv_display_power_well_deinit(struct drm_i915_private *dev_priv) |
| 1166 | { |
| 1167 | spin_lock_irq(&dev_priv->irq_lock); |
| 1168 | valleyview_disable_display_irqs(dev_priv); |
| 1169 | spin_unlock_irq(&dev_priv->irq_lock); |
| 1170 | |
Ville Syrjälä | 2230fde | 2016-02-19 18:41:52 +0200 | [diff] [blame] | 1171 | /* make sure we're done processing display irqs */ |
Chris Wilson | 91c8a32 | 2016-07-05 10:40:23 +0100 | [diff] [blame] | 1172 | synchronize_irq(dev_priv->drm.irq); |
Ville Syrjälä | 2230fde | 2016-02-19 18:41:52 +0200 | [diff] [blame] | 1173 | |
Imre Deak | 7859799 | 2016-06-16 16:37:20 +0300 | [diff] [blame] | 1174 | intel_power_sequencer_reset(dev_priv); |
Lyude | 19625e8 | 2016-06-21 17:03:44 -0400 | [diff] [blame] | 1175 | |
Lyude | b64b540 | 2016-10-26 12:36:09 -0400 | [diff] [blame] | 1176 | /* Prevent us from re-enabling polling on accident in late suspend */ |
| 1177 | if (!dev_priv->drm.dev->power.is_suspended) |
| 1178 | intel_hpd_poll_init(dev_priv); |
Ville Syrjälä | 2be7d54 | 2015-06-29 15:25:51 +0300 | [diff] [blame] | 1179 | } |
| 1180 | |
| 1181 | static void vlv_display_power_well_enable(struct drm_i915_private *dev_priv, |
| 1182 | struct i915_power_well *power_well) |
| 1183 | { |
Ander Conselvan de Oliveira | 01c3faa | 2016-10-06 19:22:14 +0300 | [diff] [blame] | 1184 | WARN_ON_ONCE(power_well->id != PUNIT_POWER_WELL_DISP2D); |
Ville Syrjälä | 2be7d54 | 2015-06-29 15:25:51 +0300 | [diff] [blame] | 1185 | |
| 1186 | vlv_set_power_well(dev_priv, power_well, true); |
| 1187 | |
| 1188 | vlv_display_power_well_init(dev_priv); |
| 1189 | } |
| 1190 | |
Daniel Vetter | 9c065a7 | 2014-09-30 10:56:38 +0200 | [diff] [blame] | 1191 | static void vlv_display_power_well_disable(struct drm_i915_private *dev_priv, |
| 1192 | struct i915_power_well *power_well) |
| 1193 | { |
Ander Conselvan de Oliveira | 01c3faa | 2016-10-06 19:22:14 +0300 | [diff] [blame] | 1194 | WARN_ON_ONCE(power_well->id != PUNIT_POWER_WELL_DISP2D); |
Daniel Vetter | 9c065a7 | 2014-09-30 10:56:38 +0200 | [diff] [blame] | 1195 | |
Ville Syrjälä | 2be7d54 | 2015-06-29 15:25:51 +0300 | [diff] [blame] | 1196 | vlv_display_power_well_deinit(dev_priv); |
Daniel Vetter | 9c065a7 | 2014-09-30 10:56:38 +0200 | [diff] [blame] | 1197 | |
| 1198 | vlv_set_power_well(dev_priv, power_well, false); |
Daniel Vetter | 9c065a7 | 2014-09-30 10:56:38 +0200 | [diff] [blame] | 1199 | } |
| 1200 | |
| 1201 | static void vlv_dpio_cmn_power_well_enable(struct drm_i915_private *dev_priv, |
| 1202 | struct i915_power_well *power_well) |
| 1203 | { |
Ander Conselvan de Oliveira | 01c3faa | 2016-10-06 19:22:14 +0300 | [diff] [blame] | 1204 | WARN_ON_ONCE(power_well->id != PUNIT_POWER_WELL_DPIO_CMN_BC); |
Daniel Vetter | 9c065a7 | 2014-09-30 10:56:38 +0200 | [diff] [blame] | 1205 | |
Ville Syrjälä | 5a8fbb7 | 2015-06-29 15:25:53 +0300 | [diff] [blame] | 1206 | /* since ref/cri clock was enabled */ |
Daniel Vetter | 9c065a7 | 2014-09-30 10:56:38 +0200 | [diff] [blame] | 1207 | udelay(1); /* >10ns for cmnreset, >0ns for sidereset */ |
| 1208 | |
| 1209 | vlv_set_power_well(dev_priv, power_well, true); |
| 1210 | |
| 1211 | /* |
| 1212 | * From VLV2A0_DP_eDP_DPIO_driver_vbios_notes_10.docx - |
| 1213 | * 6. De-assert cmn_reset/side_reset. Same as VLV X0. |
| 1214 | * a. GUnit 0x2110 bit[0] set to 1 (def 0) |
| 1215 | * b. The other bits such as sfr settings / modesel may all |
| 1216 | * be set to 0. |
| 1217 | * |
| 1218 | * This should only be done on init and resume from S3 with |
| 1219 | * both PLLs disabled, or we risk losing DPIO and PLL |
| 1220 | * synchronization. |
| 1221 | */ |
| 1222 | I915_WRITE(DPIO_CTL, I915_READ(DPIO_CTL) | DPIO_CMNRST); |
| 1223 | } |
| 1224 | |
| 1225 | static void vlv_dpio_cmn_power_well_disable(struct drm_i915_private *dev_priv, |
| 1226 | struct i915_power_well *power_well) |
| 1227 | { |
| 1228 | enum pipe pipe; |
| 1229 | |
Ander Conselvan de Oliveira | 01c3faa | 2016-10-06 19:22:14 +0300 | [diff] [blame] | 1230 | WARN_ON_ONCE(power_well->id != PUNIT_POWER_WELL_DPIO_CMN_BC); |
Daniel Vetter | 9c065a7 | 2014-09-30 10:56:38 +0200 | [diff] [blame] | 1231 | |
| 1232 | for_each_pipe(dev_priv, pipe) |
| 1233 | assert_pll_disabled(dev_priv, pipe); |
| 1234 | |
| 1235 | /* Assert common reset */ |
| 1236 | I915_WRITE(DPIO_CTL, I915_READ(DPIO_CTL) & ~DPIO_CMNRST); |
| 1237 | |
| 1238 | vlv_set_power_well(dev_priv, power_well, false); |
| 1239 | } |
| 1240 | |
Ville Syrjälä | 3014227 | 2015-07-08 23:46:01 +0300 | [diff] [blame] | 1241 | #define POWER_DOMAIN_MASK (BIT(POWER_DOMAIN_NUM) - 1) |
| 1242 | |
| 1243 | static struct i915_power_well *lookup_power_well(struct drm_i915_private *dev_priv, |
| 1244 | int power_well_id) |
| 1245 | { |
| 1246 | struct i915_power_domains *power_domains = &dev_priv->power_domains; |
Ville Syrjälä | 3014227 | 2015-07-08 23:46:01 +0300 | [diff] [blame] | 1247 | int i; |
| 1248 | |
Imre Deak | fc17f22 | 2015-11-04 19:24:11 +0200 | [diff] [blame] | 1249 | for (i = 0; i < power_domains->power_well_count; i++) { |
| 1250 | struct i915_power_well *power_well; |
| 1251 | |
| 1252 | power_well = &power_domains->power_wells[i]; |
Ander Conselvan de Oliveira | 01c3faa | 2016-10-06 19:22:14 +0300 | [diff] [blame] | 1253 | if (power_well->id == power_well_id) |
Ville Syrjälä | 3014227 | 2015-07-08 23:46:01 +0300 | [diff] [blame] | 1254 | return power_well; |
| 1255 | } |
| 1256 | |
| 1257 | return NULL; |
| 1258 | } |
| 1259 | |
| 1260 | #define BITS_SET(val, bits) (((val) & (bits)) == (bits)) |
| 1261 | |
| 1262 | static void assert_chv_phy_status(struct drm_i915_private *dev_priv) |
| 1263 | { |
| 1264 | struct i915_power_well *cmn_bc = |
| 1265 | lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_BC); |
| 1266 | struct i915_power_well *cmn_d = |
| 1267 | lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_D); |
| 1268 | u32 phy_control = dev_priv->chv_phy_control; |
| 1269 | u32 phy_status = 0; |
Ville Syrjälä | 3be60de | 2015-09-08 18:05:45 +0300 | [diff] [blame] | 1270 | u32 phy_status_mask = 0xffffffff; |
Ville Syrjälä | 3014227 | 2015-07-08 23:46:01 +0300 | [diff] [blame] | 1271 | |
Ville Syrjälä | 3be60de | 2015-09-08 18:05:45 +0300 | [diff] [blame] | 1272 | /* |
| 1273 | * The BIOS can leave the PHY is some weird state |
| 1274 | * where it doesn't fully power down some parts. |
| 1275 | * Disable the asserts until the PHY has been fully |
| 1276 | * reset (ie. the power well has been disabled at |
| 1277 | * least once). |
| 1278 | */ |
| 1279 | if (!dev_priv->chv_phy_assert[DPIO_PHY0]) |
| 1280 | phy_status_mask &= ~(PHY_STATUS_CMN_LDO(DPIO_PHY0, DPIO_CH0) | |
| 1281 | PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH0, 0) | |
| 1282 | PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH0, 1) | |
| 1283 | PHY_STATUS_CMN_LDO(DPIO_PHY0, DPIO_CH1) | |
| 1284 | PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH1, 0) | |
| 1285 | PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH1, 1)); |
| 1286 | |
| 1287 | if (!dev_priv->chv_phy_assert[DPIO_PHY1]) |
| 1288 | phy_status_mask &= ~(PHY_STATUS_CMN_LDO(DPIO_PHY1, DPIO_CH0) | |
| 1289 | PHY_STATUS_SPLINE_LDO(DPIO_PHY1, DPIO_CH0, 0) | |
| 1290 | PHY_STATUS_SPLINE_LDO(DPIO_PHY1, DPIO_CH0, 1)); |
| 1291 | |
Ville Syrjälä | 3014227 | 2015-07-08 23:46:01 +0300 | [diff] [blame] | 1292 | if (cmn_bc->ops->is_enabled(dev_priv, cmn_bc)) { |
| 1293 | phy_status |= PHY_POWERGOOD(DPIO_PHY0); |
| 1294 | |
| 1295 | /* this assumes override is only used to enable lanes */ |
| 1296 | if ((phy_control & PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY0, DPIO_CH0)) == 0) |
| 1297 | phy_control |= PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH0); |
| 1298 | |
| 1299 | if ((phy_control & PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY0, DPIO_CH1)) == 0) |
| 1300 | phy_control |= PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH1); |
| 1301 | |
| 1302 | /* CL1 is on whenever anything is on in either channel */ |
| 1303 | if (BITS_SET(phy_control, |
| 1304 | PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH0) | |
| 1305 | PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH1))) |
| 1306 | phy_status |= PHY_STATUS_CMN_LDO(DPIO_PHY0, DPIO_CH0); |
| 1307 | |
| 1308 | /* |
| 1309 | * The DPLLB check accounts for the pipe B + port A usage |
| 1310 | * with CL2 powered up but all the lanes in the second channel |
| 1311 | * powered down. |
| 1312 | */ |
| 1313 | if (BITS_SET(phy_control, |
| 1314 | PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH1)) && |
| 1315 | (I915_READ(DPLL(PIPE_B)) & DPLL_VCO_ENABLE) == 0) |
| 1316 | phy_status |= PHY_STATUS_CMN_LDO(DPIO_PHY0, DPIO_CH1); |
| 1317 | |
| 1318 | if (BITS_SET(phy_control, |
| 1319 | PHY_CH_POWER_DOWN_OVRD(0x3, DPIO_PHY0, DPIO_CH0))) |
| 1320 | phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH0, 0); |
| 1321 | if (BITS_SET(phy_control, |
| 1322 | PHY_CH_POWER_DOWN_OVRD(0xc, DPIO_PHY0, DPIO_CH0))) |
| 1323 | phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH0, 1); |
| 1324 | |
| 1325 | if (BITS_SET(phy_control, |
| 1326 | PHY_CH_POWER_DOWN_OVRD(0x3, DPIO_PHY0, DPIO_CH1))) |
| 1327 | phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH1, 0); |
| 1328 | if (BITS_SET(phy_control, |
| 1329 | PHY_CH_POWER_DOWN_OVRD(0xc, DPIO_PHY0, DPIO_CH1))) |
| 1330 | phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH1, 1); |
| 1331 | } |
| 1332 | |
| 1333 | if (cmn_d->ops->is_enabled(dev_priv, cmn_d)) { |
| 1334 | phy_status |= PHY_POWERGOOD(DPIO_PHY1); |
| 1335 | |
| 1336 | /* this assumes override is only used to enable lanes */ |
| 1337 | if ((phy_control & PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY1, DPIO_CH0)) == 0) |
| 1338 | phy_control |= PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY1, DPIO_CH0); |
| 1339 | |
| 1340 | if (BITS_SET(phy_control, |
| 1341 | PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY1, DPIO_CH0))) |
| 1342 | phy_status |= PHY_STATUS_CMN_LDO(DPIO_PHY1, DPIO_CH0); |
| 1343 | |
| 1344 | if (BITS_SET(phy_control, |
| 1345 | PHY_CH_POWER_DOWN_OVRD(0x3, DPIO_PHY1, DPIO_CH0))) |
| 1346 | phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY1, DPIO_CH0, 0); |
| 1347 | if (BITS_SET(phy_control, |
| 1348 | PHY_CH_POWER_DOWN_OVRD(0xc, DPIO_PHY1, DPIO_CH0))) |
| 1349 | phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY1, DPIO_CH0, 1); |
| 1350 | } |
| 1351 | |
Ville Syrjälä | 3be60de | 2015-09-08 18:05:45 +0300 | [diff] [blame] | 1352 | phy_status &= phy_status_mask; |
| 1353 | |
Ville Syrjälä | 3014227 | 2015-07-08 23:46:01 +0300 | [diff] [blame] | 1354 | /* |
| 1355 | * The PHY may be busy with some initial calibration and whatnot, |
| 1356 | * so the power state can take a while to actually change. |
| 1357 | */ |
Chris Wilson | 919fcd5 | 2016-06-30 15:33:35 +0100 | [diff] [blame] | 1358 | if (intel_wait_for_register(dev_priv, |
| 1359 | DISPLAY_PHY_STATUS, |
| 1360 | phy_status_mask, |
| 1361 | phy_status, |
| 1362 | 10)) |
| 1363 | DRM_ERROR("Unexpected PHY_STATUS 0x%08x, expected 0x%08x (PHY_CONTROL=0x%08x)\n", |
| 1364 | I915_READ(DISPLAY_PHY_STATUS) & phy_status_mask, |
| 1365 | phy_status, dev_priv->chv_phy_control); |
Ville Syrjälä | 3014227 | 2015-07-08 23:46:01 +0300 | [diff] [blame] | 1366 | } |
| 1367 | |
| 1368 | #undef BITS_SET |
| 1369 | |
Daniel Vetter | 9c065a7 | 2014-09-30 10:56:38 +0200 | [diff] [blame] | 1370 | static void chv_dpio_cmn_power_well_enable(struct drm_i915_private *dev_priv, |
| 1371 | struct i915_power_well *power_well) |
| 1372 | { |
| 1373 | enum dpio_phy phy; |
Ville Syrjälä | e0fce78 | 2015-07-08 23:45:54 +0300 | [diff] [blame] | 1374 | enum pipe pipe; |
| 1375 | uint32_t tmp; |
Daniel Vetter | 9c065a7 | 2014-09-30 10:56:38 +0200 | [diff] [blame] | 1376 | |
Ander Conselvan de Oliveira | 01c3faa | 2016-10-06 19:22:14 +0300 | [diff] [blame] | 1377 | WARN_ON_ONCE(power_well->id != PUNIT_POWER_WELL_DPIO_CMN_BC && |
| 1378 | power_well->id != PUNIT_POWER_WELL_DPIO_CMN_D); |
Daniel Vetter | 9c065a7 | 2014-09-30 10:56:38 +0200 | [diff] [blame] | 1379 | |
Ander Conselvan de Oliveira | 01c3faa | 2016-10-06 19:22:14 +0300 | [diff] [blame] | 1380 | if (power_well->id == PUNIT_POWER_WELL_DPIO_CMN_BC) { |
Ville Syrjälä | e0fce78 | 2015-07-08 23:45:54 +0300 | [diff] [blame] | 1381 | pipe = PIPE_A; |
Daniel Vetter | 9c065a7 | 2014-09-30 10:56:38 +0200 | [diff] [blame] | 1382 | phy = DPIO_PHY0; |
Ville Syrjälä | e0fce78 | 2015-07-08 23:45:54 +0300 | [diff] [blame] | 1383 | } else { |
| 1384 | pipe = PIPE_C; |
Daniel Vetter | 9c065a7 | 2014-09-30 10:56:38 +0200 | [diff] [blame] | 1385 | phy = DPIO_PHY1; |
Ville Syrjälä | e0fce78 | 2015-07-08 23:45:54 +0300 | [diff] [blame] | 1386 | } |
Ville Syrjälä | 5a8fbb7 | 2015-06-29 15:25:53 +0300 | [diff] [blame] | 1387 | |
| 1388 | /* since ref/cri clock was enabled */ |
Daniel Vetter | 9c065a7 | 2014-09-30 10:56:38 +0200 | [diff] [blame] | 1389 | udelay(1); /* >10ns for cmnreset, >0ns for sidereset */ |
| 1390 | vlv_set_power_well(dev_priv, power_well, true); |
| 1391 | |
| 1392 | /* Poll for phypwrgood signal */ |
Chris Wilson | ffebb83 | 2016-06-30 15:33:36 +0100 | [diff] [blame] | 1393 | if (intel_wait_for_register(dev_priv, |
| 1394 | DISPLAY_PHY_STATUS, |
| 1395 | PHY_POWERGOOD(phy), |
| 1396 | PHY_POWERGOOD(phy), |
| 1397 | 1)) |
Daniel Vetter | 9c065a7 | 2014-09-30 10:56:38 +0200 | [diff] [blame] | 1398 | DRM_ERROR("Display PHY %d is not power up\n", phy); |
| 1399 | |
Ville Syrjälä | e0fce78 | 2015-07-08 23:45:54 +0300 | [diff] [blame] | 1400 | mutex_lock(&dev_priv->sb_lock); |
| 1401 | |
| 1402 | /* Enable dynamic power down */ |
| 1403 | tmp = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW28); |
Ville Syrjälä | ee27921 | 2015-07-08 23:45:57 +0300 | [diff] [blame] | 1404 | tmp |= DPIO_DYNPWRDOWNEN_CH0 | DPIO_CL1POWERDOWNEN | |
| 1405 | DPIO_SUS_CLK_CONFIG_GATE_CLKREQ; |
Ville Syrjälä | e0fce78 | 2015-07-08 23:45:54 +0300 | [diff] [blame] | 1406 | vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW28, tmp); |
| 1407 | |
Ander Conselvan de Oliveira | 01c3faa | 2016-10-06 19:22:14 +0300 | [diff] [blame] | 1408 | if (power_well->id == PUNIT_POWER_WELL_DPIO_CMN_BC) { |
Ville Syrjälä | e0fce78 | 2015-07-08 23:45:54 +0300 | [diff] [blame] | 1409 | tmp = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW6_CH1); |
| 1410 | tmp |= DPIO_DYNPWRDOWNEN_CH1; |
| 1411 | vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW6_CH1, tmp); |
Ville Syrjälä | 3e28878 | 2015-07-08 23:45:58 +0300 | [diff] [blame] | 1412 | } else { |
| 1413 | /* |
| 1414 | * Force the non-existing CL2 off. BXT does this |
| 1415 | * too, so maybe it saves some power even though |
| 1416 | * CL2 doesn't exist? |
| 1417 | */ |
| 1418 | tmp = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW30); |
| 1419 | tmp |= DPIO_CL2_LDOFUSE_PWRENB; |
| 1420 | vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW30, tmp); |
Ville Syrjälä | e0fce78 | 2015-07-08 23:45:54 +0300 | [diff] [blame] | 1421 | } |
| 1422 | |
| 1423 | mutex_unlock(&dev_priv->sb_lock); |
| 1424 | |
Ville Syrjälä | 7072246 | 2015-04-10 18:21:28 +0300 | [diff] [blame] | 1425 | dev_priv->chv_phy_control |= PHY_COM_LANE_RESET_DEASSERT(phy); |
| 1426 | I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control); |
Ville Syrjälä | e0fce78 | 2015-07-08 23:45:54 +0300 | [diff] [blame] | 1427 | |
| 1428 | DRM_DEBUG_KMS("Enabled DPIO PHY%d (PHY_CONTROL=0x%08x)\n", |
| 1429 | phy, dev_priv->chv_phy_control); |
Ville Syrjälä | 3014227 | 2015-07-08 23:46:01 +0300 | [diff] [blame] | 1430 | |
| 1431 | assert_chv_phy_status(dev_priv); |
Daniel Vetter | 9c065a7 | 2014-09-30 10:56:38 +0200 | [diff] [blame] | 1432 | } |
| 1433 | |
| 1434 | static void chv_dpio_cmn_power_well_disable(struct drm_i915_private *dev_priv, |
| 1435 | struct i915_power_well *power_well) |
| 1436 | { |
| 1437 | enum dpio_phy phy; |
| 1438 | |
Ander Conselvan de Oliveira | 01c3faa | 2016-10-06 19:22:14 +0300 | [diff] [blame] | 1439 | WARN_ON_ONCE(power_well->id != PUNIT_POWER_WELL_DPIO_CMN_BC && |
| 1440 | power_well->id != PUNIT_POWER_WELL_DPIO_CMN_D); |
Daniel Vetter | 9c065a7 | 2014-09-30 10:56:38 +0200 | [diff] [blame] | 1441 | |
Ander Conselvan de Oliveira | 01c3faa | 2016-10-06 19:22:14 +0300 | [diff] [blame] | 1442 | if (power_well->id == PUNIT_POWER_WELL_DPIO_CMN_BC) { |
Daniel Vetter | 9c065a7 | 2014-09-30 10:56:38 +0200 | [diff] [blame] | 1443 | phy = DPIO_PHY0; |
| 1444 | assert_pll_disabled(dev_priv, PIPE_A); |
| 1445 | assert_pll_disabled(dev_priv, PIPE_B); |
| 1446 | } else { |
| 1447 | phy = DPIO_PHY1; |
| 1448 | assert_pll_disabled(dev_priv, PIPE_C); |
| 1449 | } |
| 1450 | |
Ville Syrjälä | 7072246 | 2015-04-10 18:21:28 +0300 | [diff] [blame] | 1451 | dev_priv->chv_phy_control &= ~PHY_COM_LANE_RESET_DEASSERT(phy); |
| 1452 | I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control); |
Daniel Vetter | 9c065a7 | 2014-09-30 10:56:38 +0200 | [diff] [blame] | 1453 | |
| 1454 | vlv_set_power_well(dev_priv, power_well, false); |
Ville Syrjälä | e0fce78 | 2015-07-08 23:45:54 +0300 | [diff] [blame] | 1455 | |
| 1456 | DRM_DEBUG_KMS("Disabled DPIO PHY%d (PHY_CONTROL=0x%08x)\n", |
| 1457 | phy, dev_priv->chv_phy_control); |
Ville Syrjälä | 3014227 | 2015-07-08 23:46:01 +0300 | [diff] [blame] | 1458 | |
Ville Syrjälä | 3be60de | 2015-09-08 18:05:45 +0300 | [diff] [blame] | 1459 | /* PHY is fully reset now, so we can enable the PHY state asserts */ |
| 1460 | dev_priv->chv_phy_assert[phy] = true; |
| 1461 | |
Ville Syrjälä | 3014227 | 2015-07-08 23:46:01 +0300 | [diff] [blame] | 1462 | assert_chv_phy_status(dev_priv); |
Ville Syrjälä | e0fce78 | 2015-07-08 23:45:54 +0300 | [diff] [blame] | 1463 | } |
| 1464 | |
Ville Syrjälä | 6669e39 | 2015-07-08 23:46:00 +0300 | [diff] [blame] | 1465 | static void assert_chv_phy_powergate(struct drm_i915_private *dev_priv, enum dpio_phy phy, |
| 1466 | enum dpio_channel ch, bool override, unsigned int mask) |
| 1467 | { |
| 1468 | enum pipe pipe = phy == DPIO_PHY0 ? PIPE_A : PIPE_C; |
| 1469 | u32 reg, val, expected, actual; |
| 1470 | |
Ville Syrjälä | 3be60de | 2015-09-08 18:05:45 +0300 | [diff] [blame] | 1471 | /* |
| 1472 | * The BIOS can leave the PHY is some weird state |
| 1473 | * where it doesn't fully power down some parts. |
| 1474 | * Disable the asserts until the PHY has been fully |
| 1475 | * reset (ie. the power well has been disabled at |
| 1476 | * least once). |
| 1477 | */ |
| 1478 | if (!dev_priv->chv_phy_assert[phy]) |
| 1479 | return; |
| 1480 | |
Ville Syrjälä | 6669e39 | 2015-07-08 23:46:00 +0300 | [diff] [blame] | 1481 | if (ch == DPIO_CH0) |
| 1482 | reg = _CHV_CMN_DW0_CH0; |
| 1483 | else |
| 1484 | reg = _CHV_CMN_DW6_CH1; |
| 1485 | |
| 1486 | mutex_lock(&dev_priv->sb_lock); |
| 1487 | val = vlv_dpio_read(dev_priv, pipe, reg); |
| 1488 | mutex_unlock(&dev_priv->sb_lock); |
| 1489 | |
| 1490 | /* |
| 1491 | * This assumes !override is only used when the port is disabled. |
| 1492 | * All lanes should power down even without the override when |
| 1493 | * the port is disabled. |
| 1494 | */ |
| 1495 | if (!override || mask == 0xf) { |
| 1496 | expected = DPIO_ALLDL_POWERDOWN | DPIO_ANYDL_POWERDOWN; |
| 1497 | /* |
| 1498 | * If CH1 common lane is not active anymore |
| 1499 | * (eg. for pipe B DPLL) the entire channel will |
| 1500 | * shut down, which causes the common lane registers |
| 1501 | * to read as 0. That means we can't actually check |
| 1502 | * the lane power down status bits, but as the entire |
| 1503 | * register reads as 0 it's a good indication that the |
| 1504 | * channel is indeed entirely powered down. |
| 1505 | */ |
| 1506 | if (ch == DPIO_CH1 && val == 0) |
| 1507 | expected = 0; |
| 1508 | } else if (mask != 0x0) { |
| 1509 | expected = DPIO_ANYDL_POWERDOWN; |
| 1510 | } else { |
| 1511 | expected = 0; |
| 1512 | } |
| 1513 | |
| 1514 | if (ch == DPIO_CH0) |
| 1515 | actual = val >> DPIO_ANYDL_POWERDOWN_SHIFT_CH0; |
| 1516 | else |
| 1517 | actual = val >> DPIO_ANYDL_POWERDOWN_SHIFT_CH1; |
| 1518 | actual &= DPIO_ALLDL_POWERDOWN | DPIO_ANYDL_POWERDOWN; |
| 1519 | |
| 1520 | WARN(actual != expected, |
| 1521 | "Unexpected DPIO lane power down: all %d, any %d. Expected: all %d, any %d. (0x%x = 0x%08x)\n", |
| 1522 | !!(actual & DPIO_ALLDL_POWERDOWN), !!(actual & DPIO_ANYDL_POWERDOWN), |
| 1523 | !!(expected & DPIO_ALLDL_POWERDOWN), !!(expected & DPIO_ANYDL_POWERDOWN), |
| 1524 | reg, val); |
| 1525 | } |
| 1526 | |
Ville Syrjälä | b0b3384 | 2015-07-08 23:45:55 +0300 | [diff] [blame] | 1527 | bool chv_phy_powergate_ch(struct drm_i915_private *dev_priv, enum dpio_phy phy, |
| 1528 | enum dpio_channel ch, bool override) |
| 1529 | { |
| 1530 | struct i915_power_domains *power_domains = &dev_priv->power_domains; |
| 1531 | bool was_override; |
| 1532 | |
| 1533 | mutex_lock(&power_domains->lock); |
| 1534 | |
| 1535 | was_override = dev_priv->chv_phy_control & PHY_CH_POWER_DOWN_OVRD_EN(phy, ch); |
| 1536 | |
| 1537 | if (override == was_override) |
| 1538 | goto out; |
| 1539 | |
| 1540 | if (override) |
| 1541 | dev_priv->chv_phy_control |= PHY_CH_POWER_DOWN_OVRD_EN(phy, ch); |
| 1542 | else |
| 1543 | dev_priv->chv_phy_control &= ~PHY_CH_POWER_DOWN_OVRD_EN(phy, ch); |
| 1544 | |
| 1545 | I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control); |
| 1546 | |
| 1547 | DRM_DEBUG_KMS("Power gating DPIO PHY%d CH%d (DPIO_PHY_CONTROL=0x%08x)\n", |
| 1548 | phy, ch, dev_priv->chv_phy_control); |
| 1549 | |
Ville Syrjälä | 3014227 | 2015-07-08 23:46:01 +0300 | [diff] [blame] | 1550 | assert_chv_phy_status(dev_priv); |
| 1551 | |
Ville Syrjälä | b0b3384 | 2015-07-08 23:45:55 +0300 | [diff] [blame] | 1552 | out: |
| 1553 | mutex_unlock(&power_domains->lock); |
| 1554 | |
| 1555 | return was_override; |
| 1556 | } |
| 1557 | |
Ville Syrjälä | e0fce78 | 2015-07-08 23:45:54 +0300 | [diff] [blame] | 1558 | void chv_phy_powergate_lanes(struct intel_encoder *encoder, |
| 1559 | bool override, unsigned int mask) |
| 1560 | { |
| 1561 | struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); |
| 1562 | struct i915_power_domains *power_domains = &dev_priv->power_domains; |
| 1563 | enum dpio_phy phy = vlv_dport_to_phy(enc_to_dig_port(&encoder->base)); |
| 1564 | enum dpio_channel ch = vlv_dport_to_channel(enc_to_dig_port(&encoder->base)); |
| 1565 | |
| 1566 | mutex_lock(&power_domains->lock); |
| 1567 | |
| 1568 | dev_priv->chv_phy_control &= ~PHY_CH_POWER_DOWN_OVRD(0xf, phy, ch); |
| 1569 | dev_priv->chv_phy_control |= PHY_CH_POWER_DOWN_OVRD(mask, phy, ch); |
| 1570 | |
| 1571 | if (override) |
| 1572 | dev_priv->chv_phy_control |= PHY_CH_POWER_DOWN_OVRD_EN(phy, ch); |
| 1573 | else |
| 1574 | dev_priv->chv_phy_control &= ~PHY_CH_POWER_DOWN_OVRD_EN(phy, ch); |
| 1575 | |
| 1576 | I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control); |
| 1577 | |
| 1578 | DRM_DEBUG_KMS("Power gating DPIO PHY%d CH%d lanes 0x%x (PHY_CONTROL=0x%08x)\n", |
| 1579 | phy, ch, mask, dev_priv->chv_phy_control); |
| 1580 | |
Ville Syrjälä | 3014227 | 2015-07-08 23:46:01 +0300 | [diff] [blame] | 1581 | assert_chv_phy_status(dev_priv); |
| 1582 | |
Ville Syrjälä | 6669e39 | 2015-07-08 23:46:00 +0300 | [diff] [blame] | 1583 | assert_chv_phy_powergate(dev_priv, phy, ch, override, mask); |
| 1584 | |
Ville Syrjälä | e0fce78 | 2015-07-08 23:45:54 +0300 | [diff] [blame] | 1585 | mutex_unlock(&power_domains->lock); |
Daniel Vetter | 9c065a7 | 2014-09-30 10:56:38 +0200 | [diff] [blame] | 1586 | } |
| 1587 | |
| 1588 | static bool chv_pipe_power_well_enabled(struct drm_i915_private *dev_priv, |
| 1589 | struct i915_power_well *power_well) |
| 1590 | { |
Ander Conselvan de Oliveira | 01c3faa | 2016-10-06 19:22:14 +0300 | [diff] [blame] | 1591 | enum pipe pipe = power_well->id; |
Daniel Vetter | 9c065a7 | 2014-09-30 10:56:38 +0200 | [diff] [blame] | 1592 | bool enabled; |
| 1593 | u32 state, ctrl; |
| 1594 | |
| 1595 | mutex_lock(&dev_priv->rps.hw_lock); |
| 1596 | |
| 1597 | state = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & DP_SSS_MASK(pipe); |
| 1598 | /* |
| 1599 | * We only ever set the power-on and power-gate states, anything |
| 1600 | * else is unexpected. |
| 1601 | */ |
| 1602 | WARN_ON(state != DP_SSS_PWR_ON(pipe) && state != DP_SSS_PWR_GATE(pipe)); |
| 1603 | enabled = state == DP_SSS_PWR_ON(pipe); |
| 1604 | |
| 1605 | /* |
| 1606 | * A transient state at this point would mean some unexpected party |
| 1607 | * is poking at the power controls too. |
| 1608 | */ |
| 1609 | ctrl = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & DP_SSC_MASK(pipe); |
| 1610 | WARN_ON(ctrl << 16 != state); |
| 1611 | |
| 1612 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 1613 | |
| 1614 | return enabled; |
| 1615 | } |
| 1616 | |
| 1617 | static void chv_set_pipe_power_well(struct drm_i915_private *dev_priv, |
| 1618 | struct i915_power_well *power_well, |
| 1619 | bool enable) |
| 1620 | { |
Ander Conselvan de Oliveira | 01c3faa | 2016-10-06 19:22:14 +0300 | [diff] [blame] | 1621 | enum pipe pipe = power_well->id; |
Daniel Vetter | 9c065a7 | 2014-09-30 10:56:38 +0200 | [diff] [blame] | 1622 | u32 state; |
| 1623 | u32 ctrl; |
| 1624 | |
| 1625 | state = enable ? DP_SSS_PWR_ON(pipe) : DP_SSS_PWR_GATE(pipe); |
| 1626 | |
| 1627 | mutex_lock(&dev_priv->rps.hw_lock); |
| 1628 | |
| 1629 | #define COND \ |
| 1630 | ((vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & DP_SSS_MASK(pipe)) == state) |
| 1631 | |
| 1632 | if (COND) |
| 1633 | goto out; |
| 1634 | |
| 1635 | ctrl = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ); |
| 1636 | ctrl &= ~DP_SSC_MASK(pipe); |
| 1637 | ctrl |= enable ? DP_SSC_PWR_ON(pipe) : DP_SSC_PWR_GATE(pipe); |
| 1638 | vlv_punit_write(dev_priv, PUNIT_REG_DSPFREQ, ctrl); |
| 1639 | |
| 1640 | if (wait_for(COND, 100)) |
Masanari Iida | 7e35ab8 | 2015-05-10 01:00:23 +0900 | [diff] [blame] | 1641 | DRM_ERROR("timeout setting power well state %08x (%08x)\n", |
Daniel Vetter | 9c065a7 | 2014-09-30 10:56:38 +0200 | [diff] [blame] | 1642 | state, |
| 1643 | vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ)); |
| 1644 | |
| 1645 | #undef COND |
| 1646 | |
| 1647 | out: |
| 1648 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 1649 | } |
| 1650 | |
| 1651 | static void chv_pipe_power_well_sync_hw(struct drm_i915_private *dev_priv, |
| 1652 | struct i915_power_well *power_well) |
| 1653 | { |
Ander Conselvan de Oliveira | 01c3faa | 2016-10-06 19:22:14 +0300 | [diff] [blame] | 1654 | WARN_ON_ONCE(power_well->id != PIPE_A); |
Ville Syrjälä | 8fcd5cd | 2015-06-29 15:25:50 +0300 | [diff] [blame] | 1655 | |
Daniel Vetter | 9c065a7 | 2014-09-30 10:56:38 +0200 | [diff] [blame] | 1656 | chv_set_pipe_power_well(dev_priv, power_well, power_well->count > 0); |
| 1657 | } |
| 1658 | |
| 1659 | static void chv_pipe_power_well_enable(struct drm_i915_private *dev_priv, |
| 1660 | struct i915_power_well *power_well) |
| 1661 | { |
Ander Conselvan de Oliveira | 01c3faa | 2016-10-06 19:22:14 +0300 | [diff] [blame] | 1662 | WARN_ON_ONCE(power_well->id != PIPE_A); |
Daniel Vetter | 9c065a7 | 2014-09-30 10:56:38 +0200 | [diff] [blame] | 1663 | |
| 1664 | chv_set_pipe_power_well(dev_priv, power_well, true); |
Ville Syrjälä | afd6275 | 2014-10-30 19:43:03 +0200 | [diff] [blame] | 1665 | |
Ville Syrjälä | 2be7d54 | 2015-06-29 15:25:51 +0300 | [diff] [blame] | 1666 | vlv_display_power_well_init(dev_priv); |
Daniel Vetter | 9c065a7 | 2014-09-30 10:56:38 +0200 | [diff] [blame] | 1667 | } |
| 1668 | |
| 1669 | static void chv_pipe_power_well_disable(struct drm_i915_private *dev_priv, |
| 1670 | struct i915_power_well *power_well) |
| 1671 | { |
Ander Conselvan de Oliveira | 01c3faa | 2016-10-06 19:22:14 +0300 | [diff] [blame] | 1672 | WARN_ON_ONCE(power_well->id != PIPE_A); |
Daniel Vetter | 9c065a7 | 2014-09-30 10:56:38 +0200 | [diff] [blame] | 1673 | |
Ville Syrjälä | 2be7d54 | 2015-06-29 15:25:51 +0300 | [diff] [blame] | 1674 | vlv_display_power_well_deinit(dev_priv); |
Ville Syrjälä | afd6275 | 2014-10-30 19:43:03 +0200 | [diff] [blame] | 1675 | |
Daniel Vetter | 9c065a7 | 2014-09-30 10:56:38 +0200 | [diff] [blame] | 1676 | chv_set_pipe_power_well(dev_priv, power_well, false); |
| 1677 | } |
| 1678 | |
Imre Deak | 0973128 | 2016-02-17 14:17:42 +0200 | [diff] [blame] | 1679 | static void |
| 1680 | __intel_display_power_get_domain(struct drm_i915_private *dev_priv, |
| 1681 | enum intel_display_power_domain domain) |
| 1682 | { |
| 1683 | struct i915_power_domains *power_domains = &dev_priv->power_domains; |
| 1684 | struct i915_power_well *power_well; |
| 1685 | int i; |
| 1686 | |
Imre Deak | b409ca9 | 2016-06-13 16:44:33 +0300 | [diff] [blame] | 1687 | for_each_power_well(i, power_well, BIT(domain), power_domains) |
| 1688 | intel_power_well_get(dev_priv, power_well); |
Imre Deak | 0973128 | 2016-02-17 14:17:42 +0200 | [diff] [blame] | 1689 | |
| 1690 | power_domains->domain_use_count[domain]++; |
| 1691 | } |
| 1692 | |
Daniel Vetter | e4e7684 | 2014-09-30 10:56:42 +0200 | [diff] [blame] | 1693 | /** |
| 1694 | * intel_display_power_get - grab a power domain reference |
| 1695 | * @dev_priv: i915 device instance |
| 1696 | * @domain: power domain to reference |
| 1697 | * |
| 1698 | * This function grabs a power domain reference for @domain and ensures that the |
| 1699 | * power domain and all its parents are powered up. Therefore users should only |
| 1700 | * grab a reference to the innermost power domain they need. |
| 1701 | * |
| 1702 | * Any power domain reference obtained by this function must have a symmetric |
| 1703 | * call to intel_display_power_put() to release the reference again. |
| 1704 | */ |
Daniel Vetter | 9c065a7 | 2014-09-30 10:56:38 +0200 | [diff] [blame] | 1705 | void intel_display_power_get(struct drm_i915_private *dev_priv, |
| 1706 | enum intel_display_power_domain domain) |
| 1707 | { |
Imre Deak | 0973128 | 2016-02-17 14:17:42 +0200 | [diff] [blame] | 1708 | struct i915_power_domains *power_domains = &dev_priv->power_domains; |
Daniel Vetter | 9c065a7 | 2014-09-30 10:56:38 +0200 | [diff] [blame] | 1709 | |
| 1710 | intel_runtime_pm_get(dev_priv); |
| 1711 | |
Imre Deak | 0973128 | 2016-02-17 14:17:42 +0200 | [diff] [blame] | 1712 | mutex_lock(&power_domains->lock); |
| 1713 | |
| 1714 | __intel_display_power_get_domain(dev_priv, domain); |
| 1715 | |
| 1716 | mutex_unlock(&power_domains->lock); |
| 1717 | } |
| 1718 | |
| 1719 | /** |
| 1720 | * intel_display_power_get_if_enabled - grab a reference for an enabled display power domain |
| 1721 | * @dev_priv: i915 device instance |
| 1722 | * @domain: power domain to reference |
| 1723 | * |
| 1724 | * This function grabs a power domain reference for @domain and ensures that the |
| 1725 | * power domain and all its parents are powered up. Therefore users should only |
| 1726 | * grab a reference to the innermost power domain they need. |
| 1727 | * |
| 1728 | * Any power domain reference obtained by this function must have a symmetric |
| 1729 | * call to intel_display_power_put() to release the reference again. |
| 1730 | */ |
| 1731 | bool intel_display_power_get_if_enabled(struct drm_i915_private *dev_priv, |
| 1732 | enum intel_display_power_domain domain) |
| 1733 | { |
| 1734 | struct i915_power_domains *power_domains = &dev_priv->power_domains; |
| 1735 | bool is_enabled; |
| 1736 | |
| 1737 | if (!intel_runtime_pm_get_if_in_use(dev_priv)) |
| 1738 | return false; |
Daniel Vetter | 9c065a7 | 2014-09-30 10:56:38 +0200 | [diff] [blame] | 1739 | |
| 1740 | mutex_lock(&power_domains->lock); |
| 1741 | |
Imre Deak | 0973128 | 2016-02-17 14:17:42 +0200 | [diff] [blame] | 1742 | if (__intel_display_power_is_enabled(dev_priv, domain)) { |
| 1743 | __intel_display_power_get_domain(dev_priv, domain); |
| 1744 | is_enabled = true; |
| 1745 | } else { |
| 1746 | is_enabled = false; |
Daniel Vetter | 9c065a7 | 2014-09-30 10:56:38 +0200 | [diff] [blame] | 1747 | } |
| 1748 | |
Daniel Vetter | 9c065a7 | 2014-09-30 10:56:38 +0200 | [diff] [blame] | 1749 | mutex_unlock(&power_domains->lock); |
Imre Deak | 0973128 | 2016-02-17 14:17:42 +0200 | [diff] [blame] | 1750 | |
| 1751 | if (!is_enabled) |
| 1752 | intel_runtime_pm_put(dev_priv); |
| 1753 | |
| 1754 | return is_enabled; |
Daniel Vetter | 9c065a7 | 2014-09-30 10:56:38 +0200 | [diff] [blame] | 1755 | } |
| 1756 | |
Daniel Vetter | e4e7684 | 2014-09-30 10:56:42 +0200 | [diff] [blame] | 1757 | /** |
| 1758 | * intel_display_power_put - release a power domain reference |
| 1759 | * @dev_priv: i915 device instance |
| 1760 | * @domain: power domain to reference |
| 1761 | * |
| 1762 | * This function drops the power domain reference obtained by |
| 1763 | * intel_display_power_get() and might power down the corresponding hardware |
| 1764 | * block right away if this is the last reference. |
| 1765 | */ |
Daniel Vetter | 9c065a7 | 2014-09-30 10:56:38 +0200 | [diff] [blame] | 1766 | void intel_display_power_put(struct drm_i915_private *dev_priv, |
| 1767 | enum intel_display_power_domain domain) |
| 1768 | { |
| 1769 | struct i915_power_domains *power_domains; |
| 1770 | struct i915_power_well *power_well; |
| 1771 | int i; |
| 1772 | |
| 1773 | power_domains = &dev_priv->power_domains; |
| 1774 | |
| 1775 | mutex_lock(&power_domains->lock); |
| 1776 | |
Daniel Stone | 11c86db | 2015-11-20 15:55:34 +0000 | [diff] [blame] | 1777 | WARN(!power_domains->domain_use_count[domain], |
| 1778 | "Use count on domain %s is already zero\n", |
| 1779 | intel_display_power_domain_str(domain)); |
Daniel Vetter | 9c065a7 | 2014-09-30 10:56:38 +0200 | [diff] [blame] | 1780 | power_domains->domain_use_count[domain]--; |
| 1781 | |
Imre Deak | b409ca9 | 2016-06-13 16:44:33 +0300 | [diff] [blame] | 1782 | for_each_power_well_rev(i, power_well, BIT(domain), power_domains) |
| 1783 | intel_power_well_put(dev_priv, power_well); |
Daniel Vetter | 9c065a7 | 2014-09-30 10:56:38 +0200 | [diff] [blame] | 1784 | |
| 1785 | mutex_unlock(&power_domains->lock); |
| 1786 | |
| 1787 | intel_runtime_pm_put(dev_priv); |
| 1788 | } |
| 1789 | |
Ville Syrjälä | 9d0996b | 2016-04-18 14:02:28 +0300 | [diff] [blame] | 1790 | #define HSW_DISPLAY_POWER_DOMAINS ( \ |
| 1791 | BIT(POWER_DOMAIN_PIPE_B) | \ |
| 1792 | BIT(POWER_DOMAIN_PIPE_C) | \ |
| 1793 | BIT(POWER_DOMAIN_PIPE_A_PANEL_FITTER) | \ |
| 1794 | BIT(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \ |
| 1795 | BIT(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \ |
| 1796 | BIT(POWER_DOMAIN_TRANSCODER_A) | \ |
| 1797 | BIT(POWER_DOMAIN_TRANSCODER_B) | \ |
| 1798 | BIT(POWER_DOMAIN_TRANSCODER_C) | \ |
Patrik Jakobsson | 6331a70 | 2015-11-09 16:48:21 +0100 | [diff] [blame] | 1799 | BIT(POWER_DOMAIN_PORT_DDI_B_LANES) | \ |
| 1800 | BIT(POWER_DOMAIN_PORT_DDI_C_LANES) | \ |
| 1801 | BIT(POWER_DOMAIN_PORT_DDI_D_LANES) | \ |
Ville Syrjälä | 9d0996b | 2016-04-18 14:02:28 +0300 | [diff] [blame] | 1802 | BIT(POWER_DOMAIN_PORT_CRT) | /* DDI E */ \ |
| 1803 | BIT(POWER_DOMAIN_VGA) | \ |
| 1804 | BIT(POWER_DOMAIN_AUDIO) | \ |
Daniel Vetter | 9c065a7 | 2014-09-30 10:56:38 +0200 | [diff] [blame] | 1805 | BIT(POWER_DOMAIN_INIT)) |
| 1806 | |
Ville Syrjälä | 9d0996b | 2016-04-18 14:02:28 +0300 | [diff] [blame] | 1807 | #define BDW_DISPLAY_POWER_DOMAINS ( \ |
| 1808 | BIT(POWER_DOMAIN_PIPE_B) | \ |
| 1809 | BIT(POWER_DOMAIN_PIPE_C) | \ |
| 1810 | BIT(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \ |
| 1811 | BIT(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \ |
| 1812 | BIT(POWER_DOMAIN_TRANSCODER_A) | \ |
| 1813 | BIT(POWER_DOMAIN_TRANSCODER_B) | \ |
| 1814 | BIT(POWER_DOMAIN_TRANSCODER_C) | \ |
| 1815 | BIT(POWER_DOMAIN_PORT_DDI_B_LANES) | \ |
| 1816 | BIT(POWER_DOMAIN_PORT_DDI_C_LANES) | \ |
| 1817 | BIT(POWER_DOMAIN_PORT_DDI_D_LANES) | \ |
| 1818 | BIT(POWER_DOMAIN_PORT_CRT) | /* DDI E */ \ |
| 1819 | BIT(POWER_DOMAIN_VGA) | \ |
| 1820 | BIT(POWER_DOMAIN_AUDIO) | \ |
Daniel Vetter | 9c065a7 | 2014-09-30 10:56:38 +0200 | [diff] [blame] | 1821 | BIT(POWER_DOMAIN_INIT)) |
| 1822 | |
Ville Syrjälä | 465ac0c | 2016-04-18 14:02:27 +0300 | [diff] [blame] | 1823 | #define VLV_DISPLAY_POWER_DOMAINS ( \ |
| 1824 | BIT(POWER_DOMAIN_PIPE_A) | \ |
| 1825 | BIT(POWER_DOMAIN_PIPE_B) | \ |
| 1826 | BIT(POWER_DOMAIN_PIPE_A_PANEL_FITTER) | \ |
| 1827 | BIT(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \ |
| 1828 | BIT(POWER_DOMAIN_TRANSCODER_A) | \ |
| 1829 | BIT(POWER_DOMAIN_TRANSCODER_B) | \ |
| 1830 | BIT(POWER_DOMAIN_PORT_DDI_B_LANES) | \ |
| 1831 | BIT(POWER_DOMAIN_PORT_DDI_C_LANES) | \ |
| 1832 | BIT(POWER_DOMAIN_PORT_DSI) | \ |
| 1833 | BIT(POWER_DOMAIN_PORT_CRT) | \ |
| 1834 | BIT(POWER_DOMAIN_VGA) | \ |
| 1835 | BIT(POWER_DOMAIN_AUDIO) | \ |
| 1836 | BIT(POWER_DOMAIN_AUX_B) | \ |
| 1837 | BIT(POWER_DOMAIN_AUX_C) | \ |
| 1838 | BIT(POWER_DOMAIN_GMBUS) | \ |
| 1839 | BIT(POWER_DOMAIN_INIT)) |
Daniel Vetter | 9c065a7 | 2014-09-30 10:56:38 +0200 | [diff] [blame] | 1840 | |
| 1841 | #define VLV_DPIO_CMN_BC_POWER_DOMAINS ( \ |
Patrik Jakobsson | 6331a70 | 2015-11-09 16:48:21 +0100 | [diff] [blame] | 1842 | BIT(POWER_DOMAIN_PORT_DDI_B_LANES) | \ |
| 1843 | BIT(POWER_DOMAIN_PORT_DDI_C_LANES) | \ |
Daniel Vetter | 9c065a7 | 2014-09-30 10:56:38 +0200 | [diff] [blame] | 1844 | BIT(POWER_DOMAIN_PORT_CRT) | \ |
Satheeshakrishna M | 1407121 | 2015-01-16 15:57:51 +0000 | [diff] [blame] | 1845 | BIT(POWER_DOMAIN_AUX_B) | \ |
| 1846 | BIT(POWER_DOMAIN_AUX_C) | \ |
Daniel Vetter | 9c065a7 | 2014-09-30 10:56:38 +0200 | [diff] [blame] | 1847 | BIT(POWER_DOMAIN_INIT)) |
| 1848 | |
| 1849 | #define VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS ( \ |
Patrik Jakobsson | 6331a70 | 2015-11-09 16:48:21 +0100 | [diff] [blame] | 1850 | BIT(POWER_DOMAIN_PORT_DDI_B_LANES) | \ |
Satheeshakrishna M | 1407121 | 2015-01-16 15:57:51 +0000 | [diff] [blame] | 1851 | BIT(POWER_DOMAIN_AUX_B) | \ |
Daniel Vetter | 9c065a7 | 2014-09-30 10:56:38 +0200 | [diff] [blame] | 1852 | BIT(POWER_DOMAIN_INIT)) |
| 1853 | |
| 1854 | #define VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS ( \ |
Patrik Jakobsson | 6331a70 | 2015-11-09 16:48:21 +0100 | [diff] [blame] | 1855 | BIT(POWER_DOMAIN_PORT_DDI_B_LANES) | \ |
Satheeshakrishna M | 1407121 | 2015-01-16 15:57:51 +0000 | [diff] [blame] | 1856 | BIT(POWER_DOMAIN_AUX_B) | \ |
Daniel Vetter | 9c065a7 | 2014-09-30 10:56:38 +0200 | [diff] [blame] | 1857 | BIT(POWER_DOMAIN_INIT)) |
| 1858 | |
| 1859 | #define VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS ( \ |
Patrik Jakobsson | 6331a70 | 2015-11-09 16:48:21 +0100 | [diff] [blame] | 1860 | BIT(POWER_DOMAIN_PORT_DDI_C_LANES) | \ |
Satheeshakrishna M | 1407121 | 2015-01-16 15:57:51 +0000 | [diff] [blame] | 1861 | BIT(POWER_DOMAIN_AUX_C) | \ |
Daniel Vetter | 9c065a7 | 2014-09-30 10:56:38 +0200 | [diff] [blame] | 1862 | BIT(POWER_DOMAIN_INIT)) |
| 1863 | |
| 1864 | #define VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS ( \ |
Patrik Jakobsson | 6331a70 | 2015-11-09 16:48:21 +0100 | [diff] [blame] | 1865 | BIT(POWER_DOMAIN_PORT_DDI_C_LANES) | \ |
Satheeshakrishna M | 1407121 | 2015-01-16 15:57:51 +0000 | [diff] [blame] | 1866 | BIT(POWER_DOMAIN_AUX_C) | \ |
Daniel Vetter | 9c065a7 | 2014-09-30 10:56:38 +0200 | [diff] [blame] | 1867 | BIT(POWER_DOMAIN_INIT)) |
| 1868 | |
Ville Syrjälä | 465ac0c | 2016-04-18 14:02:27 +0300 | [diff] [blame] | 1869 | #define CHV_DISPLAY_POWER_DOMAINS ( \ |
| 1870 | BIT(POWER_DOMAIN_PIPE_A) | \ |
| 1871 | BIT(POWER_DOMAIN_PIPE_B) | \ |
| 1872 | BIT(POWER_DOMAIN_PIPE_C) | \ |
| 1873 | BIT(POWER_DOMAIN_PIPE_A_PANEL_FITTER) | \ |
| 1874 | BIT(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \ |
| 1875 | BIT(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \ |
| 1876 | BIT(POWER_DOMAIN_TRANSCODER_A) | \ |
| 1877 | BIT(POWER_DOMAIN_TRANSCODER_B) | \ |
| 1878 | BIT(POWER_DOMAIN_TRANSCODER_C) | \ |
| 1879 | BIT(POWER_DOMAIN_PORT_DDI_B_LANES) | \ |
| 1880 | BIT(POWER_DOMAIN_PORT_DDI_C_LANES) | \ |
| 1881 | BIT(POWER_DOMAIN_PORT_DDI_D_LANES) | \ |
| 1882 | BIT(POWER_DOMAIN_PORT_DSI) | \ |
| 1883 | BIT(POWER_DOMAIN_VGA) | \ |
| 1884 | BIT(POWER_DOMAIN_AUDIO) | \ |
| 1885 | BIT(POWER_DOMAIN_AUX_B) | \ |
| 1886 | BIT(POWER_DOMAIN_AUX_C) | \ |
| 1887 | BIT(POWER_DOMAIN_AUX_D) | \ |
| 1888 | BIT(POWER_DOMAIN_GMBUS) | \ |
| 1889 | BIT(POWER_DOMAIN_INIT)) |
| 1890 | |
Daniel Vetter | 9c065a7 | 2014-09-30 10:56:38 +0200 | [diff] [blame] | 1891 | #define CHV_DPIO_CMN_BC_POWER_DOMAINS ( \ |
Patrik Jakobsson | 6331a70 | 2015-11-09 16:48:21 +0100 | [diff] [blame] | 1892 | BIT(POWER_DOMAIN_PORT_DDI_B_LANES) | \ |
| 1893 | BIT(POWER_DOMAIN_PORT_DDI_C_LANES) | \ |
Satheeshakrishna M | 1407121 | 2015-01-16 15:57:51 +0000 | [diff] [blame] | 1894 | BIT(POWER_DOMAIN_AUX_B) | \ |
| 1895 | BIT(POWER_DOMAIN_AUX_C) | \ |
Daniel Vetter | 9c065a7 | 2014-09-30 10:56:38 +0200 | [diff] [blame] | 1896 | BIT(POWER_DOMAIN_INIT)) |
| 1897 | |
| 1898 | #define CHV_DPIO_CMN_D_POWER_DOMAINS ( \ |
Patrik Jakobsson | 6331a70 | 2015-11-09 16:48:21 +0100 | [diff] [blame] | 1899 | BIT(POWER_DOMAIN_PORT_DDI_D_LANES) | \ |
Satheeshakrishna M | 1407121 | 2015-01-16 15:57:51 +0000 | [diff] [blame] | 1900 | BIT(POWER_DOMAIN_AUX_D) | \ |
Daniel Vetter | 9c065a7 | 2014-09-30 10:56:38 +0200 | [diff] [blame] | 1901 | BIT(POWER_DOMAIN_INIT)) |
| 1902 | |
Daniel Vetter | 9c065a7 | 2014-09-30 10:56:38 +0200 | [diff] [blame] | 1903 | static const struct i915_power_well_ops i9xx_always_on_power_well_ops = { |
| 1904 | .sync_hw = i9xx_always_on_power_well_noop, |
| 1905 | .enable = i9xx_always_on_power_well_noop, |
| 1906 | .disable = i9xx_always_on_power_well_noop, |
| 1907 | .is_enabled = i9xx_always_on_power_well_enabled, |
| 1908 | }; |
| 1909 | |
| 1910 | static const struct i915_power_well_ops chv_pipe_power_well_ops = { |
| 1911 | .sync_hw = chv_pipe_power_well_sync_hw, |
| 1912 | .enable = chv_pipe_power_well_enable, |
| 1913 | .disable = chv_pipe_power_well_disable, |
| 1914 | .is_enabled = chv_pipe_power_well_enabled, |
| 1915 | }; |
| 1916 | |
| 1917 | static const struct i915_power_well_ops chv_dpio_cmn_power_well_ops = { |
| 1918 | .sync_hw = vlv_power_well_sync_hw, |
| 1919 | .enable = chv_dpio_cmn_power_well_enable, |
| 1920 | .disable = chv_dpio_cmn_power_well_disable, |
| 1921 | .is_enabled = vlv_power_well_enabled, |
| 1922 | }; |
| 1923 | |
| 1924 | static struct i915_power_well i9xx_always_on_power_well[] = { |
| 1925 | { |
| 1926 | .name = "always-on", |
| 1927 | .always_on = 1, |
| 1928 | .domains = POWER_DOMAIN_MASK, |
| 1929 | .ops = &i9xx_always_on_power_well_ops, |
| 1930 | }, |
| 1931 | }; |
| 1932 | |
| 1933 | static const struct i915_power_well_ops hsw_power_well_ops = { |
| 1934 | .sync_hw = hsw_power_well_sync_hw, |
| 1935 | .enable = hsw_power_well_enable, |
| 1936 | .disable = hsw_power_well_disable, |
| 1937 | .is_enabled = hsw_power_well_enabled, |
| 1938 | }; |
| 1939 | |
Satheeshakrishna M | 94dd513 | 2015-02-04 13:57:44 +0000 | [diff] [blame] | 1940 | static const struct i915_power_well_ops skl_power_well_ops = { |
| 1941 | .sync_hw = skl_power_well_sync_hw, |
| 1942 | .enable = skl_power_well_enable, |
| 1943 | .disable = skl_power_well_disable, |
| 1944 | .is_enabled = skl_power_well_enabled, |
| 1945 | }; |
| 1946 | |
Patrik Jakobsson | 9f836f9 | 2015-11-16 16:20:01 +0100 | [diff] [blame] | 1947 | static const struct i915_power_well_ops gen9_dc_off_power_well_ops = { |
| 1948 | .sync_hw = gen9_dc_off_power_well_sync_hw, |
| 1949 | .enable = gen9_dc_off_power_well_enable, |
| 1950 | .disable = gen9_dc_off_power_well_disable, |
| 1951 | .is_enabled = gen9_dc_off_power_well_enabled, |
| 1952 | }; |
| 1953 | |
Imre Deak | 9c8d0b8 | 2016-06-13 16:44:34 +0300 | [diff] [blame] | 1954 | static const struct i915_power_well_ops bxt_dpio_cmn_power_well_ops = { |
| 1955 | .sync_hw = bxt_dpio_cmn_power_well_sync_hw, |
| 1956 | .enable = bxt_dpio_cmn_power_well_enable, |
| 1957 | .disable = bxt_dpio_cmn_power_well_disable, |
| 1958 | .is_enabled = bxt_dpio_cmn_power_well_enabled, |
| 1959 | }; |
| 1960 | |
Daniel Vetter | 9c065a7 | 2014-09-30 10:56:38 +0200 | [diff] [blame] | 1961 | static struct i915_power_well hsw_power_wells[] = { |
| 1962 | { |
| 1963 | .name = "always-on", |
| 1964 | .always_on = 1, |
Ville Syrjälä | 998bd66 | 2016-04-18 14:02:26 +0300 | [diff] [blame] | 1965 | .domains = POWER_DOMAIN_MASK, |
Daniel Vetter | 9c065a7 | 2014-09-30 10:56:38 +0200 | [diff] [blame] | 1966 | .ops = &i9xx_always_on_power_well_ops, |
| 1967 | }, |
| 1968 | { |
| 1969 | .name = "display", |
| 1970 | .domains = HSW_DISPLAY_POWER_DOMAINS, |
| 1971 | .ops = &hsw_power_well_ops, |
| 1972 | }, |
| 1973 | }; |
| 1974 | |
| 1975 | static struct i915_power_well bdw_power_wells[] = { |
| 1976 | { |
| 1977 | .name = "always-on", |
| 1978 | .always_on = 1, |
Ville Syrjälä | 998bd66 | 2016-04-18 14:02:26 +0300 | [diff] [blame] | 1979 | .domains = POWER_DOMAIN_MASK, |
Daniel Vetter | 9c065a7 | 2014-09-30 10:56:38 +0200 | [diff] [blame] | 1980 | .ops = &i9xx_always_on_power_well_ops, |
| 1981 | }, |
| 1982 | { |
| 1983 | .name = "display", |
| 1984 | .domains = BDW_DISPLAY_POWER_DOMAINS, |
| 1985 | .ops = &hsw_power_well_ops, |
| 1986 | }, |
| 1987 | }; |
| 1988 | |
| 1989 | static const struct i915_power_well_ops vlv_display_power_well_ops = { |
| 1990 | .sync_hw = vlv_power_well_sync_hw, |
| 1991 | .enable = vlv_display_power_well_enable, |
| 1992 | .disable = vlv_display_power_well_disable, |
| 1993 | .is_enabled = vlv_power_well_enabled, |
| 1994 | }; |
| 1995 | |
| 1996 | static const struct i915_power_well_ops vlv_dpio_cmn_power_well_ops = { |
| 1997 | .sync_hw = vlv_power_well_sync_hw, |
| 1998 | .enable = vlv_dpio_cmn_power_well_enable, |
| 1999 | .disable = vlv_dpio_cmn_power_well_disable, |
| 2000 | .is_enabled = vlv_power_well_enabled, |
| 2001 | }; |
| 2002 | |
| 2003 | static const struct i915_power_well_ops vlv_dpio_power_well_ops = { |
| 2004 | .sync_hw = vlv_power_well_sync_hw, |
| 2005 | .enable = vlv_power_well_enable, |
| 2006 | .disable = vlv_power_well_disable, |
| 2007 | .is_enabled = vlv_power_well_enabled, |
| 2008 | }; |
| 2009 | |
| 2010 | static struct i915_power_well vlv_power_wells[] = { |
| 2011 | { |
| 2012 | .name = "always-on", |
| 2013 | .always_on = 1, |
Ville Syrjälä | 998bd66 | 2016-04-18 14:02:26 +0300 | [diff] [blame] | 2014 | .domains = POWER_DOMAIN_MASK, |
Daniel Vetter | 9c065a7 | 2014-09-30 10:56:38 +0200 | [diff] [blame] | 2015 | .ops = &i9xx_always_on_power_well_ops, |
Ander Conselvan de Oliveira | 01c3faa | 2016-10-06 19:22:14 +0300 | [diff] [blame] | 2016 | .id = PUNIT_POWER_WELL_ALWAYS_ON, |
Daniel Vetter | 9c065a7 | 2014-09-30 10:56:38 +0200 | [diff] [blame] | 2017 | }, |
| 2018 | { |
| 2019 | .name = "display", |
| 2020 | .domains = VLV_DISPLAY_POWER_DOMAINS, |
Ander Conselvan de Oliveira | 01c3faa | 2016-10-06 19:22:14 +0300 | [diff] [blame] | 2021 | .id = PUNIT_POWER_WELL_DISP2D, |
Daniel Vetter | 9c065a7 | 2014-09-30 10:56:38 +0200 | [diff] [blame] | 2022 | .ops = &vlv_display_power_well_ops, |
| 2023 | }, |
| 2024 | { |
| 2025 | .name = "dpio-tx-b-01", |
| 2026 | .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS | |
| 2027 | VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS | |
| 2028 | VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS | |
| 2029 | VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS, |
| 2030 | .ops = &vlv_dpio_power_well_ops, |
Ander Conselvan de Oliveira | 01c3faa | 2016-10-06 19:22:14 +0300 | [diff] [blame] | 2031 | .id = PUNIT_POWER_WELL_DPIO_TX_B_LANES_01, |
Daniel Vetter | 9c065a7 | 2014-09-30 10:56:38 +0200 | [diff] [blame] | 2032 | }, |
| 2033 | { |
| 2034 | .name = "dpio-tx-b-23", |
| 2035 | .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS | |
| 2036 | VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS | |
| 2037 | VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS | |
| 2038 | VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS, |
| 2039 | .ops = &vlv_dpio_power_well_ops, |
Ander Conselvan de Oliveira | 01c3faa | 2016-10-06 19:22:14 +0300 | [diff] [blame] | 2040 | .id = PUNIT_POWER_WELL_DPIO_TX_B_LANES_23, |
Daniel Vetter | 9c065a7 | 2014-09-30 10:56:38 +0200 | [diff] [blame] | 2041 | }, |
| 2042 | { |
| 2043 | .name = "dpio-tx-c-01", |
| 2044 | .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS | |
| 2045 | VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS | |
| 2046 | VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS | |
| 2047 | VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS, |
| 2048 | .ops = &vlv_dpio_power_well_ops, |
Ander Conselvan de Oliveira | 01c3faa | 2016-10-06 19:22:14 +0300 | [diff] [blame] | 2049 | .id = PUNIT_POWER_WELL_DPIO_TX_C_LANES_01, |
Daniel Vetter | 9c065a7 | 2014-09-30 10:56:38 +0200 | [diff] [blame] | 2050 | }, |
| 2051 | { |
| 2052 | .name = "dpio-tx-c-23", |
| 2053 | .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS | |
| 2054 | VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS | |
| 2055 | VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS | |
| 2056 | VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS, |
| 2057 | .ops = &vlv_dpio_power_well_ops, |
Ander Conselvan de Oliveira | 01c3faa | 2016-10-06 19:22:14 +0300 | [diff] [blame] | 2058 | .id = PUNIT_POWER_WELL_DPIO_TX_C_LANES_23, |
Daniel Vetter | 9c065a7 | 2014-09-30 10:56:38 +0200 | [diff] [blame] | 2059 | }, |
| 2060 | { |
| 2061 | .name = "dpio-common", |
| 2062 | .domains = VLV_DPIO_CMN_BC_POWER_DOMAINS, |
Ander Conselvan de Oliveira | 01c3faa | 2016-10-06 19:22:14 +0300 | [diff] [blame] | 2063 | .id = PUNIT_POWER_WELL_DPIO_CMN_BC, |
Daniel Vetter | 9c065a7 | 2014-09-30 10:56:38 +0200 | [diff] [blame] | 2064 | .ops = &vlv_dpio_cmn_power_well_ops, |
| 2065 | }, |
| 2066 | }; |
| 2067 | |
| 2068 | static struct i915_power_well chv_power_wells[] = { |
| 2069 | { |
| 2070 | .name = "always-on", |
| 2071 | .always_on = 1, |
Ville Syrjälä | 998bd66 | 2016-04-18 14:02:26 +0300 | [diff] [blame] | 2072 | .domains = POWER_DOMAIN_MASK, |
Daniel Vetter | 9c065a7 | 2014-09-30 10:56:38 +0200 | [diff] [blame] | 2073 | .ops = &i9xx_always_on_power_well_ops, |
| 2074 | }, |
Daniel Vetter | 9c065a7 | 2014-09-30 10:56:38 +0200 | [diff] [blame] | 2075 | { |
| 2076 | .name = "display", |
Ville Syrjälä | baa4e57 | 2014-10-27 16:07:32 +0200 | [diff] [blame] | 2077 | /* |
Ville Syrjälä | fde61e4 | 2015-05-26 20:22:39 +0300 | [diff] [blame] | 2078 | * Pipe A power well is the new disp2d well. Pipe B and C |
| 2079 | * power wells don't actually exist. Pipe A power well is |
| 2080 | * required for any pipe to work. |
Ville Syrjälä | baa4e57 | 2014-10-27 16:07:32 +0200 | [diff] [blame] | 2081 | */ |
Ville Syrjälä | 465ac0c | 2016-04-18 14:02:27 +0300 | [diff] [blame] | 2082 | .domains = CHV_DISPLAY_POWER_DOMAINS, |
Ander Conselvan de Oliveira | 01c3faa | 2016-10-06 19:22:14 +0300 | [diff] [blame] | 2083 | .id = PIPE_A, |
Daniel Vetter | 9c065a7 | 2014-09-30 10:56:38 +0200 | [diff] [blame] | 2084 | .ops = &chv_pipe_power_well_ops, |
| 2085 | }, |
Daniel Vetter | 9c065a7 | 2014-09-30 10:56:38 +0200 | [diff] [blame] | 2086 | { |
| 2087 | .name = "dpio-common-bc", |
Ville Syrjälä | 71849b6 | 2015-04-10 18:21:29 +0300 | [diff] [blame] | 2088 | .domains = CHV_DPIO_CMN_BC_POWER_DOMAINS, |
Ander Conselvan de Oliveira | 01c3faa | 2016-10-06 19:22:14 +0300 | [diff] [blame] | 2089 | .id = PUNIT_POWER_WELL_DPIO_CMN_BC, |
Daniel Vetter | 9c065a7 | 2014-09-30 10:56:38 +0200 | [diff] [blame] | 2090 | .ops = &chv_dpio_cmn_power_well_ops, |
| 2091 | }, |
| 2092 | { |
| 2093 | .name = "dpio-common-d", |
Ville Syrjälä | 71849b6 | 2015-04-10 18:21:29 +0300 | [diff] [blame] | 2094 | .domains = CHV_DPIO_CMN_D_POWER_DOMAINS, |
Ander Conselvan de Oliveira | 01c3faa | 2016-10-06 19:22:14 +0300 | [diff] [blame] | 2095 | .id = PUNIT_POWER_WELL_DPIO_CMN_D, |
Daniel Vetter | 9c065a7 | 2014-09-30 10:56:38 +0200 | [diff] [blame] | 2096 | .ops = &chv_dpio_cmn_power_well_ops, |
| 2097 | }, |
Daniel Vetter | 9c065a7 | 2014-09-30 10:56:38 +0200 | [diff] [blame] | 2098 | }; |
| 2099 | |
Suketu Shah | 5aefb23 | 2015-04-16 14:22:10 +0530 | [diff] [blame] | 2100 | bool intel_display_power_well_is_enabled(struct drm_i915_private *dev_priv, |
| 2101 | int power_well_id) |
| 2102 | { |
| 2103 | struct i915_power_well *power_well; |
| 2104 | bool ret; |
| 2105 | |
| 2106 | power_well = lookup_power_well(dev_priv, power_well_id); |
| 2107 | ret = power_well->ops->is_enabled(dev_priv, power_well); |
| 2108 | |
| 2109 | return ret; |
| 2110 | } |
| 2111 | |
Satheeshakrishna M | 94dd513 | 2015-02-04 13:57:44 +0000 | [diff] [blame] | 2112 | static struct i915_power_well skl_power_wells[] = { |
| 2113 | { |
| 2114 | .name = "always-on", |
| 2115 | .always_on = 1, |
Ville Syrjälä | 998bd66 | 2016-04-18 14:02:26 +0300 | [diff] [blame] | 2116 | .domains = POWER_DOMAIN_MASK, |
Satheeshakrishna M | 94dd513 | 2015-02-04 13:57:44 +0000 | [diff] [blame] | 2117 | .ops = &i9xx_always_on_power_well_ops, |
Ander Conselvan de Oliveira | 01c3faa | 2016-10-06 19:22:14 +0300 | [diff] [blame] | 2118 | .id = SKL_DISP_PW_ALWAYS_ON, |
Satheeshakrishna M | 94dd513 | 2015-02-04 13:57:44 +0000 | [diff] [blame] | 2119 | }, |
| 2120 | { |
| 2121 | .name = "power well 1", |
Imre Deak | 4a76f29 | 2015-11-04 19:24:15 +0200 | [diff] [blame] | 2122 | /* Handled by the DMC firmware */ |
| 2123 | .domains = 0, |
Satheeshakrishna M | 94dd513 | 2015-02-04 13:57:44 +0000 | [diff] [blame] | 2124 | .ops = &skl_power_well_ops, |
Ander Conselvan de Oliveira | 01c3faa | 2016-10-06 19:22:14 +0300 | [diff] [blame] | 2125 | .id = SKL_DISP_PW_1, |
Satheeshakrishna M | 94dd513 | 2015-02-04 13:57:44 +0000 | [diff] [blame] | 2126 | }, |
| 2127 | { |
| 2128 | .name = "MISC IO power well", |
Imre Deak | 4a76f29 | 2015-11-04 19:24:15 +0200 | [diff] [blame] | 2129 | /* Handled by the DMC firmware */ |
| 2130 | .domains = 0, |
Satheeshakrishna M | 94dd513 | 2015-02-04 13:57:44 +0000 | [diff] [blame] | 2131 | .ops = &skl_power_well_ops, |
Ander Conselvan de Oliveira | 01c3faa | 2016-10-06 19:22:14 +0300 | [diff] [blame] | 2132 | .id = SKL_DISP_PW_MISC_IO, |
Satheeshakrishna M | 94dd513 | 2015-02-04 13:57:44 +0000 | [diff] [blame] | 2133 | }, |
| 2134 | { |
Patrik Jakobsson | 9f836f9 | 2015-11-16 16:20:01 +0100 | [diff] [blame] | 2135 | .name = "DC off", |
| 2136 | .domains = SKL_DISPLAY_DC_OFF_POWER_DOMAINS, |
| 2137 | .ops = &gen9_dc_off_power_well_ops, |
Ander Conselvan de Oliveira | 01c3faa | 2016-10-06 19:22:14 +0300 | [diff] [blame] | 2138 | .id = SKL_DISP_PW_DC_OFF, |
Patrik Jakobsson | 9f836f9 | 2015-11-16 16:20:01 +0100 | [diff] [blame] | 2139 | }, |
| 2140 | { |
Satheeshakrishna M | 94dd513 | 2015-02-04 13:57:44 +0000 | [diff] [blame] | 2141 | .name = "power well 2", |
| 2142 | .domains = SKL_DISPLAY_POWERWELL_2_POWER_DOMAINS, |
| 2143 | .ops = &skl_power_well_ops, |
Ander Conselvan de Oliveira | 01c3faa | 2016-10-06 19:22:14 +0300 | [diff] [blame] | 2144 | .id = SKL_DISP_PW_2, |
Satheeshakrishna M | 94dd513 | 2015-02-04 13:57:44 +0000 | [diff] [blame] | 2145 | }, |
| 2146 | { |
| 2147 | .name = "DDI A/E power well", |
| 2148 | .domains = SKL_DISPLAY_DDI_A_E_POWER_DOMAINS, |
| 2149 | .ops = &skl_power_well_ops, |
Ander Conselvan de Oliveira | 01c3faa | 2016-10-06 19:22:14 +0300 | [diff] [blame] | 2150 | .id = SKL_DISP_PW_DDI_A_E, |
Satheeshakrishna M | 94dd513 | 2015-02-04 13:57:44 +0000 | [diff] [blame] | 2151 | }, |
| 2152 | { |
| 2153 | .name = "DDI B power well", |
| 2154 | .domains = SKL_DISPLAY_DDI_B_POWER_DOMAINS, |
| 2155 | .ops = &skl_power_well_ops, |
Ander Conselvan de Oliveira | 01c3faa | 2016-10-06 19:22:14 +0300 | [diff] [blame] | 2156 | .id = SKL_DISP_PW_DDI_B, |
Satheeshakrishna M | 94dd513 | 2015-02-04 13:57:44 +0000 | [diff] [blame] | 2157 | }, |
| 2158 | { |
| 2159 | .name = "DDI C power well", |
| 2160 | .domains = SKL_DISPLAY_DDI_C_POWER_DOMAINS, |
| 2161 | .ops = &skl_power_well_ops, |
Ander Conselvan de Oliveira | 01c3faa | 2016-10-06 19:22:14 +0300 | [diff] [blame] | 2162 | .id = SKL_DISP_PW_DDI_C, |
Satheeshakrishna M | 94dd513 | 2015-02-04 13:57:44 +0000 | [diff] [blame] | 2163 | }, |
| 2164 | { |
| 2165 | .name = "DDI D power well", |
| 2166 | .domains = SKL_DISPLAY_DDI_D_POWER_DOMAINS, |
| 2167 | .ops = &skl_power_well_ops, |
Ander Conselvan de Oliveira | 01c3faa | 2016-10-06 19:22:14 +0300 | [diff] [blame] | 2168 | .id = SKL_DISP_PW_DDI_D, |
Satheeshakrishna M | 94dd513 | 2015-02-04 13:57:44 +0000 | [diff] [blame] | 2169 | }, |
| 2170 | }; |
| 2171 | |
Satheeshakrishna M | 0b4a2a3 | 2014-07-11 14:51:13 +0530 | [diff] [blame] | 2172 | static struct i915_power_well bxt_power_wells[] = { |
| 2173 | { |
| 2174 | .name = "always-on", |
| 2175 | .always_on = 1, |
Ville Syrjälä | 998bd66 | 2016-04-18 14:02:26 +0300 | [diff] [blame] | 2176 | .domains = POWER_DOMAIN_MASK, |
Satheeshakrishna M | 0b4a2a3 | 2014-07-11 14:51:13 +0530 | [diff] [blame] | 2177 | .ops = &i9xx_always_on_power_well_ops, |
| 2178 | }, |
| 2179 | { |
| 2180 | .name = "power well 1", |
Imre Deak | d7d7c9e | 2016-04-01 16:02:42 +0300 | [diff] [blame] | 2181 | .domains = 0, |
Satheeshakrishna M | 0b4a2a3 | 2014-07-11 14:51:13 +0530 | [diff] [blame] | 2182 | .ops = &skl_power_well_ops, |
Ander Conselvan de Oliveira | 01c3faa | 2016-10-06 19:22:14 +0300 | [diff] [blame] | 2183 | .id = SKL_DISP_PW_1, |
Satheeshakrishna M | 0b4a2a3 | 2014-07-11 14:51:13 +0530 | [diff] [blame] | 2184 | }, |
| 2185 | { |
Patrik Jakobsson | 9f836f9 | 2015-11-16 16:20:01 +0100 | [diff] [blame] | 2186 | .name = "DC off", |
| 2187 | .domains = BXT_DISPLAY_DC_OFF_POWER_DOMAINS, |
| 2188 | .ops = &gen9_dc_off_power_well_ops, |
Ander Conselvan de Oliveira | 01c3faa | 2016-10-06 19:22:14 +0300 | [diff] [blame] | 2189 | .id = SKL_DISP_PW_DC_OFF, |
Patrik Jakobsson | 9f836f9 | 2015-11-16 16:20:01 +0100 | [diff] [blame] | 2190 | }, |
| 2191 | { |
Satheeshakrishna M | 0b4a2a3 | 2014-07-11 14:51:13 +0530 | [diff] [blame] | 2192 | .name = "power well 2", |
| 2193 | .domains = BXT_DISPLAY_POWERWELL_2_POWER_DOMAINS, |
| 2194 | .ops = &skl_power_well_ops, |
Ander Conselvan de Oliveira | 01c3faa | 2016-10-06 19:22:14 +0300 | [diff] [blame] | 2195 | .id = SKL_DISP_PW_2, |
Patrik Jakobsson | 9f836f9 | 2015-11-16 16:20:01 +0100 | [diff] [blame] | 2196 | }, |
Imre Deak | 9c8d0b8 | 2016-06-13 16:44:34 +0300 | [diff] [blame] | 2197 | { |
| 2198 | .name = "dpio-common-a", |
| 2199 | .domains = BXT_DPIO_CMN_A_POWER_DOMAINS, |
| 2200 | .ops = &bxt_dpio_cmn_power_well_ops, |
Ander Conselvan de Oliveira | 01c3faa | 2016-10-06 19:22:14 +0300 | [diff] [blame] | 2201 | .id = BXT_DPIO_CMN_A, |
Ander Conselvan de Oliveira | 362624c | 2016-10-06 19:22:15 +0300 | [diff] [blame] | 2202 | .data = DPIO_PHY1, |
Imre Deak | 9c8d0b8 | 2016-06-13 16:44:34 +0300 | [diff] [blame] | 2203 | }, |
| 2204 | { |
| 2205 | .name = "dpio-common-bc", |
| 2206 | .domains = BXT_DPIO_CMN_BC_POWER_DOMAINS, |
| 2207 | .ops = &bxt_dpio_cmn_power_well_ops, |
Ander Conselvan de Oliveira | 01c3faa | 2016-10-06 19:22:14 +0300 | [diff] [blame] | 2208 | .id = BXT_DPIO_CMN_BC, |
Ander Conselvan de Oliveira | 362624c | 2016-10-06 19:22:15 +0300 | [diff] [blame] | 2209 | .data = DPIO_PHY0, |
Imre Deak | 9c8d0b8 | 2016-06-13 16:44:34 +0300 | [diff] [blame] | 2210 | }, |
Satheeshakrishna M | 0b4a2a3 | 2014-07-11 14:51:13 +0530 | [diff] [blame] | 2211 | }; |
| 2212 | |
Ander Conselvan de Oliveira | 0d03926 | 2016-12-02 10:23:50 +0200 | [diff] [blame] | 2213 | static struct i915_power_well glk_power_wells[] = { |
| 2214 | { |
| 2215 | .name = "always-on", |
| 2216 | .always_on = 1, |
| 2217 | .domains = POWER_DOMAIN_MASK, |
| 2218 | .ops = &i9xx_always_on_power_well_ops, |
| 2219 | }, |
| 2220 | { |
| 2221 | .name = "power well 1", |
| 2222 | /* Handled by the DMC firmware */ |
| 2223 | .domains = 0, |
| 2224 | .ops = &skl_power_well_ops, |
| 2225 | .id = SKL_DISP_PW_1, |
| 2226 | }, |
| 2227 | { |
| 2228 | .name = "DC off", |
| 2229 | .domains = GLK_DISPLAY_DC_OFF_POWER_DOMAINS, |
| 2230 | .ops = &gen9_dc_off_power_well_ops, |
| 2231 | .id = SKL_DISP_PW_DC_OFF, |
| 2232 | }, |
| 2233 | { |
| 2234 | .name = "power well 2", |
| 2235 | .domains = GLK_DISPLAY_POWERWELL_2_POWER_DOMAINS, |
| 2236 | .ops = &skl_power_well_ops, |
| 2237 | .id = SKL_DISP_PW_2, |
| 2238 | }, |
| 2239 | { |
Ander Conselvan de Oliveira | 0a116ce | 2016-12-02 10:23:51 +0200 | [diff] [blame] | 2240 | .name = "dpio-common-a", |
| 2241 | .domains = GLK_DPIO_CMN_A_POWER_DOMAINS, |
| 2242 | .ops = &bxt_dpio_cmn_power_well_ops, |
| 2243 | .id = BXT_DPIO_CMN_A, |
| 2244 | .data = DPIO_PHY1, |
| 2245 | }, |
| 2246 | { |
| 2247 | .name = "dpio-common-b", |
| 2248 | .domains = GLK_DPIO_CMN_B_POWER_DOMAINS, |
| 2249 | .ops = &bxt_dpio_cmn_power_well_ops, |
| 2250 | .id = BXT_DPIO_CMN_BC, |
| 2251 | .data = DPIO_PHY0, |
| 2252 | }, |
| 2253 | { |
| 2254 | .name = "dpio-common-c", |
| 2255 | .domains = GLK_DPIO_CMN_C_POWER_DOMAINS, |
| 2256 | .ops = &bxt_dpio_cmn_power_well_ops, |
| 2257 | .id = GLK_DPIO_CMN_C, |
| 2258 | .data = DPIO_PHY2, |
| 2259 | }, |
| 2260 | { |
Ander Conselvan de Oliveira | 0d03926 | 2016-12-02 10:23:50 +0200 | [diff] [blame] | 2261 | .name = "AUX A", |
| 2262 | .domains = GLK_DISPLAY_AUX_A_POWER_DOMAINS, |
| 2263 | .ops = &skl_power_well_ops, |
| 2264 | .id = GLK_DISP_PW_AUX_A, |
| 2265 | }, |
| 2266 | { |
| 2267 | .name = "AUX B", |
| 2268 | .domains = GLK_DISPLAY_AUX_B_POWER_DOMAINS, |
| 2269 | .ops = &skl_power_well_ops, |
| 2270 | .id = GLK_DISP_PW_AUX_B, |
| 2271 | }, |
| 2272 | { |
| 2273 | .name = "AUX C", |
| 2274 | .domains = GLK_DISPLAY_AUX_C_POWER_DOMAINS, |
| 2275 | .ops = &skl_power_well_ops, |
| 2276 | .id = GLK_DISP_PW_AUX_C, |
| 2277 | }, |
| 2278 | { |
| 2279 | .name = "DDI A power well", |
| 2280 | .domains = GLK_DISPLAY_DDI_A_POWER_DOMAINS, |
| 2281 | .ops = &skl_power_well_ops, |
| 2282 | .id = GLK_DISP_PW_DDI_A, |
| 2283 | }, |
| 2284 | { |
| 2285 | .name = "DDI B power well", |
| 2286 | .domains = GLK_DISPLAY_DDI_B_POWER_DOMAINS, |
| 2287 | .ops = &skl_power_well_ops, |
| 2288 | .id = SKL_DISP_PW_DDI_B, |
| 2289 | }, |
| 2290 | { |
| 2291 | .name = "DDI C power well", |
| 2292 | .domains = GLK_DISPLAY_DDI_C_POWER_DOMAINS, |
| 2293 | .ops = &skl_power_well_ops, |
| 2294 | .id = SKL_DISP_PW_DDI_C, |
| 2295 | }, |
| 2296 | }; |
| 2297 | |
Imre Deak | 1b0e3a0 | 2015-11-05 23:04:11 +0200 | [diff] [blame] | 2298 | static int |
| 2299 | sanitize_disable_power_well_option(const struct drm_i915_private *dev_priv, |
| 2300 | int disable_power_well) |
| 2301 | { |
| 2302 | if (disable_power_well >= 0) |
| 2303 | return !!disable_power_well; |
| 2304 | |
Imre Deak | 1b0e3a0 | 2015-11-05 23:04:11 +0200 | [diff] [blame] | 2305 | return 1; |
| 2306 | } |
| 2307 | |
Imre Deak | a37baf3 | 2016-02-29 22:49:03 +0200 | [diff] [blame] | 2308 | static uint32_t get_allowed_dc_mask(const struct drm_i915_private *dev_priv, |
| 2309 | int enable_dc) |
| 2310 | { |
| 2311 | uint32_t mask; |
| 2312 | int requested_dc; |
| 2313 | int max_dc; |
| 2314 | |
| 2315 | if (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv)) { |
| 2316 | max_dc = 2; |
| 2317 | mask = 0; |
Ander Conselvan de Oliveira | cc3f90f | 2016-12-02 10:23:49 +0200 | [diff] [blame] | 2318 | } else if (IS_GEN9_LP(dev_priv)) { |
Imre Deak | a37baf3 | 2016-02-29 22:49:03 +0200 | [diff] [blame] | 2319 | max_dc = 1; |
| 2320 | /* |
| 2321 | * DC9 has a separate HW flow from the rest of the DC states, |
| 2322 | * not depending on the DMC firmware. It's needed by system |
| 2323 | * suspend/resume, so allow it unconditionally. |
| 2324 | */ |
| 2325 | mask = DC_STATE_EN_DC9; |
| 2326 | } else { |
| 2327 | max_dc = 0; |
| 2328 | mask = 0; |
| 2329 | } |
| 2330 | |
Imre Deak | 66e2c4c | 2016-02-29 22:49:04 +0200 | [diff] [blame] | 2331 | if (!i915.disable_power_well) |
| 2332 | max_dc = 0; |
| 2333 | |
Imre Deak | a37baf3 | 2016-02-29 22:49:03 +0200 | [diff] [blame] | 2334 | if (enable_dc >= 0 && enable_dc <= max_dc) { |
| 2335 | requested_dc = enable_dc; |
| 2336 | } else if (enable_dc == -1) { |
| 2337 | requested_dc = max_dc; |
| 2338 | } else if (enable_dc > max_dc && enable_dc <= 2) { |
| 2339 | DRM_DEBUG_KMS("Adjusting requested max DC state (%d->%d)\n", |
| 2340 | enable_dc, max_dc); |
| 2341 | requested_dc = max_dc; |
| 2342 | } else { |
| 2343 | DRM_ERROR("Unexpected value for enable_dc (%d)\n", enable_dc); |
| 2344 | requested_dc = max_dc; |
| 2345 | } |
| 2346 | |
| 2347 | if (requested_dc > 1) |
| 2348 | mask |= DC_STATE_EN_UPTO_DC6; |
| 2349 | if (requested_dc > 0) |
| 2350 | mask |= DC_STATE_EN_UPTO_DC5; |
| 2351 | |
| 2352 | DRM_DEBUG_KMS("Allowed DC state mask %02x\n", mask); |
| 2353 | |
| 2354 | return mask; |
| 2355 | } |
| 2356 | |
Daniel Vetter | 9c065a7 | 2014-09-30 10:56:38 +0200 | [diff] [blame] | 2357 | #define set_power_wells(power_domains, __power_wells) ({ \ |
| 2358 | (power_domains)->power_wells = (__power_wells); \ |
| 2359 | (power_domains)->power_well_count = ARRAY_SIZE(__power_wells); \ |
| 2360 | }) |
| 2361 | |
Daniel Vetter | e4e7684 | 2014-09-30 10:56:42 +0200 | [diff] [blame] | 2362 | /** |
| 2363 | * intel_power_domains_init - initializes the power domain structures |
| 2364 | * @dev_priv: i915 device instance |
| 2365 | * |
| 2366 | * Initializes the power domain structures for @dev_priv depending upon the |
| 2367 | * supported platform. |
| 2368 | */ |
Daniel Vetter | 9c065a7 | 2014-09-30 10:56:38 +0200 | [diff] [blame] | 2369 | int intel_power_domains_init(struct drm_i915_private *dev_priv) |
| 2370 | { |
| 2371 | struct i915_power_domains *power_domains = &dev_priv->power_domains; |
| 2372 | |
Imre Deak | 1b0e3a0 | 2015-11-05 23:04:11 +0200 | [diff] [blame] | 2373 | i915.disable_power_well = sanitize_disable_power_well_option(dev_priv, |
| 2374 | i915.disable_power_well); |
Imre Deak | a37baf3 | 2016-02-29 22:49:03 +0200 | [diff] [blame] | 2375 | dev_priv->csr.allowed_dc_mask = get_allowed_dc_mask(dev_priv, |
| 2376 | i915.enable_dc); |
Imre Deak | 1b0e3a0 | 2015-11-05 23:04:11 +0200 | [diff] [blame] | 2377 | |
Ville Syrjälä | f0ab43e | 2015-11-09 16:48:19 +0100 | [diff] [blame] | 2378 | BUILD_BUG_ON(POWER_DOMAIN_NUM > 31); |
| 2379 | |
Daniel Vetter | 9c065a7 | 2014-09-30 10:56:38 +0200 | [diff] [blame] | 2380 | mutex_init(&power_domains->lock); |
| 2381 | |
| 2382 | /* |
| 2383 | * The enabling order will be from lower to higher indexed wells, |
| 2384 | * the disabling order is reversed. |
| 2385 | */ |
Joonas Lahtinen | 2d1fe07 | 2016-04-07 11:08:05 +0300 | [diff] [blame] | 2386 | if (IS_HASWELL(dev_priv)) { |
Daniel Vetter | 9c065a7 | 2014-09-30 10:56:38 +0200 | [diff] [blame] | 2387 | set_power_wells(power_domains, hsw_power_wells); |
Joonas Lahtinen | 2d1fe07 | 2016-04-07 11:08:05 +0300 | [diff] [blame] | 2388 | } else if (IS_BROADWELL(dev_priv)) { |
Daniel Vetter | 9c065a7 | 2014-09-30 10:56:38 +0200 | [diff] [blame] | 2389 | set_power_wells(power_domains, bdw_power_wells); |
Joonas Lahtinen | 2d1fe07 | 2016-04-07 11:08:05 +0300 | [diff] [blame] | 2390 | } else if (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv)) { |
Satheeshakrishna M | 94dd513 | 2015-02-04 13:57:44 +0000 | [diff] [blame] | 2391 | set_power_wells(power_domains, skl_power_wells); |
Joonas Lahtinen | 2d1fe07 | 2016-04-07 11:08:05 +0300 | [diff] [blame] | 2392 | } else if (IS_BROXTON(dev_priv)) { |
Satheeshakrishna M | 0b4a2a3 | 2014-07-11 14:51:13 +0530 | [diff] [blame] | 2393 | set_power_wells(power_domains, bxt_power_wells); |
Ander Conselvan de Oliveira | 0d03926 | 2016-12-02 10:23:50 +0200 | [diff] [blame] | 2394 | } else if (IS_GEMINILAKE(dev_priv)) { |
| 2395 | set_power_wells(power_domains, glk_power_wells); |
Joonas Lahtinen | 2d1fe07 | 2016-04-07 11:08:05 +0300 | [diff] [blame] | 2396 | } else if (IS_CHERRYVIEW(dev_priv)) { |
Daniel Vetter | 9c065a7 | 2014-09-30 10:56:38 +0200 | [diff] [blame] | 2397 | set_power_wells(power_domains, chv_power_wells); |
Joonas Lahtinen | 2d1fe07 | 2016-04-07 11:08:05 +0300 | [diff] [blame] | 2398 | } else if (IS_VALLEYVIEW(dev_priv)) { |
Daniel Vetter | 9c065a7 | 2014-09-30 10:56:38 +0200 | [diff] [blame] | 2399 | set_power_wells(power_domains, vlv_power_wells); |
| 2400 | } else { |
| 2401 | set_power_wells(power_domains, i9xx_always_on_power_well); |
| 2402 | } |
| 2403 | |
| 2404 | return 0; |
| 2405 | } |
| 2406 | |
Daniel Vetter | e4e7684 | 2014-09-30 10:56:42 +0200 | [diff] [blame] | 2407 | /** |
| 2408 | * intel_power_domains_fini - finalizes the power domain structures |
| 2409 | * @dev_priv: i915 device instance |
| 2410 | * |
| 2411 | * Finalizes the power domain structures for @dev_priv depending upon the |
| 2412 | * supported platform. This function also disables runtime pm and ensures that |
| 2413 | * the device stays powered up so that the driver can be reloaded. |
| 2414 | */ |
Daniel Vetter | f458ebb | 2014-09-30 10:56:39 +0200 | [diff] [blame] | 2415 | void intel_power_domains_fini(struct drm_i915_private *dev_priv) |
Daniel Vetter | 9c065a7 | 2014-09-30 10:56:38 +0200 | [diff] [blame] | 2416 | { |
David Weinehall | c49d13e | 2016-08-22 13:32:42 +0300 | [diff] [blame] | 2417 | struct device *kdev = &dev_priv->drm.pdev->dev; |
Imre Deak | 25b181b | 2015-12-17 13:44:56 +0200 | [diff] [blame] | 2418 | |
Imre Deak | aabee1b | 2015-12-15 20:10:29 +0200 | [diff] [blame] | 2419 | /* |
| 2420 | * The i915.ko module is still not prepared to be loaded when |
Daniel Vetter | f458ebb | 2014-09-30 10:56:39 +0200 | [diff] [blame] | 2421 | * the power well is not enabled, so just enable it in case |
Imre Deak | aabee1b | 2015-12-15 20:10:29 +0200 | [diff] [blame] | 2422 | * we're going to unload/reload. |
| 2423 | * The following also reacquires the RPM reference the core passed |
| 2424 | * to the driver during loading, which is dropped in |
| 2425 | * intel_runtime_pm_enable(). We have to hand back the control of the |
| 2426 | * device to the core with this reference held. |
| 2427 | */ |
Daniel Vetter | f458ebb | 2014-09-30 10:56:39 +0200 | [diff] [blame] | 2428 | intel_display_set_init_power(dev_priv, true); |
Imre Deak | d314cd4 | 2015-11-17 17:44:23 +0200 | [diff] [blame] | 2429 | |
| 2430 | /* Remove the refcount we took to keep power well support disabled. */ |
| 2431 | if (!i915.disable_power_well) |
| 2432 | intel_display_power_put(dev_priv, POWER_DOMAIN_INIT); |
Imre Deak | 25b181b | 2015-12-17 13:44:56 +0200 | [diff] [blame] | 2433 | |
| 2434 | /* |
| 2435 | * Remove the refcount we took in intel_runtime_pm_enable() in case |
| 2436 | * the platform doesn't support runtime PM. |
| 2437 | */ |
| 2438 | if (!HAS_RUNTIME_PM(dev_priv)) |
David Weinehall | c49d13e | 2016-08-22 13:32:42 +0300 | [diff] [blame] | 2439 | pm_runtime_put(kdev); |
Daniel Vetter | 9c065a7 | 2014-09-30 10:56:38 +0200 | [diff] [blame] | 2440 | } |
| 2441 | |
Imre Deak | 30eade1 | 2015-11-04 19:24:13 +0200 | [diff] [blame] | 2442 | static void intel_power_domains_sync_hw(struct drm_i915_private *dev_priv) |
Daniel Vetter | 9c065a7 | 2014-09-30 10:56:38 +0200 | [diff] [blame] | 2443 | { |
| 2444 | struct i915_power_domains *power_domains = &dev_priv->power_domains; |
| 2445 | struct i915_power_well *power_well; |
| 2446 | int i; |
| 2447 | |
| 2448 | mutex_lock(&power_domains->lock); |
| 2449 | for_each_power_well(i, power_well, POWER_DOMAIN_MASK, power_domains) { |
| 2450 | power_well->ops->sync_hw(dev_priv, power_well); |
| 2451 | power_well->hw_enabled = power_well->ops->is_enabled(dev_priv, |
| 2452 | power_well); |
| 2453 | } |
| 2454 | mutex_unlock(&power_domains->lock); |
| 2455 | } |
| 2456 | |
Ville Syrjälä | 70c2c18 | 2016-05-13 23:41:30 +0300 | [diff] [blame] | 2457 | static void gen9_dbuf_enable(struct drm_i915_private *dev_priv) |
| 2458 | { |
| 2459 | I915_WRITE(DBUF_CTL, I915_READ(DBUF_CTL) | DBUF_POWER_REQUEST); |
| 2460 | POSTING_READ(DBUF_CTL); |
| 2461 | |
| 2462 | udelay(10); |
| 2463 | |
| 2464 | if (!(I915_READ(DBUF_CTL) & DBUF_POWER_STATE)) |
| 2465 | DRM_ERROR("DBuf power enable timeout\n"); |
| 2466 | } |
| 2467 | |
| 2468 | static void gen9_dbuf_disable(struct drm_i915_private *dev_priv) |
| 2469 | { |
| 2470 | I915_WRITE(DBUF_CTL, I915_READ(DBUF_CTL) & ~DBUF_POWER_REQUEST); |
| 2471 | POSTING_READ(DBUF_CTL); |
| 2472 | |
| 2473 | udelay(10); |
| 2474 | |
| 2475 | if (I915_READ(DBUF_CTL) & DBUF_POWER_STATE) |
| 2476 | DRM_ERROR("DBuf power disable timeout!\n"); |
| 2477 | } |
| 2478 | |
Imre Deak | 73dfc22 | 2015-11-17 17:33:53 +0200 | [diff] [blame] | 2479 | static void skl_display_core_init(struct drm_i915_private *dev_priv, |
Imre Deak | 443a93a | 2016-04-04 15:42:57 +0300 | [diff] [blame] | 2480 | bool resume) |
Imre Deak | 73dfc22 | 2015-11-17 17:33:53 +0200 | [diff] [blame] | 2481 | { |
| 2482 | struct i915_power_domains *power_domains = &dev_priv->power_domains; |
Imre Deak | 443a93a | 2016-04-04 15:42:57 +0300 | [diff] [blame] | 2483 | struct i915_power_well *well; |
Imre Deak | 73dfc22 | 2015-11-17 17:33:53 +0200 | [diff] [blame] | 2484 | uint32_t val; |
| 2485 | |
Imre Deak | d26fa1d | 2015-11-04 19:24:17 +0200 | [diff] [blame] | 2486 | gen9_set_dc_state(dev_priv, DC_STATE_DISABLE); |
| 2487 | |
Imre Deak | 73dfc22 | 2015-11-17 17:33:53 +0200 | [diff] [blame] | 2488 | /* enable PCH reset handshake */ |
| 2489 | val = I915_READ(HSW_NDE_RSTWRN_OPT); |
| 2490 | I915_WRITE(HSW_NDE_RSTWRN_OPT, val | RESET_PCH_HANDSHAKE_ENABLE); |
| 2491 | |
| 2492 | /* enable PG1 and Misc I/O */ |
| 2493 | mutex_lock(&power_domains->lock); |
Imre Deak | 443a93a | 2016-04-04 15:42:57 +0300 | [diff] [blame] | 2494 | |
| 2495 | well = lookup_power_well(dev_priv, SKL_DISP_PW_1); |
| 2496 | intel_power_well_enable(dev_priv, well); |
| 2497 | |
| 2498 | well = lookup_power_well(dev_priv, SKL_DISP_PW_MISC_IO); |
| 2499 | intel_power_well_enable(dev_priv, well); |
| 2500 | |
Imre Deak | 73dfc22 | 2015-11-17 17:33:53 +0200 | [diff] [blame] | 2501 | mutex_unlock(&power_domains->lock); |
| 2502 | |
Imre Deak | 73dfc22 | 2015-11-17 17:33:53 +0200 | [diff] [blame] | 2503 | skl_init_cdclk(dev_priv); |
| 2504 | |
Ville Syrjälä | 70c2c18 | 2016-05-13 23:41:30 +0300 | [diff] [blame] | 2505 | gen9_dbuf_enable(dev_priv); |
| 2506 | |
Ville Syrjälä | 9f7eb31 | 2016-05-13 23:41:29 +0300 | [diff] [blame] | 2507 | if (resume && dev_priv->csr.dmc_payload) |
Imre Deak | 2abc525 | 2016-03-04 21:57:41 +0200 | [diff] [blame] | 2508 | intel_csr_load_program(dev_priv); |
Imre Deak | 73dfc22 | 2015-11-17 17:33:53 +0200 | [diff] [blame] | 2509 | } |
| 2510 | |
| 2511 | static void skl_display_core_uninit(struct drm_i915_private *dev_priv) |
| 2512 | { |
| 2513 | struct i915_power_domains *power_domains = &dev_priv->power_domains; |
Imre Deak | 443a93a | 2016-04-04 15:42:57 +0300 | [diff] [blame] | 2514 | struct i915_power_well *well; |
Imre Deak | 73dfc22 | 2015-11-17 17:33:53 +0200 | [diff] [blame] | 2515 | |
Imre Deak | d26fa1d | 2015-11-04 19:24:17 +0200 | [diff] [blame] | 2516 | gen9_set_dc_state(dev_priv, DC_STATE_DISABLE); |
| 2517 | |
Ville Syrjälä | 70c2c18 | 2016-05-13 23:41:30 +0300 | [diff] [blame] | 2518 | gen9_dbuf_disable(dev_priv); |
| 2519 | |
Imre Deak | 73dfc22 | 2015-11-17 17:33:53 +0200 | [diff] [blame] | 2520 | skl_uninit_cdclk(dev_priv); |
| 2521 | |
| 2522 | /* The spec doesn't call for removing the reset handshake flag */ |
| 2523 | /* disable PG1 and Misc I/O */ |
Imre Deak | 443a93a | 2016-04-04 15:42:57 +0300 | [diff] [blame] | 2524 | |
Imre Deak | 73dfc22 | 2015-11-17 17:33:53 +0200 | [diff] [blame] | 2525 | mutex_lock(&power_domains->lock); |
Imre Deak | 443a93a | 2016-04-04 15:42:57 +0300 | [diff] [blame] | 2526 | |
| 2527 | well = lookup_power_well(dev_priv, SKL_DISP_PW_MISC_IO); |
| 2528 | intel_power_well_disable(dev_priv, well); |
| 2529 | |
| 2530 | well = lookup_power_well(dev_priv, SKL_DISP_PW_1); |
| 2531 | intel_power_well_disable(dev_priv, well); |
| 2532 | |
Imre Deak | 73dfc22 | 2015-11-17 17:33:53 +0200 | [diff] [blame] | 2533 | mutex_unlock(&power_domains->lock); |
| 2534 | } |
| 2535 | |
Imre Deak | d7d7c9e | 2016-04-01 16:02:42 +0300 | [diff] [blame] | 2536 | void bxt_display_core_init(struct drm_i915_private *dev_priv, |
| 2537 | bool resume) |
| 2538 | { |
| 2539 | struct i915_power_domains *power_domains = &dev_priv->power_domains; |
| 2540 | struct i915_power_well *well; |
| 2541 | uint32_t val; |
| 2542 | |
| 2543 | gen9_set_dc_state(dev_priv, DC_STATE_DISABLE); |
| 2544 | |
| 2545 | /* |
| 2546 | * NDE_RSTWRN_OPT RST PCH Handshake En must always be 0b on BXT |
| 2547 | * or else the reset will hang because there is no PCH to respond. |
| 2548 | * Move the handshake programming to initialization sequence. |
| 2549 | * Previously was left up to BIOS. |
| 2550 | */ |
| 2551 | val = I915_READ(HSW_NDE_RSTWRN_OPT); |
| 2552 | val &= ~RESET_PCH_HANDSHAKE_ENABLE; |
| 2553 | I915_WRITE(HSW_NDE_RSTWRN_OPT, val); |
| 2554 | |
| 2555 | /* Enable PG1 */ |
| 2556 | mutex_lock(&power_domains->lock); |
| 2557 | |
| 2558 | well = lookup_power_well(dev_priv, SKL_DISP_PW_1); |
| 2559 | intel_power_well_enable(dev_priv, well); |
| 2560 | |
| 2561 | mutex_unlock(&power_domains->lock); |
| 2562 | |
Imre Deak | 324513c | 2016-06-13 16:44:36 +0300 | [diff] [blame] | 2563 | bxt_init_cdclk(dev_priv); |
Ville Syrjälä | 70c2c18 | 2016-05-13 23:41:30 +0300 | [diff] [blame] | 2564 | |
| 2565 | gen9_dbuf_enable(dev_priv); |
| 2566 | |
Imre Deak | d7d7c9e | 2016-04-01 16:02:42 +0300 | [diff] [blame] | 2567 | if (resume && dev_priv->csr.dmc_payload) |
| 2568 | intel_csr_load_program(dev_priv); |
| 2569 | } |
| 2570 | |
| 2571 | void bxt_display_core_uninit(struct drm_i915_private *dev_priv) |
| 2572 | { |
| 2573 | struct i915_power_domains *power_domains = &dev_priv->power_domains; |
| 2574 | struct i915_power_well *well; |
| 2575 | |
| 2576 | gen9_set_dc_state(dev_priv, DC_STATE_DISABLE); |
| 2577 | |
Ville Syrjälä | 70c2c18 | 2016-05-13 23:41:30 +0300 | [diff] [blame] | 2578 | gen9_dbuf_disable(dev_priv); |
| 2579 | |
Imre Deak | 324513c | 2016-06-13 16:44:36 +0300 | [diff] [blame] | 2580 | bxt_uninit_cdclk(dev_priv); |
Imre Deak | d7d7c9e | 2016-04-01 16:02:42 +0300 | [diff] [blame] | 2581 | |
| 2582 | /* The spec doesn't call for removing the reset handshake flag */ |
| 2583 | |
| 2584 | /* Disable PG1 */ |
| 2585 | mutex_lock(&power_domains->lock); |
| 2586 | |
| 2587 | well = lookup_power_well(dev_priv, SKL_DISP_PW_1); |
| 2588 | intel_power_well_disable(dev_priv, well); |
| 2589 | |
| 2590 | mutex_unlock(&power_domains->lock); |
| 2591 | } |
| 2592 | |
Ville Syrjälä | 7072246 | 2015-04-10 18:21:28 +0300 | [diff] [blame] | 2593 | static void chv_phy_control_init(struct drm_i915_private *dev_priv) |
| 2594 | { |
| 2595 | struct i915_power_well *cmn_bc = |
| 2596 | lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_BC); |
| 2597 | struct i915_power_well *cmn_d = |
| 2598 | lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_D); |
| 2599 | |
| 2600 | /* |
| 2601 | * DISPLAY_PHY_CONTROL can get corrupted if read. As a |
| 2602 | * workaround never ever read DISPLAY_PHY_CONTROL, and |
| 2603 | * instead maintain a shadow copy ourselves. Use the actual |
Ville Syrjälä | e0fce78 | 2015-07-08 23:45:54 +0300 | [diff] [blame] | 2604 | * power well state and lane status to reconstruct the |
| 2605 | * expected initial value. |
Ville Syrjälä | 7072246 | 2015-04-10 18:21:28 +0300 | [diff] [blame] | 2606 | */ |
| 2607 | dev_priv->chv_phy_control = |
Ville Syrjälä | bc28454 | 2015-05-26 20:22:38 +0300 | [diff] [blame] | 2608 | PHY_LDO_SEQ_DELAY(PHY_LDO_DELAY_600NS, DPIO_PHY0) | |
| 2609 | PHY_LDO_SEQ_DELAY(PHY_LDO_DELAY_600NS, DPIO_PHY1) | |
Ville Syrjälä | e0fce78 | 2015-07-08 23:45:54 +0300 | [diff] [blame] | 2610 | PHY_CH_POWER_MODE(PHY_CH_DEEP_PSR, DPIO_PHY0, DPIO_CH0) | |
| 2611 | PHY_CH_POWER_MODE(PHY_CH_DEEP_PSR, DPIO_PHY0, DPIO_CH1) | |
| 2612 | PHY_CH_POWER_MODE(PHY_CH_DEEP_PSR, DPIO_PHY1, DPIO_CH0); |
| 2613 | |
| 2614 | /* |
| 2615 | * If all lanes are disabled we leave the override disabled |
| 2616 | * with all power down bits cleared to match the state we |
| 2617 | * would use after disabling the port. Otherwise enable the |
| 2618 | * override and set the lane powerdown bits accding to the |
| 2619 | * current lane status. |
| 2620 | */ |
| 2621 | if (cmn_bc->ops->is_enabled(dev_priv, cmn_bc)) { |
| 2622 | uint32_t status = I915_READ(DPLL(PIPE_A)); |
| 2623 | unsigned int mask; |
| 2624 | |
| 2625 | mask = status & DPLL_PORTB_READY_MASK; |
| 2626 | if (mask == 0xf) |
| 2627 | mask = 0x0; |
| 2628 | else |
| 2629 | dev_priv->chv_phy_control |= |
| 2630 | PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY0, DPIO_CH0); |
| 2631 | |
| 2632 | dev_priv->chv_phy_control |= |
| 2633 | PHY_CH_POWER_DOWN_OVRD(mask, DPIO_PHY0, DPIO_CH0); |
| 2634 | |
| 2635 | mask = (status & DPLL_PORTC_READY_MASK) >> 4; |
| 2636 | if (mask == 0xf) |
| 2637 | mask = 0x0; |
| 2638 | else |
| 2639 | dev_priv->chv_phy_control |= |
| 2640 | PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY0, DPIO_CH1); |
| 2641 | |
| 2642 | dev_priv->chv_phy_control |= |
| 2643 | PHY_CH_POWER_DOWN_OVRD(mask, DPIO_PHY0, DPIO_CH1); |
| 2644 | |
Ville Syrjälä | 7072246 | 2015-04-10 18:21:28 +0300 | [diff] [blame] | 2645 | dev_priv->chv_phy_control |= PHY_COM_LANE_RESET_DEASSERT(DPIO_PHY0); |
Ville Syrjälä | 3be60de | 2015-09-08 18:05:45 +0300 | [diff] [blame] | 2646 | |
| 2647 | dev_priv->chv_phy_assert[DPIO_PHY0] = false; |
| 2648 | } else { |
| 2649 | dev_priv->chv_phy_assert[DPIO_PHY0] = true; |
Ville Syrjälä | e0fce78 | 2015-07-08 23:45:54 +0300 | [diff] [blame] | 2650 | } |
| 2651 | |
| 2652 | if (cmn_d->ops->is_enabled(dev_priv, cmn_d)) { |
| 2653 | uint32_t status = I915_READ(DPIO_PHY_STATUS); |
| 2654 | unsigned int mask; |
| 2655 | |
| 2656 | mask = status & DPLL_PORTD_READY_MASK; |
| 2657 | |
| 2658 | if (mask == 0xf) |
| 2659 | mask = 0x0; |
| 2660 | else |
| 2661 | dev_priv->chv_phy_control |= |
| 2662 | PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY1, DPIO_CH0); |
| 2663 | |
| 2664 | dev_priv->chv_phy_control |= |
| 2665 | PHY_CH_POWER_DOWN_OVRD(mask, DPIO_PHY1, DPIO_CH0); |
| 2666 | |
Ville Syrjälä | 7072246 | 2015-04-10 18:21:28 +0300 | [diff] [blame] | 2667 | dev_priv->chv_phy_control |= PHY_COM_LANE_RESET_DEASSERT(DPIO_PHY1); |
Ville Syrjälä | 3be60de | 2015-09-08 18:05:45 +0300 | [diff] [blame] | 2668 | |
| 2669 | dev_priv->chv_phy_assert[DPIO_PHY1] = false; |
| 2670 | } else { |
| 2671 | dev_priv->chv_phy_assert[DPIO_PHY1] = true; |
Ville Syrjälä | e0fce78 | 2015-07-08 23:45:54 +0300 | [diff] [blame] | 2672 | } |
| 2673 | |
| 2674 | I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control); |
| 2675 | |
| 2676 | DRM_DEBUG_KMS("Initial PHY_CONTROL=0x%08x\n", |
| 2677 | dev_priv->chv_phy_control); |
Ville Syrjälä | 7072246 | 2015-04-10 18:21:28 +0300 | [diff] [blame] | 2678 | } |
| 2679 | |
Daniel Vetter | 9c065a7 | 2014-09-30 10:56:38 +0200 | [diff] [blame] | 2680 | static void vlv_cmnlane_wa(struct drm_i915_private *dev_priv) |
| 2681 | { |
| 2682 | struct i915_power_well *cmn = |
| 2683 | lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_BC); |
| 2684 | struct i915_power_well *disp2d = |
| 2685 | lookup_power_well(dev_priv, PUNIT_POWER_WELL_DISP2D); |
| 2686 | |
Daniel Vetter | 9c065a7 | 2014-09-30 10:56:38 +0200 | [diff] [blame] | 2687 | /* If the display might be already active skip this */ |
Ville Syrjälä | 5d93a6e | 2014-10-16 20:52:33 +0300 | [diff] [blame] | 2688 | if (cmn->ops->is_enabled(dev_priv, cmn) && |
| 2689 | disp2d->ops->is_enabled(dev_priv, disp2d) && |
Daniel Vetter | 9c065a7 | 2014-09-30 10:56:38 +0200 | [diff] [blame] | 2690 | I915_READ(DPIO_CTL) & DPIO_CMNRST) |
| 2691 | return; |
| 2692 | |
| 2693 | DRM_DEBUG_KMS("toggling display PHY side reset\n"); |
| 2694 | |
| 2695 | /* cmnlane needs DPLL registers */ |
| 2696 | disp2d->ops->enable(dev_priv, disp2d); |
| 2697 | |
| 2698 | /* |
| 2699 | * From VLV2A0_DP_eDP_HDMI_DPIO_driver_vbios_notes_11.docx: |
| 2700 | * Need to assert and de-assert PHY SB reset by gating the |
| 2701 | * common lane power, then un-gating it. |
| 2702 | * Simply ungating isn't enough to reset the PHY enough to get |
| 2703 | * ports and lanes running. |
| 2704 | */ |
| 2705 | cmn->ops->disable(dev_priv, cmn); |
| 2706 | } |
| 2707 | |
Daniel Vetter | e4e7684 | 2014-09-30 10:56:42 +0200 | [diff] [blame] | 2708 | /** |
| 2709 | * intel_power_domains_init_hw - initialize hardware power domain state |
| 2710 | * @dev_priv: i915 device instance |
Tvrtko Ursulin | 14bb2c1 | 2016-06-03 14:02:17 +0100 | [diff] [blame] | 2711 | * @resume: Called from resume code paths or not |
Daniel Vetter | e4e7684 | 2014-09-30 10:56:42 +0200 | [diff] [blame] | 2712 | * |
| 2713 | * This function initializes the hardware power domain state and enables all |
| 2714 | * power domains using intel_display_set_init_power(). |
| 2715 | */ |
Imre Deak | 73dfc22 | 2015-11-17 17:33:53 +0200 | [diff] [blame] | 2716 | void intel_power_domains_init_hw(struct drm_i915_private *dev_priv, bool resume) |
Daniel Vetter | 9c065a7 | 2014-09-30 10:56:38 +0200 | [diff] [blame] | 2717 | { |
Daniel Vetter | 9c065a7 | 2014-09-30 10:56:38 +0200 | [diff] [blame] | 2718 | struct i915_power_domains *power_domains = &dev_priv->power_domains; |
| 2719 | |
| 2720 | power_domains->initializing = true; |
| 2721 | |
Tvrtko Ursulin | 0853723 | 2016-10-13 11:03:02 +0100 | [diff] [blame] | 2722 | if (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv)) { |
Imre Deak | 73dfc22 | 2015-11-17 17:33:53 +0200 | [diff] [blame] | 2723 | skl_display_core_init(dev_priv, resume); |
Ander Conselvan de Oliveira | b817c44 | 2016-12-02 10:23:56 +0200 | [diff] [blame] | 2724 | } else if (IS_GEN9_LP(dev_priv)) { |
Imre Deak | d7d7c9e | 2016-04-01 16:02:42 +0300 | [diff] [blame] | 2725 | bxt_display_core_init(dev_priv, resume); |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 2726 | } else if (IS_CHERRYVIEW(dev_priv)) { |
Ville Syrjälä | 770effb | 2015-07-08 23:45:51 +0300 | [diff] [blame] | 2727 | mutex_lock(&power_domains->lock); |
Ville Syrjälä | 7072246 | 2015-04-10 18:21:28 +0300 | [diff] [blame] | 2728 | chv_phy_control_init(dev_priv); |
Ville Syrjälä | 770effb | 2015-07-08 23:45:51 +0300 | [diff] [blame] | 2729 | mutex_unlock(&power_domains->lock); |
Tvrtko Ursulin | 11a914c | 2016-10-13 11:03:08 +0100 | [diff] [blame] | 2730 | } else if (IS_VALLEYVIEW(dev_priv)) { |
Daniel Vetter | 9c065a7 | 2014-09-30 10:56:38 +0200 | [diff] [blame] | 2731 | mutex_lock(&power_domains->lock); |
| 2732 | vlv_cmnlane_wa(dev_priv); |
| 2733 | mutex_unlock(&power_domains->lock); |
| 2734 | } |
| 2735 | |
| 2736 | /* For now, we need the power well to be always enabled. */ |
| 2737 | intel_display_set_init_power(dev_priv, true); |
Imre Deak | d314cd4 | 2015-11-17 17:44:23 +0200 | [diff] [blame] | 2738 | /* Disable power support if the user asked so. */ |
| 2739 | if (!i915.disable_power_well) |
| 2740 | intel_display_power_get(dev_priv, POWER_DOMAIN_INIT); |
Imre Deak | 30eade1 | 2015-11-04 19:24:13 +0200 | [diff] [blame] | 2741 | intel_power_domains_sync_hw(dev_priv); |
Daniel Vetter | 9c065a7 | 2014-09-30 10:56:38 +0200 | [diff] [blame] | 2742 | power_domains->initializing = false; |
| 2743 | } |
| 2744 | |
Daniel Vetter | e4e7684 | 2014-09-30 10:56:42 +0200 | [diff] [blame] | 2745 | /** |
Imre Deak | 73dfc22 | 2015-11-17 17:33:53 +0200 | [diff] [blame] | 2746 | * intel_power_domains_suspend - suspend power domain state |
| 2747 | * @dev_priv: i915 device instance |
| 2748 | * |
| 2749 | * This function prepares the hardware power domain state before entering |
| 2750 | * system suspend. It must be paired with intel_power_domains_init_hw(). |
| 2751 | */ |
| 2752 | void intel_power_domains_suspend(struct drm_i915_private *dev_priv) |
| 2753 | { |
Imre Deak | d314cd4 | 2015-11-17 17:44:23 +0200 | [diff] [blame] | 2754 | /* |
| 2755 | * Even if power well support was disabled we still want to disable |
| 2756 | * power wells while we are system suspended. |
| 2757 | */ |
| 2758 | if (!i915.disable_power_well) |
| 2759 | intel_display_power_put(dev_priv, POWER_DOMAIN_INIT); |
Imre Deak | 2622d79 | 2016-02-29 22:49:02 +0200 | [diff] [blame] | 2760 | |
| 2761 | if (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv)) |
| 2762 | skl_display_core_uninit(dev_priv); |
Ander Conselvan de Oliveira | b817c44 | 2016-12-02 10:23:56 +0200 | [diff] [blame] | 2763 | else if (IS_GEN9_LP(dev_priv)) |
Imre Deak | d7d7c9e | 2016-04-01 16:02:42 +0300 | [diff] [blame] | 2764 | bxt_display_core_uninit(dev_priv); |
Imre Deak | 73dfc22 | 2015-11-17 17:33:53 +0200 | [diff] [blame] | 2765 | } |
| 2766 | |
| 2767 | /** |
Daniel Vetter | e4e7684 | 2014-09-30 10:56:42 +0200 | [diff] [blame] | 2768 | * intel_runtime_pm_get - grab a runtime pm reference |
| 2769 | * @dev_priv: i915 device instance |
| 2770 | * |
| 2771 | * This function grabs a device-level runtime pm reference (mostly used for GEM |
| 2772 | * code to ensure the GTT or GT is on) and ensures that it is powered up. |
| 2773 | * |
| 2774 | * Any runtime pm reference obtained by this function must have a symmetric |
| 2775 | * call to intel_runtime_pm_put() to release the reference again. |
| 2776 | */ |
Daniel Vetter | 9c065a7 | 2014-09-30 10:56:38 +0200 | [diff] [blame] | 2777 | void intel_runtime_pm_get(struct drm_i915_private *dev_priv) |
| 2778 | { |
David Weinehall | 52a05c3 | 2016-08-22 13:32:44 +0300 | [diff] [blame] | 2779 | struct pci_dev *pdev = dev_priv->drm.pdev; |
| 2780 | struct device *kdev = &pdev->dev; |
Daniel Vetter | 9c065a7 | 2014-09-30 10:56:38 +0200 | [diff] [blame] | 2781 | |
David Weinehall | c49d13e | 2016-08-22 13:32:42 +0300 | [diff] [blame] | 2782 | pm_runtime_get_sync(kdev); |
Imre Deak | 1f814da | 2015-12-16 02:52:19 +0200 | [diff] [blame] | 2783 | |
| 2784 | atomic_inc(&dev_priv->pm.wakeref_count); |
Imre Deak | c9b8846 | 2015-12-15 20:10:34 +0200 | [diff] [blame] | 2785 | assert_rpm_wakelock_held(dev_priv); |
Daniel Vetter | 9c065a7 | 2014-09-30 10:56:38 +0200 | [diff] [blame] | 2786 | } |
| 2787 | |
Daniel Vetter | e4e7684 | 2014-09-30 10:56:42 +0200 | [diff] [blame] | 2788 | /** |
Imre Deak | 0973128 | 2016-02-17 14:17:42 +0200 | [diff] [blame] | 2789 | * intel_runtime_pm_get_if_in_use - grab a runtime pm reference if device in use |
| 2790 | * @dev_priv: i915 device instance |
| 2791 | * |
| 2792 | * This function grabs a device-level runtime pm reference if the device is |
| 2793 | * already in use and ensures that it is powered up. |
| 2794 | * |
| 2795 | * Any runtime pm reference obtained by this function must have a symmetric |
| 2796 | * call to intel_runtime_pm_put() to release the reference again. |
| 2797 | */ |
| 2798 | bool intel_runtime_pm_get_if_in_use(struct drm_i915_private *dev_priv) |
| 2799 | { |
David Weinehall | 52a05c3 | 2016-08-22 13:32:44 +0300 | [diff] [blame] | 2800 | struct pci_dev *pdev = dev_priv->drm.pdev; |
| 2801 | struct device *kdev = &pdev->dev; |
Imre Deak | 0973128 | 2016-02-17 14:17:42 +0200 | [diff] [blame] | 2802 | |
Chris Wilson | 135dc79 | 2016-02-25 21:10:28 +0000 | [diff] [blame] | 2803 | if (IS_ENABLED(CONFIG_PM)) { |
David Weinehall | c49d13e | 2016-08-22 13:32:42 +0300 | [diff] [blame] | 2804 | int ret = pm_runtime_get_if_in_use(kdev); |
Imre Deak | 0973128 | 2016-02-17 14:17:42 +0200 | [diff] [blame] | 2805 | |
Chris Wilson | 135dc79 | 2016-02-25 21:10:28 +0000 | [diff] [blame] | 2806 | /* |
| 2807 | * In cases runtime PM is disabled by the RPM core and we get |
| 2808 | * an -EINVAL return value we are not supposed to call this |
| 2809 | * function, since the power state is undefined. This applies |
| 2810 | * atm to the late/early system suspend/resume handlers. |
| 2811 | */ |
| 2812 | WARN_ON_ONCE(ret < 0); |
| 2813 | if (ret <= 0) |
| 2814 | return false; |
| 2815 | } |
Imre Deak | 0973128 | 2016-02-17 14:17:42 +0200 | [diff] [blame] | 2816 | |
| 2817 | atomic_inc(&dev_priv->pm.wakeref_count); |
| 2818 | assert_rpm_wakelock_held(dev_priv); |
| 2819 | |
| 2820 | return true; |
| 2821 | } |
| 2822 | |
| 2823 | /** |
Daniel Vetter | e4e7684 | 2014-09-30 10:56:42 +0200 | [diff] [blame] | 2824 | * intel_runtime_pm_get_noresume - grab a runtime pm reference |
| 2825 | * @dev_priv: i915 device instance |
| 2826 | * |
| 2827 | * This function grabs a device-level runtime pm reference (mostly used for GEM |
| 2828 | * code to ensure the GTT or GT is on). |
| 2829 | * |
| 2830 | * It will _not_ power up the device but instead only check that it's powered |
| 2831 | * on. Therefore it is only valid to call this functions from contexts where |
| 2832 | * the device is known to be powered up and where trying to power it up would |
| 2833 | * result in hilarity and deadlocks. That pretty much means only the system |
| 2834 | * suspend/resume code where this is used to grab runtime pm references for |
| 2835 | * delayed setup down in work items. |
| 2836 | * |
| 2837 | * Any runtime pm reference obtained by this function must have a symmetric |
| 2838 | * call to intel_runtime_pm_put() to release the reference again. |
| 2839 | */ |
Daniel Vetter | 9c065a7 | 2014-09-30 10:56:38 +0200 | [diff] [blame] | 2840 | void intel_runtime_pm_get_noresume(struct drm_i915_private *dev_priv) |
| 2841 | { |
David Weinehall | 52a05c3 | 2016-08-22 13:32:44 +0300 | [diff] [blame] | 2842 | struct pci_dev *pdev = dev_priv->drm.pdev; |
| 2843 | struct device *kdev = &pdev->dev; |
Daniel Vetter | 9c065a7 | 2014-09-30 10:56:38 +0200 | [diff] [blame] | 2844 | |
Imre Deak | c9b8846 | 2015-12-15 20:10:34 +0200 | [diff] [blame] | 2845 | assert_rpm_wakelock_held(dev_priv); |
David Weinehall | c49d13e | 2016-08-22 13:32:42 +0300 | [diff] [blame] | 2846 | pm_runtime_get_noresume(kdev); |
Imre Deak | 1f814da | 2015-12-16 02:52:19 +0200 | [diff] [blame] | 2847 | |
| 2848 | atomic_inc(&dev_priv->pm.wakeref_count); |
Daniel Vetter | 9c065a7 | 2014-09-30 10:56:38 +0200 | [diff] [blame] | 2849 | } |
| 2850 | |
Daniel Vetter | e4e7684 | 2014-09-30 10:56:42 +0200 | [diff] [blame] | 2851 | /** |
| 2852 | * intel_runtime_pm_put - release a runtime pm reference |
| 2853 | * @dev_priv: i915 device instance |
| 2854 | * |
| 2855 | * This function drops the device-level runtime pm reference obtained by |
| 2856 | * intel_runtime_pm_get() and might power down the corresponding |
| 2857 | * hardware block right away if this is the last reference. |
| 2858 | */ |
Daniel Vetter | 9c065a7 | 2014-09-30 10:56:38 +0200 | [diff] [blame] | 2859 | void intel_runtime_pm_put(struct drm_i915_private *dev_priv) |
| 2860 | { |
David Weinehall | 52a05c3 | 2016-08-22 13:32:44 +0300 | [diff] [blame] | 2861 | struct pci_dev *pdev = dev_priv->drm.pdev; |
| 2862 | struct device *kdev = &pdev->dev; |
Daniel Vetter | 9c065a7 | 2014-09-30 10:56:38 +0200 | [diff] [blame] | 2863 | |
Imre Deak | 542db3c | 2015-12-15 20:10:36 +0200 | [diff] [blame] | 2864 | assert_rpm_wakelock_held(dev_priv); |
Chris Wilson | 2eedfc7 | 2016-10-24 13:42:17 +0100 | [diff] [blame] | 2865 | atomic_dec(&dev_priv->pm.wakeref_count); |
Imre Deak | 1f814da | 2015-12-16 02:52:19 +0200 | [diff] [blame] | 2866 | |
David Weinehall | c49d13e | 2016-08-22 13:32:42 +0300 | [diff] [blame] | 2867 | pm_runtime_mark_last_busy(kdev); |
| 2868 | pm_runtime_put_autosuspend(kdev); |
Daniel Vetter | 9c065a7 | 2014-09-30 10:56:38 +0200 | [diff] [blame] | 2869 | } |
| 2870 | |
Daniel Vetter | e4e7684 | 2014-09-30 10:56:42 +0200 | [diff] [blame] | 2871 | /** |
| 2872 | * intel_runtime_pm_enable - enable runtime pm |
| 2873 | * @dev_priv: i915 device instance |
| 2874 | * |
| 2875 | * This function enables runtime pm at the end of the driver load sequence. |
| 2876 | * |
| 2877 | * Note that this function does currently not enable runtime pm for the |
| 2878 | * subordinate display power domains. That is only done on the first modeset |
| 2879 | * using intel_display_set_init_power(). |
| 2880 | */ |
Daniel Vetter | f458ebb | 2014-09-30 10:56:39 +0200 | [diff] [blame] | 2881 | void intel_runtime_pm_enable(struct drm_i915_private *dev_priv) |
Daniel Vetter | 9c065a7 | 2014-09-30 10:56:38 +0200 | [diff] [blame] | 2882 | { |
David Weinehall | 52a05c3 | 2016-08-22 13:32:44 +0300 | [diff] [blame] | 2883 | struct pci_dev *pdev = dev_priv->drm.pdev; |
David Weinehall | 52a05c3 | 2016-08-22 13:32:44 +0300 | [diff] [blame] | 2884 | struct device *kdev = &pdev->dev; |
Daniel Vetter | 9c065a7 | 2014-09-30 10:56:38 +0200 | [diff] [blame] | 2885 | |
David Weinehall | c49d13e | 2016-08-22 13:32:42 +0300 | [diff] [blame] | 2886 | pm_runtime_set_autosuspend_delay(kdev, 10000); /* 10s */ |
| 2887 | pm_runtime_mark_last_busy(kdev); |
Imre Deak | cbc68dc | 2015-12-17 19:04:33 +0200 | [diff] [blame] | 2888 | |
Imre Deak | 25b181b | 2015-12-17 13:44:56 +0200 | [diff] [blame] | 2889 | /* |
| 2890 | * Take a permanent reference to disable the RPM functionality and drop |
| 2891 | * it only when unloading the driver. Use the low level get/put helpers, |
| 2892 | * so the driver's own RPM reference tracking asserts also work on |
| 2893 | * platforms without RPM support. |
| 2894 | */ |
Tvrtko Ursulin | 6772ffe | 2016-10-13 11:02:55 +0100 | [diff] [blame] | 2895 | if (!HAS_RUNTIME_PM(dev_priv)) { |
David Weinehall | c49d13e | 2016-08-22 13:32:42 +0300 | [diff] [blame] | 2896 | pm_runtime_dont_use_autosuspend(kdev); |
| 2897 | pm_runtime_get_sync(kdev); |
Imre Deak | cbc68dc | 2015-12-17 19:04:33 +0200 | [diff] [blame] | 2898 | } else { |
David Weinehall | c49d13e | 2016-08-22 13:32:42 +0300 | [diff] [blame] | 2899 | pm_runtime_use_autosuspend(kdev); |
Imre Deak | cbc68dc | 2015-12-17 19:04:33 +0200 | [diff] [blame] | 2900 | } |
Daniel Vetter | 9c065a7 | 2014-09-30 10:56:38 +0200 | [diff] [blame] | 2901 | |
Imre Deak | aabee1b | 2015-12-15 20:10:29 +0200 | [diff] [blame] | 2902 | /* |
| 2903 | * The core calls the driver load handler with an RPM reference held. |
| 2904 | * We drop that here and will reacquire it during unloading in |
| 2905 | * intel_power_domains_fini(). |
| 2906 | */ |
David Weinehall | c49d13e | 2016-08-22 13:32:42 +0300 | [diff] [blame] | 2907 | pm_runtime_put_autosuspend(kdev); |
Daniel Vetter | 9c065a7 | 2014-09-30 10:56:38 +0200 | [diff] [blame] | 2908 | } |