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_core.h>
21#include <linux/io.h>
22
23#include <asm/cacheflush.h>
24#include <asm/suspend.h>
25
26#include <plat/regs-serial.h>
27
28#ifdef CONFIG_SAMSUNG_ATAGS
29#include <mach/hardware.h>
30#include <mach/map.h>
31#include <mach/regs-clock.h>
32#include <mach/regs-irq.h>
33#include <mach/irqs.h>
34#endif
35
36#include <asm/irq.h>
37
38#include <plat/pm.h>
39#include <mach/pm-core.h>
40
41
42
43unsigned long s3c_pm_flags;
44
45
46
47
48
49
50
51#ifdef CONFIG_SAMSUNG_PM_DEBUG
52extern void printascii(const char *);
53
54void s3c_pm_dbg(const char *fmt, ...)
55{
56 va_list va;
57 char buff[256];
58
59 va_start(va, fmt);
60 vsnprintf(buff, sizeof(buff), fmt, va);
61 va_end(va);
62
63 printascii(buff);
64}
65
66static inline void s3c_pm_debug_init(void)
67{
68
69 s3c_pm_debug_init_uart();
70}
71
72#else
73#define s3c_pm_debug_init() do { } while(0)
74
75#endif
76
77
78
79unsigned char pm_uart_udivslot;
80
81#ifdef CONFIG_SAMSUNG_PM_DEBUG
82
83static struct pm_uart_save uart_save;
84
85static void s3c_pm_save_uart(unsigned int uart, struct pm_uart_save *save)
86{
87 void __iomem *regs = S3C_VA_UARTx(uart);
88
89 save->ulcon = __raw_readl(regs + S3C2410_ULCON);
90 save->ucon = __raw_readl(regs + S3C2410_UCON);
91 save->ufcon = __raw_readl(regs + S3C2410_UFCON);
92 save->umcon = __raw_readl(regs + S3C2410_UMCON);
93 save->ubrdiv = __raw_readl(regs + S3C2410_UBRDIV);
94
95 if (pm_uart_udivslot)
96 save->udivslot = __raw_readl(regs + S3C2443_DIVSLOT);
97
98 S3C_PMDBG("UART[%d]: ULCON=%04x, UCON=%04x, UFCON=%04x, UBRDIV=%04x\n",
99 uart, save->ulcon, save->ucon, save->ufcon, save->ubrdiv);
100}
101
102static void s3c_pm_save_uarts(void)
103{
104 s3c_pm_save_uart(CONFIG_DEBUG_S3C_UART, &uart_save);
105}
106
107static void s3c_pm_restore_uart(unsigned int uart, struct pm_uart_save *save)
108{
109 void __iomem *regs = S3C_VA_UARTx(uart);
110
111 s3c_pm_arch_update_uart(regs, save);
112
113 __raw_writel(save->ulcon, regs + S3C2410_ULCON);
114 __raw_writel(save->ucon, regs + S3C2410_UCON);
115 __raw_writel(save->ufcon, regs + S3C2410_UFCON);
116 __raw_writel(save->umcon, regs + S3C2410_UMCON);
117 __raw_writel(save->ubrdiv, regs + S3C2410_UBRDIV);
118
119 if (pm_uart_udivslot)
120 __raw_writel(save->udivslot, regs + S3C2443_DIVSLOT);
121}
122
123static void s3c_pm_restore_uarts(void)
124{
125 s3c_pm_restore_uart(CONFIG_DEBUG_S3C_UART, &uart_save);
126}
127#else
128static void s3c_pm_save_uarts(void) { }
129static void s3c_pm_restore_uarts(void) { }
130#endif
131
132
133
134
135unsigned long s3c_irqwake_intmask = 0xffffffffL;
136unsigned long s3c_irqwake_eintmask = 0xffffffffL;
137
138int s3c_irqext_wake(struct irq_data *data, unsigned int state)
139{
140 unsigned long bit = 1L << IRQ_EINT_BIT(data->irq);
141
142 if (!(s3c_irqwake_eintallow & bit))
143 return -ENOENT;
144
145 printk(KERN_INFO "wake %s for irq %d\n",
146 state ? "enabled" : "disabled", data->irq);
147
148 if (!state)
149 s3c_irqwake_eintmask |= bit;
150 else
151 s3c_irqwake_eintmask &= ~bit;
152
153 return 0;
154}
155
156
157
158
159
160
161
162
163
164
165
166void s3c_pm_do_save(struct sleep_save *ptr, int count)
167{
168 for (; count > 0; count--, ptr++) {
169 ptr->val = __raw_readl(ptr->reg);
170 S3C_PMDBG("saved %p value %08lx\n", ptr->reg, ptr->val);
171 }
172}
173
174
175
176
177
178
179
180
181
182
183
184
185void s3c_pm_do_restore(struct sleep_save *ptr, int count)
186{
187 for (; count > 0; count--, ptr++) {
188 printk(KERN_DEBUG "restore %p (restore %08lx, was %08x)\n",
189 ptr->reg, ptr->val, __raw_readl(ptr->reg));
190
191 __raw_writel(ptr->val, ptr->reg);
192 }
193}
194
195
196
197
198
199
200
201
202
203
204
205
206void s3c_pm_do_restore_core(struct sleep_save *ptr, int count)
207{
208 for (; count > 0; count--, ptr++)
209 __raw_writel(ptr->val, ptr->reg);
210}
211
212
213
214
215
216static void __maybe_unused s3c_pm_show_resume_irqs(int start,
217 unsigned long which,
218 unsigned long mask)
219{
220 int i;
221
222 which &= ~mask;
223
224 for (i = 0; i <= 31; i++) {
225 if (which & (1L<<i)) {
226 S3C_PMDBG("IRQ %d asserted at resume\n", start+i);
227 }
228 }
229}
230
231
232void (*pm_cpu_prep)(void);
233int (*pm_cpu_sleep)(unsigned long);
234
235#define any_allowed(mask, allow) (((mask) & (allow)) != (allow))
236
237
238
239
240
241
242static int s3c_pm_enter(suspend_state_t state)
243{
244 int ret;
245
246
247 s3c_pm_debug_init();
248
249 S3C_PMDBG("%s(%d)\n", __func__, state);
250
251 if (pm_cpu_prep == NULL || pm_cpu_sleep == NULL) {
252 printk(KERN_ERR "%s: error: no cpu sleep function\n", __func__);
253 return -EINVAL;
254 }
255
256
257
258
259
260
261 if (!of_have_populated_dt() &&
262 !any_allowed(s3c_irqwake_intmask, s3c_irqwake_intallow) &&
263 !any_allowed(s3c_irqwake_eintmask, s3c_irqwake_eintallow)) {
264 printk(KERN_ERR "%s: No wake-up sources!\n", __func__);
265 printk(KERN_ERR "%s: Aborting sleep\n", __func__);
266 return -EINVAL;
267 }
268
269
270
271 if (!of_have_populated_dt()) {
272 samsung_pm_save_gpios();
273 samsung_pm_saved_gpios();
274 }
275
276 s3c_pm_save_uarts();
277 s3c_pm_save_core();
278
279
280
281 s3c_pm_configure_extint();
282
283 S3C_PMDBG("sleep: irq wakeup masks: %08lx,%08lx\n",
284 s3c_irqwake_intmask, s3c_irqwake_eintmask);
285
286 s3c_pm_arch_prepare_irqs();
287
288
289
290 pm_cpu_prep();
291
292
293
294 flush_cache_all();
295
296 s3c_pm_check_store();
297
298
299
300 s3c_pm_arch_stop_clocks();
301
302
303
304
305
306 ret = cpu_suspend(0, pm_cpu_sleep);
307 if (ret)
308 return ret;
309
310
311
312 s3c_pm_restore_core();
313 s3c_pm_restore_uarts();
314
315 if (!of_have_populated_dt()) {
316 samsung_pm_restore_gpios();
317 s3c_pm_restored_gpios();
318 }
319
320 s3c_pm_debug_init();
321
322
323
324 s3c_pm_arch_show_resume_irqs();
325
326 S3C_PMDBG("%s: post sleep, preparing to return\n", __func__);
327
328
329 s3c_pm_debug_smdkled(1 << 1, 0);
330
331 s3c_pm_check_restore();
332
333
334
335 S3C_PMDBG("S3C PM Resume (post-restore)\n");
336 return 0;
337}
338
339static int s3c_pm_prepare(void)
340{
341
342
343 s3c_pm_check_prepare();
344 return 0;
345}
346
347static void s3c_pm_finish(void)
348{
349 s3c_pm_check_cleanup();
350}
351
352static const struct platform_suspend_ops s3c_pm_ops = {
353 .enter = s3c_pm_enter,
354 .prepare = s3c_pm_prepare,
355 .finish = s3c_pm_finish,
356 .valid = suspend_valid_only_mem,
357};
358
359
360
361
362
363
364
365
366int __init s3c_pm_init(void)
367{
368 printk("S3C Power Management, Copyright 2004 Simtec Electronics\n");
369
370 suspend_set_ops(&s3c_pm_ops);
371 return 0;
372}
373