Rabeeh Khoury | e50b6be | 2009-03-24 16:10:15 +0200 | [diff] [blame] | 1 | /* |
Rabeeh Khoury | e50b6be | 2009-03-24 16:10:15 +0200 | [diff] [blame] | 2 | * CPU idle Marvell Kirkwood SoCs |
| 3 | * |
| 4 | * This file is licensed under the terms of the GNU General Public |
| 5 | * License version 2. This program is licensed "as is" without any |
| 6 | * warranty of any kind, whether express or implied. |
| 7 | * |
| 8 | * The cpu idle uses wait-for-interrupt and DDR self refresh in order |
| 9 | * to implement two idle states - |
| 10 | * #1 wait-for-interrupt |
| 11 | * #2 wait-for-interrupt and DDR self refresh |
Daniel Lezcano | a8e39c3 | 2013-04-26 11:05:44 +0000 | [diff] [blame] | 12 | * |
| 13 | * Maintainer: Jason Cooper <jason@lakedaemon.net> |
| 14 | * Maintainer: Andrew Lunn <andrew@lunn.ch> |
Rabeeh Khoury | e50b6be | 2009-03-24 16:10:15 +0200 | [diff] [blame] | 15 | */ |
| 16 | |
| 17 | #include <linux/kernel.h> |
Andrew Lunn | 9cfc94e | 2013-01-09 13:22:15 +0100 | [diff] [blame] | 18 | #include <linux/module.h> |
Rabeeh Khoury | e50b6be | 2009-03-24 16:10:15 +0200 | [diff] [blame] | 19 | #include <linux/init.h> |
| 20 | #include <linux/platform_device.h> |
| 21 | #include <linux/cpuidle.h> |
| 22 | #include <linux/io.h> |
Paul Gortmaker | dc28094 | 2011-07-31 16:17:29 -0400 | [diff] [blame] | 23 | #include <linux/export.h> |
Rabeeh Khoury | e50b6be | 2009-03-24 16:10:15 +0200 | [diff] [blame] | 24 | #include <asm/proc-fns.h> |
Robert Lee | b334648 | 2012-03-20 15:22:44 -0500 | [diff] [blame] | 25 | #include <asm/cpuidle.h> |
Rabeeh Khoury | e50b6be | 2009-03-24 16:10:15 +0200 | [diff] [blame] | 26 | |
| 27 | #define KIRKWOOD_MAX_STATES 2 |
| 28 | |
Andrew Lunn | 9cfc94e | 2013-01-09 13:22:15 +0100 | [diff] [blame] | 29 | static void __iomem *ddr_operation_base; |
| 30 | |
Rabeeh Khoury | e50b6be | 2009-03-24 16:10:15 +0200 | [diff] [blame] | 31 | /* Actual code that puts the SoC in different idle states */ |
| 32 | static int kirkwood_enter_idle(struct cpuidle_device *dev, |
Andrew Lunn | 9cfc94e | 2013-01-09 13:22:15 +0100 | [diff] [blame] | 33 | struct cpuidle_driver *drv, |
Deepthi Dharwar | e978aa7 | 2011-10-28 16:20:09 +0530 | [diff] [blame] | 34 | int index) |
Rabeeh Khoury | e50b6be | 2009-03-24 16:10:15 +0200 | [diff] [blame] | 35 | { |
Andrew Lunn | 9cfc94e | 2013-01-09 13:22:15 +0100 | [diff] [blame] | 36 | writel(0x7, ddr_operation_base); |
Robert Lee | b334648 | 2012-03-20 15:22:44 -0500 | [diff] [blame] | 37 | cpu_do_idle(); |
Deepthi Dharwar | e978aa7 | 2011-10-28 16:20:09 +0530 | [diff] [blame] | 38 | |
| 39 | return index; |
Rabeeh Khoury | e50b6be | 2009-03-24 16:10:15 +0200 | [diff] [blame] | 40 | } |
| 41 | |
Robert Lee | b334648 | 2012-03-20 15:22:44 -0500 | [diff] [blame] | 42 | static struct cpuidle_driver kirkwood_idle_driver = { |
| 43 | .name = "kirkwood_idle", |
| 44 | .owner = THIS_MODULE, |
Robert Lee | b334648 | 2012-03-20 15:22:44 -0500 | [diff] [blame] | 45 | .states[0] = ARM_CPUIDLE_WFI_STATE, |
| 46 | .states[1] = { |
| 47 | .enter = kirkwood_enter_idle, |
| 48 | .exit_latency = 10, |
| 49 | .target_residency = 100000, |
| 50 | .flags = CPUIDLE_FLAG_TIME_VALID, |
| 51 | .name = "DDR SR", |
| 52 | .desc = "WFI and DDR Self Refresh", |
| 53 | }, |
| 54 | .state_count = KIRKWOOD_MAX_STATES, |
| 55 | }; |
Robert Lee | b334648 | 2012-03-20 15:22:44 -0500 | [diff] [blame] | 56 | |
Rabeeh Khoury | e50b6be | 2009-03-24 16:10:15 +0200 | [diff] [blame] | 57 | /* Initialize CPU idle by registering the idle states */ |
Andrew Lunn | 9cfc94e | 2013-01-09 13:22:15 +0100 | [diff] [blame] | 58 | static int kirkwood_cpuidle_probe(struct platform_device *pdev) |
Rabeeh Khoury | e50b6be | 2009-03-24 16:10:15 +0200 | [diff] [blame] | 59 | { |
Andrew Lunn | 9cfc94e | 2013-01-09 13:22:15 +0100 | [diff] [blame] | 60 | struct resource *res; |
| 61 | |
| 62 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
Silviu-Mihai Popescu | 488540b | 2013-03-22 14:10:42 +0100 | [diff] [blame] | 63 | ddr_operation_base = devm_ioremap_resource(&pdev->dev, res); |
| 64 | if (IS_ERR(ddr_operation_base)) |
| 65 | return PTR_ERR(ddr_operation_base); |
Rabeeh Khoury | e50b6be | 2009-03-24 16:10:15 +0200 | [diff] [blame] | 66 | |
Daniel Lezcano | 30dc72c | 2013-04-23 08:54:43 +0000 | [diff] [blame] | 67 | return cpuidle_register(&kirkwood_idle_driver, NULL); |
Rabeeh Khoury | e50b6be | 2009-03-24 16:10:15 +0200 | [diff] [blame] | 68 | } |
| 69 | |
Jingoo Han | 75d6137 | 2013-08-09 16:11:34 +0900 | [diff] [blame] | 70 | static int kirkwood_cpuidle_remove(struct platform_device *pdev) |
Andrew Lunn | 9cfc94e | 2013-01-09 13:22:15 +0100 | [diff] [blame] | 71 | { |
Daniel Lezcano | 30dc72c | 2013-04-23 08:54:43 +0000 | [diff] [blame] | 72 | cpuidle_unregister(&kirkwood_idle_driver); |
Andrew Lunn | 9cfc94e | 2013-01-09 13:22:15 +0100 | [diff] [blame] | 73 | return 0; |
| 74 | } |
| 75 | |
| 76 | static struct platform_driver kirkwood_cpuidle_driver = { |
| 77 | .probe = kirkwood_cpuidle_probe, |
| 78 | .remove = kirkwood_cpuidle_remove, |
| 79 | .driver = { |
| 80 | .name = "kirkwood_cpuidle", |
| 81 | .owner = THIS_MODULE, |
| 82 | }, |
| 83 | }; |
| 84 | |
| 85 | module_platform_driver(kirkwood_cpuidle_driver); |
| 86 | |
| 87 | MODULE_AUTHOR("Andrew Lunn <andrew@lunn.ch>"); |
| 88 | MODULE_DESCRIPTION("Kirkwood cpu idle driver"); |
| 89 | MODULE_LICENSE("GPL v2"); |
| 90 | MODULE_ALIAS("platform:kirkwood-cpuidle"); |