Pull acpi_bus_register_driver into release branch
[pandora-kernel.git] / 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/config.h>
28 #include <linux/linkage.h>
29 #include <asm/assembler.h>
30 #include <asm/hardware.h>
31 #include <asm/arch/map.h>
32
33 #include <asm/arch/regs-gpio.h>
34 #include <asm/arch/regs-clock.h>
35 #include <asm/arch/regs-mem.h>
36 #include <asm/arch/regs-serial.h>
37
38 /* CONFIG_DEBUG_RESUME is dangerous if your bootloader does not
39  * reset the UART configuration, only enable if you really need this!
40 */
41 //#define CONFIG_DEBUG_RESUME
42
43         .text
44
45         /* s3c2410_cpu_suspend
46          *
47          * put the cpu into sleep mode
48          *
49          * entry:
50          *      r0 = sleep save block
51         */
52
53 ENTRY(s3c2410_cpu_suspend)
54         stmfd   sp!, { r4 - r12, lr }
55
56         @@ store co-processor registers
57
58         mrc     p15, 0, r4, c15, c1, 0  @ CP access register
59         mrc     p15, 0, r5, c13, c0, 0  @ PID
60         mrc     p15, 0, r6, c3, c0, 0   @ Domain ID
61         mrc     p15, 0, r7, c2, c0, 0   @ translation table base address
62         mrc     p15, 0, r8, c1, c0, 0   @ control register
63
64         stmia   r0, { r4 - r13 }
65
66         @@ flush the caches to ensure everything is back out to
67         @@ SDRAM before the core powers down
68
69         bl      arm920_flush_kern_cache_all
70
71         @@ prepare cpu to sleep
72
73         ldr     r4, =S3C2410_REFRESH
74         ldr     r5, =S3C24XX_MISCCR
75         ldr     r6, =S3C2410_CLKCON
76         ldr     r7, [ r4 ]              @ get REFRESH (and ensure in TLB)
77         ldr     r8, [ r5 ]              @ get MISCCR (and ensure in TLB)
78         ldr     r9, [ r6 ]              @ get CLKCON (and ensure in TLB)
79
80         orr     r7, r7, #S3C2410_REFRESH_SELF   @ SDRAM sleep command
81         orr     r8, r8, #S3C2410_MISCCR_SDSLEEP @ SDRAM power-down signals
82         orr     r9, r9, #S3C2410_CLKCON_POWER   @ power down command
83
84         teq     pc, #0                  @ first as a trial-run to load cache
85         bl      s3c2410_do_sleep
86         teq     r0, r0                  @ now do it for real
87         b       s3c2410_do_sleep        @
88
89         @@ align next bit of code to cache line
90         .align  8
91 s3c2410_do_sleep:
92         streq   r7, [ r4 ]                      @ SDRAM sleep command
93         streq   r8, [ r5 ]                      @ SDRAM power-down config
94         streq   r9, [ r6 ]                      @ CPU sleep
95 1:      beq     1b
96         mov     pc, r14
97
98         @@ return to the caller, after having the MMU
99         @@ turned on, this restores the last bits from the
100         @@ stack
101 resume_with_mmu:
102         ldmfd   sp!, { r4 - r12, pc }
103
104         .ltorg
105
106         @@ the next bits sit in the .data segment, even though they
107         @@ happen to be code... the s3c2410_sleep_save_phys needs to be
108         @@ accessed by the resume code before it can restore the MMU.
109         @@ This means that the variable has to be close enough for the
110         @@ code to read it... since the .text segment needs to be RO,
111         @@ the data segment can be the only place to put this code.
112
113         .data
114
115         .global s3c2410_sleep_save_phys
116 s3c2410_sleep_save_phys:
117         .word   0
118
119         /* s3c2410_cpu_resume
120          *
121          * resume code entry for bootloader to call
122          *
123          * we must put this code here in the data segment as we have no
124          * other way of restoring the stack pointer after sleep, and we
125          * must not write to the code segment (code is read-only)
126         */
127
128 ENTRY(s3c2410_cpu_resume)
129         mov     r0, #PSR_I_BIT | PSR_F_BIT | MODE_SVC
130         msr     cpsr_c, r0
131
132         @@ load UART to allow us to print the two characters for
133         @@ resume debug
134
135         mov     r2, #S3C24XX_PA_UART & 0xff000000
136         orr     r2, r2, #S3C24XX_PA_UART & 0xff000
137
138 #if 0
139         /* SMDK2440 LED set */
140         mov     r14, #S3C24XX_PA_GPIO
141         ldr     r12, [ r14, #0x54 ]
142         bic     r12, r12, #3<<4
143         orr     r12, r12, #1<<7
144         str     r12, [ r14, #0x54 ]
145 #endif
146
147 #ifdef CONFIG_DEBUG_RESUME
148         mov     r3, #'L'
149         strb    r3, [ r2, #S3C2410_UTXH ]
150 1001:
151         ldrb    r14, [ r3, #S3C2410_UTRSTAT ]
152         tst     r14, #S3C2410_UTRSTAT_TXE
153         beq     1001b
154 #endif /* CONFIG_DEBUG_RESUME */
155
156         mov     r1, #0
157         mcr     p15, 0, r1, c8, c7, 0           @@ invalidate I & D TLBs
158         mcr     p15, 0, r1, c7, c7, 0           @@ invalidate I & D caches
159
160         ldr     r0, s3c2410_sleep_save_phys     @ address of restore block
161         ldmia   r0, { r4 - r13 }
162
163         mcr     p15, 0, r4, c15, c1, 0          @ CP access register
164         mcr     p15, 0, r5, c13, c0, 0          @ PID
165         mcr     p15, 0, r6, c3, c0, 0           @ Domain ID
166         mcr     p15, 0, r7, c2, c0, 0           @ translation table base
167
168 #ifdef CONFIG_DEBUG_RESUME
169         mov     r3, #'R'
170         strb    r3, [ r2, #S3C2410_UTXH ]
171 #endif
172
173         ldr     r2, =resume_with_mmu
174         mcr     p15, 0, r8, c1, c0, 0           @ turn on MMU, etc
175         nop                                     @ second-to-last before mmu
176         mov     pc, r2                          @ go back to virtual address
177
178         .ltorg