Rabeeh Khoury | e50b6be | 2009-03-24 16:10:15 +0200 | [diff] [blame] | 1 | /* |
| 2 | * arch/arm/mach-kirkwood/cpuidle.c |
| 3 | * |
| 4 | * CPU idle Marvell Kirkwood SoCs |
| 5 | * |
| 6 | * This file is licensed under the terms of the GNU General Public |
| 7 | * License version 2. This program is licensed "as is" without any |
| 8 | * warranty of any kind, whether express or implied. |
| 9 | * |
| 10 | * The cpu idle uses wait-for-interrupt and DDR self refresh in order |
| 11 | * to implement two idle states - |
| 12 | * #1 wait-for-interrupt |
| 13 | * #2 wait-for-interrupt and DDR self refresh |
| 14 | */ |
| 15 | |
| 16 | #include <linux/kernel.h> |
| 17 | #include <linux/init.h> |
| 18 | #include <linux/platform_device.h> |
| 19 | #include <linux/cpuidle.h> |
| 20 | #include <linux/io.h> |
Paul Gortmaker | dc28094 | 2011-07-31 16:17:29 -0400 | [diff] [blame] | 21 | #include <linux/export.h> |
Rabeeh Khoury | e50b6be | 2009-03-24 16:10:15 +0200 | [diff] [blame] | 22 | #include <asm/proc-fns.h> |
Robert Lee | b334648 | 2012-03-20 15:22:44 -0500 | [diff] [blame^] | 23 | #include <asm/cpuidle.h> |
Rabeeh Khoury | e50b6be | 2009-03-24 16:10:15 +0200 | [diff] [blame] | 24 | #include <mach/kirkwood.h> |
| 25 | |
| 26 | #define KIRKWOOD_MAX_STATES 2 |
| 27 | |
Rabeeh Khoury | e50b6be | 2009-03-24 16:10:15 +0200 | [diff] [blame] | 28 | /* Actual code that puts the SoC in different idle states */ |
| 29 | static int kirkwood_enter_idle(struct cpuidle_device *dev, |
Deepthi Dharwar | 46bcfad | 2011-10-28 16:20:42 +0530 | [diff] [blame] | 30 | struct cpuidle_driver *drv, |
Deepthi Dharwar | e978aa7 | 2011-10-28 16:20:09 +0530 | [diff] [blame] | 31 | int index) |
Rabeeh Khoury | e50b6be | 2009-03-24 16:10:15 +0200 | [diff] [blame] | 32 | { |
Robert Lee | b334648 | 2012-03-20 15:22:44 -0500 | [diff] [blame^] | 33 | writel(0x7, DDR_OPERATION_BASE); |
| 34 | cpu_do_idle(); |
Deepthi Dharwar | e978aa7 | 2011-10-28 16:20:09 +0530 | [diff] [blame] | 35 | |
| 36 | return index; |
Rabeeh Khoury | e50b6be | 2009-03-24 16:10:15 +0200 | [diff] [blame] | 37 | } |
| 38 | |
Robert Lee | b334648 | 2012-03-20 15:22:44 -0500 | [diff] [blame^] | 39 | static struct cpuidle_driver kirkwood_idle_driver = { |
| 40 | .name = "kirkwood_idle", |
| 41 | .owner = THIS_MODULE, |
| 42 | .en_core_tk_irqen = 1, |
| 43 | .states[0] = ARM_CPUIDLE_WFI_STATE, |
| 44 | .states[1] = { |
| 45 | .enter = kirkwood_enter_idle, |
| 46 | .exit_latency = 10, |
| 47 | .target_residency = 100000, |
| 48 | .flags = CPUIDLE_FLAG_TIME_VALID, |
| 49 | .name = "DDR SR", |
| 50 | .desc = "WFI and DDR Self Refresh", |
| 51 | }, |
| 52 | .state_count = KIRKWOOD_MAX_STATES, |
| 53 | }; |
| 54 | |
| 55 | static DEFINE_PER_CPU(struct cpuidle_device, kirkwood_cpuidle_device); |
| 56 | |
Rabeeh Khoury | e50b6be | 2009-03-24 16:10:15 +0200 | [diff] [blame] | 57 | /* Initialize CPU idle by registering the idle states */ |
| 58 | static int kirkwood_init_cpuidle(void) |
| 59 | { |
| 60 | struct cpuidle_device *device; |
Rabeeh Khoury | e50b6be | 2009-03-24 16:10:15 +0200 | [diff] [blame] | 61 | |
| 62 | device = &per_cpu(kirkwood_cpuidle_device, smp_processor_id()); |
| 63 | device->state_count = KIRKWOOD_MAX_STATES; |
Rabeeh Khoury | e50b6be | 2009-03-24 16:10:15 +0200 | [diff] [blame] | 64 | |
Deepthi Dharwar | 46bcfad | 2011-10-28 16:20:42 +0530 | [diff] [blame] | 65 | cpuidle_register_driver(&kirkwood_idle_driver); |
Rabeeh Khoury | e50b6be | 2009-03-24 16:10:15 +0200 | [diff] [blame] | 66 | if (cpuidle_register_device(device)) { |
| 67 | printk(KERN_ERR "kirkwood_init_cpuidle: Failed registering\n"); |
| 68 | return -EIO; |
| 69 | } |
| 70 | return 0; |
| 71 | } |
| 72 | |
| 73 | device_initcall(kirkwood_init_cpuidle); |