| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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_suspend | 
 | 45 | 	 * | 
 | 46 | 	 * put the cpu into sleep mode | 
 | 47 | 	 * | 
 | 48 | 	 * entry: | 
 | 49 | 	 *	r0 = sleep save block | 
 | 50 | 	*/ | 
 | 51 |  | 
 | 52 | ENTRY(s3c2410_cpu_suspend) | 
 | 53 | 	stmfd	sp!, { r4 - r12, lr } | 
 | 54 |  | 
 | 55 | 	@@ store co-processor registers | 
 | 56 |  | 
 | 57 | 	mrc	p15, 0, r4, c15, c1, 0	@ CP access register | 
 | 58 | 	mrc	p15, 0, r5, c13, c0, 0	@ PID | 
 | 59 | 	mrc	p15, 0, r6, c3, c0, 0	@ Domain ID | 
 | 60 | 	mrc	p15, 0, r7, c2, c0, 0	@ translation table base address | 
| Dimitry Andric | c3fb041 | 2006-05-17 16:31:11 +0100 | [diff] [blame] | 61 | 	mrc	p15, 0, r8, c1, c0, 0	@ control register | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 |  | 
 | 63 | 	stmia	r0, { r4 - r13 } | 
 | 64 |  | 
 | 65 | 	@@ flush the caches to ensure everything is back out to | 
 | 66 | 	@@ SDRAM before the core powers down | 
 | 67 |  | 
| Ben Dooks | 4833acb | 2006-06-18 16:21:51 +0100 | [diff] [blame] | 68 | #ifndef CONFIG_CPU_DCACHE_WRITETHROUGH | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | 	bl	arm920_flush_kern_cache_all | 
| Ben Dooks | 4833acb | 2006-06-18 16:21:51 +0100 | [diff] [blame] | 70 | #endif | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 |  | 
 | 72 | 	@@ prepare cpu to sleep | 
 | 73 |  | 
 | 74 | 	ldr	r4, =S3C2410_REFRESH | 
| Lucas Correia Villa Real | 0ca5bc3 | 2006-02-01 21:24:23 +0000 | [diff] [blame] | 75 | 	ldr	r5, =S3C24XX_MISCCR | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | 	ldr	r6, =S3C2410_CLKCON | 
 | 77 | 	ldr	r7, [ r4 ]		@ get REFRESH (and ensure in TLB) | 
 | 78 | 	ldr	r8, [ r5 ]		@ get MISCCR (and ensure in TLB) | 
 | 79 | 	ldr	r9, [ r6 ]		@ get CLKCON (and ensure in TLB) | 
 | 80 |  | 
 | 81 | 	orr	r7, r7, #S3C2410_REFRESH_SELF	@ SDRAM sleep command | 
 | 82 | 	orr	r8, r8, #S3C2410_MISCCR_SDSLEEP @ SDRAM power-down signals | 
 | 83 | 	orr	r9, r9, #S3C2410_CLKCON_POWER	@ power down command | 
 | 84 |  | 
 | 85 | 	teq	pc, #0			@ first as a trial-run to load cache | 
 | 86 | 	bl	s3c2410_do_sleep | 
 | 87 | 	teq	r0, r0			@ now do it for real | 
 | 88 | 	b	s3c2410_do_sleep	@ | 
 | 89 |  | 
 | 90 | 	@@ align next bit of code to cache line | 
 | 91 | 	.align	8 | 
 | 92 | s3c2410_do_sleep: | 
 | 93 | 	streq	r7, [ r4 ]			@ SDRAM sleep command | 
 | 94 | 	streq	r8, [ r5 ]			@ SDRAM power-down config | 
 | 95 | 	streq	r9, [ r6 ]			@ CPU sleep | 
 | 96 | 1:	beq	1b | 
 | 97 | 	mov	pc, r14 | 
 | 98 |  | 
 | 99 | 	@@ return to the caller, after having the MMU | 
 | 100 | 	@@ turned on, this restores the last bits from the | 
 | 101 | 	@@ stack | 
 | 102 | resume_with_mmu: | 
 | 103 | 	ldmfd	sp!, { r4 - r12, pc } | 
 | 104 |  | 
 | 105 | 	.ltorg | 
 | 106 |  | 
 | 107 | 	@@ the next bits sit in the .data segment, even though they | 
 | 108 | 	@@ happen to be code... the s3c2410_sleep_save_phys needs to be | 
 | 109 | 	@@ accessed by the resume code before it can restore the MMU. | 
 | 110 | 	@@ This means that the variable has to be close enough for the | 
 | 111 | 	@@ code to read it... since the .text segment needs to be RO, | 
 | 112 | 	@@ the data segment can be the only place to put this code. | 
 | 113 |  | 
 | 114 | 	.data | 
 | 115 |  | 
 | 116 | 	.global	s3c2410_sleep_save_phys | 
 | 117 | s3c2410_sleep_save_phys: | 
 | 118 | 	.word	0 | 
 | 119 |  | 
 | 120 | 	/* s3c2410_cpu_resume | 
 | 121 | 	 * | 
 | 122 | 	 * resume code entry for bootloader to call | 
 | 123 | 	 * | 
 | 124 | 	 * we must put this code here in the data segment as we have no | 
 | 125 | 	 * other way of restoring the stack pointer after sleep, and we | 
 | 126 | 	 * must not write to the code segment (code is read-only) | 
 | 127 | 	*/ | 
 | 128 |  | 
 | 129 | ENTRY(s3c2410_cpu_resume) | 
