blob: 7693355ee637a60a5496bd980580380c0d19df39 [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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017
Russell Kinga09e64f2008-08-05 16:14:15 +010018#include <mach/pm.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070019
Eric Miao711be5c2007-07-18 11:38:45 +010020struct pxa_cpu_pm_fns *pxa_cpu_pm_fns;
21static unsigned long *sleep_save;
Linus Torvalds1da177e2005-04-16 15:20:36 -070022
Richard Purdie756c7b72005-11-06 15:03:23 +000023int pxa_pm_enter(suspend_state_t state)
Linus Torvalds1da177e2005-04-16 15:20:36 -070024{
Eric Miao711be5c2007-07-18 11:38:45 +010025 unsigned long sleep_save_checksum = 0, checksum = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070026 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -070027
28#ifdef CONFIG_IWMMXT
29 /* force any iWMMXt context to ram **/
Lennert Buytenhekafe4b252006-12-03 18:51:14 +010030 if (elf_hwcap & HWCAP_IWMMXT)
31 iwmmxt_task_disable(NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#endif
33
eric miao512f03f2008-01-14 15:50:54 +080034 /* 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 */
Robert Jarzmik649de512008-05-02 21:17:06 +010038 for (i = 0; i < pxa_cpu_pm_fns->save_count - 1; i++)
eric miao512f03f2008-01-14 15:50:54 +080039 sleep_save_checksum += sleep_save[i];
40 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070041
Linus Torvalds1da177e2005-04-16 15:20:36 -070042 /* *** go zzz *** */
Eric Miao711be5c2007-07-18 11:38:45 +010043 pxa_cpu_pm_fns->enter(state);
Russell King36c5ed22005-06-19 18:39:33 +010044 cpu_init();
45
eric miao512f03f2008-01-14 15:50:54 +080046 if (state != PM_SUSPEND_STANDBY) {
47 /* after sleeping, validate the checksum */
Robert Jarzmik649de512008-05-02 21:17:06 +010048 for (i = 0; i < pxa_cpu_pm_fns->save_count - 1; i++)
eric miao512f03f2008-01-14 15:50:54 +080049 checksum += sleep_save[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -070050
eric miao512f03f2008-01-14 15:50:54 +080051 /* if invalid, display message and wait for a hardware reset */
52 if (checksum != sleep_save_checksum) {
Eric Miao54386142009-01-19 18:43:12 +080053
54 lubbock_set_hexled(0xbadbadc5);
55
eric miao512f03f2008-01-14 15:50:54 +080056 while (1)
57 pxa_cpu_pm_fns->enter(state);
58 }
59 pxa_cpu_pm_fns->restore(sleep_save);
Linus Torvalds1da177e2005-04-16 15:20:36 -070060 }
61
Eric Miao711be5c2007-07-18 11:38:45 +010062 pr_debug("*** made it back from resume\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -070063
64 return 0;
65}
66
Richard Purdie756c7b72005-11-06 15:03:23 +000067EXPORT_SYMBOL_GPL(pxa_pm_enter);
68
Linus Torvalds1da177e2005-04-16 15:20:36 -070069unsigned long sleep_phys_sp(void *sp)
70{
71 return virt_to_phys(sp);
72}
Eric Miao711be5c2007-07-18 11:38:45 +010073
74static 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
Pavel Machek51cdd922009-06-11 23:25:09 +080082int pxa_pm_prepare(void)
Russell King41049802008-08-27 12:55:04 +010083{
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
Pavel Machek51cdd922009-06-11 23:25:09 +080092void pxa_pm_finish(void)
Russell King41049802008-08-27 12:55:04 +010093{
94 if (pxa_cpu_pm_fns && pxa_cpu_pm_fns->finish)
95 pxa_cpu_pm_fns->finish();
96}
97
Rafael J. Wysocki26398a72007-10-18 03:04:40 -070098static struct platform_suspend_ops pxa_pm_ops = {
Eric Miao711be5c2007-07-18 11:38:45 +010099 .valid = pxa_pm_valid,
100 .enter = pxa_pm_enter,
Russell King41049802008-08-27 12:55:04 +0100101 .prepare = pxa_pm_prepare,
102 .finish = pxa_pm_finish,
Eric Miao711be5c2007-07-18 11:38:45 +0100103};
104
105static 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
Robert Jarzmik649de512008-05-02 21:17:06 +0100112 sleep_save = kmalloc(pxa_cpu_pm_fns->save_count * sizeof(unsigned long),
113 GFP_KERNEL);
Eric Miao711be5c2007-07-18 11:38:45 +0100114 if (!sleep_save) {
115 printk(KERN_ERR "failed to alloc memory for pm save\n");
116 return -ENOMEM;
117 }
118
Rafael J. Wysocki26398a72007-10-18 03:04:40 -0700119 suspend_set_ops(&pxa_pm_ops);
Eric Miao711be5c2007-07-18 11:38:45 +0100120 return 0;
121}
122
123device_initcall(pxa_pm_init);