xref: /openbmc/linux/drivers/gpu/drm/i915/i915_suspend.c (revision 5df7bd130818dfdc9047c2a81b19737d66e55f9a)
1317c35d1SJesse Barnes /*
2317c35d1SJesse Barnes  *
3317c35d1SJesse Barnes  * Copyright 2008 (c) Intel Corporation
4317c35d1SJesse Barnes  *   Jesse Barnes <jbarnes@virtuousgeek.org>
5317c35d1SJesse Barnes  *
6317c35d1SJesse Barnes  * Permission is hereby granted, free of charge, to any person obtaining a
7317c35d1SJesse Barnes  * copy of this software and associated documentation files (the
8317c35d1SJesse Barnes  * "Software"), to deal in the Software without restriction, including
9317c35d1SJesse Barnes  * without limitation the rights to use, copy, modify, merge, publish,
10317c35d1SJesse Barnes  * distribute, sub license, and/or sell copies of the Software, and to
11317c35d1SJesse Barnes  * permit persons to whom the Software is furnished to do so, subject to
12317c35d1SJesse Barnes  * the following conditions:
13317c35d1SJesse Barnes  *
14317c35d1SJesse Barnes  * The above copyright notice and this permission notice (including the
15317c35d1SJesse Barnes  * next paragraph) shall be included in all copies or substantial portions
16317c35d1SJesse Barnes  * of the Software.
17317c35d1SJesse Barnes  *
18317c35d1SJesse Barnes  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19317c35d1SJesse Barnes  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20317c35d1SJesse Barnes  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21317c35d1SJesse Barnes  * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22317c35d1SJesse Barnes  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23317c35d1SJesse Barnes  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24317c35d1SJesse Barnes  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25317c35d1SJesse Barnes  */
26317c35d1SJesse Barnes 
2777895af2SJani Nikula #include "display/intel_de.h"
28df0566a6SJani Nikula #include "display/intel_fbc.h"
29379bc100SJani Nikula #include "display/intel_gmbus.h"
304fb87831SJani Nikula #include "display/intel_vga.h"
31379bc100SJani Nikula 
326da4a2c4SJani Nikula #include "i915_drv.h"
335e5b7fa2SEugeni Dodonov #include "i915_reg.h"
34bdd1510cSJani Nikula #include "i915_suspend.h"
35317c35d1SJesse Barnes 
360f8d2a2bSVille Syrjälä static void intel_save_swf(struct drm_i915_private *dev_priv)
370f8d2a2bSVille Syrjälä {
380f8d2a2bSVille Syrjälä 	int i;
390f8d2a2bSVille Syrjälä 
400f8d2a2bSVille Syrjälä 	/* Scratch space */
410f8d2a2bSVille Syrjälä 	if (IS_GEN(dev_priv, 2) && IS_MOBILE(dev_priv)) {
420f8d2a2bSVille Syrjälä 		for (i = 0; i < 7; i++) {
4377895af2SJani Nikula 			dev_priv->regfile.saveSWF0[i] = intel_de_read(dev_priv, SWF0(i));
4477895af2SJani Nikula 			dev_priv->regfile.saveSWF1[i] = intel_de_read(dev_priv, SWF1(i));
450f8d2a2bSVille Syrjälä 		}
460f8d2a2bSVille Syrjälä 		for (i = 0; i < 3; i++)
4777895af2SJani Nikula 			dev_priv->regfile.saveSWF3[i] = intel_de_read(dev_priv, SWF3(i));
480f8d2a2bSVille Syrjälä 	} else if (IS_GEN(dev_priv, 2)) {
490f8d2a2bSVille Syrjälä 		for (i = 0; i < 7; i++)
5077895af2SJani Nikula 			dev_priv->regfile.saveSWF1[i] = intel_de_read(dev_priv, SWF1(i));
510f8d2a2bSVille Syrjälä 	} else if (HAS_GMCH(dev_priv)) {
520f8d2a2bSVille Syrjälä 		for (i = 0; i < 16; i++) {
5377895af2SJani Nikula 			dev_priv->regfile.saveSWF0[i] = intel_de_read(dev_priv, SWF0(i));
5477895af2SJani Nikula 			dev_priv->regfile.saveSWF1[i] = intel_de_read(dev_priv, SWF1(i));
550f8d2a2bSVille Syrjälä 		}
560f8d2a2bSVille Syrjälä 		for (i = 0; i < 3; i++)
5777895af2SJani Nikula 			dev_priv->regfile.saveSWF3[i] = intel_de_read(dev_priv, SWF3(i));
580f8d2a2bSVille Syrjälä 	}
590f8d2a2bSVille Syrjälä }
600f8d2a2bSVille Syrjälä 
610f8d2a2bSVille Syrjälä static void intel_restore_swf(struct drm_i915_private *dev_priv)
620f8d2a2bSVille Syrjälä {
630f8d2a2bSVille Syrjälä 	int i;
640f8d2a2bSVille Syrjälä 
650f8d2a2bSVille Syrjälä 	/* Scratch space */
660f8d2a2bSVille Syrjälä 	if (IS_GEN(dev_priv, 2) && IS_MOBILE(dev_priv)) {
670f8d2a2bSVille Syrjälä 		for (i = 0; i < 7; i++) {
6877895af2SJani Nikula 			intel_de_write(dev_priv, SWF0(i), dev_priv->regfile.saveSWF0[i]);
6977895af2SJani Nikula 			intel_de_write(dev_priv, SWF1(i), dev_priv->regfile.saveSWF1[i]);
700f8d2a2bSVille Syrjälä 		}
710f8d2a2bSVille Syrjälä 		for (i = 0; i < 3; i++)
7277895af2SJani Nikula 			intel_de_write(dev_priv, SWF3(i), dev_priv->regfile.saveSWF3[i]);
730f8d2a2bSVille Syrjälä 	} else if (IS_GEN(dev_priv, 2)) {
740f8d2a2bSVille Syrjälä 		for (i = 0; i < 7; i++)
7577895af2SJani Nikula 			intel_de_write(dev_priv, SWF1(i), dev_priv->regfile.saveSWF1[i]);
760f8d2a2bSVille Syrjälä 	} else if (HAS_GMCH(dev_priv)) {
770f8d2a2bSVille Syrjälä 		for (i = 0; i < 16; i++) {
7877895af2SJani Nikula 			intel_de_write(dev_priv, SWF0(i), dev_priv->regfile.saveSWF0[i]);
7977895af2SJani Nikula 			intel_de_write(dev_priv, SWF1(i), dev_priv->regfile.saveSWF1[i]);
800f8d2a2bSVille Syrjälä 		}
810f8d2a2bSVille Syrjälä 		for (i = 0; i < 3; i++)
8277895af2SJani Nikula 			intel_de_write(dev_priv, SWF3(i), dev_priv->regfile.saveSWF3[i]);
830f8d2a2bSVille Syrjälä 	}
840f8d2a2bSVille Syrjälä }
850f8d2a2bSVille Syrjälä 
860f8d2a2bSVille Syrjälä void i915_save_display(struct drm_i915_private *dev_priv)
87fccdaba4SZhao Yakui {
888ff5446aSThomas Zimmermann 	struct pci_dev *pdev = to_pci_dev(dev_priv->drm.dev);
8959c0df3cSJani Nikula 
90*5df7bd13SJosé Roberto de Souza 	if (!HAS_DISPLAY(dev_priv))
91*5df7bd13SJosé Roberto de Souza 		return;
92*5df7bd13SJosé Roberto de Souza 
93fccdaba4SZhao Yakui 	/* Display arbitration control */
9429b74b7fSTvrtko Ursulin 	if (INTEL_GEN(dev_priv) <= 4)
9577895af2SJani Nikula 		dev_priv->regfile.saveDSPARB = intel_de_read(dev_priv, DSPARB);
96fccdaba4SZhao Yakui 
9759c0df3cSJani Nikula 	if (IS_GEN(dev_priv, 4))
9859c0df3cSJani Nikula 		pci_read_config_word(pdev, GCDGMBUS,
9959c0df3cSJani Nikula 				     &dev_priv->regfile.saveGCDGMBUS);
1000f8d2a2bSVille Syrjälä 
1010f8d2a2bSVille Syrjälä 	intel_save_swf(dev_priv);
102317c35d1SJesse Barnes }
103317c35d1SJesse Barnes 
1040f8d2a2bSVille Syrjälä void i915_restore_display(struct drm_i915_private *dev_priv)
105317c35d1SJesse Barnes {
1068ff5446aSThomas Zimmermann 	struct pci_dev *pdev = to_pci_dev(dev_priv->drm.dev);
10759c0df3cSJani Nikula 
108*5df7bd13SJosé Roberto de Souza 	if (!HAS_DISPLAY(dev_priv))
109*5df7bd13SJosé Roberto de Souza 		return;
110*5df7bd13SJosé Roberto de Souza 
1110f8d2a2bSVille Syrjälä 	intel_restore_swf(dev_priv);
1120f8d2a2bSVille Syrjälä 
11359c0df3cSJani Nikula 	if (IS_GEN(dev_priv, 4))
11459c0df3cSJani Nikula 		pci_write_config_word(pdev, GCDGMBUS,
11559c0df3cSJani Nikula 				      dev_priv->regfile.saveGCDGMBUS);
11659c0df3cSJani Nikula 
117881ee988SKeith Packard 	/* Display arbitration */
11829b74b7fSTvrtko Ursulin 	if (INTEL_GEN(dev_priv) <= 4)
11977895af2SJani Nikula 		intel_de_write(dev_priv, DSPARB, dev_priv->regfile.saveDSPARB);
120317c35d1SJesse Barnes 
121a2c459eeSZhao Yakui 	/* only restore FBC info on the platform that supports FBC*/
122c937ab3eSPaulo Zanoni 	intel_fbc_global_disable(dev_priv);
123768cf7f4SVille Syrjälä 
1244fb87831SJani Nikula 	intel_vga_redisable(dev_priv);
1254a1a4a44SJani Nikula 
1264a1a4a44SJani Nikula 	intel_gmbus_reset(dev_priv);
1271341d655SBen Gamari }
128