blob: b59a81a8e7d32d35d1ad9c3b1ce4cc833bf7eb7b [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 Miao711be5c2007-07-18 11:38:45 +010041 pxa_cpu_pm_fns->save(sleep_save);
Linus Torvalds1da177e2005-04-16 15:20:36 -070042
43 /* Clear sleep reset status */
44 RCSR = RCSR_SMR;
45
Linus Torvalds1da177e2005-04-16 15:20:36 -070046 /* before sleeping, calculate and save a checksum */
Eric Miao711be5c2007-07-18 11:38:45 +010047 for (i = 0; i < pxa_cpu_pm_fns->save_size - 1; i++)
48 sleep_save_checksum += sleep_save[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
50 /* *** go zzz *** */
Eric Miao711be5c2007-07-18 11:38:45 +010051 pxa_cpu_pm_fns->enter(state);
Russell King36c5ed22005-06-19 18:39:33 +010052 cpu_init();
53
Linus Torvalds1da177e2005-04-16 15:20:36 -070054 /* after sleeping, validate the checksum */
Eric Miao711be5c2007-07-18 11:38:45 +010055 for (i = 0; i < pxa_cpu_pm_fns->save_size - 1; i++)
Linus Torvalds1da177e2005-04-16 15:20:36 -070056 checksum += sleep_save[i];
57
58 /* if invalid, display message and wait for a hardware reset */
Eric Miao711be5c2007-07-18 11:38:45 +010059 if (checksum != sleep_save_checksum) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070060#ifdef CONFIG_ARCH_LUBBOCK
61 LUB_HEXLED = 0xbadbadc5;
62#endif
63 while (1)
Eric Miao711be5c2007-07-18 11:38:45 +010064 pxa_cpu_pm_fns->enter(state);
Linus Torvalds1da177e2005-04-16 15:20:36 -070065 }
66
Eric Miao711be5c2007-07-18 11:38:45 +010067 pxa_cpu_pm_fns->restore(sleep_save);
Linus Torvalds1da177e2005-04-16 15:20:36 -070068
Eric Miao711be5c2007-07-18 11:38:45 +010069 pr_debug("*** made it back from resume\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -070070
71 return 0;
72}
73
Richard Purdie756c7b72005-11-06 15:03:23 +000074EXPORT_SYMBOL_GPL(pxa_pm_enter);
75
Linus Torvalds1da177e2005-04-16 15:20:36 -070076unsigned long sleep_phys_sp(void *sp)
77{
78 return virt_to_phys(sp);
79}
Eric Miao711be5c2007-07-18 11:38:45 +010080
81static int pxa_pm_valid(suspend_state_t state)
82{
83 if (pxa_cpu_pm_fns)
84 return pxa_cpu_pm_fns->valid(state);
85
86 return -EINVAL;
87}
88
89static struct pm_ops pxa_pm_ops = {
90 .valid = pxa_pm_valid,
91 .enter = pxa_pm_enter,
92};
93
94static int __init pxa_pm_init(void)
95{
96 if (!pxa_cpu_pm_fns) {
97 printk(KERN_ERR "no valid pxa_cpu_pm_fns defined\n");
98 return -EINVAL;
99 }
100
101 sleep_save = kmalloc(pxa_cpu_pm_fns->save_size, GFP_KERNEL);
102 if (!sleep_save) {
103 printk(KERN_ERR "failed to alloc memory for pm save\n");
104 return -ENOMEM;
105 }
106
107 pm_set_ops(&pxa_pm_ops);
108 return 0;
109}
110
111device_initcall(pxa_pm_init);