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

thermal: cpu_cooling: introduce of_cpufreq_cooling_register

This patch introduces an API to register cpufreq cooling device
based on device tree node.

The registration via device tree node differs from normal
registration due to the fact that it is needed to fill
the device_node structure in order to be able to match
the cooling devices with trip points.

Cc: Zhang Rui <rui.zhang@intel.com>
Cc: linux-pm@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Eduardo Valentin <eduardo.valentin@ti.com>

+76 -6
+1
drivers/thermal/Kconfig
··· 92 92 config CPU_THERMAL 93 93 bool "generic cpu cooling support" 94 94 depends on CPU_FREQ 95 + depends on THERMAL_OF 95 96 help 96 97 This implements the generic cpu cooling mechanism through frequency 97 98 reduction. An ACPI version of this already exists
+50 -6
drivers/thermal/cpu_cooling.c
··· 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 422 * @clip_cpus: cpumask of cpus where the frequency constraints will happen. 422 423 * 423 424 * This interface function registers the cpufreq cooling device with the name 424 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 429 * Return: a valid struct thermal_cooling_device pointer on success, 428 430 * on failure, it returns a corresponding ERR_PTR(). 429 431 */ 430 - struct thermal_cooling_device * 431 - cpufreq_cooling_register(const struct cpumask *clip_cpus) 432 + static struct thermal_cooling_device * 433 + __cpufreq_cooling_register(struct device_node *np, 434 + const struct cpumask *clip_cpus) 432 435 { 433 436 struct thermal_cooling_device *cool_dev; 434 437 struct cpufreq_cooling_device *cpufreq_dev = NULL; ··· 470 467 snprintf(dev_name, sizeof(dev_name), "thermal-cpufreq-%d", 471 468 cpufreq_dev->id); 472 469 473 - cool_dev = thermal_cooling_device_register(dev_name, cpufreq_dev, 474 - &cpufreq_cooling_ops); 470 + cool_dev = thermal_of_cooling_device_register(np, dev_name, cpufreq_dev, 471 + &cpufreq_cooling_ops); 475 472 if (IS_ERR(cool_dev)) { 476 473 release_idr(&cpufreq_idr, cpufreq_dev->id); 477 474 kfree(cpufreq_dev); ··· 491 488 492 489 return cool_dev; 493 490 } 491 + 492 + /** 493 + * cpufreq_cooling_register - function to create cpufreq cooling device. 494 + * @clip_cpus: cpumask of cpus where the frequency constraints will happen. 495 + * 496 + * This interface function registers the cpufreq cooling device with the name 497 + * "thermal-cpufreq-%x". This api can support multiple instances of cpufreq 498 + * cooling devices. 499 + * 500 + * Return: a valid struct thermal_cooling_device pointer on success, 501 + * on failure, it returns a corresponding ERR_PTR(). 502 + */ 503 + struct thermal_cooling_device * 504 + cpufreq_cooling_register(const struct cpumask *clip_cpus) 505 + { 506 + return __cpufreq_cooling_register(NULL, clip_cpus); 507 + } 494 508 EXPORT_SYMBOL_GPL(cpufreq_cooling_register); 509 + 510 + /** 511 + * of_cpufreq_cooling_register - function to create cpufreq cooling device. 512 + * @np: a valid struct device_node to the cooling device device tree node 513 + * @clip_cpus: cpumask of cpus where the frequency constraints will happen. 514 + * 515 + * This interface function registers the cpufreq cooling device with the name 516 + * "thermal-cpufreq-%x". This api can support multiple instances of cpufreq 517 + * cooling devices. Using this API, the cpufreq cooling device will be 518 + * linked to the device tree node provided. 519 + * 520 + * Return: a valid struct thermal_cooling_device pointer on success, 521 + * on failure, it returns a corresponding ERR_PTR(). 522 + */ 523 + struct thermal_cooling_device * 524 + of_cpufreq_cooling_register(struct device_node *np, 525 + const struct cpumask *clip_cpus) 526 + { 527 + if (!np) 528 + return ERR_PTR(-EINVAL); 529 + 530 + return __cpufreq_cooling_register(np, clip_cpus); 531 + } 532 + EXPORT_SYMBOL_GPL(of_cpufreq_cooling_register); 495 533 496 534 /** 497 535 * cpufreq_cooling_unregister - function to remove cpufreq cooling device.
+25
include/linux/cpu_cooling.h
··· 24 24 #ifndef __CPU_COOLING_H__ 25 25 #define __CPU_COOLING_H__ 26 26 27 + #include <linux/of.h> 27 28 #include <linux/thermal.h> 28 29 #include <linux/cpumask.h> 29 30 ··· 37 36 cpufreq_cooling_register(const struct cpumask *clip_cpus); 38 37 39 38 /** 39 + * of_cpufreq_cooling_register - create cpufreq cooling device based on DT. 40 + * @np: a valid struct device_node to the cooling device device tree node. 41 + * @clip_cpus: cpumask of cpus where the frequency constraints will happen 42 + */ 43 + #ifdef CONFIG_THERMAL_OF 44 + struct thermal_cooling_device * 45 + of_cpufreq_cooling_register(struct device_node *np, 46 + const struct cpumask *clip_cpus); 47 + #else 48 + static inline struct thermal_cooling_device * 49 + of_cpufreq_cooling_register(struct device_node *np, 50 + const struct cpumask *clip_cpus) 51 + { 52 + return NULL; 53 + } 54 + #endif 55 + 56 + /** 40 57 * cpufreq_cooling_unregister - function to remove cpufreq cooling device. 41 58 * @cdev: thermal cooling device pointer. 42 59 */ ··· 64 45 #else /* !CONFIG_CPU_THERMAL */ 65 46 static inline struct thermal_cooling_device * 66 47 cpufreq_cooling_register(const struct cpumask *clip_cpus) 48 + { 49 + return NULL; 50 + } 51 + static inline struct thermal_cooling_device * 52 + of_cpufreq_cooling_register(struct device_node *np, 53 + const struct cpumask *clip_cpus) 67 54 { 68 55 return NULL; 69 56 }