generic/4.4: remove ISSI SI25CD512 SPI flash support patch
[openwrt.git] / target / linux / mediatek / patches / 0018-thermal-of-always-set-sensor-related-callbacks.patch
1 From 8c9c4ed500e92c10dc4965dcd00692b3102a328a Mon Sep 17 00:00:00 2001
2 From: Sascha Hauer <s.hauer@pengutronix.de>
3 Date: Wed, 13 May 2015 10:52:37 +0200
4 Subject: [PATCH 18/76] thermal: of: always set sensor related callbacks
5
6 Now that the thermal core treats -ENOSYS like the callbacks were
7 not present at all we no longer have to overwrite the ops during
8 runtime but instead can always set them and return -ENOSYS if no
9 sensor is registered.
10
11 Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
12 ---
13  drivers/thermal/of-thermal.c |   33 +++++++++++++--------------------
14  1 file changed, 13 insertions(+), 20 deletions(-)
15
16 --- a/drivers/thermal/of-thermal.c
17 +++ b/drivers/thermal/of-thermal.c
18 @@ -91,7 +91,7 @@ static int of_thermal_get_temp(struct th
19  {
20         struct __thermal_zone *data = tz->devdata;
21  
22 -       if (!data->ops->get_temp)
23 +       if (!data->ops)
24                 return -EINVAL;
25  
26         return data->ops->get_temp(data->sensor_data, temp);
27 @@ -178,7 +178,7 @@ static int of_thermal_set_emul_temp(stru
28         struct __thermal_zone *data = tz->devdata;
29  
30         if (!data->ops || !data->ops->set_emul_temp)
31 -               return -EINVAL;
32 +               return -ENOSYS;
33  
34         return data->ops->set_emul_temp(data->sensor_data, temp);
35  }
36 @@ -189,8 +189,8 @@ static int of_thermal_get_trend(struct t
37         struct __thermal_zone *data = tz->devdata;
38         int r;
39  
40 -       if (!data->ops->get_trend)
41 -               return -EINVAL;
42 +       if (!data->ops || !data->ops->get_trend)
43 +               return -ENOSYS;
44  
45         r = data->ops->get_trend(data->sensor_data, trip, trend);
46         if (r)
47 @@ -366,6 +366,10 @@ static int of_thermal_get_crit_temp(stru
48  }
49  
50  static struct thermal_zone_device_ops of_thermal_ops = {
51 +       .get_temp = of_thermal_get_temp,
52 +       .get_trend = of_thermal_get_trend,
53 +       .set_emul_temp = of_thermal_set_emul_temp,
54 +
55         .get_mode = of_thermal_get_mode,
56         .set_mode = of_thermal_set_mode,
57  
58 @@ -399,13 +403,13 @@ thermal_zone_of_add_sensor(struct device
59         if (!ops)
60                 return ERR_PTR(-EINVAL);
61  
62 +       if (!ops->get_temp)
63 +               return ERR_PTR(-EINVAL);
64 +
65         mutex_lock(&tzd->lock);
66         tz->ops = ops;
67         tz->sensor_data = data;
68  
69 -       tzd->ops->get_temp = of_thermal_get_temp;
70 -       tzd->ops->get_trend = of_thermal_get_trend;
71 -       tzd->ops->set_emul_temp = of_thermal_set_emul_temp;
72         mutex_unlock(&tzd->lock);
73  
74         return tzd;
75 @@ -535,9 +539,6 @@ void thermal_zone_of_sensor_unregister(s
76                 return;
77  
78         mutex_lock(&tzd->lock);
79 -       tzd->ops->get_temp = NULL;
80 -       tzd->ops->get_trend = NULL;
81 -       tzd->ops->set_emul_temp = NULL;
82  
83         tz->ops = NULL;
84         tz->sensor_data = NULL;
85 @@ -845,7 +846,6 @@ int __init of_parse_thermal_zones(void)
86  {
87         struct device_node *np, *child;
88         struct __thermal_zone *tz;
89 -       struct thermal_zone_device_ops *ops;
90  
91         np = of_find_node_by_name(NULL, "thermal-zones");
92         if (!np) {
93 @@ -869,29 +869,22 @@ int __init of_parse_thermal_zones(void)
94                         continue;
95                 }
96  
97 -               ops = kmemdup(&of_thermal_ops, sizeof(*ops), GFP_KERNEL);
98 -               if (!ops)
99 -                       goto exit_free;
100 -
101                 tzp = kzalloc(sizeof(*tzp), GFP_KERNEL);
102 -               if (!tzp) {
103 -                       kfree(ops);
104 +               if (!tzp)
105                         goto exit_free;
106 -               }
107  
108                 /* No hwmon because there might be hwmon drivers registering */
109                 tzp->no_hwmon = true;
110  
111                 zone = thermal_zone_device_register(child->name, tz->ntrips,
112                                                     0, tz,
113 -                                                   ops, tzp,
114 +                                                   &of_thermal_ops, tzp,
115                                                     tz->passive_delay,
116                                                     tz->polling_delay);
117                 if (IS_ERR(zone)) {
118                         pr_err("Failed to build %s zone %ld\n", child->name,
119                                PTR_ERR(zone));
120                         kfree(tzp);
121 -                       kfree(ops);
122                         of_thermal_free_zone(tz);
123                         /* attempting to build remaining zones still */
124                 }