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 diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c
24 index 19da022..3d8f9f9 100644
25 --- a/drivers/thermal/thermal_core.c
26 +++ b/drivers/thermal/thermal_core.c
27 @@ -413,13 +413,16 @@ static void handle_thermal_trip(struct thermal_zone_device *tz, int trip)
29 int thermal_zone_get_temp(struct thermal_zone_device *tz, int *temp)
34 int crit_temp = INT_MAX;
35 enum thermal_trip_type type;
37 - if (!tz || IS_ERR(tz) || !tz->ops->get_temp)
39 + if (!tz || IS_ERR(tz))
42 + if (!tz->ops->get_temp)
45 mutex_lock(&tz->lock);
47 @@ -445,7 +448,7 @@ int thermal_zone_get_temp(struct thermal_zone_device *tz, int *temp)
50 mutex_unlock(&tz->lock);
55 EXPORT_SYMBOL_GPL(thermal_zone_get_temp);
56 @@ -454,10 +457,11 @@ void thermal_zone_device_update(struct thermal_zone_device *tz)
60 - if (!tz->ops->get_temp)
61 + ret = thermal_zone_get_temp(tz, &temp);
66 - ret = thermal_zone_get_temp(tz, &temp);
70 @@ -783,10 +787,16 @@ emul_temp_store(struct device *dev, struct device_attribute *attr,
71 if (kstrtoul(buf, 10, &temperature))
74 - if (!tz->ops->set_emul_temp) {
75 + if (tz->ops->set_emul_temp)
76 + ret = tz->ops->set_emul_temp(tz, temperature);
80 + if (ret == -ENOSYS) {
81 mutex_lock(&tz->lock);
82 tz->emul_temperature = temperature;
83 mutex_unlock(&tz->lock);
86 ret = tz->ops->set_emul_temp(tz, temperature);