| Russell King | 801194e | 2006-06-25 12:01:48 +0100 | [diff] [blame] | 130 | 	mov	r0, #PSR_I_BIT | PSR_F_BIT | SVC_MODE | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | 	msr	cpsr_c, r0 | 
 | 132 |  | 
 | 133 | 	@@ load UART to allow us to print the two characters for | 
 | 134 | 	@@ resume debug | 
 | 135 |  | 
| Lucas Correia Villa Real | 0367a8d | 2006-01-26 15:20:50 +0000 | [diff] [blame] | 136 | 	mov	r2, #S3C24XX_PA_UART & 0xff000000 | 
 | 137 | 	orr	r2, r2, #S3C24XX_PA_UART & 0xff000 | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 |  | 
 | 139 | #if 0 | 
 | 140 | 	/* SMDK2440 LED set */ | 
| Lucas Correia Villa Real | 0367a8d | 2006-01-26 15:20:50 +0000 | [diff] [blame] | 141 | 	mov	r14, #S3C24XX_PA_GPIO | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | 	ldr	r12, [ r14, #0x54 ] | 
 | 143 | 	bic	r12, r12, #3<<4 | 
 | 144 | 	orr	r12, r12, #1<<7 | 
 | 145 | 	str	r12, [ r14, #0x54 ] | 
 | 146 | #endif | 
 | 147 |  | 
 | 148 | #ifdef CONFIG_DEBUG_RESUME | 
 | 149 | 	mov	r3, #'L' | 
 | 150 | 	strb	r3, [ r2, #S3C2410_UTXH ] | 
 | 151 | 1001: | 
 | 152 | 	ldrb	r14, [ r3, #S3C2410_UTRSTAT ] | 
 | 153 | 	tst	r14, #S3C2410_UTRSTAT_TXE | 
 | 154 | 	beq	1001b | 
 | 155 | #endif /* CONFIG_DEBUG_RESUME */ | 
 | 156 |  | 
 | 157 | 	mov	r1, #0 | 
 | 158 | 	mcr	p15, 0, r1, c8, c7, 0		@@ invalidate I & D TLBs | 
 | 159 | 	mcr	p15, 0, r1, c7, c7, 0		@@ invalidate I & D caches | 
 | 160 |  | 
 | 161 | 	ldr	r0, s3c2410_sleep_save_phys	@ address of restore block | 
 | 162 | 	ldmia	r0, { r4 - r13 } | 
 | 163 |  | 
 | 164 | 	mcr	p15, 0, r4, c15, c1, 0		@ CP access register | 
 | 165 | 	mcr	p15, 0, r5, c13, c0, 0		@ PID | 
 | 166 | 	mcr	p15, 0, r6, c3, c0, 0		@ Domain ID | 
 | 167 | 	mcr	p15, 0, r7, c2, c0, 0		@ translation table base | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 |  | 
 | 169 | #ifdef CONFIG_DEBUG_RESUME | 
 | 170 | 	mov	r3, #'R' | 
 | 171 | 	strb	r3, [ r2, #S3C2410_UTXH ] | 
 | 172 | #endif | 
 | 173 |  | 
 | 174 | 	ldr	r2, =resume_with_mmu | 
| Dimitry Andric | c3fb041 | 2006-05-17 16:31:11 +0100 | [diff] [blame] | 175 | 	mcr	p15, 0, r8, c1, c0, 0		@ turn on MMU, etc | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | 	nop					@ second-to-last before mmu | 
 | 177 | 	mov	pc, r2				@ go back to virtual address | 
 | 178 |  | 
 | 179 | 	.ltorg |