Jesse Barnes | 317c35d | 2008-08-25 15:11:06 -0700 | [diff] [blame] | 1 | /* |
| 2 | * |
| 3 | * Copyright 2008 (c) Intel Corporation |
| 4 | * Jesse Barnes <jbarnes@virtuousgeek.org> |
| 5 | * |
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 7 | * copy of this software and associated documentation files (the |
| 8 | * "Software"), to deal in the Software without restriction, including |
| 9 | * without limitation the rights to use, copy, modify, merge, publish, |
| 10 | * distribute, sub license, and/or sell copies of the Software, and to |
| 11 | * permit persons to whom the Software is furnished to do so, subject to |
| 12 | * the following conditions: |
| 13 | * |
| 14 | * The above copyright notice and this permission notice (including the |
| 15 | * next paragraph) shall be included in all copies or substantial portions |
| 16 | * of the Software. |
| 17 | * |
| 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 19 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 20 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. |
| 21 | * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR |
| 22 | * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
| 23 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
| 24 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 25 | */ |
| 26 | |
David Howells | 760285e | 2012-10-02 18:01:07 +0100 | [diff] [blame] | 27 | #include <drm/drmP.h> |
| 28 | #include <drm/i915_drm.h> |
Eric Anholt | f0217c4 | 2009-12-01 11:56:30 -0800 | [diff] [blame] | 29 | #include "intel_drv.h" |
Eugeni Dodonov | 5e5b7fa | 2012-01-07 23:40:34 -0200 | [diff] [blame] | 30 | #include "i915_reg.h" |
Jesse Barnes | 317c35d | 2008-08-25 15:11:06 -0700 | [diff] [blame] | 31 | |
Keith Packard | d70bed1 | 2011-06-29 00:30:34 -0700 | [diff] [blame] | 32 | static void i915_save_display(struct drm_device *dev) |
Zhao Yakui | fccdaba | 2009-07-08 14:13:14 +0800 | [diff] [blame] | 33 | { |
| 34 | struct drm_i915_private *dev_priv = dev->dev_private; |
Zhao Yakui | fccdaba | 2009-07-08 14:13:14 +0800 | [diff] [blame] | 35 | |
| 36 | /* Display arbitration control */ |
Paulo Zanoni | 8de0add | 2013-01-18 18:29:03 -0200 | [diff] [blame] | 37 | if (INTEL_INFO(dev)->gen <= 4) |
| 38 | dev_priv->regfile.saveDSPARB = I915_READ(DSPARB); |
Zhao Yakui | fccdaba | 2009-07-08 14:13:14 +0800 | [diff] [blame] | 39 | |
Jesse Barnes | 317c35d | 2008-08-25 15:11:06 -0700 | [diff] [blame] | 40 | /* LVDS state */ |
Jani Nikula | 1c5bb42 | 2014-11-12 17:01:10 +0200 | [diff] [blame] | 41 | if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)) |
| 42 | dev_priv->regfile.saveLVDS = I915_READ(PCH_LVDS); |
| 43 | else if (INTEL_INFO(dev)->gen <= 4 && IS_MOBILE(dev) && !IS_I830(dev)) |
| 44 | dev_priv->regfile.saveLVDS = I915_READ(LVDS); |
| 45 | |
| 46 | /* Panel power sequencer */ |
Chris Wilson | 90eb77b | 2010-08-14 14:41:23 +0100 | [diff] [blame] | 47 | if (HAS_PCH_SPLIT(dev)) { |
Daniel Vetter | f4c956a | 2012-11-02 19:55:02 +0100 | [diff] [blame] | 48 | dev_priv->regfile.savePP_CONTROL = I915_READ(PCH_PP_CONTROL); |
Daniel Vetter | f4c956a | 2012-11-02 19:55:02 +0100 | [diff] [blame] | 49 | dev_priv->regfile.savePP_ON_DELAYS = I915_READ(PCH_PP_ON_DELAYS); |
| 50 | dev_priv->regfile.savePP_OFF_DELAYS = I915_READ(PCH_PP_OFF_DELAYS); |
| 51 | dev_priv->regfile.savePP_DIVISOR = I915_READ(PCH_PP_DIVISOR); |
Jani Nikula | c7e2073 | 2014-11-11 16:48:03 +0200 | [diff] [blame] | 52 | } else if (!IS_VALLEYVIEW(dev)) { |
Jani Nikula | 1c5bb42 | 2014-11-12 17:01:10 +0200 | [diff] [blame] | 53 | dev_priv->regfile.savePP_CONTROL = I915_READ(PP_CONTROL); |
Daniel Vetter | f4c956a | 2012-11-02 19:55:02 +0100 | [diff] [blame] | 54 | dev_priv->regfile.savePP_ON_DELAYS = I915_READ(PP_ON_DELAYS); |
| 55 | dev_priv->regfile.savePP_OFF_DELAYS = I915_READ(PP_OFF_DELAYS); |
| 56 | dev_priv->regfile.savePP_DIVISOR = I915_READ(PP_DIVISOR); |
Zhenyu Wang | 4204878 | 2009-10-21 15:27:01 +0800 | [diff] [blame] | 57 | } |
Jesse Barnes | 317c35d | 2008-08-25 15:11:06 -0700 | [diff] [blame] | 58 | |
Ville Syrjälä | 768cf7f | 2014-01-23 16:49:15 +0200 | [diff] [blame] | 59 | /* save FBC interval */ |
| 60 | if (HAS_FBC(dev) && INTEL_INFO(dev)->gen <= 4 && !IS_G4X(dev)) |
| 61 | dev_priv->regfile.saveFBC_CONTROL = I915_READ(FBC_CONTROL); |
Jesse Barnes | 317c35d | 2008-08-25 15:11:06 -0700 | [diff] [blame] | 62 | } |
| 63 | |
Keith Packard | d70bed1 | 2011-06-29 00:30:34 -0700 | [diff] [blame] | 64 | static void i915_restore_display(struct drm_device *dev) |
Jesse Barnes | 317c35d | 2008-08-25 15:11:06 -0700 | [diff] [blame] | 65 | { |
| 66 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | 2ec9066 | 2013-02-19 12:11:38 -0800 | [diff] [blame] | 67 | u32 mask = 0xffffffff; |
Peng Li | 461cba2 | 2008-11-18 12:39:02 +0800 | [diff] [blame] | 68 | |
Keith Packard | 881ee98 | 2008-11-02 23:08:44 -0800 | [diff] [blame] | 69 | /* Display arbitration */ |
Paulo Zanoni | 8de0add | 2013-01-18 18:29:03 -0200 | [diff] [blame] | 70 | if (INTEL_INFO(dev)->gen <= 4) |
| 71 | I915_WRITE(DSPARB, dev_priv->regfile.saveDSPARB); |
Jesse Barnes | 317c35d | 2008-08-25 15:11:06 -0700 | [diff] [blame] | 72 | |
Daniel Vetter | 8634bd4 | 2015-02-23 12:03:30 +0100 | [diff] [blame] | 73 | mask = ~LVDS_PORT_EN; |
Jesse Barnes | 2ec9066 | 2013-02-19 12:11:38 -0800 | [diff] [blame] | 74 | |
Jani Nikula | 1c5bb42 | 2014-11-12 17:01:10 +0200 | [diff] [blame] | 75 | /* LVDS state */ |
Paulo Zanoni | 4deb88a | 2013-03-06 20:03:20 -0300 | [diff] [blame] | 76 | if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)) |
Jesse Barnes | 2ec9066 | 2013-02-19 12:11:38 -0800 | [diff] [blame] | 77 | I915_WRITE(PCH_LVDS, dev_priv->regfile.saveLVDS & mask); |
Paulo Zanoni | 4deb88a | 2013-03-06 20:03:20 -0300 | [diff] [blame] | 78 | else if (INTEL_INFO(dev)->gen <= 4 && IS_MOBILE(dev) && !IS_I830(dev)) |
Jesse Barnes | 2ec9066 | 2013-02-19 12:11:38 -0800 | [diff] [blame] | 79 | I915_WRITE(LVDS, dev_priv->regfile.saveLVDS & mask); |
Zhenyu Wang | 4204878 | 2009-10-21 15:27:01 +0800 | [diff] [blame] | 80 | |
Jani Nikula | 1c5bb42 | 2014-11-12 17:01:10 +0200 | [diff] [blame] | 81 | /* Panel power sequencer */ |
Chris Wilson | 90eb77b | 2010-08-14 14:41:23 +0100 | [diff] [blame] | 82 | if (HAS_PCH_SPLIT(dev)) { |
Daniel Vetter | f4c956a | 2012-11-02 19:55:02 +0100 | [diff] [blame] | 83 | I915_WRITE(PCH_PP_ON_DELAYS, dev_priv->regfile.savePP_ON_DELAYS); |
| 84 | I915_WRITE(PCH_PP_OFF_DELAYS, dev_priv->regfile.savePP_OFF_DELAYS); |
| 85 | I915_WRITE(PCH_PP_DIVISOR, dev_priv->regfile.savePP_DIVISOR); |
| 86 | I915_WRITE(PCH_PP_CONTROL, dev_priv->regfile.savePP_CONTROL); |
Jani Nikula | b0cd324 | 2014-11-12 16:25:43 +0200 | [diff] [blame] | 87 | } else if (!IS_VALLEYVIEW(dev)) { |
Daniel Vetter | f4c956a | 2012-11-02 19:55:02 +0100 | [diff] [blame] | 88 | I915_WRITE(PP_ON_DELAYS, dev_priv->regfile.savePP_ON_DELAYS); |
| 89 | I915_WRITE(PP_OFF_DELAYS, dev_priv->regfile.savePP_OFF_DELAYS); |
| 90 | I915_WRITE(PP_DIVISOR, dev_priv->regfile.savePP_DIVISOR); |
| 91 | I915_WRITE(PP_CONTROL, dev_priv->regfile.savePP_CONTROL); |
Zhenyu Wang | 4204878 | 2009-10-21 15:27:01 +0800 | [diff] [blame] | 92 | } |
Jesse Barnes | 317c35d | 2008-08-25 15:11:06 -0700 | [diff] [blame] | 93 | |
Zhao Yakui | a2c459e | 2010-03-19 17:05:10 +0800 | [diff] [blame] | 94 | /* only restore FBC info on the platform that supports FBC*/ |
Paulo Zanoni | 7733b49 | 2015-07-07 15:26:04 -0300 | [diff] [blame] | 95 | intel_fbc_disable(dev_priv); |
Ville Syrjälä | 768cf7f | 2014-01-23 16:49:15 +0200 | [diff] [blame] | 96 | |
| 97 | /* restore FBC interval */ |
| 98 | if (HAS_FBC(dev) && INTEL_INFO(dev)->gen <= 4 && !IS_G4X(dev)) |
| 99 | I915_WRITE(FBC_CONTROL, dev_priv->regfile.saveFBC_CONTROL); |
Daniel Vetter | a65e827 | 2013-01-25 17:53:22 +0100 | [diff] [blame] | 100 | |
Daniel Vetter | 8634bd4 | 2015-02-23 12:03:30 +0100 | [diff] [blame] | 101 | i915_redisable_vga(dev); |
Ben Gamari | 1341d65 | 2009-09-14 17:48:42 -0400 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | int i915_save_state(struct drm_device *dev) |
| 105 | { |
| 106 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 107 | int i; |
| 108 | |
Keith Packard | d70bed1 | 2011-06-29 00:30:34 -0700 | [diff] [blame] | 109 | mutex_lock(&dev->struct_mutex); |
| 110 | |
Ben Gamari | 1341d65 | 2009-09-14 17:48:42 -0400 | [diff] [blame] | 111 | i915_save_display(dev); |
| 112 | |
Jesse Barnes | 9f49c37 | 2014-12-10 12:16:05 -0800 | [diff] [blame] | 113 | if (IS_GEN4(dev)) |
| 114 | pci_read_config_word(dev->pdev, GCDGMBUS, |
| 115 | &dev_priv->regfile.saveGCDGMBUS); |
| 116 | |
Ben Gamari | 1341d65 | 2009-09-14 17:48:42 -0400 | [diff] [blame] | 117 | /* Cache mode state */ |
Jesse Barnes | e8cde23 | 2013-10-11 12:09:29 -0700 | [diff] [blame] | 118 | if (INTEL_INFO(dev)->gen < 7) |
| 119 | dev_priv->regfile.saveCACHE_MODE_0 = I915_READ(CACHE_MODE_0); |
Ben Gamari | 1341d65 | 2009-09-14 17:48:42 -0400 | [diff] [blame] | 120 | |
| 121 | /* Memory Arbitration state */ |
Daniel Vetter | f4c956a | 2012-11-02 19:55:02 +0100 | [diff] [blame] | 122 | dev_priv->regfile.saveMI_ARB_STATE = I915_READ(MI_ARB_STATE); |
Ben Gamari | 1341d65 | 2009-09-14 17:48:42 -0400 | [diff] [blame] | 123 | |
| 124 | /* Scratch space */ |
Ville Syrjälä | 85fa792 | 2015-09-18 20:03:43 +0300 | [diff] [blame] | 125 | if (IS_GEN2(dev_priv) && IS_MOBILE(dev_priv)) { |
| 126 | for (i = 0; i < 7; i++) { |
| 127 | dev_priv->regfile.saveSWF0[i] = I915_READ(SWF0(i)); |
| 128 | dev_priv->regfile.saveSWF1[i] = I915_READ(SWF1(i)); |
| 129 | } |
| 130 | for (i = 0; i < 3; i++) |
| 131 | dev_priv->regfile.saveSWF3[i] = I915_READ(SWF3(i)); |
| 132 | } else if (IS_GEN2(dev_priv)) { |
| 133 | for (i = 0; i < 7; i++) |
| 134 | dev_priv->regfile.saveSWF1[i] = I915_READ(SWF1(i)); |
| 135 | } else if (HAS_GMCH_DISPLAY(dev_priv)) { |
| 136 | for (i = 0; i < 16; i++) { |
| 137 | dev_priv->regfile.saveSWF0[i] = I915_READ(SWF0(i)); |
| 138 | dev_priv->regfile.saveSWF1[i] = I915_READ(SWF1(i)); |
| 139 | } |
| 140 | for (i = 0; i < 3; i++) |
| 141 | dev_priv->regfile.saveSWF3[i] = I915_READ(SWF3(i)); |
Ben Gamari | 1341d65 | 2009-09-14 17:48:42 -0400 | [diff] [blame] | 142 | } |
Ben Gamari | 1341d65 | 2009-09-14 17:48:42 -0400 | [diff] [blame] | 143 | |
Keith Packard | d70bed1 | 2011-06-29 00:30:34 -0700 | [diff] [blame] | 144 | mutex_unlock(&dev->struct_mutex); |
| 145 | |
Ben Gamari | 1341d65 | 2009-09-14 17:48:42 -0400 | [diff] [blame] | 146 | return 0; |
| 147 | } |
| 148 | |
| 149 | int i915_restore_state(struct drm_device *dev) |
| 150 | { |
| 151 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 152 | int i; |
| 153 | |
Keith Packard | d70bed1 | 2011-06-29 00:30:34 -0700 | [diff] [blame] | 154 | mutex_lock(&dev->struct_mutex); |
| 155 | |
Chris Wilson | 19b2dbd | 2013-06-12 10:15:12 +0100 | [diff] [blame] | 156 | i915_gem_restore_fences(dev); |
Jesse Barnes | 9f49c37 | 2014-12-10 12:16:05 -0800 | [diff] [blame] | 157 | |
| 158 | if (IS_GEN4(dev)) |
| 159 | pci_write_config_word(dev->pdev, GCDGMBUS, |
| 160 | dev_priv->regfile.saveGCDGMBUS); |
Ben Gamari | 1341d65 | 2009-09-14 17:48:42 -0400 | [diff] [blame] | 161 | i915_restore_display(dev); |
| 162 | |
Jesse Barnes | 317c35d | 2008-08-25 15:11:06 -0700 | [diff] [blame] | 163 | /* Cache mode state */ |
Jesse Barnes | e8cde23 | 2013-10-11 12:09:29 -0700 | [diff] [blame] | 164 | if (INTEL_INFO(dev)->gen < 7) |
| 165 | I915_WRITE(CACHE_MODE_0, dev_priv->regfile.saveCACHE_MODE_0 | |
| 166 | 0xffff0000); |
Jesse Barnes | 317c35d | 2008-08-25 15:11:06 -0700 | [diff] [blame] | 167 | |
| 168 | /* Memory arbitration state */ |
Daniel Vetter | f4c956a | 2012-11-02 19:55:02 +0100 | [diff] [blame] | 169 | I915_WRITE(MI_ARB_STATE, dev_priv->regfile.saveMI_ARB_STATE | 0xffff0000); |
Jesse Barnes | 317c35d | 2008-08-25 15:11:06 -0700 | [diff] [blame] | 170 | |
Ville Syrjälä | 85fa792 | 2015-09-18 20:03:43 +0300 | [diff] [blame] | 171 | /* Scratch space */ |
| 172 | if (IS_GEN2(dev_priv) && IS_MOBILE(dev_priv)) { |
| 173 | for (i = 0; i < 7; i++) { |
| 174 | I915_WRITE(SWF0(i), dev_priv->regfile.saveSWF0[i]); |
| 175 | I915_WRITE(SWF1(i), dev_priv->regfile.saveSWF1[i]); |
| 176 | } |
| 177 | for (i = 0; i < 3; i++) |
| 178 | I915_WRITE(SWF3(i), dev_priv->regfile.saveSWF3[i]); |
| 179 | } else if (IS_GEN2(dev_priv)) { |
| 180 | for (i = 0; i < 7; i++) |
| 181 | I915_WRITE(SWF1(i), dev_priv->regfile.saveSWF1[i]); |
| 182 | } else if (HAS_GMCH_DISPLAY(dev_priv)) { |
| 183 | for (i = 0; i < 16; i++) { |
| 184 | I915_WRITE(SWF0(i), dev_priv->regfile.saveSWF0[i]); |
| 185 | I915_WRITE(SWF1(i), dev_priv->regfile.saveSWF1[i]); |
| 186 | } |
| 187 | for (i = 0; i < 3; i++) |
| 188 | I915_WRITE(SWF3(i), dev_priv->regfile.saveSWF3[i]); |
Jesse Barnes | 317c35d | 2008-08-25 15:11:06 -0700 | [diff] [blame] | 189 | } |
Jesse Barnes | 317c35d | 2008-08-25 15:11:06 -0700 | [diff] [blame] | 190 | |
Keith Packard | d70bed1 | 2011-06-29 00:30:34 -0700 | [diff] [blame] | 191 | mutex_unlock(&dev->struct_mutex); |
| 192 | |
Chris Wilson | f899fc6 | 2010-07-20 15:44:45 -0700 | [diff] [blame] | 193 | intel_i2c_reset(dev); |
Eric Anholt | f0217c4 | 2009-12-01 11:56:30 -0800 | [diff] [blame] | 194 | |
Jesse Barnes | 317c35d | 2008-08-25 15:11:06 -0700 | [diff] [blame] | 195 | return 0; |
| 196 | } |