2 * SA1100 Power Management Routines
4 * Copyright (c) 2001 Cliff Brake <cbrake@accelent.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.
11 * 2001-02-06: Cliff Brake Initial code
13 * 2001-02-25: Sukjae Cho <sjcho@east.isi.edu> &
14 * Chester Kuo <chester@linux.org.tw>
15 * Save more value for the resume function! Support
16 * Bitsy/Assabet/Freebird board
18 * 2001-08-29: Nicolas Pitre <nico@cam.org>
19 * Cleaned up, pushed platform dependent stuff
20 * in the platform specific files.
22 * 2002-05-27: Nicolas Pitre Killed sleep.h and the kmalloced save array.
23 * Storage is local on the stack now.
25 #include <linux/init.h>
26 #include <linux/suspend.h>
27 #include <linux/errno.h>
28 #include <linux/time.h>
30 #include <asm/hardware.h>
31 #include <asm/memory.h>
32 #include <asm/system.h>
34 extern void sa1100_cpu_suspend(void);
35 extern void sa1100_cpu_resume(void);
37 #define SAVE(x) sleep_save[SLEEP_SAVE_##x] = x
38 #define RESTORE(x) x = sleep_save[SLEEP_SAVE_##x]
41 * List of global SA11x0 peripheral registers to preserve.
42 * More ones like CP and general purpose register values are preserved
43 * on the stack and then the stack pointer is stored last in sleep.S.
45 enum { SLEEP_SAVE_SP = 0,
47 SLEEP_SAVE_OSCR, SLEEP_SAVE_OIER,
48 SLEEP_SAVE_OSMR0, SLEEP_SAVE_OSMR1, SLEEP_SAVE_OSMR2, SLEEP_SAVE_OSMR3,
50 SLEEP_SAVE_GPDR, SLEEP_SAVE_GAFR,
51 SLEEP_SAVE_PPDR, SLEEP_SAVE_PPSR, SLEEP_SAVE_PPAR, SLEEP_SAVE_PSDR,
59 static int sa11x0_pm_enter(u32 state)
61 unsigned long sleep_save[SLEEP_SAVE_SIZE];
62 unsigned long delta, gpio;
64 if (state != PM_SUSPEND_MEM)
67 /* preserve current time */
68 delta = xtime.tv_sec - RCNR;
71 /* save vital registers */
89 /* Clear previous reset status */
90 RCSR = RCSR_HWR | RCSR_SWR | RCSR_WDR | RCSR_SMR;
92 /* set resume return address */
93 PSPR = virt_to_phys(sa1100_cpu_resume);
99 * Ensure not to come back here if it wasn't intended
104 * Ensure interrupt sources are disabled; we will re-init
105 * the interrupt subsystem via the device manager.
111 /* restore registers */
126 * Clear the peripheral sleep-hold bit.
137 /* restore current time */
138 xtime.tv_sec = RCNR + delta;
143 unsigned long sleep_phys_sp(void *sp)
145 return virt_to_phys(sp);
149 * Called after processes are frozen, but before we shut down devices.
151 static int sa11x0_pm_prepare(u32 state)
157 * Called after devices are re-setup, but before processes are thawed.
159 static int sa11x0_pm_finish(u32 state)
165 * Set to PM_DISK_FIRMWARE so we can quickly veto suspend-to-disk.
167 static struct pm_ops sa11x0_pm_ops = {
168 .pm_disk_mode = PM_DISK_FIRMWARE,
169 .prepare = sa11x0_pm_prepare,
170 .enter = sa11x0_pm_enter,
171 .finish = sa11x0_pm_finish,
174 static int __init sa11x0_pm_init(void)
176 pm_set_ops(&sa11x0_pm_ops);
180 late_initcall(sa11x0_pm_init);