blob: f7b55f34dba8225a25fb8db36f51c7f87c1c2807 [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
Jani Nikula77895af2020-11-30 13:15:57 +020027#include "display/intel_de.h"
Jani Nikuladf0566a2019-06-13 11:44:16 +030028#include "display/intel_fbc.h"
Jani Nikula379bc102019-06-13 11:44:15 +030029#include "display/intel_gmbus.h"
Jani Nikula4fb87832019-10-01 18:25:06 +030030#include "display/intel_vga.h"
Jani Nikula379bc102019-06-13 11:44:15 +030031
Jani Nikula6da4a2c2019-08-06 13:07:30 +030032#include "i915_drv.h"
Eugeni Dodonov5e5b7fa2012-01-07 23:40:34 -020033#include "i915_reg.h"
Jani Nikulabdd15102019-08-08 16:42:46 +030034#include "i915_suspend.h"
Jesse Barnes317c35d2008-08-25 15:11:06 -070035
Ville Syrjälä0f8d2a22020-10-05 20:14:41 +030036static void intel_save_swf(struct drm_i915_private *dev_priv)
37{
38 int i;
39
40 /* Scratch space */
Lucas De Marchi651e7d42021-06-05 21:50:49 -070041 if (GRAPHICS_VER(dev_priv) == 2 && IS_MOBILE(dev_priv)) {
Ville Syrjälä0f8d2a22020-10-05 20:14:41 +030042 for (i = 0; i < 7; i++) {
Jani Nikula77895af2020-11-30 13:15:57 +020043 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));
Ville Syrjälä0f8d2a22020-10-05 20:14:41 +030045 }
46 for (i = 0; i < 3; i++)
Jani Nikula77895af2020-11-30 13:15:57 +020047 dev_priv->regfile.saveSWF3[i] = intel_de_read(dev_priv, SWF3(i));
Lucas De Marchi651e7d42021-06-05 21:50:49 -070048 } else if (GRAPHICS_VER(dev_priv) == 2) {
Ville Syrjälä0f8d2a22020-10-05 20:14:41 +030049 for (i = 0; i < 7; i++)
Jani Nikula77895af2020-11-30 13:15:57 +020050 dev_priv->regfile.saveSWF1[i] = intel_de_read(dev_priv, SWF1(i));
Ville Syrjälä0f8d2a22020-10-05 20:14:41 +030051 } else if (HAS_GMCH(dev_priv)) {
52 for (i = 0; i < 16; i++) {
Jani Nikula77895af2020-11-30 13:15:57 +020053 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));
Ville Syrjälä0f8d2a22020-10-05 20:14:41 +030055 }
56 for (i = 0; i < 3; i++)
Jani Nikula77895af2020-11-30 13:15:57 +020057 dev_priv->regfile.saveSWF3[i] = intel_de_read(dev_priv, SWF3(i));
Ville Syrjälä0f8d2a22020-10-05 20:14:41 +030058 }
59}
60
61static void intel_restore_swf(struct drm_i915_private *dev_priv)
62{
63 int i;
64
65 /* Scratch space */
Lucas De Marchi651e7d42021-06-05 21:50:49 -070066 if (GRAPHICS_VER(dev_priv) == 2 && IS_MOBILE(dev_priv)) {
Ville Syrjälä0f8d2a22020-10-05 20:14:41 +030067 for (i = 0; i < 7; i++) {
Jani Nikula77895af2020-11-30 13:15:57 +020068 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]);
Ville Syrjälä0f8d2a22020-10-05 20:14:41 +030070 }
71 for (i = 0; i < 3; i++)
Jani Nikula77895af2020-11-30 13:15:57 +020072 intel_de_write(dev_priv, SWF3(i), dev_priv->regfile.saveSWF3[i]);
Lucas De Marchi651e7d42021-06-05 21:50:49 -070073 } else if (GRAPHICS_VER(dev_priv) == 2) {
Ville Syrjälä0f8d2a22020-10-05 20:14:41 +030074 for (i = 0; i < 7; i++)
Jani Nikula77895af2020-11-30 13:15:57 +020075 intel_de_write(dev_priv, SWF1(i), dev_priv->regfile.saveSWF1[i]);
Ville Syrjälä0f8d2a22020-10-05 20:14:41 +030076 } else if (HAS_GMCH(dev_priv)) {
77 for (i = 0; i < 16; i++) {
Jani Nikula77895af2020-11-30 13:15:57 +020078 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]);
Ville Syrjälä0f8d2a22020-10-05 20:14:41 +030080 }
81 for (i = 0; i < 3; i++)
Jani Nikula77895af2020-11-30 13:15:57 +020082 intel_de_write(dev_priv, SWF3(i), dev_priv->regfile.saveSWF3[i]);
Ville Syrjälä0f8d2a22020-10-05 20:14:41 +030083 }
84}
85
86void i915_save_display(struct drm_i915_private *dev_priv)
Zhao Yakuifccdaba2009-07-08 14:13:14 +080087{
Thomas Zimmermann8ff54462021-01-28 14:31:23 +010088 struct pci_dev *pdev = to_pci_dev(dev_priv->drm.dev);
Jani Nikula59c0df32020-09-10 12:52:26 +030089
José Roberto de Souza5df7bd12021-04-08 13:31:50 -070090 if (!HAS_DISPLAY(dev_priv))
91 return;
92
Zhao Yakuifccdaba2009-07-08 14:13:14 +080093 /* Display arbitration control */
Lucas De Marchi651e7d42021-06-05 21:50:49 -070094 if (GRAPHICS_VER(dev_priv) <= 4)
Jani Nikula77895af2020-11-30 13:15:57 +020095 dev_priv->regfile.saveDSPARB = intel_de_read(dev_priv, DSPARB);
Zhao Yakuifccdaba2009-07-08 14:13:14 +080096
Lucas De Marchi651e7d42021-06-05 21:50:49 -070097 if (GRAPHICS_VER(dev_priv) == 4)
Jani Nikula59c0df32020-09-10 12:52:26 +030098 pci_read_config_word(pdev, GCDGMBUS,
99 &dev_priv->regfile.saveGCDGMBUS);
Ville Syrjälä0f8d2a22020-10-05 20:14:41 +0300100
101 intel_save_swf(dev_priv);
Jesse Barnes317c35d2008-08-25 15:11:06 -0700102}
103
Ville Syrjälä0f8d2a22020-10-05 20:14:41 +0300104void i915_restore_display(struct drm_i915_private *dev_priv)
Jesse Barnes317c35d2008-08-25 15:11:06 -0700105{
Thomas Zimmermann8ff54462021-01-28 14:31:23 +0100106 struct pci_dev *pdev = to_pci_dev(dev_priv->drm.dev);
Jani Nikula59c0df32020-09-10 12:52:26 +0300107
José Roberto de Souza5df7bd12021-04-08 13:31:50 -0700108 if (!HAS_DISPLAY(dev_priv))
109 return;
110
Ville Syrjälä0f8d2a22020-10-05 20:14:41 +0300111 intel_restore_swf(dev_priv);
112
Lucas De Marchi651e7d42021-06-05 21:50:49 -0700113 if (GRAPHICS_VER(dev_priv) == 4)
Jani Nikula59c0df32020-09-10 12:52:26 +0300114 pci_write_config_word(pdev, GCDGMBUS,
115 dev_priv->regfile.saveGCDGMBUS);
116
Keith Packard881ee982008-11-02 23:08:44 -0800117 /* Display arbitration */
Lucas De Marchi651e7d42021-06-05 21:50:49 -0700118 if (GRAPHICS_VER(dev_priv) <= 4)
Jani Nikula77895af2020-11-30 13:15:57 +0200119 intel_de_write(dev_priv, DSPARB, dev_priv->regfile.saveDSPARB);
Jesse Barnes317c35d2008-08-25 15:11:06 -0700120
Zhao Yakuia2c459e2010-03-19 17:05:10 +0800121 /* only restore FBC info on the platform that supports FBC*/
Paulo Zanonic937ab3e52016-01-19 11:35:46 -0200122 intel_fbc_global_disable(dev_priv);
Ville Syrjälä768cf7f2014-01-23 16:49:15 +0200123
Jani Nikula4fb87832019-10-01 18:25:06 +0300124 intel_vga_redisable(dev_priv);
Jani Nikula4a1a4a42020-09-10 12:52:27 +0300125
126 intel_gmbus_reset(dev_priv);
Ben Gamari1341d652009-09-14 17:48:42 -0400127}