Ben Dooks | 6419711 | 2008-12-12 00:24:06 +0000 | [diff] [blame] | 1 | /* linux/arch/arm/plat-s3c/pm.c |
| 2 | * |
| 3 | * Copyright 2008 Openmoko, Inc. |
Ben Dooks | ccae941 | 2009-11-13 22:54:14 +0000 | [diff] [blame] | 4 | * Copyright 2004-2008 Simtec Electronics |
Ben Dooks | 6419711 | 2008-12-12 00:24:06 +0000 | [diff] [blame] | 5 | * Ben Dooks <ben@simtec.co.uk> |
| 6 | * http://armlinux.simtec.co.uk/ |
| 7 | * |
| 8 | * S3C common power management (suspend to ram) support. |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify |
| 11 | * it under the terms of the GNU General Public License version 2 as |
| 12 | * published by the Free Software Foundation. |
| 13 | */ |
| 14 | |
| 15 | #include <linux/init.h> |
| 16 | #include <linux/suspend.h> |
| 17 | #include <linux/errno.h> |
Ben Dooks | 2261e0e | 2008-12-12 00:24:08 +0000 | [diff] [blame] | 18 | #include <linux/delay.h> |
Tomasz Figa | cd3fc1b | 2013-05-17 18:24:29 +0200 | [diff] [blame] | 19 | #include <linux/of.h> |
Tushar Behera | 334a1c7 | 2014-02-14 10:32:45 +0900 | [diff] [blame] | 20 | #include <linux/serial_s3c.h> |
Ben Dooks | 6419711 | 2008-12-12 00:24:06 +0000 | [diff] [blame] | 21 | #include <linux/io.h> |
| 22 | |
Ben Dooks | 2261e0e | 2008-12-12 00:24:08 +0000 | [diff] [blame] | 23 | #include <asm/cacheflush.h> |
Russell King | 2c74a0c | 2011-06-22 17:41:48 +0100 | [diff] [blame] | 24 | #include <asm/suspend.h> |
Ben Dooks | 2261e0e | 2008-12-12 00:24:08 +0000 | [diff] [blame] | 25 | |
Tomasz Figa | d6280ff | 2013-06-15 09:17:33 +0900 | [diff] [blame] | 26 | #ifdef CONFIG_SAMSUNG_ATAGS |
Tomasz Figa | d6280ff | 2013-06-15 09:17:33 +0900 | [diff] [blame] | 27 | #include <mach/map.h> |
Kukjin Kim | 05a6380 | 2013-12-19 04:07:32 +0900 | [diff] [blame] | 28 | #ifndef CONFIG_ARCH_EXYNOS |
Kukjin Kim | 2857f65 | 2013-12-19 04:22:40 +0900 | [diff] [blame] | 29 | #include <mach/regs-clock.h> |
Ben Dooks | 2261e0e | 2008-12-12 00:24:08 +0000 | [diff] [blame] | 30 | #include <mach/regs-irq.h> |
Kukjin Kim | 05a6380 | 2013-12-19 04:07:32 +0900 | [diff] [blame] | 31 | #endif |
Arnd Bergmann | 7ba8022 | 2013-03-05 11:28:29 +0100 | [diff] [blame] | 32 | #include <mach/irqs.h> |
Tomasz Figa | d6280ff | 2013-06-15 09:17:33 +0900 | [diff] [blame] | 33 | #endif |
| 34 | |
Ben Dooks | 56b3442 | 2008-12-12 00:24:12 +0000 | [diff] [blame] | 35 | #include <asm/irq.h> |
Ben Dooks | 2261e0e | 2008-12-12 00:24:08 +0000 | [diff] [blame] | 36 | |
Ben Dooks | 6419711 | 2008-12-12 00:24:06 +0000 | [diff] [blame] | 37 | #include <plat/pm.h> |
Ben Dooks | 431fb7d | 2010-02-05 13:52:53 +0100 | [diff] [blame] | 38 | #include <mach/pm-core.h> |
Ben Dooks | 6419711 | 2008-12-12 00:24:06 +0000 | [diff] [blame] | 39 | |
| 40 | /* for external use */ |
| 41 | |
| 42 | unsigned long s3c_pm_flags; |
| 43 | |
Ben Dooks | 56b3442 | 2008-12-12 00:24:12 +0000 | [diff] [blame] | 44 | /* The IRQ ext-int code goes here, it is too small to currently bother |
| 45 | * with its own file. */ |
| 46 | |
| 47 | unsigned long s3c_irqwake_intmask = 0xffffffffL; |
| 48 | unsigned long s3c_irqwake_eintmask = 0xffffffffL; |
| 49 | |
Mark Brown | f5aeffb | 2010-12-02 14:35:38 +0900 | [diff] [blame] | 50 | int s3c_irqext_wake(struct irq_data *data, unsigned int state) |
Ben Dooks | 56b3442 | 2008-12-12 00:24:12 +0000 | [diff] [blame] | 51 | { |
Mark Brown | f5aeffb | 2010-12-02 14:35:38 +0900 | [diff] [blame] | 52 | unsigned long bit = 1L << IRQ_EINT_BIT(data->irq); |
Ben Dooks | 56b3442 | 2008-12-12 00:24:12 +0000 | [diff] [blame] | 53 | |
| 54 | if (!(s3c_irqwake_eintallow & bit)) |
| 55 | return -ENOENT; |
| 56 | |
| 57 | printk(KERN_INFO "wake %s for irq %d\n", |
Mark Brown | f5aeffb | 2010-12-02 14:35:38 +0900 | [diff] [blame] | 58 | state ? "enabled" : "disabled", data->irq); |
Ben Dooks | 56b3442 | 2008-12-12 00:24:12 +0000 | [diff] [blame] | 59 | |
| 60 | if (!state) |
| 61 | s3c_irqwake_eintmask |= bit; |
| 62 | else |
| 63 | s3c_irqwake_eintmask &= ~bit; |
| 64 | |
| 65 | return 0; |
| 66 | } |
Ben Dooks | 6419711 | 2008-12-12 00:24:06 +0000 | [diff] [blame] | 67 | |
Ben Dooks | 2261e0e | 2008-12-12 00:24:08 +0000 | [diff] [blame] | 68 | /* s3c2410_pm_show_resume_irqs |
| 69 | * |
| 70 | * print any IRQs asserted at resume time (ie, we woke from) |
| 71 | */ |
Maurus Cuelenaere | baab730 | 2011-04-02 10:50:22 +0900 | [diff] [blame] | 72 | static void __maybe_unused s3c_pm_show_resume_irqs(int start, |
| 73 | unsigned long which, |
| 74 | unsigned long mask) |
Ben Dooks | 2261e0e | 2008-12-12 00:24:08 +0000 | [diff] [blame] | 75 | { |
| 76 | int i; |
| 77 | |
| 78 | which &= ~mask; |
| 79 | |
| 80 | for (i = 0; i <= 31; i++) { |
| 81 | if (which & (1L<<i)) { |
| 82 | S3C_PMDBG("IRQ %d asserted at resume\n", start+i); |
| 83 | } |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | |
| 88 | void (*pm_cpu_prep)(void); |
Russell King | 29cb3cd | 2011-07-02 09:54:01 +0100 | [diff] [blame] | 89 | int (*pm_cpu_sleep)(unsigned long); |
Ben Dooks | 2261e0e | 2008-12-12 00:24:08 +0000 | [diff] [blame] | 90 | |
| 91 | #define any_allowed(mask, allow) (((mask) & (allow)) != (allow)) |
| 92 | |
| 93 | /* s3c_pm_enter |
| 94 | * |
| 95 | * central control for sleep/resume process |
| 96 | */ |
| 97 | |
| 98 | static int s3c_pm_enter(suspend_state_t state) |
| 99 | { |
Abhilash Kesavan | d3fcacf | 2013-01-25 10:40:19 -0800 | [diff] [blame] | 100 | int ret; |
Ben Dooks | 2261e0e | 2008-12-12 00:24:08 +0000 | [diff] [blame] | 101 | /* ensure the debug is initialised (if enabled) */ |
| 102 | |
| 103 | s3c_pm_debug_init(); |
| 104 | |
| 105 | S3C_PMDBG("%s(%d)\n", __func__, state); |
| 106 | |
| 107 | if (pm_cpu_prep == NULL || pm_cpu_sleep == NULL) { |
| 108 | printk(KERN_ERR "%s: error: no cpu sleep function\n", __func__); |
| 109 | return -EINVAL; |
| 110 | } |
| 111 | |
| 112 | /* check if we have anything to wake-up with... bad things seem |
| 113 | * to happen if you suspend with no wakeup (system will often |
| 114 | * require a full power-cycle) |
| 115 | */ |
| 116 | |
Tomasz Figa | cd3fc1b | 2013-05-17 18:24:29 +0200 | [diff] [blame] | 117 | if (!of_have_populated_dt() && |
| 118 | !any_allowed(s3c_irqwake_intmask, s3c_irqwake_intallow) && |
Ben Dooks | 2261e0e | 2008-12-12 00:24:08 +0000 | [diff] [blame] | 119 | !any_allowed(s3c_irqwake_eintmask, s3c_irqwake_eintallow)) { |
| 120 | printk(KERN_ERR "%s: No wake-up sources!\n", __func__); |
| 121 | printk(KERN_ERR "%s: Aborting sleep\n", __func__); |
| 122 | return -EINVAL; |
| 123 | } |
| 124 | |
Ben Dooks | 2261e0e | 2008-12-12 00:24:08 +0000 | [diff] [blame] | 125 | /* save all necessary core registers not covered by the drivers */ |
| 126 | |
Tomasz Figa | cd3fc1b | 2013-05-17 18:24:29 +0200 | [diff] [blame] | 127 | if (!of_have_populated_dt()) { |
| 128 | samsung_pm_save_gpios(); |
| 129 | samsung_pm_saved_gpios(); |
| 130 | } |
| 131 | |
Ben Dooks | d2b07fe | 2008-12-12 00:24:20 +0000 | [diff] [blame] | 132 | s3c_pm_save_uarts(); |
Ben Dooks | 2261e0e | 2008-12-12 00:24:08 +0000 | [diff] [blame] | 133 | s3c_pm_save_core(); |
| 134 | |
| 135 | /* set the irq configuration for wake */ |
| 136 | |
| 137 | s3c_pm_configure_extint(); |
| 138 | |
| 139 | S3C_PMDBG("sleep: irq wakeup masks: %08lx,%08lx\n", |
| 140 | s3c_irqwake_intmask, s3c_irqwake_eintmask); |
| 141 | |
| 142 | s3c_pm_arch_prepare_irqs(); |
| 143 | |
| 144 | /* call cpu specific preparation */ |
| 145 | |
| 146 | pm_cpu_prep(); |
| 147 | |
| 148 | /* flush cache back to ram */ |
| 149 | |
| 150 | flush_cache_all(); |
| 151 | |
| 152 | s3c_pm_check_store(); |
| 153 | |
| 154 | /* send the cpu to sleep... */ |
| 155 | |
| 156 | s3c_pm_arch_stop_clocks(); |
| 157 | |
Russell King | e7089da | 2011-06-21 19:29:26 +0100 | [diff] [blame] | 158 | /* this will also act as our return point from when |
Ben Dooks | fff94cd | 2009-03-10 11:48:07 +0000 | [diff] [blame] | 159 | * we resume as it saves its own register state and restores it |
| 160 | * during the resume. */ |
Ben Dooks | 2261e0e | 2008-12-12 00:24:08 +0000 | [diff] [blame] | 161 | |
Abhilash Kesavan | d3fcacf | 2013-01-25 10:40:19 -0800 | [diff] [blame] | 162 | ret = cpu_suspend(0, pm_cpu_sleep); |
| 163 | if (ret) |
| 164 | return ret; |
Ben Dooks | 2261e0e | 2008-12-12 00:24:08 +0000 | [diff] [blame] | 165 | |
Ben Dooks | 2261e0e | 2008-12-12 00:24:08 +0000 | [diff] [blame] | 166 | /* restore the system state */ |
| 167 | |
| 168 | s3c_pm_restore_core(); |
Ben Dooks | d2b07fe | 2008-12-12 00:24:20 +0000 | [diff] [blame] | 169 | s3c_pm_restore_uarts(); |
Tomasz Figa | cd3fc1b | 2013-05-17 18:24:29 +0200 | [diff] [blame] | 170 | |
| 171 | if (!of_have_populated_dt()) { |
| 172 | samsung_pm_restore_gpios(); |
| 173 | s3c_pm_restored_gpios(); |
| 174 | } |
Ben Dooks | 2261e0e | 2008-12-12 00:24:08 +0000 | [diff] [blame] | 175 | |
| 176 | s3c_pm_debug_init(); |
| 177 | |
| 178 | /* check what irq (if any) restored the system */ |
| 179 | |
| 180 | s3c_pm_arch_show_resume_irqs(); |
| 181 | |
| 182 | S3C_PMDBG("%s: post sleep, preparing to return\n", __func__); |
| 183 | |
Ben Dooks | bd117bd | 2009-03-10 18:19:35 +0000 | [diff] [blame] | 184 | /* LEDs should now be 1110 */ |
| 185 | s3c_pm_debug_smdkled(1 << 1, 0); |
| 186 | |
Ben Dooks | 2261e0e | 2008-12-12 00:24:08 +0000 | [diff] [blame] | 187 | s3c_pm_check_restore(); |
| 188 | |
| 189 | /* ok, let's return from sleep */ |
| 190 | |
| 191 | S3C_PMDBG("S3C PM Resume (post-restore)\n"); |
| 192 | return 0; |
| 193 | } |
| 194 | |
Ben Dooks | aa8aba6 | 2008-12-12 00:24:34 +0000 | [diff] [blame] | 195 | static int s3c_pm_prepare(void) |
| 196 | { |
| 197 | /* prepare check area if configured */ |
| 198 | |
| 199 | s3c_pm_check_prepare(); |
| 200 | return 0; |
| 201 | } |
| 202 | |
| 203 | static void s3c_pm_finish(void) |
| 204 | { |
| 205 | s3c_pm_check_cleanup(); |
| 206 | } |
| 207 | |
Lionel Debroux | 2f55ac0 | 2010-11-16 14:14:02 +0100 | [diff] [blame] | 208 | static const struct platform_suspend_ops s3c_pm_ops = { |
Ben Dooks | 2261e0e | 2008-12-12 00:24:08 +0000 | [diff] [blame] | 209 | .enter = s3c_pm_enter, |
Ben Dooks | aa8aba6 | 2008-12-12 00:24:34 +0000 | [diff] [blame] | 210 | .prepare = s3c_pm_prepare, |
| 211 | .finish = s3c_pm_finish, |
Ben Dooks | 2261e0e | 2008-12-12 00:24:08 +0000 | [diff] [blame] | 212 | .valid = suspend_valid_only_mem, |
| 213 | }; |
| 214 | |
Ben Dooks | 4e59c25 | 2008-12-12 00:24:18 +0000 | [diff] [blame] | 215 | /* s3c_pm_init |
Ben Dooks | 2261e0e | 2008-12-12 00:24:08 +0000 | [diff] [blame] | 216 | * |
| 217 | * Attach the power management functions. This should be called |
| 218 | * from the board specific initialisation if the board supports |
| 219 | * it. |
| 220 | */ |
| 221 | |
Ben Dooks | 4e59c25 | 2008-12-12 00:24:18 +0000 | [diff] [blame] | 222 | int __init s3c_pm_init(void) |
Ben Dooks | 2261e0e | 2008-12-12 00:24:08 +0000 | [diff] [blame] | 223 | { |
| 224 | printk("S3C Power Management, Copyright 2004 Simtec Electronics\n"); |
| 225 | |
| 226 | suspend_set_ops(&s3c_pm_ops); |
| 227 | return 0; |
| 228 | } |