aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorViresh Kumar <viresh.kumar@linaro.org>2017-12-05 00:32:43 -0500
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>2017-12-07 16:52:01 -0500
commitf5f263fed66f75a4482d7ad49392b4283a05885a (patch)
tree230438b70d7eae17d8f4cd17bec052be342c19c4
parentae64f9bd1d3621b5e60d7363bc20afb46aede215 (diff)
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>
-rw-r--r--Documentation/thermal/cpu-cooling-api.txt7
-rw-r--r--drivers/cpufreq/arm_big_little.c23
-rw-r--r--drivers/cpufreq/cpufreq-dt.c27
-rw-r--r--drivers/cpufreq/mediatek-cpufreq.c22
-rw-r--r--drivers/cpufreq/qoriq-cpufreq.c14
-rw-r--r--drivers/thermal/cpu_cooling.c49
-rw-r--r--include/linux/cpu_cooling.h15
7 files changed, 41 insertions, 116 deletions
diff --git a/Documentation/thermal/cpu-cooling-api.txt b/Documentation/thermal/cpu-cooling-api.txt
index 71653584cd03..4f6f5e9bb4d6 100644
--- a/Documentation/thermal/cpu-cooling-api.txt
+++ b/Documentation/thermal/cpu-cooling-api.txt
@@ -51,8 +51,7 @@ Dynamic power). "plat_static_func" is a function to calculate the
51static power consumed by these cpus (See 2.2 Static power). 51static power consumed by these cpus (See 2.2 Static power).
52 52
531.1.4 struct thermal_cooling_device *of_cpufreq_power_cooling_register( 531.1.4 struct thermal_cooling_device *of_cpufreq_power_cooling_register(
54 struct device_node *np, const struct cpumask *clip_cpus, u32 capacitance, 54 struct cpufreq_policy *policy)
55 get_static_t plat_static_func)
56 55
57Similar to cpufreq_power_cooling_register, this function register a 56Similar to cpufreq_power_cooling_register, this function register a
58cpufreq cooling device with power extensions using the device tree 57cpufreq cooling device with power extensions using the device tree
@@ -76,8 +75,8 @@ cpu. If you are using CONFIG_CPUFREQ_DT then the
76device. 75device.
77 76
78The `plat_static_func` parameter of `cpufreq_power_cooling_register()` 77The `plat_static_func` parameter of `cpufreq_power_cooling_register()`
79and `of_cpufreq_power_cooling_register()` is optional. If you don't 78is optional. If you don't provide it, only dynamic power will be
80provide it, only dynamic power will be considered. 79considered.
81 80
822.1 Dynamic power 812.1 Dynamic power
83 82
diff --git a/drivers/cpufreq/arm_big_little.c b/drivers/cpufreq/arm_big_little.c
index 65ec5f01aa8d..3d5ed4ef3927 100644
--- a/drivers/cpufreq/arm_big_little.c
+++ b/drivers/cpufreq/arm_big_little.c
@@ -526,34 +526,13 @@ static int bL_cpufreq_exit(struct cpufreq_policy *policy)
526 526
527static void bL_cpufreq_ready(struct cpufreq_policy *policy) 527static void bL_cpufreq_ready(struct cpufreq_policy *policy)
528{ 528{
529 struct device *cpu_dev = get_cpu_device(policy->cpu);
530 int cur_cluster = cpu_to_cluster(policy->cpu); 529 int cur_cluster = cpu_to_cluster(policy->cpu);
531 struct device_node *np;
532 530
533 /* Do not register a cpu_cooling device if we are in IKS mode */ 531 /* Do not register a cpu_cooling device if we are in IKS mode */
534 if (cur_cluster >= MAX_CLUSTERS) 532 if (cur_cluster >= MAX_CLUSTERS)
535 return; 533 return;
536 534
537 np = of_node_get(cpu_dev->of_node); 535 cdev[cur_cluster] = of_cpufreq_power_cooling_register(policy);
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);
557} 536}
558 537
559static struct cpufreq_driver bL_cpufreq_driver = { 538static struct cpufreq_driver bL_cpufreq_driver = {
diff --git a/drivers/cpufreq/cpufreq-dt.c b/drivers/cpufreq/cpufreq-dt.c
index 545946ad0752..1e7bec7694ab 100644
--- a/drivers/cpufreq/cpufreq-dt.c
+++ b/drivers/cpufreq/cpufreq-dt.c
@@ -319,33 +319,8 @@ static int cpufreq_exit(struct cpufreq_policy *policy)
319static void cpufreq_ready(struct cpufreq_policy *policy) 319static void cpufreq_ready(struct cpufreq_policy *policy)
320{ 320{
321 struct private_data *priv = policy->driver_data; 321 struct private_data *priv = policy->driver_data;
322 struct device_node *np = of_node_get(priv->cpu_dev->of_node);
323 322
324 if (WARN_ON(!np)) 323 priv->cdev = of_cpufreq_power_cooling_register(policy);
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);
349} 324}
350 325
351static struct cpufreq_driver dt_cpufreq_driver = { 326static struct cpufreq_driver dt_cpufreq_driver = {
diff --git a/drivers/cpufreq/mediatek-cpufreq.c b/drivers/cpufreq/mediatek-cpufreq.c
index e0d5090b303d..6ff783e1b18a 100644
--- a/drivers/cpufreq/mediatek-cpufreq.c
+++ b/drivers/cpufreq/mediatek-cpufreq.c
@@ -310,28 +310,8 @@ static int mtk_cpufreq_set_target(struct cpufreq_policy *policy,
310static void mtk_cpufreq_ready(struct cpufreq_policy *policy) 310static void mtk_cpufreq_ready(struct cpufreq_policy *policy)
311{ 311{
312 struct mtk_cpu_dvfs_info *info = policy->driver_data; 312 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;
315 313
316 if (WARN_ON(!np)) 314 info->cdev = of_cpufreq_power_cooling_register(policy);
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);
335} 315}
336 316
337static int mtk_cpu_dvfs_info_init(struct mtk_cpu_dvfs_info *info, int cpu) 317static int mtk_cpu_dvfs_info_init(struct mtk_cpu_dvfs_info *info, int cpu)
diff --git a/drivers/cpufreq/qoriq-cpufreq.c b/drivers/cpufreq/qoriq-cpufreq.c
index 4ada55b8856e..3a665c18e14e 100644
--- a/drivers/cpufreq/qoriq-cpufreq.c
+++ b/drivers/cpufreq/qoriq-cpufreq.c
@@ -275,20 +275,8 @@ static int qoriq_cpufreq_target(struct cpufreq_policy *policy,
275static void qoriq_cpufreq_ready(struct cpufreq_policy *policy) 275static void qoriq_cpufreq_ready(struct cpufreq_policy *policy)
276{ 276{
277 struct cpu_data *cpud = policy->driver_data; 277 struct cpu_data *cpud = policy->driver_data;
278 struct device_node *np = of_get_cpu_node(policy->cpu, NULL);
279 278
280 if (of_find_property(np, "#cooling-cells", NULL)) { 279 cpud->cdev = of_cpufreq_power_cooling_register(policy);
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);
292} 280}
293 281
294static struct cpufreq_driver qoriq_cpufreq_driver = { 282static struct cpufreq_driver qoriq_cpufreq_driver = {
diff --git a/drivers/thermal/cpu_cooling.c b/drivers/thermal/cpu_cooling.c
index dc63aba092e4..a31eb03c788e 100644
--- a/drivers/thermal/cpu_cooling.c
+++ b/drivers/thermal/cpu_cooling.c
@@ -873,38 +873,51 @@ EXPORT_SYMBOL(cpufreq_power_cooling_register);
873 873
874/** 874/**
875 * of_cpufreq_power_cooling_register() - create cpufreq cooling device with power extensions 875 * 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 876 * @policy: CPUFreq policy.
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)
881 * 877 *
882 * This interface function registers the cpufreq cooling device with 878 * This interface function registers the cpufreq cooling device with
883 * the name "thermal-cpufreq-%x". This api can support multiple 879 * the name "thermal-cpufreq-%x". This api can support multiple
884 * instances of cpufreq cooling devices. Using this API, the cpufreq 880 * 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.
886 * Using this function, the cooling device will implement the power 883 * Using this function, the cooling device will implement the power
887 * extensions by using a simple cpu power model. The cpus must have 884 * extensions by using a simple cpu power model. The cpus must have
888 * registered their OPPs using the OPP library. 885 * registered their OPPs using the OPP library.
889 * 886 *
890 * An optional @plat_static_func may be provided to calculate the 887 * It also takes into account, if property present in policy CPU node, the
891 * static power consumed by these cpus. If the platform's static 888 * static power consumed by the cpu.
892 * power consumption is unknown or negligible, make it NULL.
893 * 889 *
894 * Return: a valid struct thermal_cooling_device pointer on success, 890 * Return: a valid struct thermal_cooling_device pointer on success,
895 * on failure, it returns a corresponding ERR_PTR(). 891 * and NULL on failure.
896 */ 892 */
897struct thermal_cooling_device * 893struct thermal_cooling_device *
898of_cpufreq_power_cooling_register(struct device_node *np, 894of_cpufreq_power_cooling_register(struct cpufreq_policy *policy)
899 struct cpufreq_policy *policy,
900 u32 capacitance,
901 get_static_t plat_static_func)
902{ 895{
903 if (!np) 896 struct device_node *np = of_get_cpu_node(policy->cpu, NULL);
904 return ERR_PTR(-EINVAL); 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 }
905 905
906 return __cpufreq_cooling_register(np, policy, capacitance, 906 if (of_find_property(np, "#cooling-cells", NULL)) {
907 plat_static_func); 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;
908} 921}
909EXPORT_SYMBOL(of_cpufreq_power_cooling_register); 922EXPORT_SYMBOL(of_cpufreq_power_cooling_register);
910 923
diff --git a/include/linux/cpu_cooling.h b/include/linux/cpu_cooling.h
index d4292ebc5c8b..f09d4feb34f4 100644
--- a/include/linux/cpu_cooling.h
+++ b/include/linux/cpu_cooling.h
@@ -56,10 +56,7 @@ of_cpufreq_cooling_register(struct device_node *np,
56 struct cpufreq_policy *policy); 56 struct cpufreq_policy *policy);
57 57
58struct thermal_cooling_device * 58struct thermal_cooling_device *
59of_cpufreq_power_cooling_register(struct device_node *np, 59of_cpufreq_power_cooling_register(struct cpufreq_policy *policy);
60 struct cpufreq_policy *policy,
61 u32 capacitance,
62 get_static_t plat_static_func);
63#else 60#else
64static inline struct thermal_cooling_device * 61static inline struct thermal_cooling_device *
65of_cpufreq_cooling_register(struct device_node *np, 62of_cpufreq_cooling_register(struct device_node *np,
@@ -69,10 +66,7 @@ of_cpufreq_cooling_register(struct device_node *np,
69} 66}
70 67
71static inline struct thermal_cooling_device * 68static inline struct thermal_cooling_device *
72of_cpufreq_power_cooling_register(struct device_node *np, 69of_cpufreq_power_cooling_register(struct cpufreq_policy *policy)
73 struct cpufreq_policy *policy,
74 u32 capacitance,
75 get_static_t plat_static_func)
76{ 70{
77 return NULL; 71 return NULL;
78} 72}
@@ -105,10 +99,7 @@ of_cpufreq_cooling_register(struct device_node *np,
105} 99}
106 100
107static inline struct thermal_cooling_device * 101static inline struct thermal_cooling_device *
108of_cpufreq_power_cooling_register(struct device_node *np, 102of_cpufreq_power_cooling_register(struct cpufreq_policy *policy)
109 struct cpufreq_policy *policy,
110 u32 capacitance,
111 get_static_t plat_static_func)
112{ 103{
113 return NULL; 104 return NULL;
114} 105}