blob: 5d510bca0844005ae5f38c717319da1fa3948168 [file] [log] [blame]
Ben Dooksa21765a2007-02-11 18:31:01 +01001/* linux/arch/arm/plat-s3c24xx/pm.c
2 *
Ben Dooksccae9412009-11-13 22:54:14 +00003 * Copyright (c) 2004-2006 Simtec Electronics
Ben Dooksa21765a2007-02-11 18:31:01 +01004 * Ben Dooks <ben@simtec.co.uk>
5 *
6 * S3C24XX Power Manager (Suspend-To-RAM) support
7 *
8 * See Documentation/arm/Samsung-S3C24XX/Suspend.txt for more information
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 *
24 * Parts based on arch/arm/mach-pxa/pm.c
25 *
26 * Thanks to Dimitry Andric for debugging
27*/
28
29#include <linux/init.h>
30#include <linux/suspend.h>
31#include <linux/errno.h>
32#include <linux/time.h>
Ben Dooksec976d62009-05-13 22:52:24 +010033#include <linux/gpio.h>
Ben Dooksa21765a2007-02-11 18:31:01 +010034#include <linux/interrupt.h>
Ben Dooksa21765a2007-02-11 18:31:01 +010035#include <linux/serial_core.h>
Tushar Behera334a1c72014-02-14 10:32:45 +090036#include <linux/serial_s3c.h>
Russell Kingfced80c2008-09-06 12:10:45 +010037#include <linux/io.h>
Ben Dooksa21765a2007-02-11 18:31:01 +010038
Russell Kinga09e64f2008-08-05 16:14:15 +010039#include <mach/regs-clock.h>
40#include <mach/regs-gpio.h>
Russell Kinga09e64f2008-08-05 16:14:15 +010041#include <mach/regs-irq.h>
Linus Walleijb0161ca2014-01-14 14:24:24 +010042#include <mach/gpio-samsung.h>
Ben Dooksa21765a2007-02-11 18:31:01 +010043
44#include <asm/mach/time.h>
45
Ben Dooks40b956f2010-05-04 14:38:49 +090046#include <plat/gpio-cfg.h>
Ben Dooksa2b7ba92008-10-07 22:26:09 +010047#include <plat/pm.h>
Ben Dooksa21765a2007-02-11 18:31:01 +010048
Kukjin Kim37c3adc2013-02-03 17:00:11 -080049#include "regs-mem.h"
50
Ben Dooksa21765a2007-02-11 18:31:01 +010051#define PFX "s3c24xx-pm: "
52
Arnd Bergmann4f506da2015-02-27 05:50:22 +090053#ifdef CONFIG_PM_SLEEP
Ben Dooksa21765a2007-02-11 18:31:01 +010054static struct sleep_save core_save[] = {
Ben Dooksa21765a2007-02-11 18:31:01 +010055 /* we restore the timings here, with the proviso that the board
56 * brings the system up in an slower, or equal frequency setting
57 * to the original system.
58 *
59 * if we cannot guarantee this, then things are going to go very
60 * wrong here, as we modify the refresh and both pll settings.
61 */
62
63 SAVE_ITEM(S3C2410_BWSCON),
64 SAVE_ITEM(S3C2410_BANKCON0),
65 SAVE_ITEM(S3C2410_BANKCON1),
66 SAVE_ITEM(S3C2410_BANKCON2),
67 SAVE_ITEM(S3C2410_BANKCON3),
68 SAVE_ITEM(S3C2410_BANKCON4),
69 SAVE_ITEM(S3C2410_BANKCON5),
Ben Dooksa21765a2007-02-11 18:31:01 +010070};
Arnd Bergmann4f506da2015-02-27 05:50:22 +090071#endif
Ben Dooksa21765a2007-02-11 18:31:01 +010072
Ben Dooks549c7e32008-12-12 00:24:07 +000073/* s3c_pm_check_resume_pin
Ben Dooksa21765a2007-02-11 18:31:01 +010074 *
75 * check to see if the pin is configured correctly for sleep mode, and
76 * make any necessary adjustments if it is not
77*/
78
Ben Dooks549c7e32008-12-12 00:24:07 +000079static void s3c_pm_check_resume_pin(unsigned int pin, unsigned int irqoffs)
Ben Dooksa21765a2007-02-11 18:31:01 +010080{
81 unsigned long irqstate;
82 unsigned long pinstate;
Ben Dooks5690a622010-05-04 17:14:10 +090083 int irq = gpio_to_irq(pin);
Ben Dooksa21765a2007-02-11 18:31:01 +010084
85 if (irqoffs < 4)
86 irqstate = s3c_irqwake_intmask & (1L<<irqoffs);
87 else
88 irqstate = s3c_irqwake_eintmask & (1L<<irqoffs);
89
Ben Dooks99338472010-05-06 10:50:42 +090090 pinstate = s3c_gpio_getcfg(pin);
Ben Dooksa21765a2007-02-11 18:31:01 +010091
92 if (!irqstate) {
93 if (pinstate == S3C2410_GPIO_IRQ)
Ben Dooks99338472010-05-06 10:50:42 +090094 S3C_PMDBG("Leaving IRQ %d (pin %d) as is\n", irq, pin);
Ben Dooksa21765a2007-02-11 18:31:01 +010095 } else {
96 if (pinstate == S3C2410_GPIO_IRQ) {
Ben Dooks64197112008-12-12 00:24:06 +000097 S3C_PMDBG("Disabling IRQ %d (pin %d)\n", irq, pin);
Ben Dooks40b956f2010-05-04 14:38:49 +090098 s3c_gpio_cfgpin(pin, S3C2410_GPIO_INPUT);
Ben Dooksa21765a2007-02-11 18:31:01 +010099 }
100 }
101}
102
Ben Dooks2261e0e2008-12-12 00:24:08 +0000103/* s3c_pm_configure_extint
Ben Dooksa21765a2007-02-11 18:31:01 +0100104 *
105 * configure all external interrupt pins
106*/
107
Ben Dooks2261e0e2008-12-12 00:24:08 +0000108void s3c_pm_configure_extint(void)
Ben Dooksa21765a2007-02-11 18:31:01 +0100109{
110 int pin;
111
112 /* for each of the external interrupts (EINT0..EINT15) we
Adam Buchbinder48fc7f72012-09-19 21:48:00 -0400113 * need to check whether it is an external interrupt source,
Ben Dooksa21765a2007-02-11 18:31:01 +0100114 * and then configure it as an input if it is not
115 */
116
Ben Dooks070276d2009-05-17 22:32:23 +0100117 for (pin = S3C2410_GPF(0); pin <= S3C2410_GPF(7); pin++) {
118 s3c_pm_check_resume_pin(pin, pin - S3C2410_GPF(0));
Ben Dooksa21765a2007-02-11 18:31:01 +0100119 }
120
Ben Dooks070276d2009-05-17 22:32:23 +0100121 for (pin = S3C2410_GPG(0); pin <= S3C2410_GPG(7); pin++) {
122 s3c_pm_check_resume_pin(pin, (pin - S3C2410_GPG(0))+8);
Ben Dooksa21765a2007-02-11 18:31:01 +0100123 }
124}
125
Arnd Bergmann4f506da2015-02-27 05:50:22 +0900126#ifdef CONFIG_PM_SLEEP
Ben Dooks2261e0e2008-12-12 00:24:08 +0000127void s3c_pm_restore_core(void)
Ben Dooksa21765a2007-02-11 18:31:01 +0100128{
Ben Dooks64197112008-12-12 00:24:06 +0000129 s3c_pm_do_restore_core(core_save, ARRAY_SIZE(core_save));
Ben Dooksa21765a2007-02-11 18:31:01 +0100130}
131
Ben Dooks2261e0e2008-12-12 00:24:08 +0000132void s3c_pm_save_core(void)
Ben Dooksa21765a2007-02-11 18:31:01 +0100133{
Ben Dooks2261e0e2008-12-12 00:24:08 +0000134 s3c_pm_do_save(core_save, ARRAY_SIZE(core_save));
Ben Dooksa21765a2007-02-11 18:31:01 +0100135}
Arnd Bergmann4f506da2015-02-27 05:50:22 +0900136#endif