| Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 1 | /* linux/arch/arm/plat-s3c24xx/pm.c | 
 | 2 |  * | 
 | 3 |  * Copyright (c) 2004,2006 Simtec Electronics | 
 | 4 |  *	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 Dooks | ec976d6 | 2009-05-13 22:52:24 +0100 | [diff] [blame] | 33 | #include <linux/gpio.h> | 
| Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 34 | #include <linux/interrupt.h> | 
| Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 35 | #include <linux/serial_core.h> | 
| Russell King | fced80c | 2008-09-06 12:10:45 +0100 | [diff] [blame] | 36 | #include <linux/io.h> | 
| Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 37 |  | 
| Ben Dooks | a2b7ba9 | 2008-10-07 22:26:09 +0100 | [diff] [blame] | 38 | #include <plat/regs-serial.h> | 
| Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 39 | #include <mach/regs-clock.h> | 
 | 40 | #include <mach/regs-gpio.h> | 
 | 41 | #include <mach/regs-mem.h> | 
 | 42 | #include <mach/regs-irq.h> | 
| Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 43 |  | 
 | 44 | #include <asm/mach/time.h> | 
 | 45 |  | 
| Ben Dooks | a2b7ba9 | 2008-10-07 22:26:09 +0100 | [diff] [blame] | 46 | #include <plat/pm.h> | 
| Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 47 |  | 
| Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 48 | #define PFX "s3c24xx-pm: " | 
 | 49 |  | 
 | 50 | static struct sleep_save core_save[] = { | 
 | 51 | 	SAVE_ITEM(S3C2410_LOCKTIME), | 
 | 52 | 	SAVE_ITEM(S3C2410_CLKCON), | 
 | 53 |  | 
 | 54 | 	/* we restore the timings here, with the proviso that the board | 
 | 55 | 	 * brings the system up in an slower, or equal frequency setting | 
 | 56 | 	 * to the original system. | 
 | 57 | 	 * | 
 | 58 | 	 * if we cannot guarantee this, then things are going to go very | 
 | 59 | 	 * wrong here, as we modify the refresh and both pll settings. | 
 | 60 | 	 */ | 
 | 61 |  | 
 | 62 | 	SAVE_ITEM(S3C2410_BWSCON), | 
 | 63 | 	SAVE_ITEM(S3C2410_BANKCON0), | 
 | 64 | 	SAVE_ITEM(S3C2410_BANKCON1), | 
 | 65 | 	SAVE_ITEM(S3C2410_BANKCON2), | 
 | 66 | 	SAVE_ITEM(S3C2410_BANKCON3), | 
 | 67 | 	SAVE_ITEM(S3C2410_BANKCON4), | 
 | 68 | 	SAVE_ITEM(S3C2410_BANKCON5), | 
 | 69 |  | 
| Ben Dooks | e425382 | 2008-10-21 14:06:38 +0100 | [diff] [blame] | 70 | #ifndef CONFIG_CPU_FREQ | 
| Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 71 | 	SAVE_ITEM(S3C2410_CLKDIVN), | 
 | 72 | 	SAVE_ITEM(S3C2410_MPLLCON), | 
| Ben Dooks | e425382 | 2008-10-21 14:06:38 +0100 | [diff] [blame] | 73 | 	SAVE_ITEM(S3C2410_REFRESH), | 
 | 74 | #endif | 
| Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 75 | 	SAVE_ITEM(S3C2410_UPLLCON), | 
 | 76 | 	SAVE_ITEM(S3C2410_CLKSLOW), | 
| Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 77 | }; | 
 | 78 |  | 
| Ben Dooks | 62feee6 | 2008-01-28 13:01:24 +0100 | [diff] [blame] | 79 | static struct sleep_save misc_save[] = { | 
| Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 80 | 	SAVE_ITEM(S3C2410_DCLKCON), | 
 | 81 | }; | 
 | 82 |  | 
| Ben Dooks | 549c7e3 | 2008-12-12 00:24:07 +0000 | [diff] [blame] | 83 | /* s3c_pm_check_resume_pin | 
| Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 84 |  * | 
 | 85 |  * check to see if the pin is configured correctly for sleep mode, and | 
 | 86 |  * make any necessary adjustments if it is not | 
 | 87 | */ | 
 | 88 |  | 
