diff options
author | Jean Delvare <khali@linux-fr.org> | 2006-01-09 17:29:11 -0500 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2006-03-23 17:21:49 -0500 |
commit | 2488a39d233a758d41ab7de70a220bc956f3c96c (patch) | |
tree | ad13b0f0e4934215a4378f63175dfc98e44e3061 | |
parent | dedc6a7803d9c9795b504ffd8530a4ba7b3fd9ed (diff) |
[PATCH] hwmon: Use attribute arrays in f71805f
Convert the f71805f driver to use arrays of attributes. This shrinks the
compiled module from 12.0 kB to 9.6 kB. We certainly should do the same
for as many hardware monitoring drivers as possible.
This, together with a nice chip design by Fintek, makes this driver
very small, both in terms of number of lines of code and memory
consumption.
Signed-off-by: Jean Delvare <khali@linux-fr.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
-rw-r--r-- | drivers/hwmon/f71805f.c | 218 |
1 files changed, 103 insertions, 115 deletions
diff --git a/drivers/hwmon/f71805f.c b/drivers/hwmon/f71805f.c index e029e0a94ecc..8e810f05d0ae 100644 --- a/drivers/hwmon/f71805f.c +++ b/drivers/hwmon/f71805f.c | |||
@@ -384,10 +384,6 @@ static ssize_t set_in0_min(struct device *dev, struct device_attribute | |||
384 | return count; | 384 | return count; |
385 | } | 385 | } |
386 | 386 | ||
387 | static DEVICE_ATTR(in0_input, S_IRUGO, show_in0, NULL); | ||
388 | static DEVICE_ATTR(in0_max, S_IRUGO| S_IWUSR, show_in0_max, set_in0_max); | ||
389 | static DEVICE_ATTR(in0_min, S_IRUGO| S_IWUSR, show_in0_min, set_in0_min); | ||
390 | |||
391 | static ssize_t show_in(struct device *dev, struct device_attribute *devattr, | 387 | static ssize_t show_in(struct device *dev, struct device_attribute *devattr, |
392 | char *buf) | 388 | char *buf) |
393 | { | 389 | { |
@@ -450,23 +446,6 @@ static ssize_t set_in_min(struct device *dev, struct device_attribute | |||
450 | return count; | 446 | return count; |
451 | } | 447 | } |
452 | 448 | ||
453 | #define sysfs_in(offset) \ | ||
454 | static SENSOR_DEVICE_ATTR(in##offset##_input, S_IRUGO, \ | ||
455 | show_in, NULL, offset); \ | ||
456 | static SENSOR_DEVICE_ATTR(in##offset##_max, S_IRUGO | S_IWUSR, \ | ||
457 | show_in_max, set_in_max, offset); \ | ||
458 | static SENSOR_DEVICE_ATTR(in##offset##_min, S_IRUGO | S_IWUSR, \ | ||
459 | show_in_min, set_in_min, offset) | ||
460 | |||
461 | sysfs_in(1); | ||
462 | sysfs_in(2); | ||
463 | sysfs_in(3); | ||
464 | sysfs_in(4); | ||
465 | sysfs_in(5); | ||
466 | sysfs_in(6); | ||
467 | sysfs_in(7); | ||
468 | sysfs_in(8); | ||
469 | |||
470 | static ssize_t show_fan(struct device *dev, struct device_attribute *devattr, | 449 | static ssize_t show_fan(struct device *dev, struct device_attribute *devattr, |
471 | char *buf) | 450 | char *buf) |
472 | { | 451 | { |
@@ -503,16 +482,6 @@ static ssize_t set_fan_min(struct device *dev, struct device_attribute | |||
503 | return count; | 482 | return count; |
504 | } | 483 | } |
505 | 484 | ||
506 | #define sysfs_fan(offset) \ | ||
507 | static SENSOR_DEVICE_ATTR(fan##offset##_input, S_IRUGO, \ | ||
508 | show_fan, NULL, offset - 1); \ | ||
509 | static SENSOR_DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \ | ||
510 | show_fan_min, set_fan_min, offset - 1) | ||
511 | |||
512 | sysfs_fan(1); | ||
513 | sysfs_fan(2); | ||
514 | sysfs_fan(3); | ||
515 | |||
516 | static ssize_t show_temp(struct device *dev, struct device_attribute *devattr, | 485 | static ssize_t show_temp(struct device *dev, struct device_attribute *devattr, |
517 | char *buf) | 486 | char *buf) |
518 | { | 487 | { |
@@ -586,20 +555,6 @@ static ssize_t set_temp_hyst(struct device *dev, struct device_attribute | |||
586 | return count; | 555 | return count; |
587 | } | 556 | } |
588 | 557 | ||
589 | #define sysfs_temp(offset) \ | ||
590 | static SENSOR_DEVICE_ATTR(temp##offset##_input, S_IRUGO, \ | ||
591 | show_temp, NULL, offset - 1); \ | ||
592 | static SENSOR_DEVICE_ATTR(temp##offset##_max, S_IRUGO | S_IWUSR, \ | ||
593 | show_temp_max, set_temp_max, offset - 1); \ | ||
594 | static SENSOR_DEVICE_ATTR(temp##offset##_max_hyst, S_IRUGO | S_IWUSR, \ | ||
595 | show_temp_hyst, set_temp_hyst, offset - 1); \ | ||
596 | static SENSOR_DEVICE_ATTR(temp##offset##_type, S_IRUGO, \ | ||
597 | show_temp_type, NULL, offset - 1) | ||
598 | |||
599 | sysfs_temp(1); | ||
600 | sysfs_temp(2); | ||
601 | sysfs_temp(3); | ||
602 | |||
603 | static ssize_t show_alarms_in(struct device *dev, struct device_attribute | 558 | static ssize_t show_alarms_in(struct device *dev, struct device_attribute |
604 | *devattr, char *buf) | 559 | *devattr, char *buf) |
605 | { | 560 | { |
@@ -625,10 +580,6 @@ static ssize_t show_alarms_temp(struct device *dev, struct device_attribute | |||
625 | return sprintf(buf, "%d\n", (data->alarms[1] >> 3) & 0x07); | 580 | return sprintf(buf, "%d\n", (data->alarms[1] >> 3) & 0x07); |
626 | } | 581 | } |
627 | 582 | ||
628 | static DEVICE_ATTR(alarms_in, S_IRUGO, show_alarms_in, NULL); | ||
629 | static DEVICE_ATTR(alarms_fan, S_IRUGO, show_alarms_fan, NULL); | ||
630 | static DEVICE_ATTR(alarms_temp, S_IRUGO, show_alarms_temp, NULL); | ||
631 | |||
632 | static ssize_t show_name(struct device *dev, struct device_attribute | 583 | static ssize_t show_name(struct device *dev, struct device_attribute |
633 | *devattr, char *buf) | 584 | *devattr, char *buf) |
634 | { | 585 | { |
@@ -637,7 +588,89 @@ static ssize_t show_name(struct device *dev, struct device_attribute | |||
637 | return sprintf(buf, "%s\n", data->name); | 588 | return sprintf(buf, "%s\n", data->name); |
638 | } | 589 | } |
639 | 590 | ||
640 | static DEVICE_ATTR(name, S_IRUGO, show_name, NULL); | 591 | static struct device_attribute f71805f_dev_attr[] = { |
592 | __ATTR(in0_input, S_IRUGO, show_in0, NULL), | ||
593 | __ATTR(in0_max, S_IRUGO| S_IWUSR, show_in0_max, set_in0_max), | ||
594 | __ATTR(in0_min, S_IRUGO| S_IWUSR, show_in0_min, set_in0_min), | ||
595 | __ATTR(alarms_in, S_IRUGO, show_alarms_in, NULL), | ||
596 | __ATTR(alarms_fan, S_IRUGO, show_alarms_fan, NULL), | ||
597 | __ATTR(alarms_temp, S_IRUGO, show_alarms_temp, NULL), | ||
598 | __ATTR(name, S_IRUGO, show_name, NULL), | ||
599 | }; | ||
600 | |||
601 | static struct sensor_device_attribute f71805f_sensor_attr[] = { | ||
602 | SENSOR_ATTR(in1_input, S_IRUGO, show_in, NULL, 1), | ||
603 | SENSOR_ATTR(in1_max, S_IRUGO | S_IWUSR, | ||
604 | show_in_max, set_in_max, 1), | ||
605 | SENSOR_ATTR(in1_min, S_IRUGO | S_IWUSR, | ||
606 | show_in_min, set_in_min, 1), | ||
607 | SENSOR_ATTR(in2_input, S_IRUGO, show_in, NULL, 2), | ||
608 | SENSOR_ATTR(in2_max, S_IRUGO | S_IWUSR, | ||
609 | show_in_max, set_in_max, 2), | ||
610 | SENSOR_ATTR(in2_min, S_IRUGO | S_IWUSR, | ||
611 | show_in_min, set_in_min, 2), | ||
612 | SENSOR_ATTR(in3_input, S_IRUGO, show_in, NULL, 3), | ||
613 | SENSOR_ATTR(in3_max, S_IRUGO | S_IWUSR, | ||
614 | show_in_max, set_in_max, 3), | ||
615 | SENSOR_ATTR(in3_min, S_IRUGO | S_IWUSR, | ||
616 | show_in_min, set_in_min, 3), | ||
617 | SENSOR_ATTR(in4_input, S_IRUGO, show_in, NULL, 4), | ||
618 | SENSOR_ATTR(in4_max, S_IRUGO | S_IWUSR, | ||
619 | show_in_max, set_in_max, 4), | ||
620 | SENSOR_ATTR(in4_min, S_IRUGO | S_IWUSR, | ||
621 | show_in_min, set_in_min, 4), | ||
622 | SENSOR_ATTR(in5_input, S_IRUGO, show_in, NULL, 5), | ||
623 | SENSOR_ATTR(in5_max, S_IRUGO | S_IWUSR, | ||
624 | show_in_max, set_in_max, 5), | ||
625 | SENSOR_ATTR(in5_min, S_IRUGO | S_IWUSR, | ||
626 | show_in_min, set_in_min, 5), | ||
627 | SENSOR_ATTR(in6_input, S_IRUGO, show_in, NULL, 6), | ||
628 | SENSOR_ATTR(in6_max, S_IRUGO | S_IWUSR, | ||
629 | show_in_max, set_in_max, 6), | ||
630 | SENSOR_ATTR(in6_min, S_IRUGO | S_IWUSR, | ||
631 | show_in_min, set_in_min, 6), | ||
632 | SENSOR_ATTR(in7_input, S_IRUGO, show_in, NULL, 7), | ||
633 | SENSOR_ATTR(in7_max, S_IRUGO | S_IWUSR, | ||
634 | show_in_max, set_in_max, 7), | ||
635 | SENSOR_ATTR(in7_min, S_IRUGO | S_IWUSR, | ||
636 | show_in_min, set_in_min, 7), | ||
637 | SENSOR_ATTR(in8_input, S_IRUGO, show_in, NULL, 8), | ||
638 | SENSOR_ATTR(in8_max, S_IRUGO | S_IWUSR, | ||
639 | show_in_max, set_in_max, 8), | ||
640 | SENSOR_ATTR(in8_min, S_IRUGO | S_IWUSR, | ||
641 | show_in_min, set_in_min, 8), | ||
642 | |||
643 | SENSOR_ATTR(temp1_input, S_IRUGO, show_temp, NULL, 0), | ||
644 | SENSOR_ATTR(temp1_max, S_IRUGO | S_IWUSR, | ||
645 | show_temp_max, set_temp_max, 0), | ||
646 | SENSOR_ATTR(temp1_max_hyst, S_IRUGO | S_IWUSR, | ||
647 | show_temp_hyst, set_temp_hyst, 0), | ||
648 | SENSOR_ATTR(temp1_type, S_IRUGO, show_temp_type, NULL, 0), | ||
649 | SENSOR_ATTR(temp2_input, S_IRUGO, show_temp, NULL, 1), | ||
650 | SENSOR_ATTR(temp2_max, S_IRUGO | S_IWUSR, | ||
651 | show_temp_max, set_temp_max, 1), | ||
652 | SENSOR_ATTR(temp2_max_hyst, S_IRUGO | S_IWUSR, | ||
653 | show_temp_hyst, set_temp_hyst, 1), | ||
654 | SENSOR_ATTR(temp2_type, S_IRUGO, show_temp_type, NULL, 1), | ||
655 | SENSOR_ATTR(temp3_input, S_IRUGO, show_temp, NULL, 2), | ||
656 | SENSOR_ATTR(temp3_max, S_IRUGO | S_IWUSR, | ||
657 | show_temp_max, set_temp_max, 2), | ||
658 | SENSOR_ATTR(temp3_max_hyst, S_IRUGO | S_IWUSR, | ||
659 | show_temp_hyst, set_temp_hyst, 2), | ||
660 | SENSOR_ATTR(temp3_type, S_IRUGO, show_temp_type, NULL, 2), | ||
661 | }; | ||
662 | |||
663 | static struct sensor_device_attribute f71805f_fan_attr[] = { | ||
664 | SENSOR_ATTR(fan1_input, S_IRUGO, show_fan, NULL, 0), | ||
665 | SENSOR_ATTR(fan1_min, S_IRUGO | S_IWUSR, | ||
666 | show_fan_min, set_fan_min, 0), | ||
667 | SENSOR_ATTR(fan2_input, S_IRUGO, show_fan, NULL, 1), | ||
668 | SENSOR_ATTR(fan2_min, S_IRUGO | S_IWUSR, | ||
669 | show_fan_min, set_fan_min, 1), | ||
670 | SENSOR_ATTR(fan3_input, S_IRUGO, show_fan, NULL, 2), | ||
671 | SENSOR_ATTR(fan3_min, S_IRUGO | S_IWUSR, | ||
672 | show_fan_min, set_fan_min, 2), | ||
673 | }; | ||
641 | 674 | ||
642 | /* | 675 | /* |
643 | * Device registration and initialization | 676 | * Device registration and initialization |
@@ -668,7 +701,7 @@ static int __devinit f71805f_probe(struct platform_device *pdev) | |||
668 | { | 701 | { |
669 | struct f71805f_data *data; | 702 | struct f71805f_data *data; |
670 | struct resource *res; | 703 | struct resource *res; |
671 | int err; | 704 | int i, err; |
672 | 705 | ||
673 | if (!(data = kzalloc(sizeof(struct f71805f_data), GFP_KERNEL))) { | 706 | if (!(data = kzalloc(sizeof(struct f71805f_data), GFP_KERNEL))) { |
674 | err = -ENOMEM; | 707 | err = -ENOMEM; |
@@ -695,76 +728,31 @@ static int __devinit f71805f_probe(struct platform_device *pdev) | |||
695 | f71805f_init_device(data); | 728 | f71805f_init_device(data); |
696 | 729 | ||
697 | /* Register sysfs interface files */ | 730 | /* Register sysfs interface files */ |
698 | device_create_file(&pdev->dev, &dev_attr_in0_input); | 731 | for (i = 0; i < ARRAY_SIZE(f71805f_dev_attr); i++) { |
699 | device_create_file(&pdev->dev, &dev_attr_in0_max); | 732 | err = device_create_file(&pdev->dev, &f71805f_dev_attr[i]); |
700 | device_create_file(&pdev->dev, &dev_attr_in0_min); | 733 | if (err) |
701 | device_create_file(&pdev->dev, &sensor_dev_attr_in1_input.dev_attr); | 734 | goto exit_class; |
702 | device_create_file(&pdev->dev, &sensor_dev_attr_in2_input.dev_attr); | ||
703 | device_create_file(&pdev->dev, &sensor_dev_attr_in3_input.dev_attr); | ||
704 | device_create_file(&pdev->dev, &sensor_dev_attr_in4_input.dev_attr); | ||
705 | device_create_file(&pdev->dev, &sensor_dev_attr_in5_input.dev_attr); | ||
706 | device_create_file(&pdev->dev, &sensor_dev_attr_in6_input.dev_attr); | ||
707 | device_create_file(&pdev->dev, &sensor_dev_attr_in7_input.dev_attr); | ||
708 | device_create_file(&pdev->dev, &sensor_dev_attr_in8_input.dev_attr); | ||
709 | device_create_file(&pdev->dev, &sensor_dev_attr_in1_max.dev_attr); | ||
710 | device_create_file(&pdev->dev, &sensor_dev_attr_in2_max.dev_attr); | ||
711 | device_create_file(&pdev->dev, &sensor_dev_attr_in3_max.dev_attr); | ||
712 | device_create_file(&pdev->dev, &sensor_dev_attr_in4_max.dev_attr); | ||
713 | device_create_file(&pdev->dev, &sensor_dev_attr_in5_max.dev_attr); | ||
714 | device_create_file(&pdev->dev, &sensor_dev_attr_in6_max.dev_attr); | ||
715 | device_create_file(&pdev->dev, &sensor_dev_attr_in7_max.dev_attr); | ||
716 | device_create_file(&pdev->dev, &sensor_dev_attr_in8_max.dev_attr); | ||
717 | device_create_file(&pdev->dev, &sensor_dev_attr_in1_min.dev_attr); | ||
718 | device_create_file(&pdev->dev, &sensor_dev_attr_in2_min.dev_attr); | ||
719 | device_create_file(&pdev->dev, &sensor_dev_attr_in3_min.dev_attr); | ||
720 | device_create_file(&pdev->dev, &sensor_dev_attr_in4_min.dev_attr); | ||
721 | device_create_file(&pdev->dev, &sensor_dev_attr_in5_min.dev_attr); | ||
722 | device_create_file(&pdev->dev, &sensor_dev_attr_in6_min.dev_attr); | ||
723 | device_create_file(&pdev->dev, &sensor_dev_attr_in7_min.dev_attr); | ||
724 | device_create_file(&pdev->dev, &sensor_dev_attr_in8_min.dev_attr); | ||
725 | if (data->fan_enabled & (1 << 0)) { | ||
726 | device_create_file(&pdev->dev, | ||
727 | &sensor_dev_attr_fan1_input.dev_attr); | ||
728 | device_create_file(&pdev->dev, | ||
729 | &sensor_dev_attr_fan1_min.dev_attr); | ||
730 | } | 735 | } |
731 | if (data->fan_enabled & (1 << 1)) { | 736 | for (i = 0; i < ARRAY_SIZE(f71805f_sensor_attr); i++) { |
732 | device_create_file(&pdev->dev, | 737 | err = device_create_file(&pdev->dev, |
733 | &sensor_dev_attr_fan2_input.dev_attr); | 738 | &f71805f_sensor_attr[i].dev_attr); |
734 | device_create_file(&pdev->dev, | 739 | if (err) |
735 | &sensor_dev_attr_fan2_min.dev_attr); | 740 | goto exit_class; |
736 | } | 741 | } |
737 | if (data->fan_enabled & (1 << 2)) { | 742 | for (i = 0; i < ARRAY_SIZE(f71805f_fan_attr); i++) { |
738 | device_create_file(&pdev->dev, | 743 | if (!(data->fan_enabled & (1 << (i / 2)))) |
739 | &sensor_dev_attr_fan3_input.dev_attr); | 744 | continue; |
740 | device_create_file(&pdev->dev, | 745 | err = device_create_file(&pdev->dev, |
741 | &sensor_dev_attr_fan3_min.dev_attr); | 746 | &f71805f_fan_attr[i].dev_attr); |
747 | if (err) | ||
748 | goto exit_class; | ||
742 | } | 749 | } |
743 | device_create_file(&pdev->dev, | ||
744 | &sensor_dev_attr_temp1_input.dev_attr); | ||
745 | device_create_file(&pdev->dev, | ||
746 | &sensor_dev_attr_temp2_input.dev_attr); | ||
747 | device_create_file(&pdev->dev, | ||
748 | &sensor_dev_attr_temp3_input.dev_attr); | ||
749 | device_create_file(&pdev->dev, &sensor_dev_attr_temp1_max.dev_attr); | ||
750 | device_create_file(&pdev->dev, &sensor_dev_attr_temp2_max.dev_attr); | ||
751 | device_create_file(&pdev->dev, &sensor_dev_attr_temp3_max.dev_attr); | ||
752 | device_create_file(&pdev->dev, | ||
753 | &sensor_dev_attr_temp1_max_hyst.dev_attr); | ||
754 | device_create_file(&pdev->dev, | ||
755 | &sensor_dev_attr_temp2_max_hyst.dev_attr); | ||
756 | device_create_file(&pdev->dev, | ||
757 | &sensor_dev_attr_temp3_max_hyst.dev_attr); | ||
758 | device_create_file(&pdev->dev, &sensor_dev_attr_temp1_type.dev_attr); | ||
759 | device_create_file(&pdev->dev, &sensor_dev_attr_temp2_type.dev_attr); | ||
760 | device_create_file(&pdev->dev, &sensor_dev_attr_temp3_type.dev_attr); | ||
761 | device_create_file(&pdev->dev, &dev_attr_alarms_in); | ||
762 | device_create_file(&pdev->dev, &dev_attr_alarms_fan); | ||
763 | device_create_file(&pdev->dev, &dev_attr_alarms_temp); | ||
764 | device_create_file(&pdev->dev, &dev_attr_name); | ||
765 | 750 | ||
766 | return 0; | 751 | return 0; |
767 | 752 | ||
753 | exit_class: | ||
754 | dev_err(&pdev->dev, "Sysfs interface creation failed\n"); | ||
755 | hwmon_device_unregister(data->class_dev); | ||
768 | exit_free: | 756 | exit_free: |
769 | kfree(data); | 757 | kfree(data); |
770 | exit: | 758 | exit: |