2 #include <asm/ppc_asm.h>
3 #include <asm/processor.h>
7 #define SDRAM_CTRL 0x104
8 #define SC_MODE_EN (1<<31)
10 #define SC_REF_EN (1<<28)
11 #define SC_SOFT_PRE (1<<1)
13 #define GPIOW_GPIOE 0xc00
14 #define GPIOW_DDR 0xc08
15 #define GPIOW_DVO 0xc0c
18 #define CDM_SDRAM (1<<3)
21 /* helpers... beware: r10 and r4 are overwritten */
22 #define SAVE_SPRN(reg, addr) \
23 mfspr r10, SPRN_##reg; \
24 stw r10, ((addr)*4)(r4);
26 #define LOAD_SPRN(reg, addr) \
27 lwz r10, ((addr)*4)(r4); \
28 mtspr SPRN_##reg, r10; \
38 /* ---------------------------------------------------------------------- */
39 /* low-power mode with help of M68HLC908QT1 */
41 .globl lite5200_low_power
44 mr r7, r3 /* save SRAM va */
45 mr r8, r4 /* save MBAR va */
47 /* setup wakeup address for u-boot at physical location 0x0 */
48 lis r3, CONFIG_KERNEL_START@h
49 lis r4, lite5200_wakeup@h
50 ori r4, r4, lite5200_wakeup@l
56 * save stuff BDI overwrites
57 * 0xf0 (0xe0->0x100 gets overwritten when BDI connected;
58 * even when CONFIG_BDI* is disabled and MMU XLAT commented; heisenbug?))
59 * WARNING: self-refresh doesn't seem to work when BDI2000 is connected,
60 * possibly because BDI sets SDRAM registers before wakeup code does
63 ori r4, r4, registers@l
67 /* save registers to r4 [destroys r10] */
71 /* flush caches [destroys r3, r4] */
75 /* copy code to sram */
77 li r3, (sram_code_end - sram_code)/4
80 ori r3, r3, sram_code@l
88 /* get tb_ticks_per_usec */
89 lis r3, tb_ticks_per_usec@h
90 lwz r11, tb_ticks_per_usec@l(r3)
92 /* disable I and D caches */
94 ori r3, r3, HID0_ICE | HID0_DCE
95 xori r3, r3, HID0_ICE | HID0_DCE
108 lwz r4, SDRAM_CTRL(r8)
110 /* send NOP (precharge) */
111 oris r4, r4, SC_MODE_EN@h /* mode_en */
112 stw r4, SDRAM_CTRL(r8)
115 ori r4, r4, SC_SOFT_PRE /* soft_pre */
116 stw r4, SDRAM_CTRL(r8)
118 xori r4, r4, SC_SOFT_PRE
120 xoris r4, r4, SC_MODE_EN@h /* !mode_en */
121 stw r4, SDRAM_CTRL(r8)
124 /* delay (for NOP to finish) */
129 * mode_en must not be set when enabling self-refresh
130 * send AR with CKE low (self-refresh)
132 oris r4, r4, (SC_REF_EN | SC_CKE)@h
133 xoris r4, r4, (SC_CKE)@h /* ref_en !cke */
134 stw r4, SDRAM_CTRL(r8)
137 /* delay (after !CKE there should be two cycles) */
143 ori r4, r4, CDM_SDRAM
144 xori r4, r4, CDM_SDRAM
153 /* turn off with QT chip */
155 stb r4, GPIOW_GPIOE(r8) /* enable gpio_wkup1 */
158 stb r4, GPIOW_DVO(r8) /* "output" high */
160 stb r4, GPIOW_DDR(r8) /* output */
162 stb r4, GPIOW_DVO(r8) /* output high */
171 stb r4, GPIOW_DVO(r8) /* output low */
174 /* wait until we're offline */
179 /* local udelay in sram is needed */
180 udelay: /* r11 - tb_ticks_per_usec, r12 - usecs, overwrites r13 */
183 addi r12, r13, r12 /* end */
185 mftb r13 /* current */
194 /* uboot jumps here on resume */
200 LOAD_SPRN(HID1, 0x19)
201 LOAD_SPRN(HID2, 0x1a)
204 /* address translation is tricky (see turn_on_mmu) */
206 ori r10, r10, MSR_DR | MSR_IR
211 ori r10, r10, mmu_on@l
216 /* kernel offset (r4 is still set from restore_registers) */
217 addis r4, r4, CONFIG_KERNEL_START@h
221 lwz r10, (4*0x1b)(r4)
225 /* invalidate caches */
227 ori r5, r10, HID0_ICFI | HID0_DCI
228 mtspr SPRN_HID0, r5 /* invalidate caches */
234 lwz r10, (4*0x18)(r4)
235 mtspr SPRN_HID0, r10 /* restore (enable caches, DPM) */
236 /* ^ this has to be after address translation set in MSR */
241 /* restore 0xf0 (BDI2000) */
242 lis r3, CONFIG_KERNEL_START@h
243 lwz r10, (0x1d*4)(r4)
252 /* ---------------------------------------------------------------------- */
253 /* boring code: helpers */
256 #define SAVE_BAT(n, addr) \
257 SAVE_SPRN(DBAT##n##L, addr); \
258 SAVE_SPRN(DBAT##n##U, addr+1); \
259 SAVE_SPRN(IBAT##n##L, addr+2); \
260 SAVE_SPRN(IBAT##n##U, addr+3);
262 #define SAVE_SR(n, addr) \
264 stw r10, ((addr)*4)(r4);
266 #define SAVE_4SR(n, addr) \
268 SAVE_SR(n+1, addr+1); \
269 SAVE_SR(n+2, addr+2); \
270 SAVE_SR(n+3, addr+3);
276 stmw r11, 0xc(r4) /* 0xc -> 0x5f, (0x18*4-1) */
278 SAVE_SPRN(HID0, 0x18)
279 SAVE_SPRN(HID1, 0x19)
280 SAVE_SPRN(HID2, 0x1a)
282 stw r10, (4*0x1b)(r4)
283 /*SAVE_SPRN(LR, 0x1c) have to save it before the call */
284 /* 0x1d reserved by 0xf0 */
286 SAVE_SPRN(SDR1, 0x1f)
303 SAVE_SPRN(SPRG0, 0x50)
304 SAVE_SPRN(SPRG1, 0x51)
305 SAVE_SPRN(SPRG2, 0x52)
306 SAVE_SPRN(SPRG3, 0x53)
307 SAVE_SPRN(SPRG4, 0x54)
308 SAVE_SPRN(SPRG5, 0x55)
309 SAVE_SPRN(SPRG6, 0x56)
310 SAVE_SPRN(SPRG7, 0x57)
312 SAVE_SPRN(IABR, 0x58)
313 SAVE_SPRN(DABR, 0x59)
314 SAVE_SPRN(TBRL, 0x5a)
315 SAVE_SPRN(TBRU, 0x5b)
320 /* restore registers */
321 #define LOAD_BAT(n, addr) \
322 LOAD_SPRN(DBAT##n##L, addr); \
323 LOAD_SPRN(DBAT##n##U, addr+1); \
324 LOAD_SPRN(IBAT##n##L, addr+2); \
325 LOAD_SPRN(IBAT##n##U, addr+3);
327 #define LOAD_SR(n, addr) \
328 lwz r10, ((addr)*4)(r4); \
331 #define LOAD_4SR(n, addr) \
333 LOAD_SR(n+1, addr+1); \
334 LOAD_SR(n+2, addr+2); \
335 LOAD_SR(n+3, addr+3);
339 ori r4, r4, registers@l
341 /* MMU is not up yet */
342 subis r4, r4, CONFIG_KERNEL_START@h
350 * these are a bit tricky
357 * 0x1d - reserved by 0xf0 (BDI2000)
359 LOAD_SPRN(RPA, 0x1e);
360 LOAD_SPRN(SDR1, 0x1f);
362 /* restore MMU regs */
378 LOAD_SPRN(SPRG0, 0x50);
379 LOAD_SPRN(SPRG1, 0x51);
380 LOAD_SPRN(SPRG2, 0x52);
381 LOAD_SPRN(SPRG3, 0x53);
382 LOAD_SPRN(SPRG4, 0x54);
383 LOAD_SPRN(SPRG5, 0x55);
384 LOAD_SPRN(SPRG6, 0x56);
385 LOAD_SPRN(SPRG7, 0x57);
387 LOAD_SPRN(IABR, 0x58);
388 LOAD_SPRN(DABR, 0x59);
389 LOAD_SPRN(TBWL, 0x5a); /* these two have separate R/W regs */
390 LOAD_SPRN(TBWU, 0x5b);
396 /* cache flushing code. copied from arch/ppc/boot/util.S */
397 #define NUM_CACHE_LINES (128*8)
401 * Do this by just reading lots of stuff into the cache.
404 lis r3,CONFIG_KERNEL_START@h
405 ori r3,r3,CONFIG_KERNEL_START@l
406 li r4,NUM_CACHE_LINES
410 addi r3,r3,L1_CACHE_BYTES /* Next line, please */