aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoseph Lo <josephl@nvidia.com>2013-08-12 05:40:03 -0400
committerStephen Warren <swarren@nvidia.com>2013-08-12 15:29:24 -0400
commit95872f427eca73b19ac9466c25afd9bb876dc1aa (patch)
treead27d867f762c37b98d59b892b9840ba38e3016a
parent0017f447cc01fa499f1d10dec09702d381f13fe0 (diff)
ARM: tegra: add common LP1 suspend support
The LP1 suspending mode on Tegra means CPU rail off, devices and PLLs are clock gated and SDRAM in self-refresh mode. That means the low level LP1 suspending and resuming code couldn't be run on DRAM and the CPU must switch to the always on clock domain (a.k.a. CLK_M 12MHz oscillator). And the system clock (SCLK) would be switched to CLK_S, a 32KHz oscillator. The LP1 low level handling code need to be moved to IRAM area first. And marking the LP1 mask for indicating the Tegra device is in LP1. The CPU power timer needs to be re-calculated based on 32KHz that was originally based on PCLK. When resuming from LP1, the LP1 reset handler will resume PLLs and then put DRAM to normal mode. Then jumping to the "tegra_resume" that will restore full context before back to kernel. The "tegra_resume" handler was expected to be found in PMC_SCRATCH41 register. This is common LP1 procedures for Tegra, so we do these jobs mainly in this patch: * moving LP1 low level handling code to IRAM * marking LP1 mask * copying the physical address of "tegra_resume" to PMC_SCRATCH41 * re-calculate the CPU power timer based on 32KHz Signed-off-by: Joseph Lo <josephl@nvidia.com> [swarren, replaced IRAM_CODE macro with IO_ADDRESS(TEGRA_IRAM_CODE_AREA)] Signed-off-by: Stephen Warren <swarren@nvidia.com>
-rw-r--r--arch/arm/mach-tegra/pm.c110
-rw-r--r--arch/arm/mach-tegra/pm.h7
-rw-r--r--arch/arm/mach-tegra/pmc.c21
-rw-r--r--arch/arm/mach-tegra/pmc.h3
-rw-r--r--arch/arm/mach-tegra/reset.h4
5 files changed, 140 insertions, 5 deletions
diff --git a/arch/arm/mach-tegra/pm.c b/arch/arm/mach-tegra/pm.c
index 11bfce9473c1..10689924a6a7 100644
--- a/arch/arm/mach-tegra/pm.c
+++ b/arch/arm/mach-tegra/pm.c
@@ -37,12 +37,18 @@
37#include "reset.h" 37#include "reset.h"
38#include "flowctrl.h" 38#include "flowctrl.h"
39#include "fuse.h" 39#include "fuse.h"
40#include "pm.h"
40#include "pmc.h" 41#include "pmc.h"
41#include "sleep.h" 42#include "sleep.h"
42 43
43#ifdef CONFIG_PM_SLEEP 44#ifdef CONFIG_PM_SLEEP
44static DEFINE_SPINLOCK(tegra_lp2_lock); 45static DEFINE_SPINLOCK(tegra_lp2_lock);
46static u32 iram_save_size;
47static void *iram_save_addr;
48struct tegra_lp1_iram tegra_lp1_iram;
45void (*tegra_tear_down_cpu)(void); 49void (*tegra_tear_down_cpu)(void);
50void (*tegra_sleep_core_finish)(unsigned long v2p);
51static int (*tegra_sleep_func)(unsigned long v2p);
46 52
47static void tegra_tear_down_cpu_init(void) 53static void tegra_tear_down_cpu_init(void)
48{ 54{
@@ -174,14 +180,78 @@ enum tegra_suspend_mode tegra_pm_validate_suspend_mode(
174 enum tegra_suspend_mode mode) 180 enum tegra_suspend_mode mode)
175{ 181{
176 /* 182 /*
177 * The Tegra devices only support suspending to LP2 currently. 183 * The Tegra devices support suspending to LP1 or lower currently.
178 */ 184 */
179 if (mode > TEGRA_SUSPEND_LP2) 185 if (mode > TEGRA_SUSPEND_LP1)
180 return TEGRA_SUSPEND_LP2; 186 return TEGRA_SUSPEND_LP1;
181 187
182 return mode; 188 return mode;
183} 189}
184 190
191static int tegra_sleep_core(unsigned long v2p)
192{
193 setup_mm_for_reboot();
194 tegra_sleep_core_finish(v2p);
195
196 /* should never here */
197 BUG();
198
199 return 0;
200}
201
202/*
203 * tegra_lp1_iram_hook
204 *
205 * Hooking the address of LP1 reset vector and SDRAM self-refresh code in
206 * SDRAM. These codes not be copied to IRAM in this fuction. We need to
207 * copy these code to IRAM before LP0/LP1 suspend and restore the content
208 * of IRAM after resume.
209 */
210static bool tegra_lp1_iram_hook(void)
211{
212 if (!tegra_lp1_iram.start_addr || !tegra_lp1_iram.end_addr)
213 return false;
214
215 iram_save_size = tegra_lp1_iram.end_addr - tegra_lp1_iram.start_addr;
216 iram_save_addr = kmalloc(iram_save_size, GFP_KERNEL);
217 if (!iram_save_addr)
218 return false;
219
220 return true;
221}
222
223static bool tegra_sleep_core_init(void)
224{
225 if (!tegra_sleep_core_finish)
226 return false;
227
228 return true;
229}
230
231static void tegra_suspend_enter_lp1(void)
232{
233 tegra_pmc_suspend();
234
235 /* copy the reset vector & SDRAM shutdown code into IRAM */
236 memcpy(iram_save_addr, IO_ADDRESS(TEGRA_IRAM_CODE_AREA),
237 iram_save_size);
238 memcpy(IO_ADDRESS(TEGRA_IRAM_CODE_AREA), tegra_lp1_iram.start_addr,
239 iram_save_size);
240
241 *((u32 *)tegra_cpu_lp1_mask) = 1;
242}
243
244static void tegra_suspend_exit_lp1(void)
245{
246 tegra_pmc_resume();
247
248 /* restore IRAM */
249 memcpy(IO_ADDRESS(TEGRA_IRAM_CODE_AREA), iram_save_addr,
250 iram_save_size);
251
252 *(u32 *)tegra_cpu_lp1_mask = 0;
253}
254
185static const char *lp_state[TEGRA_MAX_SUSPEND_MODE] = { 255static const char *lp_state[TEGRA_MAX_SUSPEND_MODE] = {
186 [TEGRA_SUSPEND_NONE] = "none", 256 [TEGRA_SUSPEND_NONE] = "none",
187 [TEGRA_SUSPEND_LP2] = "LP2", 257 [TEGRA_SUSPEND_LP2] = "LP2",
@@ -205,6 +275,9 @@ static int __cpuinit tegra_suspend_enter(suspend_state_t state)
205 275
206 suspend_cpu_complex(); 276 suspend_cpu_complex();
207 switch (mode) { 277 switch (mode) {
278 case TEGRA_SUSPEND_LP1:
279 tegra_suspend_enter_lp1();
280 break;
208 case TEGRA_SUSPEND_LP2: 281 case TEGRA_SUSPEND_LP2:
209 tegra_set_cpu_in_lp2(); 282 tegra_set_cpu_in_lp2();
210 break; 283 break;
@@ -212,9 +285,12 @@ static int __cpuinit tegra_suspend_enter(suspend_state_t state)
212 break; 285 break;
213 } 286 }
214 287
215 cpu_suspend(PHYS_OFFSET - PAGE_OFFSET, &tegra_sleep_cpu); 288 cpu_suspend(PHYS_OFFSET - PAGE_OFFSET, tegra_sleep_func);
216 289
217 switch (mode) { 290 switch (mode) {
291 case TEGRA_SUSPEND_LP1:
292 tegra_suspend_exit_lp1();
293 break;
218 case TEGRA_SUSPEND_LP2: 294 case TEGRA_SUSPEND_LP2:
219 tegra_clear_cpu_in_lp2(); 295 tegra_clear_cpu_in_lp2();
220 break; 296 break;
@@ -235,12 +311,36 @@ static const struct platform_suspend_ops tegra_suspend_ops = {
235 311
236void __init tegra_init_suspend(void) 312void __init tegra_init_suspend(void)
237{ 313{
238 if (tegra_pmc_get_suspend_mode() == TEGRA_SUSPEND_NONE) 314 enum tegra_suspend_mode mode = tegra_pmc_get_suspend_mode();
315
316 if (mode == TEGRA_SUSPEND_NONE)
239 return; 317 return;
240 318
241 tegra_tear_down_cpu_init(); 319 tegra_tear_down_cpu_init();
242 tegra_pmc_suspend_init(); 320 tegra_pmc_suspend_init();
243 321
322 if (mode >= TEGRA_SUSPEND_LP1) {
323 if (!tegra_lp1_iram_hook() || !tegra_sleep_core_init()) {
324 pr_err("%s: unable to allocate memory for SDRAM"
325 "self-refresh -- LP0/LP1 unavailable\n",
326 __func__);
327 tegra_pmc_set_suspend_mode(TEGRA_SUSPEND_LP2);
328 mode = TEGRA_SUSPEND_LP2;
329 }
330 }
331
332 /* set up sleep function for cpu_suspend */
333 switch (mode) {
334 case TEGRA_SUSPEND_LP1:
335 tegra_sleep_func = tegra_sleep_core;
336 break;
337 case TEGRA_SUSPEND_LP2:
338 tegra_sleep_func = tegra_sleep_cpu;
339 break;
340 default:
341 break;
342 }
343
244 suspend_set_ops(&tegra_suspend_ops); 344 suspend_set_ops(&tegra_suspend_ops);
245} 345}
246#endif 346#endif
diff --git a/arch/arm/mach-tegra/pm.h b/arch/arm/mach-tegra/pm.h
index 94c4b9d9077c..478706edebbe 100644
--- a/arch/arm/mach-tegra/pm.h
+++ b/arch/arm/mach-tegra/pm.h
@@ -23,6 +23,13 @@
23 23
24#include "pmc.h" 24#include "pmc.h"
25 25
26struct tegra_lp1_iram {
27 void *start_addr;
28 void *end_addr;
29};
30extern struct tegra_lp1_iram tegra_lp1_iram;
31extern void (*tegra_sleep_core_finish)(unsigned long v2p);
32
26extern unsigned long l2x0_saved_regs_addr; 33extern unsigned long l2x0_saved_regs_addr;
27 34
28void save_cpu_arch_register(void); 35void save_cpu_arch_register(void);
diff --git a/arch/arm/mach-tegra/pmc.c b/arch/arm/mach-tegra/pmc.c
index 03e640512e3e..8acb881f7cfe 100644
--- a/arch/arm/mach-tegra/pmc.c
+++ b/arch/arm/mach-tegra/pmc.c
@@ -196,6 +196,24 @@ enum tegra_suspend_mode tegra_pmc_get_suspend_mode(void)
196 return pmc_pm_data.suspend_mode; 196 return pmc_pm_data.suspend_mode;
197} 197}
198 198
199void tegra_pmc_set_suspend_mode(enum tegra_suspend_mode mode)
200{
201 if (mode < TEGRA_SUSPEND_NONE || mode >= TEGRA_MAX_SUSPEND_MODE)
202 return;
203
204 pmc_pm_data.suspend_mode = mode;
205}
206
207void tegra_pmc_suspend(void)
208{
209 tegra_pmc_writel(virt_to_phys(tegra_resume), PMC_SCRATCH41);
210}
211
212void tegra_pmc_resume(void)
213{
214 tegra_pmc_writel(0x0, PMC_SCRATCH41);
215}
216
199void tegra_pmc_pm_set(enum tegra_suspend_mode mode) 217void tegra_pmc_pm_set(enum tegra_suspend_mode mode)
200{ 218{
201 u32 reg, csr_reg; 219 u32 reg, csr_reg;
@@ -219,6 +237,9 @@ void tegra_pmc_pm_set(enum tegra_suspend_mode mode)
219 } 237 }
220 238
221 switch (mode) { 239 switch (mode) {
240 case TEGRA_SUSPEND_LP1:
241 rate = 32768;
242 break;
222 case TEGRA_SUSPEND_LP2: 243 case TEGRA_SUSPEND_LP2:
223 rate = clk_get_rate(tegra_pclk); 244 rate = clk_get_rate(tegra_pclk);
224 break; 245 break;
diff --git a/arch/arm/mach-tegra/pmc.h b/arch/arm/mach-tegra/pmc.h
index e1c2df272f7d..549f8c7b762c 100644
--- a/arch/arm/mach-tegra/pmc.h
+++ b/arch/arm/mach-tegra/pmc.h
@@ -28,6 +28,9 @@ enum tegra_suspend_mode {
28 28
29#ifdef CONFIG_PM_SLEEP 29#ifdef CONFIG_PM_SLEEP
30enum tegra_suspend_mode tegra_pmc_get_suspend_mode(void); 30enum tegra_suspend_mode tegra_pmc_get_suspend_mode(void);
31void tegra_pmc_set_suspend_mode(enum tegra_suspend_mode mode);
32void tegra_pmc_suspend(void);
33void tegra_pmc_resume(void);
31void tegra_pmc_pm_set(enum tegra_suspend_mode mode); 34void tegra_pmc_pm_set(enum tegra_suspend_mode mode);
32void tegra_pmc_suspend_init(void); 35void tegra_pmc_suspend_init(void);
33#endif 36#endif
diff --git a/arch/arm/mach-tegra/reset.h b/arch/arm/mach-tegra/reset.h
index c90d8e9c4ad2..76a93434c6ee 100644
--- a/arch/arm/mach-tegra/reset.h
+++ b/arch/arm/mach-tegra/reset.h
@@ -39,6 +39,10 @@ void __tegra_cpu_reset_handler_end(void);
39void tegra_secondary_startup(void); 39void tegra_secondary_startup(void);
40 40
41#ifdef CONFIG_PM_SLEEP 41#ifdef CONFIG_PM_SLEEP
42#define tegra_cpu_lp1_mask \
43 (IO_ADDRESS(TEGRA_IRAM_BASE + TEGRA_IRAM_RESET_HANDLER_OFFSET + \
44 ((u32)&__tegra_cpu_reset_handler_data[TEGRA_RESET_MASK_LP1] - \
45 (u32)__tegra_cpu_reset_handler_start)))
42#define tegra_cpu_lp2_mask \ 46#define tegra_cpu_lp2_mask \
43 (IO_ADDRESS(TEGRA_IRAM_BASE + TEGRA_IRAM_RESET_HANDLER_OFFSET + \ 47 (IO_ADDRESS(TEGRA_IRAM_BASE + TEGRA_IRAM_RESET_HANDLER_OFFSET + \
44 ((u32)&__tegra_cpu_reset_handler_data[TEGRA_RESET_MASK_LP2] - \ 48 ((u32)&__tegra_cpu_reset_handler_data[TEGRA_RESET_MASK_LP2] - \