]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/blob - arch/arm/mach-sa1100/pm.c
Linux-2.6.12-rc2
[mirror_ubuntu-hirsute-kernel.git] / arch / arm / mach-sa1100 / pm.c
1 /*
2 * SA1100 Power Management Routines
3 *
4 * Copyright (c) 2001 Cliff Brake <cbrake@accelent.com>
5 *
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 *
9 * History:
10 *
11 * 2001-02-06: Cliff Brake Initial code
12 *
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
17 *
18 * 2001-08-29: Nicolas Pitre <nico@cam.org>
19 * Cleaned up, pushed platform dependent stuff
20 * in the platform specific files.
21 *
22 * 2002-05-27: Nicolas Pitre Killed sleep.h and the kmalloced save array.
23 * Storage is local on the stack now.
24 */
25 #include <linux/init.h>
26 #include <linux/suspend.h>
27 #include <linux/errno.h>
28 #include <linux/time.h>
29
30 #include <asm/hardware.h>
31 #include <asm/memory.h>
32 #include <asm/system.h>
33 #include <asm/mach/time.h>
34
35 extern void sa1100_cpu_suspend(void);
36 extern void sa1100_cpu_resume(void);
37
38 #define SAVE(x) sleep_save[SLEEP_SAVE_##x] = x
39 #define RESTORE(x) x = sleep_save[SLEEP_SAVE_##x]
40
41 /*
42 * List of global SA11x0 peripheral registers to preserve.
43 * More ones like CP and general purpose register values are preserved
44 * on the stack and then the stack pointer is stored last in sleep.S.
45 */
46 enum { SLEEP_SAVE_SP = 0,
47
48 SLEEP_SAVE_GPDR, SLEEP_SAVE_GAFR,
49 SLEEP_SAVE_PPDR, SLEEP_SAVE_PPSR, SLEEP_SAVE_PPAR, SLEEP_SAVE_PSDR,
50
51 SLEEP_SAVE_Ser1SDCR0,
52
53 SLEEP_SAVE_SIZE
54 };
55
56
57 static int sa11x0_pm_enter(suspend_state_t state)
58 {
59 unsigned long gpio, sleep_save[SLEEP_SAVE_SIZE];
60 struct timespec delta, rtc;
61
62 if (state != PM_SUSPEND_MEM)
63 return -EINVAL;
64
65 /* preserve current time */
66 rtc.tv_sec = RCNR;
67 rtc.tv_nsec = 0;
68 save_time_delta(&delta, &rtc);
69 gpio = GPLR;
70
71 /* save vital registers */
72 SAVE(GPDR);
73 SAVE(GAFR);
74
75 SAVE(PPDR);
76 SAVE(PPSR);
77 SAVE(PPAR);
78 SAVE(PSDR);
79
80 SAVE(Ser1SDCR0);
81
82 /* Clear previous reset status */
83 RCSR = RCSR_HWR | RCSR_SWR | RCSR_WDR | RCSR_SMR;
84
85 /* set resume return address */
86 PSPR = virt_to_phys(sa1100_cpu_resume);
87
88 /* go zzz */
89 sa1100_cpu_suspend();
90
91 /*
92 * Ensure not to come back here if it wasn't intended
93 */
94 PSPR = 0;
95
96 /*
97 * Ensure interrupt sources are disabled; we will re-init
98 * the interrupt subsystem via the device manager.
99 */
100 ICLR = 0;
101 ICCR = 1;
102 ICMR = 0;
103
104 /* restore registers */
105 RESTORE(GPDR);
106 RESTORE(GAFR);
107
108 RESTORE(PPDR);
109 RESTORE(PPSR);
110 RESTORE(PPAR);
111 RESTORE(PSDR);
112
113 RESTORE(Ser1SDCR0);
114
115 GPSR = gpio;
116 GPCR = ~gpio;
117
118 /*
119 * Clear the peripheral sleep-hold bit.
120 */
121 PSSR = PSSR_PH;
122
123 /* restore current time */
124 rtc.tv_sec = RCNR;
125 restore_time_delta(&delta, &rtc);
126
127 return 0;
128 }
129
130 unsigned long sleep_phys_sp(void *sp)
131 {
132 return virt_to_phys(sp);
133 }
134
135 /*
136 * Called after processes are frozen, but before we shut down devices.
137 */
138 static int sa11x0_pm_prepare(suspend_state_t state)
139 {
140 return 0;
141 }
142
143 /*
144 * Called after devices are re-setup, but before processes are thawed.
145 */
146 static int sa11x0_pm_finish(suspend_state_t state)
147 {
148 return 0;
149 }
150
151 /*
152 * Set to PM_DISK_FIRMWARE so we can quickly veto suspend-to-disk.
153 */
154 static struct pm_ops sa11x0_pm_ops = {
155 .pm_disk_mode = PM_DISK_FIRMWARE,
156 .prepare = sa11x0_pm_prepare,
157 .enter = sa11x0_pm_enter,
158 .finish = sa11x0_pm_finish,
159 };
160
161 static int __init sa11x0_pm_init(void)
162 {
163 pm_set_ops(&sa11x0_pm_ops);
164 return 0;
165 }
166
167 late_initcall(sa11x0_pm_init);