| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | #include <linux/init.h> | 
| Richard Purdie | 756c7b7 | 2005-11-06 15:03:23 +0000 | [diff] [blame] | 14 | #include <linux/module.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | #include <linux/suspend.h> | 
|  | 16 | #include <linux/errno.h> | 
| Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 17 | #include <linux/slab.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 |  | 
| Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 19 | #include <mach/pm.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 |  | 
| Eric Miao | 711be5c | 2007-07-18 11:38:45 +0100 | [diff] [blame] | 21 | struct pxa_cpu_pm_fns *pxa_cpu_pm_fns; | 
|  | 22 | static unsigned long *sleep_save; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 |  | 
| Richard Purdie | 756c7b7 | 2005-11-06 15:03:23 +0000 | [diff] [blame] | 24 | int pxa_pm_enter(suspend_state_t state) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | { | 
| Eric Miao | 711be5c | 2007-07-18 11:38:45 +0100 | [diff] [blame] | 26 | unsigned long sleep_save_checksum = 0, checksum = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | int i; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 |  | 
|  | 29 | #ifdef CONFIG_IWMMXT | 
|  | 30 | /* force any iWMMXt context to ram **/ | 
| Lennert Buytenhek | afe4b25 | 2006-12-03 18:51:14 +0100 | [diff] [blame] | 31 | if (elf_hwcap & HWCAP_IWMMXT) | 
|  | 32 | iwmmxt_task_disable(NULL); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | #endif | 
|  | 34 |  | 
| eric miao | 512f03f | 2008-01-14 15:50:54 +0800 | [diff] [blame] | 35 | /* skip registers saving for standby */ | 
| Eric Miao | 3d9cb0e | 2011-01-26 05:04:00 +0800 | [diff] [blame] | 36 | if (state != PM_SUSPEND_STANDBY && pxa_cpu_pm_fns->save) { | 
| eric miao | 512f03f | 2008-01-14 15:50:54 +0800 | [diff] [blame] | 37 | pxa_cpu_pm_fns->save(sleep_save); | 
|  | 38 | /* before sleeping, calculate and save a checksum */ | 
| Robert Jarzmik | 649de51 | 2008-05-02 21:17:06 +0100 | [diff] [blame] | 39 | for (i = 0; i < pxa_cpu_pm_fns->save_count - 1; i++) | 
| eric miao | 512f03f | 2008-01-14 15:50:54 +0800 | [diff] [blame] | 40 | sleep_save_checksum += sleep_save[i]; | 
|  | 41 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | /* *** go zzz *** */ | 
| Eric Miao | 711be5c | 2007-07-18 11:38:45 +0100 | [diff] [blame] | 44 | pxa_cpu_pm_fns->enter(state); | 
| Russell King | 36c5ed2 | 2005-06-19 18:39:33 +0100 | [diff] [blame] | 45 | cpu_init(); | 
|  | 46 |  | 
| Eric Miao | 3d9cb0e | 2011-01-26 05:04:00 +0800 | [diff] [blame] | 47 | if (state != PM_SUSPEND_STANDBY && pxa_cpu_pm_fns->restore) { | 
| eric miao | 512f03f | 2008-01-14 15:50:54 +0800 | [diff] [blame] | 48 | /* after sleeping, validate the checksum */ | 
| Robert Jarzmik | 649de51 | 2008-05-02 21:17:06 +0100 | [diff] [blame] | 49 | for (i = 0; i < pxa_cpu_pm_fns->save_count - 1; i++) | 
| eric miao | 512f03f | 2008-01-14 15:50:54 +0800 | [diff] [blame] | 50 | checksum += sleep_save[i]; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 |  | 
| eric miao | 512f03f | 2008-01-14 15:50:54 +0800 | [diff] [blame] | 52 | /* if invalid, display message and wait for a hardware reset */ | 
|  | 53 | if (checksum != sleep_save_checksum) { | 
| Eric Miao | 5438614 | 2009-01-19 18:43:12 +0800 | [diff] [blame] | 54 |  | 
|  | 55 | lubbock_set_hexled(0xbadbadc5); | 
|  | 56 |  | 
| eric miao | 512f03f | 2008-01-14 15:50:54 +0800 | [diff] [blame] | 57 | while (1) | 
|  | 58 | pxa_cpu_pm_fns->enter(state); | 
|  | 59 | } | 
|  | 60 | pxa_cpu_pm_fns->restore(sleep_save); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | } | 
|  | 62 |  | 
| Eric Miao | 711be5c | 2007-07-18 11:38:45 +0100 | [diff] [blame] | 63 | pr_debug("*** made it back from resume\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 |  | 
|  | 65 | return 0; | 
|  | 66 | } | 
|  | 67 |  | 
| Richard Purdie | 756c7b7 | 2005-11-06 15:03:23 +0000 | [diff] [blame] | 68 | EXPORT_SYMBOL_GPL(pxa_pm_enter); | 
|  | 69 |  | 
| Eric Miao | 711be5c | 2007-07-18 11:38:45 +0100 | [diff] [blame] | 70 | static int pxa_pm_valid(suspend_state_t state) | 
|  | 71 | { | 
|  | 72 | if (pxa_cpu_pm_fns) | 
|  | 73 | return pxa_cpu_pm_fns->valid(state); | 
|  | 74 |  | 
|  | 75 | return -EINVAL; | 
|  | 76 | } | 
|  | 77 |  | 
| Pavel Machek | 51cdd92 | 2009-06-11 23:25:09 +0800 | [diff] [blame] | 78 | int pxa_pm_prepare(void) | 
| Russell King | 4104980 | 2008-08-27 12:55:04 +0100 | [diff] [blame] | 79 | { | 
|  | 80 | int ret = 0; | 
|  | 81 |  | 
|  | 82 | if (pxa_cpu_pm_fns && pxa_cpu_pm_fns->prepare) | 
|  | 83 | ret = pxa_cpu_pm_fns->prepare(); | 
|  | 84 |  | 
|  | 85 | return ret; | 
|  | 86 | } | 
|  | 87 |  | 
| Pavel Machek | 51cdd92 | 2009-06-11 23:25:09 +0800 | [diff] [blame] | 88 | void pxa_pm_finish(void) | 
| Russell King | 4104980 | 2008-08-27 12:55:04 +0100 | [diff] [blame] | 89 | { | 
|  | 90 | if (pxa_cpu_pm_fns && pxa_cpu_pm_fns->finish) | 
|  | 91 | pxa_cpu_pm_fns->finish(); | 
|  | 92 | } | 
|  | 93 |  | 
| Lionel Debroux | 2f55ac0 | 2010-11-16 14:14:02 +0100 | [diff] [blame] | 94 | static const struct platform_suspend_ops pxa_pm_ops = { | 
| Eric Miao | 711be5c | 2007-07-18 11:38:45 +0100 | [diff] [blame] | 95 | .valid		= pxa_pm_valid, | 
|  | 96 | .enter		= pxa_pm_enter, | 
| Russell King | 4104980 | 2008-08-27 12:55:04 +0100 | [diff] [blame] | 97 | .prepare	= pxa_pm_prepare, | 
|  | 98 | .finish		= pxa_pm_finish, | 
| Eric Miao | 711be5c | 2007-07-18 11:38:45 +0100 | [diff] [blame] | 99 | }; | 
|  | 100 |  | 
|  | 101 | static int __init pxa_pm_init(void) | 
|  | 102 | { | 
|  | 103 | if (!pxa_cpu_pm_fns) { | 
|  | 104 | printk(KERN_ERR "no valid pxa_cpu_pm_fns defined\n"); | 
|  | 105 | return -EINVAL; | 
|  | 106 | } | 
|  | 107 |  | 
| Robert Jarzmik | 649de51 | 2008-05-02 21:17:06 +0100 | [diff] [blame] | 108 | sleep_save = kmalloc(pxa_cpu_pm_fns->save_count * sizeof(unsigned long), | 
|  | 109 | GFP_KERNEL); | 
| Eric Miao | 711be5c | 2007-07-18 11:38:45 +0100 | [diff] [blame] | 110 | if (!sleep_save) { | 
|  | 111 | printk(KERN_ERR "failed to alloc memory for pm save\n"); | 
|  | 112 | return -ENOMEM; | 
|  | 113 | } | 
|  | 114 |  | 
| Rafael J. Wysocki | 26398a7 | 2007-10-18 03:04:40 -0700 | [diff] [blame] | 115 | suspend_set_ops(&pxa_pm_ops); | 
| Eric Miao | 711be5c | 2007-07-18 11:38:45 +0100 | [diff] [blame] | 116 | return 0; | 
|  | 117 | } | 
|  | 118 |  | 
|  | 119 | device_initcall(pxa_pm_init); |