blob: 143e08a599d4097e0e47ea243ed7d34f3e2cf085 [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>
Ben Dooksec976d62009-05-13 22:52:24 +010028#include <linux/gpio.h>
Russell Kingfced80c2008-09-06 12:10:45 +010029#include <linux/io.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070030
Russell Kinga09e64f2008-08-05 16:14:15 +010031#include <mach/hardware.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070032
Ben Dooksa21765a2007-02-11 18:31:01 +010033#include <asm/mach-types.h>
34
Russell Kinga09e64f2008-08-05 16:14:15 +010035#include <mach/regs-gpio.h>
36#include <mach/h1940.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070037
Ben Dooksa2b7ba92008-10-07 22:26:09 +010038#include <plat/cpu.h>
39#include <plat/pm.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070040
Ben Dooksa21765a2007-02-11 18:31:01 +010041static void s3c2410_pm_prepare(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070042{
Ben Dooksa21765a2007-02-11 18:31:01 +010043 /* ensure at least GSTATUS3 has the resume address */
Linus Torvalds1da177e2005-04-16 15:20:36 -070044
Ben Dooksef30e142008-12-12 00:24:19 +000045 __raw_writel(virt_to_phys(s3c_cpu_resume), S3C2410_GSTATUS3);
Linus Torvalds1da177e2005-04-16 15:20:36 -070046
Ben Dooks64197112008-12-12 00:24:06 +000047 S3C_PMDBG("GSTATUS3 0x%08x\n", __raw_readl(S3C2410_GSTATUS3));
48 S3C_PMDBG("GSTATUS4 0x%08x\n", __raw_readl(S3C2410_GSTATUS4));
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
Ben Dooksa21765a2007-02-11 18:31:01 +010050 if (machine_is_h1940()) {
51 void *base = phys_to_virt(H1940_SUSPEND_CHECK);
52 unsigned long ptr;
53 unsigned long calc = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070054
Ben Dooksa21765a2007-02-11 18:31:01 +010055 /* generate check for the bootloader to check on resume */
Linus Torvalds1da177e2005-04-16 15:20:36 -070056
Ben Dooksa21765a2007-02-11 18:31:01 +010057 for (ptr = 0; ptr < 0x40000; ptr += 0x400)
58 calc += __raw_readl(base+ptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -070059
Ben Dooksa21765a2007-02-11 18:31:01 +010060 __raw_writel(calc, phys_to_virt(H1940_SUSPEND_CHECKSUM));
Linus Torvalds1da177e2005-04-16 15:20:36 -070061 }
62
Ben Dooksa21765a2007-02-11 18:31:01 +010063 /* the RX3715 uses similar code and the same H1940 and the
64 * same offsets for resume and checksum pointers */
65
66 if (machine_is_rx3715()) {
67 void *base = phys_to_virt(H1940_SUSPEND_CHECK);
68 unsigned long ptr;
69 unsigned long calc = 0;
70
71 /* generate check for the bootloader to check on resume */
72
73 for (ptr = 0; ptr < 0x40000; ptr += 0x4)
74 calc += __raw_readl(base+ptr);
75
76 __raw_writel(calc, phys_to_virt(H1940_SUSPEND_CHECKSUM));
77 }
78
79 if ( machine_is_aml_m5900() )
Ben Dooks070276d2009-05-17 22:32:23 +010080 s3c2410_gpio_setpin(S3C2410_GPF(2), 1);
Ben Dooksa21765a2007-02-11 18:31:01 +010081
Linus Torvalds1da177e2005-04-16 15:20:36 -070082}
83
Ben Dooksa21765a2007-02-11 18:31:01 +010084static int s3c2410_pm_resume(struct sys_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -070085{
Ben Dooksa21765a2007-02-11 18:31:01 +010086 unsigned long tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -070087
Ben Dooksa21765a2007-02-11 18:31:01 +010088 /* unset the return-from-sleep flag, to ensure reset */
Linus Torvalds1da177e2005-04-16 15:20:36 -070089
Ben Dooksa21765a2007-02-11 18:31:01 +010090 tmp = __raw_readl(S3C2410_GSTATUS2);
91 tmp &= S3C2410_GSTATUS2_OFFRESET;
92 __raw_writel(tmp, S3C2410_GSTATUS2);
Linus Torvalds1da177e2005-04-16 15:20:36 -070093
Ben Dooksa21765a2007-02-11 18:31:01 +010094 if ( machine_is_aml_m5900() )
Ben Dooks070276d2009-05-17 22:32:23 +010095 s3c2410_gpio_setpin(S3C2410_GPF(2), 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -070096
Linus Torvalds1da177e2005-04-16 15:20:36 -070097 return 0;
98}
99
Ben Dooksa21765a2007-02-11 18:31:01 +0100100static int s3c2410_pm_add(struct sys_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101{
Ben Dooksa21765a2007-02-11 18:31:01 +0100102 pm_cpu_prep = s3c2410_pm_prepare;
103 pm_cpu_sleep = s3c2410_cpu_suspend;
104
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105 return 0;
106}
107
Ben Dooksa21765a2007-02-11 18:31:01 +0100108#if defined(CONFIG_CPU_S3C2410)
109static struct sysdev_driver s3c2410_pm_driver = {
110 .add = s3c2410_pm_add,
111 .resume = s3c2410_pm_resume,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112};
113
Ben Dooksa21765a2007-02-11 18:31:01 +0100114/* register ourselves */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115
Ben Dooksa21765a2007-02-11 18:31:01 +0100116static int __init s3c2410_pm_drvinit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117{
Ben Dooksa21765a2007-02-11 18:31:01 +0100118 return sysdev_driver_register(&s3c2410_sysclass, &s3c2410_pm_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119}
Ben Dooksa21765a2007-02-11 18:31:01 +0100120
121arch_initcall(s3c2410_pm_drvinit);
122#endif
123
124#if defined(CONFIG_CPU_S3C2440)
125static struct sysdev_driver s3c2440_pm_driver = {
126 .add = s3c2410_pm_add,
127 .resume = s3c2410_pm_resume,
128};
129
130static int __init s3c2440_pm_drvinit(void)
131{
132 return sysdev_driver_register(&s3c2440_sysclass, &s3c2440_pm_driver);
133}
134
135arch_initcall(s3c2440_pm_drvinit);
136#endif
137
138#if defined(CONFIG_CPU_S3C2442)
139static struct sysdev_driver s3c2442_pm_driver = {
140 .add = s3c2410_pm_add,
141 .resume = s3c2410_pm_resume,
142};
143
144static int __init s3c2442_pm_drvinit(void)
145{
146 return sysdev_driver_register(&s3c2442_sysclass, &s3c2442_pm_driver);
147}
148
149arch_initcall(s3c2442_pm_drvinit);
150#endif