blob: cea0a6c4b1db007c09a9819b68cd50212422b11e [file] [log] [blame]
Rabeeh Khourye50b6be2009-03-24 16:10:15 +02001/*
Rabeeh Khourye50b6be2009-03-24 16:10:15 +02002 * 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 Lezcanoa8e39c32013-04-26 11:05:44 +000012 *
13 * Maintainer: Jason Cooper <jason@lakedaemon.net>
14 * Maintainer: Andrew Lunn <andrew@lunn.ch>
Rabeeh Khourye50b6be2009-03-24 16:10:15 +020015 */
16
17#include <linux/kernel.h>
Andrew Lunn9cfc94e2013-01-09 13:22:15 +010018#include <linux/module.h>
Rabeeh Khourye50b6be2009-03-24 16:10:15 +020019#include <linux/init.h>
20#include <linux/platform_device.h>
21#include <linux/cpuidle.h>
22#include <linux/io.h>
Paul Gortmakerdc280942011-07-31 16:17:29 -040023#include <linux/export.h>
Rabeeh Khourye50b6be2009-03-24 16:10:15 +020024#include <asm/proc-fns.h>
Robert Leeb3346482012-03-20 15:22:44 -050025#include <asm/cpuidle.h>
Rabeeh Khourye50b6be2009-03-24 16:10:15 +020026
27#define KIRKWOOD_MAX_STATES 2
28
Andrew Lunn9cfc94e2013-01-09 13:22:15 +010029static void __iomem *ddr_operation_base;
30
Rabeeh Khourye50b6be2009-03-24 16:10:15 +020031/* Actual code that puts the SoC in different idle states */
32static int kirkwood_enter_idle(struct cpuidle_device *dev,
Andrew Lunn9cfc94e2013-01-09 13:22:15 +010033 struct cpuidle_driver *drv,
Deepthi Dharware978aa72011-10-28 16:20:09 +053034 int index)
Rabeeh Khourye50b6be2009-03-24 16:10:15 +020035{
Andrew Lunn9cfc94e2013-01-09 13:22:15 +010036 writel(0x7, ddr_operation_base);
Robert Leeb3346482012-03-20 15:22:44 -050037 cpu_do_idle();
Deepthi Dharware978aa72011-10-28 16:20:09 +053038
39 return index;
Rabeeh Khourye50b6be2009-03-24 16:10:15 +020040}
41
Robert Leeb3346482012-03-20 15:22:44 -050042static struct cpuidle_driver kirkwood_idle_driver = {
43 .name = "kirkwood_idle",
44 .owner = THIS_MODULE,
Robert Leeb3346482012-03-20 15:22:44 -050045 .states[0] = ARM_CPUIDLE_WFI_STATE,
46 .states[1] = {
47 .enter = kirkwood_enter_idle,
48 .exit_latency = 10,
49 .target_residency = 100000,
Robert Leeb3346482012-03-20 15:22:44 -050050 .name = "DDR SR",
51 .desc = "WFI and DDR Self Refresh",
52 },
53 .state_count = KIRKWOOD_MAX_STATES,
54};
Robert Leeb3346482012-03-20 15:22:44 -050055
Rabeeh Khourye50b6be2009-03-24 16:10:15 +020056/* Initialize CPU idle by registering the idle states */
Andrew Lunn9cfc94e2013-01-09 13:22:15 +010057static int kirkwood_cpuidle_probe(struct platform_device *pdev)
Rabeeh Khourye50b6be2009-03-24 16:10:15 +020058{
Andrew Lunn9cfc94e2013-01-09 13:22:15 +010059 struct resource *res;
60
61 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
Silviu-Mihai Popescu488540b2013-03-22 14:10:42 +010062 ddr_operation_base = devm_ioremap_resource(&pdev->dev, res);
63 if (IS_ERR(ddr_operation_base))
64 return PTR_ERR(ddr_operation_base);
Rabeeh Khourye50b6be2009-03-24 16:10:15 +020065
Daniel Lezcano30dc72c2013-04-23 08:54:43 +000066 return cpuidle_register(&kirkwood_idle_driver, NULL);
Rabeeh Khourye50b6be2009-03-24 16:10:15 +020067}
68
Jingoo Han75d61372013-08-09 16:11:34 +090069static int kirkwood_cpuidle_remove(struct platform_device *pdev)
Andrew Lunn9cfc94e2013-01-09 13:22:15 +010070{
Daniel Lezcano30dc72c2013-04-23 08:54:43 +000071 cpuidle_unregister(&kirkwood_idle_driver);
Andrew Lunn9cfc94e2013-01-09 13:22:15 +010072 return 0;
73}
74
75static struct platform_driver kirkwood_cpuidle_driver = {
76 .probe = kirkwood_cpuidle_probe,
77 .remove = kirkwood_cpuidle_remove,
78 .driver = {
79 .name = "kirkwood_cpuidle",
Andrew Lunn9cfc94e2013-01-09 13:22:15 +010080 },
81};
82
83module_platform_driver(kirkwood_cpuidle_driver);
84
85MODULE_AUTHOR("Andrew Lunn <andrew@lunn.ch>");
86MODULE_DESCRIPTION("Kirkwood cpu idle driver");
87MODULE_LICENSE("GPL v2");
88MODULE_ALIAS("platform:kirkwood-cpuidle");