Rob Herring | be6a98d | 2012-10-12 12:45:34 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2012 Calxeda, Inc. |
| 3 | * |
| 4 | * Based on arch/arm/plat-mxc/cpuidle.c: |
| 5 | * Copyright 2012 Freescale Semiconductor, Inc. |
| 6 | * Copyright 2012 Linaro Ltd. |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify it |
| 9 | * under the terms and conditions of the GNU General Public License, |
| 10 | * version 2, as published by the Free Software Foundation. |
| 11 | * |
| 12 | * This program is distributed in the hope it will be useful, but WITHOUT |
| 13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 14 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 15 | * more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License along with |
| 18 | * this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | */ |
| 20 | |
| 21 | #include <linux/cpuidle.h> |
| 22 | #include <linux/init.h> |
| 23 | #include <linux/io.h> |
| 24 | #include <linux/of.h> |
| 25 | #include <linux/time.h> |
| 26 | #include <linux/delay.h> |
| 27 | #include <linux/suspend.h> |
| 28 | #include <asm/cpuidle.h> |
| 29 | #include <asm/proc-fns.h> |
| 30 | #include <asm/smp_scu.h> |
| 31 | #include <asm/suspend.h> |
| 32 | #include <asm/cacheflush.h> |
| 33 | #include <asm/cp15.h> |
| 34 | |
| 35 | extern void highbank_set_cpu_jump(int cpu, void *jump_addr); |
| 36 | extern void *scu_base_addr; |
| 37 | |
Rob Herring | be6a98d | 2012-10-12 12:45:34 -0500 | [diff] [blame] | 38 | static inline unsigned int get_auxcr(void) |
| 39 | { |
| 40 | unsigned int val; |
| 41 | asm("mrc p15, 0, %0, c1, c0, 1 @ get AUXCR" : "=r" (val) : : "cc"); |
| 42 | return val; |
| 43 | } |
| 44 | |
| 45 | static inline void set_auxcr(unsigned int val) |
| 46 | { |
| 47 | asm volatile("mcr p15, 0, %0, c1, c0, 1 @ set AUXCR" |
| 48 | : : "r" (val) : "cc"); |
| 49 | isb(); |
| 50 | } |
| 51 | |
| 52 | static noinline void calxeda_idle_restore(void) |
| 53 | { |
| 54 | set_cr(get_cr() | CR_C); |
| 55 | set_auxcr(get_auxcr() | 0x40); |
| 56 | scu_power_mode(scu_base_addr, SCU_PM_NORMAL); |
| 57 | } |
| 58 | |
| 59 | static int calxeda_idle_finish(unsigned long val) |
| 60 | { |
| 61 | /* Already flushed cache, but do it again as the outer cache functions |
| 62 | * dirty the cache with spinlocks */ |
| 63 | flush_cache_all(); |
| 64 | |
| 65 | set_auxcr(get_auxcr() & ~0x40); |
| 66 | set_cr(get_cr() & ~CR_C); |
| 67 | |
| 68 | scu_power_mode(scu_base_addr, SCU_PM_DORMANT); |
| 69 | |
| 70 | cpu_do_idle(); |
| 71 | |
| 72 | /* Restore things if we didn't enter power-gating */ |
| 73 | calxeda_idle_restore(); |
| 74 | return 1; |
| 75 | } |
| 76 | |
| 77 | static int calxeda_pwrdown_idle(struct cpuidle_device *dev, |
| 78 | struct cpuidle_driver *drv, |
| 79 | int index) |
| 80 | { |
| 81 | highbank_set_cpu_jump(smp_processor_id(), cpu_resume); |
| 82 | cpu_suspend(0, calxeda_idle_finish); |
| 83 | return index; |
| 84 | } |
| 85 | |
Rob Herring | be6a98d | 2012-10-12 12:45:34 -0500 | [diff] [blame] | 86 | static struct cpuidle_driver calxeda_idle_driver = { |
| 87 | .name = "calxeda_idle", |
Rob Herring | be6a98d | 2012-10-12 12:45:34 -0500 | [diff] [blame] | 88 | .states = { |
| 89 | ARM_CPUIDLE_WFI_STATE, |
| 90 | { |
| 91 | .name = "PG", |
| 92 | .desc = "Power Gate", |
| 93 | .flags = CPUIDLE_FLAG_TIME_VALID, |
| 94 | .exit_latency = 30, |
| 95 | .power_usage = 50, |
| 96 | .target_residency = 200, |
| 97 | .enter = calxeda_pwrdown_idle, |
| 98 | }, |
| 99 | }, |
| 100 | .state_count = 2, |
| 101 | }; |
| 102 | |
| 103 | static int __init calxeda_cpuidle_init(void) |
| 104 | { |
Rob Herring | be6a98d | 2012-10-12 12:45:34 -0500 | [diff] [blame] | 105 | if (!of_machine_is_compatible("calxeda,highbank")) |
| 106 | return -ENODEV; |
| 107 | |
Daniel Lezcano | 0b210d9 | 2013-04-23 08:54:42 +0000 | [diff] [blame^] | 108 | return cpuidle_register(&calxeda_idle_driver, NULL); |
Rob Herring | be6a98d | 2012-10-12 12:45:34 -0500 | [diff] [blame] | 109 | } |
| 110 | module_init(calxeda_cpuidle_init); |