xref: /linux/drivers/cpuidle/cpuidle-kirkwood.c (revision 9cfc94eb0f4843af5d1141a37d7b7ca5d3b27220)
1*9cfc94ebSAndrew Lunn /*
2*9cfc94ebSAndrew Lunn  * arch/arm/mach-kirkwood/cpuidle.c
3*9cfc94ebSAndrew Lunn  *
4*9cfc94ebSAndrew Lunn  * CPU idle Marvell Kirkwood SoCs
5*9cfc94ebSAndrew Lunn  *
6*9cfc94ebSAndrew Lunn  * This file is licensed under the terms of the GNU General Public
7*9cfc94ebSAndrew Lunn  * License version 2.  This program is licensed "as is" without any
8*9cfc94ebSAndrew Lunn  * warranty of any kind, whether express or implied.
9*9cfc94ebSAndrew Lunn  *
10*9cfc94ebSAndrew Lunn  * The cpu idle uses wait-for-interrupt and DDR self refresh in order
11*9cfc94ebSAndrew Lunn  * to implement two idle states -
12*9cfc94ebSAndrew Lunn  * #1 wait-for-interrupt
13*9cfc94ebSAndrew Lunn  * #2 wait-for-interrupt and DDR self refresh
14*9cfc94ebSAndrew Lunn  */
15*9cfc94ebSAndrew Lunn 
16*9cfc94ebSAndrew Lunn #include <linux/kernel.h>
17*9cfc94ebSAndrew Lunn #include <linux/module.h>
18*9cfc94ebSAndrew Lunn #include <linux/init.h>
19*9cfc94ebSAndrew Lunn #include <linux/platform_device.h>
20*9cfc94ebSAndrew Lunn #include <linux/cpuidle.h>
21*9cfc94ebSAndrew Lunn #include <linux/io.h>
22*9cfc94ebSAndrew Lunn #include <linux/export.h>
23*9cfc94ebSAndrew Lunn #include <asm/proc-fns.h>
24*9cfc94ebSAndrew Lunn #include <asm/cpuidle.h>
25*9cfc94ebSAndrew Lunn 
26*9cfc94ebSAndrew Lunn #define KIRKWOOD_MAX_STATES	2
27*9cfc94ebSAndrew Lunn 
28*9cfc94ebSAndrew Lunn static void __iomem *ddr_operation_base;
29*9cfc94ebSAndrew Lunn 
30*9cfc94ebSAndrew Lunn /* Actual code that puts the SoC in different idle states */
31*9cfc94ebSAndrew Lunn static int kirkwood_enter_idle(struct cpuidle_device *dev,
32*9cfc94ebSAndrew Lunn 			       struct cpuidle_driver *drv,
33*9cfc94ebSAndrew Lunn 			       int index)
34*9cfc94ebSAndrew Lunn {
35*9cfc94ebSAndrew Lunn 	writel(0x7, ddr_operation_base);
36*9cfc94ebSAndrew Lunn 	cpu_do_idle();
37*9cfc94ebSAndrew Lunn 
38*9cfc94ebSAndrew Lunn 	return index;
39*9cfc94ebSAndrew Lunn }
40*9cfc94ebSAndrew Lunn 
41*9cfc94ebSAndrew Lunn static struct cpuidle_driver kirkwood_idle_driver = {
42*9cfc94ebSAndrew Lunn 	.name			= "kirkwood_idle",
43*9cfc94ebSAndrew Lunn 	.owner			= THIS_MODULE,
44*9cfc94ebSAndrew Lunn 	.en_core_tk_irqen	= 1,
45*9cfc94ebSAndrew Lunn 	.states[0]		= ARM_CPUIDLE_WFI_STATE,
46*9cfc94ebSAndrew Lunn 	.states[1]		= {
47*9cfc94ebSAndrew Lunn 		.enter			= kirkwood_enter_idle,
48*9cfc94ebSAndrew Lunn 		.exit_latency		= 10,
49*9cfc94ebSAndrew Lunn 		.target_residency	= 100000,
50*9cfc94ebSAndrew Lunn 		.flags			= CPUIDLE_FLAG_TIME_VALID,
51*9cfc94ebSAndrew Lunn 		.name			= "DDR SR",
52*9cfc94ebSAndrew Lunn 		.desc			= "WFI and DDR Self Refresh",
53*9cfc94ebSAndrew Lunn 	},
54*9cfc94ebSAndrew Lunn 	.state_count = KIRKWOOD_MAX_STATES,
55*9cfc94ebSAndrew Lunn };
56*9cfc94ebSAndrew Lunn static struct cpuidle_device *device;
57*9cfc94ebSAndrew Lunn 
58*9cfc94ebSAndrew Lunn static DEFINE_PER_CPU(struct cpuidle_device, kirkwood_cpuidle_device);
59*9cfc94ebSAndrew Lunn 
60*9cfc94ebSAndrew Lunn /* Initialize CPU idle by registering the idle states */
61*9cfc94ebSAndrew Lunn static int kirkwood_cpuidle_probe(struct platform_device *pdev)
62*9cfc94ebSAndrew Lunn {
63*9cfc94ebSAndrew Lunn 	struct resource *res;
64*9cfc94ebSAndrew Lunn 
65*9cfc94ebSAndrew Lunn 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
66*9cfc94ebSAndrew Lunn 	if (res == NULL)
67*9cfc94ebSAndrew Lunn 		return -EINVAL;
68*9cfc94ebSAndrew Lunn 
69*9cfc94ebSAndrew Lunn 	ddr_operation_base = devm_request_and_ioremap(&pdev->dev, res);
70*9cfc94ebSAndrew Lunn 	if (!ddr_operation_base)
71*9cfc94ebSAndrew Lunn 		return -EADDRNOTAVAIL;
72*9cfc94ebSAndrew Lunn 
73*9cfc94ebSAndrew Lunn 	device = &per_cpu(kirkwood_cpuidle_device, smp_processor_id());
74*9cfc94ebSAndrew Lunn 	device->state_count = KIRKWOOD_MAX_STATES;
75*9cfc94ebSAndrew Lunn 
76*9cfc94ebSAndrew Lunn 	cpuidle_register_driver(&kirkwood_idle_driver);
77*9cfc94ebSAndrew Lunn 	if (cpuidle_register_device(device)) {
78*9cfc94ebSAndrew Lunn 		pr_err("kirkwood_init_cpuidle: Failed registering\n");
79*9cfc94ebSAndrew Lunn 		return -EIO;
80*9cfc94ebSAndrew Lunn 	}
81*9cfc94ebSAndrew Lunn 	return 0;
82*9cfc94ebSAndrew Lunn }
83*9cfc94ebSAndrew Lunn 
84*9cfc94ebSAndrew Lunn int kirkwood_cpuidle_remove(struct platform_device *pdev)
85*9cfc94ebSAndrew Lunn {
86*9cfc94ebSAndrew Lunn 	cpuidle_unregister_device(device);
87*9cfc94ebSAndrew Lunn 	cpuidle_unregister_driver(&kirkwood_idle_driver);
88*9cfc94ebSAndrew Lunn 
89*9cfc94ebSAndrew Lunn 	return 0;
90*9cfc94ebSAndrew Lunn }
91*9cfc94ebSAndrew Lunn 
92*9cfc94ebSAndrew Lunn static struct platform_driver kirkwood_cpuidle_driver = {
93*9cfc94ebSAndrew Lunn 	.probe = kirkwood_cpuidle_probe,
94*9cfc94ebSAndrew Lunn 	.remove = kirkwood_cpuidle_remove,
95*9cfc94ebSAndrew Lunn 	.driver = {
96*9cfc94ebSAndrew Lunn 		   .name = "kirkwood_cpuidle",
97*9cfc94ebSAndrew Lunn 		   .owner = THIS_MODULE,
98*9cfc94ebSAndrew Lunn 		   },
99*9cfc94ebSAndrew Lunn };
100*9cfc94ebSAndrew Lunn 
101*9cfc94ebSAndrew Lunn module_platform_driver(kirkwood_cpuidle_driver);
102*9cfc94ebSAndrew Lunn 
103*9cfc94ebSAndrew Lunn MODULE_AUTHOR("Andrew Lunn <andrew@lunn.ch>");
104*9cfc94ebSAndrew Lunn MODULE_DESCRIPTION("Kirkwood cpu idle driver");
105*9cfc94ebSAndrew Lunn MODULE_LICENSE("GPL v2");
106*9cfc94ebSAndrew Lunn MODULE_ALIAS("platform:kirkwood-cpuidle");
107