Rob Herring | be6a98d | 2012-10-12 12:45:34 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2012 Calxeda, Inc. |
| 3 | * |
Daniel Lezcano | a8e39c3 | 2013-04-26 11:05:44 +0000 | [diff] [blame] | 4 | * Based on arch/arm/plat-mxc/cpuidle.c: #v3.7 |
Rob Herring | be6a98d | 2012-10-12 12:45:34 -0500 | [diff] [blame] | 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/>. |
Daniel Lezcano | a8e39c3 | 2013-04-26 11:05:44 +0000 | [diff] [blame] | 19 | * |
| 20 | * Maintainer: Rob Herring <rob.herring@calxeda.com> |
Rob Herring | be6a98d | 2012-10-12 12:45:34 -0500 | [diff] [blame] | 21 | */ |
| 22 | |
| 23 | #include <linux/cpuidle.h> |
Rob Herring | 34a5eeb | 2013-02-26 16:16:53 -0600 | [diff] [blame] | 24 | #include <linux/cpu_pm.h> |
Rob Herring | be6a98d | 2012-10-12 12:45:34 -0500 | [diff] [blame] | 25 | #include <linux/init.h> |
| 26 | #include <linux/io.h> |
Rob Herring | be6a98d | 2012-10-12 12:45:34 -0500 | [diff] [blame] | 27 | #include <linux/time.h> |
| 28 | #include <linux/delay.h> |
| 29 | #include <linux/suspend.h> |
Daniel Lezcano | 60a66e3 | 2013-09-27 12:47:45 +0200 | [diff] [blame^] | 30 | #include <linux/platform_device.h> |
Rob Herring | be6a98d | 2012-10-12 12:45:34 -0500 | [diff] [blame] | 31 | #include <asm/cpuidle.h> |
| 32 | #include <asm/proc-fns.h> |
| 33 | #include <asm/smp_scu.h> |
| 34 | #include <asm/suspend.h> |
| 35 | #include <asm/cacheflush.h> |
| 36 | #include <asm/cp15.h> |
| 37 | |
| 38 | extern void highbank_set_cpu_jump(int cpu, void *jump_addr); |
Jingoo Han | 3e0c190 | 2013-08-09 16:09:15 +0900 | [diff] [blame] | 39 | extern void __iomem *scu_base_addr; |
Rob Herring | be6a98d | 2012-10-12 12:45:34 -0500 | [diff] [blame] | 40 | |
Rob Herring | be6a98d | 2012-10-12 12:45:34 -0500 | [diff] [blame] | 41 | static noinline void calxeda_idle_restore(void) |
| 42 | { |
| 43 | set_cr(get_cr() | CR_C); |
| 44 | set_auxcr(get_auxcr() | 0x40); |
| 45 | scu_power_mode(scu_base_addr, SCU_PM_NORMAL); |
| 46 | } |
| 47 | |
| 48 | static int calxeda_idle_finish(unsigned long val) |
| 49 | { |
| 50 | /* Already flushed cache, but do it again as the outer cache functions |
| 51 | * dirty the cache with spinlocks */ |
| 52 | flush_cache_all(); |
| 53 | |
| 54 | set_auxcr(get_auxcr() & ~0x40); |
| 55 | set_cr(get_cr() & ~CR_C); |
| 56 | |
| 57 | scu_power_mode(scu_base_addr, SCU_PM_DORMANT); |
| 58 | |
| 59 | cpu_do_idle(); |
| 60 | |
| 61 | /* Restore things if we didn't enter power-gating */ |
| 62 | calxeda_idle_restore(); |
| 63 | return 1; |
| 64 | } |
| 65 | |
| 66 | static int calxeda_pwrdown_idle(struct cpuidle_device *dev, |
| 67 | struct cpuidle_driver *drv, |
| 68 | int index) |
| 69 | { |
Rob Herring | 34a5eeb | 2013-02-26 16:16:53 -0600 | [diff] [blame] | 70 | cpu_pm_enter(); |
Rob Herring | be6a98d | 2012-10-12 12:45:34 -0500 | [diff] [blame] | 71 | highbank_set_cpu_jump(smp_processor_id(), cpu_resume); |
| 72 | cpu_suspend(0, calxeda_idle_finish); |
Rob Herring | 34a5eeb | 2013-02-26 16:16:53 -0600 | [diff] [blame] | 73 | cpu_pm_exit(); |
| 74 | |
Rob Herring | be6a98d | 2012-10-12 12:45:34 -0500 | [diff] [blame] | 75 | return index; |
| 76 | } |
| 77 | |
Rob Herring | be6a98d | 2012-10-12 12:45:34 -0500 | [diff] [blame] | 78 | static struct cpuidle_driver calxeda_idle_driver = { |
| 79 | .name = "calxeda_idle", |
Rob Herring | be6a98d | 2012-10-12 12:45:34 -0500 | [diff] [blame] | 80 | .states = { |
| 81 | ARM_CPUIDLE_WFI_STATE, |
| 82 | { |
| 83 | .name = "PG", |
| 84 | .desc = "Power Gate", |
| 85 | .flags = CPUIDLE_FLAG_TIME_VALID, |
| 86 | .exit_latency = 30, |
| 87 | .power_usage = 50, |
| 88 | .target_residency = 200, |
| 89 | .enter = calxeda_pwrdown_idle, |
| 90 | }, |
| 91 | }, |
| 92 | .state_count = 2, |
| 93 | }; |
| 94 | |
Daniel Lezcano | 60a66e3 | 2013-09-27 12:47:45 +0200 | [diff] [blame^] | 95 | static int __init calxeda_cpuidle_probe(struct platform_device *pdev) |
Rob Herring | be6a98d | 2012-10-12 12:45:34 -0500 | [diff] [blame] | 96 | { |
Daniel Lezcano | 0b210d9 | 2013-04-23 08:54:42 +0000 | [diff] [blame] | 97 | return cpuidle_register(&calxeda_idle_driver, NULL); |
Rob Herring | be6a98d | 2012-10-12 12:45:34 -0500 | [diff] [blame] | 98 | } |
Daniel Lezcano | 60a66e3 | 2013-09-27 12:47:45 +0200 | [diff] [blame^] | 99 | |
| 100 | static struct platform_driver calxeda_cpuidle_plat_driver = { |
| 101 | .driver = { |
| 102 | .name = "cpuidle-calxeda", |
| 103 | .owner = THIS_MODULE, |
| 104 | }, |
| 105 | .probe = calxeda_cpuidle_probe, |
| 106 | }; |
| 107 | |
| 108 | module_platform_driver(calxeda_cpuidle_plat_driver); |