hc
2024-05-13 9d77db3c730780c8ef5ccd4b66403ff5675cfe4e
kernel/drivers/hwmon/smsc47m192.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * smsc47m192.c - Support for hardware monitoring block of
34 * SMSC LPC47M192 and compatible Super I/O chips
....@@ -5,20 +6,6 @@
56 * Copyright (C) 2006 Hartmut Rick <linux@rick.claranet.de>
67 *
78 * Derived from lm78.c and other chip drivers.
8
- *
9
- * This program is free software; you can redistribute it and/or modify
10
- * it under the terms of the GNU General Public License as published by
11
- * the Free Software Foundation; either version 2 of the License, or
12
- * (at your option) any later version.
13
- *
14
- * This program is distributed in the hope that it will be useful,
15
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
- * GNU General Public License for more details.
18
- *
19
- * You should have received a copy of the GNU General Public License
20
- * along with this program; if not, write to the Free Software
21
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
229 */
2310
2411 #include <linux/module.h>
....@@ -179,8 +166,8 @@
179166 }
180167
181168 /* Voltages */
182
-static ssize_t show_in(struct device *dev, struct device_attribute *attr,
183
- char *buf)
169
+static ssize_t in_show(struct device *dev, struct device_attribute *attr,
170
+ char *buf)
184171 {
185172 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
186173 int nr = sensor_attr->index;
....@@ -188,8 +175,8 @@
188175 return sprintf(buf, "%d\n", IN_FROM_REG(data->in[nr], nr));
189176 }
190177
191
-static ssize_t show_in_min(struct device *dev, struct device_attribute *attr,
192
- char *buf)
178
+static ssize_t in_min_show(struct device *dev, struct device_attribute *attr,
179
+ char *buf)
193180 {
194181 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
195182 int nr = sensor_attr->index;
....@@ -197,8 +184,8 @@
197184 return sprintf(buf, "%d\n", IN_FROM_REG(data->in_min[nr], nr));
198185 }
199186
200
-static ssize_t show_in_max(struct device *dev, struct device_attribute *attr,
201
- char *buf)
187
+static ssize_t in_max_show(struct device *dev, struct device_attribute *attr,
188
+ char *buf)
202189 {
203190 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
204191 int nr = sensor_attr->index;
....@@ -206,8 +193,8 @@
206193 return sprintf(buf, "%d\n", IN_FROM_REG(data->in_max[nr], nr));
207194 }
208195
209
-static ssize_t set_in_min(struct device *dev, struct device_attribute *attr,
210
- const char *buf, size_t count)
196
+static ssize_t in_min_store(struct device *dev, struct device_attribute *attr,
197
+ const char *buf, size_t count)
211198 {
212199 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
213200 int nr = sensor_attr->index;
....@@ -228,8 +215,8 @@
228215 return count;
229216 }
230217
231
-static ssize_t set_in_max(struct device *dev, struct device_attribute *attr,
232
- const char *buf, size_t count)
218
+static ssize_t in_max_store(struct device *dev, struct device_attribute *attr,
219
+ const char *buf, size_t count)
233220 {
234221 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
235222 int nr = sensor_attr->index;
....@@ -250,26 +237,34 @@
250237 return count;
251238 }
252239
253
-#define show_in_offset(offset) \
254
-static SENSOR_DEVICE_ATTR(in##offset##_input, S_IRUGO, \
255
- show_in, NULL, offset); \
256
-static SENSOR_DEVICE_ATTR(in##offset##_min, S_IRUGO | S_IWUSR, \
257
- show_in_min, set_in_min, offset); \
258
-static SENSOR_DEVICE_ATTR(in##offset##_max, S_IRUGO | S_IWUSR, \
259
- show_in_max, set_in_max, offset);
260
-
261
-show_in_offset(0)
262
-show_in_offset(1)
263
-show_in_offset(2)
264
-show_in_offset(3)
265
-show_in_offset(4)
266
-show_in_offset(5)
267
-show_in_offset(6)
268
-show_in_offset(7)
240
+static SENSOR_DEVICE_ATTR_RO(in0_input, in, 0);
241
+static SENSOR_DEVICE_ATTR_RW(in0_min, in_min, 0);
242
+static SENSOR_DEVICE_ATTR_RW(in0_max, in_max, 0);
243
+static SENSOR_DEVICE_ATTR_RO(in1_input, in, 1);
244
+static SENSOR_DEVICE_ATTR_RW(in1_min, in_min, 1);
245
+static SENSOR_DEVICE_ATTR_RW(in1_max, in_max, 1);
246
+static SENSOR_DEVICE_ATTR_RO(in2_input, in, 2);
247
+static SENSOR_DEVICE_ATTR_RW(in2_min, in_min, 2);
248
+static SENSOR_DEVICE_ATTR_RW(in2_max, in_max, 2);
249
+static SENSOR_DEVICE_ATTR_RO(in3_input, in, 3);
250
+static SENSOR_DEVICE_ATTR_RW(in3_min, in_min, 3);
251
+static SENSOR_DEVICE_ATTR_RW(in3_max, in_max, 3);
252
+static SENSOR_DEVICE_ATTR_RO(in4_input, in, 4);
253
+static SENSOR_DEVICE_ATTR_RW(in4_min, in_min, 4);
254
+static SENSOR_DEVICE_ATTR_RW(in4_max, in_max, 4);
255
+static SENSOR_DEVICE_ATTR_RO(in5_input, in, 5);
256
+static SENSOR_DEVICE_ATTR_RW(in5_min, in_min, 5);
257
+static SENSOR_DEVICE_ATTR_RW(in5_max, in_max, 5);
258
+static SENSOR_DEVICE_ATTR_RO(in6_input, in, 6);
259
+static SENSOR_DEVICE_ATTR_RW(in6_min, in_min, 6);
260
+static SENSOR_DEVICE_ATTR_RW(in6_max, in_max, 6);
261
+static SENSOR_DEVICE_ATTR_RO(in7_input, in, 7);
262
+static SENSOR_DEVICE_ATTR_RW(in7_min, in_min, 7);
263
+static SENSOR_DEVICE_ATTR_RW(in7_max, in_max, 7);
269264
270265 /* Temperatures */
271
-static ssize_t show_temp(struct device *dev, struct device_attribute *attr,
272
- char *buf)
266
+static ssize_t temp_show(struct device *dev, struct device_attribute *attr,
267
+ char *buf)
273268 {
274269 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
275270 int nr = sensor_attr->index;
....@@ -277,8 +272,8 @@
277272 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp[nr]));
278273 }
279274
280
-static ssize_t show_temp_min(struct device *dev, struct device_attribute *attr,
281
- char *buf)
275
+static ssize_t temp_min_show(struct device *dev,
276
+ struct device_attribute *attr, char *buf)
282277 {
283278 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
284279 int nr = sensor_attr->index;
....@@ -286,8 +281,8 @@
286281 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_min[nr]));
287282 }
288283
289
-static ssize_t show_temp_max(struct device *dev, struct device_attribute *attr,
290
- char *buf)
284
+static ssize_t temp_max_show(struct device *dev,
285
+ struct device_attribute *attr, char *buf)
291286 {
292287 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
293288 int nr = sensor_attr->index;
....@@ -295,8 +290,9 @@
295290 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_max[nr]));
296291 }
297292
298
-static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr,
299
- const char *buf, size_t count)
293
+static ssize_t temp_min_store(struct device *dev,
294
+ struct device_attribute *attr, const char *buf,
295
+ size_t count)
300296 {
301297 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
302298 int nr = sensor_attr->index;
....@@ -317,8 +313,9 @@
317313 return count;
318314 }
319315
320
-static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr,
321
- const char *buf, size_t count)
316
+static ssize_t temp_max_store(struct device *dev,
317
+ struct device_attribute *attr, const char *buf,
318
+ size_t count)
322319 {
323320 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
324321 int nr = sensor_attr->index;
....@@ -339,8 +336,8 @@
339336 return count;
340337 }
341338
342
-static ssize_t show_temp_offset(struct device *dev, struct device_attribute
343
- *attr, char *buf)
339
+static ssize_t temp_offset_show(struct device *dev,
340
+ struct device_attribute *attr, char *buf)
344341 {
345342 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
346343 int nr = sensor_attr->index;
....@@ -348,8 +345,9 @@
348345 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_offset[nr]));
349346 }
350347
351
-static ssize_t set_temp_offset(struct device *dev, struct device_attribute
352
- *attr, const char *buf, size_t count)
348
+static ssize_t temp_offset_store(struct device *dev,
349
+ struct device_attribute *attr,
350
+ const char *buf, size_t count)
353351 {
354352 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
355353 int nr = sensor_attr->index;
....@@ -385,19 +383,18 @@
385383 return count;
386384 }
387385
388
-#define show_temp_index(index) \
389
-static SENSOR_DEVICE_ATTR(temp##index##_input, S_IRUGO, \
390
- show_temp, NULL, index-1); \
391
-static SENSOR_DEVICE_ATTR(temp##index##_min, S_IRUGO | S_IWUSR, \
392
- show_temp_min, set_temp_min, index-1); \
393
-static SENSOR_DEVICE_ATTR(temp##index##_max, S_IRUGO | S_IWUSR, \
394
- show_temp_max, set_temp_max, index-1); \
395
-static SENSOR_DEVICE_ATTR(temp##index##_offset, S_IRUGO | S_IWUSR, \
396
- show_temp_offset, set_temp_offset, index-1);
397
-
398
-show_temp_index(1)
399
-show_temp_index(2)
400
-show_temp_index(3)
386
+static SENSOR_DEVICE_ATTR_RO(temp1_input, temp, 0);
387
+static SENSOR_DEVICE_ATTR_RW(temp1_min, temp_min, 0);
388
+static SENSOR_DEVICE_ATTR_RW(temp1_max, temp_max, 0);
389
+static SENSOR_DEVICE_ATTR_RW(temp1_offset, temp_offset, 0);
390
+static SENSOR_DEVICE_ATTR_RO(temp2_input, temp, 1);
391
+static SENSOR_DEVICE_ATTR_RW(temp2_min, temp_min, 1);
392
+static SENSOR_DEVICE_ATTR_RW(temp2_max, temp_max, 1);
393
+static SENSOR_DEVICE_ATTR_RW(temp2_offset, temp_offset, 1);
394
+static SENSOR_DEVICE_ATTR_RO(temp3_input, temp, 2);
395
+static SENSOR_DEVICE_ATTR_RW(temp3_min, temp_min, 2);
396
+static SENSOR_DEVICE_ATTR_RW(temp3_max, temp_max, 2);
397
+static SENSOR_DEVICE_ATTR_RW(temp3_offset, temp_offset, 2);
401398
402399 /* VID */
403400 static ssize_t cpu0_vid_show(struct device *dev,
....@@ -434,8 +431,8 @@
434431 static DEVICE_ATTR_RW(vrm);
435432
436433 /* Alarms */
437
-static ssize_t show_alarm(struct device *dev, struct device_attribute *attr,
438
- char *buf)
434
+static ssize_t alarm_show(struct device *dev, struct device_attribute *attr,
435
+ char *buf)
439436 {
440437 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
441438 int nr = sensor_attr->index;
....@@ -443,19 +440,19 @@
443440 return sprintf(buf, "%u\n", (data->alarms & nr) ? 1 : 0);
444441 }
445442
446
-static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 0x0010);
447
-static SENSOR_DEVICE_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL, 0x0020);
448
-static SENSOR_DEVICE_ATTR(temp3_alarm, S_IRUGO, show_alarm, NULL, 0x0040);
449
-static SENSOR_DEVICE_ATTR(temp2_fault, S_IRUGO, show_alarm, NULL, 0x4000);
450
-static SENSOR_DEVICE_ATTR(temp3_fault, S_IRUGO, show_alarm, NULL, 0x8000);
451
-static SENSOR_DEVICE_ATTR(in0_alarm, S_IRUGO, show_alarm, NULL, 0x0001);
452
-static SENSOR_DEVICE_ATTR(in1_alarm, S_IRUGO, show_alarm, NULL, 0x0002);
453
-static SENSOR_DEVICE_ATTR(in2_alarm, S_IRUGO, show_alarm, NULL, 0x0004);
454
-static SENSOR_DEVICE_ATTR(in3_alarm, S_IRUGO, show_alarm, NULL, 0x0008);
455
-static SENSOR_DEVICE_ATTR(in4_alarm, S_IRUGO, show_alarm, NULL, 0x0100);
456
-static SENSOR_DEVICE_ATTR(in5_alarm, S_IRUGO, show_alarm, NULL, 0x0200);
457
-static SENSOR_DEVICE_ATTR(in6_alarm, S_IRUGO, show_alarm, NULL, 0x0400);
458
-static SENSOR_DEVICE_ATTR(in7_alarm, S_IRUGO, show_alarm, NULL, 0x0800);
443
+static SENSOR_DEVICE_ATTR_RO(temp1_alarm, alarm, 0x0010);
444
+static SENSOR_DEVICE_ATTR_RO(temp2_alarm, alarm, 0x0020);
445
+static SENSOR_DEVICE_ATTR_RO(temp3_alarm, alarm, 0x0040);
446
+static SENSOR_DEVICE_ATTR_RO(temp2_fault, alarm, 0x4000);
447
+static SENSOR_DEVICE_ATTR_RO(temp3_fault, alarm, 0x8000);
448
+static SENSOR_DEVICE_ATTR_RO(in0_alarm, alarm, 0x0001);
449
+static SENSOR_DEVICE_ATTR_RO(in1_alarm, alarm, 0x0002);
450
+static SENSOR_DEVICE_ATTR_RO(in2_alarm, alarm, 0x0004);
451
+static SENSOR_DEVICE_ATTR_RO(in3_alarm, alarm, 0x0008);
452
+static SENSOR_DEVICE_ATTR_RO(in4_alarm, alarm, 0x0100);
453
+static SENSOR_DEVICE_ATTR_RO(in5_alarm, alarm, 0x0200);
454
+static SENSOR_DEVICE_ATTR_RO(in6_alarm, alarm, 0x0400);
455
+static SENSOR_DEVICE_ATTR_RO(in7_alarm, alarm, 0x0800);
459456
460457 static struct attribute *smsc47m192_attributes[] = {
461458 &sensor_dev_attr_in0_input.dev_attr.attr,
....@@ -590,8 +587,7 @@
590587 return 0;
591588 }
592589
593
-static int smsc47m192_probe(struct i2c_client *client,
594
- const struct i2c_device_id *id)
590
+static int smsc47m192_probe(struct i2c_client *client)
595591 {
596592 struct device *dev = &client->dev;
597593 struct device *hwmon_dev;
....@@ -632,7 +628,7 @@
632628 .driver = {
633629 .name = "smsc47m192",
634630 },
635
- .probe = smsc47m192_probe,
631
+ .probe_new = smsc47m192_probe,
636632 .id_table = smsc47m192_id,
637633 .detect = smsc47m192_detect,
638634 .address_list = normal_i2c,