aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon/adt7470.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/hwmon/adt7470.c')
-rw-r--r--drivers/hwmon/adt7470.c100
1 files changed, 85 insertions, 15 deletions
diff --git a/drivers/hwmon/adt7470.c b/drivers/hwmon/adt7470.c
index 9810aaa0489d..747693ab2ff1 100644
--- a/drivers/hwmon/adt7470.c
+++ b/drivers/hwmon/adt7470.c
@@ -48,7 +48,22 @@ I2C_CLIENT_INSMOD_1(adt7470);
48#define ADT7470_REG_CFG 0x40 48#define ADT7470_REG_CFG 0x40
49#define ADT7470_FSPD_MASK 0x04 49#define ADT7470_FSPD_MASK 0x04
50#define ADT7470_REG_ALARM1 0x41 50#define ADT7470_REG_ALARM1 0x41
51#define ADT7470_R1T_ALARM 0x01
52#define ADT7470_R2T_ALARM 0x02
53#define ADT7470_R3T_ALARM 0x04
54#define ADT7470_R4T_ALARM 0x08
55#define ADT7470_R5T_ALARM 0x10
56#define ADT7470_R6T_ALARM 0x20
57#define ADT7470_R7T_ALARM 0x40
58#define ADT7470_OOL_ALARM 0x80
51#define ADT7470_REG_ALARM2 0x42 59#define ADT7470_REG_ALARM2 0x42
60#define ADT7470_R8T_ALARM 0x01
61#define ADT7470_R9T_ALARM 0x02
62#define ADT7470_R10T_ALARM 0x04
63#define ADT7470_FAN1_ALARM 0x10
64#define ADT7470_FAN2_ALARM 0x20
65#define ADT7470_FAN3_ALARM 0x40
66#define ADT7470_FAN4_ALARM 0x80
52#define ADT7470_REG_TEMP_LIMITS_BASE_ADDR 0x44 67#define ADT7470_REG_TEMP_LIMITS_BASE_ADDR 0x44
53#define ADT7470_REG_TEMP_LIMITS_MAX_ADDR 0x57 68#define ADT7470_REG_TEMP_LIMITS_MAX_ADDR 0x57
54#define ADT7470_REG_FAN_MIN_BASE_ADDR 0x58 69#define ADT7470_REG_FAN_MIN_BASE_ADDR 0x58
@@ -97,6 +112,8 @@ I2C_CLIENT_INSMOD_1(adt7470);
97#define ADT7470_REG_PWM_AUTO_TEMP(x) (ADT7470_REG_PWM_AUTO_TEMP_BASE_ADDR + \ 112#define ADT7470_REG_PWM_AUTO_TEMP(x) (ADT7470_REG_PWM_AUTO_TEMP_BASE_ADDR + \
98 ((x) / 2)) 113 ((x) / 2))
99 114
115#define ALARM2(x) ((x) << 8)
116
100#define ADT7470_VENDOR 0x41 117#define ADT7470_VENDOR 0x41
101#define ADT7470_DEVICE 0x70 118#define ADT7470_DEVICE 0x70
102/* datasheet only mentions a revision 2 */ 119/* datasheet only mentions a revision 2 */
@@ -114,8 +131,6 @@ I2C_CLIENT_INSMOD_1(adt7470);
114/* sleep 1s while gathering temperature data */ 131/* sleep 1s while gathering temperature data */
115#define TEMP_COLLECTION_TIME 1000 132#define TEMP_COLLECTION_TIME 1000
116 133
117#define power_of_2(x) (((x) & ((x) - 1)) == 0)
118
119/* datasheet says to divide this number by the fan reading to get fan rpm */ 134/* datasheet says to divide this number by the fan reading to get fan rpm */
120#define FAN_PERIOD_TO_RPM(x) ((90000 * 60) / (x)) 135#define FAN_PERIOD_TO_RPM(x) ((90000 * 60) / (x))
121#define FAN_RPM_TO_PERIOD FAN_PERIOD_TO_RPM 136#define FAN_RPM_TO_PERIOD FAN_PERIOD_TO_RPM
@@ -138,7 +153,8 @@ struct adt7470_data {
138 u16 fan[ADT7470_FAN_COUNT]; 153 u16 fan[ADT7470_FAN_COUNT];
139 u16 fan_min[ADT7470_FAN_COUNT]; 154 u16 fan_min[ADT7470_FAN_COUNT];
140 u16 fan_max[ADT7470_FAN_COUNT]; 155 u16 fan_max[ADT7470_FAN_COUNT];
141 u16 alarms, alarms_mask; 156 u16 alarm;
157 u16 alarms_mask;
142 u8 force_pwm_max; 158 u8 force_pwm_max;
143 u8 pwm[ADT7470_PWM_COUNT]; 159 u8 pwm[ADT7470_PWM_COUNT];
144 u8 pwm_max[ADT7470_PWM_COUNT]; 160 u8 pwm_max[ADT7470_PWM_COUNT];
@@ -262,7 +278,10 @@ static struct adt7470_data *adt7470_update_device(struct device *dev)
262 else 278 else
263 data->force_pwm_max = 0; 279 data->force_pwm_max = 0;
264 280
265 data->alarms = adt7470_read_word_data(client, ADT7470_REG_ALARM1); 281 data->alarm = i2c_smbus_read_byte_data(client, ADT7470_REG_ALARM1);
282 if (data->alarm & ADT7470_OOL_ALARM)
283 data->alarm |= ALARM2(i2c_smbus_read_byte_data(client,
284 ADT7470_REG_ALARM2));
266 data->alarms_mask = adt7470_read_word_data(client, 285 data->alarms_mask = adt7470_read_word_data(client,
267 ADT7470_REG_ALARM1_MASK); 286 ADT7470_REG_ALARM1_MASK);
268 287
@@ -370,17 +389,13 @@ static ssize_t show_temp(struct device *dev, struct device_attribute *devattr,
370 return sprintf(buf, "%d\n", 1000 * data->temp[attr->index]); 389 return sprintf(buf, "%d\n", 1000 * data->temp[attr->index]);
371} 390}
372 391
373static ssize_t show_alarms(struct device *dev, 392static ssize_t show_alarm_mask(struct device *dev,
374 struct device_attribute *devattr, 393 struct device_attribute *devattr,
375 char *buf) 394 char *buf)
376{ 395{
377 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
378 struct adt7470_data *data = adt7470_update_device(dev); 396 struct adt7470_data *data = adt7470_update_device(dev);
379 397
380 if (attr->index) 398 return sprintf(buf, "%x\n", data->alarms_mask);
381 return sprintf(buf, "%x\n", data->alarms);
382 else
383 return sprintf(buf, "%x\n", data->alarms_mask);
384} 399}
385 400
386static ssize_t show_fan_max(struct device *dev, 401static ssize_t show_fan_max(struct device *dev,
@@ -677,7 +692,7 @@ static int cvt_auto_temp(int input)
677{ 692{
678 if (input == ADT7470_PWM_ALL_TEMPS) 693 if (input == ADT7470_PWM_ALL_TEMPS)
679 return 0; 694 return 0;
680 if (input < 1 || !power_of_2(input)) 695 if (input < 1 || !is_power_of_2(input))
681 return -EINVAL; 696 return -EINVAL;
682 return ilog2(input) + 1; 697 return ilog2(input) + 1;
683} 698}
@@ -715,8 +730,20 @@ static ssize_t set_pwm_auto_temp(struct device *dev,
715 return count; 730 return count;
716} 731}
717 732
718static SENSOR_DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL, 0); 733static ssize_t show_alarm(struct device *dev,
719static SENSOR_DEVICE_ATTR(alarm_mask, S_IRUGO, show_alarms, NULL, 1); 734 struct device_attribute *devattr,
735 char *buf)
736{
737 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
738 struct adt7470_data *data = adt7470_update_device(dev);
739
740 if (data->alarm & attr->index)
741 return sprintf(buf, "1\n");
742 else
743 return sprintf(buf, "0\n");
744}
745
746static DEVICE_ATTR(alarm_mask, S_IRUGO, show_alarm_mask, NULL);
720 747
721static SENSOR_DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, show_temp_max, 748static SENSOR_DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, show_temp_max,
722 set_temp_max, 0); 749 set_temp_max, 0);
@@ -771,6 +798,27 @@ static SENSOR_DEVICE_ATTR(temp8_input, S_IRUGO, show_temp, NULL, 7);
771static SENSOR_DEVICE_ATTR(temp9_input, S_IRUGO, show_temp, NULL, 8); 798static SENSOR_DEVICE_ATTR(temp9_input, S_IRUGO, show_temp, NULL, 8);
772static SENSOR_DEVICE_ATTR(temp10_input, S_IRUGO, show_temp, NULL, 9); 799static SENSOR_DEVICE_ATTR(temp10_input, S_IRUGO, show_temp, NULL, 9);
773 800
801static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL,
802 ADT7470_R1T_ALARM);
803static SENSOR_DEVICE_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL,
804 ADT7470_R2T_ALARM);
805static SENSOR_DEVICE_ATTR(temp3_alarm, S_IRUGO, show_alarm, NULL,
806 ADT7470_R3T_ALARM);
807static SENSOR_DEVICE_ATTR(temp4_alarm, S_IRUGO, show_alarm, NULL,
808 ADT7470_R4T_ALARM);
809static SENSOR_DEVICE_ATTR(temp5_alarm, S_IRUGO, show_alarm, NULL,
810 ADT7470_R5T_ALARM);
811static SENSOR_DEVICE_ATTR(temp6_alarm, S_IRUGO, show_alarm, NULL,
812 ADT7470_R6T_ALARM);
813static SENSOR_DEVICE_ATTR(temp7_alarm, S_IRUGO, show_alarm, NULL,
814 ADT7470_R7T_ALARM);
815static SENSOR_DEVICE_ATTR(temp8_alarm, S_IRUGO, show_alarm, NULL,
816 ALARM2(ADT7470_R8T_ALARM));
817static SENSOR_DEVICE_ATTR(temp9_alarm, S_IRUGO, show_alarm, NULL,
818 ALARM2(ADT7470_R9T_ALARM));
819static SENSOR_DEVICE_ATTR(temp10_alarm, S_IRUGO, show_alarm, NULL,
820 ALARM2(ADT7470_R10T_ALARM));
821
774static SENSOR_DEVICE_ATTR(fan1_max, S_IWUSR | S_IRUGO, show_fan_max, 822static SENSOR_DEVICE_ATTR(fan1_max, S_IWUSR | S_IRUGO, show_fan_max,
775 set_fan_max, 0); 823 set_fan_max, 0);
776static SENSOR_DEVICE_ATTR(fan2_max, S_IWUSR | S_IRUGO, show_fan_max, 824static SENSOR_DEVICE_ATTR(fan2_max, S_IWUSR | S_IRUGO, show_fan_max,
@@ -794,6 +842,15 @@ static SENSOR_DEVICE_ATTR(fan2_input, S_IRUGO, show_fan, NULL, 1);
794static SENSOR_DEVICE_ATTR(fan3_input, S_IRUGO, show_fan, NULL, 2); 842static SENSOR_DEVICE_ATTR(fan3_input, S_IRUGO, show_fan, NULL, 2);
795static SENSOR_DEVICE_ATTR(fan4_input, S_IRUGO, show_fan, NULL, 3); 843static SENSOR_DEVICE_ATTR(fan4_input, S_IRUGO, show_fan, NULL, 3);
796 844
845static SENSOR_DEVICE_ATTR(fan1_alarm, S_IRUGO, show_alarm, NULL,
846 ALARM2(ADT7470_FAN1_ALARM));
847static SENSOR_DEVICE_ATTR(fan2_alarm, S_IRUGO, show_alarm, NULL,
848 ALARM2(ADT7470_FAN2_ALARM));
849static SENSOR_DEVICE_ATTR(fan3_alarm, S_IRUGO, show_alarm, NULL,
850 ALARM2(ADT7470_FAN3_ALARM));
851static SENSOR_DEVICE_ATTR(fan4_alarm, S_IRUGO, show_alarm, NULL,
852 ALARM2(ADT7470_FAN4_ALARM));
853
797static SENSOR_DEVICE_ATTR(force_pwm_max, S_IWUSR | S_IRUGO, 854static SENSOR_DEVICE_ATTR(force_pwm_max, S_IWUSR | S_IRUGO,
798 show_force_pwm_max, set_force_pwm_max, 0); 855 show_force_pwm_max, set_force_pwm_max, 0);
799 856
@@ -858,8 +915,7 @@ static SENSOR_DEVICE_ATTR(pwm4_auto_channels_temp, S_IWUSR | S_IRUGO,
858 915
859static struct attribute *adt7470_attr[] = 916static struct attribute *adt7470_attr[] =
860{ 917{
861 &sensor_dev_attr_alarms.dev_attr.attr, 918 &dev_attr_alarm_mask.attr,
862 &sensor_dev_attr_alarm_mask.dev_attr.attr,
863 &sensor_dev_attr_temp1_max.dev_attr.attr, 919 &sensor_dev_attr_temp1_max.dev_attr.attr,
864 &sensor_dev_attr_temp2_max.dev_attr.attr, 920 &sensor_dev_attr_temp2_max.dev_attr.attr,
865 &sensor_dev_attr_temp3_max.dev_attr.attr, 921 &sensor_dev_attr_temp3_max.dev_attr.attr,
@@ -890,6 +946,16 @@ static struct attribute *adt7470_attr[] =
890 &sensor_dev_attr_temp8_input.dev_attr.attr, 946 &sensor_dev_attr_temp8_input.dev_attr.attr,
891 &sensor_dev_attr_temp9_input.dev_attr.attr, 947 &sensor_dev_attr_temp9_input.dev_attr.attr,
892 &sensor_dev_attr_temp10_input.dev_attr.attr, 948 &sensor_dev_attr_temp10_input.dev_attr.attr,
949 &sensor_dev_attr_temp1_alarm.dev_attr.attr,
950 &sensor_dev_attr_temp2_alarm.dev_attr.attr,
951 &sensor_dev_attr_temp3_alarm.dev_attr.attr,
952 &sensor_dev_attr_temp4_alarm.dev_attr.attr,
953 &sensor_dev_attr_temp5_alarm.dev_attr.attr,
954 &sensor_dev_attr_temp6_alarm.dev_attr.attr,
955 &sensor_dev_attr_temp7_alarm.dev_attr.attr,
956 &sensor_dev_attr_temp8_alarm.dev_attr.attr,
957 &sensor_dev_attr_temp9_alarm.dev_attr.attr,
958 &sensor_dev_attr_temp10_alarm.dev_attr.attr,
893 &sensor_dev_attr_fan1_max.dev_attr.attr, 959 &sensor_dev_attr_fan1_max.dev_attr.attr,
894 &sensor_dev_attr_fan2_max.dev_attr.attr, 960 &sensor_dev_attr_fan2_max.dev_attr.attr,
895 &sensor_dev_attr_fan3_max.dev_attr.attr, 961 &sensor_dev_attr_fan3_max.dev_attr.attr,
@@ -902,6 +968,10 @@ static struct attribute *adt7470_attr[] =
902 &sensor_dev_attr_fan2_input.dev_attr.attr, 968 &sensor_dev_attr_fan2_input.dev_attr.attr,
903 &sensor_dev_attr_fan3_input.dev_attr.attr, 969 &sensor_dev_attr_fan3_input.dev_attr.attr,
904 &sensor_dev_attr_fan4_input.dev_attr.attr, 970 &sensor_dev_attr_fan4_input.dev_attr.attr,
971 &sensor_dev_attr_fan1_alarm.dev_attr.attr,
972 &sensor_dev_attr_fan2_alarm.dev_attr.attr,
973 &sensor_dev_attr_fan3_alarm.dev_attr.attr,
974 &sensor_dev_attr_fan4_alarm.dev_attr.attr,
905 &sensor_dev_attr_force_pwm_max.dev_attr.attr, 975 &sensor_dev_attr_force_pwm_max.dev_attr.attr,
906 &sensor_dev_attr_pwm1.dev_attr.attr, 976 &sensor_dev_attr_pwm1.dev_attr.attr,
907 &sensor_dev_attr_pwm2.dev_attr.attr, 977 &sensor_dev_attr_pwm2.dev_attr.attr,