blob: 1ccac618468ef6360f823ef5b5650efcdad5ca01 [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
David Howells760285e2012-10-02 18:01:07 +010027#include <drm/drmP.h>
28#include <drm/i915_drm.h>
Eric Anholtf0217c42009-12-01 11:56:30 -080029#include "intel_drv.h"
Eugeni Dodonov5e5b7fa2012-01-07 23:40:34 -020030#include "i915_reg.h"
Jesse Barnes317c35d2008-08-25 15:11:06 -070031
Keith Packardd70bed12011-06-29 00:30:34 -070032static void i915_save_display(struct drm_device *dev)
Zhao Yakuifccdaba2009-07-08 14:13:14 +080033{
34 struct drm_i915_private *dev_priv = dev->dev_private;
Zhao Yakuifccdaba2009-07-08 14:13:14 +080035
36 /* Display arbitration control */
Paulo Zanoni8de0add2013-01-18 18:29:03 -020037 if (INTEL_INFO(dev)->gen <= 4)
38 dev_priv->regfile.saveDSPARB = I915_READ(DSPARB);
Zhao Yakuifccdaba2009-07-08 14:13:14 +080039
Jesse Barnes317c35d2008-08-25 15:11:06 -070040 /* LVDS state */
Jani Nikula1c5bb422014-11-12 17:01:10 +020041 if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev))
42 dev_priv->regfile.saveLVDS = I915_READ(PCH_LVDS);
43 else if (INTEL_INFO(dev)->gen <= 4 && IS_MOBILE(dev) && !IS_I830(dev))
44 dev_priv->regfile.saveLVDS = I915_READ(LVDS);
45
46 /* Panel power sequencer */
Chris Wilson90eb77b2010-08-14 14:41:23 +010047 if (HAS_PCH_SPLIT(dev)) {
Daniel Vetterf4c956a2012-11-02 19:55:02 +010048 dev_priv->regfile.savePP_CONTROL = I915_READ(PCH_PP_CONTROL);
Daniel Vetterf4c956a2012-11-02 19:55:02 +010049 dev_priv->regfile.savePP_ON_DELAYS = I915_READ(PCH_PP_ON_DELAYS);
50 dev_priv->regfile.savePP_OFF_DELAYS = I915_READ(PCH_PP_OFF_DELAYS);
51 dev_priv->regfile.savePP_DIVISOR = I915_READ(PCH_PP_DIVISOR);
Jani Nikulac7e20732014-11-11 16:48:03 +020052 } else if (!IS_VALLEYVIEW(dev)) {
Jani Nikula1c5bb422014-11-12 17:01:10 +020053 dev_priv->regfile.savePP_CONTROL = I915_READ(PP_CONTROL);
Daniel Vetterf4c956a2012-11-02 19:55:02 +010054 dev_priv->regfile.savePP_ON_DELAYS = I915_READ(PP_ON_DELAYS);
55 dev_priv->regfile.savePP_OFF_DELAYS = I915_READ(PP_OFF_DELAYS);
56 dev_priv->regfile.savePP_DIVISOR = I915_READ(PP_DIVISOR);
Zhenyu Wang42048782009-10-21 15:27:01 +080057 }
Jesse Barnes317c35d2008-08-25 15:11:06 -070058
Ville Syrjälä768cf7f2014-01-23 16:49:15 +020059 /* save FBC interval */
60 if (HAS_FBC(dev) && INTEL_INFO(dev)->gen <= 4 && !IS_G4X(dev))
61 dev_priv->regfile.saveFBC_CONTROL = I915_READ(FBC_CONTROL);
Jesse Barnes317c35d2008-08-25 15:11:06 -070062}
63
Keith Packardd70bed12011-06-29 00:30:34 -070064static void i915_restore_display(struct drm_device *dev)
Jesse Barnes317c35d2008-08-25 15:11:06 -070065{
66 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes2ec90662013-02-19 12:11:38 -080067 u32 mask = 0xffffffff;
Peng Li461cba22008-11-18 12:39:02 +080068
Keith Packard881ee982008-11-02 23:08:44 -080069 /* Display arbitration */
Paulo Zanoni8de0add2013-01-18 18:29:03 -020070 if (INTEL_INFO(dev)->gen <= 4)
71 I915_WRITE(DSPARB, dev_priv->regfile.saveDSPARB);
Jesse Barnes317c35d2008-08-25 15:11:06 -070072
Daniel Vetter8634bd42015-02-23 12:03:30 +010073 mask = ~LVDS_PORT_EN;
Jesse Barnes2ec90662013-02-19 12:11:38 -080074
Jani Nikula1c5bb422014-11-12 17:01:10 +020075 /* LVDS state */
Paulo Zanoni4deb88a2013-03-06 20:03:20 -030076 if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev))
Jesse Barnes2ec90662013-02-19 12:11:38 -080077 I915_WRITE(PCH_LVDS, dev_priv->regfile.saveLVDS & mask);
Paulo Zanoni4deb88a2013-03-06 20:03:20 -030078 else if (INTEL_INFO(dev)->gen <= 4 && IS_MOBILE(dev) && !IS_I830(dev))
Jesse Barnes2ec90662013-02-19 12:11:38 -080079 I915_WRITE(LVDS, dev_priv->regfile.saveLVDS & mask);
Zhenyu Wang42048782009-10-21 15:27:01 +080080
Jani Nikula1c5bb422014-11-12 17:01:10 +020081 /* Panel power sequencer */
Chris Wilson90eb77b2010-08-14 14:41:23 +010082 if (HAS_PCH_SPLIT(dev)) {
Daniel Vetterf4c956a2012-11-02 19:55:02 +010083 I915_WRITE(PCH_PP_ON_DELAYS, dev_priv->regfile.savePP_ON_DELAYS);
84 I915_WRITE(PCH_PP_OFF_DELAYS, dev_priv->regfile.savePP_OFF_DELAYS);
85 I915_WRITE(PCH_PP_DIVISOR, dev_priv->regfile.savePP_DIVISOR);
86 I915_WRITE(PCH_PP_CONTROL, dev_priv->regfile.savePP_CONTROL);
Jani Nikulab0cd3242014-11-12 16:25:43 +020087 } else if (!IS_VALLEYVIEW(dev)) {
Daniel Vetterf4c956a2012-11-02 19:55:02 +010088 I915_WRITE(PP_ON_DELAYS, dev_priv->regfile.savePP_ON_DELAYS);
89 I915_WRITE(PP_OFF_DELAYS, dev_priv->regfile.savePP_OFF_DELAYS);
90 I915_WRITE(PP_DIVISOR, dev_priv->regfile.savePP_DIVISOR);
91 I915_WRITE(PP_CONTROL, dev_priv->regfile.savePP_CONTROL);
Zhenyu Wang42048782009-10-21 15:27:01 +080092 }
Jesse Barnes317c35d2008-08-25 15:11:06 -070093
Zhao Yakuia2c459e2010-03-19 17:05:10 +080094 /* only restore FBC info on the platform that supports FBC*/
Paulo Zanoni7733b492015-07-07 15:26:04 -030095 intel_fbc_disable(dev_priv);
Ville Syrjälä768cf7f2014-01-23 16:49:15 +020096
97 /* restore FBC interval */
98 if (HAS_FBC(dev) && INTEL_INFO(dev)->gen <= 4 && !IS_G4X(dev))
99 I915_WRITE(FBC_CONTROL, dev_priv->regfile.saveFBC_CONTROL);
Daniel Vettera65e8272013-01-25 17:53:22 +0100100
Daniel Vetter8634bd42015-02-23 12:03:30 +0100101 i915_redisable_vga(dev);
Ben Gamari1341d652009-09-14 17:48:42 -0400102}
103
104int i915_save_state(struct drm_device *dev)
105{
106 struct drm_i915_private *dev_priv = dev->dev_private;
107 int i;
108
Keith Packardd70bed12011-06-29 00:30:34 -0700109 mutex_lock(&dev->struct_mutex);
110
Ben Gamari1341d652009-09-14 17:48:42 -0400111 i915_save_display(dev);
112
Jesse Barnes9f49c372014-12-10 12:16:05 -0800113 if (IS_GEN4(dev))
114 pci_read_config_word(dev->pdev, GCDGMBUS,
115 &dev_priv->regfile.saveGCDGMBUS);
116
Ben Gamari1341d652009-09-14 17:48:42 -0400117 /* Cache mode state */
Jesse Barnese8cde232013-10-11 12:09:29 -0700118 if (INTEL_INFO(dev)->gen < 7)
119 dev_priv->regfile.saveCACHE_MODE_0 = I915_READ(CACHE_MODE_0);
Ben Gamari1341d652009-09-14 17:48:42 -0400120
121 /* Memory Arbitration state */
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100122 dev_priv->regfile.saveMI_ARB_STATE = I915_READ(MI_ARB_STATE);
Ben Gamari1341d652009-09-14 17:48:42 -0400123
124 /* Scratch space */
125 for (i = 0; i < 16; i++) {
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100126 dev_priv->regfile.saveSWF0[i] = I915_READ(SWF00 + (i << 2));
127 dev_priv->regfile.saveSWF1[i] = I915_READ(SWF10 + (i << 2));
Ben Gamari1341d652009-09-14 17:48:42 -0400128 }
129 for (i = 0; i < 3; i++)
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100130 dev_priv->regfile.saveSWF2[i] = I915_READ(SWF30 + (i << 2));
Ben Gamari1341d652009-09-14 17:48:42 -0400131
Keith Packardd70bed12011-06-29 00:30:34 -0700132 mutex_unlock(&dev->struct_mutex);
133
Ben Gamari1341d652009-09-14 17:48:42 -0400134 return 0;
135}
136
137int i915_restore_state(struct drm_device *dev)
138{
139 struct drm_i915_private *dev_priv = dev->dev_private;
140 int i;
141
Keith Packardd70bed12011-06-29 00:30:34 -0700142 mutex_lock(&dev->struct_mutex);
143
Chris Wilson19b2dbd2013-06-12 10:15:12 +0100144 i915_gem_restore_fences(dev);
Jesse Barnes9f49c372014-12-10 12:16:05 -0800145
146 if (IS_GEN4(dev))
147 pci_write_config_word(dev->pdev, GCDGMBUS,
148 dev_priv->regfile.saveGCDGMBUS);
Ben Gamari1341d652009-09-14 17:48:42 -0400149 i915_restore_display(dev);
150
Jesse Barnes317c35d2008-08-25 15:11:06 -0700151 /* Cache mode state */
Jesse Barnese8cde232013-10-11 12:09:29 -0700152 if (INTEL_INFO(dev)->gen < 7)
153 I915_WRITE(CACHE_MODE_0, dev_priv->regfile.saveCACHE_MODE_0 |
154 0xffff0000);
Jesse Barnes317c35d2008-08-25 15:11:06 -0700155
156 /* Memory arbitration state */
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100157 I915_WRITE(MI_ARB_STATE, dev_priv->regfile.saveMI_ARB_STATE | 0xffff0000);
Jesse Barnes317c35d2008-08-25 15:11:06 -0700158
159 for (i = 0; i < 16; i++) {
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100160 I915_WRITE(SWF00 + (i << 2), dev_priv->regfile.saveSWF0[i]);
161 I915_WRITE(SWF10 + (i << 2), dev_priv->regfile.saveSWF1[i]);
Jesse Barnes317c35d2008-08-25 15:11:06 -0700162 }
163 for (i = 0; i < 3; i++)
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100164 I915_WRITE(SWF30 + (i << 2), dev_priv->regfile.saveSWF2[i]);
Jesse Barnes317c35d2008-08-25 15:11:06 -0700165
Keith Packardd70bed12011-06-29 00:30:34 -0700166 mutex_unlock(&dev->struct_mutex);
167
Chris Wilsonf899fc62010-07-20 15:44:45 -0700168 intel_i2c_reset(dev);
Eric Anholtf0217c42009-12-01 11:56:30 -0800169
Jesse Barnes317c35d2008-08-25 15:11:06 -0700170 return 0;
171}