diff options
author | Viresh Kumar <viresh.kumar@linaro.org> | 2017-12-05 00:32:43 -0500 |
---|---|---|
committer | Rafael J. Wysocki <rafael.j.wysocki@intel.com> | 2017-12-07 16:52:01 -0500 |
commit | f5f263fed66f75a4482d7ad49392b4283a05885a (patch) | |
tree | 230438b70d7eae17d8f4cd17bec052be342c19c4 | |
parent | ae64f9bd1d3621b5e60d7363bc20afb46aede215 (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.txt | 7 | ||||
-rw-r--r-- | drivers/cpufreq/arm_big_little.c | 23 | ||||
-rw-r--r-- | drivers/cpufreq/cpufreq-dt.c | 27 | ||||
-rw-r--r-- | drivers/cpufreq/mediatek-cpufreq.c | 22 | ||||
-rw-r--r-- | drivers/cpufreq/qoriq-cpufreq.c | 14 | ||||
-rw-r--r-- | drivers/thermal/cpu_cooling.c | 49 | ||||
-rw-r--r-- | include/linux/cpu_cooling.h | 15 |
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 | |||
51 | static power consumed by these cpus (See 2.2 Static power). | 51 | static power consumed by these cpus (See 2.2 Static power). |
52 | 52 | ||
53 | 1.1.4 struct thermal_cooling_device *of_cpufreq_power_cooling_register( | 53 | 1.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 | ||
57 | Similar to cpufreq_power_cooling_register, this function register a | 56 | Similar to cpufreq_power_cooling_register, this function register a |
58 | cpufreq cooling device with power extensions using the device tree | 57 | cpufreq cooling device with power extensions using the device tree |
@@ -76,8 +75,8 @@ cpu. If you are using CONFIG_CPUFREQ_DT then the | |||
76 | device. | 75 | device. |
77 | 76 | ||
78 | The `plat_static_func` parameter of `cpufreq_power_cooling_register()` | 77 | The `plat_static_func` parameter of `cpufreq_power_cooling_register()` |
79 | and `of_cpufreq_power_cooling_register()` is optional. If you don't | 78 | is optional. If you don't provide it, only dynamic power will be |
80 | provide it, only dynamic power will be considered. | 79 | considered. |
81 | 80 | ||
82 | 2.1 Dynamic power | 81 | 2.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 | ||
527 | static void bL_cpufreq_ready(struct cpufreq_policy *policy) | 527 | static 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 | ||
559 | static struct cpufreq_driver bL_cpufreq_driver = { | 538 | static 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) | |||
319 | static void cpufreq_ready(struct cpufreq_policy *policy) | 319 | static 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 | ||
351 | static struct cpufreq_driver dt_cpufreq_driver = { | 326 | static 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, | |||
310 | static void mtk_cpufreq_ready(struct cpufreq_policy *policy) | 310 | static 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 | ||
337 | static int mtk_cpu_dvfs_info_init(struct mtk_cpu_dvfs_info *info, int cpu) | 317 | static 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, | |||
275 | static void qoriq_cpufreq_ready(struct cpufreq_policy *policy) | 275 | static 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 | ||
294 | static struct cpufreq_driver qoriq_cpufreq_driver = { | 282 | static 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 | */ |
897 | struct thermal_cooling_device * | 893 | struct thermal_cooling_device * |
898 | of_cpufreq_power_cooling_register(struct device_node *np, | 894 | of_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 | } |
909 | EXPORT_SYMBOL(of_cpufreq_power_cooling_register); | 922 | EXPORT_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 | ||
58 | struct thermal_cooling_device * | 58 | struct thermal_cooling_device * |
59 | of_cpufreq_power_cooling_register(struct device_node *np, | 59 | of_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 |
64 | static inline struct thermal_cooling_device * | 61 | static inline struct thermal_cooling_device * |
65 | of_cpufreq_cooling_register(struct device_node *np, | 62 | of_cpufreq_cooling_register(struct device_node *np, |
@@ -69,10 +66,7 @@ of_cpufreq_cooling_register(struct device_node *np, | |||
69 | } | 66 | } |
70 | 67 | ||
71 | static inline struct thermal_cooling_device * | 68 | static inline struct thermal_cooling_device * |
72 | of_cpufreq_power_cooling_register(struct device_node *np, | 69 | of_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 | ||
107 | static inline struct thermal_cooling_device * | 101 | static inline struct thermal_cooling_device * |
108 | of_cpufreq_power_cooling_register(struct device_node *np, | 102 | of_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 | } |