pm.c 3.8 KB
Newer Older
1 2
/* linux/arch/arm/plat-s3c24xx/pm.c
 *
3
 * Copyright (c) 2004-2006 Simtec Electronics
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
 *	Ben Dooks <ben@simtec.co.uk>
 *
 * S3C24XX Power Manager (Suspend-To-RAM) support
 *
 * See Documentation/arm/Samsung-S3C24XX/Suspend.txt for more information
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 * Parts based on arch/arm/mach-pxa/pm.c
 *
 * Thanks to Dimitry Andric for debugging
*/

#include <linux/init.h>
#include <linux/suspend.h>
#include <linux/errno.h>
#include <linux/time.h>
33
#include <linux/gpio.h>
34 35
#include <linux/interrupt.h>
#include <linux/serial_core.h>
36
#include <linux/io.h>
37

38
#include <plat/regs-serial.h>
39 40 41
#include <mach/regs-clock.h>
#include <mach/regs-gpio.h>
#include <mach/regs-irq.h>
42 43 44

#include <asm/mach/time.h>

45
#include <plat/gpio-cfg.h>
46
#include <plat/pm.h>
47

48 49
#include "regs-mem.h"

50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
#define PFX "s3c24xx-pm: "

static struct sleep_save core_save[] = {
	SAVE_ITEM(S3C2410_LOCKTIME),
	SAVE_ITEM(S3C2410_CLKCON),

	/* we restore the timings here, with the proviso that the board
	 * brings the system up in an slower, or equal frequency setting
	 * to the original system.
	 *
	 * if we cannot guarantee this, then things are going to go very
	 * wrong here, as we modify the refresh and both pll settings.
	 */

	SAVE_ITEM(S3C2410_BWSCON),
	SAVE_ITEM(S3C2410_BANKCON0),
	SAVE_ITEM(S3C2410_BANKCON1),
	SAVE_ITEM(S3C2410_BANKCON2),
	SAVE_ITEM(S3C2410_BANKCON3),
	SAVE_ITEM(S3C2410_BANKCON4),
	SAVE_ITEM(S3C2410_BANKCON5),

72
#ifndef CONFIG_CPU_FREQ
73 74
	SAVE_ITEM(S3C2410_CLKDIVN),
	SAVE_ITEM(S3C2410_MPLLCON),
75 76
	SAVE_ITEM(S3C2410_REFRESH),
#endif
77 78 79 80
	SAVE_ITEM(S3C2410_UPLLCON),
	SAVE_ITEM(S3C2410_CLKSLOW),
};

81
static struct sleep_save misc_save[] = {
82 83 84
	SAVE_ITEM(S3C2410_DCLKCON),
};

85
/* s3c_pm_check_resume_pin
86 87 88 89 90
 *
 * check to see if the pin is configured correctly for sleep mode, and
 * make any necessary adjustments if it is not
*/

91
static void s3c_pm_check_resume_pin(unsigned int pin, unsigned int irqoffs)
92 93 94
{
	unsigned long irqstate;
	unsigned long pinstate;
95
	int irq = gpio_to_irq(pin);
96 97 98 99 100 101

	if (irqoffs < 4)
		irqstate = s3c_irqwake_intmask & (1L<<irqoffs);
	else
		irqstate = s3c_irqwake_eintmask & (1L<<irqoffs);

102
	pinstate = s3c_gpio_getcfg(pin);
103 104 105

	if (!irqstate) {
		if (pinstate == S3C2410_GPIO_IRQ)
106
			S3C_PMDBG("Leaving IRQ %d (pin %d) as is\n", irq, pin);
107 108
	} else {
		if (pinstate == S3C2410_GPIO_IRQ) {
109
			S3C_PMDBG("Disabling IRQ %d (pin %d)\n", irq, pin);
110
			s3c_gpio_cfgpin(pin, S3C2410_GPIO_INPUT);
111 112 113 114
		}
	}
}

115
/* s3c_pm_configure_extint
116 117 118 119
 *
 * configure all external interrupt pins
*/

120
void s3c_pm_configure_extint(void)
121 122 123 124
{
	int pin;

	/* for each of the external interrupts (EINT0..EINT15) we
125
	 * need to check whether it is an external interrupt source,
126 127 128
	 * and then configure it as an input if it is not
	*/

129 130
	for (pin = S3C2410_GPF(0); pin <= S3C2410_GPF(7); pin++) {
		s3c_pm_check_resume_pin(pin, pin - S3C2410_GPF(0));
131 132
	}

133 134
	for (pin = S3C2410_GPG(0); pin <= S3C2410_GPG(7); pin++) {
		s3c_pm_check_resume_pin(pin, (pin - S3C2410_GPG(0))+8);
135 136 137
	}
}

138

139
void s3c_pm_restore_core(void)
140
{
141 142
	s3c_pm_do_restore_core(core_save, ARRAY_SIZE(core_save));
	s3c_pm_do_restore(misc_save, ARRAY_SIZE(misc_save));
143 144
}

145
void s3c_pm_save_core(void)
146
{
147 148
	s3c_pm_do_save(misc_save, ARRAY_SIZE(misc_save));
	s3c_pm_do_save(core_save, ARRAY_SIZE(core_save));
149
}
150