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