hc
2023-12-06 08f87f769b595151be1afeff53e144f543faa614
kernel/drivers/hwmon/lm80.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * lm80.c - From lm_sensors, Linux kernel modules for hardware
34 * monitoring
....@@ -5,20 +6,6 @@
56 * and Philip Edelbrock <phil@netroedge.com>
67 *
78 * Ported to Linux 2.6 by Tiago Sousa <mirage@kaotik.org>
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>
....@@ -269,7 +256,7 @@
269256 * Sysfs stuff
270257 */
271258
272
-static ssize_t show_in(struct device *dev, struct device_attribute *attr,
259
+static ssize_t in_show(struct device *dev, struct device_attribute *attr,
273260 char *buf)
274261 {
275262 struct lm80_data *data = lm80_update_device(dev);
....@@ -281,8 +268,8 @@
281268 return sprintf(buf, "%d\n", IN_FROM_REG(data->in[nr][index]));
282269 }
283270
284
-static ssize_t set_in(struct device *dev, struct device_attribute *attr,
285
- const char *buf, size_t count)
271
+static ssize_t in_store(struct device *dev, struct device_attribute *attr,
272
+ const char *buf, size_t count)
286273 {
287274 struct lm80_data *data = dev_get_drvdata(dev);
288275 struct i2c_client *client = data->client;
....@@ -303,7 +290,7 @@
303290 return count;
304291 }
305292
306
-static ssize_t show_fan(struct device *dev, struct device_attribute *attr,
293
+static ssize_t fan_show(struct device *dev, struct device_attribute *attr,
307294 char *buf)
308295 {
309296 int index = to_sensor_dev_attr_2(attr)->index;
....@@ -315,8 +302,8 @@
315302 DIV_FROM_REG(data->fan_div[index])));
316303 }
317304
318
-static ssize_t show_fan_div(struct device *dev, struct device_attribute *attr,
319
- char *buf)
305
+static ssize_t fan_div_show(struct device *dev, struct device_attribute *attr,
306
+ char *buf)
320307 {
321308 int nr = to_sensor_dev_attr(attr)->index;
322309 struct lm80_data *data = lm80_update_device(dev);
....@@ -325,8 +312,8 @@
325312 return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[nr]));
326313 }
327314
328
-static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr,
329
- const char *buf, size_t count)
315
+static ssize_t fan_store(struct device *dev, struct device_attribute *attr,
316
+ const char *buf, size_t count)
330317 {
331318 int index = to_sensor_dev_attr_2(attr)->index;
332319 int nr = to_sensor_dev_attr_2(attr)->nr;
....@@ -352,8 +339,9 @@
352339 * least surprise; the user doesn't expect the fan minimum to change just
353340 * because the divisor changed.
354341 */
355
-static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr,
356
- const char *buf, size_t count)
342
+static ssize_t fan_div_store(struct device *dev,
343
+ struct device_attribute *attr, const char *buf,
344
+ size_t count)
357345 {
358346 int nr = to_sensor_dev_attr(attr)->index;
359347 struct lm80_data *data = dev_get_drvdata(dev);
....@@ -410,7 +398,7 @@
410398 return count;
411399 }
412400
413
-static ssize_t show_temp(struct device *dev, struct device_attribute *devattr,
401
+static ssize_t temp_show(struct device *dev, struct device_attribute *devattr,
414402 char *buf)
415403 {
416404 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
....@@ -420,8 +408,9 @@
420408 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp[attr->index]));
421409 }
422410
423
-static ssize_t set_temp(struct device *dev, struct device_attribute *devattr,
424
- const char *buf, size_t count)
411
+static ssize_t temp_store(struct device *dev,
412
+ struct device_attribute *devattr, const char *buf,
413
+ size_t count)
425414 {
426415 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
427416 struct lm80_data *data = dev_get_drvdata(dev);
....@@ -448,7 +437,7 @@
448437 return sprintf(buf, "%u\n", data->alarms);
449438 }
450439
451
-static ssize_t show_alarm(struct device *dev, struct device_attribute *attr,
440
+static ssize_t alarm_show(struct device *dev, struct device_attribute *attr,
452441 char *buf)
453442 {
454443 int bitnr = to_sensor_dev_attr(attr)->index;
....@@ -458,72 +447,50 @@
458447 return sprintf(buf, "%u\n", (data->alarms >> bitnr) & 1);
459448 }
460449
461
-static SENSOR_DEVICE_ATTR_2(in0_min, S_IWUSR | S_IRUGO,
462
- show_in, set_in, i_min, 0);
463
-static SENSOR_DEVICE_ATTR_2(in1_min, S_IWUSR | S_IRUGO,
464
- show_in, set_in, i_min, 1);
465
-static SENSOR_DEVICE_ATTR_2(in2_min, S_IWUSR | S_IRUGO,
466
- show_in, set_in, i_min, 2);
467
-static SENSOR_DEVICE_ATTR_2(in3_min, S_IWUSR | S_IRUGO,
468
- show_in, set_in, i_min, 3);
469
-static SENSOR_DEVICE_ATTR_2(in4_min, S_IWUSR | S_IRUGO,
470
- show_in, set_in, i_min, 4);
471
-static SENSOR_DEVICE_ATTR_2(in5_min, S_IWUSR | S_IRUGO,
472
- show_in, set_in, i_min, 5);
473
-static SENSOR_DEVICE_ATTR_2(in6_min, S_IWUSR | S_IRUGO,
474
- show_in, set_in, i_min, 6);
475
-static SENSOR_DEVICE_ATTR_2(in0_max, S_IWUSR | S_IRUGO,
476
- show_in, set_in, i_max, 0);
477
-static SENSOR_DEVICE_ATTR_2(in1_max, S_IWUSR | S_IRUGO,
478
- show_in, set_in, i_max, 1);
479
-static SENSOR_DEVICE_ATTR_2(in2_max, S_IWUSR | S_IRUGO,
480
- show_in, set_in, i_max, 2);
481
-static SENSOR_DEVICE_ATTR_2(in3_max, S_IWUSR | S_IRUGO,
482
- show_in, set_in, i_max, 3);
483
-static SENSOR_DEVICE_ATTR_2(in4_max, S_IWUSR | S_IRUGO,
484
- show_in, set_in, i_max, 4);
485
-static SENSOR_DEVICE_ATTR_2(in5_max, S_IWUSR | S_IRUGO,
486
- show_in, set_in, i_max, 5);
487
-static SENSOR_DEVICE_ATTR_2(in6_max, S_IWUSR | S_IRUGO,
488
- show_in, set_in, i_max, 6);
489
-static SENSOR_DEVICE_ATTR_2(in0_input, S_IRUGO, show_in, NULL, i_input, 0);
490
-static SENSOR_DEVICE_ATTR_2(in1_input, S_IRUGO, show_in, NULL, i_input, 1);
491
-static SENSOR_DEVICE_ATTR_2(in2_input, S_IRUGO, show_in, NULL, i_input, 2);
492
-static SENSOR_DEVICE_ATTR_2(in3_input, S_IRUGO, show_in, NULL, i_input, 3);
493
-static SENSOR_DEVICE_ATTR_2(in4_input, S_IRUGO, show_in, NULL, i_input, 4);
494
-static SENSOR_DEVICE_ATTR_2(in5_input, S_IRUGO, show_in, NULL, i_input, 5);
495
-static SENSOR_DEVICE_ATTR_2(in6_input, S_IRUGO, show_in, NULL, i_input, 6);
496
-static SENSOR_DEVICE_ATTR_2(fan1_min, S_IWUSR | S_IRUGO,
497
- show_fan, set_fan_min, f_min, 0);
498
-static SENSOR_DEVICE_ATTR_2(fan2_min, S_IWUSR | S_IRUGO,
499
- show_fan, set_fan_min, f_min, 1);
500
-static SENSOR_DEVICE_ATTR_2(fan1_input, S_IRUGO, show_fan, NULL, f_input, 0);
501
-static SENSOR_DEVICE_ATTR_2(fan2_input, S_IRUGO, show_fan, NULL, f_input, 1);
502
-static SENSOR_DEVICE_ATTR(fan1_div, S_IWUSR | S_IRUGO,
503
- show_fan_div, set_fan_div, 0);
504
-static SENSOR_DEVICE_ATTR(fan2_div, S_IWUSR | S_IRUGO,
505
- show_fan_div, set_fan_div, 1);
506
-static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL, t_input);
507
-static SENSOR_DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, show_temp,
508
- set_temp, t_hot_max);
509
-static SENSOR_DEVICE_ATTR(temp1_max_hyst, S_IWUSR | S_IRUGO, show_temp,
510
- set_temp, t_hot_hyst);
511
-static SENSOR_DEVICE_ATTR(temp1_crit, S_IWUSR | S_IRUGO, show_temp,
512
- set_temp, t_os_max);
513
-static SENSOR_DEVICE_ATTR(temp1_crit_hyst, S_IWUSR | S_IRUGO, show_temp,
514
- set_temp, t_os_hyst);
450
+static SENSOR_DEVICE_ATTR_2_RW(in0_min, in, i_min, 0);
451
+static SENSOR_DEVICE_ATTR_2_RW(in1_min, in, i_min, 1);
452
+static SENSOR_DEVICE_ATTR_2_RW(in2_min, in, i_min, 2);
453
+static SENSOR_DEVICE_ATTR_2_RW(in3_min, in, i_min, 3);
454
+static SENSOR_DEVICE_ATTR_2_RW(in4_min, in, i_min, 4);
455
+static SENSOR_DEVICE_ATTR_2_RW(in5_min, in, i_min, 5);
456
+static SENSOR_DEVICE_ATTR_2_RW(in6_min, in, i_min, 6);
457
+static SENSOR_DEVICE_ATTR_2_RW(in0_max, in, i_max, 0);
458
+static SENSOR_DEVICE_ATTR_2_RW(in1_max, in, i_max, 1);
459
+static SENSOR_DEVICE_ATTR_2_RW(in2_max, in, i_max, 2);
460
+static SENSOR_DEVICE_ATTR_2_RW(in3_max, in, i_max, 3);
461
+static SENSOR_DEVICE_ATTR_2_RW(in4_max, in, i_max, 4);
462
+static SENSOR_DEVICE_ATTR_2_RW(in5_max, in, i_max, 5);
463
+static SENSOR_DEVICE_ATTR_2_RW(in6_max, in, i_max, 6);
464
+static SENSOR_DEVICE_ATTR_2_RO(in0_input, in, i_input, 0);
465
+static SENSOR_DEVICE_ATTR_2_RO(in1_input, in, i_input, 1);
466
+static SENSOR_DEVICE_ATTR_2_RO(in2_input, in, i_input, 2);
467
+static SENSOR_DEVICE_ATTR_2_RO(in3_input, in, i_input, 3);
468
+static SENSOR_DEVICE_ATTR_2_RO(in4_input, in, i_input, 4);
469
+static SENSOR_DEVICE_ATTR_2_RO(in5_input, in, i_input, 5);
470
+static SENSOR_DEVICE_ATTR_2_RO(in6_input, in, i_input, 6);
471
+static SENSOR_DEVICE_ATTR_2_RW(fan1_min, fan, f_min, 0);
472
+static SENSOR_DEVICE_ATTR_2_RW(fan2_min, fan, f_min, 1);
473
+static SENSOR_DEVICE_ATTR_2_RO(fan1_input, fan, f_input, 0);
474
+static SENSOR_DEVICE_ATTR_2_RO(fan2_input, fan, f_input, 1);
475
+static SENSOR_DEVICE_ATTR_RW(fan1_div, fan_div, 0);
476
+static SENSOR_DEVICE_ATTR_RW(fan2_div, fan_div, 1);
477
+static SENSOR_DEVICE_ATTR_RO(temp1_input, temp, t_input);
478
+static SENSOR_DEVICE_ATTR_RW(temp1_max, temp, t_hot_max);
479
+static SENSOR_DEVICE_ATTR_RW(temp1_max_hyst, temp, t_hot_hyst);
480
+static SENSOR_DEVICE_ATTR_RW(temp1_crit, temp, t_os_max);
481
+static SENSOR_DEVICE_ATTR_RW(temp1_crit_hyst, temp, t_os_hyst);
515482 static DEVICE_ATTR_RO(alarms);
516
-static SENSOR_DEVICE_ATTR(in0_alarm, S_IRUGO, show_alarm, NULL, 0);
517
-static SENSOR_DEVICE_ATTR(in1_alarm, S_IRUGO, show_alarm, NULL, 1);
518
-static SENSOR_DEVICE_ATTR(in2_alarm, S_IRUGO, show_alarm, NULL, 2);
519
-static SENSOR_DEVICE_ATTR(in3_alarm, S_IRUGO, show_alarm, NULL, 3);
520
-static SENSOR_DEVICE_ATTR(in4_alarm, S_IRUGO, show_alarm, NULL, 4);
521
-static SENSOR_DEVICE_ATTR(in5_alarm, S_IRUGO, show_alarm, NULL, 5);
522
-static SENSOR_DEVICE_ATTR(in6_alarm, S_IRUGO, show_alarm, NULL, 6);
523
-static SENSOR_DEVICE_ATTR(fan1_alarm, S_IRUGO, show_alarm, NULL, 10);
524
-static SENSOR_DEVICE_ATTR(fan2_alarm, S_IRUGO, show_alarm, NULL, 11);
525
-static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, show_alarm, NULL, 8);
526
-static SENSOR_DEVICE_ATTR(temp1_crit_alarm, S_IRUGO, show_alarm, NULL, 13);
483
+static SENSOR_DEVICE_ATTR_RO(in0_alarm, alarm, 0);
484
+static SENSOR_DEVICE_ATTR_RO(in1_alarm, alarm, 1);
485
+static SENSOR_DEVICE_ATTR_RO(in2_alarm, alarm, 2);
486
+static SENSOR_DEVICE_ATTR_RO(in3_alarm, alarm, 3);
487
+static SENSOR_DEVICE_ATTR_RO(in4_alarm, alarm, 4);
488
+static SENSOR_DEVICE_ATTR_RO(in5_alarm, alarm, 5);
489
+static SENSOR_DEVICE_ATTR_RO(in6_alarm, alarm, 6);
490
+static SENSOR_DEVICE_ATTR_RO(fan1_alarm, alarm, 10);
491
+static SENSOR_DEVICE_ATTR_RO(fan2_alarm, alarm, 11);
492
+static SENSOR_DEVICE_ATTR_RO(temp1_max_alarm, alarm, 8);
493
+static SENSOR_DEVICE_ATTR_RO(temp1_crit_alarm, alarm, 13);
527494
528495 /*
529496 * Real code
....@@ -624,8 +591,7 @@
624591 return 0;
625592 }
626593
627
-static int lm80_probe(struct i2c_client *client,
628
- const struct i2c_device_id *id)
594
+static int lm80_probe(struct i2c_client *client)
629595 {
630596 struct device *dev = &client->dev;
631597 struct device *hwmon_dev;
....@@ -667,7 +633,7 @@
667633 .driver = {
668634 .name = "lm80",
669635 },
670
- .probe = lm80_probe,
636
+ .probe_new = lm80_probe,
671637 .id_table = lm80_id,
672638 .detect = lm80_detect,
673639 .address_list = normal_i2c,