blob: 166c15f629162eeef0b45b356d9eedf32218d001 [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>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090017#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070018
Russell Kinga09e64f2008-08-05 16:14:15 +010019#include <mach/pm.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020
Eric Miao711be5c2007-07-18 11:38:45 +010021struct pxa_cpu_pm_fns *pxa_cpu_pm_fns;
22static unsigned long *sleep_save;
Linus Torvalds1da177e2005-04-16 15:20:36 -070023
Richard Purdie756c7b72005-11-06 15:03:23 +000024int pxa_pm_enter(suspend_state_t state)
Linus Torvalds1da177e2005-04-16 15:20:36 -070025{
Eric Miao711be5c2007-07-18 11:38:45 +010026 unsigned long sleep_save_checksum = 0, checksum = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070027 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -070028
29#ifdef CONFIG_IWMMXT
30 /* force any iWMMXt context to ram **/
Lennert Buytenhekafe4b252006-12-03 18:51:14 +010031 if (elf_hwcap & HWCAP_IWMMXT)
32 iwmmxt_task_disable(NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#endif
34
eric miao512f03f2008-01-14 15:50:54 +080035 /* skip registers saving for standby */
36 if (state != PM_SUSPEND_STANDBY) {
37 pxa_cpu_pm_fns->save(sleep_save);
38 /* before sleeping, calculate and save a checksum */
Robert Jarzmik649de512008-05-02 21:17:06 +010039 for (i = 0; i < pxa_cpu_pm_fns->save_count - 1; i++)
eric miao512f03f2008-01-14 15:50:54 +080040 sleep_save_checksum += sleep_save[i];
41 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070042
Linus Torvalds1da177e2005-04-16 15:20:36 -070043 /* *** go zzz *** */
Eric Miao711be5c2007-07-18 11:38:45 +010044 pxa_cpu_pm_fns->enter(state);
Russell King36c5ed22005-06-19 18:39:33 +010045 cpu_init();
46
eric miao512f03f2008-01-14 15:50:54 +080047 if (state != PM_SUSPEND_STANDBY) {
48 /* after sleeping, validate the checksum */
Robert Jarzmik649de512008-05-02 21:17:06 +010049 for (i = 0; i < pxa_cpu_pm_fns->save_count - 1; i++)
eric miao512f03f2008-01-14 15:50:54 +080050 checksum += sleep_save[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -070051
eric miao512f03f2008-01-14 15:50:54 +080052 /* if invalid, display message and wait for a hardware reset */
53 if (checksum != sleep_save_checksum) {
Eric Miao54386142009-01-19 18:43:12 +080054
55 lubbock_set_hexled(0xbadbadc5);
56
eric miao512f03f2008-01-14 15:50:54 +080057 while (1)
58 pxa_cpu_pm_fns->enter(state);
59 }
60 pxa_cpu_pm_fns->restore(sleep_save);
Linus Torvalds1da177e2005-04-16 15:20:36 -070061 }
62
Eric Miao711be5c2007-07-18 11:38:45 +010063 pr_debug("*** made it back from resume\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -070064
65 return 0;
66}
67
Richard Purdie756c7b72005-11-06 15:03:23 +000068EXPORT_SYMBOL_GPL(pxa_pm_enter);
69
Linus Torvalds1da177e2005-04-16 15:20:36 -070070unsigned long sleep_phys_sp(void *sp)
71{
72 return virt_to_phys(sp);
73}
Eric Miao711be5c2007-07-18 11:38:45 +010074
75static int pxa_pm_valid(suspend_state_t state)
76{
77 if (pxa_cpu_pm_fns)
78 return pxa_cpu_pm_fns->valid(state);
79
80 return -EINVAL;
81}
82
Pavel Machek51cdd922009-06-11 23:25:09 +080083int pxa_pm_prepare(void)
Russell King41049802008-08-27 12:55:04 +010084{
85 int ret = 0;
86
87 if (pxa_cpu_pm_fns && pxa_cpu_pm_fns->prepare)
88 ret = pxa_cpu_pm_fns->prepare();
89
90 return ret;
91}
92
Pavel Machek51cdd922009-06-11 23:25:09 +080093void pxa_pm_finish(void)
Russell King41049802008-08-27 12:55:04 +010094{
95 if (pxa_cpu_pm_fns && pxa_cpu_pm_fns->finish)
96 pxa_cpu_pm_fns->finish();
97}
98
Rafael J. Wysocki26398a72007-10-18 03:04:40 -070099static struct platform_suspend_ops pxa_pm_ops = {
Eric Miao711be5c2007-07-18 11:38:45 +0100100 .valid = pxa_pm_valid,
101 .enter = pxa_pm_enter,
Russell King41049802008-08-27 12:55:04 +0100102 .prepare = pxa_pm_prepare,
103 .finish = pxa_pm_finish,
Eric Miao711be5c2007-07-18 11:38:45 +0100104};
105
106static int __init pxa_pm_init(void)
107{
108 if (!pxa_cpu_pm_fns) {
109 printk(KERN_ERR "no valid pxa_cpu_pm_fns defined\n");
110 return -EINVAL;
111 }
112
Robert Jarzmik649de512008-05-02 21:17:06 +0100113 sleep_save = kmalloc(pxa_cpu_pm_fns->save_count * sizeof(unsigned long),
114 GFP_KERNEL);
Eric Miao711be5c2007-07-18 11:38:45 +0100115 if (!sleep_save) {
116 printk(KERN_ERR "failed to alloc memory for pm save\n");
117 return -ENOMEM;
118 }
119
Rafael J. Wysocki26398a72007-10-18 03:04:40 -0700120 suspend_set_ops(&pxa_pm_ops);
Eric Miao711be5c2007-07-18 11:38:45 +0100121 return 0;
122}
123
124device_initcall(pxa_pm_init);