diff options
author | Jean Delvare <khali@linux-fr.org> | 2010-08-14 15:08:58 -0400 |
---|---|---|
committer | Jean Delvare <khali@linux-fr.org> | 2010-08-14 15:08:58 -0400 |
commit | 9d32df192d2e4db4d59f26a3ea73601bd1a733e5 (patch) | |
tree | 69d44f6e2707af0d77244f78461a4c690f4ca0a8 /drivers/hwmon | |
parent | 328716bc16b7077ea5f6293c7420247c570d6480 (diff) |
hwmon: (pc87427) Add support for the second logical device
The second logical device contains the voltage and temperature
registers. We have to extend the driver to support a second logical
device before we can add support for these features.
Signed-off-by: Jean Delvare <khali@linux-fr.org>
Acked-by: Guenter Roeck <guenter.roeck@ericsson.com>
Diffstat (limited to 'drivers/hwmon')
-rw-r--r-- | drivers/hwmon/pc87427.c | 129 |
1 files changed, 87 insertions, 42 deletions
diff --git a/drivers/hwmon/pc87427.c b/drivers/hwmon/pc87427.c index 869822785b4f..129a33ce3fe4 100644 --- a/drivers/hwmon/pc87427.c +++ b/drivers/hwmon/pc87427.c | |||
@@ -65,6 +65,7 @@ struct pc87427_data { | |||
65 | }; | 65 | }; |
66 | 66 | ||
67 | struct pc87427_sio_data { | 67 | struct pc87427_sio_data { |
68 | unsigned short address[2]; | ||
68 | u8 has_fanin; | 69 | u8 has_fanin; |
69 | u8 has_fanout; | 70 | u8 has_fanout; |
70 | }; | 71 | }; |
@@ -608,6 +609,46 @@ static DEVICE_ATTR(name, S_IRUGO, show_name, NULL); | |||
608 | * Device detection, attach and detach | 609 | * Device detection, attach and detach |
609 | */ | 610 | */ |
610 | 611 | ||
612 | static void pc87427_release_regions(struct platform_device *pdev, int count) | ||
613 | { | ||
614 | struct resource *res; | ||
615 | int i; | ||
616 | |||
617 | for (i = 0; i < count; i++) { | ||
618 | res = platform_get_resource(pdev, IORESOURCE_IO, i); | ||
619 | release_region(res->start, resource_size(res)); | ||
620 | } | ||
621 | } | ||
622 | |||
623 | static int __devinit pc87427_request_regions(struct platform_device *pdev, | ||
624 | int count) | ||
625 | { | ||
626 | struct resource *res; | ||
627 | int i, err = 0; | ||
628 | |||
629 | for (i = 0; i < count; i++) { | ||
630 | res = platform_get_resource(pdev, IORESOURCE_IO, i); | ||
631 | if (!res) { | ||
632 | err = -ENOENT; | ||
633 | dev_err(&pdev->dev, "Missing resource #%d\n", i); | ||
634 | break; | ||
635 | } | ||
636 | if (!request_region(res->start, resource_size(res), DRVNAME)) { | ||
637 | err = -EBUSY; | ||
638 | dev_err(&pdev->dev, | ||
639 | "Failed to request region 0x%lx-0x%lx\n", | ||
640 | (unsigned long)res->start, | ||
641 | (unsigned long)res->end); | ||
642 | break; | ||
643 | } | ||
644 | } | ||
645 | |||
646 | if (err && i) | ||
647 | pc87427_release_regions(pdev, i); | ||
648 | |||
649 | return err; | ||
650 | } | ||
651 | |||
611 | static void __devinit pc87427_init_device(struct device *dev) | 652 | static void __devinit pc87427_init_device(struct device *dev) |
612 | { | 653 | { |
613 | struct pc87427_sio_data *sio_data = dev->platform_data; | 654 | struct pc87427_sio_data *sio_data = dev->platform_data; |
@@ -664,9 +705,9 @@ static void __devinit pc87427_init_device(struct device *dev) | |||
664 | 705 | ||
665 | static int __devinit pc87427_probe(struct platform_device *pdev) | 706 | static int __devinit pc87427_probe(struct platform_device *pdev) |
666 | { | 707 | { |
708 | struct pc87427_sio_data *sio_data = pdev->dev.platform_data; | ||
667 | struct pc87427_data *data; | 709 | struct pc87427_data *data; |
668 | struct resource *res; | 710 | int i, err, res_count; |
669 | int i, err; | ||
670 | 711 | ||
671 | data = kzalloc(sizeof(struct pc87427_data), GFP_KERNEL); | 712 | data = kzalloc(sizeof(struct pc87427_data), GFP_KERNEL); |
672 | if (!data) { | 713 | if (!data) { |
@@ -675,16 +716,13 @@ static int __devinit pc87427_probe(struct platform_device *pdev) | |||
675 | goto exit; | 716 | goto exit; |
676 | } | 717 | } |
677 | 718 | ||
678 | /* This will need to be revisited when we add support for | 719 | data->address[0] = sio_data->address[0]; |
679 | temperature and voltage monitoring. */ | 720 | data->address[1] = sio_data->address[1]; |
680 | res = platform_get_resource(pdev, IORESOURCE_IO, 0); | 721 | res_count = (data->address[0] != 0) + (data->address[1] != 0); |
681 | if (!request_region(res->start, resource_size(res), DRVNAME)) { | 722 | |
682 | err = -EBUSY; | 723 | err = pc87427_request_regions(pdev, res_count); |
683 | dev_err(&pdev->dev, "Failed to request region 0x%lx-0x%lx\n", | 724 | if (err) |
684 | (unsigned long)res->start, (unsigned long)res->end); | ||
685 | goto exit_kfree; | 725 | goto exit_kfree; |
686 | } | ||
687 | data->address[0] = res->start; | ||
688 | 726 | ||
689 | mutex_init(&data->lock); | 727 | mutex_init(&data->lock); |
690 | data->name = "pc87427"; | 728 | data->name = "pc87427"; |
@@ -733,7 +771,7 @@ exit_remove_files: | |||
733 | sysfs_remove_group(&pdev->dev.kobj, &pc87427_group_pwm[i]); | 771 | sysfs_remove_group(&pdev->dev.kobj, &pc87427_group_pwm[i]); |
734 | } | 772 | } |
735 | exit_release_region: | 773 | exit_release_region: |
736 | release_region(res->start, resource_size(res)); | 774 | pc87427_release_regions(pdev, res_count); |
737 | exit_kfree: | 775 | exit_kfree: |
738 | platform_set_drvdata(pdev, NULL); | 776 | platform_set_drvdata(pdev, NULL); |
739 | kfree(data); | 777 | kfree(data); |
@@ -744,8 +782,9 @@ exit: | |||
744 | static int __devexit pc87427_remove(struct platform_device *pdev) | 782 | static int __devexit pc87427_remove(struct platform_device *pdev) |
745 | { | 783 | { |
746 | struct pc87427_data *data = platform_get_drvdata(pdev); | 784 | struct pc87427_data *data = platform_get_drvdata(pdev); |
747 | struct resource *res; | 785 | int i, res_count; |
748 | int i; | 786 | |
787 | res_count = (data->address[0] != 0) + (data->address[1] != 0); | ||
749 | 788 | ||
750 | hwmon_device_unregister(data->hwmon_dev); | 789 | hwmon_device_unregister(data->hwmon_dev); |
751 | device_remove_file(&pdev->dev, &dev_attr_name); | 790 | device_remove_file(&pdev->dev, &dev_attr_name); |
@@ -762,8 +801,7 @@ static int __devexit pc87427_remove(struct platform_device *pdev) | |||
762 | platform_set_drvdata(pdev, NULL); | 801 | platform_set_drvdata(pdev, NULL); |
763 | kfree(data); | 802 | kfree(data); |
764 | 803 | ||
765 | res = platform_get_resource(pdev, IORESOURCE_IO, 0); | 804 | pc87427_release_regions(pdev, res_count); |
766 | release_region(res->start, resource_size(res)); | ||
767 | 805 | ||
768 | return 0; | 806 | return 0; |
769 | } | 807 | } |
@@ -778,29 +816,37 @@ static struct platform_driver pc87427_driver = { | |||
778 | .remove = __devexit_p(pc87427_remove), | 816 | .remove = __devexit_p(pc87427_remove), |
779 | }; | 817 | }; |
780 | 818 | ||
781 | static int __init pc87427_device_add(unsigned short address, | 819 | static int __init pc87427_device_add(const struct pc87427_sio_data *sio_data) |
782 | const struct pc87427_sio_data *sio_data) | ||
783 | { | 820 | { |
784 | struct resource res = { | 821 | struct resource res[2] = { |
785 | .start = address, | 822 | { .flags = IORESOURCE_IO }, |
786 | .end = address + REGION_LENGTH - 1, | 823 | { .flags = IORESOURCE_IO }, |
787 | .name = logdev_str[0], | ||
788 | .flags = IORESOURCE_IO, | ||
789 | }; | 824 | }; |
790 | int err; | 825 | int err, i, res_count; |
791 | 826 | ||
792 | err = acpi_check_resource_conflict(&res); | 827 | res_count = 0; |
793 | if (err) | 828 | for (i = 0; i < 2; i++) { |
794 | goto exit; | 829 | if (!sio_data->address[i]) |
830 | continue; | ||
831 | res[res_count].start = sio_data->address[i]; | ||
832 | res[res_count].end = sio_data->address[i] + REGION_LENGTH - 1; | ||
833 | res[res_count].name = logdev_str[i]; | ||
795 | 834 | ||
796 | pdev = platform_device_alloc(DRVNAME, address); | 835 | err = acpi_check_resource_conflict(&res[res_count]); |
836 | if (err) | ||
837 | goto exit; | ||
838 | |||
839 | res_count++; | ||
840 | } | ||
841 | |||
842 | pdev = platform_device_alloc(DRVNAME, res[0].start); | ||
797 | if (!pdev) { | 843 | if (!pdev) { |
798 | err = -ENOMEM; | 844 | err = -ENOMEM; |
799 | printk(KERN_ERR DRVNAME ": Device allocation failed\n"); | 845 | printk(KERN_ERR DRVNAME ": Device allocation failed\n"); |
800 | goto exit; | 846 | goto exit; |
801 | } | 847 | } |
802 | 848 | ||
803 | err = platform_device_add_resources(pdev, &res, 1); | 849 | err = platform_device_add_resources(pdev, res, res_count); |
804 | if (err) { | 850 | if (err) { |
805 | printk(KERN_ERR DRVNAME ": Device resource addition failed " | 851 | printk(KERN_ERR DRVNAME ": Device resource addition failed " |
806 | "(%d)\n", err); | 852 | "(%d)\n", err); |
@@ -829,8 +875,7 @@ exit: | |||
829 | return err; | 875 | return err; |
830 | } | 876 | } |
831 | 877 | ||
832 | static int __init pc87427_find(int sioaddr, unsigned short *address, | 878 | static int __init pc87427_find(int sioaddr, struct pc87427_sio_data *sio_data) |
833 | struct pc87427_sio_data *sio_data) | ||
834 | { | 879 | { |
835 | u16 val; | 880 | u16 val; |
836 | u8 cfg, cfg_b; | 881 | u8 cfg, cfg_b; |
@@ -844,7 +889,7 @@ static int __init pc87427_find(int sioaddr, unsigned short *address, | |||
844 | } | 889 | } |
845 | 890 | ||
846 | for (i = 0; i < 2; i++) { | 891 | for (i = 0; i < 2; i++) { |
847 | address[i] = 0; | 892 | sio_data->address[i] = 0; |
848 | /* Select logical device */ | 893 | /* Select logical device */ |
849 | superio_outb(sioaddr, SIOREG_LDSEL, logdev[i]); | 894 | superio_outb(sioaddr, SIOREG_LDSEL, logdev[i]); |
850 | 895 | ||
@@ -869,7 +914,13 @@ static int __init pc87427_find(int sioaddr, unsigned short *address, | |||
869 | "for logical device 0x%02x\n", logdev[i]); | 914 | "for logical device 0x%02x\n", logdev[i]); |
870 | continue; | 915 | continue; |
871 | } | 916 | } |
872 | address[i] = val; | 917 | sio_data->address[i] = val; |
918 | } | ||
919 | |||
920 | /* No point in loading the driver if everything is disabled */ | ||
921 | if (!sio_data->address[0] && !sio_data->address[1]) { | ||
922 | err = -ENODEV; | ||
923 | goto exit; | ||
873 | } | 924 | } |
874 | 925 | ||
875 | /* Check which fan inputs are wired */ | 926 | /* Check which fan inputs are wired */ |
@@ -923,16 +974,10 @@ exit: | |||
923 | static int __init pc87427_init(void) | 974 | static int __init pc87427_init(void) |
924 | { | 975 | { |
925 | int err; | 976 | int err; |
926 | unsigned short address[2]; | ||
927 | struct pc87427_sio_data sio_data; | 977 | struct pc87427_sio_data sio_data; |
928 | 978 | ||
929 | if (pc87427_find(0x2e, address, &sio_data) | 979 | if (pc87427_find(0x2e, &sio_data) |
930 | && pc87427_find(0x4e, address, &sio_data)) | 980 | && pc87427_find(0x4e, &sio_data)) |
931 | return -ENODEV; | ||
932 | |||
933 | /* For now the driver only handles fans so we only care about the | ||
934 | first address. */ | ||
935 | if (!address[0]) | ||
936 | return -ENODEV; | 981 | return -ENODEV; |
937 | 982 | ||
938 | err = platform_driver_register(&pc87427_driver); | 983 | err = platform_driver_register(&pc87427_driver); |
@@ -940,7 +985,7 @@ static int __init pc87427_init(void) | |||
940 | goto exit; | 985 | goto exit; |
941 | 986 | ||
942 | /* Sets global pdev as a side effect */ | 987 | /* Sets global pdev as a side effect */ |
943 | err = pc87427_device_add(address[0], &sio_data); | 988 | err = pc87427_device_add(&sio_data); |
944 | if (err) | 989 | if (err) |
945 | goto exit_driver; | 990 | goto exit_driver; |
946 | 991 | ||