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> |
| 26 | #include <linux/suspend.h> |
| 27 | #include <linux/errno.h> |
| 28 | #include <linux/time.h> |
| 29 | |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 30 | #include <mach/hardware.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | #include <asm/memory.h> |
| 32 | #include <asm/system.h> |
| 33 | #include <asm/mach/time.h> |
| 34 | |
Russell King | 96c2001 | 2011-02-06 17:41:40 +0000 | [diff] [blame] | 35 | extern void sa1100_cpu_suspend(long); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | |
| 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 Jarzmik | 649de51 | 2008-05-02 21:17:06 +0100 | [diff] [blame] | 45 | enum { SLEEP_SAVE_GPDR, SLEEP_SAVE_GAFR, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | SLEEP_SAVE_PPDR, SLEEP_SAVE_PPSR, SLEEP_SAVE_PPAR, SLEEP_SAVE_PSDR, |
| 47 | |
| 48 | SLEEP_SAVE_Ser1SDCR0, |
| 49 | |
Robert Jarzmik | 649de51 | 2008-05-02 21:17:06 +0100 | [diff] [blame] | 50 | SLEEP_SAVE_COUNT |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | }; |
| 52 | |
| 53 | |
| 54 | static int sa11x0_pm_enter(suspend_state_t state) |
| 55 | { |
Robert Jarzmik | 649de51 | 2008-05-02 21:17:06 +0100 | [diff] [blame] | 56 | unsigned long gpio, sleep_save[SLEEP_SAVE_COUNT]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | 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 King | 96c2001 | 2011-02-06 17:41:40 +0000 | [diff] [blame] | 75 | PSPR = virt_to_phys(cpu_resume); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | |
| 77 | /* go zzz */ |
Russell King | 96c2001 | 2011-02-06 17:41:40 +0000 | [diff] [blame] | 78 | sa1100_cpu_suspend(PLAT_PHYS_OFFSET - PAGE_OFFSET); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | |
Russell King | 36c5ed2 | 2005-06-19 18:39:33 +0100 | [diff] [blame] | 80 | cpu_init(); |
| 81 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | /* |
| 83 | * Ensure not to come back here if it wasn't intended |
| 84 | */ |
| 85 | PSPR = 0; |
| 86 | |
| 87 | /* |
| 88 | * Ensure interrupt sources are disabled; we will re-init |
| 89 | * the interrupt subsystem via the device manager. |
| 90 | */ |
| 91 | ICLR = 0; |
| 92 | ICCR = 1; |
| 93 | ICMR = 0; |
| 94 | |
| 95 | /* restore registers */ |
| 96 | RESTORE(GPDR); |
| 97 | RESTORE(GAFR); |
| 98 | |
| 99 | RESTORE(PPDR); |
| 100 | RESTORE(PPSR); |
| 101 | RESTORE(PPAR); |
| 102 | RESTORE(PSDR); |
| 103 | |
| 104 | RESTORE(Ser1SDCR0); |
| 105 | |
| 106 | GPSR = gpio; |
| 107 | GPCR = ~gpio; |
| 108 | |
| 109 | /* |
| 110 | * Clear the peripheral sleep-hold bit. |
| 111 | */ |
| 112 | PSSR = PSSR_PH; |
| 113 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | return 0; |
| 115 | } |
| 116 | |
Lionel Debroux | 2f55ac0 | 2010-11-16 14:14:02 +0100 | [diff] [blame] | 117 | static const struct platform_suspend_ops sa11x0_pm_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | .enter = sa11x0_pm_enter, |
Rafael J. Wysocki | 26398a7 | 2007-10-18 03:04:40 -0700 | [diff] [blame] | 119 | .valid = suspend_valid_only_mem, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | }; |
| 121 | |
| 122 | static int __init sa11x0_pm_init(void) |
| 123 | { |
Rafael J. Wysocki | 26398a7 | 2007-10-18 03:04:40 -0700 | [diff] [blame] | 124 | suspend_set_ops(&sa11x0_pm_ops); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | return 0; |
| 126 | } |
| 127 | |
| 128 | late_initcall(sa11x0_pm_init); |