xref: /linux/drivers/gpu/drm/i915/i915_suspend.c (revision a3a02a52bcfcbcc4a637d4b68bf1bc391c9fad02)
1 /*
2  *
3  * Copyright 2008 (c) Intel Corporation
4  *   Jesse Barnes <jbarnes@virtuousgeek.org>
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the
8  * "Software"), to deal in the Software without restriction, including
9  * without limitation the rights to use, copy, modify, merge, publish,
10  * distribute, sub license, and/or sell copies of the Software, and to
11  * permit persons to whom the Software is furnished to do so, subject to
12  * the following conditions:
13  *
14  * The above copyright notice and this permission notice (including the
15  * next paragraph) shall be included in all copies or substantial portions
16  * of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21  * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25  */
26 
27 #include "display/intel_de.h"
28 #include "display/intel_gmbus.h"
29 #include "display/intel_vga.h"
30 
31 #include "i915_drv.h"
32 #include "i915_reg.h"
33 #include "i915_suspend.h"
34 #include "intel_pci_config.h"
35 
36 static void intel_save_swf(struct drm_i915_private *dev_priv)
37 {
38 	int i;
39 
40 	/* Scratch space */
41 	if (GRAPHICS_VER(dev_priv) == 2 && IS_MOBILE(dev_priv)) {
42 		for (i = 0; i < 7; i++) {
43 			dev_priv->regfile.saveSWF0[i] = intel_de_read(dev_priv,
44 								      SWF0(dev_priv, i));
45 			dev_priv->regfile.saveSWF1[i] = intel_de_read(dev_priv,
46 								      SWF1(dev_priv, i));
47 		}
48 		for (i = 0; i < 3; i++)
49 			dev_priv->regfile.saveSWF3[i] = intel_de_read(dev_priv,
50 								      SWF3(dev_priv, i));
51 	} else if (GRAPHICS_VER(dev_priv) == 2) {
52 		for (i = 0; i < 7; i++)
53 			dev_priv->regfile.saveSWF1[i] = intel_de_read(dev_priv,
54 								      SWF1(dev_priv, i));
55 	} else if (HAS_GMCH(dev_priv)) {
56 		for (i = 0; i < 16; i++) {
57 			dev_priv->regfile.saveSWF0[i] = intel_de_read(dev_priv,
58 								      SWF0(dev_priv, i));
59 			dev_priv->regfile.saveSWF1[i] = intel_de_read(dev_priv,
60 								      SWF1(dev_priv, i));
61 		}
62 		for (i = 0; i < 3; i++)
63 			dev_priv->regfile.saveSWF3[i] = intel_de_read(dev_priv,
64 								      SWF3(dev_priv, i));
65 	}
66 }
67 
68 static void intel_restore_swf(struct drm_i915_private *dev_priv)
69 {
70 	int i;
71 
72 	/* Scratch space */
73 	if (GRAPHICS_VER(dev_priv) == 2 && IS_MOBILE(dev_priv)) {
74 		for (i = 0; i < 7; i++) {
75 			intel_de_write(dev_priv, SWF0(dev_priv, i),
76 				       dev_priv->regfile.saveSWF0[i]);
77 			intel_de_write(dev_priv, SWF1(dev_priv, i),
78 				       dev_priv->regfile.saveSWF1[i]);
79 		}
80 		for (i = 0; i < 3; i++)
81 			intel_de_write(dev_priv, SWF3(dev_priv, i),
82 				       dev_priv->regfile.saveSWF3[i]);
83 	} else if (GRAPHICS_VER(dev_priv) == 2) {
84 		for (i = 0; i < 7; i++)
85 			intel_de_write(dev_priv, SWF1(dev_priv, i),
86 				       dev_priv->regfile.saveSWF1[i]);
87 	} else if (HAS_GMCH(dev_priv)) {
88 		for (i = 0; i < 16; i++) {
89 			intel_de_write(dev_priv, SWF0(dev_priv, i),
90 				       dev_priv->regfile.saveSWF0[i]);
91 			intel_de_write(dev_priv, SWF1(dev_priv, i),
92 				       dev_priv->regfile.saveSWF1[i]);
93 		}
94 		for (i = 0; i < 3; i++)
95 			intel_de_write(dev_priv, SWF3(dev_priv, i),
96 				       dev_priv->regfile.saveSWF3[i]);
97 	}
98 }
99 
100 void i915_save_display(struct drm_i915_private *dev_priv)
101 {
102 	struct pci_dev *pdev = to_pci_dev(dev_priv->drm.dev);
103 
104 	if (!HAS_DISPLAY(dev_priv))
105 		return;
106 
107 	/* Display arbitration control */
108 	if (GRAPHICS_VER(dev_priv) <= 4)
109 		dev_priv->regfile.saveDSPARB = intel_de_read(dev_priv,
110 							     DSPARB(dev_priv));
111 
112 	if (GRAPHICS_VER(dev_priv) == 4)
113 		pci_read_config_word(pdev, GCDGMBUS,
114 				     &dev_priv->regfile.saveGCDGMBUS);
115 
116 	intel_save_swf(dev_priv);
117 }
118 
119 void i915_restore_display(struct drm_i915_private *dev_priv)
120 {
121 	struct pci_dev *pdev = to_pci_dev(dev_priv->drm.dev);
122 
123 	if (!HAS_DISPLAY(dev_priv))
124 		return;
125 
126 	intel_restore_swf(dev_priv);
127 
128 	if (GRAPHICS_VER(dev_priv) == 4)
129 		pci_write_config_word(pdev, GCDGMBUS,
130 				      dev_priv->regfile.saveGCDGMBUS);
131 
132 	/* Display arbitration */
133 	if (GRAPHICS_VER(dev_priv) <= 4)
134 		intel_de_write(dev_priv, DSPARB(dev_priv),
135 			       dev_priv->regfile.saveDSPARB);
136 
137 	intel_vga_redisable(dev_priv);
138 
139 	intel_gmbus_reset(dev_priv);
140 }
141