1 /* SPDX-License-Identifier: GPL-2.0 */
3 #include <asm/ppc_asm.h>
4 #include <asm/processor.h>
8 #define SDRAM_CTRL 0x104
9 #define SC_MODE_EN (1<<31)
10 #define SC_CKE (1<<30)
11 #define SC_REF_EN (1<<28)
12 #define SC_SOFT_PRE (1<<1)
14 #define GPIOW_GPIOE 0xc00
15 #define GPIOW_DDR 0xc08
16 #define GPIOW_DVO 0xc0c
19 #define CDM_SDRAM (1<<3)
22 /* helpers... beware: r10 and r4 are overwritten */
23 #define SAVE_SPRN(reg, addr) \
24 mfspr r10, SPRN_##reg; \
25 stw r10, ((addr)*4)(r4);
27 #define LOAD_SPRN(reg, addr) \
28 lwz r10, ((addr)*4)(r4); \
29 mtspr SPRN_##reg, r10; \
39 /* ---------------------------------------------------------------------- */
40 /* low-power mode with help of M68HLC908QT1 */
42 .globl lite5200_low_power
45 mr r7, r3 /* save SRAM va */
46 mr r8, r4 /* save MBAR va */
48 /* setup wakeup address for u-boot at physical location 0x0 */
49 lis r3, CONFIG_KERNEL_START@h
50 lis r4, lite5200_wakeup@h
51 ori r4, r4, lite5200_wakeup@l
57 * save stuff BDI overwrites
58 * 0xf0 (0xe0->0x100 gets overwritten when BDI connected;
59 * even when CONFIG_BDI* is disabled and MMU XLAT commented; heisenbug?))
60 * WARNING: self-refresh doesn't seem to work when BDI2000 is connected,
61 * possibly because BDI sets SDRAM registers before wakeup code does
64 ori r4, r4, registers@l
68 /* save registers to r4 [destroys r10] */
72 /* flush caches [destroys r3, r4] */
76 /* copy code to sram */
78 li r3, (sram_code_end - sram_code)/4
81 ori r3, r3, sram_code@l
89 /* get tb_ticks_per_usec */
90 lis r3, tb_ticks_per_usec@h
91 lwz r11, tb_ticks_per_usec@l(r3)
93 /* disable I and D caches */
95 ori r3, r3, HID0_ICE | HID0_DCE
96 xori r3, r3, HID0_ICE | HID0_DCE
109 lwz r4, SDRAM_CTRL(r8)
111 /* send NOP (precharge) */
112 oris r4, r4, SC_MODE_EN@h /* mode_en */
113 stw r4, SDRAM_CTRL(r8)
116 ori r4, r4, SC_SOFT_PRE /* soft_pre */
117 stw r4, SDRAM_CTRL(r8)
119 xori r4, r4, SC_SOFT_PRE
121 xoris r4, r4, SC_MODE_EN@h /* !mode_en */
122 stw r4, SDRAM_CTRL(r8)
125 /* delay (for NOP to finish) */
130 * mode_en must not be set when enabling self-refresh
131 * send AR with CKE low (self-refresh)
133 oris r4, r4, (SC_REF_EN | SC_CKE)@h
134 xoris r4, r4, (SC_CKE)@h /* ref_en !cke */
135 stw r4, SDRAM_CTRL(r8)
138 /* delay (after !CKE there should be two cycles) */
144 ori r4, r4, CDM_SDRAM
145 xori r4, r4, CDM_SDRAM
154 /* turn off with QT chip */
156 stb r4, GPIOW_GPIOE(r8) /* enable gpio_wkup1 */
159 stb r4, GPIOW_DVO(r8) /* "output" high */
161 stb r4, GPIOW_DDR(r8) /* output */
163 stb r4, GPIOW_DVO(r8) /* output high */
172 stb r4, GPIOW_DVO(r8) /* output low */
175 /* wait until we're offline */
180 /* local udelay in sram is needed */
181 udelay: /* r11 - tb_ticks_per_usec, r12 - usecs, overwrites r13 */
184 addi r12, r13, r12 /* end */
186 mftb r13 /* current */
195 /* uboot jumps here on resume */
201 LOAD_SPRN(HID1, 0x19)
202 LOAD_SPRN(HID2, 0x1a)
205 /* address translation is tricky (see turn_on_mmu) */
207 ori r10, r10, MSR_DR | MSR_IR
212 ori r10, r10, mmu_on@l
217 /* kernel offset (r4 is still set from restore_registers) */
218 addis r4, r4, CONFIG_KERNEL_START@h
222 lwz r10, (4*0x1b)(r4)
226 /* invalidate caches */
228 ori r5, r10, HID0_ICFI | HID0_DCI
229 mtspr SPRN_HID0, r5 /* invalidate caches */
235 lwz r10, (4*0x18)(r4)
236 mtspr SPRN_HID0, r10 /* restore (enable caches, DPM) */
237 /* ^ this has to be after address translation set in MSR */
242 /* restore 0xf0 (BDI2000) */
243 lis r3, CONFIG_KERNEL_START@h
244 lwz r10, (0x1d*4)(r4)
253 /* ---------------------------------------------------------------------- */
254 /* boring code: helpers */
257 #define SAVE_BAT(n, addr) \
258 SAVE_SPRN(DBAT##n##L, addr); \
259 SAVE_SPRN(DBAT##n##U, addr+1); \
260 SAVE_SPRN(IBAT##n##L, addr+2); \
261 SAVE_SPRN(IBAT##n##U, addr+3);
263 #define SAVE_SR(n, addr) \
265 stw r10, ((addr)*4)(r4);
267 #define SAVE_4SR(n, addr) \
269 SAVE_SR(n+1, addr+1); \
270 SAVE_SR(n+2, addr+2); \
271 SAVE_SR(n+3, addr+3);
277 stmw r11, 0xc(r4) /* 0xc -> 0x5f, (0x18*4-1) */
279 SAVE_SPRN(HID0, 0x18)
280 SAVE_SPRN(HID1, 0x19)
281 SAVE_SPRN(HID2, 0x1a)
283 stw r10, (4*0x1b)(r4)
284 /*SAVE_SPRN(LR, 0x1c) have to save it before the call */
285 /* 0x1d reserved by 0xf0 */
287 SAVE_SPRN(SDR1, 0x1f)
304 SAVE_SPRN(SPRG0, 0x50)
305 SAVE_SPRN(SPRG1, 0x51)
306 SAVE_SPRN(SPRG2, 0x52)
307 SAVE_SPRN(SPRG3, 0x53)
308 SAVE_SPRN(SPRG4, 0x54)
309 SAVE_SPRN(SPRG5, 0x55)
310 SAVE_SPRN(SPRG6, 0x56)
311 SAVE_SPRN(SPRG7, 0x57)
313 SAVE_SPRN(IABR, 0x58)
314 SAVE_SPRN(DABR, 0x59)
315 SAVE_SPRN(TBRL, 0x5a)
316 SAVE_SPRN(TBRU, 0x5b)
321 /* restore registers */
322 #define LOAD_BAT(n, addr) \
323 LOAD_SPRN(DBAT##n##L, addr); \
324 LOAD_SPRN(DBAT##n##U, addr+1); \
325 LOAD_SPRN(IBAT##n##L, addr+2); \
326 LOAD_SPRN(IBAT##n##U, addr+3);
328 #define LOAD_SR(n, addr) \
329 lwz r10, ((addr)*4)(r4); \
332 #define LOAD_4SR(n, addr) \
334 LOAD_SR(n+1, addr+1); \
335 LOAD_SR(n+2, addr+2); \
336 LOAD_SR(n+3, addr+3);
340 ori r4, r4, registers@l
342 /* MMU is not up yet */
343 subis r4, r4, CONFIG_KERNEL_START@h
351 * these are a bit tricky
358 * 0x1d - reserved by 0xf0 (BDI2000)
360 LOAD_SPRN(RPA, 0x1e);
361 LOAD_SPRN(SDR1, 0x1f);
363 /* restore MMU regs */
379 LOAD_SPRN(SPRG0, 0x50);
380 LOAD_SPRN(SPRG1, 0x51);
381 LOAD_SPRN(SPRG2, 0x52);
382 LOAD_SPRN(SPRG3, 0x53);
383 LOAD_SPRN(SPRG4, 0x54);
384 LOAD_SPRN(SPRG5, 0x55);
385 LOAD_SPRN(SPRG6, 0x56);
386 LOAD_SPRN(SPRG7, 0x57);
388 LOAD_SPRN(IABR, 0x58);
389 LOAD_SPRN(DABR, 0x59);
390 LOAD_SPRN(TBWL, 0x5a); /* these two have separate R/W regs */
391 LOAD_SPRN(TBWU, 0x5b);
397 /* cache flushing code. copied from arch/ppc/boot/util.S */
398 #define NUM_CACHE_LINES (128*8)
402 * Do this by just reading lots of stuff into the cache.
405 lis r3,CONFIG_KERNEL_START@h
406 ori r3,r3,CONFIG_KERNEL_START@l
407 li r4,NUM_CACHE_LINES
411 addi r3,r3,L1_CACHE_BYTES /* Next line, please */