blob: d7803b43473243c4ca8222a761bb87aad508641b [file] [log] [blame]
Ben Dooks64197112008-12-12 00:24:06 +00001/* linux/arch/arm/plat-s3c/pm.c
2 *
3 * Copyright 2008 Openmoko, Inc.
Ben Dooksccae9412009-11-13 22:54:14 +00004 * Copyright 2004-2008 Simtec Electronics
Ben Dooks64197112008-12-12 00:24:06 +00005 * Ben Dooks <ben@simtec.co.uk>
6 * http://armlinux.simtec.co.uk/
7 *
8 * S3C common power management (suspend to ram) support.
9 *
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.
13*/
14
15#include <linux/init.h>
16#include <linux/suspend.h>
17#include <linux/errno.h>
Ben Dooks2261e0e2008-12-12 00:24:08 +000018#include <linux/delay.h>
Tomasz Figacd3fc1b2013-05-17 18:24:29 +020019#include <linux/of.h>
Tushar Behera334a1c72014-02-14 10:32:45 +090020#include <linux/serial_s3c.h>
Ben Dooks64197112008-12-12 00:24:06 +000021#include <linux/io.h>
22
Ben Dooks2261e0e2008-12-12 00:24:08 +000023#include <asm/cacheflush.h>
Russell King2c74a0c2011-06-22 17:41:48 +010024#include <asm/suspend.h>
Ben Dooks2261e0e2008-12-12 00:24:08 +000025
Tomasz Figad6280ff2013-06-15 09:17:33 +090026#include <mach/map.h>
Kukjin Kim2857f652013-12-19 04:22:40 +090027#include <mach/regs-clock.h>
Ben Dooks2261e0e2008-12-12 00:24:08 +000028#include <mach/regs-irq.h>
Arnd Bergmann7ba80222013-03-05 11:28:29 +010029#include <mach/irqs.h>
Tomasz Figad6280ff2013-06-15 09:17:33 +090030
Ben Dooks56b34422008-12-12 00:24:12 +000031#include <asm/irq.h>
Ben Dooks2261e0e2008-12-12 00:24:08 +000032
Ben Dooks64197112008-12-12 00:24:06 +000033#include <plat/pm.h>
Ben Dooks431fb7d2010-02-05 13:52:53 +010034#include <mach/pm-core.h>
Ben Dooks64197112008-12-12 00:24:06 +000035
36/* for external use */
37
38unsigned long s3c_pm_flags;
39
Ben Dooks56b34422008-12-12 00:24:12 +000040/* The IRQ ext-int code goes here, it is too small to currently bother
41 * with its own file. */
42
43unsigned long s3c_irqwake_intmask = 0xffffffffL;
44unsigned long s3c_irqwake_eintmask = 0xffffffffL;
45
Mark Brownf5aeffb2010-12-02 14:35:38 +090046int s3c_irqext_wake(struct irq_data *data, unsigned int state)
Ben Dooks56b34422008-12-12 00:24:12 +000047{
Mark Brownf5aeffb2010-12-02 14:35:38 +090048 unsigned long bit = 1L << IRQ_EINT_BIT(data->irq);
Ben Dooks56b34422008-12-12 00:24:12 +000049
50 if (!(s3c_irqwake_eintallow & bit))
51 return -ENOENT;
52
53 printk(KERN_INFO "wake %s for irq %d\n",
Mark Brownf5aeffb2010-12-02 14:35:38 +090054 state ? "enabled" : "disabled", data->irq);
Ben Dooks56b34422008-12-12 00:24:12 +000055
56 if (!state)
57 s3c_irqwake_eintmask |= bit;
58 else
59 s3c_irqwake_eintmask &= ~bit;
60
61 return 0;
62}
Ben Dooks64197112008-12-12 00:24:06 +000063
Ben Dooks2261e0e2008-12-12 00:24:08 +000064void (*pm_cpu_prep)(void);
Russell King29cb3cd2011-07-02 09:54:01 +010065int (*pm_cpu_sleep)(unsigned long);
Ben Dooks2261e0e2008-12-12 00:24:08 +000066
67#define any_allowed(mask, allow) (((mask) & (allow)) != (allow))
68
69/* s3c_pm_enter
70 *
71 * central control for sleep/resume process
72*/
73
74static int s3c_pm_enter(suspend_state_t state)
75{
Abhilash Kesavand3fcacf2013-01-25 10:40:19 -080076 int ret;
Ben Dooks2261e0e2008-12-12 00:24:08 +000077 /* ensure the debug is initialised (if enabled) */
78
79 s3c_pm_debug_init();
80
81 S3C_PMDBG("%s(%d)\n", __func__, state);
82
83 if (pm_cpu_prep == NULL || pm_cpu_sleep == NULL) {
84 printk(KERN_ERR "%s: error: no cpu sleep function\n", __func__);
85 return -EINVAL;
86 }
87
88 /* check if we have anything to wake-up with... bad things seem
89 * to happen if you suspend with no wakeup (system will often
90 * require a full power-cycle)
91 */
92
Tomasz Figacd3fc1b2013-05-17 18:24:29 +020093 if (!of_have_populated_dt() &&
94 !any_allowed(s3c_irqwake_intmask, s3c_irqwake_intallow) &&
Ben Dooks2261e0e2008-12-12 00:24:08 +000095 !any_allowed(s3c_irqwake_eintmask, s3c_irqwake_eintallow)) {
96 printk(KERN_ERR "%s: No wake-up sources!\n", __func__);
97 printk(KERN_ERR "%s: Aborting sleep\n", __func__);
98 return -EINVAL;
99 }
100
Ben Dooks2261e0e2008-12-12 00:24:08 +0000101 /* save all necessary core registers not covered by the drivers */
102
Tomasz Figacd3fc1b2013-05-17 18:24:29 +0200103 if (!of_have_populated_dt()) {
104 samsung_pm_save_gpios();
105 samsung_pm_saved_gpios();
106 }
107
Ben Dooksd2b07fe2008-12-12 00:24:20 +0000108 s3c_pm_save_uarts();
Ben Dooks2261e0e2008-12-12 00:24:08 +0000109 s3c_pm_save_core();
110
111 /* set the irq configuration for wake */
112
113 s3c_pm_configure_extint();
114
115 S3C_PMDBG("sleep: irq wakeup masks: %08lx,%08lx\n",
116 s3c_irqwake_intmask, s3c_irqwake_eintmask);
117
118 s3c_pm_arch_prepare_irqs();
119
120 /* call cpu specific preparation */
121
122 pm_cpu_prep();
123
124 /* flush cache back to ram */
125
126 flush_cache_all();
127
128 s3c_pm_check_store();
129
130 /* send the cpu to sleep... */
131
132 s3c_pm_arch_stop_clocks();
133
Russell Kinge7089da2011-06-21 19:29:26 +0100134 /* this will also act as our return point from when
Ben Dooksfff94cd2009-03-10 11:48:07 +0000135 * we resume as it saves its own register state and restores it
136 * during the resume. */
Ben Dooks2261e0e2008-12-12 00:24:08 +0000137
Abhilash Kesavand3fcacf2013-01-25 10:40:19 -0800138 ret = cpu_suspend(0, pm_cpu_sleep);
139 if (ret)
140 return ret;
Ben Dooks2261e0e2008-12-12 00:24:08 +0000141
Ben Dooks2261e0e2008-12-12 00:24:08 +0000142 /* restore the system state */
143
144 s3c_pm_restore_core();
Ben Dooksd2b07fe2008-12-12 00:24:20 +0000145 s3c_pm_restore_uarts();
Tomasz Figacd3fc1b2013-05-17 18:24:29 +0200146
147 if (!of_have_populated_dt()) {
148 samsung_pm_restore_gpios();
149 s3c_pm_restored_gpios();
150 }
Ben Dooks2261e0e2008-12-12 00:24:08 +0000151
152 s3c_pm_debug_init();
153
154 /* check what irq (if any) restored the system */
155
156 s3c_pm_arch_show_resume_irqs();
157
158 S3C_PMDBG("%s: post sleep, preparing to return\n", __func__);
159
Ben Dooksbd117bd2009-03-10 18:19:35 +0000160 /* LEDs should now be 1110 */
161 s3c_pm_debug_smdkled(1 << 1, 0);
162
Ben Dooks2261e0e2008-12-12 00:24:08 +0000163 s3c_pm_check_restore();
164
165 /* ok, let's return from sleep */
166
167 S3C_PMDBG("S3C PM Resume (post-restore)\n");
168 return 0;
169}
170
Ben Dooksaa8aba62008-12-12 00:24:34 +0000171static int s3c_pm_prepare(void)
172{
173 /* prepare check area if configured */
174
175 s3c_pm_check_prepare();
176 return 0;
177}
178
179static void s3c_pm_finish(void)
180{
181 s3c_pm_check_cleanup();
182}
183
Lionel Debroux2f55ac02010-11-16 14:14:02 +0100184static const struct platform_suspend_ops s3c_pm_ops = {
Ben Dooks2261e0e2008-12-12 00:24:08 +0000185 .enter = s3c_pm_enter,
Ben Dooksaa8aba62008-12-12 00:24:34 +0000186 .prepare = s3c_pm_prepare,
187 .finish = s3c_pm_finish,
Ben Dooks2261e0e2008-12-12 00:24:08 +0000188 .valid = suspend_valid_only_mem,
189};
190
Ben Dooks4e59c252008-12-12 00:24:18 +0000191/* s3c_pm_init
Ben Dooks2261e0e2008-12-12 00:24:08 +0000192 *
193 * Attach the power management functions. This should be called
194 * from the board specific initialisation if the board supports
195 * it.
196*/
197
Ben Dooks4e59c252008-12-12 00:24:18 +0000198int __init s3c_pm_init(void)
Ben Dooks2261e0e2008-12-12 00:24:08 +0000199{
200 printk("S3C Power Management, Copyright 2004 Simtec Electronics\n");
201
202 suspend_set_ops(&s3c_pm_ops);
203 return 0;
204}