hc
2023-12-09 b22da3d8526a935aa31e086e63f60ff3246cb61c
kernel/drivers/power/supply/ds2781_battery.c
....@@ -1,14 +1,10 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * 1-wire client/driver for the Maxim/Dallas DS2781 Stand-Alone Fuel Gauge IC
34 *
45 * Author: Renata Sayakhova <renata@oktetlabs.ru>
56 *
67 * Based on ds2780_battery drivers
7
- *
8
- * This program is free software; you can redistribute it and/or modify
9
- * it under the terms of the GNU General Public License version 2 as
10
- * published by the Free Software Foundation.
11
- *
128 */
139
1410 #include <linux/module.h>
....@@ -172,7 +168,7 @@
172168 return ret;
173169 /*
174170 * The voltage value is located in 10 bits across the voltage MSB
175
- * and LSB registers in two's compliment form
171
+ * and LSB registers in two's complement form
176172 * Sign bit of the voltage value is in bit 7 of the voltage MSB register
177173 * Bits 9 - 3 of the voltage value are in bits 6 - 0 of the
178174 * voltage MSB register
....@@ -201,7 +197,7 @@
201197 return ret;
202198 /*
203199 * The temperature value is located in 10 bits across the temperature
204
- * MSB and LSB registers in two's compliment form
200
+ * MSB and LSB registers in two's complement form
205201 * Sign bit of the temperature value is in bit 7 of the temperature
206202 * MSB register
207203 * Bits 9 - 3 of the temperature value are in bits 6 - 0 of the
....@@ -246,7 +242,7 @@
246242
247243 /*
248244 * The current value is located in 16 bits across the current MSB
249
- * and LSB registers in two's compliment form
245
+ * and LSB registers in two's complement form
250246 * Sign bit of the current value is in bit 7 of the current MSB register
251247 * Bits 14 - 8 of the current value are in bits 6 - 0 of the current
252248 * MSB register
....@@ -660,7 +656,7 @@
660656 return count;
661657 }
662658
663
-static const struct bin_attribute ds2781_param_eeprom_bin_attr = {
659
+static struct bin_attribute ds2781_param_eeprom_bin_attr = {
664660 .attr = {
665661 .name = "param_eeprom",
666662 .mode = S_IRUGO | S_IWUSR,
....@@ -706,7 +702,7 @@
706702 return count;
707703 }
708704
709
-static const struct bin_attribute ds2781_user_eeprom_bin_attr = {
705
+static struct bin_attribute ds2781_user_eeprom_bin_attr = {
710706 .attr = {
711707 .name = "user_eeprom",
712708 .mode = S_IRUGO | S_IWUSR,
....@@ -725,8 +721,7 @@
725721 static DEVICE_ATTR(pio_pin, S_IRUGO | S_IWUSR, ds2781_get_pio_pin,
726722 ds2781_set_pio_pin);
727723
728
-
729
-static struct attribute *ds2781_attributes[] = {
724
+static struct attribute *ds2781_sysfs_attrs[] = {
730725 &dev_attr_pmod_enabled.attr,
731726 &dev_attr_sense_resistor_value.attr,
732727 &dev_attr_rsgain_setting.attr,
....@@ -734,14 +729,26 @@
734729 NULL
735730 };
736731
737
-static const struct attribute_group ds2781_attr_group = {
738
- .attrs = ds2781_attributes,
732
+static struct bin_attribute *ds2781_sysfs_bin_attrs[] = {
733
+ &ds2781_param_eeprom_bin_attr,
734
+ &ds2781_user_eeprom_bin_attr,
735
+ NULL,
736
+};
737
+
738
+static const struct attribute_group ds2781_sysfs_group = {
739
+ .attrs = ds2781_sysfs_attrs,
740
+ .bin_attrs = ds2781_sysfs_bin_attrs,
741
+
742
+};
743
+
744
+static const struct attribute_group *ds2781_sysfs_groups[] = {
745
+ &ds2781_sysfs_group,
746
+ NULL,
739747 };
740748
741749 static int ds2781_battery_probe(struct platform_device *pdev)
742750 {
743751 struct power_supply_config psy_cfg = {};
744
- int ret = 0;
745752 struct ds2781_device_info *dev_info;
746753
747754 dev_info = devm_kzalloc(&pdev->dev, sizeof(*dev_info), GFP_KERNEL);
....@@ -759,61 +766,15 @@
759766 dev_info->bat_desc.get_property = ds2781_battery_get_property;
760767
761768 psy_cfg.drv_data = dev_info;
769
+ psy_cfg.attr_grp = ds2781_sysfs_groups;
762770
763
- dev_info->bat = power_supply_register(&pdev->dev, &dev_info->bat_desc,
764
- &psy_cfg);
771
+ dev_info->bat = devm_power_supply_register(&pdev->dev,
772
+ &dev_info->bat_desc,
773
+ &psy_cfg);
765774 if (IS_ERR(dev_info->bat)) {
766775 dev_err(dev_info->dev, "failed to register battery\n");
767
- ret = PTR_ERR(dev_info->bat);
768
- goto fail;
776
+ return PTR_ERR(dev_info->bat);
769777 }
770
-
771
- ret = sysfs_create_group(&dev_info->bat->dev.kobj, &ds2781_attr_group);
772
- if (ret) {
773
- dev_err(dev_info->dev, "failed to create sysfs group\n");
774
- goto fail_unregister;
775
- }
776
-
777
- ret = sysfs_create_bin_file(&dev_info->bat->dev.kobj,
778
- &ds2781_param_eeprom_bin_attr);
779
- if (ret) {
780
- dev_err(dev_info->dev,
781
- "failed to create param eeprom bin file");
782
- goto fail_remove_group;
783
- }
784
-
785
- ret = sysfs_create_bin_file(&dev_info->bat->dev.kobj,
786
- &ds2781_user_eeprom_bin_attr);
787
- if (ret) {
788
- dev_err(dev_info->dev,
789
- "failed to create user eeprom bin file");
790
- goto fail_remove_bin_file;
791
- }
792
-
793
- return 0;
794
-
795
-fail_remove_bin_file:
796
- sysfs_remove_bin_file(&dev_info->bat->dev.kobj,
797
- &ds2781_param_eeprom_bin_attr);
798
-fail_remove_group:
799
- sysfs_remove_group(&dev_info->bat->dev.kobj, &ds2781_attr_group);
800
-fail_unregister:
801
- power_supply_unregister(dev_info->bat);
802
-fail:
803
- return ret;
804
-}
805
-
806
-static int ds2781_battery_remove(struct platform_device *pdev)
807
-{
808
- struct ds2781_device_info *dev_info = platform_get_drvdata(pdev);
809
-
810
- /*
811
- * Remove attributes before unregistering power supply
812
- * because 'bat' will be freed on power_supply_unregister() call.
813
- */
814
- sysfs_remove_group(&dev_info->bat->dev.kobj, &ds2781_attr_group);
815
-
816
- power_supply_unregister(dev_info->bat);
817778
818779 return 0;
819780 }
....@@ -823,12 +784,11 @@
823784 .name = "ds2781-battery",
824785 },
825786 .probe = ds2781_battery_probe,
826
- .remove = ds2781_battery_remove,
827787 };
828788 module_platform_driver(ds2781_battery_driver);
829789
830790 MODULE_LICENSE("GPL");
831791 MODULE_AUTHOR("Renata Sayakhova <renata@oktetlabs.ru>");
832
-MODULE_DESCRIPTION("Maxim/Dallas DS2781 Stand-Alone Fuel Gauage IC driver");
792
+MODULE_DESCRIPTION("Maxim/Dallas DS2781 Stand-Alone Fuel Gauge IC driver");
833793 MODULE_ALIAS("platform:ds2781-battery");
834794