blob: 72e3ab2ac0884de145891c31840f957c8a74220a [file] [log] [blame]
Ben Dooksbd117bd2009-03-10 18:19:35 +00001/* linux/arch/arm/plat-s3c64xx/pm.c
2 *
3 * Copyright 2008 Openmoko, Inc.
4 * Copyright 2008 Simtec Electronics
5 * Ben Dooks <ben@simtec.co.uk>
6 * http://armlinux.simtec.co.uk/
7 *
8 * S3C64XX CPU PM support.
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 version 2 as
12 * published by the Free Software Foundation.
13*/
14
15#include <linux/init.h>
16#include <linux/suspend.h>
17#include <linux/serial_core.h>
18#include <linux/io.h>
Abhilash Kesavanf98d4292011-08-13 10:40:52 +090019#include <linux/gpio.h>
Ben Dooksbd117bd2009-03-10 18:19:35 +000020
21#include <mach/map.h>
Ben Dooksfda22572010-05-20 12:56:45 +090022#include <mach/irqs.h>
Ben Dooksbd117bd2009-03-10 18:19:35 +000023
24#include <plat/pm.h>
Ben Dooksfda22572010-05-20 12:56:45 +090025#include <plat/wakeup-mask.h>
26
Ben Dooks3501c9a2010-01-26 10:45:40 +090027#include <mach/regs-sys.h>
28#include <mach/regs-gpio.h>
29#include <mach/regs-clock.h>
30#include <mach/regs-syscon-power.h>
31#include <mach/regs-gpio-memport.h>
Ben Dooksbd117bd2009-03-10 18:19:35 +000032
33#ifdef CONFIG_S3C_PM_DEBUG_LED_SMDK
Ben Dooksbd117bd2009-03-10 18:19:35 +000034void s3c_pm_debug_smdkled(u32 set, u32 clear)
35{
36 unsigned long flags;
Joonyoung Shim31858472011-05-06 09:37:17 +090037 int i;
Ben Dooksbd117bd2009-03-10 18:19:35 +000038
39 local_irq_save(flags);
Joonyoung Shim31858472011-05-06 09:37:17 +090040 for (i = 0; i < 4; i++) {
41 if (clear & (1 << i))
42 gpio_set_value(S3C64XX_GPN(12 + i), 0);
43 if (set & (1 << i))
44 gpio_set_value(S3C64XX_GPN(12 + i), 1);
45 }
Ben Dooksbd117bd2009-03-10 18:19:35 +000046 local_irq_restore(flags);
47}
48#endif
49
50static struct sleep_save core_save[] = {
51 SAVE_ITEM(S3C_APLL_LOCK),
52 SAVE_ITEM(S3C_MPLL_LOCK),
53 SAVE_ITEM(S3C_EPLL_LOCK),
54 SAVE_ITEM(S3C_CLK_SRC),
55 SAVE_ITEM(S3C_CLK_DIV0),
56 SAVE_ITEM(S3C_CLK_DIV1),
57 SAVE_ITEM(S3C_CLK_DIV2),
58 SAVE_ITEM(S3C_CLK_OUT),
59 SAVE_ITEM(S3C_HCLK_GATE),
60 SAVE_ITEM(S3C_PCLK_GATE),
61 SAVE_ITEM(S3C_SCLK_GATE),
62 SAVE_ITEM(S3C_MEM0_GATE),
63
64 SAVE_ITEM(S3C_EPLL_CON1),
65 SAVE_ITEM(S3C_EPLL_CON0),
66
67 SAVE_ITEM(S3C64XX_MEM0DRVCON),
68 SAVE_ITEM(S3C64XX_MEM1DRVCON),
69
70#ifndef CONFIG_CPU_FREQ
71 SAVE_ITEM(S3C_APLL_CON),
72 SAVE_ITEM(S3C_MPLL_CON),
73#endif
74};
75
76static struct sleep_save misc_save[] = {
77 SAVE_ITEM(S3C64XX_AHB_CON0),
78 SAVE_ITEM(S3C64XX_AHB_CON1),
79 SAVE_ITEM(S3C64XX_AHB_CON2),
80
81 SAVE_ITEM(S3C64XX_SPCON),
82
83 SAVE_ITEM(S3C64XX_MEM0CONSTOP),
84 SAVE_ITEM(S3C64XX_MEM1CONSTOP),
85 SAVE_ITEM(S3C64XX_MEM0CONSLP0),
86 SAVE_ITEM(S3C64XX_MEM0CONSLP1),
87 SAVE_ITEM(S3C64XX_MEM1CONSLP),
Tomasz Figa348276f2011-08-23 11:33:08 +090088
89 SAVE_ITEM(S3C64XX_SDMA_SEL),
Ben Dooksbd117bd2009-03-10 18:19:35 +000090};
91
92void s3c_pm_configure_extint(void)
93{
94 __raw_writel(s3c_irqwake_eintmask, S3C64XX_EINT_MASK);
95}
96
Ben Dooksbd117bd2009-03-10 18:19:35 +000097void s3c_pm_restore_core(void)
98{
99 __raw_writel(0, S3C64XX_EINT_MASK);
100
101 s3c_pm_debug_smdkled(1 << 2, 0);
102
103 s3c_pm_do_restore_core(core_save, ARRAY_SIZE(core_save));
104 s3c_pm_do_restore(misc_save, ARRAY_SIZE(misc_save));
105}
106
107void s3c_pm_save_core(void)
108{
109 s3c_pm_do_save(misc_save, ARRAY_SIZE(misc_save));
110 s3c_pm_do_save(core_save, ARRAY_SIZE(core_save));
111}
112
113/* since both s3c6400 and s3c6410 share the same sleep pm calls, we
114 * put the per-cpu code in here until any new cpu comes along and changes
115 * this.
116 */
117
Russell King29cb3cd2011-07-02 09:54:01 +0100118static int s3c64xx_cpu_suspend(unsigned long arg)
Ben Dooksbd117bd2009-03-10 18:19:35 +0000119{
120 unsigned long tmp;
121
122 /* set our standby method to sleep */
123
124 tmp = __raw_readl(S3C64XX_PWR_CFG);
125 tmp &= ~S3C64XX_PWRCFG_CFG_WFI_MASK;
126 tmp |= S3C64XX_PWRCFG_CFG_WFI_SLEEP;
127 __raw_writel(tmp, S3C64XX_PWR_CFG);
128
129 /* clear any old wakeup */
130
131 __raw_writel(__raw_readl(S3C64XX_WAKEUP_STAT),
132 S3C64XX_WAKEUP_STAT);
133
134 /* set the LED state to 0110 over sleep */
135 s3c_pm_debug_smdkled(3 << 1, 0xf);
136
137 /* issue the standby signal into the pm unit. Note, we
138 * issue a write-buffer drain just in case */
139
140 tmp = 0;
141
142 asm("b 1f\n\t"
143 ".align 5\n\t"
144 "1:\n\t"
145 "mcr p15, 0, %0, c7, c10, 5\n\t"
146 "mcr p15, 0, %0, c7, c10, 4\n\t"
147 "mcr p15, 0, %0, c7, c0, 4" :: "r" (tmp));
148
149 /* we should never get past here */
150
151 panic("sleep resumed to originator?");
152}
153
Ben Dooksfda22572010-05-20 12:56:45 +0900154/* mapping of interrupts to parts of the wakeup mask */
155static struct samsung_wakeup_mask wake_irqs[] = {
156 { .irq = IRQ_RTC_ALARM, .bit = S3C64XX_PWRCFG_RTC_ALARM_DISABLE, },
157 { .irq = IRQ_RTC_TIC, .bit = S3C64XX_PWRCFG_RTC_TICK_DISABLE, },
158 { .irq = IRQ_PENDN, .bit = S3C64XX_PWRCFG_TS_DISABLE, },
159 { .irq = IRQ_HSMMC0, .bit = S3C64XX_PWRCFG_MMC0_DISABLE, },
160 { .irq = IRQ_HSMMC1, .bit = S3C64XX_PWRCFG_MMC1_DISABLE, },
161 { .irq = IRQ_HSMMC2, .bit = S3C64XX_PWRCFG_MMC2_DISABLE, },
162 { .irq = NO_WAKEUP_IRQ, .bit = S3C64XX_PWRCFG_BATF_DISABLE},
163 { .irq = NO_WAKEUP_IRQ, .bit = S3C64XX_PWRCFG_MSM_DISABLE },
164 { .irq = NO_WAKEUP_IRQ, .bit = S3C64XX_PWRCFG_HSI_DISABLE },
165 { .irq = NO_WAKEUP_IRQ, .bit = S3C64XX_PWRCFG_MSM_DISABLE },
166};
167
Ben Dooksbd117bd2009-03-10 18:19:35 +0000168static void s3c64xx_pm_prepare(void)
169{
Ben Dooksfda22572010-05-20 12:56:45 +0900170 samsung_sync_wakemask(S3C64XX_PWR_CFG,
171 wake_irqs, ARRAY_SIZE(wake_irqs));
172
Ben Dooksbd117bd2009-03-10 18:19:35 +0000173 /* store address of resume. */
174 __raw_writel(virt_to_phys(s3c_cpu_resume), S3C64XX_INFORM0);
175
176 /* ensure previous wakeup state is cleared before sleeping */
177 __raw_writel(__raw_readl(S3C64XX_WAKEUP_STAT), S3C64XX_WAKEUP_STAT);
178}
179
180static int s3c64xx_pm_init(void)
181{
182 pm_cpu_prep = s3c64xx_pm_prepare;
183 pm_cpu_sleep = s3c64xx_cpu_suspend;
184 pm_uart_udivslot = 1;
Joonyoung Shim31858472011-05-06 09:37:17 +0900185
186#ifdef CONFIG_S3C_PM_DEBUG_LED_SMDK
187 gpio_request(S3C64XX_GPN(12), "DEBUG_LED0");
188 gpio_request(S3C64XX_GPN(13), "DEBUG_LED1");
189 gpio_request(S3C64XX_GPN(14), "DEBUG_LED2");
190 gpio_request(S3C64XX_GPN(15), "DEBUG_LED3");
191 gpio_direction_output(S3C64XX_GPN(12), 0);
192 gpio_direction_output(S3C64XX_GPN(13), 0);
193 gpio_direction_output(S3C64XX_GPN(14), 0);
194 gpio_direction_output(S3C64XX_GPN(15), 0);
195#endif
196
Ben Dooksbd117bd2009-03-10 18:19:35 +0000197 return 0;
198}
199
200arch_initcall(s3c64xx_pm_init);