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