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_fbc.h"
29 #include "display/intel_gmbus.h"
30 #include "display/intel_vga.h"
31 
32 #include "i915_drv.h"
33 #include "i915_reg.h"
34 #include "i915_suspend.h"
35 
36 static void intel_save_swf(struct drm_i915_private *dev_priv)
37 {
38 	int i;
39 
40 	/* Scratch space */
41 	if (IS_GEN(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, SWF0(i));
44 			dev_priv->regfile.saveSWF1[i] = intel_de_read(dev_priv, SWF1(i));
45 		}
46 		for (i = 0; i < 3; i++)
47 			dev_priv->regfile.saveSWF3[i] = intel_de_read(dev_priv, SWF3(i));
48 	} else if (IS_GEN(dev_priv, 2)) {
49 		for (i = 0; i < 7; i++)
50 			dev_priv->regfile.saveSWF1[i] = intel_de_read(dev_priv, SWF1(i));
51 	} else if (HAS_GMCH(dev_priv)) {
52 		for (i = 0; i < 16; i++) {
53 			dev_priv->regfile.saveSWF0[i] = intel_de_read(dev_priv, SWF0(i));
54 			dev_priv->regfile.saveSWF1[i] = intel_de_read(dev_priv, SWF1(i));
55 		}
56 		for (i = 0; i < 3; i++)
57 			dev_priv->regfile.saveSWF3[i] = intel_de_read(dev_priv, SWF3(i));
58 	}
59 }
60 
61 static void intel_restore_swf(struct drm_i915_private *dev_priv)
62 {
63 	int i;
64 
65 	/* Scratch space */
66 	if (IS_GEN(dev_priv, 2) && IS_MOBILE(dev_priv)) {
67 		for (i = 0; i < 7; i++) {
68 			intel_de_write(dev_priv, SWF0(i), dev_priv->regfile.saveSWF0[i]);
69 			intel_de_write(dev_priv, SWF1(i), dev_priv->regfile.saveSWF1[i]);
70 		}
71 		for (i = 0; i < 3; i++)
72 			intel_de_write(dev_priv, SWF3(i), dev_priv->regfile.saveSWF3[i]);
73 	} else if (IS_GEN(dev_priv, 2)) {
74 		for (i = 0; i < 7; i++)
75 			intel_de_write(dev_priv, SWF1(i), dev_priv->regfile.saveSWF1[i]);
76 	} else if (HAS_GMCH(dev_priv)) {
77 		for (i = 0; i < 16; i++) {
78 			intel_de_write(dev_priv, SWF0(i), dev_priv->regfile.saveSWF0[i]);
79 			intel_de_write(dev_priv, SWF1(i), dev_priv->regfile.saveSWF1[i]);
80 		}
81 		for (i = 0; i < 3; i++)
82 			intel_de_write(dev_priv, SWF3(i), dev_priv->regfile.saveSWF3[i]);
83 	}
84 }
85 
86 void i915_save_display(struct drm_i915_private *dev_priv)
87 {
88 	struct pci_dev *pdev = to_pci_dev(dev_priv->drm.dev);
89 
90 	/* Display arbitration control */
91 	if (INTEL_GEN(dev_priv) <= 4)
92 		dev_priv->regfile.saveDSPARB = intel_de_read(dev_priv, DSPARB);
93 
94 	if (IS_GEN(dev_priv, 4))
95 		pci_read_config_word(pdev, GCDGMBUS,
96 				     &dev_priv->regfile.saveGCDGMBUS);
97 
98 	intel_save_swf(dev_priv);
99 }
100 
101 void i915_restore_display(struct drm_i915_private *dev_priv)
102 {
103 	struct pci_dev *pdev = to_pci_dev(dev_priv->drm.dev);
104 
105 	intel_restore_swf(dev_priv);
106 
107 	if (IS_GEN(dev_priv, 4))
108 		pci_write_config_word(pdev, GCDGMBUS,
109 				      dev_priv->regfile.saveGCDGMBUS);
110 
111 	/* Display arbitration */
112 	if (INTEL_GEN(dev_priv) <= 4)
113 		intel_de_write(dev_priv, DSPARB, dev_priv->regfile.saveDSPARB);
114 
115 	/* only restore FBC info on the platform that supports FBC*/
116 	intel_fbc_global_disable(dev_priv);
117 
118 	intel_vga_redisable(dev_priv);
119 
120 	intel_gmbus_reset(dev_priv);
121 }
122