Jesse Barnes | 317c35d | 2008-08-25 15:11:06 -0700 | [diff] [blame] | 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 | |
Jani Nikula | 77895af | 2020-11-30 13:15:57 +0200 | [diff] [blame] | 27 | #include "display/intel_de.h" |
Jani Nikula | df0566a | 2019-06-13 11:44:16 +0300 | [diff] [blame] | 28 | #include "display/intel_fbc.h" |
Jani Nikula | 379bc10 | 2019-06-13 11:44:15 +0300 | [diff] [blame] | 29 | #include "display/intel_gmbus.h" |
Jani Nikula | 4fb8783 | 2019-10-01 18:25:06 +0300 | [diff] [blame] | 30 | #include "display/intel_vga.h" |
Jani Nikula | 379bc10 | 2019-06-13 11:44:15 +0300 | [diff] [blame] | 31 | |
Jani Nikula | 6da4a2c | 2019-08-06 13:07:30 +0300 | [diff] [blame] | 32 | #include "i915_drv.h" |
Eugeni Dodonov | 5e5b7fa | 2012-01-07 23:40:34 -0200 | [diff] [blame] | 33 | #include "i915_reg.h" |
Jani Nikula | bdd1510 | 2019-08-08 16:42:46 +0300 | [diff] [blame] | 34 | #include "i915_suspend.h" |
Jesse Barnes | 317c35d | 2008-08-25 15:11:06 -0700 | [diff] [blame] | 35 | |
Ville Syrjälä | 0f8d2a2 | 2020-10-05 20:14:41 +0300 | [diff] [blame] | 36 | static void intel_save_swf(struct drm_i915_private *dev_priv) |
| 37 | { |
| 38 | int i; |
| 39 | |
| 40 | /* Scratch space */ |
Lucas De Marchi | 651e7d4 | 2021-06-05 21:50:49 -0700 | [diff] [blame] | 41 | if (GRAPHICS_VER(dev_priv) == 2 && IS_MOBILE(dev_priv)) { |
Ville Syrjälä | 0f8d2a2 | 2020-10-05 20:14:41 +0300 | [diff] [blame] | 42 | for (i = 0; i < 7; i++) { |
Jani Nikula | 77895af | 2020-11-30 13:15:57 +0200 | [diff] [blame] | 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)); |
Ville Syrjälä | 0f8d2a2 | 2020-10-05 20:14:41 +0300 | [diff] [blame] | 45 | } |
| 46 | for (i = 0; i < 3; i++) |
Jani Nikula | 77895af | 2020-11-30 13:15:57 +0200 | [diff] [blame] | 47 | dev_priv->regfile.saveSWF3[i] = intel_de_read(dev_priv, SWF3(i)); |
Lucas De Marchi | 651e7d4 | 2021-06-05 21:50:49 -0700 | [diff] [blame] | 48 | } else if (GRAPHICS_VER(dev_priv) == 2) { |
Ville Syrjälä | 0f8d2a2 | 2020-10-05 20:14:41 +0300 | [diff] [blame] | 49 | for (i = 0; i < 7; i++) |
Jani Nikula | 77895af | 2020-11-30 13:15:57 +0200 | [diff] [blame] | 50 | dev_priv->regfile.saveSWF1[i] = intel_de_read(dev_priv, SWF1(i)); |
Ville Syrjälä | 0f8d2a2 | 2020-10-05 20:14:41 +0300 | [diff] [blame] | 51 | } else if (HAS_GMCH(dev_priv)) { |
| 52 | for (i = 0; i < 16; i++) { |
Jani Nikula | 77895af | 2020-11-30 13:15:57 +0200 | [diff] [blame] | 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)); |
Ville Syrjälä | 0f8d2a2 | 2020-10-05 20:14:41 +0300 | [diff] [blame] | 55 | } |
| 56 | for (i = 0; i < 3; i++) |
Jani Nikula | 77895af | 2020-11-30 13:15:57 +0200 | [diff] [blame] | 57 | dev_priv->regfile.saveSWF3[i] = intel_de_read(dev_priv, SWF3(i)); |
Ville Syrjälä | 0f8d2a2 | 2020-10-05 20:14:41 +0300 | [diff] [blame] | 58 | } |
| 59 | } |
| 60 | |
| 61 | static void intel_restore_swf(struct drm_i915_private *dev_priv) |
| 62 | { |
| 63 | int i; |
| 64 | |
| 65 | /* Scratch space */ |
Lucas De Marchi | 651e7d4 | 2021-06-05 21:50:49 -0700 | [diff] [blame] | 66 | if (GRAPHICS_VER(dev_priv) == 2 && IS_MOBILE(dev_priv)) { |
Ville Syrjälä | 0f8d2a2 | 2020-10-05 20:14:41 +0300 | [diff] [blame] | 67 | for (i = 0; i < 7; i++) { |
Jani Nikula | 77895af | 2020-11-30 13:15:57 +0200 | [diff] [blame] | 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]); |
Ville Syrjälä | 0f8d2a2 | 2020-10-05 20:14:41 +0300 | [diff] [blame] | 70 | } |
| 71 | for (i = 0; i < 3; i++) |
Jani Nikula | 77895af | 2020-11-30 13:15:57 +0200 | [diff] [blame] | 72 | intel_de_write(dev_priv, SWF3(i), dev_priv->regfile.saveSWF3[i]); |
Lucas De Marchi | 651e7d4 | 2021-06-05 21:50:49 -0700 | [diff] [blame] | 73 | } else if (GRAPHICS_VER(dev_priv) == 2) { |
Ville Syrjälä | 0f8d2a2 | 2020-10-05 20:14:41 +0300 | [diff] [blame] | 74 | for (i = 0; i < 7; i++) |
Jani Nikula | 77895af | 2020-11-30 13:15:57 +0200 | [diff] [blame] | 75 | intel_de_write(dev_priv, SWF1(i), dev_priv->regfile.saveSWF1[i]); |
Ville Syrjälä | 0f8d2a2 | 2020-10-05 20:14:41 +0300 | [diff] [blame] | 76 | } else if (HAS_GMCH(dev_priv)) { |
| 77 | for (i = 0; i < 16; i++) { |
Jani Nikula | 77895af | 2020-11-30 13:15:57 +0200 | [diff] [blame] | 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]); |
Ville Syrjälä | 0f8d2a2 | 2020-10-05 20:14:41 +0300 | [diff] [blame] | 80 | } |
| 81 | for (i = 0; i < 3; i++) |
Jani Nikula | 77895af | 2020-11-30 13:15:57 +0200 | [diff] [blame] | 82 | intel_de_write(dev_priv, SWF3(i), dev_priv->regfile.saveSWF3[i]); |
Ville Syrjälä | 0f8d2a2 | 2020-10-05 20:14:41 +0300 | [diff] [blame] | 83 | } |
| 84 | } |
| 85 | |
| 86 | void i915_save_display(struct drm_i915_private *dev_priv) |
Zhao Yakui | fccdaba | 2009-07-08 14:13:14 +0800 | [diff] [blame] | 87 | { |
Thomas Zimmermann | 8ff5446 | 2021-01-28 14:31:23 +0100 | [diff] [blame] | 88 | struct pci_dev *pdev = to_pci_dev(dev_priv->drm.dev); |
Jani Nikula | 59c0df3 | 2020-09-10 12:52:26 +0300 | [diff] [blame] | 89 | |
José Roberto de Souza | 5df7bd1 | 2021-04-08 13:31:50 -0700 | [diff] [blame] | 90 | if (!HAS_DISPLAY(dev_priv)) |
| 91 | return; |
| 92 | |
Zhao Yakui | fccdaba | 2009-07-08 14:13:14 +0800 | [diff] [blame] | 93 | /* Display arbitration control */ |
Lucas De Marchi | 651e7d4 | 2021-06-05 21:50:49 -0700 | [diff] [blame] | 94 | if (GRAPHICS_VER(dev_priv) <= 4) |
Jani Nikula | 77895af | 2020-11-30 13:15:57 +0200 | [diff] [blame] | 95 | dev_priv->regfile.saveDSPARB = intel_de_read(dev_priv, DSPARB); |
Zhao Yakui | fccdaba | 2009-07-08 14:13:14 +0800 | [diff] [blame] | 96 | |
Lucas De Marchi | 651e7d4 | 2021-06-05 21:50:49 -0700 | [diff] [blame] | 97 | if (GRAPHICS_VER(dev_priv) == 4) |
Jani Nikula | 59c0df3 | 2020-09-10 12:52:26 +0300 | [diff] [blame] | 98 | pci_read_config_word(pdev, GCDGMBUS, |
| 99 | &dev_priv->regfile.saveGCDGMBUS); |
Ville Syrjälä | 0f8d2a2 | 2020-10-05 20:14:41 +0300 | [diff] [blame] | 100 | |
| 101 | intel_save_swf(dev_priv); |
Jesse Barnes | 317c35d | 2008-08-25 15:11:06 -0700 | [diff] [blame] | 102 | } |
| 103 | |
Ville Syrjälä | 0f8d2a2 | 2020-10-05 20:14:41 +0300 | [diff] [blame] | 104 | void i915_restore_display(struct drm_i915_private *dev_priv) |
Jesse Barnes | 317c35d | 2008-08-25 15:11:06 -0700 | [diff] [blame] | 105 | { |
Thomas Zimmermann | 8ff5446 | 2021-01-28 14:31:23 +0100 | [diff] [blame] | 106 | struct pci_dev *pdev = to_pci_dev(dev_priv->drm.dev); |
Jani Nikula | 59c0df3 | 2020-09-10 12:52:26 +0300 | [diff] [blame] | 107 | |
José Roberto de Souza | 5df7bd1 | 2021-04-08 13:31:50 -0700 | [diff] [blame] | 108 | if (!HAS_DISPLAY(dev_priv)) |
| 109 | return; |
| 110 | |
Ville Syrjälä | 0f8d2a2 | 2020-10-05 20:14:41 +0300 | [diff] [blame] | 111 | intel_restore_swf(dev_priv); |
| 112 | |
Lucas De Marchi | 651e7d4 | 2021-06-05 21:50:49 -0700 | [diff] [blame] | 113 | if (GRAPHICS_VER(dev_priv) == 4) |
Jani Nikula | 59c0df3 | 2020-09-10 12:52:26 +0300 | [diff] [blame] | 114 | pci_write_config_word(pdev, GCDGMBUS, |
| 115 | dev_priv->regfile.saveGCDGMBUS); |
| 116 | |
Keith Packard | 881ee98 | 2008-11-02 23:08:44 -0800 | [diff] [blame] | 117 | /* Display arbitration */ |
Lucas De Marchi | 651e7d4 | 2021-06-05 21:50:49 -0700 | [diff] [blame] | 118 | if (GRAPHICS_VER(dev_priv) <= 4) |
Jani Nikula | 77895af | 2020-11-30 13:15:57 +0200 | [diff] [blame] | 119 | intel_de_write(dev_priv, DSPARB, dev_priv->regfile.saveDSPARB); |
Jesse Barnes | 317c35d | 2008-08-25 15:11:06 -0700 | [diff] [blame] | 120 | |
Zhao Yakui | a2c459e | 2010-03-19 17:05:10 +0800 | [diff] [blame] | 121 | /* only restore FBC info on the platform that supports FBC*/ |
Paulo Zanoni | c937ab3e5 | 2016-01-19 11:35:46 -0200 | [diff] [blame] | 122 | intel_fbc_global_disable(dev_priv); |
Ville Syrjälä | 768cf7f | 2014-01-23 16:49:15 +0200 | [diff] [blame] | 123 | |
Jani Nikula | 4fb8783 | 2019-10-01 18:25:06 +0300 | [diff] [blame] | 124 | intel_vga_redisable(dev_priv); |
Jani Nikula | 4a1a4a4 | 2020-09-10 12:52:27 +0300 | [diff] [blame] | 125 | |
| 126 | intel_gmbus_reset(dev_priv); |
Ben Gamari | 1341d65 | 2009-09-14 17:48:42 -0400 | [diff] [blame] | 127 | } |