blob: ba43ff9e81646616acac13ce2de1e5a9d48e9414 [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>
Ben Dooksa21765a2007-02-11 18:31:01 +010027#include <linux/sysdev.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070028
Russell Kinga09e64f2008-08-05 16:14:15 +010029#include <mach/hardware.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070030#include <asm/io.h>
31
Ben Dooksa21765a2007-02-11 18:31:01 +010032#include <asm/mach-types.h>
33
Russell Kinga09e64f2008-08-05 16:14:15 +010034#include <mach/regs-gpio.h>
35#include <mach/h1940.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036
Ben Dooksa21765a2007-02-11 18:31:01 +010037#include <asm/plat-s3c24xx/cpu.h>
38#include <asm/plat-s3c24xx/pm.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070039
40#ifdef CONFIG_S3C2410_PM_DEBUG
Ben Dooksa21765a2007-02-11 18:31:01 +010041extern void pm_dbg(const char *fmt, ...);
Linus Torvalds1da177e2005-04-16 15:20:36 -070042#define DBG(fmt...) pm_dbg(fmt)
43#else
44#define DBG(fmt...) printk(KERN_DEBUG fmt)
Linus Torvalds1da177e2005-04-16 15:20:36 -070045#endif
46
Ben Dooksa21765a2007-02-11 18:31:01 +010047static void s3c2410_pm_prepare(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070048{
Ben Dooksa21765a2007-02-11 18:31:01 +010049 /* ensure at least GSTATUS3 has the resume address */
Linus Torvalds1da177e2005-04-16 15:20:36 -070050
Ben Dooksa21765a2007-02-11 18:31:01 +010051 __raw_writel(virt_to_phys(s3c2410_cpu_resume), S3C2410_GSTATUS3);
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
Ben Dooksa21765a2007-02-11 18:31:01 +010053 DBG("GSTATUS3 0x%08x\n", __raw_readl(S3C2410_GSTATUS3));
54 DBG("GSTATUS4 0x%08x\n", __raw_readl(S3C2410_GSTATUS4));
Linus Torvalds1da177e2005-04-16 15:20:36 -070055
Ben Dooksa21765a2007-02-11 18:31:01 +010056 if (machine_is_h1940()) {
57 void *base = phys_to_virt(H1940_SUSPEND_CHECK);
58 unsigned long ptr;
59 unsigned long calc = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070060
Ben Dooksa21765a2007-02-11 18:31:01 +010061 /* generate check for the bootloader to check on resume */
Linus Torvalds1da177e2005-04-16 15:20:36 -070062
Ben Dooksa21765a2007-02-11 18:31:01 +010063 for (ptr = 0; ptr < 0x40000; ptr += 0x400)
64 calc += __raw_readl(base+ptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -070065
Ben Dooksa21765a2007-02-11 18:31:01 +010066 __raw_writel(calc, phys_to_virt(H1940_SUSPEND_CHECKSUM));
Linus Torvalds1da177e2005-04-16 15:20:36 -070067 }
68
Ben Dooksa21765a2007-02-11 18:31:01 +010069 /* the RX3715 uses similar code and the same H1940 and the
70 * same offsets for resume and checksum pointers */
71
72 if (machine_is_rx3715()) {
73 void *base = phys_to_virt(H1940_SUSPEND_CHECK);
74 unsigned long ptr;
75 unsigned long calc = 0;
76
77 /* generate check for the bootloader to check on resume */
78
79 for (ptr = 0; ptr < 0x40000; ptr += 0x4)
80 calc += __raw_readl(base+ptr);
81
82 __raw_writel(calc, phys_to_virt(H1940_SUSPEND_CHECKSUM));
83 }
84
85 if ( machine_is_aml_m5900() )
86 s3c2410_gpio_setpin(S3C2410_GPF2, 1);
87
Linus Torvalds1da177e2005-04-16 15:20:36 -070088}
89
Ben Dooksa21765a2007-02-11 18:31:01 +010090static int s3c2410_pm_resume(struct sys_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -070091{
Ben Dooksa21765a2007-02-11 18:31:01 +010092 unsigned long tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -070093
Ben Dooksa21765a2007-02-11 18:31:01 +010094 /* unset the return-from-sleep flag, to ensure reset */
Linus Torvalds1da177e2005-04-16 15:20:36 -070095
Ben Dooksa21765a2007-02-11 18:31:01 +010096 tmp = __raw_readl(S3C2410_GSTATUS2);
97 tmp &= S3C2410_GSTATUS2_OFFRESET;
98 __raw_writel(tmp, S3C2410_GSTATUS2);
Linus Torvalds1da177e2005-04-16 15:20:36 -070099
Ben Dooksa21765a2007-02-11 18:31:01 +0100100 if ( machine_is_aml_m5900() )
101 s3c2410_gpio_setpin(S3C2410_GPF2, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103 return 0;
104}
105
Ben Dooksa21765a2007-02-11 18:31:01 +0100106static int s3c2410_pm_add(struct sys_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107{
Ben Dooksa21765a2007-02-11 18:31:01 +0100108 pm_cpu_prep = s3c2410_pm_prepare;
109 pm_cpu_sleep = s3c2410_cpu_suspend;
110
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111 return 0;
112}
113
Ben Dooksa21765a2007-02-11 18:31:01 +0100114#if defined(CONFIG_CPU_S3C2410)
115static struct sysdev_driver s3c2410_pm_driver = {
116 .add = s3c2410_pm_add,
117 .resume = s3c2410_pm_resume,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118};
119
Ben Dooksa21765a2007-02-11 18:31:01 +0100120/* register ourselves */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121
Ben Dooksa21765a2007-02-11 18:31:01 +0100122static int __init s3c2410_pm_drvinit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123{
Ben Dooksa21765a2007-02-11 18:31:01 +0100124 return sysdev_driver_register(&s3c2410_sysclass, &s3c2410_pm_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125}
Ben Dooksa21765a2007-02-11 18:31:01 +0100126
127arch_initcall(s3c2410_pm_drvinit);
128#endif
129
130#if defined(CONFIG_CPU_S3C2440)
131static struct sysdev_driver s3c2440_pm_driver = {
132 .add = s3c2410_pm_add,
133 .resume = s3c2410_pm_resume,
134};
135
136static int __init s3c2440_pm_drvinit(void)
137{
138 return sysdev_driver_register(&s3c2440_sysclass, &s3c2440_pm_driver);
139}
140
141arch_initcall(s3c2440_pm_drvinit);
142#endif
143
144#if defined(CONFIG_CPU_S3C2442)
145static struct sysdev_driver s3c2442_pm_driver = {
146 .add = s3c2410_pm_add,
147 .resume = s3c2410_pm_resume,
148};
149
150static int __init s3c2442_pm_drvinit(void)
151{
152 return sysdev_driver_register(&s3c2442_sysclass, &s3c2442_pm_driver);
153}
154
155arch_initcall(s3c2442_pm_drvinit);
156#endif