1 /* sleep.S: power saving mode entry
3 * Copyright (C) 2004 Red Hat, Inc. All Rights Reserved.
4 * Written by David Woodhouse (dwmw2@infradead.org)
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
13 #include <linux/sys.h>
14 #include <linux/linkage.h>
15 #include <asm/setup.h>
16 #include <asm/segment.h>
18 #include <asm/ptrace.h>
19 #include <asm/errno.h>
20 #include <asm/cache.h>
21 #include <asm/spr-regs.h>
23 #define __addr_MASK 0xfeff9820 /* interrupt controller mask */
25 #define __addr_FR55X_DRCN 0xfeff0218 /* Address of DRCN register */
26 #define FR55X_DSTS_OFFSET -4 /* Offset from DRCN to DSTS */
27 #define FR55X_SDRAMC_DSTS_SSI 0x00000002 /* indicates that the SDRAM is in self-refresh mode */
29 #define __addr_FR4XX_DRCN 0xfe000430 /* Address of DRCN register */
30 #define FR4XX_DSTS_OFFSET -8 /* Offset from DRCN to DSTS */
31 #define FR4XX_SDRAMC_DSTS_SSI 0x00000001 /* indicates that the SDRAM is in self-refresh mode */
33 #define SDRAMC_DRCN_SR 0x00000001 /* transition SDRAM into self-refresh mode */
37 .globl __sleep_save_area
51 ###############################################################################
53 # CPU suspension routine
54 # - void frv_cpu_suspend(unsigned long pdm_mode)
56 ###############################################################################
57 .globl frv_cpu_suspend
58 .type frv_cpu_suspend,@function
61 #----------------------------------------------------
62 # save hsr0, psr, isr, and lr for resume code
63 #----------------------------------------------------
64 li __sleep_save_area,gr11
73 # store the return address from sleep in GR14, and its complement in GR13 as a check
74 li __ramboot_resume,gr14
76 # Resume via RAMBOOT# will turn MMU off, so bootloader needs a physical address.
77 sethi.p %hi(__page_offset),gr13
78 setlo %lo(__page_offset),gr13
83 #----------------------------------------------------
84 # preload and lock into icache that code which may have to run
85 # when dram is in self-refresh state.
86 #----------------------------------------------------
91 or gr3,gr8,gr7 // add the sleep bits for later
93 li #__icache_lock_start,gr3
94 li #__icache_lock_end,gr4
96 addi gr3,#L1_CACHE_BYTES,gr3
102 andi.p gr8,#~PSR_PIL,gr8
108 subicc gr4,#3,gr0,icc0
111 li __addr_FR4XX_DRCN,gr4
112 li FR4XX_SDRAMC_DSTS_SSI,gr5
113 li FR4XX_DSTS_OFFSET,gr6
114 bra __icache_lock_start
117 li __addr_FR55X_DRCN,gr4
118 li FR55X_SDRAMC_DSTS_SSI,gr5
119 li FR55X_DSTS_OFFSET,gr6
120 bra __icache_lock_start
122 .size frv_cpu_suspend, .-frv_cpu_suspend
125 # the final part of the sleep sequence...
126 # - we want it to be be cacheline aligned so we can lock it into the icache easily
127 # On entry: gr7 holds desired hsr0 sleep value
128 # gr8 holds desired psr sleep value
130 .balign L1_CACHE_BYTES
131 .type __icache_lock_start,@function
134 #----------------------------------------------------
135 # put SDRAM in self-refresh mode
136 #----------------------------------------------------
138 # Flush all data in the cache using the DCEF instruction.
143 # Execute dummy load from SDRAM
146 # put the SDRAM into self-refresh mode
148 ori gr11,#SDRAMC_DRCN_SR,gr11
152 # wait for SDRAM to reach self-refresh mode
153 1: ld @(gr4,gr6),gr11
154 andcc gr11,gr5,gr11,icc0
157 # Set the GPIO register so that the IRQ[3:0] pins become valid, as required.
158 # Set the clock mode (CLKC register) as required.
159 # - At this time, also set the CLKC register P0 bit.
161 # Set the HSR0 register PDM field.
164 # Execute NOP 32 times.
169 #if 0 // Fujitsu recommend to skip this and will update docs.
170 # Release the interrupt mask setting of the MASK register of the
171 # interrupt controller if necessary.
176 # Set the PSR register ET bit to 1 to enable interrupts.
179 ###################################################
180 # this is only reached if waking up via interrupt
181 ###################################################
183 # Execute NOP 32 times.
188 #----------------------------------------------------
189 # wake SDRAM from self-refresh mode
190 #----------------------------------------------------
192 andi gr11,#~SDRAMC_DRCN_SR,gr11
196 ld @(gr4,gr6),gr11 // Wait for it to come back...
197 andcc gr11,gr5,gr0,icc0
200 # wait for the SDRAM to stabilise
202 3: subicc gr3,#1,gr3,icc0
205 # now that DRAM is back, this is the end of the code which gets
208 .size __icache_lock_start, .-__icache_lock_start
210 # Fall-through to the RAMBOOT# wakeup path
212 ###############################################################################
214 # resume from suspend re-entry point reached via RAMBOOT# and bootloader
216 ###############################################################################
219 #----------------------------------------------------
220 # restore hsr0, psr, isr, and leave saved lr in gr7
221 #----------------------------------------------------
222 li __sleep_save_area,gr11
225 sethi.p %hi(HSR0_EXMMU),gr3
226 setlo %lo(HSR0_EXMMU),gr3
227 andcc gr3,gr4,gr0,icc0
230 # need to use physical address
231 sethi.p %hi(__page_offset),gr3
232 setlo %lo(__page_offset),gr3
235 # flush all tlb entries
237 setlos.p #PAGE_SIZE,gr5
241 subicc.p gr4,#1,gr4,icc0
245 # need a temporary mapping for the current physical address we are
246 # using between time MMU is enabled and jump to virtual address is
248 sethi.p %hi(0x00000000),gr4
249 setlo %lo(0x00000000),gr4 ; physical address
250 setlos #xAMPRx_L|xAMPRx_M|xAMPRx_SS_256Mb|xAMPRx_S_KERNEL|xAMPRx_V,gr5
256 movgs gr4,iamlr1 ; mapped from real address 0
257 movgs gr5,iampr1 ; cached kernel memory at 0x00000000
261 lddi @(gr11,#0),gr4 ; hsr0, psr
262 lddi @(gr11,#8),gr6 ; isr, lr
271 movgs gr0,iampr1 ; get rid of temporary mapping
276 #----------------------------------------------------
277 # unlock the icache which was locked before going to sleep
278 #----------------------------------------------------
279 li __icache_lock_start,gr3
280 li __icache_lock_end,gr4
282 addi gr3,#L1_CACHE_BYTES,gr3
286 #----------------------------------------------------
287 # back to business as usual
288 #----------------------------------------------------
291 #endif /* CONFIG_PM */
293 ###############################################################################
295 # CPU core sleep mode routine
297 ###############################################################################
298 .globl frv_cpu_core_sleep
299 .type frv_cpu_core_sleep,@function
302 # Preload into icache.
303 li #__core_sleep_icache_lock_start,gr3
304 li #__core_sleep_icache_lock_end,gr4
307 addi gr3,#L1_CACHE_BYTES,gr3
311 bra __core_sleep_icache_lock_start
313 .balign L1_CACHE_BYTES
314 __core_sleep_icache_lock_start:
316 # (1) Set the PSR register ET bit to 0 to disable interrupts.
318 andi.p gr8,#~(PSR_PIL),gr8
319 andi gr8,#~(PSR_ET),gr4
322 #if 0 // Fujitsu recommend to skip this and will update docs.
323 # (2) Set '1' to all bits in the MASK register of the interrupt
324 # controller and mask interrupts.
325 sethi.p %hi(__addr_MASK),gr9
326 setlo %lo(__addr_MASK),gr9
327 sethi.p %hi(0xffff0000),gr4
328 setlo %lo(0xffff0000),gr4
332 # (3) Flush all data in the cache using the DCEF instruction.
335 # (4) Execute the memory barrier instruction
338 # (5) Set the GPIO register so that the IRQ[3:0] pins become valid, as required.
339 # (6) Set the clock mode (CLKC register) as required.
340 # - At this time, also set the CLKC register P0 bit.
341 # (7) Set the HSR0 register PDM field to 001 .
343 ori gr4,HSR0_PDM_CORE_SLEEP,gr4
346 # (8) Execute NOP 32 times.
351 #if 0 // Fujitsu recommend to skip this and will update docs.
352 # (9) Release the interrupt mask setting of the MASK register of the
353 # interrupt controller if necessary.
358 # (10) Set the PSR register ET bit to 1 to enable interrupts.
361 __core_sleep_icache_lock_end:
364 li __core_sleep_icache_lock_start,gr3
365 li __core_sleep_icache_lock_end,gr4
367 addi gr3,#L1_CACHE_BYTES,gr3
373 .size frv_cpu_core_sleep, .-frv_cpu_core_sleep