diff options
author | Axel Lin <axel.lin@ingics.com> | 2014-07-23 00:39:21 -0400 |
---|---|---|
committer | Guenter Roeck <linux@roeck-us.net> | 2014-08-04 10:01:40 -0400 |
commit | 8eb406100c9da01ebe983702aae6d479c882d5cb (patch) | |
tree | 706be680585357e2ea0af5c879ae8ba42a1eb789 | |
parent | 8de2dcc9a1355f83885d34888b7e6549d9ea6d92 (diff) |
hwmon: (lm78) Convert to devm_hwmon_device_register_with_groups
Use ATTRIBUTE_GROUPS macro and devm_hwmon_device_register_with_groups() to
simplify the code a bit.
Signed-off-by: Axel Lin <axel.lin@ingics.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
-rw-r--r-- | drivers/hwmon/lm78.c | 98 |
1 files changed, 15 insertions, 83 deletions
diff --git a/drivers/hwmon/lm78.c b/drivers/hwmon/lm78.c index c1eb464f0fd0..759661c7d480 100644 --- a/drivers/hwmon/lm78.c +++ b/drivers/hwmon/lm78.c | |||
@@ -123,7 +123,6 @@ static inline int TEMP_FROM_REG(s8 val) | |||
123 | 123 | ||
124 | struct lm78_data { | 124 | struct lm78_data { |
125 | struct i2c_client *client; | 125 | struct i2c_client *client; |
126 | struct device *hwmon_dev; | ||
127 | struct mutex lock; | 126 | struct mutex lock; |
128 | enum chips type; | 127 | enum chips type; |
129 | 128 | ||
@@ -468,7 +467,7 @@ static SENSOR_DEVICE_ATTR(fan2_alarm, S_IRUGO, show_alarm, NULL, 7); | |||
468 | static SENSOR_DEVICE_ATTR(fan3_alarm, S_IRUGO, show_alarm, NULL, 11); | 467 | static SENSOR_DEVICE_ATTR(fan3_alarm, S_IRUGO, show_alarm, NULL, 11); |
469 | static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 4); | 468 | static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 4); |
470 | 469 | ||
471 | static struct attribute *lm78_attributes[] = { | 470 | static struct attribute *lm78_attrs[] = { |
472 | &sensor_dev_attr_in0_input.dev_attr.attr, | 471 | &sensor_dev_attr_in0_input.dev_attr.attr, |
473 | &sensor_dev_attr_in0_min.dev_attr.attr, | 472 | &sensor_dev_attr_in0_min.dev_attr.attr, |
474 | &sensor_dev_attr_in0_max.dev_attr.attr, | 473 | &sensor_dev_attr_in0_max.dev_attr.attr, |
@@ -519,9 +518,7 @@ static struct attribute *lm78_attributes[] = { | |||
519 | NULL | 518 | NULL |
520 | }; | 519 | }; |
521 | 520 | ||
522 | static const struct attribute_group lm78_group = { | 521 | ATTRIBUTE_GROUPS(lm78); |
523 | .attrs = lm78_attributes, | ||
524 | }; | ||
525 | 522 | ||
526 | /* | 523 | /* |
527 | * ISA related code | 524 | * ISA related code |
@@ -533,19 +530,6 @@ static struct platform_device *pdev; | |||
533 | 530 | ||
534 | static unsigned short isa_address = 0x290; | 531 | static unsigned short isa_address = 0x290; |
535 | 532 | ||
536 | /* | ||
537 | * I2C devices get this name attribute automatically, but for ISA devices | ||
538 | * we must create it by ourselves. | ||
539 | */ | ||
540 | static ssize_t show_name(struct device *dev, struct device_attribute | ||
541 | *devattr, char *buf) | ||
542 | { | ||
543 | struct lm78_data *data = dev_get_drvdata(dev); | ||
544 | |||
545 | return sprintf(buf, "%s\n", data->name); | ||
546 | } | ||
547 | static DEVICE_ATTR(name, S_IRUGO, show_name, NULL); | ||
548 | |||
549 | static struct lm78_data *lm78_data_if_isa(void) | 533 | static struct lm78_data *lm78_data_if_isa(void) |
550 | { | 534 | { |
551 | return pdev ? platform_get_drvdata(pdev) : NULL; | 535 | return pdev ? platform_get_drvdata(pdev) : NULL; |
@@ -661,46 +645,23 @@ static int lm78_i2c_detect(struct i2c_client *client, | |||
661 | static int lm78_i2c_probe(struct i2c_client *client, | 645 | static int lm78_i2c_probe(struct i2c_client *client, |
662 | const struct i2c_device_id *id) | 646 | const struct i2c_device_id *id) |
663 | { | 647 | { |
648 | struct device *dev = &client->dev; | ||
649 | struct device *hwmon_dev; | ||
664 | struct lm78_data *data; | 650 | struct lm78_data *data; |
665 | int err; | ||
666 | 651 | ||
667 | data = devm_kzalloc(&client->dev, sizeof(struct lm78_data), GFP_KERNEL); | 652 | data = devm_kzalloc(dev, sizeof(struct lm78_data), GFP_KERNEL); |
668 | if (!data) | 653 | if (!data) |
669 | return -ENOMEM; | 654 | return -ENOMEM; |
670 | 655 | ||
671 | i2c_set_clientdata(client, data); | ||
672 | data->client = client; | 656 | data->client = client; |
673 | data->type = id->driver_data; | 657 | data->type = id->driver_data; |
674 | 658 | ||
675 | /* Initialize the LM78 chip */ | 659 | /* Initialize the LM78 chip */ |
676 | lm78_init_device(data); | 660 | lm78_init_device(data); |
677 | 661 | ||
678 | /* Register sysfs hooks */ | 662 | hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name, |
679 | err = sysfs_create_group(&client->dev.kobj, &lm78_group); | 663 | data, lm78_groups); |
680 | if (err) | 664 | return PTR_ERR_OR_ZERO(hwmon_dev); |
681 | return err; | ||
682 | |||
683 | data->hwmon_dev = hwmon_device_register(&client->dev); | ||
684 | if (IS_ERR(data->hwmon_dev)) { | ||
685 | err = PTR_ERR(data->hwmon_dev); | ||
686 | goto error; | ||
687 | } | ||
688 | |||
689 | return 0; | ||
690 | |||
691 | error: | ||
692 | sysfs_remove_group(&client->dev.kobj, &lm78_group); | ||
693 | return err; | ||
694 | } | ||
695 | |||
696 | static int lm78_i2c_remove(struct i2c_client *client) | ||
697 | { | ||
698 | struct lm78_data *data = i2c_get_clientdata(client); | ||
699 | |||
700 | hwmon_device_unregister(data->hwmon_dev); | ||
701 | sysfs_remove_group(&client->dev.kobj, &lm78_group); | ||
702 | |||
703 | return 0; | ||
704 | } | 665 | } |
705 | 666 | ||
706 | static const struct i2c_device_id lm78_i2c_id[] = { | 667 | static const struct i2c_device_id lm78_i2c_id[] = { |
@@ -716,7 +677,6 @@ static struct i2c_driver lm78_driver = { | |||
716 | .name = "lm78", | 677 | .name = "lm78", |
717 | }, | 678 | }, |
718 | .probe = lm78_i2c_probe, | 679 | .probe = lm78_i2c_probe, |
719 | .remove = lm78_i2c_remove, | ||
720 | .id_table = lm78_i2c_id, | 680 | .id_table = lm78_i2c_id, |
721 | .detect = lm78_i2c_detect, | 681 | .detect = lm78_i2c_detect, |
722 | .address_list = normal_i2c, | 682 | .address_list = normal_i2c, |
@@ -839,17 +799,18 @@ static struct lm78_data *lm78_update_device(struct device *dev) | |||
839 | #ifdef CONFIG_ISA | 799 | #ifdef CONFIG_ISA |
840 | static int lm78_isa_probe(struct platform_device *pdev) | 800 | static int lm78_isa_probe(struct platform_device *pdev) |
841 | { | 801 | { |
842 | int err; | 802 | struct device *dev = &pdev->dev; |
803 | struct device *hwmon_dev; | ||
843 | struct lm78_data *data; | 804 | struct lm78_data *data; |
844 | struct resource *res; | 805 | struct resource *res; |
845 | 806 | ||
846 | /* Reserve the ISA region */ | 807 | /* Reserve the ISA region */ |
847 | res = platform_get_resource(pdev, IORESOURCE_IO, 0); | 808 | res = platform_get_resource(pdev, IORESOURCE_IO, 0); |
848 | if (!devm_request_region(&pdev->dev, res->start + LM78_ADDR_REG_OFFSET, | 809 | if (!devm_request_region(dev, res->start + LM78_ADDR_REG_OFFSET, |
849 | 2, "lm78")) | 810 | 2, "lm78")) |
850 | return -EBUSY; | 811 | return -EBUSY; |
851 | 812 | ||
852 | data = devm_kzalloc(&pdev->dev, sizeof(struct lm78_data), GFP_KERNEL); | 813 | data = devm_kzalloc(dev, sizeof(struct lm78_data), GFP_KERNEL); |
853 | if (!data) | 814 | if (!data) |
854 | return -ENOMEM; | 815 | return -ENOMEM; |
855 | 816 | ||
@@ -868,37 +829,9 @@ static int lm78_isa_probe(struct platform_device *pdev) | |||
868 | /* Initialize the LM78 chip */ | 829 | /* Initialize the LM78 chip */ |
869 | lm78_init_device(data); | 830 | lm78_init_device(data); |
870 | 831 | ||
871 | /* Register sysfs hooks */ | 832 | hwmon_dev = devm_hwmon_device_register_with_groups(dev, data->name, |
872 | err = sysfs_create_group(&pdev->dev.kobj, &lm78_group); | 833 | data, lm78_groups); |
873 | if (err) | 834 | return PTR_ERR_OR_ZERO(hwmon_dev); |
874 | goto exit_remove_files; | ||
875 | err = device_create_file(&pdev->dev, &dev_attr_name); | ||
876 | if (err) | ||
877 | goto exit_remove_files; | ||
878 | |||
879 | data->hwmon_dev = hwmon_device_register(&pdev->dev); | ||
880 | if (IS_ERR(data->hwmon_dev)) { | ||
881 | err = PTR_ERR(data->hwmon_dev); | ||
882 | goto exit_remove_files; | ||
883 | } | ||
884 | |||
885 | return 0; | ||
886 | |||
887 | exit_remove_files: | ||
888 | sysfs_remove_group(&pdev->dev.kobj, &lm78_group); | ||
889 | device_remove_file(&pdev->dev, &dev_attr_name); | ||
890 | return err; | ||
891 | } | ||
892 | |||
893 | static int lm78_isa_remove(struct platform_device *pdev) | ||
894 | { | ||
895 | struct lm78_data *data = platform_get_drvdata(pdev); | ||
896 | |||
897 | hwmon_device_unregister(data->hwmon_dev); | ||
898 | sysfs_remove_group(&pdev->dev.kobj, &lm78_group); | ||
899 | device_remove_file(&pdev->dev, &dev_attr_name); | ||
900 | |||
901 | return 0; | ||
902 | } | 835 | } |
903 | 836 | ||
904 | static struct platform_driver lm78_isa_driver = { | 837 | static struct platform_driver lm78_isa_driver = { |
@@ -907,7 +840,6 @@ static struct platform_driver lm78_isa_driver = { | |||
907 | .name = "lm78", | 840 | .name = "lm78", |
908 | }, | 841 | }, |
909 | .probe = lm78_isa_probe, | 842 | .probe = lm78_isa_probe, |
910 | .remove = lm78_isa_remove, | ||
911 | }; | 843 | }; |
912 | 844 | ||
913 | /* return 1 if a supported chip is found, 0 otherwise */ | 845 | /* return 1 if a supported chip is found, 0 otherwise */ |