blob: af530637777af7f0349dbeaacc6bc6d70b2032fc [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
27#include "drmP.h"
28#include "drm.h"
29#include "i915_drm.h"
Eric Anholtf0217c42009-12-01 11:56:30 -080030#include "intel_drv.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
Chris Wilson90eb77b2010-08-14 14:41:23 +010037 if (HAS_PCH_SPLIT(dev)) {
Zhenyu Wang42048782009-10-21 15:27:01 +080038 dpll_reg = (pipe == PIPE_A) ? PCH_DPLL_A: PCH_DPLL_B;
39 } else {
40 dpll_reg = (pipe == PIPE_A) ? DPLL_A: DPLL_B;
41 }
42
43 return (I915_READ(dpll_reg) & DPLL_VCO_ENABLE);
Jesse Barnes317c35d2008-08-25 15:11:06 -070044}
45
46static void i915_save_palette(struct drm_device *dev, enum pipe pipe)
47{
48 struct drm_i915_private *dev_priv = dev->dev_private;
49 unsigned long reg = (pipe == PIPE_A ? PALETTE_A : PALETTE_B);
50 u32 *array;
51 int i;
52
53 if (!i915_pipe_enabled(dev, pipe))
54 return;
55
Chris Wilson90eb77b2010-08-14 14:41:23 +010056 if (HAS_PCH_SPLIT(dev))
Zhenyu Wang42048782009-10-21 15:27:01 +080057 reg = (pipe == PIPE_A) ? LGC_PALETTE_A : LGC_PALETTE_B;
58
Jesse Barnes317c35d2008-08-25 15:11:06 -070059 if (pipe == PIPE_A)
60 array = dev_priv->save_palette_a;
61 else
62 array = dev_priv->save_palette_b;
63
64 for(i = 0; i < 256; i++)
65 array[i] = I915_READ(reg + (i << 2));
66}
67
68static void i915_restore_palette(struct drm_device *dev, enum pipe pipe)
69{
70 struct drm_i915_private *dev_priv = dev->dev_private;
71 unsigned long reg = (pipe == PIPE_A ? PALETTE_A : PALETTE_B);
72 u32 *array;
73 int i;
74
75 if (!i915_pipe_enabled(dev, pipe))
76 return;
77
Chris Wilson90eb77b2010-08-14 14:41:23 +010078 if (HAS_PCH_SPLIT(dev))
Zhenyu Wang42048782009-10-21 15:27:01 +080079 reg = (pipe == PIPE_A) ? LGC_PALETTE_A : LGC_PALETTE_B;
80
Jesse Barnes317c35d2008-08-25 15:11:06 -070081 if (pipe == PIPE_A)
82 array = dev_priv->save_palette_a;
83 else
84 array = dev_priv->save_palette_b;
85
86 for(i = 0; i < 256; i++)
87 I915_WRITE(reg + (i << 2), array[i]);
88}
89
90static u8 i915_read_indexed(struct drm_device *dev, u16 index_port, u16 data_port, u8 reg)
91{
92 struct drm_i915_private *dev_priv = dev->dev_private;
93
94 I915_WRITE8(index_port, reg);
95 return I915_READ8(data_port);
96}
97
98static u8 i915_read_ar(struct drm_device *dev, u16 st01, u8 reg, u16 palette_enable)
99{
100 struct drm_i915_private *dev_priv = dev->dev_private;
101
102 I915_READ8(st01);
103 I915_WRITE8(VGA_AR_INDEX, palette_enable | reg);
104 return I915_READ8(VGA_AR_DATA_READ);
105}
106
107static void i915_write_ar(struct drm_device *dev, u16 st01, u8 reg, u8 val, u16 palette_enable)
108{
109 struct drm_i915_private *dev_priv = dev->dev_private;
110
111 I915_READ8(st01);
112 I915_WRITE8(VGA_AR_INDEX, palette_enable | reg);
113 I915_WRITE8(VGA_AR_DATA_WRITE, val);
114}
115
116static void i915_write_indexed(struct drm_device *dev, u16 index_port, u16 data_port, u8 reg, u8 val)
117{
118 struct drm_i915_private *dev_priv = dev->dev_private;
119
120 I915_WRITE8(index_port, reg);
121 I915_WRITE8(data_port, val);
122}
123
124static void i915_save_vga(struct drm_device *dev)
125{
126 struct drm_i915_private *dev_priv = dev->dev_private;
127 int i;
128 u16 cr_index, cr_data, st01;
129
130 /* VGA color palette registers */
131 dev_priv->saveDACMASK = I915_READ8(VGA_DACMASK);
Jesse Barnes317c35d2008-08-25 15:11:06 -0700132
133 /* MSR bits */
134 dev_priv->saveMSR = I915_READ8(VGA_MSR_READ);
135 if (dev_priv->saveMSR & VGA_MSR_CGA_MODE) {
136 cr_index = VGA_CR_INDEX_CGA;
137 cr_data = VGA_CR_DATA_CGA;
138 st01 = VGA_ST01_CGA;
139 } else {
140 cr_index = VGA_CR_INDEX_MDA;
141 cr_data = VGA_CR_DATA_MDA;
142 st01 = VGA_ST01_MDA;
143 }
144
145 /* CRT controller regs */
146 i915_write_indexed(dev, cr_index, cr_data, 0x11,
147 i915_read_indexed(dev, cr_index, cr_data, 0x11) &
148 (~0x80));
149 for (i = 0; i <= 0x24; i++)
150 dev_priv->saveCR[i] =
151 i915_read_indexed(dev, cr_index, cr_data, i);
152 /* Make sure we don't turn off CR group 0 writes */
153 dev_priv->saveCR[0x11] &= ~0x80;
154
155 /* Attribute controller registers */
156 I915_READ8(st01);
157 dev_priv->saveAR_INDEX = I915_READ8(VGA_AR_INDEX);
158 for (i = 0; i <= 0x14; i++)
159 dev_priv->saveAR[i] = i915_read_ar(dev, st01, i, 0);
160 I915_READ8(st01);
161 I915_WRITE8(VGA_AR_INDEX, dev_priv->saveAR_INDEX);
162 I915_READ8(st01);
163
164 /* Graphics controller registers */
165 for (i = 0; i < 9; i++)
166 dev_priv->saveGR[i] =
167 i915_read_indexed(dev, VGA_GR_INDEX, VGA_GR_DATA, i);
168
169 dev_priv->saveGR[0x10] =
170 i915_read_indexed(dev, VGA_GR_INDEX, VGA_GR_DATA, 0x10);
171 dev_priv->saveGR[0x11] =
172 i915_read_indexed(dev, VGA_GR_INDEX, VGA_GR_DATA, 0x11);
173 dev_priv->saveGR[0x18] =
174 i915_read_indexed(dev, VGA_GR_INDEX, VGA_GR_DATA, 0x18);
175
176 /* Sequencer registers */
177 for (i = 0; i < 8; i++)
178 dev_priv->saveSR[i] =
179 i915_read_indexed(dev, VGA_SR_INDEX, VGA_SR_DATA, i);
180}
181
182static void i915_restore_vga(struct drm_device *dev)
183{
184 struct drm_i915_private *dev_priv = dev->dev_private;
185 int i;
186 u16 cr_index, cr_data, st01;
187
188 /* MSR bits */
189 I915_WRITE8(VGA_MSR_WRITE, dev_priv->saveMSR);
190 if (dev_priv->saveMSR & VGA_MSR_CGA_MODE) {
191 cr_index = VGA_CR_INDEX_CGA;
192 cr_data = VGA_CR_DATA_CGA;
193 st01 = VGA_ST01_CGA;
194 } else {
195 cr_index = VGA_CR_INDEX_MDA;
196 cr_data = VGA_CR_DATA_MDA;
197 st01 = VGA_ST01_MDA;
198 }
199
200 /* Sequencer registers, don't write SR07 */
201 for (i = 0; i < 7; i++)
202 i915_write_indexed(dev, VGA_SR_INDEX, VGA_SR_DATA, i,
203 dev_priv->saveSR[i]);
204
205 /* CRT controller regs */
206 /* Enable CR group 0 writes */
207 i915_write_indexed(dev, cr_index, cr_data, 0x11, dev_priv->saveCR[0x11]);
208 for (i = 0; i <= 0x24; i++)
209 i915_write_indexed(dev, cr_index, cr_data, i, dev_priv->saveCR[i]);
210
211 /* Graphics controller regs */
212 for (i = 0; i < 9; i++)
213 i915_write_indexed(dev, VGA_GR_INDEX, VGA_GR_DATA, i,
214 dev_priv->saveGR[i]);
215
216 i915_write_indexed(dev, VGA_GR_INDEX, VGA_GR_DATA, 0x10,
217 dev_priv->saveGR[0x10]);
218 i915_write_indexed(dev, VGA_GR_INDEX, VGA_GR_DATA, 0x11,
219 dev_priv->saveGR[0x11]);
220 i915_write_indexed(dev, VGA_GR_INDEX, VGA_GR_DATA, 0x18,
221 dev_priv->saveGR[0x18]);
222
223 /* Attribute controller registers */
224 I915_READ8(st01); /* switch back to index mode */
225 for (i = 0; i <= 0x14; i++)
226 i915_write_ar(dev, st01, i, dev_priv->saveAR[i], 0);
227 I915_READ8(st01); /* switch back to index mode */
228 I915_WRITE8(VGA_AR_INDEX, dev_priv->saveAR_INDEX | 0x20);
229 I915_READ8(st01);
230
231 /* VGA color palette registers */
232 I915_WRITE8(VGA_DACMASK, dev_priv->saveDACMASK);
Jesse Barnes317c35d2008-08-25 15:11:06 -0700233}
234
Zhao Yakuifccdaba2009-07-08 14:13:14 +0800235static void i915_save_modeset_reg(struct drm_device *dev)
Jesse Barnes317c35d2008-08-25 15:11:06 -0700236{
237 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson312817a2010-11-22 11:50:11 +0000238 int i;
Jesse Barnes317c35d2008-08-25 15:11:06 -0700239
Zhao Yakuifccdaba2009-07-08 14:13:14 +0800240 if (drm_core_check_feature(dev, DRIVER_MODESET))
241 return;
Ben Gamari1341d652009-09-14 17:48:42 -0400242
Chris Wilsonf3c91c12010-11-21 09:56:00 +0000243 /* Cursor state */
244 dev_priv->saveCURACNTR = I915_READ(CURACNTR);
245 dev_priv->saveCURAPOS = I915_READ(CURAPOS);
246 dev_priv->saveCURABASE = I915_READ(CURABASE);
247 dev_priv->saveCURBCNTR = I915_READ(CURBCNTR);
248 dev_priv->saveCURBPOS = I915_READ(CURBPOS);
249 dev_priv->saveCURBBASE = I915_READ(CURBBASE);
250 if (IS_GEN2(dev))
251 dev_priv->saveCURSIZE = I915_READ(CURSIZE);
252
Chris Wilson90eb77b2010-08-14 14:41:23 +0100253 if (HAS_PCH_SPLIT(dev)) {
Zhenyu Wang5586c8b2009-11-06 02:13:02 +0000254 dev_priv->savePCH_DREF_CONTROL = I915_READ(PCH_DREF_CONTROL);
255 dev_priv->saveDISP_ARB_CTL = I915_READ(DISP_ARB_CTL);
256 }
257
Jesse Barnes317c35d2008-08-25 15:11:06 -0700258 /* Pipe & plane A info */
259 dev_priv->savePIPEACONF = I915_READ(PIPEACONF);
260 dev_priv->savePIPEASRC = I915_READ(PIPEASRC);
Chris Wilson90eb77b2010-08-14 14:41:23 +0100261 if (HAS_PCH_SPLIT(dev)) {
Zhenyu Wang42048782009-10-21 15:27:01 +0800262 dev_priv->saveFPA0 = I915_READ(PCH_FPA0);
263 dev_priv->saveFPA1 = I915_READ(PCH_FPA1);
264 dev_priv->saveDPLL_A = I915_READ(PCH_DPLL_A);
265 } else {
266 dev_priv->saveFPA0 = I915_READ(FPA0);
267 dev_priv->saveFPA1 = I915_READ(FPA1);
268 dev_priv->saveDPLL_A = I915_READ(DPLL_A);
269 }
Chris Wilsona6c45cf2010-09-17 00:32:17 +0100270 if (INTEL_INFO(dev)->gen >= 4 && !HAS_PCH_SPLIT(dev))
Jesse Barnes317c35d2008-08-25 15:11:06 -0700271 dev_priv->saveDPLL_A_MD = I915_READ(DPLL_A_MD);
272 dev_priv->saveHTOTAL_A = I915_READ(HTOTAL_A);
273 dev_priv->saveHBLANK_A = I915_READ(HBLANK_A);
274 dev_priv->saveHSYNC_A = I915_READ(HSYNC_A);
275 dev_priv->saveVTOTAL_A = I915_READ(VTOTAL_A);
276 dev_priv->saveVBLANK_A = I915_READ(VBLANK_A);
277 dev_priv->saveVSYNC_A = I915_READ(VSYNC_A);
Chris Wilson90eb77b2010-08-14 14:41:23 +0100278 if (!HAS_PCH_SPLIT(dev))
Zhenyu Wang42048782009-10-21 15:27:01 +0800279 dev_priv->saveBCLRPAT_A = I915_READ(BCLRPAT_A);
280
Chris Wilson90eb77b2010-08-14 14:41:23 +0100281 if (HAS_PCH_SPLIT(dev)) {
Zhenyu Wang5586c8b2009-11-06 02:13:02 +0000282 dev_priv->savePIPEA_DATA_M1 = I915_READ(PIPEA_DATA_M1);
283 dev_priv->savePIPEA_DATA_N1 = I915_READ(PIPEA_DATA_N1);
284 dev_priv->savePIPEA_LINK_M1 = I915_READ(PIPEA_LINK_M1);
285 dev_priv->savePIPEA_LINK_N1 = I915_READ(PIPEA_LINK_N1);
286
Zhenyu Wang42048782009-10-21 15:27:01 +0800287 dev_priv->saveFDI_TXA_CTL = I915_READ(FDI_TXA_CTL);
288 dev_priv->saveFDI_RXA_CTL = I915_READ(FDI_RXA_CTL);
289
290 dev_priv->savePFA_CTL_1 = I915_READ(PFA_CTL_1);
291 dev_priv->savePFA_WIN_SZ = I915_READ(PFA_WIN_SZ);
292 dev_priv->savePFA_WIN_POS = I915_READ(PFA_WIN_POS);
293
Zhenyu Wang5586c8b2009-11-06 02:13:02 +0000294 dev_priv->saveTRANSACONF = I915_READ(TRANSACONF);
Zhenyu Wang42048782009-10-21 15:27:01 +0800295 dev_priv->saveTRANS_HTOTAL_A = I915_READ(TRANS_HTOTAL_A);
296 dev_priv->saveTRANS_HBLANK_A = I915_READ(TRANS_HBLANK_A);
297 dev_priv->saveTRANS_HSYNC_A = I915_READ(TRANS_HSYNC_A);
298 dev_priv->saveTRANS_VTOTAL_A = I915_READ(TRANS_VTOTAL_A);
299 dev_priv->saveTRANS_VBLANK_A = I915_READ(TRANS_VBLANK_A);
300 dev_priv->saveTRANS_VSYNC_A = I915_READ(TRANS_VSYNC_A);
301 }
Jesse Barnes317c35d2008-08-25 15:11:06 -0700302
303 dev_priv->saveDSPACNTR = I915_READ(DSPACNTR);
304 dev_priv->saveDSPASTRIDE = I915_READ(DSPASTRIDE);
305 dev_priv->saveDSPASIZE = I915_READ(DSPASIZE);
306 dev_priv->saveDSPAPOS = I915_READ(DSPAPOS);
307 dev_priv->saveDSPAADDR = I915_READ(DSPAADDR);
Chris Wilsona6c45cf2010-09-17 00:32:17 +0100308 if (INTEL_INFO(dev)->gen >= 4) {
Jesse Barnes317c35d2008-08-25 15:11:06 -0700309 dev_priv->saveDSPASURF = I915_READ(DSPASURF);
310 dev_priv->saveDSPATILEOFF = I915_READ(DSPATILEOFF);
311 }
312 i915_save_palette(dev, PIPE_A);
313 dev_priv->savePIPEASTAT = I915_READ(PIPEASTAT);
314
315 /* Pipe & plane B info */
316 dev_priv->savePIPEBCONF = I915_READ(PIPEBCONF);
317 dev_priv->savePIPEBSRC = I915_READ(PIPEBSRC);
Chris Wilson90eb77b2010-08-14 14:41:23 +0100318 if (HAS_PCH_SPLIT(dev)) {
Zhenyu Wang42048782009-10-21 15:27:01 +0800319 dev_priv->saveFPB0 = I915_READ(PCH_FPB0);
320 dev_priv->saveFPB1 = I915_READ(PCH_FPB1);
321 dev_priv->saveDPLL_B = I915_READ(PCH_DPLL_B);
322 } else {
323 dev_priv->saveFPB0 = I915_READ(FPB0);
324 dev_priv->saveFPB1 = I915_READ(FPB1);
325 dev_priv->saveDPLL_B = I915_READ(DPLL_B);
326 }
Chris Wilsona6c45cf2010-09-17 00:32:17 +0100327 if (INTEL_INFO(dev)->gen >= 4 && !HAS_PCH_SPLIT(dev))
Jesse Barnes317c35d2008-08-25 15:11:06 -0700328 dev_priv->saveDPLL_B_MD = I915_READ(DPLL_B_MD);
329 dev_priv->saveHTOTAL_B = I915_READ(HTOTAL_B);
330 dev_priv->saveHBLANK_B = I915_READ(HBLANK_B);
331 dev_priv->saveHSYNC_B = I915_READ(HSYNC_B);
332 dev_priv->saveVTOTAL_B = I915_READ(VTOTAL_B);
333 dev_priv->saveVBLANK_B = I915_READ(VBLANK_B);
334 dev_priv->saveVSYNC_B = I915_READ(VSYNC_B);
Chris Wilson90eb77b2010-08-14 14:41:23 +0100335 if (!HAS_PCH_SPLIT(dev))
Zhenyu Wang42048782009-10-21 15:27:01 +0800336 dev_priv->saveBCLRPAT_B = I915_READ(BCLRPAT_B);
337
Chris Wilson90eb77b2010-08-14 14:41:23 +0100338 if (HAS_PCH_SPLIT(dev)) {
Zhenyu Wang5586c8b2009-11-06 02:13:02 +0000339 dev_priv->savePIPEB_DATA_M1 = I915_READ(PIPEB_DATA_M1);
340 dev_priv->savePIPEB_DATA_N1 = I915_READ(PIPEB_DATA_N1);
341 dev_priv->savePIPEB_LINK_M1 = I915_READ(PIPEB_LINK_M1);
342 dev_priv->savePIPEB_LINK_N1 = I915_READ(PIPEB_LINK_N1);
343
Zhenyu Wang42048782009-10-21 15:27:01 +0800344 dev_priv->saveFDI_TXB_CTL = I915_READ(FDI_TXB_CTL);
345 dev_priv->saveFDI_RXB_CTL = I915_READ(FDI_RXB_CTL);
346
347 dev_priv->savePFB_CTL_1 = I915_READ(PFB_CTL_1);
348 dev_priv->savePFB_WIN_SZ = I915_READ(PFB_WIN_SZ);
349 dev_priv->savePFB_WIN_POS = I915_READ(PFB_WIN_POS);
350
Zhenyu Wang5586c8b2009-11-06 02:13:02 +0000351 dev_priv->saveTRANSBCONF = I915_READ(TRANSBCONF);
Zhenyu Wang42048782009-10-21 15:27:01 +0800352 dev_priv->saveTRANS_HTOTAL_B = I915_READ(TRANS_HTOTAL_B);
353 dev_priv->saveTRANS_HBLANK_B = I915_READ(TRANS_HBLANK_B);
354 dev_priv->saveTRANS_HSYNC_B = I915_READ(TRANS_HSYNC_B);
355 dev_priv->saveTRANS_VTOTAL_B = I915_READ(TRANS_VTOTAL_B);
356 dev_priv->saveTRANS_VBLANK_B = I915_READ(TRANS_VBLANK_B);
357 dev_priv->saveTRANS_VSYNC_B = I915_READ(TRANS_VSYNC_B);
358 }
Jesse Barnes317c35d2008-08-25 15:11:06 -0700359
360 dev_priv->saveDSPBCNTR = I915_READ(DSPBCNTR);
361 dev_priv->saveDSPBSTRIDE = I915_READ(DSPBSTRIDE);
362 dev_priv->saveDSPBSIZE = I915_READ(DSPBSIZE);
363 dev_priv->saveDSPBPOS = I915_READ(DSPBPOS);
364 dev_priv->saveDSPBADDR = I915_READ(DSPBADDR);
Chris Wilsona6c45cf2010-09-17 00:32:17 +0100365 if (INTEL_INFO(dev)->gen >= 4) {
Jesse Barnes317c35d2008-08-25 15:11:06 -0700366 dev_priv->saveDSPBSURF = I915_READ(DSPBSURF);
367 dev_priv->saveDSPBTILEOFF = I915_READ(DSPBTILEOFF);
368 }
369 i915_save_palette(dev, PIPE_B);
370 dev_priv->savePIPEBSTAT = I915_READ(PIPEBSTAT);
Chris Wilson312817a2010-11-22 11:50:11 +0000371
372 /* Fences */
373 switch (INTEL_INFO(dev)->gen) {
374 case 6:
375 for (i = 0; i < 16; i++)
376 dev_priv->saveFENCE[i] = I915_READ64(FENCE_REG_SANDYBRIDGE_0 + (i * 8));
377 break;
378 case 5:
379 case 4:
380 for (i = 0; i < 16; i++)
381 dev_priv->saveFENCE[i] = I915_READ64(FENCE_REG_965_0 + (i * 8));
382 break;
383 case 3:
384 if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev))
385 for (i = 0; i < 8; i++)
386 dev_priv->saveFENCE[i+8] = I915_READ(FENCE_REG_945_8 + (i * 4));
387 case 2:
388 for (i = 0; i < 8; i++)
389 dev_priv->saveFENCE[i] = I915_READ(FENCE_REG_830_0 + (i * 4));
390 break;
391 }
392
Zhao Yakuifccdaba2009-07-08 14:13:14 +0800393 return;
394}
Ben Gamari1341d652009-09-14 17:48:42 -0400395
Zhao Yakuifccdaba2009-07-08 14:13:14 +0800396static void i915_restore_modeset_reg(struct drm_device *dev)
397{
398 struct drm_i915_private *dev_priv = dev->dev_private;
Zhenyu Wang42048782009-10-21 15:27:01 +0800399 int dpll_a_reg, fpa0_reg, fpa1_reg;
400 int dpll_b_reg, fpb0_reg, fpb1_reg;
Chris Wilson312817a2010-11-22 11:50:11 +0000401 int i;
Jesse Barnes317c35d2008-08-25 15:11:06 -0700402
Zhao Yakuifccdaba2009-07-08 14:13:14 +0800403 if (drm_core_check_feature(dev, DRIVER_MODESET))
404 return;
405
Chris Wilson312817a2010-11-22 11:50:11 +0000406 /* Fences */
407 switch (INTEL_INFO(dev)->gen) {
408 case 6:
409 for (i = 0; i < 16; i++)
410 I915_WRITE64(FENCE_REG_SANDYBRIDGE_0 + (i * 8), dev_priv->saveFENCE[i]);
411 break;
412 case 5:
413 case 4:
414 for (i = 0; i < 16; i++)
415 I915_WRITE64(FENCE_REG_965_0 + (i * 8), dev_priv->saveFENCE[i]);
416 break;
417 case 3:
418 case 2:
419 if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev))
420 for (i = 0; i < 8; i++)
421 I915_WRITE(FENCE_REG_945_8 + (i * 4), dev_priv->saveFENCE[i+8]);
422 for (i = 0; i < 8; i++)
423 I915_WRITE(FENCE_REG_830_0 + (i * 4), dev_priv->saveFENCE[i]);
424 break;
425 }
426
427
Chris Wilson90eb77b2010-08-14 14:41:23 +0100428 if (HAS_PCH_SPLIT(dev)) {
Zhenyu Wang42048782009-10-21 15:27:01 +0800429 dpll_a_reg = PCH_DPLL_A;
430 dpll_b_reg = PCH_DPLL_B;
431 fpa0_reg = PCH_FPA0;
432 fpb0_reg = PCH_FPB0;
433 fpa1_reg = PCH_FPA1;
434 fpb1_reg = PCH_FPB1;
435 } else {
436 dpll_a_reg = DPLL_A;
437 dpll_b_reg = DPLL_B;
438 fpa0_reg = FPA0;
439 fpb0_reg = FPB0;
440 fpa1_reg = FPA1;
441 fpb1_reg = FPB1;
442 }
443
Chris Wilson90eb77b2010-08-14 14:41:23 +0100444 if (HAS_PCH_SPLIT(dev)) {
Zhenyu Wang5586c8b2009-11-06 02:13:02 +0000445 I915_WRITE(PCH_DREF_CONTROL, dev_priv->savePCH_DREF_CONTROL);
446 I915_WRITE(DISP_ARB_CTL, dev_priv->saveDISP_ARB_CTL);
447 }
448
Zhao Yakuifccdaba2009-07-08 14:13:14 +0800449 /* Pipe & plane A info */
450 /* Prime the clock */
451 if (dev_priv->saveDPLL_A & DPLL_VCO_ENABLE) {
Zhenyu Wang42048782009-10-21 15:27:01 +0800452 I915_WRITE(dpll_a_reg, dev_priv->saveDPLL_A &
Zhao Yakuifccdaba2009-07-08 14:13:14 +0800453 ~DPLL_VCO_ENABLE);
Chris Wilson72bcb262010-08-14 14:41:22 +0100454 POSTING_READ(dpll_a_reg);
455 udelay(150);
Zhao Yakuifccdaba2009-07-08 14:13:14 +0800456 }
Zhenyu Wang42048782009-10-21 15:27:01 +0800457 I915_WRITE(fpa0_reg, dev_priv->saveFPA0);
458 I915_WRITE(fpa1_reg, dev_priv->saveFPA1);
Zhao Yakuifccdaba2009-07-08 14:13:14 +0800459 /* Actually enable it */
Zhenyu Wang42048782009-10-21 15:27:01 +0800460 I915_WRITE(dpll_a_reg, dev_priv->saveDPLL_A);
Chris Wilson72bcb262010-08-14 14:41:22 +0100461 POSTING_READ(dpll_a_reg);
462 udelay(150);
Chris Wilsona6c45cf2010-09-17 00:32:17 +0100463 if (INTEL_INFO(dev)->gen >= 4 && !HAS_PCH_SPLIT(dev)) {
Zhao Yakuifccdaba2009-07-08 14:13:14 +0800464 I915_WRITE(DPLL_A_MD, dev_priv->saveDPLL_A_MD);
Chris Wilson72bcb262010-08-14 14:41:22 +0100465 POSTING_READ(DPLL_A_MD);
466 }
467 udelay(150);
Zhao Yakuifccdaba2009-07-08 14:13:14 +0800468
469 /* Restore mode */
470 I915_WRITE(HTOTAL_A, dev_priv->saveHTOTAL_A);
471 I915_WRITE(HBLANK_A, dev_priv->saveHBLANK_A);
472 I915_WRITE(HSYNC_A, dev_priv->saveHSYNC_A);
473 I915_WRITE(VTOTAL_A, dev_priv->saveVTOTAL_A);
474 I915_WRITE(VBLANK_A, dev_priv->saveVBLANK_A);
475 I915_WRITE(VSYNC_A, dev_priv->saveVSYNC_A);
Chris Wilson90eb77b2010-08-14 14:41:23 +0100476 if (!HAS_PCH_SPLIT(dev))
Zhenyu Wang42048782009-10-21 15:27:01 +0800477 I915_WRITE(BCLRPAT_A, dev_priv->saveBCLRPAT_A);
478
Chris Wilson90eb77b2010-08-14 14:41:23 +0100479 if (HAS_PCH_SPLIT(dev)) {
Zhenyu Wang5586c8b2009-11-06 02:13:02 +0000480 I915_WRITE(PIPEA_DATA_M1, dev_priv->savePIPEA_DATA_M1);
481 I915_WRITE(PIPEA_DATA_N1, dev_priv->savePIPEA_DATA_N1);
482 I915_WRITE(PIPEA_LINK_M1, dev_priv->savePIPEA_LINK_M1);
483 I915_WRITE(PIPEA_LINK_N1, dev_priv->savePIPEA_LINK_N1);
484
Zhenyu Wang42048782009-10-21 15:27:01 +0800485 I915_WRITE(FDI_RXA_CTL, dev_priv->saveFDI_RXA_CTL);
486 I915_WRITE(FDI_TXA_CTL, dev_priv->saveFDI_TXA_CTL);
487
488 I915_WRITE(PFA_CTL_1, dev_priv->savePFA_CTL_1);
489 I915_WRITE(PFA_WIN_SZ, dev_priv->savePFA_WIN_SZ);
490 I915_WRITE(PFA_WIN_POS, dev_priv->savePFA_WIN_POS);
491
Zhenyu Wang5586c8b2009-11-06 02:13:02 +0000492 I915_WRITE(TRANSACONF, dev_priv->saveTRANSACONF);
Zhenyu Wang42048782009-10-21 15:27:01 +0800493 I915_WRITE(TRANS_HTOTAL_A, dev_priv->saveTRANS_HTOTAL_A);
494 I915_WRITE(TRANS_HBLANK_A, dev_priv->saveTRANS_HBLANK_A);
495 I915_WRITE(TRANS_HSYNC_A, dev_priv->saveTRANS_HSYNC_A);
496 I915_WRITE(TRANS_VTOTAL_A, dev_priv->saveTRANS_VTOTAL_A);
497 I915_WRITE(TRANS_VBLANK_A, dev_priv->saveTRANS_VBLANK_A);
498 I915_WRITE(TRANS_VSYNC_A, dev_priv->saveTRANS_VSYNC_A);
499 }
Zhao Yakuifccdaba2009-07-08 14:13:14 +0800500
501 /* Restore plane info */
502 I915_WRITE(DSPASIZE, dev_priv->saveDSPASIZE);
503 I915_WRITE(DSPAPOS, dev_priv->saveDSPAPOS);
504 I915_WRITE(PIPEASRC, dev_priv->savePIPEASRC);
505 I915_WRITE(DSPAADDR, dev_priv->saveDSPAADDR);
506 I915_WRITE(DSPASTRIDE, dev_priv->saveDSPASTRIDE);
Chris Wilsona6c45cf2010-09-17 00:32:17 +0100507 if (INTEL_INFO(dev)->gen >= 4) {
Zhao Yakuifccdaba2009-07-08 14:13:14 +0800508 I915_WRITE(DSPASURF, dev_priv->saveDSPASURF);
509 I915_WRITE(DSPATILEOFF, dev_priv->saveDSPATILEOFF);
510 }
511
512 I915_WRITE(PIPEACONF, dev_priv->savePIPEACONF);
513
514 i915_restore_palette(dev, PIPE_A);
515 /* Enable the plane */
516 I915_WRITE(DSPACNTR, dev_priv->saveDSPACNTR);
517 I915_WRITE(DSPAADDR, I915_READ(DSPAADDR));
518
519 /* Pipe & plane B info */
520 if (dev_priv->saveDPLL_B & DPLL_VCO_ENABLE) {
Zhenyu Wang42048782009-10-21 15:27:01 +0800521 I915_WRITE(dpll_b_reg, dev_priv->saveDPLL_B &
Zhao Yakuifccdaba2009-07-08 14:13:14 +0800522 ~DPLL_VCO_ENABLE);
Chris Wilson72bcb262010-08-14 14:41:22 +0100523 POSTING_READ(dpll_b_reg);
524 udelay(150);
Zhao Yakuifccdaba2009-07-08 14:13:14 +0800525 }
Zhenyu Wang42048782009-10-21 15:27:01 +0800526 I915_WRITE(fpb0_reg, dev_priv->saveFPB0);
527 I915_WRITE(fpb1_reg, dev_priv->saveFPB1);
Zhao Yakuifccdaba2009-07-08 14:13:14 +0800528 /* Actually enable it */
Zhenyu Wang42048782009-10-21 15:27:01 +0800529 I915_WRITE(dpll_b_reg, dev_priv->saveDPLL_B);
Chris Wilson72bcb262010-08-14 14:41:22 +0100530 POSTING_READ(dpll_b_reg);
531 udelay(150);
Chris Wilsona6c45cf2010-09-17 00:32:17 +0100532 if (INTEL_INFO(dev)->gen >= 4 && !HAS_PCH_SPLIT(dev)) {
Zhao Yakuifccdaba2009-07-08 14:13:14 +0800533 I915_WRITE(DPLL_B_MD, dev_priv->saveDPLL_B_MD);
Chris Wilson72bcb262010-08-14 14:41:22 +0100534 POSTING_READ(DPLL_B_MD);
535 }
536 udelay(150);
Zhao Yakuifccdaba2009-07-08 14:13:14 +0800537
538 /* Restore mode */
539 I915_WRITE(HTOTAL_B, dev_priv->saveHTOTAL_B);
540 I915_WRITE(HBLANK_B, dev_priv->saveHBLANK_B);
541 I915_WRITE(HSYNC_B, dev_priv->saveHSYNC_B);
542 I915_WRITE(VTOTAL_B, dev_priv->saveVTOTAL_B);
543 I915_WRITE(VBLANK_B, dev_priv->saveVBLANK_B);
544 I915_WRITE(VSYNC_B, dev_priv->saveVSYNC_B);
Chris Wilson90eb77b2010-08-14 14:41:23 +0100545 if (!HAS_PCH_SPLIT(dev))
Zhenyu Wang42048782009-10-21 15:27:01 +0800546 I915_WRITE(BCLRPAT_B, dev_priv->saveBCLRPAT_B);
547
Chris Wilson90eb77b2010-08-14 14:41:23 +0100548 if (HAS_PCH_SPLIT(dev)) {
Zhenyu Wang5586c8b2009-11-06 02:13:02 +0000549 I915_WRITE(PIPEB_DATA_M1, dev_priv->savePIPEB_DATA_M1);
550 I915_WRITE(PIPEB_DATA_N1, dev_priv->savePIPEB_DATA_N1);
551 I915_WRITE(PIPEB_LINK_M1, dev_priv->savePIPEB_LINK_M1);
552 I915_WRITE(PIPEB_LINK_N1, dev_priv->savePIPEB_LINK_N1);
553
Zhenyu Wang42048782009-10-21 15:27:01 +0800554 I915_WRITE(FDI_RXB_CTL, dev_priv->saveFDI_RXB_CTL);
555 I915_WRITE(FDI_TXB_CTL, dev_priv->saveFDI_TXB_CTL);
556
557 I915_WRITE(PFB_CTL_1, dev_priv->savePFB_CTL_1);
558 I915_WRITE(PFB_WIN_SZ, dev_priv->savePFB_WIN_SZ);
559 I915_WRITE(PFB_WIN_POS, dev_priv->savePFB_WIN_POS);
560
Zhenyu Wang5586c8b2009-11-06 02:13:02 +0000561 I915_WRITE(TRANSBCONF, dev_priv->saveTRANSBCONF);
Zhenyu Wang42048782009-10-21 15:27:01 +0800562 I915_WRITE(TRANS_HTOTAL_B, dev_priv->saveTRANS_HTOTAL_B);
563 I915_WRITE(TRANS_HBLANK_B, dev_priv->saveTRANS_HBLANK_B);
564 I915_WRITE(TRANS_HSYNC_B, dev_priv->saveTRANS_HSYNC_B);
565 I915_WRITE(TRANS_VTOTAL_B, dev_priv->saveTRANS_VTOTAL_B);
566 I915_WRITE(TRANS_VBLANK_B, dev_priv->saveTRANS_VBLANK_B);
567 I915_WRITE(TRANS_VSYNC_B, dev_priv->saveTRANS_VSYNC_B);
568 }
Zhao Yakuifccdaba2009-07-08 14:13:14 +0800569
570 /* Restore plane info */
571 I915_WRITE(DSPBSIZE, dev_priv->saveDSPBSIZE);
572 I915_WRITE(DSPBPOS, dev_priv->saveDSPBPOS);
573 I915_WRITE(PIPEBSRC, dev_priv->savePIPEBSRC);
574 I915_WRITE(DSPBADDR, dev_priv->saveDSPBADDR);
575 I915_WRITE(DSPBSTRIDE, dev_priv->saveDSPBSTRIDE);
Chris Wilsona6c45cf2010-09-17 00:32:17 +0100576 if (INTEL_INFO(dev)->gen >= 4) {
Zhao Yakuifccdaba2009-07-08 14:13:14 +0800577 I915_WRITE(DSPBSURF, dev_priv->saveDSPBSURF);
578 I915_WRITE(DSPBTILEOFF, dev_priv->saveDSPBTILEOFF);
579 }
580
581 I915_WRITE(PIPEBCONF, dev_priv->savePIPEBCONF);
582
583 i915_restore_palette(dev, PIPE_B);
584 /* Enable the plane */
585 I915_WRITE(DSPBCNTR, dev_priv->saveDSPBCNTR);
586 I915_WRITE(DSPBADDR, I915_READ(DSPBADDR));
587
Chris Wilsonf3c91c12010-11-21 09:56:00 +0000588 /* Cursor state */
589 I915_WRITE(CURAPOS, dev_priv->saveCURAPOS);
590 I915_WRITE(CURACNTR, dev_priv->saveCURACNTR);
591 I915_WRITE(CURABASE, dev_priv->saveCURABASE);
592 I915_WRITE(CURBPOS, dev_priv->saveCURBPOS);
593 I915_WRITE(CURBCNTR, dev_priv->saveCURBCNTR);
594 I915_WRITE(CURBBASE, dev_priv->saveCURBBASE);
595 if (IS_GEN2(dev))
596 I915_WRITE(CURSIZE, dev_priv->saveCURSIZE);
597
Zhao Yakuifccdaba2009-07-08 14:13:14 +0800598 return;
599}
Ben Gamari1341d652009-09-14 17:48:42 -0400600
601void i915_save_display(struct drm_device *dev)
Zhao Yakuifccdaba2009-07-08 14:13:14 +0800602{
603 struct drm_i915_private *dev_priv = dev->dev_private;
Zhao Yakuifccdaba2009-07-08 14:13:14 +0800604
605 /* Display arbitration control */
606 dev_priv->saveDSPARB = I915_READ(DSPARB);
607
608 /* This is only meaningful in non-KMS mode */
609 /* Don't save them in KMS mode */
610 i915_save_modeset_reg(dev);
Ben Gamari1341d652009-09-14 17:48:42 -0400611
Jesse Barnes317c35d2008-08-25 15:11:06 -0700612 /* CRT state */
Chris Wilson90eb77b2010-08-14 14:41:23 +0100613 if (HAS_PCH_SPLIT(dev)) {
Zhenyu Wang42048782009-10-21 15:27:01 +0800614 dev_priv->saveADPA = I915_READ(PCH_ADPA);
615 } else {
616 dev_priv->saveADPA = I915_READ(ADPA);
617 }
Jesse Barnes317c35d2008-08-25 15:11:06 -0700618
619 /* LVDS state */
Chris Wilson90eb77b2010-08-14 14:41:23 +0100620 if (HAS_PCH_SPLIT(dev)) {
Zhenyu Wang42048782009-10-21 15:27:01 +0800621 dev_priv->savePP_CONTROL = I915_READ(PCH_PP_CONTROL);
622 dev_priv->saveBLC_PWM_CTL = I915_READ(BLC_PWM_PCH_CTL1);
623 dev_priv->saveBLC_PWM_CTL2 = I915_READ(BLC_PWM_PCH_CTL2);
624 dev_priv->saveBLC_CPU_PWM_CTL = I915_READ(BLC_PWM_CPU_CTL);
625 dev_priv->saveBLC_CPU_PWM_CTL2 = I915_READ(BLC_PWM_CPU_CTL2);
626 dev_priv->saveLVDS = I915_READ(PCH_LVDS);
627 } else {
628 dev_priv->savePP_CONTROL = I915_READ(PP_CONTROL);
629 dev_priv->savePFIT_PGM_RATIOS = I915_READ(PFIT_PGM_RATIOS);
630 dev_priv->saveBLC_PWM_CTL = I915_READ(BLC_PWM_CTL);
631 dev_priv->saveBLC_HIST_CTL = I915_READ(BLC_HIST_CTL);
Chris Wilsona6c45cf2010-09-17 00:32:17 +0100632 if (INTEL_INFO(dev)->gen >= 4)
Zhenyu Wang42048782009-10-21 15:27:01 +0800633 dev_priv->saveBLC_PWM_CTL2 = I915_READ(BLC_PWM_CTL2);
634 if (IS_MOBILE(dev) && !IS_I830(dev))
635 dev_priv->saveLVDS = I915_READ(LVDS);
636 }
637
Chris Wilson90eb77b2010-08-14 14:41:23 +0100638 if (!IS_I830(dev) && !IS_845G(dev) && !HAS_PCH_SPLIT(dev))
Jesse Barnes317c35d2008-08-25 15:11:06 -0700639 dev_priv->savePFIT_CONTROL = I915_READ(PFIT_CONTROL);
Zhenyu Wang42048782009-10-21 15:27:01 +0800640
Chris Wilson90eb77b2010-08-14 14:41:23 +0100641 if (HAS_PCH_SPLIT(dev)) {
Zhenyu Wang42048782009-10-21 15:27:01 +0800642 dev_priv->savePP_ON_DELAYS = I915_READ(PCH_PP_ON_DELAYS);
643 dev_priv->savePP_OFF_DELAYS = I915_READ(PCH_PP_OFF_DELAYS);
644 dev_priv->savePP_DIVISOR = I915_READ(PCH_PP_DIVISOR);
645 } else {
646 dev_priv->savePP_ON_DELAYS = I915_READ(PP_ON_DELAYS);
647 dev_priv->savePP_OFF_DELAYS = I915_READ(PP_OFF_DELAYS);
648 dev_priv->savePP_DIVISOR = I915_READ(PP_DIVISOR);
649 }
Jesse Barnes317c35d2008-08-25 15:11:06 -0700650
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700651 /* Display Port state */
652 if (SUPPORTS_INTEGRATED_DP(dev)) {
653 dev_priv->saveDP_B = I915_READ(DP_B);
654 dev_priv->saveDP_C = I915_READ(DP_C);
655 dev_priv->saveDP_D = I915_READ(DP_D);
656 dev_priv->savePIPEA_GMCH_DATA_M = I915_READ(PIPEA_GMCH_DATA_M);
657 dev_priv->savePIPEB_GMCH_DATA_M = I915_READ(PIPEB_GMCH_DATA_M);
658 dev_priv->savePIPEA_GMCH_DATA_N = I915_READ(PIPEA_GMCH_DATA_N);
659 dev_priv->savePIPEB_GMCH_DATA_N = I915_READ(PIPEB_GMCH_DATA_N);
660 dev_priv->savePIPEA_DP_LINK_M = I915_READ(PIPEA_DP_LINK_M);
661 dev_priv->savePIPEB_DP_LINK_M = I915_READ(PIPEB_DP_LINK_M);
662 dev_priv->savePIPEA_DP_LINK_N = I915_READ(PIPEA_DP_LINK_N);
663 dev_priv->savePIPEB_DP_LINK_N = I915_READ(PIPEB_DP_LINK_N);
664 }
Jesse Barnes317c35d2008-08-25 15:11:06 -0700665 /* FIXME: save TV & SDVO state */
666
Zhao Yakuia2c459e2010-03-19 17:05:10 +0800667 /* Only save FBC state on the platform that supports FBC */
668 if (I915_HAS_FBC(dev)) {
Chris Wilson90eb77b2010-08-14 14:41:23 +0100669 if (HAS_PCH_SPLIT(dev)) {
Zhao Yakuib52eb4d2010-06-12 14:32:27 +0800670 dev_priv->saveDPFC_CB_BASE = I915_READ(ILK_DPFC_CB_BASE);
671 } else if (IS_GM45(dev)) {
Zhao Yakuia2c459e2010-03-19 17:05:10 +0800672 dev_priv->saveDPFC_CB_BASE = I915_READ(DPFC_CB_BASE);
673 } else {
674 dev_priv->saveFBC_CFB_BASE = I915_READ(FBC_CFB_BASE);
675 dev_priv->saveFBC_LL_BASE = I915_READ(FBC_LL_BASE);
676 dev_priv->saveFBC_CONTROL2 = I915_READ(FBC_CONTROL2);
677 dev_priv->saveFBC_CONTROL = I915_READ(FBC_CONTROL);
678 }
Jesse Barnes06027f92009-10-05 13:47:26 -0700679 }
Jesse Barnes317c35d2008-08-25 15:11:06 -0700680
Jesse Barnes317c35d2008-08-25 15:11:06 -0700681 /* VGA state */
682 dev_priv->saveVGA0 = I915_READ(VGA0);
683 dev_priv->saveVGA1 = I915_READ(VGA1);
684 dev_priv->saveVGA_PD = I915_READ(VGA_PD);
Chris Wilson90eb77b2010-08-14 14:41:23 +0100685 if (HAS_PCH_SPLIT(dev))
Zhenyu Wang42048782009-10-21 15:27:01 +0800686 dev_priv->saveVGACNTRL = I915_READ(CPU_VGACNTRL);
687 else
688 dev_priv->saveVGACNTRL = I915_READ(VGACNTRL);
Jesse Barnes317c35d2008-08-25 15:11:06 -0700689
Jesse Barnes317c35d2008-08-25 15:11:06 -0700690 i915_save_vga(dev);
Jesse Barnes317c35d2008-08-25 15:11:06 -0700691}
692
Ben Gamari1341d652009-09-14 17:48:42 -0400693void i915_restore_display(struct drm_device *dev)
Jesse Barnes317c35d2008-08-25 15:11:06 -0700694{
695 struct drm_i915_private *dev_priv = dev->dev_private;
Peng Li461cba22008-11-18 12:39:02 +0800696
Keith Packard881ee982008-11-02 23:08:44 -0800697 /* Display arbitration */
Jesse Barnes317c35d2008-08-25 15:11:06 -0700698 I915_WRITE(DSPARB, dev_priv->saveDSPARB);
699
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700700 /* Display port ratios (must be done before clock is set) */
701 if (SUPPORTS_INTEGRATED_DP(dev)) {
702 I915_WRITE(PIPEA_GMCH_DATA_M, dev_priv->savePIPEA_GMCH_DATA_M);
703 I915_WRITE(PIPEB_GMCH_DATA_M, dev_priv->savePIPEB_GMCH_DATA_M);
704 I915_WRITE(PIPEA_GMCH_DATA_N, dev_priv->savePIPEA_GMCH_DATA_N);
705 I915_WRITE(PIPEB_GMCH_DATA_N, dev_priv->savePIPEB_GMCH_DATA_N);
706 I915_WRITE(PIPEA_DP_LINK_M, dev_priv->savePIPEA_DP_LINK_M);
707 I915_WRITE(PIPEB_DP_LINK_M, dev_priv->savePIPEB_DP_LINK_M);
708 I915_WRITE(PIPEA_DP_LINK_N, dev_priv->savePIPEA_DP_LINK_N);
709 I915_WRITE(PIPEB_DP_LINK_N, dev_priv->savePIPEB_DP_LINK_N);
710 }
Ben Gamari1341d652009-09-14 17:48:42 -0400711
Zhao Yakuifccdaba2009-07-08 14:13:14 +0800712 /* This is only meaningful in non-KMS mode */
713 /* Don't restore them in KMS mode */
714 i915_restore_modeset_reg(dev);
Ben Gamari1341d652009-09-14 17:48:42 -0400715
Jesse Barnes317c35d2008-08-25 15:11:06 -0700716 /* CRT state */
Chris Wilson90eb77b2010-08-14 14:41:23 +0100717 if (HAS_PCH_SPLIT(dev))
Zhenyu Wang42048782009-10-21 15:27:01 +0800718 I915_WRITE(PCH_ADPA, dev_priv->saveADPA);
719 else
720 I915_WRITE(ADPA, dev_priv->saveADPA);
Jesse Barnes317c35d2008-08-25 15:11:06 -0700721
722 /* LVDS state */
Chris Wilsona6c45cf2010-09-17 00:32:17 +0100723 if (INTEL_INFO(dev)->gen >= 4 && !HAS_PCH_SPLIT(dev))
Jesse Barnes317c35d2008-08-25 15:11:06 -0700724 I915_WRITE(BLC_PWM_CTL2, dev_priv->saveBLC_PWM_CTL2);
Zhenyu Wang42048782009-10-21 15:27:01 +0800725
Chris Wilson90eb77b2010-08-14 14:41:23 +0100726 if (HAS_PCH_SPLIT(dev)) {
Zhenyu Wang42048782009-10-21 15:27:01 +0800727 I915_WRITE(PCH_LVDS, dev_priv->saveLVDS);
728 } else if (IS_MOBILE(dev) && !IS_I830(dev))
Jesse Barnes317c35d2008-08-25 15:11:06 -0700729 I915_WRITE(LVDS, dev_priv->saveLVDS);
Zhenyu Wang42048782009-10-21 15:27:01 +0800730
Chris Wilson90eb77b2010-08-14 14:41:23 +0100731 if (!IS_I830(dev) && !IS_845G(dev) && !HAS_PCH_SPLIT(dev))
Jesse Barnes317c35d2008-08-25 15:11:06 -0700732 I915_WRITE(PFIT_CONTROL, dev_priv->savePFIT_CONTROL);
733
Chris Wilson90eb77b2010-08-14 14:41:23 +0100734 if (HAS_PCH_SPLIT(dev)) {
Zhenyu Wang42048782009-10-21 15:27:01 +0800735 I915_WRITE(BLC_PWM_PCH_CTL1, dev_priv->saveBLC_PWM_CTL);
736 I915_WRITE(BLC_PWM_PCH_CTL2, dev_priv->saveBLC_PWM_CTL2);
737 I915_WRITE(BLC_PWM_CPU_CTL, dev_priv->saveBLC_CPU_PWM_CTL);
738 I915_WRITE(BLC_PWM_CPU_CTL2, dev_priv->saveBLC_CPU_PWM_CTL2);
739 I915_WRITE(PCH_PP_ON_DELAYS, dev_priv->savePP_ON_DELAYS);
740 I915_WRITE(PCH_PP_OFF_DELAYS, dev_priv->savePP_OFF_DELAYS);
741 I915_WRITE(PCH_PP_DIVISOR, dev_priv->savePP_DIVISOR);
742 I915_WRITE(PCH_PP_CONTROL, dev_priv->savePP_CONTROL);
Jesse Barnes88271da2011-01-05 12:01:24 -0800743 I915_WRITE(RSTDBYCTL,
Matthew Garrettb5b72e82010-02-02 18:30:47 +0000744 dev_priv->saveMCHBAR_RENDER_STANDBY);
Zhenyu Wang42048782009-10-21 15:27:01 +0800745 } else {
746 I915_WRITE(PFIT_PGM_RATIOS, dev_priv->savePFIT_PGM_RATIOS);
747 I915_WRITE(BLC_PWM_CTL, dev_priv->saveBLC_PWM_CTL);
748 I915_WRITE(BLC_HIST_CTL, dev_priv->saveBLC_HIST_CTL);
749 I915_WRITE(PP_ON_DELAYS, dev_priv->savePP_ON_DELAYS);
750 I915_WRITE(PP_OFF_DELAYS, dev_priv->savePP_OFF_DELAYS);
751 I915_WRITE(PP_DIVISOR, dev_priv->savePP_DIVISOR);
752 I915_WRITE(PP_CONTROL, dev_priv->savePP_CONTROL);
753 }
Jesse Barnes317c35d2008-08-25 15:11:06 -0700754
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700755 /* Display Port state */
756 if (SUPPORTS_INTEGRATED_DP(dev)) {
757 I915_WRITE(DP_B, dev_priv->saveDP_B);
758 I915_WRITE(DP_C, dev_priv->saveDP_C);
759 I915_WRITE(DP_D, dev_priv->saveDP_D);
760 }
Jesse Barnes317c35d2008-08-25 15:11:06 -0700761 /* FIXME: restore TV & SDVO state */
762
Zhao Yakuia2c459e2010-03-19 17:05:10 +0800763 /* only restore FBC info on the platform that supports FBC*/
764 if (I915_HAS_FBC(dev)) {
Chris Wilson90eb77b2010-08-14 14:41:23 +0100765 if (HAS_PCH_SPLIT(dev)) {
Zhao Yakuib52eb4d2010-06-12 14:32:27 +0800766 ironlake_disable_fbc(dev);
767 I915_WRITE(ILK_DPFC_CB_BASE, dev_priv->saveDPFC_CB_BASE);
768 } else if (IS_GM45(dev)) {
Zhao Yakuia2c459e2010-03-19 17:05:10 +0800769 g4x_disable_fbc(dev);
770 I915_WRITE(DPFC_CB_BASE, dev_priv->saveDPFC_CB_BASE);
771 } else {
772 i8xx_disable_fbc(dev);
773 I915_WRITE(FBC_CFB_BASE, dev_priv->saveFBC_CFB_BASE);
774 I915_WRITE(FBC_LL_BASE, dev_priv->saveFBC_LL_BASE);
775 I915_WRITE(FBC_CONTROL2, dev_priv->saveFBC_CONTROL2);
776 I915_WRITE(FBC_CONTROL, dev_priv->saveFBC_CONTROL);
777 }
Jesse Barnes06027f92009-10-05 13:47:26 -0700778 }
Jesse Barnes317c35d2008-08-25 15:11:06 -0700779 /* VGA state */
Chris Wilson90eb77b2010-08-14 14:41:23 +0100780 if (HAS_PCH_SPLIT(dev))
Zhenyu Wang42048782009-10-21 15:27:01 +0800781 I915_WRITE(CPU_VGACNTRL, dev_priv->saveVGACNTRL);
782 else
783 I915_WRITE(VGACNTRL, dev_priv->saveVGACNTRL);
Jesse Barnes317c35d2008-08-25 15:11:06 -0700784 I915_WRITE(VGA0, dev_priv->saveVGA0);
785 I915_WRITE(VGA1, dev_priv->saveVGA1);
786 I915_WRITE(VGA_PD, dev_priv->saveVGA_PD);
Chris Wilson72bcb262010-08-14 14:41:22 +0100787 POSTING_READ(VGA_PD);
788 udelay(150);
Jesse Barnes317c35d2008-08-25 15:11:06 -0700789
Ben Gamari1341d652009-09-14 17:48:42 -0400790 i915_restore_vga(dev);
791}
792
793int i915_save_state(struct drm_device *dev)
794{
795 struct drm_i915_private *dev_priv = dev->dev_private;
796 int i;
797
798 pci_read_config_byte(dev->pdev, LBB, &dev_priv->saveLBB);
799
Ben Gamari1341d652009-09-14 17:48:42 -0400800 /* Hardware status page */
801 dev_priv->saveHWS = I915_READ(HWS_PGA);
802
803 i915_save_display(dev);
804
805 /* Interrupt state */
Chris Wilson90eb77b2010-08-14 14:41:23 +0100806 if (HAS_PCH_SPLIT(dev)) {
Zhenyu Wang42048782009-10-21 15:27:01 +0800807 dev_priv->saveDEIER = I915_READ(DEIER);
808 dev_priv->saveDEIMR = I915_READ(DEIMR);
809 dev_priv->saveGTIER = I915_READ(GTIER);
810 dev_priv->saveGTIMR = I915_READ(GTIMR);
811 dev_priv->saveFDI_RXA_IMR = I915_READ(FDI_RXA_IMR);
812 dev_priv->saveFDI_RXB_IMR = I915_READ(FDI_RXB_IMR);
Matthew Garrettb5b72e82010-02-02 18:30:47 +0000813 dev_priv->saveMCHBAR_RENDER_STANDBY =
Jesse Barnes88271da2011-01-05 12:01:24 -0800814 I915_READ(RSTDBYCTL);
Zhenyu Wang42048782009-10-21 15:27:01 +0800815 } else {
816 dev_priv->saveIER = I915_READ(IER);
817 dev_priv->saveIMR = I915_READ(IMR);
818 }
Ben Gamari1341d652009-09-14 17:48:42 -0400819
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800820 if (IS_IRONLAKE_M(dev))
Jesse Barnesf97108d2010-01-29 11:27:07 -0800821 ironlake_disable_drps(dev);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800822 if (IS_GEN6(dev))
823 gen6_disable_rps(dev);
Jesse Barnesf97108d2010-01-29 11:27:07 -0800824
Chris Wilson5909a772010-12-20 09:45:15 +0000825 /* XXX disabling the clock gating breaks suspend on gm45
Chris Wilson0cdab212010-12-05 17:27:06 +0000826 intel_disable_clock_gating(dev);
Chris Wilson5909a772010-12-20 09:45:15 +0000827 */
Chris Wilson0cdab212010-12-05 17:27:06 +0000828
Ben Gamari1341d652009-09-14 17:48:42 -0400829 /* Cache mode state */
830 dev_priv->saveCACHE_MODE_0 = I915_READ(CACHE_MODE_0);
831
832 /* Memory Arbitration state */
833 dev_priv->saveMI_ARB_STATE = I915_READ(MI_ARB_STATE);
834
835 /* Scratch space */
836 for (i = 0; i < 16; i++) {
837 dev_priv->saveSWF0[i] = I915_READ(SWF00 + (i << 2));
838 dev_priv->saveSWF1[i] = I915_READ(SWF10 + (i << 2));
839 }
840 for (i = 0; i < 3; i++)
841 dev_priv->saveSWF2[i] = I915_READ(SWF30 + (i << 2));
842
Ben Gamari1341d652009-09-14 17:48:42 -0400843 return 0;
844}
845
846int i915_restore_state(struct drm_device *dev)
847{
848 struct drm_i915_private *dev_priv = dev->dev_private;
849 int i;
850
851 pci_write_config_byte(dev->pdev, LBB, dev_priv->saveLBB);
852
Ben Gamari1341d652009-09-14 17:48:42 -0400853 /* Hardware status page */
854 I915_WRITE(HWS_PGA, dev_priv->saveHWS);
855
Ben Gamari1341d652009-09-14 17:48:42 -0400856 i915_restore_display(dev);
857
858 /* Interrupt state */
Chris Wilson90eb77b2010-08-14 14:41:23 +0100859 if (HAS_PCH_SPLIT(dev)) {
Zhenyu Wang42048782009-10-21 15:27:01 +0800860 I915_WRITE(DEIER, dev_priv->saveDEIER);
861 I915_WRITE(DEIMR, dev_priv->saveDEIMR);
862 I915_WRITE(GTIER, dev_priv->saveGTIER);
863 I915_WRITE(GTIMR, dev_priv->saveGTIMR);
864 I915_WRITE(FDI_RXA_IMR, dev_priv->saveFDI_RXA_IMR);
865 I915_WRITE(FDI_RXB_IMR, dev_priv->saveFDI_RXB_IMR);
866 } else {
867 I915_WRITE (IER, dev_priv->saveIER);
868 I915_WRITE (IMR, dev_priv->saveIMR);
869 }
Ben Gamari1341d652009-09-14 17:48:42 -0400870
Jesse Barnes317c35d2008-08-25 15:11:06 -0700871 /* Clock gating state */
Chris Wilson0cdab212010-12-05 17:27:06 +0000872 intel_enable_clock_gating(dev);
Jesse Barnes317c35d2008-08-25 15:11:06 -0700873
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800874 if (IS_IRONLAKE_M(dev)) {
Jesse Barnesf97108d2010-01-29 11:27:07 -0800875 ironlake_enable_drps(dev);
Kyle McMartin48fcfc82010-11-03 16:27:57 -0400876 intel_init_emon(dev);
877 }
Jesse Barnesf97108d2010-01-29 11:27:07 -0800878
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800879 if (IS_GEN6(dev))
880 gen6_enable_rps(dev_priv);
881
Jesse Barnes317c35d2008-08-25 15:11:06 -0700882 /* Cache mode state */
883 I915_WRITE (CACHE_MODE_0, dev_priv->saveCACHE_MODE_0 | 0xffff0000);
884
885 /* Memory arbitration state */
886 I915_WRITE (MI_ARB_STATE, dev_priv->saveMI_ARB_STATE | 0xffff0000);
887
888 for (i = 0; i < 16; i++) {
889 I915_WRITE(SWF00 + (i << 2), dev_priv->saveSWF0[i]);
Roel Kluin819e0062009-07-26 00:50:38 +0200890 I915_WRITE(SWF10 + (i << 2), dev_priv->saveSWF1[i]);
Jesse Barnes317c35d2008-08-25 15:11:06 -0700891 }
892 for (i = 0; i < 3; i++)
893 I915_WRITE(SWF30 + (i << 2), dev_priv->saveSWF2[i]);
894
Chris Wilsonf899fc62010-07-20 15:44:45 -0700895 intel_i2c_reset(dev);
Eric Anholtf0217c42009-12-01 11:56:30 -0800896
Jesse Barnes317c35d2008-08-25 15:11:06 -0700897 return 0;
898}