1 /* linux/arch/arm/plat-s3c/pm.c
3 * Copyright 2008 Openmoko, Inc.
4 * Copyright 2004-2008 Simtec Electronics
5 * Ben Dooks <ben@simtec.co.uk>
6 * http://armlinux.simtec.co.uk/
8 * S3C common power management (suspend to ram) support.
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
15 #include <linux/init.h>
16 #include <linux/suspend.h>
17 #include <linux/errno.h>
18 #include <linux/delay.h>
20 #include <linux/serial_s3c.h>
23 #include <asm/cacheflush.h>
24 #include <asm/suspend.h>
26 #ifdef CONFIG_SAMSUNG_ATAGS
28 #ifndef CONFIG_ARCH_EXYNOS
29 #include <mach/regs-clock.h>
30 #include <mach/regs-irq.h>
32 #include <mach/irqs.h>
38 #include <mach/pm-core.h>
40 /* for external use */
42 unsigned long s3c_pm_flags
;
44 /* The IRQ ext-int code goes here, it is too small to currently bother
45 * with its own file. */
47 unsigned long s3c_irqwake_intmask
= 0xffffffffL
;
48 unsigned long s3c_irqwake_eintmask
= 0xffffffffL
;
50 int s3c_irqext_wake(struct irq_data
*data
, unsigned int state
)
52 unsigned long bit
= 1L << IRQ_EINT_BIT(data
->irq
);
54 if (!(s3c_irqwake_eintallow
& bit
))
57 printk(KERN_INFO
"wake %s for irq %d\n",
58 state
? "enabled" : "disabled", data
->irq
);
61 s3c_irqwake_eintmask
|= bit
;
63 s3c_irqwake_eintmask
&= ~bit
;
68 /* s3c2410_pm_show_resume_irqs
70 * print any IRQs asserted at resume time (ie, we woke from)
72 static void __maybe_unused
s3c_pm_show_resume_irqs(int start
,
80 for (i
= 0; i
<= 31; i
++) {
81 if (which
& (1L<<i
)) {
82 S3C_PMDBG("IRQ %d asserted at resume\n", start
+i
);
88 void (*pm_cpu_prep
)(void);
89 int (*pm_cpu_sleep
)(unsigned long);
91 #define any_allowed(mask, allow) (((mask) & (allow)) != (allow))
95 * central control for sleep/resume process
98 static int s3c_pm_enter(suspend_state_t state
)
101 /* ensure the debug is initialised (if enabled) */
105 S3C_PMDBG("%s(%d)\n", __func__
, state
);
107 if (pm_cpu_prep
== NULL
|| pm_cpu_sleep
== NULL
) {
108 printk(KERN_ERR
"%s: error: no cpu sleep function\n", __func__
);
112 /* check if we have anything to wake-up with... bad things seem
113 * to happen if you suspend with no wakeup (system will often
114 * require a full power-cycle)
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__
);
125 /* save all necessary core registers not covered by the drivers */
127 if (!of_have_populated_dt()) {
128 samsung_pm_save_gpios();
129 samsung_pm_saved_gpios();
135 /* set the irq configuration for wake */
137 s3c_pm_configure_extint();
139 S3C_PMDBG("sleep: irq wakeup masks: %08lx,%08lx\n",
140 s3c_irqwake_intmask
, s3c_irqwake_eintmask
);
142 s3c_pm_arch_prepare_irqs();
144 /* call cpu specific preparation */
148 /* flush cache back to ram */
152 s3c_pm_check_store();
154 /* send the cpu to sleep... */
156 s3c_pm_arch_stop_clocks();
158 /* this will also act as our return point from when
159 * we resume as it saves its own register state and restores it
160 * during the resume. */
162 ret
= cpu_suspend(0, pm_cpu_sleep
);
166 /* restore the system state */
168 s3c_pm_restore_core();
169 s3c_pm_restore_uarts();
171 if (!of_have_populated_dt()) {
172 samsung_pm_restore_gpios();
173 s3c_pm_restored_gpios();
178 /* check what irq (if any) restored the system */
180 s3c_pm_arch_show_resume_irqs();
182 S3C_PMDBG("%s: post sleep, preparing to return\n", __func__
);
184 /* LEDs should now be 1110 */
185 s3c_pm_debug_smdkled(1 << 1, 0);
187 s3c_pm_check_restore();
189 /* ok, let's return from sleep */
191 S3C_PMDBG("S3C PM Resume (post-restore)\n");
195 static int s3c_pm_prepare(void)
197 /* prepare check area if configured */
199 s3c_pm_check_prepare();
203 static void s3c_pm_finish(void)
205 s3c_pm_check_cleanup();
208 static 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
,
217 * Attach the power management functions. This should be called
218 * from the board specific initialisation if the board supports
222 int __init
s3c_pm_init(void)
224 printk("S3C Power Management, Copyright 2004 Simtec Electronics\n");
226 suspend_set_ops(&s3c_pm_ops
);