Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
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 | */ | |
1da177e4 | 13 | #include <linux/init.h> |
756c7b74 | 14 | #include <linux/module.h> |
1da177e4 LT |
15 | #include <linux/suspend.h> |
16 | #include <linux/errno.h> | |
17 | #include <linux/time.h> | |
18 | ||
a09e64fb | 19 | #include <mach/hardware.h> |
1da177e4 LT |
20 | #include <asm/memory.h> |
21 | #include <asm/system.h> | |
a09e64fb RK |
22 | #include <mach/pm.h> |
23 | #include <mach/pxa-regs.h> | |
24 | #include <mach/lubbock.h> | |
1da177e4 LT |
25 | #include <asm/mach/time.h> |
26 | ||
711be5cc EM |
27 | struct pxa_cpu_pm_fns *pxa_cpu_pm_fns; |
28 | static unsigned long *sleep_save; | |
1da177e4 | 29 | |
756c7b74 | 30 | int pxa_pm_enter(suspend_state_t state) |
1da177e4 | 31 | { |
711be5cc | 32 | unsigned long sleep_save_checksum = 0, checksum = 0; |
1da177e4 | 33 | int i; |
1da177e4 LT |
34 | |
35 | #ifdef CONFIG_IWMMXT | |
36 | /* force any iWMMXt context to ram **/ | |
afe4b25e LB |
37 | if (elf_hwcap & HWCAP_IWMMXT) |
38 | iwmmxt_task_disable(NULL); | |
1da177e4 LT |
39 | #endif |
40 | ||
512f03fd | 41 | /* 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 */ | |
649de51b | 45 | for (i = 0; i < pxa_cpu_pm_fns->save_count - 1; i++) |
512f03fd | 46 | sleep_save_checksum += sleep_save[i]; |
47 | } | |
1da177e4 | 48 | |
1da177e4 | 49 | /* *** go zzz *** */ |
711be5cc | 50 | pxa_cpu_pm_fns->enter(state); |
36c5ed23 RK |
51 | cpu_init(); |
52 | ||
512f03fd | 53 | if (state != PM_SUSPEND_STANDBY) { |
54 | /* after sleeping, validate the checksum */ | |
649de51b | 55 | for (i = 0; i < pxa_cpu_pm_fns->save_count - 1; i++) |
512f03fd | 56 | checksum += sleep_save[i]; |
1da177e4 | 57 | |
512f03fd | 58 | /* if invalid, display message and wait for a hardware reset */ |
59 | if (checksum != sleep_save_checksum) { | |
1da177e4 | 60 | #ifdef CONFIG_ARCH_LUBBOCK |
512f03fd | 61 | LUB_HEXLED = 0xbadbadc5; |
1da177e4 | 62 | #endif |
512f03fd | 63 | while (1) |
64 | pxa_cpu_pm_fns->enter(state); | |
65 | } | |
66 | pxa_cpu_pm_fns->restore(sleep_save); | |
1da177e4 LT |
67 | } |
68 | ||
711be5cc | 69 | pr_debug("*** made it back from resume\n"); |
1da177e4 LT |
70 | |
71 | return 0; | |
72 | } | |
73 | ||
756c7b74 RP |
74 | EXPORT_SYMBOL_GPL(pxa_pm_enter); |
75 | ||
1da177e4 LT |
76 | unsigned long sleep_phys_sp(void *sp) |
77 | { | |
78 | return virt_to_phys(sp); | |
79 | } | |
711be5cc EM |
80 | |
81 | static 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 | ||
4104980a RK |
89 | static int pxa_pm_prepare(void) |
90 | { | |
91 | int ret = 0; | |
92 | ||
93 | if (pxa_cpu_pm_fns && pxa_cpu_pm_fns->prepare) | |
94 | ret = pxa_cpu_pm_fns->prepare(); | |
95 | ||
96 | return ret; | |
97 | } | |
98 | ||
99 | static void pxa_pm_finish(void) | |
100 | { | |
101 | if (pxa_cpu_pm_fns && pxa_cpu_pm_fns->finish) | |
102 | pxa_cpu_pm_fns->finish(); | |
103 | } | |
104 | ||
26398a70 | 105 | static struct platform_suspend_ops pxa_pm_ops = { |
711be5cc EM |
106 | .valid = pxa_pm_valid, |
107 | .enter = pxa_pm_enter, | |
4104980a RK |
108 | .prepare = pxa_pm_prepare, |
109 | .finish = pxa_pm_finish, | |
711be5cc EM |
110 | }; |
111 | ||
112 | static int __init pxa_pm_init(void) | |
113 | { | |
114 | if (!pxa_cpu_pm_fns) { | |
115 | printk(KERN_ERR "no valid pxa_cpu_pm_fns defined\n"); | |
116 | return -EINVAL; | |
117 | } | |
118 | ||
649de51b RJ |
119 | sleep_save = kmalloc(pxa_cpu_pm_fns->save_count * sizeof(unsigned long), |
120 | GFP_KERNEL); | |
711be5cc EM |
121 | if (!sleep_save) { |
122 | printk(KERN_ERR "failed to alloc memory for pm save\n"); | |
123 | return -ENOMEM; | |
124 | } | |
125 | ||
26398a70 | 126 | suspend_set_ops(&pxa_pm_ops); |
711be5cc EM |
127 | return 0; |
128 | } | |
129 | ||
130 | device_initcall(pxa_pm_init); |