blob: 2fa499ec6afebf52cad16e2641192029a1cf44ef [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * SA1100 Power Management Routines
3 *
4 * Copyright (c) 2001 Cliff Brake <cbrake@accelent.com>
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License.
8 *
9 * History:
10 *
11 * 2001-02-06: Cliff Brake Initial code
12 *
13 * 2001-02-25: Sukjae Cho <sjcho@east.isi.edu> &
14 * Chester Kuo <chester@linux.org.tw>
15 * Save more value for the resume function! Support
16 * Bitsy/Assabet/Freebird board
17 *
Nicolas Pitre2f82af02009-09-14 03:25:28 -040018 * 2001-08-29: Nicolas Pitre <nico@fluxnic.net>
Linus Torvalds1da177e2005-04-16 15:20:36 -070019 * Cleaned up, pushed platform dependent stuff
20 * in the platform specific files.
21 *
22 * 2002-05-27: Nicolas Pitre Killed sleep.h and the kmalloced save array.
23 * Storage is local on the stack now.
24 */
25#include <linux/init.h>
26#include <linux/suspend.h>
27#include <linux/errno.h>
28#include <linux/time.h>
29
Russell Kinga09e64f2008-08-05 16:14:15 +010030#include <mach/hardware.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070031#include <asm/memory.h>
Russell King2c74a0c2011-06-22 17:41:48 +010032#include <asm/suspend.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#include <asm/mach/time.h>
34
Russell King29cb3cd2011-07-02 09:54:01 +010035extern int sa1100_finish_suspend(unsigned long);
Linus Torvalds1da177e2005-04-16 15:20:36 -070036
37#define SAVE(x) sleep_save[SLEEP_SAVE_##x] = x
38#define RESTORE(x) x = sleep_save[SLEEP_SAVE_##x]
39
40/*
41 * List of global SA11x0 peripheral registers to preserve.
42 * More ones like CP and general purpose register values are preserved
43 * on the stack and then the stack pointer is stored last in sleep.S.
44 */
Robert Jarzmik649de512008-05-02 21:17:06 +010045enum { SLEEP_SAVE_GPDR, SLEEP_SAVE_GAFR,
Linus Torvalds1da177e2005-04-16 15:20:36 -070046 SLEEP_SAVE_PPDR, SLEEP_SAVE_PPSR, SLEEP_SAVE_PPAR, SLEEP_SAVE_PSDR,
47
48 SLEEP_SAVE_Ser1SDCR0,
49
Robert Jarzmik649de512008-05-02 21:17:06 +010050 SLEEP_SAVE_COUNT
Linus Torvalds1da177e2005-04-16 15:20:36 -070051};
52
53
54static int sa11x0_pm_enter(suspend_state_t state)
55{
Robert Jarzmik649de512008-05-02 21:17:06 +010056 unsigned long gpio, sleep_save[SLEEP_SAVE_COUNT];
Linus Torvalds1da177e2005-04-16 15:20:36 -070057
Linus Torvalds1da177e2005-04-16 15:20:36 -070058 gpio = GPLR;
59
60 /* save vital registers */
61 SAVE(GPDR);
62 SAVE(GAFR);
63
64 SAVE(PPDR);
65 SAVE(PPSR);
66 SAVE(PPAR);
67 SAVE(PSDR);
68
69 SAVE(Ser1SDCR0);
70
71 /* Clear previous reset status */
72 RCSR = RCSR_HWR | RCSR_SWR | RCSR_WDR | RCSR_SMR;
73
74 /* set resume return address */
Russell King96c20012011-02-06 17:41:40 +000075 PSPR = virt_to_phys(cpu_resume);
Linus Torvalds1da177e2005-04-16 15:20:36 -070076
77 /* go zzz */
Russell King2c74a0c2011-06-22 17:41:48 +010078 cpu_suspend(0, sa1100_finish_suspend);
Linus Torvalds1da177e2005-04-16 15:20:36 -070079
Linus Torvalds1da177e2005-04-16 15:20:36 -070080 /*
81 * Ensure not to come back here if it wasn't intended
82 */
83 PSPR = 0;
84
85 /*
86 * Ensure interrupt sources are disabled; we will re-init
87 * the interrupt subsystem via the device manager.
88 */
89 ICLR = 0;
90 ICCR = 1;
91 ICMR = 0;
92
93 /* restore registers */
94 RESTORE(GPDR);
95 RESTORE(GAFR);
96
97 RESTORE(PPDR);
98 RESTORE(PPSR);
99 RESTORE(PPAR);
100 RESTORE(PSDR);
101
102 RESTORE(Ser1SDCR0);
103
104 GPSR = gpio;
105 GPCR = ~gpio;
106
107 /*
108 * Clear the peripheral sleep-hold bit.
109 */
110 PSSR = PSSR_PH;
111
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112 return 0;
113}
114
Lionel Debroux2f55ac02010-11-16 14:14:02 +0100115static const struct platform_suspend_ops sa11x0_pm_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116 .enter = sa11x0_pm_enter,
Rafael J. Wysocki26398a72007-10-18 03:04:40 -0700117 .valid = suspend_valid_only_mem,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118};
119
120static int __init sa11x0_pm_init(void)
121{
Rafael J. Wysocki26398a72007-10-18 03:04:40 -0700122 suspend_set_ops(&sa11x0_pm_ops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123 return 0;
124}
125
126late_initcall(sa11x0_pm_init);