blob: 87fc481d92d4949f0a22a0f10d49a8f1051c2b36 [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>
Russell Kingfced80c2008-09-06 12:10:45 +010028#include <linux/io.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070029
Russell Kinga09e64f2008-08-05 16:14:15 +010030#include <mach/hardware.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070031
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 Dooksa2b7ba92008-10-07 22:26:09 +010037#include <plat/cpu.h>
38#include <plat/pm.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070039
Ben Dooksa21765a2007-02-11 18:31:01 +010040static void s3c2410_pm_prepare(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070041{
Ben Dooksa21765a2007-02-11 18:31:01 +010042 /* ensure at least GSTATUS3 has the resume address */
Linus Torvalds1da177e2005-04-16 15:20:36 -070043
Ben Dooksef30e142008-12-12 00:24:19 +000044 __raw_writel(virt_to_phys(s3c_cpu_resume), S3C2410_GSTATUS3);
Linus Torvalds1da177e2005-04-16 15:20:36 -070045
Ben Dooks64197112008-12-12 00:24:06 +000046 S3C_PMDBG("GSTATUS3 0x%08x\n", __raw_readl(S3C2410_GSTATUS3));
47 S3C_PMDBG("GSTATUS4 0x%08x\n", __raw_readl(S3C2410_GSTATUS4));
Linus Torvalds1da177e2005-04-16 15:20:36 -070048
Ben Dooksa21765a2007-02-11 18:31:01 +010049 if (machine_is_h1940()) {
50 void *base = phys_to_virt(H1940_SUSPEND_CHECK);
51 unsigned long ptr;
52 unsigned long calc = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070053
Ben Dooksa21765a2007-02-11 18:31:01 +010054 /* generate check for the bootloader to check on resume */
Linus Torvalds1da177e2005-04-16 15:20:36 -070055
Ben Dooksa21765a2007-02-11 18:31:01 +010056 for (ptr = 0; ptr < 0x40000; ptr += 0x400)
57 calc += __raw_readl(base+ptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -070058
Ben Dooksa21765a2007-02-11 18:31:01 +010059 __raw_writel(calc, phys_to_virt(H1940_SUSPEND_CHECKSUM));
Linus Torvalds1da177e2005-04-16 15:20:36 -070060 }
61
Ben Dooksa21765a2007-02-11 18:31:01 +010062 /* the RX3715 uses similar code and the same H1940 and the
63 * same offsets for resume and checksum pointers */
64
65 if (machine_is_rx3715()) {
66 void *base = phys_to_virt(H1940_SUSPEND_CHECK);
67 unsigned long ptr;
68 unsigned long calc = 0;
69
70 /* generate check for the bootloader to check on resume */
71
72 for (ptr = 0; ptr < 0x40000; ptr += 0x4)
73 calc += __raw_readl(base+ptr);
74
75 __raw_writel(calc, phys_to_virt(H1940_SUSPEND_CHECKSUM));
76 }
77
78 if ( machine_is_aml_m5900() )
79 s3c2410_gpio_setpin(S3C2410_GPF2, 1);
80
Linus Torvalds1da177e2005-04-16 15:20:36 -070081}
82
Ben Dooksa21765a2007-02-11 18:31:01 +010083static int s3c2410_pm_resume(struct sys_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -070084{
Ben Dooksa21765a2007-02-11 18:31:01 +010085 unsigned long tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -070086
Ben Dooksa21765a2007-02-11 18:31:01 +010087 /* unset the return-from-sleep flag, to ensure reset */
Linus Torvalds1da177e2005-04-16 15:20:36 -070088
Ben Dooksa21765a2007-02-11 18:31:01 +010089 tmp = __raw_readl(S3C2410_GSTATUS2);
90 tmp &= S3C2410_GSTATUS2_OFFRESET;
91 __raw_writel(tmp, S3C2410_GSTATUS2);
Linus Torvalds1da177e2005-04-16 15:20:36 -070092
Ben Dooksa21765a2007-02-11 18:31:01 +010093 if ( machine_is_aml_m5900() )
94 s3c2410_gpio_setpin(S3C2410_GPF2, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -070095
Linus Torvalds1da177e2005-04-16 15:20:36 -070096 return 0;
97}
98
Ben Dooksa21765a2007-02-11 18:31:01 +010099static int s3c2410_pm_add(struct sys_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100{
Ben Dooksa21765a2007-02-11 18:31:01 +0100101 pm_cpu_prep = s3c2410_pm_prepare;
102 pm_cpu_sleep = s3c2410_cpu_suspend;
103
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104 return 0;
105}
106
Ben Dooksa21765a2007-02-11 18:31:01 +0100107#if defined(CONFIG_CPU_S3C2410)
108static struct sysdev_driver s3c2410_pm_driver = {
109 .add = s3c2410_pm_add,
110 .resume = s3c2410_pm_resume,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111};
112
Ben Dooksa21765a2007-02-11 18:31:01 +0100113/* register ourselves */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114
Ben Dooksa21765a2007-02-11 18:31:01 +0100115static int __init s3c2410_pm_drvinit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116{
Ben Dooksa21765a2007-02-11 18:31:01 +0100117 return sysdev_driver_register(&s3c2410_sysclass, &s3c2410_pm_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118}
Ben Dooksa21765a2007-02-11 18:31:01 +0100119
120arch_initcall(s3c2410_pm_drvinit);
121#endif
122
123#if defined(CONFIG_CPU_S3C2440)
124static struct sysdev_driver s3c2440_pm_driver = {
125 .add = s3c2410_pm_add,
126 .resume = s3c2410_pm_resume,
127};
128
129static int __init s3c2440_pm_drvinit(void)
130{
131 return sysdev_driver_register(&s3c2440_sysclass, &s3c2440_pm_driver);
132}
133
134arch_initcall(s3c2440_pm_drvinit);
135#endif
136
137#if defined(CONFIG_CPU_S3C2442)
138static struct sysdev_driver s3c2442_pm_driver = {
139 .add = s3c2410_pm_add,
140 .resume = s3c2410_pm_resume,
141};
142
143static int __init s3c2442_pm_drvinit(void)
144{
145 return sysdev_driver_register(&s3c2442_sysclass, &s3c2442_pm_driver);
146}
147
148arch_initcall(s3c2442_pm_drvinit);
149#endif