diff options
-rw-r--r-- | drivers/thermal/Kconfig | 1 | ||||
-rw-r--r-- | drivers/thermal/cpu_cooling.c | 56 | ||||
-rw-r--r-- | include/linux/cpu_cooling.h | 25 |
3 files changed, 76 insertions, 6 deletions
diff --git a/drivers/thermal/Kconfig b/drivers/thermal/Kconfig index a150f8d53322..3feb5377fbf6 100644 --- a/drivers/thermal/Kconfig +++ b/drivers/thermal/Kconfig | |||
@@ -92,6 +92,7 @@ config THERMAL_GOV_USER_SPACE | |||
92 | config CPU_THERMAL | 92 | config CPU_THERMAL |
93 | bool "generic cpu cooling support" | 93 | bool "generic cpu cooling support" |
94 | depends on CPU_FREQ | 94 | depends on CPU_FREQ |
95 | depends on THERMAL_OF | ||
95 | help | 96 | help |
96 | This implements the generic cpu cooling mechanism through frequency | 97 | This implements the generic cpu cooling mechanism through frequency |
97 | reduction. An ACPI version of this already exists | 98 | reduction. An ACPI version of this already exists |
diff --git a/drivers/thermal/cpu_cooling.c b/drivers/thermal/cpu_cooling.c index 02a46f23d14c..a6cb5531403f 100644 --- a/drivers/thermal/cpu_cooling.c +++ b/drivers/thermal/cpu_cooling.c | |||
@@ -417,18 +417,21 @@ static struct notifier_block thermal_cpufreq_notifier_block = { | |||
417 | }; | 417 | }; |
418 | 418 | ||
419 | /** | 419 | /** |
420 | * cpufreq_cooling_register - function to create cpufreq cooling device. | 420 | * __cpufreq_cooling_register - helper function to create cpufreq cooling device |
421 | * @np: a valid struct device_node to the cooling device device tree node | ||
421 | * @clip_cpus: cpumask of cpus where the frequency constraints will happen. | 422 | * @clip_cpus: cpumask of cpus where the frequency constraints will happen. |
422 | * | 423 | * |
423 | * This interface function registers the cpufreq cooling device with the name | 424 | * This interface function registers the cpufreq cooling device with the name |
424 | * "thermal-cpufreq-%x". This api can support multiple instances of cpufreq | 425 | * "thermal-cpufreq-%x". This api can support multiple instances of cpufreq |
425 | * cooling devices. | 426 | * cooling devices. It also gives the opportunity to link the cooling device |
427 | * with a device tree node, in order to bind it via the thermal DT code. | ||
426 | * | 428 | * |
427 | * Return: a valid struct thermal_cooling_device pointer on success, | 429 | * Return: a valid struct thermal_cooling_device pointer on success, |
428 | * on failure, it returns a corresponding ERR_PTR(). | 430 | * on failure, it returns a corresponding ERR_PTR(). |
429 | */ | 431 | */ |
430 | struct thermal_cooling_device * | 432 | static struct thermal_cooling_device * |
431 | cpufreq_cooling_register(const struct cpumask *clip_cpus) | 433 | __cpufreq_cooling_register(struct device_node *np, |
434 | const struct cpumask *clip_cpus) | ||
432 | { | 435 | { |
433 | struct thermal_cooling_device *cool_dev; | 436 | struct thermal_cooling_device *cool_dev; |
434 | struct cpufreq_cooling_device *cpufreq_dev = NULL; | 437 | struct cpufreq_cooling_device *cpufreq_dev = NULL; |
@@ -467,8 +470,8 @@ cpufreq_cooling_register(const struct cpumask *clip_cpus) | |||
467 | snprintf(dev_name, sizeof(dev_name), "thermal-cpufreq-%d", | 470 | snprintf(dev_name, sizeof(dev_name), "thermal-cpufreq-%d", |
468 | cpufreq_dev->id); | 471 | cpufreq_dev->id); |
469 | 472 | ||
470 | cool_dev = thermal_cooling_device_register(dev_name, cpufreq_dev, | 473 | cool_dev = thermal_of_cooling_device_register(np, dev_name, cpufreq_dev, |
471 | &cpufreq_cooling_ops); | 474 | &cpufreq_cooling_ops); |
472 | if (IS_ERR(cool_dev)) { | 475 | if (IS_ERR(cool_dev)) { |
473 | release_idr(&cpufreq_idr, cpufreq_dev->id); | 476 | release_idr(&cpufreq_idr, cpufreq_dev->id); |
474 | kfree(cpufreq_dev); | 477 | kfree(cpufreq_dev); |
@@ -488,9 +491,50 @@ cpufreq_cooling_register(const struct cpumask *clip_cpus) | |||
488 | 491 | ||
489 | return cool_dev; | 492 | return cool_dev; |
490 | } | 493 | } |
494 | |||
495 | /** | ||
496 | * cpufreq_cooling_register - function to create cpufreq cooling device. | ||
497 | * @clip_cpus: cpumask of cpus where the frequency constraints will happen. | ||
498 | * | ||
499 | * This interface function registers the cpufreq cooling device with the name | ||
500 | * "thermal-cpufreq-%x". This api can support multiple instances of cpufreq | ||
501 | * cooling devices. | ||
502 | * | ||
503 | * Return: a valid struct thermal_cooling_device pointer on success, | ||
504 | * on failure, it returns a corresponding ERR_PTR(). | ||
505 | */ | ||
506 | struct thermal_cooling_device * | ||
507 | cpufreq_cooling_register(const struct cpumask *clip_cpus) | ||
508 | { | ||
509 | return __cpufreq_cooling_register(NULL, clip_cpus); | ||
510 | } | ||
491 | EXPORT_SYMBOL_GPL(cpufreq_cooling_register); | 511 | EXPORT_SYMBOL_GPL(cpufreq_cooling_register); |
492 | 512 | ||
493 | /** | 513 | /** |
514 | * of_cpufreq_cooling_register - function to create cpufreq cooling device. | ||
515 | * @np: a valid struct device_node to the cooling device device tree node | ||
516 | * @clip_cpus: cpumask of cpus where the frequency constraints will happen. | ||
517 | * | ||
518 | * This interface function registers the cpufreq cooling device with the name | ||
519 | * "thermal-cpufreq-%x". This api can support multiple instances of cpufreq | ||
520 | * cooling devices. Using this API, the cpufreq cooling device will be | ||
521 | * linked to the device tree node provided. | ||
522 | * | ||
523 | * Return: a valid struct thermal_cooling_device pointer on success, | ||
524 | * on failure, it returns a corresponding ERR_PTR(). | ||
525 | */ | ||
526 | struct thermal_cooling_device * | ||
527 | of_cpufreq_cooling_register(struct device_node *np, | ||
528 | const struct cpumask *clip_cpus) | ||
529 | { | ||
530 | if (!np) | ||
531 | return ERR_PTR(-EINVAL); | ||
532 | |||
533 | return __cpufreq_cooling_register(np, clip_cpus); | ||
534 | } | ||
535 | EXPORT_SYMBOL_GPL(of_cpufreq_cooling_register); | ||
536 | |||
537 | /** | ||
494 | * cpufreq_cooling_unregister - function to remove cpufreq cooling device. | 538 | * cpufreq_cooling_unregister - function to remove cpufreq cooling device. |
495 | * @cdev: thermal cooling device pointer. | 539 | * @cdev: thermal cooling device pointer. |
496 | * | 540 | * |
diff --git a/include/linux/cpu_cooling.h b/include/linux/cpu_cooling.h index a5d52eea8232..c303d383def1 100644 --- a/include/linux/cpu_cooling.h +++ b/include/linux/cpu_cooling.h | |||
@@ -24,6 +24,7 @@ | |||
24 | #ifndef __CPU_COOLING_H__ | 24 | #ifndef __CPU_COOLING_H__ |
25 | #define __CPU_COOLING_H__ | 25 | #define __CPU_COOLING_H__ |
26 | 26 | ||
27 | #include <linux/of.h> | ||
27 | #include <linux/thermal.h> | 28 | #include <linux/thermal.h> |
28 | #include <linux/cpumask.h> | 29 | #include <linux/cpumask.h> |
29 | 30 | ||
@@ -36,6 +37,24 @@ struct thermal_cooling_device * | |||
36 | cpufreq_cooling_register(const struct cpumask *clip_cpus); | 37 | cpufreq_cooling_register(const struct cpumask *clip_cpus); |
37 | 38 | ||
38 | /** | 39 | /** |
40 | * of_cpufreq_cooling_register - create cpufreq cooling device based on DT. | ||
41 | * @np: a valid struct device_node to the cooling device device tree node. | ||
42 | * @clip_cpus: cpumask of cpus where the frequency constraints will happen | ||
43 | */ | ||
44 | #ifdef CONFIG_THERMAL_OF | ||
45 | struct thermal_cooling_device * | ||
46 | of_cpufreq_cooling_register(struct device_node *np, | ||
47 | const struct cpumask *clip_cpus); | ||
48 | #else | ||
49 | static inline struct thermal_cooling_device * | ||
50 | of_cpufreq_cooling_register(struct device_node *np, | ||
51 | const struct cpumask *clip_cpus) | ||
52 | { | ||
53 | return NULL; | ||
54 | } | ||
55 | #endif | ||
56 | |||
57 | /** | ||
39 | * cpufreq_cooling_unregister - function to remove cpufreq cooling device. | 58 | * cpufreq_cooling_unregister - function to remove cpufreq cooling device. |
40 | * @cdev: thermal cooling device pointer. | 59 | * @cdev: thermal cooling device pointer. |
41 | */ | 60 | */ |
@@ -48,6 +67,12 @@ cpufreq_cooling_register(const struct cpumask *clip_cpus) | |||
48 | { | 67 | { |
49 | return NULL; | 68 | return NULL; |
50 | } | 69 | } |
70 | static inline struct thermal_cooling_device * | ||
71 | of_cpufreq_cooling_register(struct device_node *np, | ||
72 | const struct cpumask *clip_cpus) | ||
73 | { | ||
74 | return NULL; | ||
75 | } | ||
51 | static inline | 76 | static inline |
52 | void cpufreq_cooling_unregister(struct thermal_cooling_device *cdev) | 77 | void cpufreq_cooling_unregister(struct thermal_cooling_device *cdev) |
53 | { | 78 | { |