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>
263169663aSRussell King #include <linux/io.h>
271da177e4SLinus Torvalds #include <linux/suspend.h>
281da177e4SLinus Torvalds #include <linux/errno.h>
291da177e4SLinus Torvalds #include <linux/time.h>
301da177e4SLinus Torvalds
31a09e64fbSRussell King #include <mach/hardware.h>
32*a9ff6961SLinus Walleij #include <asm/page.h>
332c74a0ceSRussell King #include <asm/suspend.h>
341da177e4SLinus Torvalds #include <asm/mach/time.h>
351da177e4SLinus Torvalds
366475f4bbSArnd Bergmann #include "generic.h"
376475f4bbSArnd Bergmann
3829cb3cd2SRussell King extern int sa1100_finish_suspend(unsigned long);
391da177e4SLinus Torvalds
401da177e4SLinus Torvalds #define SAVE(x) sleep_save[SLEEP_SAVE_##x] = x
411da177e4SLinus Torvalds #define RESTORE(x) x = sleep_save[SLEEP_SAVE_##x]
421da177e4SLinus Torvalds
431da177e4SLinus Torvalds /*
441da177e4SLinus Torvalds * List of global SA11x0 peripheral registers to preserve.
451da177e4SLinus Torvalds * More ones like CP and general purpose register values are preserved
461da177e4SLinus Torvalds * on the stack and then the stack pointer is stored last in sleep.S.
471da177e4SLinus Torvalds */
48649de51bSRobert Jarzmik enum { SLEEP_SAVE_GPDR, SLEEP_SAVE_GAFR,
491da177e4SLinus Torvalds SLEEP_SAVE_PPDR, SLEEP_SAVE_PPSR, SLEEP_SAVE_PPAR, SLEEP_SAVE_PSDR,
501da177e4SLinus Torvalds
511da177e4SLinus Torvalds SLEEP_SAVE_Ser1SDCR0,
521da177e4SLinus Torvalds
53649de51bSRobert Jarzmik SLEEP_SAVE_COUNT
541da177e4SLinus Torvalds };
551da177e4SLinus Torvalds
561da177e4SLinus Torvalds
sa11x0_pm_enter(suspend_state_t state)571da177e4SLinus Torvalds static int sa11x0_pm_enter(suspend_state_t state)
581da177e4SLinus Torvalds {
59649de51bSRobert Jarzmik unsigned long gpio, sleep_save[SLEEP_SAVE_COUNT];
601da177e4SLinus Torvalds
611da177e4SLinus Torvalds gpio = GPLR;
621da177e4SLinus Torvalds
631da177e4SLinus Torvalds /* save vital registers */
641da177e4SLinus Torvalds SAVE(GPDR);
651da177e4SLinus Torvalds SAVE(GAFR);
661da177e4SLinus Torvalds
671da177e4SLinus Torvalds SAVE(PPDR);
681da177e4SLinus Torvalds SAVE(PPSR);
691da177e4SLinus Torvalds SAVE(PPAR);
701da177e4SLinus Torvalds SAVE(PSDR);
711da177e4SLinus Torvalds
721da177e4SLinus Torvalds SAVE(Ser1SDCR0);
731da177e4SLinus Torvalds
741da177e4SLinus Torvalds /* Clear previous reset status */
751da177e4SLinus Torvalds RCSR = RCSR_HWR | RCSR_SWR | RCSR_WDR | RCSR_SMR;
761da177e4SLinus Torvalds
771da177e4SLinus Torvalds /* set resume return address */
7864fc2a94SFlorian Fainelli PSPR = __pa_symbol(cpu_resume);
791da177e4SLinus Torvalds
801da177e4SLinus Torvalds /* go zzz */
812c74a0ceSRussell King cpu_suspend(0, sa1100_finish_suspend);
821da177e4SLinus Torvalds
831da177e4SLinus Torvalds /*
841da177e4SLinus Torvalds * Ensure not to come back here if it wasn't intended
851da177e4SLinus Torvalds */
86e461894dSDmitry Eremin-Solenikov RCSR = RCSR_SMR;
871da177e4SLinus Torvalds PSPR = 0;
881da177e4SLinus Torvalds
891da177e4SLinus Torvalds /*
901da177e4SLinus Torvalds * Ensure interrupt sources are disabled; we will re-init
911da177e4SLinus Torvalds * the interrupt subsystem via the device manager.
921da177e4SLinus Torvalds */
931da177e4SLinus Torvalds ICLR = 0;
941da177e4SLinus Torvalds ICCR = 1;
951da177e4SLinus Torvalds ICMR = 0;
961da177e4SLinus Torvalds
971da177e4SLinus Torvalds /* restore registers */
981da177e4SLinus Torvalds RESTORE(GPDR);
991da177e4SLinus Torvalds RESTORE(GAFR);
1001da177e4SLinus Torvalds
1011da177e4SLinus Torvalds RESTORE(PPDR);
1021da177e4SLinus Torvalds RESTORE(PPSR);
1031da177e4SLinus Torvalds RESTORE(PPAR);
1041da177e4SLinus Torvalds RESTORE(PSDR);
1051da177e4SLinus Torvalds
1061da177e4SLinus Torvalds RESTORE(Ser1SDCR0);
1071da177e4SLinus Torvalds
1081da177e4SLinus Torvalds GPSR = gpio;
1091da177e4SLinus Torvalds GPCR = ~gpio;
1101da177e4SLinus Torvalds
1111da177e4SLinus Torvalds /*
1121da177e4SLinus Torvalds * Clear the peripheral sleep-hold bit.
1131da177e4SLinus Torvalds */
1141da177e4SLinus Torvalds PSSR = PSSR_PH;
1151da177e4SLinus Torvalds
1161da177e4SLinus Torvalds return 0;
1171da177e4SLinus Torvalds }
1181da177e4SLinus Torvalds
1192f55ac07SLionel Debroux static const struct platform_suspend_ops sa11x0_pm_ops = {
1201da177e4SLinus Torvalds .enter = sa11x0_pm_enter,
12126398a70SRafael J. Wysocki .valid = suspend_valid_only_mem,
1221da177e4SLinus Torvalds };
1231da177e4SLinus Torvalds
sa11x0_pm_init(void)1247fea1ba5SShawn Guo int __init sa11x0_pm_init(void)
1251da177e4SLinus Torvalds {
12626398a70SRafael J. Wysocki suspend_set_ops(&sa11x0_pm_ops);
1271da177e4SLinus Torvalds return 0;
1281da177e4SLinus Torvalds }
129