xref: /openbmc/linux/drivers/gpu/drm/i915/i915_suspend.c (revision 317c35d1446f68b34d4de4e1100fc01680bd4877)
1*317c35d1SJesse Barnes /*
2*317c35d1SJesse Barnes  *
3*317c35d1SJesse Barnes  * Copyright 2008 (c) Intel Corporation
4*317c35d1SJesse Barnes  *   Jesse Barnes <jbarnes@virtuousgeek.org>
5*317c35d1SJesse Barnes  *
6*317c35d1SJesse Barnes  * Permission is hereby granted, free of charge, to any person obtaining a
7*317c35d1SJesse Barnes  * copy of this software and associated documentation files (the
8*317c35d1SJesse Barnes  * "Software"), to deal in the Software without restriction, including
9*317c35d1SJesse Barnes  * without limitation the rights to use, copy, modify, merge, publish,
10*317c35d1SJesse Barnes  * distribute, sub license, and/or sell copies of the Software, and to
11*317c35d1SJesse Barnes  * permit persons to whom the Software is furnished to do so, subject to
12*317c35d1SJesse Barnes  * the following conditions:
13*317c35d1SJesse Barnes  *
14*317c35d1SJesse Barnes  * The above copyright notice and this permission notice (including the
15*317c35d1SJesse Barnes  * next paragraph) shall be included in all copies or substantial portions
16*317c35d1SJesse Barnes  * of the Software.
17*317c35d1SJesse Barnes  *
18*317c35d1SJesse Barnes  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19*317c35d1SJesse Barnes  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20*317c35d1SJesse Barnes  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21*317c35d1SJesse Barnes  * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22*317c35d1SJesse Barnes  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23*317c35d1SJesse Barnes  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24*317c35d1SJesse Barnes  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25*317c35d1SJesse Barnes  */
26*317c35d1SJesse Barnes 
27*317c35d1SJesse Barnes #include "drmP.h"
28*317c35d1SJesse Barnes #include "drm.h"
29*317c35d1SJesse Barnes #include "i915_drm.h"
30*317c35d1SJesse Barnes #include "i915_drv.h"
31*317c35d1SJesse Barnes 
32*317c35d1SJesse Barnes static bool i915_pipe_enabled(struct drm_device *dev, enum pipe pipe)
33*317c35d1SJesse Barnes {
34*317c35d1SJesse Barnes 	struct drm_i915_private *dev_priv = dev->dev_private;
35*317c35d1SJesse Barnes 
36*317c35d1SJesse Barnes 	if (pipe == PIPE_A)
37*317c35d1SJesse Barnes 		return (I915_READ(DPLL_A) & DPLL_VCO_ENABLE);
38*317c35d1SJesse Barnes 	else
39*317c35d1SJesse Barnes 		return (I915_READ(DPLL_B) & DPLL_VCO_ENABLE);
40*317c35d1SJesse Barnes }
41*317c35d1SJesse Barnes 
42*317c35d1SJesse Barnes static void i915_save_palette(struct drm_device *dev, enum pipe pipe)
43*317c35d1SJesse Barnes {
44*317c35d1SJesse Barnes 	struct drm_i915_private *dev_priv = dev->dev_private;
45*317c35d1SJesse Barnes 	unsigned long reg = (pipe == PIPE_A ? PALETTE_A : PALETTE_B);
46*317c35d1SJesse Barnes 	u32 *array;
47*317c35d1SJesse Barnes 	int i;
48*317c35d1SJesse Barnes 
49*317c35d1SJesse Barnes 	if (!i915_pipe_enabled(dev, pipe))
50*317c35d1SJesse Barnes 		return;
51*317c35d1SJesse Barnes 
52*317c35d1SJesse Barnes 	if (pipe == PIPE_A)
53*317c35d1SJesse Barnes 		array = dev_priv->save_palette_a;
54*317c35d1SJesse Barnes 	else
55*317c35d1SJesse Barnes 		array = dev_priv->save_palette_b;
56*317c35d1SJesse Barnes 
57*317c35d1SJesse Barnes 	for(i = 0; i < 256; i++)
58*317c35d1SJesse Barnes 		array[i] = I915_READ(reg + (i << 2));
59*317c35d1SJesse Barnes }
60*317c35d1SJesse Barnes 
61*317c35d1SJesse Barnes static void i915_restore_palette(struct drm_device *dev, enum pipe pipe)
62*317c35d1SJesse Barnes {
63*317c35d1SJesse Barnes 	struct drm_i915_private *dev_priv = dev->dev_private;
64*317c35d1SJesse Barnes 	unsigned long reg = (pipe == PIPE_A ? PALETTE_A : PALETTE_B);
65*317c35d1SJesse Barnes 	u32 *array;
66*317c35d1SJesse Barnes 	int i;
67*317c35d1SJesse Barnes 
68*317c35d1SJesse Barnes 	if (!i915_pipe_enabled(dev, pipe))
69*317c35d1SJesse Barnes 		return;
70*317c35d1SJesse Barnes 
71*317c35d1SJesse Barnes 	if (pipe == PIPE_A)
72*317c35d1SJesse Barnes 		array = dev_priv->save_palette_a;
73*317c35d1SJesse Barnes 	else
74*317c35d1SJesse Barnes 		array = dev_priv->save_palette_b;
75*317c35d1SJesse Barnes 
76*317c35d1SJesse Barnes 	for(i = 0; i < 256; i++)
77*317c35d1SJesse Barnes 		I915_WRITE(reg + (i << 2), array[i]);
78*317c35d1SJesse Barnes }
79*317c35d1SJesse Barnes 
80*317c35d1SJesse Barnes static u8 i915_read_indexed(struct drm_device *dev, u16 index_port, u16 data_port, u8 reg)
81*317c35d1SJesse Barnes {
82*317c35d1SJesse Barnes 	struct drm_i915_private *dev_priv = dev->dev_private;
83*317c35d1SJesse Barnes 
84*317c35d1SJesse Barnes 	I915_WRITE8(index_port, reg);
85*317c35d1SJesse Barnes 	return I915_READ8(data_port);
86*317c35d1SJesse Barnes }
87*317c35d1SJesse Barnes 
88*317c35d1SJesse Barnes static u8 i915_read_ar(struct drm_device *dev, u16 st01, u8 reg, u16 palette_enable)
89*317c35d1SJesse Barnes {
90*317c35d1SJesse Barnes 	struct drm_i915_private *dev_priv = dev->dev_private;
91*317c35d1SJesse Barnes 
92*317c35d1SJesse Barnes 	I915_READ8(st01);
93*317c35d1SJesse Barnes 	I915_WRITE8(VGA_AR_INDEX, palette_enable | reg);
94*317c35d1SJesse Barnes 	return I915_READ8(VGA_AR_DATA_READ);
95*317c35d1SJesse Barnes }
96*317c35d1SJesse Barnes 
97*317c35d1SJesse Barnes static void i915_write_ar(struct drm_device *dev, u16 st01, u8 reg, u8 val, u16 palette_enable)
98*317c35d1SJesse Barnes {
99*317c35d1SJesse Barnes 	struct drm_i915_private *dev_priv = dev->dev_private;
100*317c35d1SJesse Barnes 
101*317c35d1SJesse Barnes 	I915_READ8(st01);
102*317c35d1SJesse Barnes 	I915_WRITE8(VGA_AR_INDEX, palette_enable | reg);
103*317c35d1SJesse Barnes 	I915_WRITE8(VGA_AR_DATA_WRITE, val);
104*317c35d1SJesse Barnes }
105*317c35d1SJesse Barnes 
106*317c35d1SJesse Barnes static void i915_write_indexed(struct drm_device *dev, u16 index_port, u16 data_port, u8 reg, u8 val)
107*317c35d1SJesse Barnes {
108*317c35d1SJesse Barnes 	struct drm_i915_private *dev_priv = dev->dev_private;
109*317c35d1SJesse Barnes 
110*317c35d1SJesse Barnes 	I915_WRITE8(index_port, reg);
111*317c35d1SJesse Barnes 	I915_WRITE8(data_port, val);
112*317c35d1SJesse Barnes }
113*317c35d1SJesse Barnes 
114*317c35d1SJesse Barnes static void i915_save_vga(struct drm_device *dev)
115*317c35d1SJesse Barnes {
116*317c35d1SJesse Barnes 	struct drm_i915_private *dev_priv = dev->dev_private;
117*317c35d1SJesse Barnes 	int i;
118*317c35d1SJesse Barnes 	u16 cr_index, cr_data, st01;
119*317c35d1SJesse Barnes 
120*317c35d1SJesse Barnes 	/* VGA color palette registers */
121*317c35d1SJesse Barnes 	dev_priv->saveDACMASK = I915_READ8(VGA_DACMASK);
122*317c35d1SJesse Barnes 	/* DACCRX automatically increments during read */
123*317c35d1SJesse Barnes 	I915_WRITE8(VGA_DACRX, 0);
124*317c35d1SJesse Barnes 	/* Read 3 bytes of color data from each index */
125*317c35d1SJesse Barnes 	for (i = 0; i < 256 * 3; i++)
126*317c35d1SJesse Barnes 		dev_priv->saveDACDATA[i] = I915_READ8(VGA_DACDATA);
127*317c35d1SJesse Barnes 
128*317c35d1SJesse Barnes 	/* MSR bits */
129*317c35d1SJesse Barnes 	dev_priv->saveMSR = I915_READ8(VGA_MSR_READ);
130*317c35d1SJesse Barnes 	if (dev_priv->saveMSR & VGA_MSR_CGA_MODE) {
131*317c35d1SJesse Barnes 		cr_index = VGA_CR_INDEX_CGA;
132*317c35d1SJesse Barnes 		cr_data = VGA_CR_DATA_CGA;
133*317c35d1SJesse Barnes 		st01 = VGA_ST01_CGA;
134*317c35d1SJesse Barnes 	} else {
135*317c35d1SJesse Barnes 		cr_index = VGA_CR_INDEX_MDA;
136*317c35d1SJesse Barnes 		cr_data = VGA_CR_DATA_MDA;
137*317c35d1SJesse Barnes 		st01 = VGA_ST01_MDA;
138*317c35d1SJesse Barnes 	}
139*317c35d1SJesse Barnes 
140*317c35d1SJesse Barnes 	/* CRT controller regs */
141*317c35d1SJesse Barnes 	i915_write_indexed(dev, cr_index, cr_data, 0x11,
142*317c35d1SJesse Barnes 			   i915_read_indexed(dev, cr_index, cr_data, 0x11) &
143*317c35d1SJesse Barnes 			   (~0x80));
144*317c35d1SJesse Barnes 	for (i = 0; i <= 0x24; i++)
145*317c35d1SJesse Barnes 		dev_priv->saveCR[i] =
146*317c35d1SJesse Barnes 			i915_read_indexed(dev, cr_index, cr_data, i);
147*317c35d1SJesse Barnes 	/* Make sure we don't turn off CR group 0 writes */
148*317c35d1SJesse Barnes 	dev_priv->saveCR[0x11] &= ~0x80;
149*317c35d1SJesse Barnes 
150*317c35d1SJesse Barnes 	/* Attribute controller registers */
151*317c35d1SJesse Barnes 	I915_READ8(st01);
152*317c35d1SJesse Barnes 	dev_priv->saveAR_INDEX = I915_READ8(VGA_AR_INDEX);
153*317c35d1SJesse Barnes 	for (i = 0; i <= 0x14; i++)
154*317c35d1SJesse Barnes 		dev_priv->saveAR[i] = i915_read_ar(dev, st01, i, 0);
155*317c35d1SJesse Barnes 	I915_READ8(st01);
156*317c35d1SJesse Barnes 	I915_WRITE8(VGA_AR_INDEX, dev_priv->saveAR_INDEX);
157*317c35d1SJesse Barnes 	I915_READ8(st01);
158*317c35d1SJesse Barnes 
159*317c35d1SJesse Barnes 	/* Graphics controller registers */
160*317c35d1SJesse Barnes 	for (i = 0; i < 9; i++)
161*317c35d1SJesse Barnes 		dev_priv->saveGR[i] =
162*317c35d1SJesse Barnes 			i915_read_indexed(dev, VGA_GR_INDEX, VGA_GR_DATA, i);
163*317c35d1SJesse Barnes 
164*317c35d1SJesse Barnes 	dev_priv->saveGR[0x10] =
165*317c35d1SJesse Barnes 		i915_read_indexed(dev, VGA_GR_INDEX, VGA_GR_DATA, 0x10);
166*317c35d1SJesse Barnes 	dev_priv->saveGR[0x11] =
167*317c35d1SJesse Barnes 		i915_read_indexed(dev, VGA_GR_INDEX, VGA_GR_DATA, 0x11);
168*317c35d1SJesse Barnes 	dev_priv->saveGR[0x18] =
169*317c35d1SJesse Barnes 		i915_read_indexed(dev, VGA_GR_INDEX, VGA_GR_DATA, 0x18);
170*317c35d1SJesse Barnes 
171*317c35d1SJesse Barnes 	/* Sequencer registers */
172*317c35d1SJesse Barnes 	for (i = 0; i < 8; i++)
173*317c35d1SJesse Barnes 		dev_priv->saveSR[i] =
174*317c35d1SJesse Barnes 			i915_read_indexed(dev, VGA_SR_INDEX, VGA_SR_DATA, i);
175*317c35d1SJesse Barnes }
176*317c35d1SJesse Barnes 
177*317c35d1SJesse Barnes static void i915_restore_vga(struct drm_device *dev)
178*317c35d1SJesse Barnes {
179*317c35d1SJesse Barnes 	struct drm_i915_private *dev_priv = dev->dev_private;
180*317c35d1SJesse Barnes 	int i;
181*317c35d1SJesse Barnes 	u16 cr_index, cr_data, st01;
182*317c35d1SJesse Barnes 
183*317c35d1SJesse Barnes 	/* MSR bits */
184*317c35d1SJesse Barnes 	I915_WRITE8(VGA_MSR_WRITE, dev_priv->saveMSR);
185*317c35d1SJesse Barnes 	if (dev_priv->saveMSR & VGA_MSR_CGA_MODE) {
186*317c35d1SJesse Barnes 		cr_index = VGA_CR_INDEX_CGA;
187*317c35d1SJesse Barnes 		cr_data = VGA_CR_DATA_CGA;
188*317c35d1SJesse Barnes 		st01 = VGA_ST01_CGA;
189*317c35d1SJesse Barnes 	} else {
190*317c35d1SJesse Barnes 		cr_index = VGA_CR_INDEX_MDA;
191*317c35d1SJesse Barnes 		cr_data = VGA_CR_DATA_MDA;
192*317c35d1SJesse Barnes 		st01 = VGA_ST01_MDA;
193*317c35d1SJesse Barnes 	}
194*317c35d1SJesse Barnes 
195*317c35d1SJesse Barnes 	/* Sequencer registers, don't write SR07 */
196*317c35d1SJesse Barnes 	for (i = 0; i < 7; i++)
197*317c35d1SJesse Barnes 		i915_write_indexed(dev, VGA_SR_INDEX, VGA_SR_DATA, i,
198*317c35d1SJesse Barnes 				   dev_priv->saveSR[i]);
199*317c35d1SJesse Barnes 
200*317c35d1SJesse Barnes 	/* CRT controller regs */
201*317c35d1SJesse Barnes 	/* Enable CR group 0 writes */
202*317c35d1SJesse Barnes 	i915_write_indexed(dev, cr_index, cr_data, 0x11, dev_priv->saveCR[0x11]);
203*317c35d1SJesse Barnes 	for (i = 0; i <= 0x24; i++)
204*317c35d1SJesse Barnes 		i915_write_indexed(dev, cr_index, cr_data, i, dev_priv->saveCR[i]);
205*317c35d1SJesse Barnes 
206*317c35d1SJesse Barnes 	/* Graphics controller regs */
207*317c35d1SJesse Barnes 	for (i = 0; i < 9; i++)
208*317c35d1SJesse Barnes 		i915_write_indexed(dev, VGA_GR_INDEX, VGA_GR_DATA, i,
209*317c35d1SJesse Barnes 				   dev_priv->saveGR[i]);
210*317c35d1SJesse Barnes 
211*317c35d1SJesse Barnes 	i915_write_indexed(dev, VGA_GR_INDEX, VGA_GR_DATA, 0x10,
212*317c35d1SJesse Barnes 			   dev_priv->saveGR[0x10]);
213*317c35d1SJesse Barnes 	i915_write_indexed(dev, VGA_GR_INDEX, VGA_GR_DATA, 0x11,
214*317c35d1SJesse Barnes 			   dev_priv->saveGR[0x11]);
215*317c35d1SJesse Barnes 	i915_write_indexed(dev, VGA_GR_INDEX, VGA_GR_DATA, 0x18,
216*317c35d1SJesse Barnes 			   dev_priv->saveGR[0x18]);
217*317c35d1SJesse Barnes 
218*317c35d1SJesse Barnes 	/* Attribute controller registers */
219*317c35d1SJesse Barnes 	I915_READ8(st01); /* switch back to index mode */
220*317c35d1SJesse Barnes 	for (i = 0; i <= 0x14; i++)
221*317c35d1SJesse Barnes 		i915_write_ar(dev, st01, i, dev_priv->saveAR[i], 0);
222*317c35d1SJesse Barnes 	I915_READ8(st01); /* switch back to index mode */
223*317c35d1SJesse Barnes 	I915_WRITE8(VGA_AR_INDEX, dev_priv->saveAR_INDEX | 0x20);
224*317c35d1SJesse Barnes 	I915_READ8(st01);
225*317c35d1SJesse Barnes 
226*317c35d1SJesse Barnes 	/* VGA color palette registers */
227*317c35d1SJesse Barnes 	I915_WRITE8(VGA_DACMASK, dev_priv->saveDACMASK);
228*317c35d1SJesse Barnes 	/* DACCRX automatically increments during read */
229*317c35d1SJesse Barnes 	I915_WRITE8(VGA_DACWX, 0);
230*317c35d1SJesse Barnes 	/* Read 3 bytes of color data from each index */
231*317c35d1SJesse Barnes 	for (i = 0; i < 256 * 3; i++)
232*317c35d1SJesse Barnes 		I915_WRITE8(VGA_DACDATA, dev_priv->saveDACDATA[i]);
233*317c35d1SJesse Barnes 
234*317c35d1SJesse Barnes }
235*317c35d1SJesse Barnes 
236*317c35d1SJesse Barnes int i915_save_state(struct drm_device *dev)
237*317c35d1SJesse Barnes {
238*317c35d1SJesse Barnes 	struct drm_i915_private *dev_priv = dev->dev_private;
239*317c35d1SJesse Barnes 	int i;
240*317c35d1SJesse Barnes 
241*317c35d1SJesse Barnes 	pci_read_config_byte(dev->pdev, LBB, &dev_priv->saveLBB);
242*317c35d1SJesse Barnes 
243*317c35d1SJesse Barnes 	/* Display arbitration control */
244*317c35d1SJesse Barnes 	dev_priv->saveDSPARB = I915_READ(DSPARB);
245*317c35d1SJesse Barnes 
246*317c35d1SJesse Barnes 	/* Pipe & plane A info */
247*317c35d1SJesse Barnes 	dev_priv->savePIPEACONF = I915_READ(PIPEACONF);
248*317c35d1SJesse Barnes 	dev_priv->savePIPEASRC = I915_READ(PIPEASRC);
249*317c35d1SJesse Barnes 	dev_priv->saveFPA0 = I915_READ(FPA0);
250*317c35d1SJesse Barnes 	dev_priv->saveFPA1 = I915_READ(FPA1);
251*317c35d1SJesse Barnes 	dev_priv->saveDPLL_A = I915_READ(DPLL_A);
252*317c35d1SJesse Barnes 	if (IS_I965G(dev))
253*317c35d1SJesse Barnes 		dev_priv->saveDPLL_A_MD = I915_READ(DPLL_A_MD);
254*317c35d1SJesse Barnes 	dev_priv->saveHTOTAL_A = I915_READ(HTOTAL_A);
255*317c35d1SJesse Barnes 	dev_priv->saveHBLANK_A = I915_READ(HBLANK_A);
256*317c35d1SJesse Barnes 	dev_priv->saveHSYNC_A = I915_READ(HSYNC_A);
257*317c35d1SJesse Barnes 	dev_priv->saveVTOTAL_A = I915_READ(VTOTAL_A);
258*317c35d1SJesse Barnes 	dev_priv->saveVBLANK_A = I915_READ(VBLANK_A);
259*317c35d1SJesse Barnes 	dev_priv->saveVSYNC_A = I915_READ(VSYNC_A);
260*317c35d1SJesse Barnes 	dev_priv->saveBCLRPAT_A = I915_READ(BCLRPAT_A);
261*317c35d1SJesse Barnes 
262*317c35d1SJesse Barnes 	dev_priv->saveDSPACNTR = I915_READ(DSPACNTR);
263*317c35d1SJesse Barnes 	dev_priv->saveDSPASTRIDE = I915_READ(DSPASTRIDE);
264*317c35d1SJesse Barnes 	dev_priv->saveDSPASIZE = I915_READ(DSPASIZE);
265*317c35d1SJesse Barnes 	dev_priv->saveDSPAPOS = I915_READ(DSPAPOS);
266*317c35d1SJesse Barnes 	dev_priv->saveDSPAADDR = I915_READ(DSPAADDR);
267*317c35d1SJesse Barnes 	if (IS_I965G(dev)) {
268*317c35d1SJesse Barnes 		dev_priv->saveDSPASURF = I915_READ(DSPASURF);
269*317c35d1SJesse Barnes 		dev_priv->saveDSPATILEOFF = I915_READ(DSPATILEOFF);
270*317c35d1SJesse Barnes 	}
271*317c35d1SJesse Barnes 	i915_save_palette(dev, PIPE_A);
272*317c35d1SJesse Barnes 	dev_priv->savePIPEASTAT = I915_READ(PIPEASTAT);
273*317c35d1SJesse Barnes 
274*317c35d1SJesse Barnes 	/* Pipe & plane B info */
275*317c35d1SJesse Barnes 	dev_priv->savePIPEBCONF = I915_READ(PIPEBCONF);
276*317c35d1SJesse Barnes 	dev_priv->savePIPEBSRC = I915_READ(PIPEBSRC);
277*317c35d1SJesse Barnes 	dev_priv->saveFPB0 = I915_READ(FPB0);
278*317c35d1SJesse Barnes 	dev_priv->saveFPB1 = I915_READ(FPB1);
279*317c35d1SJesse Barnes 	dev_priv->saveDPLL_B = I915_READ(DPLL_B);
280*317c35d1SJesse Barnes 	if (IS_I965G(dev))
281*317c35d1SJesse Barnes 		dev_priv->saveDPLL_B_MD = I915_READ(DPLL_B_MD);
282*317c35d1SJesse Barnes 	dev_priv->saveHTOTAL_B = I915_READ(HTOTAL_B);
283*317c35d1SJesse Barnes 	dev_priv->saveHBLANK_B = I915_READ(HBLANK_B);
284*317c35d1SJesse Barnes 	dev_priv->saveHSYNC_B = I915_READ(HSYNC_B);
285*317c35d1SJesse Barnes 	dev_priv->saveVTOTAL_B = I915_READ(VTOTAL_B);
286*317c35d1SJesse Barnes 	dev_priv->saveVBLANK_B = I915_READ(VBLANK_B);
287*317c35d1SJesse Barnes 	dev_priv->saveVSYNC_B = I915_READ(VSYNC_B);
288*317c35d1SJesse Barnes 	dev_priv->saveBCLRPAT_A = I915_READ(BCLRPAT_A);
289*317c35d1SJesse Barnes 
290*317c35d1SJesse Barnes 	dev_priv->saveDSPBCNTR = I915_READ(DSPBCNTR);
291*317c35d1SJesse Barnes 	dev_priv->saveDSPBSTRIDE = I915_READ(DSPBSTRIDE);
292*317c35d1SJesse Barnes 	dev_priv->saveDSPBSIZE = I915_READ(DSPBSIZE);
293*317c35d1SJesse Barnes 	dev_priv->saveDSPBPOS = I915_READ(DSPBPOS);
294*317c35d1SJesse Barnes 	dev_priv->saveDSPBADDR = I915_READ(DSPBADDR);
295*317c35d1SJesse Barnes 	if (IS_I965GM(dev) || IS_IGD_GM(dev)) {
296*317c35d1SJesse Barnes 		dev_priv->saveDSPBSURF = I915_READ(DSPBSURF);
297*317c35d1SJesse Barnes 		dev_priv->saveDSPBTILEOFF = I915_READ(DSPBTILEOFF);
298*317c35d1SJesse Barnes 	}
299*317c35d1SJesse Barnes 	i915_save_palette(dev, PIPE_B);
300*317c35d1SJesse Barnes 	dev_priv->savePIPEBSTAT = I915_READ(PIPEBSTAT);
301*317c35d1SJesse Barnes 
302*317c35d1SJesse Barnes 	/* CRT state */
303*317c35d1SJesse Barnes 	dev_priv->saveADPA = I915_READ(ADPA);
304*317c35d1SJesse Barnes 
305*317c35d1SJesse Barnes 	/* LVDS state */
306*317c35d1SJesse Barnes 	dev_priv->savePP_CONTROL = I915_READ(PP_CONTROL);
307*317c35d1SJesse Barnes 	dev_priv->savePFIT_PGM_RATIOS = I915_READ(PFIT_PGM_RATIOS);
308*317c35d1SJesse Barnes 	dev_priv->saveBLC_PWM_CTL = I915_READ(BLC_PWM_CTL);
309*317c35d1SJesse Barnes 	if (IS_I965G(dev))
310*317c35d1SJesse Barnes 		dev_priv->saveBLC_PWM_CTL2 = I915_READ(BLC_PWM_CTL2);
311*317c35d1SJesse Barnes 	if (IS_MOBILE(dev) && !IS_I830(dev))
312*317c35d1SJesse Barnes 		dev_priv->saveLVDS = I915_READ(LVDS);
313*317c35d1SJesse Barnes 	if (!IS_I830(dev) && !IS_845G(dev))
314*317c35d1SJesse Barnes 		dev_priv->savePFIT_CONTROL = I915_READ(PFIT_CONTROL);
315*317c35d1SJesse Barnes 	dev_priv->savePP_ON_DELAYS = I915_READ(PP_ON_DELAYS);
316*317c35d1SJesse Barnes 	dev_priv->savePP_OFF_DELAYS = I915_READ(PP_OFF_DELAYS);
317*317c35d1SJesse Barnes 	dev_priv->savePP_DIVISOR = I915_READ(PP_DIVISOR);
318*317c35d1SJesse Barnes 
319*317c35d1SJesse Barnes 	/* FIXME: save TV & SDVO state */
320*317c35d1SJesse Barnes 
321*317c35d1SJesse Barnes 	/* FBC state */
322*317c35d1SJesse Barnes 	dev_priv->saveFBC_CFB_BASE = I915_READ(FBC_CFB_BASE);
323*317c35d1SJesse Barnes 	dev_priv->saveFBC_LL_BASE = I915_READ(FBC_LL_BASE);
324*317c35d1SJesse Barnes 	dev_priv->saveFBC_CONTROL2 = I915_READ(FBC_CONTROL2);
325*317c35d1SJesse Barnes 	dev_priv->saveFBC_CONTROL = I915_READ(FBC_CONTROL);
326*317c35d1SJesse Barnes 
327*317c35d1SJesse Barnes 	/* Interrupt state */
328*317c35d1SJesse Barnes 	dev_priv->saveIIR = I915_READ(IIR);
329*317c35d1SJesse Barnes 	dev_priv->saveIER = I915_READ(IER);
330*317c35d1SJesse Barnes 	dev_priv->saveIMR = I915_READ(IMR);
331*317c35d1SJesse Barnes 
332*317c35d1SJesse Barnes 	/* VGA state */
333*317c35d1SJesse Barnes 	dev_priv->saveVGA0 = I915_READ(VGA0);
334*317c35d1SJesse Barnes 	dev_priv->saveVGA1 = I915_READ(VGA1);
335*317c35d1SJesse Barnes 	dev_priv->saveVGA_PD = I915_READ(VGA_PD);
336*317c35d1SJesse Barnes 	dev_priv->saveVGACNTRL = I915_READ(VGACNTRL);
337*317c35d1SJesse Barnes 
338*317c35d1SJesse Barnes 	/* Clock gating state */
339*317c35d1SJesse Barnes 	dev_priv->saveD_STATE = I915_READ(D_STATE);
340*317c35d1SJesse Barnes 	dev_priv->saveCG_2D_DIS = I915_READ(CG_2D_DIS);
341*317c35d1SJesse Barnes 
342*317c35d1SJesse Barnes 	/* Cache mode state */
343*317c35d1SJesse Barnes 	dev_priv->saveCACHE_MODE_0 = I915_READ(CACHE_MODE_0);
344*317c35d1SJesse Barnes 
345*317c35d1SJesse Barnes 	/* Memory Arbitration state */
346*317c35d1SJesse Barnes 	dev_priv->saveMI_ARB_STATE = I915_READ(MI_ARB_STATE);
347*317c35d1SJesse Barnes 
348*317c35d1SJesse Barnes 	/* Scratch space */
349*317c35d1SJesse Barnes 	for (i = 0; i < 16; i++) {
350*317c35d1SJesse Barnes 		dev_priv->saveSWF0[i] = I915_READ(SWF00 + (i << 2));
351*317c35d1SJesse Barnes 		dev_priv->saveSWF1[i] = I915_READ(SWF10 + (i << 2));
352*317c35d1SJesse Barnes 	}
353*317c35d1SJesse Barnes 	for (i = 0; i < 3; i++)
354*317c35d1SJesse Barnes 		dev_priv->saveSWF2[i] = I915_READ(SWF30 + (i << 2));
355*317c35d1SJesse Barnes 
356*317c35d1SJesse Barnes 	i915_save_vga(dev);
357*317c35d1SJesse Barnes 
358*317c35d1SJesse Barnes 	return 0;
359*317c35d1SJesse Barnes }
360*317c35d1SJesse Barnes 
361*317c35d1SJesse Barnes int i915_restore_state(struct drm_device *dev)
362*317c35d1SJesse Barnes {
363*317c35d1SJesse Barnes 	struct drm_i915_private *dev_priv = dev->dev_private;
364*317c35d1SJesse Barnes 	int i;
365*317c35d1SJesse Barnes 
366*317c35d1SJesse Barnes 	pci_write_config_byte(dev->pdev, LBB, dev_priv->saveLBB);
367*317c35d1SJesse Barnes 
368*317c35d1SJesse Barnes 	I915_WRITE(DSPARB, dev_priv->saveDSPARB);
369*317c35d1SJesse Barnes 
370*317c35d1SJesse Barnes 	/* Pipe & plane A info */
371*317c35d1SJesse Barnes 	/* Prime the clock */
372*317c35d1SJesse Barnes 	if (dev_priv->saveDPLL_A & DPLL_VCO_ENABLE) {
373*317c35d1SJesse Barnes 		I915_WRITE(DPLL_A, dev_priv->saveDPLL_A &
374*317c35d1SJesse Barnes 			   ~DPLL_VCO_ENABLE);
375*317c35d1SJesse Barnes 		DRM_UDELAY(150);
376*317c35d1SJesse Barnes 	}
377*317c35d1SJesse Barnes 	I915_WRITE(FPA0, dev_priv->saveFPA0);
378*317c35d1SJesse Barnes 	I915_WRITE(FPA1, dev_priv->saveFPA1);
379*317c35d1SJesse Barnes 	/* Actually enable it */
380*317c35d1SJesse Barnes 	I915_WRITE(DPLL_A, dev_priv->saveDPLL_A);
381*317c35d1SJesse Barnes 	DRM_UDELAY(150);
382*317c35d1SJesse Barnes 	if (IS_I965G(dev))
383*317c35d1SJesse Barnes 		I915_WRITE(DPLL_A_MD, dev_priv->saveDPLL_A_MD);
384*317c35d1SJesse Barnes 	DRM_UDELAY(150);
385*317c35d1SJesse Barnes 
386*317c35d1SJesse Barnes 	/* Restore mode */
387*317c35d1SJesse Barnes 	I915_WRITE(HTOTAL_A, dev_priv->saveHTOTAL_A);
388*317c35d1SJesse Barnes 	I915_WRITE(HBLANK_A, dev_priv->saveHBLANK_A);
389*317c35d1SJesse Barnes 	I915_WRITE(HSYNC_A, dev_priv->saveHSYNC_A);
390*317c35d1SJesse Barnes 	I915_WRITE(VTOTAL_A, dev_priv->saveVTOTAL_A);
391*317c35d1SJesse Barnes 	I915_WRITE(VBLANK_A, dev_priv->saveVBLANK_A);
392*317c35d1SJesse Barnes 	I915_WRITE(VSYNC_A, dev_priv->saveVSYNC_A);
393*317c35d1SJesse Barnes 	I915_WRITE(BCLRPAT_A, dev_priv->saveBCLRPAT_A);
394*317c35d1SJesse Barnes 
395*317c35d1SJesse Barnes 	/* Restore plane info */
396*317c35d1SJesse Barnes 	I915_WRITE(DSPASIZE, dev_priv->saveDSPASIZE);
397*317c35d1SJesse Barnes 	I915_WRITE(DSPAPOS, dev_priv->saveDSPAPOS);
398*317c35d1SJesse Barnes 	I915_WRITE(PIPEASRC, dev_priv->savePIPEASRC);
399*317c35d1SJesse Barnes 	I915_WRITE(DSPAADDR, dev_priv->saveDSPAADDR);
400*317c35d1SJesse Barnes 	I915_WRITE(DSPASTRIDE, dev_priv->saveDSPASTRIDE);
401*317c35d1SJesse Barnes 	if (IS_I965G(dev)) {
402*317c35d1SJesse Barnes 		I915_WRITE(DSPASURF, dev_priv->saveDSPASURF);
403*317c35d1SJesse Barnes 		I915_WRITE(DSPATILEOFF, dev_priv->saveDSPATILEOFF);
404*317c35d1SJesse Barnes 	}
405*317c35d1SJesse Barnes 
406*317c35d1SJesse Barnes 	I915_WRITE(PIPEACONF, dev_priv->savePIPEACONF);
407*317c35d1SJesse Barnes 
408*317c35d1SJesse Barnes 	i915_restore_palette(dev, PIPE_A);
409*317c35d1SJesse Barnes 	/* Enable the plane */
410*317c35d1SJesse Barnes 	I915_WRITE(DSPACNTR, dev_priv->saveDSPACNTR);
411*317c35d1SJesse Barnes 	I915_WRITE(DSPAADDR, I915_READ(DSPAADDR));
412*317c35d1SJesse Barnes 
413*317c35d1SJesse Barnes 	/* Pipe & plane B info */
414*317c35d1SJesse Barnes 	if (dev_priv->saveDPLL_B & DPLL_VCO_ENABLE) {
415*317c35d1SJesse Barnes 		I915_WRITE(DPLL_B, dev_priv->saveDPLL_B &
416*317c35d1SJesse Barnes 			   ~DPLL_VCO_ENABLE);
417*317c35d1SJesse Barnes 		DRM_UDELAY(150);
418*317c35d1SJesse Barnes 	}
419*317c35d1SJesse Barnes 	I915_WRITE(FPB0, dev_priv->saveFPB0);
420*317c35d1SJesse Barnes 	I915_WRITE(FPB1, dev_priv->saveFPB1);
421*317c35d1SJesse Barnes 	/* Actually enable it */
422*317c35d1SJesse Barnes 	I915_WRITE(DPLL_B, dev_priv->saveDPLL_B);
423*317c35d1SJesse Barnes 	DRM_UDELAY(150);
424*317c35d1SJesse Barnes 	if (IS_I965G(dev))
425*317c35d1SJesse Barnes 		I915_WRITE(DPLL_B_MD, dev_priv->saveDPLL_B_MD);
426*317c35d1SJesse Barnes 	DRM_UDELAY(150);
427*317c35d1SJesse Barnes 
428*317c35d1SJesse Barnes 	/* Restore mode */
429*317c35d1SJesse Barnes 	I915_WRITE(HTOTAL_B, dev_priv->saveHTOTAL_B);
430*317c35d1SJesse Barnes 	I915_WRITE(HBLANK_B, dev_priv->saveHBLANK_B);
431*317c35d1SJesse Barnes 	I915_WRITE(HSYNC_B, dev_priv->saveHSYNC_B);
432*317c35d1SJesse Barnes 	I915_WRITE(VTOTAL_B, dev_priv->saveVTOTAL_B);
433*317c35d1SJesse Barnes 	I915_WRITE(VBLANK_B, dev_priv->saveVBLANK_B);
434*317c35d1SJesse Barnes 	I915_WRITE(VSYNC_B, dev_priv->saveVSYNC_B);
435*317c35d1SJesse Barnes 	I915_WRITE(BCLRPAT_B, dev_priv->saveBCLRPAT_B);
436*317c35d1SJesse Barnes 
437*317c35d1SJesse Barnes 	/* Restore plane info */
438*317c35d1SJesse Barnes 	I915_WRITE(DSPBSIZE, dev_priv->saveDSPBSIZE);
439*317c35d1SJesse Barnes 	I915_WRITE(DSPBPOS, dev_priv->saveDSPBPOS);
440*317c35d1SJesse Barnes 	I915_WRITE(PIPEBSRC, dev_priv->savePIPEBSRC);
441*317c35d1SJesse Barnes 	I915_WRITE(DSPBADDR, dev_priv->saveDSPBADDR);
442*317c35d1SJesse Barnes 	I915_WRITE(DSPBSTRIDE, dev_priv->saveDSPBSTRIDE);
443*317c35d1SJesse Barnes 	if (IS_I965G(dev)) {
444*317c35d1SJesse Barnes 		I915_WRITE(DSPBSURF, dev_priv->saveDSPBSURF);
445*317c35d1SJesse Barnes 		I915_WRITE(DSPBTILEOFF, dev_priv->saveDSPBTILEOFF);
446*317c35d1SJesse Barnes 	}
447*317c35d1SJesse Barnes 
448*317c35d1SJesse Barnes 	I915_WRITE(PIPEBCONF, dev_priv->savePIPEBCONF);
449*317c35d1SJesse Barnes 
450*317c35d1SJesse Barnes 	i915_restore_palette(dev, PIPE_B);
451*317c35d1SJesse Barnes 	/* Enable the plane */
452*317c35d1SJesse Barnes 	I915_WRITE(DSPBCNTR, dev_priv->saveDSPBCNTR);
453*317c35d1SJesse Barnes 	I915_WRITE(DSPBADDR, I915_READ(DSPBADDR));
454*317c35d1SJesse Barnes 
455*317c35d1SJesse Barnes 	/* CRT state */
456*317c35d1SJesse Barnes 	I915_WRITE(ADPA, dev_priv->saveADPA);
457*317c35d1SJesse Barnes 
458*317c35d1SJesse Barnes 	/* LVDS state */
459*317c35d1SJesse Barnes 	if (IS_I965G(dev))
460*317c35d1SJesse Barnes 		I915_WRITE(BLC_PWM_CTL2, dev_priv->saveBLC_PWM_CTL2);
461*317c35d1SJesse Barnes 	if (IS_MOBILE(dev) && !IS_I830(dev))
462*317c35d1SJesse Barnes 		I915_WRITE(LVDS, dev_priv->saveLVDS);
463*317c35d1SJesse Barnes 	if (!IS_I830(dev) && !IS_845G(dev))
464*317c35d1SJesse Barnes 		I915_WRITE(PFIT_CONTROL, dev_priv->savePFIT_CONTROL);
465*317c35d1SJesse Barnes 
466*317c35d1SJesse Barnes 	I915_WRITE(PFIT_PGM_RATIOS, dev_priv->savePFIT_PGM_RATIOS);
467*317c35d1SJesse Barnes 	I915_WRITE(BLC_PWM_CTL, dev_priv->saveBLC_PWM_CTL);
468*317c35d1SJesse Barnes 	I915_WRITE(PP_ON_DELAYS, dev_priv->savePP_ON_DELAYS);
469*317c35d1SJesse Barnes 	I915_WRITE(PP_OFF_DELAYS, dev_priv->savePP_OFF_DELAYS);
470*317c35d1SJesse Barnes 	I915_WRITE(PP_DIVISOR, dev_priv->savePP_DIVISOR);
471*317c35d1SJesse Barnes 	I915_WRITE(PP_CONTROL, dev_priv->savePP_CONTROL);
472*317c35d1SJesse Barnes 
473*317c35d1SJesse Barnes 	/* FIXME: restore TV & SDVO state */
474*317c35d1SJesse Barnes 
475*317c35d1SJesse Barnes 	/* FBC info */
476*317c35d1SJesse Barnes 	I915_WRITE(FBC_CFB_BASE, dev_priv->saveFBC_CFB_BASE);
477*317c35d1SJesse Barnes 	I915_WRITE(FBC_LL_BASE, dev_priv->saveFBC_LL_BASE);
478*317c35d1SJesse Barnes 	I915_WRITE(FBC_CONTROL2, dev_priv->saveFBC_CONTROL2);
479*317c35d1SJesse Barnes 	I915_WRITE(FBC_CONTROL, dev_priv->saveFBC_CONTROL);
480*317c35d1SJesse Barnes 
481*317c35d1SJesse Barnes 	/* VGA state */
482*317c35d1SJesse Barnes 	I915_WRITE(VGACNTRL, dev_priv->saveVGACNTRL);
483*317c35d1SJesse Barnes 	I915_WRITE(VGA0, dev_priv->saveVGA0);
484*317c35d1SJesse Barnes 	I915_WRITE(VGA1, dev_priv->saveVGA1);
485*317c35d1SJesse Barnes 	I915_WRITE(VGA_PD, dev_priv->saveVGA_PD);
486*317c35d1SJesse Barnes 	DRM_UDELAY(150);
487*317c35d1SJesse Barnes 
488*317c35d1SJesse Barnes 	/* Clock gating state */
489*317c35d1SJesse Barnes 	I915_WRITE (D_STATE, dev_priv->saveD_STATE);
490*317c35d1SJesse Barnes 	I915_WRITE (CG_2D_DIS, dev_priv->saveCG_2D_DIS);
491*317c35d1SJesse Barnes 
492*317c35d1SJesse Barnes 	/* Cache mode state */
493*317c35d1SJesse Barnes 	I915_WRITE (CACHE_MODE_0, dev_priv->saveCACHE_MODE_0 | 0xffff0000);
494*317c35d1SJesse Barnes 
495*317c35d1SJesse Barnes 	/* Memory arbitration state */
496*317c35d1SJesse Barnes 	I915_WRITE (MI_ARB_STATE, dev_priv->saveMI_ARB_STATE | 0xffff0000);
497*317c35d1SJesse Barnes 
498*317c35d1SJesse Barnes 	for (i = 0; i < 16; i++) {
499*317c35d1SJesse Barnes 		I915_WRITE(SWF00 + (i << 2), dev_priv->saveSWF0[i]);
500*317c35d1SJesse Barnes 		I915_WRITE(SWF10 + (i << 2), dev_priv->saveSWF1[i+7]);
501*317c35d1SJesse Barnes 	}
502*317c35d1SJesse Barnes 	for (i = 0; i < 3; i++)
503*317c35d1SJesse Barnes 		I915_WRITE(SWF30 + (i << 2), dev_priv->saveSWF2[i]);
504*317c35d1SJesse Barnes 
505*317c35d1SJesse Barnes 	i915_restore_vga(dev);
506*317c35d1SJesse Barnes 
507*317c35d1SJesse Barnes 	return 0;
508*317c35d1SJesse Barnes }
509*317c35d1SJesse Barnes 
510