power.c 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. /**************************************************************************
  2. * Copyright (c) 2009-2011, Intel Corporation.
  3. * All Rights Reserved.
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining a
  6. * copy of this software and associated documentation files (the "Software"),
  7. * to deal in the Software without restriction, including without limitation
  8. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  9. * and/or sell copies of the Software, and to permit persons to whom the
  10. * Software is furnished to do so, subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice (including the next
  13. * paragraph) shall be included in all copies or substantial portions of the
  14. * Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  19. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  21. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  22. * SOFTWARE.
  23. *
  24. * Authors:
  25. * Benjamin Defnet <[email protected]>
  26. * Rajesh Poornachandran <[email protected]>
  27. * Massively reworked
  28. * Alan Cox <[email protected]>
  29. */
  30. #include "gem.h"
  31. #include "power.h"
  32. #include "psb_drv.h"
  33. #include "psb_reg.h"
  34. #include "psb_intel_reg.h"
  35. #include "psb_irq.h"
  36. #include <linux/mutex.h>
  37. #include <linux/pm_runtime.h>
  38. /**
  39. * gma_power_init - initialise power manager
  40. * @dev: our device
  41. *
  42. * Set up for power management tracking of our hardware.
  43. */
  44. void gma_power_init(struct drm_device *dev)
  45. {
  46. struct drm_psb_private *dev_priv = to_drm_psb_private(dev);
  47. /* FIXME: Move APM/OSPM base into relevant device code */
  48. dev_priv->apm_base = dev_priv->apm_reg & 0xffff;
  49. dev_priv->ospm_base &= 0xffff;
  50. if (dev_priv->ops->init_pm)
  51. dev_priv->ops->init_pm(dev);
  52. /*
  53. * Runtime pm support is broken atm. So for now unconditionally
  54. * call pm_runtime_get() here and put it again in psb_driver_unload()
  55. *
  56. * To fix this we need to call pm_runtime_get() once for each active
  57. * pipe at boot and then put() / get() for each pipe disable / enable
  58. * so that the device gets runtime suspended when no pipes are active.
  59. * Once this is in place the pm_runtime_get() below should be replaced
  60. * by a pm_runtime_allow() call to undo the pm_runtime_forbid() from
  61. * pci_pm_init().
  62. */
  63. pm_runtime_get(dev->dev);
  64. dev_priv->pm_initialized = true;
  65. }
  66. /**
  67. * gma_power_uninit - end power manager
  68. * @dev: device to end for
  69. *
  70. * Undo the effects of gma_power_init
  71. */
  72. void gma_power_uninit(struct drm_device *dev)
  73. {
  74. struct drm_psb_private *dev_priv = to_drm_psb_private(dev);
  75. if (!dev_priv->pm_initialized)
  76. return;
  77. pm_runtime_put_noidle(dev->dev);
  78. }
  79. /**
  80. * gma_suspend_display - suspend the display logic
  81. * @dev: our DRM device
  82. *
  83. * Suspend the display logic of the graphics interface
  84. */
  85. static void gma_suspend_display(struct drm_device *dev)
  86. {
  87. struct drm_psb_private *dev_priv = to_drm_psb_private(dev);
  88. dev_priv->ops->save_regs(dev);
  89. dev_priv->ops->power_down(dev);
  90. }
  91. /**
  92. * gma_resume_display - resume display side logic
  93. * @pdev: PCI device
  94. *
  95. * Resume the display hardware restoring state and enabling
  96. * as necessary.
  97. */
  98. static void gma_resume_display(struct pci_dev *pdev)
  99. {
  100. struct drm_device *dev = pci_get_drvdata(pdev);
  101. struct drm_psb_private *dev_priv = to_drm_psb_private(dev);
  102. /* turn on the display power island */
  103. dev_priv->ops->power_up(dev);
  104. PSB_WVDC32(dev_priv->pge_ctl | _PSB_PGETBL_ENABLED, PSB_PGETBL_CTL);
  105. pci_write_config_word(pdev, PSB_GMCH_CTRL,
  106. dev_priv->gmch_ctrl | _PSB_GMCH_ENABLED);
  107. /* Rebuild our GTT mappings */
  108. psb_gtt_resume(dev);
  109. psb_gem_mm_resume(dev);
  110. dev_priv->ops->restore_regs(dev);
  111. }
  112. /**
  113. * gma_suspend_pci - suspend PCI side
  114. * @pdev: PCI device
  115. *
  116. * Perform the suspend processing on our PCI device state
  117. */
  118. static void gma_suspend_pci(struct pci_dev *pdev)
  119. {
  120. struct drm_device *dev = pci_get_drvdata(pdev);
  121. struct drm_psb_private *dev_priv = to_drm_psb_private(dev);
  122. int bsm, vbt;
  123. pci_save_state(pdev);
  124. pci_read_config_dword(pdev, 0x5C, &bsm);
  125. dev_priv->regs.saveBSM = bsm;
  126. pci_read_config_dword(pdev, 0xFC, &vbt);
  127. dev_priv->regs.saveVBT = vbt;
  128. pci_disable_device(pdev);
  129. pci_set_power_state(pdev, PCI_D3hot);
  130. }
  131. /**
  132. * gma_resume_pci - resume helper
  133. * @pdev: our PCI device
  134. *
  135. * Perform the resume processing on our PCI device state - rewrite
  136. * register state and re-enable the PCI device
  137. */
  138. static int gma_resume_pci(struct pci_dev *pdev)
  139. {
  140. struct drm_device *dev = pci_get_drvdata(pdev);
  141. struct drm_psb_private *dev_priv = to_drm_psb_private(dev);
  142. pci_set_power_state(pdev, PCI_D0);
  143. pci_restore_state(pdev);
  144. pci_write_config_dword(pdev, 0x5c, dev_priv->regs.saveBSM);
  145. pci_write_config_dword(pdev, 0xFC, dev_priv->regs.saveVBT);
  146. return pci_enable_device(pdev);
  147. }
  148. /**
  149. * gma_power_suspend - bus callback for suspend
  150. * @_dev: our device
  151. *
  152. * Called back by the PCI layer during a suspend of the system. We
  153. * perform the necessary shut down steps and save enough state that
  154. * we can undo this when resume is called.
  155. */
  156. int gma_power_suspend(struct device *_dev)
  157. {
  158. struct pci_dev *pdev = to_pci_dev(_dev);
  159. struct drm_device *dev = pci_get_drvdata(pdev);
  160. gma_irq_uninstall(dev);
  161. gma_suspend_display(dev);
  162. gma_suspend_pci(pdev);
  163. return 0;
  164. }
  165. /**
  166. * gma_power_resume - resume power
  167. * @_dev: our device
  168. *
  169. * Resume the PCI side of the graphics and then the displays
  170. */
  171. int gma_power_resume(struct device *_dev)
  172. {
  173. struct pci_dev *pdev = to_pci_dev(_dev);
  174. struct drm_device *dev = pci_get_drvdata(pdev);
  175. gma_resume_pci(pdev);
  176. gma_resume_display(pdev);
  177. gma_irq_install(dev);
  178. return 0;
  179. }
  180. /**
  181. * gma_power_begin - begin requiring power
  182. * @dev: our DRM device
  183. * @force_on: true to force power on
  184. *
  185. * Begin an action that requires the display power island is enabled.
  186. * We refcount the islands.
  187. */
  188. bool gma_power_begin(struct drm_device *dev, bool force_on)
  189. {
  190. if (force_on)
  191. return pm_runtime_resume_and_get(dev->dev) == 0;
  192. else
  193. return pm_runtime_get_if_in_use(dev->dev) == 1;
  194. }
  195. /**
  196. * gma_power_end - end use of power
  197. * @dev: Our DRM device
  198. *
  199. * Indicate that one of our gma_power_begin() requested periods when
  200. * the diplay island power is needed has completed.
  201. */
  202. void gma_power_end(struct drm_device *dev)
  203. {
  204. pm_runtime_put(dev->dev);
  205. }