hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/hwmon/lm85.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * lm85.c - Part of lm_sensors, Linux kernel modules for hardware
34 * monitoring
....@@ -8,20 +9,6 @@
89 * Copyright (C) 2007--2014 Jean Delvare <jdelvare@suse.de>
910 *
1011 * Chip details at <http://www.national.com/ds/LM/LM85.pdf>
11
- *
12
- * This program is free software; you can redistribute it and/or modify
13
- * it under the terms of the GNU General Public License as published by
14
- * the Free Software Foundation; either version 2 of the License, or
15
- * (at your option) any later version.
16
- *
17
- * This program is distributed in the hope that it will be useful,
18
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20
- * GNU General Public License for more details.
21
- *
22
- * You should have received a copy of the GNU General Public License
23
- * along with this program; if not, write to the Free Software
24
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
2512 */
2613
2714 #include <linux/module.h>
....@@ -41,7 +28,7 @@
4128 static const unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, I2C_CLIENT_END };
4229
4330 enum chips {
44
- lm85,
31
+ lm85, lm96000,
4532 adm1027, adt7463, adt7468,
4633 emc6d100, emc6d102, emc6d103, emc6d103s
4734 };
....@@ -165,7 +152,6 @@
165152 #define PWM_TO_REG(val) clamp_val(val, 0, 255)
166153 #define PWM_FROM_REG(val) (val)
167154
168
-
169155 /*
170156 * ZONEs have the following parameters:
171157 * Limit (low) temp, 1. degC
....@@ -198,13 +184,18 @@
198184 #define RANGE_FROM_REG(val) lm85_range_map[(val) & 0x0f]
199185
200186 /* These are the PWM frequency encodings */
201
-static const int lm85_freq_map[8] = { /* 1 Hz */
187
+static const int lm85_freq_map[] = { /* 1 Hz */
202188 10, 15, 23, 30, 38, 47, 61, 94
203189 };
204
-static const int adm1027_freq_map[8] = { /* 1 Hz */
190
+
191
+static const int lm96000_freq_map[] = { /* 1 Hz */
192
+ 10, 15, 23, 30, 38, 47, 61, 94,
193
+ 22500, 24000, 25700, 25700, 27700, 27700, 30000, 30000
194
+};
195
+
196
+static const int adm1027_freq_map[] = { /* 1 Hz */
205197 11, 15, 22, 29, 35, 44, 59, 88
206198 };
207
-#define FREQ_MAP_LEN 8
208199
209200 static int FREQ_TO_REG(const int *map,
210201 unsigned int map_size, unsigned long freq)
....@@ -212,9 +203,9 @@
212203 return find_closest(freq, map, map_size);
213204 }
214205
215
-static int FREQ_FROM_REG(const int *map, u8 reg)
206
+static int FREQ_FROM_REG(const int *map, unsigned int map_size, u8 reg)
216207 {
217
- return map[reg & 0x07];
208
+ return map[reg % map_size];
218209 }
219210
220211 /*
....@@ -296,6 +287,8 @@
296287 struct i2c_client *client;
297288 const struct attribute_group *groups[6];
298289 const int *freq_map;
290
+ unsigned int freq_map_size;
291
+
299292 enum chips type;
300293
301294 bool has_vid5; /* true if VID5 is configured for ADT7463 or ADT7468 */
....@@ -514,7 +507,7 @@
514507 data->autofan[i].config =
515508 lm85_read_value(client, LM85_REG_AFAN_CONFIG(i));
516509 val = lm85_read_value(client, LM85_REG_AFAN_RANGE(i));
517
- data->pwm_freq[i] = val & 0x07;
510
+ data->pwm_freq[i] = val % data->freq_map_size;
518511 data->zone[i].range = val >> 4;
519512 data->autofan[i].min_pwm =
520513 lm85_read_value(client, LM85_REG_AFAN_MINPWM(i));
....@@ -556,24 +549,25 @@
556549 }
557550
558551 /* 4 Fans */
559
-static ssize_t show_fan(struct device *dev, struct device_attribute *attr,
560
- char *buf)
552
+static ssize_t fan_show(struct device *dev, struct device_attribute *attr,
553
+ char *buf)
561554 {
562555 int nr = to_sensor_dev_attr(attr)->index;
563556 struct lm85_data *data = lm85_update_device(dev);
564557 return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan[nr]));
565558 }
566559
567
-static ssize_t show_fan_min(struct device *dev, struct device_attribute *attr,
568
- char *buf)
560
+static ssize_t fan_min_show(struct device *dev, struct device_attribute *attr,
561
+ char *buf)
569562 {
570563 int nr = to_sensor_dev_attr(attr)->index;
571564 struct lm85_data *data = lm85_update_device(dev);
572565 return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan_min[nr]));
573566 }
574567
575
-static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr,
576
- const char *buf, size_t count)
568
+static ssize_t fan_min_store(struct device *dev,
569
+ struct device_attribute *attr, const char *buf,
570
+ size_t count)
577571 {
578572 int nr = to_sensor_dev_attr(attr)->index;
579573 struct lm85_data *data = dev_get_drvdata(dev);
....@@ -592,16 +586,14 @@
592586 return count;
593587 }
594588
595
-#define show_fan_offset(offset) \
596
-static SENSOR_DEVICE_ATTR(fan##offset##_input, S_IRUGO, \
597
- show_fan, NULL, offset - 1); \
598
-static SENSOR_DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \
599
- show_fan_min, set_fan_min, offset - 1)
600
-
601
-show_fan_offset(1);
602
-show_fan_offset(2);
603
-show_fan_offset(3);
604
-show_fan_offset(4);
589
+static SENSOR_DEVICE_ATTR_RO(fan1_input, fan, 0);
590
+static SENSOR_DEVICE_ATTR_RW(fan1_min, fan_min, 0);
591
+static SENSOR_DEVICE_ATTR_RO(fan2_input, fan, 1);
592
+static SENSOR_DEVICE_ATTR_RW(fan2_min, fan_min, 1);
593
+static SENSOR_DEVICE_ATTR_RO(fan3_input, fan, 2);
594
+static SENSOR_DEVICE_ATTR_RW(fan3_min, fan_min, 2);
595
+static SENSOR_DEVICE_ATTR_RO(fan4_input, fan, 3);
596
+static SENSOR_DEVICE_ATTR_RW(fan4_min, fan_min, 3);
605597
606598 /* vid, vrm, alarms */
607599
....@@ -660,44 +652,44 @@
660652
661653 static DEVICE_ATTR_RO(alarms);
662654
663
-static ssize_t show_alarm(struct device *dev, struct device_attribute *attr,
664
- char *buf)
655
+static ssize_t alarm_show(struct device *dev, struct device_attribute *attr,
656
+ char *buf)
665657 {
666658 int nr = to_sensor_dev_attr(attr)->index;
667659 struct lm85_data *data = lm85_update_device(dev);
668660 return sprintf(buf, "%u\n", (data->alarms >> nr) & 1);
669661 }
670662
671
-static SENSOR_DEVICE_ATTR(in0_alarm, S_IRUGO, show_alarm, NULL, 0);
672
-static SENSOR_DEVICE_ATTR(in1_alarm, S_IRUGO, show_alarm, NULL, 1);
673
-static SENSOR_DEVICE_ATTR(in2_alarm, S_IRUGO, show_alarm, NULL, 2);
674
-static SENSOR_DEVICE_ATTR(in3_alarm, S_IRUGO, show_alarm, NULL, 3);
675
-static SENSOR_DEVICE_ATTR(in4_alarm, S_IRUGO, show_alarm, NULL, 8);
676
-static SENSOR_DEVICE_ATTR(in5_alarm, S_IRUGO, show_alarm, NULL, 18);
677
-static SENSOR_DEVICE_ATTR(in6_alarm, S_IRUGO, show_alarm, NULL, 16);
678
-static SENSOR_DEVICE_ATTR(in7_alarm, S_IRUGO, show_alarm, NULL, 17);
679
-static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 4);
680
-static SENSOR_DEVICE_ATTR(temp1_fault, S_IRUGO, show_alarm, NULL, 14);
681
-static SENSOR_DEVICE_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL, 5);
682
-static SENSOR_DEVICE_ATTR(temp3_alarm, S_IRUGO, show_alarm, NULL, 6);
683
-static SENSOR_DEVICE_ATTR(temp3_fault, S_IRUGO, show_alarm, NULL, 15);
684
-static SENSOR_DEVICE_ATTR(fan1_alarm, S_IRUGO, show_alarm, NULL, 10);
685
-static SENSOR_DEVICE_ATTR(fan2_alarm, S_IRUGO, show_alarm, NULL, 11);
686
-static SENSOR_DEVICE_ATTR(fan3_alarm, S_IRUGO, show_alarm, NULL, 12);
687
-static SENSOR_DEVICE_ATTR(fan4_alarm, S_IRUGO, show_alarm, NULL, 13);
663
+static SENSOR_DEVICE_ATTR_RO(in0_alarm, alarm, 0);
664
+static SENSOR_DEVICE_ATTR_RO(in1_alarm, alarm, 1);
665
+static SENSOR_DEVICE_ATTR_RO(in2_alarm, alarm, 2);
666
+static SENSOR_DEVICE_ATTR_RO(in3_alarm, alarm, 3);
667
+static SENSOR_DEVICE_ATTR_RO(in4_alarm, alarm, 8);
668
+static SENSOR_DEVICE_ATTR_RO(in5_alarm, alarm, 18);
669
+static SENSOR_DEVICE_ATTR_RO(in6_alarm, alarm, 16);
670
+static SENSOR_DEVICE_ATTR_RO(in7_alarm, alarm, 17);
671
+static SENSOR_DEVICE_ATTR_RO(temp1_alarm, alarm, 4);
672
+static SENSOR_DEVICE_ATTR_RO(temp1_fault, alarm, 14);
673
+static SENSOR_DEVICE_ATTR_RO(temp2_alarm, alarm, 5);
674
+static SENSOR_DEVICE_ATTR_RO(temp3_alarm, alarm, 6);
675
+static SENSOR_DEVICE_ATTR_RO(temp3_fault, alarm, 15);
676
+static SENSOR_DEVICE_ATTR_RO(fan1_alarm, alarm, 10);
677
+static SENSOR_DEVICE_ATTR_RO(fan2_alarm, alarm, 11);
678
+static SENSOR_DEVICE_ATTR_RO(fan3_alarm, alarm, 12);
679
+static SENSOR_DEVICE_ATTR_RO(fan4_alarm, alarm, 13);
688680
689681 /* pwm */
690682
691
-static ssize_t show_pwm(struct device *dev, struct device_attribute *attr,
692
- char *buf)
683
+static ssize_t pwm_show(struct device *dev, struct device_attribute *attr,
684
+ char *buf)
693685 {
694686 int nr = to_sensor_dev_attr(attr)->index;
695687 struct lm85_data *data = lm85_update_device(dev);
696688 return sprintf(buf, "%d\n", PWM_FROM_REG(data->pwm[nr]));
697689 }
698690
699
-static ssize_t set_pwm(struct device *dev, struct device_attribute *attr,
700
- const char *buf, size_t count)
691
+static ssize_t pwm_store(struct device *dev, struct device_attribute *attr,
692
+ const char *buf, size_t count)
701693 {
702694 int nr = to_sensor_dev_attr(attr)->index;
703695 struct lm85_data *data = dev_get_drvdata(dev);
....@@ -716,8 +708,8 @@
716708 return count;
717709 }
718710
719
-static ssize_t show_pwm_enable(struct device *dev, struct device_attribute
720
- *attr, char *buf)
711
+static ssize_t pwm_enable_show(struct device *dev,
712
+ struct device_attribute *attr, char *buf)
721713 {
722714 int nr = to_sensor_dev_attr(attr)->index;
723715 struct lm85_data *data = lm85_update_device(dev);
....@@ -738,8 +730,9 @@
738730 return sprintf(buf, "%d\n", enable);
739731 }
740732
741
-static ssize_t set_pwm_enable(struct device *dev, struct device_attribute
742
- *attr, const char *buf, size_t count)
733
+static ssize_t pwm_enable_store(struct device *dev,
734
+ struct device_attribute *attr,
735
+ const char *buf, size_t count)
743736 {
744737 int nr = to_sensor_dev_attr(attr)->index;
745738 struct lm85_data *data = dev_get_drvdata(dev);
....@@ -781,8 +774,8 @@
781774 return count;
782775 }
783776
784
-static ssize_t show_pwm_freq(struct device *dev,
785
- struct device_attribute *attr, char *buf)
777
+static ssize_t pwm_freq_show(struct device *dev,
778
+ struct device_attribute *attr, char *buf)
786779 {
787780 int nr = to_sensor_dev_attr(attr)->index;
788781 struct lm85_data *data = lm85_update_device(dev);
....@@ -791,13 +784,15 @@
791784 if (IS_ADT7468_HFPWM(data))
792785 freq = 22500;
793786 else
794
- freq = FREQ_FROM_REG(data->freq_map, data->pwm_freq[nr]);
787
+ freq = FREQ_FROM_REG(data->freq_map, data->freq_map_size,
788
+ data->pwm_freq[nr]);
795789
796790 return sprintf(buf, "%d\n", freq);
797791 }
798792
799
-static ssize_t set_pwm_freq(struct device *dev,
800
- struct device_attribute *attr, const char *buf, size_t count)
793
+static ssize_t pwm_freq_store(struct device *dev,
794
+ struct device_attribute *attr, const char *buf,
795
+ size_t count)
801796 {
802797 int nr = to_sensor_dev_attr(attr)->index;
803798 struct lm85_data *data = dev_get_drvdata(dev);
....@@ -820,7 +815,7 @@
820815 lm85_write_value(client, ADT7468_REG_CFG5, data->cfg5);
821816 } else { /* Low freq. mode */
822817 data->pwm_freq[nr] = FREQ_TO_REG(data->freq_map,
823
- FREQ_MAP_LEN, val);
818
+ data->freq_map_size, val);
824819 lm85_write_value(client, LM85_REG_AFAN_RANGE(nr),
825820 (data->zone[nr].range << 4)
826821 | data->pwm_freq[nr]);
....@@ -833,22 +828,20 @@
833828 return count;
834829 }
835830
836
-#define show_pwm_reg(offset) \
837
-static SENSOR_DEVICE_ATTR(pwm##offset, S_IRUGO | S_IWUSR, \
838
- show_pwm, set_pwm, offset - 1); \
839
-static SENSOR_DEVICE_ATTR(pwm##offset##_enable, S_IRUGO | S_IWUSR, \
840
- show_pwm_enable, set_pwm_enable, offset - 1); \
841
-static SENSOR_DEVICE_ATTR(pwm##offset##_freq, S_IRUGO | S_IWUSR, \
842
- show_pwm_freq, set_pwm_freq, offset - 1)
843
-
844
-show_pwm_reg(1);
845
-show_pwm_reg(2);
846
-show_pwm_reg(3);
831
+static SENSOR_DEVICE_ATTR_RW(pwm1, pwm, 0);
832
+static SENSOR_DEVICE_ATTR_RW(pwm1_enable, pwm_enable, 0);
833
+static SENSOR_DEVICE_ATTR_RW(pwm1_freq, pwm_freq, 0);
834
+static SENSOR_DEVICE_ATTR_RW(pwm2, pwm, 1);
835
+static SENSOR_DEVICE_ATTR_RW(pwm2_enable, pwm_enable, 1);
836
+static SENSOR_DEVICE_ATTR_RW(pwm2_freq, pwm_freq, 1);
837
+static SENSOR_DEVICE_ATTR_RW(pwm3, pwm, 2);
838
+static SENSOR_DEVICE_ATTR_RW(pwm3_enable, pwm_enable, 2);
839
+static SENSOR_DEVICE_ATTR_RW(pwm3_freq, pwm_freq, 2);
847840
848841 /* Voltages */
849842
850
-static ssize_t show_in(struct device *dev, struct device_attribute *attr,
851
- char *buf)
843
+static ssize_t in_show(struct device *dev, struct device_attribute *attr,
844
+ char *buf)
852845 {
853846 int nr = to_sensor_dev_attr(attr)->index;
854847 struct lm85_data *data = lm85_update_device(dev);
....@@ -856,16 +849,16 @@
856849 data->in_ext[nr]));
857850 }
858851
859
-static ssize_t show_in_min(struct device *dev, struct device_attribute *attr,
860
- char *buf)
852
+static ssize_t in_min_show(struct device *dev, struct device_attribute *attr,
853
+ char *buf)
861854 {
862855 int nr = to_sensor_dev_attr(attr)->index;
863856 struct lm85_data *data = lm85_update_device(dev);
864857 return sprintf(buf, "%d\n", INS_FROM_REG(nr, data->in_min[nr]));
865858 }
866859
867
-static ssize_t set_in_min(struct device *dev, struct device_attribute *attr,
868
- const char *buf, size_t count)
860
+static ssize_t in_min_store(struct device *dev, struct device_attribute *attr,
861
+ const char *buf, size_t count)
869862 {
870863 int nr = to_sensor_dev_attr(attr)->index;
871864 struct lm85_data *data = dev_get_drvdata(dev);
....@@ -884,16 +877,16 @@
884877 return count;
885878 }
886879
887
-static ssize_t show_in_max(struct device *dev, struct device_attribute *attr,
888
- char *buf)
880
+static ssize_t in_max_show(struct device *dev, struct device_attribute *attr,
881
+ char *buf)
889882 {
890883 int nr = to_sensor_dev_attr(attr)->index;
891884 struct lm85_data *data = lm85_update_device(dev);
892885 return sprintf(buf, "%d\n", INS_FROM_REG(nr, data->in_max[nr]));
893886 }
894887
895
-static ssize_t set_in_max(struct device *dev, struct device_attribute *attr,
896
- const char *buf, size_t count)
888
+static ssize_t in_max_store(struct device *dev, struct device_attribute *attr,
889
+ const char *buf, size_t count)
897890 {
898891 int nr = to_sensor_dev_attr(attr)->index;
899892 struct lm85_data *data = dev_get_drvdata(dev);
....@@ -912,27 +905,35 @@
912905 return count;
913906 }
914907
915
-#define show_in_reg(offset) \
916
-static SENSOR_DEVICE_ATTR(in##offset##_input, S_IRUGO, \
917
- show_in, NULL, offset); \
918
-static SENSOR_DEVICE_ATTR(in##offset##_min, S_IRUGO | S_IWUSR, \
919
- show_in_min, set_in_min, offset); \
920
-static SENSOR_DEVICE_ATTR(in##offset##_max, S_IRUGO | S_IWUSR, \
921
- show_in_max, set_in_max, offset)
922
-
923
-show_in_reg(0);
924
-show_in_reg(1);
925
-show_in_reg(2);
926
-show_in_reg(3);
927
-show_in_reg(4);
928
-show_in_reg(5);
929
-show_in_reg(6);
930
-show_in_reg(7);
908
+static SENSOR_DEVICE_ATTR_RO(in0_input, in, 0);
909
+static SENSOR_DEVICE_ATTR_RW(in0_min, in_min, 0);
910
+static SENSOR_DEVICE_ATTR_RW(in0_max, in_max, 0);
911
+static SENSOR_DEVICE_ATTR_RO(in1_input, in, 1);
912
+static SENSOR_DEVICE_ATTR_RW(in1_min, in_min, 1);
913
+static SENSOR_DEVICE_ATTR_RW(in1_max, in_max, 1);
914
+static SENSOR_DEVICE_ATTR_RO(in2_input, in, 2);
915
+static SENSOR_DEVICE_ATTR_RW(in2_min, in_min, 2);
916
+static SENSOR_DEVICE_ATTR_RW(in2_max, in_max, 2);
917
+static SENSOR_DEVICE_ATTR_RO(in3_input, in, 3);
918
+static SENSOR_DEVICE_ATTR_RW(in3_min, in_min, 3);
919
+static SENSOR_DEVICE_ATTR_RW(in3_max, in_max, 3);
920
+static SENSOR_DEVICE_ATTR_RO(in4_input, in, 4);
921
+static SENSOR_DEVICE_ATTR_RW(in4_min, in_min, 4);
922
+static SENSOR_DEVICE_ATTR_RW(in4_max, in_max, 4);
923
+static SENSOR_DEVICE_ATTR_RO(in5_input, in, 5);
924
+static SENSOR_DEVICE_ATTR_RW(in5_min, in_min, 5);
925
+static SENSOR_DEVICE_ATTR_RW(in5_max, in_max, 5);
926
+static SENSOR_DEVICE_ATTR_RO(in6_input, in, 6);
927
+static SENSOR_DEVICE_ATTR_RW(in6_min, in_min, 6);
928
+static SENSOR_DEVICE_ATTR_RW(in6_max, in_max, 6);
929
+static SENSOR_DEVICE_ATTR_RO(in7_input, in, 7);
930
+static SENSOR_DEVICE_ATTR_RW(in7_min, in_min, 7);
931
+static SENSOR_DEVICE_ATTR_RW(in7_max, in_max, 7);
931932
932933 /* Temps */
933934
934
-static ssize_t show_temp(struct device *dev, struct device_attribute *attr,
935
- char *buf)
935
+static ssize_t temp_show(struct device *dev, struct device_attribute *attr,
936
+ char *buf)
936937 {
937938 int nr = to_sensor_dev_attr(attr)->index;
938939 struct lm85_data *data = lm85_update_device(dev);
....@@ -940,16 +941,17 @@
940941 data->temp_ext[nr]));
941942 }
942943
943
-static ssize_t show_temp_min(struct device *dev, struct device_attribute *attr,
944
- char *buf)
944
+static ssize_t temp_min_show(struct device *dev,
945
+ struct device_attribute *attr, char *buf)
945946 {
946947 int nr = to_sensor_dev_attr(attr)->index;
947948 struct lm85_data *data = lm85_update_device(dev);
948949 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_min[nr]));
949950 }
950951
951
-static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr,
952
- const char *buf, size_t count)
952
+static ssize_t temp_min_store(struct device *dev,
953
+ struct device_attribute *attr, const char *buf,
954
+ size_t count)
953955 {
954956 int nr = to_sensor_dev_attr(attr)->index;
955957 struct lm85_data *data = dev_get_drvdata(dev);
....@@ -971,16 +973,17 @@
971973 return count;
972974 }
973975
974
-static ssize_t show_temp_max(struct device *dev, struct device_attribute *attr,
975
- char *buf)
976
+static ssize_t temp_max_show(struct device *dev,
977
+ struct device_attribute *attr, char *buf)
976978 {
977979 int nr = to_sensor_dev_attr(attr)->index;
978980 struct lm85_data *data = lm85_update_device(dev);
979981 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_max[nr]));
980982 }
981983
982
-static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr,
983
- const char *buf, size_t count)
984
+static ssize_t temp_max_store(struct device *dev,
985
+ struct device_attribute *attr, const char *buf,
986
+ size_t count)
984987 {
985988 int nr = to_sensor_dev_attr(attr)->index;
986989 struct lm85_data *data = dev_get_drvdata(dev);
....@@ -1002,31 +1005,30 @@
10021005 return count;
10031006 }
10041007
1005
-#define show_temp_reg(offset) \
1006
-static SENSOR_DEVICE_ATTR(temp##offset##_input, S_IRUGO, \
1007
- show_temp, NULL, offset - 1); \
1008
-static SENSOR_DEVICE_ATTR(temp##offset##_min, S_IRUGO | S_IWUSR, \
1009
- show_temp_min, set_temp_min, offset - 1); \
1010
-static SENSOR_DEVICE_ATTR(temp##offset##_max, S_IRUGO | S_IWUSR, \
1011
- show_temp_max, set_temp_max, offset - 1);
1012
-
1013
-show_temp_reg(1);
1014
-show_temp_reg(2);
1015
-show_temp_reg(3);
1016
-
1008
+static SENSOR_DEVICE_ATTR_RO(temp1_input, temp, 0);
1009
+static SENSOR_DEVICE_ATTR_RW(temp1_min, temp_min, 0);
1010
+static SENSOR_DEVICE_ATTR_RW(temp1_max, temp_max, 0);
1011
+static SENSOR_DEVICE_ATTR_RO(temp2_input, temp, 1);
1012
+static SENSOR_DEVICE_ATTR_RW(temp2_min, temp_min, 1);
1013
+static SENSOR_DEVICE_ATTR_RW(temp2_max, temp_max, 1);
1014
+static SENSOR_DEVICE_ATTR_RO(temp3_input, temp, 2);
1015
+static SENSOR_DEVICE_ATTR_RW(temp3_min, temp_min, 2);
1016
+static SENSOR_DEVICE_ATTR_RW(temp3_max, temp_max, 2);
10171017
10181018 /* Automatic PWM control */
10191019
1020
-static ssize_t show_pwm_auto_channels(struct device *dev,
1021
- struct device_attribute *attr, char *buf)
1020
+static ssize_t pwm_auto_channels_show(struct device *dev,
1021
+ struct device_attribute *attr,
1022
+ char *buf)
10221023 {
10231024 int nr = to_sensor_dev_attr(attr)->index;
10241025 struct lm85_data *data = lm85_update_device(dev);
10251026 return sprintf(buf, "%d\n", ZONE_FROM_REG(data->autofan[nr].config));
10261027 }
10271028
1028
-static ssize_t set_pwm_auto_channels(struct device *dev,
1029
- struct device_attribute *attr, const char *buf, size_t count)
1029
+static ssize_t pwm_auto_channels_store(struct device *dev,
1030
+ struct device_attribute *attr,
1031
+ const char *buf, size_t count)
10301032 {
10311033 int nr = to_sensor_dev_attr(attr)->index;
10321034 struct lm85_data *data = dev_get_drvdata(dev);
....@@ -1047,16 +1049,17 @@
10471049 return count;
10481050 }
10491051
1050
-static ssize_t show_pwm_auto_pwm_min(struct device *dev,
1051
- struct device_attribute *attr, char *buf)
1052
+static ssize_t pwm_auto_pwm_min_show(struct device *dev,
1053
+ struct device_attribute *attr, char *buf)
10521054 {
10531055 int nr = to_sensor_dev_attr(attr)->index;
10541056 struct lm85_data *data = lm85_update_device(dev);
10551057 return sprintf(buf, "%d\n", PWM_FROM_REG(data->autofan[nr].min_pwm));
10561058 }
10571059
1058
-static ssize_t set_pwm_auto_pwm_min(struct device *dev,
1059
- struct device_attribute *attr, const char *buf, size_t count)
1060
+static ssize_t pwm_auto_pwm_min_store(struct device *dev,
1061
+ struct device_attribute *attr,
1062
+ const char *buf, size_t count)
10601063 {
10611064 int nr = to_sensor_dev_attr(attr)->index;
10621065 struct lm85_data *data = dev_get_drvdata(dev);
....@@ -1076,16 +1079,18 @@
10761079 return count;
10771080 }
10781081
1079
-static ssize_t show_pwm_auto_pwm_minctl(struct device *dev,
1080
- struct device_attribute *attr, char *buf)
1082
+static ssize_t pwm_auto_pwm_minctl_show(struct device *dev,
1083
+ struct device_attribute *attr,
1084
+ char *buf)
10811085 {
10821086 int nr = to_sensor_dev_attr(attr)->index;
10831087 struct lm85_data *data = lm85_update_device(dev);
10841088 return sprintf(buf, "%d\n", data->autofan[nr].min_off);
10851089 }
10861090
1087
-static ssize_t set_pwm_auto_pwm_minctl(struct device *dev,
1088
- struct device_attribute *attr, const char *buf, size_t count)
1091
+static ssize_t pwm_auto_pwm_minctl_store(struct device *dev,
1092
+ struct device_attribute *attr,
1093
+ const char *buf, size_t count)
10891094 {
10901095 int nr = to_sensor_dev_attr(attr)->index;
10911096 struct lm85_data *data = dev_get_drvdata(dev);
....@@ -1109,25 +1114,21 @@
11091114 return count;
11101115 }
11111116
1112
-#define pwm_auto(offset) \
1113
-static SENSOR_DEVICE_ATTR(pwm##offset##_auto_channels, \
1114
- S_IRUGO | S_IWUSR, show_pwm_auto_channels, \
1115
- set_pwm_auto_channels, offset - 1); \
1116
-static SENSOR_DEVICE_ATTR(pwm##offset##_auto_pwm_min, \
1117
- S_IRUGO | S_IWUSR, show_pwm_auto_pwm_min, \
1118
- set_pwm_auto_pwm_min, offset - 1); \
1119
-static SENSOR_DEVICE_ATTR(pwm##offset##_auto_pwm_minctl, \
1120
- S_IRUGO | S_IWUSR, show_pwm_auto_pwm_minctl, \
1121
- set_pwm_auto_pwm_minctl, offset - 1)
1122
-
1123
-pwm_auto(1);
1124
-pwm_auto(2);
1125
-pwm_auto(3);
1117
+static SENSOR_DEVICE_ATTR_RW(pwm1_auto_channels, pwm_auto_channels, 0);
1118
+static SENSOR_DEVICE_ATTR_RW(pwm1_auto_pwm_min, pwm_auto_pwm_min, 0);
1119
+static SENSOR_DEVICE_ATTR_RW(pwm1_auto_pwm_minctl, pwm_auto_pwm_minctl, 0);
1120
+static SENSOR_DEVICE_ATTR_RW(pwm2_auto_channels, pwm_auto_channels, 1);
1121
+static SENSOR_DEVICE_ATTR_RW(pwm2_auto_pwm_min, pwm_auto_pwm_min, 1);
1122
+static SENSOR_DEVICE_ATTR_RW(pwm2_auto_pwm_minctl, pwm_auto_pwm_minctl, 1);
1123
+static SENSOR_DEVICE_ATTR_RW(pwm3_auto_channels, pwm_auto_channels, 2);
1124
+static SENSOR_DEVICE_ATTR_RW(pwm3_auto_pwm_min, pwm_auto_pwm_min, 2);
1125
+static SENSOR_DEVICE_ATTR_RW(pwm3_auto_pwm_minctl, pwm_auto_pwm_minctl, 2);
11261126
11271127 /* Temperature settings for automatic PWM control */
11281128
1129
-static ssize_t show_temp_auto_temp_off(struct device *dev,
1130
- struct device_attribute *attr, char *buf)
1129
+static ssize_t temp_auto_temp_off_show(struct device *dev,
1130
+ struct device_attribute *attr,
1131
+ char *buf)
11311132 {
11321133 int nr = to_sensor_dev_attr(attr)->index;
11331134 struct lm85_data *data = lm85_update_device(dev);
....@@ -1135,8 +1136,9 @@
11351136 HYST_FROM_REG(data->zone[nr].hyst));
11361137 }
11371138
1138
-static ssize_t set_temp_auto_temp_off(struct device *dev,
1139
- struct device_attribute *attr, const char *buf, size_t count)
1139
+static ssize_t temp_auto_temp_off_store(struct device *dev,
1140
+ struct device_attribute *attr,
1141
+ const char *buf, size_t count)
11401142 {
11411143 int nr = to_sensor_dev_attr(attr)->index;
11421144 struct lm85_data *data = dev_get_drvdata(dev);
....@@ -1164,16 +1166,18 @@
11641166 return count;
11651167 }
11661168
1167
-static ssize_t show_temp_auto_temp_min(struct device *dev,
1168
- struct device_attribute *attr, char *buf)
1169
+static ssize_t temp_auto_temp_min_show(struct device *dev,
1170
+ struct device_attribute *attr,
1171
+ char *buf)
11691172 {
11701173 int nr = to_sensor_dev_attr(attr)->index;
11711174 struct lm85_data *data = lm85_update_device(dev);
11721175 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->zone[nr].limit));
11731176 }
11741177
1175
-static ssize_t set_temp_auto_temp_min(struct device *dev,
1176
- struct device_attribute *attr, const char *buf, size_t count)
1178
+static ssize_t temp_auto_temp_min_store(struct device *dev,
1179
+ struct device_attribute *attr,
1180
+ const char *buf, size_t count)
11771181 {
11781182 int nr = to_sensor_dev_attr(attr)->index;
11791183 struct lm85_data *data = dev_get_drvdata(dev);
....@@ -1196,14 +1200,15 @@
11961200 TEMP_FROM_REG(data->zone[nr].limit));
11971201 lm85_write_value(client, LM85_REG_AFAN_RANGE(nr),
11981202 ((data->zone[nr].range & 0x0f) << 4)
1199
- | (data->pwm_freq[nr] & 0x07));
1203
+ | data->pwm_freq[nr]);
12001204
12011205 mutex_unlock(&data->update_lock);
12021206 return count;
12031207 }
12041208
1205
-static ssize_t show_temp_auto_temp_max(struct device *dev,
1206
- struct device_attribute *attr, char *buf)
1209
+static ssize_t temp_auto_temp_max_show(struct device *dev,
1210
+ struct device_attribute *attr,
1211
+ char *buf)
12071212 {
12081213 int nr = to_sensor_dev_attr(attr)->index;
12091214 struct lm85_data *data = lm85_update_device(dev);
....@@ -1211,8 +1216,9 @@
12111216 RANGE_FROM_REG(data->zone[nr].range));
12121217 }
12131218
1214
-static ssize_t set_temp_auto_temp_max(struct device *dev,
1215
- struct device_attribute *attr, const char *buf, size_t count)
1219
+static ssize_t temp_auto_temp_max_store(struct device *dev,
1220
+ struct device_attribute *attr,
1221
+ const char *buf, size_t count)
12161222 {
12171223 int nr = to_sensor_dev_attr(attr)->index;
12181224 struct lm85_data *data = dev_get_drvdata(dev);
....@@ -1232,21 +1238,23 @@
12321238 val - min);
12331239 lm85_write_value(client, LM85_REG_AFAN_RANGE(nr),
12341240 ((data->zone[nr].range & 0x0f) << 4)
1235
- | (data->pwm_freq[nr] & 0x07));
1241
+ | data->pwm_freq[nr]);
12361242 mutex_unlock(&data->update_lock);
12371243 return count;
12381244 }
12391245
1240
-static ssize_t show_temp_auto_temp_crit(struct device *dev,
1241
- struct device_attribute *attr, char *buf)
1246
+static ssize_t temp_auto_temp_crit_show(struct device *dev,
1247
+ struct device_attribute *attr,
1248
+ char *buf)
12421249 {
12431250 int nr = to_sensor_dev_attr(attr)->index;
12441251 struct lm85_data *data = lm85_update_device(dev);
12451252 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->zone[nr].critical));
12461253 }
12471254
1248
-static ssize_t set_temp_auto_temp_crit(struct device *dev,
1249
- struct device_attribute *attr, const char *buf, size_t count)
1255
+static ssize_t temp_auto_temp_crit_store(struct device *dev,
1256
+ struct device_attribute *attr,
1257
+ const char *buf, size_t count)
12501258 {
12511259 int nr = to_sensor_dev_attr(attr)->index;
12521260 struct lm85_data *data = dev_get_drvdata(dev);
....@@ -1266,23 +1274,18 @@
12661274 return count;
12671275 }
12681276
1269
-#define temp_auto(offset) \
1270
-static SENSOR_DEVICE_ATTR(temp##offset##_auto_temp_off, \
1271
- S_IRUGO | S_IWUSR, show_temp_auto_temp_off, \
1272
- set_temp_auto_temp_off, offset - 1); \
1273
-static SENSOR_DEVICE_ATTR(temp##offset##_auto_temp_min, \
1274
- S_IRUGO | S_IWUSR, show_temp_auto_temp_min, \
1275
- set_temp_auto_temp_min, offset - 1); \
1276
-static SENSOR_DEVICE_ATTR(temp##offset##_auto_temp_max, \
1277
- S_IRUGO | S_IWUSR, show_temp_auto_temp_max, \
1278
- set_temp_auto_temp_max, offset - 1); \
1279
-static SENSOR_DEVICE_ATTR(temp##offset##_auto_temp_crit, \
1280
- S_IRUGO | S_IWUSR, show_temp_auto_temp_crit, \
1281
- set_temp_auto_temp_crit, offset - 1);
1282
-
1283
-temp_auto(1);
1284
-temp_auto(2);
1285
-temp_auto(3);
1277
+static SENSOR_DEVICE_ATTR_RW(temp1_auto_temp_off, temp_auto_temp_off, 0);
1278
+static SENSOR_DEVICE_ATTR_RW(temp1_auto_temp_min, temp_auto_temp_min, 0);
1279
+static SENSOR_DEVICE_ATTR_RW(temp1_auto_temp_max, temp_auto_temp_max, 0);
1280
+static SENSOR_DEVICE_ATTR_RW(temp1_auto_temp_crit, temp_auto_temp_crit, 0);
1281
+static SENSOR_DEVICE_ATTR_RW(temp2_auto_temp_off, temp_auto_temp_off, 1);
1282
+static SENSOR_DEVICE_ATTR_RW(temp2_auto_temp_min, temp_auto_temp_min, 1);
1283
+static SENSOR_DEVICE_ATTR_RW(temp2_auto_temp_max, temp_auto_temp_max, 1);
1284
+static SENSOR_DEVICE_ATTR_RW(temp2_auto_temp_crit, temp_auto_temp_crit, 1);
1285
+static SENSOR_DEVICE_ATTR_RW(temp3_auto_temp_off, temp_auto_temp_off, 2);
1286
+static SENSOR_DEVICE_ATTR_RW(temp3_auto_temp_min, temp_auto_temp_min, 2);
1287
+static SENSOR_DEVICE_ATTR_RW(temp3_auto_temp_max, temp_auto_temp_max, 2);
1288
+static SENSOR_DEVICE_ATTR_RW(temp3_auto_temp_crit, temp_auto_temp_crit, 2);
12861289
12871290 static struct attribute *lm85_attributes[] = {
12881291 &sensor_dev_attr_fan1_input.dev_attr.attr,
....@@ -1496,7 +1499,7 @@
14961499 "Found Winbond WPCD377I, ignoring\n");
14971500 return -ENODEV;
14981501 }
1499
- type_name = "lm85";
1502
+ type_name = "lm96000";
15001503 break;
15011504 }
15021505 } else if (company == LM85_COMPANY_ANALOG_DEV) {
....@@ -1541,7 +1544,9 @@
15411544 return 0;
15421545 }
15431546
1544
-static int lm85_probe(struct i2c_client *client, const struct i2c_device_id *id)
1547
+static const struct i2c_device_id lm85_id[];
1548
+
1549
+static int lm85_probe(struct i2c_client *client)
15451550 {
15461551 struct device *dev = &client->dev;
15471552 struct device *hwmon_dev;
....@@ -1556,7 +1561,7 @@
15561561 if (client->dev.of_node)
15571562 data->type = (enum chips)of_device_get_match_data(&client->dev);
15581563 else
1559
- data->type = id->driver_data;
1564
+ data->type = i2c_match_id(lm85_id, client)->driver_data;
15601565 mutex_init(&data->update_lock);
15611566
15621567 /* Fill in the chip specific driver values */
....@@ -1569,9 +1574,15 @@
15691574 case emc6d103:
15701575 case emc6d103s:
15711576 data->freq_map = adm1027_freq_map;
1577
+ data->freq_map_size = ARRAY_SIZE(adm1027_freq_map);
1578
+ break;
1579
+ case lm96000:
1580
+ data->freq_map = lm96000_freq_map;
1581
+ data->freq_map_size = ARRAY_SIZE(lm96000_freq_map);
15721582 break;
15731583 default:
15741584 data->freq_map = lm85_freq_map;
1585
+ data->freq_map_size = ARRAY_SIZE(lm85_freq_map);
15751586 }
15761587
15771588 /* Set the VRM version */
....@@ -1618,6 +1629,7 @@
16181629 { "lm85", lm85 },
16191630 { "lm85b", lm85 },
16201631 { "lm85c", lm85 },
1632
+ { "lm96000", lm96000 },
16211633 { "emc6d100", emc6d100 },
16221634 { "emc6d101", emc6d100 },
16231635 { "emc6d102", emc6d102 },
....@@ -1627,7 +1639,7 @@
16271639 };
16281640 MODULE_DEVICE_TABLE(i2c, lm85_id);
16291641
1630
-static const struct of_device_id lm85_of_match[] = {
1642
+static const struct of_device_id __maybe_unused lm85_of_match[] = {
16311643 {
16321644 .compatible = "adi,adm1027",
16331645 .data = (void *)adm1027
....@@ -1651,6 +1663,10 @@
16511663 {
16521664 .compatible = "national,lm85c",
16531665 .data = (void *)lm85
1666
+ },
1667
+ {
1668
+ .compatible = "ti,lm96000",
1669
+ .data = (void *)lm96000
16541670 },
16551671 {
16561672 .compatible = "smsc,emc6d100",
....@@ -1682,7 +1698,7 @@
16821698 .name = "lm85",
16831699 .of_match_table = of_match_ptr(lm85_of_match),
16841700 },
1685
- .probe = lm85_probe,
1701
+ .probe_new = lm85_probe,
16861702 .id_table = lm85_id,
16871703 .detect = lm85_detect,
16881704 .address_list = normal_i2c,