1 From: Wei Ni <wni@nvidia.com>
2 Subject: hwmon: lm90: expose to thermal fw via DT nodes
4 This patch adds to lm90 temperature sensor the possibility
5 to expose itself as thermal zone device, registered on the
8 The thermal zone is built only if a device tree node
9 describing a thermal zone for this sensor is present
10 inside the lm90 DT node. Otherwise, the driver behavior
14 http://www.gossamer-threads.com/lists/linux/kernel/1992853
16 BUG=chrome-os-partner:30834
17 TEST=Verified. Build and boot up system.
19 Signed-off-by: Wei Ni <wni@nvidia.com>
20 Reviewed-on: https://chromium-review.googlesource.com/181447
21 Reviewed-by: Dylan Reid <dgreid@chromium.org>
22 Tested-by: Dylan Reid <dgreid@chromium.org>
23 Commit-Queue: Dylan Reid <dgreid@chromium.org>
24 Change-Id: Id356b94d7e8f4b49ec15e46b17a1fa2ff0cbf8cf
25 Reviewed-on: https://chromium-review.googlesource.com/212414
26 Tested-by: Wei Ni <wni.nvidia@gmail.com>
27 Reviewed-by: Olof Johansson <olofj@chromium.org>
28 Commit-Queue: Olof Johansson <olofj@chromium.org>
30 --- a/drivers/hwmon/lm90.c
31 +++ b/drivers/hwmon/lm90.c
33 #include <linux/sysfs.h>
34 #include <linux/interrupt.h>
35 #include <linux/regulator/consumer.h>
36 +#include <linux/of.h>
37 +#include <linux/thermal.h>
41 @@ -119,6 +121,13 @@ static const unsigned short normal_i2c[]
42 enum chips { lm90, adm1032, lm99, lm86, max6657, max6659, adt7461, max6680,
43 max6646, w83l771, max6696, sa56004, g781, tmp451 };
55 @@ -368,6 +377,7 @@ struct lm90_data {
56 struct i2c_client *client;
57 struct device *hwmon_dev;
58 const struct attribute_group *groups[6];
59 + struct thermal_zone_device *tz[SENSOR_ID_END];
60 struct mutex update_lock;
61 struct regulator *regulator;
62 char valid; /* zero until following fields are valid */
63 @@ -880,6 +890,24 @@ static ssize_t show_temp11(struct device
64 return sprintf(buf, "%d\n", read_temp11(dev, attr->index));
67 +static int lm90_read_local_temp(void *dev, int *temp)
69 + *temp = read_temp11(dev, 4);
73 +static int lm90_read_remote_temp(void *dev, int *temp)
75 + *temp = read_temp11(dev, 0);
79 +static int lm90_read_remote2_temp(void *dev, int *temp)
81 + *temp = read_temp11(dev, 5);
85 static int write_temp11(struct device *dev, int nr, int index, long val)
88 @@ -1210,6 +1238,18 @@ static const struct attribute_group lm90
89 .attrs = lm90_temp3_attributes,
92 +static const struct thermal_zone_of_device_ops local_temp_sensor = {
93 + .get_temp = lm90_read_local_temp,
96 +static const struct thermal_zone_of_device_ops remote_temp_sensor = {
97 + .get_temp = lm90_read_remote_temp,
100 +static const struct thermal_zone_of_device_ops remote2_temp_sensor = {
101 + .get_temp = lm90_read_remote2_temp,
104 /* pec used for ADM1032 only */
105 static ssize_t show_pec(struct device *dev, struct device_attribute *dummy,
107 @@ -1659,6 +1699,30 @@ static int lm90_probe(struct i2c_client
111 + data->tz[LOCAL] = thermal_zone_of_sensor_register(&client->dev,
114 + &local_temp_sensor);
115 + if (IS_ERR(data->tz[LOCAL]))
116 + data->tz[LOCAL] = NULL;
118 + data->tz[REMOTE] = thermal_zone_of_sensor_register(&client->dev,
121 + &remote_temp_sensor);
122 + if (IS_ERR(data->tz[REMOTE]))
123 + data->tz[REMOTE] = NULL;
125 + if (data->flags & LM90_HAVE_TEMP3) {
126 + data->tz[REMOTE2] = thermal_zone_of_sensor_register(
130 + &remote2_temp_sensor);
131 + if (IS_ERR(data->tz[REMOTE2]))
132 + data->tz[REMOTE2] = NULL;
138 @@ -1674,8 +1738,11 @@ exit_restore:
140 static int lm90_remove(struct i2c_client *client)
143 struct lm90_data *data = i2c_get_clientdata(client);
145 + for (i = 0; i < SENSOR_ID_END; i++)
146 + thermal_zone_of_sensor_unregister(&client->dev, data->tz[i]);
147 hwmon_device_unregister(data->hwmon_dev);
148 device_remove_file(&client->dev, &dev_attr_pec);
149 lm90_restore_conf(client, data);