| Vitaly Wool | 78818e4 | 2006-05-16 11:54:37 +0100 | [diff] [blame] | 1 | /* | 
 | 2 |  * arch/arm/mach-pnx4008/pm.c | 
 | 3 |  * | 
 | 4 |  * Power Management driver for PNX4008 | 
 | 5 |  * | 
 | 6 |  * Authors: Vitaly Wool, Dmitry Chigirev <source@mvista.com> | 
 | 7 |  * | 
 | 8 |  * 2005 (c) MontaVista Software, Inc. This file is licensed under | 
 | 9 |  * the terms of the GNU General Public License version 2. This program | 
 | 10 |  * is licensed "as is" without any warranty of any kind, whether express | 
 | 11 |  * or implied. | 
 | 12 |  */ | 
 | 13 |  | 
 | 14 | #include <linux/pm.h> | 
 | 15 | #include <linux/rtc.h> | 
 | 16 | #include <linux/sched.h> | 
 | 17 | #include <linux/proc_fs.h> | 
| Rafael J. Wysocki | 95d9ffb | 2007-10-18 03:04:39 -0700 | [diff] [blame] | 18 | #include <linux/suspend.h> | 
| Vitaly Wool | 78818e4 | 2006-05-16 11:54:37 +0100 | [diff] [blame] | 19 | #include <linux/delay.h> | 
 | 20 | #include <linux/clk.h> | 
 | 21 |  | 
 | 22 | #include <asm/io.h> | 
 | 23 | #include <asm/mach-types.h> | 
 | 24 | #include <asm/cacheflush.h> | 
 | 25 | #include <asm/arch/pm.h> | 
 | 26 | #include <asm/arch/clock.h> | 
 | 27 |  | 
 | 28 | #define SRAM_VA IO_ADDRESS(PNX4008_IRAM_BASE) | 
 | 29 |  | 
 | 30 | static void *saved_sram; | 
 | 31 |  | 
 | 32 | static struct clk *pll4_clk; | 
 | 33 |  | 
 | 34 | static inline void pnx4008_standby(void) | 
 | 35 | { | 
 | 36 | 	void (*pnx4008_cpu_standby_ptr) (void); | 
 | 37 |  | 
 | 38 | 	local_irq_disable(); | 
 | 39 | 	local_fiq_disable(); | 
 | 40 |  | 
 | 41 | 	clk_disable(pll4_clk); | 
 | 42 |  | 
 | 43 | 	/*saving portion of SRAM to be used by suspend function. */ | 
 | 44 | 	memcpy(saved_sram, (void *)SRAM_VA, pnx4008_cpu_standby_sz); | 
 | 45 |  | 
 | 46 | 	/*make sure SRAM copy gets physically written into SDRAM. | 
 | 47 | 	   SDRAM will be placed into self-refresh during power down */ | 
 | 48 | 	flush_cache_all(); | 
 | 49 |  | 
 | 50 | 	/*copy suspend function into SRAM */ | 
 | 51 | 	memcpy((void *)SRAM_VA, pnx4008_cpu_standby, pnx4008_cpu_standby_sz); | 
 | 52 |  | 
 | 53 | 	/*do suspend */ | 
 | 54 | 	pnx4008_cpu_standby_ptr = (void *)SRAM_VA; | 
 | 55 | 	pnx4008_cpu_standby_ptr(); | 
 | 56 |  | 
 | 57 | 	/*restoring portion of SRAM that was used by suspend function */ | 
 | 58 | 	memcpy((void *)SRAM_VA, saved_sram, pnx4008_cpu_standby_sz); | 
 | 59 |  | 
 | 60 | 	clk_enable(pll4_clk); | 
 | 61 |  | 
 | 62 | 	local_fiq_enable(); | 
 | 63 | 	local_irq_enable(); | 
 | 64 | } | 
 | 65 |  | 
 | 66 | static inline void pnx4008_suspend(void) | 
 | 67 | { | 
 | 68 | 	void (*pnx4008_cpu_suspend_ptr) (void); | 
 | 69 |  | 
 | 70 | 	local_irq_disable(); | 
 | 71 | 	local_fiq_disable(); | 
 | 72 |  | 
 | 73 | 	clk_disable(pll4_clk); | 
 | 74 |  | 
 | 75 | 	__raw_writel(0xffffffff, START_INT_RSR_REG(SE_PIN_BASE_INT)); | 
 | 76 | 	__raw_writel(0xffffffff, START_INT_RSR_REG(SE_INT_BASE_INT)); | 
 | 77 |  | 
 | 78 | 	/*saving portion of SRAM to be used by suspend function. */ | 
 | 79 | 	memcpy(saved_sram, (void *)SRAM_VA, pnx4008_cpu_suspend_sz); | 
 | 80 |  | 
 | 81 | 	/*make sure SRAM copy gets physically written into SDRAM. | 
 | 82 | 	   SDRAM will be placed into self-refresh during power down */ | 
 | 83 | 	flush_cache_all(); | 
 | 84 |  | 
 | 85 | 	/*copy suspend function into SRAM */ | 
 | 86 | 	memcpy((void *)SRAM_VA, pnx4008_cpu_suspend, pnx4008_cpu_suspend_sz); | 
 | 87 |  | 
 | 88 | 	/*do suspend */ | 
 | 89 | 	pnx4008_cpu_suspend_ptr = (void *)SRAM_VA; | 
 | 90 | 	pnx4008_cpu_suspend_ptr(); | 
 | 91 |  | 
 | 92 | 	/*restoring portion of SRAM that was used by suspend function */ | 
 | 93 | 	memcpy((void *)SRAM_VA, saved_sram, pnx4008_cpu_suspend_sz); | 
 | 94 |  | 
 | 95 | 	clk_enable(pll4_clk); | 
 | 96 |  | 
 | 97 | 	local_fiq_enable(); | 
 | 98 | 	local_irq_enable(); | 
 | 99 | } | 
 | 100 |  | 
 | 101 | static int pnx4008_pm_enter(suspend_state_t state) | 
 | 102 | { | 
 | 103 | 	switch (state) { | 
 | 104 | 	case PM_SUSPEND_STANDBY: | 
 | 105 | 		pnx4008_standby(); | 
 | 106 | 		break; | 
 | 107 | 	case PM_SUSPEND_MEM: | 
 | 108 | 		pnx4008_suspend(); | 
 | 109 | 		break; | 
| Vitaly Wool | 78818e4 | 2006-05-16 11:54:37 +0100 | [diff] [blame] | 110 | 	} | 
 | 111 | 	return 0; | 
 | 112 | } | 
 | 113 |  | 
