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_SWITCH 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)
251 _ASM_NOKPROBE_SYMBOL(lite5200_wakeup)
254 /* ---------------------------------------------------------------------- */
255 /* boring code: helpers */
258 #define SAVE_BAT(n, addr) \
259 SAVE_SPRN(DBAT##n##L, addr); \
260 SAVE_SPRN(DBAT##n##U, addr+1); \
261 SAVE_SPRN(IBAT##n##L, addr+2); \
262 SAVE_SPRN(IBAT##n##U, addr+3);
264 #define SAVE_SR(n, addr) \
266 stw r10, ((addr)*4)(r4);
268 #define SAVE_4SR(n, addr) \
270 SAVE_SR(n+1, addr+1); \
271 SAVE_SR(n+2, addr+2); \
272 SAVE_SR(n+3, addr+3);
278 stmw r11, 0xc(r4) /* 0xc -> 0x5f, (0x18*4-1) */
280 SAVE_SPRN(HID0, 0x18)
281 SAVE_SPRN(HID1, 0x19)
282 SAVE_SPRN(HID2, 0x1a)
284 stw r10, (4*0x1b)(r4)
285 /*SAVE_SPRN(LR, 0x1c) have to save it before the call */
286 /* 0x1d reserved by 0xf0 */
288 SAVE_SPRN(SDR1, 0x1f)
305 SAVE_SPRN(SPRG0, 0x50)
306 SAVE_SPRN(SPRG1, 0x51)
307 SAVE_SPRN(SPRG2, 0x52)
308 SAVE_SPRN(SPRG3, 0x53)
309 SAVE_SPRN(SPRG4, 0x54)
310 SAVE_SPRN(SPRG5, 0x55)
311 SAVE_SPRN(SPRG6, 0x56)
312 SAVE_SPRN(SPRG7, 0x57)
314 SAVE_SPRN(IABR, 0x58)
315 SAVE_SPRN(DABR, 0x59)
316 SAVE_SPRN(TBRL, 0x5a)
317 SAVE_SPRN(TBRU, 0x5b)
322 /* restore registers */
323 #define LOAD_BAT(n, addr) \
324 LOAD_SPRN(DBAT##n##L, addr); \
325 LOAD_SPRN(DBAT##n##U, addr+1); \
326 LOAD_SPRN(IBAT##n##L, addr+2); \
327 LOAD_SPRN(IBAT##n##U, addr+3);
329 #define LOAD_SR(n, addr) \
330 lwz r10, ((addr)*4)(r4); \
333 #define LOAD_4SR(n, addr) \
335 LOAD_SR(n+1, addr+1); \
336 LOAD_SR(n+2, addr+2); \
337 LOAD_SR(n+3, addr+3);
341 ori r4, r4, registers@l
343 /* MMU is not up yet */
344 subis r4, r4, CONFIG_KERNEL_START@h
352 * these are a bit tricky
359 * 0x1d - reserved by 0xf0 (BDI2000)
361 LOAD_SPRN(RPA, 0x1e);
362 LOAD_SPRN(SDR1, 0x1f);
364 /* restore MMU regs */
380 LOAD_SPRN(SPRG0, 0x50);
381 LOAD_SPRN(SPRG1, 0x51);
382 LOAD_SPRN(SPRG2, 0x52);
383 LOAD_SPRN(SPRG3, 0x53);
384 LOAD_SPRN(SPRG4, 0x54);
385 LOAD_SPRN(SPRG5, 0x55);
386 LOAD_SPRN(SPRG6, 0x56);
387 LOAD_SPRN(SPRG7, 0x57);
389 LOAD_SPRN(IABR, 0x58);
390 LOAD_SPRN(DABR, 0x59);
391 LOAD_SPRN(TBWL, 0x5a); /* these two have separate R/W regs */
392 LOAD_SPRN(TBWU, 0x5b);
395 _ASM_NOKPROBE_SYMBOL(restore_regs)
399 /* cache flushing code. copied from arch/ppc/boot/util.S */
400 #define NUM_CACHE_LINES (128*8)
404 * Do this by just reading lots of stuff into the cache.
407 lis r3,CONFIG_KERNEL_START@h
408 ori r3,r3,CONFIG_KERNEL_START@l
409 li r4,NUM_CACHE_LINES
413 addi r3,r3,L1_CACHE_BYTES /* Next line, please */