generic/4.4: remove ISSI SI25CD512 SPI flash support patch
[openwrt.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 --- 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
26   */
27  int thermal_zone_get_temp(struct thermal_zone_device *tz, int *temp)
28  {
29 -       int ret = -EINVAL;
30 +       int ret;
31         int count;
32         int crit_temp = INT_MAX;
33         enum thermal_trip_type type;
34  
35 -       if (!tz || IS_ERR(tz) || !tz->ops->get_temp)
36 -               goto exit;
37 +       if (!tz || IS_ERR(tz))
38 +               return -EINVAL;
39 +
40 +       if (!tz->ops->get_temp)
41 +               return -ENOSYS;
42  
43         mutex_lock(&tz->lock);
44  
45 @@ -448,7 +451,7 @@ int thermal_zone_get_temp(struct thermal
46         }
47   
48         mutex_unlock(&tz->lock);
49 -exit:
50 +
51         return ret;
52  }
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))
56                 return;
57  
58 -       if (!tz->ops->get_temp)
59 +       ret = thermal_zone_get_temp(tz, &temp);
60 +
61 +       if (ret == -ENOSYS)
62                 return;
63  
64 -       ret = thermal_zone_get_temp(tz, &temp);
65         if (ret) {
66                 if (ret != -EAGAIN)
67                         dev_warn(&tz->device,
68 @@ -803,10 +807,16 @@ emul_temp_store(struct device *dev, stru
69         if (kstrtoul(buf, 10, &temperature))
70                 return -EINVAL;
71  
72 -       if (!tz->ops->set_emul_temp) {
73 +       if (tz->ops->set_emul_temp)
74 +               ret = tz->ops->set_emul_temp(tz, temperature);
75 +       else
76 +               ret = -ENOSYS;
77 +
78 +       if (ret == -ENOSYS) {
79                 mutex_lock(&tz->lock);
80                 tz->emul_temperature = temperature;
81                 mutex_unlock(&tz->lock);
82 +               ret = 0;
83         } else {
84                 ret = tz->ops->set_emul_temp(tz, temperature);
85         }