aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon
diff options
context:
space:
mode:
authorGuenter Roeck <linux@roeck-us.net>2013-03-18 12:22:50 -0400
committerGuenter Roeck <linux@roeck-us.net>2013-08-12 01:10:38 -0400
commitf73cf632dfb43d6236210aa38038cc91fd053ff6 (patch)
treeeed8d3ef9a61681a06568d6d73226449d72cadf2 /drivers/hwmon
parent1c2faa22472fedf2c420041033700c700a1dfc96 (diff)
hwmon: (nct6775) Allocate attributes dynamically from templates
Static attribute allocation is large and very repetitive. Allocate attributes and attribute groups dynamically instead. This reduces the size of the driver source by more than 600 lines, and object size by more than 20k (more than 30%). Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Diffstat (limited to 'drivers/hwmon')
-rw-r--r--drivers/hwmon/nct6775.c1610
1 files changed, 507 insertions, 1103 deletions
diff --git a/drivers/hwmon/nct6775.c b/drivers/hwmon/nct6775.c
index 99cec1825420..778772d6bdda 100644
--- a/drivers/hwmon/nct6775.c
+++ b/drivers/hwmon/nct6775.c
@@ -554,6 +554,10 @@ struct nct6775_data {
554 const char *name; 554 const char *name;
555 555
556 struct device *hwmon_dev; 556 struct device *hwmon_dev;
557 struct attribute_group *group_in;
558 struct attribute_group *group_fan;
559 struct attribute_group *group_temp;
560 struct attribute_group *group_pwm;
557 561
558 u16 reg_temp[4][NUM_TEMP]; /* 0=temp, 1=temp_over, 2=temp_hyst, 562 u16 reg_temp[4][NUM_TEMP]; /* 0=temp, 1=temp_over, 2=temp_hyst,
559 * 3=temp_crit 563 * 3=temp_crit
@@ -672,6 +676,8 @@ struct nct6775_data {
672 u8 vid; 676 u8 vid;
673 u8 vrm; 677 u8 vrm;
674 678
679 bool have_vid;
680
675 u16 have_temp; 681 u16 have_temp;
676 u16 have_temp_fixed; 682 u16 have_temp_fixed;
677 u16 have_in; 683 u16 have_in;
@@ -688,6 +694,138 @@ struct nct6775_sio_data {
688 enum kinds kind; 694 enum kinds kind;
689}; 695};
690 696
697struct sensor_device_template {
698 struct device_attribute dev_attr;
699 union {
700 struct {
701 u8 nr;
702 u8 index;
703 } s;
704 int index;
705 } u;
706 bool s2; /* true if both index and nr are used */
707};
708
709struct sensor_device_attr_u {
710 union {
711 struct sensor_device_attribute a1;
712 struct sensor_device_attribute_2 a2;
713 } u;
714 char name[32];
715};
716
717#define __TEMPLATE_ATTR(_template, _mode, _show, _store) { \
718 .attr = {.name = _template, .mode = _mode }, \
719 .show = _show, \
720 .store = _store, \
721}
722
723#define SENSOR_DEVICE_TEMPLATE(_template, _mode, _show, _store, _index) \
724 { .dev_attr = __TEMPLATE_ATTR(_template, _mode, _show, _store), \
725 .u.index = _index, \
726 .s2 = false }
727
728#define SENSOR_DEVICE_TEMPLATE_2(_template, _mode, _show, _store, \
729 _nr, _index) \
730 { .dev_attr = __TEMPLATE_ATTR(_template, _mode, _show, _store), \
731 .u.s.index = _index, \
732 .u.s.nr = _nr, \
733 .s2 = true }
734
735#define SENSOR_TEMPLATE(_name, _template, _mode, _show, _store, _index) \
736static struct sensor_device_template sensor_dev_template_##_name \
737 = SENSOR_DEVICE_TEMPLATE(_template, _mode, _show, _store, \
738 _index)
739
740#define SENSOR_TEMPLATE_2(_name, _template, _mode, _show, _store, \
741 _nr, _index) \
742static struct sensor_device_template sensor_dev_template_##_name \
743 = SENSOR_DEVICE_TEMPLATE_2(_template, _mode, _show, _store, \
744 _nr, _index)
745
746struct sensor_template_group {
747 struct sensor_device_template **templates;
748 umode_t (*is_visible)(struct kobject *, struct attribute *, int);
749 int base;
750};
751
752static struct attribute_group *
753nct6775_create_attr_group(struct device *dev, struct sensor_template_group *tg,
754 int repeat)
755{
756 struct attribute_group *group;
757 struct sensor_device_attr_u *su;
758 struct sensor_device_attribute *a;
759 struct sensor_device_attribute_2 *a2;
760 struct attribute **attrs;
761 struct sensor_device_template **t;
762 int err, i, j, count;
763
764 if (repeat <= 0)
765 return ERR_PTR(-EINVAL);
766
767 t = tg->templates;
768 for (count = 0; *t; t++, count++)
769 ;
770
771 if (count == 0)
772 return ERR_PTR(-EINVAL);
773
774 group = devm_kzalloc(dev, sizeof(*group), GFP_KERNEL);
775 if (group == NULL)
776 return ERR_PTR(-ENOMEM);
777
778 attrs = devm_kzalloc(dev, sizeof(*attrs) * (repeat * count + 1),
779 GFP_KERNEL);
780 if (attrs == NULL)
781 return ERR_PTR(-ENOMEM);
782
783 su = devm_kzalloc(dev, sizeof(*su) * repeat * count,
784 GFP_KERNEL);
785 if (su == NULL)
786 return ERR_PTR(-ENOMEM);
787
788 group->attrs = attrs;
789 group->is_visible = tg->is_visible;
790
791 for (i = 0; i < repeat; i++) {
792 t = tg->templates;
793 for (j = 0; *t != NULL; j++) {
794 snprintf(su->name, sizeof(su->name),
795 (*t)->dev_attr.attr.name, tg->base + i);
796 if ((*t)->s2) {
797 a2 = &su->u.a2;
798 a2->dev_attr.attr.name = su->name;
799 a2->nr = (*t)->u.s.nr + i;
800 a2->index = (*t)->u.s.index;
801 a2->dev_attr.attr.mode =
802 (*t)->dev_attr.attr.mode;
803 a2->dev_attr.show = (*t)->dev_attr.show;
804 a2->dev_attr.store = (*t)->dev_attr.store;
805 *attrs = &a2->dev_attr.attr;
806 } else {
807 a = &su->u.a1;
808 a->dev_attr.attr.name = su->name;
809 a->index = (*t)->u.index + i;
810 a->dev_attr.attr.mode =
811 (*t)->dev_attr.attr.mode;
812 a->dev_attr.show = (*t)->dev_attr.show;
813 a->dev_attr.store = (*t)->dev_attr.store;
814 *attrs = &a->dev_attr.attr;
815 }
816 attrs++;
817 su++;
818 t++;
819 }
820 }
821
822 err = sysfs_create_group(&dev->kobj, group);
823 if (err)
824 return ERR_PTR(-ENOMEM);
825
826 return group;
827}
828
691static bool is_word_sized(struct nct6775_data *data, u16 reg) 829static bool is_word_sized(struct nct6775_data *data, u16 reg)
692{ 830{
693 switch (data->kind) { 831 switch (data->kind) {
@@ -1230,224 +1368,42 @@ show_temp_alarm(struct device *dev, struct device_attribute *attr, char *buf)
1230 return sprintf(buf, "%u\n", alarm); 1368 return sprintf(buf, "%u\n", alarm);
1231} 1369}
1232 1370
1233static SENSOR_DEVICE_ATTR_2(in0_input, S_IRUGO, show_in_reg, NULL, 0, 0); 1371static umode_t nct6775_in_is_visible(struct kobject *kobj,
1234static SENSOR_DEVICE_ATTR_2(in1_input, S_IRUGO, show_in_reg, NULL, 1, 0); 1372 struct attribute *attr, int index)
1235static SENSOR_DEVICE_ATTR_2(in2_input, S_IRUGO, show_in_reg, NULL, 2, 0); 1373{
1236static SENSOR_DEVICE_ATTR_2(in3_input, S_IRUGO, show_in_reg, NULL, 3, 0); 1374 struct device *dev = container_of(kobj, struct device, kobj);
1237static SENSOR_DEVICE_ATTR_2(in4_input, S_IRUGO, show_in_reg, NULL, 4, 0); 1375 struct nct6775_data *data = dev_get_drvdata(dev);
1238static SENSOR_DEVICE_ATTR_2(in5_input, S_IRUGO, show_in_reg, NULL, 5, 0); 1376 int in = index / 4; /* voltage index */
1239static SENSOR_DEVICE_ATTR_2(in6_input, S_IRUGO, show_in_reg, NULL, 6, 0); 1377
1240static SENSOR_DEVICE_ATTR_2(in7_input, S_IRUGO, show_in_reg, NULL, 7, 0); 1378 if (!(data->have_in & (1 << in)))
1241static SENSOR_DEVICE_ATTR_2(in8_input, S_IRUGO, show_in_reg, NULL, 8, 0); 1379 return 0;
1242static SENSOR_DEVICE_ATTR_2(in9_input, S_IRUGO, show_in_reg, NULL, 9, 0); 1380
1243static SENSOR_DEVICE_ATTR_2(in10_input, S_IRUGO, show_in_reg, NULL, 10, 0); 1381 return attr->mode;
1244static SENSOR_DEVICE_ATTR_2(in11_input, S_IRUGO, show_in_reg, NULL, 11, 0); 1382}
1245static SENSOR_DEVICE_ATTR_2(in12_input, S_IRUGO, show_in_reg, NULL, 12, 0); 1383
1246static SENSOR_DEVICE_ATTR_2(in13_input, S_IRUGO, show_in_reg, NULL, 13, 0); 1384SENSOR_TEMPLATE_2(in_input, "in%d_input", S_IRUGO, show_in_reg, NULL, 0, 0);
1247static SENSOR_DEVICE_ATTR_2(in14_input, S_IRUGO, show_in_reg, NULL, 14, 0); 1385SENSOR_TEMPLATE(in_alarm, "in%d_alarm", S_IRUGO, show_alarm, NULL, 0);
1248 1386SENSOR_TEMPLATE_2(in_min, "in%d_min", S_IWUSR | S_IRUGO, show_in_reg,
1249static SENSOR_DEVICE_ATTR(in0_alarm, S_IRUGO, show_alarm, NULL, 0); 1387 store_in_reg, 0, 1);
1250static SENSOR_DEVICE_ATTR(in1_alarm, S_IRUGO, show_alarm, NULL, 1); 1388SENSOR_TEMPLATE_2(in_max, "in%d_max", S_IWUSR | S_IRUGO, show_in_reg,
1251static SENSOR_DEVICE_ATTR(in2_alarm, S_IRUGO, show_alarm, NULL, 2); 1389 store_in_reg, 0, 2);
1252static SENSOR_DEVICE_ATTR(in3_alarm, S_IRUGO, show_alarm, NULL, 3); 1390
1253static SENSOR_DEVICE_ATTR(in4_alarm, S_IRUGO, show_alarm, NULL, 4); 1391/*
1254static SENSOR_DEVICE_ATTR(in5_alarm, S_IRUGO, show_alarm, NULL, 5); 1392 * nct6775_in_is_visible uses the index into the following array
1255static SENSOR_DEVICE_ATTR(in6_alarm, S_IRUGO, show_alarm, NULL, 6); 1393 * to determine if attributes should be created or not.
1256static SENSOR_DEVICE_ATTR(in7_alarm, S_IRUGO, show_alarm, NULL, 7); 1394 * Any change in order or content must be matched.
1257static SENSOR_DEVICE_ATTR(in8_alarm, S_IRUGO, show_alarm, NULL, 8); 1395 */
1258static SENSOR_DEVICE_ATTR(in9_alarm, S_IRUGO, show_alarm, NULL, 9); 1396static struct sensor_device_template *nct6775_attributes_in_template[] = {
1259static SENSOR_DEVICE_ATTR(in10_alarm, S_IRUGO, show_alarm, NULL, 10); 1397 &sensor_dev_template_in_input,
1260static SENSOR_DEVICE_ATTR(in11_alarm, S_IRUGO, show_alarm, NULL, 11); 1398 &sensor_dev_template_in_alarm,
1261static SENSOR_DEVICE_ATTR(in12_alarm, S_IRUGO, show_alarm, NULL, 12); 1399 &sensor_dev_template_in_min,
1262static SENSOR_DEVICE_ATTR(in13_alarm, S_IRUGO, show_alarm, NULL, 13); 1400 &sensor_dev_template_in_max,
1263static SENSOR_DEVICE_ATTR(in14_alarm, S_IRUGO, show_alarm, NULL, 14); 1401 NULL
1264
1265static SENSOR_DEVICE_ATTR_2(in0_min, S_IWUSR | S_IRUGO, show_in_reg,
1266 store_in_reg, 0, 1);
1267static SENSOR_DEVICE_ATTR_2(in1_min, S_IWUSR | S_IRUGO, show_in_reg,
1268 store_in_reg, 1, 1);
1269static SENSOR_DEVICE_ATTR_2(in2_min, S_IWUSR | S_IRUGO, show_in_reg,
1270 store_in_reg, 2, 1);
1271static SENSOR_DEVICE_ATTR_2(in3_min, S_IWUSR | S_IRUGO, show_in_reg,
1272 store_in_reg, 3, 1);
1273static SENSOR_DEVICE_ATTR_2(in4_min, S_IWUSR | S_IRUGO, show_in_reg,
1274 store_in_reg, 4, 1);
1275static SENSOR_DEVICE_ATTR_2(in5_min, S_IWUSR | S_IRUGO, show_in_reg,
1276 store_in_reg, 5, 1);
1277static SENSOR_DEVICE_ATTR_2(in6_min, S_IWUSR | S_IRUGO, show_in_reg,
1278 store_in_reg, 6, 1);
1279static SENSOR_DEVICE_ATTR_2(in7_min, S_IWUSR | S_IRUGO, show_in_reg,
1280 store_in_reg, 7, 1);
1281static SENSOR_DEVICE_ATTR_2(in8_min, S_IWUSR | S_IRUGO, show_in_reg,
1282 store_in_reg, 8, 1);
1283static SENSOR_DEVICE_ATTR_2(in9_min, S_IWUSR | S_IRUGO, show_in_reg,
1284 store_in_reg, 9, 1);
1285static SENSOR_DEVICE_ATTR_2(in10_min, S_IWUSR | S_IRUGO, show_in_reg,
1286 store_in_reg, 10, 1);
1287static SENSOR_DEVICE_ATTR_2(in11_min, S_IWUSR | S_IRUGO, show_in_reg,
1288 store_in_reg, 11, 1);
1289static SENSOR_DEVICE_ATTR_2(in12_min, S_IWUSR | S_IRUGO, show_in_reg,
1290 store_in_reg, 12, 1);
1291static SENSOR_DEVICE_ATTR_2(in13_min, S_IWUSR | S_IRUGO, show_in_reg,
1292 store_in_reg, 13, 1);
1293static SENSOR_DEVICE_ATTR_2(in14_min, S_IWUSR | S_IRUGO, show_in_reg,
1294 store_in_reg, 14, 1);
1295
1296static SENSOR_DEVICE_ATTR_2(in0_max, S_IWUSR | S_IRUGO, show_in_reg,
1297 store_in_reg, 0, 2);
1298static SENSOR_DEVICE_ATTR_2(in1_max, S_IWUSR | S_IRUGO, show_in_reg,
1299 store_in_reg, 1, 2);
1300static SENSOR_DEVICE_ATTR_2(in2_max, S_IWUSR | S_IRUGO, show_in_reg,
1301 store_in_reg, 2, 2);
1302static SENSOR_DEVICE_ATTR_2(in3_max, S_IWUSR | S_IRUGO, show_in_reg,
1303 store_in_reg, 3, 2);
1304static SENSOR_DEVICE_ATTR_2(in4_max, S_IWUSR | S_IRUGO, show_in_reg,
1305 store_in_reg, 4, 2);
1306static SENSOR_DEVICE_ATTR_2(in5_max, S_IWUSR | S_IRUGO, show_in_reg,
1307 store_in_reg, 5, 2);
1308static SENSOR_DEVICE_ATTR_2(in6_max, S_IWUSR | S_IRUGO, show_in_reg,
1309 store_in_reg, 6, 2);
1310static SENSOR_DEVICE_ATTR_2(in7_max, S_IWUSR | S_IRUGO, show_in_reg,
1311 store_in_reg, 7, 2);
1312static SENSOR_DEVICE_ATTR_2(in8_max, S_IWUSR | S_IRUGO, show_in_reg,
1313 store_in_reg, 8, 2);
1314static SENSOR_DEVICE_ATTR_2(in9_max, S_IWUSR | S_IRUGO, show_in_reg,
1315 store_in_reg, 9, 2);
1316static SENSOR_DEVICE_ATTR_2(in10_max, S_IWUSR | S_IRUGO, show_in_reg,
1317 store_in_reg, 10, 2);
1318static SENSOR_DEVICE_ATTR_2(in11_max, S_IWUSR | S_IRUGO, show_in_reg,
1319 store_in_reg, 11, 2);
1320static SENSOR_DEVICE_ATTR_2(in12_max, S_IWUSR | S_IRUGO, show_in_reg,
1321 store_in_reg, 12, 2);
1322static SENSOR_DEVICE_ATTR_2(in13_max, S_IWUSR | S_IRUGO, show_in_reg,
1323 store_in_reg, 13, 2);
1324static SENSOR_DEVICE_ATTR_2(in14_max, S_IWUSR | S_IRUGO, show_in_reg,
1325 store_in_reg, 14, 2);
1326
1327static struct attribute *nct6775_attributes_in[15][5] = {
1328 {
1329 &sensor_dev_attr_in0_input.dev_attr.attr,
1330 &sensor_dev_attr_in0_min.dev_attr.attr,
1331 &sensor_dev_attr_in0_max.dev_attr.attr,
1332 &sensor_dev_attr_in0_alarm.dev_attr.attr,
1333 NULL
1334 },
1335 {
1336 &sensor_dev_attr_in1_input.dev_attr.attr,
1337 &sensor_dev_attr_in1_min.dev_attr.attr,
1338 &sensor_dev_attr_in1_max.dev_attr.attr,
1339 &sensor_dev_attr_in1_alarm.dev_attr.attr,
1340 NULL
1341 },
1342 {
1343 &sensor_dev_attr_in2_input.dev_attr.attr,
1344 &sensor_dev_attr_in2_min.dev_attr.attr,
1345 &sensor_dev_attr_in2_max.dev_attr.attr,
1346 &sensor_dev_attr_in2_alarm.dev_attr.attr,
1347 NULL
1348 },
1349 {
1350 &sensor_dev_attr_in3_input.dev_attr.attr,
1351 &sensor_dev_attr_in3_min.dev_attr.attr,
1352 &sensor_dev_attr_in3_max.dev_attr.attr,
1353 &sensor_dev_attr_in3_alarm.dev_attr.attr,
1354 NULL
1355 },
1356 {
1357 &sensor_dev_attr_in4_input.dev_attr.attr,
1358 &sensor_dev_attr_in4_min.dev_attr.attr,
1359 &sensor_dev_attr_in4_max.dev_attr.attr,
1360 &sensor_dev_attr_in4_alarm.dev_attr.attr,
1361 NULL
1362 },
1363 {
1364 &sensor_dev_attr_in5_input.dev_attr.attr,
1365 &sensor_dev_attr_in5_min.dev_attr.attr,
1366 &sensor_dev_attr_in5_max.dev_attr.attr,
1367 &sensor_dev_attr_in5_alarm.dev_attr.attr,
1368 NULL
1369 },
1370 {
1371 &sensor_dev_attr_in6_input.dev_attr.attr,
1372 &sensor_dev_attr_in6_min.dev_attr.attr,
1373 &sensor_dev_attr_in6_max.dev_attr.attr,
1374 &sensor_dev_attr_in6_alarm.dev_attr.attr,
1375 NULL
1376 },
1377 {
1378 &sensor_dev_attr_in7_input.dev_attr.attr,
1379 &sensor_dev_attr_in7_min.dev_attr.attr,
1380 &sensor_dev_attr_in7_max.dev_attr.attr,
1381 &sensor_dev_attr_in7_alarm.dev_attr.attr,
1382 NULL
1383 },
1384 {
1385 &sensor_dev_attr_in8_input.dev_attr.attr,
1386 &sensor_dev_attr_in8_min.dev_attr.attr,
1387 &sensor_dev_attr_in8_max.dev_attr.attr,
1388 &sensor_dev_attr_in8_alarm.dev_attr.attr,
1389 NULL
1390 },
1391 {
1392 &sensor_dev_attr_in9_input.dev_attr.attr,
1393 &sensor_dev_attr_in9_min.dev_attr.attr,
1394 &sensor_dev_attr_in9_max.dev_attr.attr,
1395 &sensor_dev_attr_in9_alarm.dev_attr.attr,
1396 NULL
1397 },
1398 {
1399 &sensor_dev_attr_in10_input.dev_attr.attr,
1400 &sensor_dev_attr_in10_min.dev_attr.attr,
1401 &sensor_dev_attr_in10_max.dev_attr.attr,
1402 &sensor_dev_attr_in10_alarm.dev_attr.attr,
1403 NULL
1404 },
1405 {
1406 &sensor_dev_attr_in11_input.dev_attr.attr,
1407 &sensor_dev_attr_in11_min.dev_attr.attr,
1408 &sensor_dev_attr_in11_max.dev_attr.attr,
1409 &sensor_dev_attr_in11_alarm.dev_attr.attr,
1410 NULL
1411 },
1412 {
1413 &sensor_dev_attr_in12_input.dev_attr.attr,
1414 &sensor_dev_attr_in12_min.dev_attr.attr,
1415 &sensor_dev_attr_in12_max.dev_attr.attr,
1416 &sensor_dev_attr_in12_alarm.dev_attr.attr,
1417 NULL
1418 },
1419 {
1420 &sensor_dev_attr_in13_input.dev_attr.attr,
1421 &sensor_dev_attr_in13_min.dev_attr.attr,
1422 &sensor_dev_attr_in13_max.dev_attr.attr,
1423 &sensor_dev_attr_in13_alarm.dev_attr.attr,
1424 NULL
1425 },
1426 {
1427 &sensor_dev_attr_in14_input.dev_attr.attr,
1428 &sensor_dev_attr_in14_min.dev_attr.attr,
1429 &sensor_dev_attr_in14_max.dev_attr.attr,
1430 &sensor_dev_attr_in14_alarm.dev_attr.attr,
1431 NULL
1432 },
1433}; 1402};
1434 1403
1435static const struct attribute_group nct6775_group_in[15] = { 1404static struct sensor_template_group nct6775_in_template_group = {
1436 { .attrs = nct6775_attributes_in[0] }, 1405 .templates = nct6775_attributes_in_template,
1437 { .attrs = nct6775_attributes_in[1] }, 1406 .is_visible = nct6775_in_is_visible,
1438 { .attrs = nct6775_attributes_in[2] },
1439 { .attrs = nct6775_attributes_in[3] },
1440 { .attrs = nct6775_attributes_in[4] },
1441 { .attrs = nct6775_attributes_in[5] },
1442 { .attrs = nct6775_attributes_in[6] },
1443 { .attrs = nct6775_attributes_in[7] },
1444 { .attrs = nct6775_attributes_in[8] },
1445 { .attrs = nct6775_attributes_in[9] },
1446 { .attrs = nct6775_attributes_in[10] },
1447 { .attrs = nct6775_attributes_in[11] },
1448 { .attrs = nct6775_attributes_in[12] },
1449 { .attrs = nct6775_attributes_in[13] },
1450 { .attrs = nct6775_attributes_in[14] },
1451}; 1407};
1452 1408
1453static ssize_t 1409static ssize_t
@@ -1608,54 +1564,54 @@ store_fan_pulses(struct device *dev, struct device_attribute *attr,
1608 return count; 1564 return count;
1609} 1565}
1610 1566
1611static struct sensor_device_attribute sda_fan_input[] = { 1567static umode_t nct6775_fan_is_visible(struct kobject *kobj,
1612 SENSOR_ATTR(fan1_input, S_IRUGO, show_fan, NULL, 0), 1568 struct attribute *attr, int index)
1613 SENSOR_ATTR(fan2_input, S_IRUGO, show_fan, NULL, 1), 1569{
1614 SENSOR_ATTR(fan3_input, S_IRUGO, show_fan, NULL, 2), 1570 struct device *dev = container_of(kobj, struct device, kobj);
1615 SENSOR_ATTR(fan4_input, S_IRUGO, show_fan, NULL, 3), 1571 struct nct6775_data *data = dev_get_drvdata(dev);
1616 SENSOR_ATTR(fan5_input, S_IRUGO, show_fan, NULL, 4), 1572 int fan = index / 5; /* fan index */
1617}; 1573 int nr = index % 5; /* attribute index */
1618 1574
1619static struct sensor_device_attribute sda_fan_alarm[] = { 1575 if (!(data->has_fan & (1 << fan)))
1620 SENSOR_ATTR(fan1_alarm, S_IRUGO, show_alarm, NULL, FAN_ALARM_BASE), 1576 return 0;
1621 SENSOR_ATTR(fan2_alarm, S_IRUGO, show_alarm, NULL, FAN_ALARM_BASE + 1),
1622 SENSOR_ATTR(fan3_alarm, S_IRUGO, show_alarm, NULL, FAN_ALARM_BASE + 2),
1623 SENSOR_ATTR(fan4_alarm, S_IRUGO, show_alarm, NULL, FAN_ALARM_BASE + 3),
1624 SENSOR_ATTR(fan5_alarm, S_IRUGO, show_alarm, NULL, FAN_ALARM_BASE + 4),
1625};
1626 1577
1627static struct sensor_device_attribute sda_fan_min[] = { 1578 if (nr == 1 && data->ALARM_BITS[FAN_ALARM_BASE + fan] == -1)
1628 SENSOR_ATTR(fan1_min, S_IWUSR | S_IRUGO, show_fan_min, 1579 return 0;
1629 store_fan_min, 0), 1580 if (nr == 3 && !(data->has_fan_min & (1 << fan)))
1630 SENSOR_ATTR(fan2_min, S_IWUSR | S_IRUGO, show_fan_min, 1581 return 0;
1631 store_fan_min, 1), 1582 if (nr == 4 && data->kind != nct6775)
1632 SENSOR_ATTR(fan3_min, S_IWUSR | S_IRUGO, show_fan_min, 1583 return 0;
1633 store_fan_min, 2),
1634 SENSOR_ATTR(fan4_min, S_IWUSR | S_IRUGO, show_fan_min,
1635 store_fan_min, 3),
1636 SENSOR_ATTR(fan5_min, S_IWUSR | S_IRUGO, show_fan_min,
1637 store_fan_min, 4),
1638};
1639 1584
1640static struct sensor_device_attribute sda_fan_pulses[] = { 1585 return attr->mode;
1641 SENSOR_ATTR(fan1_pulses, S_IWUSR | S_IRUGO, show_fan_pulses, 1586}
1642 store_fan_pulses, 0), 1587
1643 SENSOR_ATTR(fan2_pulses, S_IWUSR | S_IRUGO, show_fan_pulses, 1588SENSOR_TEMPLATE(fan_input, "fan%d_input", S_IRUGO, show_fan, NULL, 0);
1644 store_fan_pulses, 1), 1589SENSOR_TEMPLATE(fan_alarm, "fan%d_alarm", S_IRUGO, show_alarm, NULL,
1645 SENSOR_ATTR(fan3_pulses, S_IWUSR | S_IRUGO, show_fan_pulses, 1590 FAN_ALARM_BASE);
1646 store_fan_pulses, 2), 1591SENSOR_TEMPLATE(fan_pulses, "fan%d_pulses", S_IWUSR | S_IRUGO, show_fan_pulses,
1647 SENSOR_ATTR(fan4_pulses, S_IWUSR | S_IRUGO, show_fan_pulses, 1592 store_fan_pulses, 0);
1648 store_fan_pulses, 3), 1593SENSOR_TEMPLATE(fan_min, "fan%d_min", S_IWUSR | S_IRUGO, show_fan_min,
1649 SENSOR_ATTR(fan5_pulses, S_IWUSR | S_IRUGO, show_fan_pulses, 1594 store_fan_min, 0);
1650 store_fan_pulses, 4), 1595SENSOR_TEMPLATE(fan_div, "fan%d_div", S_IRUGO, show_fan_div, NULL, 0);
1596
1597/*
1598 * nct6775_fan_is_visible uses the index into the following array
1599 * to determine if attributes should be created or not.
1600 * Any change in order or content must be matched.
1601 */
1602static struct sensor_device_template *nct6775_attributes_fan_template[] = {
1603 &sensor_dev_template_fan_input,
1604 &sensor_dev_template_fan_alarm, /* 1 */
1605 &sensor_dev_template_fan_pulses,
1606 &sensor_dev_template_fan_min, /* 3 */
1607 &sensor_dev_template_fan_div, /* 4 */
1608 NULL
1651}; 1609};
1652 1610
1653static struct sensor_device_attribute sda_fan_div[] = { 1611static struct sensor_template_group nct6775_fan_template_group = {
1654 SENSOR_ATTR(fan1_div, S_IRUGO, show_fan_div, NULL, 0), 1612 .templates = nct6775_attributes_fan_template,
1655 SENSOR_ATTR(fan2_div, S_IRUGO, show_fan_div, NULL, 1), 1613 .is_visible = nct6775_fan_is_visible,
1656 SENSOR_ATTR(fan3_div, S_IRUGO, show_fan_div, NULL, 2), 1614 .base = 1,
1657 SENSOR_ATTR(fan4_div, S_IRUGO, show_fan_div, NULL, 3),
1658 SENSOR_ATTR(fan5_div, S_IRUGO, show_fan_div, NULL, 4),
1659}; 1615};
1660 1616
1661static ssize_t 1617static ssize_t
@@ -1785,142 +1741,70 @@ store_temp_type(struct device *dev, struct device_attribute *attr,
1785 return count; 1741 return count;
1786} 1742}
1787 1743
1788static struct sensor_device_attribute_2 sda_temp_input[] = { 1744static umode_t nct6775_temp_is_visible(struct kobject *kobj,
1789 SENSOR_ATTR_2(temp1_input, S_IRUGO, show_temp, NULL, 0, 0), 1745 struct attribute *attr, int index)
1790 SENSOR_ATTR_2(temp2_input, S_IRUGO, show_temp, NULL, 1, 0), 1746{
1791 SENSOR_ATTR_2(temp3_input, S_IRUGO, show_temp, NULL, 2, 0), 1747 struct device *dev = container_of(kobj, struct device, kobj);
1792 SENSOR_ATTR_2(temp4_input, S_IRUGO, show_temp, NULL, 3, 0), 1748 struct nct6775_data *data = dev_get_drvdata(dev);
1793 SENSOR_ATTR_2(temp5_input, S_IRUGO, show_temp, NULL, 4, 0), 1749 int temp = index / 8; /* temp index */
1794 SENSOR_ATTR_2(temp6_input, S_IRUGO, show_temp, NULL, 5, 0), 1750 int nr = index % 8; /* attribute index */
1795 SENSOR_ATTR_2(temp7_input, S_IRUGO, show_temp, NULL, 6, 0),
1796 SENSOR_ATTR_2(temp8_input, S_IRUGO, show_temp, NULL, 7, 0),
1797 SENSOR_ATTR_2(temp9_input, S_IRUGO, show_temp, NULL, 8, 0),
1798 SENSOR_ATTR_2(temp10_input, S_IRUGO, show_temp, NULL, 9, 0),
1799};
1800 1751
1801static struct sensor_device_attribute sda_temp_label[] = { 1752 if (!(data->have_temp & (1 << temp)))
1802 SENSOR_ATTR(temp1_label, S_IRUGO, show_temp_label, NULL, 0), 1753 return 0;
1803 SENSOR_ATTR(temp2_label, S_IRUGO, show_temp_label, NULL, 1),
1804 SENSOR_ATTR(temp3_label, S_IRUGO, show_temp_label, NULL, 2),
1805 SENSOR_ATTR(temp4_label, S_IRUGO, show_temp_label, NULL, 3),
1806 SENSOR_ATTR(temp5_label, S_IRUGO, show_temp_label, NULL, 4),
1807 SENSOR_ATTR(temp6_label, S_IRUGO, show_temp_label, NULL, 5),
1808 SENSOR_ATTR(temp7_label, S_IRUGO, show_temp_label, NULL, 6),
1809 SENSOR_ATTR(temp8_label, S_IRUGO, show_temp_label, NULL, 7),
1810 SENSOR_ATTR(temp9_label, S_IRUGO, show_temp_label, NULL, 8),
1811 SENSOR_ATTR(temp10_label, S_IRUGO, show_temp_label, NULL, 9),
1812};
1813 1754
1814static struct sensor_device_attribute_2 sda_temp_max[] = { 1755 if (nr == 2 && find_temp_source(data, temp, data->num_temp_alarms) < 0)
1815 SENSOR_ATTR_2(temp1_max, S_IRUGO | S_IWUSR, show_temp, store_temp, 1756 return 0; /* alarm */
1816 0, 1),
1817 SENSOR_ATTR_2(temp2_max, S_IRUGO | S_IWUSR, show_temp, store_temp,
1818 1, 1),
1819 SENSOR_ATTR_2(temp3_max, S_IRUGO | S_IWUSR, show_temp, store_temp,
1820 2, 1),
1821 SENSOR_ATTR_2(temp4_max, S_IRUGO | S_IWUSR, show_temp, store_temp,
1822 3, 1),
1823 SENSOR_ATTR_2(temp5_max, S_IRUGO | S_IWUSR, show_temp, store_temp,
1824 4, 1),
1825 SENSOR_ATTR_2(temp6_max, S_IRUGO | S_IWUSR, show_temp, store_temp,
1826 5, 1),
1827 SENSOR_ATTR_2(temp7_max, S_IRUGO | S_IWUSR, show_temp, store_temp,
1828 6, 1),
1829 SENSOR_ATTR_2(temp8_max, S_IRUGO | S_IWUSR, show_temp, store_temp,
1830 7, 1),
1831 SENSOR_ATTR_2(temp9_max, S_IRUGO | S_IWUSR, show_temp, store_temp,
1832 8, 1),
1833 SENSOR_ATTR_2(temp10_max, S_IRUGO | S_IWUSR, show_temp, store_temp,
1834 9, 1),
1835};
1836 1757
1837static struct sensor_device_attribute_2 sda_temp_max_hyst[] = { 1758 if (nr == 3 && !data->reg_temp[1][temp]) /* max */
1838 SENSOR_ATTR_2(temp1_max_hyst, S_IRUGO | S_IWUSR, show_temp, store_temp, 1759 return 0;
1839 0, 2),
1840 SENSOR_ATTR_2(temp2_max_hyst, S_IRUGO | S_IWUSR, show_temp, store_temp,
1841 1, 2),
1842 SENSOR_ATTR_2(temp3_max_hyst, S_IRUGO | S_IWUSR, show_temp, store_temp,
1843 2, 2),
1844 SENSOR_ATTR_2(temp4_max_hyst, S_IRUGO | S_IWUSR, show_temp, store_temp,
1845 3, 2),
1846 SENSOR_ATTR_2(temp5_max_hyst, S_IRUGO | S_IWUSR, show_temp, store_temp,
1847 4, 2),
1848 SENSOR_ATTR_2(temp6_max_hyst, S_IRUGO | S_IWUSR, show_temp, store_temp,
1849 5, 2),
1850 SENSOR_ATTR_2(temp7_max_hyst, S_IRUGO | S_IWUSR, show_temp, store_temp,
1851 6, 2),
1852 SENSOR_ATTR_2(temp8_max_hyst, S_IRUGO | S_IWUSR, show_temp, store_temp,
1853 7, 2),
1854 SENSOR_ATTR_2(temp9_max_hyst, S_IRUGO | S_IWUSR, show_temp, store_temp,
1855 8, 2),
1856 SENSOR_ATTR_2(temp10_max_hyst, S_IRUGO | S_IWUSR, show_temp, store_temp,
1857 9, 2),
1858};
1859 1760
1860static struct sensor_device_attribute_2 sda_temp_crit[] = { 1761 if (nr == 4 && !data->reg_temp[2][temp]) /* max_hyst */
1861 SENSOR_ATTR_2(temp1_crit, S_IRUGO | S_IWUSR, show_temp, store_temp, 1762 return 0;
1862 0, 3),
1863 SENSOR_ATTR_2(temp2_crit, S_IRUGO | S_IWUSR, show_temp, store_temp,
1864 1, 3),
1865 SENSOR_ATTR_2(temp3_crit, S_IRUGO | S_IWUSR, show_temp, store_temp,
1866 2, 3),
1867 SENSOR_ATTR_2(temp4_crit, S_IRUGO | S_IWUSR, show_temp, store_temp,
1868 3, 3),
1869 SENSOR_ATTR_2(temp5_crit, S_IRUGO | S_IWUSR, show_temp, store_temp,
1870 4, 3),
1871 SENSOR_ATTR_2(temp6_crit, S_IRUGO | S_IWUSR, show_temp, store_temp,
1872 5, 3),
1873 SENSOR_ATTR_2(temp7_crit, S_IRUGO | S_IWUSR, show_temp, store_temp,
1874 6, 3),
1875 SENSOR_ATTR_2(temp8_crit, S_IRUGO | S_IWUSR, show_temp, store_temp,
1876 7, 3),
1877 SENSOR_ATTR_2(temp9_crit, S_IRUGO | S_IWUSR, show_temp, store_temp,
1878 8, 3),
1879 SENSOR_ATTR_2(temp10_crit, S_IRUGO | S_IWUSR, show_temp, store_temp,
1880 9, 3),
1881};
1882 1763
1883static struct sensor_device_attribute sda_temp_offset[] = { 1764 if (nr == 5 && !data->reg_temp[3][temp]) /* crit */
1884 SENSOR_ATTR(temp1_offset, S_IRUGO | S_IWUSR, show_temp_offset, 1765 return 0;
1885 store_temp_offset, 0),
1886 SENSOR_ATTR(temp2_offset, S_IRUGO | S_IWUSR, show_temp_offset,
1887 store_temp_offset, 1),
1888 SENSOR_ATTR(temp3_offset, S_IRUGO | S_IWUSR, show_temp_offset,
1889 store_temp_offset, 2),
1890 SENSOR_ATTR(temp4_offset, S_IRUGO | S_IWUSR, show_temp_offset,
1891 store_temp_offset, 3),
1892 SENSOR_ATTR(temp5_offset, S_IRUGO | S_IWUSR, show_temp_offset,
1893 store_temp_offset, 4),
1894 SENSOR_ATTR(temp6_offset, S_IRUGO | S_IWUSR, show_temp_offset,
1895 store_temp_offset, 5),
1896};
1897 1766
1898static struct sensor_device_attribute sda_temp_type[] = { 1767 if (nr > 5 && !(data->have_temp_fixed & (1 << temp)))
1899 SENSOR_ATTR(temp1_type, S_IRUGO | S_IWUSR, show_temp_type, 1768 return 0;
1900 store_temp_type, 0), 1769
1901 SENSOR_ATTR(temp2_type, S_IRUGO | S_IWUSR, show_temp_type, 1770 return attr->mode;
1902 store_temp_type, 1), 1771}
1903 SENSOR_ATTR(temp3_type, S_IRUGO | S_IWUSR, show_temp_type, 1772
1904 store_temp_type, 2), 1773SENSOR_TEMPLATE_2(temp_input, "temp%d_input", S_IRUGO, show_temp, NULL, 0, 0);
1905 SENSOR_ATTR(temp4_type, S_IRUGO | S_IWUSR, show_temp_type, 1774SENSOR_TEMPLATE(temp_label, "temp%d_label", S_IRUGO, show_temp_label, NULL, 0);
1906 store_temp_type, 3), 1775SENSOR_TEMPLATE_2(temp_max, "temp%d_max", S_IRUGO | S_IWUSR, show_temp,
1907 SENSOR_ATTR(temp5_type, S_IRUGO | S_IWUSR, show_temp_type, 1776 store_temp, 0, 1);
1908 store_temp_type, 4), 1777SENSOR_TEMPLATE_2(temp_max_hyst, "temp%d_max_hyst", S_IRUGO | S_IWUSR,
1909 SENSOR_ATTR(temp6_type, S_IRUGO | S_IWUSR, show_temp_type, 1778 show_temp, store_temp, 0, 2);
1910 store_temp_type, 5), 1779SENSOR_TEMPLATE_2(temp_crit, "temp%d_crit", S_IRUGO | S_IWUSR, show_temp,
1780 store_temp, 0, 3);
1781SENSOR_TEMPLATE(temp_offset, "temp%d_offset", S_IRUGO | S_IWUSR,
1782 show_temp_offset, store_temp_offset, 0);
1783SENSOR_TEMPLATE(temp_type, "temp%d_type", S_IRUGO | S_IWUSR, show_temp_type,
1784 store_temp_type, 0);
1785SENSOR_TEMPLATE(temp_alarm, "temp%d_alarm", S_IRUGO, show_temp_alarm, NULL, 0);
1786
1787/*
1788 * nct6775_temp_is_visible uses the index into the following array
1789 * to determine if attributes should be created or not.
1790 * Any change in order or content must be matched.
1791 */
1792static struct sensor_device_template *nct6775_attributes_temp_template[] = {
1793 &sensor_dev_template_temp_input,
1794 &sensor_dev_template_temp_label,
1795 &sensor_dev_template_temp_alarm, /* 2 */
1796 &sensor_dev_template_temp_max, /* 3 */
1797 &sensor_dev_template_temp_max_hyst, /* 4 */
1798 &sensor_dev_template_temp_crit, /* 5 */
1799 &sensor_dev_template_temp_offset, /* 6 */
1800 &sensor_dev_template_temp_type, /* 7 */
1801 NULL
1911}; 1802};
1912 1803
1913static struct sensor_device_attribute sda_temp_alarm[] = { 1804static struct sensor_template_group nct6775_temp_template_group = {
1914 SENSOR_ATTR(temp1_alarm, S_IRUGO, show_temp_alarm, NULL, 0), 1805 .templates = nct6775_attributes_temp_template,
1915 SENSOR_ATTR(temp2_alarm, S_IRUGO, show_temp_alarm, NULL, 1), 1806 .is_visible = nct6775_temp_is_visible,
1916 SENSOR_ATTR(temp3_alarm, S_IRUGO, show_temp_alarm, NULL, 2), 1807 .base = 1,
1917 SENSOR_ATTR(temp4_alarm, S_IRUGO, show_temp_alarm, NULL, 3),
1918 SENSOR_ATTR(temp5_alarm, S_IRUGO, show_temp_alarm, NULL, 4),
1919 SENSOR_ATTR(temp6_alarm, S_IRUGO, show_temp_alarm, NULL, 5),
1920 SENSOR_ATTR(temp7_alarm, S_IRUGO, show_temp_alarm, NULL, 6),
1921 SENSOR_ATTR(temp8_alarm, S_IRUGO, show_temp_alarm, NULL, 7),
1922 SENSOR_ATTR(temp9_alarm, S_IRUGO, show_temp_alarm, NULL, 8),
1923 SENSOR_ATTR(temp10_alarm, S_IRUGO, show_temp_alarm, NULL, 9),
1924}; 1808};
1925 1809
1926static ssize_t 1810static ssize_t
@@ -2422,77 +2306,19 @@ store_speed_tolerance(struct device *dev, struct device_attribute *attr,
2422 return count; 2306 return count;
2423} 2307}
2424 2308
2425static SENSOR_DEVICE_ATTR_2(pwm1, S_IWUSR | S_IRUGO, show_pwm, store_pwm, 0, 0); 2309SENSOR_TEMPLATE_2(pwm, "pwm%d", S_IWUSR | S_IRUGO, show_pwm, store_pwm, 0, 0);
2426static SENSOR_DEVICE_ATTR_2(pwm2, S_IWUSR | S_IRUGO, show_pwm, store_pwm, 1, 0); 2310SENSOR_TEMPLATE(pwm_mode, "pwm%d_mode", S_IWUSR | S_IRUGO, show_pwm_mode,
2427static SENSOR_DEVICE_ATTR_2(pwm3, S_IWUSR | S_IRUGO, show_pwm, store_pwm, 2, 0); 2311 store_pwm_mode, 0);
2428static SENSOR_DEVICE_ATTR_2(pwm4, S_IWUSR | S_IRUGO, show_pwm, store_pwm, 3, 0); 2312SENSOR_TEMPLATE(pwm_enable, "pwm%d_enable", S_IWUSR | S_IRUGO, show_pwm_enable,
2429static SENSOR_DEVICE_ATTR_2(pwm5, S_IWUSR | S_IRUGO, show_pwm, store_pwm, 4, 0); 2313 store_pwm_enable, 0);
2430 2314SENSOR_TEMPLATE(pwm_temp_sel, "pwm%d_temp_sel", S_IWUSR | S_IRUGO,
2431static SENSOR_DEVICE_ATTR(pwm1_mode, S_IWUSR | S_IRUGO, show_pwm_mode, 2315 show_pwm_temp_sel, store_pwm_temp_sel, 0);
2432 store_pwm_mode, 0); 2316SENSOR_TEMPLATE(pwm_target_temp, "pwm%d_target_temp", S_IWUSR | S_IRUGO,
2433static SENSOR_DEVICE_ATTR(pwm2_mode, S_IWUSR | S_IRUGO, show_pwm_mode, 2317 show_target_temp, store_target_temp, 0);
2434 store_pwm_mode, 1); 2318SENSOR_TEMPLATE(fan_target, "fan%d_target", S_IWUSR | S_IRUGO,
2435static SENSOR_DEVICE_ATTR(pwm3_mode, S_IWUSR | S_IRUGO, show_pwm_mode, 2319 show_target_speed, store_target_speed, 0);
2436 store_pwm_mode, 2); 2320SENSOR_TEMPLATE(fan_tolerance, "fan%d_tolerance", S_IWUSR | S_IRUGO,
2437static SENSOR_DEVICE_ATTR(pwm4_mode, S_IWUSR | S_IRUGO, show_pwm_mode, 2321 show_speed_tolerance, store_speed_tolerance, 0);
2438 store_pwm_mode, 3);
2439static SENSOR_DEVICE_ATTR(pwm5_mode, S_IWUSR | S_IRUGO, show_pwm_mode,
2440 store_pwm_mode, 4);
2441
2442static SENSOR_DEVICE_ATTR(pwm1_enable, S_IWUSR | S_IRUGO, show_pwm_enable,
2443 store_pwm_enable, 0);
2444static SENSOR_DEVICE_ATTR(pwm2_enable, S_IWUSR | S_IRUGO, show_pwm_enable,
2445 store_pwm_enable, 1);
2446static SENSOR_DEVICE_ATTR(pwm3_enable, S_IWUSR | S_IRUGO, show_pwm_enable,
2447 store_pwm_enable, 2);
2448static SENSOR_DEVICE_ATTR(pwm4_enable, S_IWUSR | S_IRUGO, show_pwm_enable,
2449 store_pwm_enable, 3);
2450static SENSOR_DEVICE_ATTR(pwm5_enable, S_IWUSR | S_IRUGO, show_pwm_enable,
2451 store_pwm_enable, 4);
2452
2453static SENSOR_DEVICE_ATTR(pwm1_temp_sel, S_IWUSR | S_IRUGO,
2454 show_pwm_temp_sel, store_pwm_temp_sel, 0);
2455static SENSOR_DEVICE_ATTR(pwm2_temp_sel, S_IWUSR | S_IRUGO,
2456 show_pwm_temp_sel, store_pwm_temp_sel, 1);
2457static SENSOR_DEVICE_ATTR(pwm3_temp_sel, S_IWUSR | S_IRUGO,
2458 show_pwm_temp_sel, store_pwm_temp_sel, 2);
2459static SENSOR_DEVICE_ATTR(pwm4_temp_sel, S_IWUSR | S_IRUGO,
2460 show_pwm_temp_sel, store_pwm_temp_sel, 3);
2461static SENSOR_DEVICE_ATTR(pwm5_temp_sel, S_IWUSR | S_IRUGO,
2462 show_pwm_temp_sel, store_pwm_temp_sel, 4);
2463
2464static SENSOR_DEVICE_ATTR(pwm1_target_temp, S_IWUSR | S_IRUGO, show_target_temp,
2465 store_target_temp, 0);
2466static SENSOR_DEVICE_ATTR(pwm2_target_temp, S_IWUSR | S_IRUGO, show_target_temp,
2467 store_target_temp, 1);
2468static SENSOR_DEVICE_ATTR(pwm3_target_temp, S_IWUSR | S_IRUGO, show_target_temp,
2469 store_target_temp, 2);
2470static SENSOR_DEVICE_ATTR(pwm4_target_temp, S_IWUSR | S_IRUGO, show_target_temp,
2471 store_target_temp, 3);
2472static SENSOR_DEVICE_ATTR(pwm5_target_temp, S_IWUSR | S_IRUGO, show_target_temp,
2473 store_target_temp, 4);
2474
2475static SENSOR_DEVICE_ATTR(fan1_target, S_IWUSR | S_IRUGO, show_target_speed,
2476 store_target_speed, 0);
2477static SENSOR_DEVICE_ATTR(fan2_target, S_IWUSR | S_IRUGO, show_target_speed,
2478 store_target_speed, 1);
2479static SENSOR_DEVICE_ATTR(fan3_target, S_IWUSR | S_IRUGO, show_target_speed,
2480 store_target_speed, 2);
2481static SENSOR_DEVICE_ATTR(fan4_target, S_IWUSR | S_IRUGO, show_target_speed,
2482 store_target_speed, 3);
2483static SENSOR_DEVICE_ATTR(fan5_target, S_IWUSR | S_IRUGO, show_target_speed,
2484 store_target_speed, 4);
2485
2486static SENSOR_DEVICE_ATTR(fan1_tolerance, S_IWUSR | S_IRUGO,
2487 show_speed_tolerance, store_speed_tolerance, 0);
2488static SENSOR_DEVICE_ATTR(fan2_tolerance, S_IWUSR | S_IRUGO,
2489 show_speed_tolerance, store_speed_tolerance, 1);
2490static SENSOR_DEVICE_ATTR(fan3_tolerance, S_IWUSR | S_IRUGO,
2491 show_speed_tolerance, store_speed_tolerance, 2);
2492static SENSOR_DEVICE_ATTR(fan4_tolerance, S_IWUSR | S_IRUGO,
2493 show_speed_tolerance, store_speed_tolerance, 3);
2494static SENSOR_DEVICE_ATTR(fan5_tolerance, S_IWUSR | S_IRUGO,
2495 show_speed_tolerance, store_speed_tolerance, 4);
2496 2322
2497/* Smart Fan registers */ 2323/* Smart Fan registers */
2498 2324
@@ -2531,79 +2357,18 @@ store_weight_temp(struct device *dev, struct device_attribute *attr,
2531 return count; 2357 return count;
2532} 2358}
2533 2359
2534static SENSOR_DEVICE_ATTR(pwm1_weight_temp_sel, S_IWUSR | S_IRUGO, 2360SENSOR_TEMPLATE(pwm_weight_temp_sel, "pwm%d_weight_temp_sel", S_IWUSR | S_IRUGO,
2535 show_pwm_weight_temp_sel, store_pwm_weight_temp_sel, 2361 show_pwm_weight_temp_sel, store_pwm_weight_temp_sel, 0);
2536 0); 2362SENSOR_TEMPLATE_2(pwm_weight_temp_step, "pwm%d_weight_temp_step",
2537static SENSOR_DEVICE_ATTR(pwm2_weight_temp_sel, S_IWUSR | S_IRUGO, 2363 S_IWUSR | S_IRUGO, show_weight_temp, store_weight_temp, 0, 0);
2538 show_pwm_weight_temp_sel, store_pwm_weight_temp_sel, 2364SENSOR_TEMPLATE_2(pwm_weight_temp_step_tol, "pwm%d_weight_temp_step_tol",
2539 1); 2365 S_IWUSR | S_IRUGO, show_weight_temp, store_weight_temp, 0, 1);
2540static SENSOR_DEVICE_ATTR(pwm3_weight_temp_sel, S_IWUSR | S_IRUGO, 2366SENSOR_TEMPLATE_2(pwm_weight_temp_step_base, "pwm%d_weight_temp_step_base",
2541 show_pwm_weight_temp_sel, store_pwm_weight_temp_sel, 2367 S_IWUSR | S_IRUGO, show_weight_temp, store_weight_temp, 0, 2);
2542 2); 2368SENSOR_TEMPLATE_2(pwm_weight_duty_step, "pwm%d_weight_duty_step",
2543static SENSOR_DEVICE_ATTR(pwm4_weight_temp_sel, S_IWUSR | S_IRUGO, 2369 S_IWUSR | S_IRUGO, show_pwm, store_pwm, 0, 5);
2544 show_pwm_weight_temp_sel, store_pwm_weight_temp_sel, 2370SENSOR_TEMPLATE_2(pwm_weight_duty_base, "pwm%d_weight_duty_base",
2545 3); 2371 S_IWUSR | S_IRUGO, show_pwm, store_pwm, 0, 6);
2546static SENSOR_DEVICE_ATTR(pwm5_weight_temp_sel, S_IWUSR | S_IRUGO,
2547 show_pwm_weight_temp_sel, store_pwm_weight_temp_sel,
2548 4);
2549
2550static SENSOR_DEVICE_ATTR_2(pwm1_weight_temp_step, S_IWUSR | S_IRUGO,
2551 show_weight_temp, store_weight_temp, 0, 0);
2552static SENSOR_DEVICE_ATTR_2(pwm2_weight_temp_step, S_IWUSR | S_IRUGO,
2553 show_weight_temp, store_weight_temp, 1, 0);
2554static SENSOR_DEVICE_ATTR_2(pwm3_weight_temp_step, S_IWUSR | S_IRUGO,
2555 show_weight_temp, store_weight_temp, 2, 0);
2556static SENSOR_DEVICE_ATTR_2(pwm4_weight_temp_step, S_IWUSR | S_IRUGO,
2557 show_weight_temp, store_weight_temp, 3, 0);
2558static SENSOR_DEVICE_ATTR_2(pwm5_weight_temp_step, S_IWUSR | S_IRUGO,
2559 show_weight_temp, store_weight_temp, 4, 0);
2560
2561static SENSOR_DEVICE_ATTR_2(pwm1_weight_temp_step_tol, S_IWUSR | S_IRUGO,
2562 show_weight_temp, store_weight_temp, 0, 1);
2563static SENSOR_DEVICE_ATTR_2(pwm2_weight_temp_step_tol, S_IWUSR | S_IRUGO,
2564 show_weight_temp, store_weight_temp, 1, 1);
2565static SENSOR_DEVICE_ATTR_2(pwm3_weight_temp_step_tol, S_IWUSR | S_IRUGO,
2566 show_weight_temp, store_weight_temp, 2, 1);
2567static SENSOR_DEVICE_ATTR_2(pwm4_weight_temp_step_tol, S_IWUSR | S_IRUGO,
2568 show_weight_temp, store_weight_temp, 3, 1);
2569static SENSOR_DEVICE_ATTR_2(pwm5_weight_temp_step_tol, S_IWUSR | S_IRUGO,
2570 show_weight_temp, store_weight_temp, 4, 1);
2571
2572static SENSOR_DEVICE_ATTR_2(pwm1_weight_temp_step_base, S_IWUSR | S_IRUGO,
2573 show_weight_temp, store_weight_temp, 0, 2);
2574static SENSOR_DEVICE_ATTR_2(pwm2_weight_temp_step_base, S_IWUSR | S_IRUGO,
2575 show_weight_temp, store_weight_temp, 1, 2);
2576static SENSOR_DEVICE_ATTR_2(pwm3_weight_temp_step_base, S_IWUSR | S_IRUGO,
2577 show_weight_temp, store_weight_temp, 2, 2);
2578static SENSOR_DEVICE_ATTR_2(pwm4_weight_temp_step_base, S_IWUSR | S_IRUGO,
2579 show_weight_temp, store_weight_temp, 3, 2);
2580static SENSOR_DEVICE_ATTR_2(pwm5_weight_temp_step_base, S_IWUSR | S_IRUGO,
2581 show_weight_temp, store_weight_temp, 4, 2);
2582
2583static SENSOR_DEVICE_ATTR_2(pwm1_weight_duty_step, S_IWUSR | S_IRUGO,
2584 show_pwm, store_pwm, 0, 5);
2585static SENSOR_DEVICE_ATTR_2(pwm2_weight_duty_step, S_IWUSR | S_IRUGO,
2586 show_pwm, store_pwm, 1, 5);
2587static SENSOR_DEVICE_ATTR_2(pwm3_weight_duty_step, S_IWUSR | S_IRUGO,
2588 show_pwm, store_pwm, 2, 5);
2589static SENSOR_DEVICE_ATTR_2(pwm4_weight_duty_step, S_IWUSR | S_IRUGO,
2590 show_pwm, store_pwm, 3, 5);
2591static SENSOR_DEVICE_ATTR_2(pwm5_weight_duty_step, S_IWUSR | S_IRUGO,
2592 show_pwm, store_pwm, 4, 5);
2593
2594/* duty_base is not supported on all chips */
2595static struct sensor_device_attribute_2 sda_weight_duty_base[] = {
2596 SENSOR_ATTR_2(pwm1_weight_duty_base, S_IWUSR | S_IRUGO,
2597 show_pwm, store_pwm, 0, 6),
2598 SENSOR_ATTR_2(pwm2_weight_duty_base, S_IWUSR | S_IRUGO,
2599 show_pwm, store_pwm, 1, 6),
2600 SENSOR_ATTR_2(pwm3_weight_duty_base, S_IWUSR | S_IRUGO,
2601 show_pwm, store_pwm, 2, 6),
2602 SENSOR_ATTR_2(pwm4_weight_duty_base, S_IWUSR | S_IRUGO,
2603 show_pwm, store_pwm, 3, 6),
2604 SENSOR_ATTR_2(pwm5_weight_duty_base, S_IWUSR | S_IRUGO,
2605 show_pwm, store_pwm, 4, 6),
2606};
2607 2372
2608static ssize_t 2373static ssize_t
2609show_fan_time(struct device *dev, struct device_attribute *attr, char *buf) 2374show_fan_time(struct device *dev, struct device_attribute *attr, char *buf)
@@ -2651,227 +2416,6 @@ show_name(struct device *dev, struct device_attribute *attr, char *buf)
2651 2416
2652static DEVICE_ATTR(name, S_IRUGO, show_name, NULL); 2417static DEVICE_ATTR(name, S_IRUGO, show_name, NULL);
2653 2418
2654static SENSOR_DEVICE_ATTR_2(pwm1_stop_time, S_IWUSR | S_IRUGO, show_fan_time,
2655 store_fan_time, 0, 0);
2656static SENSOR_DEVICE_ATTR_2(pwm2_stop_time, S_IWUSR | S_IRUGO, show_fan_time,
2657 store_fan_time, 1, 0);
2658static SENSOR_DEVICE_ATTR_2(pwm3_stop_time, S_IWUSR | S_IRUGO, show_fan_time,
2659 store_fan_time, 2, 0);
2660static SENSOR_DEVICE_ATTR_2(pwm4_stop_time, S_IWUSR | S_IRUGO, show_fan_time,
2661 store_fan_time, 3, 0);
2662static SENSOR_DEVICE_ATTR_2(pwm5_stop_time, S_IWUSR | S_IRUGO, show_fan_time,
2663 store_fan_time, 4, 0);
2664
2665static SENSOR_DEVICE_ATTR_2(pwm1_step_up_time, S_IWUSR | S_IRUGO, show_fan_time,
2666 store_fan_time, 0, 1);
2667static SENSOR_DEVICE_ATTR_2(pwm2_step_up_time, S_IWUSR | S_IRUGO, show_fan_time,
2668 store_fan_time, 1, 1);
2669static SENSOR_DEVICE_ATTR_2(pwm3_step_up_time, S_IWUSR | S_IRUGO, show_fan_time,
2670 store_fan_time, 2, 1);
2671static SENSOR_DEVICE_ATTR_2(pwm4_step_up_time, S_IWUSR | S_IRUGO, show_fan_time,
2672 store_fan_time, 3, 1);
2673static SENSOR_DEVICE_ATTR_2(pwm5_step_up_time, S_IWUSR | S_IRUGO, show_fan_time,
2674 store_fan_time, 4, 1);
2675
2676static SENSOR_DEVICE_ATTR_2(pwm1_step_down_time, S_IWUSR | S_IRUGO,
2677 show_fan_time, store_fan_time, 0, 2);
2678static SENSOR_DEVICE_ATTR_2(pwm2_step_down_time, S_IWUSR | S_IRUGO,
2679 show_fan_time, store_fan_time, 1, 2);
2680static SENSOR_DEVICE_ATTR_2(pwm3_step_down_time, S_IWUSR | S_IRUGO,
2681 show_fan_time, store_fan_time, 2, 2);
2682static SENSOR_DEVICE_ATTR_2(pwm4_step_down_time, S_IWUSR | S_IRUGO,
2683 show_fan_time, store_fan_time, 3, 2);
2684static SENSOR_DEVICE_ATTR_2(pwm5_step_down_time, S_IWUSR | S_IRUGO,
2685 show_fan_time, store_fan_time, 4, 2);
2686
2687static SENSOR_DEVICE_ATTR_2(pwm1_start, S_IWUSR | S_IRUGO, show_pwm,
2688 store_pwm, 0, 1);
2689static SENSOR_DEVICE_ATTR_2(pwm2_start, S_IWUSR | S_IRUGO, show_pwm,
2690 store_pwm, 1, 1);
2691static SENSOR_DEVICE_ATTR_2(pwm3_start, S_IWUSR | S_IRUGO, show_pwm,
2692 store_pwm, 2, 1);
2693static SENSOR_DEVICE_ATTR_2(pwm4_start, S_IWUSR | S_IRUGO, show_pwm,
2694 store_pwm, 3, 1);
2695static SENSOR_DEVICE_ATTR_2(pwm5_start, S_IWUSR | S_IRUGO, show_pwm,
2696 store_pwm, 4, 1);
2697
2698static SENSOR_DEVICE_ATTR_2(pwm1_floor, S_IWUSR | S_IRUGO, show_pwm,
2699 store_pwm, 0, 2);
2700static SENSOR_DEVICE_ATTR_2(pwm2_floor, S_IWUSR | S_IRUGO, show_pwm,
2701 store_pwm, 1, 2);
2702static SENSOR_DEVICE_ATTR_2(pwm3_floor, S_IWUSR | S_IRUGO, show_pwm,
2703 store_pwm, 2, 2);
2704static SENSOR_DEVICE_ATTR_2(pwm4_floor, S_IWUSR | S_IRUGO, show_pwm,
2705 store_pwm, 3, 2);
2706static SENSOR_DEVICE_ATTR_2(pwm5_floor, S_IWUSR | S_IRUGO, show_pwm,
2707 store_pwm, 4, 2);
2708
2709static SENSOR_DEVICE_ATTR_2(pwm1_temp_tolerance, S_IWUSR | S_IRUGO,
2710 show_temp_tolerance, store_temp_tolerance, 0, 0);
2711static SENSOR_DEVICE_ATTR_2(pwm2_temp_tolerance, S_IWUSR | S_IRUGO,
2712 show_temp_tolerance, store_temp_tolerance, 1, 0);
2713static SENSOR_DEVICE_ATTR_2(pwm3_temp_tolerance, S_IWUSR | S_IRUGO,
2714 show_temp_tolerance, store_temp_tolerance, 2, 0);
2715static SENSOR_DEVICE_ATTR_2(pwm4_temp_tolerance, S_IWUSR | S_IRUGO,
2716 show_temp_tolerance, store_temp_tolerance, 3, 0);
2717static SENSOR_DEVICE_ATTR_2(pwm5_temp_tolerance, S_IWUSR | S_IRUGO,
2718 show_temp_tolerance, store_temp_tolerance, 4, 0);
2719
2720static SENSOR_DEVICE_ATTR_2(pwm1_crit_temp_tolerance, S_IWUSR | S_IRUGO,
2721 show_temp_tolerance, store_temp_tolerance, 0, 1);
2722static SENSOR_DEVICE_ATTR_2(pwm2_crit_temp_tolerance, S_IWUSR | S_IRUGO,
2723 show_temp_tolerance, store_temp_tolerance, 1, 1);
2724static SENSOR_DEVICE_ATTR_2(pwm3_crit_temp_tolerance, S_IWUSR | S_IRUGO,
2725 show_temp_tolerance, store_temp_tolerance, 2, 1);
2726static SENSOR_DEVICE_ATTR_2(pwm4_crit_temp_tolerance, S_IWUSR | S_IRUGO,
2727 show_temp_tolerance, store_temp_tolerance, 3, 1);
2728static SENSOR_DEVICE_ATTR_2(pwm5_crit_temp_tolerance, S_IWUSR | S_IRUGO,
2729 show_temp_tolerance, store_temp_tolerance, 4, 1);
2730
2731/* pwm_max is not supported on all chips */
2732static struct sensor_device_attribute_2 sda_pwm_max[] = {
2733 SENSOR_ATTR_2(pwm1_max, S_IWUSR | S_IRUGO, show_pwm, store_pwm,
2734 0, 3),
2735 SENSOR_ATTR_2(pwm2_max, S_IWUSR | S_IRUGO, show_pwm, store_pwm,
2736 1, 3),
2737 SENSOR_ATTR_2(pwm3_max, S_IWUSR | S_IRUGO, show_pwm, store_pwm,
2738 2, 3),
2739 SENSOR_ATTR_2(pwm4_max, S_IWUSR | S_IRUGO, show_pwm, store_pwm,
2740 3, 3),
2741 SENSOR_ATTR_2(pwm5_max, S_IWUSR | S_IRUGO, show_pwm, store_pwm,
2742 4, 3),
2743};
2744
2745/* pwm_step is not supported on all chips */
2746static struct sensor_device_attribute_2 sda_pwm_step[] = {
2747 SENSOR_ATTR_2(pwm1_step, S_IWUSR | S_IRUGO, show_pwm, store_pwm, 0, 4),
2748 SENSOR_ATTR_2(pwm2_step, S_IWUSR | S_IRUGO, show_pwm, store_pwm, 1, 4),
2749 SENSOR_ATTR_2(pwm3_step, S_IWUSR | S_IRUGO, show_pwm, store_pwm, 2, 4),
2750 SENSOR_ATTR_2(pwm4_step, S_IWUSR | S_IRUGO, show_pwm, store_pwm, 3, 4),
2751 SENSOR_ATTR_2(pwm5_step, S_IWUSR | S_IRUGO, show_pwm, store_pwm, 4, 4),
2752};
2753
2754static struct attribute *nct6775_attributes_pwm[5][20] = {
2755 {
2756 &sensor_dev_attr_pwm1.dev_attr.attr,
2757 &sensor_dev_attr_pwm1_mode.dev_attr.attr,
2758 &sensor_dev_attr_pwm1_enable.dev_attr.attr,
2759 &sensor_dev_attr_pwm1_temp_sel.dev_attr.attr,
2760 &sensor_dev_attr_pwm1_temp_tolerance.dev_attr.attr,
2761 &sensor_dev_attr_pwm1_crit_temp_tolerance.dev_attr.attr,
2762 &sensor_dev_attr_pwm1_target_temp.dev_attr.attr,
2763 &sensor_dev_attr_fan1_target.dev_attr.attr,
2764 &sensor_dev_attr_fan1_tolerance.dev_attr.attr,
2765 &sensor_dev_attr_pwm1_stop_time.dev_attr.attr,
2766 &sensor_dev_attr_pwm1_step_up_time.dev_attr.attr,
2767 &sensor_dev_attr_pwm1_step_down_time.dev_attr.attr,
2768 &sensor_dev_attr_pwm1_start.dev_attr.attr,
2769 &sensor_dev_attr_pwm1_floor.dev_attr.attr,
2770 &sensor_dev_attr_pwm1_weight_temp_sel.dev_attr.attr,
2771 &sensor_dev_attr_pwm1_weight_temp_step.dev_attr.attr,
2772 &sensor_dev_attr_pwm1_weight_temp_step_tol.dev_attr.attr,
2773 &sensor_dev_attr_pwm1_weight_temp_step_base.dev_attr.attr,
2774 &sensor_dev_attr_pwm1_weight_duty_step.dev_attr.attr,
2775 NULL
2776 },
2777 {
2778 &sensor_dev_attr_pwm2.dev_attr.attr,
2779 &sensor_dev_attr_pwm2_mode.dev_attr.attr,
2780 &sensor_dev_attr_pwm2_enable.dev_attr.attr,
2781 &sensor_dev_attr_pwm2_temp_sel.dev_attr.attr,
2782 &sensor_dev_attr_pwm2_temp_tolerance.dev_attr.attr,
2783 &sensor_dev_attr_pwm2_crit_temp_tolerance.dev_attr.attr,
2784 &sensor_dev_attr_pwm2_target_temp.dev_attr.attr,
2785 &sensor_dev_attr_fan2_target.dev_attr.attr,
2786 &sensor_dev_attr_fan2_tolerance.dev_attr.attr,
2787 &sensor_dev_attr_pwm2_stop_time.dev_attr.attr,
2788 &sensor_dev_attr_pwm2_step_up_time.dev_attr.attr,
2789 &sensor_dev_attr_pwm2_step_down_time.dev_attr.attr,
2790 &sensor_dev_attr_pwm2_start.dev_attr.attr,
2791 &sensor_dev_attr_pwm2_floor.dev_attr.attr,
2792 &sensor_dev_attr_pwm2_weight_temp_sel.dev_attr.attr,
2793 &sensor_dev_attr_pwm2_weight_temp_step.dev_attr.attr,
2794 &sensor_dev_attr_pwm2_weight_temp_step_tol.dev_attr.attr,
2795 &sensor_dev_attr_pwm2_weight_temp_step_base.dev_attr.attr,
2796 &sensor_dev_attr_pwm2_weight_duty_step.dev_attr.attr,
2797 NULL
2798 },
2799 {
2800 &sensor_dev_attr_pwm3.dev_attr.attr,
2801 &sensor_dev_attr_pwm3_mode.dev_attr.attr,
2802 &sensor_dev_attr_pwm3_enable.dev_attr.attr,
2803 &sensor_dev_attr_pwm3_temp_sel.dev_attr.attr,
2804 &sensor_dev_attr_pwm3_temp_tolerance.dev_attr.attr,
2805 &sensor_dev_attr_pwm3_crit_temp_tolerance.dev_attr.attr,
2806 &sensor_dev_attr_pwm3_target_temp.dev_attr.attr,
2807 &sensor_dev_attr_fan3_target.dev_attr.attr,
2808 &sensor_dev_attr_fan3_tolerance.dev_attr.attr,
2809 &sensor_dev_attr_pwm3_stop_time.dev_attr.attr,
2810 &sensor_dev_attr_pwm3_step_up_time.dev_attr.attr,
2811 &sensor_dev_attr_pwm3_step_down_time.dev_attr.attr,
2812 &sensor_dev_attr_pwm3_start.dev_attr.attr,
2813 &sensor_dev_attr_pwm3_floor.dev_attr.attr,
2814 &sensor_dev_attr_pwm3_weight_temp_sel.dev_attr.attr,
2815 &sensor_dev_attr_pwm3_weight_temp_step.dev_attr.attr,
2816 &sensor_dev_attr_pwm3_weight_temp_step_tol.dev_attr.attr,
2817 &sensor_dev_attr_pwm3_weight_temp_step_base.dev_attr.attr,
2818 &sensor_dev_attr_pwm3_weight_duty_step.dev_attr.attr,
2819 NULL
2820 },
2821 {
2822 &sensor_dev_attr_pwm4.dev_attr.attr,
2823 &sensor_dev_attr_pwm4_mode.dev_attr.attr,
2824 &sensor_dev_attr_pwm4_enable.dev_attr.attr,
2825 &sensor_dev_attr_pwm4_temp_sel.dev_attr.attr,
2826 &sensor_dev_attr_pwm4_temp_tolerance.dev_attr.attr,
2827 &sensor_dev_attr_pwm4_crit_temp_tolerance.dev_attr.attr,
2828 &sensor_dev_attr_pwm4_target_temp.dev_attr.attr,
2829 &sensor_dev_attr_fan4_target.dev_attr.attr,
2830 &sensor_dev_attr_fan4_tolerance.dev_attr.attr,
2831 &sensor_dev_attr_pwm4_stop_time.dev_attr.attr,
2832 &sensor_dev_attr_pwm4_step_up_time.dev_attr.attr,
2833 &sensor_dev_attr_pwm4_step_down_time.dev_attr.attr,
2834 &sensor_dev_attr_pwm4_start.dev_attr.attr,
2835 &sensor_dev_attr_pwm4_floor.dev_attr.attr,
2836 &sensor_dev_attr_pwm4_weight_temp_sel.dev_attr.attr,
2837 &sensor_dev_attr_pwm4_weight_temp_step.dev_attr.attr,
2838 &sensor_dev_attr_pwm4_weight_temp_step_tol.dev_attr.attr,
2839 &sensor_dev_attr_pwm4_weight_temp_step_base.dev_attr.attr,
2840 &sensor_dev_attr_pwm4_weight_duty_step.dev_attr.attr,
2841 NULL
2842 },
2843 {
2844 &sensor_dev_attr_pwm5.dev_attr.attr,
2845 &sensor_dev_attr_pwm5_mode.dev_attr.attr,
2846 &sensor_dev_attr_pwm5_enable.dev_attr.attr,
2847 &sensor_dev_attr_pwm5_temp_sel.dev_attr.attr,
2848 &sensor_dev_attr_pwm5_temp_tolerance.dev_attr.attr,
2849 &sensor_dev_attr_pwm5_crit_temp_tolerance.dev_attr.attr,
2850 &sensor_dev_attr_pwm5_target_temp.dev_attr.attr,
2851 &sensor_dev_attr_fan5_target.dev_attr.attr,
2852 &sensor_dev_attr_fan5_tolerance.dev_attr.attr,
2853 &sensor_dev_attr_pwm5_stop_time.dev_attr.attr,
2854 &sensor_dev_attr_pwm5_step_up_time.dev_attr.attr,
2855 &sensor_dev_attr_pwm5_step_down_time.dev_attr.attr,
2856 &sensor_dev_attr_pwm5_start.dev_attr.attr,
2857 &sensor_dev_attr_pwm5_floor.dev_attr.attr,
2858 &sensor_dev_attr_pwm5_weight_temp_sel.dev_attr.attr,
2859 &sensor_dev_attr_pwm5_weight_temp_step.dev_attr.attr,
2860 &sensor_dev_attr_pwm5_weight_temp_step_tol.dev_attr.attr,
2861 &sensor_dev_attr_pwm5_weight_temp_step_base.dev_attr.attr,
2862 &sensor_dev_attr_pwm5_weight_duty_step.dev_attr.attr,
2863 NULL
2864 },
2865};
2866
2867static const struct attribute_group nct6775_group_pwm[5] = {
2868 { .attrs = nct6775_attributes_pwm[0] },
2869 { .attrs = nct6775_attributes_pwm[1] },
2870 { .attrs = nct6775_attributes_pwm[2] },
2871 { .attrs = nct6775_attributes_pwm[3] },
2872 { .attrs = nct6775_attributes_pwm[4] },
2873};
2874
2875static ssize_t 2419static ssize_t
2876show_auto_pwm(struct device *dev, struct device_attribute *attr, char *buf) 2420show_auto_pwm(struct device *dev, struct device_attribute *attr, char *buf)
2877{ 2421{
@@ -2992,155 +2536,140 @@ store_auto_temp(struct device *dev, struct device_attribute *attr,
2992 return count; 2536 return count;
2993} 2537}
2994 2538
2539static umode_t nct6775_pwm_is_visible(struct kobject *kobj,
2540 struct attribute *attr, int index)
2541{
2542 struct device *dev = container_of(kobj, struct device, kobj);
2543 struct nct6775_data *data = dev_get_drvdata(dev);
2544 int pwm = index / 36; /* pwm index */
2545 int nr = index % 36; /* attribute index */
2546
2547 if (!(data->has_pwm & (1 << pwm)))
2548 return 0;
2549
2550 if (nr == 19 && data->REG_PWM[3] == NULL) /* pwm_max */
2551 return 0;
2552 if (nr == 20 && data->REG_PWM[4] == NULL) /* pwm_step */
2553 return 0;
2554 if (nr == 21 && data->REG_PWM[6] == NULL) /* weight_duty_base */
2555 return 0;
2556
2557 if (nr >= 22 && nr <= 35) { /* auto point */
2558 int api = (nr - 22) / 2; /* auto point index */
2559
2560 if (api > data->auto_pwm_num)
2561 return 0;
2562 }
2563 return attr->mode;
2564}
2565
2566SENSOR_TEMPLATE_2(pwm_stop_time, "pwm%d_stop_time", S_IWUSR | S_IRUGO,
2567 show_fan_time, store_fan_time, 0, 0);
2568SENSOR_TEMPLATE_2(pwm_step_up_time, "pwm%d_step_up_time", S_IWUSR | S_IRUGO,
2569 show_fan_time, store_fan_time, 0, 1);
2570SENSOR_TEMPLATE_2(pwm_step_down_time, "pwm%d_step_down_time", S_IWUSR | S_IRUGO,
2571 show_fan_time, store_fan_time, 0, 2);
2572SENSOR_TEMPLATE_2(pwm_start, "pwm%d_start", S_IWUSR | S_IRUGO, show_pwm,
2573 store_pwm, 0, 1);
2574SENSOR_TEMPLATE_2(pwm_floor, "pwm%d_floor", S_IWUSR | S_IRUGO, show_pwm,
2575 store_pwm, 0, 2);
2576SENSOR_TEMPLATE_2(pwm_temp_tolerance, "pwm%d_temp_tolerance", S_IWUSR | S_IRUGO,
2577 show_temp_tolerance, store_temp_tolerance, 0, 0);
2578SENSOR_TEMPLATE_2(pwm_crit_temp_tolerance, "pwm%d_crit_temp_tolerance",
2579 S_IWUSR | S_IRUGO, show_temp_tolerance, store_temp_tolerance,
2580 0, 1);
2581
2582SENSOR_TEMPLATE_2(pwm_max, "pwm%d_max", S_IWUSR | S_IRUGO, show_pwm, store_pwm,
2583 0, 3);
2584
2585SENSOR_TEMPLATE_2(pwm_step, "pwm%d_step", S_IWUSR | S_IRUGO, show_pwm,
2586 store_pwm, 0, 4);
2587
2588SENSOR_TEMPLATE_2(pwm_auto_point1_pwm, "pwm%d_auto_point1_pwm",
2589 S_IWUSR | S_IRUGO, show_auto_pwm, store_auto_pwm, 0, 0);
2590SENSOR_TEMPLATE_2(pwm_auto_point1_temp, "pwm%d_auto_point1_temp",
2591 S_IWUSR | S_IRUGO, show_auto_temp, store_auto_temp, 0, 0);
2592
2593SENSOR_TEMPLATE_2(pwm_auto_point2_pwm, "pwm%d_auto_point2_pwm",
2594 S_IWUSR | S_IRUGO, show_auto_pwm, store_auto_pwm, 0, 1);
2595SENSOR_TEMPLATE_2(pwm_auto_point2_temp, "pwm%d_auto_point2_temp",
2596 S_IWUSR | S_IRUGO, show_auto_temp, store_auto_temp, 0, 1);
2597
2598SENSOR_TEMPLATE_2(pwm_auto_point3_pwm, "pwm%d_auto_point3_pwm",
2599 S_IWUSR | S_IRUGO, show_auto_pwm, store_auto_pwm, 0, 2);
2600SENSOR_TEMPLATE_2(pwm_auto_point3_temp, "pwm%d_auto_point3_temp",
2601 S_IWUSR | S_IRUGO, show_auto_temp, store_auto_temp, 0, 2);
2602
2603SENSOR_TEMPLATE_2(pwm_auto_point4_pwm, "pwm%d_auto_point4_pwm",
2604 S_IWUSR | S_IRUGO, show_auto_pwm, store_auto_pwm, 0, 3);
2605SENSOR_TEMPLATE_2(pwm_auto_point4_temp, "pwm%d_auto_point4_temp",
2606 S_IWUSR | S_IRUGO, show_auto_temp, store_auto_temp, 0, 3);
2607
2608SENSOR_TEMPLATE_2(pwm_auto_point5_pwm, "pwm%d_auto_point5_pwm",
2609 S_IWUSR | S_IRUGO, show_auto_pwm, store_auto_pwm, 0, 4);
2610SENSOR_TEMPLATE_2(pwm_auto_point5_temp, "pwm%d_auto_point5_temp",
2611 S_IWUSR | S_IRUGO, show_auto_temp, store_auto_temp, 0, 4);
2612
2613SENSOR_TEMPLATE_2(pwm_auto_point6_pwm, "pwm%d_auto_point6_pwm",
2614 S_IWUSR | S_IRUGO, show_auto_pwm, store_auto_pwm, 0, 5);
2615SENSOR_TEMPLATE_2(pwm_auto_point6_temp, "pwm%d_auto_point6_temp",
2616 S_IWUSR | S_IRUGO, show_auto_temp, store_auto_temp, 0, 5);
2617
2618SENSOR_TEMPLATE_2(pwm_auto_point7_pwm, "pwm%d_auto_point7_pwm",
2619 S_IWUSR | S_IRUGO, show_auto_pwm, store_auto_pwm, 0, 6);
2620SENSOR_TEMPLATE_2(pwm_auto_point7_temp, "pwm%d_auto_point7_temp",
2621 S_IWUSR | S_IRUGO, show_auto_temp, store_auto_temp, 0, 6);
2622
2995/* 2623/*
2996 * The number of auto-point trip points is chip dependent. 2624 * nct6775_pwm_is_visible uses the index into the following array
2997 * Need to check support while generating/removing attribute files. 2625 * to determine if attributes should be created or not.
2626 * Any change in order or content must be matched.
2998 */ 2627 */
2999static struct sensor_device_attribute_2 sda_auto_pwm_arrays[] = { 2628static struct sensor_device_template *nct6775_attributes_pwm_template[] = {
3000 SENSOR_ATTR_2(pwm1_auto_point1_pwm, S_IWUSR | S_IRUGO, 2629 &sensor_dev_template_pwm,
3001 show_auto_pwm, store_auto_pwm, 0, 0), 2630 &sensor_dev_template_pwm_mode,
3002 SENSOR_ATTR_2(pwm1_auto_point1_temp, S_IWUSR | S_IRUGO, 2631 &sensor_dev_template_pwm_enable,
3003 show_auto_temp, store_auto_temp, 0, 0), 2632 &sensor_dev_template_pwm_temp_sel,
3004 SENSOR_ATTR_2(pwm1_auto_point2_pwm, S_IWUSR | S_IRUGO, 2633 &sensor_dev_template_pwm_temp_tolerance,
3005 show_auto_pwm, store_auto_pwm, 0, 1), 2634 &sensor_dev_template_pwm_crit_temp_tolerance,
3006 SENSOR_ATTR_2(pwm1_auto_point2_temp, S_IWUSR | S_IRUGO, 2635 &sensor_dev_template_pwm_target_temp,
3007 show_auto_temp, store_auto_temp, 0, 1), 2636 &sensor_dev_template_fan_target,
3008 SENSOR_ATTR_2(pwm1_auto_point3_pwm, S_IWUSR | S_IRUGO, 2637 &sensor_dev_template_fan_tolerance,
3009 show_auto_pwm, store_auto_pwm, 0, 2), 2638 &sensor_dev_template_pwm_stop_time,
3010 SENSOR_ATTR_2(pwm1_auto_point3_temp, S_IWUSR | S_IRUGO, 2639 &sensor_dev_template_pwm_step_up_time,
3011 show_auto_temp, store_auto_temp, 0, 2), 2640 &sensor_dev_template_pwm_step_down_time,
3012 SENSOR_ATTR_2(pwm1_auto_point4_pwm, S_IWUSR | S_IRUGO, 2641 &sensor_dev_template_pwm_start,
3013 show_auto_pwm, store_auto_pwm, 0, 3), 2642 &sensor_dev_template_pwm_floor,
3014 SENSOR_ATTR_2(pwm1_auto_point4_temp, S_IWUSR | S_IRUGO, 2643 &sensor_dev_template_pwm_weight_temp_sel,
3015 show_auto_temp, store_auto_temp, 0, 3), 2644 &sensor_dev_template_pwm_weight_temp_step,
3016 SENSOR_ATTR_2(pwm1_auto_point5_pwm, S_IWUSR | S_IRUGO, 2645 &sensor_dev_template_pwm_weight_temp_step_tol,
3017 show_auto_pwm, store_auto_pwm, 0, 4), 2646 &sensor_dev_template_pwm_weight_temp_step_base,
3018 SENSOR_ATTR_2(pwm1_auto_point5_temp, S_IWUSR | S_IRUGO, 2647 &sensor_dev_template_pwm_weight_duty_step,
3019 show_auto_temp, store_auto_temp, 0, 4), 2648 &sensor_dev_template_pwm_max, /* 19 */
3020 SENSOR_ATTR_2(pwm1_auto_point6_pwm, S_IWUSR | S_IRUGO, 2649 &sensor_dev_template_pwm_step, /* 20 */
3021 show_auto_pwm, store_auto_pwm, 0, 5), 2650 &sensor_dev_template_pwm_weight_duty_base, /* 21 */
3022 SENSOR_ATTR_2(pwm1_auto_point6_temp, S_IWUSR | S_IRUGO, 2651 &sensor_dev_template_pwm_auto_point1_pwm, /* 22 */
3023 show_auto_temp, store_auto_temp, 0, 5), 2652 &sensor_dev_template_pwm_auto_point1_temp,
3024 SENSOR_ATTR_2(pwm1_auto_point7_pwm, S_IWUSR | S_IRUGO, 2653 &sensor_dev_template_pwm_auto_point2_pwm,
3025 show_auto_pwm, store_auto_pwm, 0, 6), 2654 &sensor_dev_template_pwm_auto_point2_temp,
3026 SENSOR_ATTR_2(pwm1_auto_point7_temp, S_IWUSR | S_IRUGO, 2655 &sensor_dev_template_pwm_auto_point3_pwm,
3027 show_auto_temp, store_auto_temp, 0, 6), 2656 &sensor_dev_template_pwm_auto_point3_temp,
3028 2657 &sensor_dev_template_pwm_auto_point4_pwm,
3029 SENSOR_ATTR_2(pwm2_auto_point1_pwm, S_IWUSR | S_IRUGO, 2658 &sensor_dev_template_pwm_auto_point4_temp,
3030 show_auto_pwm, store_auto_pwm, 1, 0), 2659 &sensor_dev_template_pwm_auto_point5_pwm,
3031 SENSOR_ATTR_2(pwm2_auto_point1_temp, S_IWUSR | S_IRUGO, 2660 &sensor_dev_template_pwm_auto_point5_temp,
3032 show_auto_temp, store_auto_temp, 1, 0), 2661 &sensor_dev_template_pwm_auto_point6_pwm,
3033 SENSOR_ATTR_2(pwm2_auto_point2_pwm, S_IWUSR | S_IRUGO, 2662 &sensor_dev_template_pwm_auto_point6_temp,
3034 show_auto_pwm, store_auto_pwm, 1, 1), 2663 &sensor_dev_template_pwm_auto_point7_pwm,
3035 SENSOR_ATTR_2(pwm2_auto_point2_temp, S_IWUSR | S_IRUGO, 2664 &sensor_dev_template_pwm_auto_point7_temp, /* 35 */
3036 show_auto_temp, store_auto_temp, 1, 1), 2665
3037 SENSOR_ATTR_2(pwm2_auto_point3_pwm, S_IWUSR | S_IRUGO, 2666 NULL
3038 show_auto_pwm, store_auto_pwm, 1, 2), 2667};
3039 SENSOR_ATTR_2(pwm2_auto_point3_temp, S_IWUSR | S_IRUGO, 2668
3040 show_auto_temp, store_auto_temp, 1, 2), 2669static struct sensor_template_group nct6775_pwm_template_group = {
3041 SENSOR_ATTR_2(pwm2_auto_point4_pwm, S_IWUSR | S_IRUGO, 2670 .templates = nct6775_attributes_pwm_template,
3042 show_auto_pwm, store_auto_pwm, 1, 3), 2671 .is_visible = nct6775_pwm_is_visible,
3043 SENSOR_ATTR_2(pwm2_auto_point4_temp, S_IWUSR | S_IRUGO, 2672 .base = 1,
3044 show_auto_temp, store_auto_temp, 1, 3),
3045 SENSOR_ATTR_2(pwm2_auto_point5_pwm, S_IWUSR | S_IRUGO,
3046 show_auto_pwm, store_auto_pwm, 1, 4),
3047 SENSOR_ATTR_2(pwm2_auto_point5_temp, S_IWUSR | S_IRUGO,
3048 show_auto_temp, store_auto_temp, 1, 4),
3049 SENSOR_ATTR_2(pwm2_auto_point6_pwm, S_IWUSR | S_IRUGO,
3050 show_auto_pwm, store_auto_pwm, 1, 5),
3051 SENSOR_ATTR_2(pwm2_auto_point6_temp, S_IWUSR | S_IRUGO,
3052 show_auto_temp, store_auto_temp, 1, 5),
3053 SENSOR_ATTR_2(pwm2_auto_point7_pwm, S_IWUSR | S_IRUGO,
3054 show_auto_pwm, store_auto_pwm, 1, 6),
3055 SENSOR_ATTR_2(pwm2_auto_point7_temp, S_IWUSR | S_IRUGO,
3056 show_auto_temp, store_auto_temp, 1, 6),
3057
3058 SENSOR_ATTR_2(pwm3_auto_point1_pwm, S_IWUSR | S_IRUGO,
3059 show_auto_pwm, store_auto_pwm, 2, 0),
3060 SENSOR_ATTR_2(pwm3_auto_point1_temp, S_IWUSR | S_IRUGO,
3061 show_auto_temp, store_auto_temp, 2, 0),
3062 SENSOR_ATTR_2(pwm3_auto_point2_pwm, S_IWUSR | S_IRUGO,
3063 show_auto_pwm, store_auto_pwm, 2, 1),
3064 SENSOR_ATTR_2(pwm3_auto_point2_temp, S_IWUSR | S_IRUGO,
3065 show_auto_temp, store_auto_temp, 2, 1),
3066 SENSOR_ATTR_2(pwm3_auto_point3_pwm, S_IWUSR | S_IRUGO,
3067 show_auto_pwm, store_auto_pwm, 2, 2),
3068 SENSOR_ATTR_2(pwm3_auto_point3_temp, S_IWUSR | S_IRUGO,
3069 show_auto_temp, store_auto_temp, 2, 2),
3070 SENSOR_ATTR_2(pwm3_auto_point4_pwm, S_IWUSR | S_IRUGO,
3071 show_auto_pwm, store_auto_pwm, 2, 3),
3072 SENSOR_ATTR_2(pwm3_auto_point4_temp, S_IWUSR | S_IRUGO,
3073 show_auto_temp, store_auto_temp, 2, 3),
3074 SENSOR_ATTR_2(pwm3_auto_point5_pwm, S_IWUSR | S_IRUGO,
3075 show_auto_pwm, store_auto_pwm, 2, 4),
3076 SENSOR_ATTR_2(pwm3_auto_point5_temp, S_IWUSR | S_IRUGO,
3077 show_auto_temp, store_auto_temp, 2, 4),
3078 SENSOR_ATTR_2(pwm3_auto_point6_pwm, S_IWUSR | S_IRUGO,
3079 show_auto_pwm, store_auto_pwm, 2, 5),
3080 SENSOR_ATTR_2(pwm3_auto_point6_temp, S_IWUSR | S_IRUGO,
3081 show_auto_temp, store_auto_temp, 2, 5),
3082 SENSOR_ATTR_2(pwm3_auto_point7_pwm, S_IWUSR | S_IRUGO,
3083 show_auto_pwm, store_auto_pwm, 2, 6),
3084 SENSOR_ATTR_2(pwm3_auto_point7_temp, S_IWUSR | S_IRUGO,
3085 show_auto_temp, store_auto_temp, 2, 6),
3086
3087 SENSOR_ATTR_2(pwm4_auto_point1_pwm, S_IWUSR | S_IRUGO,
3088 show_auto_pwm, store_auto_pwm, 3, 0),
3089 SENSOR_ATTR_2(pwm4_auto_point1_temp, S_IWUSR | S_IRUGO,
3090 show_auto_temp, store_auto_temp, 3, 0),
3091 SENSOR_ATTR_2(pwm4_auto_point2_pwm, S_IWUSR | S_IRUGO,
3092 show_auto_pwm, store_auto_pwm, 3, 1),
3093 SENSOR_ATTR_2(pwm4_auto_point2_temp, S_IWUSR | S_IRUGO,
3094 show_auto_temp, store_auto_temp, 3, 1),
3095 SENSOR_ATTR_2(pwm4_auto_point3_pwm, S_IWUSR | S_IRUGO,
3096 show_auto_pwm, store_auto_pwm, 3, 2),
3097 SENSOR_ATTR_2(pwm4_auto_point3_temp, S_IWUSR | S_IRUGO,
3098 show_auto_temp, store_auto_temp, 3, 2),
3099 SENSOR_ATTR_2(pwm4_auto_point4_pwm, S_IWUSR | S_IRUGO,
3100 show_auto_pwm, store_auto_pwm, 3, 3),
3101 SENSOR_ATTR_2(pwm4_auto_point4_temp, S_IWUSR | S_IRUGO,
3102 show_auto_temp, store_auto_temp, 3, 3),
3103 SENSOR_ATTR_2(pwm4_auto_point5_pwm, S_IWUSR | S_IRUGO,
3104 show_auto_pwm, store_auto_pwm, 3, 4),
3105 SENSOR_ATTR_2(pwm4_auto_point5_temp, S_IWUSR | S_IRUGO,
3106 show_auto_temp, store_auto_temp, 3, 4),
3107 SENSOR_ATTR_2(pwm4_auto_point6_pwm, S_IWUSR | S_IRUGO,
3108 show_auto_pwm, store_auto_pwm, 3, 5),
3109 SENSOR_ATTR_2(pwm4_auto_point6_temp, S_IWUSR | S_IRUGO,
3110 show_auto_temp, store_auto_temp, 3, 5),
3111 SENSOR_ATTR_2(pwm4_auto_point7_pwm, S_IWUSR | S_IRUGO,
3112 show_auto_pwm, store_auto_pwm, 3, 6),
3113 SENSOR_ATTR_2(pwm4_auto_point7_temp, S_IWUSR | S_IRUGO,
3114 show_auto_temp, store_auto_temp, 3, 6),
3115
3116 SENSOR_ATTR_2(pwm5_auto_point1_pwm, S_IWUSR | S_IRUGO,
3117 show_auto_pwm, store_auto_pwm, 4, 0),
3118 SENSOR_ATTR_2(pwm5_auto_point1_temp, S_IWUSR | S_IRUGO,
3119 show_auto_temp, store_auto_temp, 4, 0),
3120 SENSOR_ATTR_2(pwm5_auto_point2_pwm, S_IWUSR | S_IRUGO,
3121 show_auto_pwm, store_auto_pwm, 4, 1),
3122 SENSOR_ATTR_2(pwm5_auto_point2_temp, S_IWUSR | S_IRUGO,
3123 show_auto_temp, store_auto_temp, 4, 1),
3124 SENSOR_ATTR_2(pwm5_auto_point3_pwm, S_IWUSR | S_IRUGO,
3125 show_auto_pwm, store_auto_pwm, 4, 2),
3126 SENSOR_ATTR_2(pwm5_auto_point3_temp, S_IWUSR | S_IRUGO,
3127 show_auto_temp, store_auto_temp, 4, 2),
3128 SENSOR_ATTR_2(pwm5_auto_point4_pwm, S_IWUSR | S_IRUGO,
3129 show_auto_pwm, store_auto_pwm, 4, 3),
3130 SENSOR_ATTR_2(pwm5_auto_point4_temp, S_IWUSR | S_IRUGO,
3131 show_auto_temp, store_auto_temp, 4, 3),
3132 SENSOR_ATTR_2(pwm5_auto_point5_pwm, S_IWUSR | S_IRUGO,
3133 show_auto_pwm, store_auto_pwm, 4, 4),
3134 SENSOR_ATTR_2(pwm5_auto_point5_temp, S_IWUSR | S_IRUGO,
3135 show_auto_temp, store_auto_temp, 4, 4),
3136 SENSOR_ATTR_2(pwm5_auto_point6_pwm, S_IWUSR | S_IRUGO,
3137 show_auto_pwm, store_auto_pwm, 4, 5),
3138 SENSOR_ATTR_2(pwm5_auto_point6_temp, S_IWUSR | S_IRUGO,
3139 show_auto_temp, store_auto_temp, 4, 5),
3140 SENSOR_ATTR_2(pwm5_auto_point7_pwm, S_IWUSR | S_IRUGO,
3141 show_auto_pwm, store_auto_pwm, 4, 6),
3142 SENSOR_ATTR_2(pwm5_auto_point7_temp, S_IWUSR | S_IRUGO,
3143 show_auto_temp, store_auto_temp, 4, 6),
3144}; 2673};
3145 2674
3146static ssize_t 2675static ssize_t
@@ -3195,71 +2724,65 @@ error:
3195 return count; 2724 return count;
3196} 2725}
3197 2726
3198static struct sensor_device_attribute sda_caseopen[] = { 2727static SENSOR_DEVICE_ATTR(intrusion0_alarm, S_IWUSR | S_IRUGO, show_alarm,
3199 SENSOR_ATTR(intrusion0_alarm, S_IWUSR | S_IRUGO, show_alarm, 2728 clear_caseopen, INTRUSION_ALARM_BASE);
3200 clear_caseopen, INTRUSION_ALARM_BASE), 2729static SENSOR_DEVICE_ATTR(intrusion1_alarm, S_IWUSR | S_IRUGO, show_alarm,
3201 SENSOR_ATTR(intrusion1_alarm, S_IWUSR | S_IRUGO, show_alarm, 2730 clear_caseopen, INTRUSION_ALARM_BASE + 1);
3202 clear_caseopen, INTRUSION_ALARM_BASE + 1),
3203};
3204 2731
3205/* 2732static umode_t nct6775_other_is_visible(struct kobject *kobj,
3206 * Driver and device management 2733 struct attribute *attr, int index)
3207 */
3208
3209static void nct6775_device_remove_files(struct device *dev)
3210{ 2734{
3211 /* 2735 struct device *dev = container_of(kobj, struct device, kobj);
3212 * some entries in the following arrays may not have been used in
3213 * device_create_file(), but device_remove_file() will ignore them
3214 */
3215 int i;
3216 struct nct6775_data *data = dev_get_drvdata(dev); 2736 struct nct6775_data *data = dev_get_drvdata(dev);
3217 2737
3218 for (i = 0; i < data->pwm_num; i++) 2738 if (index == 1 && !data->have_vid)
3219 sysfs_remove_group(&dev->kobj, &nct6775_group_pwm[i]); 2739 return 0;
3220 2740
3221 for (i = 0; i < ARRAY_SIZE(sda_pwm_max); i++) 2741 if (index == 2 || index == 3) {
3222 device_remove_file(dev, &sda_pwm_max[i].dev_attr); 2742 if (data->ALARM_BITS[INTRUSION_ALARM_BASE + index - 2] < 0)
2743 return 0;
2744 }
3223 2745
3224 for (i = 0; i < ARRAY_SIZE(sda_pwm_step); i++) 2746 return attr->mode;
3225 device_remove_file(dev, &sda_pwm_step[i].dev_attr); 2747}
3226 2748
3227 for (i = 0; i < ARRAY_SIZE(sda_weight_duty_base); i++) 2749/*
3228 device_remove_file(dev, &sda_weight_duty_base[i].dev_attr); 2750 * nct6775_other_is_visible uses the index into the following array
2751 * to determine if attributes should be created or not.
2752 * Any change in order or content must be matched.
2753 */
2754static struct attribute *nct6775_attributes_other[] = {
2755 &dev_attr_name.attr,
2756 &dev_attr_cpu0_vid.attr, /* 1 */
2757 &sensor_dev_attr_intrusion0_alarm.dev_attr.attr, /* 2 */
2758 &sensor_dev_attr_intrusion1_alarm.dev_attr.attr, /* 3 */
3229 2759
3230 for (i = 0; i < ARRAY_SIZE(sda_auto_pwm_arrays); i++) 2760 NULL
3231 device_remove_file(dev, &sda_auto_pwm_arrays[i].dev_attr); 2761};
3232 2762
3233 for (i = 0; i < data->in_num; i++) 2763static const struct attribute_group nct6775_group_other = {
3234 sysfs_remove_group(&dev->kobj, &nct6775_group_in[i]); 2764 .attrs = nct6775_attributes_other,
2765 .is_visible = nct6775_other_is_visible,
2766};
3235 2767
3236 for (i = 0; i < 5; i++) { 2768/*
3237 device_remove_file(dev, &sda_fan_input[i].dev_attr); 2769 * Driver and device management
3238 device_remove_file(dev, &sda_fan_alarm[i].dev_attr); 2770 */
3239 device_remove_file(dev, &sda_fan_div[i].dev_attr);
3240 device_remove_file(dev, &sda_fan_min[i].dev_attr);
3241 device_remove_file(dev, &sda_fan_pulses[i].dev_attr);
3242 }
3243 for (i = 0; i < NUM_TEMP; i++) {
3244 if (!(data->have_temp & (1 << i)))
3245 continue;
3246 device_remove_file(dev, &sda_temp_input[i].dev_attr);
3247 device_remove_file(dev, &sda_temp_label[i].dev_attr);
3248 device_remove_file(dev, &sda_temp_max[i].dev_attr);
3249 device_remove_file(dev, &sda_temp_max_hyst[i].dev_attr);
3250 device_remove_file(dev, &sda_temp_crit[i].dev_attr);
3251 device_remove_file(dev, &sda_temp_alarm[i].dev_attr);
3252 if (!(data->have_temp_fixed & (1 << i)))
3253 continue;
3254 device_remove_file(dev, &sda_temp_type[i].dev_attr);
3255 device_remove_file(dev, &sda_temp_offset[i].dev_attr);
3256 }
3257 2771
3258 device_remove_file(dev, &sda_caseopen[0].dev_attr); 2772static void nct6775_device_remove_files(struct device *dev)
3259 device_remove_file(dev, &sda_caseopen[1].dev_attr); 2773{
2774 struct nct6775_data *data = dev_get_drvdata(dev);
3260 2775
3261 device_remove_file(dev, &dev_attr_name); 2776 if (data->group_pwm)
3262 device_remove_file(dev, &dev_attr_cpu0_vid); 2777 sysfs_remove_group(&dev->kobj, data->group_pwm);
2778 if (data->group_in)
2779 sysfs_remove_group(&dev->kobj, data->group_in);
2780 if (data->group_fan)
2781 sysfs_remove_group(&dev->kobj, data->group_fan);
2782 if (data->group_temp)
2783 sysfs_remove_group(&dev->kobj, data->group_temp);
2784
2785 sysfs_remove_group(&dev->kobj, &nct6775_group_other);
3263} 2786}
3264 2787
3265/* Get the monitoring functions started */ 2788/* Get the monitoring functions started */
@@ -3304,18 +2827,13 @@ static inline void nct6775_init_device(struct nct6775_data *data)
3304 } 2827 }
3305} 2828}
3306 2829
3307static int 2830static void
3308nct6775_check_fan_inputs(const struct nct6775_sio_data *sio_data, 2831nct6775_check_fan_inputs(const struct nct6775_sio_data *sio_data,
3309 struct nct6775_data *data) 2832 struct nct6775_data *data)
3310{ 2833{
3311 int regval; 2834 int regval;
3312 bool fan3pin, fan3min, fan4pin, fan4min, fan5pin; 2835 bool fan3pin, fan3min, fan4pin, fan4min, fan5pin;
3313 bool pwm3pin, pwm4pin, pwm5pin; 2836 bool pwm3pin, pwm4pin, pwm5pin;
3314 int ret;
3315
3316 ret = superio_enter(sio_data->sioreg);
3317 if (ret)
3318 return ret;
3319 2837
3320 /* fan4 and fan5 share some pins with the GPIO and serial flash */ 2838 /* fan4 and fan5 share some pins with the GPIO and serial flash */
3321 if (data->kind == nct6775) { 2839 if (data->kind == nct6775) {
@@ -3372,8 +2890,6 @@ nct6775_check_fan_inputs(const struct nct6775_sio_data *sio_data,
3372 fan4min = fan4pin; 2890 fan4min = fan4pin;
3373 } 2891 }
3374 2892
3375 superio_exit(sio_data->sioreg);
3376
3377 data->has_fan = data->has_fan_min = 0x03; /* fan1 and fan2 */ 2893 data->has_fan = data->has_fan_min = 0x03; /* fan1 and fan2 */
3378 data->has_fan |= fan3pin << 2; 2894 data->has_fan |= fan3pin << 2;
3379 data->has_fan_min |= fan3min << 2; 2895 data->has_fan_min |= fan3min << 2;
@@ -3382,8 +2898,6 @@ nct6775_check_fan_inputs(const struct nct6775_sio_data *sio_data,
3382 data->has_fan_min |= (fan4min << 3) | (fan5pin << 4); 2898 data->has_fan_min |= (fan4min << 3) | (fan5pin << 4);
3383 2899
3384 data->has_pwm = 0x03 | (pwm3pin << 2) | (pwm4pin << 3) | (pwm5pin << 4); 2900 data->has_pwm = 0x03 | (pwm3pin << 2) | (pwm4pin << 3) | (pwm5pin << 4);
3385
3386 return 0;
3387} 2901}
3388 2902
3389static void add_temp_sensors(struct nct6775_data *data, const u16 *regp, 2903static void add_temp_sensors(struct nct6775_data *data, const u16 *regp,
@@ -3423,8 +2937,8 @@ static int nct6775_probe(struct platform_device *pdev)
3423 const u16 *reg_temp, *reg_temp_over, *reg_temp_hyst, *reg_temp_config; 2937 const u16 *reg_temp, *reg_temp_over, *reg_temp_hyst, *reg_temp_config;
3424 const u16 *reg_temp_alternate, *reg_temp_crit; 2938 const u16 *reg_temp_alternate, *reg_temp_crit;
3425 int num_reg_temp; 2939 int num_reg_temp;
3426 bool have_vid = false;
3427 u8 cr2a; 2940 u8 cr2a;
2941 struct attribute_group *group;
3428 2942
3429 res = platform_get_resource(pdev, IORESOURCE_IO, 0); 2943 res = platform_get_resource(pdev, IORESOURCE_IO, 0);
3430 if (!devm_request_region(&pdev->dev, res->start, IOREGION_LENGTH, 2944 if (!devm_request_region(&pdev->dev, res->start, IOREGION_LENGTH,
@@ -3767,10 +3281,10 @@ static int nct6775_probe(struct platform_device *pdev)
3767 cr2a = superio_inb(sio_data->sioreg, 0x2a); 3281 cr2a = superio_inb(sio_data->sioreg, 0x2a);
3768 switch (data->kind) { 3282 switch (data->kind) {
3769 case nct6775: 3283 case nct6775:
3770 have_vid = (cr2a & 0x40); 3284 data->have_vid = (cr2a & 0x40);
3771 break; 3285 break;
3772 case nct6776: 3286 case nct6776:
3773 have_vid = (cr2a & 0x60) == 0x40; 3287 data->have_vid = (cr2a & 0x60) == 0x40;
3774 break; 3288 break;
3775 case nct6779: 3289 case nct6779:
3776 break; 3290 break;
@@ -3780,7 +3294,7 @@ static int nct6775_probe(struct platform_device *pdev)
3780 * Read VID value 3294 * Read VID value
3781 * We can get the VID input values directly at logical device D 0xe3. 3295 * We can get the VID input values directly at logical device D 0xe3.
3782 */ 3296 */
3783 if (have_vid) { 3297 if (data->have_vid) {
3784 superio_select(sio_data->sioreg, NCT6775_LD_VID); 3298 superio_select(sio_data->sioreg, NCT6775_LD_VID);
3785 data->vid = superio_inb(sio_data->sioreg, 0xe3); 3299 data->vid = superio_inb(sio_data->sioreg, 0xe3);
3786 data->vrm = vid_which_vrm(); 3300 data->vrm = vid_which_vrm();
@@ -3807,157 +3321,47 @@ static int nct6775_probe(struct platform_device *pdev)
3807 data->name); 3321 data->name);
3808 } 3322 }
3809 3323
3810 superio_exit(sio_data->sioreg); 3324 nct6775_check_fan_inputs(sio_data, data);
3811
3812 if (have_vid) {
3813 err = device_create_file(dev, &dev_attr_cpu0_vid);
3814 if (err)
3815 return err;
3816 }
3817 3325
3818 err = nct6775_check_fan_inputs(sio_data, data); 3326 superio_exit(sio_data->sioreg);
3819 if (err)
3820 goto exit_remove;
3821 3327
3822 /* Read fan clock dividers immediately */ 3328 /* Read fan clock dividers immediately */
3823 nct6775_init_fan_common(dev, data); 3329 nct6775_init_fan_common(dev, data);
3824 3330
3825 /* Register sysfs hooks */ 3331 /* Register sysfs hooks */
3826 for (i = 0; i < data->pwm_num; i++) { 3332 group = nct6775_create_attr_group(dev, &nct6775_pwm_template_group,
3827 if (!(data->has_pwm & (1 << i))) 3333 data->pwm_num);
3828 continue; 3334 if (IS_ERR(group)) {
3829 3335 err = PTR_ERR(group);
3830 err = sysfs_create_group(&dev->kobj, &nct6775_group_pwm[i]); 3336 goto exit_remove;
3831 if (err)
3832 goto exit_remove;
3833
3834 if (data->REG_PWM[3]) {
3835 err = device_create_file(dev,
3836 &sda_pwm_max[i].dev_attr);
3837 if (err)
3838 goto exit_remove;
3839 }
3840 if (data->REG_PWM[4]) {
3841 err = device_create_file(dev,
3842 &sda_pwm_step[i].dev_attr);
3843 if (err)
3844 goto exit_remove;
3845 }
3846 if (data->REG_PWM[6]) {
3847 err = device_create_file(dev,
3848 &sda_weight_duty_base[i].dev_attr);
3849 if (err)
3850 goto exit_remove;
3851 }
3852 }
3853 for (i = 0; i < ARRAY_SIZE(sda_auto_pwm_arrays); i++) {
3854 struct sensor_device_attribute_2 *attr =
3855 &sda_auto_pwm_arrays[i];
3856
3857 if (!(data->has_pwm & (1 << attr->nr)))
3858 continue;
3859 if (attr->index > data->auto_pwm_num)
3860 continue;
3861 err = device_create_file(dev, &attr->dev_attr);
3862 if (err)
3863 goto exit_remove;
3864 }
3865
3866 for (i = 0; i < data->in_num; i++) {
3867 if (!(data->have_in & (1 << i)))
3868 continue;
3869 err = sysfs_create_group(&dev->kobj, &nct6775_group_in[i]);
3870 if (err)
3871 goto exit_remove;
3872 } 3337 }
3338 data->group_pwm = group;
3873 3339
3874 for (i = 0; i < 5; i++) { 3340 group = nct6775_create_attr_group(dev, &nct6775_in_template_group,
3875 if (data->has_fan & (1 << i)) { 3341 fls(data->have_in));
3876 err = device_create_file(dev, 3342 if (IS_ERR(group)) {
3877 &sda_fan_input[i].dev_attr); 3343 err = PTR_ERR(group);
3878 if (err) 3344 goto exit_remove;
3879 goto exit_remove;
3880 if (data->ALARM_BITS[FAN_ALARM_BASE + i] >= 0) {
3881 err = device_create_file(dev,
3882 &sda_fan_alarm[i].dev_attr);
3883 if (err)
3884 goto exit_remove;
3885 }
3886 if (data->kind != nct6776 &&
3887 data->kind != nct6779) {
3888 err = device_create_file(dev,
3889 &sda_fan_div[i].dev_attr);
3890 if (err)
3891 goto exit_remove;
3892 }
3893 if (data->has_fan_min & (1 << i)) {
3894 err = device_create_file(dev,
3895 &sda_fan_min[i].dev_attr);
3896 if (err)
3897 goto exit_remove;
3898 }
3899 err = device_create_file(dev,
3900 &sda_fan_pulses[i].dev_attr);
3901 if (err)
3902 goto exit_remove;
3903 }
3904 } 3345 }
3346 data->group_in = group;
3905 3347
3906 for (i = 0; i < NUM_TEMP; i++) { 3348 group = nct6775_create_attr_group(dev, &nct6775_fan_template_group,
3907 if (!(data->have_temp & (1 << i))) 3349 fls(data->has_fan));
3908 continue; 3350 if (IS_ERR(group)) {
3909 err = device_create_file(dev, &sda_temp_input[i].dev_attr); 3351 err = PTR_ERR(group);
3910 if (err) 3352 goto exit_remove;
3911 goto exit_remove;
3912 if (data->temp_label) {
3913 err = device_create_file(dev,
3914 &sda_temp_label[i].dev_attr);
3915 if (err)
3916 goto exit_remove;
3917 }
3918 if (data->reg_temp[1][i]) {
3919 err = device_create_file(dev,
3920 &sda_temp_max[i].dev_attr);
3921 if (err)
3922 goto exit_remove;
3923 }
3924 if (data->reg_temp[2][i]) {
3925 err = device_create_file(dev,
3926 &sda_temp_max_hyst[i].dev_attr);
3927 if (err)
3928 goto exit_remove;
3929 }
3930 if (data->reg_temp[3][i]) {
3931 err = device_create_file(dev,
3932 &sda_temp_crit[i].dev_attr);
3933 if (err)
3934 goto exit_remove;
3935 }
3936 if (find_temp_source(data, i, data->num_temp_alarms) >= 0) {
3937 err = device_create_file(dev,
3938 &sda_temp_alarm[i].dev_attr);
3939 if (err)
3940 goto exit_remove;
3941 }
3942 if (!(data->have_temp_fixed & (1 << i)))
3943 continue;
3944 err = device_create_file(dev, &sda_temp_type[i].dev_attr);
3945 if (err)
3946 goto exit_remove;
3947 err = device_create_file(dev, &sda_temp_offset[i].dev_attr);
3948 if (err)
3949 goto exit_remove;
3950 } 3353 }
3354 data->group_fan = group;
3951 3355
3952 for (i = 0; i < ARRAY_SIZE(sda_caseopen); i++) { 3356 group = nct6775_create_attr_group(dev, &nct6775_temp_template_group,
3953 if (data->ALARM_BITS[INTRUSION_ALARM_BASE + i] < 0) 3357 fls(data->have_temp));
3954 continue; 3358 if (IS_ERR(group)) {
3955 err = device_create_file(dev, &sda_caseopen[i].dev_attr); 3359 err = PTR_ERR(group);
3956 if (err) 3360 goto exit_remove;
3957 goto exit_remove;
3958 } 3361 }
3362 data->group_temp = group;
3959 3363
3960 err = device_create_file(dev, &dev_attr_name); 3364 err = sysfs_create_group(&dev->kobj, &nct6775_group_other);
3961 if (err) 3365 if (err)
3962 goto exit_remove; 3366 goto exit_remove;
3963 3367