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