mediatek: add support for the new MT7623 Arm SoC
[openwrt/staging/wigyori.git] / target / linux / mediatek / patches / 0017-thermal-Allow-sensor-ops-to-fail-with-ENOSYS.patch
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
5
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.
11
12 Let the core test for -ENOSYS from these callbacks and treat it like
13 if the callbacks were not present.
14
15 This allows of-thermal to always set the sensor related callbacks and
16 to make struct thermal_zone_device_ops const again.
17
18 Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
19 ---
20 drivers/thermal/thermal_core.c | 24 +++++++++++++++++-------
21 1 file changed, 17 insertions(+), 7 deletions(-)
22
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)
28 */
29 int thermal_zone_get_temp(struct thermal_zone_device *tz, int *temp)
30 {
31 - int ret = -EINVAL;
32 + int ret;
33 int count;
34 int crit_temp = INT_MAX;
35 enum thermal_trip_type type;
36
37 - if (!tz || IS_ERR(tz) || !tz->ops->get_temp)
38 - goto exit;
39 + if (!tz || IS_ERR(tz))
40 + return -EINVAL;
41 +
42 + if (!tz->ops->get_temp)
43 + return -ENOSYS;
44
45 mutex_lock(&tz->lock);
46
47 @@ -445,7 +448,7 @@ int thermal_zone_get_temp(struct thermal_zone_device *tz, int *temp)
48 }
49
50 mutex_unlock(&tz->lock);
51 -exit:
52 +
53 return ret;
54 }
55 EXPORT_SYMBOL_GPL(thermal_zone_get_temp);
56 @@ -454,10 +457,11 @@ void thermal_zone_device_update(struct thermal_zone_device *tz)
57 {
58 int temp, ret, count;
59
60 - if (!tz->ops->get_temp)
61 + ret = thermal_zone_get_temp(tz, &temp);
62 +
63 + if (ret == -ENOSYS)
64 return;
65
66 - ret = thermal_zone_get_temp(tz, &temp);
67 if (ret) {
68 if (ret != -EAGAIN)
69 dev_warn(&tz->device,
70 @@ -783,10 +787,16 @@ emul_temp_store(struct device *dev, struct device_attribute *attr,
71 if (kstrtoul(buf, 10, &temperature))
72 return -EINVAL;
73
74 - if (!tz->ops->set_emul_temp) {
75 + if (tz->ops->set_emul_temp)
76 + ret = tz->ops->set_emul_temp(tz, temperature);
77 + else
78 + ret = -ENOSYS;
79 +
80 + if (ret == -ENOSYS) {
81 mutex_lock(&tz->lock);
82 tz->emul_temperature = temperature;
83 mutex_unlock(&tz->lock);
84 + ret = 0;
85 } else {
86 ret = tz->ops->set_emul_temp(tz, temperature);
87 }
88 --
89 1.7.10.4
90