Skip to content

Commit f5f263f

Browse files
vireshkrafaeljw
authored andcommitted
cpu_cooling: Make of_cpufreq_power_cooling_register() parse DT
All the callers of of_cpufreq_power_cooling_register() have almost identical code and it makes more sense to move that code into the helper as its all about reading DT properties. This got rid of lot of redundant code. Acked-by: Eduardo Valentin <edubezval@gmail.com> Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent ae64f9b commit f5f263f

File tree

7 files changed

+41
-116
lines changed

7 files changed

+41
-116
lines changed

Documentation/thermal/cpu-cooling-api.txt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@ Dynamic power). "plat_static_func" is a function to calculate the
5151
static power consumed by these cpus (See 2.2 Static power).
5252

5353
1.1.4 struct thermal_cooling_device *of_cpufreq_power_cooling_register(
54-
struct device_node *np, const struct cpumask *clip_cpus, u32 capacitance,
55-
get_static_t plat_static_func)
54+
struct cpufreq_policy *policy)
5655

5756
Similar to cpufreq_power_cooling_register, this function register a
5857
cpufreq cooling device with power extensions using the device tree
@@ -76,8 +75,8 @@ cpu. If you are using CONFIG_CPUFREQ_DT then the
7675
device.
7776

7877
The `plat_static_func` parameter of `cpufreq_power_cooling_register()`
79-
and `of_cpufreq_power_cooling_register()` is optional. If you don't
80-
provide it, only dynamic power will be considered.
78+
is optional. If you don't provide it, only dynamic power will be
79+
considered.
8180

8281
2.1 Dynamic power
8382

drivers/cpufreq/arm_big_little.c

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -526,34 +526,13 @@ static int bL_cpufreq_exit(struct cpufreq_policy *policy)
526526

527527
static void bL_cpufreq_ready(struct cpufreq_policy *policy)
528528
{
529-
struct device *cpu_dev = get_cpu_device(policy->cpu);
530529
int cur_cluster = cpu_to_cluster(policy->cpu);
531-
struct device_node *np;
532530

533531
/* Do not register a cpu_cooling device if we are in IKS mode */
534532
if (cur_cluster >= MAX_CLUSTERS)
535533
return;
536534

537-
np = of_node_get(cpu_dev->of_node);
538-
if (WARN_ON(!np))
539-
return;
540-
541-
if (of_find_property(np, "#cooling-cells", NULL)) {
542-
u32 power_coefficient = 0;
543-
544-
of_property_read_u32(np, "dynamic-power-coefficient",
545-
&power_coefficient);
546-
547-
cdev[cur_cluster] = of_cpufreq_power_cooling_register(np,
548-
policy, power_coefficient, NULL);
549-
if (IS_ERR(cdev[cur_cluster])) {
550-
dev_err(cpu_dev,
551-
"running cpufreq without cooling device: %ld\n",
552-
PTR_ERR(cdev[cur_cluster]));
553-
cdev[cur_cluster] = NULL;
554-
}
555-
}
556-
of_node_put(np);
535+
cdev[cur_cluster] = of_cpufreq_power_cooling_register(policy);
557536
}
558537

