aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon/lm78.c
diff options
context:
space:
mode:
authorJean Delvare <khali@linux-fr.org>2011-07-25 15:46:11 -0400
committerJean Delvare <khali@endymion.delvare>2011-07-25 15:46:11 -0400
commited4cebdf9cfbf5f97f388ae7f2ac2b24fc362a39 (patch)
tree630cefdbda12ed9e6783abc2fb141e8dadd24336 /drivers/hwmon/lm78.c
parente9b6e9f3d4c58f76da8ec8286c7b901af8575f5b (diff)
hwmon: (lm78) Avoid forward declarations
Move code around to avoid several forward declarations. Also group ISA-related functions together, to make future changes easier. Signed-off-by: Jean Delvare <khali@linux-fr.org> Cc: Dean Nelson <dnelson@redhat.com>
Diffstat (limited to 'drivers/hwmon/lm78.c')
-rw-r--r--drivers/hwmon/lm78.c205
1 files changed, 98 insertions, 107 deletions
diff --git a/drivers/hwmon/lm78.c b/drivers/hwmon/lm78.c
index 4cb24eafe318..5b7c69570619 100644
--- a/drivers/hwmon/lm78.c
+++ b/drivers/hwmon/lm78.c
@@ -143,50 +143,12 @@ struct lm78_data {
143}; 143};
144 144
145 145
146static int lm78_i2c_detect(struct i2c_client *client,
147 struct i2c_board_info *info);
148static int lm78_i2c_probe(struct i2c_client *client,
149 const struct i2c_device_id *id);
150static int lm78_i2c_remove(struct i2c_client *client);
151
152static int __devinit lm78_isa_probe(struct platform_device *pdev);
153static int __devexit lm78_isa_remove(struct platform_device *pdev);
154
155static int lm78_read_value(struct lm78_data *data, u8 reg); 146static int lm78_read_value(struct lm78_data *data, u8 reg);
156static int lm78_write_value(struct lm78_data *data, u8 reg, u8 value); 147static int lm78_write_value(struct lm78_data *data, u8 reg, u8 value);
157static struct lm78_data *lm78_update_device(struct device *dev); 148static struct lm78_data *lm78_update_device(struct device *dev);
158static void lm78_init_device(struct lm78_data *data); 149static void lm78_init_device(struct lm78_data *data);
159 150
160 151
161static const struct i2c_device_id lm78_i2c_id[] = {
162 { "lm78", lm78 },
163 { "lm79", lm79 },
164 { }
165};
166MODULE_DEVICE_TABLE(i2c, lm78_i2c_id);
167
168static struct i2c_driver lm78_driver = {
169 .class = I2C_CLASS_HWMON,
170 .driver = {
171 .name = "lm78",
172 },
173 .probe = lm78_i2c_probe,
174 .remove = lm78_i2c_remove,
175 .id_table = lm78_i2c_id,
176 .detect = lm78_i2c_detect,
177 .address_list = normal_i2c,
178};
179
180static struct platform_driver lm78_isa_driver = {
181 .driver = {
182 .owner = THIS_MODULE,
183 .name = "lm78",
184 },
185 .probe = lm78_isa_probe,
186 .remove = __devexit_p(lm78_isa_remove),
187};
188
189
190/* 7 Voltages */ 152/* 7 Voltages */
191static ssize_t show_in(struct device *dev, struct device_attribute *da, 153static ssize_t show_in(struct device *dev, struct device_attribute *da,
192 char *buf) 154 char *buf)
@@ -663,76 +625,24 @@ static int lm78_i2c_remove(struct i2c_client *client)
663 return 0; 625 return 0;
664} 626}
665 627
666static int __devinit lm78_isa_probe(struct platform_device *pdev) 628static const struct i2c_device_id lm78_i2c_id[] = {
667{ 629 { "lm78", lm78 },
668 int err; 630 { "lm79", lm79 },
669 struct lm78_data *data; 631 { }
670 struct resource *res; 632};
671 633MODULE_DEVICE_TABLE(i2c, lm78_i2c_id);
672 /* Reserve the ISA region */
673 res = platform_get_resource(pdev, IORESOURCE_IO, 0);
674 if (!request_region(res->start + LM78_ADDR_REG_OFFSET, 2, "lm78")) {
675 err = -EBUSY;
676 goto exit;
677 }
678
679 if (!(data = kzalloc(sizeof(struct lm78_data), GFP_KERNEL))) {
680 err = -ENOMEM;
681 goto exit_release_region;
682 }
683 mutex_init(&data->lock);
684 data->isa_addr = res->start;
685 platform_set_drvdata(pdev, data);
686
687 if (lm78_read_value(data, LM78_REG_CHIPID) & 0x80) {
688 data->type = lm79;
689 data->name = "lm79";
690 } else {
691 data->type = lm78;
692 data->name = "lm78";
693 }
694
695 /* Initialize the LM78 chip */
696 lm78_init_device(data);
697
698 /* Register sysfs hooks */
699 if ((err = sysfs_create_group(&pdev->dev.kobj, &lm78_group))
700 || (err = device_create_file(&pdev->dev, &dev_attr_name)))
701 goto exit_remove_files;
702
703 data->hwmon_dev = hwmon_device_register(&pdev->dev);
704 if (IS_ERR(data->hwmon_dev)) {
705 err = PTR_ERR(data->hwmon_dev);
706 goto exit_remove_files;
707 }
708
709 return 0;
710
711 exit_remove_files:
712 sysfs_remove_group(&pdev->dev.kobj, &lm78_group);
713 device_remove_file(&pdev->dev, &dev_attr_name);
714 kfree(data);
715 exit_release_region:
716 release_region(res->start + LM78_ADDR_REG_OFFSET, 2);
717 exit:
718 return err;
719}
720
721static int __devexit lm78_isa_remove(struct platform_device *pdev)
722{
723 struct lm78_data *data = platform_get_drvdata(pdev);
724 struct resource *res;
725
726 hwmon_device_unregister(data->hwmon_dev);
727 sysfs_remove_group(&pdev->dev.kobj, &lm78_group);
728 device_remove_file(&pdev->dev, &dev_attr_name);
729 kfree(data);
730
731 res = platform_get_resource(pdev, IORESOURCE_IO, 0);
732 release_region(res->start + LM78_ADDR_REG_OFFSET, 2);
733 634
734 return 0; 635static struct i2c_driver lm78_driver = {
735} 636 .class = I2C_CLASS_HWMON,
637 .driver = {
638 .name = "lm78",
639 },
640 .probe = lm78_i2c_probe,
641 .remove = lm78_i2c_remove,
642 .id_table = lm78_i2c_id,
643 .detect = lm78_i2c_detect,
644 .address_list = normal_i2c,
645};
736 646
737/* The SMBus locks itself, but ISA access must be locked explicitly! 647/* The SMBus locks itself, but ISA access must be locked explicitly!
738 We don't want to lock the whole ISA bus, so we lock each client 648 We don't want to lock the whole ISA bus, so we lock each client
@@ -849,6 +759,87 @@ static struct lm78_data *lm78_update_device(struct device *dev)
849 return data; 759 return data;
850} 760}
851 761
762static int __devinit lm78_isa_probe(struct platform_device *pdev)
763{
764 int err;
765 struct lm78_data *data;
766 struct resource *res;
767
768 /* Reserve the ISA region */
769 res = platform_get_resource(pdev, IORESOURCE_IO, 0);
770 if (!request_region(res->start + LM78_ADDR_REG_OFFSET, 2, "lm78")) {
771 err = -EBUSY;
772 goto exit;
773 }
774
775 data = kzalloc(sizeof(struct lm78_data), GFP_KERNEL);
776 if (!data) {
777 err = -ENOMEM;
778 goto exit_release_region;
779 }
780 mutex_init(&data->lock);
781 data->isa_addr = res->start;
782 platform_set_drvdata(pdev, data);
783
784 if (lm78_read_value(data, LM78_REG_CHIPID) & 0x80) {
785 data->type = lm79;
786 data->name = "lm79";
787 } else {
788 data->type = lm78;
789 data->name = "lm78";
790 }
791
792 /* Initialize the LM78 chip */
793 lm78_init_device(data);
794
795 /* Register sysfs hooks */
796 if ((err = sysfs_create_group(&pdev->dev.kobj, &lm78_group))
797 || (err = device_create_file(&pdev->dev, &dev_attr_name)))
798 goto exit_remove_files;
799
800 data->hwmon_dev = hwmon_device_register(&pdev->dev);
801 if (IS_ERR(data->hwmon_dev)) {
802 err = PTR_ERR(data->hwmon_dev);
803 goto exit_remove_files;
804 }
805
806 return 0;
807
808 exit_remove_files:
809 sysfs_remove_group(&pdev->dev.kobj, &lm78_group);
810 device_remove_file(&pdev->dev, &dev_attr_name);
811 kfree(data);
812 exit_release_region:
813 release_region(res->start + LM78_ADDR_REG_OFFSET, 2);
814 exit:
815 return err;
816}
817
818static int __devexit lm78_isa_remove(struct platform_device *pdev)
819{
820 struct lm78_data *data = platform_get_drvdata(pdev);
821 struct resource *res;
822
823 hwmon_device_unregister(data->hwmon_dev);
824 sysfs_remove_group(&pdev->dev.kobj, &lm78_group);
825 device_remove_file(&pdev->dev, &dev_attr_name);
826 kfree(data);
827
828 res = platform_get_resource(pdev, IORESOURCE_IO, 0);
829 release_region(res->start + LM78_ADDR_REG_OFFSET, 2);
830
831 return 0;
832}
833
834static struct platform_driver lm78_isa_driver = {
835 .driver = {
836 .owner = THIS_MODULE,
837 .name = "lm78",
838 },
839 .probe = lm78_isa_probe,
840 .remove = __devexit_p(lm78_isa_remove),
841};
842
852/* return 1 if a supported chip is found, 0 otherwise */ 843/* return 1 if a supported chip is found, 0 otherwise */
853static int __init lm78_isa_found(unsigned short address) 844static int __init lm78_isa_found(unsigned short address)
854{ 845{