blob: 329df2152dcd8c3a590a8805ecc09bdc9701654a [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * PXA250/210 Power Management Routines
3 *
4 * Original code for the SA11x0:
5 * Copyright (c) 2001 Cliff Brake <cbrake@accelent.com>
6 *
7 * Modified for the PXA250 by Nicolas Pitre:
8 * Copyright (c) 2002 Monta Vista Software, Inc.
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License.
12 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070013#include <linux/init.h>
Richard Purdie756c7b72005-11-06 15:03:23 +000014#include <linux/module.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include <linux/suspend.h>
16#include <linux/errno.h>
17#include <linux/time.h>
18
19#include <asm/hardware.h>
20#include <asm/memory.h>
21#include <asm/system.h>
Richard Purdie756c7b72005-11-06 15:03:23 +000022#include <asm/arch/pm.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070023#include <asm/arch/pxa-regs.h>
24#include <asm/arch/lubbock.h>
25#include <asm/mach/time.h>
26
Eric Miao711be5c2007-07-18 11:38:45 +010027struct pxa_cpu_pm_fns *pxa_cpu_pm_fns;
28static unsigned long *sleep_save;
Linus Torvalds1da177e2005-04-16 15:20:36 -070029
Richard Purdie756c7b72005-11-06 15:03:23 +000030int pxa_pm_enter(suspend_state_t state)
Linus Torvalds1da177e2005-04-16 15:20:36 -070031{
Eric Miao711be5c2007-07-18 11:38:45 +010032 unsigned long sleep_save_checksum = 0, checksum = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070033 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -070034
35#ifdef CONFIG_IWMMXT
36 /* force any iWMMXt context to ram **/
Lennert Buytenhekafe4b252006-12-03 18:51:14 +010037 if (elf_hwcap & HWCAP_IWMMXT)
38 iwmmxt_task_disable(NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -070039#endif
40
eric miao512f03f2008-01-14 15:50:54 +080041 /* skip registers saving for standby */
42 if (state != PM_SUSPEND_STANDBY) {
43 pxa_cpu_pm_fns->save(sleep_save);
44 /* before sleeping, calculate and save a checksum */
Robert Jarzmik649de512008-05-02 21:17:06 +010045 for (i = 0; i < pxa_cpu_pm_fns->save_count - 1; i++)
eric miao512f03f2008-01-14 15:50:54 +080046 sleep_save_checksum += sleep_save[i];
47 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070048
Dmitry Baryshkovd3930612008-04-21 11:54:13 +010049 /* Clear reset status */
50 RCSR = RCSR_HWR | RCSR_WDR | RCSR_SMR | RCSR_GPR;
Linus Torvalds1da177e2005-04-16 15:20:36 -070051
Linus Torvalds1da177e2005-04-16 15:20:36 -070052 /* *** go zzz *** */
Eric Miao711be5c2007-07-18 11:38:45 +010053 pxa_cpu_pm_fns->enter(state);
Russell King36c5ed22005-06-19 18:39:33 +010054 cpu_init();
55
eric miao512f03f2008-01-14 15:50:54 +080056 if (state != PM_SUSPEND_STANDBY) {
57 /* after sleeping, validate the checksum */
Robert Jarzmik649de512008-05-02 21:17:06 +010058 for (i = 0; i < pxa_cpu_pm_fns->save_count - 1; i++)
eric miao512f03f2008-01-14 15:50:54 +080059 checksum += sleep_save[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -070060
eric miao512f03f2008-01-14 15:50:54 +080061 /* if invalid, display message and wait for a hardware reset */
62 if (checksum != sleep_save_checksum) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070063#ifdef CONFIG_ARCH_LUBBOCK
eric miao512f03f2008-01-14 15:50:54 +080064 LUB_HEXLED = 0xbadbadc5;
Linus Torvalds1da177e2005-04-16 15:20:36 -070065#endif
eric miao512f03f2008-01-14 15:50:54 +080066 while (1)
67 pxa_cpu_pm_fns->enter(state);
68 }
69 pxa_cpu_pm_fns->restore(sleep_save);
Linus Torvalds1da177e2005-04-16 15:20:36 -070070 }
71
Eric Miao711be5c2007-07-18 11:38:45 +010072 pr_debug("*** made it back from resume\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -070073
74 return 0;
75}
76
Richard Purdie756c7b72005-11-06 15:03:23 +000077EXPORT_SYMBOL_GPL(pxa_pm_enter);
78
Linus Torvalds1da177e2005-04-16 15:20:36 -070079unsigned long sleep_phys_sp(void *sp)
80{
81 return virt_to_phys(sp);
82}
Eric Miao711be5c2007-07-18 11:38:45 +010083
84static int pxa_pm_valid(suspend_state_t state)
85{
86 if (pxa_cpu_pm_fns)
87 return pxa_cpu_pm_fns->valid(state);
88
89 return -EINVAL;
90}
91
Rafael J. Wysocki26398a72007-10-18 03:04:40 -070092static struct platform_suspend_ops pxa_pm_ops = {
Eric Miao711be5c2007-07-18 11:38:45 +010093 .valid = pxa_pm_valid,
94 .enter = pxa_pm_enter,
95};
96
97static int __init pxa_pm_init(void)
98{
99 if (!pxa_cpu_pm_fns) {
100 printk(KERN_ERR "no valid pxa_cpu_pm_fns defined\n");
101 return -EINVAL;
102 }
103
Robert Jarzmik649de512008-05-02 21:17:06 +0100104 sleep_save = kmalloc(pxa_cpu_pm_fns->save_count * sizeof(unsigned long),
105 GFP_KERNEL);
Eric Miao711be5c2007-07-18 11:38:45 +0100106 if (!sleep_save) {
107 printk(KERN_ERR "failed to alloc memory for pm save\n");
108 return -ENOMEM;
109 }
110
Rafael J. Wysocki26398a72007-10-18 03:04:40 -0700111 suspend_set_ops(&pxa_pm_ops);
Eric Miao711be5c2007-07-18 11:38:45 +0100112 return 0;
113}
114
115device_initcall(pxa_pm_init);