aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon/w83781d.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/hwmon/w83781d.c')
-rw-r--r--drivers/hwmon/w83781d.c206
1 files changed, 182 insertions, 24 deletions
diff --git a/drivers/hwmon/w83781d.c b/drivers/hwmon/w83781d.c
index dcc941a5aaff..a6a1edfe7614 100644
--- a/drivers/hwmon/w83781d.c
+++ b/drivers/hwmon/w83781d.c
@@ -220,7 +220,7 @@ DIV_TO_REG(long val, enum chips type)
220 the driver field to differentiate between I2C and ISA chips. */ 220 the driver field to differentiate between I2C and ISA chips. */
221struct w83781d_data { 221struct w83781d_data {
222 struct i2c_client client; 222 struct i2c_client client;
223 struct class_device *class_dev; 223 struct device *hwmon_dev;
224 struct mutex lock; 224 struct mutex lock;
225 enum chips type; 225 enum chips type;
226 226
@@ -251,9 +251,7 @@ struct w83781d_data {
251 u8 pwm2_enable; /* Boolean */ 251 u8 pwm2_enable; /* Boolean */
252 u16 sens[3]; /* 782D/783S only. 252 u16 sens[3]; /* 782D/783S only.
253 1 = pentium diode; 2 = 3904 diode; 253 1 = pentium diode; 2 = 3904 diode;
254 3000-5000 = thermistor beta. 254 4 = thermistor */
255 Default = 3435.
256 Other Betas unimplemented */
257 u8 vrm; 255 u8 vrm;
258}; 256};
259 257
@@ -410,7 +408,7 @@ static ssize_t store_temp_##reg (struct device *dev, \
410 struct sensor_device_attribute *attr = to_sensor_dev_attr(da); \ 408 struct sensor_device_attribute *attr = to_sensor_dev_attr(da); \
411 struct w83781d_data *data = dev_get_drvdata(dev); \ 409 struct w83781d_data *data = dev_get_drvdata(dev); \
412 int nr = attr->index; \ 410 int nr = attr->index; \
413 s32 val; \ 411 long val; \
414 \ 412 \
415 val = simple_strtol(buf, NULL, 10); \ 413 val = simple_strtol(buf, NULL, 10); \
416 \ 414 \
@@ -456,7 +454,7 @@ static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid_reg, NULL);
456static ssize_t 454static ssize_t
457show_vrm_reg(struct device *dev, struct device_attribute *attr, char *buf) 455show_vrm_reg(struct device *dev, struct device_attribute *attr, char *buf)
458{ 456{
459 struct w83781d_data *data = w83781d_update_device(dev); 457 struct w83781d_data *data = dev_get_drvdata(dev);
460 return sprintf(buf, "%ld\n", (long) data->vrm); 458 return sprintf(buf, "%ld\n", (long) data->vrm);
461} 459}
462 460
@@ -483,6 +481,39 @@ show_alarms_reg(struct device *dev, struct device_attribute *attr, char *buf)
483 481
484static DEVICE_ATTR(alarms, S_IRUGO, show_alarms_reg, NULL); 482static DEVICE_ATTR(alarms, S_IRUGO, show_alarms_reg, NULL);
485 483
484static ssize_t show_alarm(struct device *dev, struct device_attribute *attr,
485 char *buf)
486{
487 struct w83781d_data *data = w83781d_update_device(dev);
488 int bitnr = to_sensor_dev_attr(attr)->index;
489 return sprintf(buf, "%u\n", (data->alarms >> bitnr) & 1);
490}
491
492/* The W83781D has a single alarm bit for temp2 and temp3 */
493static ssize_t show_temp3_alarm(struct device *dev,
494 struct device_attribute *attr, char *buf)
495{
496 struct w83781d_data *data = w83781d_update_device(dev);
497 int bitnr = (data->type == w83781d) ? 5 : 13;
498 return sprintf(buf, "%u\n", (data->alarms >> bitnr) & 1);
499}
500
501static SENSOR_DEVICE_ATTR(in0_alarm, S_IRUGO, show_alarm, NULL, 0);
502static SENSOR_DEVICE_ATTR(in1_alarm, S_IRUGO, show_alarm, NULL, 1);
503static SENSOR_DEVICE_ATTR(in2_alarm, S_IRUGO, show_alarm, NULL, 2);
504static SENSOR_DEVICE_ATTR(in3_alarm, S_IRUGO, show_alarm, NULL, 3);
505static SENSOR_DEVICE_ATTR(in4_alarm, S_IRUGO, show_alarm, NULL, 8);
506static SENSOR_DEVICE_ATTR(in5_alarm, S_IRUGO, show_alarm, NULL, 9);
507static SENSOR_DEVICE_ATTR(in6_alarm, S_IRUGO, show_alarm, NULL, 10);
508static SENSOR_DEVICE_ATTR(in7_alarm, S_IRUGO, show_alarm, NULL, 16);
509static SENSOR_DEVICE_ATTR(in8_alarm, S_IRUGO, show_alarm, NULL, 17);
510static SENSOR_DEVICE_ATTR(fan1_alarm, S_IRUGO, show_alarm, NULL, 6);
511static SENSOR_DEVICE_ATTR(fan2_alarm, S_IRUGO, show_alarm, NULL, 7);
512static SENSOR_DEVICE_ATTR(fan3_alarm, S_IRUGO, show_alarm, NULL, 11);
513static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 4);
514static SENSOR_DEVICE_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL, 5);
515static SENSOR_DEVICE_ATTR(temp3_alarm, S_IRUGO, show_temp3_alarm, NULL, 0);
516
486static ssize_t show_beep_mask (struct device *dev, struct device_attribute *attr, char *buf) 517static ssize_t show_beep_mask (struct device *dev, struct device_attribute *attr, char *buf)
487{ 518{
488 struct w83781d_data *data = w83781d_update_device(dev); 519 struct w83781d_data *data = w83781d_update_device(dev);
@@ -546,6 +577,100 @@ static DEVICE_ATTR(beep_mask, S_IRUGO | S_IWUSR,
546static DEVICE_ATTR(beep_enable, S_IRUGO | S_IWUSR, 577static DEVICE_ATTR(beep_enable, S_IRUGO | S_IWUSR,
547 show_beep_enable, store_beep_enable); 578 show_beep_enable, store_beep_enable);
548 579
580static ssize_t show_beep(struct device *dev, struct device_attribute *attr,
581 char *buf)
582{
583 struct w83781d_data *data = w83781d_update_device(dev);
584 int bitnr = to_sensor_dev_attr(attr)->index;
585 return sprintf(buf, "%u\n", (data->beep_mask >> bitnr) & 1);
586}
587
588static ssize_t
589store_beep(struct device *dev, struct device_attribute *attr,
590 const char *buf, size_t count)
591{
592 struct w83781d_data *data = dev_get_drvdata(dev);
593 int bitnr = to_sensor_dev_attr(attr)->index;
594 unsigned long bit;
595 u8 reg;
596
597 bit = simple_strtoul(buf, NULL, 10);
598 if (bit & ~1)
599 return -EINVAL;
600
601 mutex_lock(&data->update_lock);
602 if (bit)
603 data->beep_mask |= (1 << bitnr);
604 else
605 data->beep_mask &= ~(1 << bitnr);
606
607 if (bitnr < 8) {
608 reg = w83781d_read_value(data, W83781D_REG_BEEP_INTS1);
609 if (bit)
610 reg |= (1 << bitnr);
611 else
612 reg &= ~(1 << bitnr);
613 w83781d_write_value(data, W83781D_REG_BEEP_INTS1, reg);
614 } else if (bitnr < 16) {
615 reg = w83781d_read_value(data, W83781D_REG_BEEP_INTS2);
616 if (bit)
617 reg |= (1 << (bitnr - 8));
618 else
619 reg &= ~(1 << (bitnr - 8));
620 w83781d_write_value(data, W83781D_REG_BEEP_INTS2, reg);
621 } else {
622 reg = w83781d_read_value(data, W83781D_REG_BEEP_INTS3);
623 if (bit)
624 reg |= (1 << (bitnr - 16));
625 else
626 reg &= ~(1 << (bitnr - 16));
627 w83781d_write_value(data, W83781D_REG_BEEP_INTS3, reg);
628 }
629 mutex_unlock(&data->update_lock);
630
631 return count;
632}
633
634/* The W83781D has a single beep bit for temp2 and temp3 */
635static ssize_t show_temp3_beep(struct device *dev,
636 struct device_attribute *attr, char *buf)
637{
638 struct w83781d_data *data = w83781d_update_device(dev);
639 int bitnr = (data->type == w83781d) ? 5 : 13;
640 return sprintf(buf, "%u\n", (data->beep_mask >> bitnr) & 1);
641}
642
643static SENSOR_DEVICE_ATTR(in0_beep, S_IRUGO | S_IWUSR,
644 show_beep, store_beep, 0);
645static SENSOR_DEVICE_ATTR(in1_beep, S_IRUGO | S_IWUSR,
646 show_beep, store_beep, 1);
647static SENSOR_DEVICE_ATTR(in2_beep, S_IRUGO | S_IWUSR,
648 show_beep, store_beep, 2);
649static SENSOR_DEVICE_ATTR(in3_beep, S_IRUGO | S_IWUSR,
650 show_beep, store_beep, 3);
651static SENSOR_DEVICE_ATTR(in4_beep, S_IRUGO | S_IWUSR,
652 show_beep, store_beep, 8);
653static SENSOR_DEVICE_ATTR(in5_beep, S_IRUGO | S_IWUSR,
654 show_beep, store_beep, 9);
655static SENSOR_DEVICE_ATTR(in6_beep, S_IRUGO | S_IWUSR,
656 show_beep, store_beep, 10);
657static SENSOR_DEVICE_ATTR(in7_beep, S_IRUGO | S_IWUSR,
658 show_beep, store_beep, 16);
659static SENSOR_DEVICE_ATTR(in8_beep, S_IRUGO | S_IWUSR,
660 show_beep, store_beep, 17);
661static SENSOR_DEVICE_ATTR(fan1_beep, S_IRUGO | S_IWUSR,
662 show_beep, store_beep, 6);
663static SENSOR_DEVICE_ATTR(fan2_beep, S_IRUGO | S_IWUSR,
664 show_beep, store_beep, 7);
665static SENSOR_DEVICE_ATTR(fan3_beep, S_IRUGO | S_IWUSR,
666 show_beep, store_beep, 11);
667static SENSOR_DEVICE_ATTR(temp1_beep, S_IRUGO | S_IWUSR,
668 show_beep, store_beep, 4);
669static SENSOR_DEVICE_ATTR(temp2_beep, S_IRUGO | S_IWUSR,
670 show_beep, store_beep, 5);
671static SENSOR_DEVICE_ATTR(temp3_beep, S_IRUGO,
672 show_temp3_beep, store_beep, 13);
673
549static ssize_t 674static ssize_t
550show_fan_div(struct device *dev, struct device_attribute *da, char *buf) 675show_fan_div(struct device *dev, struct device_attribute *da, char *buf)
551{ 676{
@@ -721,15 +846,19 @@ store_sensor(struct device *dev, struct device_attribute *da,
721 tmp & ~BIT_SCFG2[nr]); 846 tmp & ~BIT_SCFG2[nr]);
722 data->sens[nr] = val; 847 data->sens[nr] = val;
723 break; 848 break;
724 case W83781D_DEFAULT_BETA: /* thermistor */ 849 case W83781D_DEFAULT_BETA:
850 dev_warn(dev, "Sensor type %d is deprecated, please use 4 "
851 "instead\n", W83781D_DEFAULT_BETA);
852 /* fall through */
853 case 4: /* thermistor */
725 tmp = w83781d_read_value(data, W83781D_REG_SCFG1); 854 tmp = w83781d_read_value(data, W83781D_REG_SCFG1);
726 w83781d_write_value(data, W83781D_REG_SCFG1, 855 w83781d_write_value(data, W83781D_REG_SCFG1,
727 tmp & ~BIT_SCFG1[nr]); 856 tmp & ~BIT_SCFG1[nr]);
728 data->sens[nr] = val; 857 data->sens[nr] = val;
729 break; 858 break;
730 default: 859 default:
731 dev_err(dev, "Invalid sensor type %ld; must be 1, 2, or %d\n", 860 dev_err(dev, "Invalid sensor type %ld; must be 1, 2, or 4\n",
732 (long) val, W83781D_DEFAULT_BETA); 861 (long) val);
733 break; 862 break;
734 } 863 }
735 864
@@ -875,17 +1004,23 @@ ERROR_SC_0:
875#define IN_UNIT_ATTRS(X) \ 1004#define IN_UNIT_ATTRS(X) \
876 &sensor_dev_attr_in##X##_input.dev_attr.attr, \ 1005 &sensor_dev_attr_in##X##_input.dev_attr.attr, \
877 &sensor_dev_attr_in##X##_min.dev_attr.attr, \ 1006 &sensor_dev_attr_in##X##_min.dev_attr.attr, \
878 &sensor_dev_attr_in##X##_max.dev_attr.attr 1007 &sensor_dev_attr_in##X##_max.dev_attr.attr, \
1008 &sensor_dev_attr_in##X##_alarm.dev_attr.attr, \
1009 &sensor_dev_attr_in##X##_beep.dev_attr.attr
879 1010
880#define FAN_UNIT_ATTRS(X) \ 1011#define FAN_UNIT_ATTRS(X) \
881 &sensor_dev_attr_fan##X##_input.dev_attr.attr, \ 1012 &sensor_dev_attr_fan##X##_input.dev_attr.attr, \
882 &sensor_dev_attr_fan##X##_min.dev_attr.attr, \ 1013 &sensor_dev_attr_fan##X##_min.dev_attr.attr, \
883 &sensor_dev_attr_fan##X##_div.dev_attr.attr 1014 &sensor_dev_attr_fan##X##_div.dev_attr.attr, \
1015 &sensor_dev_attr_fan##X##_alarm.dev_attr.attr, \
1016 &sensor_dev_attr_fan##X##_beep.dev_attr.attr
884 1017
885#define TEMP_UNIT_ATTRS(X) \ 1018#define TEMP_UNIT_ATTRS(X) \
886 &sensor_dev_attr_temp##X##_input.dev_attr.attr, \ 1019 &sensor_dev_attr_temp##X##_input.dev_attr.attr, \
887 &sensor_dev_attr_temp##X##_max.dev_attr.attr, \ 1020 &sensor_dev_attr_temp##X##_max.dev_attr.attr, \
888 &sensor_dev_attr_temp##X##_max_hyst.dev_attr.attr 1021 &sensor_dev_attr_temp##X##_max_hyst.dev_attr.attr, \
1022 &sensor_dev_attr_temp##X##_alarm.dev_attr.attr, \
1023 &sensor_dev_attr_temp##X##_beep.dev_attr.attr
889 1024
890static struct attribute* w83781d_attributes[] = { 1025static struct attribute* w83781d_attributes[] = {
891 IN_UNIT_ATTRS(0), 1026 IN_UNIT_ATTRS(0),
@@ -944,7 +1079,11 @@ w83781d_create_files(struct device *dev, int kind, int is_isa)
944 || (err = device_create_file(dev, 1079 || (err = device_create_file(dev,
945 &sensor_dev_attr_in1_min.dev_attr)) 1080 &sensor_dev_attr_in1_min.dev_attr))
946 || (err = device_create_file(dev, 1081 || (err = device_create_file(dev,
947 &sensor_dev_attr_in1_max.dev_attr))) 1082 &sensor_dev_attr_in1_max.dev_attr))
1083 || (err = device_create_file(dev,
1084 &sensor_dev_attr_in1_alarm.dev_attr))
1085 || (err = device_create_file(dev,
1086 &sensor_dev_attr_in1_beep.dev_attr)))
948 return err; 1087 return err;
949 } 1088 }
950 if (kind != as99127f && kind != w83781d && kind != w83783s) { 1089 if (kind != as99127f && kind != w83781d && kind != w83783s) {
@@ -955,11 +1094,19 @@ w83781d_create_files(struct device *dev, int kind, int is_isa)
955 || (err = device_create_file(dev, 1094 || (err = device_create_file(dev,
956 &sensor_dev_attr_in7_max.dev_attr)) 1095 &sensor_dev_attr_in7_max.dev_attr))
957 || (err = device_create_file(dev, 1096 || (err = device_create_file(dev,
1097 &sensor_dev_attr_in7_alarm.dev_attr))
1098 || (err = device_create_file(dev,
1099 &sensor_dev_attr_in7_beep.dev_attr))
1100 || (err = device_create_file(dev,
958 &sensor_dev_attr_in8_input.dev_attr)) 1101 &sensor_dev_attr_in8_input.dev_attr))
959 || (err = device_create_file(dev, 1102 || (err = device_create_file(dev,
960 &sensor_dev_attr_in8_min.dev_attr)) 1103 &sensor_dev_attr_in8_min.dev_attr))
961 || (err = device_create_file(dev, 1104 || (err = device_create_file(dev,
962 &sensor_dev_attr_in8_max.dev_attr))) 1105 &sensor_dev_attr_in8_max.dev_attr))
1106 || (err = device_create_file(dev,
1107 &sensor_dev_attr_in8_alarm.dev_attr))
1108 || (err = device_create_file(dev,
1109 &sensor_dev_attr_in8_beep.dev_attr)))
963 return err; 1110 return err;
964 } 1111 }
965 if (kind != w83783s) { 1112 if (kind != w83783s) {
@@ -968,8 +1115,19 @@ w83781d_create_files(struct device *dev, int kind, int is_isa)
968 || (err = device_create_file(dev, 1115 || (err = device_create_file(dev,
969 &sensor_dev_attr_temp3_max.dev_attr)) 1116 &sensor_dev_attr_temp3_max.dev_attr))
970 || (err = device_create_file(dev, 1117 || (err = device_create_file(dev,
971 &sensor_dev_attr_temp3_max_hyst.dev_attr))) 1118 &sensor_dev_attr_temp3_max_hyst.dev_attr))
1119 || (err = device_create_file(dev,
1120 &sensor_dev_attr_temp3_alarm.dev_attr))
1121 || (err = device_create_file(dev,
1122 &sensor_dev_attr_temp3_beep.dev_attr)))
972 return err; 1123 return err;
1124
1125 if (kind != w83781d)
1126 err = sysfs_chmod_file(&dev->kobj,
1127 &sensor_dev_attr_temp3_alarm.dev_attr.attr,
1128 S_IRUGO | S_IWUSR);
1129 if (err)
1130 return err;
973 } 1131 }
974 1132
975 if (kind != w83781d && kind != as99127f) { 1133 if (kind != w83781d && kind != as99127f) {
@@ -1156,9 +1314,9 @@ w83781d_detect(struct i2c_adapter *adapter, int address, int kind)
1156 if (err) 1314 if (err)
1157 goto ERROR4; 1315 goto ERROR4;
1158 1316
1159 data->class_dev = hwmon_device_register(dev); 1317 data->hwmon_dev = hwmon_device_register(dev);
1160 if (IS_ERR(data->class_dev)) { 1318 if (IS_ERR(data->hwmon_dev)) {
1161 err = PTR_ERR(data->class_dev); 1319 err = PTR_ERR(data->hwmon_dev);
1162 goto ERROR4; 1320 goto ERROR4;
1163 } 1321 }
1164 1322
@@ -1192,7 +1350,7 @@ w83781d_detach_client(struct i2c_client *client)
1192 1350
1193 /* main client */ 1351 /* main client */
1194 if (data) { 1352 if (data) {
1195 hwmon_device_unregister(data->class_dev); 1353 hwmon_device_unregister(data->hwmon_dev);
1196 sysfs_remove_group(&client->dev.kobj, &w83781d_group); 1354 sysfs_remove_group(&client->dev.kobj, &w83781d_group);
1197 sysfs_remove_group(&client->dev.kobj, &w83781d_group_opt); 1355 sysfs_remove_group(&client->dev.kobj, &w83781d_group_opt);
1198 } 1356 }
@@ -1259,9 +1417,9 @@ w83781d_isa_probe(struct platform_device *pdev)
1259 if (err) 1417 if (err)
1260 goto exit_remove_files; 1418 goto exit_remove_files;
1261 1419
1262 data->class_dev = hwmon_device_register(&pdev->dev); 1420 data->hwmon_dev = hwmon_device_register(&pdev->dev);
1263 if (IS_ERR(data->class_dev)) { 1421 if (IS_ERR(data->hwmon_dev)) {
1264 err = PTR_ERR(data->class_dev); 1422 err = PTR_ERR(data->hwmon_dev);
1265 goto exit_remove_files; 1423 goto exit_remove_files;
1266 } 1424 }
1267 1425
@@ -1283,7 +1441,7 @@ w83781d_isa_remove(struct platform_device *pdev)
1283{ 1441{
1284 struct w83781d_data *data = platform_get_drvdata(pdev); 1442 struct w83781d_data *data = platform_get_drvdata(pdev);
1285 1443
1286 hwmon_device_unregister(data->class_dev); 1444 hwmon_device_unregister(data->hwmon_dev);
1287 sysfs_remove_group(&pdev->dev.kobj, &w83781d_group); 1445 sysfs_remove_group(&pdev->dev.kobj, &w83781d_group);
1288 sysfs_remove_group(&pdev->dev.kobj, &w83781d_group_opt); 1446 sysfs_remove_group(&pdev->dev.kobj, &w83781d_group_opt);
1289 device_remove_file(&pdev->dev, &dev_attr_name); 1447 device_remove_file(&pdev->dev, &dev_attr_name);
@@ -1485,7 +1643,7 @@ w83781d_init_device(struct device *dev)
1485 tmp = w83781d_read_value(data, W83781D_REG_SCFG1); 1643 tmp = w83781d_read_value(data, W83781D_REG_SCFG1);
1486 for (i = 1; i <= 3; i++) { 1644 for (i = 1; i <= 3; i++) {
1487 if (!(tmp & BIT_SCFG1[i - 1])) { 1645 if (!(tmp & BIT_SCFG1[i - 1])) {
1488 data->sens[i - 1] = W83781D_DEFAULT_BETA; 1646 data->sens[i - 1] = 4;
1489 } else { 1647 } else {
1490 if (w83781d_read_value 1648 if (w83781d_read_value
1491 (data, 1649 (data,