xref: /openbmc/linux/drivers/gpu/drm/i915/i915_suspend.c (revision 7e470f103d7579836a536c15862b70118379f7f4)
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"
35*7e470f10SJani Nikula #include "intel_pci_config.h"
36317c35d1SJesse Barnes 
370f8d2a2bSVille Syrjälä static void intel_save_swf(struct drm_i915_private *dev_priv)
380f8d2a2bSVille Syrjälä {
390f8d2a2bSVille Syrjälä 	int i;
400f8d2a2bSVille Syrjälä 
410f8d2a2bSVille Syrjälä 	/* Scratch space */
42651e7d48SLucas De Marchi 	if (GRAPHICS_VER(dev_priv) == 2 && IS_MOBILE(dev_priv)) {
430f8d2a2bSVille Syrjälä 		for (i = 0; i < 7; i++) {
4477895af2SJani Nikula 			dev_priv->regfile.saveSWF0[i] = intel_de_read(dev_priv, SWF0(i));
4577895af2SJani Nikula 			dev_priv->regfile.saveSWF1[i] = intel_de_read(dev_priv, SWF1(i));
460f8d2a2bSVille Syrjälä 		}
470f8d2a2bSVille Syrjälä 		for (i = 0; i < 3; i++)
4877895af2SJani Nikula 			dev_priv->regfile.saveSWF3[i] = intel_de_read(dev_priv, SWF3(i));
49651e7d48SLucas De Marchi 	} else if (GRAPHICS_VER(dev_priv) == 2) {
500f8d2a2bSVille Syrjälä 		for (i = 0; i < 7; i++)
5177895af2SJani Nikula 			dev_priv->regfile.saveSWF1[i] = intel_de_read(dev_priv, SWF1(i));
520f8d2a2bSVille Syrjälä 	} else if (HAS_GMCH(dev_priv)) {
530f8d2a2bSVille Syrjälä 		for (i = 0; i < 16; i++) {
5477895af2SJani Nikula 			dev_priv->regfile.saveSWF0[i] = intel_de_read(dev_priv, SWF0(i));
5577895af2SJani Nikula 			dev_priv->regfile.saveSWF1[i] = intel_de_read(dev_priv, SWF1(i));
560f8d2a2bSVille Syrjälä 		}
570f8d2a2bSVille Syrjälä 		for (i = 0; i < 3; i++)
5877895af2SJani Nikula 			dev_priv->regfile.saveSWF3[i] = intel_de_read(dev_priv, SWF3(i));
590f8d2a2bSVille Syrjälä 	}
600f8d2a2bSVille Syrjälä }
610f8d2a2bSVille Syrjälä 
620f8d2a2bSVille Syrjälä static void intel_restore_swf(struct drm_i915_private *dev_priv)
630f8d2a2bSVille Syrjälä {
640f8d2a2bSVille Syrjälä 	int i;
650f8d2a2bSVille Syrjälä 
660f8d2a2bSVille Syrjälä 	/* Scratch space */
67651e7d48SLucas De Marchi 	if (GRAPHICS_VER(dev_priv) == 2 && IS_MOBILE(dev_priv)) {
680f8d2a2bSVille Syrjälä 		for (i = 0; i < 7; i++) {
6977895af2SJani Nikula 			intel_de_write(dev_priv, SWF0(i), dev_priv->regfile.saveSWF0[i]);
7077895af2SJani Nikula 			intel_de_write(dev_priv, SWF1(i), dev_priv->regfile.saveSWF1[i]);
710f8d2a2bSVille Syrjälä 		}
720f8d2a2bSVille Syrjälä 		for (i = 0; i < 3; i++)
7377895af2SJani Nikula 			intel_de_write(dev_priv, SWF3(i), dev_priv->regfile.saveSWF3[i]);
74651e7d48SLucas De Marchi 	} else if (GRAPHICS_VER(dev_priv) == 2) {
750f8d2a2bSVille Syrjälä 		for (i = 0; i < 7; i++)
7677895af2SJani Nikula 			intel_de_write(dev_priv, SWF1(i), dev_priv->regfile.saveSWF1[i]);
770f8d2a2bSVille Syrjälä 	} else if (HAS_GMCH(dev_priv)) {
780f8d2a2bSVille Syrjälä 		for (i = 0; i < 16; i++) {
7977895af2SJani Nikula 			intel_de_write(dev_priv, SWF0(i), dev_priv->regfile.saveSWF0[i]);
8077895af2SJani Nikula 			intel_de_write(dev_priv, SWF1(i), dev_priv->regfile.saveSWF1[i]);
810f8d2a2bSVille Syrjälä 		}
820f8d2a2bSVille Syrjälä 		for (i = 0; i < 3; i++)
8377895af2SJani Nikula 			intel_de_write(dev_priv, SWF3(i), dev_priv->regfile.saveSWF3[i]);
840f8d2a2bSVille Syrjälä 	}
850f8d2a2bSVille Syrjälä }
860f8d2a2bSVille Syrjälä 
870f8d2a2bSVille Syrjälä void i915_save_display(struct drm_i915_private *dev_priv)
88fccdaba4SZhao Yakui {
898ff5446aSThomas Zimmermann 	struct pci_dev *pdev = to_pci_dev(dev_priv->drm.dev);
9059c0df3cSJani Nikula 
915df7bd13SJosé Roberto de Souza 	if (!HAS_DISPLAY(dev_priv))
925df7bd13SJosé Roberto de Souza 		return;
935df7bd13SJosé Roberto de Souza 
94fccdaba4SZhao Yakui 	/* Display arbitration control */
95651e7d48SLucas De Marchi 	if (GRAPHICS_VER(dev_priv) <= 4)
9677895af2SJani Nikula 		dev_priv->regfile.saveDSPARB = intel_de_read(dev_priv, DSPARB);
97fccdaba4SZhao Yakui 
98651e7d48SLucas De Marchi 	if (GRAPHICS_VER(dev_priv) == 4)
9959c0df3cSJani Nikula 		pci_read_config_word(pdev, GCDGMBUS,
10059c0df3cSJani Nikula 				     &dev_priv->regfile.saveGCDGMBUS);
1010f8d2a2bSVille Syrjälä 
1020f8d2a2bSVille Syrjälä 	intel_save_swf(dev_priv);
103317c35d1SJesse Barnes }
104317c35d1SJesse Barnes 
1050f8d2a2bSVille Syrjälä void i915_restore_display(struct drm_i915_private *dev_priv)
106317c35d1SJesse Barnes {
1078ff5446aSThomas Zimmermann 	struct pci_dev *pdev = to_pci_dev(dev_priv->drm.dev);
10859c0df3cSJani Nikula 
1095df7bd13SJosé Roberto de Souza 	if (!HAS_DISPLAY(dev_priv))
1105df7bd13SJosé Roberto de Souza 		return;
1115df7bd13SJosé Roberto de Souza 
1120f8d2a2bSVille Syrjälä 	intel_restore_swf(dev_priv);
1130f8d2a2bSVille Syrjälä 
114651e7d48SLucas De Marchi 	if (GRAPHICS_VER(dev_priv) == 4)
11559c0df3cSJani Nikula 		pci_write_config_word(pdev, GCDGMBUS,
11659c0df3cSJani Nikula 				      dev_priv->regfile.saveGCDGMBUS);
11759c0df3cSJani Nikula 
118881ee988SKeith Packard 	/* Display arbitration */
119651e7d48SLucas De Marchi 	if (GRAPHICS_VER(dev_priv) <= 4)
12077895af2SJani Nikula 		intel_de_write(dev_priv, DSPARB, dev_priv->regfile.saveDSPARB);
121317c35d1SJesse Barnes 
122a2c459eeSZhao Yakui 	/* only restore FBC info on the platform that supports FBC*/
123c937ab3eSPaulo Zanoni 	intel_fbc_global_disable(dev_priv);
124768cf7f4SVille Syrjälä 
1254fb87831SJani Nikula 	intel_vga_redisable(dev_priv);
1264a1a4a44SJani Nikula 
1274a1a4a44SJani Nikula 	intel_gmbus_reset(dev_priv);
1281341d655SBen Gamari }
129