]> Pileus Git - ~andy/linux/blob - arch/arm/mach-s3c2410/sleep.S
[ARM] 3802/1: S3C24XX: PM tidy up cache flushing
[~andy/linux] / arch / arm / mach-s3c2410 / sleep.S
1 /* linux/arch/arm/mach-s3c2410/sleep.S
2  *
3  * Copyright (c) 2004 Simtec Electronics
4  *      Ben Dooks <ben@simtec.co.uk>
5  *
6  * S3C2410 Power Manager (Suspend-To-RAM) support
7  *
8  * Based on PXA/SA1100 sleep code by:
9  *      Nicolas Pitre, (c) 2002 Monta Vista Software Inc
10  *      Cliff Brake, (c) 2001
11  *
12  * This program is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation; either version 2 of the License, or
15  * (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
25 */
26
27 #include <linux/linkage.h>
28 #include <asm/assembler.h>
29 #include <asm/hardware.h>
30 #include <asm/arch/map.h>
31
32 #include <asm/arch/regs-gpio.h>
33 #include <asm/arch/regs-clock.h>
34 #include <asm/arch/regs-mem.h>
35 #include <asm/arch/regs-serial.h>
36
37 /* CONFIG_DEBUG_RESUME is dangerous if your bootloader does not
38  * reset the UART configuration, only enable if you really need this!
39 */
40 //#define CONFIG_DEBUG_RESUME
41
42         .text
43
44         /* s3c2410_cpu_save
45          *
46          * save enough of the CPU state to allow us to re-start
47          * pm.c code. as we store items like the sp/lr, we will
48          * end up returning from this function when the cpu resumes
49          * so the return value is set to mark this.
50          *
51          * This arangement means we avoid having to flush the cache
52          * from this code.
53          *
54          * entry:
55          *      r0 = pointer to save block
56          *
57          * exit:
58          *      r0 = 0 => we stored everything
59          *           1 => resumed from sleep
60         */
61
62 ENTRY(s3c2410_cpu_save)
63         stmfd   sp!, { r4 - r12, lr }
64
65         @@ store co-processor registers
66
67         mrc     p15, 0, r4, c15, c1, 0  @ CP access register
68         mrc     p15, 0, r5, c13, c0, 0  @ PID
69         mrc     p15, 0, r6, c3, c0, 0   @ Domain ID
70         mrc     p15, 0, r7, c2, c0, 0   @ translation table base address
71         mrc     p15, 0, r8, c1, c0, 0   @ control register
72
73         stmia   r0, { r4 - r13 }
74
75         mov     r0, #0
76         ldmfd   sp, { r4 - r12, pc }
77
78         /* s3c2410_cpu_suspend
79          *
80          * put the cpu into sleep mode
81         */
82
83 ENTRY(s3c2410_cpu_suspend)
84         @@ prepare cpu to sleep
85
86         ldr     r4, =S3C2410_REFRESH
87         ldr     r5, =S3C24XX_MISCCR
88         ldr     r6, =S3C2410_CLKCON
89         ldr     r7, [ r4 ]              @ get REFRESH (and ensure in TLB)
90         ldr     r8, [ r5 ]              @ get MISCCR (and ensure in TLB)
91         ldr     r9, [ r6 ]              @ get CLKCON (and ensure in TLB)
92
93         orr     r7, r7, #S3C2410_REFRESH_SELF   @ SDRAM sleep command
94         orr     r8, r8, #S3C2410_MISCCR_SDSLEEP @ SDRAM power-down signals
95         orr     r9, r9, #S3C2410_CLKCON_POWER   @ power down command
96
97         teq     pc, #0                  @ first as a trial-run to load cache
98         bl      s3c2410_do_sleep
99         teq     r0, r0                  @ now do it for real
100         b       s3c2410_do_sleep        @
101
102         @@ align next bit of code to cache line
103         .align  8
104 s3c2410_do_sleep:
105         streq   r7, [ r4 ]                      @ SDRAM sleep command
106         streq   r8, [ r5 ]                      @ SDRAM power-down config
107         streq   r9, [ r6 ]                      @ CPU sleep
108 1:      beq     1b
109         mov     pc, r14
110
111         @@ return to the caller, after having the MMU
112         @@ turned on, this restores the last bits from the
113         @@ stack
114 resume_with_mmu:
115         mov     r0, #1
116         ldmfd   sp!, { r4 - r12, pc }
117
118         .ltorg
119
120         @@ the next bits sit in the .data segment, even though they
121         @@ happen to be code... the s3c2410_sleep_save_phys needs to be
122         @@ accessed by the resume code before it can restore the MMU.
123         @@ This means that the variable has to be close enough for the
124         @@ code to read it... since the .text segment needs to be RO,
125         @@ the data segment can be the only place to put this code.
126
127         .data
128
129         .global s3c2410_sleep_save_phys
130 s3c2410_sleep_save_phys:
131         .word   0
132
133         /* s3c2410_cpu_resume
134          *
135          * resume code entry for bootloader to call
136          *
137          * we must put this code here in the data segment as we have no
138          * other way of restoring the stack pointer after sleep, and we
139          * must not write to the code segment (code is read-only)
140         */
141
142 ENTRY(s3c2410_cpu_resume)
143         mov     r0, #PSR_I_BIT | PSR_F_BIT | SVC_MODE
144         msr     cpsr_c, r0
145
146         @@ load UART to allow us to print the two characters for
147         @@ resume debug
148
149         mov     r2, #S3C24XX_PA_UART & 0xff000000
150         orr     r2, r2, #S3C24XX_PA_UART & 0xff000
151
152 #if 0
153         /* SMDK2440 LED set */
154         mov     r14, #S3C24XX_PA_GPIO
155         ldr     r12, [ r14, #0x54 ]
156         bic     r12, r12, #3<<4
157         orr     r12, r12, #1<<7
158         str     r12, [ r14, #0x54 ]
159 #endif
160
161 #ifdef CONFIG_DEBUG_RESUME
162         mov     r3, #'L'
163         strb    r3, [ r2, #S3C2410_UTXH ]
164 1001:
165         ldrb    r14, [ r3, #S3C2410_UTRSTAT ]
166         tst     r14, #S3C2410_UTRSTAT_TXE
167         beq     1001b
168 #endif /* CONFIG_DEBUG_RESUME */
169
170         mov     r1, #0
171         mcr     p15, 0, r1, c8, c7, 0           @@ invalidate I & D TLBs
172         mcr     p15, 0, r1, c7, c7, 0           @@ invalidate I & D caches
173
174         ldr     r0, s3c2410_sleep_save_phys     @ address of restore block
175         ldmia   r0, { r4 - r13 }
176
177         mcr     p15, 0, r4, c15, c1, 0          @ CP access register
178         mcr     p15, 0, r5, c13, c0, 0          @ PID
179         mcr     p15, 0, r6, c3, c0, 0           @ Domain ID
180         mcr     p15, 0, r7, c2, c0, 0           @ translation table base
181
182 #ifdef CONFIG_DEBUG_RESUME
183         mov     r3, #'R'
184         strb    r3, [ r2, #S3C2410_UTXH ]
185 #endif
186
187         ldr     r2, =resume_with_mmu
188         mcr     p15, 0, r8, c1, c0, 0           @ turn on MMU, etc
189         nop                                     @ second-to-last before mmu
190         mov     pc, r2                          @ go back to virtual address
191
192         .ltorg