spi-topcliff-pch: Fix issue for transmitting over 4KByte
[zen-stable.git] / arch / arm / plat-samsung / pm.c
blob64ab65f0fdbc652cd1e0f165ec13bf5a61cc6377
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>
19 #include <linux/serial_core.h>
20 #include <linux/io.h>
22 #include <asm/cacheflush.h>
23 #include <asm/suspend.h>
24 #include <mach/hardware.h>
25 #include <mach/map.h>
27 #include <plat/regs-serial.h>
28 #include <mach/regs-clock.h>
29 #include <mach/regs-irq.h>
30 #include <asm/irq.h>
32 #include <plat/pm.h>
33 #include <mach/pm-core.h>
35 /* for external use */
37 unsigned long s3c_pm_flags;
39 /* Debug code:
41 * This code supports debug output to the low level UARTs for use on
42 * resume before the console layer is available.
45 #ifdef CONFIG_SAMSUNG_PM_DEBUG
46 extern void printascii(const char *);
48 void s3c_pm_dbg(const char *fmt, ...)
50 va_list va;
51 char buff[256];
53 va_start(va, fmt);
54 vsprintf(buff, fmt, va);
55 va_end(va);
57 printascii(buff);
60 static inline void s3c_pm_debug_init(void)
62 /* restart uart clocks so we can use them to output */
63 s3c_pm_debug_init_uart();
66 #else
67 #define s3c_pm_debug_init() do { } while(0)
69 #endif /* CONFIG_SAMSUNG_PM_DEBUG */
71 /* Save the UART configurations if we are configured for debug. */
73 unsigned char pm_uart_udivslot;
75 #ifdef CONFIG_SAMSUNG_PM_DEBUG
77 struct pm_uart_save uart_save[CONFIG_SERIAL_SAMSUNG_UARTS];
79 static void s3c_pm_save_uart(unsigned int uart, struct pm_uart_save *save)
81 void __iomem *regs = S3C_VA_UARTx(uart);
83 save->ulcon = __raw_readl(regs + S3C2410_ULCON);
84 save->ucon = __raw_readl(regs + S3C2410_UCON);
85 save->ufcon = __raw_readl(regs + S3C2410_UFCON);
86 save->umcon = __raw_readl(regs + S3C2410_UMCON);
87 save->ubrdiv = __raw_readl(regs + S3C2410_UBRDIV);
89 if (pm_uart_udivslot)
90 save->udivslot = __raw_readl(regs + S3C2443_DIVSLOT);
92 S3C_PMDBG("UART[%d]: ULCON=%04x, UCON=%04x, UFCON=%04x, UBRDIV=%04x\n",
93 uart, save->ulcon, save->ucon, save->ufcon, save->ubrdiv);
96 static void s3c_pm_save_uarts(void)
98 struct pm_uart_save *save = uart_save;
99 unsigned int uart;
101 for (uart = 0; uart < CONFIG_SERIAL_SAMSUNG_UARTS; uart++, save++)
102 s3c_pm_save_uart(uart, save);
105 static void s3c_pm_restore_uart(unsigned int uart, struct pm_uart_save *save)
107 void __iomem *regs = S3C_VA_UARTx(uart);
109 s3c_pm_arch_update_uart(regs, save);
111 __raw_writel(save->ulcon, regs + S3C2410_ULCON);
112 __raw_writel(save->ucon, regs + S3C2410_UCON);
113 __raw_writel(save->ufcon, regs + S3C2410_UFCON);
114 __raw_writel(save->umcon, regs + S3C2410_UMCON);
115 __raw_writel(save->ubrdiv, regs + S3C2410_UBRDIV);
117 if (pm_uart_udivslot)
118 __raw_writel(save->udivslot, regs + S3C2443_DIVSLOT);
121 static void s3c_pm_restore_uarts(void)
123 struct pm_uart_save *save = uart_save;
124 unsigned int uart;
126 for (uart = 0; uart < CONFIG_SERIAL_SAMSUNG_UARTS; uart++, save++)
127 s3c_pm_restore_uart(uart, save);
129 #else
130 static void s3c_pm_save_uarts(void) { }
131 static void s3c_pm_restore_uarts(void) { }
132 #endif
134 /* The IRQ ext-int code goes here, it is too small to currently bother
135 * with its own file. */
137 unsigned long s3c_irqwake_intmask = 0xffffffffL;
138 unsigned long s3c_irqwake_eintmask = 0xffffffffL;
140 int s3c_irqext_wake(struct irq_data *data, unsigned int state)
142 unsigned long bit = 1L << IRQ_EINT_BIT(data->irq);
144 if (!(s3c_irqwake_eintallow & bit))
145 return -ENOENT;
147 printk(KERN_INFO "wake %s for irq %d\n",
148 state ? "enabled" : "disabled", data->irq);
150 if (!state)
151 s3c_irqwake_eintmask |= bit;
152 else
153 s3c_irqwake_eintmask &= ~bit;
155 return 0;
158 /* helper functions to save and restore register state */
161 * s3c_pm_do_save() - save a set of registers for restoration on resume.
162 * @ptr: Pointer to an array of registers.
163 * @count: Size of the ptr array.
165 * Run through the list of registers given, saving their contents in the
166 * array for later restoration when we wakeup.
168 void s3c_pm_do_save(struct sleep_save *ptr, int count)
170 for (; count > 0; count--, ptr++) {
171 ptr->val = __raw_readl(ptr->reg);
172 S3C_PMDBG("saved %p value %08lx\n", ptr->reg, ptr->val);
177 * s3c_pm_do_restore() - restore register values from the save list.
178 * @ptr: Pointer to an array of registers.
179 * @count: Size of the ptr array.
181 * Restore the register values saved from s3c_pm_do_save().
183 * Note, we do not use S3C_PMDBG() in here, as the system may not have
184 * restore the UARTs state yet
187 void s3c_pm_do_restore(struct sleep_save *ptr, int count)
189 for (; count > 0; count--, ptr++) {
190 printk(KERN_DEBUG "restore %p (restore %08lx, was %08x)\n",
191 ptr->reg, ptr->val, __raw_readl(ptr->reg));
193 __raw_writel(ptr->val, ptr->reg);
198 * s3c_pm_do_restore_core() - early restore register values from save list.
200 * This is similar to s3c_pm_do_restore() except we try and minimise the
201 * side effects of the function in case registers that hardware might need
202 * to work has been restored.
204 * WARNING: Do not put any debug in here that may effect memory or use
205 * peripherals, as things may be changing!
208 void s3c_pm_do_restore_core(struct sleep_save *ptr, int count)
210 for (; count > 0; count--, ptr++)
211 __raw_writel(ptr->val, ptr->reg);
214 /* s3c2410_pm_show_resume_irqs
216 * print any IRQs asserted at resume time (ie, we woke from)
218 static void __maybe_unused s3c_pm_show_resume_irqs(int start,
219 unsigned long which,
220 unsigned long mask)
222 int i;
224 which &= ~mask;
226 for (i = 0; i <= 31; i++) {
227 if (which & (1L<<i)) {
228 S3C_PMDBG("IRQ %d asserted at resume\n", start+i);
234 void (*pm_cpu_prep)(void);
235 int (*pm_cpu_sleep)(unsigned long);
237 #define any_allowed(mask, allow) (((mask) & (allow)) != (allow))
239 /* s3c_pm_enter
241 * central control for sleep/resume process
244 static int s3c_pm_enter(suspend_state_t state)
246 /* ensure the debug is initialised (if enabled) */
248 s3c_pm_debug_init();
250 S3C_PMDBG("%s(%d)\n", __func__, state);
252 if (pm_cpu_prep == NULL || pm_cpu_sleep == NULL) {
253 printk(KERN_ERR "%s: error: no cpu sleep function\n", __func__);
254 return -EINVAL;
257 /* check if we have anything to wake-up with... bad things seem
258 * to happen if you suspend with no wakeup (system will often
259 * require a full power-cycle)
262 if (!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;
269 /* save all necessary core registers not covered by the drivers */
271 samsung_pm_save_gpios();
272 samsung_pm_saved_gpios();
273 s3c_pm_save_uarts();
274 s3c_pm_save_core();
276 /* set the irq configuration for wake */
278 s3c_pm_configure_extint();
280 S3C_PMDBG("sleep: irq wakeup masks: %08lx,%08lx\n",
281 s3c_irqwake_intmask, s3c_irqwake_eintmask);
283 s3c_pm_arch_prepare_irqs();
285 /* call cpu specific preparation */
287 pm_cpu_prep();
289 /* flush cache back to ram */
291 flush_cache_all();
293 s3c_pm_check_store();
295 /* send the cpu to sleep... */
297 s3c_pm_arch_stop_clocks();
299 /* this will also act as our return point from when
300 * we resume as it saves its own register state and restores it
301 * during the resume. */
303 cpu_suspend(0, pm_cpu_sleep);
305 /* restore the system state */
307 s3c_pm_restore_core();
308 s3c_pm_restore_uarts();
309 samsung_pm_restore_gpios();
310 s3c_pm_restored_gpios();
312 s3c_pm_debug_init();
314 /* check what irq (if any) restored the system */
316 s3c_pm_arch_show_resume_irqs();
318 S3C_PMDBG("%s: post sleep, preparing to return\n", __func__);
320 /* LEDs should now be 1110 */
321 s3c_pm_debug_smdkled(1 << 1, 0);
323 s3c_pm_check_restore();
325 /* ok, let's return from sleep */
327 S3C_PMDBG("S3C PM Resume (post-restore)\n");
328 return 0;
331 static int s3c_pm_prepare(void)
333 /* prepare check area if configured */
335 s3c_pm_check_prepare();
336 return 0;
339 static void s3c_pm_finish(void)
341 s3c_pm_check_cleanup();
344 static const struct platform_suspend_ops s3c_pm_ops = {
345 .enter = s3c_pm_enter,
346 .prepare = s3c_pm_prepare,
347 .finish = s3c_pm_finish,
348 .valid = suspend_valid_only_mem,
351 /* s3c_pm_init
353 * Attach the power management functions. This should be called
354 * from the board specific initialisation if the board supports
355 * it.
358 int __init s3c_pm_init(void)
360 printk("S3C Power Management, Copyright 2004 Simtec Electronics\n");
362 suspend_set_ops(&s3c_pm_ops);
363 return 0;