Skip to content

Commit 73dbcb6

Browse files
committed
powercap/drivers/dtpm: Add CPU DT initialization support
Based on the previous DT changes in the core code, use the 'setup' callback to initialize the CPU DTPM backend. Code is reorganized to stick to the DTPM table description. No functional changes. Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org> Reviewed-by: Ulf Hansson <ulf.hansson@linaro.org> Link: https://lore.kernel.org/r/20220128163537.212248-4-daniel.lezcano@linaro.org
1 parent 3759ec6 commit 73dbcb6

1 file changed

Lines changed: 30 additions & 6 deletions

File tree

drivers/powercap/dtpm_cpu.c

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <linux/cpuhotplug.h>
2222
#include <linux/dtpm.h>
2323
#include <linux/energy_model.h>
24+
#include <linux/of.h>
2425
#include <linux/pm_qos.h>
2526
#include <linux/slab.h>
2627
#include <linux/units.h>
@@ -176,13 +177,28 @@ static int cpuhp_dtpm_cpu_offline(unsigned int cpu)
176177
}
177178

178179
static int cpuhp_dtpm_cpu_online(unsigned int cpu)
180+
{
181+
struct dtpm_cpu *dtpm_cpu;
182+
183+
dtpm_cpu = per_cpu(dtpm_per_cpu, cpu);
184+
if (dtpm_cpu)
185+
return dtpm_update_power(&dtpm_cpu->dtpm);
186+
187+
return 0;
188+
}
189+
190+
static int __dtpm_cpu_setup(int cpu, struct dtpm *parent)
179191
{
180192
struct dtpm_cpu *dtpm_cpu;
181193
struct cpufreq_policy *policy;
182194
struct em_perf_domain *pd;
183195
char name[CPUFREQ_NAME_LEN];
184196
int ret = -ENOMEM;
185197

198+
dtpm_cpu = per_cpu(dtpm_per_cpu, cpu);
199+
if (dtpm_cpu)
200+
return 0;
201+
186202
policy = cpufreq_cpu_get(cpu);
187203
if (!policy)
188204
return 0;
@@ -191,10 +207,6 @@ static int cpuhp_dtpm_cpu_online(unsigned int cpu)
191207
if (!pd)
192208
return -EINVAL;
193209

194-
dtpm_cpu = per_cpu(dtpm_per_cpu, cpu);
195-
if (dtpm_cpu)
196-
return dtpm_update_power(&dtpm_cpu->dtpm);
197-
198210
dtpm_cpu = kzalloc(sizeof(*dtpm_cpu), GFP_KERNEL);
199211
if (!dtpm_cpu)
200212
return -ENOMEM;
@@ -207,7 +219,7 @@ static int cpuhp_dtpm_cpu_online(unsigned int cpu)
207219

208220
snprintf(name, sizeof(name), "cpu%d-cpufreq", dtpm_cpu->cpu);
209221

210-
ret = dtpm_register(name, &dtpm_cpu->dtpm, NULL);
222+
ret = dtpm_register(name, &dtpm_cpu->dtpm, parent);
211223
if (ret)
212224
goto out_kfree_dtpm_cpu;
213225

@@ -231,7 +243,18 @@ static int cpuhp_dtpm_cpu_online(unsigned int cpu)
231243
return ret;
232244
}
233245

234-
static int __init dtpm_cpu_init(void)
246+
static int dtpm_cpu_setup(struct dtpm *dtpm, struct device_node *np)
247+
{
248+
int cpu;
249+
250+
cpu = of_cpu_node_to_id(np);
251+
if (cpu < 0)
252+
return 0;
253+
254+
return __dtpm_cpu_setup(cpu, dtpm);
255+
}
256+
257+
static int dtpm_cpu_init(void)
235258
{
236259
int ret;
237260

@@ -272,4 +295,5 @@ static int __init dtpm_cpu_init(void)
272295
struct dtpm_subsys_ops dtpm_cpu_ops = {
273296
.name = KBUILD_MODNAME,
274297
.init = dtpm_cpu_init,
298+
.setup = dtpm_cpu_setup,
275299
};

0 commit comments

Comments
 (0)