1 /* sleep.S: power saving mode entry
3 * Copyright (C) 2004 Red Hat, Inc. All Rights Reserved.
4 * Written by David Woodhouse (dwmw2@redhat.com)
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/config.h>
15 #include <linux/linkage.h>
16 #include <asm/setup.h>
17 #include <asm/segment.h>
19 #include <asm/ptrace.h>
20 #include <asm/errno.h>
21 #include <asm/cache.h>
22 #include <asm/spr-regs.h>
24 #define __addr_MASK 0xfeff9820 /* interrupt controller mask */
26 #define __addr_FR55X_DRCN 0xfeff0218 /* Address of DRCN register */
27 #define FR55X_DSTS_OFFSET -4 /* Offset from DRCN to DSTS */
28 #define FR55X_SDRAMC_DSTS_SSI 0x00000002 /* indicates that the SDRAM is in self-refresh mode */
30 #define __addr_FR4XX_DRCN 0xfe000430 /* Address of DRCN register */
31 #define FR4XX_DSTS_OFFSET -8 /* Offset from DRCN to DSTS */
32 #define FR4XX_SDRAMC_DSTS_SSI 0x00000001 /* indicates that the SDRAM is in self-refresh mode */
34 #define SDRAMC_DRCN_SR 0x00000001 /* transition SDRAM into self-refresh mode */
38 .globl __sleep_save_area
52 ###############################################################################
54 # CPU suspension routine
55 # - void frv_cpu_suspend(unsigned long pdm_mode)
57 ###############################################################################
58 .globl frv_cpu_suspend
59 .type frv_cpu_suspend,@function
62 #----------------------------------------------------
63 # save hsr0, psr, isr, and lr for resume code
64 #----------------------------------------------------
65 li __sleep_save_area,gr11
74 # store the return address from sleep in GR14, and its complement in GR13 as a check
75 li __ramboot_resume,gr14
77 # Resume via RAMBOOT# will turn MMU off, so bootloader needs a physical address.
78 sethi.p %hi(__page_offset),gr13
79 setlo %lo(__page_offset),gr13
84 #----------------------------------------------------
85 # preload and lock into icache that code which may have to run
86 # when dram is in self-refresh state.
87 #----------------------------------------------------
92 or gr3,gr8,gr7 // add the sleep bits for later
94 li #__icache_lock_start,gr3
95 li #__icache_lock_end,gr4
97 addi gr3,#L1_CACHE_BYTES,gr3
103 andi.p gr8,#~PSR_PIL,gr8
109 subicc gr4,#3,gr0,icc0
112 li __addr_FR4XX_DRCN,gr4
113 li FR4XX_SDRAMC_DSTS_SSI,gr5
114 li FR4XX_DSTS_OFFSET,gr6
115 bra __icache_lock_start
118 li __addr_FR55X_DRCN,gr4
119 li FR55X_SDRAMC_DSTS_SSI,gr5
120 li FR55X_DSTS_OFFSET,gr6
121 bra __icache_lock_start
123 .size frv_cpu_suspend, .-frv_cpu_suspend
126 # the final part of the sleep sequence...
127 # - we want it to be be cacheline aligned so we can lock it into the icache easily
128 # On entry: gr7 holds desired hsr0 sleep value
129 # gr8 holds desired psr sleep value
131 .balign L1_CACHE_BYTES
132 .type __icache_lock_start,@function
135 #----------------------------------------------------
136 # put SDRAM in self-refresh mode
137 #----------------------------------------------------
139 # Flush all data in the cache using the DCEF instruction.
144 # Execute dummy load from SDRAM
147 # put the SDRAM into self-refresh mode
149 ori gr11,#SDRAMC_DRCN_SR,gr11
153 # wait for SDRAM to reach self-refresh mode
154 1: ld @(gr4,gr6),gr11
155 andcc gr11,gr5,gr11,icc0
158 # Set the GPIO register so that the IRQ[3:0] pins become valid, as required.
159 # Set the clock mode (CLKC register) as required.
160 # - At this time, also set the CLKC register P0 bit.
162 # Set the HSR0 register PDM field.
165 # Execute NOP 32 times.
170 #if 0 // Fujitsu recommend to skip this and will update docs.
171 # Release the interrupt mask setting of the MASK register of the
172 # interrupt controller if necessary.
177 # Set the PSR register ET bit to 1 to enable interrupts.
180 ###################################################
181 # this is only reached if waking up via interrupt
182 ###################################################
184 # Execute NOP 32 times.
189 #----------------------------------------------------
190 # wake SDRAM from self-refresh mode
191 #----------------------------------------------------
193 andi gr11,#~SDRAMC_DRCN_SR,gr11
197 ld @(gr4,gr6),gr11 // Wait for it to come back...
198 andcc gr11,gr5,gr0,icc0
201 # wait for the SDRAM to stabilise
203 3: subicc gr3,#1,gr3,icc0
206 # now that DRAM is back, this is the end of the code which gets
209 .size __icache_lock_start, .-__icache_lock_start
211 # Fall-through to the RAMBOOT# wakeup path
213 ###############################################################################
215 # resume from suspend re-entry point reached via RAMBOOT# and bootloader
217 ###############################################################################
220 #----------------------------------------------------
221 # restore hsr0, psr, isr, and leave saved lr in gr7
222 #----------------------------------------------------
223 li __sleep_save_area,gr11
226 sethi.p %hi(HSR0_EXMMU),gr3
227 setlo %lo(HSR0_EXMMU),gr3
228 andcc gr3,gr4,gr0,icc0
231 # need to use physical address
232 sethi.p %hi(__page_offset),gr3
233 setlo %lo(__page_offset),gr3
236 # flush all tlb entries
238 setlos.p #PAGE_SIZE,gr5
242 subicc.p gr4,#1,gr4,icc0
246 # need a temporary mapping for the current physical address we are
247 # using between time MMU is enabled and jump to virtual address is
249 sethi.p %hi(0x00000000),gr4
250 setlo %lo(0x00000000),gr4 ; physical address
251 setlos #xAMPRx_L|xAMPRx_M|xAMPRx_SS_256Mb|xAMPRx_S_KERNEL|xAMPRx_V,gr5
257 movgs gr4,iamlr1 ; mapped from real address 0
258 movgs gr5,iampr1 ; cached kernel memory at 0x00000000
262 lddi @(gr11,#0),gr4 ; hsr0, psr
263 lddi @(gr11,#8),gr6 ; isr, lr
272 movgs gr0,iampr1 ; get rid of temporary mapping
277 #----------------------------------------------------
278 # unlock the icache which was locked before going to sleep
279 #----------------------------------------------------
280 li __icache_lock_start,gr3
281 li __icache_lock_end,gr4
283 addi gr3,#L1_CACHE_BYTES,gr3
287 #----------------------------------------------------
288 # back to business as usual
289 #----------------------------------------------------
292 #endif /* CONFIG_PM */
294 ###############################################################################
296 # CPU core sleep mode routine
298 ###############################################################################
299 .globl frv_cpu_core_sleep
300 .type frv_cpu_core_sleep,@function
303 # Preload into icache.
304 li #__core_sleep_icache_lock_start,gr3
305 li #__core_sleep_icache_lock_end,gr4
308 addi gr3,#L1_CACHE_BYTES,gr3
312 bra __core_sleep_icache_lock_start
314 .balign L1_CACHE_BYTES
315 __core_sleep_icache_lock_start:
317 # (1) Set the PSR register ET bit to 0 to disable interrupts.
319 andi.p gr8,#~(PSR_PIL),gr8
320 andi gr8,#~(PSR_ET),gr4
323 #if 0 // Fujitsu recommend to skip this and will update docs.
324 # (2) Set '1' to all bits in the MASK register of the interrupt
325 # controller and mask interrupts.
326 sethi.p %hi(__addr_MASK),gr9
327 setlo %lo(__addr_MASK),gr9
328 sethi.p %hi(0xffff0000),gr4
329 setlo %lo(0xffff0000),gr4
333 # (3) Flush all data in the cache using the DCEF instruction.
336 # (4) Execute the memory barrier instruction
339 # (5) Set the GPIO register so that the IRQ[3:0] pins become valid, as required.
340 # (6) Set the clock mode (CLKC register) as required.
341 # - At this time, also set the CLKC register P0 bit.
342 # (7) Set the HSR0 register PDM field to 001 .
344 ori gr4,HSR0_PDM_CORE_SLEEP,gr4
347 # (8) Execute NOP 32 times.
352 #if 0 // Fujitsu recommend to skip this and will update docs.
353 # (9) Release the interrupt mask setting of the MASK register of the
354 # interrupt controller if necessary.
359 # (10) Set the PSR register ET bit to 1 to enable interrupts.
362 __core_sleep_icache_lock_end:
365 li __core_sleep_icache_lock_start,gr3
366 li __core_sleep_icache_lock_end,gr4
368 addi gr3,#L1_CACHE_BYTES,gr3
374 .size frv_cpu_core_sleep, .-frv_cpu_core_sleep