lite5200_sleep.S 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  1. #include <asm/reg.h>
  2. #include <asm/ppc_asm.h>
  3. #include <asm/processor.h>
  4. #include <asm/cache.h>
  5. #define SDRAM_CTRL 0x104
  6. #define SC_MODE_EN (1<<31)
  7. #define SC_CKE (1<<30)
  8. #define SC_REF_EN (1<<28)
  9. #define SC_SOFT_PRE (1<<1)
  10. #define GPIOW_GPIOE 0xc00
  11. #define GPIOW_DDR 0xc08
  12. #define GPIOW_DVO 0xc0c
  13. #define CDM_CE 0x214
  14. #define CDM_SDRAM (1<<3)
  15. /* helpers... beware: r10 and r4 are overwritten */
  16. #define SAVE_SPRN(reg, addr) \
  17. mfspr r10, SPRN_##reg; \
  18. stw r10, ((addr)*4)(r4);
  19. #define LOAD_SPRN(reg, addr) \
  20. lwz r10, ((addr)*4)(r4); \
  21. mtspr SPRN_##reg, r10; \
  22. sync; \
  23. isync;
  24. .data
  25. registers:
  26. .space 0x5c*4
  27. .text
  28. /* ---------------------------------------------------------------------- */
  29. /* low-power mode with help of M68HLC908QT1 */
  30. .globl lite5200_low_power
  31. lite5200_low_power:
  32. mr r7, r3 /* save SRAM va */
  33. mr r8, r4 /* save MBAR va */
  34. /* setup wakeup address for u-boot at physical location 0x0 */
  35. lis r3, CONFIG_KERNEL_START@h
  36. lis r4, lite5200_wakeup@h
  37. ori r4, r4, lite5200_wakeup@l
  38. sub r4, r4, r3
  39. stw r4, 0(r3)
  40. /*
  41. * save stuff BDI overwrites
  42. * 0xf0 (0xe0->0x100 gets overwritten when BDI connected;
  43. * even when CONFIG_BDI* is disabled and MMU XLAT commented; heisenbug?))
  44. * WARNING: self-refresh doesn't seem to work when BDI2000 is connected,
  45. * possibly because BDI sets SDRAM registers before wakeup code does
  46. */
  47. lis r4, registers@h
  48. ori r4, r4, registers@l
  49. lwz r10, 0xf0(r3)
  50. stw r10, (0x1d*4)(r4)
  51. /* save registers to r4 [destroys r10] */
  52. SAVE_SPRN(LR, 0x1c)
  53. bl save_regs
  54. /* flush caches [destroys r3, r4] */
  55. bl flush_data_cache
  56. /* copy code to sram */
  57. mr r4, r7
  58. li r3, (sram_code_end - sram_code)/4
  59. mtctr r3
  60. lis r3, sram_code@h
  61. ori r3, r3, sram_code@l
  62. 1:
  63. lwz r5, 0(r3)
  64. stw r5, 0(r4)
  65. addi r3, r3, 4
  66. addi r4, r4, 4
  67. bdnz 1b
  68. /* get tb_ticks_per_usec */
  69. lis r3, tb_ticks_per_usec@h
  70. lwz r11, tb_ticks_per_usec@l(r3)
  71. /* disable I and D caches */
  72. mfspr r3, SPRN_HID0
  73. ori r3, r3, HID0_ICE | HID0_DCE
  74. xori r3, r3, HID0_ICE | HID0_DCE
  75. sync; isync;
  76. mtspr SPRN_HID0, r3
  77. sync; isync;
  78. /* jump to sram */
  79. mtlr r7
  80. blrl
  81. /* doesn't return */
  82. sram_code:
  83. /* self refresh */
  84. lwz r4, SDRAM_CTRL(r8)
  85. /* send NOP (precharge) */
  86. oris r4, r4, SC_MODE_EN@h /* mode_en */
  87. stw r4, SDRAM_CTRL(r8)
  88. sync
  89. ori r4, r4, SC_SOFT_PRE /* soft_pre */
  90. stw r4, SDRAM_CTRL(r8)
  91. sync
  92. xori r4, r4, SC_SOFT_PRE
  93. xoris r4, r4, SC_MODE_EN@h /* !mode_en */
  94. stw r4, SDRAM_CTRL(r8)
  95. sync
  96. /* delay (for NOP to finish) */
  97. li r12, 1
  98. bl udelay
  99. /*
  100. * mode_en must not be set when enabling self-refresh
  101. * send AR with CKE low (self-refresh)
  102. */
  103. oris r4, r4, (SC_REF_EN | SC_CKE)@h
  104. xoris r4, r4, (SC_CKE)@h /* ref_en !cke */
  105. stw r4, SDRAM_CTRL(r8)
  106. sync
  107. /* delay (after !CKE there should be two cycles) */
  108. li r12, 1
  109. bl udelay
  110. /* disable clock */
  111. lwz r4, CDM_CE(r8)
  112. ori r4, r4, CDM_SDRAM
  113. xori r4, r4, CDM_SDRAM
  114. stw r4, CDM_CE(r8)
  115. sync
  116. /* delay a bit */
  117. li r12, 1
  118. bl udelay
  119. /* turn off with QT chip */
  120. li r4, 0x02
  121. stb r4, GPIOW_GPIOE(r8) /* enable gpio_wkup1 */
  122. sync
  123. stb r4, GPIOW_DVO(r8) /* "output" high */
  124. sync
  125. stb r4, GPIOW_DDR(r8) /* output */
  126. sync
  127. stb r4, GPIOW_DVO(r8) /* output high */
  128. sync
  129. /* 10uS delay */
  130. li r12, 10
  131. bl udelay
  132. /* turn off */
  133. li r4, 0
  134. stb r4, GPIOW_DVO(r8) /* output low */
  135. sync
  136. /* wait until we're offline */
  137. 1:
  138. b 1b
  139. /* local udelay in sram is needed */
  140. udelay: /* r11 - tb_ticks_per_usec, r12 - usecs, overwrites r13 */
  141. mullw r12, r12, r11
  142. mftb r13 /* start */
  143. addi r12, r13, r12 /* end */
  144. 1:
  145. mftb r13 /* current */
  146. cmp cr0, r13, r12
  147. blt 1b
  148. blr
  149. sram_code_end:
  150. /* uboot jumps here on resume */
  151. lite5200_wakeup:
  152. bl restore_regs
  153. /* HIDs, MSR */
  154. LOAD_SPRN(HID1, 0x19)
  155. LOAD_SPRN(HID2, 0x1a)
  156. /* address translation is tricky (see turn_on_mmu) */
  157. mfmsr r10
  158. ori r10, r10, MSR_DR | MSR_IR
  159. mtspr SPRN_SRR1, r10
  160. lis r10, mmu_on@h
  161. ori r10, r10, mmu_on@l
  162. mtspr SPRN_SRR0, r10
  163. sync
  164. rfi
  165. mmu_on:
  166. /* kernel offset (r4 is still set from restore_registers) */
  167. addis r4, r4, CONFIG_KERNEL_START@h
  168. /* restore MSR */
  169. lwz r10, (4*0x1b)(r4)
  170. mtmsr r10
  171. sync; isync;
  172. /* invalidate caches */
  173. mfspr r10, SPRN_HID0
  174. ori r5, r10, HID0_ICFI | HID0_DCI
  175. mtspr SPRN_HID0, r5 /* invalidate caches */
  176. sync; isync;
  177. mtspr SPRN_HID0, r10
  178. sync; isync;
  179. /* enable caches */
  180. lwz r10, (4*0x18)(r4)
  181. mtspr SPRN_HID0, r10 /* restore (enable caches, DPM) */
  182. /* ^ this has to be after address translation set in MSR */
  183. sync
  184. isync
  185. /* restore 0xf0 (BDI2000) */
  186. lis r3, CONFIG_KERNEL_START@h
  187. lwz r10, (0x1d*4)(r4)
  188. stw r10, 0xf0(r3)
  189. LOAD_SPRN(LR, 0x1c)
  190. blr
  191. /* ---------------------------------------------------------------------- */
  192. /* boring code: helpers */
  193. /* save registers */
  194. #define SAVE_BAT(n, addr) \
  195. SAVE_SPRN(DBAT##n##L, addr); \
  196. SAVE_SPRN(DBAT##n##U, addr+1); \
  197. SAVE_SPRN(IBAT##n##L, addr+2); \
  198. SAVE_SPRN(IBAT##n##U, addr+3);
  199. #define SAVE_SR(n, addr) \
  200. mfsr r10, n; \
  201. stw r10, ((addr)*4)(r4);
  202. #define SAVE_4SR(n, addr) \
  203. SAVE_SR(n, addr); \
  204. SAVE_SR(n+1, addr+1); \
  205. SAVE_SR(n+2, addr+2); \
  206. SAVE_SR(n+3, addr+3);
  207. save_regs:
  208. stw r0, 0(r4)
  209. stw r1, 0x4(r4)
  210. stw r2, 0x8(r4)
  211. stmw r11, 0xc(r4) /* 0xc -> 0x5f, (0x18*4-1) */
  212. SAVE_SPRN(HID0, 0x18)
  213. SAVE_SPRN(HID1, 0x19)
  214. SAVE_SPRN(HID2, 0x1a)
  215. mfmsr r10
  216. stw r10, (4*0x1b)(r4)
  217. /*SAVE_SPRN(LR, 0x1c) have to save it before the call */
  218. /* 0x1d reserved by 0xf0 */
  219. SAVE_SPRN(RPA, 0x1e)
  220. SAVE_SPRN(SDR1, 0x1f)
  221. /* save MMU regs */
  222. SAVE_BAT(0, 0x20)
  223. SAVE_BAT(1, 0x24)
  224. SAVE_BAT(2, 0x28)
  225. SAVE_BAT(3, 0x2c)
  226. SAVE_BAT(4, 0x30)
  227. SAVE_BAT(5, 0x34)
  228. SAVE_BAT(6, 0x38)
  229. SAVE_BAT(7, 0x3c)
  230. SAVE_4SR(0, 0x40)
  231. SAVE_4SR(4, 0x44)
  232. SAVE_4SR(8, 0x48)
  233. SAVE_4SR(12, 0x4c)
  234. SAVE_SPRN(SPRG0, 0x50)
  235. SAVE_SPRN(SPRG1, 0x51)
  236. SAVE_SPRN(SPRG2, 0x52)
  237. SAVE_SPRN(SPRG3, 0x53)
  238. SAVE_SPRN(SPRG4, 0x54)
  239. SAVE_SPRN(SPRG5, 0x55)
  240. SAVE_SPRN(SPRG6, 0x56)
  241. SAVE_SPRN(SPRG7, 0x57)
  242. SAVE_SPRN(IABR, 0x58)
  243. SAVE_SPRN(DABR, 0x59)
  244. SAVE_SPRN(TBRL, 0x5a)
  245. SAVE_SPRN(TBRU, 0x5b)
  246. blr
  247. /* restore registers */
  248. #define LOAD_BAT(n, addr) \
  249. LOAD_SPRN(DBAT##n##L, addr); \
  250. LOAD_SPRN(DBAT##n##U, addr+1); \
  251. LOAD_SPRN(IBAT##n##L, addr+2); \
  252. LOAD_SPRN(IBAT##n##U, addr+3);
  253. #define LOAD_SR(n, addr) \
  254. lwz r10, ((addr)*4)(r4); \
  255. mtsr n, r10;
  256. #define LOAD_4SR(n, addr) \
  257. LOAD_SR(n, addr); \
  258. LOAD_SR(n+1, addr+1); \
  259. LOAD_SR(n+2, addr+2); \
  260. LOAD_SR(n+3, addr+3);
  261. restore_regs:
  262. lis r4, registers@h
  263. ori r4, r4, registers@l
  264. /* MMU is not up yet */
  265. subis r4, r4, CONFIG_KERNEL_START@h
  266. lwz r0, 0(r4)
  267. lwz r1, 0x4(r4)
  268. lwz r2, 0x8(r4)
  269. lmw r11, 0xc(r4)
  270. /*
  271. * these are a bit tricky
  272. *
  273. * 0x18 - HID0
  274. * 0x19 - HID1
  275. * 0x1a - HID2
  276. * 0x1b - MSR
  277. * 0x1c - LR
  278. * 0x1d - reserved by 0xf0 (BDI2000)
  279. */
  280. LOAD_SPRN(RPA, 0x1e);
  281. LOAD_SPRN(SDR1, 0x1f);
  282. /* restore MMU regs */
  283. LOAD_BAT(0, 0x20)
  284. LOAD_BAT(1, 0x24)
  285. LOAD_BAT(2, 0x28)
  286. LOAD_BAT(3, 0x2c)
  287. LOAD_BAT(4, 0x30)
  288. LOAD_BAT(5, 0x34)
  289. LOAD_BAT(6, 0x38)
  290. LOAD_BAT(7, 0x3c)
  291. LOAD_4SR(0, 0x40)
  292. LOAD_4SR(4, 0x44)
  293. LOAD_4SR(8, 0x48)
  294. LOAD_4SR(12, 0x4c)
  295. /* rest of regs */
  296. LOAD_SPRN(SPRG0, 0x50);
  297. LOAD_SPRN(SPRG1, 0x51);
  298. LOAD_SPRN(SPRG2, 0x52);
  299. LOAD_SPRN(SPRG3, 0x53);
  300. LOAD_SPRN(SPRG4, 0x54);
  301. LOAD_SPRN(SPRG5, 0x55);
  302. LOAD_SPRN(SPRG6, 0x56);
  303. LOAD_SPRN(SPRG7, 0x57);
  304. LOAD_SPRN(IABR, 0x58);
  305. LOAD_SPRN(DABR, 0x59);
  306. LOAD_SPRN(TBWL, 0x5a); /* these two have separate R/W regs */
  307. LOAD_SPRN(TBWU, 0x5b);
  308. blr
  309. /* cache flushing code. copied from arch/ppc/boot/util.S */
  310. #define NUM_CACHE_LINES (128*8)
  311. /*
  312. * Flush data cache
  313. * Do this by just reading lots of stuff into the cache.
  314. */
  315. flush_data_cache:
  316. lis r3,CONFIG_KERNEL_START@h
  317. ori r3,r3,CONFIG_KERNEL_START@l
  318. li r4,NUM_CACHE_LINES
  319. mtctr r4
  320. 1:
  321. lwz r4,0(r3)
  322. addi r3,r3,L1_CACHE_BYTES /* Next line, please */
  323. bdnz 1b
  324. blr