pm_suspend.S 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. /*
  2. * arch/arm/mach-at91/pm_slow_clock.S
  3. *
  4. * Copyright (C) 2006 Savin Zlobec
  5. *
  6. * AT91SAM9 support:
  7. * Copyright (C) 2007 Anti Sullin <anti.sullin@artecdesign.ee
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2 as
  11. * published by the Free Software Foundation.
  12. *
  13. */
  14. #include <linux/linkage.h>
  15. #include <linux/clk/at91_pmc.h>
  16. #include "pm.h"
  17. #define SRAMC_SELF_FRESH_ACTIVE 0x01
  18. #define SRAMC_SELF_FRESH_EXIT 0x00
  19. pmc .req r0
  20. tmp1 .req r4
  21. tmp2 .req r5
  22. /*
  23. * Wait until master clock is ready (after switching master clock source)
  24. */
  25. .macro wait_mckrdy
  26. 1: ldr tmp1, [pmc, #AT91_PMC_SR]
  27. tst tmp1, #AT91_PMC_MCKRDY
  28. beq 1b
  29. .endm
  30. /*
  31. * Wait until master oscillator has stabilized.
  32. */
  33. .macro wait_moscrdy
  34. 1: ldr tmp1, [pmc, #AT91_PMC_SR]
  35. tst tmp1, #AT91_PMC_MOSCS
  36. beq 1b
  37. .endm
  38. /*
  39. * Wait until PLLA has locked.
  40. */
  41. .macro wait_pllalock
  42. 1: ldr tmp1, [pmc, #AT91_PMC_SR]
  43. tst tmp1, #AT91_PMC_LOCKA
  44. beq 1b
  45. .endm
  46. /*
  47. * Put the processor to enter the idle state
  48. */
  49. .macro at91_cpu_idle
  50. #if defined(CONFIG_CPU_V7)
  51. mov tmp1, #AT91_PMC_PCK
  52. str tmp1, [pmc, #AT91_PMC_SCDR]
  53. dsb
  54. wfi @ Wait For Interrupt
  55. #else
  56. mcr p15, 0, tmp1, c7, c0, 4
  57. #endif
  58. .endm
  59. .text
  60. .arm
  61. /*
  62. * void at91_pm_suspend_in_sram(void __iomem *pmc, void __iomem *sdramc,
  63. * void __iomem *ramc1, int memctrl)
  64. * @input param:
  65. * @r0: base address of AT91_PMC
  66. * @r1: base address of SDRAM Controller (SDRAM, DDRSDR, or AT91_SYS)
  67. * @r2: base address of second SDRAM Controller or 0 if not present
  68. * @r3: pm information
  69. */
  70. /* at91_pm_suspend_in_sram must be 8-byte aligned per the requirements of fncpy() */
  71. .align 3
  72. ENTRY(at91_pm_suspend_in_sram)
  73. /* Save registers on stack */
  74. stmfd sp!, {r4 - r12, lr}
  75. /* Drain write buffer */
  76. mov tmp1, #0
  77. mcr p15, 0, tmp1, c7, c10, 4
  78. str r0, .pmc_base
  79. str r1, .sramc_base
  80. str r2, .sramc1_base
  81. and r0, r3, #AT91_PM_MEMTYPE_MASK
  82. str r0, .memtype
  83. lsr r0, r3, #AT91_PM_MODE_OFFSET
  84. and r0, r0, #AT91_PM_MODE_MASK
  85. str r0, .pm_mode
  86. /* Active the self-refresh mode */
  87. mov r0, #SRAMC_SELF_FRESH_ACTIVE
  88. bl at91_sramc_self_refresh
  89. ldr r0, .pm_mode
  90. tst r0, #AT91_PM_SLOW_CLOCK
  91. beq skip_disable_main_clock
  92. ldr pmc, .pmc_base
  93. /* Save Master clock setting */
  94. ldr tmp1, [pmc, #AT91_PMC_MCKR]
  95. str tmp1, .saved_mckr
  96. /*
  97. * Set the Master clock source to slow clock
  98. */
  99. bic tmp1, tmp1, #AT91_PMC_CSS
  100. str tmp1, [pmc, #AT91_PMC_MCKR]
  101. wait_mckrdy
  102. /* Save PLLA setting and disable it */
  103. ldr tmp1, [pmc, #AT91_CKGR_PLLAR]
  104. str tmp1, .saved_pllar
  105. mov tmp1, #AT91_PMC_PLLCOUNT
  106. orr tmp1, tmp1, #(1 << 29) /* bit 29 always set */
  107. str tmp1, [pmc, #AT91_CKGR_PLLAR]
  108. /* Turn off the main oscillator */
  109. ldr tmp1, [pmc, #AT91_CKGR_MOR]
  110. bic tmp1, tmp1, #AT91_PMC_MOSCEN
  111. orr tmp1, tmp1, #AT91_PMC_KEY
  112. str tmp1, [pmc, #AT91_CKGR_MOR]
  113. skip_disable_main_clock:
  114. ldr pmc, .pmc_base
  115. /* Wait for interrupt */
  116. at91_cpu_idle
  117. ldr r0, .pm_mode
  118. tst r0, #AT91_PM_SLOW_CLOCK
  119. beq skip_enable_main_clock
  120. ldr pmc, .pmc_base
  121. /* Turn on the main oscillator */
  122. ldr tmp1, [pmc, #AT91_CKGR_MOR]
  123. orr tmp1, tmp1, #AT91_PMC_MOSCEN
  124. orr tmp1, tmp1, #AT91_PMC_KEY
  125. str tmp1, [pmc, #AT91_CKGR_MOR]
  126. wait_moscrdy
  127. /* Restore PLLA setting */
  128. ldr tmp1, .saved_pllar
  129. str tmp1, [pmc, #AT91_CKGR_PLLAR]
  130. tst tmp1, #(AT91_PMC_MUL & 0xff0000)
  131. bne 3f
  132. tst tmp1, #(AT91_PMC_MUL & ~0xff0000)
  133. beq 4f
  134. 3:
  135. wait_pllalock
  136. 4:
  137. /*
  138. * Restore master clock setting
  139. */
  140. ldr tmp1, .saved_mckr
  141. str tmp1, [pmc, #AT91_PMC_MCKR]
  142. wait_mckrdy
  143. skip_enable_main_clock:
  144. /* Exit the self-refresh mode */
  145. mov r0, #SRAMC_SELF_FRESH_EXIT
  146. bl at91_sramc_self_refresh
  147. /* Restore registers, and return */
  148. ldmfd sp!, {r4 - r12, pc}
  149. ENDPROC(at91_pm_suspend_in_sram)
  150. /*
  151. * void at91_sramc_self_refresh(unsigned int is_active)
  152. *
  153. * @input param:
  154. * @r0: 1 - active self-refresh mode
  155. * 0 - exit self-refresh mode
  156. * register usage:
  157. * @r1: memory type
  158. * @r2: base address of the sram controller
  159. */
  160. ENTRY(at91_sramc_self_refresh)
  161. ldr r1, .memtype
  162. ldr r2, .sramc_base
  163. cmp r1, #AT91_MEMCTRL_MC
  164. bne ddrc_sf
  165. /*
  166. * at91rm9200 Memory controller
  167. */
  168. /*
  169. * For exiting the self-refresh mode, do nothing,
  170. * automatically exit the self-refresh mode.
  171. */
  172. tst r0, #SRAMC_SELF_FRESH_ACTIVE
  173. beq exit_sramc_sf
  174. /* Active SDRAM self-refresh mode */
  175. mov r3, #1
  176. str r3, [r2, #AT91_MC_SDRAMC_SRR]
  177. b exit_sramc_sf
  178. ddrc_sf:
  179. cmp r1, #AT91_MEMCTRL_DDRSDR
  180. bne sdramc_sf
  181. /*
  182. * DDR Memory controller
  183. */
  184. tst r0, #SRAMC_SELF_FRESH_ACTIVE
  185. beq ddrc_exit_sf
  186. /* LPDDR1 --> force DDR2 mode during self-refresh */
  187. ldr r3, [r2, #AT91_DDRSDRC_MDR]
  188. str r3, .saved_sam9_mdr
  189. bic r3, r3, #~AT91_DDRSDRC_MD
  190. cmp r3, #AT91_DDRSDRC_MD_LOW_POWER_DDR
  191. ldreq r3, [r2, #AT91_DDRSDRC_MDR]
  192. biceq r3, r3, #AT91_DDRSDRC_MD
  193. orreq r3, r3, #AT91_DDRSDRC_MD_DDR2
  194. streq r3, [r2, #AT91_DDRSDRC_MDR]
  195. /* Active DDRC self-refresh mode */
  196. ldr r3, [r2, #AT91_DDRSDRC_LPR]
  197. str r3, .saved_sam9_lpr
  198. bic r3, r3, #AT91_DDRSDRC_LPCB
  199. orr r3, r3, #AT91_DDRSDRC_LPCB_SELF_REFRESH
  200. str r3, [r2, #AT91_DDRSDRC_LPR]
  201. /* If using the 2nd ddr controller */
  202. ldr r2, .sramc1_base
  203. cmp r2, #0
  204. beq no_2nd_ddrc
  205. ldr r3, [r2, #AT91_DDRSDRC_MDR]
  206. str r3, .saved_sam9_mdr1
  207. bic r3, r3, #~AT91_DDRSDRC_MD
  208. cmp r3, #AT91_DDRSDRC_MD_LOW_POWER_DDR
  209. ldreq r3, [r2, #AT91_DDRSDRC_MDR]
  210. biceq r3, r3, #AT91_DDRSDRC_MD
  211. orreq r3, r3, #AT91_DDRSDRC_MD_DDR2
  212. streq r3, [r2, #AT91_DDRSDRC_MDR]
  213. /* Active DDRC self-refresh mode */
  214. ldr r3, [r2, #AT91_DDRSDRC_LPR]
  215. str r3, .saved_sam9_lpr1
  216. bic r3, r3, #AT91_DDRSDRC_LPCB
  217. orr r3, r3, #AT91_DDRSDRC_LPCB_SELF_REFRESH
  218. str r3, [r2, #AT91_DDRSDRC_LPR]
  219. no_2nd_ddrc:
  220. b exit_sramc_sf
  221. ddrc_exit_sf:
  222. /* Restore MDR in case of LPDDR1 */
  223. ldr r3, .saved_sam9_mdr
  224. str r3, [r2, #AT91_DDRSDRC_MDR]
  225. /* Restore LPR on AT91 with DDRAM */
  226. ldr r3, .saved_sam9_lpr
  227. str r3, [r2, #AT91_DDRSDRC_LPR]
  228. /* If using the 2nd ddr controller */
  229. ldr r2, .sramc1_base
  230. cmp r2, #0
  231. ldrne r3, .saved_sam9_mdr1
  232. strne r3, [r2, #AT91_DDRSDRC_MDR]
  233. ldrne r3, .saved_sam9_lpr1
  234. strne r3, [r2, #AT91_DDRSDRC_LPR]
  235. b exit_sramc_sf
  236. /*
  237. * SDRAMC Memory controller
  238. */
  239. sdramc_sf:
  240. tst r0, #SRAMC_SELF_FRESH_ACTIVE
  241. beq sdramc_exit_sf
  242. /* Active SDRAMC self-refresh mode */
  243. ldr r3, [r2, #AT91_SDRAMC_LPR]
  244. str r3, .saved_sam9_lpr
  245. bic r3, r3, #AT91_SDRAMC_LPCB
  246. orr r3, r3, #AT91_SDRAMC_LPCB_SELF_REFRESH
  247. str r3, [r2, #AT91_SDRAMC_LPR]
  248. sdramc_exit_sf:
  249. ldr r3, .saved_sam9_lpr
  250. str r3, [r2, #AT91_SDRAMC_LPR]
  251. exit_sramc_sf:
  252. mov pc, lr
  253. ENDPROC(at91_sramc_self_refresh)
  254. .pmc_base:
  255. .word 0
  256. .sramc_base:
  257. .word 0
  258. .sramc1_base:
  259. .word 0
  260. .memtype:
  261. .word 0
  262. .pm_mode:
  263. .word 0
  264. .saved_mckr:
  265. .word 0
  266. .saved_pllar:
  267. .word 0
  268. .saved_sam9_lpr:
  269. .word 0
  270. .saved_sam9_lpr1:
  271. .word 0
  272. .saved_sam9_mdr:
  273. .word 0
  274. .saved_sam9_mdr1:
  275. .word 0
  276. ENTRY(at91_pm_suspend_in_sram_sz)
  277. .word .-at91_pm_suspend_in_sram