Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 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 Pitre | 2f82af0 | 2009-09-14 03:25:28 -0400 | [diff] [blame] | 18 | * 2001-08-29: Nicolas Pitre <nico@fluxnic.net> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | * 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> |
Russell King | 3169663 | 2012-06-06 11:42:36 +0100 | [diff] [blame] | 26 | #include <linux/io.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | #include <linux/suspend.h> |
| 28 | #include <linux/errno.h> |
| 29 | #include <linux/time.h> |
| 30 | |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 31 | #include <mach/hardware.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | #include <asm/memory.h> |
Russell King | 2c74a0c | 2011-06-22 17:41:48 +0100 | [diff] [blame] | 33 | #include <asm/suspend.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | #include <asm/mach/time.h> |
| 35 | |
Russell King | 29cb3cd | 2011-07-02 09:54:01 +0100 | [diff] [blame] | 36 | extern int sa1100_finish_suspend(unsigned long); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | |
| 38 | #define SAVE(x) sleep_save[SLEEP_SAVE_##x] = x |
| 39 | #define RESTORE(x) x = sleep_save[SLEEP_SAVE_##x] |
| 40 | |
| 41 | /* |
| 42 | * List of global SA11x0 peripheral registers to preserve. |
| 43 | * More ones like CP and general purpose register values are preserved |
| 44 | * on the stack and then the stack pointer is stored last in sleep.S. |
| 45 | */ |
Robert Jarzmik | 649de51 | 2008-05-02 21:17:06 +0100 | [diff] [blame] | 46 | enum { SLEEP_SAVE_GPDR, SLEEP_SAVE_GAFR, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | SLEEP_SAVE_PPDR, SLEEP_SAVE_PPSR, SLEEP_SAVE_PPAR, SLEEP_SAVE_PSDR, |
| 48 | |
| 49 | SLEEP_SAVE_Ser1SDCR0, |
| 50 | |
Robert Jarzmik | 649de51 | 2008-05-02 21:17:06 +0100 | [diff] [blame] | 51 | SLEEP_SAVE_COUNT |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | }; |
| 53 | |
| 54 | |
| 55 | static int sa11x0_pm_enter(suspend_state_t state) |
| 56 | { |
Robert Jarzmik | 649de51 | 2008-05-02 21:17:06 +0100 | [diff] [blame] | 57 | unsigned long gpio, sleep_save[SLEEP_SAVE_COUNT]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | gpio = GPLR; |
| 60 | |
| 61 | /* save vital registers */ |
| 62 | SAVE(GPDR); |
| 63 | SAVE(GAFR); |
| 64 | |
| 65 | SAVE(PPDR); |
| 66 | SAVE(PPSR); |
| 67 | SAVE(PPAR); |
| 68 | SAVE(PSDR); |
| 69 | |
| 70 | SAVE(Ser1SDCR0); |
| 71 | |
| 72 | /* Clear previous reset status */ |
| 73 | RCSR = RCSR_HWR | RCSR_SWR | RCSR_WDR | RCSR_SMR; |
| 74 | |
| 75 | /* set resume return address */ |
Russell King | 96c2001 | 2011-02-06 17:41:40 +0000 | [diff] [blame] | 76 | PSPR = virt_to_phys(cpu_resume); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | |
| 78 | /* go zzz */ |
Russell King | 2c74a0c | 2011-06-22 17:41:48 +0100 | [diff] [blame] | 79 | cpu_suspend(0, sa1100_finish_suspend); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | /* |
| 82 | * Ensure not to come back here if it wasn't intended |
| 83 | */ |
| 84 | PSPR = 0; |
| 85 | |
| 86 | /* |
| 87 | * Ensure interrupt sources are disabled; we will re-init |
| 88 | * the interrupt subsystem via the device manager. |
| 89 | */ |
| 90 | ICLR = 0; |
| 91 | ICCR = 1; |
| 92 | ICMR = 0; |
| 93 | |
| 94 | /* restore registers */ |
| 95 | RESTORE(GPDR); |
| 96 | RESTORE(GAFR); |
| 97 | |
| 98 | RESTORE(PPDR); |
| 99 | RESTORE(PPSR); |
| 100 | RESTORE(PPAR); |
| 101 | RESTORE(PSDR); |
| 102 | |
| 103 | RESTORE(Ser1SDCR0); |
| 104 | |
| 105 | GPSR = gpio; |
| 106 | GPCR = ~gpio; |
| 107 | |
| 108 | /* |
| 109 | * Clear the peripheral sleep-hold bit. |
| 110 | */ |
| 111 | PSSR = PSSR_PH; |
| 112 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | return 0; |
| 114 | } |
| 115 | |
Lionel Debroux | 2f55ac0 | 2010-11-16 14:14:02 +0100 | [diff] [blame] | 116 | static const struct platform_suspend_ops sa11x0_pm_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | .enter = sa11x0_pm_enter, |
Rafael J. Wysocki | 26398a7 | 2007-10-18 03:04:40 -0700 | [diff] [blame] | 118 | .valid = suspend_valid_only_mem, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | }; |
| 120 | |
Shawn Guo | 7fea1ba | 2012-04-26 21:22:45 +0800 | [diff] [blame] | 121 | int __init sa11x0_pm_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | { |
Rafael J. Wysocki | 26398a7 | 2007-10-18 03:04:40 -0700 | [diff] [blame] | 123 | suspend_set_ops(&sa11x0_pm_ops); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | return 0; |
| 125 | } |