Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* linux/arch/arm/mach-s3c2410/pm.c |
| 2 | * |
Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 3 | * Copyright (c) 2006 Simtec Electronics |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * Ben Dooks <ben@simtec.co.uk> |
| 5 | * |
Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 6 | * S3C2410 (and compatible) Power Manager (Suspend-To-RAM) support |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | */ |
| 22 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | #include <linux/init.h> |
| 24 | #include <linux/suspend.h> |
| 25 | #include <linux/errno.h> |
| 26 | #include <linux/time.h> |
Kay Sievers | 4a858cf | 2011-12-21 16:01:38 -0800 | [diff] [blame] | 27 | #include <linux/device.h> |
Rafael J. Wysocki | bb072c3 | 2011-04-22 22:03:21 +0200 | [diff] [blame] | 28 | #include <linux/syscore_ops.h> |
Ben Dooks | ec976d6 | 2009-05-13 22:52:24 +0100 | [diff] [blame] | 29 | #include <linux/gpio.h> |
Russell King | fced80c | 2008-09-06 12:10:45 +0100 | [diff] [blame] | 30 | #include <linux/io.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | |
Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 32 | #include <asm/mach-types.h> |
| 33 | |
Kukjin Kim | 232910d | 2013-01-02 10:18:58 -0800 | [diff] [blame] | 34 | #include <mach/hardware.h> |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 35 | #include <mach/regs-gpio.h> |
Linus Walleij | b0161ca | 2014-01-14 14:24:24 +0100 | [diff] [blame] | 36 | #include <mach/gpio-samsung.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | |
Linus Walleij | 3643741 | 2014-01-14 15:05:22 +0100 | [diff] [blame] | 38 | #include <plat/gpio-cfg.h> |
Ben Dooks | a2b7ba9 | 2008-10-07 22:26:09 +0100 | [diff] [blame] | 39 | #include <plat/cpu.h> |
| 40 | #include <plat/pm.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | |
Kukjin Kim | 232910d | 2013-01-02 10:18:58 -0800 | [diff] [blame] | 42 | #include "h1940.h" |
| 43 | |
Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 44 | static void s3c2410_pm_prepare(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | { |
Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 46 | /* ensure at least GSTATUS3 has the resume address */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | |
Ben Dooks | ef30e14 | 2008-12-12 00:24:19 +0000 | [diff] [blame] | 48 | __raw_writel(virt_to_phys(s3c_cpu_resume), S3C2410_GSTATUS3); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | |
Ben Dooks | 6419711 | 2008-12-12 00:24:06 +0000 | [diff] [blame] | 50 | S3C_PMDBG("GSTATUS3 0x%08x\n", __raw_readl(S3C2410_GSTATUS3)); |
| 51 | S3C_PMDBG("GSTATUS4 0x%08x\n", __raw_readl(S3C2410_GSTATUS4)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | |
Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 53 | if (machine_is_h1940()) { |
| 54 | void *base = phys_to_virt(H1940_SUSPEND_CHECK); |
| 55 | unsigned long ptr; |
| 56 | unsigned long calc = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | |
Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 58 | /* generate check for the bootloader to check on resume */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | |
Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 60 | for (ptr = 0; ptr < 0x40000; ptr += 0x400) |
| 61 | calc += __raw_readl(base+ptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | |
Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 63 | __raw_writel(calc, phys_to_virt(H1940_SUSPEND_CHECKSUM)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | } |
| 65 | |
Vasily Khoruzhick | 0741b7d | 2010-05-11 09:55:10 +0300 | [diff] [blame] | 66 | /* RX3715 and RX1950 use similar to H1940 code and the |
Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 67 | * same offsets for resume and checksum pointers */ |
| 68 | |
Vasily Khoruzhick | 0741b7d | 2010-05-11 09:55:10 +0300 | [diff] [blame] | 69 | if (machine_is_rx3715() || machine_is_rx1950()) { |
Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 70 | void *base = phys_to_virt(H1940_SUSPEND_CHECK); |
| 71 | unsigned long ptr; |
| 72 | unsigned long calc = 0; |
| 73 | |
| 74 | /* generate check for the bootloader to check on resume */ |
| 75 | |
| 76 | for (ptr = 0; ptr < 0x40000; ptr += 0x4) |
| 77 | calc += __raw_readl(base+ptr); |
| 78 | |
| 79 | __raw_writel(calc, phys_to_virt(H1940_SUSPEND_CHECKSUM)); |
| 80 | } |
| 81 | |
Sylwester Nawrocki | 9491173 | 2012-07-13 18:05:00 +0900 | [diff] [blame] | 82 | if (machine_is_aml_m5900()) { |
| 83 | gpio_request_one(S3C2410_GPF(2), GPIOF_OUT_INIT_HIGH, NULL); |
| 84 | gpio_free(S3C2410_GPF(2)); |
| 85 | } |
Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 86 | |
Vasily Khoruzhick | 192ff91 | 2010-05-11 09:55:11 +0300 | [diff] [blame] | 87 | if (machine_is_rx1950()) { |
| 88 | /* According to S3C2442 user's manual, page 7-17, |
| 89 | * when the system is operating in NAND boot mode, |
| 90 | * the hardware pin configuration - EINT[23:21] – |
| 91 | * must be set as input for starting up after |
| 92 | * wakeup from sleep mode |
| 93 | */ |
| 94 | s3c_gpio_cfgpin(S3C2410_GPG(13), S3C2410_GPIO_INPUT); |
| 95 | s3c_gpio_cfgpin(S3C2410_GPG(14), S3C2410_GPIO_INPUT); |
| 96 | s3c_gpio_cfgpin(S3C2410_GPG(15), S3C2410_GPIO_INPUT); |
| 97 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | } |
| 99 | |
Rafael J. Wysocki | bb072c3 | 2011-04-22 22:03:21 +0200 | [diff] [blame] | 100 | static void s3c2410_pm_resume(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | { |
Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 102 | unsigned long tmp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | |
Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 104 | /* unset the return-from-sleep flag, to ensure reset */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | |
Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 106 | tmp = __raw_readl(S3C2410_GSTATUS2); |
| 107 | tmp &= S3C2410_GSTATUS2_OFFRESET; |
| 108 | __raw_writel(tmp, S3C2410_GSTATUS2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | |
Sylwester Nawrocki | 9491173 | 2012-07-13 18:05:00 +0900 | [diff] [blame] | 110 | if (machine_is_aml_m5900()) { |
| 111 | gpio_request_one(S3C2410_GPF(2), GPIOF_OUT_INIT_LOW, NULL); |
| 112 | gpio_free(S3C2410_GPF(2)); |
| 113 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | } |
| 115 | |
Rafael J. Wysocki | bb072c3 | 2011-04-22 22:03:21 +0200 | [diff] [blame] | 116 | struct syscore_ops s3c2410_pm_syscore_ops = { |
| 117 | .resume = s3c2410_pm_resume, |
| 118 | }; |
| 119 | |
Heiko Stuebner | 04511a6 | 2012-01-27 15:35:25 +0900 | [diff] [blame] | 120 | static int s3c2410_pm_add(struct device *dev, struct subsys_interface *sif) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | { |
Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 122 | pm_cpu_prep = s3c2410_pm_prepare; |
| 123 | pm_cpu_sleep = s3c2410_cpu_suspend; |
| 124 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | return 0; |
| 126 | } |
| 127 | |
Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 128 | #if defined(CONFIG_CPU_S3C2410) |
Kay Sievers | 4a858cf | 2011-12-21 16:01:38 -0800 | [diff] [blame] | 129 | static struct subsys_interface s3c2410_pm_interface = { |
| 130 | .name = "s3c2410_pm", |
| 131 | .subsys = &s3c2410_subsys, |
| 132 | .add_dev = s3c2410_pm_add, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | }; |
| 134 | |
Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 135 | /* register ourselves */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | |
Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 137 | static int __init s3c2410_pm_drvinit(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | { |
Kay Sievers | 4a858cf | 2011-12-21 16:01:38 -0800 | [diff] [blame] | 139 | return subsys_interface_register(&s3c2410_pm_interface); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | } |
Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 141 | |
| 142 | arch_initcall(s3c2410_pm_drvinit); |
Ben Dooks | f017679 | 2009-07-30 23:23:38 +0100 | [diff] [blame] | 143 | |
Kay Sievers | 4a858cf | 2011-12-21 16:01:38 -0800 | [diff] [blame] | 144 | static struct subsys_interface s3c2410a_pm_interface = { |
| 145 | .name = "s3c2410a_pm", |
Kukjin Kim | ea04018 | 2012-01-06 16:08:09 +0900 | [diff] [blame] | 146 | .subsys = &s3c2410a_subsys, |
Kay Sievers | 4a858cf | 2011-12-21 16:01:38 -0800 | [diff] [blame] | 147 | .add_dev = s3c2410_pm_add, |
Ben Dooks | f017679 | 2009-07-30 23:23:38 +0100 | [diff] [blame] | 148 | }; |
| 149 | |
| 150 | static int __init s3c2410a_pm_drvinit(void) |
| 151 | { |
Kay Sievers | 4a858cf | 2011-12-21 16:01:38 -0800 | [diff] [blame] | 152 | return subsys_interface_register(&s3c2410a_pm_interface); |
Ben Dooks | f017679 | 2009-07-30 23:23:38 +0100 | [diff] [blame] | 153 | } |
| 154 | |
| 155 | arch_initcall(s3c2410a_pm_drvinit); |
Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 156 | #endif |
| 157 | |
| 158 | #if defined(CONFIG_CPU_S3C2440) |
Kay Sievers | 4a858cf | 2011-12-21 16:01:38 -0800 | [diff] [blame] | 159 | static struct subsys_interface s3c2440_pm_interface = { |
| 160 | .name = "s3c2440_pm", |
| 161 | .subsys = &s3c2440_subsys, |
| 162 | .add_dev = s3c2410_pm_add, |
Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 163 | }; |
| 164 | |
| 165 | static int __init s3c2440_pm_drvinit(void) |
| 166 | { |
Kay Sievers | 4a858cf | 2011-12-21 16:01:38 -0800 | [diff] [blame] | 167 | return subsys_interface_register(&s3c2440_pm_interface); |
Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | arch_initcall(s3c2440_pm_drvinit); |
| 171 | #endif |
| 172 | |
| 173 | #if defined(CONFIG_CPU_S3C2442) |
Kay Sievers | 4a858cf | 2011-12-21 16:01:38 -0800 | [diff] [blame] | 174 | static struct subsys_interface s3c2442_pm_interface = { |
| 175 | .name = "s3c2442_pm", |
| 176 | .subsys = &s3c2442_subsys, |
| 177 | .add_dev = s3c2410_pm_add, |
Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 178 | }; |
| 179 | |
| 180 | static int __init s3c2442_pm_drvinit(void) |
| 181 | { |
Kay Sievers | 4a858cf | 2011-12-21 16:01:38 -0800 | [diff] [blame] | 182 | return subsys_interface_register(&s3c2442_pm_interface); |
Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 183 | } |
| 184 | |
| 185 | arch_initcall(s3c2442_pm_drvinit); |
| 186 | #endif |