xref: /openbmc/linux/arch/arm/mach-pxa/pm.c (revision 51cdd928)
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>
171da177e4SLinus Torvalds 
18a09e64fbSRussell King #include <mach/pm.h>
191da177e4SLinus Torvalds 
20711be5ccSEric Miao struct pxa_cpu_pm_fns *pxa_cpu_pm_fns;
21711be5ccSEric Miao static unsigned long *sleep_save;
221da177e4SLinus Torvalds 
23756c7b74SRichard Purdie int pxa_pm_enter(suspend_state_t state)
241da177e4SLinus Torvalds {
25711be5ccSEric Miao 	unsigned long sleep_save_checksum = 0, checksum = 0;
261da177e4SLinus Torvalds 	int i;
271da177e4SLinus Torvalds 
281da177e4SLinus Torvalds #ifdef CONFIG_IWMMXT
291da177e4SLinus Torvalds 	/* force any iWMMXt context to ram **/
30afe4b25eSLennert Buytenhek 	if (elf_hwcap & HWCAP_IWMMXT)
311da177e4SLinus Torvalds 		iwmmxt_task_disable(NULL);
321da177e4SLinus Torvalds #endif
331da177e4SLinus Torvalds 
34512f03fdSeric miao 	/* skip registers saving for standby */
35512f03fdSeric miao 	if (state != PM_SUSPEND_STANDBY) {
36711be5ccSEric Miao 		pxa_cpu_pm_fns->save(sleep_save);
371da177e4SLinus Torvalds 		/* before sleeping, calculate and save a checksum */
38649de51bSRobert Jarzmik 		for (i = 0; i < pxa_cpu_pm_fns->save_count - 1; i++)
39711be5ccSEric Miao 			sleep_save_checksum += sleep_save[i];
40512f03fdSeric miao 	}
41512f03fdSeric miao 
421da177e4SLinus Torvalds 	/* *** go zzz *** */
43711be5ccSEric Miao 	pxa_cpu_pm_fns->enter(state);
4436c5ed23SRussell King 	cpu_init();
4536c5ed23SRussell King 
46512f03fdSeric miao 	if (state != PM_SUSPEND_STANDBY) {
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 
5454386145SEric Miao 			lubbock_set_hexled(0xbadbadc5);
5554386145SEric Miao 
561da177e4SLinus Torvalds 			while (1)
57711be5ccSEric Miao 				pxa_cpu_pm_fns->enter(state);
581da177e4SLinus Torvalds 		}
59711be5ccSEric Miao 		pxa_cpu_pm_fns->restore(sleep_save);
60512f03fdSeric miao 	}
611da177e4SLinus Torvalds 
62711be5ccSEric Miao 	pr_debug("*** made it back from resume\n");
631da177e4SLinus Torvalds 
641da177e4SLinus Torvalds 	return 0;
651da177e4SLinus Torvalds }
661da177e4SLinus Torvalds 
67756c7b74SRichard Purdie EXPORT_SYMBOL_GPL(pxa_pm_enter);
68756c7b74SRichard Purdie 
691da177e4SLinus Torvalds unsigned long sleep_phys_sp(void *sp)
701da177e4SLinus Torvalds {
711da177e4SLinus Torvalds 	return virt_to_phys(sp);
721da177e4SLinus Torvalds }
73711be5ccSEric Miao 
74711be5ccSEric Miao static int pxa_pm_valid(suspend_state_t state)
75711be5ccSEric Miao {
76711be5ccSEric Miao 	if (pxa_cpu_pm_fns)
77711be5ccSEric Miao 		return pxa_cpu_pm_fns->valid(state);
78711be5ccSEric Miao 
79711be5ccSEric Miao 	return -EINVAL;
80711be5ccSEric Miao }
81711be5ccSEric Miao 
8251cdd928SPavel Machek int pxa_pm_prepare(void)
834104980aSRussell King {
844104980aSRussell King 	int ret = 0;
854104980aSRussell King 
864104980aSRussell King 	if (pxa_cpu_pm_fns && pxa_cpu_pm_fns->prepare)
874104980aSRussell King 		ret = pxa_cpu_pm_fns->prepare();
884104980aSRussell King 
894104980aSRussell King 	return ret;
904104980aSRussell King }
914104980aSRussell King 
9251cdd928SPavel Machek void pxa_pm_finish(void)
934104980aSRussell King {
944104980aSRussell King 	if (pxa_cpu_pm_fns && pxa_cpu_pm_fns->finish)
954104980aSRussell King 		pxa_cpu_pm_fns->finish();
964104980aSRussell King }
974104980aSRussell King 
9826398a70SRafael J. Wysocki static struct platform_suspend_ops pxa_pm_ops = {
99711be5ccSEric Miao 	.valid		= pxa_pm_valid,
100711be5ccSEric Miao 	.enter		= pxa_pm_enter,
1014104980aSRussell King 	.prepare	= pxa_pm_prepare,
1024104980aSRussell King 	.finish		= pxa_pm_finish,
103711be5ccSEric Miao };
104711be5ccSEric Miao 
105711be5ccSEric Miao static int __init pxa_pm_init(void)
106711be5ccSEric Miao {
107711be5ccSEric Miao 	if (!pxa_cpu_pm_fns) {
108711be5ccSEric Miao 		printk(KERN_ERR "no valid pxa_cpu_pm_fns defined\n");
109711be5ccSEric Miao 		return -EINVAL;
110711be5ccSEric Miao 	}
111711be5ccSEric Miao 
112649de51bSRobert Jarzmik 	sleep_save = kmalloc(pxa_cpu_pm_fns->save_count * sizeof(unsigned long),
113649de51bSRobert Jarzmik 			     GFP_KERNEL);
114711be5ccSEric Miao 	if (!sleep_save) {
115711be5ccSEric Miao 		printk(KERN_ERR "failed to alloc memory for pm save\n");
116711be5ccSEric Miao 		return -ENOMEM;
117711be5ccSEric Miao 	}
118711be5ccSEric Miao 
11926398a70SRafael J. Wysocki 	suspend_set_ops(&pxa_pm_ops);
120711be5ccSEric Miao 	return 0;
121711be5ccSEric Miao }
122711be5ccSEric Miao 
123711be5ccSEric Miao device_initcall(pxa_pm_init);
124