1 From 5b622cb2d6ff44b1fb0750beee61f93f2c00548a Mon Sep 17 00:00:00 2001
2 From: Sascha Hauer <s.hauer@pengutronix.de>
3 Date: Wed, 13 May 2015 10:52:36 +0200
4 Subject: [PATCH 17/76] thermal: Allow sensor ops to fail with -ENOSYS
6 The thermal core uses the existence of the .get_temp, .get_trend and
7 .set_emul_temp to detect whether this operation exists and should be
8 used or whether it should be emulated in software. This makes problems
9 for of-thermal which has to modify the struct thermal_zone_device_ops
10 during runtime whenever a sensor is registered or unregistered.
12 Let the core test for -ENOSYS from these callbacks and treat it like
13 if the callbacks were not present.
15 This allows of-thermal to always set the sensor related callbacks and
16 to make struct thermal_zone_device_ops const again.
18 Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
20 drivers/thermal/thermal_core.c | 24 +++++++++++++++++-------
21 1 file changed, 17 insertions(+), 7 deletions(-)
23 --- a/drivers/thermal/thermal_core.c
24 +++ b/drivers/thermal/thermal_core.c
25 @@ -416,13 +416,16 @@ static void handle_thermal_trip(struct t
27 int thermal_zone_get_temp(struct thermal_zone_device *tz, int *temp)
32 int crit_temp = INT_MAX;
33 enum thermal_trip_type type;
35 - if (!tz || IS_ERR(tz) || !tz->ops->get_temp)
37 + if (!tz || IS_ERR(tz))
40 + if (!tz->ops->get_temp)
43 mutex_lock(&tz->lock);
45 @@ -448,7 +451,7 @@ int thermal_zone_get_temp(struct thermal
48 mutex_unlock(&tz->lock);
53 EXPORT_SYMBOL_GPL(thermal_zone_get_temp);
54 @@ -460,10 +463,11 @@ void thermal_zone_device_update(struct t
55 if (atomic_read(&in_suspend))
58 - if (!tz->ops->get_temp)
59 + ret = thermal_zone_get_temp(tz, &temp);
64 - ret = thermal_zone_get_temp(tz, &temp);
68 @@ -803,10 +807,16 @@ emul_temp_store(struct device *dev, stru
69 if (kstrtoul(buf, 10, &temperature))
72 - if (!tz->ops->set_emul_temp) {
73 + if (tz->ops->set_emul_temp)
74 + ret = tz->ops->set_emul_temp(tz, temperature);
78 + if (ret == -ENOSYS) {
79 mutex_lock(&tz->lock);
80 tz->emul_temperature = temperature;
81 mutex_unlock(&tz->lock);
84 ret = tz->ops->set_emul_temp(tz, temperature);