xref: /openbmc/linux/arch/arm/mach-pxa/pm.c (revision d3930614)
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 #include <linux/time.h>
181da177e4SLinus Torvalds 
191da177e4SLinus Torvalds #include <asm/hardware.h>
201da177e4SLinus Torvalds #include <asm/memory.h>
211da177e4SLinus Torvalds #include <asm/system.h>
22756c7b74SRichard Purdie #include <asm/arch/pm.h>
231da177e4SLinus Torvalds #include <asm/arch/pxa-regs.h>
241da177e4SLinus Torvalds #include <asm/arch/lubbock.h>
251da177e4SLinus Torvalds #include <asm/mach/time.h>
261da177e4SLinus Torvalds 
27711be5ccSEric Miao struct pxa_cpu_pm_fns *pxa_cpu_pm_fns;
28711be5ccSEric Miao static unsigned long *sleep_save;
291da177e4SLinus Torvalds 
30756c7b74SRichard Purdie int pxa_pm_enter(suspend_state_t state)
311da177e4SLinus Torvalds {
32711be5ccSEric Miao 	unsigned long sleep_save_checksum = 0, checksum = 0;
331da177e4SLinus Torvalds 	int i;
341da177e4SLinus Torvalds 
351da177e4SLinus Torvalds #ifdef CONFIG_IWMMXT
361da177e4SLinus Torvalds 	/* force any iWMMXt context to ram **/
37afe4b25eSLennert Buytenhek 	if (elf_hwcap & HWCAP_IWMMXT)
381da177e4SLinus Torvalds 		iwmmxt_task_disable(NULL);
391da177e4SLinus Torvalds #endif
401da177e4SLinus Torvalds 
41512f03fdSeric miao 	/* skip registers saving for standby */
42512f03fdSeric miao 	if (state != PM_SUSPEND_STANDBY) {
43711be5ccSEric Miao 		pxa_cpu_pm_fns->save(sleep_save);
441da177e4SLinus Torvalds 		/* before sleeping, calculate and save a checksum */
45711be5ccSEric Miao 		for (i = 0; i < pxa_cpu_pm_fns->save_size - 1; i++)
46711be5ccSEric Miao 			sleep_save_checksum += sleep_save[i];
47512f03fdSeric miao 	}
48512f03fdSeric miao 
49d3930614SDmitry Baryshkov 	/* Clear reset status */
50d3930614SDmitry Baryshkov 	RCSR = RCSR_HWR | RCSR_WDR | RCSR_SMR | RCSR_GPR;
511da177e4SLinus Torvalds 
521da177e4SLinus Torvalds 	/* *** go zzz *** */
53711be5ccSEric Miao 	pxa_cpu_pm_fns->enter(state);
5436c5ed23SRussell King 	cpu_init();
5536c5ed23SRussell King 
56512f03fdSeric miao 	if (state != PM_SUSPEND_STANDBY) {
571da177e4SLinus Torvalds 		/* after sleeping, validate the checksum */
58711be5ccSEric Miao 		for (i = 0; i < pxa_cpu_pm_fns->save_size - 1; i++)
591da177e4SLinus Torvalds 			checksum += sleep_save[i];
601da177e4SLinus Torvalds 
611da177e4SLinus Torvalds 		/* if invalid, display message and wait for a hardware reset */
62711be5ccSEric Miao 		if (checksum != sleep_save_checksum) {
631da177e4SLinus Torvalds #ifdef CONFIG_ARCH_LUBBOCK
641da177e4SLinus Torvalds 			LUB_HEXLED = 0xbadbadc5;
651da177e4SLinus Torvalds #endif
661da177e4SLinus Torvalds 			while (1)
67711be5ccSEric Miao 				pxa_cpu_pm_fns->enter(state);
681da177e4SLinus Torvalds 		}
69711be5ccSEric Miao 		pxa_cpu_pm_fns->restore(sleep_save);
70512f03fdSeric miao 	}
711da177e4SLinus Torvalds 
72711be5ccSEric Miao 	pr_debug("*** made it back from resume\n");
731da177e4SLinus Torvalds 
741da177e4SLinus Torvalds 	return 0;
751da177e4SLinus Torvalds }
761da177e4SLinus Torvalds 
77756c7b74SRichard Purdie EXPORT_SYMBOL_GPL(pxa_pm_enter);
78756c7b74SRichard Purdie 
791da177e4SLinus Torvalds unsigned long sleep_phys_sp(void *sp)
801da177e4SLinus Torvalds {
811da177e4SLinus Torvalds 	return virt_to_phys(sp);
821da177e4SLinus Torvalds }
83711be5ccSEric Miao 
84711be5ccSEric Miao static int pxa_pm_valid(suspend_state_t state)
85711be5ccSEric Miao {
86711be5ccSEric Miao 	if (pxa_cpu_pm_fns)
87711be5ccSEric Miao 		return pxa_cpu_pm_fns->valid(state);
88711be5ccSEric Miao 
89711be5ccSEric Miao 	return -EINVAL;
90711be5ccSEric Miao }
91711be5ccSEric Miao 
9226398a70SRafael J. Wysocki static struct platform_suspend_ops pxa_pm_ops = {
93711be5ccSEric Miao 	.valid		= pxa_pm_valid,
94711be5ccSEric Miao 	.enter		= pxa_pm_enter,
95711be5ccSEric Miao };
96711be5ccSEric Miao 
97711be5ccSEric Miao static int __init pxa_pm_init(void)
98711be5ccSEric Miao {
99711be5ccSEric Miao 	if (!pxa_cpu_pm_fns) {
100711be5ccSEric Miao 		printk(KERN_ERR "no valid pxa_cpu_pm_fns defined\n");
101711be5ccSEric Miao 		return -EINVAL;
102711be5ccSEric Miao 	}
103711be5ccSEric Miao 
104711be5ccSEric Miao 	sleep_save = kmalloc(pxa_cpu_pm_fns->save_size, GFP_KERNEL);
105711be5ccSEric Miao 	if (!sleep_save) {
106711be5ccSEric Miao 		printk(KERN_ERR "failed to alloc memory for pm save\n");
107711be5ccSEric Miao 		return -ENOMEM;
108711be5ccSEric Miao 	}
109711be5ccSEric Miao 
11026398a70SRafael J. Wysocki 	suspend_set_ops(&pxa_pm_ops);
111711be5ccSEric Miao 	return 0;
112711be5ccSEric Miao }
113711be5ccSEric Miao 
114711be5ccSEric Miao device_initcall(pxa_pm_init);
115