hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/hwmon/tmp421.c
....@@ -1,18 +1,9 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /* tmp421.c
23 *
34 * Copyright (C) 2009 Andre Prendel <andre.prendel@gmx.de>
45 * Preliminary support by:
56 * Melvin Rook, Raymond Ng
6
- *
7
- * This program is free software; you can redistribute it and/or modify
8
- * it under the terms of the GNU General Public License as published by
9
- * the Free Software Foundation; either version 2 of the License, or
10
- * (at your option) any later version.
11
- *
12
- * This program is distributed in the hope that it will be useful,
13
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
- * GNU General Public License for more details.
167 */
178
189 /*
....@@ -70,7 +61,7 @@
7061 };
7162 MODULE_DEVICE_TABLE(i2c, tmp421_id);
7263
73
-static const struct of_device_id tmp421_of_match[] = {
64
+static const struct of_device_id __maybe_unused tmp421_of_match[] = {
7465 {
7566 .compatible = "ti,tmp421",
7667 .data = (void *)2
....@@ -122,37 +113,56 @@
122113 return DIV_ROUND_CLOSEST(temp * 1000, 256);
123114 }
124115
125
-static struct tmp421_data *tmp421_update_device(struct device *dev)
116
+static int tmp421_update_device(struct tmp421_data *data)
126117 {
127
- struct tmp421_data *data = dev_get_drvdata(dev);
128118 struct i2c_client *client = data->client;
119
+ int ret = 0;
129120 int i;
130121
131122 mutex_lock(&data->update_lock);
132123
133
- if (time_after(jiffies, data->last_updated + 2 * HZ) || !data->valid) {
134
- data->config = i2c_smbus_read_byte_data(client,
135
- TMP421_CONFIG_REG_1);
124
+ if (time_after(jiffies, data->last_updated + (HZ / 2)) ||
125
+ !data->valid) {
126
+ ret = i2c_smbus_read_byte_data(client, TMP421_CONFIG_REG_1);
127
+ if (ret < 0)
128
+ goto exit;
129
+ data->config = ret;
136130
137131 for (i = 0; i < data->channels; i++) {
138
- data->temp[i] = i2c_smbus_read_byte_data(client,
139
- TMP421_TEMP_MSB[i]) << 8;
140
- data->temp[i] |= i2c_smbus_read_byte_data(client,
141
- TMP421_TEMP_LSB[i]);
132
+ ret = i2c_smbus_read_byte_data(client, TMP421_TEMP_MSB[i]);
133
+ if (ret < 0)
134
+ goto exit;
135
+ data->temp[i] = ret << 8;
136
+
137
+ ret = i2c_smbus_read_byte_data(client, TMP421_TEMP_LSB[i]);
138
+ if (ret < 0)
139
+ goto exit;
140
+ data->temp[i] |= ret;
142141 }
143142 data->last_updated = jiffies;
144143 data->valid = 1;
145144 }
146145
146
+exit:
147147 mutex_unlock(&data->update_lock);
148148
149
- return data;
149
+ if (ret < 0) {
150
+ data->valid = 0;
151
+ return ret;
152
+ }
153
+
154
+ return 0;
150155 }
151156
152157 static int tmp421_read(struct device *dev, enum hwmon_sensor_types type,
153158 u32 attr, int channel, long *val)
154159 {
155
- struct tmp421_data *tmp421 = tmp421_update_device(dev);
160
+ struct tmp421_data *tmp421 = dev_get_drvdata(dev);
161
+ int ret = 0;
162
+
163
+ ret = tmp421_update_device(tmp421);
164
+ if (ret)
165
+ return ret;
156166
157167 switch (attr) {
158168 case hwmon_temp_input:
....@@ -215,8 +225,10 @@
215225 {
216226 enum chips kind;
217227 struct i2c_adapter *adapter = client->adapter;
218
- const char * const names[] = { "TMP421", "TMP422", "TMP423",
219
- "TMP441", "TMP442" };
228
+ static const char * const names[] = {
229
+ "TMP421", "TMP422", "TMP423",
230
+ "TMP441", "TMP442"
231
+ };
220232 int addr = client->addr;
221233 u8 reg;
222234
....@@ -274,8 +286,7 @@
274286 .read = tmp421_read,
275287 };
276288
277
-static int tmp421_probe(struct i2c_client *client,
278
- const struct i2c_device_id *id)
289
+static int tmp421_probe(struct i2c_client *client)
279290 {
280291 struct device *dev = &client->dev;
281292 struct device *hwmon_dev;
....@@ -291,7 +302,7 @@
291302 data->channels = (unsigned long)
292303 of_device_get_match_data(&client->dev);
293304 else
294
- data->channels = id->driver_data;
305
+ data->channels = i2c_match_id(tmp421_id, client)->driver_data;
295306 data->client = client;
296307
297308 err = tmp421_init_client(client);
....@@ -322,7 +333,7 @@
322333 .name = "tmp421",
323334 .of_match_table = of_match_ptr(tmp421_of_match),
324335 },
325
- .probe = tmp421_probe,
336
+ .probe_new = tmp421_probe,
326337 .id_table = tmp421_id,
327338 .detect = tmp421_detect,
328339 .address_list = normal_i2c,