power.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /*
  2. * BRIEF MODULE DESCRIPTION
  3. * Au1xx0 Power Management routines.
  4. *
  5. * Copyright 2001, 2008 MontaVista Software Inc.
  6. * Author: MontaVista Software, Inc. <source@mvista.com>
  7. *
  8. * Some of the routines are right out of init/main.c, whose
  9. * copyrights apply here.
  10. *
  11. * This program is free software; you can redistribute it and/or modify it
  12. * under the terms of the GNU General Public License as published by the
  13. * Free Software Foundation; either version 2 of the License, or (at your
  14. * option) any later version.
  15. *
  16. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
  17. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  18. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
  19. * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  20. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  21. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  22. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  23. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  25. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. *
  27. * You should have received a copy of the GNU General Public License along
  28. * with this program; if not, write to the Free Software Foundation, Inc.,
  29. * 675 Mass Ave, Cambridge, MA 02139, USA.
  30. */
  31. #include <linux/pm.h>
  32. #include <linux/sysctl.h>
  33. #include <linux/jiffies.h>
  34. #include <asm/uaccess.h>
  35. #include <asm/mach-au1x00/au1000.h>
  36. /*
  37. * We need to save/restore a bunch of core registers that are
  38. * either volatile or reset to some state across a processor sleep.
  39. * If reading a register doesn't provide a proper result for a
  40. * later restore, we have to provide a function for loading that
  41. * register and save a copy.
  42. *
  43. * We only have to save/restore registers that aren't otherwise
  44. * done as part of a driver pm_* function.
  45. */
  46. static unsigned int sleep_sys_clocks[5];
  47. static unsigned int sleep_sys_pinfunc;
  48. static unsigned int sleep_static_memctlr[4][3];
  49. static void save_core_regs(void)
  50. {
  51. /* Clocks and PLLs. */
  52. sleep_sys_clocks[0] = alchemy_rdsys(AU1000_SYS_FREQCTRL0);
  53. sleep_sys_clocks[1] = alchemy_rdsys(AU1000_SYS_FREQCTRL1);
  54. sleep_sys_clocks[2] = alchemy_rdsys(AU1000_SYS_CLKSRC);
  55. sleep_sys_clocks[3] = alchemy_rdsys(AU1000_SYS_CPUPLL);
  56. sleep_sys_clocks[4] = alchemy_rdsys(AU1000_SYS_AUXPLL);
  57. /* pin mux config */
  58. sleep_sys_pinfunc = alchemy_rdsys(AU1000_SYS_PINFUNC);
  59. /* Save the static memory controller configuration. */
  60. sleep_static_memctlr[0][0] = alchemy_rdsmem(AU1000_MEM_STCFG0);
  61. sleep_static_memctlr[0][1] = alchemy_rdsmem(AU1000_MEM_STTIME0);
  62. sleep_static_memctlr[0][2] = alchemy_rdsmem(AU1000_MEM_STADDR0);
  63. sleep_static_memctlr[1][0] = alchemy_rdsmem(AU1000_MEM_STCFG1);
  64. sleep_static_memctlr[1][1] = alchemy_rdsmem(AU1000_MEM_STTIME1);
  65. sleep_static_memctlr[1][2] = alchemy_rdsmem(AU1000_MEM_STADDR1);
  66. sleep_static_memctlr[2][0] = alchemy_rdsmem(AU1000_MEM_STCFG2);
  67. sleep_static_memctlr[2][1] = alchemy_rdsmem(AU1000_MEM_STTIME2);
  68. sleep_static_memctlr[2][2] = alchemy_rdsmem(AU1000_MEM_STADDR2);
  69. sleep_static_memctlr[3][0] = alchemy_rdsmem(AU1000_MEM_STCFG3);
  70. sleep_static_memctlr[3][1] = alchemy_rdsmem(AU1000_MEM_STTIME3);
  71. sleep_static_memctlr[3][2] = alchemy_rdsmem(AU1000_MEM_STADDR3);
  72. }
  73. static void restore_core_regs(void)
  74. {
  75. /* restore clock configuration. Writing CPUPLL last will
  76. * stall a bit and stabilize other clocks (unless this is
  77. * one of those Au1000 with a write-only PLL, where we dont
  78. * have a valid value)
  79. */
  80. alchemy_wrsys(sleep_sys_clocks[0], AU1000_SYS_FREQCTRL0);
  81. alchemy_wrsys(sleep_sys_clocks[1], AU1000_SYS_FREQCTRL1);
  82. alchemy_wrsys(sleep_sys_clocks[2], AU1000_SYS_CLKSRC);
  83. alchemy_wrsys(sleep_sys_clocks[4], AU1000_SYS_AUXPLL);
  84. if (!au1xxx_cpu_has_pll_wo())
  85. alchemy_wrsys(sleep_sys_clocks[3], AU1000_SYS_CPUPLL);
  86. alchemy_wrsys(sleep_sys_pinfunc, AU1000_SYS_PINFUNC);
  87. /* Restore the static memory controller configuration. */
  88. alchemy_wrsmem(sleep_static_memctlr[0][0], AU1000_MEM_STCFG0);
  89. alchemy_wrsmem(sleep_static_memctlr[0][1], AU1000_MEM_STTIME0);
  90. alchemy_wrsmem(sleep_static_memctlr[0][2], AU1000_MEM_STADDR0);
  91. alchemy_wrsmem(sleep_static_memctlr[1][0], AU1000_MEM_STCFG1);
  92. alchemy_wrsmem(sleep_static_memctlr[1][1], AU1000_MEM_STTIME1);
  93. alchemy_wrsmem(sleep_static_memctlr[1][2], AU1000_MEM_STADDR1);
  94. alchemy_wrsmem(sleep_static_memctlr[2][0], AU1000_MEM_STCFG2);
  95. alchemy_wrsmem(sleep_static_memctlr[2][1], AU1000_MEM_STTIME2);
  96. alchemy_wrsmem(sleep_static_memctlr[2][2], AU1000_MEM_STADDR2);
  97. alchemy_wrsmem(sleep_static_memctlr[3][0], AU1000_MEM_STCFG3);
  98. alchemy_wrsmem(sleep_static_memctlr[3][1], AU1000_MEM_STTIME3);
  99. alchemy_wrsmem(sleep_static_memctlr[3][2], AU1000_MEM_STADDR3);
  100. }
  101. void au_sleep(void)
  102. {
  103. save_core_regs();
  104. switch (alchemy_get_cputype()) {
  105. case ALCHEMY_CPU_AU1000:
  106. case ALCHEMY_CPU_AU1500:
  107. case ALCHEMY_CPU_AU1100:
  108. alchemy_sleep_au1000();
  109. break;
  110. case ALCHEMY_CPU_AU1550:
  111. case ALCHEMY_CPU_AU1200:
  112. alchemy_sleep_au1550();
  113. break;
  114. case ALCHEMY_CPU_AU1300:
  115. alchemy_sleep_au1300();
  116. break;
  117. }
  118. restore_core_regs();
  119. }