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> |
Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 27 | #include <linux/sysdev.h> |
Russell King | fced80c | 2008-09-06 12:10:45 +0100 | [diff] [blame] | 28 | #include <linux/io.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 30 | #include <mach/hardware.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 | |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 34 | #include <mach/regs-gpio.h> |
| 35 | #include <mach/h1940.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | |
Ben Dooks | a2b7ba9 | 2008-10-07 22:26:09 +0100 | [diff] [blame] | 37 | #include <plat/cpu.h> |
| 38 | #include <plat/pm.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | |
Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 40 | static void s3c2410_pm_prepare(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | { |
Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 42 | /* ensure at least GSTATUS3 has the resume address */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | |
Ben Dooks | ef30e14 | 2008-12-12 00:24:19 +0000 | [diff] [blame] | 44 | __raw_writel(virt_to_phys(s3c_cpu_resume), S3C2410_GSTATUS3); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | |
Ben Dooks | 6419711 | 2008-12-12 00:24:06 +0000 | [diff] [blame] | 46 | S3C_PMDBG("GSTATUS3 0x%08x\n", __raw_readl(S3C2410_GSTATUS3)); |
| 47 | S3C_PMDBG("GSTATUS4 0x%08x\n", __raw_readl(S3C2410_GSTATUS4)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | |
Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 49 | if (machine_is_h1940()) { |
| 50 | void *base = phys_to_virt(H1940_SUSPEND_CHECK); |
| 51 | unsigned long ptr; |
| 52 | unsigned long calc = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | |
Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 54 | /* generate check for the bootloader to check on resume */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | |
Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 56 | for (ptr = 0; ptr < 0x40000; ptr += 0x400) |
| 57 | calc += __raw_readl(base+ptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | |
Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 59 | __raw_writel(calc, phys_to_virt(H1940_SUSPEND_CHECKSUM)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | } |
| 61 | |
Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 62 | /* 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | } |
| 82 | |
Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 83 | static int s3c2410_pm_resume(struct sys_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | { |
Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 85 | unsigned long tmp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | |
Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 87 | /* unset the return-from-sleep flag, to ensure reset */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | |
Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 89 | tmp = __raw_readl(S3C2410_GSTATUS2); |
| 90 | tmp &= S3C2410_GSTATUS2_OFFRESET; |
| 91 | __raw_writel(tmp, S3C2410_GSTATUS2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | |
Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 93 | if ( machine_is_aml_m5900() ) |
| 94 | s3c2410_gpio_setpin(S3C2410_GPF2, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | return 0; |
| 97 | } |
| 98 | |
Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 99 | static int s3c2410_pm_add(struct sys_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | { |
Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 101 | pm_cpu_prep = s3c2410_pm_prepare; |
| 102 | pm_cpu_sleep = s3c2410_cpu_suspend; |
| 103 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | return 0; |
| 105 | } |
| 106 | |
Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 107 | #if defined(CONFIG_CPU_S3C2410) |
| 108 | static struct sysdev_driver s3c2410_pm_driver = { |
| 109 | .add = s3c2410_pm_add, |
| 110 | .resume = s3c2410_pm_resume, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | }; |
| 112 | |
Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 113 | /* register ourselves */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | |
Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 115 | static int __init s3c2410_pm_drvinit(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | { |
Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 117 | return sysdev_driver_register(&s3c2410_sysclass, &s3c2410_pm_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | } |
Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 119 | |
| 120 | arch_initcall(s3c2410_pm_drvinit); |
| 121 | #endif |
| 122 | |
| 123 | #if defined(CONFIG_CPU_S3C2440) |
| 124 | static struct sysdev_driver s3c2440_pm_driver = { |
| 125 | .add = s3c2410_pm_add, |
| 126 | .resume = s3c2410_pm_resume, |
| 127 | }; |
| 128 | |
| 129 | static int __init s3c2440_pm_drvinit(void) |
| 130 | { |
| 131 | return sysdev_driver_register(&s3c2440_sysclass, &s3c2440_pm_driver); |
| 132 | } |
| 133 | |
| 134 | arch_initcall(s3c2440_pm_drvinit); |
| 135 | #endif |
| 136 | |
| 137 | #if defined(CONFIG_CPU_S3C2442) |
| 138 | static struct sysdev_driver s3c2442_pm_driver = { |
| 139 | .add = s3c2410_pm_add, |
| 140 | .resume = s3c2410_pm_resume, |
| 141 | }; |
| 142 | |
| 143 | static int __init s3c2442_pm_drvinit(void) |
| 144 | { |
| 145 | return sysdev_driver_register(&s3c2442_sysclass, &s3c2442_pm_driver); |
| 146 | } |
| 147 | |
| 148 | arch_initcall(s3c2442_pm_drvinit); |
| 149 | #endif |