1
2
3
4
5
6
7
8
9
10
11
12
13#include <linux/suspend.h>
14#include <linux/sched.h>
15#include <linux/proc_fs.h>
16#include <linux/interrupt.h>
17#include <linux/sysfs.h>
18#include <linux/module.h>
19#include <linux/platform_device.h>
20
21#include <asm/io.h>
22#include <asm/irq.h>
23#include <asm/atomic.h>
24#include <asm/mach/time.h>
25#include <asm/mach/irq.h>
26#include <asm/mach-types.h>
27
28#include <asm/arch/at91_pmc.h>
29#include <asm/arch/at91rm9200_mc.h>
30#include <asm/arch/gpio.h>
31#include <asm/arch/cpu.h>
32
33#include "generic.h"
34
35
36static int at91_pm_valid_state(suspend_state_t state)
37{
38 switch (state) {
39 case PM_SUSPEND_ON:
40 case PM_SUSPEND_STANDBY:
41 case PM_SUSPEND_MEM:
42 return 1;
43
44 default:
45 return 0;
46 }
47}
48
49
50static suspend_state_t target_state;
51
52
53
54
55static int at91_pm_set_target(suspend_state_t state)
56{
57 target_state = state;
58 return 0;
59}
60
61
62
63
64
65static int at91_pm_verify_clocks(void)
66{
67 unsigned long scsr;
68 int i;
69
70 scsr = at91_sys_read(AT91_PMC_SCSR);
71
72
73 if (cpu_is_at91rm9200()) {
74 if ((scsr & (AT91RM9200_PMC_UHP | AT91RM9200_PMC_UDP)) != 0) {
75 pr_debug("AT91: PM - Suspend-to-RAM with USB still active\n");
76 return 0;
77 }
78 } else if (cpu_is_at91sam9260() || cpu_is_at91sam9261() || cpu_is_at91sam9263()) {
79 if ((scsr & (AT91SAM926x_PMC_UHP | AT91SAM926x_PMC_UDP)) != 0) {
80 pr_debug("AT91: PM - Suspend-to-RAM with USB still active\n");
81 return 0;
82 }
83 }
84
85#ifdef CONFIG_AT91_PROGRAMMABLE_CLOCKS
86
87 for (i = 0; i < 4; i++) {
88 u32 css;
89
90 if ((scsr & (AT91_PMC_PCK0 << i)) == 0)
91 continue;
92
93 css = at91_sys_read(AT91_PMC_PCKR(i)) & AT91_PMC_CSS;
94 if (css != AT91_PMC_CSS_SLOW) {
95 pr_debug("AT91: PM - Suspend-to-RAM with PCK%d src %d\n", i, css);
96 return 0;
97 }
98 }
99#endif
100
101 return 1;
102}
103
104
105
106
107
108
109
110
111
112
113
114int at91_suspend_entering_slow_clock(void)
115{
116 return (target_state == PM_SUSPEND_MEM);
117}
118EXPORT_SYMBOL(at91_suspend_entering_slow_clock);
119
120
121static void (*slow_clock)(void);
122
123
124static int at91_pm_enter(suspend_state_t state)
125{
126 at91_gpio_suspend();
127 at91_irq_suspend();
128
129 pr_debug("AT91: PM - wake mask %08x, pm state %d\n",
130
131 (at91_sys_read(AT91_PMC_PCSR)
132 | (1 << AT91_ID_FIQ)
133 | (1 << AT91_ID_SYS)
134 | (at91_extern_irq))
135 & at91_sys_read(AT91_AIC_IMR),
136 state);
137
138 switch (state) {
139
140
141
142
143
144 case PM_SUSPEND_MEM:
145
146
147
148 if (!at91_pm_verify_clocks())
149 goto error;
150
151
152
153
154
155 if (slow_clock) {
156 slow_clock();
157 break;
158 } else {
159
160 pr_info("AT91: PM - no slow clock mode yet ...\n");
161
162 }
163
164
165
166
167
168
169
170 case PM_SUSPEND_STANDBY:
171
172
173
174
175
176 asm("b 1f; .align 5; 1:");
177 asm("mcr p15, 0, r0, c7, c10, 4");
178 at91_sys_write(AT91_SDRAMC_SRR, 1);
179
180
181 case PM_SUSPEND_ON:
182 asm("mcr p15, 0, r0, c7, c0, 4");
183 break;
184
185 default:
186 pr_debug("AT91: PM - bogus suspend state %d\n", state);
187 goto error;
188 }
189
190 pr_debug("AT91: PM - wakeup %08x\n",
191 at91_sys_read(AT91_AIC_IPR) & at91_sys_read(AT91_AIC_IMR));
192
193error:
194 target_state = PM_SUSPEND_ON;
195 at91_irq_resume();
196 at91_gpio_resume();
197 return 0;
198}
199
200
201static struct platform_suspend_ops at91_pm_ops ={
202 .valid = at91_pm_valid_state,
203 .set_target = at91_pm_set_target,
204 .enter = at91_pm_enter,
205};
206
207static int __init at91_pm_init(void)
208{
209 printk("AT91: Power Management\n");
210
211#ifdef CONFIG_AT91_PM_SLOW_CLOCK
212
213
214
215 slow_clock = (void *) (AT91_VA_BASE_SRAM + (3 * SZ_4K));
216 memcpy(slow_clock, at91rm9200_slow_clock, at91rm9200_slow_clock_sz);
217#endif
218
219
220 at91_sys_write(AT91_SDRAMC_LPR, 0);
221
222 suspend_set_ops(&at91_pm_ops);
223
224 return 0;
225}
226arch_initcall(at91_pm_init);
227