Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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

+30 -6
+30 -6
drivers/powercap/dtpm_cpu.c
··· 21 21 #include <linux/cpuhotplug.h> 22 22 #include <linux/dtpm.h> 23 23 #include <linux/energy_model.h> 24 + #include <linux/of.h> 24 25 #include <linux/pm_qos.h> 25 26 #include <linux/slab.h> 26 27 #include <linux/units.h> ··· 179 178 static int cpuhp_dtpm_cpu_online(unsigned int cpu) 180 179 { 181 180 struct dtpm_cpu *dtpm_cpu; 181 + 182 + dtpm_cpu = per_cpu(dtpm_per_cpu, cpu); 183 + if (dtpm_cpu) 184 + return dtpm_update_power(&dtpm_cpu->dtpm); 185 + 186 + return 0; 187 + } 188 + 189 + static int __dtpm_cpu_setup(int cpu, struct dtpm *parent) 190 + { 191 + struct dtpm_cpu *dtpm_cpu; 182 192 struct cpufreq_policy *policy; 183 193 struct em_perf_domain *pd; 184 194 char name[CPUFREQ_NAME_LEN]; 185 195 int ret = -ENOMEM; 196 + 197 + dtpm_cpu = per_cpu(dtpm_per_cpu, cpu); 198 + if (dtpm_cpu) 199 + return 0; 186 200 187 201 policy = cpufreq_cpu_get(cpu); 188 202 if (!policy) ··· 206 190 pd = em_cpu_get(cpu); 207 191 if (!pd) 208 192 return -EINVAL; 209 - 210 - dtpm_cpu = per_cpu(dtpm_per_cpu, cpu); 211 - if (dtpm_cpu) 212 - return dtpm_update_power(&dtpm_cpu->dtpm); 213 193 214 194 dtpm_cpu = kzalloc(sizeof(*dtpm_cpu), GFP_KERNEL); 215 195 if (!dtpm_cpu) ··· 219 207 220 208 snprintf(name, sizeof(name), "cpu%d-cpufreq", dtpm_cpu->cpu); 221 209 222 - ret = dtpm_register(name, &dtpm_cpu->dtpm, NULL); 210 + ret = dtpm_register(name, &dtpm_cpu->dtpm, parent); 223 211 if (ret) 224 212 goto out_kfree_dtpm_cpu; 225 213 ··· 243 231 return ret; 244 232 } 245 233 246 - static int __init dtpm_cpu_init(void) 234 + static int dtpm_cpu_setup(struct dtpm *dtpm, struct device_node *np) 235 + { 236 + int cpu; 237 + 238 + cpu = of_cpu_node_to_id(np); 239 + if (cpu < 0) 240 + return 0; 241 + 242 + return __dtpm_cpu_setup(cpu, dtpm); 243 + } 244 + 245 + static int dtpm_cpu_init(void) 247 246 { 248 247 int ret; 249 248 ··· 295 272 struct dtpm_subsys_ops dtpm_cpu_ops = { 296 273 .name = KBUILD_MODNAME, 297 274 .init = dtpm_cpu_init, 275 + .setup = dtpm_cpu_setup, 298 276 };