hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/hwmon/adm1029.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0
12 /*
23 * adm1029.c - Part of lm_sensors, Linux kernel modules for hardware monitoring
34 *
....@@ -9,20 +10,6 @@
910 * Very rare chip please let me know if you use it
1011 *
1112 * http://www.analog.com/UploadedFiles/Data_Sheets/ADM1029.pdf
12
- *
13
- *
14
- * This program is free software; you can redistribute it and/or modify
15
- * it under the terms of the GNU General Public License as published by
16
- * the Free Software Foundation version 2 of the License
17
- *
18
- * This program is distributed in the hope that it will be useful,
19
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
- * GNU General Public License for more details.
22
- *
23
- * You should have received a copy of the GNU General Public License
24
- * along with this program; if not, write to the Free Software
25
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
2613 */
2714
2815 #include <linux/module.h>
....@@ -111,7 +98,7 @@
11198
11299 struct adm1029_data {
113100 struct i2c_client *client;
114
- struct mutex update_lock;
101
+ struct mutex update_lock; /* protect register access */
115102 char valid; /* zero until following fields are valid */
116103 unsigned long last_updated; /* in jiffies */
117104
....@@ -134,8 +121,7 @@
134121 * Use the "cache" Luke, don't recheck values
135122 * if there are already checked not a long time later
136123 */
137
- if (time_after(jiffies, data->last_updated + HZ * 2)
138
- || !data->valid) {
124
+ if (time_after(jiffies, data->last_updated + HZ * 2) || !data->valid) {
139125 int nr;
140126
141127 dev_dbg(&client->dev, "Updating adm1029 data\n");
....@@ -170,22 +156,24 @@
170156 */
171157
172158 static ssize_t
173
-show_temp(struct device *dev, struct device_attribute *devattr, char *buf)
159
+temp_show(struct device *dev, struct device_attribute *devattr, char *buf)
174160 {
175161 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
176162 struct adm1029_data *data = adm1029_update_device(dev);
163
+
177164 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp[attr->index]));
178165 }
179166
180167 static ssize_t
181
-show_fan(struct device *dev, struct device_attribute *devattr, char *buf)
168
+fan_show(struct device *dev, struct device_attribute *devattr, char *buf)
182169 {
183170 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
184171 struct adm1029_data *data = adm1029_update_device(dev);
185172 u16 val;
186
- if (data->fan[attr->index] == 0
187
- || (data->fan_div[attr->index] & 0xC0) == 0
188
- || data->fan[attr->index] == 255) {
173
+
174
+ if (data->fan[attr->index] == 0 ||
175
+ (data->fan_div[attr->index] & 0xC0) == 0 ||
176
+ data->fan[attr->index] == 255) {
189177 return sprintf(buf, "0\n");
190178 }
191179
....@@ -195,17 +183,19 @@
195183 }
196184
197185 static ssize_t
198
-show_fan_div(struct device *dev, struct device_attribute *devattr, char *buf)
186
+fan_div_show(struct device *dev, struct device_attribute *devattr, char *buf)
199187 {
200188 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
201189 struct adm1029_data *data = adm1029_update_device(dev);
190
+
202191 if ((data->fan_div[attr->index] & 0xC0) == 0)
203192 return sprintf(buf, "0\n");
204193 return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[attr->index]));
205194 }
206195
207
-static ssize_t set_fan_div(struct device *dev,
208
- struct device_attribute *devattr, const char *buf, size_t count)
196
+static ssize_t fan_div_store(struct device *dev,
197
+ struct device_attribute *devattr,
198
+ const char *buf, size_t count)
209199 {
210200 struct adm1029_data *data = dev_get_drvdata(dev);
211201 struct i2c_client *client = data->client;
....@@ -213,6 +203,7 @@
213203 u8 reg;
214204 long val;
215205 int ret = kstrtol(buf, 10, &val);
206
+
216207 if (ret < 0)
217208 return ret;
218209
....@@ -253,32 +244,27 @@
253244 return count;
254245 }
255246
256
-/*
257
- * Access rights on sysfs. S_IRUGO: Is Readable by User, Group and Others
258
- * S_IWUSR: Is Writable by User.
259
- */
260
-static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL, 0);
261
-static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, show_temp, NULL, 1);
262
-static SENSOR_DEVICE_ATTR(temp3_input, S_IRUGO, show_temp, NULL, 2);
247
+/* Access rights on sysfs. */
248
+static SENSOR_DEVICE_ATTR_RO(temp1_input, temp, 0);
249
+static SENSOR_DEVICE_ATTR_RO(temp2_input, temp, 1);
250
+static SENSOR_DEVICE_ATTR_RO(temp3_input, temp, 2);
263251
264
-static SENSOR_DEVICE_ATTR(temp1_max, S_IRUGO, show_temp, NULL, 3);
265
-static SENSOR_DEVICE_ATTR(temp2_max, S_IRUGO, show_temp, NULL, 4);
266
-static SENSOR_DEVICE_ATTR(temp3_max, S_IRUGO, show_temp, NULL, 5);
252
+static SENSOR_DEVICE_ATTR_RO(temp1_max, temp, 3);
253
+static SENSOR_DEVICE_ATTR_RO(temp2_max, temp, 4);
254
+static SENSOR_DEVICE_ATTR_RO(temp3_max, temp, 5);
267255
268
-static SENSOR_DEVICE_ATTR(temp1_min, S_IRUGO, show_temp, NULL, 6);
269
-static SENSOR_DEVICE_ATTR(temp2_min, S_IRUGO, show_temp, NULL, 7);
270
-static SENSOR_DEVICE_ATTR(temp3_min, S_IRUGO, show_temp, NULL, 8);
256
+static SENSOR_DEVICE_ATTR_RO(temp1_min, temp, 6);
257
+static SENSOR_DEVICE_ATTR_RO(temp2_min, temp, 7);
258
+static SENSOR_DEVICE_ATTR_RO(temp3_min, temp, 8);
271259
272
-static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, show_fan, NULL, 0);
273
-static SENSOR_DEVICE_ATTR(fan2_input, S_IRUGO, show_fan, NULL, 1);
260
+static SENSOR_DEVICE_ATTR_RO(fan1_input, fan, 0);
261
+static SENSOR_DEVICE_ATTR_RO(fan2_input, fan, 1);
274262
275
-static SENSOR_DEVICE_ATTR(fan1_min, S_IRUGO, show_fan, NULL, 2);
276
-static SENSOR_DEVICE_ATTR(fan2_min, S_IRUGO, show_fan, NULL, 3);
263
+static SENSOR_DEVICE_ATTR_RO(fan1_min, fan, 2);
264
+static SENSOR_DEVICE_ATTR_RO(fan2_min, fan, 3);
277265
278
-static SENSOR_DEVICE_ATTR(fan1_div, S_IRUGO | S_IWUSR,
279
- show_fan_div, set_fan_div, 0);
280
-static SENSOR_DEVICE_ATTR(fan2_div, S_IRUGO | S_IWUSR,
281
- show_fan_div, set_fan_div, 1);
266
+static SENSOR_DEVICE_ATTR_RW(fan1_div, fan_div, 0);
267
+static SENSOR_DEVICE_ATTR_RW(fan2_div, fan_div, 1);
282268
283269 static struct attribute *adm1029_attrs[] = {
284270 &sensor_dev_attr_temp1_input.dev_attr.attr,
....@@ -327,10 +313,10 @@
327313 temp_devices_installed = i2c_smbus_read_byte_data(client,
328314 ADM1029_REG_TEMP_DEVICES_INSTALLED);
329315 nb_fan_support = i2c_smbus_read_byte_data(client,
330
- ADM1029_REG_NB_FAN_SUPPORT);
316
+ ADM1029_REG_NB_FAN_SUPPORT);
331317 /* 0x41 is Analog Devices */
332
- if (man_id != 0x41 || (temp_devices_installed & 0xf9) != 0x01
333
- || nb_fan_support != 0x03)
318
+ if (man_id != 0x41 || (temp_devices_installed & 0xf9) != 0x01 ||
319
+ nb_fan_support != 0x03)
334320 return -ENODEV;
335321
336322 if ((chip_id & 0xF0) != 0x00) {
....@@ -366,8 +352,7 @@
366352 return 1;
367353 }
368354
369
-static int adm1029_probe(struct i2c_client *client,
370
- const struct i2c_device_id *id)
355
+static int adm1029_probe(struct i2c_client *client)
371356 {
372357 struct device *dev = &client->dev;
373358 struct adm1029_data *data;
....@@ -404,7 +389,7 @@
404389 .driver = {
405390 .name = "adm1029",
406391 },
407
- .probe = adm1029_probe,
392
+ .probe_new = adm1029_probe,
408393 .id_table = adm1029_id,
409394 .detect = adm1029_detect,
410395 .address_list = normal_i2c,