1
2
3
4
5
6
7
8
9
10
11
12#include <linux/cpuidle.h>
13#include <linux/cpu_pm.h>
14#include <linux/slab.h>
15#include <linux/of.h>
16
17#include <asm/cpu.h>
18#include <asm/cputype.h>
19#include <asm/cpuidle.h>
20#include <asm/mcpm.h>
21#include <asm/smp_plat.h>
22#include <asm/suspend.h>
23
24#include "dt_idle_states.h"
25
26static int bl_enter_powerdown(struct cpuidle_device *dev,
27 struct cpuidle_driver *drv, int idx);
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59static struct cpuidle_driver bl_idle_little_driver = {
60 .name = "little_idle",
61 .owner = THIS_MODULE,
62 .states[0] = ARM_CPUIDLE_WFI_STATE,
63 .states[1] = {
64 .enter = bl_enter_powerdown,
65 .exit_latency = 700,
66 .target_residency = 2500,
67 .flags = CPUIDLE_FLAG_TIMER_STOP,
68 .name = "C1",
69 .desc = "ARM little-cluster power down",
70 },
71 .state_count = 2,
72};
73
74static const struct of_device_id bl_idle_state_match[] __initconst = {
75 { .compatible = "arm,idle-state",
76 .data = bl_enter_powerdown },
77 { },
78};
79
80static struct cpuidle_driver bl_idle_big_driver = {
81 .name = "big_idle",
82 .owner = THIS_MODULE,
83 .states[0] = ARM_CPUIDLE_WFI_STATE,
84 .states[1] = {
85 .enter = bl_enter_powerdown,
86 .exit_latency = 500,
87 .target_residency = 2000,
88 .flags = CPUIDLE_FLAG_TIMER_STOP,
89 .name = "C1",
90 .desc = "ARM big-cluster power down",
91 },
92 .state_count = 2,
93};
94
95
96
97
98
99
100static int notrace bl_powerdown_finisher(unsigned long arg)
101{
102
103 unsigned int mpidr = read_cpuid_mpidr();
104 unsigned int cluster = MPIDR_AFFINITY_LEVEL(mpidr, 1);
105 unsigned int cpu = MPIDR_AFFINITY_LEVEL(mpidr, 0);
106
107 mcpm_set_entry_vector(cpu, cluster, cpu_resume);
108 mcpm_cpu_suspend();
109
110
111 return 1;
112}
113
114
115
116
117
118
119
120
121
122
123static int bl_enter_powerdown(struct cpuidle_device *dev,
124 struct cpuidle_driver *drv, int idx)
125{
126 cpu_pm_enter();
127
128 cpu_suspend(0, bl_powerdown_finisher);
129
130
131 mcpm_cpu_powered_up();
132
133 cpu_pm_exit();
134
135 return idx;
136}
137
138static int __init bl_idle_driver_init(struct cpuidle_driver *drv, int part_id)
139{
140 struct cpumask *cpumask;
141 int cpu;
142
143 cpumask = kzalloc(cpumask_size(), GFP_KERNEL);
144 if (!cpumask)
145 return -ENOMEM;
146
147 for_each_possible_cpu(cpu)
148 if (smp_cpuid_part(cpu) == part_id)
149 cpumask_set_cpu(cpu, cpumask);
150
151 drv->cpumask = cpumask;
152
153 return 0;
154}
155
156static const struct of_device_id compatible_machine_match[] = {
157 { .compatible = "arm,vexpress,v2p-ca15_a7" },
158 { .compatible = "samsung,exynos5420" },
159 { .compatible = "samsung,exynos5800" },
160 {},
161};
162
163static int __init bl_idle_init(void)
164{
165 int ret;
166 struct device_node *root = of_find_node_by_path("/");
167 const struct of_device_id *match_id;
168
169 if (!root)
170 return -ENODEV;
171
172
173
174
175 match_id = of_match_node(compatible_machine_match, root);
176
177 of_node_put(root);
178
179 if (!match_id)
180 return -ENODEV;
181
182 if (!mcpm_is_available())
183 return -EUNATCH;
184
185
186
187
188
189
190
191 ret = bl_idle_driver_init(&bl_idle_little_driver,
192 ARM_CPU_PART_CORTEX_A7);
193 if (ret)
194 return ret;
195
196 ret = bl_idle_driver_init(&bl_idle_big_driver, ARM_CPU_PART_CORTEX_A15);
197 if (ret)
198 goto out_uninit_little;
199
200
201 ret = dt_init_idle_driver(&bl_idle_big_driver, bl_idle_state_match, 1);
202 if (ret < 0)
203 goto out_uninit_big;
204
205
206 ret = dt_init_idle_driver(&bl_idle_little_driver,
207 bl_idle_state_match, 1);
208 if (ret < 0)
209 goto out_uninit_big;
210
211 ret = cpuidle_register(&bl_idle_little_driver, NULL);
212 if (ret)
213 goto out_uninit_big;
214
215 ret = cpuidle_register(&bl_idle_big_driver, NULL);
216 if (ret)
217 goto out_unregister_little;
218
219 return 0;
220
221out_unregister_little:
222 cpuidle_unregister(&bl_idle_little_driver);
223out_uninit_big:
224 kfree(bl_idle_big_driver.cpumask);
225out_uninit_little:
226 kfree(bl_idle_little_driver.cpumask);
227
228 return ret;
229}
230device_initcall(bl_idle_init);
231