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 | |
Jesse Barnes | 317c35d | 2008-08-25 15:11:06 -0700 | [diff] [blame] | 32 | static u8 i915_read_indexed(struct drm_device *dev, u16 index_port, u16 data_port, u8 reg) |
| 33 | { |
| 34 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 35 | |
| 36 | I915_WRITE8(index_port, reg); |
| 37 | return I915_READ8(data_port); |
| 38 | } |
| 39 | |
| 40 | static u8 i915_read_ar(struct drm_device *dev, u16 st01, u8 reg, u16 palette_enable) |
| 41 | { |
| 42 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 43 | |
| 44 | I915_READ8(st01); |
| 45 | I915_WRITE8(VGA_AR_INDEX, palette_enable | reg); |
| 46 | return I915_READ8(VGA_AR_DATA_READ); |
| 47 | } |
| 48 | |
| 49 | static void i915_write_ar(struct drm_device *dev, u16 st01, u8 reg, u8 val, u16 palette_enable) |
| 50 | { |
| 51 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 52 | |
| 53 | I915_READ8(st01); |
| 54 | I915_WRITE8(VGA_AR_INDEX, palette_enable | reg); |
| 55 | I915_WRITE8(VGA_AR_DATA_WRITE, val); |
| 56 | } |
| 57 | |
| 58 | static void i915_write_indexed(struct drm_device *dev, u16 index_port, u16 data_port, u8 reg, u8 val) |
| 59 | { |
| 60 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 61 | |
| 62 | I915_WRITE8(index_port, reg); |
| 63 | I915_WRITE8(data_port, val); |
| 64 | } |
| 65 | |
| 66 | static void i915_save_vga(struct drm_device *dev) |
| 67 | { |
| 68 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 69 | int i; |
| 70 | u16 cr_index, cr_data, st01; |
| 71 | |
Daniel Vetter | 44cec74 | 2013-01-25 17:53:21 +0100 | [diff] [blame] | 72 | /* VGA state */ |
| 73 | dev_priv->regfile.saveVGA0 = I915_READ(VGA0); |
| 74 | dev_priv->regfile.saveVGA1 = I915_READ(VGA1); |
| 75 | dev_priv->regfile.saveVGA_PD = I915_READ(VGA_PD); |
Ville Syrjälä | 766aa1c | 2013-01-25 21:44:46 +0200 | [diff] [blame] | 76 | dev_priv->regfile.saveVGACNTRL = I915_READ(i915_vgacntrl_reg(dev)); |
Daniel Vetter | 44cec74 | 2013-01-25 17:53:21 +0100 | [diff] [blame] | 77 | |
Jesse Barnes | 317c35d | 2008-08-25 15:11:06 -0700 | [diff] [blame] | 78 | /* VGA color palette registers */ |
Daniel Vetter | f4c956a | 2012-11-02 19:55:02 +0100 | [diff] [blame] | 79 | dev_priv->regfile.saveDACMASK = I915_READ8(VGA_DACMASK); |
Jesse Barnes | 317c35d | 2008-08-25 15:11:06 -0700 | [diff] [blame] | 80 | |
| 81 | /* MSR bits */ |
Daniel Vetter | f4c956a | 2012-11-02 19:55:02 +0100 | [diff] [blame] | 82 | dev_priv->regfile.saveMSR = I915_READ8(VGA_MSR_READ); |
| 83 | if (dev_priv->regfile.saveMSR & VGA_MSR_CGA_MODE) { |
Jesse Barnes | 317c35d | 2008-08-25 15:11:06 -0700 | [diff] [blame] | 84 | cr_index = VGA_CR_INDEX_CGA; |
| 85 | cr_data = VGA_CR_DATA_CGA; |
| 86 | st01 = VGA_ST01_CGA; |
| 87 | } else { |
| 88 | cr_index = VGA_CR_INDEX_MDA; |
| 89 | cr_data = VGA_CR_DATA_MDA; |
| 90 | st01 = VGA_ST01_MDA; |
| 91 | } |
| 92 | |
| 93 | /* CRT controller regs */ |
| 94 | i915_write_indexed(dev, cr_index, cr_data, 0x11, |
| 95 | i915_read_indexed(dev, cr_index, cr_data, 0x11) & |
| 96 | (~0x80)); |
| 97 | for (i = 0; i <= 0x24; i++) |
Daniel Vetter | f4c956a | 2012-11-02 19:55:02 +0100 | [diff] [blame] | 98 | dev_priv->regfile.saveCR[i] = |
Jesse Barnes | 317c35d | 2008-08-25 15:11:06 -0700 | [diff] [blame] | 99 | i915_read_indexed(dev, cr_index, cr_data, i); |
| 100 | /* Make sure we don't turn off CR group 0 writes */ |
Daniel Vetter | f4c956a | 2012-11-02 19:55:02 +0100 | [diff] [blame] | 101 | dev_priv->regfile.saveCR[0x11] &= ~0x80; |
Jesse Barnes | 317c35d | 2008-08-25 15:11:06 -0700 | [diff] [blame] | 102 | |
| 103 | /* Attribute controller registers */ |
| 104 | I915_READ8(st01); |
Daniel Vetter | f4c956a | 2012-11-02 19:55:02 +0100 | [diff] [blame] | 105 | dev_priv->regfile.saveAR_INDEX = I915_READ8(VGA_AR_INDEX); |
Jesse Barnes | 317c35d | 2008-08-25 15:11:06 -0700 | [diff] [blame] | 106 | for (i = 0; i <= 0x14; i++) |
Daniel Vetter | f4c956a | 2012-11-02 19:55:02 +0100 | [diff] [blame] | 107 | dev_priv->regfile.saveAR[i] = i915_read_ar(dev, st01, i, 0); |
Jesse Barnes | 317c35d | 2008-08-25 15:11:06 -0700 | [diff] [blame] | 108 | I915_READ8(st01); |
Daniel Vetter | f4c956a | 2012-11-02 19:55:02 +0100 | [diff] [blame] | 109 | I915_WRITE8(VGA_AR_INDEX, dev_priv->regfile.saveAR_INDEX); |
Jesse Barnes | 317c35d | 2008-08-25 15:11:06 -0700 | [diff] [blame] | 110 | I915_READ8(st01); |
| 111 | |
| 112 | /* Graphics controller registers */ |
| 113 | for (i = 0; i < 9; i++) |
Daniel Vetter | f4c956a | 2012-11-02 19:55:02 +0100 | [diff] [blame] | 114 | dev_priv->regfile.saveGR[i] = |
Jesse Barnes | 317c35d | 2008-08-25 15:11:06 -0700 | [diff] [blame] | 115 | i915_read_indexed(dev, VGA_GR_INDEX, VGA_GR_DATA, i); |
| 116 | |
Daniel Vetter | f4c956a | 2012-11-02 19:55:02 +0100 | [diff] [blame] | 117 | dev_priv->regfile.saveGR[0x10] = |
Jesse Barnes | 317c35d | 2008-08-25 15:11:06 -0700 | [diff] [blame] | 118 | i915_read_indexed(dev, VGA_GR_INDEX, VGA_GR_DATA, 0x10); |
Daniel Vetter | f4c956a | 2012-11-02 19:55:02 +0100 | [diff] [blame] | 119 | dev_priv->regfile.saveGR[0x11] = |
Jesse Barnes | 317c35d | 2008-08-25 15:11:06 -0700 | [diff] [blame] | 120 | i915_read_indexed(dev, VGA_GR_INDEX, VGA_GR_DATA, 0x11); |
Daniel Vetter | f4c956a | 2012-11-02 19:55:02 +0100 | [diff] [blame] | 121 | dev_priv->regfile.saveGR[0x18] = |
Jesse Barnes | 317c35d | 2008-08-25 15:11:06 -0700 | [diff] [blame] | 122 | i915_read_indexed(dev, VGA_GR_INDEX, VGA_GR_DATA, 0x18); |
| 123 | |
| 124 | /* Sequencer registers */ |
| 125 | for (i = 0; i < 8; i++) |
Daniel Vetter | f4c956a | 2012-11-02 19:55:02 +0100 | [diff] [blame] | 126 | dev_priv->regfile.saveSR[i] = |
Jesse Barnes | 317c35d | 2008-08-25 15:11:06 -0700 | [diff] [blame] | 127 | i915_read_indexed(dev, VGA_SR_INDEX, VGA_SR_DATA, i); |
| 128 | } |
| 129 | |
| 130 | static void i915_restore_vga(struct drm_device *dev) |
| 131 | { |
| 132 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 133 | int i; |
| 134 | u16 cr_index, cr_data, st01; |
| 135 | |
Daniel Vetter | 44cec74 | 2013-01-25 17:53:21 +0100 | [diff] [blame] | 136 | /* VGA state */ |
Ville Syrjälä | 766aa1c | 2013-01-25 21:44:46 +0200 | [diff] [blame] | 137 | I915_WRITE(i915_vgacntrl_reg(dev), dev_priv->regfile.saveVGACNTRL); |
Daniel Vetter | 44cec74 | 2013-01-25 17:53:21 +0100 | [diff] [blame] | 138 | |
| 139 | I915_WRITE(VGA0, dev_priv->regfile.saveVGA0); |
| 140 | I915_WRITE(VGA1, dev_priv->regfile.saveVGA1); |
| 141 | I915_WRITE(VGA_PD, dev_priv->regfile.saveVGA_PD); |
| 142 | POSTING_READ(VGA_PD); |
| 143 | udelay(150); |
| 144 | |
Jesse Barnes | 317c35d | 2008-08-25 15:11:06 -0700 | [diff] [blame] | 145 | /* MSR bits */ |
Daniel Vetter | f4c956a | 2012-11-02 19:55:02 +0100 | [diff] [blame] | 146 | I915_WRITE8(VGA_MSR_WRITE, dev_priv->regfile.saveMSR); |
| 147 | if (dev_priv->regfile.saveMSR & VGA_MSR_CGA_MODE) { |
Jesse Barnes | 317c35d | 2008-08-25 15:11:06 -0700 | [diff] [blame] | 148 | cr_index = VGA_CR_INDEX_CGA; |
| 149 | cr_data = VGA_CR_DATA_CGA; |
| 150 | st01 = VGA_ST01_CGA; |
| 151 | } else { |
| 152 | cr_index = VGA_CR_INDEX_MDA; |
| 153 | cr_data = VGA_CR_DATA_MDA; |
| 154 | st01 = VGA_ST01_MDA; |
| 155 | } |
| 156 | |
| 157 | /* Sequencer registers, don't write SR07 */ |
| 158 | for (i = 0; i < 7; i++) |
| 159 | i915_write_indexed(dev, VGA_SR_INDEX, VGA_SR_DATA, i, |
Daniel Vetter | f4c956a | 2012-11-02 19:55:02 +0100 | [diff] [blame] | 160 | dev_priv->regfile.saveSR[i]); |
Jesse Barnes | 317c35d | 2008-08-25 15:11:06 -0700 | [diff] [blame] | 161 | |
| 162 | /* CRT controller regs */ |
| 163 | /* Enable CR group 0 writes */ |
Daniel Vetter | f4c956a | 2012-11-02 19:55:02 +0100 | [diff] [blame] | 164 | i915_write_indexed(dev, cr_index, cr_data, 0x11, dev_priv->regfile.saveCR[0x11]); |
Jesse Barnes | 317c35d | 2008-08-25 15:11:06 -0700 | [diff] [blame] | 165 | for (i = 0; i <= 0x24; i++) |
Daniel Vetter | f4c956a | 2012-11-02 19:55:02 +0100 | [diff] [blame] | 166 | i915_write_indexed(dev, cr_index, cr_data, i, dev_priv->regfile.saveCR[i]); |
Jesse Barnes | 317c35d | 2008-08-25 15:11:06 -0700 | [diff] [blame] | 167 | |
| 168 | /* Graphics controller regs */ |
| 169 | for (i = 0; i < 9; i++) |
| 170 | i915_write_indexed(dev, VGA_GR_INDEX, VGA_GR_DATA, i, |
Daniel Vetter | f4c956a | 2012-11-02 19:55:02 +0100 | [diff] [blame] | 171 | dev_priv->regfile.saveGR[i]); |
Jesse Barnes | 317c35d | 2008-08-25 15:11:06 -0700 | [diff] [blame] | 172 | |
| 173 | i915_write_indexed(dev, VGA_GR_INDEX, VGA_GR_DATA, 0x10, |
Daniel Vetter | f4c956a | 2012-11-02 19:55:02 +0100 | [diff] [blame] | 174 | dev_priv->regfile.saveGR[0x10]); |
Jesse Barnes | 317c35d | 2008-08-25 15:11:06 -0700 | [diff] [blame] | 175 | i915_write_indexed(dev, VGA_GR_INDEX, VGA_GR_DATA, 0x11, |
Daniel Vetter | f4c956a | 2012-11-02 19:55:02 +0100 | [diff] [blame] | 176 | dev_priv->regfile.saveGR[0x11]); |
Jesse Barnes | 317c35d | 2008-08-25 15:11:06 -0700 | [diff] [blame] | 177 | i915_write_indexed(dev, VGA_GR_INDEX, VGA_GR_DATA, 0x18, |
Daniel Vetter | f4c956a | 2012-11-02 19:55:02 +0100 | [diff] [blame] | 178 | dev_priv->regfile.saveGR[0x18]); |
Jesse Barnes | 317c35d | 2008-08-25 15:11:06 -0700 | [diff] [blame] | 179 | |
| 180 | /* Attribute controller registers */ |
| 181 | I915_READ8(st01); /* switch back to index mode */ |
| 182 | for (i = 0; i <= 0x14; i++) |
Daniel Vetter | f4c956a | 2012-11-02 19:55:02 +0100 | [diff] [blame] | 183 | i915_write_ar(dev, st01, i, dev_priv->regfile.saveAR[i], 0); |
Jesse Barnes | 317c35d | 2008-08-25 15:11:06 -0700 | [diff] [blame] | 184 | I915_READ8(st01); /* switch back to index mode */ |
Daniel Vetter | f4c956a | 2012-11-02 19:55:02 +0100 | [diff] [blame] | 185 | I915_WRITE8(VGA_AR_INDEX, dev_priv->regfile.saveAR_INDEX | 0x20); |
Jesse Barnes | 317c35d | 2008-08-25 15:11:06 -0700 | [diff] [blame] | 186 | I915_READ8(st01); |
| 187 | |
| 188 | /* VGA color palette registers */ |
Daniel Vetter | f4c956a | 2012-11-02 19:55:02 +0100 | [diff] [blame] | 189 | I915_WRITE8(VGA_DACMASK, dev_priv->regfile.saveDACMASK); |
Jesse Barnes | 317c35d | 2008-08-25 15:11:06 -0700 | [diff] [blame] | 190 | } |
| 191 | |
Keith Packard | d70bed1 | 2011-06-29 00:30:34 -0700 | [diff] [blame] | 192 | static void i915_save_display(struct drm_device *dev) |
Zhao Yakui | fccdaba | 2009-07-08 14:13:14 +0800 | [diff] [blame] | 193 | { |
| 194 | struct drm_i915_private *dev_priv = dev->dev_private; |
Zhao Yakui | fccdaba | 2009-07-08 14:13:14 +0800 | [diff] [blame] | 195 | |
| 196 | /* Display arbitration control */ |
Paulo Zanoni | 8de0add | 2013-01-18 18:29:03 -0200 | [diff] [blame] | 197 | if (INTEL_INFO(dev)->gen <= 4) |
| 198 | dev_priv->regfile.saveDSPARB = I915_READ(DSPARB); |
Zhao Yakui | fccdaba | 2009-07-08 14:13:14 +0800 | [diff] [blame] | 199 | |
| 200 | /* This is only meaningful in non-KMS mode */ |
Daniel Vetter | f4c956a | 2012-11-02 19:55:02 +0100 | [diff] [blame] | 201 | /* Don't regfile.save them in KMS mode */ |
Daniel Vetter | 2e9723a | 2013-01-25 17:53:19 +0100 | [diff] [blame] | 202 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
Daniel Vetter | d8157a3 | 2013-01-25 17:53:20 +0100 | [diff] [blame] | 203 | i915_save_display_reg(dev); |
Ben Gamari | 1341d65 | 2009-09-14 17:48:42 -0400 | [diff] [blame] | 204 | |
Jesse Barnes | 317c35d | 2008-08-25 15:11:06 -0700 | [diff] [blame] | 205 | /* LVDS state */ |
Jani Nikula | 1c5bb42 | 2014-11-12 17:01:10 +0200 | [diff] [blame] | 206 | if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)) |
| 207 | dev_priv->regfile.saveLVDS = I915_READ(PCH_LVDS); |
| 208 | else if (INTEL_INFO(dev)->gen <= 4 && IS_MOBILE(dev) && !IS_I830(dev)) |
| 209 | dev_priv->regfile.saveLVDS = I915_READ(LVDS); |
| 210 | |
| 211 | /* Panel power sequencer */ |
Chris Wilson | 90eb77b | 2010-08-14 14:41:23 +0100 | [diff] [blame] | 212 | if (HAS_PCH_SPLIT(dev)) { |
Daniel Vetter | f4c956a | 2012-11-02 19:55:02 +0100 | [diff] [blame] | 213 | dev_priv->regfile.savePP_CONTROL = I915_READ(PCH_PP_CONTROL); |
Daniel Vetter | f4c956a | 2012-11-02 19:55:02 +0100 | [diff] [blame] | 214 | dev_priv->regfile.savePP_ON_DELAYS = I915_READ(PCH_PP_ON_DELAYS); |
| 215 | dev_priv->regfile.savePP_OFF_DELAYS = I915_READ(PCH_PP_OFF_DELAYS); |
| 216 | dev_priv->regfile.savePP_DIVISOR = I915_READ(PCH_PP_DIVISOR); |
Jani Nikula | c7e2073 | 2014-11-11 16:48:03 +0200 | [diff] [blame] | 217 | } else if (!IS_VALLEYVIEW(dev)) { |
Jani Nikula | 1c5bb42 | 2014-11-12 17:01:10 +0200 | [diff] [blame] | 218 | dev_priv->regfile.savePP_CONTROL = I915_READ(PP_CONTROL); |
Daniel Vetter | f4c956a | 2012-11-02 19:55:02 +0100 | [diff] [blame] | 219 | dev_priv->regfile.savePP_ON_DELAYS = I915_READ(PP_ON_DELAYS); |
| 220 | dev_priv->regfile.savePP_OFF_DELAYS = I915_READ(PP_OFF_DELAYS); |
| 221 | dev_priv->regfile.savePP_DIVISOR = I915_READ(PP_DIVISOR); |
Zhenyu Wang | 4204878 | 2009-10-21 15:27:01 +0800 | [diff] [blame] | 222 | } |
Jesse Barnes | 317c35d | 2008-08-25 15:11:06 -0700 | [diff] [blame] | 223 | |
Ville Syrjälä | 768cf7f | 2014-01-23 16:49:15 +0200 | [diff] [blame] | 224 | /* save FBC interval */ |
| 225 | if (HAS_FBC(dev) && INTEL_INFO(dev)->gen <= 4 && !IS_G4X(dev)) |
| 226 | dev_priv->regfile.saveFBC_CONTROL = I915_READ(FBC_CONTROL); |
Jesse Barnes | 317c35d | 2008-08-25 15:11:06 -0700 | [diff] [blame] | 227 | |
Daniel Vetter | 44cec74 | 2013-01-25 17:53:21 +0100 | [diff] [blame] | 228 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
| 229 | i915_save_vga(dev); |
Jesse Barnes | 317c35d | 2008-08-25 15:11:06 -0700 | [diff] [blame] | 230 | } |
| 231 | |
Keith Packard | d70bed1 | 2011-06-29 00:30:34 -0700 | [diff] [blame] | 232 | static void i915_restore_display(struct drm_device *dev) |
Jesse Barnes | 317c35d | 2008-08-25 15:11:06 -0700 | [diff] [blame] | 233 | { |
| 234 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | 2ec9066 | 2013-02-19 12:11:38 -0800 | [diff] [blame] | 235 | u32 mask = 0xffffffff; |
Peng Li | 461cba2 | 2008-11-18 12:39:02 +0800 | [diff] [blame] | 236 | |
Keith Packard | 881ee98 | 2008-11-02 23:08:44 -0800 | [diff] [blame] | 237 | /* Display arbitration */ |
Paulo Zanoni | 8de0add | 2013-01-18 18:29:03 -0200 | [diff] [blame] | 238 | if (INTEL_INFO(dev)->gen <= 4) |
| 239 | I915_WRITE(DSPARB, dev_priv->regfile.saveDSPARB); |
Jesse Barnes | 317c35d | 2008-08-25 15:11:06 -0700 | [diff] [blame] | 240 | |
Daniel Vetter | 2e9723a | 2013-01-25 17:53:19 +0100 | [diff] [blame] | 241 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
Daniel Vetter | d8157a3 | 2013-01-25 17:53:20 +0100 | [diff] [blame] | 242 | i915_restore_display_reg(dev); |
Ben Gamari | 1341d65 | 2009-09-14 17:48:42 -0400 | [diff] [blame] | 243 | |
Jesse Barnes | 2ec9066 | 2013-02-19 12:11:38 -0800 | [diff] [blame] | 244 | if (drm_core_check_feature(dev, DRIVER_MODESET)) |
| 245 | mask = ~LVDS_PORT_EN; |
| 246 | |
Jani Nikula | 1c5bb42 | 2014-11-12 17:01:10 +0200 | [diff] [blame] | 247 | /* LVDS state */ |
Paulo Zanoni | 4deb88a | 2013-03-06 20:03:20 -0300 | [diff] [blame] | 248 | if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)) |
Jesse Barnes | 2ec9066 | 2013-02-19 12:11:38 -0800 | [diff] [blame] | 249 | I915_WRITE(PCH_LVDS, dev_priv->regfile.saveLVDS & mask); |
Paulo Zanoni | 4deb88a | 2013-03-06 20:03:20 -0300 | [diff] [blame] | 250 | 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] | 251 | I915_WRITE(LVDS, dev_priv->regfile.saveLVDS & mask); |
Zhenyu Wang | 4204878 | 2009-10-21 15:27:01 +0800 | [diff] [blame] | 252 | |
Jani Nikula | 1c5bb42 | 2014-11-12 17:01:10 +0200 | [diff] [blame] | 253 | /* Panel power sequencer */ |
Chris Wilson | 90eb77b | 2010-08-14 14:41:23 +0100 | [diff] [blame] | 254 | if (HAS_PCH_SPLIT(dev)) { |
Daniel Vetter | f4c956a | 2012-11-02 19:55:02 +0100 | [diff] [blame] | 255 | I915_WRITE(PCH_PP_ON_DELAYS, dev_priv->regfile.savePP_ON_DELAYS); |
| 256 | I915_WRITE(PCH_PP_OFF_DELAYS, dev_priv->regfile.savePP_OFF_DELAYS); |
| 257 | I915_WRITE(PCH_PP_DIVISOR, dev_priv->regfile.savePP_DIVISOR); |
| 258 | I915_WRITE(PCH_PP_CONTROL, dev_priv->regfile.savePP_CONTROL); |
Jani Nikula | b0cd324 | 2014-11-12 16:25:43 +0200 | [diff] [blame] | 259 | } else if (!IS_VALLEYVIEW(dev)) { |
Daniel Vetter | f4c956a | 2012-11-02 19:55:02 +0100 | [diff] [blame] | 260 | I915_WRITE(PP_ON_DELAYS, dev_priv->regfile.savePP_ON_DELAYS); |
| 261 | I915_WRITE(PP_OFF_DELAYS, dev_priv->regfile.savePP_OFF_DELAYS); |
| 262 | I915_WRITE(PP_DIVISOR, dev_priv->regfile.savePP_DIVISOR); |
| 263 | I915_WRITE(PP_CONTROL, dev_priv->regfile.savePP_CONTROL); |
Zhenyu Wang | 4204878 | 2009-10-21 15:27:01 +0800 | [diff] [blame] | 264 | } |
Jesse Barnes | 317c35d | 2008-08-25 15:11:06 -0700 | [diff] [blame] | 265 | |
Zhao Yakui | a2c459e | 2010-03-19 17:05:10 +0800 | [diff] [blame] | 266 | /* only restore FBC info on the platform that supports FBC*/ |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 267 | intel_fbc_disable(dev); |
Ville Syrjälä | 768cf7f | 2014-01-23 16:49:15 +0200 | [diff] [blame] | 268 | |
| 269 | /* restore FBC interval */ |
| 270 | if (HAS_FBC(dev) && INTEL_INFO(dev)->gen <= 4 && !IS_G4X(dev)) |
| 271 | I915_WRITE(FBC_CONTROL, dev_priv->regfile.saveFBC_CONTROL); |
Daniel Vetter | a65e827 | 2013-01-25 17:53:22 +0100 | [diff] [blame] | 272 | |
Daniel Vetter | 44cec74 | 2013-01-25 17:53:21 +0100 | [diff] [blame] | 273 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
| 274 | i915_restore_vga(dev); |
Zhenyu Wang | 4204878 | 2009-10-21 15:27:01 +0800 | [diff] [blame] | 275 | else |
Daniel Vetter | 44cec74 | 2013-01-25 17:53:21 +0100 | [diff] [blame] | 276 | i915_redisable_vga(dev); |
Ben Gamari | 1341d65 | 2009-09-14 17:48:42 -0400 | [diff] [blame] | 277 | } |
| 278 | |
| 279 | int i915_save_state(struct drm_device *dev) |
| 280 | { |
| 281 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 282 | int i; |
| 283 | |
Keith Packard | d70bed1 | 2011-06-29 00:30:34 -0700 | [diff] [blame] | 284 | mutex_lock(&dev->struct_mutex); |
| 285 | |
Ben Gamari | 1341d65 | 2009-09-14 17:48:42 -0400 | [diff] [blame] | 286 | i915_save_display(dev); |
| 287 | |
Daniel Vetter | 905c27b | 2012-10-17 11:32:56 +0200 | [diff] [blame] | 288 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) { |
| 289 | /* Interrupt state */ |
| 290 | if (HAS_PCH_SPLIT(dev)) { |
Daniel Vetter | f4c956a | 2012-11-02 19:55:02 +0100 | [diff] [blame] | 291 | dev_priv->regfile.saveDEIER = I915_READ(DEIER); |
| 292 | dev_priv->regfile.saveDEIMR = I915_READ(DEIMR); |
| 293 | dev_priv->regfile.saveGTIER = I915_READ(GTIER); |
| 294 | dev_priv->regfile.saveGTIMR = I915_READ(GTIMR); |
| 295 | dev_priv->regfile.saveFDI_RXA_IMR = I915_READ(_FDI_RXA_IMR); |
| 296 | dev_priv->regfile.saveFDI_RXB_IMR = I915_READ(_FDI_RXB_IMR); |
| 297 | dev_priv->regfile.saveMCHBAR_RENDER_STANDBY = |
Daniel Vetter | 905c27b | 2012-10-17 11:32:56 +0200 | [diff] [blame] | 298 | I915_READ(RSTDBYCTL); |
Daniel Vetter | f4c956a | 2012-11-02 19:55:02 +0100 | [diff] [blame] | 299 | dev_priv->regfile.savePCH_PORT_HOTPLUG = I915_READ(PCH_PORT_HOTPLUG); |
Daniel Vetter | 905c27b | 2012-10-17 11:32:56 +0200 | [diff] [blame] | 300 | } else { |
Daniel Vetter | f4c956a | 2012-11-02 19:55:02 +0100 | [diff] [blame] | 301 | dev_priv->regfile.saveIER = I915_READ(IER); |
| 302 | dev_priv->regfile.saveIMR = I915_READ(IMR); |
Daniel Vetter | 905c27b | 2012-10-17 11:32:56 +0200 | [diff] [blame] | 303 | } |
Zhenyu Wang | 4204878 | 2009-10-21 15:27:01 +0800 | [diff] [blame] | 304 | } |
Ben Gamari | 1341d65 | 2009-09-14 17:48:42 -0400 | [diff] [blame] | 305 | |
Ben Gamari | 1341d65 | 2009-09-14 17:48:42 -0400 | [diff] [blame] | 306 | /* Cache mode state */ |
Jesse Barnes | e8cde23 | 2013-10-11 12:09:29 -0700 | [diff] [blame] | 307 | if (INTEL_INFO(dev)->gen < 7) |
| 308 | dev_priv->regfile.saveCACHE_MODE_0 = I915_READ(CACHE_MODE_0); |
Ben Gamari | 1341d65 | 2009-09-14 17:48:42 -0400 | [diff] [blame] | 309 | |
| 310 | /* Memory Arbitration state */ |
Daniel Vetter | f4c956a | 2012-11-02 19:55:02 +0100 | [diff] [blame] | 311 | dev_priv->regfile.saveMI_ARB_STATE = I915_READ(MI_ARB_STATE); |
Ben Gamari | 1341d65 | 2009-09-14 17:48:42 -0400 | [diff] [blame] | 312 | |
| 313 | /* Scratch space */ |
| 314 | for (i = 0; i < 16; i++) { |
Daniel Vetter | f4c956a | 2012-11-02 19:55:02 +0100 | [diff] [blame] | 315 | dev_priv->regfile.saveSWF0[i] = I915_READ(SWF00 + (i << 2)); |
| 316 | dev_priv->regfile.saveSWF1[i] = I915_READ(SWF10 + (i << 2)); |
Ben Gamari | 1341d65 | 2009-09-14 17:48:42 -0400 | [diff] [blame] | 317 | } |
| 318 | for (i = 0; i < 3; i++) |
Daniel Vetter | f4c956a | 2012-11-02 19:55:02 +0100 | [diff] [blame] | 319 | dev_priv->regfile.saveSWF2[i] = I915_READ(SWF30 + (i << 2)); |
Ben Gamari | 1341d65 | 2009-09-14 17:48:42 -0400 | [diff] [blame] | 320 | |
Keith Packard | d70bed1 | 2011-06-29 00:30:34 -0700 | [diff] [blame] | 321 | mutex_unlock(&dev->struct_mutex); |
| 322 | |
Ben Gamari | 1341d65 | 2009-09-14 17:48:42 -0400 | [diff] [blame] | 323 | return 0; |
| 324 | } |
| 325 | |
| 326 | int i915_restore_state(struct drm_device *dev) |
| 327 | { |
| 328 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 329 | int i; |
| 330 | |
Keith Packard | d70bed1 | 2011-06-29 00:30:34 -0700 | [diff] [blame] | 331 | mutex_lock(&dev->struct_mutex); |
| 332 | |
Chris Wilson | 19b2dbd | 2013-06-12 10:15:12 +0100 | [diff] [blame] | 333 | i915_gem_restore_fences(dev); |
Ben Gamari | 1341d65 | 2009-09-14 17:48:42 -0400 | [diff] [blame] | 334 | i915_restore_display(dev); |
| 335 | |
Daniel Vetter | 905c27b | 2012-10-17 11:32:56 +0200 | [diff] [blame] | 336 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) { |
| 337 | /* Interrupt state */ |
| 338 | if (HAS_PCH_SPLIT(dev)) { |
Daniel Vetter | f4c956a | 2012-11-02 19:55:02 +0100 | [diff] [blame] | 339 | I915_WRITE(DEIER, dev_priv->regfile.saveDEIER); |
| 340 | I915_WRITE(DEIMR, dev_priv->regfile.saveDEIMR); |
| 341 | I915_WRITE(GTIER, dev_priv->regfile.saveGTIER); |
| 342 | I915_WRITE(GTIMR, dev_priv->regfile.saveGTIMR); |
| 343 | I915_WRITE(_FDI_RXA_IMR, dev_priv->regfile.saveFDI_RXA_IMR); |
| 344 | I915_WRITE(_FDI_RXB_IMR, dev_priv->regfile.saveFDI_RXB_IMR); |
| 345 | I915_WRITE(PCH_PORT_HOTPLUG, dev_priv->regfile.savePCH_PORT_HOTPLUG); |
Jani Nikula | c934a16 | 2014-11-11 16:48:04 +0200 | [diff] [blame] | 346 | I915_WRITE(RSTDBYCTL, |
| 347 | dev_priv->regfile.saveMCHBAR_RENDER_STANDBY); |
Daniel Vetter | 905c27b | 2012-10-17 11:32:56 +0200 | [diff] [blame] | 348 | } else { |
Daniel Vetter | f4c956a | 2012-11-02 19:55:02 +0100 | [diff] [blame] | 349 | I915_WRITE(IER, dev_priv->regfile.saveIER); |
| 350 | I915_WRITE(IMR, dev_priv->regfile.saveIMR); |
Daniel Vetter | 905c27b | 2012-10-17 11:32:56 +0200 | [diff] [blame] | 351 | } |
Zhenyu Wang | 4204878 | 2009-10-21 15:27:01 +0800 | [diff] [blame] | 352 | } |
Keith Packard | d70bed1 | 2011-06-29 00:30:34 -0700 | [diff] [blame] | 353 | |
Jesse Barnes | 317c35d | 2008-08-25 15:11:06 -0700 | [diff] [blame] | 354 | /* Cache mode state */ |
Jesse Barnes | e8cde23 | 2013-10-11 12:09:29 -0700 | [diff] [blame] | 355 | if (INTEL_INFO(dev)->gen < 7) |
| 356 | I915_WRITE(CACHE_MODE_0, dev_priv->regfile.saveCACHE_MODE_0 | |
| 357 | 0xffff0000); |
Jesse Barnes | 317c35d | 2008-08-25 15:11:06 -0700 | [diff] [blame] | 358 | |
| 359 | /* Memory arbitration state */ |
Daniel Vetter | f4c956a | 2012-11-02 19:55:02 +0100 | [diff] [blame] | 360 | I915_WRITE(MI_ARB_STATE, dev_priv->regfile.saveMI_ARB_STATE | 0xffff0000); |
Jesse Barnes | 317c35d | 2008-08-25 15:11:06 -0700 | [diff] [blame] | 361 | |
| 362 | for (i = 0; i < 16; i++) { |
Daniel Vetter | f4c956a | 2012-11-02 19:55:02 +0100 | [diff] [blame] | 363 | I915_WRITE(SWF00 + (i << 2), dev_priv->regfile.saveSWF0[i]); |
| 364 | I915_WRITE(SWF10 + (i << 2), dev_priv->regfile.saveSWF1[i]); |
Jesse Barnes | 317c35d | 2008-08-25 15:11:06 -0700 | [diff] [blame] | 365 | } |
| 366 | for (i = 0; i < 3; i++) |
Daniel Vetter | f4c956a | 2012-11-02 19:55:02 +0100 | [diff] [blame] | 367 | I915_WRITE(SWF30 + (i << 2), dev_priv->regfile.saveSWF2[i]); |
Jesse Barnes | 317c35d | 2008-08-25 15:11:06 -0700 | [diff] [blame] | 368 | |
Keith Packard | d70bed1 | 2011-06-29 00:30:34 -0700 | [diff] [blame] | 369 | mutex_unlock(&dev->struct_mutex); |
| 370 | |
Chris Wilson | f899fc6 | 2010-07-20 15:44:45 -0700 | [diff] [blame] | 371 | intel_i2c_reset(dev); |
Eric Anholt | f0217c4 | 2009-12-01 11:56:30 -0800 | [diff] [blame] | 372 | |
Jesse Barnes | 317c35d | 2008-08-25 15:11:06 -0700 | [diff] [blame] | 373 | return 0; |
| 374 | } |