xref: /openbmc/linux/arch/arm/mach-pxa/pm.c (revision ce79f3a1)
11da177e4SLinus Torvalds /*
21da177e4SLinus Torvalds  * PXA250/210 Power Management Routines
31da177e4SLinus Torvalds  *
41da177e4SLinus Torvalds  * Original code for the SA11x0:
51da177e4SLinus Torvalds  * Copyright (c) 2001 Cliff Brake <cbrake@accelent.com>
61da177e4SLinus Torvalds  *
71da177e4SLinus Torvalds  * Modified for the PXA250 by Nicolas Pitre:
81da177e4SLinus Torvalds  * Copyright (c) 2002 Monta Vista Software, Inc.
91da177e4SLinus Torvalds  *
101da177e4SLinus Torvalds  * This program is free software; you can redistribute it and/or
111da177e4SLinus Torvalds  * modify it under the terms of the GNU General Public License.
121da177e4SLinus Torvalds  */
131da177e4SLinus Torvalds #include <linux/init.h>
14756c7b74SRichard Purdie #include <linux/module.h>
151da177e4SLinus Torvalds #include <linux/suspend.h>
161da177e4SLinus Torvalds #include <linux/errno.h>
175a0e3ad6STejun Heo #include <linux/slab.h>
181da177e4SLinus Torvalds 
194c25c5d2SArnd Bergmann #include "pm.h"
201da177e4SLinus Torvalds 
21711be5ccSEric Miao struct pxa_cpu_pm_fns *pxa_cpu_pm_fns;
22711be5ccSEric Miao static unsigned long *sleep_save;
231da177e4SLinus Torvalds 
pxa_pm_enter(suspend_state_t state)24756c7b74SRichard Purdie int pxa_pm_enter(suspend_state_t state)
251da177e4SLinus Torvalds {
26711be5ccSEric Miao 	unsigned long sleep_save_checksum = 0, checksum = 0;
271da177e4SLinus Torvalds 	int i;
281da177e4SLinus Torvalds 
291da177e4SLinus Torvalds #ifdef CONFIG_IWMMXT
301da177e4SLinus Torvalds 	/* force any iWMMXt context to ram **/
31afe4b25eSLennert Buytenhek 	if (elf_hwcap & HWCAP_IWMMXT)
321da177e4SLinus Torvalds 		iwmmxt_task_disable(NULL);
331da177e4SLinus Torvalds #endif
341da177e4SLinus Torvalds 
35512f03fdSeric miao 	/* skip registers saving for standby */
363d9cb0eaSEric Miao 	if (state != PM_SUSPEND_STANDBY && pxa_cpu_pm_fns->save) {
37711be5ccSEric Miao 		pxa_cpu_pm_fns->save(sleep_save);
381da177e4SLinus Torvalds 		/* before sleeping, calculate and save a checksum */
39649de51bSRobert Jarzmik 		for (i = 0; i < pxa_cpu_pm_fns->save_count - 1; i++)
40711be5ccSEric Miao 			sleep_save_checksum += sleep_save[i];
41512f03fdSeric miao 	}
42512f03fdSeric miao 
431da177e4SLinus Torvalds 	/* *** go zzz *** */
44711be5ccSEric Miao 	pxa_cpu_pm_fns->enter(state);
4536c5ed23SRussell King 
463d9cb0eaSEric Miao 	if (state != PM_SUSPEND_STANDBY && pxa_cpu_pm_fns->restore) {
471da177e4SLinus Torvalds 		/* after sleeping, validate the checksum */
48649de51bSRobert Jarzmik 		for (i = 0; i < pxa_cpu_pm_fns->save_count - 1; i++)
491da177e4SLinus Torvalds 			checksum += sleep_save[i];
501da177e4SLinus Torvalds 
511da177e4SLinus Torvalds 		/* if invalid, display message and wait for a hardware reset */
52711be5ccSEric Miao 		if (checksum != sleep_save_checksum) {
5354386145SEric Miao 
541da177e4SLinus Torvalds 			while (1)
55711be5ccSEric Miao 				pxa_cpu_pm_fns->enter(state);
561da177e4SLinus Torvalds 		}
57711be5ccSEric Miao 		pxa_cpu_pm_fns->restore(sleep_save);
58512f03fdSeric miao 	}
591da177e4SLinus Torvalds 
60711be5ccSEric Miao 	pr_debug("*** made it back from resume\n");
611da177e4SLinus Torvalds 
621da177e4SLinus Torvalds 	return 0;
631da177e4SLinus Torvalds }
641da177e4SLinus Torvalds 
65756c7b74SRichard Purdie EXPORT_SYMBOL_GPL(pxa_pm_enter);
66756c7b74SRichard Purdie 
pxa_pm_valid(suspend_state_t state)67711be5ccSEric Miao static int pxa_pm_valid(suspend_state_t state)
68711be5ccSEric Miao {
69711be5ccSEric Miao 	if (pxa_cpu_pm_fns)
70711be5ccSEric Miao 		return pxa_cpu_pm_fns->valid(state);
71711be5ccSEric Miao 
72711be5ccSEric Miao 	return -EINVAL;
73711be5ccSEric Miao }
74711be5ccSEric Miao 
pxa_pm_prepare(void)7551cdd928SPavel Machek int pxa_pm_prepare(void)
764104980aSRussell King {
774104980aSRussell King 	int ret = 0;
784104980aSRussell King 
794104980aSRussell King 	if (pxa_cpu_pm_fns && pxa_cpu_pm_fns->prepare)
804104980aSRussell King 		ret = pxa_cpu_pm_fns->prepare();
814104980aSRussell King 
824104980aSRussell King 	return ret;
834104980aSRussell King }
844104980aSRussell King 
pxa_pm_finish(void)8551cdd928SPavel Machek void pxa_pm_finish(void)
864104980aSRussell King {
874104980aSRussell King 	if (pxa_cpu_pm_fns && pxa_cpu_pm_fns->finish)
884104980aSRussell King 		pxa_cpu_pm_fns->finish();
894104980aSRussell King }
904104980aSRussell King 
912f55ac07SLionel Debroux static const struct platform_suspend_ops pxa_pm_ops = {
92711be5ccSEric Miao 	.valid		= pxa_pm_valid,
93711be5ccSEric Miao 	.enter		= pxa_pm_enter,
944104980aSRussell King 	.prepare	= pxa_pm_prepare,
954104980aSRussell King 	.finish		= pxa_pm_finish,
96711be5ccSEric Miao };
97711be5ccSEric Miao 
pxa_pm_init(void)98711be5ccSEric Miao static int __init pxa_pm_init(void)
99711be5ccSEric Miao {
100711be5ccSEric Miao 	if (!pxa_cpu_pm_fns) {
101711be5ccSEric Miao 		printk(KERN_ERR "no valid pxa_cpu_pm_fns defined\n");
102711be5ccSEric Miao 		return -EINVAL;
103711be5ccSEric Miao 	}
104711be5ccSEric Miao 
10585711105SMarkus Elfring 	sleep_save = kmalloc_array(pxa_cpu_pm_fns->save_count,
10685711105SMarkus Elfring 				   sizeof(*sleep_save),
107649de51bSRobert Jarzmik 				   GFP_KERNEL);
108c276557dSMarkus Elfring 	if (!sleep_save)
109711be5ccSEric Miao 		return -ENOMEM;
110711be5ccSEric Miao 
11126398a70SRafael J. Wysocki 	suspend_set_ops(&pxa_pm_ops);
112711be5ccSEric Miao 	return 0;
113711be5ccSEric Miao }
114711be5ccSEric Miao 
115711be5ccSEric Miao device_initcall(pxa_pm_init);
116