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