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> |
Andrew Lunn | 9cfc94e | 2013-01-09 13:22:15 +0100 | [diff] [blame] | 17 | #include <linux/module.h> |
Rabeeh Khoury | e50b6be | 2009-03-24 16:10:15 +0200 | [diff] [blame] | 18 | #include <linux/init.h> |
| 19 | #include <linux/platform_device.h> |
| 20 | #include <linux/cpuidle.h> |
| 21 | #include <linux/io.h> |
Paul Gortmaker | dc28094 | 2011-07-31 16:17:29 -0400 | [diff] [blame] | 22 | #include <linux/export.h> |
Rabeeh Khoury | e50b6be | 2009-03-24 16:10:15 +0200 | [diff] [blame] | 23 | #include <asm/proc-fns.h> |
Robert Lee | b334648 | 2012-03-20 15:22:44 -0500 | [diff] [blame] | 24 | #include <asm/cpuidle.h> |
Rabeeh Khoury | e50b6be | 2009-03-24 16:10:15 +0200 | [diff] [blame] | 25 | |
| 26 | #define KIRKWOOD_MAX_STATES 2 |
| 27 | |
Andrew Lunn | 9cfc94e | 2013-01-09 13:22:15 +0100 | [diff] [blame] | 28 | static void __iomem *ddr_operation_base; |
| 29 | |
Rabeeh Khoury | e50b6be | 2009-03-24 16:10:15 +0200 | [diff] [blame] | 30 | /* Actual code that puts the SoC in different idle states */ |
| 31 | static int kirkwood_enter_idle(struct cpuidle_device *dev, |
Andrew Lunn | 9cfc94e | 2013-01-09 13:22:15 +0100 | [diff] [blame] | 32 | struct cpuidle_driver *drv, |
Deepthi Dharwar | e978aa7 | 2011-10-28 16:20:09 +0530 | [diff] [blame] | 33 | int index) |
Rabeeh Khoury | e50b6be | 2009-03-24 16:10:15 +0200 | [diff] [blame] | 34 | { |
Andrew Lunn | 9cfc94e | 2013-01-09 13:22:15 +0100 | [diff] [blame] | 35 | writel(0x7, ddr_operation_base); |
Robert Lee | b334648 | 2012-03-20 15:22:44 -0500 | [diff] [blame] | 36 | cpu_do_idle(); |
Deepthi Dharwar | e978aa7 | 2011-10-28 16:20:09 +0530 | [diff] [blame] | 37 | |
| 38 | return index; |
Rabeeh Khoury | e50b6be | 2009-03-24 16:10:15 +0200 | [diff] [blame] | 39 | } |
| 40 | |
Robert Lee | b334648 | 2012-03-20 15:22:44 -0500 | [diff] [blame] | 41 | static struct cpuidle_driver kirkwood_idle_driver = { |
| 42 | .name = "kirkwood_idle", |
| 43 | .owner = THIS_MODULE, |
Robert Lee | b334648 | 2012-03-20 15:22:44 -0500 | [diff] [blame] | 44 | .states[0] = ARM_CPUIDLE_WFI_STATE, |
| 45 | .states[1] = { |
| 46 | .enter = kirkwood_enter_idle, |
| 47 | .exit_latency = 10, |
| 48 | .target_residency = 100000, |
| 49 | .flags = CPUIDLE_FLAG_TIME_VALID, |
| 50 | .name = "DDR SR", |
| 51 | .desc = "WFI and DDR Self Refresh", |
| 52 | }, |
| 53 | .state_count = KIRKWOOD_MAX_STATES, |
| 54 | }; |
Robert Lee | b334648 | 2012-03-20 15:22:44 -0500 | [diff] [blame] | 55 | |
Rabeeh Khoury | e50b6be | 2009-03-24 16:10:15 +0200 | [diff] [blame] | 56 | /* Initialize CPU idle by registering the idle states */ |
Andrew Lunn | 9cfc94e | 2013-01-09 13:22:15 +0100 | [diff] [blame] | 57 | static int kirkwood_cpuidle_probe(struct platform_device *pdev) |
Rabeeh Khoury | e50b6be | 2009-03-24 16:10:15 +0200 | [diff] [blame] | 58 | { |
Andrew Lunn | 9cfc94e | 2013-01-09 13:22:15 +0100 | [diff] [blame] | 59 | struct resource *res; |
| 60 | |
| 61 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 62 | if (res == NULL) |
| 63 | return -EINVAL; |
| 64 | |
Silviu-Mihai Popescu | 488540b | 2013-03-22 14:10:42 +0100 | [diff] [blame] | 65 | ddr_operation_base = devm_ioremap_resource(&pdev->dev, res); |
| 66 | if (IS_ERR(ddr_operation_base)) |
| 67 | return PTR_ERR(ddr_operation_base); |
Rabeeh Khoury | e50b6be | 2009-03-24 16:10:15 +0200 | [diff] [blame] | 68 | |
Daniel Lezcano | 30dc72c | 2013-04-23 08:54:43 +0000 | [diff] [blame^] | 69 | return cpuidle_register(&kirkwood_idle_driver, NULL); |
Rabeeh Khoury | e50b6be | 2009-03-24 16:10:15 +0200 | [diff] [blame] | 70 | } |
| 71 | |
Andrew Lunn | 9cfc94e | 2013-01-09 13:22:15 +0100 | [diff] [blame] | 72 | int kirkwood_cpuidle_remove(struct platform_device *pdev) |
| 73 | { |
Daniel Lezcano | 30dc72c | 2013-04-23 08:54:43 +0000 | [diff] [blame^] | 74 | cpuidle_unregister(&kirkwood_idle_driver); |
Andrew Lunn | 9cfc94e | 2013-01-09 13:22:15 +0100 | [diff] [blame] | 75 | return 0; |
| 76 | } |
| 77 | |
| 78 | static struct platform_driver kirkwood_cpuidle_driver = { |
| 79 | .probe = kirkwood_cpuidle_probe, |
| 80 | .remove = kirkwood_cpuidle_remove, |
| 81 | .driver = { |
| 82 | .name = "kirkwood_cpuidle", |
| 83 | .owner = THIS_MODULE, |
| 84 | }, |
| 85 | }; |
| 86 | |
| 87 | module_platform_driver(kirkwood_cpuidle_driver); |
| 88 | |
| 89 | MODULE_AUTHOR("Andrew Lunn <andrew@lunn.ch>"); |
| 90 | MODULE_DESCRIPTION("Kirkwood cpu idle driver"); |
| 91 | MODULE_LICENSE("GPL v2"); |
| 92 | MODULE_ALIAS("platform:kirkwood-cpuidle"); |