1
2
3
4
5
6
7
8
9
10
11
12
13
14
15#include <linux/init.h>
16#include <linux/suspend.h>
17#include <linux/errno.h>
18#include <linux/delay.h>
19#include <linux/of.h>
20#include <linux/serial_s3c.h>
21#include <linux/io.h>
22
23#include <asm/cacheflush.h>
24#include <asm/suspend.h>
25
26#ifdef CONFIG_SAMSUNG_ATAGS
27#include <mach/map.h>
28#ifndef CONFIG_ARCH_EXYNOS
29#include <mach/regs-clock.h>
30#include <mach/regs-irq.h>
31#endif
32#include <mach/irqs.h>
33#endif
34
35#include <asm/irq.h>
36
37#include <plat/pm.h>
38#include <mach/pm-core.h>
39
40
41
42unsigned long s3c_pm_flags;
43
44
45
46
47unsigned long s3c_irqwake_intmask = 0xffffffffL;
48unsigned long s3c_irqwake_eintmask = 0xffffffffL;
49
50int s3c_irqext_wake(struct irq_data *data, unsigned int state)
51{
52 unsigned long bit = 1L << IRQ_EINT_BIT(data->irq);
53
54 if (!(s3c_irqwake_eintallow & bit))
55 return -ENOENT;
56
57 printk(KERN_INFO "wake %s for irq %d\n",
58 state ? "enabled" : "disabled", data->irq);
59
60 if (!state)
61 s3c_irqwake_eintmask |= bit;
62 else
63 s3c_irqwake_eintmask &= ~bit;
64
65 return 0;
66}
67
68
69
70
71
72static void __maybe_unused s3c_pm_show_resume_irqs(int start,
73 unsigned long which,
74 unsigned long mask)
75{
76 int i;
77
78 which &= ~mask;
79
80 for (i = 0; i <= 31; i++) {
81 if (which & (1L<<i)) {
82 S3C_PMDBG("IRQ %d asserted at resume\n", start+i);
83 }
84 }
85}
86
87
88void (*pm_cpu_prep)(void);
89int (*pm_cpu_sleep)(unsigned long);
90
91#define any_allowed(mask, allow) (((mask) & (allow)) != (allow))
92
93
94
95
96
97
98static int s3c_pm_enter(suspend_state_t state)
99{
100 int ret;
101
102
103 s3c_pm_debug_init();
104
105 S3C_PMDBG("%s(%d)\n", __func__, state);
106
107 if (pm_cpu_prep == NULL || pm_cpu_sleep == NULL) {
108 printk(KERN_ERR "%s: error: no cpu sleep function\n", __func__);
109 return -EINVAL;
110 }
111
112
113
114
115
116
117 if (!of_have_populated_dt() &&
118 !any_allowed(s3c_irqwake_intmask, s3c_irqwake_intallow) &&
119 !any_allowed(s3c_irqwake_eintmask, s3c_irqwake_eintallow)) {
120 printk(KERN_ERR "%s: No wake-up sources!\n", __func__);
121 printk(KERN_ERR "%s: Aborting sleep\n", __func__);
122 return -EINVAL;
123 }
124
125
126
127 if (!of_have_populated_dt()) {
128 samsung_pm_save_gpios();
129 samsung_pm_saved_gpios();
130 }
131
132 s3c_pm_save_uarts();
133 s3c_pm_save_core();
134
135
136
137 s3c_pm_configure_extint();
138
139 S3C_PMDBG("sleep: irq wakeup masks: %08lx,%08lx\n",
140 s3c_irqwake_intmask, s3c_irqwake_eintmask);
141
142 s3c_pm_arch_prepare_irqs();
143
144
145
146 pm_cpu_prep();
147
148
149
150 flush_cache_all();
151
152 s3c_pm_check_store();
153
154
155
156 s3c_pm_arch_stop_clocks();
157
158
159
160
161
162 ret = cpu_suspend(0, pm_cpu_sleep);
163 if (ret)
164 return ret;
165
166
167
168 s3c_pm_restore_core();
169 s3c_pm_restore_uarts();
170
171 if (!of_have_populated_dt()) {
172 samsung_pm_restore_gpios();
173 s3c_pm_restored_gpios();
174 }
175
176 s3c_pm_debug_init();
177
178
179
180 s3c_pm_arch_show_resume_irqs();
181
182 S3C_PMDBG("%s: post sleep, preparing to return\n", __func__);
183
184
185 s3c_pm_debug_smdkled(1 << 1, 0);
186
187 s3c_pm_check_restore();
188
189
190
191 S3C_PMDBG("S3C PM Resume (post-restore)\n");
192 return 0;
193}
194
195static int s3c_pm_prepare(void)
196{
197
198
199 s3c_pm_check_prepare();
200 return 0;
201}
202
203static void s3c_pm_finish(void)
204{
205 s3c_pm_check_cleanup();
206}
207
208static const struct platform_suspend_ops s3c_pm_ops = {
209 .enter = s3c_pm_enter,
210 .prepare = s3c_pm_prepare,
211 .finish = s3c_pm_finish,
212 .valid = suspend_valid_only_mem,
213};
214
215
216
217
218
219
220
221
222int __init s3c_pm_init(void)
223{
224 printk("S3C Power Management, Copyright 2004 Simtec Electronics\n");
225
226 suspend_set_ops(&s3c_pm_ops);
227 return 0;
228}
229