e47e8a27f049f52a07ae83b1026432c52c9e7851
[openwrt/svn-archive/archive.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 diff --git a/drivers/thermal/of-thermal.c b/drivers/thermal/of-thermal.c
17 index c84404d..b9c35bd 100644
18 --- a/drivers/thermal/of-thermal.c
19 +++ b/drivers/thermal/of-thermal.c
20 @@ -91,7 +91,7 @@ static int of_thermal_get_temp(struct thermal_zone_device *tz,
21 {
22 struct __thermal_zone *data = tz->devdata;
23
24 - if (!data->ops->get_temp)
25 + if (!data->ops)
26 return -EINVAL;
27
28 return data->ops->get_temp(data->sensor_data, temp);
29 @@ -178,7 +178,7 @@ static int of_thermal_set_emul_temp(struct thermal_zone_device *tz,
30 struct __thermal_zone *data = tz->devdata;
31
32 if (!data->ops || !data->ops->set_emul_temp)
33 - return -EINVAL;
34 + return -ENOSYS;
35
36 return data->ops->set_emul_temp(data->sensor_data, temp);
37 }
38 @@ -189,8 +189,8 @@ static int of_thermal_get_trend(struct thermal_zone_device *tz, int trip,
39 struct __thermal_zone *data = tz->devdata;
40 int r;
41
42 - if (!data->ops->get_trend)
43 - return -EINVAL;
44 + if (!data->ops || !data->ops->get_trend)
45 + return -ENOSYS;
46
47 r = data->ops->get_trend(data->sensor_data, trip, trend);
48 if (r)
49 @@ -366,6 +366,10 @@ static int of_thermal_get_crit_temp(struct thermal_zone_device *tz,
50 }
51
52 static struct thermal_zone_device_ops of_thermal_ops = {
53 + .get_temp = of_thermal_get_temp,
54 + .get_trend = of_thermal_get_trend,
55 + .set_emul_temp = of_thermal_set_emul_temp,
56 +
57 .get_mode = of_thermal_get_mode,
58 .set_mode = of_thermal_set_mode,
59
60 @@ -399,13 +403,13 @@ thermal_zone_of_add_sensor(struct device_node *zone,
61 if (!ops)
62 return ERR_PTR(-EINVAL);
63
64 + if (!ops->get_temp)
65 + return ERR_PTR(-EINVAL);
66 +
67 mutex_lock(&tzd->lock);
68 tz->ops = ops;
69 tz->sensor_data = data;
70
71 - tzd->ops->get_temp = of_thermal_get_temp;
72 - tzd->ops->get_trend = of_thermal_get_trend;
73 - tzd->ops->set_emul_temp = of_thermal_set_emul_temp;
74 mutex_unlock(&tzd->lock);
75
76 return tzd;
77 @@ -535,9 +539,6 @@ void thermal_zone_of_sensor_unregister(struct device *dev,
78 return;
79
80 mutex_lock(&tzd->lock);
81 - tzd->ops->get_temp = NULL;
82 - tzd->ops->get_trend = NULL;
83 - tzd->ops->set_emul_temp = NULL;
84
85 tz->ops = NULL;
86 tz->sensor_data = NULL;
87 @@ -845,7 +846,6 @@ int __init of_parse_thermal_zones(void)
88 {
89 struct device_node *np, *child;
90 struct __thermal_zone *tz;
91 - struct thermal_zone_device_ops *ops;
92
93 np = of_find_node_by_name(NULL, "thermal-zones");
94 if (!np) {
95 @@ -869,29 +869,22 @@ int __init of_parse_thermal_zones(void)
96 continue;
97 }
98
99 - ops = kmemdup(&of_thermal_ops, sizeof(*ops), GFP_KERNEL);
100 - if (!ops)
101 - goto exit_free;
102 -
103 tzp = kzalloc(sizeof(*tzp), GFP_KERNEL);
104 - if (!tzp) {
105 - kfree(ops);
106 + if (!tzp)
107 goto exit_free;
108 - }
109
110 /* No hwmon because there might be hwmon drivers registering */
111 tzp->no_hwmon = true;
112
113 zone = thermal_zone_device_register(child->name, tz->ntrips,
114 0, tz,
115 - ops, tzp,
116 + &of_thermal_ops, tzp,
117 tz->passive_delay,
118 tz->polling_delay);
119 if (IS_ERR(zone)) {
120 pr_err("Failed to build %s zone %ld\n", child->name,
121 PTR_ERR(zone));
122 kfree(tzp);
123 - kfree(ops);
124 of_thermal_free_zone(tz);
125 /* attempting to build remaining zones still */
126 }
127 --
128 1.7.10.4
129