2 * PXA250/210 Power Management Routines
4 * Original code for the SA11x0:
5 * Copyright (c) 2001 Cliff Brake <cbrake@accelent.com>
7 * Modified for the PXA250 by Nicolas Pitre:
8 * Copyright (c) 2002 Monta Vista Software, Inc.
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License.
13 #include <linux/init.h>
14 #include <linux/module.h>
15 #include <linux/suspend.h>
16 #include <linux/errno.h>
20 struct pxa_cpu_pm_fns *pxa_cpu_pm_fns;
21 static unsigned long *sleep_save;
23 int pxa_pm_enter(suspend_state_t state)
25 unsigned long sleep_save_checksum = 0, checksum = 0;
29 /* force any iWMMXt context to ram **/
30 if (elf_hwcap & HWCAP_IWMMXT)
31 iwmmxt_task_disable(NULL);
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 */
38 for (i = 0; i < pxa_cpu_pm_fns->save_count - 1; i++)
39 sleep_save_checksum += sleep_save[i];
43 pxa_cpu_pm_fns->enter(state);
46 if (state != PM_SUSPEND_STANDBY) {
47 /* after sleeping, validate the checksum */
48 for (i = 0; i < pxa_cpu_pm_fns->save_count - 1; i++)
49 checksum += sleep_save[i];
51 /* if invalid, display message and wait for a hardware reset */
52 if (checksum != sleep_save_checksum) {
54 lubbock_set_hexled(0xbadbadc5);
57 pxa_cpu_pm_fns->enter(state);
59 pxa_cpu_pm_fns->restore(sleep_save);
62 pr_debug("*** made it back from resume\n");
67 EXPORT_SYMBOL_GPL(pxa_pm_enter);
69 unsigned long sleep_phys_sp(void *sp)
71 return virt_to_phys(sp);
74 static int pxa_pm_valid(suspend_state_t state)
77 return pxa_cpu_pm_fns->valid(state);
82 int pxa_pm_prepare(void)
86 if (pxa_cpu_pm_fns && pxa_cpu_pm_fns->prepare)
87 ret = pxa_cpu_pm_fns->prepare();
92 void pxa_pm_finish(void)
94 if (pxa_cpu_pm_fns && pxa_cpu_pm_fns->finish)
95 pxa_cpu_pm_fns->finish();
98 static struct platform_suspend_ops pxa_pm_ops = {
99 .valid = pxa_pm_valid,
100 .enter = pxa_pm_enter,
101 .prepare = pxa_pm_prepare,
102 .finish = pxa_pm_finish,
105 static int __init pxa_pm_init(void)
107 if (!pxa_cpu_pm_fns) {
108 printk(KERN_ERR "no valid pxa_cpu_pm_fns defined\n");
112 sleep_save = kmalloc(pxa_cpu_pm_fns->save_count * sizeof(unsigned long),
115 printk(KERN_ERR "failed to alloc memory for pm save\n");
119 suspend_set_ops(&pxa_pm_ops);
123 device_initcall(pxa_pm_init);