aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTushar Khandelwal <tushar.khandelwal@arm.com>2017-07-12 18:27:51 +0100
committerRyan Harkin <ryan.harkin@linaro.org>2017-07-27 09:53:34 +0100
commit19b8e7858950ad1d95ce159ccac9af3ed24b452e (patch)
tree72a17b3394445a5b28452cb90e63a6ee0591e387
parent8ac1970a0bb9afa9a0a16e45c91dc6c5d16efb09 (diff)
drivers: thermal: add OF api's to support scmi thermal
mainline patch reference: e498b4984db82b4ba3ceea7dba813222a31e9c2e Change-Id: Id9e62fd42d7de838e4271cb6011d8327e07a047f Signed-off-by: Tushar Khandelwal <tushar.khandelwal@arm.com>
-rw-r--r--drivers/thermal/of-thermal.c51
-rw-r--r--include/linux/thermal.h4
2 files changed, 55 insertions, 0 deletions
diff --git a/drivers/thermal/of-thermal.c b/drivers/thermal/of-thermal.c
index be4eedcb839a..ca191622e4d2 100644
--- a/drivers/thermal/of-thermal.c
+++ b/drivers/thermal/of-thermal.c
@@ -425,6 +425,57 @@ thermal_zone_of_add_sensor(struct device_node *zone,
return tzd;
}
+static void devm_thermal_zone_of_sensor_release(struct device *dev, void *res)
+{
+ thermal_zone_of_sensor_unregister(dev,
+ *(struct thermal_zone_device **)res);
+}
+
+
+/**
+ * devm_thermal_zone_of_sensor_register - Resource managed version of
+ * thermal_zone_of_sensor_register()
+ * @dev: a valid struct device pointer of a sensor device. Must contain
+ * a valid .of_node, for the sensor node.
+ * @sensor_id: a sensor identifier, in case the sensor IP has more
+ * than one sensors
+ * @data: a private pointer (owned by the caller) that will be passed
+ * back, when a temperature reading is needed.
+ * @ops: struct thermal_zone_of_device_ops *. Must contain at least .get_temp.
+ *
+ * Refer thermal_zone_of_sensor_register() for more details.
+ *
+ * Return: On success returns a valid struct thermal_zone_device,
+ * otherwise, it returns a corresponding ERR_PTR(). Caller must
+ * check the return value with help of IS_ERR() helper.
+ * Registered thermal_zone_device device will automatically be
+ * released when device is unbounded.
+ */
+struct thermal_zone_device *devm_thermal_zone_of_sensor_register(
+ struct device *dev, int sensor_id,
+ void *data, const struct thermal_zone_of_device_ops *ops)
+{
+ struct thermal_zone_device **ptr, *tzd;
+
+ ptr = devres_alloc(devm_thermal_zone_of_sensor_release, sizeof(*ptr),
+ GFP_KERNEL);
+ if (!ptr)
+ return ERR_PTR(-ENOMEM);
+
+ tzd = thermal_zone_of_sensor_register(dev, sensor_id, data, ops);
+ if (IS_ERR(tzd)) {
+ devres_free(ptr);
+ return tzd;
+ }
+
+ *ptr = tzd;
+ devres_add(dev, ptr);
+
+ return tzd;
+}
+EXPORT_SYMBOL_GPL(devm_thermal_zone_of_sensor_register);
+
+
/**
* thermal_zone_of_sensor_register - registers a sensor to a DT thermal zone
* @dev: a valid struct device pointer of a sensor device. Must contain
diff --git a/include/linux/thermal.h b/include/linux/thermal.h
index 4a849f19e6c9..b6e9ed8fad72 100644
--- a/include/linux/thermal.h
+++ b/include/linux/thermal.h
@@ -359,6 +359,10 @@ struct thermal_trip {
/* Function declarations */
#ifdef CONFIG_THERMAL_OF
+struct thermal_zone_device *devm_thermal_zone_of_sensor_register(
+ struct device *dev, int id, void *data,
+ const struct thermal_zone_of_device_ops *ops);
+
struct thermal_zone_device *
thermal_zone_of_sensor_register(struct device *dev, int id, void *data,
const struct thermal_zone_of_device_ops *ops);