Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'tegra-for-3.9-soc-cpuidle' of git://git.kernel.org/pub/scm/linux/kernel/git/swarren/linux-tegra into next/soc

From Stephen Warren:
ARM: tegra: cpuidle enhancements

This pull request implements a new "LP2" cpuidle state for Tegra20,
which makes use of the couple cpuidle feature.

It is based on (most of) the previous pull request, with tag
tegra-for-3.9-soc-usb.

* tag 'tegra-for-3.9-soc-cpuidle' of git://git.kernel.org/pub/scm/linux/kernel/git/swarren/linux-tegra:
ARM: tegra20: cpuidle: apply coupled cpuidle for powered-down mode
ARM: tegra20: flowctrl: add support for cpu_suspend_enter/exit
clk: tegra20: Implementing CPU low-power function for tegra_cpu_car_ops
ARM: tegra20: cpuidle: add powered-down state for secondary CPU
ARM: tegra: add pending SGI checking API

Signed-off-by: Olof Johansson <olof@lixom.net>

+609 -9
+1
arch/arm/mach-tegra/Kconfig
··· 4 4 5 5 config ARCH_TEGRA_2x_SOC 6 6 bool "Enable support for Tegra20 family" 7 + select ARCH_NEEDS_CPU_IDLE_COUPLED if SMP 7 8 select ARCH_REQUIRE_GPIOLIB 8 9 select ARM_ERRATA_720789 9 10 select ARM_ERRATA_742230 if SMP
+193 -4
arch/arm/mach-tegra/cpuidle-tegra20.c
··· 22 22 #include <linux/kernel.h> 23 23 #include <linux/module.h> 24 24 #include <linux/cpuidle.h> 25 + #include <linux/cpu_pm.h> 26 + #include <linux/clockchips.h> 27 + #include <linux/clk/tegra.h> 25 28 26 29 #include <asm/cpuidle.h> 30 + #include <asm/proc-fns.h> 31 + #include <asm/suspend.h> 32 + #include <asm/smp_plat.h> 33 + 34 + #include "pm.h" 35 + #include "sleep.h" 36 + #include "iomap.h" 37 + #include "irq.h" 38 + #include "flowctrl.h" 39 + 40 + #ifdef CONFIG_PM_SLEEP 41 + static bool abort_flag; 42 + static atomic_t abort_barrier; 43 + static int tegra20_idle_lp2_coupled(struct cpuidle_device *dev, 44 + struct cpuidle_driver *drv, 45 + int index); 46 + #endif 47 + 48 + static struct cpuidle_state tegra_idle_states[] = { 49 + [0] = ARM_CPUIDLE_WFI_STATE_PWR(600), 50 + #ifdef CONFIG_PM_SLEEP 51 + [1] = { 52 + .enter = tegra20_idle_lp2_coupled, 53 + .exit_latency = 5000, 54 + .target_residency = 10000, 55 + .power_usage = 0, 56 + .flags = CPUIDLE_FLAG_TIME_VALID | 57 + CPUIDLE_FLAG_COUPLED, 58 + .name = "powered-down", 59 + .desc = "CPU power gated", 60 + }, 61 + #endif 62 + }; 27 63 28 64 static struct cpuidle_driver tegra_idle_driver = { 29 65 .name = "tegra_idle", 30 66 .owner = THIS_MODULE, 31 67 .en_core_tk_irqen = 1, 32 - .state_count = 1, 33 - .states = { 34 - [0] = ARM_CPUIDLE_WFI_STATE_PWR(600), 35 - }, 36 68 }; 37 69 38 70 static DEFINE_PER_CPU(struct cpuidle_device, tegra_idle_device); 71 + 72 + #ifdef CONFIG_PM_SLEEP 73 + #ifdef CONFIG_SMP 74 + static void __iomem *pmc = IO_ADDRESS(TEGRA_PMC_BASE); 75 + 76 + static int tegra20_reset_sleeping_cpu_1(void) 77 + { 78 + int ret = 0; 79 + 80 + tegra_pen_lock(); 81 + 82 + if (readl(pmc + PMC_SCRATCH41) == CPU_RESETTABLE) 83 + tegra20_cpu_shutdown(1); 84 + else 85 + ret = -EINVAL; 86 + 87 + tegra_pen_unlock(); 88 + 89 + return ret; 90 + } 91 + 92 + static void tegra20_wake_cpu1_from_reset(void) 93 + { 94 + tegra_pen_lock(); 95 + 96 + tegra20_cpu_clear_resettable(); 97 + 98 + /* enable cpu clock on cpu */ 99 + tegra_enable_cpu_clock(1); 100 + 101 + /* take the CPU out of reset */ 102 + tegra_cpu_out_of_reset(1); 103 + 104 + /* unhalt the cpu */ 105 + flowctrl_write_cpu_halt(1, 0); 106 + 107 + tegra_pen_unlock(); 108 + } 109 + 110 + static int tegra20_reset_cpu_1(void) 111 + { 112 + if (!cpu_online(1) || !tegra20_reset_sleeping_cpu_1()) 113 + return 0; 114 + 115 + tegra20_wake_cpu1_from_reset(); 116 + return -EBUSY; 117 + } 118 + #else 119 + static inline void tegra20_wake_cpu1_from_reset(void) 120 + { 121 + } 122 + 123 + static inline int tegra20_reset_cpu_1(void) 124 + { 125 + return 0; 126 + } 127 + #endif 128 + 129 + static bool tegra20_cpu_cluster_power_down(struct cpuidle_device *dev, 130 + struct cpuidle_driver *drv, 131 + int index) 132 + { 133 + struct cpuidle_state *state = &drv->states[index]; 134 + u32 cpu_on_time = state->exit_latency; 135 + u32 cpu_off_time = state->target_residency - state->exit_latency; 136 + 137 + while (tegra20_cpu_is_resettable_soon()) 138 + cpu_relax(); 139 + 140 + if (tegra20_reset_cpu_1() || !tegra_cpu_rail_off_ready()) 141 + return false; 142 + 143 + clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_ENTER, &dev->cpu); 144 + 145 + tegra_idle_lp2_last(cpu_on_time, cpu_off_time); 146 + 147 + clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_EXIT, &dev->cpu); 148 + 149 + if (cpu_online(1)) 150 + tegra20_wake_cpu1_from_reset(); 151 + 152 + return true; 153 + } 154 + 155 + #ifdef CONFIG_SMP 156 + static bool tegra20_idle_enter_lp2_cpu_1(struct cpuidle_device *dev, 157 + struct cpuidle_driver *drv, 158 + int index) 159 + { 160 + clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_ENTER, &dev->cpu); 161 + 162 + cpu_suspend(0, tegra20_sleep_cpu_secondary_finish); 163 + 164 + tegra20_cpu_clear_resettable(); 165 + 166 + clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_EXIT, &dev->cpu); 167 + 168 + return true; 169 + } 170 + #else 171 + static inline bool tegra20_idle_enter_lp2_cpu_1(struct cpuidle_device *dev, 172 + struct cpuidle_driver *drv, 173 + int index) 174 + { 175 + return true; 176 + } 177 + #endif 178 + 179 + static int tegra20_idle_lp2_coupled(struct cpuidle_device *dev, 180 + struct cpuidle_driver *drv, 181 + int index) 182 + { 183 + u32 cpu = is_smp() ? cpu_logical_map(dev->cpu) : dev->cpu; 184 + bool entered_lp2 = false; 185 + 186 + if (tegra_pending_sgi()) 187 + ACCESS_ONCE(abort_flag) = true; 188 + 189 + cpuidle_coupled_parallel_barrier(dev, &abort_barrier); 190 + 191 + if (abort_flag) { 192 + cpuidle_coupled_parallel_barrier(dev, &abort_barrier); 193 + abort_flag = false; /* clean flag for next coming */ 194 + return -EINTR; 195 + } 196 + 197 + local_fiq_disable(); 198 + 199 + tegra_set_cpu_in_lp2(cpu); 200 + cpu_pm_enter(); 201 + 202 + if (cpu == 0) 203 + entered_lp2 = tegra20_cpu_cluster_power_down(dev, drv, index); 204 + else 205 + entered_lp2 = tegra20_idle_enter_lp2_cpu_1(dev, drv, index); 206 + 207 + cpu_pm_exit(); 208 + tegra_clear_cpu_in_lp2(cpu); 209 + 210 + local_fiq_enable(); 211 + 212 + smp_rmb(); 213 + 214 + return entered_lp2 ? index : 0; 215 + } 216 + #endif 39 217 40 218 int __init tegra20_cpuidle_init(void) 41 219 { ··· 221 43 unsigned int cpu; 222 44 struct cpuidle_device *dev; 223 45 struct cpuidle_driver *drv = &tegra_idle_driver; 46 + 47 + #ifdef CONFIG_PM_SLEEP 48 + tegra_tear_down_cpu = tegra20_tear_down_cpu; 49 + #endif 50 + 51 + drv->state_count = ARRAY_SIZE(tegra_idle_states); 52 + memcpy(drv->states, tegra_idle_states, 53 + drv->state_count * sizeof(drv->states[0])); 224 54 225 55 ret = cpuidle_register_driver(&tegra_idle_driver); 226 56 if (ret) { ··· 239 53 for_each_possible_cpu(cpu) { 240 54 dev = &per_cpu(tegra_idle_device, cpu); 241 55 dev->cpu = cpu; 56 + #ifdef CONFIG_ARCH_NEEDS_CPU_IDLE_COUPLED 57 + dev->coupled_cpus = *cpu_possible_mask; 58 + #endif 242 59 243 60 dev->state_count = drv->state_count; 244 61 ret = cpuidle_register_device(dev);
+33 -5
arch/arm/mach-tegra/flowctrl.c
··· 25 25 26 26 #include "flowctrl.h" 27 27 #include "iomap.h" 28 + #include "fuse.h" 28 29 29 30 static u8 flowctrl_offset_halt_cpu[] = { 30 31 FLOW_CTRL_HALT_CPU0_EVENTS, ··· 76 75 int i; 77 76 78 77 reg = flowctrl_read_cpu_csr(cpuid); 79 - reg &= ~TEGRA30_FLOW_CTRL_CSR_WFE_BITMAP; /* clear wfe bitmap */ 80 - reg &= ~TEGRA30_FLOW_CTRL_CSR_WFI_BITMAP; /* clear wfi bitmap */ 78 + switch (tegra_chip_id) { 79 + case TEGRA20: 80 + /* clear wfe bitmap */ 81 + reg &= ~TEGRA20_FLOW_CTRL_CSR_WFE_BITMAP; 82 + /* clear wfi bitmap */ 83 + reg &= ~TEGRA20_FLOW_CTRL_CSR_WFI_BITMAP; 84 + /* pwr gating on wfe */ 85 + reg |= TEGRA20_FLOW_CTRL_CSR_WFE_CPU0 << cpuid; 86 + break; 87 + case TEGRA30: 88 + /* clear wfe bitmap */ 89 + reg &= ~TEGRA30_FLOW_CTRL_CSR_WFE_BITMAP; 90 + /* clear wfi bitmap */ 91 + reg &= ~TEGRA30_FLOW_CTRL_CSR_WFI_BITMAP; 92 + /* pwr gating on wfi */ 93 + reg |= TEGRA30_FLOW_CTRL_CSR_WFI_CPU0 << cpuid; 94 + break; 95 + } 81 96 reg |= FLOW_CTRL_CSR_INTR_FLAG; /* clear intr flag */ 82 97 reg |= FLOW_CTRL_CSR_EVENT_FLAG; /* clear event flag */ 83 - reg |= TEGRA30_FLOW_CTRL_CSR_WFI_CPU0 << cpuid; /* pwr gating on wfi */ 84 98 reg |= FLOW_CTRL_CSR_ENABLE; /* pwr gating */ 85 99 flowctrl_write_cpu_csr(cpuid, reg); 86 100 ··· 115 99 116 100 /* Disable powergating via flow controller for CPU0 */ 117 101 reg = flowctrl_read_cpu_csr(cpuid); 118 - reg &= ~TEGRA30_FLOW_CTRL_CSR_WFE_BITMAP; /* clear wfe bitmap */ 119 - reg &= ~TEGRA30_FLOW_CTRL_CSR_WFI_BITMAP; /* clear wfi bitmap */ 102 + switch (tegra_chip_id) { 103 + case TEGRA20: 104 + /* clear wfe bitmap */ 105 + reg &= ~TEGRA20_FLOW_CTRL_CSR_WFE_BITMAP; 106 + /* clear wfi bitmap */ 107 + reg &= ~TEGRA20_FLOW_CTRL_CSR_WFI_BITMAP; 108 + break; 109 + case TEGRA30: 110 + /* clear wfe bitmap */ 111 + reg &= ~TEGRA30_FLOW_CTRL_CSR_WFE_BITMAP; 112 + /* clear wfi bitmap */ 113 + reg &= ~TEGRA30_FLOW_CTRL_CSR_WFI_BITMAP; 114 + break; 115 + } 120 116 reg &= ~FLOW_CTRL_CSR_ENABLE; /* clear enable */ 121 117 reg |= FLOW_CTRL_CSR_INTR_FLAG; /* clear intr */ 122 118 reg |= FLOW_CTRL_CSR_EVENT_FLAG; /* clear event */
+4
arch/arm/mach-tegra/flowctrl.h
··· 34 34 #define FLOW_CTRL_HALT_CPU1_EVENTS 0x14 35 35 #define FLOW_CTRL_CPU1_CSR 0x18 36 36 37 + #define TEGRA20_FLOW_CTRL_CSR_WFE_CPU0 (1 << 4) 38 + #define TEGRA20_FLOW_CTRL_CSR_WFE_BITMAP (3 << 4) 39 + #define TEGRA20_FLOW_CTRL_CSR_WFI_BITMAP 0 40 + 37 41 #define TEGRA30_FLOW_CTRL_CSR_WFI_CPU0 (1 << 8) 38 42 #define TEGRA30_FLOW_CTRL_CSR_WFE_BITMAP (0xF << 4) 39 43 #define TEGRA30_FLOW_CTRL_CSR_WFI_BITMAP (0xF << 8)
+15
arch/arm/mach-tegra/irq.c
··· 44 44 45 45 #define FIRST_LEGACY_IRQ 32 46 46 47 + #define SGI_MASK 0xFFFF 48 + 47 49 static int num_ictlrs; 48 50 49 51 static void __iomem *ictlr_reg_base[] = { ··· 55 53 IO_ADDRESS(TEGRA_QUATERNARY_ICTLR_BASE), 56 54 IO_ADDRESS(TEGRA_QUINARY_ICTLR_BASE), 57 55 }; 56 + 57 + bool tegra_pending_sgi(void) 58 + { 59 + u32 pending_set; 60 + void __iomem *distbase = IO_ADDRESS(TEGRA_ARM_INT_DIST_BASE); 61 + 62 + pending_set = readl_relaxed(distbase + GIC_DIST_PENDING_SET); 63 + 64 + if (pending_set & SGI_MASK) 65 + return true; 66 + 67 + return false; 68 + } 58 69 59 70 static inline void tegra_irq_write_mask(unsigned int irq, unsigned long reg) 60 71 {
+22
arch/arm/mach-tegra/irq.h
··· 1 + /* 2 + * Copyright (c) 2012, NVIDIA Corporation. All rights reserved. 3 + * 4 + * This program is free software; you can redistribute it and/or modify it 5 + * under the terms and conditions of the GNU General Public License, 6 + * version 2, as published by the Free Software Foundation. 7 + * 8 + * This program is distributed in the hope it will be useful, but WITHOUT 9 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 10 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 11 + * more details. 12 + * 13 + * You should have received a copy of the GNU General Public License 14 + * along with this program. If not, see <http://www.gnu.org/licenses/>. 15 + */ 16 + 17 + #ifndef __TEGRA_IRQ_H 18 + #define __TEGRA_IRQ_H 19 + 20 + bool tegra_pending_sgi(void); 21 + 22 + #endif
+3
arch/arm/mach-tegra/pm.c
··· 36 36 #include "iomap.h" 37 37 #include "reset.h" 38 38 #include "flowctrl.h" 39 + #include "fuse.h" 39 40 #include "sleep.h" 40 41 41 42 #define TEGRA_POWER_CPU_PWRREQ_OE (1 << 16) /* CPU pwr req enable */ ··· 174 173 175 174 if ((phy_cpu_id == 0) && cpumask_equal(cpu_lp2_mask, cpu_online_mask)) 176 175 last_cpu = true; 176 + else if (tegra_chip_id == TEGRA20 && phy_cpu_id == 1) 177 + tegra20_cpu_set_resettable_soon(); 177 178 178 179 spin_unlock(&tegra_lp2_lock); 179 180 return last_cpu;
+200
arch/arm/mach-tegra/sleep-tegra20.S
··· 21 21 #include <linux/linkage.h> 22 22 23 23 #include <asm/assembler.h> 24 + #include <asm/proc-fns.h> 25 + #include <asm/cp15.h> 24 26 25 27 #include "sleep.h" 26 28 #include "flowctrl.h" ··· 57 55 ENTRY(tegra20_cpu_shutdown) 58 56 cmp r0, #0 59 57 moveq pc, lr @ must not be called for CPU 0 58 + mov32 r1, TEGRA_PMC_VIRT + PMC_SCRATCH41 59 + mov r12, #CPU_RESETTABLE 60 + str r12, [r1] 60 61 61 62 cpu_to_halt_reg r1, r0 62 63 ldr r3, =TEGRA_FLOW_CTRL_VIRT ··· 79 74 beq . 80 75 mov pc, lr 81 76 ENDPROC(tegra20_cpu_shutdown) 77 + #endif 78 + 79 + #ifdef CONFIG_PM_SLEEP 80 + /* 81 + * tegra_pen_lock 82 + * 83 + * spinlock implementation with no atomic test-and-set and no coherence 84 + * using Peterson's algorithm on strongly-ordered registers 85 + * used to synchronize a cpu waking up from wfi with entering lp2 on idle 86 + * 87 + * The reference link of Peterson's algorithm: 88 + * http://en.wikipedia.org/wiki/Peterson's_algorithm 89 + * 90 + * SCRATCH37 = r1 = !turn (inverted from Peterson's algorithm) 91 + * on cpu 0: 92 + * r2 = flag[0] (in SCRATCH38) 93 + * r3 = flag[1] (in SCRATCH39) 94 + * on cpu1: 95 + * r2 = flag[1] (in SCRATCH39) 96 + * r3 = flag[0] (in SCRATCH38) 97 + * 98 + * must be called with MMU on 99 + * corrupts r0-r3, r12 100 + */ 101 + ENTRY(tegra_pen_lock) 102 + mov32 r3, TEGRA_PMC_VIRT 103 + cpu_id r0 104 + add r1, r3, #PMC_SCRATCH37 105 + cmp r0, #0 106 + addeq r2, r3, #PMC_SCRATCH38 107 + addeq r3, r3, #PMC_SCRATCH39 108 + addne r2, r3, #PMC_SCRATCH39 109 + addne r3, r3, #PMC_SCRATCH38 110 + 111 + mov r12, #1 112 + str r12, [r2] @ flag[cpu] = 1 113 + dsb 114 + str r12, [r1] @ !turn = cpu 115 + 1: dsb 116 + ldr r12, [r3] 117 + cmp r12, #1 @ flag[!cpu] == 1? 118 + ldreq r12, [r1] 119 + cmpeq r12, r0 @ !turn == cpu? 120 + beq 1b @ while !turn == cpu && flag[!cpu] == 1 121 + 122 + mov pc, lr @ locked 123 + ENDPROC(tegra_pen_lock) 124 + 125 + ENTRY(tegra_pen_unlock) 126 + dsb 127 + mov32 r3, TEGRA_PMC_VIRT 128 + cpu_id r0 129 + cmp r0, #0 130 + addeq r2, r3, #PMC_SCRATCH38 131 + addne r2, r3, #PMC_SCRATCH39 132 + mov r12, #0 133 + str r12, [r2] 134 + mov pc, lr 135 + ENDPROC(tegra_pen_unlock) 136 + 137 + /* 138 + * tegra20_cpu_clear_resettable(void) 139 + * 140 + * Called to clear the "resettable soon" flag in PMC_SCRATCH41 when 141 + * it is expected that the secondary CPU will be idle soon. 142 + */ 143 + ENTRY(tegra20_cpu_clear_resettable) 144 + mov32 r1, TEGRA_PMC_VIRT + PMC_SCRATCH41 145 + mov r12, #CPU_NOT_RESETTABLE 146 + str r12, [r1] 147 + mov pc, lr 148 + ENDPROC(tegra20_cpu_clear_resettable) 149 + 150 + /* 151 + * tegra20_cpu_set_resettable_soon(void) 152 + * 153 + * Called to set the "resettable soon" flag in PMC_SCRATCH41 when 154 + * it is expected that the secondary CPU will be idle soon. 155 + */ 156 + ENTRY(tegra20_cpu_set_resettable_soon) 157 + mov32 r1, TEGRA_PMC_VIRT + PMC_SCRATCH41 158 + mov r12, #CPU_RESETTABLE_SOON 159 + str r12, [r1] 160 + mov pc, lr 161 + ENDPROC(tegra20_cpu_set_resettable_soon) 162 + 163 + /* 164 + * tegra20_cpu_is_resettable_soon(void) 165 + * 166 + * Returns true if the "resettable soon" flag in PMC_SCRATCH41 has been 167 + * set because it is expected that the secondary CPU will be idle soon. 168 + */ 169 + ENTRY(tegra20_cpu_is_resettable_soon) 170 + mov32 r1, TEGRA_PMC_VIRT + PMC_SCRATCH41 171 + ldr r12, [r1] 172 + cmp r12, #CPU_RESETTABLE_SOON 173 + moveq r0, #1 174 + movne r0, #0 175 + mov pc, lr 176 + ENDPROC(tegra20_cpu_is_resettable_soon) 177 + 178 + /* 179 + * tegra20_sleep_cpu_secondary_finish(unsigned long v2p) 180 + * 181 + * Enters WFI on secondary CPU by exiting coherency. 182 + */ 183 + ENTRY(tegra20_sleep_cpu_secondary_finish) 184 + stmfd sp!, {r4-r11, lr} 185 + 186 + mrc p15, 0, r11, c1, c0, 1 @ save actlr before exiting coherency 187 + 188 + /* Flush and disable the L1 data cache */ 189 + bl tegra_disable_clean_inv_dcache 190 + 191 + mov32 r0, TEGRA_PMC_VIRT + PMC_SCRATCH41 192 + mov r3, #CPU_RESETTABLE 193 + str r3, [r0] 194 + 195 + bl cpu_do_idle 196 + 197 + /* 198 + * cpu may be reset while in wfi, which will return through 199 + * tegra_resume to cpu_resume 200 + * or interrupt may wake wfi, which will return here 201 + * cpu state is unchanged - MMU is on, cache is on, coherency 202 + * is off, and the data cache is off 203 + * 204 + * r11 contains the original actlr 205 + */ 206 + 207 + bl tegra_pen_lock 208 + 209 + mov32 r3, TEGRA_PMC_VIRT 210 + add r0, r3, #PMC_SCRATCH41 211 + mov r3, #CPU_NOT_RESETTABLE 212 + str r3, [r0] 213 + 214 + bl tegra_pen_unlock 215 + 216 + /* Re-enable the data cache */ 217 + mrc p15, 0, r10, c1, c0, 0 218 + orr r10, r10, #CR_C 219 + mcr p15, 0, r10, c1, c0, 0 220 + isb 221 + 222 + mcr p15, 0, r11, c1, c0, 1 @ reenable coherency 223 + 224 + /* Invalidate the TLBs & BTAC */ 225 + mov r1, #0 226 + mcr p15, 0, r1, c8, c3, 0 @ invalidate shared TLBs 227 + mcr p15, 0, r1, c7, c1, 6 @ invalidate shared BTAC 228 + dsb 229 + isb 230 + 231 + /* the cpu was running with coherency disabled, 232 + * caches may be out of date */ 233 + bl v7_flush_kern_cache_louis 234 + 235 + ldmfd sp!, {r4 - r11, pc} 236 + ENDPROC(tegra20_sleep_cpu_secondary_finish) 237 + 238 + /* 239 + * tegra20_tear_down_cpu 240 + * 241 + * Switches the CPU cluster to PLL-P and enters sleep. 242 + */ 243 + ENTRY(tegra20_tear_down_cpu) 244 + bl tegra_switch_cpu_to_pllp 245 + b tegra20_enter_sleep 246 + ENDPROC(tegra20_tear_down_cpu) 247 + 248 + /* 249 + * tegra20_enter_sleep 250 + * 251 + * uses flow controller to enter sleep state 252 + * executes from IRAM with SDRAM in selfrefresh when target state is LP0 or LP1 253 + * executes from SDRAM with target state is LP2 254 + */ 255 + tegra20_enter_sleep: 256 + mov32 r6, TEGRA_FLOW_CTRL_BASE 257 + 258 + mov r0, #FLOW_CTRL_WAIT_FOR_INTERRUPT 259 + orr r0, r0, #FLOW_CTRL_HALT_CPU_IRQ | FLOW_CTRL_HALT_CPU_FIQ 260 + cpu_id r1 261 + cpu_to_halt_reg r1, r1 262 + str r0, [r6, r1] 263 + dsb 264 + ldr r0, [r6, r1] /* memory barrier */ 265 + 266 + halted: 267 + dsb 268 + wfe /* CPU should be power gated here */ 269 + isb 270 + b halted 271 + 82 272 #endif
+19
arch/arm/mach-tegra/sleep.S
··· 34 34 #include "flowctrl.h" 35 35 #include "sleep.h" 36 36 37 + #define CLK_RESET_CCLK_BURST 0x20 38 + #define CLK_RESET_CCLK_DIVIDER 0x24 39 + 37 40 #if defined(CONFIG_HOTPLUG_CPU) || defined(CONFIG_PM_SLEEP) 38 41 /* 39 42 * tegra_disable_clean_inv_dcache ··· 113 110 mov pc, r0 114 111 ENDPROC(tegra_shut_off_mmu) 115 112 .popsection 113 + 114 + /* 115 + * tegra_switch_cpu_to_pllp 116 + * 117 + * In LP2 the normal cpu clock pllx will be turned off. Switch the CPU to pllp 118 + */ 119 + ENTRY(tegra_switch_cpu_to_pllp) 120 + /* in LP2 idle (SDRAM active), set the CPU burst policy to PLLP */ 121 + mov32 r5, TEGRA_CLK_RESET_BASE 122 + mov r0, #(2 << 28) @ burst policy = run mode 123 + orr r0, r0, #(4 << 4) @ use PLLP in run mode burst 124 + str r0, [r5, #CLK_RESET_CCLK_BURST] 125 + mov r0, #0 126 + str r0, [r5, #CLK_RESET_CCLK_DIVIDER] 127 + mov pc, lr 128 + ENDPROC(tegra_switch_cpu_to_pllp) 116 129 #endif
+26
arch/arm/mach-tegra/sleep.h
··· 25 25 + IO_PPSB_VIRT) 26 26 #define TEGRA_CLK_RESET_VIRT (TEGRA_CLK_RESET_BASE - IO_PPSB_PHYS \ 27 27 + IO_PPSB_VIRT) 28 + #define TEGRA_PMC_VIRT (TEGRA_PMC_BASE - IO_APB_PHYS + IO_APB_VIRT) 29 + 30 + /* PMC_SCRATCH37-39 and 41 are used for tegra_pen_lock and idle */ 31 + #define PMC_SCRATCH37 0x130 32 + #define PMC_SCRATCH38 0x134 33 + #define PMC_SCRATCH39 0x138 34 + #define PMC_SCRATCH41 0x140 35 + 36 + #ifdef CONFIG_ARCH_TEGRA_2x_SOC 37 + #define CPU_RESETTABLE 2 38 + #define CPU_RESETTABLE_SOON 1 39 + #define CPU_NOT_RESETTABLE 0 40 + #endif 28 41 29 42 #ifdef __ASSEMBLY__ 30 43 /* returns the offset of the flow controller halt register for a cpu */ ··· 117 104 .endm 118 105 #endif /* CONFIG_CACHE_L2X0 */ 119 106 #else 107 + void tegra_pen_lock(void); 108 + void tegra_pen_unlock(void); 120 109 void tegra_resume(void); 121 110 int tegra_sleep_cpu_finish(unsigned long); 122 111 void tegra_disable_clean_inv_dcache(void); ··· 131 116 static inline void tegra30_hotplug_init(void) {} 132 117 #endif 133 118 119 + void tegra20_cpu_shutdown(int cpu); 120 + int tegra20_cpu_is_resettable_soon(void); 121 + void tegra20_cpu_clear_resettable(void); 122 + #ifdef CONFIG_ARCH_TEGRA_2x_SOC 123 + void tegra20_cpu_set_resettable_soon(void); 124 + #else 125 + static inline void tegra20_cpu_set_resettable_soon(void) {} 126 + #endif 127 + 128 + int tegra20_sleep_cpu_secondary_finish(unsigned long); 129 + void tegra20_tear_down_cpu(void); 134 130 int tegra30_sleep_cpu_secondary_finish(unsigned long); 135 131 void tegra30_tear_down_cpu(void); 136 132
+93
drivers/clk/tegra/clk-tegra20.c
··· 21 21 #include <linux/of.h> 22 22 #include <linux/of_address.h> 23 23 #include <linux/clk/tegra.h> 24 + #include <linux/delay.h> 24 25 25 26 #include "clk.h" 26 27 ··· 105 104 #define SUPER_SCLK_DIVIDER 0x2c 106 105 #define CLK_SYSTEM_RATE 0x30 107 106 107 + #define CCLK_BURST_POLICY_SHIFT 28 108 + #define CCLK_RUN_POLICY_SHIFT 4 109 + #define CCLK_IDLE_POLICY_SHIFT 0 110 + #define CCLK_IDLE_POLICY 1 111 + #define CCLK_RUN_POLICY 2 112 + #define CCLK_BURST_POLICY_PLLX 8 113 + 108 114 #define CLK_SOURCE_I2S1 0x100 109 115 #define CLK_SOURCE_I2S2 0x104 110 116 #define CLK_SOURCE_SPDIF_OUT 0x108 ··· 176 168 177 169 #define CPU_CLOCK(cpu) (0x1 << (8 + cpu)) 178 170 #define CPU_RESET(cpu) (0x1111ul << (cpu)) 171 + 172 + #ifdef CONFIG_PM_SLEEP 173 + static struct cpu_clk_suspend_context { 174 + u32 pllx_misc; 175 + u32 pllx_base; 176 + 177 + u32 cpu_burst; 178 + u32 clk_csite_src; 179 + u32 cclk_divider; 180 + } tegra20_cpu_clk_sctx; 181 + #endif 179 182 180 183 static int periph_clk_enb_refcnt[CLK_OUT_ENB_NUM * 32]; 181 184 ··· 1155 1136 clk_base + TEGRA_CLK_RST_CONTROLLER_CLK_CPU_CMPLX); 1156 1137 } 1157 1138 1139 + #ifdef CONFIG_PM_SLEEP 1140 + static bool tegra20_cpu_rail_off_ready(void) 1141 + { 1142 + unsigned int cpu_rst_status; 1143 + 1144 + cpu_rst_status = readl(clk_base + 1145 + TEGRA_CLK_RST_CONTROLLER_RST_CPU_CMPLX_SET); 1146 + 1147 + return !!(cpu_rst_status & 0x2); 1148 + } 1149 + 1150 + static void tegra20_cpu_clock_suspend(void) 1151 + { 1152 + /* switch coresite to clk_m, save off original source */ 1153 + tegra20_cpu_clk_sctx.clk_csite_src = 1154 + readl(clk_base + CLK_SOURCE_CSITE); 1155 + writel(3<<30, clk_base + CLK_SOURCE_CSITE); 1156 + 1157 + tegra20_cpu_clk_sctx.cpu_burst = 1158 + readl(clk_base + CCLK_BURST_POLICY); 1159 + tegra20_cpu_clk_sctx.pllx_base = 1160 + readl(clk_base + PLLX_BASE); 1161 + tegra20_cpu_clk_sctx.pllx_misc = 1162 + readl(clk_base + PLLX_MISC); 1163 + tegra20_cpu_clk_sctx.cclk_divider = 1164 + readl(clk_base + SUPER_CCLK_DIVIDER); 1165 + } 1166 + 1167 + static void tegra20_cpu_clock_resume(void) 1168 + { 1169 + unsigned int reg, policy; 1170 + 1171 + /* Is CPU complex already running on PLLX? */ 1172 + reg = readl(clk_base + CCLK_BURST_POLICY); 1173 + policy = (reg >> CCLK_BURST_POLICY_SHIFT) & 0xF; 1174 + 1175 + if (policy == CCLK_IDLE_POLICY) 1176 + reg = (reg >> CCLK_IDLE_POLICY_SHIFT) & 0xF; 1177 + else if (policy == CCLK_RUN_POLICY) 1178 + reg = (reg >> CCLK_RUN_POLICY_SHIFT) & 0xF; 1179 + else 1180 + BUG(); 1181 + 1182 + if (reg != CCLK_BURST_POLICY_PLLX) { 1183 + /* restore PLLX settings if CPU is on different PLL */ 1184 + writel(tegra20_cpu_clk_sctx.pllx_misc, 1185 + clk_base + PLLX_MISC); 1186 + writel(tegra20_cpu_clk_sctx.pllx_base, 1187 + clk_base + PLLX_BASE); 1188 + 1189 + /* wait for PLL stabilization if PLLX was enabled */ 1190 + if (tegra20_cpu_clk_sctx.pllx_base & (1 << 30)) 1191 + udelay(300); 1192 + } 1193 + 1194 + /* 1195 + * Restore original burst policy setting for calls resulting from CPU 1196 + * LP2 in idle or system suspend. 1197 + */ 1198 + writel(tegra20_cpu_clk_sctx.cclk_divider, 1199 + clk_base + SUPER_CCLK_DIVIDER); 1200 + writel(tegra20_cpu_clk_sctx.cpu_burst, 1201 + clk_base + CCLK_BURST_POLICY); 1202 + 1203 + writel(tegra20_cpu_clk_sctx.clk_csite_src, 1204 + clk_base + CLK_SOURCE_CSITE); 1205 + } 1206 + #endif 1207 + 1158 1208 static struct tegra_cpu_car_ops tegra20_cpu_car_ops = { 1159 1209 .wait_for_reset = tegra20_wait_cpu_in_reset, 1160 1210 .put_in_reset = tegra20_put_cpu_in_reset, 1161 1211 .out_of_reset = tegra20_cpu_out_of_reset, 1162 1212 .enable_clock = tegra20_enable_cpu_clock, 1163 1213 .disable_clock = tegra20_disable_cpu_clock, 1214 + #ifdef CONFIG_PM_SLEEP 1215 + .rail_off_ready = tegra20_cpu_rail_off_ready, 1216 + .suspend = tegra20_cpu_clock_suspend, 1217 + .resume = tegra20_cpu_clock_resume, 1218 + #endif 1164 1219 }; 1165 1220 1166 1221 static __initdata struct tegra_clk_init_table init_table[] = {