| Ben Dooks | 549c7e3 | 2008-12-12 00:24:07 +0000 | [diff] [blame] | 89 | static void s3c_pm_check_resume_pin(unsigned int pin, unsigned int irqoffs) | 
| Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 90 | { | 
 | 91 | 	unsigned long irqstate; | 
 | 92 | 	unsigned long pinstate; | 
 | 93 | 	int irq = s3c2410_gpio_getirq(pin); | 
 | 94 |  | 
 | 95 | 	if (irqoffs < 4) | 
 | 96 | 		irqstate = s3c_irqwake_intmask & (1L<<irqoffs); | 
 | 97 | 	else | 
 | 98 | 		irqstate = s3c_irqwake_eintmask & (1L<<irqoffs); | 
 | 99 |  | 
 | 100 | 	pinstate = s3c2410_gpio_getcfg(pin); | 
 | 101 |  | 
 | 102 | 	if (!irqstate) { | 
 | 103 | 		if (pinstate == S3C2410_GPIO_IRQ) | 
| Ben Dooks | 6419711 | 2008-12-12 00:24:06 +0000 | [diff] [blame] | 104 | 			S3C_PMDBG("Leaving IRQ %d (pin %d) enabled\n", irq, pin); | 
| Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 105 | 	} else { | 
 | 106 | 		if (pinstate == S3C2410_GPIO_IRQ) { | 
| Ben Dooks | 6419711 | 2008-12-12 00:24:06 +0000 | [diff] [blame] | 107 | 			S3C_PMDBG("Disabling IRQ %d (pin %d)\n", irq, pin); | 
| Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 108 | 			s3c2410_gpio_cfgpin(pin, S3C2410_GPIO_INPUT); | 
 | 109 | 		} | 
 | 110 | 	} | 
 | 111 | } | 
 | 112 |  | 
| Ben Dooks | 2261e0e | 2008-12-12 00:24:08 +0000 | [diff] [blame] | 113 | /* s3c_pm_configure_extint | 
| Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 114 |  * | 
 | 115 |  * configure all external interrupt pins | 
 | 116 | */ | 
 | 117 |  | 
| Ben Dooks | 2261e0e | 2008-12-12 00:24:08 +0000 | [diff] [blame] | 118 | void s3c_pm_configure_extint(void) | 
| Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 119 | { | 
 | 120 | 	int pin; | 
 | 121 |  | 
 | 122 | 	/* for each of the external interrupts (EINT0..EINT15) we | 
 | 123 | 	 * need to check wether it is an external interrupt source, | 
 | 124 | 	 * and then configure it as an input if it is not | 
 | 125 | 	*/ | 
 | 126 |  | 
| Ben Dooks | 070276d | 2009-05-17 22:32:23 +0100 | [diff] [blame] | 127 | 	for (pin = S3C2410_GPF(0); pin <= S3C2410_GPF(7); pin++) { | 
 | 128 | 		s3c_pm_check_resume_pin(pin, pin - S3C2410_GPF(0)); | 
| Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 129 | 	} | 
 | 130 |  | 
| Ben Dooks | 070276d | 2009-05-17 22:32:23 +0100 | [diff] [blame] | 131 | 	for (pin = S3C2410_GPG(0); pin <= S3C2410_GPG(7); pin++) { | 
 | 132 | 		s3c_pm_check_resume_pin(pin, (pin - S3C2410_GPG(0))+8); | 
| Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 133 | 	} | 
 | 134 | } | 
 | 135 |  | 
| Ben Dooks | 62feee6 | 2008-01-28 13:01:24 +0100 | [diff] [blame] | 136 |  | 
| Ben Dooks | 2261e0e | 2008-12-12 00:24:08 +0000 | [diff] [blame] | 137 | void s3c_pm_restore_core(void) | 
| Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 138 | { | 
| Ben Dooks | 6419711 | 2008-12-12 00:24:06 +0000 | [diff] [blame] | 139 | 	s3c_pm_do_restore_core(core_save, ARRAY_SIZE(core_save)); | 
 | 140 | 	s3c_pm_do_restore(misc_save, ARRAY_SIZE(misc_save)); | 
| Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 141 | } | 
 | 142 |  | 
| Ben Dooks | 2261e0e | 2008-12-12 00:24:08 +0000 | [diff] [blame] | 143 | void s3c_pm_save_core(void) | 
| Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 144 | { | 
| Ben Dooks | 2261e0e | 2008-12-12 00:24:08 +0000 | [diff] [blame] | 145 | 	s3c_pm_do_save(misc_save, ARRAY_SIZE(misc_save)); | 
 | 146 | 	s3c_pm_do_save(core_save, ARRAY_SIZE(core_save)); | 
| Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 147 | } | 
| Ben Dooks | 2261e0e | 2008-12-12 00:24:08 +0000 | [diff] [blame] | 148 |  |