hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/hwmon/adm1031.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * adm1031.c - Part of lm_sensors, Linux kernel modules for hardware
34 * monitoring
....@@ -5,20 +6,6 @@
56 * Supports adm1030 / adm1031
67 * Copyright (C) 2004 Alexandre d'Alton <alex@alexdalton.org>
78 * Reworked by Jean Delvare <jdelvare@suse.de>
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>
....@@ -331,7 +318,7 @@
331318 return -EINVAL;
332319 }
333320
334
-static ssize_t show_fan_auto_channel(struct device *dev,
321
+static ssize_t fan_auto_channel_show(struct device *dev,
335322 struct device_attribute *attr, char *buf)
336323 {
337324 int nr = to_sensor_dev_attr(attr)->index;
....@@ -340,8 +327,8 @@
340327 }
341328
342329 static ssize_t
343
-set_fan_auto_channel(struct device *dev, struct device_attribute *attr,
344
- const char *buf, size_t count)
330
+fan_auto_channel_store(struct device *dev, struct device_attribute *attr,
331
+ const char *buf, size_t count)
345332 {
346333 struct adm1031_data *data = dev_get_drvdata(dev);
347334 struct i2c_client *client = data->client;
....@@ -392,13 +379,11 @@
392379 return count;
393380 }
394381
395
-static SENSOR_DEVICE_ATTR(auto_fan1_channel, S_IRUGO | S_IWUSR,
396
- show_fan_auto_channel, set_fan_auto_channel, 0);
397
-static SENSOR_DEVICE_ATTR(auto_fan2_channel, S_IRUGO | S_IWUSR,
398
- show_fan_auto_channel, set_fan_auto_channel, 1);
382
+static SENSOR_DEVICE_ATTR_RW(auto_fan1_channel, fan_auto_channel, 0);
383
+static SENSOR_DEVICE_ATTR_RW(auto_fan2_channel, fan_auto_channel, 1);
399384
400385 /* Auto Temps */
401
-static ssize_t show_auto_temp_off(struct device *dev,
386
+static ssize_t auto_temp_off_show(struct device *dev,
402387 struct device_attribute *attr, char *buf)
403388 {
404389 int nr = to_sensor_dev_attr(attr)->index;
....@@ -406,7 +391,7 @@
406391 return sprintf(buf, "%d\n",
407392 AUTO_TEMP_OFF_FROM_REG(data->auto_temp[nr]));
408393 }
409
-static ssize_t show_auto_temp_min(struct device *dev,
394
+static ssize_t auto_temp_min_show(struct device *dev,
410395 struct device_attribute *attr, char *buf)
411396 {
412397 int nr = to_sensor_dev_attr(attr)->index;
....@@ -415,8 +400,8 @@
415400 AUTO_TEMP_MIN_FROM_REG(data->auto_temp[nr]));
416401 }
417402 static ssize_t
418
-set_auto_temp_min(struct device *dev, struct device_attribute *attr,
419
- const char *buf, size_t count)
403
+auto_temp_min_store(struct device *dev, struct device_attribute *attr,
404
+ const char *buf, size_t count)
420405 {
421406 struct adm1031_data *data = dev_get_drvdata(dev);
422407 struct i2c_client *client = data->client;
....@@ -436,7 +421,7 @@
436421 mutex_unlock(&data->update_lock);
437422 return count;
438423 }
439
-static ssize_t show_auto_temp_max(struct device *dev,
424
+static ssize_t auto_temp_max_show(struct device *dev,
440425 struct device_attribute *attr, char *buf)
441426 {
442427 int nr = to_sensor_dev_attr(attr)->index;
....@@ -445,8 +430,8 @@
445430 AUTO_TEMP_MAX_FROM_REG(data->auto_temp[nr]));
446431 }
447432 static ssize_t
448
-set_auto_temp_max(struct device *dev, struct device_attribute *attr,
449
- const char *buf, size_t count)
433
+auto_temp_max_store(struct device *dev, struct device_attribute *attr,
434
+ const char *buf, size_t count)
450435 {
451436 struct adm1031_data *data = dev_get_drvdata(dev);
452437 struct i2c_client *client = data->client;
....@@ -468,28 +453,26 @@
468453 return count;
469454 }
470455
471
-#define auto_temp_reg(offset) \
472
-static SENSOR_DEVICE_ATTR(auto_temp##offset##_off, S_IRUGO, \
473
- show_auto_temp_off, NULL, offset - 1); \
474
-static SENSOR_DEVICE_ATTR(auto_temp##offset##_min, S_IRUGO | S_IWUSR, \
475
- show_auto_temp_min, set_auto_temp_min, offset - 1); \
476
-static SENSOR_DEVICE_ATTR(auto_temp##offset##_max, S_IRUGO | S_IWUSR, \
477
- show_auto_temp_max, set_auto_temp_max, offset - 1)
478
-
479
-auto_temp_reg(1);
480
-auto_temp_reg(2);
481
-auto_temp_reg(3);
456
+static SENSOR_DEVICE_ATTR_RO(auto_temp1_off, auto_temp_off, 0);
457
+static SENSOR_DEVICE_ATTR_RW(auto_temp1_min, auto_temp_min, 0);
458
+static SENSOR_DEVICE_ATTR_RW(auto_temp1_max, auto_temp_max, 0);
459
+static SENSOR_DEVICE_ATTR_RO(auto_temp2_off, auto_temp_off, 1);
460
+static SENSOR_DEVICE_ATTR_RW(auto_temp2_min, auto_temp_min, 1);
461
+static SENSOR_DEVICE_ATTR_RW(auto_temp2_max, auto_temp_max, 1);
462
+static SENSOR_DEVICE_ATTR_RO(auto_temp3_off, auto_temp_off, 2);
463
+static SENSOR_DEVICE_ATTR_RW(auto_temp3_min, auto_temp_min, 2);
464
+static SENSOR_DEVICE_ATTR_RW(auto_temp3_max, auto_temp_max, 2);
482465
483466 /* pwm */
484
-static ssize_t show_pwm(struct device *dev,
485
- struct device_attribute *attr, char *buf)
467
+static ssize_t pwm_show(struct device *dev, struct device_attribute *attr,
468
+ char *buf)
486469 {
487470 int nr = to_sensor_dev_attr(attr)->index;
488471 struct adm1031_data *data = adm1031_update_device(dev);
489472 return sprintf(buf, "%d\n", PWM_FROM_REG(data->pwm[nr]));
490473 }
491
-static ssize_t set_pwm(struct device *dev, struct device_attribute *attr,
492
- const char *buf, size_t count)
474
+static ssize_t pwm_store(struct device *dev, struct device_attribute *attr,
475
+ const char *buf, size_t count)
493476 {
494477 struct adm1031_data *data = dev_get_drvdata(dev);
495478 struct i2c_client *client = data->client;
....@@ -517,12 +500,10 @@
517500 return count;
518501 }
519502
520
-static SENSOR_DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, show_pwm, set_pwm, 0);
521
-static SENSOR_DEVICE_ATTR(pwm2, S_IRUGO | S_IWUSR, show_pwm, set_pwm, 1);
522
-static SENSOR_DEVICE_ATTR(auto_fan1_min_pwm, S_IRUGO | S_IWUSR,
523
- show_pwm, set_pwm, 0);
524
-static SENSOR_DEVICE_ATTR(auto_fan2_min_pwm, S_IRUGO | S_IWUSR,
525
- show_pwm, set_pwm, 1);
503
+static SENSOR_DEVICE_ATTR_RW(pwm1, pwm, 0);
504
+static SENSOR_DEVICE_ATTR_RW(pwm2, pwm, 1);
505
+static SENSOR_DEVICE_ATTR_RW(auto_fan1_min_pwm, pwm, 0);
506
+static SENSOR_DEVICE_ATTR_RW(auto_fan2_min_pwm, pwm, 1);
526507
527508 /* Fans */
528509
....@@ -572,9 +553,8 @@
572553 return res;
573554 }
574555
575
-
576
-static ssize_t show_fan(struct device *dev,
577
- struct device_attribute *attr, char *buf)
556
+static ssize_t fan_show(struct device *dev, struct device_attribute *attr,
557
+ char *buf)
578558 {
579559 int nr = to_sensor_dev_attr(attr)->index;
580560 struct adm1031_data *data = adm1031_update_device(dev);
....@@ -585,15 +565,15 @@
585565 return sprintf(buf, "%d\n", value);
586566 }
587567
588
-static ssize_t show_fan_div(struct device *dev,
589
- struct device_attribute *attr, char *buf)
568
+static ssize_t fan_div_show(struct device *dev, struct device_attribute *attr,
569
+ char *buf)
590570 {
591571 int nr = to_sensor_dev_attr(attr)->index;
592572 struct adm1031_data *data = adm1031_update_device(dev);
593573 return sprintf(buf, "%d\n", FAN_DIV_FROM_REG(data->fan_div[nr]));
594574 }
595
-static ssize_t show_fan_min(struct device *dev,
596
- struct device_attribute *attr, char *buf)
575
+static ssize_t fan_min_show(struct device *dev, struct device_attribute *attr,
576
+ char *buf)
597577 {
598578 int nr = to_sensor_dev_attr(attr)->index;
599579 struct adm1031_data *data = adm1031_update_device(dev);
....@@ -601,8 +581,9 @@
601581 FAN_FROM_REG(data->fan_min[nr],
602582 FAN_DIV_FROM_REG(data->fan_div[nr])));
603583 }
604
-static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr,
605
- const char *buf, size_t count)
584
+static ssize_t fan_min_store(struct device *dev,
585
+ struct device_attribute *attr, const char *buf,
586
+ size_t count)
606587 {
607588 struct adm1031_data *data = dev_get_drvdata(dev);
608589 struct i2c_client *client = data->client;
....@@ -625,8 +606,9 @@
625606 mutex_unlock(&data->update_lock);
626607 return count;
627608 }
628
-static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr,
629
- const char *buf, size_t count)
609
+static ssize_t fan_div_store(struct device *dev,
610
+ struct device_attribute *attr, const char *buf,
611
+ size_t count)
630612 {
631613 struct adm1031_data *data = dev_get_drvdata(dev);
632614 struct i2c_client *client = data->client;
....@@ -673,21 +655,16 @@
673655 return count;
674656 }
675657
676
-#define fan_offset(offset) \
677
-static SENSOR_DEVICE_ATTR(fan##offset##_input, S_IRUGO, \
678
- show_fan, NULL, offset - 1); \
679
-static SENSOR_DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \
680
- show_fan_min, set_fan_min, offset - 1); \
681
-static SENSOR_DEVICE_ATTR(fan##offset##_div, S_IRUGO | S_IWUSR, \
682
- show_fan_div, set_fan_div, offset - 1)
683
-
684
-fan_offset(1);
685
-fan_offset(2);
686
-
658
+static SENSOR_DEVICE_ATTR_RO(fan1_input, fan, 0);
659
+static SENSOR_DEVICE_ATTR_RW(fan1_min, fan_min, 0);
660
+static SENSOR_DEVICE_ATTR_RW(fan1_div, fan_div, 0);
661
+static SENSOR_DEVICE_ATTR_RO(fan2_input, fan, 1);
662
+static SENSOR_DEVICE_ATTR_RW(fan2_min, fan_min, 1);
663
+static SENSOR_DEVICE_ATTR_RW(fan2_div, fan_div, 1);
687664
688665 /* Temps */
689
-static ssize_t show_temp(struct device *dev,
690
- struct device_attribute *attr, char *buf)
666
+static ssize_t temp_show(struct device *dev, struct device_attribute *attr,
667
+ char *buf)
691668 {
692669 int nr = to_sensor_dev_attr(attr)->index;
693670 struct adm1031_data *data = adm1031_update_device(dev);
....@@ -697,7 +674,7 @@
697674 (((data->ext_temp[nr] >> ((nr - 1) * 3)) & 7));
698675 return sprintf(buf, "%d\n", TEMP_FROM_REG_EXT(data->temp[nr], ext));
699676 }
700
-static ssize_t show_temp_offset(struct device *dev,
677
+static ssize_t temp_offset_show(struct device *dev,
701678 struct device_attribute *attr, char *buf)
702679 {
703680 int nr = to_sensor_dev_attr(attr)->index;
....@@ -705,30 +682,30 @@
705682 return sprintf(buf, "%d\n",
706683 TEMP_OFFSET_FROM_REG(data->temp_offset[nr]));
707684 }
708
-static ssize_t show_temp_min(struct device *dev,
685
+static ssize_t temp_min_show(struct device *dev,
709686 struct device_attribute *attr, char *buf)
710687 {
711688 int nr = to_sensor_dev_attr(attr)->index;
712689 struct adm1031_data *data = adm1031_update_device(dev);
713690 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_min[nr]));
714691 }
715
-static ssize_t show_temp_max(struct device *dev,
692
+static ssize_t temp_max_show(struct device *dev,
716693 struct device_attribute *attr, char *buf)
717694 {
718695 int nr = to_sensor_dev_attr(attr)->index;
719696 struct adm1031_data *data = adm1031_update_device(dev);
720697 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_max[nr]));
721698 }
722
-static ssize_t show_temp_crit(struct device *dev,
699
+static ssize_t temp_crit_show(struct device *dev,
723700 struct device_attribute *attr, char *buf)
724701 {
725702 int nr = to_sensor_dev_attr(attr)->index;
726703 struct adm1031_data *data = adm1031_update_device(dev);
727704 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_crit[nr]));
728705 }
729
-static ssize_t set_temp_offset(struct device *dev,
730
- struct device_attribute *attr, const char *buf,
731
- size_t count)
706
+static ssize_t temp_offset_store(struct device *dev,
707
+ struct device_attribute *attr,
708
+ const char *buf, size_t count)
732709 {
733710 struct adm1031_data *data = dev_get_drvdata(dev);
734711 struct i2c_client *client = data->client;
....@@ -748,8 +725,9 @@
748725 mutex_unlock(&data->update_lock);
749726 return count;
750727 }
751
-static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr,
752
- const char *buf, size_t count)
728
+static ssize_t temp_min_store(struct device *dev,
729
+ struct device_attribute *attr, const char *buf,
730
+ size_t count)
753731 {
754732 struct adm1031_data *data = dev_get_drvdata(dev);
755733 struct i2c_client *client = data->client;
....@@ -769,8 +747,9 @@
769747 mutex_unlock(&data->update_lock);
770748 return count;
771749 }
772
-static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr,
773
- const char *buf, size_t count)
750
+static ssize_t temp_max_store(struct device *dev,
751
+ struct device_attribute *attr, const char *buf,
752
+ size_t count)
774753 {
775754 struct adm1031_data *data = dev_get_drvdata(dev);
776755 struct i2c_client *client = data->client;
....@@ -790,8 +769,9 @@
790769 mutex_unlock(&data->update_lock);
791770 return count;
792771 }
793
-static ssize_t set_temp_crit(struct device *dev, struct device_attribute *attr,
794
- const char *buf, size_t count)
772
+static ssize_t temp_crit_store(struct device *dev,
773
+ struct device_attribute *attr, const char *buf,
774
+ size_t count)
795775 {
796776 struct adm1031_data *data = dev_get_drvdata(dev);
797777 struct i2c_client *client = data->client;
....@@ -812,21 +792,21 @@
812792 return count;
813793 }
814794
815
-#define temp_reg(offset) \
816
-static SENSOR_DEVICE_ATTR(temp##offset##_input, S_IRUGO, \
817
- show_temp, NULL, offset - 1); \
818
-static SENSOR_DEVICE_ATTR(temp##offset##_offset, S_IRUGO | S_IWUSR, \
819
- show_temp_offset, set_temp_offset, offset - 1); \
820
-static SENSOR_DEVICE_ATTR(temp##offset##_min, S_IRUGO | S_IWUSR, \
821
- show_temp_min, set_temp_min, offset - 1); \
822
-static SENSOR_DEVICE_ATTR(temp##offset##_max, S_IRUGO | S_IWUSR, \
823
- show_temp_max, set_temp_max, offset - 1); \
824
-static SENSOR_DEVICE_ATTR(temp##offset##_crit, S_IRUGO | S_IWUSR, \
825
- show_temp_crit, set_temp_crit, offset - 1)
826
-
827
-temp_reg(1);
828
-temp_reg(2);
829
-temp_reg(3);
795
+static SENSOR_DEVICE_ATTR_RO(temp1_input, temp, 0);
796
+static SENSOR_DEVICE_ATTR_RW(temp1_offset, temp_offset, 0);
797
+static SENSOR_DEVICE_ATTR_RW(temp1_min, temp_min, 0);
798
+static SENSOR_DEVICE_ATTR_RW(temp1_max, temp_max, 0);
799
+static SENSOR_DEVICE_ATTR_RW(temp1_crit, temp_crit, 0);
800
+static SENSOR_DEVICE_ATTR_RO(temp2_input, temp, 1);
801
+static SENSOR_DEVICE_ATTR_RW(temp2_offset, temp_offset, 1);
802
+static SENSOR_DEVICE_ATTR_RW(temp2_min, temp_min, 1);
803
+static SENSOR_DEVICE_ATTR_RW(temp2_max, temp_max, 1);
804
+static SENSOR_DEVICE_ATTR_RW(temp2_crit, temp_crit, 1);
805
+static SENSOR_DEVICE_ATTR_RO(temp3_input, temp, 2);
806
+static SENSOR_DEVICE_ATTR_RW(temp3_offset, temp_offset, 2);
807
+static SENSOR_DEVICE_ATTR_RW(temp3_min, temp_min, 2);
808
+static SENSOR_DEVICE_ATTR_RW(temp3_max, temp_max, 2);
809
+static SENSOR_DEVICE_ATTR_RW(temp3_crit, temp_crit, 2);
830810
831811 /* Alarms */
832812 static ssize_t alarms_show(struct device *dev, struct device_attribute *attr,
....@@ -838,29 +818,29 @@
838818
839819 static DEVICE_ATTR_RO(alarms);
840820
841
-static ssize_t show_alarm(struct device *dev,
842
- struct device_attribute *attr, char *buf)
821
+static ssize_t alarm_show(struct device *dev, struct device_attribute *attr,
822
+ char *buf)
843823 {
844824 int bitnr = to_sensor_dev_attr(attr)->index;
845825 struct adm1031_data *data = adm1031_update_device(dev);
846826 return sprintf(buf, "%d\n", (data->alarm >> bitnr) & 1);
847827 }
848828
849
-static SENSOR_DEVICE_ATTR(fan1_alarm, S_IRUGO, show_alarm, NULL, 0);
850
-static SENSOR_DEVICE_ATTR(fan1_fault, S_IRUGO, show_alarm, NULL, 1);
851
-static SENSOR_DEVICE_ATTR(temp2_max_alarm, S_IRUGO, show_alarm, NULL, 2);
852
-static SENSOR_DEVICE_ATTR(temp2_min_alarm, S_IRUGO, show_alarm, NULL, 3);
853
-static SENSOR_DEVICE_ATTR(temp2_crit_alarm, S_IRUGO, show_alarm, NULL, 4);
854
-static SENSOR_DEVICE_ATTR(temp2_fault, S_IRUGO, show_alarm, NULL, 5);
855
-static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, show_alarm, NULL, 6);
856
-static SENSOR_DEVICE_ATTR(temp1_min_alarm, S_IRUGO, show_alarm, NULL, 7);
857
-static SENSOR_DEVICE_ATTR(fan2_alarm, S_IRUGO, show_alarm, NULL, 8);
858
-static SENSOR_DEVICE_ATTR(fan2_fault, S_IRUGO, show_alarm, NULL, 9);
859
-static SENSOR_DEVICE_ATTR(temp3_max_alarm, S_IRUGO, show_alarm, NULL, 10);
860
-static SENSOR_DEVICE_ATTR(temp3_min_alarm, S_IRUGO, show_alarm, NULL, 11);
861
-static SENSOR_DEVICE_ATTR(temp3_crit_alarm, S_IRUGO, show_alarm, NULL, 12);
862
-static SENSOR_DEVICE_ATTR(temp3_fault, S_IRUGO, show_alarm, NULL, 13);
863
-static SENSOR_DEVICE_ATTR(temp1_crit_alarm, S_IRUGO, show_alarm, NULL, 14);
829
+static SENSOR_DEVICE_ATTR_RO(fan1_alarm, alarm, 0);
830
+static SENSOR_DEVICE_ATTR_RO(fan1_fault, alarm, 1);
831
+static SENSOR_DEVICE_ATTR_RO(temp2_max_alarm, alarm, 2);
832
+static SENSOR_DEVICE_ATTR_RO(temp2_min_alarm, alarm, 3);
833
+static SENSOR_DEVICE_ATTR_RO(temp2_crit_alarm, alarm, 4);
834
+static SENSOR_DEVICE_ATTR_RO(temp2_fault, alarm, 5);
835
+static SENSOR_DEVICE_ATTR_RO(temp1_max_alarm, alarm, 6);
836
+static SENSOR_DEVICE_ATTR_RO(temp1_min_alarm, alarm, 7);
837
+static SENSOR_DEVICE_ATTR_RO(fan2_alarm, alarm, 8);
838
+static SENSOR_DEVICE_ATTR_RO(fan2_fault, alarm, 9);
839
+static SENSOR_DEVICE_ATTR_RO(temp3_max_alarm, alarm, 10);
840
+static SENSOR_DEVICE_ATTR_RO(temp3_min_alarm, alarm, 11);
841
+static SENSOR_DEVICE_ATTR_RO(temp3_crit_alarm, alarm, 12);
842
+static SENSOR_DEVICE_ATTR_RO(temp3_fault, alarm, 13);
843
+static SENSOR_DEVICE_ATTR_RO(temp1_crit_alarm, alarm, 14);
864844
865845 /* Update Interval */
866846 static const unsigned int update_intervals[] = {
....@@ -1042,8 +1022,9 @@
10421022 data->update_interval = update_intervals[i];
10431023 }
10441024
1045
-static int adm1031_probe(struct i2c_client *client,
1046
- const struct i2c_device_id *id)
1025
+static const struct i2c_device_id adm1031_id[];
1026
+
1027
+static int adm1031_probe(struct i2c_client *client)
10471028 {
10481029 struct device *dev = &client->dev;
10491030 struct device *hwmon_dev;
....@@ -1055,7 +1036,7 @@
10551036
10561037 i2c_set_clientdata(client, data);
10571038 data->client = client;
1058
- data->chip_type = id->driver_data;
1039
+ data->chip_type = i2c_match_id(adm1031_id, client)->driver_data;
10591040 mutex_init(&data->update_lock);
10601041
10611042 if (data->chip_type == adm1030)
....@@ -1088,7 +1069,7 @@
10881069 .driver = {
10891070 .name = "adm1031",
10901071 },
1091
- .probe = adm1031_probe,
1072
+ .probe_new = adm1031_probe,
10921073 .id_table = adm1031_id,
10931074 .detect = adm1031_detect,
10941075 .address_list = normal_i2c,