ARM: tegra30: cpuidle: add LP2 support
Subsystems (3)
v2 cover ARM: tegra30: cpuidle: add LP2 support
The CPU idle LP2 is a power gating idle mode for Tegra30. It supports the secondary CPUs (i.e., CPU1-CPU3) to go into LP2 dynamically. When any of the secondary CPUs go into LP2, it can be power gated alone. There is a limitation on CPU0. The CPU0 can go into LP2 only when all secondary CPUs are already in LP2. After CPU0 is in LP2, the CPU rail can be turned off.
Verified on Seaboard(Tegra20) and Cardhu(Tegra30).
This patch set should depend on these two patches:
d8be3dc ARM: tegra: rename the file of "sleep-tXX" to "sleep-tegraXX" 01b176e ARM: tegra30: clocks: add AHB and APB clocks
Previous work can be found at:
V1:
http://www.mail-archive.com/linux-tegra at vger.kernel.org/msg06319.html
Joseph Lo (7):
ARM: tegra: cpuidle: separate cpuidle driver for different chips
ARM: tegra: cpuidle: add LP2 resume function
ARM: tegra30: cpuidle: add LP2 driver for secondary CPUs
ARM: tegra30: common: enable csite clock
ARM: tegra30: clocks: add CPU low-power function into
tegra_cpu_car_ops
ARM: tegra30: flowctrl: add cpu_suspend_exter/exit function
ARM: tegra30: cpuidle: add LP2 driver for CPU0
arch/arm/mach-tegra/Makefile | 7 +
arch/arm/mach-tegra/common.c | 1 +
.../mach-tegra/{cpuidle.c => cpuidle-tegra20.c} | 7 +-
arch/arm/mach-tegra/cpuidle-tegra30.c | 185 ++++++++++++++++
arch/arm/mach-tegra/cpuidle.c | 47 ++---
arch/arm/mach-tegra/cpuidle.h | 32 +++
arch/arm/mach-tegra/flowctrl.c | 47 ++++
arch/arm/mach-tegra/flowctrl.h | 8 +
arch/arm/mach-tegra/headsmp.S | 58 +++++
arch/arm/mach-tegra/pm.c | 220 ++++++++++++++++++++
arch/arm/mach-tegra/pm.h | 33 +++
arch/arm/mach-tegra/reset.c | 6 +
arch/arm/mach-tegra/reset.h | 9 +
arch/arm/mach-tegra/sleep-tegra30.S | 67 ++++++
arch/arm/mach-tegra/sleep.S | 71 +++++++
arch/arm/mach-tegra/sleep.h | 5 +
arch/arm/mach-tegra/tegra30_clocks.c | 107 ++++++++++
arch/arm/mach-tegra/tegra_cpu_car.h | 37 ++++
18 files changed, 908 insertions(+), 39 deletions(-)
copy arch/arm/mach-tegra/{cpuidle.c => cpuidle-tegra20.c} (91%)
create mode 100644 arch/arm/mach-tegra/cpuidle-tegra30.c
create mode 100644 arch/arm/mach-tegra/cpuidle.h
create mode 100644 arch/arm/mach-tegra/pm.c
create mode 100644 arch/arm/mach-tegra/pm.hPATCH v2 1/7 ARM: tegra: cpuidle: separate cpuidle driver for different chips
The different Tegra chips may have different CPU idle states and data. Individual CPU idle driver make it more easy to maintain.
---
V2:
* only remove the line of file name and path in the (c) header
arch/arm/mach-tegra/Makefile | 6 +++
.../mach-tegra/{cpuidle.c => cpuidle-tegra20.c} | 7 +--
.../mach-tegra/{cpuidle.c => cpuidle-tegra30.c} | 7 +--
arch/arm/mach-tegra/cpuidle.c | 47 +++++--------------
arch/arm/mach-tegra/cpuidle.h | 32 +++++++++++++
5 files changed, 55 insertions(+), 44 deletions(-)
copy arch/arm/mach-tegra/{cpuidle.c => cpuidle-tegra20.c} (91%)
copy arch/arm/mach-tegra/{cpuidle.c => cpuidle-tegra30.c} (91%)
create mode 100644 arch/arm/mach-tegra/cpuidle.harch/arm/mach-tegra/Makefile +6 -0
@@ -14,9 +14,15 @@ obj-$(CONFIG_ARCH_TEGRA_2x_SOC) += tegra20_clocks.o obj-$(CONFIG_ARCH_TEGRA_2x_SOC) += tegra20_clocks_data.o obj-$(CONFIG_ARCH_TEGRA_2x_SOC) += tegra2_emc.o obj-$(CONFIG_ARCH_TEGRA_2x_SOC) += sleep-tegra20.o +ifeq ($(CONFIG_CPU_IDLE),y) +obj-$(CONFIG_ARCH_TEGRA_2x_SOC) += cpuidle-tegra20.o +endif obj-$(CONFIG_ARCH_TEGRA_3x_SOC) += tegra30_clocks.o obj-$(CONFIG_ARCH_TEGRA_3x_SOC) += tegra30_clocks_data.o obj-$(CONFIG_ARCH_TEGRA_3x_SOC) += sleep-tegra30.o +ifeq ($(CONFIG_CPU_IDLE),y) +obj-$(CONFIG_ARCH_TEGRA_3x_SOC) += cpuidle-tegra30.o +endif obj-$(CONFIG_SMP) += platsmp.o headsmp.o obj-$(CONFIG_SMP) += reset.o obj-$(CONFIG_HOTPLUG_CPU) += hotplug.o
arch/arm/mach-tegra/cpuidle-tegra20.c renamed from arch/arm/mach-tegra/cpuidle.c +2 -5
@@ -1,6 +1,4 @@/* -* arch/arm/mach-tegra/cpuidle.c -* * CPU idle driver for Tegra CPUs * * Copyright (c) 2010-2012, NVIDIA Corporation.
@@ -27,7 +25,7 @@#include <asm/cpuidle.h> -struct cpuidle_driver tegra_idle_driver = { +static struct cpuidle_driver tegra_idle_driver = { .name ="tegra_idle" , .owner =THIS_MODULE , .en_core_tk_irqen =1 ,
@@ -39,7 +37,7 @@ struct cpuidle_driver tegra_idle_driver = { static DEFINE_PER_CPU(struct cpuidle_device, tegra_idle_device); -static int __init tegra_cpuidle_init (void ) +int __init tegra20_cpuidle_init (void ) {int ret;unsigned int cpu;
@@ -66,4 +64,3 @@ static int __init tegra_cpuidle_init(void) }return 0 ; } -device_initcall (tegra_cpuidle_init);
arch/arm/mach-tegra/cpuidle-tegra30.c renamed from arch/arm/mach-tegra/cpuidle.c +2 -5
@@ -1,6 +1,4 @@/* -* arch/arm/mach-tegra/cpuidle.c -* * CPU idle driver for Tegra CPUs * * Copyright (c) 2010-2012, NVIDIA Corporation.
@@ -27,7 +25,7 @@#include <asm/cpuidle.h> -struct cpuidle_driver tegra_idle_driver = { +static struct cpuidle_driver tegra_idle_driver = { .name ="tegra_idle" , .owner =THIS_MODULE , .en_core_tk_irqen =1 ,
@@ -39,7 +37,7 @@ struct cpuidle_driver tegra_idle_driver = { static DEFINE_PER_CPU(struct cpuidle_device, tegra_idle_device); -static int __init tegra_cpuidle_init (void ) +int __init tegra30_cpuidle_init (void ) {int ret;unsigned int cpu;
@@ -66,4 +64,3 @@ static int __init tegra_cpuidle_init(void) }return 0 ; } -device_initcall (tegra_cpuidle_init);
arch/arm/mach-tegra/cpuidle.c +13 -34
60 lines not on this page · raw message
arch/arm/mach-tegra/cpuidle.h new file +32 -0
@@ -0,0 +1,32 @@ +/* +* Copyright (c) 2012, NVIDIA Corporation. All rights reserved. +* +* This program is free software; you can redistribute it and/or modify it +* under the terms and conditions of the GNU General Public License, +* version 2, as published by the Free Software Foundation. +* +* This program is distributed in the hope it will be useful, but WITHOUT +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +* more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef __MACH_TEGRA_CPUIDLE_H +#define __MACH_TEGRA_CPUIDLE_H + +#ifdef CONFIG_ARCH_TEGRA_2x_SOC +int tegra20_cpuidle_init (void ); +#else +static inline int tegra20_cpuidle_init (void ) {return -ENODEV ; } +#endif + +#ifdef CONFIG_ARCH_TEGRA_3x_SOC +int tegra30_cpuidle_init (void ); +#else +static inline int tegra30_cpuidle_init (void ) {return -ENODEV ; } +#endif + +#endif
Signature · 1 line
1.7.0.4
PATCH v2 2/7 ARM: tegra: cpuidle: add LP2 resume function
In reply to Joseph LoLP2 is one of the Tegra low power states that supports power gating both CPU cores and GICs. Adding a resume function for taking care the CPUs that resume from LP2. This function was been hooked to reset handler. We take care everything here before go into kernel.
Based on the work by:
Scott Williams <[email protected]>
Colin Cross <[email protected]>
Gary King <[email protected]>
---
V2:
* moving the code that only for Tegra30 inside the ifdef in the tegra_resume
arch/arm/mach-tegra/headsmp.S | 58 +++++++++++++++++++++++++++++++++++++++++ arch/arm/mach-tegra/reset.c | 6 ++++ arch/arm/mach-tegra/sleep.h | 1 + 3 files changed, 65 insertions(+), 0 deletions(-)
arch/arm/mach-tegra/headsmp.S +58 -0
@@ -69,6 +69,53 @@ ENTRY(tegra_secondary_startup) b secondary_startup ENDPROC(tegra_secondary_startup) +#ifdef CONFIG_PM_SLEEP +/* + * tegra_resume + * + * CPU boot vector when restarting the a CPU following + * an LP2 transition. Also branched to by LP0 and LP1 resume after + * re-enabling sdram. + */ +ENTRY(tegra_resume) + bl v7_invalidate_l1 + /* Enable coresight */ + mov32 r0, 0xC5ACCE55 + mcr p14, 0, r0, c7, c12, 6 + + cpu_id r0 + cmp r0, #0 @ CPU0? + bne cpu_resume @ no + +#ifdef CONFIG_ARCH_TEGRA_3x_SOC + /* Are we on Tegra20? */ + mov32 r6, TEGRA_APB_MISC_BASE + ldr r0, [r6, #APB_MISC_GP_HIDREV] + and r0, r0, #0xff00 + cmp r0, #(0x20 << 8) + beq 1f @ Yes + /* Clear the flow controller flags for this CPU. */ + mov32 r2, TEGRA_FLOW_CTRL_BASE + FLOW_CTRL_CPU0_CSR @ CPU0 CSR + ldr r1, [r2] + /* Clear event & intr flag */ + orr r1, r1, \ + #FLOW_CTRL_CSR_INTR_FLAG | FLOW_CTRL_CSR_EVENT_FLAG + movw r0, #0x0FFD @ enable, cluster_switch, immed, & bitmaps + bic r1, r1, r0 + str r1, [r2] +1: +#endif + + /* enable SCU */ + mov32 r0, TEGRA_ARM_PERIF_BASE + ldr r1, [r0] + orr r1, r1, #1 + str r1, [r0] + + b cpu_resume +ENDPROC(tegra_resume) +#endif + .align L1_CACHE_SHIFT ENTRY(__tegra_cpu_reset_handler_start)
@@ -122,6 +169,17 @@ ENTRY(__tegra_cpu_reset_handler) 1: #endif + /* Waking up from LP2? */ + ldr r9, [r12, #RESET_DATA(MASK_LP2)] + tst r9, r11 @ if in_lp2 + beq __is_not_lp2 + ldr lr, [r12, #RESET_DATA(STARTUP_LP2)] + cmp lr, #0 + bleq __die @ no LP2 startup handler + bx lr + +__is_not_lp2: + #ifdef CONFIG_SMP /* * Can only be secondary boot (initial or hotplug) but CPU 0
arch/arm/mach-tegra/reset.c +6 -0
@@ -26,6 +26,7 @@#include <mach/irammap.h> #include "reset.h" +#include "sleep.h" #include "fuse.h" #define TEGRA_IRAM_RESET_BASE (TEGRA_IRAM_BASE + \
@@ -80,5 +81,10 @@ void __init tegra_cpu_reset_handler_init(void)virt_to_phys ((void *)tegra_secondary_startup);#endif +#ifdef CONFIG_PM_SLEEP + __tegra_cpu_reset_handler_data[TEGRA_RESET_STARTUP_LP2 ] = +virt_to_phys ((void *)tegra_resume); +#endif +tegra_cpu_reset_handler_enable (); }
arch/arm/mach-tegra/sleep.h +1 -0
@@ -72,6 +72,7 @@ dsb .endm#else +void tegra_resume (void );#ifdef CONFIG_HOTPLUG_CPU void tegra20_hotplug_init (void );
Signature · 1 line
1.7.0.4
PATCH v2 3/7 ARM: tegra30: cpuidle: add LP2 driver for secondary CPUs
In reply to Joseph LoThis supports power-gated (LP2) idle on secondary CPUs for Tegra30. The secondary CPUs can go into LP2 state independently. When CPU goes into LP2 state, it saves it's state and puts itself to flow controlled WFI state. After that, it will been power gated.
Based on the work by:
Scott Williams <[email protected]>
---
V2:
* static initialization for idle states when PM_SLEEP is true or not
* using inline fuction to replace the empty fuction when #ifdef false
* convert the phy cpu number by cpu_logical_map
* update the usage of tegra_cpu_lp2_mask (only one copy in the IRAM)
* update the usage of data cache maintenance API for LP2
* disable L1 data cache
* v7_flush_dcache_louis
* exit SMP coherency
arch/arm/mach-tegra/Makefile | 1 + arch/arm/mach-tegra/cpuidle-tegra30.c | 86 +++++++++++++++++++++++++++++++++ arch/arm/mach-tegra/pm.c | 75 ++++++++++++++++++++++++++++ arch/arm/mach-tegra/pm.h | 30 +++++++++++ arch/arm/mach-tegra/reset.h | 9 ++++ arch/arm/mach-tegra/sleep-tegra30.S | 23 +++++++++ arch/arm/mach-tegra/sleep.S | 29 +++++++++++ arch/arm/mach-tegra/sleep.h | 2 + 8 files changed, 255 insertions(+), 0 deletions(-) create mode 100644 arch/arm/mach-tegra/pm.c create mode 100644 arch/arm/mach-tegra/pm.h
arch/arm/mach-tegra/Makefile +1 -0
@@ -8,6 +8,7 @@ obj-y += pmc.o obj-y += flowctrl.o obj-y += powergate.o obj-y += apbio.o +obj-y += pm.o obj-$(CONFIG_CPU_IDLE) += cpuidle.o obj-$(CONFIG_CPU_IDLE) += sleep.o obj-$(CONFIG_ARCH_TEGRA_2x_SOC) += tegra20_clocks.o
arch/arm/mach-tegra/cpuidle-tegra30.c +86 -0
107 lines not on this page · raw message
arch/arm/mach-tegra/pm.c new file +75 -0
75 lines not on this page · raw message
arch/arm/mach-tegra/pm.h new file +30 -0
@@ -0,0 +1,30 @@ +/* +* Copyright (C) 2010 Google, Inc. +* Copyright (c) 2010-2012 NVIDIA Corporation. All rights reserved. +* +* Author: +* Colin Cross <[email protected]> +* +* This program is free software; you can redistribute it and/or modify it +* under the terms and conditions of the GNU General Public License, +* version 2, as published by the Free Software Foundation. +* +* This program is distributed in the hope it will be useful, but WITHOUT +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +* more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef _MACH_TEGRA_PM_H_ +#define _MACH_TEGRA_PM_H_ + +void save_cpu_arch_register (void ); +void restore_cpu_arch_register (void ); + +void tegra_clear_cpu_in_lp2 (int phy_cpu_id); +bool tegra_set_cpu_in_lp2 (int phy_cpu_id); + +#endif /* _MACH_TEGRA_PM_H_ */
arch/arm/mach-tegra/reset.h +9 -0
@@ -29,6 +29,8 @@#ifndef __ASSEMBLY__ +#include <mach/irammap.h> +extern unsigned long __tegra_cpu_reset_handler_data[TEGRA_RESET_DATA_SIZE ];void __tegra_cpu_reset_handler_start (void );
@@ -36,6 +38,13 @@ void __tegra_cpu_reset_handler(void);void __tegra_cpu_reset_handler_end (void );void tegra_secondary_startup (void ); +#ifdef CONFIG_PM_SLEEP +#define tegra_cpu_lp2_mask \ + (IO_ADDRESS(TEGRA_IRAM_BASE + TEGRA_IRAM_RESET_HANDLER_OFFSET + \ + ((u32)&__tegra_cpu_reset_handler_data[TEGRA_RESET_MASK_LP2] - \ + (u32)__tegra_cpu_reset_handler_start))) +#endif +#define tegra_cpu_reset_handler_offset \ ((u32)__tegra_cpu_reset_handler - \ (u32)__tegra_cpu_reset_handler_start)
arch/arm/mach-tegra/sleep-tegra30.S +23 -0
@@ -17,6 +17,8 @@ #include <linux/linkage.h> #include <asm/assembler.h> +#include <asm/asm-offsets.h> +#include <asm/glue-cache.h> #include "sleep.h" #include "flowctrl.h"
@@ -80,6 +82,7 @@ delay_1: ldr r3, [r1] @ read CSR str r3, [r1] @ clear CSR tst r0, #TEGRA30_POWER_HOTPLUG_SHUTDOWN + moveq r3, #FLOW_CTRL_WAIT_FOR_INTERRUPT @ For LP2 movne r3, #FLOW_CTRL_WAITEVENT @ For hotplug str r3, [r2] ldr r0, [r2]
@@ -103,3 +106,23 @@ wfe_war: ENDPROC(tegra30_cpu_shutdown) #endif + +#ifdef CONFIG_PM_SLEEP +/* + * tegra30_sleep_cpu_secondary_finish(unsigned long v2p) + * + * Enters LP2 on secondary CPU by exiting coherency and powergating the CPU. + */ +ENTRY(tegra30_sleep_cpu_secondary_finish) + mov r7, lr + + /* Flush and disable the L1 data cache */ + bl tegra_disable_clean_inv_dcache + + /* Powergate this CPU. */ + mov r0, #0 @ power mode flags (!hotplug) + bl tegra30_cpu_shutdown + mov r0, #1 @ never return here + mov pc, r7 +ENDPROC(tegra30_sleep_cpu_secondary_finish) +#endif
arch/arm/mach-tegra/sleep.S +29 -0
@@ -25,9 +25,38 @@ #include <linux/linkage.h> #include <asm/assembler.h> +#include <asm/cp15.h> #include <mach/iomap.h> #include "flowctrl.h" #include "sleep.h" +#ifdef CONFIG_PM_SLEEP +/* + * tegra_disable_clean_inv_dcache + * + * disable, clean & invalidate the D-cache + * + * Corrupted registers: r1-r3, r6, r8, r9-r11 + */ +ENTRY(tegra_disable_clean_inv_dcache) + stmfd sp!, {r0, r4-r5, r7, r9-r11, lr} + dmb @ ensure ordering + + /* Disable the D-cache */ + mrc p15, 0, r2, c1, c0, 0 + bic r2, r2, #CR_C + mcr p15, 0, r2, c1, c0, 0 + isb + + /* Flush the D-cache */ + bl v7_flush_dcache_louis + + /* Trun off coherency */ + exit_smp r4, r5 + + ldmfd sp!, {r0, r4-r5, r7, r9-r11, pc} +ENDPROC(tegra_disable_clean_inv_dcache) + +#endif
arch/arm/mach-tegra/sleep.h +2 -0
@@ -82,5 +82,7 @@ static inline void tegra20_hotplug_init(void) {}static inline void tegra30_hotplug_init (void ) {}#endif +int tegra30_sleep_cpu_secondary_finish (unsigned long ); +#endif #endif
Signature · 1 line
1.7.0.4
PATCH v2 4/7 ARM: tegra30: common: enable csite clock
In reply to Joseph LoEnable csite (debug and trace controller) clock at init to prevent it be disabled. And this also the necessary clock for CPU be brought up or resumed from a power-gate low power state (e.g., LP2).
---
V2:
* same with V1
arch/arm/mach-tegra/common.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
arch/arm/mach-tegra/common.c +1 -0
@@ -108,6 +108,7 @@ static __initdata struct tegra_clk_init_table tegra30_clk_init_table[] = { { "sclk", "pll_p_out4", 102000000, true }, { "hclk", "sclk", 102000000, true }, { "pclk", "hclk", 51000000, true }, + { "csite", NULL, 0, true }, { NULL, NULL, 0, 0}, }; #endif
Signature · 1 line
1.7.0.4
PATCH v2 5/7 ARM: tegra30: clocks: add CPU low-power function into tegra_cpu_car_ops
In reply to Joseph LoAdd suspend, resume and rail_off_ready API into tegra_cpu_car_ops. These functions were used for CPU low-power state maintenance (e.g., LP2). One thing needs to notice the rail_off_ready API only availalbe for cpu_g cluster not cpu_lp cluster.
---
V2:
* same with V1
arch/arm/mach-tegra/tegra30_clocks.c | 107 ++++++++++++++++++++++++++++++++++ arch/arm/mach-tegra/tegra_cpu_car.h | 37 ++++++++++++ 2 files changed, 144 insertions(+), 0 deletions(-)
arch/arm/mach-tegra/tegra30_clocks.c +107 -0
@@ -32,6 +32,7 @@#include <asm/clkdev.h> #include <mach/iomap.h> +#include <mach/powergate.h> #include "clock.h" #include "fuse.h"
@@ -310,6 +311,31 @@#define CPU_CLOCK (cpu) (0x1 << (8 + cpu))#define CPU_RESET (cpu) (0x1111ul << (cpu)) +#define CLK_RESET_CCLK_BURST 0x20 +#define CLK_RESET_CCLK_DIVIDER 0x24 +#define CLK_RESET_PLLX_BASE 0xe0 +#define CLK_RESET_PLLX_MISC 0xe4 + +#define CLK_RESET_SOURCE_CSITE 0x1d4 + +#define CLK_RESET_CCLK_BURST_POLICY_SHIFT 28 +#define CLK_RESET_CCLK_RUN_POLICY_SHIFT 4 +#define CLK_RESET_CCLK_IDLE_POLICY_SHIFT 0 +#define CLK_RESET_CCLK_IDLE_POLICY 1 +#define CLK_RESET_CCLK_RUN_POLICY 2 +#define CLK_RESET_CCLK_BURST_POLICY_PLLX 8 + +#ifdef CONFIG_PM_SLEEP +static struct cpu_clk_suspend_context { +u32 pllx_misc; +u32 pllx_base; + +u32 cpu_burst; +u32 clk_csite_src; +u32 cclk_divider; +} tegra30_cpu_clk_sctx; +#endif +/** * Structure defining the fields for USB UTMI clocks Parameters. */
@@ -2387,12 +2413,93 @@ static void tegra30_disable_cpu_clock(u32 cpu) reg_clk_base + TEGRA_CLK_RST_CONTROLLER_CLK_CPU_CMPLX); } +#ifdef CONFIG_PM_SLEEP +static bool tegra30_cpu_rail_off_ready (void ) +{ +unsigned int cpu_rst_status; +int cpu_pwr_status; + + cpu_rst_status =readl (reg_clk_base + +TEGRA30_CLK_RST_CONTROLLER_CPU_CMPLX_STATUS ); + cpu_pwr_status =tegra_powergate_is_powered (TEGRA_POWERGATE_CPU1 ) || +tegra_powergate_is_powered (TEGRA_POWERGATE_CPU2 ) || +tegra_powergate_is_powered (TEGRA_POWERGATE_CPU3 ); + +if (((cpu_rst_status &0xE ) !=0xE ) || cpu_pwr_status) +return false; + +return true; +} + +static void tegra30_cpu_clock_suspend (void ) +{ +/* switch coresite to clk_m, save off original source */ + tegra30_cpu_clk_sctx.clk_csite_src = +readl (reg_clk_base +CLK_RESET_SOURCE_CSITE ); +writel (3 <<30 , reg_clk_base +CLK_RESET_SOURCE_CSITE ); + + tegra30_cpu_clk_sctx.cpu_burst = +readl (reg_clk_base +CLK_RESET_CCLK_BURST ); + tegra30_cpu_clk_sctx.pllx_base = +readl (reg_clk_base +CLK_RESET_PLLX_BASE ); + tegra30_cpu_clk_sctx.pllx_misc = +readl (reg_clk_base +CLK_RESET_PLLX_MISC ); + tegra30_cpu_clk_sctx.cclk_divider = +readl (reg_clk_base +CLK_RESET_CCLK_DIVIDER ); +} + +static void tegra30_cpu_clock_resume (void ) +{ +unsigned int reg, policy; + +/* Is CPU complex already running on PLLX? */ + reg =readl (reg_clk_base +CLK_RESET_CCLK_BURST ); + policy = (reg >>CLK_RESET_CCLK_BURST_POLICY_SHIFT ) &0xF ; + +if (policy ==CLK_RESET_CCLK_IDLE_POLICY ) + reg = (reg >>CLK_RESET_CCLK_IDLE_POLICY_SHIFT ) &0xF ; +else if (policy ==CLK_RESET_CCLK_RUN_POLICY ) + reg = (reg >>CLK_RESET_CCLK_RUN_POLICY_SHIFT ) &0xF ; +else +BUG (); + +if (reg !=CLK_RESET_CCLK_BURST_POLICY_PLLX ) { +/* restore PLLX settings if CPU is on different PLL */ +writel (tegra30_cpu_clk_sctx.pllx_misc, + reg_clk_base +CLK_RESET_PLLX_MISC ); +writel (tegra30_cpu_clk_sctx.pllx_base, + reg_clk_base +CLK_RESET_PLLX_BASE ); + +/* wait for PLL stabilization if PLLX was enabled */ +if (tegra30_cpu_clk_sctx.pllx_base & (1 <<30 )) +udelay (300 ); + } + +/* +* Restore original burst policy setting for calls resulting from CPU +* LP2 in idle or system suspend. +*/ +writel (tegra30_cpu_clk_sctx.cclk_divider, + reg_clk_base +CLK_RESET_CCLK_DIVIDER ); +writel (tegra30_cpu_clk_sctx.cpu_burst, + reg_clk_base +CLK_RESET_CCLK_BURST ); + +writel (tegra30_cpu_clk_sctx.clk_csite_src, + reg_clk_base +CLK_RESET_SOURCE_CSITE ); +} +#endif +static struct tegra_cpu_car_ops tegra30_cpu_car_ops = { .wait_for_reset = tegra30_wait_cpu_in_reset, .put_in_reset = tegra30_put_cpu_in_reset, .out_of_reset = tegra30_cpu_out_of_reset, .enable_clock = tegra30_enable_cpu_clock, .disable_clock = tegra30_disable_cpu_clock, +#ifdef CONFIG_PM_SLEEP + .rail_off_ready = tegra30_cpu_rail_off_ready, + .suspend = tegra30_cpu_clock_suspend, + .resume = tegra30_cpu_clock_resume, +#endif };void __init tegra30_cpu_car_ops_init (void )
arch/arm/mach-tegra/tegra_cpu_car.h +37 -0
@@ -30,6 +30,12 @@* CPU clock un-gate * disable_clock: * CPU clock gate +* rail_off_ready: +* CPU is ready for rail off +* suspend: +* save the clock settings when CPU go into low-power state +* resume: +* restore the clock settings when CPU exit low-power state */ struct tegra_cpu_car_ops {void (*wait_for_reset)(u32 cpu);
@@ -37,6 +43,11 @@ struct tegra_cpu_car_ops {void (*out_of_reset)(u32 cpu);void (*enable_clock)(u32 cpu);void (*disable_clock)(u32 cpu); +#ifdef CONFIG_PM_SLEEP +bool (*rail_off_ready)(void ); +void (*suspend)(void ); +void (*resume)(void ); +#endif };extern struct tegra_cpu_car_ops *tegra_cpu_car_ops;
@@ -81,6 +92,32 @@ static inline void tegra_disable_cpu_clock(u32 cpu) tegra_cpu_car_ops->disable_clock (cpu); } +#ifdef CONFIG_PM_SLEEP +static inline bool tegra_cpu_rail_off_ready (void ) +{ +if (WARN_ON (!tegra_cpu_car_ops->rail_off_ready)) +return false; + +return tegra_cpu_car_ops->rail_off_ready (); +} + +static inline void tegra_cpu_clock_suspend (void ) +{ +if (WARN_ON (!tegra_cpu_car_ops->suspend)) +return ; + + tegra_cpu_car_ops->suspend (); +} + +static inline void tegra_cpu_clock_resume (void ) +{ +if (WARN_ON (!tegra_cpu_car_ops->resume)) +return ; + + tegra_cpu_car_ops->resume (); +} +#endif +void tegra20_cpu_car_ops_init (void );void tegra30_cpu_car_ops_init (void );
Signature · 1 line
1.7.0.4
PATCH v2 6/7 ARM: tegra30: flowctrl: add cpu_suspend_exter/exit function
In reply to Joseph LoThe flow controller can help CPU to go into suspend mode (deep power saving mode). When CPU go into deep power saving mode, it needs some careful settings before getting into and after leaving. The enter and exit functions do that by configuring appropriate mode for flow controller.
---
V2:
* same with V1
arch/arm/mach-tegra/flowctrl.c | 47 ++++++++++++++++++++++++++++++++++++++++ arch/arm/mach-tegra/flowctrl.h | 8 ++++++ 2 files changed, 55 insertions(+), 0 deletions(-)
arch/arm/mach-tegra/flowctrl.c +47 -0
@@ -21,6 +21,7 @@#include <linux/init.h> #include <linux/kernel.h> #include <linux/io.h> +#include <linux/cpumask.h> #include <mach/iomap.h>
@@ -51,6 +52,14 @@ static void flowctrl_update(u8 offset, u32 value)readl_relaxed (addr); } +u32 flowctrl_read_cpu_csr (unsigned int cpuid) +{ +u8 offset = flowctrl_offset_cpu_csr[cpuid]; +void __iomem *addr =IO_ADDRESS (TEGRA_FLOW_CTRL_BASE ) + offset; + +return readl (addr); +} +void flowctrl_write_cpu_csr (unsigned int cpuid,u32 value) {return flowctrl_update (flowctrl_offset_cpu_csr[cpuid], value);
@@ -60,3 +69,41 @@ void flowctrl_write_cpu_halt(unsigned int cpuid, u32 value) {return flowctrl_update (flowctrl_offset_halt_cpu[cpuid], value); } + +void flowctrl_cpu_suspend_enter (unsigned int cpuid) +{ +unsigned int reg; +int i; + + reg =flowctrl_read_cpu_csr (cpuid); + reg &= ~TEGRA30_FLOW_CTRL_CSR_WFE_BITMAP ;/* clear wfe bitmap */ + reg &= ~TEGRA30_FLOW_CTRL_CSR_WFI_BITMAP ;/* clear wfi bitmap */ + reg |=FLOW_CTRL_CSR_INTR_FLAG ;/* clear intr flag */ + reg |=FLOW_CTRL_CSR_EVENT_FLAG ;/* clear event flag */ + reg |=TEGRA30_FLOW_CTRL_CSR_WFI_CPU0 << cpuid;/* pwr gating on wfi */ + reg |=FLOW_CTRL_CSR_ENABLE ;/* pwr gating */ +flowctrl_write_cpu_csr (cpuid, reg); + +for (i =0 ; i <num_possible_cpus (); i++) { +if (i == cpuid) +continue ; + reg =flowctrl_read_cpu_csr (i); + reg |=FLOW_CTRL_CSR_EVENT_FLAG ; + reg |=FLOW_CTRL_CSR_INTR_FLAG ; +flowctrl_write_cpu_csr (i, reg); + } +} + +void flowctrl_cpu_suspend_exit (unsigned int cpuid) +{ +unsigned int reg; + +/* Disable powergating via flow controller for CPU0 */ + reg =flowctrl_read_cpu_csr (cpuid); + reg &= ~TEGRA30_FLOW_CTRL_CSR_WFE_BITMAP ;/* clear wfe bitmap */ + reg &= ~TEGRA30_FLOW_CTRL_CSR_WFI_BITMAP ;/* clear wfi bitmap */ + reg &= ~FLOW_CTRL_CSR_ENABLE ;/* clear enable */ + reg |=FLOW_CTRL_CSR_INTR_FLAG ;/* clear intr */ + reg |=FLOW_CTRL_CSR_EVENT_FLAG ;/* clear event */ +flowctrl_write_cpu_csr (cpuid, reg); +}
arch/arm/mach-tegra/flowctrl.h +8 -0
@@ -34,9 +34,17 @@#define FLOW_CTRL_HALT_CPU1_EVENTS 0x14#define FLOW_CTRL_CPU1_CSR 0x18 +#define TEGRA30_FLOW_CTRL_CSR_WFI_CPU0 (1 << 8) +#define TEGRA30_FLOW_CTRL_CSR_WFE_BITMAP (0xF << 4) +#define TEGRA30_FLOW_CTRL_CSR_WFI_BITMAP (0xF << 8) +#ifndef __ASSEMBLY__ +u32 flowctrl_read_cpu_csr (unsigned int cpuid);void flowctrl_write_cpu_csr (unsigned int cpuid,u32 value);void flowctrl_write_cpu_halt (unsigned int cpuid,u32 value); + +void flowctrl_cpu_suspend_enter (unsigned int cpuid); +void flowctrl_cpu_suspend_exit (unsigned int cpuid);#endif #endif
Signature · 1 line
1.7.0.4
PATCH v2 7/7 ARM: tegra30: cpuidle: add LP2 driver for CPU0
In reply to Joseph LoThe cpuidle LP2 is a power gating idle mode. It support power gating vdd_cpu rail after all cpu cores in LP2. For Tegra30, the CPU0 must be last one to go into LP2. We need to take care and make sure whole secondary CPUs were in LP2 by checking CPU and power gate status. After that, the CPU0 can go into LP2 safely. Then power gating the CPU rail.
Base on the work by:
Scott Williams <[email protected]>
---
V2:
* refine the pclk usage in "set_power_timers"
arch/arm/mach-tegra/cpuidle-tegra30.c | 41 +++++++++- arch/arm/mach-tegra/pm.c | 145 +++++++++++++++++++++++++++++++++ arch/arm/mach-tegra/pm.h | 3 + arch/arm/mach-tegra/sleep-tegra30.S | 44 ++++++++++ arch/arm/mach-tegra/sleep.S | 42 ++++++++++ arch/arm/mach-tegra/sleep.h | 2 + 6 files changed, 273 insertions(+), 4 deletions(-)
arch/arm/mach-tegra/cpuidle-tegra30.c +37 -4
@@ -32,6 +32,7 @@#include "pm.h" #include "sleep.h" +#include "tegra_cpu_car.h" #ifdef CONFIG_PM_SLEEP static int tegra30_idle_lp2(struct cpuidle_device *dev,
@@ -67,6 +68,28 @@ static struct cpuidle_driver tegra_idle_driver = { static DEFINE_PER_CPU(struct cpuidle_device, tegra_idle_device);#ifdef CONFIG_PM_SLEEP +static bool tegra30_idle_enter_lp2_cpu_0 (struct cpuidle_device *dev, +struct cpuidle_driver *drv, +int index) +{ +struct cpuidle_state *state = &drv->states[index]; +u32 cpu_on_time = state->exit_latency; +u32 cpu_off_time = state->target_residency - state->exit_latency; + +if (num_online_cpus () >1 && !tegra_cpu_rail_off_ready ()) { +cpu_do_idle (); +return false; + } + +clockevents_notify (CLOCK_EVT_NOTIFY_BROADCAST_ENTER , &dev->cpu); + +tegra_idle_lp2_last (cpu_on_time, cpu_off_time); + +clockevents_notify (CLOCK_EVT_NOTIFY_BROADCAST_EXIT , &dev->cpu); + +return true; +} +#ifdef CONFIG_SMP static bool tegra30_idle_enter_lp2_cpu_n(struct cpuidle_device *dev, struct cpuidle_driver *drv,
@@ -101,16 +124,22 @@ static int __cpuinit tegra30_idle_lp2(struct cpuidle_device *dev, {u32 cpu =is_smp () ?cpu_logical_map (dev->cpu) : dev->cpu;bool entered_lp2 = false; +bool last_cpu;local_fiq_disable (); -tegra_set_cpu_in_lp2 (cpu); + last_cpu =tegra_set_cpu_in_lp2 (cpu);cpu_pm_enter (); -if (cpu ==0 ) -cpu_do_idle (); -else +if (cpu ==0 ) { +if (last_cpu) + entered_lp2 =tegra30_idle_enter_lp2_cpu_0 (dev, drv, + index); +else +cpu_do_idle (); + }else { entered_lp2 =tegra30_idle_enter_lp2_cpu_n (dev, drv, index); + }cpu_pm_exit ();tegra_clear_cpu_in_lp2 (cpu);
@@ -130,6 +159,10 @@ int __init tegra30_cpuidle_init(void)struct cpuidle_device *dev;struct cpuidle_driver *drv = &tegra_idle_driver; +#ifdef CONFIG_PM_SLEEP + tegra_tear_down_cpu = tegra30_tear_down_cpu; +#endif + ret =cpuidle_register_driver (&tegra_idle_driver);if (ret) {pr_err ("CPUidle driver registration failed\n" );
arch/arm/mach-tegra/pm.c +145 -0
169 lines not on this page · raw message
arch/arm/mach-tegra/pm.h +3 -0
@@ -27,4 +27,7 @@ void restore_cpu_arch_register(void);void tegra_clear_cpu_in_lp2 (int phy_cpu_id);bool tegra_set_cpu_in_lp2 (int phy_cpu_id); +void tegra_idle_lp2_last (u32 cpu_on_time,u32 cpu_off_time); +extern void (*tegra_tear_down_cpu)(void ); +#endif /* _MACH_TEGRA_PM_H_ */
arch/arm/mach-tegra/sleep-tegra30.S +44 -0
48 lines not on this page · raw message
arch/arm/mach-tegra/sleep.S +42 -0
52 lines not on this page · raw message
arch/arm/mach-tegra/sleep.h +2 -0
@@ -73,6 +73,7 @@ .endm#else void tegra_resume (void ); +int tegra_sleep_cpu_finish (unsigned long );#ifdef CONFIG_HOTPLUG_CPU void tegra20_hotplug_init (void );
@@ -83,6 +84,7 @@ static inline void tegra30_hotplug_init(void) {}#endif int tegra30_sleep_cpu_secondary_finish (unsigned long ); +void tegra30_tear_down_cpu (void );#endif #endif
Signature · 1 line
1.7.0.4
v2 cover ARM: tegra30: cpuidle: add LP2 support
In reply to Joseph LoQuoted 8 lines · Joseph Lo
The CPU idle LP2 is a power gating idle mode for Tegra30. It supports the secondary CPUs (i.e., CPU1-CPU3) to go into LP2 dynamically. When any of the secondary CPUs go into LP2, it can be power gated alone. There is a limitation on CPU0. The CPU0 can go into LP2 only when all secondary CPUs are already in LP2. After CPU0 is in LP2, the CPU rail can be turned off.
Verified on Seaboard(Tegra20) and Cardhu(Tegra30).
Quoted 8 lines
This patch set should depend on these two patches:
d8be3dc ARM: tegra: rename the file of "sleep-tXX" to "sleep-tegraXX" 01b176e ARM: tegra30: clocks: add AHB and APB clocksPrevious work can be found at:
V1:
http://www.mail-archive.com/linux-tegra at vger.kernel.org/msg06319.html
Hi Stephen,
I need to abandon this patch set. There is a potential issue that will cause CPU0 corruption. I am investigate on this and will get back to you later.
Thanks,
Joseph