2 * arch/arm/mach-tegra/suspend.c
4 * CPU complex suspend & resume functions for Tegra SoCs
6 * Copyright (c) 2009-2010, NVIDIA Corporation.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 #include <linux/kernel.h>
24 #include <linux/init.h>
26 #include <linux/sched.h>
27 #include <linux/smp.h>
28 #include <linux/irq.h>
29 #include <linux/interrupt.h>
30 #include <linux/clk.h>
31 #include <linux/err.h>
32 #include <linux/debugfs.h>
33 #include <linux/delay.h>
34 #include <linux/suspend.h>
35 #include <linux/slab.h>
36 #include <linux/serial_reg.h>
37 #include <linux/seq_file.h>
38 #include <linux/uaccess.h>
40 #include <linux/regulator/machine.h>
42 #include <asm/cacheflush.h>
43 #include <asm/hardware/cache-l2x0.h>
44 #include <asm/hardware/gic.h>
45 #include <asm/localtimer.h>
46 #include <asm/pgalloc.h>
47 #include <asm/tlbflush.h>
50 #include <mach/iomap.h>
51 #include <mach/iovmm.h>
52 #include <mach/irqs.h>
53 #include <mach/legacy_irq.h>
54 #include <mach/suspend.h>
59 struct suspend_context {
61 * The next 7 values are referenced by offset in __restart_plls
62 * in headsmp-t2.S, and should not be moved
79 volatile struct suspend_context tegra_sctx;
81 static void __iomem *pmc = IO_ADDRESS(TEGRA_PMC_BASE);
82 static void __iomem *clk_rst = IO_ADDRESS(TEGRA_CLK_RESET_BASE);
83 static void __iomem *flow_ctrl = IO_ADDRESS(TEGRA_FLOW_CTRL_BASE);
84 static void __iomem *evp_reset = IO_ADDRESS(TEGRA_EXCEPTION_VECTORS_BASE)+0x100;
85 static void __iomem *tmrus = IO_ADDRESS(TEGRA_TMRUS_BASE);
88 #define PMC_CTRL_LATCH_WAKEUPS (1 << 5)
89 #define PMC_WAKE_MASK 0xc
90 #define PMC_WAKE_LEVEL 0x10
91 #define PMC_DPAD_ORIDE 0x1C
92 #define PMC_WAKE_DELAY 0xe0
93 #define PMC_DPD_SAMPLE 0x20
95 #define PMC_WAKE_STATUS 0x14
96 #define PMC_SW_WAKE_STATUS 0x18
97 #define PMC_COREPWRGOOD_TIMER 0x3c
98 #define PMC_SCRATCH0 0x50
99 #define PMC_SCRATCH1 0x54
100 #define PMC_CPUPWRGOOD_TIMER 0xc8
101 #define PMC_CPUPWROFF_TIMER 0xcc
102 #define PMC_COREPWROFF_TIMER PMC_WAKE_DELAY
103 #define PMC_SCRATCH38 0x134
104 #define PMC_SCRATCH39 0x138
105 #define PMC_SCRATCH41 0x140
107 #define CLK_RESET_CCLK_BURST 0x20
108 #define CLK_RESET_CCLK_DIVIDER 0x24
109 #define CLK_RESET_PLLC_BASE 0x80
110 #define CLK_RESET_PLLM_BASE 0x90
111 #define CLK_RESET_PLLX_BASE 0xe0
112 #define CLK_RESET_PLLX_MISC 0xe4
113 #define CLK_RESET_PLLP_BASE 0xa0
114 #define CLK_RESET_PLLP_OUTA 0xa4
115 #define CLK_RESET_PLLP_OUTB 0xa8
116 #define CLK_RESET_PLLP_MISC 0xac
118 #define CLK_RESET_SOURCE_CSITE 0x1d4
121 #define CLK_RESET_CCLK_BURST_POLICY_SHIFT 28
122 #define CLK_RESET_CCLK_BURST_POLICY_PLLM 3
123 #define CLK_RESET_CCLK_BURST_POLICY_PLLX 8
125 #define FLOW_CTRL_CPU_CSR 0x8
126 #define FLOW_CTRL_CPU1_CSR 0x18
128 unsigned long tegra_pgd_phys; /* pgd used by hotplug & LP2 bootup */
129 static pgd_t *tegra_pgd;
130 void *tegra_context_area = NULL;
132 static struct clk *tegra_pclk = NULL;
133 static const struct tegra_suspend_platform_data *pdata = NULL;
134 static unsigned long wb0_restore = 0;
135 static enum tegra_suspend_mode current_suspend_mode;
137 static unsigned int tegra_time_in_suspend[32];
139 static inline unsigned int time_to_bin(unsigned int time)
144 unsigned long tegra_cpu_power_good_time(void)
146 if (WARN_ON_ONCE(!pdata))
149 return pdata->cpu_timer;
152 unsigned long tegra_cpu_power_off_time(void)
154 if (WARN_ON_ONCE(!pdata))
157 return pdata->cpu_off_timer;
160 enum tegra_suspend_mode tegra_get_suspend_mode(void)
163 return TEGRA_SUSPEND_NONE;
165 return pdata->suspend_mode;
168 static void set_power_timers(unsigned long us_on, unsigned long us_off,
171 static int last_pclk = 0;
172 unsigned long long ticks;
173 unsigned long long pclk;
175 if (WARN_ON_ONCE(rate <= 0))
180 if (rate != last_pclk) {
181 ticks = (us_on * pclk) + 999999ull;
182 do_div(ticks, 1000000);
183 writel((unsigned long)ticks, pmc + PMC_CPUPWRGOOD_TIMER);
185 ticks = (us_off * pclk) + 999999ull;
186 do_div(ticks, 1000000);
187 writel((unsigned long)ticks, pmc + PMC_CPUPWROFF_TIMER);
193 static int create_suspend_pgtable(void)
197 /* arrays of virtual-to-physical mappings which must be
198 * present to safely boot hotplugged / LP2-idled CPUs.
199 * tegra_hotplug_startup (hotplug reset vector) is mapped
200 * VA=PA so that the translation post-MMU is the same as
201 * pre-MMU, IRAM is mapped VA=PA so that SDRAM self-refresh
202 * can safely disable the MMU */
203 unsigned long addr_v[] = {
206 (unsigned long)tegra_context_area,
207 #ifdef CONFIG_HOTPLUG_CPU
208 (unsigned long)virt_to_phys(tegra_hotplug_startup),
210 (unsigned long)__cortex_a9_restore,
211 (unsigned long)virt_to_phys(__shut_off_mmu),
213 unsigned long addr_p[] = {
216 (unsigned long)virt_to_phys(tegra_context_area),
217 #ifdef CONFIG_HOTPLUG_CPU
218 (unsigned long)virt_to_phys(tegra_hotplug_startup),
220 (unsigned long)virt_to_phys(__cortex_a9_restore),
221 (unsigned long)virt_to_phys(__shut_off_mmu),
223 unsigned int flags = PMD_TYPE_SECT | PMD_SECT_AP_WRITE |
224 PMD_SECT_WBWA | PMD_SECT_S;
226 tegra_pgd = pgd_alloc(&init_mm);
230 for (i=0; i<ARRAY_SIZE(addr_p); i++) {
231 unsigned long v = addr_v[i];
232 pmd = pmd_offset(tegra_pgd + pgd_index(v), v);
233 *pmd = __pmd((addr_p[i] & PGDIR_MASK) | flags);
234 flush_pmd_entry(pmd);
235 outer_clean_range(__pa(pmd), __pa(pmd + 1));
238 tegra_pgd_phys = virt_to_phys(tegra_pgd);
239 __cpuc_flush_dcache_area(&tegra_pgd_phys,
240 sizeof(tegra_pgd_phys));
241 outer_clean_range(__pa(&tegra_pgd_phys),
242 __pa(&tegra_pgd_phys+1));
244 __cpuc_flush_dcache_area(&tegra_context_area,
245 sizeof(tegra_context_area));
246 outer_clean_range(__pa(&tegra_context_area),
247 __pa(&tegra_context_area+1));
255 * suspend_cpu_complex
257 * disable periodic IRQs used for DVFS to prevent suspend wakeups
258 * disable coresight debug interface
262 static noinline void restore_cpu_complex(void)
266 /* restore original burst policy setting; PLLX state restored
267 * by CPU boot-up code - wait for PLL stabilization if PLLX
268 * was enabled, or if explicitly requested by caller */
270 BUG_ON(readl(clk_rst + CLK_RESET_PLLX_BASE) != tegra_sctx.pllx_base);
272 if (tegra_sctx.pllx_base & (1<<30)) {
273 while (readl(tmrus)-tegra_sctx.pll_timeout >= 0x80000000UL)
276 writel(tegra_sctx.cclk_divider, clk_rst + CLK_RESET_CCLK_DIVIDER);
277 writel(tegra_sctx.cpu_burst, clk_rst + CLK_RESET_CCLK_BURST);
278 writel(tegra_sctx.clk_csite_src, clk_rst + CLK_RESET_SOURCE_CSITE);
280 /* do not power-gate the CPU when flow controlled */
281 reg = readl(flow_ctrl + FLOW_CTRL_CPU_CSR);
282 reg &= ~((1<<5) | (1<<4) | 1); /* clear WFE bitmask */
283 reg |= (1<<14); /* write-1-clear event flag */
284 writel(reg, flow_ctrl + FLOW_CTRL_CPU_CSR);
287 #ifdef CONFIG_HAVE_ARM_TWD
288 writel(tegra_sctx.twd_ctrl, twd_base + 0x8);
289 writel(tegra_sctx.twd_load, twd_base + 0);
293 get_irq_chip(IRQ_LOCALTIMER)->unmask(IRQ_LOCALTIMER);
295 enable_irq(INT_SYS_STATS_MON);
298 static noinline void suspend_cpu_complex(void)
303 disable_irq(INT_SYS_STATS_MON);
305 /* switch coresite to clk_m, save off original source */
306 tegra_sctx.clk_csite_src = readl(clk_rst + CLK_RESET_SOURCE_CSITE);
307 writel(3<<30, clk_rst + CLK_RESET_SOURCE_CSITE);
309 tegra_sctx.cpu_burst = readl(clk_rst + CLK_RESET_CCLK_BURST);
310 tegra_sctx.pllx_base = readl(clk_rst + CLK_RESET_PLLX_BASE);
311 tegra_sctx.pllx_misc = readl(clk_rst + CLK_RESET_PLLX_MISC);
312 tegra_sctx.pllp_base = readl(clk_rst + CLK_RESET_PLLP_BASE);
313 tegra_sctx.pllp_outa = readl(clk_rst + CLK_RESET_PLLP_OUTA);
314 tegra_sctx.pllp_outb = readl(clk_rst + CLK_RESET_PLLP_OUTB);
315 tegra_sctx.pllp_misc = readl(clk_rst + CLK_RESET_PLLP_MISC);
316 tegra_sctx.cclk_divider = readl(clk_rst + CLK_RESET_CCLK_DIVIDER);
318 #ifdef CONFIG_HAVE_ARM_TWD
319 tegra_sctx.twd_ctrl = readl(twd_base + 0x8);
320 tegra_sctx.twd_load = readl(twd_base + 0);
324 reg = readl(flow_ctrl + FLOW_CTRL_CPU_CSR);
325 /* clear any pending events, set the WFE bitmap to specify just
326 * CPU0, and clear any pending events for this CPU */
327 reg &= ~(1<<5); /* clear CPU1 WFE */
328 reg |= (1<<14) | (1<<4) | 1; /* enable CPU0 WFE */
329 writel(reg, flow_ctrl + FLOW_CTRL_CPU_CSR);
332 for (i=1; i<num_present_cpus(); i++) {
333 unsigned int offs = FLOW_CTRL_CPU1_CSR + (i-1)*8;
334 reg = readl(flow_ctrl + offs);
335 writel(reg | (1<<14), flow_ctrl + offs);
343 unsigned int tegra_suspend_lp2(unsigned int us)
346 unsigned long orig, reg;
349 reg = readl(pmc + PMC_CTRL);
350 mode = (reg >> TEGRA_POWER_PMC_SHIFT) & TEGRA_POWER_PMC_MASK;
351 mode |= TEGRA_POWER_CPU_PWRREQ_OE;
352 if (pdata->separate_req)
353 mode |= TEGRA_POWER_PWRREQ_OE;
355 mode &= ~TEGRA_POWER_PWRREQ_OE;
356 mode &= ~TEGRA_POWER_EFFECT_LP0;
358 orig = readl(evp_reset);
359 writel(virt_to_phys(tegra_lp2_startup), evp_reset);
361 set_power_timers(pdata->cpu_timer, pdata->cpu_off_timer,
362 clk_get_rate_all_locked(tegra_pclk));
365 tegra_lp2_set_trigger(us);
367 suspend_cpu_complex();
368 stop_critical_timings();
370 /* structure is written by reset code, so the L2 lines
371 * must be invalidated */
372 outer_flush_range(__pa(&tegra_sctx),__pa(&tegra_sctx+1));
375 __cortex_a9_save(mode);
376 /* return from __cortex_a9_restore */
378 restore_cpu_complex();
379 start_critical_timings();
381 remain = tegra_lp2_timer_remain();
383 tegra_lp2_set_trigger(0);
385 writel(orig, evp_reset);
392 /* ensures that sufficient time is passed for a register write to
393 * serialize into the 32KHz domain */
394 static void pmc_32kwritel(u32 val, unsigned long offs)
396 writel(val, pmc + offs);
400 static u8 *iram_save = NULL;
401 static unsigned int iram_save_size = 0;
402 static void __iomem *iram_code = IO_ADDRESS(TEGRA_IRAM_CODE_AREA);
404 static void tegra_suspend_dram(bool do_lp0)
406 unsigned int mode = TEGRA_POWER_SDRAM_SELFREFRESH;
407 unsigned long orig, reg;
409 orig = readl(evp_reset);
410 /* copy the reset vector and SDRAM shutdown code into IRAM */
411 memcpy(iram_save, iram_code, iram_save_size);
412 memcpy(iram_code, (void *)__tegra_lp1_reset, iram_save_size);
414 set_power_timers(pdata->cpu_timer, pdata->cpu_off_timer, 32768);
416 reg = readl(pmc + PMC_CTRL);
417 mode |= ((reg >> TEGRA_POWER_PMC_SHIFT) & TEGRA_POWER_PMC_MASK);
420 writel(TEGRA_IRAM_CODE_AREA, evp_reset);
422 mode |= TEGRA_POWER_CPU_PWRREQ_OE;
423 if (pdata->separate_req)
424 mode |= TEGRA_POWER_PWRREQ_OE;
426 mode &= ~TEGRA_POWER_PWRREQ_OE;
427 mode &= ~TEGRA_POWER_EFFECT_LP0;
429 tegra_legacy_irq_set_lp1_wake_mask();
431 u32 boot_flag = readl(pmc + PMC_SCRATCH0);
432 pmc_32kwritel(boot_flag | 1, PMC_SCRATCH0);
433 pmc_32kwritel(wb0_restore, PMC_SCRATCH1);
434 writel(0x0, pmc + PMC_SCRATCH39);
435 mode |= TEGRA_POWER_CPU_PWRREQ_OE;
436 mode |= TEGRA_POWER_PWRREQ_OE;
437 mode |= TEGRA_POWER_EFFECT_LP0;
439 /* for platforms where the core & CPU power requests are
440 * combined as a single request to the PMU, transition to
441 * LP0 state by temporarily enabling both requests
443 if (!pdata->separate_req) {
444 reg |= ((mode & TEGRA_POWER_PMC_MASK) <<
445 TEGRA_POWER_PMC_SHIFT);
446 pmc_32kwritel(reg, PMC_CTRL);
447 mode &= ~TEGRA_POWER_CPU_PWRREQ_OE;
450 tegra_set_lp0_wake_pads(pdata->wake_enb, pdata->wake_high,
454 suspend_cpu_complex();
458 __cortex_a9_save(mode);
459 restore_cpu_complex();
461 writel(orig, evp_reset);
465 memcpy(iram_code, iram_save, iram_save_size);
466 tegra_legacy_irq_restore_mask();
468 /* for platforms where the core & CPU power requests are
469 * combined as a single request to the PMU, transition out
470 * of LP0 state by temporarily enabling both requests
472 if (!pdata->separate_req) {
473 reg = readl(pmc + PMC_CTRL);
474 reg |= (TEGRA_POWER_CPU_PWRREQ_OE << TEGRA_POWER_PMC_SHIFT);
475 pmc_32kwritel(reg, PMC_CTRL);
476 reg &= ~(TEGRA_POWER_PWRREQ_OE << TEGRA_POWER_PMC_SHIFT);
477 writel(reg, pmc + PMC_CTRL);
484 static int tegra_suspend_begin(suspend_state_t state)
486 return regulator_suspend_prepare(state);
489 static int tegra_suspend_prepare_late(void)
491 disable_irq(INT_SYS_STATS_MON);
492 return tegra_iovmm_suspend();
495 static void tegra_suspend_wake(void)
497 tegra_iovmm_resume();
498 enable_irq(INT_SYS_STATS_MON);
501 static u8 uart_state[5];
503 static int tegra_debug_uart_suspend(void)
508 if (TEGRA_DEBUG_UART_BASE == 0)
511 uart = IO_ADDRESS(TEGRA_DEBUG_UART_BASE);
513 lcr = readb(uart + UART_LCR * 4);
516 uart_state[1] = readb(uart + UART_MCR * 4);
519 writeb(lcr & ~UART_LCR_DLAB, uart + UART_LCR * 4);
521 uart_state[2] = readb(uart + UART_IER * 4);
524 writeb(lcr | UART_LCR_DLAB, uart + UART_LCR * 4);
526 uart_state[3] = readb(uart + UART_DLL * 4);
527 uart_state[4] = readb(uart + UART_DLM * 4);
529 writeb(lcr, uart + UART_LCR * 4);
534 static void tegra_debug_uart_resume(void)
539 if (TEGRA_DEBUG_UART_BASE == 0)
542 uart = IO_ADDRESS(TEGRA_DEBUG_UART_BASE);
546 writeb(uart_state[1], uart + UART_MCR * 4);
549 writeb(lcr & ~UART_LCR_DLAB, uart + UART_LCR * 4);
551 writeb(uart_state[2], uart + UART_IER * 4);
554 writeb(lcr | UART_LCR_DLAB, uart + UART_LCR * 4);
556 writeb(uart_state[3], uart + UART_DLL * 4);
557 writeb(uart_state[4], uart + UART_DLM * 4);
559 writeb(lcr, uart + UART_LCR * 4);
562 #define MC_SECURITY_START 0x6c
563 #define MC_SECURITY_SIZE 0x70
564 #define MC_SECURITY_CFG2 0x7c
566 static int tegra_suspend_enter(suspend_state_t state)
568 struct irq_desc *desc;
569 void __iomem *mc = IO_ADDRESS(TEGRA_MC_BASE);
571 u32 mc_data[3] = {0, 0, 0};
573 bool do_lp0 = (current_suspend_mode == TEGRA_SUSPEND_LP0);
574 bool do_lp2 = (current_suspend_mode == TEGRA_SUSPEND_LP2);
588 local_irq_save(flags);
591 pr_info("Entering suspend state LP%d\n", lp_state);
595 tegra_debug_uart_suspend();
596 tegra_pinmux_suspend();
597 tegra_timer_suspend();
598 tegra_gpio_suspend();
601 mc_data[0] = readl(mc + MC_SECURITY_START);
602 mc_data[1] = readl(mc + MC_SECURITY_SIZE);
603 mc_data[2] = readl(mc + MC_SECURITY_CFG2);
606 for_each_irq_desc(irq, desc) {
607 if ((desc->status & IRQ_WAKEUP) &&
608 (desc->status & IRQ_SUSPENDED)) {
609 get_irq_chip(irq)->unmask(irq);
613 rtc_before = tegra_rtc_read_ms();
616 tegra_suspend_lp2(0);
618 tegra_suspend_dram(do_lp0);
620 rtc_after = tegra_rtc_read_ms();
622 for_each_irq_desc(irq, desc) {
623 if ((desc->status & IRQ_WAKEUP) &&
624 (desc->status & IRQ_SUSPENDED)) {
625 get_irq_chip(irq)->mask(irq);
629 /* Clear DPD sample */
630 writel(0x0, pmc + PMC_DPD_SAMPLE);
633 writel(mc_data[0], mc + MC_SECURITY_START);
634 writel(mc_data[1], mc + MC_SECURITY_SIZE);
635 writel(mc_data[2], mc + MC_SECURITY_CFG2);
639 tegra_timer_resume();
640 tegra_pinmux_resume();
641 tegra_debug_uart_resume();
646 secs = rtc_after - rtc_before;
647 ms = do_div(secs, 1000);
648 pr_info("Suspended for %llu.%03u seconds\n", secs, ms);
650 tegra_time_in_suspend[time_to_bin(secs)]++;
653 local_irq_restore(flags);
658 static struct platform_suspend_ops tegra_suspend_ops = {
659 .valid = suspend_valid_only_mem,
660 .begin = tegra_suspend_begin,
661 .prepare_late = tegra_suspend_prepare_late,
662 .wake = tegra_suspend_wake,
663 .enter = tegra_suspend_enter,
667 void __init tegra_init_suspend(struct tegra_suspend_platform_data *plat)
671 tegra_pclk = clk_get_sys(NULL, "pclk");
677 if (plat->suspend_mode == TEGRA_SUSPEND_LP0 && tegra_lp0_vec_size) {
678 wb0_restore = tegra_lp0_vec_start;
680 pr_warning("Suspend mode LP0 requested, but missing lp0_vec\n");
681 pr_warning("Disabling LP0\n");
682 plat->suspend_mode = TEGRA_SUSPEND_LP1;
685 tegra_context_area = kzalloc(CONTEXT_SIZE_BYTES * NR_CPUS, GFP_KERNEL);
687 if (tegra_context_area && create_suspend_pgtable()) {
688 kfree(tegra_context_area);
689 tegra_context_area = NULL;
693 iram_save_size = (unsigned long)__tegra_iram_end;
694 iram_save_size -= (unsigned long)__tegra_lp1_reset;
696 iram_save = kmalloc(iram_save_size, GFP_KERNEL);
698 pr_err("%s: unable to allocate memory for SDRAM self-refresh "
699 "LP0/LP1 unavailable\n", __func__);
700 plat->suspend_mode = TEGRA_SUSPEND_LP2;
702 /* CPU reset vector for LP0 and LP1 */
703 writel(virt_to_phys(tegra_lp2_startup), pmc + PMC_SCRATCH41);
705 /* Always enable CPU power request; just normal polarity is supported */
706 reg = readl(pmc + PMC_CTRL);
707 BUG_ON(reg & (TEGRA_POWER_CPU_PWRREQ_POLARITY << TEGRA_POWER_PMC_SHIFT));
708 reg |= (TEGRA_POWER_CPU_PWRREQ_OE << TEGRA_POWER_PMC_SHIFT);
709 pmc_32kwritel(reg, PMC_CTRL);
711 /* Configure core power request and system clock control if LP0
713 writel(pdata->core_timer, pmc + PMC_COREPWRGOOD_TIMER);
714 writel(pdata->core_off_timer, pmc + PMC_COREPWROFF_TIMER);
715 reg = readl(pmc + PMC_CTRL);
716 mode = (reg >> TEGRA_POWER_PMC_SHIFT) & TEGRA_POWER_PMC_MASK;
718 mode &= ~TEGRA_POWER_SYSCLK_POLARITY;
719 mode &= ~TEGRA_POWER_PWRREQ_POLARITY;
721 if (!pdata->sysclkreq_high)
722 mode |= TEGRA_POWER_SYSCLK_POLARITY;
723 if (!pdata->corereq_high)
724 mode |= TEGRA_POWER_PWRREQ_POLARITY;
726 /* configure output inverters while the request is tristated */
727 reg |= (mode << TEGRA_POWER_PMC_SHIFT);
728 pmc_32kwritel(reg, PMC_CTRL);
730 /* now enable requests */
731 reg |= (TEGRA_POWER_SYSCLK_OE << TEGRA_POWER_PMC_SHIFT);
732 if (pdata->separate_req)
733 reg |= (TEGRA_POWER_PWRREQ_OE << TEGRA_POWER_PMC_SHIFT);
734 writel(reg, pmc + PMC_CTRL);
736 if (pdata->suspend_mode == TEGRA_SUSPEND_LP0)
739 suspend_set_ops(&tegra_suspend_ops);
742 current_suspend_mode = plat->suspend_mode;
745 #ifdef CONFIG_DEBUG_FS
746 static const char *tegra_suspend_name[TEGRA_MAX_SUSPEND_MODE] = {
747 [TEGRA_SUSPEND_NONE] = "none",
748 [TEGRA_SUSPEND_LP2] = "lp2",
749 [TEGRA_SUSPEND_LP1] = "lp1",
750 [TEGRA_SUSPEND_LP0] = "lp0",
753 static int tegra_suspend_debug_show(struct seq_file *s, void *data)
755 seq_printf(s, "%s\n", tegra_suspend_name[*(int *)s->private]);
759 static int tegra_suspend_debug_open(struct inode *inode, struct file *file)
761 return single_open(file, tegra_suspend_debug_show, inode->i_private);
764 static int tegra_suspend_debug_write(struct file *file,
765 const char __user *user_buf, size_t count, loff_t *ppos)
770 struct seq_file *s = file->private_data;
771 enum tegra_suspend_mode *val = s->private;
773 memset(buf, 0x00, sizeof(buf));
774 buf_size = min(count, (sizeof(buf)-1));
775 if (copy_from_user(buf, user_buf, buf_size))
778 for (i = 0; i < TEGRA_MAX_SUSPEND_MODE; i++) {
779 if (!strnicmp(buf, tegra_suspend_name[i],
780 strlen(tegra_suspend_name[i]))) {
781 if (i > pdata->suspend_mode)
791 static const struct file_operations tegra_suspend_debug_fops = {
792 .open = tegra_suspend_debug_open,
793 .write = tegra_suspend_debug_write,
796 .release = single_release,
799 static int tegra_suspend_time_debug_show(struct seq_file *s, void *data)
802 seq_printf(s, "time (secs) count\n");
803 seq_printf(s, "------------------\n");
804 for (bin = 0; bin < 32; bin++) {
805 if (tegra_time_in_suspend[bin] == 0)
807 seq_printf(s, "%4d - %4d %4u\n",
808 bin ? 1 << (bin - 1) : 0, 1 << bin,
809 tegra_time_in_suspend[bin]);
814 static int tegra_suspend_time_debug_open(struct inode *inode, struct file *file)
816 return single_open(file, tegra_suspend_time_debug_show, NULL);
819 static const struct file_operations tegra_suspend_time_debug_fops = {
820 .open = tegra_suspend_time_debug_open,
823 .release = single_release,
826 static int __init tegra_suspend_debug_init(void)
830 d = debugfs_create_file("suspend_mode", 0755, NULL,
831 (void *)¤t_suspend_mode, &tegra_suspend_debug_fops);
833 pr_info("Failed to create suspend_mode debug file\n");
837 d = debugfs_create_file("suspend_time", 0755, NULL, NULL,
838 &tegra_suspend_time_debug_fops);
840 pr_info("Failed to create suspend_time debug file\n");
847 late_initcall(tegra_suspend_debug_init);