blob: bcde494b380523996dea0cb75d657539d2211cbd [file] [log] [blame]
Jesse Barnes317c35d2008-08-25 15:11:06 -07001/*
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 Howells760285e2012-10-02 18:01:07 +010027#include <drm/drmP.h>
28#include <drm/i915_drm.h>
Eric Anholtf0217c42009-12-01 11:56:30 -080029#include "intel_drv.h"
Eugeni Dodonov5e5b7fa2012-01-07 23:40:34 -020030#include "i915_reg.h"
Jesse Barnes317c35d2008-08-25 15:11:06 -070031
32static bool i915_pipe_enabled(struct drm_device *dev, enum pipe pipe)
33{
34 struct drm_i915_private *dev_priv = dev->dev_private;
Zhenyu Wang42048782009-10-21 15:27:01 +080035 u32 dpll_reg;
Jesse Barnes317c35d2008-08-25 15:11:06 -070036
Eugeni Dodonov07c1e8c2012-01-07 23:40:35 -020037 /* On IVB, 3rd pipe shares PLL with another one */
38 if (pipe > 1)
39 return false;
40
Jesse Barnes9db4a9c2011-02-07 12:26:52 -080041 if (HAS_PCH_SPLIT(dev))
Jesse Barnesee7b9f92012-04-20 17:11:53 +010042 dpll_reg = _PCH_DPLL(pipe);
Jesse Barnes9db4a9c2011-02-07 12:26:52 -080043 else
44 dpll_reg = (pipe == PIPE_A) ? _DPLL_A : _DPLL_B;
Zhenyu Wang42048782009-10-21 15:27:01 +080045
46 return (I915_READ(dpll_reg) & DPLL_VCO_ENABLE);
Jesse Barnes317c35d2008-08-25 15:11:06 -070047}
48
49static void i915_save_palette(struct drm_device *dev, enum pipe pipe)
50{
51 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes9db4a9c2011-02-07 12:26:52 -080052 unsigned long reg = (pipe == PIPE_A ? _PALETTE_A : _PALETTE_B);
Jesse Barnes317c35d2008-08-25 15:11:06 -070053 u32 *array;
54 int i;
55
56 if (!i915_pipe_enabled(dev, pipe))
57 return;
58
Chris Wilson90eb77b2010-08-14 14:41:23 +010059 if (HAS_PCH_SPLIT(dev))
Jesse Barnes9db4a9c2011-02-07 12:26:52 -080060 reg = (pipe == PIPE_A) ? _LGC_PALETTE_A : _LGC_PALETTE_B;
Zhenyu Wang42048782009-10-21 15:27:01 +080061
Jesse Barnes317c35d2008-08-25 15:11:06 -070062 if (pipe == PIPE_A)
Daniel Vetterf4c956a2012-11-02 19:55:02 +010063 array = dev_priv->regfile.save_palette_a;
Jesse Barnes317c35d2008-08-25 15:11:06 -070064 else
Daniel Vetterf4c956a2012-11-02 19:55:02 +010065 array = dev_priv->regfile.save_palette_b;
Jesse Barnes317c35d2008-08-25 15:11:06 -070066
Akshay Joshi0206e352011-08-16 15:34:10 -040067 for (i = 0; i < 256; i++)
Jesse Barnes317c35d2008-08-25 15:11:06 -070068 array[i] = I915_READ(reg + (i << 2));
69}
70
71static void i915_restore_palette(struct drm_device *dev, enum pipe pipe)
72{
73 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes9db4a9c2011-02-07 12:26:52 -080074 unsigned long reg = (pipe == PIPE_A ? _PALETTE_A : _PALETTE_B);
Jesse Barnes317c35d2008-08-25 15:11:06 -070075 u32 *array;
76 int i;
77
78 if (!i915_pipe_enabled(dev, pipe))
79 return;
80
Chris Wilson90eb77b2010-08-14 14:41:23 +010081 if (HAS_PCH_SPLIT(dev))
Jesse Barnes9db4a9c2011-02-07 12:26:52 -080082 reg = (pipe == PIPE_A) ? _LGC_PALETTE_A : _LGC_PALETTE_B;
Zhenyu Wang42048782009-10-21 15:27:01 +080083
Jesse Barnes317c35d2008-08-25 15:11:06 -070084 if (pipe == PIPE_A)
Daniel Vetterf4c956a2012-11-02 19:55:02 +010085 array = dev_priv->regfile.save_palette_a;
Jesse Barnes317c35d2008-08-25 15:11:06 -070086 else
Daniel Vetterf4c956a2012-11-02 19:55:02 +010087 array = dev_priv->regfile.save_palette_b;
Jesse Barnes317c35d2008-08-25 15:11:06 -070088
Akshay Joshi0206e352011-08-16 15:34:10 -040089 for (i = 0; i < 256; i++)
Jesse Barnes317c35d2008-08-25 15:11:06 -070090 I915_WRITE(reg + (i << 2), array[i]);
91}
92
93static u8 i915_read_indexed(struct drm_device *dev, u16 index_port, u16 data_port, u8 reg)
94{
95 struct drm_i915_private *dev_priv = dev->dev_private;
96
97 I915_WRITE8(index_port, reg);
98 return I915_READ8(data_port);
99}
100
101static u8 i915_read_ar(struct drm_device *dev, u16 st01, u8 reg, u16 palette_enable)
102{
103 struct drm_i915_private *dev_priv = dev->dev_private;
104
105 I915_READ8(st01);
106 I915_WRITE8(VGA_AR_INDEX, palette_enable | reg);
107 return I915_READ8(VGA_AR_DATA_READ);
108}
109
110static void i915_write_ar(struct drm_device *dev, u16 st01, u8 reg, u8 val, u16 palette_enable)
111{
112 struct drm_i915_private *dev_priv = dev->dev_private;
113
114 I915_READ8(st01);
115 I915_WRITE8(VGA_AR_INDEX, palette_enable | reg);
116 I915_WRITE8(VGA_AR_DATA_WRITE, val);
117}
118
119static void i915_write_indexed(struct drm_device *dev, u16 index_port, u16 data_port, u8 reg, u8 val)
120{
121 struct drm_i915_private *dev_priv = dev->dev_private;
122
123 I915_WRITE8(index_port, reg);
124 I915_WRITE8(data_port, val);
125}
126
127static void i915_save_vga(struct drm_device *dev)
128{
129 struct drm_i915_private *dev_priv = dev->dev_private;
130 int i;
131 u16 cr_index, cr_data, st01;
132
133 /* VGA color palette registers */
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100134 dev_priv->regfile.saveDACMASK = I915_READ8(VGA_DACMASK);
Jesse Barnes317c35d2008-08-25 15:11:06 -0700135
136 /* MSR bits */
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100137 dev_priv->regfile.saveMSR = I915_READ8(VGA_MSR_READ);
138 if (dev_priv->regfile.saveMSR & VGA_MSR_CGA_MODE) {
Jesse Barnes317c35d2008-08-25 15:11:06 -0700139 cr_index = VGA_CR_INDEX_CGA;
140 cr_data = VGA_CR_DATA_CGA;
141 st01 = VGA_ST01_CGA;
142 } else {
143 cr_index = VGA_CR_INDEX_MDA;
144 cr_data = VGA_CR_DATA_MDA;
145 st01 = VGA_ST01_MDA;
146 }
147
148 /* CRT controller regs */
149 i915_write_indexed(dev, cr_index, cr_data, 0x11,
150 i915_read_indexed(dev, cr_index, cr_data, 0x11) &
151 (~0x80));
152 for (i = 0; i <= 0x24; i++)
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100153 dev_priv->regfile.saveCR[i] =
Jesse Barnes317c35d2008-08-25 15:11:06 -0700154 i915_read_indexed(dev, cr_index, cr_data, i);
155 /* Make sure we don't turn off CR group 0 writes */
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100156 dev_priv->regfile.saveCR[0x11] &= ~0x80;
Jesse Barnes317c35d2008-08-25 15:11:06 -0700157
158 /* Attribute controller registers */
159 I915_READ8(st01);
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100160 dev_priv->regfile.saveAR_INDEX = I915_READ8(VGA_AR_INDEX);
Jesse Barnes317c35d2008-08-25 15:11:06 -0700161 for (i = 0; i <= 0x14; i++)
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100162 dev_priv->regfile.saveAR[i] = i915_read_ar(dev, st01, i, 0);
Jesse Barnes317c35d2008-08-25 15:11:06 -0700163 I915_READ8(st01);
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100164 I915_WRITE8(VGA_AR_INDEX, dev_priv->regfile.saveAR_INDEX);
Jesse Barnes317c35d2008-08-25 15:11:06 -0700165 I915_READ8(st01);
166
167 /* Graphics controller registers */
168 for (i = 0; i < 9; i++)
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100169 dev_priv->regfile.saveGR[i] =
Jesse Barnes317c35d2008-08-25 15:11:06 -0700170 i915_read_indexed(dev, VGA_GR_INDEX, VGA_GR_DATA, i);
171
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100172 dev_priv->regfile.saveGR[0x10] =
Jesse Barnes317c35d2008-08-25 15:11:06 -0700173 i915_read_indexed(dev, VGA_GR_INDEX, VGA_GR_DATA, 0x10);
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100174 dev_priv->regfile.saveGR[0x11] =
Jesse Barnes317c35d2008-08-25 15:11:06 -0700175 i915_read_indexed(dev, VGA_GR_INDEX, VGA_GR_DATA, 0x11);
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100176 dev_priv->regfile.saveGR[0x18] =
Jesse Barnes317c35d2008-08-25 15:11:06 -0700177 i915_read_indexed(dev, VGA_GR_INDEX, VGA_GR_DATA, 0x18);
178
179 /* Sequencer registers */
180 for (i = 0; i < 8; i++)
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100181 dev_priv->regfile.saveSR[i] =
Jesse Barnes317c35d2008-08-25 15:11:06 -0700182 i915_read_indexed(dev, VGA_SR_INDEX, VGA_SR_DATA, i);
183}
184
185static void i915_restore_vga(struct drm_device *dev)
186{
187 struct drm_i915_private *dev_priv = dev->dev_private;
188 int i;
189 u16 cr_index, cr_data, st01;
190
191 /* MSR bits */
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100192 I915_WRITE8(VGA_MSR_WRITE, dev_priv->regfile.saveMSR);
193 if (dev_priv->regfile.saveMSR & VGA_MSR_CGA_MODE) {
Jesse Barnes317c35d2008-08-25 15:11:06 -0700194 cr_index = VGA_CR_INDEX_CGA;
195 cr_data = VGA_CR_DATA_CGA;
196 st01 = VGA_ST01_CGA;
197 } else {
198 cr_index = VGA_CR_INDEX_MDA;
199 cr_data = VGA_CR_DATA_MDA;
200 st01 = VGA_ST01_MDA;
201 }
202
203 /* Sequencer registers, don't write SR07 */
204 for (i = 0; i < 7; i++)
205 i915_write_indexed(dev, VGA_SR_INDEX, VGA_SR_DATA, i,
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100206 dev_priv->regfile.saveSR[i]);
Jesse Barnes317c35d2008-08-25 15:11:06 -0700207
208 /* CRT controller regs */
209 /* Enable CR group 0 writes */
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100210 i915_write_indexed(dev, cr_index, cr_data, 0x11, dev_priv->regfile.saveCR[0x11]);
Jesse Barnes317c35d2008-08-25 15:11:06 -0700211 for (i = 0; i <= 0x24; i++)
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100212 i915_write_indexed(dev, cr_index, cr_data, i, dev_priv->regfile.saveCR[i]);
Jesse Barnes317c35d2008-08-25 15:11:06 -0700213
214 /* Graphics controller regs */
215 for (i = 0; i < 9; i++)
216 i915_write_indexed(dev, VGA_GR_INDEX, VGA_GR_DATA, i,
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100217 dev_priv->regfile.saveGR[i]);
Jesse Barnes317c35d2008-08-25 15:11:06 -0700218
219 i915_write_indexed(dev, VGA_GR_INDEX, VGA_GR_DATA, 0x10,
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100220 dev_priv->regfile.saveGR[0x10]);
Jesse Barnes317c35d2008-08-25 15:11:06 -0700221 i915_write_indexed(dev, VGA_GR_INDEX, VGA_GR_DATA, 0x11,
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100222 dev_priv->regfile.saveGR[0x11]);
Jesse Barnes317c35d2008-08-25 15:11:06 -0700223 i915_write_indexed(dev, VGA_GR_INDEX, VGA_GR_DATA, 0x18,
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100224 dev_priv->regfile.saveGR[0x18]);
Jesse Barnes317c35d2008-08-25 15:11:06 -0700225
226 /* Attribute controller registers */
227 I915_READ8(st01); /* switch back to index mode */
228 for (i = 0; i <= 0x14; i++)
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100229 i915_write_ar(dev, st01, i, dev_priv->regfile.saveAR[i], 0);
Jesse Barnes317c35d2008-08-25 15:11:06 -0700230 I915_READ8(st01); /* switch back to index mode */
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100231 I915_WRITE8(VGA_AR_INDEX, dev_priv->regfile.saveAR_INDEX | 0x20);
Jesse Barnes317c35d2008-08-25 15:11:06 -0700232 I915_READ8(st01);
233
234 /* VGA color palette registers */
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100235 I915_WRITE8(VGA_DACMASK, dev_priv->regfile.saveDACMASK);
Jesse Barnes317c35d2008-08-25 15:11:06 -0700236}
237
Zhao Yakuifccdaba2009-07-08 14:13:14 +0800238static void i915_save_modeset_reg(struct drm_device *dev)
Jesse Barnes317c35d2008-08-25 15:11:06 -0700239{
240 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson312817a2010-11-22 11:50:11 +0000241 int i;
Jesse Barnes317c35d2008-08-25 15:11:06 -0700242
Chris Wilsonf3c91c12010-11-21 09:56:00 +0000243 /* Cursor state */
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100244 dev_priv->regfile.saveCURACNTR = I915_READ(_CURACNTR);
245 dev_priv->regfile.saveCURAPOS = I915_READ(_CURAPOS);
246 dev_priv->regfile.saveCURABASE = I915_READ(_CURABASE);
247 dev_priv->regfile.saveCURBCNTR = I915_READ(_CURBCNTR);
248 dev_priv->regfile.saveCURBPOS = I915_READ(_CURBPOS);
249 dev_priv->regfile.saveCURBBASE = I915_READ(_CURBBASE);
Chris Wilsonf3c91c12010-11-21 09:56:00 +0000250 if (IS_GEN2(dev))
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100251 dev_priv->regfile.saveCURSIZE = I915_READ(CURSIZE);
Chris Wilsonf3c91c12010-11-21 09:56:00 +0000252
Chris Wilson90eb77b2010-08-14 14:41:23 +0100253 if (HAS_PCH_SPLIT(dev)) {
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100254 dev_priv->regfile.savePCH_DREF_CONTROL = I915_READ(PCH_DREF_CONTROL);
255 dev_priv->regfile.saveDISP_ARB_CTL = I915_READ(DISP_ARB_CTL);
Zhenyu Wang5586c8b2009-11-06 02:13:02 +0000256 }
257
Jesse Barnes317c35d2008-08-25 15:11:06 -0700258 /* Pipe & plane A info */
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100259 dev_priv->regfile.savePIPEACONF = I915_READ(_PIPEACONF);
260 dev_priv->regfile.savePIPEASRC = I915_READ(_PIPEASRC);
Chris Wilson90eb77b2010-08-14 14:41:23 +0100261 if (HAS_PCH_SPLIT(dev)) {
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100262 dev_priv->regfile.saveFPA0 = I915_READ(_PCH_FPA0);
263 dev_priv->regfile.saveFPA1 = I915_READ(_PCH_FPA1);
264 dev_priv->regfile.saveDPLL_A = I915_READ(_PCH_DPLL_A);
Zhenyu Wang42048782009-10-21 15:27:01 +0800265 } else {
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100266 dev_priv->regfile.saveFPA0 = I915_READ(_FPA0);
267 dev_priv->regfile.saveFPA1 = I915_READ(_FPA1);
268 dev_priv->regfile.saveDPLL_A = I915_READ(_DPLL_A);
Zhenyu Wang42048782009-10-21 15:27:01 +0800269 }
Chris Wilsona6c45cf2010-09-17 00:32:17 +0100270 if (INTEL_INFO(dev)->gen >= 4 && !HAS_PCH_SPLIT(dev))
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100271 dev_priv->regfile.saveDPLL_A_MD = I915_READ(_DPLL_A_MD);
272 dev_priv->regfile.saveHTOTAL_A = I915_READ(_HTOTAL_A);
273 dev_priv->regfile.saveHBLANK_A = I915_READ(_HBLANK_A);
274 dev_priv->regfile.saveHSYNC_A = I915_READ(_HSYNC_A);
275 dev_priv->regfile.saveVTOTAL_A = I915_READ(_VTOTAL_A);
276 dev_priv->regfile.saveVBLANK_A = I915_READ(_VBLANK_A);
277 dev_priv->regfile.saveVSYNC_A = I915_READ(_VSYNC_A);
Chris Wilson90eb77b2010-08-14 14:41:23 +0100278 if (!HAS_PCH_SPLIT(dev))
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100279 dev_priv->regfile.saveBCLRPAT_A = I915_READ(_BCLRPAT_A);
Zhenyu Wang42048782009-10-21 15:27:01 +0800280
Chris Wilson90eb77b2010-08-14 14:41:23 +0100281 if (HAS_PCH_SPLIT(dev)) {
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100282 dev_priv->regfile.savePIPEA_DATA_M1 = I915_READ(_PIPEA_DATA_M1);
283 dev_priv->regfile.savePIPEA_DATA_N1 = I915_READ(_PIPEA_DATA_N1);
284 dev_priv->regfile.savePIPEA_LINK_M1 = I915_READ(_PIPEA_LINK_M1);
285 dev_priv->regfile.savePIPEA_LINK_N1 = I915_READ(_PIPEA_LINK_N1);
Zhenyu Wang5586c8b2009-11-06 02:13:02 +0000286
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100287 dev_priv->regfile.saveFDI_TXA_CTL = I915_READ(_FDI_TXA_CTL);
288 dev_priv->regfile.saveFDI_RXA_CTL = I915_READ(_FDI_RXA_CTL);
Zhenyu Wang42048782009-10-21 15:27:01 +0800289
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100290 dev_priv->regfile.savePFA_CTL_1 = I915_READ(_PFA_CTL_1);
291 dev_priv->regfile.savePFA_WIN_SZ = I915_READ(_PFA_WIN_SZ);
292 dev_priv->regfile.savePFA_WIN_POS = I915_READ(_PFA_WIN_POS);
Zhenyu Wang42048782009-10-21 15:27:01 +0800293
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100294 dev_priv->regfile.saveTRANSACONF = I915_READ(_TRANSACONF);
295 dev_priv->regfile.saveTRANS_HTOTAL_A = I915_READ(_TRANS_HTOTAL_A);
296 dev_priv->regfile.saveTRANS_HBLANK_A = I915_READ(_TRANS_HBLANK_A);
297 dev_priv->regfile.saveTRANS_HSYNC_A = I915_READ(_TRANS_HSYNC_A);
298 dev_priv->regfile.saveTRANS_VTOTAL_A = I915_READ(_TRANS_VTOTAL_A);
299 dev_priv->regfile.saveTRANS_VBLANK_A = I915_READ(_TRANS_VBLANK_A);
300 dev_priv->regfile.saveTRANS_VSYNC_A = I915_READ(_TRANS_VSYNC_A);
Zhenyu Wang42048782009-10-21 15:27:01 +0800301 }
Jesse Barnes317c35d2008-08-25 15:11:06 -0700302
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100303 dev_priv->regfile.saveDSPACNTR = I915_READ(_DSPACNTR);
304 dev_priv->regfile.saveDSPASTRIDE = I915_READ(_DSPASTRIDE);
305 dev_priv->regfile.saveDSPASIZE = I915_READ(_DSPASIZE);
306 dev_priv->regfile.saveDSPAPOS = I915_READ(_DSPAPOS);
307 dev_priv->regfile.saveDSPAADDR = I915_READ(_DSPAADDR);
Chris Wilsona6c45cf2010-09-17 00:32:17 +0100308 if (INTEL_INFO(dev)->gen >= 4) {
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100309 dev_priv->regfile.saveDSPASURF = I915_READ(_DSPASURF);
310 dev_priv->regfile.saveDSPATILEOFF = I915_READ(_DSPATILEOFF);
Jesse Barnes317c35d2008-08-25 15:11:06 -0700311 }
312 i915_save_palette(dev, PIPE_A);
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100313 dev_priv->regfile.savePIPEASTAT = I915_READ(_PIPEASTAT);
Jesse Barnes317c35d2008-08-25 15:11:06 -0700314
315 /* Pipe & plane B info */
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100316 dev_priv->regfile.savePIPEBCONF = I915_READ(_PIPEBCONF);
317 dev_priv->regfile.savePIPEBSRC = I915_READ(_PIPEBSRC);
Chris Wilson90eb77b2010-08-14 14:41:23 +0100318 if (HAS_PCH_SPLIT(dev)) {
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100319 dev_priv->regfile.saveFPB0 = I915_READ(_PCH_FPB0);
320 dev_priv->regfile.saveFPB1 = I915_READ(_PCH_FPB1);
321 dev_priv->regfile.saveDPLL_B = I915_READ(_PCH_DPLL_B);
Zhenyu Wang42048782009-10-21 15:27:01 +0800322 } else {
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100323 dev_priv->regfile.saveFPB0 = I915_READ(_FPB0);
324 dev_priv->regfile.saveFPB1 = I915_READ(_FPB1);
325 dev_priv->regfile.saveDPLL_B = I915_READ(_DPLL_B);
Zhenyu Wang42048782009-10-21 15:27:01 +0800326 }
Chris Wilsona6c45cf2010-09-17 00:32:17 +0100327 if (INTEL_INFO(dev)->gen >= 4 && !HAS_PCH_SPLIT(dev))
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100328 dev_priv->regfile.saveDPLL_B_MD = I915_READ(_DPLL_B_MD);
329 dev_priv->regfile.saveHTOTAL_B = I915_READ(_HTOTAL_B);
330 dev_priv->regfile.saveHBLANK_B = I915_READ(_HBLANK_B);
331 dev_priv->regfile.saveHSYNC_B = I915_READ(_HSYNC_B);
332 dev_priv->regfile.saveVTOTAL_B = I915_READ(_VTOTAL_B);
333 dev_priv->regfile.saveVBLANK_B = I915_READ(_VBLANK_B);
334 dev_priv->regfile.saveVSYNC_B = I915_READ(_VSYNC_B);
Chris Wilson90eb77b2010-08-14 14:41:23 +0100335 if (!HAS_PCH_SPLIT(dev))
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100336 dev_priv->regfile.saveBCLRPAT_B = I915_READ(_BCLRPAT_B);
Zhenyu Wang42048782009-10-21 15:27:01 +0800337
Chris Wilson90eb77b2010-08-14 14:41:23 +0100338 if (HAS_PCH_SPLIT(dev)) {
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100339 dev_priv->regfile.savePIPEB_DATA_M1 = I915_READ(_PIPEB_DATA_M1);
340 dev_priv->regfile.savePIPEB_DATA_N1 = I915_READ(_PIPEB_DATA_N1);
341 dev_priv->regfile.savePIPEB_LINK_M1 = I915_READ(_PIPEB_LINK_M1);
342 dev_priv->regfile.savePIPEB_LINK_N1 = I915_READ(_PIPEB_LINK_N1);
Zhenyu Wang5586c8b2009-11-06 02:13:02 +0000343
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100344 dev_priv->regfile.saveFDI_TXB_CTL = I915_READ(_FDI_TXB_CTL);
345 dev_priv->regfile.saveFDI_RXB_CTL = I915_READ(_FDI_RXB_CTL);
Zhenyu Wang42048782009-10-21 15:27:01 +0800346
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100347 dev_priv->regfile.savePFB_CTL_1 = I915_READ(_PFB_CTL_1);
348 dev_priv->regfile.savePFB_WIN_SZ = I915_READ(_PFB_WIN_SZ);
349 dev_priv->regfile.savePFB_WIN_POS = I915_READ(_PFB_WIN_POS);
Zhenyu Wang42048782009-10-21 15:27:01 +0800350
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100351 dev_priv->regfile.saveTRANSBCONF = I915_READ(_TRANSBCONF);
352 dev_priv->regfile.saveTRANS_HTOTAL_B = I915_READ(_TRANS_HTOTAL_B);
353 dev_priv->regfile.saveTRANS_HBLANK_B = I915_READ(_TRANS_HBLANK_B);
354 dev_priv->regfile.saveTRANS_HSYNC_B = I915_READ(_TRANS_HSYNC_B);
355 dev_priv->regfile.saveTRANS_VTOTAL_B = I915_READ(_TRANS_VTOTAL_B);
356 dev_priv->regfile.saveTRANS_VBLANK_B = I915_READ(_TRANS_VBLANK_B);
357 dev_priv->regfile.saveTRANS_VSYNC_B = I915_READ(_TRANS_VSYNC_B);
Zhenyu Wang42048782009-10-21 15:27:01 +0800358 }
Jesse Barnes317c35d2008-08-25 15:11:06 -0700359
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100360 dev_priv->regfile.saveDSPBCNTR = I915_READ(_DSPBCNTR);
361 dev_priv->regfile.saveDSPBSTRIDE = I915_READ(_DSPBSTRIDE);
362 dev_priv->regfile.saveDSPBSIZE = I915_READ(_DSPBSIZE);
363 dev_priv->regfile.saveDSPBPOS = I915_READ(_DSPBPOS);
364 dev_priv->regfile.saveDSPBADDR = I915_READ(_DSPBADDR);
Chris Wilsona6c45cf2010-09-17 00:32:17 +0100365 if (INTEL_INFO(dev)->gen >= 4) {
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100366 dev_priv->regfile.saveDSPBSURF = I915_READ(_DSPBSURF);
367 dev_priv->regfile.saveDSPBTILEOFF = I915_READ(_DSPBTILEOFF);
Jesse Barnes317c35d2008-08-25 15:11:06 -0700368 }
369 i915_save_palette(dev, PIPE_B);
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100370 dev_priv->regfile.savePIPEBSTAT = I915_READ(_PIPEBSTAT);
Chris Wilson312817a2010-11-22 11:50:11 +0000371
372 /* Fences */
373 switch (INTEL_INFO(dev)->gen) {
Daniel Vetter775d17b2011-10-09 21:52:01 +0200374 case 7:
Chris Wilson312817a2010-11-22 11:50:11 +0000375 case 6:
376 for (i = 0; i < 16; i++)
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100377 dev_priv->regfile.saveFENCE[i] = I915_READ64(FENCE_REG_SANDYBRIDGE_0 + (i * 8));
Chris Wilson312817a2010-11-22 11:50:11 +0000378 break;
379 case 5:
380 case 4:
381 for (i = 0; i < 16; i++)
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100382 dev_priv->regfile.saveFENCE[i] = I915_READ64(FENCE_REG_965_0 + (i * 8));
Chris Wilson312817a2010-11-22 11:50:11 +0000383 break;
384 case 3:
385 if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev))
386 for (i = 0; i < 8; i++)
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100387 dev_priv->regfile.saveFENCE[i+8] = I915_READ(FENCE_REG_945_8 + (i * 4));
Chris Wilson312817a2010-11-22 11:50:11 +0000388 case 2:
389 for (i = 0; i < 8; i++)
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100390 dev_priv->regfile.saveFENCE[i] = I915_READ(FENCE_REG_830_0 + (i * 4));
Chris Wilson312817a2010-11-22 11:50:11 +0000391 break;
392 }
393
Daniel Vetter7fdd74a2012-10-11 20:08:25 +0200394 /* CRT state */
395 if (HAS_PCH_SPLIT(dev))
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100396 dev_priv->regfile.saveADPA = I915_READ(PCH_ADPA);
Daniel Vetter7fdd74a2012-10-11 20:08:25 +0200397 else
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100398 dev_priv->regfile.saveADPA = I915_READ(ADPA);
Daniel Vetter7fdd74a2012-10-11 20:08:25 +0200399
Zhao Yakuifccdaba2009-07-08 14:13:14 +0800400 return;
401}
Ben Gamari1341d652009-09-14 17:48:42 -0400402
Zhao Yakuifccdaba2009-07-08 14:13:14 +0800403static void i915_restore_modeset_reg(struct drm_device *dev)
404{
405 struct drm_i915_private *dev_priv = dev->dev_private;
Zhenyu Wang42048782009-10-21 15:27:01 +0800406 int dpll_a_reg, fpa0_reg, fpa1_reg;
407 int dpll_b_reg, fpb0_reg, fpb1_reg;
Chris Wilson312817a2010-11-22 11:50:11 +0000408 int i;
Jesse Barnes317c35d2008-08-25 15:11:06 -0700409
Daniel Vetter2e9723a2013-01-25 17:53:19 +0100410 /* Display port ratios (must be done before clock is set) */
411 if (SUPPORTS_INTEGRATED_DP(dev)) {
412 I915_WRITE(_PIPEA_GMCH_DATA_M, dev_priv->regfile.savePIPEA_GMCH_DATA_M);
413 I915_WRITE(_PIPEB_GMCH_DATA_M, dev_priv->regfile.savePIPEB_GMCH_DATA_M);
414 I915_WRITE(_PIPEA_GMCH_DATA_N, dev_priv->regfile.savePIPEA_GMCH_DATA_N);
415 I915_WRITE(_PIPEB_GMCH_DATA_N, dev_priv->regfile.savePIPEB_GMCH_DATA_N);
416 I915_WRITE(_PIPEA_DP_LINK_M, dev_priv->regfile.savePIPEA_DP_LINK_M);
417 I915_WRITE(_PIPEB_DP_LINK_M, dev_priv->regfile.savePIPEB_DP_LINK_M);
418 I915_WRITE(_PIPEA_DP_LINK_N, dev_priv->regfile.savePIPEA_DP_LINK_N);
419 I915_WRITE(_PIPEB_DP_LINK_N, dev_priv->regfile.savePIPEB_DP_LINK_N);
420 }
Zhao Yakuifccdaba2009-07-08 14:13:14 +0800421
Chris Wilson312817a2010-11-22 11:50:11 +0000422 /* Fences */
423 switch (INTEL_INFO(dev)->gen) {
Daniel Vetter775d17b2011-10-09 21:52:01 +0200424 case 7:
Chris Wilson312817a2010-11-22 11:50:11 +0000425 case 6:
426 for (i = 0; i < 16; i++)
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100427 I915_WRITE64(FENCE_REG_SANDYBRIDGE_0 + (i * 8), dev_priv->regfile.saveFENCE[i]);
Chris Wilson312817a2010-11-22 11:50:11 +0000428 break;
429 case 5:
430 case 4:
431 for (i = 0; i < 16; i++)
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100432 I915_WRITE64(FENCE_REG_965_0 + (i * 8), dev_priv->regfile.saveFENCE[i]);
Chris Wilson312817a2010-11-22 11:50:11 +0000433 break;
434 case 3:
435 case 2:
436 if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev))
437 for (i = 0; i < 8; i++)
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100438 I915_WRITE(FENCE_REG_945_8 + (i * 4), dev_priv->regfile.saveFENCE[i+8]);
Chris Wilson312817a2010-11-22 11:50:11 +0000439 for (i = 0; i < 8; i++)
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100440 I915_WRITE(FENCE_REG_830_0 + (i * 4), dev_priv->regfile.saveFENCE[i]);
Chris Wilson312817a2010-11-22 11:50:11 +0000441 break;
442 }
443
444
Chris Wilson90eb77b2010-08-14 14:41:23 +0100445 if (HAS_PCH_SPLIT(dev)) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800446 dpll_a_reg = _PCH_DPLL_A;
447 dpll_b_reg = _PCH_DPLL_B;
448 fpa0_reg = _PCH_FPA0;
449 fpb0_reg = _PCH_FPB0;
450 fpa1_reg = _PCH_FPA1;
451 fpb1_reg = _PCH_FPB1;
Zhenyu Wang42048782009-10-21 15:27:01 +0800452 } else {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800453 dpll_a_reg = _DPLL_A;
454 dpll_b_reg = _DPLL_B;
455 fpa0_reg = _FPA0;
456 fpb0_reg = _FPB0;
457 fpa1_reg = _FPA1;
458 fpb1_reg = _FPB1;
Zhenyu Wang42048782009-10-21 15:27:01 +0800459 }
460
Chris Wilson90eb77b2010-08-14 14:41:23 +0100461 if (HAS_PCH_SPLIT(dev)) {
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100462 I915_WRITE(PCH_DREF_CONTROL, dev_priv->regfile.savePCH_DREF_CONTROL);
463 I915_WRITE(DISP_ARB_CTL, dev_priv->regfile.saveDISP_ARB_CTL);
Zhenyu Wang5586c8b2009-11-06 02:13:02 +0000464 }
465
Zhao Yakuifccdaba2009-07-08 14:13:14 +0800466 /* Pipe & plane A info */
467 /* Prime the clock */
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100468 if (dev_priv->regfile.saveDPLL_A & DPLL_VCO_ENABLE) {
469 I915_WRITE(dpll_a_reg, dev_priv->regfile.saveDPLL_A &
Zhao Yakuifccdaba2009-07-08 14:13:14 +0800470 ~DPLL_VCO_ENABLE);
Chris Wilson72bcb262010-08-14 14:41:22 +0100471 POSTING_READ(dpll_a_reg);
472 udelay(150);
Zhao Yakuifccdaba2009-07-08 14:13:14 +0800473 }
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100474 I915_WRITE(fpa0_reg, dev_priv->regfile.saveFPA0);
475 I915_WRITE(fpa1_reg, dev_priv->regfile.saveFPA1);
Zhao Yakuifccdaba2009-07-08 14:13:14 +0800476 /* Actually enable it */
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100477 I915_WRITE(dpll_a_reg, dev_priv->regfile.saveDPLL_A);
Chris Wilson72bcb262010-08-14 14:41:22 +0100478 POSTING_READ(dpll_a_reg);
479 udelay(150);
Chris Wilsona6c45cf2010-09-17 00:32:17 +0100480 if (INTEL_INFO(dev)->gen >= 4 && !HAS_PCH_SPLIT(dev)) {
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100481 I915_WRITE(_DPLL_A_MD, dev_priv->regfile.saveDPLL_A_MD);
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800482 POSTING_READ(_DPLL_A_MD);
Chris Wilson72bcb262010-08-14 14:41:22 +0100483 }
484 udelay(150);
Zhao Yakuifccdaba2009-07-08 14:13:14 +0800485
486 /* Restore mode */
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100487 I915_WRITE(_HTOTAL_A, dev_priv->regfile.saveHTOTAL_A);
488 I915_WRITE(_HBLANK_A, dev_priv->regfile.saveHBLANK_A);
489 I915_WRITE(_HSYNC_A, dev_priv->regfile.saveHSYNC_A);
490 I915_WRITE(_VTOTAL_A, dev_priv->regfile.saveVTOTAL_A);
491 I915_WRITE(_VBLANK_A, dev_priv->regfile.saveVBLANK_A);
492 I915_WRITE(_VSYNC_A, dev_priv->regfile.saveVSYNC_A);
Chris Wilson90eb77b2010-08-14 14:41:23 +0100493 if (!HAS_PCH_SPLIT(dev))
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100494 I915_WRITE(_BCLRPAT_A, dev_priv->regfile.saveBCLRPAT_A);
Zhenyu Wang42048782009-10-21 15:27:01 +0800495
Chris Wilson90eb77b2010-08-14 14:41:23 +0100496 if (HAS_PCH_SPLIT(dev)) {
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100497 I915_WRITE(_PIPEA_DATA_M1, dev_priv->regfile.savePIPEA_DATA_M1);
498 I915_WRITE(_PIPEA_DATA_N1, dev_priv->regfile.savePIPEA_DATA_N1);
499 I915_WRITE(_PIPEA_LINK_M1, dev_priv->regfile.savePIPEA_LINK_M1);
500 I915_WRITE(_PIPEA_LINK_N1, dev_priv->regfile.savePIPEA_LINK_N1);
Zhenyu Wang5586c8b2009-11-06 02:13:02 +0000501
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100502 I915_WRITE(_FDI_RXA_CTL, dev_priv->regfile.saveFDI_RXA_CTL);
503 I915_WRITE(_FDI_TXA_CTL, dev_priv->regfile.saveFDI_TXA_CTL);
Zhenyu Wang42048782009-10-21 15:27:01 +0800504
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100505 I915_WRITE(_PFA_CTL_1, dev_priv->regfile.savePFA_CTL_1);
506 I915_WRITE(_PFA_WIN_SZ, dev_priv->regfile.savePFA_WIN_SZ);
507 I915_WRITE(_PFA_WIN_POS, dev_priv->regfile.savePFA_WIN_POS);
Zhenyu Wang42048782009-10-21 15:27:01 +0800508
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100509 I915_WRITE(_TRANSACONF, dev_priv->regfile.saveTRANSACONF);
510 I915_WRITE(_TRANS_HTOTAL_A, dev_priv->regfile.saveTRANS_HTOTAL_A);
511 I915_WRITE(_TRANS_HBLANK_A, dev_priv->regfile.saveTRANS_HBLANK_A);
512 I915_WRITE(_TRANS_HSYNC_A, dev_priv->regfile.saveTRANS_HSYNC_A);
513 I915_WRITE(_TRANS_VTOTAL_A, dev_priv->regfile.saveTRANS_VTOTAL_A);
514 I915_WRITE(_TRANS_VBLANK_A, dev_priv->regfile.saveTRANS_VBLANK_A);
515 I915_WRITE(_TRANS_VSYNC_A, dev_priv->regfile.saveTRANS_VSYNC_A);
Zhenyu Wang42048782009-10-21 15:27:01 +0800516 }
Zhao Yakuifccdaba2009-07-08 14:13:14 +0800517
518 /* Restore plane info */
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100519 I915_WRITE(_DSPASIZE, dev_priv->regfile.saveDSPASIZE);
520 I915_WRITE(_DSPAPOS, dev_priv->regfile.saveDSPAPOS);
521 I915_WRITE(_PIPEASRC, dev_priv->regfile.savePIPEASRC);
522 I915_WRITE(_DSPAADDR, dev_priv->regfile.saveDSPAADDR);
523 I915_WRITE(_DSPASTRIDE, dev_priv->regfile.saveDSPASTRIDE);
Chris Wilsona6c45cf2010-09-17 00:32:17 +0100524 if (INTEL_INFO(dev)->gen >= 4) {
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100525 I915_WRITE(_DSPASURF, dev_priv->regfile.saveDSPASURF);
526 I915_WRITE(_DSPATILEOFF, dev_priv->regfile.saveDSPATILEOFF);
Zhao Yakuifccdaba2009-07-08 14:13:14 +0800527 }
528
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100529 I915_WRITE(_PIPEACONF, dev_priv->regfile.savePIPEACONF);
Zhao Yakuifccdaba2009-07-08 14:13:14 +0800530
531 i915_restore_palette(dev, PIPE_A);
532 /* Enable the plane */
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100533 I915_WRITE(_DSPACNTR, dev_priv->regfile.saveDSPACNTR);
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800534 I915_WRITE(_DSPAADDR, I915_READ(_DSPAADDR));
Zhao Yakuifccdaba2009-07-08 14:13:14 +0800535
536 /* Pipe & plane B info */
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100537 if (dev_priv->regfile.saveDPLL_B & DPLL_VCO_ENABLE) {
538 I915_WRITE(dpll_b_reg, dev_priv->regfile.saveDPLL_B &
Zhao Yakuifccdaba2009-07-08 14:13:14 +0800539 ~DPLL_VCO_ENABLE);
Chris Wilson72bcb262010-08-14 14:41:22 +0100540 POSTING_READ(dpll_b_reg);
541 udelay(150);
Zhao Yakuifccdaba2009-07-08 14:13:14 +0800542 }
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100543 I915_WRITE(fpb0_reg, dev_priv->regfile.saveFPB0);
544 I915_WRITE(fpb1_reg, dev_priv->regfile.saveFPB1);
Zhao Yakuifccdaba2009-07-08 14:13:14 +0800545 /* Actually enable it */
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100546 I915_WRITE(dpll_b_reg, dev_priv->regfile.saveDPLL_B);
Chris Wilson72bcb262010-08-14 14:41:22 +0100547 POSTING_READ(dpll_b_reg);
548 udelay(150);
Chris Wilsona6c45cf2010-09-17 00:32:17 +0100549 if (INTEL_INFO(dev)->gen >= 4 && !HAS_PCH_SPLIT(dev)) {
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100550 I915_WRITE(_DPLL_B_MD, dev_priv->regfile.saveDPLL_B_MD);
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800551 POSTING_READ(_DPLL_B_MD);
Chris Wilson72bcb262010-08-14 14:41:22 +0100552 }
553 udelay(150);
Zhao Yakuifccdaba2009-07-08 14:13:14 +0800554
555 /* Restore mode */
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100556 I915_WRITE(_HTOTAL_B, dev_priv->regfile.saveHTOTAL_B);
557 I915_WRITE(_HBLANK_B, dev_priv->regfile.saveHBLANK_B);
558 I915_WRITE(_HSYNC_B, dev_priv->regfile.saveHSYNC_B);
559 I915_WRITE(_VTOTAL_B, dev_priv->regfile.saveVTOTAL_B);
560 I915_WRITE(_VBLANK_B, dev_priv->regfile.saveVBLANK_B);
561 I915_WRITE(_VSYNC_B, dev_priv->regfile.saveVSYNC_B);
Chris Wilson90eb77b2010-08-14 14:41:23 +0100562 if (!HAS_PCH_SPLIT(dev))
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100563 I915_WRITE(_BCLRPAT_B, dev_priv->regfile.saveBCLRPAT_B);
Zhenyu Wang42048782009-10-21 15:27:01 +0800564
Chris Wilson90eb77b2010-08-14 14:41:23 +0100565 if (HAS_PCH_SPLIT(dev)) {
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100566 I915_WRITE(_PIPEB_DATA_M1, dev_priv->regfile.savePIPEB_DATA_M1);
567 I915_WRITE(_PIPEB_DATA_N1, dev_priv->regfile.savePIPEB_DATA_N1);
568 I915_WRITE(_PIPEB_LINK_M1, dev_priv->regfile.savePIPEB_LINK_M1);
569 I915_WRITE(_PIPEB_LINK_N1, dev_priv->regfile.savePIPEB_LINK_N1);
Zhenyu Wang5586c8b2009-11-06 02:13:02 +0000570
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100571 I915_WRITE(_FDI_RXB_CTL, dev_priv->regfile.saveFDI_RXB_CTL);
572 I915_WRITE(_FDI_TXB_CTL, dev_priv->regfile.saveFDI_TXB_CTL);
Zhenyu Wang42048782009-10-21 15:27:01 +0800573
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100574 I915_WRITE(_PFB_CTL_1, dev_priv->regfile.savePFB_CTL_1);
575 I915_WRITE(_PFB_WIN_SZ, dev_priv->regfile.savePFB_WIN_SZ);
576 I915_WRITE(_PFB_WIN_POS, dev_priv->regfile.savePFB_WIN_POS);
Zhenyu Wang42048782009-10-21 15:27:01 +0800577
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100578 I915_WRITE(_TRANSBCONF, dev_priv->regfile.saveTRANSBCONF);
579 I915_WRITE(_TRANS_HTOTAL_B, dev_priv->regfile.saveTRANS_HTOTAL_B);
580 I915_WRITE(_TRANS_HBLANK_B, dev_priv->regfile.saveTRANS_HBLANK_B);
581 I915_WRITE(_TRANS_HSYNC_B, dev_priv->regfile.saveTRANS_HSYNC_B);
582 I915_WRITE(_TRANS_VTOTAL_B, dev_priv->regfile.saveTRANS_VTOTAL_B);
583 I915_WRITE(_TRANS_VBLANK_B, dev_priv->regfile.saveTRANS_VBLANK_B);
584 I915_WRITE(_TRANS_VSYNC_B, dev_priv->regfile.saveTRANS_VSYNC_B);
Zhenyu Wang42048782009-10-21 15:27:01 +0800585 }
Zhao Yakuifccdaba2009-07-08 14:13:14 +0800586
587 /* Restore plane info */
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100588 I915_WRITE(_DSPBSIZE, dev_priv->regfile.saveDSPBSIZE);
589 I915_WRITE(_DSPBPOS, dev_priv->regfile.saveDSPBPOS);
590 I915_WRITE(_PIPEBSRC, dev_priv->regfile.savePIPEBSRC);
591 I915_WRITE(_DSPBADDR, dev_priv->regfile.saveDSPBADDR);
592 I915_WRITE(_DSPBSTRIDE, dev_priv->regfile.saveDSPBSTRIDE);
Chris Wilsona6c45cf2010-09-17 00:32:17 +0100593 if (INTEL_INFO(dev)->gen >= 4) {
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100594 I915_WRITE(_DSPBSURF, dev_priv->regfile.saveDSPBSURF);
595 I915_WRITE(_DSPBTILEOFF, dev_priv->regfile.saveDSPBTILEOFF);
Zhao Yakuifccdaba2009-07-08 14:13:14 +0800596 }
597
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100598 I915_WRITE(_PIPEBCONF, dev_priv->regfile.savePIPEBCONF);
Zhao Yakuifccdaba2009-07-08 14:13:14 +0800599
600 i915_restore_palette(dev, PIPE_B);
601 /* Enable the plane */
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100602 I915_WRITE(_DSPBCNTR, dev_priv->regfile.saveDSPBCNTR);
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800603 I915_WRITE(_DSPBADDR, I915_READ(_DSPBADDR));
Zhao Yakuifccdaba2009-07-08 14:13:14 +0800604
Chris Wilsonf3c91c12010-11-21 09:56:00 +0000605 /* Cursor state */
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100606 I915_WRITE(_CURAPOS, dev_priv->regfile.saveCURAPOS);
607 I915_WRITE(_CURACNTR, dev_priv->regfile.saveCURACNTR);
608 I915_WRITE(_CURABASE, dev_priv->regfile.saveCURABASE);
609 I915_WRITE(_CURBPOS, dev_priv->regfile.saveCURBPOS);
610 I915_WRITE(_CURBCNTR, dev_priv->regfile.saveCURBCNTR);
611 I915_WRITE(_CURBBASE, dev_priv->regfile.saveCURBBASE);
Chris Wilsonf3c91c12010-11-21 09:56:00 +0000612 if (IS_GEN2(dev))
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100613 I915_WRITE(CURSIZE, dev_priv->regfile.saveCURSIZE);
Chris Wilsonf3c91c12010-11-21 09:56:00 +0000614
Daniel Vetter7fdd74a2012-10-11 20:08:25 +0200615 /* CRT state */
616 if (HAS_PCH_SPLIT(dev))
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100617 I915_WRITE(PCH_ADPA, dev_priv->regfile.saveADPA);
Daniel Vetter7fdd74a2012-10-11 20:08:25 +0200618 else
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100619 I915_WRITE(ADPA, dev_priv->regfile.saveADPA);
Daniel Vetter7fdd74a2012-10-11 20:08:25 +0200620
Zhao Yakuifccdaba2009-07-08 14:13:14 +0800621 return;
622}
Ben Gamari1341d652009-09-14 17:48:42 -0400623
Keith Packardd70bed12011-06-29 00:30:34 -0700624static void i915_save_display(struct drm_device *dev)
Zhao Yakuifccdaba2009-07-08 14:13:14 +0800625{
626 struct drm_i915_private *dev_priv = dev->dev_private;
Zhao Yakuifccdaba2009-07-08 14:13:14 +0800627
628 /* Display arbitration control */
Paulo Zanoni8de0add2013-01-18 18:29:03 -0200629 if (INTEL_INFO(dev)->gen <= 4)
630 dev_priv->regfile.saveDSPARB = I915_READ(DSPARB);
Zhao Yakuifccdaba2009-07-08 14:13:14 +0800631
632 /* This is only meaningful in non-KMS mode */
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100633 /* Don't regfile.save them in KMS mode */
Daniel Vetter2e9723a2013-01-25 17:53:19 +0100634 if (!drm_core_check_feature(dev, DRIVER_MODESET))
635 i915_save_modeset_reg(dev);
Ben Gamari1341d652009-09-14 17:48:42 -0400636
Jesse Barnes317c35d2008-08-25 15:11:06 -0700637 /* LVDS state */
Chris Wilson90eb77b2010-08-14 14:41:23 +0100638 if (HAS_PCH_SPLIT(dev)) {
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100639 dev_priv->regfile.savePP_CONTROL = I915_READ(PCH_PP_CONTROL);
640 dev_priv->regfile.saveBLC_PWM_CTL = I915_READ(BLC_PWM_PCH_CTL1);
641 dev_priv->regfile.saveBLC_PWM_CTL2 = I915_READ(BLC_PWM_PCH_CTL2);
642 dev_priv->regfile.saveBLC_CPU_PWM_CTL = I915_READ(BLC_PWM_CPU_CTL);
643 dev_priv->regfile.saveBLC_CPU_PWM_CTL2 = I915_READ(BLC_PWM_CPU_CTL2);
644 dev_priv->regfile.saveLVDS = I915_READ(PCH_LVDS);
Zhenyu Wang42048782009-10-21 15:27:01 +0800645 } else {
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100646 dev_priv->regfile.savePP_CONTROL = I915_READ(PP_CONTROL);
647 dev_priv->regfile.savePFIT_PGM_RATIOS = I915_READ(PFIT_PGM_RATIOS);
648 dev_priv->regfile.saveBLC_PWM_CTL = I915_READ(BLC_PWM_CTL);
649 dev_priv->regfile.saveBLC_HIST_CTL = I915_READ(BLC_HIST_CTL);
Chris Wilsona6c45cf2010-09-17 00:32:17 +0100650 if (INTEL_INFO(dev)->gen >= 4)
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100651 dev_priv->regfile.saveBLC_PWM_CTL2 = I915_READ(BLC_PWM_CTL2);
Zhenyu Wang42048782009-10-21 15:27:01 +0800652 if (IS_MOBILE(dev) && !IS_I830(dev))
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100653 dev_priv->regfile.saveLVDS = I915_READ(LVDS);
Zhenyu Wang42048782009-10-21 15:27:01 +0800654 }
655
Chris Wilson90eb77b2010-08-14 14:41:23 +0100656 if (!IS_I830(dev) && !IS_845G(dev) && !HAS_PCH_SPLIT(dev))
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100657 dev_priv->regfile.savePFIT_CONTROL = I915_READ(PFIT_CONTROL);
Zhenyu Wang42048782009-10-21 15:27:01 +0800658
Chris Wilson90eb77b2010-08-14 14:41:23 +0100659 if (HAS_PCH_SPLIT(dev)) {
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100660 dev_priv->regfile.savePP_ON_DELAYS = I915_READ(PCH_PP_ON_DELAYS);
661 dev_priv->regfile.savePP_OFF_DELAYS = I915_READ(PCH_PP_OFF_DELAYS);
662 dev_priv->regfile.savePP_DIVISOR = I915_READ(PCH_PP_DIVISOR);
Zhenyu Wang42048782009-10-21 15:27:01 +0800663 } else {
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100664 dev_priv->regfile.savePP_ON_DELAYS = I915_READ(PP_ON_DELAYS);
665 dev_priv->regfile.savePP_OFF_DELAYS = I915_READ(PP_OFF_DELAYS);
666 dev_priv->regfile.savePP_DIVISOR = I915_READ(PP_DIVISOR);
Zhenyu Wang42048782009-10-21 15:27:01 +0800667 }
Jesse Barnes317c35d2008-08-25 15:11:06 -0700668
Daniel Vetterf81183f2012-10-17 11:32:55 +0200669 if (!drm_core_check_feature(dev, DRIVER_MODESET)) {
670 /* Display Port state */
671 if (SUPPORTS_INTEGRATED_DP(dev)) {
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100672 dev_priv->regfile.saveDP_B = I915_READ(DP_B);
673 dev_priv->regfile.saveDP_C = I915_READ(DP_C);
674 dev_priv->regfile.saveDP_D = I915_READ(DP_D);
675 dev_priv->regfile.savePIPEA_GMCH_DATA_M = I915_READ(_PIPEA_GMCH_DATA_M);
676 dev_priv->regfile.savePIPEB_GMCH_DATA_M = I915_READ(_PIPEB_GMCH_DATA_M);
677 dev_priv->regfile.savePIPEA_GMCH_DATA_N = I915_READ(_PIPEA_GMCH_DATA_N);
678 dev_priv->regfile.savePIPEB_GMCH_DATA_N = I915_READ(_PIPEB_GMCH_DATA_N);
679 dev_priv->regfile.savePIPEA_DP_LINK_M = I915_READ(_PIPEA_DP_LINK_M);
680 dev_priv->regfile.savePIPEB_DP_LINK_M = I915_READ(_PIPEB_DP_LINK_M);
681 dev_priv->regfile.savePIPEA_DP_LINK_N = I915_READ(_PIPEA_DP_LINK_N);
682 dev_priv->regfile.savePIPEB_DP_LINK_N = I915_READ(_PIPEB_DP_LINK_N);
Daniel Vetterf81183f2012-10-17 11:32:55 +0200683 }
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100684 /* FIXME: regfile.save TV & SDVO state */
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700685 }
Jesse Barnes317c35d2008-08-25 15:11:06 -0700686
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100687 /* Only regfile.save FBC state on the platform that supports FBC */
Zhao Yakuia2c459e2010-03-19 17:05:10 +0800688 if (I915_HAS_FBC(dev)) {
Chris Wilson90eb77b2010-08-14 14:41:23 +0100689 if (HAS_PCH_SPLIT(dev)) {
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100690 dev_priv->regfile.saveDPFC_CB_BASE = I915_READ(ILK_DPFC_CB_BASE);
Zhao Yakuib52eb4d2010-06-12 14:32:27 +0800691 } else if (IS_GM45(dev)) {
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100692 dev_priv->regfile.saveDPFC_CB_BASE = I915_READ(DPFC_CB_BASE);
Zhao Yakuia2c459e2010-03-19 17:05:10 +0800693 } else {
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100694 dev_priv->regfile.saveFBC_CFB_BASE = I915_READ(FBC_CFB_BASE);
695 dev_priv->regfile.saveFBC_LL_BASE = I915_READ(FBC_LL_BASE);
696 dev_priv->regfile.saveFBC_CONTROL2 = I915_READ(FBC_CONTROL2);
697 dev_priv->regfile.saveFBC_CONTROL = I915_READ(FBC_CONTROL);
Zhao Yakuia2c459e2010-03-19 17:05:10 +0800698 }
Jesse Barnes06027f92009-10-05 13:47:26 -0700699 }
Jesse Barnes317c35d2008-08-25 15:11:06 -0700700
Jesse Barnes317c35d2008-08-25 15:11:06 -0700701 /* VGA state */
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100702 dev_priv->regfile.saveVGA0 = I915_READ(VGA0);
703 dev_priv->regfile.saveVGA1 = I915_READ(VGA1);
704 dev_priv->regfile.saveVGA_PD = I915_READ(VGA_PD);
Chris Wilson90eb77b2010-08-14 14:41:23 +0100705 if (HAS_PCH_SPLIT(dev))
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100706 dev_priv->regfile.saveVGACNTRL = I915_READ(CPU_VGACNTRL);
Zhenyu Wang42048782009-10-21 15:27:01 +0800707 else
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100708 dev_priv->regfile.saveVGACNTRL = I915_READ(VGACNTRL);
Jesse Barnes317c35d2008-08-25 15:11:06 -0700709
Jesse Barnes317c35d2008-08-25 15:11:06 -0700710 i915_save_vga(dev);
Jesse Barnes317c35d2008-08-25 15:11:06 -0700711}
712
Keith Packardd70bed12011-06-29 00:30:34 -0700713static void i915_restore_display(struct drm_device *dev)
Jesse Barnes317c35d2008-08-25 15:11:06 -0700714{
715 struct drm_i915_private *dev_priv = dev->dev_private;
Peng Li461cba22008-11-18 12:39:02 +0800716
Keith Packard881ee982008-11-02 23:08:44 -0800717 /* Display arbitration */
Paulo Zanoni8de0add2013-01-18 18:29:03 -0200718 if (INTEL_INFO(dev)->gen <= 4)
719 I915_WRITE(DSPARB, dev_priv->regfile.saveDSPARB);
Jesse Barnes317c35d2008-08-25 15:11:06 -0700720
Daniel Vetter2e9723a2013-01-25 17:53:19 +0100721 if (!drm_core_check_feature(dev, DRIVER_MODESET))
722 i915_restore_modeset_reg(dev);
Ben Gamari1341d652009-09-14 17:48:42 -0400723
Jesse Barnes317c35d2008-08-25 15:11:06 -0700724 /* LVDS state */
Chris Wilsona6c45cf2010-09-17 00:32:17 +0100725 if (INTEL_INFO(dev)->gen >= 4 && !HAS_PCH_SPLIT(dev))
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100726 I915_WRITE(BLC_PWM_CTL2, dev_priv->regfile.saveBLC_PWM_CTL2);
Zhenyu Wang42048782009-10-21 15:27:01 +0800727
Chris Wilson90eb77b2010-08-14 14:41:23 +0100728 if (HAS_PCH_SPLIT(dev)) {
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100729 I915_WRITE(PCH_LVDS, dev_priv->regfile.saveLVDS);
Zhenyu Wang42048782009-10-21 15:27:01 +0800730 } else if (IS_MOBILE(dev) && !IS_I830(dev))
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100731 I915_WRITE(LVDS, dev_priv->regfile.saveLVDS);
Zhenyu Wang42048782009-10-21 15:27:01 +0800732
Chris Wilson90eb77b2010-08-14 14:41:23 +0100733 if (!IS_I830(dev) && !IS_845G(dev) && !HAS_PCH_SPLIT(dev))
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100734 I915_WRITE(PFIT_CONTROL, dev_priv->regfile.savePFIT_CONTROL);
Jesse Barnes317c35d2008-08-25 15:11:06 -0700735
Chris Wilson90eb77b2010-08-14 14:41:23 +0100736 if (HAS_PCH_SPLIT(dev)) {
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100737 I915_WRITE(BLC_PWM_PCH_CTL1, dev_priv->regfile.saveBLC_PWM_CTL);
738 I915_WRITE(BLC_PWM_PCH_CTL2, dev_priv->regfile.saveBLC_PWM_CTL2);
Takashi Iwai6db65cb2012-06-21 15:30:41 +0200739 /* NOTE: BLC_PWM_CPU_CTL must be written after BLC_PWM_CPU_CTL2;
740 * otherwise we get blank eDP screen after S3 on some machines
741 */
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100742 I915_WRITE(BLC_PWM_CPU_CTL2, dev_priv->regfile.saveBLC_CPU_PWM_CTL2);
743 I915_WRITE(BLC_PWM_CPU_CTL, dev_priv->regfile.saveBLC_CPU_PWM_CTL);
744 I915_WRITE(PCH_PP_ON_DELAYS, dev_priv->regfile.savePP_ON_DELAYS);
745 I915_WRITE(PCH_PP_OFF_DELAYS, dev_priv->regfile.savePP_OFF_DELAYS);
746 I915_WRITE(PCH_PP_DIVISOR, dev_priv->regfile.savePP_DIVISOR);
747 I915_WRITE(PCH_PP_CONTROL, dev_priv->regfile.savePP_CONTROL);
Jesse Barnes88271da2011-01-05 12:01:24 -0800748 I915_WRITE(RSTDBYCTL,
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100749 dev_priv->regfile.saveMCHBAR_RENDER_STANDBY);
Zhenyu Wang42048782009-10-21 15:27:01 +0800750 } else {
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100751 I915_WRITE(PFIT_PGM_RATIOS, dev_priv->regfile.savePFIT_PGM_RATIOS);
752 I915_WRITE(BLC_PWM_CTL, dev_priv->regfile.saveBLC_PWM_CTL);
753 I915_WRITE(BLC_HIST_CTL, dev_priv->regfile.saveBLC_HIST_CTL);
754 I915_WRITE(PP_ON_DELAYS, dev_priv->regfile.savePP_ON_DELAYS);
755 I915_WRITE(PP_OFF_DELAYS, dev_priv->regfile.savePP_OFF_DELAYS);
756 I915_WRITE(PP_DIVISOR, dev_priv->regfile.savePP_DIVISOR);
757 I915_WRITE(PP_CONTROL, dev_priv->regfile.savePP_CONTROL);
Zhenyu Wang42048782009-10-21 15:27:01 +0800758 }
Jesse Barnes317c35d2008-08-25 15:11:06 -0700759
Daniel Vetterf81183f2012-10-17 11:32:55 +0200760 if (!drm_core_check_feature(dev, DRIVER_MODESET)) {
761 /* Display Port state */
762 if (SUPPORTS_INTEGRATED_DP(dev)) {
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100763 I915_WRITE(DP_B, dev_priv->regfile.saveDP_B);
764 I915_WRITE(DP_C, dev_priv->regfile.saveDP_C);
765 I915_WRITE(DP_D, dev_priv->regfile.saveDP_D);
Daniel Vetterf81183f2012-10-17 11:32:55 +0200766 }
767 /* FIXME: restore TV & SDVO state */
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700768 }
Jesse Barnes317c35d2008-08-25 15:11:06 -0700769
Zhao Yakuia2c459e2010-03-19 17:05:10 +0800770 /* only restore FBC info on the platform that supports FBC*/
Chris Wilson43a95392011-07-08 12:22:36 +0100771 intel_disable_fbc(dev);
Zhao Yakuia2c459e2010-03-19 17:05:10 +0800772 if (I915_HAS_FBC(dev)) {
Chris Wilson90eb77b2010-08-14 14:41:23 +0100773 if (HAS_PCH_SPLIT(dev)) {
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100774 I915_WRITE(ILK_DPFC_CB_BASE, dev_priv->regfile.saveDPFC_CB_BASE);
Zhao Yakuib52eb4d2010-06-12 14:32:27 +0800775 } else if (IS_GM45(dev)) {
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100776 I915_WRITE(DPFC_CB_BASE, dev_priv->regfile.saveDPFC_CB_BASE);
Zhao Yakuia2c459e2010-03-19 17:05:10 +0800777 } else {
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100778 I915_WRITE(FBC_CFB_BASE, dev_priv->regfile.saveFBC_CFB_BASE);
779 I915_WRITE(FBC_LL_BASE, dev_priv->regfile.saveFBC_LL_BASE);
780 I915_WRITE(FBC_CONTROL2, dev_priv->regfile.saveFBC_CONTROL2);
781 I915_WRITE(FBC_CONTROL, dev_priv->regfile.saveFBC_CONTROL);
Zhao Yakuia2c459e2010-03-19 17:05:10 +0800782 }
Jesse Barnes06027f92009-10-05 13:47:26 -0700783 }
Jesse Barnes317c35d2008-08-25 15:11:06 -0700784 /* VGA state */
Chris Wilson90eb77b2010-08-14 14:41:23 +0100785 if (HAS_PCH_SPLIT(dev))
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100786 I915_WRITE(CPU_VGACNTRL, dev_priv->regfile.saveVGACNTRL);
Zhenyu Wang42048782009-10-21 15:27:01 +0800787 else
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100788 I915_WRITE(VGACNTRL, dev_priv->regfile.saveVGACNTRL);
Ben Widawsky483f1792011-06-22 09:55:01 -0700789
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100790 I915_WRITE(VGA0, dev_priv->regfile.saveVGA0);
791 I915_WRITE(VGA1, dev_priv->regfile.saveVGA1);
792 I915_WRITE(VGA_PD, dev_priv->regfile.saveVGA_PD);
Chris Wilson72bcb262010-08-14 14:41:22 +0100793 POSTING_READ(VGA_PD);
794 udelay(150);
Jesse Barnes317c35d2008-08-25 15:11:06 -0700795
Ben Gamari1341d652009-09-14 17:48:42 -0400796 i915_restore_vga(dev);
797}
798
799int i915_save_state(struct drm_device *dev)
800{
801 struct drm_i915_private *dev_priv = dev->dev_private;
802 int i;
803
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100804 pci_read_config_byte(dev->pdev, LBB, &dev_priv->regfile.saveLBB);
Ben Gamari1341d652009-09-14 17:48:42 -0400805
Keith Packardd70bed12011-06-29 00:30:34 -0700806 mutex_lock(&dev->struct_mutex);
807
Ben Gamari1341d652009-09-14 17:48:42 -0400808 i915_save_display(dev);
809
Daniel Vetter905c27b2012-10-17 11:32:56 +0200810 if (!drm_core_check_feature(dev, DRIVER_MODESET)) {
811 /* Interrupt state */
812 if (HAS_PCH_SPLIT(dev)) {
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100813 dev_priv->regfile.saveDEIER = I915_READ(DEIER);
814 dev_priv->regfile.saveDEIMR = I915_READ(DEIMR);
815 dev_priv->regfile.saveGTIER = I915_READ(GTIER);
816 dev_priv->regfile.saveGTIMR = I915_READ(GTIMR);
817 dev_priv->regfile.saveFDI_RXA_IMR = I915_READ(_FDI_RXA_IMR);
818 dev_priv->regfile.saveFDI_RXB_IMR = I915_READ(_FDI_RXB_IMR);
819 dev_priv->regfile.saveMCHBAR_RENDER_STANDBY =
Daniel Vetter905c27b2012-10-17 11:32:56 +0200820 I915_READ(RSTDBYCTL);
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100821 dev_priv->regfile.savePCH_PORT_HOTPLUG = I915_READ(PCH_PORT_HOTPLUG);
Daniel Vetter905c27b2012-10-17 11:32:56 +0200822 } else {
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100823 dev_priv->regfile.saveIER = I915_READ(IER);
824 dev_priv->regfile.saveIMR = I915_READ(IMR);
Daniel Vetter905c27b2012-10-17 11:32:56 +0200825 }
Zhenyu Wang42048782009-10-21 15:27:01 +0800826 }
Ben Gamari1341d652009-09-14 17:48:42 -0400827
Daniel Vetter8090c6b2012-06-24 16:42:32 +0200828 intel_disable_gt_powersave(dev);
Jesse Barnesf97108d2010-01-29 11:27:07 -0800829
Ben Gamari1341d652009-09-14 17:48:42 -0400830 /* Cache mode state */
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100831 dev_priv->regfile.saveCACHE_MODE_0 = I915_READ(CACHE_MODE_0);
Ben Gamari1341d652009-09-14 17:48:42 -0400832
833 /* Memory Arbitration state */
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100834 dev_priv->regfile.saveMI_ARB_STATE = I915_READ(MI_ARB_STATE);
Ben Gamari1341d652009-09-14 17:48:42 -0400835
836 /* Scratch space */
837 for (i = 0; i < 16; i++) {
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100838 dev_priv->regfile.saveSWF0[i] = I915_READ(SWF00 + (i << 2));
839 dev_priv->regfile.saveSWF1[i] = I915_READ(SWF10 + (i << 2));
Ben Gamari1341d652009-09-14 17:48:42 -0400840 }
841 for (i = 0; i < 3; i++)
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100842 dev_priv->regfile.saveSWF2[i] = I915_READ(SWF30 + (i << 2));
Ben Gamari1341d652009-09-14 17:48:42 -0400843
Keith Packardd70bed12011-06-29 00:30:34 -0700844 mutex_unlock(&dev->struct_mutex);
845
Ben Gamari1341d652009-09-14 17:48:42 -0400846 return 0;
847}
848
849int i915_restore_state(struct drm_device *dev)
850{
851 struct drm_i915_private *dev_priv = dev->dev_private;
852 int i;
853
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100854 pci_write_config_byte(dev->pdev, LBB, dev_priv->regfile.saveLBB);
Ben Gamari1341d652009-09-14 17:48:42 -0400855
Keith Packardd70bed12011-06-29 00:30:34 -0700856 mutex_lock(&dev->struct_mutex);
857
Ben Gamari1341d652009-09-14 17:48:42 -0400858 i915_restore_display(dev);
859
Daniel Vetter905c27b2012-10-17 11:32:56 +0200860 if (!drm_core_check_feature(dev, DRIVER_MODESET)) {
861 /* Interrupt state */
862 if (HAS_PCH_SPLIT(dev)) {
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100863 I915_WRITE(DEIER, dev_priv->regfile.saveDEIER);
864 I915_WRITE(DEIMR, dev_priv->regfile.saveDEIMR);
865 I915_WRITE(GTIER, dev_priv->regfile.saveGTIER);
866 I915_WRITE(GTIMR, dev_priv->regfile.saveGTIMR);
867 I915_WRITE(_FDI_RXA_IMR, dev_priv->regfile.saveFDI_RXA_IMR);
868 I915_WRITE(_FDI_RXB_IMR, dev_priv->regfile.saveFDI_RXB_IMR);
869 I915_WRITE(PCH_PORT_HOTPLUG, dev_priv->regfile.savePCH_PORT_HOTPLUG);
Daniel Vetter905c27b2012-10-17 11:32:56 +0200870 } else {
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100871 I915_WRITE(IER, dev_priv->regfile.saveIER);
872 I915_WRITE(IMR, dev_priv->regfile.saveIMR);
Daniel Vetter905c27b2012-10-17 11:32:56 +0200873 }
Zhenyu Wang42048782009-10-21 15:27:01 +0800874 }
Keith Packardd70bed12011-06-29 00:30:34 -0700875
Jesse Barnes317c35d2008-08-25 15:11:06 -0700876 /* Cache mode state */
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100877 I915_WRITE(CACHE_MODE_0, dev_priv->regfile.saveCACHE_MODE_0 | 0xffff0000);
Jesse Barnes317c35d2008-08-25 15:11:06 -0700878
879 /* Memory arbitration state */
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100880 I915_WRITE(MI_ARB_STATE, dev_priv->regfile.saveMI_ARB_STATE | 0xffff0000);
Jesse Barnes317c35d2008-08-25 15:11:06 -0700881
882 for (i = 0; i < 16; i++) {
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100883 I915_WRITE(SWF00 + (i << 2), dev_priv->regfile.saveSWF0[i]);
884 I915_WRITE(SWF10 + (i << 2), dev_priv->regfile.saveSWF1[i]);
Jesse Barnes317c35d2008-08-25 15:11:06 -0700885 }
886 for (i = 0; i < 3; i++)
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100887 I915_WRITE(SWF30 + (i << 2), dev_priv->regfile.saveSWF2[i]);
Jesse Barnes317c35d2008-08-25 15:11:06 -0700888
Keith Packardd70bed12011-06-29 00:30:34 -0700889 mutex_unlock(&dev->struct_mutex);
890
Chris Wilsonf899fc62010-07-20 15:44:45 -0700891 intel_i2c_reset(dev);
Eric Anholtf0217c42009-12-01 11:56:30 -0800892
Jesse Barnes317c35d2008-08-25 15:11:06 -0700893 return 0;
894}