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