power.c 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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/init.h>
  32. #include <linux/pm.h>
  33. #include <linux/sysctl.h>
  34. #include <linux/jiffies.h>
  35. #include <asm/uaccess.h>
  36. #include <asm/mach-au1x00/au1000.h>
  37. #if defined(CONFIG_SOC_AU1550) || defined(CONFIG_SOC_AU1200)
  38. #include <asm/mach-au1x00/au1xxx_dbdma.h>
  39. #endif
  40. #ifdef CONFIG_PM
  41. /*
  42. * We need to save/restore a bunch of core registers that are
  43. * either volatile or reset to some state across a processor sleep.
  44. * If reading a register doesn't provide a proper result for a
  45. * later restore, we have to provide a function for loading that
  46. * register and save a copy.
  47. *
  48. * We only have to save/restore registers that aren't otherwise
  49. * done as part of a driver pm_* function.
  50. */
  51. static unsigned int sleep_uart0_inten;
  52. static unsigned int sleep_uart0_fifoctl;
  53. static unsigned int sleep_uart0_linectl;
  54. static unsigned int sleep_uart0_clkdiv;
  55. static unsigned int sleep_uart0_enable;
  56. static unsigned int sleep_usb[2];
  57. static unsigned int sleep_sys_clocks[5];
  58. static unsigned int sleep_sys_pinfunc;
  59. static unsigned int sleep_static_memctlr[4][3];
  60. static void save_core_regs(void)
  61. {
  62. extern void save_au1xxx_intctl(void);
  63. extern void pm_eth0_shutdown(void);
  64. /*
  65. * Do the serial ports.....these really should be a pm_*
  66. * registered function by the driver......but of course the
  67. * standard serial driver doesn't understand our Au1xxx
  68. * unique registers.
  69. */
  70. sleep_uart0_inten = au_readl(UART0_ADDR + UART_IER);
  71. sleep_uart0_fifoctl = au_readl(UART0_ADDR + UART_FCR);
  72. sleep_uart0_linectl = au_readl(UART0_ADDR + UART_LCR);
  73. sleep_uart0_clkdiv = au_readl(UART0_ADDR + UART_CLK);
  74. sleep_uart0_enable = au_readl(UART0_ADDR + UART_MOD_CNTRL);
  75. au_sync();
  76. #ifndef CONFIG_SOC_AU1200
  77. /* Shutdown USB host/device. */
  78. sleep_usb[0] = au_readl(USB_HOST_CONFIG);
  79. /* There appears to be some undocumented reset register.... */
  80. au_writel(0, 0xb0100004);
  81. au_sync();
  82. au_writel(0, USB_HOST_CONFIG);
  83. au_sync();
  84. sleep_usb[1] = au_readl(USBD_ENABLE);
  85. au_writel(0, USBD_ENABLE);
  86. au_sync();
  87. #else /* AU1200 */
  88. /* enable access to OTG mmio so we can save OTG CAP/MUX.
  89. * FIXME: write an OTG driver and move this stuff there!
  90. */
  91. au_writel(au_readl(USB_MSR_BASE + 4) | (1 << 6), USB_MSR_BASE + 4);
  92. au_sync();
  93. sleep_usb[0] = au_readl(0xb4020020); /* OTG_CAP */
  94. sleep_usb[1] = au_readl(0xb4020024); /* OTG_MUX */
  95. #endif
  96. /* Save interrupt controller state. */
  97. save_au1xxx_intctl();
  98. /* Clocks and PLLs. */
  99. sleep_sys_clocks[0] = au_readl(SYS_FREQCTRL0);
  100. sleep_sys_clocks[1] = au_readl(SYS_FREQCTRL1);
  101. sleep_sys_clocks[2] = au_readl(SYS_CLKSRC);
  102. sleep_sys_clocks[3] = au_readl(SYS_CPUPLL);
  103. sleep_sys_clocks[4] = au_readl(SYS_AUXPLL);
  104. /* pin mux config */
  105. sleep_sys_pinfunc = au_readl(SYS_PINFUNC);
  106. /* Save the static memory controller configuration. */
  107. sleep_static_memctlr[0][0] = au_readl(MEM_STCFG0);
  108. sleep_static_memctlr[0][1] = au_readl(MEM_STTIME0);
  109. sleep_static_memctlr[0][2] = au_readl(MEM_STADDR0);
  110. sleep_static_memctlr[1][0] = au_readl(MEM_STCFG1);
  111. sleep_static_memctlr[1][1] = au_readl(MEM_STTIME1);
  112. sleep_static_memctlr[1][2] = au_readl(MEM_STADDR1);
  113. sleep_static_memctlr[2][0] = au_readl(MEM_STCFG2);
  114. sleep_static_memctlr[2][1] = au_readl(MEM_STTIME2);
  115. sleep_static_memctlr[2][2] = au_readl(MEM_STADDR2);
  116. sleep_static_memctlr[3][0] = au_readl(MEM_STCFG3);
  117. sleep_static_memctlr[3][1] = au_readl(MEM_STTIME3);
  118. sleep_static_memctlr[3][2] = au_readl(MEM_STADDR3);
  119. #if defined(CONFIG_SOC_AU1550) || defined(CONFIG_SOC_AU1200)
  120. au1xxx_dbdma_suspend();
  121. #endif
  122. }
  123. static void restore_core_regs(void)
  124. {
  125. /* restore clock configuration. Writing CPUPLL last will
  126. * stall a bit and stabilize other clocks (unless this is
  127. * one of those Au1000 with a write-only PLL, where we dont
  128. * have a valid value)
  129. */
  130. au_writel(sleep_sys_clocks[0], SYS_FREQCTRL0);
  131. au_writel(sleep_sys_clocks[1], SYS_FREQCTRL1);
  132. au_writel(sleep_sys_clocks[2], SYS_CLKSRC);
  133. au_writel(sleep_sys_clocks[4], SYS_AUXPLL);
  134. if (!au1xxx_cpu_has_pll_wo())
  135. au_writel(sleep_sys_clocks[3], SYS_CPUPLL);
  136. au_sync();
  137. au_writel(sleep_sys_pinfunc, SYS_PINFUNC);
  138. au_sync();
  139. #ifndef CONFIG_SOC_AU1200
  140. au_writel(sleep_usb[0], USB_HOST_CONFIG);
  141. au_writel(sleep_usb[1], USBD_ENABLE);
  142. au_sync();
  143. #else
  144. /* enable accces to OTG memory */
  145. au_writel(au_readl(USB_MSR_BASE + 4) | (1 << 6), USB_MSR_BASE + 4);
  146. au_sync();
  147. /* restore OTG caps and port mux. */
  148. au_writel(sleep_usb[0], 0xb4020020 + 0); /* OTG_CAP */
  149. au_sync();
  150. au_writel(sleep_usb[1], 0xb4020020 + 4); /* OTG_MUX */
  151. au_sync();
  152. #endif
  153. /* Restore the static memory controller configuration. */
  154. au_writel(sleep_static_memctlr[0][0], MEM_STCFG0);
  155. au_writel(sleep_static_memctlr[0][1], MEM_STTIME0);
  156. au_writel(sleep_static_memctlr[0][2], MEM_STADDR0);
  157. au_writel(sleep_static_memctlr[1][0], MEM_STCFG1);
  158. au_writel(sleep_static_memctlr[1][1], MEM_STTIME1);
  159. au_writel(sleep_static_memctlr[1][2], MEM_STADDR1);
  160. au_writel(sleep_static_memctlr[2][0], MEM_STCFG2);
  161. au_writel(sleep_static_memctlr[2][1], MEM_STTIME2);
  162. au_writel(sleep_static_memctlr[2][2], MEM_STADDR2);
  163. au_writel(sleep_static_memctlr[3][0], MEM_STCFG3);
  164. au_writel(sleep_static_memctlr[3][1], MEM_STTIME3);
  165. au_writel(sleep_static_memctlr[3][2], MEM_STADDR3);
  166. /*
  167. * Enable the UART if it was enabled before sleep.
  168. * I guess I should define module control bits........
  169. */
  170. if (sleep_uart0_enable & 0x02) {
  171. au_writel(0, UART0_ADDR + UART_MOD_CNTRL); au_sync();
  172. au_writel(1, UART0_ADDR + UART_MOD_CNTRL); au_sync();
  173. au_writel(3, UART0_ADDR + UART_MOD_CNTRL); au_sync();
  174. au_writel(sleep_uart0_inten, UART0_ADDR + UART_IER); au_sync();
  175. au_writel(sleep_uart0_fifoctl, UART0_ADDR + UART_FCR); au_sync();
  176. au_writel(sleep_uart0_linectl, UART0_ADDR + UART_LCR); au_sync();
  177. au_writel(sleep_uart0_clkdiv, UART0_ADDR + UART_CLK); au_sync();
  178. }
  179. restore_au1xxx_intctl();
  180. #if defined(CONFIG_SOC_AU1550) || defined(CONFIG_SOC_AU1200)
  181. au1xxx_dbdma_resume();
  182. #endif
  183. }
  184. void au_sleep(void)
  185. {
  186. save_core_regs();
  187. au1xxx_save_and_sleep();
  188. restore_core_regs();
  189. }
  190. #endif /* CONFIG_PM */