xref: /openbmc/linux/drivers/gpu/drm/i915/i915_suspend.c (revision 5e5b7fa2ad84f7806d0c7f5af8e1440bc91b4ec7)
1317c35d1SJesse Barnes /*
2317c35d1SJesse Barnes  *
3317c35d1SJesse Barnes  * Copyright 2008 (c) Intel Corporation
4317c35d1SJesse Barnes  *   Jesse Barnes <jbarnes@virtuousgeek.org>
5317c35d1SJesse Barnes  *
6317c35d1SJesse Barnes  * Permission is hereby granted, free of charge, to any person obtaining a
7317c35d1SJesse Barnes  * copy of this software and associated documentation files (the
8317c35d1SJesse Barnes  * "Software"), to deal in the Software without restriction, including
9317c35d1SJesse Barnes  * without limitation the rights to use, copy, modify, merge, publish,
10317c35d1SJesse Barnes  * distribute, sub license, and/or sell copies of the Software, and to
11317c35d1SJesse Barnes  * permit persons to whom the Software is furnished to do so, subject to
12317c35d1SJesse Barnes  * the following conditions:
13317c35d1SJesse Barnes  *
14317c35d1SJesse Barnes  * The above copyright notice and this permission notice (including the
15317c35d1SJesse Barnes  * next paragraph) shall be included in all copies or substantial portions
16317c35d1SJesse Barnes  * of the Software.
17317c35d1SJesse Barnes  *
18317c35d1SJesse Barnes  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19317c35d1SJesse Barnes  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20317c35d1SJesse Barnes  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21317c35d1SJesse Barnes  * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22317c35d1SJesse Barnes  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23317c35d1SJesse Barnes  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24317c35d1SJesse Barnes  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25317c35d1SJesse Barnes  */
26317c35d1SJesse Barnes 
27317c35d1SJesse Barnes #include "drmP.h"
28317c35d1SJesse Barnes #include "drm.h"
29317c35d1SJesse Barnes #include "i915_drm.h"
30f0217c42SEric Anholt #include "intel_drv.h"
31*5e5b7fa2SEugeni Dodonov #include "i915_reg.h"
32317c35d1SJesse Barnes 
33317c35d1SJesse Barnes static bool i915_pipe_enabled(struct drm_device *dev, enum pipe pipe)
34317c35d1SJesse Barnes {
35317c35d1SJesse Barnes 	struct drm_i915_private *dev_priv = dev->dev_private;
3642048781SZhenyu Wang 	u32	dpll_reg;
37317c35d1SJesse Barnes 
389db4a9c7SJesse Barnes 	if (HAS_PCH_SPLIT(dev))
39*5e5b7fa2SEugeni Dodonov 		dpll_reg = PCH_DPLL(pipe);
409db4a9c7SJesse Barnes 	else
419db4a9c7SJesse Barnes 		dpll_reg = (pipe == PIPE_A) ? _DPLL_A : _DPLL_B;
4242048781SZhenyu Wang 
4342048781SZhenyu Wang 	return (I915_READ(dpll_reg) & DPLL_VCO_ENABLE);
44317c35d1SJesse Barnes }
45317c35d1SJesse Barnes 
46317c35d1SJesse Barnes static void i915_save_palette(struct drm_device *dev, enum pipe pipe)
47317c35d1SJesse Barnes {
48317c35d1SJesse Barnes 	struct drm_i915_private *dev_priv = dev->dev_private;
499db4a9c7SJesse Barnes 	unsigned long reg = (pipe == PIPE_A ? _PALETTE_A : _PALETTE_B);
50317c35d1SJesse Barnes 	u32 *array;
51317c35d1SJesse Barnes 	int i;
52317c35d1SJesse Barnes 
53317c35d1SJesse Barnes 	if (!i915_pipe_enabled(dev, pipe))
54317c35d1SJesse Barnes 		return;
55317c35d1SJesse Barnes 
5690eb77baSChris Wilson 	if (HAS_PCH_SPLIT(dev))
579db4a9c7SJesse Barnes 		reg = (pipe == PIPE_A) ? _LGC_PALETTE_A : _LGC_PALETTE_B;
5842048781SZhenyu Wang 
59317c35d1SJesse Barnes 	if (pipe == PIPE_A)
60317c35d1SJesse Barnes 		array = dev_priv->save_palette_a;
61317c35d1SJesse Barnes 	else
62317c35d1SJesse Barnes 		array = dev_priv->save_palette_b;
63317c35d1SJesse Barnes 
64317c35d1SJesse Barnes 	for (i = 0; i < 256; i++)
65317c35d1SJesse Barnes 		array[i] = I915_READ(reg + (i << 2));
66317c35d1SJesse Barnes }
67317c35d1SJesse Barnes 
68317c35d1SJesse Barnes static void i915_restore_palette(struct drm_device *dev, enum pipe pipe)
69317c35d1SJesse Barnes {
70317c35d1SJesse Barnes 	struct drm_i915_private *dev_priv = dev->dev_private;
719db4a9c7SJesse Barnes 	unsigned long reg = (pipe == PIPE_A ? _PALETTE_A : _PALETTE_B);
72317c35d1SJesse Barnes 	u32 *array;
73317c35d1SJesse Barnes 	int i;
74317c35d1SJesse Barnes 
75317c35d1SJesse Barnes 	if (!i915_pipe_enabled(dev, pipe))
76317c35d1SJesse Barnes 		return;
77317c35d1SJesse Barnes 
7890eb77baSChris Wilson 	if (HAS_PCH_SPLIT(dev))
799db4a9c7SJesse Barnes 		reg = (pipe == PIPE_A) ? _LGC_PALETTE_A : _LGC_PALETTE_B;
8042048781SZhenyu Wang 
81317c35d1SJesse Barnes 	if (pipe == PIPE_A)
82317c35d1SJesse Barnes 		array = dev_priv->save_palette_a;
83317c35d1SJesse Barnes 	else
84317c35d1SJesse Barnes 		array = dev_priv->save_palette_b;
85317c35d1SJesse Barnes 
86317c35d1SJesse Barnes 	for (i = 0; i < 256; i++)
87317c35d1SJesse Barnes 		I915_WRITE(reg + (i << 2), array[i]);
88317c35d1SJesse Barnes }
89317c35d1SJesse Barnes 
90317c35d1SJesse Barnes static u8 i915_read_indexed(struct drm_device *dev, u16 index_port, u16 data_port, u8 reg)
91317c35d1SJesse Barnes {
92317c35d1SJesse Barnes 	struct drm_i915_private *dev_priv = dev->dev_private;
93317c35d1SJesse Barnes 
94317c35d1SJesse Barnes 	I915_WRITE8(index_port, reg);
95317c35d1SJesse Barnes 	return I915_READ8(data_port);
96317c35d1SJesse Barnes }
97317c35d1SJesse Barnes 
98317c35d1SJesse Barnes static u8 i915_read_ar(struct drm_device *dev, u16 st01, u8 reg, u16 palette_enable)
99317c35d1SJesse Barnes {
100317c35d1SJesse Barnes 	struct drm_i915_private *dev_priv = dev->dev_private;
101317c35d1SJesse Barnes 
102317c35d1SJesse Barnes 	I915_READ8(st01);
103317c35d1SJesse Barnes 	I915_WRITE8(VGA_AR_INDEX, palette_enable | reg);
104317c35d1SJesse Barnes 	return I915_READ8(VGA_AR_DATA_READ);
105317c35d1SJesse Barnes }
106317c35d1SJesse Barnes 
107317c35d1SJesse Barnes static void i915_write_ar(struct drm_device *dev, u16 st01, u8 reg, u8 val, u16 palette_enable)
108317c35d1SJesse Barnes {
109317c35d1SJesse Barnes 	struct drm_i915_private *dev_priv = dev->dev_private;
110317c35d1SJesse Barnes 
111317c35d1SJesse Barnes 	I915_READ8(st01);
112317c35d1SJesse Barnes 	I915_WRITE8(VGA_AR_INDEX, palette_enable | reg);
113317c35d1SJesse Barnes 	I915_WRITE8(VGA_AR_DATA_WRITE, val);
114317c35d1SJesse Barnes }
115317c35d1SJesse Barnes 
116317c35d1SJesse Barnes static void i915_write_indexed(struct drm_device *dev, u16 index_port, u16 data_port, u8 reg, u8 val)
117317c35d1SJesse Barnes {
118317c35d1SJesse Barnes 	struct drm_i915_private *dev_priv = dev->dev_private;
119317c35d1SJesse Barnes 
120317c35d1SJesse Barnes 	I915_WRITE8(index_port, reg);
121317c35d1SJesse Barnes 	I915_WRITE8(data_port, val);
122317c35d1SJesse Barnes }
123317c35d1SJesse Barnes 
124317c35d1SJesse Barnes static void i915_save_vga(struct drm_device *dev)
125317c35d1SJesse Barnes {
126317c35d1SJesse Barnes 	struct drm_i915_private *dev_priv = dev->dev_private;
127317c35d1SJesse Barnes 	int i;
128317c35d1SJesse Barnes 	u16 cr_index, cr_data, st01;
129317c35d1SJesse Barnes 
130317c35d1SJesse Barnes 	/* VGA color palette registers */
131317c35d1SJesse Barnes 	dev_priv->saveDACMASK = I915_READ8(VGA_DACMASK);
132317c35d1SJesse Barnes 
133317c35d1SJesse Barnes 	/* MSR bits */
134317c35d1SJesse Barnes 	dev_priv->saveMSR = I915_READ8(VGA_MSR_READ);
135317c35d1SJesse Barnes 	if (dev_priv->saveMSR & VGA_MSR_CGA_MODE) {
136317c35d1SJesse Barnes 		cr_index = VGA_CR_INDEX_CGA;
137317c35d1SJesse Barnes 		cr_data = VGA_CR_DATA_CGA;
138317c35d1SJesse Barnes 		st01 = VGA_ST01_CGA;
139317c35d1SJesse Barnes 	} else {
140317c35d1SJesse Barnes 		cr_index = VGA_CR_INDEX_MDA;
141317c35d1SJesse Barnes 		cr_data = VGA_CR_DATA_MDA;
142317c35d1SJesse Barnes 		st01 = VGA_ST01_MDA;
143317c35d1SJesse Barnes 	}
144317c35d1SJesse Barnes 
145317c35d1SJesse Barnes 	/* CRT controller regs */
146317c35d1SJesse Barnes 	i915_write_indexed(dev, cr_index, cr_data, 0x11,
147317c35d1SJesse Barnes 			   i915_read_indexed(dev, cr_index, cr_data, 0x11) &
148317c35d1SJesse Barnes 			   (~0x80));
149317c35d1SJesse Barnes 	for (i = 0; i <= 0x24; i++)
150317c35d1SJesse Barnes 		dev_priv->saveCR[i] =
151317c35d1SJesse Barnes 			i915_read_indexed(dev, cr_index, cr_data, i);
152317c35d1SJesse Barnes 	/* Make sure we don't turn off CR group 0 writes */
153317c35d1SJesse Barnes 	dev_priv->saveCR[0x11] &= ~0x80;
154317c35d1SJesse Barnes 
155317c35d1SJesse Barnes 	/* Attribute controller registers */
156317c35d1SJesse Barnes 	I915_READ8(st01);
157317c35d1SJesse Barnes 	dev_priv->saveAR_INDEX = I915_READ8(VGA_AR_INDEX);
158317c35d1SJesse Barnes 	for (i = 0; i <= 0x14; i++)
159317c35d1SJesse Barnes 		dev_priv->saveAR[i] = i915_read_ar(dev, st01, i, 0);
160317c35d1SJesse Barnes 	I915_READ8(st01);
161317c35d1SJesse Barnes 	I915_WRITE8(VGA_AR_INDEX, dev_priv->saveAR_INDEX);
162317c35d1SJesse Barnes 	I915_READ8(st01);
163317c35d1SJesse Barnes 
164317c35d1SJesse Barnes 	/* Graphics controller registers */
165317c35d1SJesse Barnes 	for (i = 0; i < 9; i++)
166317c35d1SJesse Barnes 		dev_priv->saveGR[i] =
167317c35d1SJesse Barnes 			i915_read_indexed(dev, VGA_GR_INDEX, VGA_GR_DATA, i);
168317c35d1SJesse Barnes 
169317c35d1SJesse Barnes 	dev_priv->saveGR[0x10] =
170317c35d1SJesse Barnes 		i915_read_indexed(dev, VGA_GR_INDEX, VGA_GR_DATA, 0x10);
171317c35d1SJesse Barnes 	dev_priv->saveGR[0x11] =
172317c35d1SJesse Barnes 		i915_read_indexed(dev, VGA_GR_INDEX, VGA_GR_DATA, 0x11);
173317c35d1SJesse Barnes 	dev_priv->saveGR[0x18] =
174317c35d1SJesse Barnes 		i915_read_indexed(dev, VGA_GR_INDEX, VGA_GR_DATA, 0x18);
175317c35d1SJesse Barnes 
176317c35d1SJesse Barnes 	/* Sequencer registers */
177317c35d1SJesse Barnes 	for (i = 0; i < 8; i++)
178317c35d1SJesse Barnes 		dev_priv->saveSR[i] =
179317c35d1SJesse Barnes 			i915_read_indexed(dev, VGA_SR_INDEX, VGA_SR_DATA, i);
180317c35d1SJesse Barnes }
181317c35d1SJesse Barnes 
182317c35d1SJesse Barnes static void i915_restore_vga(struct drm_device *dev)
183317c35d1SJesse Barnes {
184317c35d1SJesse Barnes 	struct drm_i915_private *dev_priv = dev->dev_private;
185317c35d1SJesse Barnes 	int i;
186317c35d1SJesse Barnes 	u16 cr_index, cr_data, st01;
187317c35d1SJesse Barnes 
188317c35d1SJesse Barnes 	/* MSR bits */
189317c35d1SJesse Barnes 	I915_WRITE8(VGA_MSR_WRITE, dev_priv->saveMSR);
190317c35d1SJesse Barnes 	if (dev_priv->saveMSR & VGA_MSR_CGA_MODE) {
191317c35d1SJesse Barnes 		cr_index = VGA_CR_INDEX_CGA;
192317c35d1SJesse Barnes 		cr_data = VGA_CR_DATA_CGA;
193317c35d1SJesse Barnes 		st01 = VGA_ST01_CGA;
194317c35d1SJesse Barnes 	} else {
195317c35d1SJesse Barnes 		cr_index = VGA_CR_INDEX_MDA;
196317c35d1SJesse Barnes 		cr_data = VGA_CR_DATA_MDA;
197317c35d1SJesse Barnes 		st01 = VGA_ST01_MDA;
198317c35d1SJesse Barnes 	}
199317c35d1SJesse Barnes 
200317c35d1SJesse Barnes 	/* Sequencer registers, don't write SR07 */
201317c35d1SJesse Barnes 	for (i = 0; i < 7; i++)
202317c35d1SJesse Barnes 		i915_write_indexed(dev, VGA_SR_INDEX, VGA_SR_DATA, i,
203317c35d1SJesse Barnes 				   dev_priv->saveSR[i]);
204317c35d1SJesse Barnes 
205317c35d1SJesse Barnes 	/* CRT controller regs */
206317c35d1SJesse Barnes 	/* Enable CR group 0 writes */
207317c35d1SJesse Barnes 	i915_write_indexed(dev, cr_index, cr_data, 0x11, dev_priv->saveCR[0x11]);
208317c35d1SJesse Barnes 	for (i = 0; i <= 0x24; i++)
209317c35d1SJesse Barnes 		i915_write_indexed(dev, cr_index, cr_data, i, dev_priv->saveCR[i]);
210317c35d1SJesse Barnes 
211317c35d1SJesse Barnes 	/* Graphics controller regs */
212317c35d1SJesse Barnes 	for (i = 0; i < 9; i++)
213317c35d1SJesse Barnes 		i915_write_indexed(dev, VGA_GR_INDEX, VGA_GR_DATA, i,
214317c35d1SJesse Barnes 				   dev_priv->saveGR[i]);
215317c35d1SJesse Barnes 
216317c35d1SJesse Barnes 	i915_write_indexed(dev, VGA_GR_INDEX, VGA_GR_DATA, 0x10,
217317c35d1SJesse Barnes 			   dev_priv->saveGR[0x10]);
218317c35d1SJesse Barnes 	i915_write_indexed(dev, VGA_GR_INDEX, VGA_GR_DATA, 0x11,
219317c35d1SJesse Barnes 			   dev_priv->saveGR[0x11]);
220317c35d1SJesse Barnes 	i915_write_indexed(dev, VGA_GR_INDEX, VGA_GR_DATA, 0x18,
221317c35d1SJesse Barnes 			   dev_priv->saveGR[0x18]);
222317c35d1SJesse Barnes 
223317c35d1SJesse Barnes 	/* Attribute controller registers */
224317c35d1SJesse Barnes 	I915_READ8(st01); /* switch back to index mode */
225317c35d1SJesse Barnes 	for (i = 0; i <= 0x14; i++)
226317c35d1SJesse Barnes 		i915_write_ar(dev, st01, i, dev_priv->saveAR[i], 0);
227317c35d1SJesse Barnes 	I915_READ8(st01); /* switch back to index mode */
228317c35d1SJesse Barnes 	I915_WRITE8(VGA_AR_INDEX, dev_priv->saveAR_INDEX | 0x20);
229317c35d1SJesse Barnes 	I915_READ8(st01);
230317c35d1SJesse Barnes 
231317c35d1SJesse Barnes 	/* VGA color palette registers */
232317c35d1SJesse Barnes 	I915_WRITE8(VGA_DACMASK, dev_priv->saveDACMASK);
233317c35d1SJesse Barnes }
234317c35d1SJesse Barnes 
235fccdaba4SZhao Yakui static void i915_save_modeset_reg(struct drm_device *dev)
236317c35d1SJesse Barnes {
237317c35d1SJesse Barnes 	struct drm_i915_private *dev_priv = dev->dev_private;
238312817a3SChris Wilson 	int i;
239317c35d1SJesse Barnes 
240fccdaba4SZhao Yakui 	if (drm_core_check_feature(dev, DRIVER_MODESET))
241fccdaba4SZhao Yakui 		return;
2421341d655SBen Gamari 
243f3c91c1dSChris Wilson 	/* Cursor state */
2449db4a9c7SJesse Barnes 	dev_priv->saveCURACNTR = I915_READ(_CURACNTR);
2459db4a9c7SJesse Barnes 	dev_priv->saveCURAPOS = I915_READ(_CURAPOS);
2469db4a9c7SJesse Barnes 	dev_priv->saveCURABASE = I915_READ(_CURABASE);
2479db4a9c7SJesse Barnes 	dev_priv->saveCURBCNTR = I915_READ(_CURBCNTR);
2489db4a9c7SJesse Barnes 	dev_priv->saveCURBPOS = I915_READ(_CURBPOS);
2499db4a9c7SJesse Barnes 	dev_priv->saveCURBBASE = I915_READ(_CURBBASE);
250f3c91c1dSChris Wilson 	if (IS_GEN2(dev))
251f3c91c1dSChris Wilson 		dev_priv->saveCURSIZE = I915_READ(CURSIZE);
252f3c91c1dSChris Wilson 
25390eb77baSChris Wilson 	if (HAS_PCH_SPLIT(dev)) {
2545586c8bcSZhenyu Wang 		dev_priv->savePCH_DREF_CONTROL = I915_READ(PCH_DREF_CONTROL);
2555586c8bcSZhenyu Wang 		dev_priv->saveDISP_ARB_CTL = I915_READ(DISP_ARB_CTL);
2565586c8bcSZhenyu Wang 	}
2575586c8bcSZhenyu Wang 
258317c35d1SJesse Barnes 	/* Pipe & plane A info */
2599db4a9c7SJesse Barnes 	dev_priv->savePIPEACONF = I915_READ(_PIPEACONF);
2609db4a9c7SJesse Barnes 	dev_priv->savePIPEASRC = I915_READ(_PIPEASRC);
26190eb77baSChris Wilson 	if (HAS_PCH_SPLIT(dev)) {
2629db4a9c7SJesse Barnes 		dev_priv->saveFPA0 = I915_READ(_PCH_FPA0);
2639db4a9c7SJesse Barnes 		dev_priv->saveFPA1 = I915_READ(_PCH_FPA1);
2649db4a9c7SJesse Barnes 		dev_priv->saveDPLL_A = I915_READ(_PCH_DPLL_A);
26542048781SZhenyu Wang 	} else {
2669db4a9c7SJesse Barnes 		dev_priv->saveFPA0 = I915_READ(_FPA0);
2679db4a9c7SJesse Barnes 		dev_priv->saveFPA1 = I915_READ(_FPA1);
2689db4a9c7SJesse Barnes 		dev_priv->saveDPLL_A = I915_READ(_DPLL_A);
26942048781SZhenyu Wang 	}
270a6c45cf0SChris Wilson 	if (INTEL_INFO(dev)->gen >= 4 && !HAS_PCH_SPLIT(dev))
2719db4a9c7SJesse Barnes 		dev_priv->saveDPLL_A_MD = I915_READ(_DPLL_A_MD);
2729db4a9c7SJesse Barnes 	dev_priv->saveHTOTAL_A = I915_READ(_HTOTAL_A);
2739db4a9c7SJesse Barnes 	dev_priv->saveHBLANK_A = I915_READ(_HBLANK_A);
2749db4a9c7SJesse Barnes 	dev_priv->saveHSYNC_A = I915_READ(_HSYNC_A);
2759db4a9c7SJesse Barnes 	dev_priv->saveVTOTAL_A = I915_READ(_VTOTAL_A);
2769db4a9c7SJesse Barnes 	dev_priv->saveVBLANK_A = I915_READ(_VBLANK_A);
2779db4a9c7SJesse Barnes 	dev_priv->saveVSYNC_A = I915_READ(_VSYNC_A);
27890eb77baSChris Wilson 	if (!HAS_PCH_SPLIT(dev))
2799db4a9c7SJesse Barnes 		dev_priv->saveBCLRPAT_A = I915_READ(_BCLRPAT_A);
280317c35d1SJesse Barnes 
28190eb77baSChris Wilson 	if (HAS_PCH_SPLIT(dev)) {
2829db4a9c7SJesse Barnes 		dev_priv->savePIPEA_DATA_M1 = I915_READ(_PIPEA_DATA_M1);
2839db4a9c7SJesse Barnes 		dev_priv->savePIPEA_DATA_N1 = I915_READ(_PIPEA_DATA_N1);
2849db4a9c7SJesse Barnes 		dev_priv->savePIPEA_LINK_M1 = I915_READ(_PIPEA_LINK_M1);
2859db4a9c7SJesse Barnes 		dev_priv->savePIPEA_LINK_N1 = I915_READ(_PIPEA_LINK_N1);
2865586c8bcSZhenyu Wang 
2879db4a9c7SJesse Barnes 		dev_priv->saveFDI_TXA_CTL = I915_READ(_FDI_TXA_CTL);
2889db4a9c7SJesse Barnes 		dev_priv->saveFDI_RXA_CTL = I915_READ(_FDI_RXA_CTL);
28942048781SZhenyu Wang 
2909db4a9c7SJesse Barnes 		dev_priv->savePFA_CTL_1 = I915_READ(_PFA_CTL_1);
2919db4a9c7SJesse Barnes 		dev_priv->savePFA_WIN_SZ = I915_READ(_PFA_WIN_SZ);
2929db4a9c7SJesse Barnes 		dev_priv->savePFA_WIN_POS = I915_READ(_PFA_WIN_POS);
29342048781SZhenyu Wang 
2949db4a9c7SJesse Barnes 		dev_priv->saveTRANSACONF = I915_READ(_TRANSACONF);
2959db4a9c7SJesse Barnes 		dev_priv->saveTRANS_HTOTAL_A = I915_READ(_TRANS_HTOTAL_A);
2969db4a9c7SJesse Barnes 		dev_priv->saveTRANS_HBLANK_A = I915_READ(_TRANS_HBLANK_A);
2979db4a9c7SJesse Barnes 		dev_priv->saveTRANS_HSYNC_A = I915_READ(_TRANS_HSYNC_A);
2989db4a9c7SJesse Barnes 		dev_priv->saveTRANS_VTOTAL_A = I915_READ(_TRANS_VTOTAL_A);
2999db4a9c7SJesse Barnes 		dev_priv->saveTRANS_VBLANK_A = I915_READ(_TRANS_VBLANK_A);
3009db4a9c7SJesse Barnes 		dev_priv->saveTRANS_VSYNC_A = I915_READ(_TRANS_VSYNC_A);
30142048781SZhenyu Wang 	}
30242048781SZhenyu Wang 
3039db4a9c7SJesse Barnes 	dev_priv->saveDSPACNTR = I915_READ(_DSPACNTR);
3049db4a9c7SJesse Barnes 	dev_priv->saveDSPASTRIDE = I915_READ(_DSPASTRIDE);
3059db4a9c7SJesse Barnes 	dev_priv->saveDSPASIZE = I915_READ(_DSPASIZE);
3069db4a9c7SJesse Barnes 	dev_priv->saveDSPAPOS = I915_READ(_DSPAPOS);
3079db4a9c7SJesse Barnes 	dev_priv->saveDSPAADDR = I915_READ(_DSPAADDR);
308a6c45cf0SChris Wilson 	if (INTEL_INFO(dev)->gen >= 4) {
3099db4a9c7SJesse Barnes 		dev_priv->saveDSPASURF = I915_READ(_DSPASURF);
3109db4a9c7SJesse Barnes 		dev_priv->saveDSPATILEOFF = I915_READ(_DSPATILEOFF);
311317c35d1SJesse Barnes 	}
312317c35d1SJesse Barnes 	i915_save_palette(dev, PIPE_A);
3139db4a9c7SJesse Barnes 	dev_priv->savePIPEASTAT = I915_READ(_PIPEASTAT);
314317c35d1SJesse Barnes 
315317c35d1SJesse Barnes 	/* Pipe & plane B info */
3169db4a9c7SJesse Barnes 	dev_priv->savePIPEBCONF = I915_READ(_PIPEBCONF);
3179db4a9c7SJesse Barnes 	dev_priv->savePIPEBSRC = I915_READ(_PIPEBSRC);
31890eb77baSChris Wilson 	if (HAS_PCH_SPLIT(dev)) {
3199db4a9c7SJesse Barnes 		dev_priv->saveFPB0 = I915_READ(_PCH_FPB0);
3209db4a9c7SJesse Barnes 		dev_priv->saveFPB1 = I915_READ(_PCH_FPB1);
3219db4a9c7SJesse Barnes 		dev_priv->saveDPLL_B = I915_READ(_PCH_DPLL_B);
32242048781SZhenyu Wang 	} else {
3239db4a9c7SJesse Barnes 		dev_priv->saveFPB0 = I915_READ(_FPB0);
3249db4a9c7SJesse Barnes 		dev_priv->saveFPB1 = I915_READ(_FPB1);
3259db4a9c7SJesse Barnes 		dev_priv->saveDPLL_B = I915_READ(_DPLL_B);
32642048781SZhenyu Wang 	}
327a6c45cf0SChris Wilson 	if (INTEL_INFO(dev)->gen >= 4 && !HAS_PCH_SPLIT(dev))
3289db4a9c7SJesse Barnes 		dev_priv->saveDPLL_B_MD = I915_READ(_DPLL_B_MD);
3299db4a9c7SJesse Barnes 	dev_priv->saveHTOTAL_B = I915_READ(_HTOTAL_B);
3309db4a9c7SJesse Barnes 	dev_priv->saveHBLANK_B = I915_READ(_HBLANK_B);
3319db4a9c7SJesse Barnes 	dev_priv->saveHSYNC_B = I915_READ(_HSYNC_B);
3329db4a9c7SJesse Barnes 	dev_priv->saveVTOTAL_B = I915_READ(_VTOTAL_B);
3339db4a9c7SJesse Barnes 	dev_priv->saveVBLANK_B = I915_READ(_VBLANK_B);
3349db4a9c7SJesse Barnes 	dev_priv->saveVSYNC_B = I915_READ(_VSYNC_B);
33590eb77baSChris Wilson 	if (!HAS_PCH_SPLIT(dev))
3369db4a9c7SJesse Barnes 		dev_priv->saveBCLRPAT_B = I915_READ(_BCLRPAT_B);
33742048781SZhenyu Wang 
33890eb77baSChris Wilson 	if (HAS_PCH_SPLIT(dev)) {
3399db4a9c7SJesse Barnes 		dev_priv->savePIPEB_DATA_M1 = I915_READ(_PIPEB_DATA_M1);
3409db4a9c7SJesse Barnes 		dev_priv->savePIPEB_DATA_N1 = I915_READ(_PIPEB_DATA_N1);
3419db4a9c7SJesse Barnes 		dev_priv->savePIPEB_LINK_M1 = I915_READ(_PIPEB_LINK_M1);
3429db4a9c7SJesse Barnes 		dev_priv->savePIPEB_LINK_N1 = I915_READ(_PIPEB_LINK_N1);
3435586c8bcSZhenyu Wang 
3449db4a9c7SJesse Barnes 		dev_priv->saveFDI_TXB_CTL = I915_READ(_FDI_TXB_CTL);
3459db4a9c7SJesse Barnes 		dev_priv->saveFDI_RXB_CTL = I915_READ(_FDI_RXB_CTL);
34642048781SZhenyu Wang 
3479db4a9c7SJesse Barnes 		dev_priv->savePFB_CTL_1 = I915_READ(_PFB_CTL_1);
3489db4a9c7SJesse Barnes 		dev_priv->savePFB_WIN_SZ = I915_READ(_PFB_WIN_SZ);
3499db4a9c7SJesse Barnes 		dev_priv->savePFB_WIN_POS = I915_READ(_PFB_WIN_POS);
35042048781SZhenyu Wang 
3519db4a9c7SJesse Barnes 		dev_priv->saveTRANSBCONF = I915_READ(_TRANSBCONF);
3529db4a9c7SJesse Barnes 		dev_priv->saveTRANS_HTOTAL_B = I915_READ(_TRANS_HTOTAL_B);
3539db4a9c7SJesse Barnes 		dev_priv->saveTRANS_HBLANK_B = I915_READ(_TRANS_HBLANK_B);
3549db4a9c7SJesse Barnes 		dev_priv->saveTRANS_HSYNC_B = I915_READ(_TRANS_HSYNC_B);
3559db4a9c7SJesse Barnes 		dev_priv->saveTRANS_VTOTAL_B = I915_READ(_TRANS_VTOTAL_B);
3569db4a9c7SJesse Barnes 		dev_priv->saveTRANS_VBLANK_B = I915_READ(_TRANS_VBLANK_B);
3579db4a9c7SJesse Barnes 		dev_priv->saveTRANS_VSYNC_B = I915_READ(_TRANS_VSYNC_B);
35842048781SZhenyu Wang 	}
359317c35d1SJesse Barnes 
3609db4a9c7SJesse Barnes 	dev_priv->saveDSPBCNTR = I915_READ(_DSPBCNTR);
3619db4a9c7SJesse Barnes 	dev_priv->saveDSPBSTRIDE = I915_READ(_DSPBSTRIDE);
3629db4a9c7SJesse Barnes 	dev_priv->saveDSPBSIZE = I915_READ(_DSPBSIZE);
3639db4a9c7SJesse Barnes 	dev_priv->saveDSPBPOS = I915_READ(_DSPBPOS);
3649db4a9c7SJesse Barnes 	dev_priv->saveDSPBADDR = I915_READ(_DSPBADDR);
365a6c45cf0SChris Wilson 	if (INTEL_INFO(dev)->gen >= 4) {
3669db4a9c7SJesse Barnes 		dev_priv->saveDSPBSURF = I915_READ(_DSPBSURF);
3679db4a9c7SJesse Barnes 		dev_priv->saveDSPBTILEOFF = I915_READ(_DSPBTILEOFF);
368317c35d1SJesse Barnes 	}
369317c35d1SJesse Barnes 	i915_save_palette(dev, PIPE_B);
3709db4a9c7SJesse Barnes 	dev_priv->savePIPEBSTAT = I915_READ(_PIPEBSTAT);
371312817a3SChris Wilson 
372312817a3SChris Wilson 	/* Fences */
373312817a3SChris Wilson 	switch (INTEL_INFO(dev)->gen) {
374775d17b6SDaniel Vetter 	case 7:
375312817a3SChris Wilson 	case 6:
376312817a3SChris Wilson 		for (i = 0; i < 16; i++)
377312817a3SChris Wilson 			dev_priv->saveFENCE[i] = I915_READ64(FENCE_REG_SANDYBRIDGE_0 + (i * 8));
378312817a3SChris Wilson 		break;
379312817a3SChris Wilson 	case 5:
380312817a3SChris Wilson 	case 4:
381312817a3SChris Wilson 		for (i = 0; i < 16; i++)
382312817a3SChris Wilson 			dev_priv->saveFENCE[i] = I915_READ64(FENCE_REG_965_0 + (i * 8));
383312817a3SChris Wilson 		break;
384312817a3SChris Wilson 	case 3:
385312817a3SChris Wilson 		if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev))
386312817a3SChris Wilson 			for (i = 0; i < 8; i++)
387312817a3SChris Wilson 				dev_priv->saveFENCE[i+8] = I915_READ(FENCE_REG_945_8 + (i * 4));
388312817a3SChris Wilson 	case 2:
389312817a3SChris Wilson 		for (i = 0; i < 8; i++)
390312817a3SChris Wilson 			dev_priv->saveFENCE[i] = I915_READ(FENCE_REG_830_0 + (i * 4));
391312817a3SChris Wilson 		break;
392312817a3SChris Wilson 	}
393312817a3SChris Wilson 
394fccdaba4SZhao Yakui 	return;
395fccdaba4SZhao Yakui }
3961341d655SBen Gamari 
397fccdaba4SZhao Yakui static void i915_restore_modeset_reg(struct drm_device *dev)
398fccdaba4SZhao Yakui {
399fccdaba4SZhao Yakui 	struct drm_i915_private *dev_priv = dev->dev_private;
40042048781SZhenyu Wang 	int dpll_a_reg, fpa0_reg, fpa1_reg;
40142048781SZhenyu Wang 	int dpll_b_reg, fpb0_reg, fpb1_reg;
402312817a3SChris Wilson 	int i;
403317c35d1SJesse Barnes 
404fccdaba4SZhao Yakui 	if (drm_core_check_feature(dev, DRIVER_MODESET))
405fccdaba4SZhao Yakui 		return;
406fccdaba4SZhao Yakui 
407312817a3SChris Wilson 	/* Fences */
408312817a3SChris Wilson 	switch (INTEL_INFO(dev)->gen) {
409775d17b6SDaniel Vetter 	case 7:
410312817a3SChris Wilson 	case 6:
411312817a3SChris Wilson 		for (i = 0; i < 16; i++)
412312817a3SChris Wilson 			I915_WRITE64(FENCE_REG_SANDYBRIDGE_0 + (i * 8), dev_priv->saveFENCE[i]);
413312817a3SChris Wilson 		break;
414312817a3SChris Wilson 	case 5:
415312817a3SChris Wilson 	case 4:
416312817a3SChris Wilson 		for (i = 0; i < 16; i++)
417312817a3SChris Wilson 			I915_WRITE64(FENCE_REG_965_0 + (i * 8), dev_priv->saveFENCE[i]);
418312817a3SChris Wilson 		break;
419312817a3SChris Wilson 	case 3:
420312817a3SChris Wilson 	case 2:
421312817a3SChris Wilson 		if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev))
422312817a3SChris Wilson 			for (i = 0; i < 8; i++)
423312817a3SChris Wilson 				I915_WRITE(FENCE_REG_945_8 + (i * 4), dev_priv->saveFENCE[i+8]);
424312817a3SChris Wilson 		for (i = 0; i < 8; i++)
425312817a3SChris Wilson 			I915_WRITE(FENCE_REG_830_0 + (i * 4), dev_priv->saveFENCE[i]);
426312817a3SChris Wilson 		break;
427312817a3SChris Wilson 	}
428312817a3SChris Wilson 
429312817a3SChris Wilson 
43090eb77baSChris Wilson 	if (HAS_PCH_SPLIT(dev)) {
4319db4a9c7SJesse Barnes 		dpll_a_reg = _PCH_DPLL_A;
4329db4a9c7SJesse Barnes 		dpll_b_reg = _PCH_DPLL_B;
4339db4a9c7SJesse Barnes 		fpa0_reg = _PCH_FPA0;
4349db4a9c7SJesse Barnes 		fpb0_reg = _PCH_FPB0;
4359db4a9c7SJesse Barnes 		fpa1_reg = _PCH_FPA1;
4369db4a9c7SJesse Barnes 		fpb1_reg = _PCH_FPB1;
43742048781SZhenyu Wang 	} else {
4389db4a9c7SJesse Barnes 		dpll_a_reg = _DPLL_A;
4399db4a9c7SJesse Barnes 		dpll_b_reg = _DPLL_B;
4409db4a9c7SJesse Barnes 		fpa0_reg = _FPA0;
4419db4a9c7SJesse Barnes 		fpb0_reg = _FPB0;
4429db4a9c7SJesse Barnes 		fpa1_reg = _FPA1;
4439db4a9c7SJesse Barnes 		fpb1_reg = _FPB1;
44442048781SZhenyu Wang 	}
44542048781SZhenyu Wang 
44690eb77baSChris Wilson 	if (HAS_PCH_SPLIT(dev)) {
4475586c8bcSZhenyu Wang 		I915_WRITE(PCH_DREF_CONTROL, dev_priv->savePCH_DREF_CONTROL);
4485586c8bcSZhenyu Wang 		I915_WRITE(DISP_ARB_CTL, dev_priv->saveDISP_ARB_CTL);
4495586c8bcSZhenyu Wang 	}
4505586c8bcSZhenyu Wang 
451fccdaba4SZhao Yakui 	/* Pipe & plane A info */
452fccdaba4SZhao Yakui 	/* Prime the clock */
453fccdaba4SZhao Yakui 	if (dev_priv->saveDPLL_A & DPLL_VCO_ENABLE) {
45442048781SZhenyu Wang 		I915_WRITE(dpll_a_reg, dev_priv->saveDPLL_A &
455fccdaba4SZhao Yakui 			   ~DPLL_VCO_ENABLE);
45672bcb269SChris Wilson 		POSTING_READ(dpll_a_reg);
45772bcb269SChris Wilson 		udelay(150);
458fccdaba4SZhao Yakui 	}
45942048781SZhenyu Wang 	I915_WRITE(fpa0_reg, dev_priv->saveFPA0);
46042048781SZhenyu Wang 	I915_WRITE(fpa1_reg, dev_priv->saveFPA1);
461fccdaba4SZhao Yakui 	/* Actually enable it */
46242048781SZhenyu Wang 	I915_WRITE(dpll_a_reg, dev_priv->saveDPLL_A);
46372bcb269SChris Wilson 	POSTING_READ(dpll_a_reg);
46472bcb269SChris Wilson 	udelay(150);
465a6c45cf0SChris Wilson 	if (INTEL_INFO(dev)->gen >= 4 && !HAS_PCH_SPLIT(dev)) {
4669db4a9c7SJesse Barnes 		I915_WRITE(_DPLL_A_MD, dev_priv->saveDPLL_A_MD);
4679db4a9c7SJesse Barnes 		POSTING_READ(_DPLL_A_MD);
46872bcb269SChris Wilson 	}
46972bcb269SChris Wilson 	udelay(150);
470fccdaba4SZhao Yakui 
471fccdaba4SZhao Yakui 	/* Restore mode */
4729db4a9c7SJesse Barnes 	I915_WRITE(_HTOTAL_A, dev_priv->saveHTOTAL_A);
4739db4a9c7SJesse Barnes 	I915_WRITE(_HBLANK_A, dev_priv->saveHBLANK_A);
4749db4a9c7SJesse Barnes 	I915_WRITE(_HSYNC_A, dev_priv->saveHSYNC_A);
4759db4a9c7SJesse Barnes 	I915_WRITE(_VTOTAL_A, dev_priv->saveVTOTAL_A);
4769db4a9c7SJesse Barnes 	I915_WRITE(_VBLANK_A, dev_priv->saveVBLANK_A);
4779db4a9c7SJesse Barnes 	I915_WRITE(_VSYNC_A, dev_priv->saveVSYNC_A);
47890eb77baSChris Wilson 	if (!HAS_PCH_SPLIT(dev))
4799db4a9c7SJesse Barnes 		I915_WRITE(_BCLRPAT_A, dev_priv->saveBCLRPAT_A);
480fccdaba4SZhao Yakui 
48190eb77baSChris Wilson 	if (HAS_PCH_SPLIT(dev)) {
4829db4a9c7SJesse Barnes 		I915_WRITE(_PIPEA_DATA_M1, dev_priv->savePIPEA_DATA_M1);
4839db4a9c7SJesse Barnes 		I915_WRITE(_PIPEA_DATA_N1, dev_priv->savePIPEA_DATA_N1);
4849db4a9c7SJesse Barnes 		I915_WRITE(_PIPEA_LINK_M1, dev_priv->savePIPEA_LINK_M1);
4859db4a9c7SJesse Barnes 		I915_WRITE(_PIPEA_LINK_N1, dev_priv->savePIPEA_LINK_N1);
4865586c8bcSZhenyu Wang 
4879db4a9c7SJesse Barnes 		I915_WRITE(_FDI_RXA_CTL, dev_priv->saveFDI_RXA_CTL);
4889db4a9c7SJesse Barnes 		I915_WRITE(_FDI_TXA_CTL, dev_priv->saveFDI_TXA_CTL);
48942048781SZhenyu Wang 
4909db4a9c7SJesse Barnes 		I915_WRITE(_PFA_CTL_1, dev_priv->savePFA_CTL_1);
4919db4a9c7SJesse Barnes 		I915_WRITE(_PFA_WIN_SZ, dev_priv->savePFA_WIN_SZ);
4929db4a9c7SJesse Barnes 		I915_WRITE(_PFA_WIN_POS, dev_priv->savePFA_WIN_POS);
49342048781SZhenyu Wang 
4949db4a9c7SJesse Barnes 		I915_WRITE(_TRANSACONF, dev_priv->saveTRANSACONF);
4959db4a9c7SJesse Barnes 		I915_WRITE(_TRANS_HTOTAL_A, dev_priv->saveTRANS_HTOTAL_A);
4969db4a9c7SJesse Barnes 		I915_WRITE(_TRANS_HBLANK_A, dev_priv->saveTRANS_HBLANK_A);
4979db4a9c7SJesse Barnes 		I915_WRITE(_TRANS_HSYNC_A, dev_priv->saveTRANS_HSYNC_A);
4989db4a9c7SJesse Barnes 		I915_WRITE(_TRANS_VTOTAL_A, dev_priv->saveTRANS_VTOTAL_A);
4999db4a9c7SJesse Barnes 		I915_WRITE(_TRANS_VBLANK_A, dev_priv->saveTRANS_VBLANK_A);
5009db4a9c7SJesse Barnes 		I915_WRITE(_TRANS_VSYNC_A, dev_priv->saveTRANS_VSYNC_A);
50142048781SZhenyu Wang 	}
50242048781SZhenyu Wang 
503fccdaba4SZhao Yakui 	/* Restore plane info */
5049db4a9c7SJesse Barnes 	I915_WRITE(_DSPASIZE, dev_priv->saveDSPASIZE);
5059db4a9c7SJesse Barnes 	I915_WRITE(_DSPAPOS, dev_priv->saveDSPAPOS);
5069db4a9c7SJesse Barnes 	I915_WRITE(_PIPEASRC, dev_priv->savePIPEASRC);
5079db4a9c7SJesse Barnes 	I915_WRITE(_DSPAADDR, dev_priv->saveDSPAADDR);
5089db4a9c7SJesse Barnes 	I915_WRITE(_DSPASTRIDE, dev_priv->saveDSPASTRIDE);
509a6c45cf0SChris Wilson 	if (INTEL_INFO(dev)->gen >= 4) {
5109db4a9c7SJesse Barnes 		I915_WRITE(_DSPASURF, dev_priv->saveDSPASURF);
5119db4a9c7SJesse Barnes 		I915_WRITE(_DSPATILEOFF, dev_priv->saveDSPATILEOFF);
512fccdaba4SZhao Yakui 	}
513fccdaba4SZhao Yakui 
5149db4a9c7SJesse Barnes 	I915_WRITE(_PIPEACONF, dev_priv->savePIPEACONF);
515fccdaba4SZhao Yakui 
516fccdaba4SZhao Yakui 	i915_restore_palette(dev, PIPE_A);
517fccdaba4SZhao Yakui 	/* Enable the plane */
5189db4a9c7SJesse Barnes 	I915_WRITE(_DSPACNTR, dev_priv->saveDSPACNTR);
5199db4a9c7SJesse Barnes 	I915_WRITE(_DSPAADDR, I915_READ(_DSPAADDR));
520fccdaba4SZhao Yakui 
521fccdaba4SZhao Yakui 	/* Pipe & plane B info */
522fccdaba4SZhao Yakui 	if (dev_priv->saveDPLL_B & DPLL_VCO_ENABLE) {
52342048781SZhenyu Wang 		I915_WRITE(dpll_b_reg, dev_priv->saveDPLL_B &
524fccdaba4SZhao Yakui 			   ~DPLL_VCO_ENABLE);
52572bcb269SChris Wilson 		POSTING_READ(dpll_b_reg);
52672bcb269SChris Wilson 		udelay(150);
527fccdaba4SZhao Yakui 	}
52842048781SZhenyu Wang 	I915_WRITE(fpb0_reg, dev_priv->saveFPB0);
52942048781SZhenyu Wang 	I915_WRITE(fpb1_reg, dev_priv->saveFPB1);
530fccdaba4SZhao Yakui 	/* Actually enable it */
53142048781SZhenyu Wang 	I915_WRITE(dpll_b_reg, dev_priv->saveDPLL_B);
53272bcb269SChris Wilson 	POSTING_READ(dpll_b_reg);
53372bcb269SChris Wilson 	udelay(150);
534a6c45cf0SChris Wilson 	if (INTEL_INFO(dev)->gen >= 4 && !HAS_PCH_SPLIT(dev)) {
5359db4a9c7SJesse Barnes 		I915_WRITE(_DPLL_B_MD, dev_priv->saveDPLL_B_MD);
5369db4a9c7SJesse Barnes 		POSTING_READ(_DPLL_B_MD);
53772bcb269SChris Wilson 	}
53872bcb269SChris Wilson 	udelay(150);
539fccdaba4SZhao Yakui 
540fccdaba4SZhao Yakui 	/* Restore mode */
5419db4a9c7SJesse Barnes 	I915_WRITE(_HTOTAL_B, dev_priv->saveHTOTAL_B);
5429db4a9c7SJesse Barnes 	I915_WRITE(_HBLANK_B, dev_priv->saveHBLANK_B);
5439db4a9c7SJesse Barnes 	I915_WRITE(_HSYNC_B, dev_priv->saveHSYNC_B);
5449db4a9c7SJesse Barnes 	I915_WRITE(_VTOTAL_B, dev_priv->saveVTOTAL_B);
5459db4a9c7SJesse Barnes 	I915_WRITE(_VBLANK_B, dev_priv->saveVBLANK_B);
5469db4a9c7SJesse Barnes 	I915_WRITE(_VSYNC_B, dev_priv->saveVSYNC_B);
54790eb77baSChris Wilson 	if (!HAS_PCH_SPLIT(dev))
5489db4a9c7SJesse Barnes 		I915_WRITE(_BCLRPAT_B, dev_priv->saveBCLRPAT_B);
549fccdaba4SZhao Yakui 
55090eb77baSChris Wilson 	if (HAS_PCH_SPLIT(dev)) {
5519db4a9c7SJesse Barnes 		I915_WRITE(_PIPEB_DATA_M1, dev_priv->savePIPEB_DATA_M1);
5529db4a9c7SJesse Barnes 		I915_WRITE(_PIPEB_DATA_N1, dev_priv->savePIPEB_DATA_N1);
5539db4a9c7SJesse Barnes 		I915_WRITE(_PIPEB_LINK_M1, dev_priv->savePIPEB_LINK_M1);
5549db4a9c7SJesse Barnes 		I915_WRITE(_PIPEB_LINK_N1, dev_priv->savePIPEB_LINK_N1);
5555586c8bcSZhenyu Wang 
5569db4a9c7SJesse Barnes 		I915_WRITE(_FDI_RXB_CTL, dev_priv->saveFDI_RXB_CTL);
5579db4a9c7SJesse Barnes 		I915_WRITE(_FDI_TXB_CTL, dev_priv->saveFDI_TXB_CTL);
55842048781SZhenyu Wang 
5599db4a9c7SJesse Barnes 		I915_WRITE(_PFB_CTL_1, dev_priv->savePFB_CTL_1);
5609db4a9c7SJesse Barnes 		I915_WRITE(_PFB_WIN_SZ, dev_priv->savePFB_WIN_SZ);
5619db4a9c7SJesse Barnes 		I915_WRITE(_PFB_WIN_POS, dev_priv->savePFB_WIN_POS);
56242048781SZhenyu Wang 
5639db4a9c7SJesse Barnes 		I915_WRITE(_TRANSBCONF, dev_priv->saveTRANSBCONF);
5649db4a9c7SJesse Barnes 		I915_WRITE(_TRANS_HTOTAL_B, dev_priv->saveTRANS_HTOTAL_B);
5659db4a9c7SJesse Barnes 		I915_WRITE(_TRANS_HBLANK_B, dev_priv->saveTRANS_HBLANK_B);
5669db4a9c7SJesse Barnes 		I915_WRITE(_TRANS_HSYNC_B, dev_priv->saveTRANS_HSYNC_B);
5679db4a9c7SJesse Barnes 		I915_WRITE(_TRANS_VTOTAL_B, dev_priv->saveTRANS_VTOTAL_B);
5689db4a9c7SJesse Barnes 		I915_WRITE(_TRANS_VBLANK_B, dev_priv->saveTRANS_VBLANK_B);
5699db4a9c7SJesse Barnes 		I915_WRITE(_TRANS_VSYNC_B, dev_priv->saveTRANS_VSYNC_B);
57042048781SZhenyu Wang 	}
57142048781SZhenyu Wang 
572fccdaba4SZhao Yakui 	/* Restore plane info */
5739db4a9c7SJesse Barnes 	I915_WRITE(_DSPBSIZE, dev_priv->saveDSPBSIZE);
5749db4a9c7SJesse Barnes 	I915_WRITE(_DSPBPOS, dev_priv->saveDSPBPOS);
5759db4a9c7SJesse Barnes 	I915_WRITE(_PIPEBSRC, dev_priv->savePIPEBSRC);
5769db4a9c7SJesse Barnes 	I915_WRITE(_DSPBADDR, dev_priv->saveDSPBADDR);
5779db4a9c7SJesse Barnes 	I915_WRITE(_DSPBSTRIDE, dev_priv->saveDSPBSTRIDE);
578a6c45cf0SChris Wilson 	if (INTEL_INFO(dev)->gen >= 4) {
5799db4a9c7SJesse Barnes 		I915_WRITE(_DSPBSURF, dev_priv->saveDSPBSURF);
5809db4a9c7SJesse Barnes 		I915_WRITE(_DSPBTILEOFF, dev_priv->saveDSPBTILEOFF);
581fccdaba4SZhao Yakui 	}
582fccdaba4SZhao Yakui 
5839db4a9c7SJesse Barnes 	I915_WRITE(_PIPEBCONF, dev_priv->savePIPEBCONF);
584fccdaba4SZhao Yakui 
585fccdaba4SZhao Yakui 	i915_restore_palette(dev, PIPE_B);
586fccdaba4SZhao Yakui 	/* Enable the plane */
5879db4a9c7SJesse Barnes 	I915_WRITE(_DSPBCNTR, dev_priv->saveDSPBCNTR);
5889db4a9c7SJesse Barnes 	I915_WRITE(_DSPBADDR, I915_READ(_DSPBADDR));
589fccdaba4SZhao Yakui 
590f3c91c1dSChris Wilson 	/* Cursor state */
5919db4a9c7SJesse Barnes 	I915_WRITE(_CURAPOS, dev_priv->saveCURAPOS);
5929db4a9c7SJesse Barnes 	I915_WRITE(_CURACNTR, dev_priv->saveCURACNTR);
5939db4a9c7SJesse Barnes 	I915_WRITE(_CURABASE, dev_priv->saveCURABASE);
5949db4a9c7SJesse Barnes 	I915_WRITE(_CURBPOS, dev_priv->saveCURBPOS);
5959db4a9c7SJesse Barnes 	I915_WRITE(_CURBCNTR, dev_priv->saveCURBCNTR);
5969db4a9c7SJesse Barnes 	I915_WRITE(_CURBBASE, dev_priv->saveCURBBASE);
597f3c91c1dSChris Wilson 	if (IS_GEN2(dev))
598f3c91c1dSChris Wilson 		I915_WRITE(CURSIZE, dev_priv->saveCURSIZE);
599f3c91c1dSChris Wilson 
600fccdaba4SZhao Yakui 	return;
601fccdaba4SZhao Yakui }
6021341d655SBen Gamari 
603d70bed19SKeith Packard static void i915_save_display(struct drm_device *dev)
604fccdaba4SZhao Yakui {
605fccdaba4SZhao Yakui 	struct drm_i915_private *dev_priv = dev->dev_private;
606fccdaba4SZhao Yakui 
607fccdaba4SZhao Yakui 	/* Display arbitration control */
608fccdaba4SZhao Yakui 	dev_priv->saveDSPARB = I915_READ(DSPARB);
609fccdaba4SZhao Yakui 
610fccdaba4SZhao Yakui 	/* This is only meaningful in non-KMS mode */
611fccdaba4SZhao Yakui 	/* Don't save them in KMS mode */
612fccdaba4SZhao Yakui 	i915_save_modeset_reg(dev);
6131341d655SBen Gamari 
614317c35d1SJesse Barnes 	/* CRT state */
61590eb77baSChris Wilson 	if (HAS_PCH_SPLIT(dev)) {
61642048781SZhenyu Wang 		dev_priv->saveADPA = I915_READ(PCH_ADPA);
61742048781SZhenyu Wang 	} else {
618317c35d1SJesse Barnes 		dev_priv->saveADPA = I915_READ(ADPA);
61942048781SZhenyu Wang 	}
620317c35d1SJesse Barnes 
621317c35d1SJesse Barnes 	/* LVDS state */
62290eb77baSChris Wilson 	if (HAS_PCH_SPLIT(dev)) {
62342048781SZhenyu Wang 		dev_priv->savePP_CONTROL = I915_READ(PCH_PP_CONTROL);
62442048781SZhenyu Wang 		dev_priv->saveBLC_PWM_CTL = I915_READ(BLC_PWM_PCH_CTL1);
62542048781SZhenyu Wang 		dev_priv->saveBLC_PWM_CTL2 = I915_READ(BLC_PWM_PCH_CTL2);
62642048781SZhenyu Wang 		dev_priv->saveBLC_CPU_PWM_CTL = I915_READ(BLC_PWM_CPU_CTL);
62742048781SZhenyu Wang 		dev_priv->saveBLC_CPU_PWM_CTL2 = I915_READ(BLC_PWM_CPU_CTL2);
62842048781SZhenyu Wang 		dev_priv->saveLVDS = I915_READ(PCH_LVDS);
62942048781SZhenyu Wang 	} else {
630317c35d1SJesse Barnes 		dev_priv->savePP_CONTROL = I915_READ(PP_CONTROL);
631317c35d1SJesse Barnes 		dev_priv->savePFIT_PGM_RATIOS = I915_READ(PFIT_PGM_RATIOS);
632317c35d1SJesse Barnes 		dev_priv->saveBLC_PWM_CTL = I915_READ(BLC_PWM_CTL);
6330eb96d6eSJesse Barnes 		dev_priv->saveBLC_HIST_CTL = I915_READ(BLC_HIST_CTL);
634a6c45cf0SChris Wilson 		if (INTEL_INFO(dev)->gen >= 4)
635317c35d1SJesse Barnes 			dev_priv->saveBLC_PWM_CTL2 = I915_READ(BLC_PWM_CTL2);
636317c35d1SJesse Barnes 		if (IS_MOBILE(dev) && !IS_I830(dev))
637317c35d1SJesse Barnes 			dev_priv->saveLVDS = I915_READ(LVDS);
63842048781SZhenyu Wang 	}
63942048781SZhenyu Wang 
64090eb77baSChris Wilson 	if (!IS_I830(dev) && !IS_845G(dev) && !HAS_PCH_SPLIT(dev))
641317c35d1SJesse Barnes 		dev_priv->savePFIT_CONTROL = I915_READ(PFIT_CONTROL);
64242048781SZhenyu Wang 
64390eb77baSChris Wilson 	if (HAS_PCH_SPLIT(dev)) {
64442048781SZhenyu Wang 		dev_priv->savePP_ON_DELAYS = I915_READ(PCH_PP_ON_DELAYS);
64542048781SZhenyu Wang 		dev_priv->savePP_OFF_DELAYS = I915_READ(PCH_PP_OFF_DELAYS);
64642048781SZhenyu Wang 		dev_priv->savePP_DIVISOR = I915_READ(PCH_PP_DIVISOR);
64742048781SZhenyu Wang 	} else {
648317c35d1SJesse Barnes 		dev_priv->savePP_ON_DELAYS = I915_READ(PP_ON_DELAYS);
649317c35d1SJesse Barnes 		dev_priv->savePP_OFF_DELAYS = I915_READ(PP_OFF_DELAYS);
650317c35d1SJesse Barnes 		dev_priv->savePP_DIVISOR = I915_READ(PP_DIVISOR);
65142048781SZhenyu Wang 	}
652317c35d1SJesse Barnes 
653a4fc5ed6SKeith Packard 	/* Display Port state */
654a4fc5ed6SKeith Packard 	if (SUPPORTS_INTEGRATED_DP(dev)) {
655a4fc5ed6SKeith Packard 		dev_priv->saveDP_B = I915_READ(DP_B);
656a4fc5ed6SKeith Packard 		dev_priv->saveDP_C = I915_READ(DP_C);
657a4fc5ed6SKeith Packard 		dev_priv->saveDP_D = I915_READ(DP_D);
6589db4a9c7SJesse Barnes 		dev_priv->savePIPEA_GMCH_DATA_M = I915_READ(_PIPEA_GMCH_DATA_M);
6599db4a9c7SJesse Barnes 		dev_priv->savePIPEB_GMCH_DATA_M = I915_READ(_PIPEB_GMCH_DATA_M);
6609db4a9c7SJesse Barnes 		dev_priv->savePIPEA_GMCH_DATA_N = I915_READ(_PIPEA_GMCH_DATA_N);
6619db4a9c7SJesse Barnes 		dev_priv->savePIPEB_GMCH_DATA_N = I915_READ(_PIPEB_GMCH_DATA_N);
6629db4a9c7SJesse Barnes 		dev_priv->savePIPEA_DP_LINK_M = I915_READ(_PIPEA_DP_LINK_M);
6639db4a9c7SJesse Barnes 		dev_priv->savePIPEB_DP_LINK_M = I915_READ(_PIPEB_DP_LINK_M);
6649db4a9c7SJesse Barnes 		dev_priv->savePIPEA_DP_LINK_N = I915_READ(_PIPEA_DP_LINK_N);
6659db4a9c7SJesse Barnes 		dev_priv->savePIPEB_DP_LINK_N = I915_READ(_PIPEB_DP_LINK_N);
666a4fc5ed6SKeith Packard 	}
667317c35d1SJesse Barnes 	/* FIXME: save TV & SDVO state */
668317c35d1SJesse Barnes 
669a2c459eeSZhao Yakui 	/* Only save FBC state on the platform that supports FBC */
670a2c459eeSZhao Yakui 	if (I915_HAS_FBC(dev)) {
67190eb77baSChris Wilson 		if (HAS_PCH_SPLIT(dev)) {
672b52eb4dcSZhao Yakui 			dev_priv->saveDPFC_CB_BASE = I915_READ(ILK_DPFC_CB_BASE);
673b52eb4dcSZhao Yakui 		} else if (IS_GM45(dev)) {
67406027f91SJesse Barnes 			dev_priv->saveDPFC_CB_BASE = I915_READ(DPFC_CB_BASE);
67506027f91SJesse Barnes 		} else {
676317c35d1SJesse Barnes 			dev_priv->saveFBC_CFB_BASE = I915_READ(FBC_CFB_BASE);
677317c35d1SJesse Barnes 			dev_priv->saveFBC_LL_BASE = I915_READ(FBC_LL_BASE);
678317c35d1SJesse Barnes 			dev_priv->saveFBC_CONTROL2 = I915_READ(FBC_CONTROL2);
679317c35d1SJesse Barnes 			dev_priv->saveFBC_CONTROL = I915_READ(FBC_CONTROL);
68006027f91SJesse Barnes 		}
681a2c459eeSZhao Yakui 	}
682317c35d1SJesse Barnes 
683317c35d1SJesse Barnes 	/* VGA state */
684317c35d1SJesse Barnes 	dev_priv->saveVGA0 = I915_READ(VGA0);
685317c35d1SJesse Barnes 	dev_priv->saveVGA1 = I915_READ(VGA1);
686317c35d1SJesse Barnes 	dev_priv->saveVGA_PD = I915_READ(VGA_PD);
68790eb77baSChris Wilson 	if (HAS_PCH_SPLIT(dev))
68842048781SZhenyu Wang 		dev_priv->saveVGACNTRL = I915_READ(CPU_VGACNTRL);
68942048781SZhenyu Wang 	else
690317c35d1SJesse Barnes 		dev_priv->saveVGACNTRL = I915_READ(VGACNTRL);
691317c35d1SJesse Barnes 
692317c35d1SJesse Barnes 	i915_save_vga(dev);
693317c35d1SJesse Barnes }
694317c35d1SJesse Barnes 
695d70bed19SKeith Packard static void i915_restore_display(struct drm_device *dev)
696317c35d1SJesse Barnes {
697317c35d1SJesse Barnes 	struct drm_i915_private *dev_priv = dev->dev_private;
698461cba2dSPeng Li 
699881ee988SKeith Packard 	/* Display arbitration */
700317c35d1SJesse Barnes 	I915_WRITE(DSPARB, dev_priv->saveDSPARB);
701317c35d1SJesse Barnes 
702a4fc5ed6SKeith Packard 	/* Display port ratios (must be done before clock is set) */
703a4fc5ed6SKeith Packard 	if (SUPPORTS_INTEGRATED_DP(dev)) {
7049db4a9c7SJesse Barnes 		I915_WRITE(_PIPEA_GMCH_DATA_M, dev_priv->savePIPEA_GMCH_DATA_M);
7059db4a9c7SJesse Barnes 		I915_WRITE(_PIPEB_GMCH_DATA_M, dev_priv->savePIPEB_GMCH_DATA_M);
7069db4a9c7SJesse Barnes 		I915_WRITE(_PIPEA_GMCH_DATA_N, dev_priv->savePIPEA_GMCH_DATA_N);
7079db4a9c7SJesse Barnes 		I915_WRITE(_PIPEB_GMCH_DATA_N, dev_priv->savePIPEB_GMCH_DATA_N);
7089db4a9c7SJesse Barnes 		I915_WRITE(_PIPEA_DP_LINK_M, dev_priv->savePIPEA_DP_LINK_M);
7099db4a9c7SJesse Barnes 		I915_WRITE(_PIPEB_DP_LINK_M, dev_priv->savePIPEB_DP_LINK_M);
7109db4a9c7SJesse Barnes 		I915_WRITE(_PIPEA_DP_LINK_N, dev_priv->savePIPEA_DP_LINK_N);
7119db4a9c7SJesse Barnes 		I915_WRITE(_PIPEB_DP_LINK_N, dev_priv->savePIPEB_DP_LINK_N);
712a4fc5ed6SKeith Packard 	}
7131341d655SBen Gamari 
714fccdaba4SZhao Yakui 	/* This is only meaningful in non-KMS mode */
715fccdaba4SZhao Yakui 	/* Don't restore them in KMS mode */
716fccdaba4SZhao Yakui 	i915_restore_modeset_reg(dev);
7171341d655SBen Gamari 
718317c35d1SJesse Barnes 	/* CRT state */
71990eb77baSChris Wilson 	if (HAS_PCH_SPLIT(dev))
72042048781SZhenyu Wang 		I915_WRITE(PCH_ADPA, dev_priv->saveADPA);
72142048781SZhenyu Wang 	else
722317c35d1SJesse Barnes 		I915_WRITE(ADPA, dev_priv->saveADPA);
723317c35d1SJesse Barnes 
724317c35d1SJesse Barnes 	/* LVDS state */
725a6c45cf0SChris Wilson 	if (INTEL_INFO(dev)->gen >= 4 && !HAS_PCH_SPLIT(dev))
726317c35d1SJesse Barnes 		I915_WRITE(BLC_PWM_CTL2, dev_priv->saveBLC_PWM_CTL2);
72742048781SZhenyu Wang 
72890eb77baSChris Wilson 	if (HAS_PCH_SPLIT(dev)) {
72942048781SZhenyu Wang 		I915_WRITE(PCH_LVDS, dev_priv->saveLVDS);
73042048781SZhenyu Wang 	} else if (IS_MOBILE(dev) && !IS_I830(dev))
731317c35d1SJesse Barnes 		I915_WRITE(LVDS, dev_priv->saveLVDS);
73242048781SZhenyu Wang 
73390eb77baSChris Wilson 	if (!IS_I830(dev) && !IS_845G(dev) && !HAS_PCH_SPLIT(dev))
734317c35d1SJesse Barnes 		I915_WRITE(PFIT_CONTROL, dev_priv->savePFIT_CONTROL);
735317c35d1SJesse Barnes 
73690eb77baSChris Wilson 	if (HAS_PCH_SPLIT(dev)) {
73742048781SZhenyu Wang 		I915_WRITE(BLC_PWM_PCH_CTL1, dev_priv->saveBLC_PWM_CTL);
73842048781SZhenyu Wang 		I915_WRITE(BLC_PWM_PCH_CTL2, dev_priv->saveBLC_PWM_CTL2);
73942048781SZhenyu Wang 		I915_WRITE(BLC_PWM_CPU_CTL, dev_priv->saveBLC_CPU_PWM_CTL);
74042048781SZhenyu Wang 		I915_WRITE(BLC_PWM_CPU_CTL2, dev_priv->saveBLC_CPU_PWM_CTL2);
74142048781SZhenyu Wang 		I915_WRITE(PCH_PP_ON_DELAYS, dev_priv->savePP_ON_DELAYS);
74242048781SZhenyu Wang 		I915_WRITE(PCH_PP_OFF_DELAYS, dev_priv->savePP_OFF_DELAYS);
74342048781SZhenyu Wang 		I915_WRITE(PCH_PP_DIVISOR, dev_priv->savePP_DIVISOR);
74442048781SZhenyu Wang 		I915_WRITE(PCH_PP_CONTROL, dev_priv->savePP_CONTROL);
74588271da3SJesse Barnes 		I915_WRITE(RSTDBYCTL,
746b5b72e89SMatthew Garrett 			   dev_priv->saveMCHBAR_RENDER_STANDBY);
74742048781SZhenyu Wang 	} else {
748317c35d1SJesse Barnes 		I915_WRITE(PFIT_PGM_RATIOS, dev_priv->savePFIT_PGM_RATIOS);
749317c35d1SJesse Barnes 		I915_WRITE(BLC_PWM_CTL, dev_priv->saveBLC_PWM_CTL);
7500eb96d6eSJesse Barnes 		I915_WRITE(BLC_HIST_CTL, dev_priv->saveBLC_HIST_CTL);
751317c35d1SJesse Barnes 		I915_WRITE(PP_ON_DELAYS, dev_priv->savePP_ON_DELAYS);
752317c35d1SJesse Barnes 		I915_WRITE(PP_OFF_DELAYS, dev_priv->savePP_OFF_DELAYS);
753317c35d1SJesse Barnes 		I915_WRITE(PP_DIVISOR, dev_priv->savePP_DIVISOR);
754317c35d1SJesse Barnes 		I915_WRITE(PP_CONTROL, dev_priv->savePP_CONTROL);
75542048781SZhenyu Wang 	}
756317c35d1SJesse Barnes 
757a4fc5ed6SKeith Packard 	/* Display Port state */
758a4fc5ed6SKeith Packard 	if (SUPPORTS_INTEGRATED_DP(dev)) {
759a4fc5ed6SKeith Packard 		I915_WRITE(DP_B, dev_priv->saveDP_B);
760a4fc5ed6SKeith Packard 		I915_WRITE(DP_C, dev_priv->saveDP_C);
761a4fc5ed6SKeith Packard 		I915_WRITE(DP_D, dev_priv->saveDP_D);
762a4fc5ed6SKeith Packard 	}
763317c35d1SJesse Barnes 	/* FIXME: restore TV & SDVO state */
764317c35d1SJesse Barnes 
765a2c459eeSZhao Yakui 	/* only restore FBC info on the platform that supports FBC*/
76643a9539fSChris Wilson 	intel_disable_fbc(dev);
767a2c459eeSZhao Yakui 	if (I915_HAS_FBC(dev)) {
76890eb77baSChris Wilson 		if (HAS_PCH_SPLIT(dev)) {
769b52eb4dcSZhao Yakui 			I915_WRITE(ILK_DPFC_CB_BASE, dev_priv->saveDPFC_CB_BASE);
770b52eb4dcSZhao Yakui 		} else if (IS_GM45(dev)) {
77106027f91SJesse Barnes 			I915_WRITE(DPFC_CB_BASE, dev_priv->saveDPFC_CB_BASE);
77206027f91SJesse Barnes 		} else {
773317c35d1SJesse Barnes 			I915_WRITE(FBC_CFB_BASE, dev_priv->saveFBC_CFB_BASE);
774317c35d1SJesse Barnes 			I915_WRITE(FBC_LL_BASE, dev_priv->saveFBC_LL_BASE);
775317c35d1SJesse Barnes 			I915_WRITE(FBC_CONTROL2, dev_priv->saveFBC_CONTROL2);
776317c35d1SJesse Barnes 			I915_WRITE(FBC_CONTROL, dev_priv->saveFBC_CONTROL);
77706027f91SJesse Barnes 		}
778a2c459eeSZhao Yakui 	}
779317c35d1SJesse Barnes 	/* VGA state */
78090eb77baSChris Wilson 	if (HAS_PCH_SPLIT(dev))
78142048781SZhenyu Wang 		I915_WRITE(CPU_VGACNTRL, dev_priv->saveVGACNTRL);
78242048781SZhenyu Wang 	else
783317c35d1SJesse Barnes 		I915_WRITE(VGACNTRL, dev_priv->saveVGACNTRL);
784483f1798SBen Widawsky 
785317c35d1SJesse Barnes 	I915_WRITE(VGA0, dev_priv->saveVGA0);
786317c35d1SJesse Barnes 	I915_WRITE(VGA1, dev_priv->saveVGA1);
787317c35d1SJesse Barnes 	I915_WRITE(VGA_PD, dev_priv->saveVGA_PD);
78872bcb269SChris Wilson 	POSTING_READ(VGA_PD);
78972bcb269SChris Wilson 	udelay(150);
790317c35d1SJesse Barnes 
7911341d655SBen Gamari 	i915_restore_vga(dev);
7921341d655SBen Gamari }
7931341d655SBen Gamari 
7941341d655SBen Gamari int i915_save_state(struct drm_device *dev)
7951341d655SBen Gamari {
7961341d655SBen Gamari 	struct drm_i915_private *dev_priv = dev->dev_private;
7971341d655SBen Gamari 	int i;
7981341d655SBen Gamari 
7991341d655SBen Gamari 	pci_read_config_byte(dev->pdev, LBB, &dev_priv->saveLBB);
8001341d655SBen Gamari 
801d70bed19SKeith Packard 	mutex_lock(&dev->struct_mutex);
802d70bed19SKeith Packard 
803968b503eSChris Wilson 	/* Hardware status page */
804968b503eSChris Wilson 	dev_priv->saveHWS = I915_READ(HWS_PGA);
805968b503eSChris Wilson 
8061341d655SBen Gamari 	i915_save_display(dev);
8071341d655SBen Gamari 
8081341d655SBen Gamari 	/* Interrupt state */
80990eb77baSChris Wilson 	if (HAS_PCH_SPLIT(dev)) {
81042048781SZhenyu Wang 		dev_priv->saveDEIER = I915_READ(DEIER);
81142048781SZhenyu Wang 		dev_priv->saveDEIMR = I915_READ(DEIMR);
81242048781SZhenyu Wang 		dev_priv->saveGTIER = I915_READ(GTIER);
81342048781SZhenyu Wang 		dev_priv->saveGTIMR = I915_READ(GTIMR);
8149db4a9c7SJesse Barnes 		dev_priv->saveFDI_RXA_IMR = I915_READ(_FDI_RXA_IMR);
8159db4a9c7SJesse Barnes 		dev_priv->saveFDI_RXB_IMR = I915_READ(_FDI_RXB_IMR);
816b5b72e89SMatthew Garrett 		dev_priv->saveMCHBAR_RENDER_STANDBY =
81788271da3SJesse Barnes 			I915_READ(RSTDBYCTL);
818cda2bb78SAdam Jackson 		dev_priv->savePCH_PORT_HOTPLUG = I915_READ(PCH_PORT_HOTPLUG);
81942048781SZhenyu Wang 	} else {
8201341d655SBen Gamari 		dev_priv->saveIER = I915_READ(IER);
8211341d655SBen Gamari 		dev_priv->saveIMR = I915_READ(IMR);
82242048781SZhenyu Wang 	}
8231341d655SBen Gamari 
8243b8d8d91SJesse Barnes 	if (IS_IRONLAKE_M(dev))
825f97108d1SJesse Barnes 		ironlake_disable_drps(dev);
8263b8d8d91SJesse Barnes 	if (IS_GEN6(dev))
8273b8d8d91SJesse Barnes 		gen6_disable_rps(dev);
828f97108d1SJesse Barnes 
8291341d655SBen Gamari 	/* Cache mode state */
8301341d655SBen Gamari 	dev_priv->saveCACHE_MODE_0 = I915_READ(CACHE_MODE_0);
8311341d655SBen Gamari 
8321341d655SBen Gamari 	/* Memory Arbitration state */
8331341d655SBen Gamari 	dev_priv->saveMI_ARB_STATE = I915_READ(MI_ARB_STATE);
8341341d655SBen Gamari 
8351341d655SBen Gamari 	/* Scratch space */
8361341d655SBen Gamari 	for (i = 0; i < 16; i++) {
8371341d655SBen Gamari 		dev_priv->saveSWF0[i] = I915_READ(SWF00 + (i << 2));
8381341d655SBen Gamari 		dev_priv->saveSWF1[i] = I915_READ(SWF10 + (i << 2));
8391341d655SBen Gamari 	}
8401341d655SBen Gamari 	for (i = 0; i < 3; i++)
8411341d655SBen Gamari 		dev_priv->saveSWF2[i] = I915_READ(SWF30 + (i << 2));
8421341d655SBen Gamari 
843d70bed19SKeith Packard 	mutex_unlock(&dev->struct_mutex);
844d70bed19SKeith Packard 
8451341d655SBen Gamari 	return 0;
8461341d655SBen Gamari }
8471341d655SBen Gamari 
8481341d655SBen Gamari int i915_restore_state(struct drm_device *dev)
8491341d655SBen Gamari {
8501341d655SBen Gamari 	struct drm_i915_private *dev_priv = dev->dev_private;
8511341d655SBen Gamari 	int i;
8521341d655SBen Gamari 
8531341d655SBen Gamari 	pci_write_config_byte(dev->pdev, LBB, dev_priv->saveLBB);
8541341d655SBen Gamari 
855d70bed19SKeith Packard 	mutex_lock(&dev->struct_mutex);
856d70bed19SKeith Packard 
857968b503eSChris Wilson 	/* Hardware status page */
858968b503eSChris Wilson 	I915_WRITE(HWS_PGA, dev_priv->saveHWS);
859968b503eSChris Wilson 
8601341d655SBen Gamari 	i915_restore_display(dev);
8611341d655SBen Gamari 
8621341d655SBen Gamari 	/* Interrupt state */
86390eb77baSChris Wilson 	if (HAS_PCH_SPLIT(dev)) {
86442048781SZhenyu Wang 		I915_WRITE(DEIER, dev_priv->saveDEIER);
86542048781SZhenyu Wang 		I915_WRITE(DEIMR, dev_priv->saveDEIMR);
86642048781SZhenyu Wang 		I915_WRITE(GTIER, dev_priv->saveGTIER);
86742048781SZhenyu Wang 		I915_WRITE(GTIMR, dev_priv->saveGTIMR);
8689db4a9c7SJesse Barnes 		I915_WRITE(_FDI_RXA_IMR, dev_priv->saveFDI_RXA_IMR);
8699db4a9c7SJesse Barnes 		I915_WRITE(_FDI_RXB_IMR, dev_priv->saveFDI_RXB_IMR);
870cda2bb78SAdam Jackson 		I915_WRITE(PCH_PORT_HOTPLUG, dev_priv->savePCH_PORT_HOTPLUG);
87142048781SZhenyu Wang 	} else {
8721341d655SBen Gamari 		I915_WRITE(IER, dev_priv->saveIER);
8731341d655SBen Gamari 		I915_WRITE(IMR, dev_priv->saveIMR);
87442048781SZhenyu Wang 	}
875d70bed19SKeith Packard 	mutex_unlock(&dev->struct_mutex);
8761341d655SBen Gamari 
87792b79f43SKeith Packard 	if (drm_core_check_feature(dev, DRIVER_MODESET))
878645c62a5SJesse Barnes 		intel_init_clock_gating(dev);
879d5bb081bSJesse Barnes 
8803b8d8d91SJesse Barnes 	if (IS_IRONLAKE_M(dev)) {
881f97108d1SJesse Barnes 		ironlake_enable_drps(dev);
88248fcfc88SKyle McMartin 		intel_init_emon(dev);
88348fcfc88SKyle McMartin 	}
884f97108d1SJesse Barnes 
88523b2f8bbSJesse Barnes 	if (IS_GEN6(dev)) {
8863b8d8d91SJesse Barnes 		gen6_enable_rps(dev_priv);
88723b2f8bbSJesse Barnes 		gen6_update_ring_freq(dev_priv);
88823b2f8bbSJesse Barnes 	}
8893b8d8d91SJesse Barnes 
890d70bed19SKeith Packard 	mutex_lock(&dev->struct_mutex);
891d70bed19SKeith Packard 
892317c35d1SJesse Barnes 	/* Cache mode state */
893317c35d1SJesse Barnes 	I915_WRITE(CACHE_MODE_0, dev_priv->saveCACHE_MODE_0 | 0xffff0000);
894317c35d1SJesse Barnes 
895317c35d1SJesse Barnes 	/* Memory arbitration state */
896317c35d1SJesse Barnes 	I915_WRITE(MI_ARB_STATE, dev_priv->saveMI_ARB_STATE | 0xffff0000);
897317c35d1SJesse Barnes 
898317c35d1SJesse Barnes 	for (i = 0; i < 16; i++) {
899317c35d1SJesse Barnes 		I915_WRITE(SWF00 + (i << 2), dev_priv->saveSWF0[i]);
900819e0064SRoel Kluin 		I915_WRITE(SWF10 + (i << 2), dev_priv->saveSWF1[i]);
901317c35d1SJesse Barnes 	}
902317c35d1SJesse Barnes 	for (i = 0; i < 3; i++)
903317c35d1SJesse Barnes 		I915_WRITE(SWF30 + (i << 2), dev_priv->saveSWF2[i]);
904317c35d1SJesse Barnes 
905d70bed19SKeith Packard 	mutex_unlock(&dev->struct_mutex);
906d70bed19SKeith Packard 
907f899fc64SChris Wilson 	intel_i2c_reset(dev);
908f0217c42SEric Anholt 
909317c35d1SJesse Barnes 	return 0;
910317c35d1SJesse Barnes }
911