http://downloads.netgear.com/files/GPL/GPL_Source_V361j_DM111PSP_series_consumer_rele...
[bcm963xx.git] / kernel / linux / arch / arm / mach-pxa / sleep.S
1 /*
2  * Low-level PXA250/210 sleep/wakeUp support
3  *
4  * Initial SA1110 code:
5  * Copyright (c) 2001 Cliff Brake <cbrake@accelent.com>
6  *
7  * Adapted for PXA by Nicolas Pitre:
8  * Copyright (c) 2002 Monta Vista Software, Inc.
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License.
12  */
13
14 #include <linux/config.h>
15 #include <linux/linkage.h>
16 #include <asm/assembler.h>
17 #include <asm/hardware.h>
18
19                 .text
20
21 /*
22  * pxa_cpu_suspend()
23  *
24  * Forces CPU into sleep state
25  */
26
27 ENTRY(pxa_cpu_suspend)
28
29         mra     r2, r3, acc0
30         stmfd   sp!, {r2 - r12, lr}             @ save registers on stack
31
32         @ get coprocessor registers
33         mrc     p15, 0, r4, c15, c1, 0          @ CP access reg
34         mrc     p15, 0, r5, c13, c0, 0          @ PID
35         mrc     p15, 0, r6, c3, c0, 0           @ domain ID
36         mrc     p15, 0, r7, c2, c0, 0           @ translation table base addr
37         mrc     p15, 0, r8, c1, c1, 0           @ auxiliary control reg
38         mrc     p15, 0, r9, c1, c0, 0           @ control reg
39
40         @ store them plus current virtual stack ptr on stack
41         mov     r10, sp
42         stmfd   sp!, {r4 - r10}
43
44         @ preserve phys address of stack
45         mov     r0, sp
46         bl      sleep_phys_sp
47         ldr     r1, =sleep_save_sp
48         str     r0, [r1]
49
50         @ clean data cache
51         bl      xscale_flush_kern_cache_all
52
53         @ Put the processor to sleep
54         @ (also workaround for sighting 28071)
55
56         @ prepare value for sleep mode
57         mov     r1, #3                          @ sleep mode
58
59         @ prepare to put SDRAM into self-refresh manually
60         ldr     r4, =MDREFR
61         ldr     r5, [r4]
62         orr     r5, r5, #MDREFR_SLFRSH
63
64         @ prepare pointer to physical address 0 (virtual mapping in generic.c)
65         mov     r2, #UNCACHED_PHYS_0
66
67         @ align execution to a cache line
68         b       1f
69
70         .ltorg
71         .align  5
72 1:
73
74         @ All needed values are now in registers.
75         @ These last instructions should be in cache
76
77         @ put SDRAM into self-refresh
78         str     r5, [r4]
79
80         @ force address lines low by reading at physical address 0
81         ldr     r3, [r2]
82
83         @ enter sleep mode
84         mcr     p14, 0, r1, c7, c0, 0
85
86 20:     nop
87         b       20b                             @ loop waiting for sleep
88
89 /*
90  * cpu_pxa_resume()
91  *
92  * entry point from bootloader into kernel during resume
93  *
94  * Note: Yes, part of the following code is located into the .data section.
95  *       This is to allow sleep_save_sp to be accessed with a relative load
96  *       while we can't rely on any MMU translation.  We could have put
97  *       sleep_save_sp in the .text section as well, but some setups might
98  *       insist on it to be truly read-only.
99  */
100
101         .data
102         .align 5
103 ENTRY(pxa_cpu_resume)
104         mov     r0, #PSR_I_BIT | PSR_F_BIT | MODE_SVC   @ set SVC, irqs off
105         msr     cpsr_c, r0
106
107         ldr     r0, sleep_save_sp               @ stack phys addr
108         ldr     r2, =resume_after_mmu           @ its absolute virtual address
109         ldmfd   r0, {r4 - r9, sp}               @ CP regs + virt stack ptr
110
111         mov     r1, #0
112         mcr     p15, 0, r1, c8, c7, 0           @ invalidate I & D TLBs
113         mcr     p15, 0, r1, c7, c7, 0           @ invalidate I & D caches, BTB
114
115 #ifdef CONFIG_XSCALE_CACHE_ERRATA
116         bic     r9, r9, #0x0004                 @ see cpu_xscale_proc_init
117 #endif
118
119         mcr     p15, 0, r4, c15, c1, 0          @ CP access reg
120         mcr     p15, 0, r5, c13, c0, 0          @ PID
121         mcr     p15, 0, r6, c3, c0, 0           @ domain ID
122         mcr     p15, 0, r7, c2, c0, 0           @ translation table base addr
123         mcr     p15, 0, r8, c1, c1, 0           @ auxiliary control reg
124         b       resume_turn_on_mmu              @ cache align execution
125
126         .align 5
127 resume_turn_on_mmu:
128         mcr     p15, 0, r9, c1, c0, 0           @ turn on MMU, caches, etc.
129
130         @ Let us ensure we jump to resume_after_mmu only when the mcr above
131         @ actually took effect.  They call it the "cpwait" operation.
132         mrc     p15, 0, r1, c2, c0, 0           @ queue a dependency on CP15
133         sub     pc, r2, r1, lsr #32             @ jump to virtual addr
134         nop
135         nop
136         nop
137
138 sleep_save_sp:
139         .word   0                               @ preserve stack phys ptr here
140
141         .text
142 resume_after_mmu:
143 #ifdef CONFIG_XSCALE_CACHE_ERRATA
144         bl      cpu_xscale_proc_init
145 #endif
146         ldmfd   sp!, {r2, r3}
147         mar     acc0, r2, r3
148         ldmfd   sp!, {r4 - r12, pc}             @ return to caller
149
150