xref: /openbmc/linux/arch/arm/mach-sa1100/pm.c (revision 2f82af08fcc7dc01a7e98a49a5995a77e32a2925)
11da177e4SLinus Torvalds /*
21da177e4SLinus Torvalds  * SA1100 Power Management Routines
31da177e4SLinus Torvalds  *
41da177e4SLinus Torvalds  * Copyright (c) 2001 Cliff Brake <cbrake@accelent.com>
51da177e4SLinus Torvalds  *
61da177e4SLinus Torvalds  * This program is free software; you can redistribute it and/or
71da177e4SLinus Torvalds  * modify it under the terms of the GNU General Public License.
81da177e4SLinus Torvalds  *
91da177e4SLinus Torvalds  * History:
101da177e4SLinus Torvalds  *
111da177e4SLinus Torvalds  * 2001-02-06:	Cliff Brake         Initial code
121da177e4SLinus Torvalds  *
131da177e4SLinus Torvalds  * 2001-02-25:	Sukjae Cho <sjcho@east.isi.edu> &
141da177e4SLinus Torvalds  * 		Chester Kuo <chester@linux.org.tw>
151da177e4SLinus Torvalds  * 			Save more value for the resume function! Support
161da177e4SLinus Torvalds  * 			Bitsy/Assabet/Freebird board
171da177e4SLinus Torvalds  *
18*2f82af08SNicolas Pitre  * 2001-08-29:	Nicolas Pitre <nico@fluxnic.net>
191da177e4SLinus Torvalds  * 			Cleaned up, pushed platform dependent stuff
201da177e4SLinus Torvalds  * 			in the platform specific files.
211da177e4SLinus Torvalds  *
221da177e4SLinus Torvalds  * 2002-05-27:	Nicolas Pitre	Killed sleep.h and the kmalloced save array.
231da177e4SLinus Torvalds  * 				Storage is local on the stack now.
241da177e4SLinus Torvalds  */
251da177e4SLinus Torvalds #include <linux/init.h>
261da177e4SLinus Torvalds #include <linux/suspend.h>
271da177e4SLinus Torvalds #include <linux/errno.h>
281da177e4SLinus Torvalds #include <linux/time.h>
291da177e4SLinus Torvalds 
30a09e64fbSRussell King #include <mach/hardware.h>
311da177e4SLinus Torvalds #include <asm/memory.h>
321da177e4SLinus Torvalds #include <asm/system.h>
331da177e4SLinus Torvalds #include <asm/mach/time.h>
341da177e4SLinus Torvalds 
351da177e4SLinus Torvalds extern void sa1100_cpu_suspend(void);
361da177e4SLinus Torvalds extern void sa1100_cpu_resume(void);
371da177e4SLinus Torvalds 
381da177e4SLinus Torvalds #define SAVE(x)		sleep_save[SLEEP_SAVE_##x] = x
391da177e4SLinus Torvalds #define RESTORE(x)	x = sleep_save[SLEEP_SAVE_##x]
401da177e4SLinus Torvalds 
411da177e4SLinus Torvalds /*
421da177e4SLinus Torvalds  * List of global SA11x0 peripheral registers to preserve.
431da177e4SLinus Torvalds  * More ones like CP and general purpose register values are preserved
441da177e4SLinus Torvalds  * on the stack and then the stack pointer is stored last in sleep.S.
451da177e4SLinus Torvalds  */
46649de51bSRobert Jarzmik enum {	SLEEP_SAVE_GPDR, SLEEP_SAVE_GAFR,
471da177e4SLinus Torvalds 	SLEEP_SAVE_PPDR, SLEEP_SAVE_PPSR, SLEEP_SAVE_PPAR, SLEEP_SAVE_PSDR,
481da177e4SLinus Torvalds 
491da177e4SLinus Torvalds 	SLEEP_SAVE_Ser1SDCR0,
501da177e4SLinus Torvalds 
51649de51bSRobert Jarzmik 	SLEEP_SAVE_COUNT
521da177e4SLinus Torvalds };
531da177e4SLinus Torvalds 
541da177e4SLinus Torvalds 
551da177e4SLinus Torvalds static int sa11x0_pm_enter(suspend_state_t state)
561da177e4SLinus Torvalds {
57649de51bSRobert Jarzmik 	unsigned long gpio, sleep_save[SLEEP_SAVE_COUNT];
581da177e4SLinus Torvalds 
591da177e4SLinus Torvalds 	gpio = GPLR;
601da177e4SLinus Torvalds 
611da177e4SLinus Torvalds 	/* save vital registers */
621da177e4SLinus Torvalds 	SAVE(GPDR);
631da177e4SLinus Torvalds 	SAVE(GAFR);
641da177e4SLinus Torvalds 
651da177e4SLinus Torvalds 	SAVE(PPDR);
661da177e4SLinus Torvalds 	SAVE(PPSR);
671da177e4SLinus Torvalds 	SAVE(PPAR);
681da177e4SLinus Torvalds 	SAVE(PSDR);
691da177e4SLinus Torvalds 
701da177e4SLinus Torvalds 	SAVE(Ser1SDCR0);
711da177e4SLinus Torvalds 
721da177e4SLinus Torvalds 	/* Clear previous reset status */
731da177e4SLinus Torvalds 	RCSR = RCSR_HWR | RCSR_SWR | RCSR_WDR | RCSR_SMR;
741da177e4SLinus Torvalds 
751da177e4SLinus Torvalds 	/* set resume return address */
761da177e4SLinus Torvalds 	PSPR = virt_to_phys(sa1100_cpu_resume);
771da177e4SLinus Torvalds 
781da177e4SLinus Torvalds 	/* go zzz */
791da177e4SLinus Torvalds 	sa1100_cpu_suspend();
801da177e4SLinus Torvalds 
8136c5ed23SRussell King 	cpu_init();
8236c5ed23SRussell King 
831da177e4SLinus Torvalds 	/*
841da177e4SLinus Torvalds 	 * Ensure not to come back here if it wasn't intended
851da177e4SLinus Torvalds 	 */
861da177e4SLinus Torvalds 	PSPR = 0;
871da177e4SLinus Torvalds 
881da177e4SLinus Torvalds 	/*
891da177e4SLinus Torvalds 	 * Ensure interrupt sources are disabled; we will re-init
901da177e4SLinus Torvalds 	 * the interrupt subsystem via the device manager.
911da177e4SLinus Torvalds 	 */
921da177e4SLinus Torvalds 	ICLR = 0;
931da177e4SLinus Torvalds 	ICCR = 1;
941da177e4SLinus Torvalds 	ICMR = 0;
951da177e4SLinus Torvalds 
961da177e4SLinus Torvalds 	/* restore registers */
971da177e4SLinus Torvalds 	RESTORE(GPDR);
981da177e4SLinus Torvalds 	RESTORE(GAFR);
991da177e4SLinus Torvalds 
1001da177e4SLinus Torvalds 	RESTORE(PPDR);
1011da177e4SLinus Torvalds 	RESTORE(PPSR);
1021da177e4SLinus Torvalds 	RESTORE(PPAR);
1031da177e4SLinus Torvalds 	RESTORE(PSDR);
1041da177e4SLinus Torvalds 
1051da177e4SLinus Torvalds 	RESTORE(Ser1SDCR0);
1061da177e4SLinus Torvalds 
1071da177e4SLinus Torvalds 	GPSR = gpio;
1081da177e4SLinus Torvalds 	GPCR = ~gpio;
1091da177e4SLinus Torvalds 
1101da177e4SLinus Torvalds 	/*
1111da177e4SLinus Torvalds 	 * Clear the peripheral sleep-hold bit.
1121da177e4SLinus Torvalds 	 */
1131da177e4SLinus Torvalds 	PSSR = PSSR_PH;
1141da177e4SLinus Torvalds 
1151da177e4SLinus Torvalds 	return 0;
1161da177e4SLinus Torvalds }
1171da177e4SLinus Torvalds 
1181da177e4SLinus Torvalds unsigned long sleep_phys_sp(void *sp)
1191da177e4SLinus Torvalds {
1201da177e4SLinus Torvalds 	return virt_to_phys(sp);
1211da177e4SLinus Torvalds }
1221da177e4SLinus Torvalds 
12326398a70SRafael J. Wysocki static struct platform_suspend_ops sa11x0_pm_ops = {
1241da177e4SLinus Torvalds 	.enter		= sa11x0_pm_enter,
12526398a70SRafael J. Wysocki 	.valid		= suspend_valid_only_mem,
1261da177e4SLinus Torvalds };
1271da177e4SLinus Torvalds 
1281da177e4SLinus Torvalds static int __init sa11x0_pm_init(void)
1291da177e4SLinus Torvalds {
13026398a70SRafael J. Wysocki 	suspend_set_ops(&sa11x0_pm_ops);
1311da177e4SLinus Torvalds 	return 0;
1321da177e4SLinus Torvalds }
1331da177e4SLinus Torvalds 
1341da177e4SLinus Torvalds late_initcall(sa11x0_pm_init);
135