blob: 949ae05e07c5c8ff103c6d053da9c650bccbfe96 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* linux/arch/arm/mach-s3c2410/pm.c
2 *
Ben Dooksa21765a2007-02-11 18:31:01 +01003 * Copyright (c) 2006 Simtec Electronics
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 * Ben Dooks <ben@simtec.co.uk>
5 *
Ben Dooksa21765a2007-02-11 18:31:01 +01006 * S3C2410 (and compatible) Power Manager (Suspend-To-RAM) support
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 *
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 Torvalds1da177e2005-04-16 15:20:36 -070021*/
22
Linus Torvalds1da177e2005-04-16 15:20:36 -070023#include <linux/init.h>
24#include <linux/suspend.h>
25#include <linux/errno.h>
26#include <linux/time.h>
Kay Sievers4a858cf2011-12-21 16:01:38 -080027#include <linux/device.h>
Rafael J. Wysockibb072c32011-04-22 22:03:21 +020028#include <linux/syscore_ops.h>
Ben Dooksec976d62009-05-13 22:52:24 +010029#include <linux/gpio.h>
Russell Kingfced80c2008-09-06 12:10:45 +010030#include <linux/io.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070031
Russell Kinga09e64f2008-08-05 16:14:15 +010032#include <mach/hardware.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070033
Ben Dooksa21765a2007-02-11 18:31:01 +010034#include <asm/mach-types.h>
35
Russell Kinga09e64f2008-08-05 16:14:15 +010036#include <mach/regs-gpio.h>
37#include <mach/h1940.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070038
Ben Dooksa2b7ba92008-10-07 22:26:09 +010039#include <plat/cpu.h>
40#include <plat/pm.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070041
Ben Dooksa21765a2007-02-11 18:31:01 +010042static void s3c2410_pm_prepare(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070043{
Ben Dooksa21765a2007-02-11 18:31:01 +010044 /* ensure at least GSTATUS3 has the resume address */
Linus Torvalds1da177e2005-04-16 15:20:36 -070045
Ben Dooksef30e142008-12-12 00:24:19 +000046 __raw_writel(virt_to_phys(s3c_cpu_resume), S3C2410_GSTATUS3);
Linus Torvalds1da177e2005-04-16 15:20:36 -070047
Ben Dooks64197112008-12-12 00:24:06 +000048 S3C_PMDBG("GSTATUS3 0x%08x\n", __raw_readl(S3C2410_GSTATUS3));
49 S3C_PMDBG("GSTATUS4 0x%08x\n", __raw_readl(S3C2410_GSTATUS4));
Linus Torvalds1da177e2005-04-16 15:20:36 -070050
Ben Dooksa21765a2007-02-11 18:31:01 +010051 if (machine_is_h1940()) {
52 void *base = phys_to_virt(H1940_SUSPEND_CHECK);
53 unsigned long ptr;
54 unsigned long calc = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070055
Ben Dooksa21765a2007-02-11 18:31:01 +010056 /* generate check for the bootloader to check on resume */
Linus Torvalds1da177e2005-04-16 15:20:36 -070057
Ben Dooksa21765a2007-02-11 18:31:01 +010058 for (ptr = 0; ptr < 0x40000; ptr += 0x400)
59 calc += __raw_readl(base+ptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -070060
Ben Dooksa21765a2007-02-11 18:31:01 +010061 __raw_writel(calc, phys_to_virt(H1940_SUSPEND_CHECKSUM));
Linus Torvalds1da177e2005-04-16 15:20:36 -070062 }
63
Vasily Khoruzhick0741b7d2010-05-11 09:55:10 +030064 /* RX3715 and RX1950 use similar to H1940 code and the
Ben Dooksa21765a2007-02-11 18:31:01 +010065 * same offsets for resume and checksum pointers */
66
Vasily Khoruzhick0741b7d2010-05-11 09:55:10 +030067 if (machine_is_rx3715() || machine_is_rx1950()) {
Ben Dooksa21765a2007-02-11 18:31:01 +010068 void *base = phys_to_virt(H1940_SUSPEND_CHECK);
69 unsigned long ptr;
70 unsigned long calc = 0;
71
72 /* generate check for the bootloader to check on resume */
73
74 for (ptr = 0; ptr < 0x40000; ptr += 0x4)
75 calc += __raw_readl(base+ptr);
76
77 __raw_writel(calc, phys_to_virt(H1940_SUSPEND_CHECKSUM));
78 }
79
Sylwester Nawrocki94911732012-07-13 18:05:00 +090080 if (machine_is_aml_m5900()) {
81 gpio_request_one(S3C2410_GPF(2), GPIOF_OUT_INIT_HIGH, NULL);
82 gpio_free(S3C2410_GPF(2));
83 }
Ben Dooksa21765a2007-02-11 18:31:01 +010084
Vasily Khoruzhick192ff912010-05-11 09:55:11 +030085 if (machine_is_rx1950()) {
86 /* According to S3C2442 user's manual, page 7-17,
87 * when the system is operating in NAND boot mode,
88 * the hardware pin configuration - EINT[23:21] –
89 * must be set as input for starting up after
90 * wakeup from sleep mode
91 */
92 s3c_gpio_cfgpin(S3C2410_GPG(13), S3C2410_GPIO_INPUT);
93 s3c_gpio_cfgpin(S3C2410_GPG(14), S3C2410_GPIO_INPUT);
94 s3c_gpio_cfgpin(S3C2410_GPG(15), S3C2410_GPIO_INPUT);
95 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070096}
97
Rafael J. Wysockibb072c32011-04-22 22:03:21 +020098static void s3c2410_pm_resume(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070099{
Ben Dooksa21765a2007-02-11 18:31:01 +0100100 unsigned long tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101
Ben Dooksa21765a2007-02-11 18:31:01 +0100102 /* unset the return-from-sleep flag, to ensure reset */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103
Ben Dooksa21765a2007-02-11 18:31:01 +0100104 tmp = __raw_readl(S3C2410_GSTATUS2);
105 tmp &= S3C2410_GSTATUS2_OFFRESET;
106 __raw_writel(tmp, S3C2410_GSTATUS2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107
Sylwester Nawrocki94911732012-07-13 18:05:00 +0900108 if (machine_is_aml_m5900()) {
109 gpio_request_one(S3C2410_GPF(2), GPIOF_OUT_INIT_LOW, NULL);
110 gpio_free(S3C2410_GPF(2));
111 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112}
113
Rafael J. Wysockibb072c32011-04-22 22:03:21 +0200114struct syscore_ops s3c2410_pm_syscore_ops = {
115 .resume = s3c2410_pm_resume,
116};
117
Heiko Stuebner04511a62012-01-27 15:35:25 +0900118static int s3c2410_pm_add(struct device *dev, struct subsys_interface *sif)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119{
Ben Dooksa21765a2007-02-11 18:31:01 +0100120 pm_cpu_prep = s3c2410_pm_prepare;
121 pm_cpu_sleep = s3c2410_cpu_suspend;
122
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123 return 0;
124}
125
Ben Dooksa21765a2007-02-11 18:31:01 +0100126#if defined(CONFIG_CPU_S3C2410)
Kay Sievers4a858cf2011-12-21 16:01:38 -0800127static struct subsys_interface s3c2410_pm_interface = {
128 .name = "s3c2410_pm",
129 .subsys = &s3c2410_subsys,
130 .add_dev = s3c2410_pm_add,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131};
132
Ben Dooksa21765a2007-02-11 18:31:01 +0100133/* register ourselves */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134
Ben Dooksa21765a2007-02-11 18:31:01 +0100135static int __init s3c2410_pm_drvinit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136{
Kay Sievers4a858cf2011-12-21 16:01:38 -0800137 return subsys_interface_register(&s3c2410_pm_interface);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138}
Ben Dooksa21765a2007-02-11 18:31:01 +0100139
140arch_initcall(s3c2410_pm_drvinit);
Ben Dooksf0176792009-07-30 23:23:38 +0100141
Kay Sievers4a858cf2011-12-21 16:01:38 -0800142static struct subsys_interface s3c2410a_pm_interface = {
143 .name = "s3c2410a_pm",
Kukjin Kimea040182012-01-06 16:08:09 +0900144 .subsys = &s3c2410a_subsys,
Kay Sievers4a858cf2011-12-21 16:01:38 -0800145 .add_dev = s3c2410_pm_add,
Ben Dooksf0176792009-07-30 23:23:38 +0100146};
147
148static int __init s3c2410a_pm_drvinit(void)
149{
Kay Sievers4a858cf2011-12-21 16:01:38 -0800150 return subsys_interface_register(&s3c2410a_pm_interface);
Ben Dooksf0176792009-07-30 23:23:38 +0100151}
152
153arch_initcall(s3c2410a_pm_drvinit);
Ben Dooksa21765a2007-02-11 18:31:01 +0100154#endif
155
156#if defined(CONFIG_CPU_S3C2440)
Kay Sievers4a858cf2011-12-21 16:01:38 -0800157static struct subsys_interface s3c2440_pm_interface = {
158 .name = "s3c2440_pm",
159 .subsys = &s3c2440_subsys,
160 .add_dev = s3c2410_pm_add,
Ben Dooksa21765a2007-02-11 18:31:01 +0100161};
162
163static int __init s3c2440_pm_drvinit(void)
164{
Kay Sievers4a858cf2011-12-21 16:01:38 -0800165 return subsys_interface_register(&s3c2440_pm_interface);
Ben Dooksa21765a2007-02-11 18:31:01 +0100166}
167
168arch_initcall(s3c2440_pm_drvinit);
169#endif
170
171#if defined(CONFIG_CPU_S3C2442)
Kay Sievers4a858cf2011-12-21 16:01:38 -0800172static struct subsys_interface s3c2442_pm_interface = {
173 .name = "s3c2442_pm",
174 .subsys = &s3c2442_subsys,
175 .add_dev = s3c2410_pm_add,
Ben Dooksa21765a2007-02-11 18:31:01 +0100176};
177
178static int __init s3c2442_pm_drvinit(void)
179{
Kay Sievers4a858cf2011-12-21 16:01:38 -0800180 return subsys_interface_register(&s3c2442_pm_interface);
Ben Dooksa21765a2007-02-11 18:31:01 +0100181}
182
183arch_initcall(s3c2442_pm_drvinit);
184#endif