Commit | Line | Data |
---|---|---|
e50b6bef RK |
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> | |
9cfc94eb | 17 | #include <linux/module.h> |
e50b6bef RK |
18 | #include <linux/init.h> |
19 | #include <linux/platform_device.h> | |
20 | #include <linux/cpuidle.h> | |
21 | #include <linux/io.h> | |
dc28094b | 22 | #include <linux/export.h> |
e50b6bef | 23 | #include <asm/proc-fns.h> |
b334648d | 24 | #include <asm/cpuidle.h> |
e50b6bef RK |
25 | |
26 | #define KIRKWOOD_MAX_STATES 2 | |
27 | ||
9cfc94eb AL |
28 | static void __iomem *ddr_operation_base; |
29 | ||
e50b6bef RK |
30 | /* Actual code that puts the SoC in different idle states */ |
31 | static int kirkwood_enter_idle(struct cpuidle_device *dev, | |
9cfc94eb | 32 | struct cpuidle_driver *drv, |
e978aa7d | 33 | int index) |
e50b6bef | 34 | { |
9cfc94eb | 35 | writel(0x7, ddr_operation_base); |
b334648d | 36 | cpu_do_idle(); |
e978aa7d DD |
37 | |
38 | return index; | |
e50b6bef RK |
39 | } |
40 | ||
b334648d RL |
41 | static struct cpuidle_driver kirkwood_idle_driver = { |
42 | .name = "kirkwood_idle", | |
43 | .owner = THIS_MODULE, | |
b334648d RL |
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 | }; | |
9cfc94eb | 55 | static struct cpuidle_device *device; |
b334648d RL |
56 | |
57 | static DEFINE_PER_CPU(struct cpuidle_device, kirkwood_cpuidle_device); | |
58 | ||
e50b6bef | 59 | /* Initialize CPU idle by registering the idle states */ |
9cfc94eb | 60 | static int kirkwood_cpuidle_probe(struct platform_device *pdev) |
e50b6bef | 61 | { |
9cfc94eb AL |
62 | struct resource *res; |
63 | ||
64 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | |
65 | if (res == NULL) | |
66 | return -EINVAL; | |
67 | ||
488540bf SMP |
68 | ddr_operation_base = devm_ioremap_resource(&pdev->dev, res); |
69 | if (IS_ERR(ddr_operation_base)) | |
70 | return PTR_ERR(ddr_operation_base); | |
e50b6bef RK |
71 | |
72 | device = &per_cpu(kirkwood_cpuidle_device, smp_processor_id()); | |
73 | device->state_count = KIRKWOOD_MAX_STATES; | |
e50b6bef | 74 | |
46bcfad7 | 75 | cpuidle_register_driver(&kirkwood_idle_driver); |
e50b6bef | 76 | if (cpuidle_register_device(device)) { |
98adf932 | 77 | pr_err("kirkwood_init_cpuidle: Failed registering\n"); |
e50b6bef RK |
78 | return -EIO; |
79 | } | |
80 | return 0; | |
81 | } | |
82 | ||
9cfc94eb AL |
83 | int kirkwood_cpuidle_remove(struct platform_device *pdev) |
84 | { | |
85 | cpuidle_unregister_device(device); | |
86 | cpuidle_unregister_driver(&kirkwood_idle_driver); | |
87 | ||
88 | return 0; | |
89 | } | |
90 | ||
91 | static struct platform_driver kirkwood_cpuidle_driver = { | |
92 | .probe = kirkwood_cpuidle_probe, | |
93 | .remove = kirkwood_cpuidle_remove, | |
94 | .driver = { | |
95 | .name = "kirkwood_cpuidle", | |
96 | .owner = THIS_MODULE, | |
97 | }, | |
98 | }; | |
99 | ||
100 | module_platform_driver(kirkwood_cpuidle_driver); | |
101 | ||
102 | MODULE_AUTHOR("Andrew Lunn <andrew@lunn.ch>"); | |
103 | MODULE_DESCRIPTION("Kirkwood cpu idle driver"); | |
104 | MODULE_LICENSE("GPL v2"); | |
105 | MODULE_ALIAS("platform:kirkwood-cpuidle"); |