xref: /openbmc/linux/arch/arm/mach-sa1100/pm.c (revision 7fea1ba58e61c17fb59dfc50c408945f307addc6)
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  *
182f82af08SNicolas 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>
322c74a0ceSRussell King #include <asm/suspend.h>
331da177e4SLinus Torvalds #include <asm/mach/time.h>
341da177e4SLinus Torvalds 
3529cb3cd2SRussell King extern int sa1100_finish_suspend(unsigned long);
361da177e4SLinus Torvalds 
371da177e4SLinus Torvalds #define SAVE(x)		sleep_save[SLEEP_SAVE_##x] = x
381da177e4SLinus Torvalds #define RESTORE(x)	x = sleep_save[SLEEP_SAVE_##x]
391da177e4SLinus Torvalds 
401da177e4SLinus Torvalds /*
411da177e4SLinus Torvalds  * List of global SA11x0 peripheral registers to preserve.
421da177e4SLinus Torvalds  * More ones like CP and general purpose register values are preserved
431da177e4SLinus Torvalds  * on the stack and then the stack pointer is stored last in sleep.S.
441da177e4SLinus Torvalds  */
45649de51bSRobert Jarzmik enum {	SLEEP_SAVE_GPDR, SLEEP_SAVE_GAFR,
461da177e4SLinus Torvalds 	SLEEP_SAVE_PPDR, SLEEP_SAVE_PPSR, SLEEP_SAVE_PPAR, SLEEP_SAVE_PSDR,
471da177e4SLinus Torvalds 
481da177e4SLinus Torvalds 	SLEEP_SAVE_Ser1SDCR0,
491da177e4SLinus Torvalds 
50649de51bSRobert Jarzmik 	SLEEP_SAVE_COUNT
511da177e4SLinus Torvalds };
521da177e4SLinus Torvalds 
531da177e4SLinus Torvalds 
541da177e4SLinus Torvalds static int sa11x0_pm_enter(suspend_state_t state)
551da177e4SLinus Torvalds {
56649de51bSRobert Jarzmik 	unsigned long gpio, sleep_save[SLEEP_SAVE_COUNT];
571da177e4SLinus Torvalds 
581da177e4SLinus Torvalds 	gpio = GPLR;
591da177e4SLinus Torvalds 
601da177e4SLinus Torvalds 	/* save vital registers */
611da177e4SLinus Torvalds 	SAVE(GPDR);
621da177e4SLinus Torvalds 	SAVE(GAFR);
631da177e4SLinus Torvalds 
641da177e4SLinus Torvalds 	SAVE(PPDR);
651da177e4SLinus Torvalds 	SAVE(PPSR);
661da177e4SLinus Torvalds 	SAVE(PPAR);
671da177e4SLinus Torvalds 	SAVE(PSDR);
681da177e4SLinus Torvalds 
691da177e4SLinus Torvalds 	SAVE(Ser1SDCR0);
701da177e4SLinus Torvalds 
711da177e4SLinus Torvalds 	/* Clear previous reset status */
721da177e4SLinus Torvalds 	RCSR = RCSR_HWR | RCSR_SWR | RCSR_WDR | RCSR_SMR;
731da177e4SLinus Torvalds 
741da177e4SLinus Torvalds 	/* set resume return address */
7596c20015SRussell King 	PSPR = virt_to_phys(cpu_resume);
761da177e4SLinus Torvalds 
771da177e4SLinus Torvalds 	/* go zzz */
782c74a0ceSRussell King 	cpu_suspend(0, sa1100_finish_suspend);
791da177e4SLinus Torvalds 
801da177e4SLinus Torvalds 	/*
811da177e4SLinus Torvalds 	 * Ensure not to come back here if it wasn't intended
821da177e4SLinus Torvalds 	 */
831da177e4SLinus Torvalds 	PSPR = 0;
841da177e4SLinus Torvalds 
851da177e4SLinus Torvalds 	/*
861da177e4SLinus Torvalds 	 * Ensure interrupt sources are disabled; we will re-init
871da177e4SLinus Torvalds 	 * the interrupt subsystem via the device manager.
881da177e4SLinus Torvalds 	 */
891da177e4SLinus Torvalds 	ICLR = 0;
901da177e4SLinus Torvalds 	ICCR = 1;
911da177e4SLinus Torvalds 	ICMR = 0;
921da177e4SLinus Torvalds 
931da177e4SLinus Torvalds 	/* restore registers */
941da177e4SLinus Torvalds 	RESTORE(GPDR);
951da177e4SLinus Torvalds 	RESTORE(GAFR);
961da177e4SLinus Torvalds 
971da177e4SLinus Torvalds 	RESTORE(PPDR);
981da177e4SLinus Torvalds 	RESTORE(PPSR);
991da177e4SLinus Torvalds 	RESTORE(PPAR);
1001da177e4SLinus Torvalds 	RESTORE(PSDR);
1011da177e4SLinus Torvalds 
1021da177e4SLinus Torvalds 	RESTORE(Ser1SDCR0);
1031da177e4SLinus Torvalds 
1041da177e4SLinus Torvalds 	GPSR = gpio;
1051da177e4SLinus Torvalds 	GPCR = ~gpio;
1061da177e4SLinus Torvalds 
1071da177e4SLinus Torvalds 	/*
1081da177e4SLinus Torvalds 	 * Clear the peripheral sleep-hold bit.
1091da177e4SLinus Torvalds 	 */
1101da177e4SLinus Torvalds 	PSSR = PSSR_PH;
1111da177e4SLinus Torvalds 
1121da177e4SLinus Torvalds 	return 0;
1131da177e4SLinus Torvalds }
1141da177e4SLinus Torvalds 
1152f55ac07SLionel Debroux static const struct platform_suspend_ops sa11x0_pm_ops = {
1161da177e4SLinus Torvalds 	.enter		= sa11x0_pm_enter,
11726398a70SRafael J. Wysocki 	.valid		= suspend_valid_only_mem,
1181da177e4SLinus Torvalds };
1191da177e4SLinus Torvalds 
120*7fea1ba5SShawn Guo int __init sa11x0_pm_init(void)
1211da177e4SLinus Torvalds {
12226398a70SRafael J. Wysocki 	suspend_set_ops(&sa11x0_pm_ops);
1231da177e4SLinus Torvalds 	return 0;
1241da177e4SLinus Torvalds }
125