aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEduardo Valentin <eduardo.valentin@ti.com>2013-09-26 15:55:01 -0400
committerEduardo Valentin <eduardo.valentin@ti.com>2013-12-04 08:31:34 -0500
commita116b5d44f144586ef03a93f14ddc63f4a85e906 (patch)
tree51ba653f45fb1858c9f859b674f7101be8eb2fb4
parent4e5e4705bf69ea450f58fc709ac5888f321a9299 (diff)
thermal: core: introduce thermal_of_cooling_device_register
This patch adds a new API to allow registering cooling devices in the thermal framework derived from device tree nodes. This API links the cooling device with the device tree node so that binding with thermal zones is possible, given that thermal zones are pointing to cooling device device tree nodes. 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>
-rw-r--r--drivers/thermal/thermal_core.c58
-rw-r--r--include/linux/thermal.h4
2 files changed, 58 insertions, 4 deletions
diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c
index 3392fcb92796..e381d521c355 100644
--- a/drivers/thermal/thermal_core.c
+++ b/drivers/thermal/thermal_core.c
@@ -34,6 +34,7 @@
34#include <linux/thermal.h> 34#include <linux/thermal.h>
35#include <linux/reboot.h> 35#include <linux/reboot.h>
36#include <linux/string.h> 36#include <linux/string.h>
37#include <linux/of.h>
37#include <net/netlink.h> 38#include <net/netlink.h>
38#include <net/genetlink.h> 39#include <net/genetlink.h>
39 40
@@ -1055,7 +1056,8 @@ static struct class thermal_class = {
1055}; 1056};
1056 1057
1057/** 1058/**
1058 * thermal_cooling_device_register() - register a new thermal cooling device 1059 * __thermal_cooling_device_register() - register a new thermal cooling device
1060 * @np: a pointer to a device tree node.
1059 * @type: the thermal cooling device type. 1061 * @type: the thermal cooling device type.
1060 * @devdata: device private data. 1062 * @devdata: device private data.
1061 * @ops: standard thermal cooling devices callbacks. 1063 * @ops: standard thermal cooling devices callbacks.
@@ -1063,13 +1065,16 @@ static struct class thermal_class = {
1063 * This interface function adds a new thermal cooling device (fan/processor/...) 1065 * This interface function adds a new thermal cooling device (fan/processor/...)
1064 * to /sys/class/thermal/ folder as cooling_device[0-*]. It tries to bind itself 1066 * to /sys/class/thermal/ folder as cooling_device[0-*]. It tries to bind itself
1065 * to all the thermal zone devices registered at the same time. 1067 * to all the thermal zone devices registered at the same time.
1068 * It also gives the opportunity to link the cooling device to a device tree
1069 * node, so that it can be bound to a thermal zone created out of device tree.
1066 * 1070 *
1067 * Return: a pointer to the created struct thermal_cooling_device or an 1071 * Return: a pointer to the created struct thermal_cooling_device or an
1068 * ERR_PTR. Caller must check return value with IS_ERR*() helpers. 1072 * ERR_PTR. Caller must check return value with IS_ERR*() helpers.
1069 */ 1073 */
1070struct thermal_cooling_device * 1074static struct thermal_cooling_device *
1071thermal_cooling_device_register(char *type, void *devdata, 1075__thermal_cooling_device_register(struct device_node *np,
1072 const struct thermal_cooling_device_ops *ops) 1076 char *type, void *devdata,
1077 const struct thermal_cooling_device_ops *ops)
1073{ 1078{
1074 struct thermal_cooling_device *cdev; 1079 struct thermal_cooling_device *cdev;
1075 int result; 1080 int result;
@@ -1094,6 +1099,7 @@ thermal_cooling_device_register(char *type, void *devdata,
1094 strlcpy(cdev->type, type ? : "", sizeof(cdev->type)); 1099 strlcpy(cdev->type, type ? : "", sizeof(cdev->type));
1095 mutex_init(&cdev->lock); 1100 mutex_init(&cdev->lock);
1096 INIT_LIST_HEAD(&cdev->thermal_instances); 1101 INIT_LIST_HEAD(&cdev->thermal_instances);
1102 cdev->np = np;
1097 cdev->ops = ops; 1103 cdev->ops = ops;
1098 cdev->updated = true; 1104 cdev->updated = true;
1099 cdev->device.class = &thermal_class; 1105 cdev->device.class = &thermal_class;
@@ -1136,9 +1142,53 @@ unregister:
1136 device_unregister(&cdev->device); 1142 device_unregister(&cdev->device);
1137 return ERR_PTR(result); 1143 return ERR_PTR(result);
1138} 1144}
1145
1146/**
1147 * thermal_cooling_device_register() - register a new thermal cooling device
1148 * @type: the thermal cooling device type.
1149 * @devdata: device private data.
1150 * @ops: standard thermal cooling devices callbacks.
1151 *
1152 * This interface function adds a new thermal cooling device (fan/processor/...)
1153 * to /sys/class/thermal/ folder as cooling_device[0-*]. It tries to bind itself
1154 * to all the thermal zone devices registered at the same time.
1155 *
1156 * Return: a pointer to the created struct thermal_cooling_device or an
1157 * ERR_PTR. Caller must check return value with IS_ERR*() helpers.
1158 */
1159struct thermal_cooling_device *
1160thermal_cooling_device_register(char *type, void *devdata,
1161 const struct thermal_cooling_device_ops *ops)
1162{
1163 return __thermal_cooling_device_register(NULL, type, devdata, ops);
1164}
1139EXPORT_SYMBOL_GPL(thermal_cooling_device_register); 1165EXPORT_SYMBOL_GPL(thermal_cooling_device_register);
1140 1166
1141/** 1167/**
1168 * thermal_of_cooling_device_register() - register an OF thermal cooling device
1169 * @np: a pointer to a device tree node.
1170 * @type: the thermal cooling device type.
1171 * @devdata: device private data.
1172 * @ops: standard thermal cooling devices callbacks.
1173 *
1174 * This function will register a cooling device with device tree node reference.
1175 * This interface function adds a new thermal cooling device (fan/processor/...)
1176 * to /sys/class/thermal/ folder as cooling_device[0-*]. It tries to bind itself
1177 * to all the thermal zone devices registered at the same time.
1178 *
1179 * Return: a pointer to the created struct thermal_cooling_device or an
1180 * ERR_PTR. Caller must check return value with IS_ERR*() helpers.
1181 */
1182struct thermal_cooling_device *
1183thermal_of_cooling_device_register(struct device_node *np,
1184 char *type, void *devdata,
1185 const struct thermal_cooling_device_ops *ops)
1186{
1187 return __thermal_cooling_device_register(np, type, devdata, ops);
1188}
1189EXPORT_SYMBOL_GPL(thermal_of_cooling_device_register);
1190
1191/**
1142 * thermal_cooling_device_unregister - removes the registered thermal cooling device 1192 * thermal_cooling_device_unregister - removes the registered thermal cooling device
1143 * @cdev: the thermal cooling device to remove. 1193 * @cdev: the thermal cooling device to remove.
1144 * 1194 *
diff --git a/include/linux/thermal.h b/include/linux/thermal.h
index b780c5b27122..f7e11c7ea7d9 100644
--- a/include/linux/thermal.h
+++ b/include/linux/thermal.h
@@ -25,6 +25,7 @@
25#ifndef __THERMAL_H__ 25#ifndef __THERMAL_H__
26#define __THERMAL_H__ 26#define __THERMAL_H__
27 27
28#include <linux/of.h>
28#include <linux/idr.h> 29#include <linux/idr.h>
29#include <linux/device.h> 30#include <linux/device.h>
30#include <linux/workqueue.h> 31#include <linux/workqueue.h>
@@ -280,6 +281,9 @@ void thermal_zone_device_update(struct thermal_zone_device *);
280 281
281struct thermal_cooling_device *thermal_cooling_device_register(char *, void *, 282struct thermal_cooling_device *thermal_cooling_device_register(char *, void *,
282 const struct thermal_cooling_device_ops *); 283 const struct thermal_cooling_device_ops *);
284struct thermal_cooling_device *
285thermal_of_cooling_device_register(struct device_node *np, char *, void *,
286 const struct thermal_cooling_device_ops *);
283void thermal_cooling_device_unregister(struct thermal_cooling_device *); 287void thermal_cooling_device_unregister(struct thermal_cooling_device *);
284struct thermal_zone_device *thermal_zone_get_zone_by_name(const char *name); 288struct thermal_zone_device *thermal_zone_get_zone_by_name(const char *name);
285int thermal_zone_get_temp(struct thermal_zone_device *tz, unsigned long *temp); 289int thermal_zone_get_temp(struct thermal_zone_device *tz, unsigned long *temp);