| Tony Lindgren | 670c104 | 2006-04-02 17:46:25 +0100 | [diff] [blame] | 1 | /* | 
 | 2 |  * linux/arch/arm/mach-omap2/pm.c | 
 | 3 |  * | 
 | 4 |  * OMAP2 Power Management Routines | 
 | 5 |  * | 
 | 6 |  * Copyright (C) 2006 Nokia Corporation | 
 | 7 |  * Tony Lindgren <tony@atomide.com> | 
 | 8 |  * | 
 | 9 |  * Copyright (C) 2005 Texas Instruments, Inc. | 
 | 10 |  * Richard Woodruff <r-woodruff2@ti.com> | 
 | 11 |  * | 
 | 12 |  * Based on pm.c for omap1 | 
 | 13 |  * | 
 | 14 |  * This program is free software; you can redistribute it and/or modify | 
 | 15 |  * it under the terms of the GNU General Public License version 2 as | 
 | 16 |  * published by the Free Software Foundation. | 
 | 17 |  */ | 
 | 18 |  | 
| Rafael J. Wysocki | 95d9ffb | 2007-10-18 03:04:39 -0700 | [diff] [blame] | 19 | #include <linux/suspend.h> | 
| Tony Lindgren | 670c104 | 2006-04-02 17:46:25 +0100 | [diff] [blame] | 20 | #include <linux/sched.h> | 
 | 21 | #include <linux/proc_fs.h> | 
| Tony Lindgren | 670c104 | 2006-04-02 17:46:25 +0100 | [diff] [blame] | 22 | #include <linux/interrupt.h> | 
 | 23 | #include <linux/sysfs.h> | 
 | 24 | #include <linux/module.h> | 
| Tony Lindgren | 22a16f3 | 2006-06-26 16:16:18 -0700 | [diff] [blame] | 25 | #include <linux/delay.h> | 
| Tony Lindgren | b81ad56 | 2008-03-18 10:59:00 +0200 | [diff] [blame] | 26 | #include <linux/clk.h> | 
| Tony Lindgren | 670c104 | 2006-04-02 17:46:25 +0100 | [diff] [blame] | 27 |  | 
 | 28 | #include <asm/io.h> | 
 | 29 | #include <asm/irq.h> | 
 | 30 | #include <asm/atomic.h> | 
 | 31 | #include <asm/mach/time.h> | 
 | 32 | #include <asm/mach/irq.h> | 
 | 33 | #include <asm/mach-types.h> | 
 | 34 |  | 
 | 35 | #include <asm/arch/irqs.h> | 
 | 36 | #include <asm/arch/clock.h> | 
 | 37 | #include <asm/arch/sram.h> | 
 | 38 | #include <asm/arch/pm.h> | 
 | 39 |  | 
 | 40 | static struct clk *vclk; | 
 | 41 | static void (*omap2_sram_idle)(void); | 
 | 42 | static void (*omap2_sram_suspend)(int dllctrl, int cpu_rev); | 
 | 43 | static void (*saved_idle)(void); | 
 | 44 |  | 
| Tony Lindgren | 22a16f3 | 2006-06-26 16:16:18 -0700 | [diff] [blame] | 45 | extern void __init pmdomain_init(void); | 
 | 46 | extern void pmdomain_set_autoidle(void); | 
 | 47 |  | 
 | 48 | static unsigned int omap24xx_sleep_save[OMAP24XX_SLEEP_SAVE_SIZE]; | 
 | 49 |  | 
| Tony Lindgren | 670c104 | 2006-04-02 17:46:25 +0100 | [diff] [blame] | 50 | void omap2_pm_idle(void) | 
 | 51 | { | 
 | 52 | 	local_irq_disable(); | 
 | 53 | 	local_fiq_disable(); | 
 | 54 | 	if (need_resched()) { | 
 | 55 | 		local_fiq_enable(); | 
 | 56 | 		local_irq_enable(); | 
 | 57 | 		return; | 
 | 58 | 	} | 
 | 59 |  | 
 | 60 | 	/* | 
 | 61 | 	 * Since an interrupt may set up a timer, we don't want to | 
 | 62 | 	 * reprogram the hardware timer with interrupts enabled. | 
 | 63 | 	 * Re-enable interrupts only after returning from idle. | 
 | 64 | 	 */ | 
 | 65 | 	timer_dyn_reprogram(); | 
 | 66 |  | 
 | 67 | 	omap2_sram_idle(); | 
 | 68 | 	local_fiq_enable(); | 
 | 69 | 	local_irq_enable(); | 
 | 70 | } | 
 | 71 |  | 
