i915_suspend.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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. #include <drm/drmP.h>
  27. #include <drm/i915_drm.h>
  28. #include "intel_drv.h"
  29. #include "i915_reg.h"
  30. static void i915_save_display(struct drm_device *dev)
  31. {
  32. struct drm_i915_private *dev_priv = dev->dev_private;
  33. /* Display arbitration control */
  34. if (INTEL_INFO(dev)->gen <= 4)
  35. dev_priv->regfile.saveDSPARB = I915_READ(DSPARB);
  36. /* LVDS state */
  37. if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev))
  38. dev_priv->regfile.saveLVDS = I915_READ(PCH_LVDS);
  39. else if (INTEL_INFO(dev)->gen <= 4 && IS_MOBILE(dev) && !IS_I830(dev))
  40. dev_priv->regfile.saveLVDS = I915_READ(LVDS);
  41. /* Panel power sequencer */
  42. if (HAS_PCH_SPLIT(dev)) {
  43. dev_priv->regfile.savePP_CONTROL = I915_READ(PCH_PP_CONTROL);
  44. dev_priv->regfile.savePP_ON_DELAYS = I915_READ(PCH_PP_ON_DELAYS);
  45. dev_priv->regfile.savePP_OFF_DELAYS = I915_READ(PCH_PP_OFF_DELAYS);
  46. dev_priv->regfile.savePP_DIVISOR = I915_READ(PCH_PP_DIVISOR);
  47. } else if (!IS_VALLEYVIEW(dev)) {
  48. dev_priv->regfile.savePP_CONTROL = I915_READ(PP_CONTROL);
  49. dev_priv->regfile.savePP_ON_DELAYS = I915_READ(PP_ON_DELAYS);
  50. dev_priv->regfile.savePP_OFF_DELAYS = I915_READ(PP_OFF_DELAYS);
  51. dev_priv->regfile.savePP_DIVISOR = I915_READ(PP_DIVISOR);
  52. }
  53. /* save FBC interval */
  54. if (HAS_FBC(dev) && INTEL_INFO(dev)->gen <= 4 && !IS_G4X(dev))
  55. dev_priv->regfile.saveFBC_CONTROL = I915_READ(FBC_CONTROL);
  56. }
  57. static void i915_restore_display(struct drm_device *dev)
  58. {
  59. struct drm_i915_private *dev_priv = dev->dev_private;
  60. u32 mask = 0xffffffff;
  61. /* Display arbitration */
  62. if (INTEL_INFO(dev)->gen <= 4)
  63. I915_WRITE(DSPARB, dev_priv->regfile.saveDSPARB);
  64. mask = ~LVDS_PORT_EN;
  65. /* LVDS state */
  66. if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev))
  67. I915_WRITE(PCH_LVDS, dev_priv->regfile.saveLVDS & mask);
  68. else if (INTEL_INFO(dev)->gen <= 4 && IS_MOBILE(dev) && !IS_I830(dev))
  69. I915_WRITE(LVDS, dev_priv->regfile.saveLVDS & mask);
  70. /* Panel power sequencer */
  71. if (HAS_PCH_SPLIT(dev)) {
  72. I915_WRITE(PCH_PP_ON_DELAYS, dev_priv->regfile.savePP_ON_DELAYS);
  73. I915_WRITE(PCH_PP_OFF_DELAYS, dev_priv->regfile.savePP_OFF_DELAYS);
  74. I915_WRITE(PCH_PP_DIVISOR, dev_priv->regfile.savePP_DIVISOR);
  75. I915_WRITE(PCH_PP_CONTROL, dev_priv->regfile.savePP_CONTROL);
  76. } else if (!IS_VALLEYVIEW(dev)) {
  77. I915_WRITE(PP_ON_DELAYS, dev_priv->regfile.savePP_ON_DELAYS);
  78. I915_WRITE(PP_OFF_DELAYS, dev_priv->regfile.savePP_OFF_DELAYS);
  79. I915_WRITE(PP_DIVISOR, dev_priv->regfile.savePP_DIVISOR);
  80. I915_WRITE(PP_CONTROL, dev_priv->regfile.savePP_CONTROL);
  81. }
  82. /* only restore FBC info on the platform that supports FBC*/
  83. intel_fbc_disable(dev_priv);
  84. /* restore FBC interval */
  85. if (HAS_FBC(dev) && INTEL_INFO(dev)->gen <= 4 && !IS_G4X(dev))
  86. I915_WRITE(FBC_CONTROL, dev_priv->regfile.saveFBC_CONTROL);
  87. i915_redisable_vga(dev);
  88. }
  89. int i915_save_state(struct drm_device *dev)
  90. {
  91. struct drm_i915_private *dev_priv = dev->dev_private;
  92. int i;
  93. mutex_lock(&dev->struct_mutex);
  94. i915_save_display(dev);
  95. if (IS_GEN4(dev))
  96. pci_read_config_word(dev->pdev, GCDGMBUS,
  97. &dev_priv->regfile.saveGCDGMBUS);
  98. /* Cache mode state */
  99. if (INTEL_INFO(dev)->gen < 7)
  100. dev_priv->regfile.saveCACHE_MODE_0 = I915_READ(CACHE_MODE_0);
  101. /* Memory Arbitration state */
  102. dev_priv->regfile.saveMI_ARB_STATE = I915_READ(MI_ARB_STATE);
  103. /* Scratch space */
  104. if (IS_GEN2(dev_priv) && IS_MOBILE(dev_priv)) {
  105. for (i = 0; i < 7; i++) {
  106. dev_priv->regfile.saveSWF0[i] = I915_READ(SWF0(i));
  107. dev_priv->regfile.saveSWF1[i] = I915_READ(SWF1(i));
  108. }
  109. for (i = 0; i < 3; i++)
  110. dev_priv->regfile.saveSWF3[i] = I915_READ(SWF3(i));
  111. } else if (IS_GEN2(dev_priv)) {
  112. for (i = 0; i < 7; i++)
  113. dev_priv->regfile.saveSWF1[i] = I915_READ(SWF1(i));
  114. } else if (HAS_GMCH_DISPLAY(dev_priv)) {
  115. for (i = 0; i < 16; i++) {
  116. dev_priv->regfile.saveSWF0[i] = I915_READ(SWF0(i));
  117. dev_priv->regfile.saveSWF1[i] = I915_READ(SWF1(i));
  118. }
  119. for (i = 0; i < 3; i++)
  120. dev_priv->regfile.saveSWF3[i] = I915_READ(SWF3(i));
  121. }
  122. mutex_unlock(&dev->struct_mutex);
  123. return 0;
  124. }
  125. int i915_restore_state(struct drm_device *dev)
  126. {
  127. struct drm_i915_private *dev_priv = dev->dev_private;
  128. int i;
  129. mutex_lock(&dev->struct_mutex);
  130. i915_gem_restore_fences(dev);
  131. if (IS_GEN4(dev))
  132. pci_write_config_word(dev->pdev, GCDGMBUS,
  133. dev_priv->regfile.saveGCDGMBUS);
  134. i915_restore_display(dev);
  135. /* Cache mode state */
  136. if (INTEL_INFO(dev)->gen < 7)
  137. I915_WRITE(CACHE_MODE_0, dev_priv->regfile.saveCACHE_MODE_0 |
  138. 0xffff0000);
  139. /* Memory arbitration state */
  140. I915_WRITE(MI_ARB_STATE, dev_priv->regfile.saveMI_ARB_STATE | 0xffff0000);
  141. /* Scratch space */
  142. if (IS_GEN2(dev_priv) && IS_MOBILE(dev_priv)) {
  143. for (i = 0; i < 7; i++) {
  144. I915_WRITE(SWF0(i), dev_priv->regfile.saveSWF0[i]);
  145. I915_WRITE(SWF1(i), dev_priv->regfile.saveSWF1[i]);
  146. }
  147. for (i = 0; i < 3; i++)
  148. I915_WRITE(SWF3(i), dev_priv->regfile.saveSWF3[i]);
  149. } else if (IS_GEN2(dev_priv)) {
  150. for (i = 0; i < 7; i++)
  151. I915_WRITE(SWF1(i), dev_priv->regfile.saveSWF1[i]);
  152. } else if (HAS_GMCH_DISPLAY(dev_priv)) {
  153. for (i = 0; i < 16; i++) {
  154. I915_WRITE(SWF0(i), dev_priv->regfile.saveSWF0[i]);
  155. I915_WRITE(SWF1(i), dev_priv->regfile.saveSWF1[i]);
  156. }
  157. for (i = 0; i < 3; i++)
  158. I915_WRITE(SWF3(i), dev_priv->regfile.saveSWF3[i]);
  159. }
  160. mutex_unlock(&dev->struct_mutex);
  161. intel_i2c_reset(dev);
  162. return 0;
  163. }