| Johannes Berg | e8c9c50 | 2007-04-30 15:09:54 -0700 | [diff] [blame] | 114 | static int pnx4008_pm_valid(suspend_state_t state) | 
| Vitaly Wool | 78818e4 | 2006-05-16 11:54:37 +0100 | [diff] [blame] | 115 | { | 
| Johannes Berg | e8c9c50 | 2007-04-30 15:09:54 -0700 | [diff] [blame] | 116 | 	return (state == PM_SUSPEND_STANDBY) || | 
 | 117 | 	       (state == PM_SUSPEND_MEM); | 
| Vitaly Wool | 78818e4 | 2006-05-16 11:54:37 +0100 | [diff] [blame] | 118 | } | 
 | 119 |  | 
| Rafael J. Wysocki | 26398a7 | 2007-10-18 03:04:40 -0700 | [diff] [blame] | 120 | static struct platform_suspend_ops pnx4008_pm_ops = { | 
| Vitaly Wool | 78818e4 | 2006-05-16 11:54:37 +0100 | [diff] [blame] | 121 | 	.enter = pnx4008_pm_enter, | 
| Johannes Berg | e8c9c50 | 2007-04-30 15:09:54 -0700 | [diff] [blame] | 122 | 	.valid = pnx4008_pm_valid, | 
| Vitaly Wool | 78818e4 | 2006-05-16 11:54:37 +0100 | [diff] [blame] | 123 | }; | 
 | 124 |  | 
 | 125 | static int __init pnx4008_pm_init(void) | 
 | 126 | { | 
 | 127 | 	u32 sram_size_to_allocate; | 
 | 128 |  | 
 | 129 | 	pll4_clk = clk_get(0, "ck_pll4"); | 
 | 130 | 	if (IS_ERR(pll4_clk)) { | 
 | 131 | 		printk(KERN_ERR | 
 | 132 | 		       "PM Suspend cannot acquire ARM(PLL4) clock control\n"); | 
 | 133 | 		return PTR_ERR(pll4_clk); | 
 | 134 | 	} | 
 | 135 |  | 
 | 136 | 	if (pnx4008_cpu_standby_sz > pnx4008_cpu_suspend_sz) | 
 | 137 | 		sram_size_to_allocate = pnx4008_cpu_standby_sz; | 
 | 138 | 	else | 
 | 139 | 		sram_size_to_allocate = pnx4008_cpu_suspend_sz; | 
 | 140 |  | 
 | 141 | 	saved_sram = kmalloc(sram_size_to_allocate, GFP_ATOMIC); | 
 | 142 | 	if (!saved_sram) { | 
 | 143 | 		printk(KERN_ERR | 
 | 144 | 		       "PM Suspend: cannot allocate memory to save portion of SRAM\n"); | 
 | 145 | 		clk_put(pll4_clk); | 
 | 146 | 		return -ENOMEM; | 
 | 147 | 	} | 
 | 148 |  | 
| Rafael J. Wysocki | 26398a7 | 2007-10-18 03:04:40 -0700 | [diff] [blame] | 149 | 	suspend_set_ops(&pnx4008_pm_ops); | 
| Vitaly Wool | 78818e4 | 2006-05-16 11:54:37 +0100 | [diff] [blame] | 150 | 	return 0; | 
 | 151 | } | 
 | 152 |  | 
 | 153 | late_initcall(pnx4008_pm_init); |