aboutsummaryrefslogtreecommitdiffstats
path: root/arch/arm/plat-s3c
diff options
context:
space:
mode:
authorRussell King <rmk@dyn-67.arm.linux.org.uk>2009-03-26 18:44:43 -0400
committerRussell King <rmk+kernel@arm.linux.org.uk>2009-03-26 18:44:43 -0400
commitf5f0e17a8475dee913f362510e6a8ab987d27b9f (patch)
treeebe44e7774400730f6c15cd5a84187113c274e3d /arch/arm/plat-s3c
parent2f3ec501ba1e1a68ab9d413f143bdc8f46417fc1 (diff)
parentfff94cd9f5527bbba13aa5ea5719d16531ca8e65 (diff)
Merge branch 'next-s3c-pm' of git://aeryn.fluff.org.uk/bjdooks/linux into devel
Diffstat (limited to 'arch/arm/plat-s3c')
-rw-r--r--arch/arm/plat-s3c/Makefile5
-rw-r--r--arch/arm/plat-s3c/include/plat/pm.h174
-rw-r--r--arch/arm/plat-s3c/pm-check.c242
-rw-r--r--arch/arm/plat-s3c/pm.c363
4 files changed, 784 insertions, 0 deletions
diff --git a/arch/arm/plat-s3c/Makefile b/arch/arm/plat-s3c/Makefile
index 39195f972d5e..8d7815d25a51 100644
--- a/arch/arm/plat-s3c/Makefile
+++ b/arch/arm/plat-s3c/Makefile
@@ -18,6 +18,11 @@ obj-y += pwm-clock.o
18obj-y += gpio.o 18obj-y += gpio.o
19obj-y += gpio-config.o 19obj-y += gpio-config.o
20 20
21# PM support
22
23obj-$(CONFIG_PM) += pm.o
24obj-$(CONFIG_S3C2410_PM_CHECK) += pm-check.o
25
21# devices 26# devices
22 27
23obj-$(CONFIG_S3C_DEV_HSMMC) += dev-hsmmc.o 28obj-$(CONFIG_S3C_DEV_HSMMC) += dev-hsmmc.o
diff --git a/arch/arm/plat-s3c/include/plat/pm.h b/arch/arm/plat-s3c/include/plat/pm.h
new file mode 100644
index 000000000000..3779775133a9
--- /dev/null
+++ b/arch/arm/plat-s3c/include/plat/pm.h
@@ -0,0 +1,174 @@
1/* linux/include/asm-arm/plat-s3c24xx/pm.h
2 *
3 * Copyright (c) 2004 Simtec Electronics
4 * http://armlinux.simtec.co.uk/
5 * Written by Ben Dooks, <ben@simtec.co.uk>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10*/
11
12/* s3c_pm_init
13 *
14 * called from board at initialisation time to setup the power
15 * management
16*/
17
18#ifdef CONFIG_PM
19
20extern __init int s3c_pm_init(void);
21
22#else
23
24static inline int s3c_pm_init(void)
25{
26 return 0;
27}
28#endif
29
30/* configuration for the IRQ mask over sleep */
31extern unsigned long s3c_irqwake_intmask;
32extern unsigned long s3c_irqwake_eintmask;
33
34/* IRQ masks for IRQs allowed to go to sleep (see irq.c) */
35extern unsigned long s3c_irqwake_intallow;
36extern unsigned long s3c_irqwake_eintallow;
37
38/* per-cpu sleep functions */
39
40extern void (*pm_cpu_prep)(void);
41extern void (*pm_cpu_sleep)(void);
42
43/* Flags for PM Control */
44
45extern unsigned long s3c_pm_flags;
46
47/* from sleep.S */
48
49extern int s3c_cpu_save(unsigned long *saveblk);
50extern void s3c_cpu_resume(void);
51
52extern void s3c2410_cpu_suspend(void);
53
54extern unsigned long s3c_sleep_save_phys;
55
56/* sleep save info */
57
58/**
59 * struct sleep_save - save information for shared peripherals.
60 * @reg: Pointer to the register to save.
61 * @val: Holder for the value saved from reg.
62 *
63 * This describes a list of registers which is used by the pm core and
64 * other subsystem to save and restore register values over suspend.
65 */
66struct sleep_save {
67 void __iomem *reg;
68 unsigned long val;
69};
70
71#define SAVE_ITEM(x) \
72 { .reg = (x) }
73
74/**
75 * struct pm_uart_save - save block for core UART
76 * @ulcon: Save value for S3C2410_ULCON
77 * @ucon: Save value for S3C2410_UCON
78 * @ufcon: Save value for S3C2410_UFCON
79 * @umcon: Save value for S3C2410_UMCON
80 * @ubrdiv: Save value for S3C2410_UBRDIV
81 *
82 * Save block for UART registers to be held over sleep and restored if they
83 * are needed (say by debug).
84*/
85struct pm_uart_save {
86 u32 ulcon;
87 u32 ucon;
88 u32 ufcon;
89 u32 umcon;
90 u32 ubrdiv;
91};
92
93/* helper functions to save/restore lists of registers. */
94
95extern void s3c_pm_do_save(struct sleep_save *ptr, int count);
96extern void s3c_pm_do_restore(struct sleep_save *ptr, int count);
97extern void s3c_pm_do_restore_core(struct sleep_save *ptr, int count);
98
99#ifdef CONFIG_PM
100extern int s3c_irqext_wake(unsigned int irqno, unsigned int state);
101extern int s3c24xx_irq_suspend(struct sys_device *dev, pm_message_t state);
102extern int s3c24xx_irq_resume(struct sys_device *dev);
103#else
104#define s3c_irqext_wake NULL
105#define s3c24xx_irq_suspend NULL
106#define s3c24xx_irq_resume NULL
107#endif
108
109/* PM debug functions */
110
111#ifdef CONFIG_S3C2410_PM_DEBUG
112/**
113 * s3c_pm_dbg() - low level debug function for use in suspend/resume.
114 * @msg: The message to print.
115 *
116 * This function is used mainly to debug the resume process before the system
117 * can rely on printk/console output. It uses the low-level debugging output
118 * routine printascii() to do its work.
119 */
120extern void s3c_pm_dbg(const char *msg, ...);
121
122#define S3C_PMDBG(fmt...) s3c_pm_dbg(fmt)
123#else
124#define S3C_PMDBG(fmt...) printk(KERN_DEBUG fmt)
125#endif
126
127/* suspend memory checking */
128
129#ifdef CONFIG_S3C2410_PM_CHECK
130extern void s3c_pm_check_prepare(void);
131extern void s3c_pm_check_restore(void);
132extern void s3c_pm_check_cleanup(void);
133extern void s3c_pm_check_store(void);
134#else
135#define s3c_pm_check_prepare() do { } while(0)
136#define s3c_pm_check_restore() do { } while(0)
137#define s3c_pm_check_cleanup() do { } while(0)
138#define s3c_pm_check_store() do { } while(0)
139#endif
140
141/**
142 * s3c_pm_configure_extint() - ensure pins are correctly set for IRQ
143 *
144 * Setup all the necessary GPIO pins for waking the system on external
145 * interrupt.
146 */
147extern void s3c_pm_configure_extint(void);
148
149/**
150 * s3c_pm_restore_gpios() - restore the state of the gpios after sleep.
151 *
152 * Restore the state of the GPIO pins after sleep, which may involve ensuring
153 * that we do not glitch the state of the pins from that the bootloader's
154 * resume code has done.
155*/
156extern void s3c_pm_restore_gpios(void);
157
158/**
159 * s3c_pm_save_gpios() - save the state of the GPIOs for restoring after sleep.
160 *
161 * Save the GPIO states for resotration on resume. See s3c_pm_restore_gpios().
162 */
163extern void s3c_pm_save_gpios(void);
164
165/**
166 * s3c_pm_cb_flushcache - callback for assembly code
167 *
168 * Callback to issue flush_cache_all() as this call is
169 * not a directly callable object.
170 */
171extern void s3c_pm_cb_flushcache(void);
172
173extern void s3c_pm_save_core(void);
174extern void s3c_pm_restore_core(void);
diff --git a/arch/arm/plat-s3c/pm-check.c b/arch/arm/plat-s3c/pm-check.c
new file mode 100644
index 000000000000..39f2555564da
--- /dev/null
+++ b/arch/arm/plat-s3c/pm-check.c
@@ -0,0 +1,242 @@
1/* linux/arch/arm/plat-s3c/pm-check.c
2 * originally in linux/arch/arm/plat-s3c24xx/pm.c
3 *
4 * Copyright (c) 2004,2006,2008 Simtec Electronics
5 * http://armlinux.simtec.co.uk
6 * Ben Dooks <ben@simtec.co.uk>
7 *
8 * S3C Power Mangament - suspend/resume memory corruptiuon check.
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/kernel.h>
16#include <linux/suspend.h>
17#include <linux/init.h>
18#include <linux/crc32.h>
19#include <linux/ioport.h>
20
21#include <plat/pm.h>
22
23#if CONFIG_S3C2410_PM_CHECK_CHUNKSIZE < 1
24#error CONFIG_S3C2410_PM_CHECK_CHUNKSIZE must be a positive non-zero value
25#endif
26
27/* suspend checking code...
28 *
29 * this next area does a set of crc checks over all the installed
30 * memory, so the system can verify if the resume was ok.
31 *
32 * CONFIG_S3C2410_PM_CHECK_CHUNKSIZE defines the block-size for the CRC,
33 * increasing it will mean that the area corrupted will be less easy to spot,
34 * and reducing the size will cause the CRC save area to grow
35*/
36
37#define CHECK_CHUNKSIZE (CONFIG_S3C2410_PM_CHECK_CHUNKSIZE * 1024)
38
39static u32 crc_size; /* size needed for the crc block */
40static u32 *crcs; /* allocated over suspend/resume */
41
42typedef u32 *(run_fn_t)(struct resource *ptr, u32 *arg);
43
44/* s3c_pm_run_res
45 *
46 * go through the given resource list, and look for system ram
47*/
48
49static void s3c_pm_run_res(struct resource *ptr, run_fn_t fn, u32 *arg)
50{
51 while (ptr != NULL) {
52 if (ptr->child != NULL)
53 s3c_pm_run_res(ptr->child, fn, arg);
54
55 if ((ptr->flags & IORESOURCE_MEM) &&
56 strcmp(ptr->name, "System RAM") == 0) {
57 S3C_PMDBG("Found system RAM at %08lx..%08lx\n",
58 (unsigned long)ptr->start,
59 (unsigned long)ptr->end);
60 arg = (fn)(ptr, arg);
61 }
62
63 ptr = ptr->sibling;
64 }
65}
66
67static void s3c_pm_run_sysram(run_fn_t fn, u32 *arg)
68{
69 s3c_pm_run_res(&iomem_resource, fn, arg);
70}
71
72static u32 *s3c_pm_countram(struct resource *res, u32 *val)
73{
74 u32 size = (u32)(res->end - res->start)+1;
75
76 size += CHECK_CHUNKSIZE-1;
77 size /= CHECK_CHUNKSIZE;
78
79 S3C_PMDBG("Area %08lx..%08lx, %d blocks\n",
80 (unsigned long)res->start, (unsigned long)res->end, size);
81
82 *val += size * sizeof(u32);
83 return val;
84}
85
86/* s3c_pm_prepare_check
87 *
88 * prepare the necessary information for creating the CRCs. This
89 * must be done before the final save, as it will require memory
90 * allocating, and thus touching bits of the kernel we do not
91 * know about.
92*/
93
94void s3c_pm_check_prepare(void)
95{
96 crc_size = 0;
97
98 s3c_pm_run_sysram(s3c_pm_countram, &crc_size);
99
100 S3C_PMDBG("s3c_pm_prepare_check: %u checks needed\n", crc_size);
101
102 crcs = kmalloc(crc_size+4, GFP_KERNEL);
103 if (crcs == NULL)
104 printk(KERN_ERR "Cannot allocated CRC save area\n");
105}
106
107static u32 *s3c_pm_makecheck(struct resource *res, u32 *val)
108{
109 unsigned long addr, left;
110
111 for (addr = res->start; addr < res->end;
112 addr += CHECK_CHUNKSIZE) {
113 left = res->end - addr;
114
115 if (left > CHECK_CHUNKSIZE)
116 left = CHECK_CHUNKSIZE;
117
118 *val = crc32_le(~0, phys_to_virt(addr), left);
119 val++;
120 }
121
122 return val;
123}
124
125/* s3c_pm_check_store
126 *
127 * compute the CRC values for the memory blocks before the final
128 * sleep.
129*/
130
131void s3c_pm_check_store(void)
132{
133 if (crcs != NULL)
134 s3c_pm_run_sysram(s3c_pm_makecheck, crcs);
135}
136
137/* in_region
138 *
139 * return TRUE if the area defined by ptr..ptr+size contains the
140 * what..what+whatsz
141*/
142
143static inline int in_region(void *ptr, int size, void *what, size_t whatsz)
144{
145 if ((what+whatsz) < ptr)
146 return 0;
147
148 if (what > (ptr+size))
149 return 0;
150
151 return 1;
152}
153
154/**
155 * s3c_pm_runcheck() - helper to check a resource on restore.
156 * @res: The resource to check
157 * @vak: Pointer to list of CRC32 values to check.
158 *
159 * Called from the s3c_pm_check_restore() via s3c_pm_run_sysram(), this
160 * function runs the given memory resource checking it against the stored
161 * CRC to ensure that memory is restored. The function tries to skip as
162 * many of the areas used during the suspend process.
163 */
164static u32 *s3c_pm_runcheck(struct resource *res, u32 *val)
165{
166 void *save_at = phys_to_virt(s3c_sleep_save_phys);
167 unsigned long addr;
168 unsigned long left;
169 void *stkpage;
170 void *ptr;
171 u32 calc;
172
173 stkpage = (void *)((u32)&calc & ~PAGE_MASK);
174
175 for (addr = res->start; addr < res->end;
176 addr += CHECK_CHUNKSIZE) {
177 left = res->end - addr;
178
179 if (left > CHECK_CHUNKSIZE)
180 left = CHECK_CHUNKSIZE;
181
182 ptr = phys_to_virt(addr);
183
184 if (in_region(ptr, left, stkpage, 4096)) {
185 S3C_PMDBG("skipping %08lx, has stack in\n", addr);
186 goto skip_check;
187 }
188
189 if (in_region(ptr, left, crcs, crc_size)) {
190 S3C_PMDBG("skipping %08lx, has crc block in\n", addr);
191 goto skip_check;
192 }
193
194 if (in_region(ptr, left, save_at, 32*4 )) {
195 S3C_PMDBG("skipping %08lx, has save block in\n", addr);
196 goto skip_check;
197 }
198
199 /* calculate and check the checksum */
200
201 calc = crc32_le(~0, ptr, left);
202 if (calc != *val) {
203 printk(KERN_ERR "Restore CRC error at "
204 "%08lx (%08x vs %08x)\n", addr, calc, *val);
205
206 S3C_PMDBG("Restore CRC error at %08lx (%08x vs %08x)\n",
207 addr, calc, *val);
208 }
209
210 skip_check:
211 val++;
212 }
213
214 return val;
215}
216
217/**
218 * s3c_pm_check_restore() - memory check called on resume
219 *
220 * check the CRCs after the restore event and free the memory used
221 * to hold them
222*/
223void s3c_pm_check_restore(void)
224{
225 if (crcs != NULL)
226 s3c_pm_run_sysram(s3c_pm_runcheck, crcs);
227}
228
229/**
230 * s3c_pm_check_cleanup() - free memory resources
231 *
232 * Free the resources that where allocated by the suspend
233 * memory check code. We do this separately from the
234 * s3c_pm_check_restore() function as we cannot call any
235 * functions that might sleep during that resume.
236 */
237void s3c_pm_check_cleanup(void)
238{
239 kfree(crcs);
240 crcs = NULL;
241}
242
diff --git a/arch/arm/plat-s3c/pm.c b/arch/arm/plat-s3c/pm.c
new file mode 100644
index 000000000000..061182ca66e3
--- /dev/null
+++ b/arch/arm/plat-s3c/pm.c
@@ -0,0 +1,363 @@
1/* linux/arch/arm/plat-s3c/pm.c
2 *
3 * Copyright 2008 Openmoko, Inc.
4 * Copyright 2004,2006,2008 Simtec Electronics
5 * 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>
18#include <linux/delay.h>
19#include <linux/serial_core.h>
20#include <linux/io.h>
21
22#include <asm/cacheflush.h>
23#include <mach/hardware.h>
24
25#include <plat/regs-serial.h>
26#include <mach/regs-clock.h>
27#include <mach/regs-gpio.h>
28#include <mach/regs-mem.h>
29#include <mach/regs-irq.h>
30#include <asm/irq.h>
31
32#include <plat/pm.h>
33#include <plat/pm-core.h>
34
35/* for external use */
36
37unsigned long s3c_pm_flags;
38
39/* Debug code:
40 *
41 * This code supports debug output to the low level UARTs for use on
42 * resume before the console layer is available.
43*/
44
45#ifdef CONFIG_S3C2410_PM_DEBUG
46extern void printascii(const char *);
47
48void s3c_pm_dbg(const char *fmt, ...)
49{
50 va_list va;
51 char buff[256];
52
53 va_start(va, fmt);
54 vsprintf(buff, fmt, va);
55 va_end(va);
56
57 printascii(buff);
58}
59
60static inline void s3c_pm_debug_init(void)
61{
62 /* restart uart clocks so we can use them to output */
63 s3c_pm_debug_init_uart();
64}
65
66#else
67#define s3c_pm_debug_init() do { } while(0)
68
69#endif /* CONFIG_S3C2410_PM_DEBUG */
70
71/* Save the UART configurations if we are configured for debug. */
72
73#ifdef CONFIG_S3C2410_PM_DEBUG
74
75struct pm_uart_save uart_save[CONFIG_SERIAL_SAMSUNG_UARTS];
76
77static void s3c_pm_save_uart(unsigned int uart, struct pm_uart_save *save)
78{
79 void __iomem *regs = S3C_VA_UARTx(uart);
80
81 save->ulcon = __raw_readl(regs + S3C2410_ULCON);
82 save->ucon = __raw_readl(regs + S3C2410_UCON);
83 save->ufcon = __raw_readl(regs + S3C2410_UFCON);
84 save->umcon = __raw_readl(regs + S3C2410_UMCON);
85 save->ubrdiv = __raw_readl(regs + S3C2410_UBRDIV);
86}
87
88static void s3c_pm_save_uarts(void)
89{
90 struct pm_uart_save *save = uart_save;
91 unsigned int uart;
92
93 for (uart = 0; uart < CONFIG_SERIAL_SAMSUNG_UARTS; uart++, save++)
94 s3c_pm_save_uart(uart, save);
95}
96
97static void s3c_pm_restore_uart(unsigned int uart, struct pm_uart_save *save)
98{
99 void __iomem *regs = S3C_VA_UARTx(uart);
100
101 __raw_writel(save->ulcon, regs + S3C2410_ULCON);
102 __raw_writel(save->ucon, regs + S3C2410_UCON);
103 __raw_writel(save->ufcon, regs + S3C2410_UFCON);
104 __raw_writel(save->umcon, regs + S3C2410_UMCON);
105 __raw_writel(save->ubrdiv, regs + S3C2410_UBRDIV);
106}
107
108static void s3c_pm_restore_uarts(void)
109{
110 struct pm_uart_save *save = uart_save;
111 unsigned int uart;
112
113 for (uart = 0; uart < CONFIG_SERIAL_SAMSUNG_UARTS; uart++, save++)
114 s3c_pm_restore_uart(uart, save);
115}
116#else
117static void s3c_pm_save_uarts(void) { }
118static void s3c_pm_restore_uarts(void) { }
119#endif
120
121/* The IRQ ext-int code goes here, it is too small to currently bother
122 * with its own file. */
123
124unsigned long s3c_irqwake_intmask = 0xffffffffL;
125unsigned long s3c_irqwake_eintmask = 0xffffffffL;
126
127int s3c_irqext_wake(unsigned int irqno, unsigned int state)
128{
129 unsigned long bit = 1L << IRQ_EINT_BIT(irqno);
130
131 if (!(s3c_irqwake_eintallow & bit))
132 return -ENOENT;
133
134 printk(KERN_INFO "wake %s for irq %d\n",
135 state ? "enabled" : "disabled", irqno);
136
137 if (!state)
138 s3c_irqwake_eintmask |= bit;
139 else
140 s3c_irqwake_eintmask &= ~bit;
141
142 return 0;
143}
144
145/* helper functions to save and restore register state */
146
147/**
148 * s3c_pm_do_save() - save a set of registers for restoration on resume.
149 * @ptr: Pointer to an array of registers.
150 * @count: Size of the ptr array.
151 *
152 * Run through the list of registers given, saving their contents in the
153 * array for later restoration when we wakeup.
154 */
155void s3c_pm_do_save(struct sleep_save *ptr, int count)
156{
157 for (; count > 0; count--, ptr++) {
158 ptr->val = __raw_readl(ptr->reg);
159 S3C_PMDBG("saved %p value %08lx\n", ptr->reg, ptr->val);
160 }
161}
162
163/**
164 * s3c_pm_do_restore() - restore register values from the save list.
165 * @ptr: Pointer to an array of registers.
166 * @count: Size of the ptr array.
167 *
168 * Restore the register values saved from s3c_pm_do_save().
169 *
170 * Note, we do not use S3C_PMDBG() in here, as the system may not have
171 * restore the UARTs state yet
172*/
173
174void s3c_pm_do_restore(struct sleep_save *ptr, int count)
175{
176 for (; count > 0; count--, ptr++) {
177 printk(KERN_DEBUG "restore %p (restore %08lx, was %08x)\n",
178 ptr->reg, ptr->val, __raw_readl(ptr->reg));
179
180 __raw_writel(ptr->val, ptr->reg);
181 }
182}
183
184/**
185 * s3c_pm_do_restore_core() - early restore register values from save list.
186 *
187 * This is similar to s3c_pm_do_restore() except we try and minimise the
188 * side effects of the function in case registers that hardware might need
189 * to work has been restored.
190 *
191 * WARNING: Do not put any debug in here that may effect memory or use
192 * peripherals, as things may be changing!
193*/
194
195void s3c_pm_do_restore_core(struct sleep_save *ptr, int count)
196{
197 for (; count > 0; count--, ptr++)
198 __raw_writel(ptr->val, ptr->reg);
199}
200
201/* s3c2410_pm_show_resume_irqs
202 *
203 * print any IRQs asserted at resume time (ie, we woke from)
204*/
205static void s3c_pm_show_resume_irqs(int start, unsigned long which,
206 unsigned long mask)
207{
208 int i;
209
210 which &= ~mask;
211
212 for (i = 0; i <= 31; i++) {
213 if (which & (1L<<i)) {
214 S3C_PMDBG("IRQ %d asserted at resume\n", start+i);
215 }
216 }
217}
218
219
220void (*pm_cpu_prep)(void);
221void (*pm_cpu_sleep)(void);
222
223#define any_allowed(mask, allow) (((mask) & (allow)) != (allow))
224
225/* s3c_pm_enter
226 *
227 * central control for sleep/resume process
228*/
229
230static int s3c_pm_enter(suspend_state_t state)
231{
232 static unsigned long regs_save[16];
233
234 /* ensure the debug is initialised (if enabled) */
235
236 s3c_pm_debug_init();
237
238 S3C_PMDBG("%s(%d)\n", __func__, state);
239
240 if (pm_cpu_prep == NULL || pm_cpu_sleep == NULL) {
241 printk(KERN_ERR "%s: error: no cpu sleep function\n", __func__);
242 return -EINVAL;
243 }
244
245 /* check if we have anything to wake-up with... bad things seem
246 * to happen if you suspend with no wakeup (system will often
247 * require a full power-cycle)
248 */
249
250 if (!any_allowed(s3c_irqwake_intmask, s3c_irqwake_intallow) &&
251 !any_allowed(s3c_irqwake_eintmask, s3c_irqwake_eintallow)) {
252 printk(KERN_ERR "%s: No wake-up sources!\n", __func__);
253 printk(KERN_ERR "%s: Aborting sleep\n", __func__);
254 return -EINVAL;
255 }
256
257 /* store the physical address of the register recovery block */
258
259 s3c_sleep_save_phys = virt_to_phys(regs_save);
260
261 S3C_PMDBG("s3c_sleep_save_phys=0x%08lx\n", s3c_sleep_save_phys);
262
263 /* save all necessary core registers not covered by the drivers */
264
265 s3c_pm_save_gpios();
266 s3c_pm_save_uarts();
267 s3c_pm_save_core();
268
269 /* set the irq configuration for wake */
270
271 s3c_pm_configure_extint();
272
273 S3C_PMDBG("sleep: irq wakeup masks: %08lx,%08lx\n",
274 s3c_irqwake_intmask, s3c_irqwake_eintmask);
275
276 s3c_pm_arch_prepare_irqs();
277
278 /* call cpu specific preparation */
279
280 pm_cpu_prep();
281
282 /* flush cache back to ram */
283
284 flush_cache_all();
285
286 s3c_pm_check_store();
287
288 /* send the cpu to sleep... */
289
290 s3c_pm_arch_stop_clocks();
291
292 /* s3c_cpu_save will also act as our return point from when
293 * we resume as it saves its own register state and restores it
294 * during the resume. */
295
296 s3c_cpu_save(regs_save);
297
298 /* restore the cpu state using the kernel's cpu init code. */
299
300 cpu_init();
301
302 /* restore the system state */
303
304 s3c_pm_restore_core();
305 s3c_pm_restore_uarts();
306 s3c_pm_restore_gpios();
307
308 s3c_pm_debug_init();
309
310 /* check what irq (if any) restored the system */
311
312 s3c_pm_arch_show_resume_irqs();
313
314 S3C_PMDBG("%s: post sleep, preparing to return\n", __func__);
315
316 s3c_pm_check_restore();
317
318 /* ok, let's return from sleep */
319
320 S3C_PMDBG("S3C PM Resume (post-restore)\n");
321 return 0;
322}
323
324/* callback from assembly code */
325void s3c_pm_cb_flushcache(void)
326{
327 flush_cache_all();
328}
329
330static int s3c_pm_prepare(void)
331{
332 /* prepare check area if configured */
333
334 s3c_pm_check_prepare();
335 return 0;
336}
337
338static void s3c_pm_finish(void)
339{
340 s3c_pm_check_cleanup();
341}
342
343static struct platform_suspend_ops s3c_pm_ops = {
344 .enter = s3c_pm_enter,
345 .prepare = s3c_pm_prepare,
346 .finish = s3c_pm_finish,
347 .valid = suspend_valid_only_mem,
348};
349
350/* s3c_pm_init
351 *
352 * Attach the power management functions. This should be called
353 * from the board specific initialisation if the board supports
354 * it.
355*/
356
357int __init s3c_pm_init(void)
358{
359 printk("S3C Power Management, Copyright 2004 Simtec Electronics\n");
360
361 suspend_set_ops(&s3c_pm_ops);
362 return 0;
363}