559538
static struct cpufreq_driver bL_cpufreq_driver = {

drivers/cpufreq/cpufreq-dt.c

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -319,33 +319,8 @@ static int cpufreq_exit(struct cpufreq_policy *policy)
319319
static void cpufreq_ready(struct cpufreq_policy *policy)
320320
{
321321
struct private_data *priv = policy->driver_data;
322-
struct device_node *np = of_node_get(priv->cpu_dev->of_node);
323322

324-
if (WARN_ON(!np))
325-
return;
326-
327-
/*
328-
* For now, just loading the cooling device;
329-
* thermal DT code takes care of matching them.
330-
*/
331-
if (of_find_property(np, "#cooling-cells", NULL)) {
332-
u32 power_coefficient = 0;
333-
334-
of_property_read_u32(np, "dynamic-power-coefficient",
335-
&power_coefficient);
336-
337-
priv->cdev = of_cpufreq_power_cooling_register(np,
338-
policy, power_coefficient, NULL);
339-
if (IS_ERR(priv->cdev)) {
340-
dev_err(priv->cpu_dev,
341-
"running cpufreq without cooling device: %ld\n",
342-
PTR_ERR(priv->cdev));
343-
344-
priv->cdev = NULL;
345-
}
346-
}
347-
348-
of_node_put(np);
323+
priv->cdev = of_cpufreq_power_cooling_register(policy);
349324
}
350325

351326
static struct cpufreq_driver dt_cpufreq_driver = {

drivers/cpufreq/mediatek-cpufreq.c

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -310,28 +310,8 @@ static int mtk_cpufreq_set_target(struct cpufreq_policy *policy,
310310
static void mtk_cpufreq_ready(struct cpufreq_policy *policy)
311311
{
312312
struct mtk_cpu_dvfs_info *info = policy->driver_data;
313-
struct device_node *np = of_node_get(info->cpu_dev->of_node);
314-
u32 capacitance = 0;
315313

316-
if (WARN_ON(!np))
317-
return;
318-
319-
if (of_find_property(np, "#cooling-cells", NULL)) {
320-
of_property_read_u32(np, DYNAMIC_POWER, &capacitance);
321-
322-
info->cdev = of_cpufreq_power_cooling_register(np,
323-
policy, capacitance, NULL);
324-
325-
if (IS_ERR(info->cdev)) {
326-
dev_err(info->cpu_dev,
327-
"running cpufreq without cooling device: %ld\n",
328-
PTR_ERR(info->cdev));
329-
330-
info->cdev = NULL;
331-
}
332-
}
333-
334-
of_node_put(np);
314+
info->cdev = of_cpufreq_power_cooling_register(policy);
335315
}
336316

337317
static int mtk_cpu_dvfs_info_init(struct mtk_cpu_dvfs_info *info, int cpu)

drivers/cpufreq/qoriq-cpufreq.c

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -275,20 +275,8 @@ static int qoriq_cpufreq_target(struct cpufreq_policy *policy,
275275
static void qoriq_cpufreq_ready(struct cpufreq_policy *policy)
276276
{
277277
struct cpu_data *cpud = policy->driver_data;
278-
struct device_node *np = of_get_cpu_node(policy->cpu, NULL);
279278

280-
if (of_find_property(np, "#cooling-cells", NULL)) {
281-
cpud->cdev = of_cpufreq_cooling_register(np, policy);
282-
283-
if (IS_ERR(cpud->cdev) && PTR_ERR(cpud->cdev) != -ENOSYS) {
284-
pr_err("cpu%d is not running as cooling device: %ld\n",
285-
policy->cpu, PTR_ERR(cpud->cdev));
286-
287-
cpud->cdev = NULL;
288-
}
289-
}
290-
291-
of_node_put(np);
279+
cpud->cdev = of_cpufreq_power_cooling_register(policy);
292280
}
293281

294282
static struct cpufreq_driver qoriq_cpufreq_driver = {

drivers/thermal/cpu_cooling.c

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -873,38 +873,51 @@ EXPORT_SYMBOL(cpufreq_power_cooling_register);
873873

874874
/**
875875
* of_cpufreq_power_cooling_register() - create cpufreq cooling device with power extensions
876-
* @np: a valid struct device_node to the cooling device device tree node
877-
* @policy: cpufreq policy
878-
* @capacitance: dynamic power coefficient for these cpus
879-
* @plat_static_func: function to calculate the static power consumed by these
880-
* cpus (optional)
876+
* @policy: CPUFreq policy.
881877
*
882878
* This interface function registers the cpufreq cooling device with
883879
* the name "thermal-cpufreq-%x". This api can support multiple
884880
* instances of cpufreq cooling devices. Using this API, the cpufreq
885-
* cooling device will be linked to the device tree node provided.
881+
* cooling device will be linked to the device tree node of the provided
882+
* policy's CPU.
886883
* Using this function, the cooling device will implement the power
887884
* extensions by using a simple cpu power model. The cpus must have
888885
* registered their OPPs using the OPP library.
889886
*
890-
* An optional @plat_static_func may be provided to calculate the
891-
* static power consumed by these cpus. If the platform's static
892-
* power consumption is unknown or negligible, make it NULL.
887+
* It also takes into account, if property present in policy CPU node, the
888+
* static power consumed by the cpu.
893889
*
894890
* Return: a valid struct thermal_cooling_device pointer on success,
895-
* on failure, it returns a corresponding ERR_PTR().
891+
* and NULL on failure.
896892
*/
897893
struct thermal_cooling_device *
898-
of_cpufreq_power_cooling_register(struct device_node *np,
899-
struct cpufreq_policy *policy,
900-
u32 capacitance,
901-
get_static_t plat_static_func)
894+
of_cpufreq_power_cooling_register(struct cpufreq_policy *policy)
902895
{
903-
if (!np)
904-
return ERR_PTR(-EINVAL);
896+
struct device_node *np = of_get_cpu_node(policy->cpu, NULL);
897+
struct thermal_cooling_device *cdev = NULL;
898+
u32 capacitance = 0;
899+
900+
if (!np) {
901+
pr_err("cpu_cooling: OF node not available for cpu%d\n",
902+
policy->cpu);
903+
return NULL;
904+
}
905905

906-
return __cpufreq_cooling_register(np, policy, capacitance,
907-
plat_static_func);
906+
if (of_find_property(np, "#cooling-cells", NULL)) {
907+
of_property_read_u32(np, "dynamic-power-coefficient",
908+
&capacitance);
909+
910+
cdev = __cpufreq_cooling_register(np, policy, capacitance,
911+
NULL);
912+
if (IS_ERR(cdev)) {
913+
pr_err("cpu_cooling: cpu%d is not running as cooling device: %ld\n",
914+
policy->cpu, PTR_ERR(cdev));
915+
cdev = NULL;
916+
}
917+
}
918+
919+
of_node_put(np);
920+
return cdev;
908921
}
909922
EXPORT_SYMBOL(of_cpufreq_power_cooling_register);
910923

include/linux/cpu_cooling.h

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,7 @@ of_cpufreq_cooling_register(struct device_node *np,
5656
struct cpufreq_policy *policy);
5757

5858
struct thermal_cooling_device *
59-
of_cpufreq_power_cooling_register(struct device_node *np,
60-
struct cpufreq_policy *policy,
61-
u32 capacitance,
62-
get_static_t plat_static_func);
59+
of_cpufreq_power_cooling_register(struct cpufreq_policy *policy);
6360
#else
6461
static inline struct thermal_cooling_device *
6562
of_cpufreq_cooling_register(struct device_node *np,
@@ -69,10 +66,7 @@ of_cpufreq_cooling_register(struct device_node *np,
6966
}
7067

7168
static inline struct thermal_cooling_device *
72-
of_cpufreq_power_cooling_register(struct device_node *np,
73-
struct cpufreq_policy *policy,
74-
u32 capacitance,
75-
get_static_t plat_static_func)
69+
of_cpufreq_power_cooling_register(struct cpufreq_policy *policy)
7670
{
7771
return NULL;
7872
}
@@ -105,10 +99,7 @@ of_cpufreq_cooling_register(struct device_node *np,
10599
}
106100

107101
static inline struct thermal_cooling_device *
108-
of_cpufreq_power_cooling_register(struct device_node *np,
109-
struct cpufreq_policy *policy,
110-
u32 capacitance,
111-
get_static_t plat_static_func)
102+
of_cpufreq_power_cooling_register(struct cpufreq_policy *policy)
112103
{
113104
return NULL;
114105
}

0 commit comments

Comments
 (0)