| Rafael J. Wysocki | e6c5eb9 | 2007-10-18 03:04:41 -0700 | [diff] [blame] | 72 | static int omap2_pm_prepare(void) | 
| Tony Lindgren | 670c104 | 2006-04-02 17:46:25 +0100 | [diff] [blame] | 73 | { | 
| Tony Lindgren | 670c104 | 2006-04-02 17:46:25 +0100 | [diff] [blame] | 74 | 	/* We cannot sleep in idle until we have resumed */ | 
 | 75 | 	saved_idle = pm_idle; | 
 | 76 | 	pm_idle = NULL; | 
| Rafael J. Wysocki | e6c5eb9 | 2007-10-18 03:04:41 -0700 | [diff] [blame] | 77 | 	return 0; | 
| Tony Lindgren | 670c104 | 2006-04-02 17:46:25 +0100 | [diff] [blame] | 78 | } | 
 | 79 |  | 
| Tony Lindgren | 22a16f3 | 2006-06-26 16:16:18 -0700 | [diff] [blame] | 80 | static int omap2_pm_suspend(void) | 
 | 81 | { | 
| Tony Lindgren | 22a16f3 | 2006-06-26 16:16:18 -0700 | [diff] [blame] | 82 | 	return 0; | 
 | 83 | } | 
 | 84 |  | 
| Tony Lindgren | 670c104 | 2006-04-02 17:46:25 +0100 | [diff] [blame] | 85 | static int omap2_pm_enter(suspend_state_t state) | 
 | 86 | { | 
| Tony Lindgren | 22a16f3 | 2006-06-26 16:16:18 -0700 | [diff] [blame] | 87 | 	int ret = 0; | 
 | 88 |  | 
| Tony Lindgren | 670c104 | 2006-04-02 17:46:25 +0100 | [diff] [blame] | 89 | 	switch (state) | 
 | 90 | 	{ | 
 | 91 | 	case PM_SUSPEND_STANDBY: | 
 | 92 | 	case PM_SUSPEND_MEM: | 
| Tony Lindgren | 22a16f3 | 2006-06-26 16:16:18 -0700 | [diff] [blame] | 93 | 		ret = omap2_pm_suspend(); | 
| Tony Lindgren | 670c104 | 2006-04-02 17:46:25 +0100 | [diff] [blame] | 94 | 		break; | 
| Tony Lindgren | 670c104 | 2006-04-02 17:46:25 +0100 | [diff] [blame] | 95 | 	default: | 
| Tony Lindgren | 22a16f3 | 2006-06-26 16:16:18 -0700 | [diff] [blame] | 96 | 		ret = -EINVAL; | 
| Tony Lindgren | 670c104 | 2006-04-02 17:46:25 +0100 | [diff] [blame] | 97 | 	} | 
 | 98 |  | 
| Tony Lindgren | 22a16f3 | 2006-06-26 16:16:18 -0700 | [diff] [blame] | 99 | 	return ret; | 
| Tony Lindgren | 670c104 | 2006-04-02 17:46:25 +0100 | [diff] [blame] | 100 | } | 
 | 101 |  | 
| Rafael J. Wysocki | e6c5eb9 | 2007-10-18 03:04:41 -0700 | [diff] [blame] | 102 | static void omap2_pm_finish(void) | 
| Tony Lindgren | 670c104 | 2006-04-02 17:46:25 +0100 | [diff] [blame] | 103 | { | 
 | 104 | 	pm_idle = saved_idle; | 
| Tony Lindgren | 670c104 | 2006-04-02 17:46:25 +0100 | [diff] [blame] | 105 | } | 
 | 106 |  | 
| Rafael J. Wysocki | 26398a7 | 2007-10-18 03:04:40 -0700 | [diff] [blame] | 107 | static struct platform_suspend_ops omap_pm_ops = { | 
| Tony Lindgren | 670c104 | 2006-04-02 17:46:25 +0100 | [diff] [blame] | 108 | 	.prepare	= omap2_pm_prepare, | 
 | 109 | 	.enter		= omap2_pm_enter, | 
 | 110 | 	.finish		= omap2_pm_finish, | 
| Rafael J. Wysocki | 26398a7 | 2007-10-18 03:04:40 -0700 | [diff] [blame] | 111 | 	.valid		= suspend_valid_only_mem, | 
| Tony Lindgren | 670c104 | 2006-04-02 17:46:25 +0100 | [diff] [blame] | 112 | }; | 
 | 113 |  | 
 | 114 | int __init omap2_pm_init(void) | 
 | 115 | { | 
| Tony Lindgren | 670c104 | 2006-04-02 17:46:25 +0100 | [diff] [blame] | 116 | 	return 0; | 
 | 117 | } | 
 | 118 |  | 
 | 119 | __initcall(omap2_pm_init); |