hc
2023-12-09 b22da3d8526a935aa31e086e63f60ff3246cb61c
kernel/drivers/power/supply/ds2780_battery.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * 1-wire client/driver for the Maxim/Dallas DS2780 Stand-Alone Fuel Gauge IC
34 *
....@@ -6,11 +7,6 @@
67 * Author: Clifton Barnes <cabarnes@indesign-llc.com>
78 *
89 * Based on ds2760_battery and ds2782_battery drivers
9
- *
10
- * This program is free software; you can redistribute it and/or modify
11
- * it under the terms of the GNU General Public License version 2 as
12
- * published by the Free Software Foundation.
13
- *
1410 */
1511
1612 #include <linux/module.h>
....@@ -164,7 +160,7 @@
164160
165161 /*
166162 * The voltage value is located in 10 bits across the voltage MSB
167
- * and LSB registers in two's compliment form
163
+ * and LSB registers in two's complement form
168164 * Sign bit of the voltage value is in bit 7 of the voltage MSB register
169165 * Bits 9 - 3 of the voltage value are in bits 6 - 0 of the
170166 * voltage MSB register
....@@ -192,7 +188,7 @@
192188
193189 /*
194190 * The temperature value is located in 10 bits across the temperature
195
- * MSB and LSB registers in two's compliment form
191
+ * MSB and LSB registers in two's complement form
196192 * Sign bit of the temperature value is in bit 7 of the temperature
197193 * MSB register
198194 * Bits 9 - 3 of the temperature value are in bits 6 - 0 of the
....@@ -245,7 +241,7 @@
245241
246242 /*
247243 * The current value is located in 16 bits across the current MSB
248
- * and LSB registers in two's compliment form
244
+ * and LSB registers in two's complement form
249245 * Sign bit of the current value is in bit 7 of the current MSB register
250246 * Bits 14 - 8 of the current value are in bits 6 - 0 of the current
251247 * MSB register
....@@ -658,7 +654,7 @@
658654 return count;
659655 }
660656
661
-static const struct bin_attribute ds2780_param_eeprom_bin_attr = {
657
+static struct bin_attribute ds2780_param_eeprom_bin_attr = {
662658 .attr = {
663659 .name = "param_eeprom",
664660 .mode = S_IRUGO | S_IWUSR,
....@@ -703,7 +699,7 @@
703699 return count;
704700 }
705701
706
-static const struct bin_attribute ds2780_user_eeprom_bin_attr = {
702
+static struct bin_attribute ds2780_user_eeprom_bin_attr = {
707703 .attr = {
708704 .name = "user_eeprom",
709705 .mode = S_IRUGO | S_IWUSR,
....@@ -722,8 +718,7 @@
722718 static DEVICE_ATTR(pio_pin, S_IRUGO | S_IWUSR, ds2780_get_pio_pin,
723719 ds2780_set_pio_pin);
724720
725
-
726
-static struct attribute *ds2780_attributes[] = {
721
+static struct attribute *ds2780_sysfs_attrs[] = {
727722 &dev_attr_pmod_enabled.attr,
728723 &dev_attr_sense_resistor_value.attr,
729724 &dev_attr_rsgain_setting.attr,
....@@ -731,21 +726,30 @@
731726 NULL
732727 };
733728
734
-static const struct attribute_group ds2780_attr_group = {
735
- .attrs = ds2780_attributes,
729
+static struct bin_attribute *ds2780_sysfs_bin_attrs[] = {
730
+ &ds2780_param_eeprom_bin_attr,
731
+ &ds2780_user_eeprom_bin_attr,
732
+ NULL
733
+};
734
+
735
+static const struct attribute_group ds2780_sysfs_group = {
736
+ .attrs = ds2780_sysfs_attrs,
737
+ .bin_attrs = ds2780_sysfs_bin_attrs,
738
+};
739
+
740
+static const struct attribute_group *ds2780_sysfs_groups[] = {
741
+ &ds2780_sysfs_group,
742
+ NULL,
736743 };
737744
738745 static int ds2780_battery_probe(struct platform_device *pdev)
739746 {
740747 struct power_supply_config psy_cfg = {};
741
- int ret = 0;
742748 struct ds2780_device_info *dev_info;
743749
744750 dev_info = devm_kzalloc(&pdev->dev, sizeof(*dev_info), GFP_KERNEL);
745
- if (!dev_info) {
746
- ret = -ENOMEM;
747
- goto fail;
748
- }
751
+ if (!dev_info)
752
+ return -ENOMEM;
749753
750754 platform_set_drvdata(pdev, dev_info);
751755
....@@ -758,61 +762,15 @@
758762 dev_info->bat_desc.get_property = ds2780_battery_get_property;
759763
760764 psy_cfg.drv_data = dev_info;
765
+ psy_cfg.attr_grp = ds2780_sysfs_groups;
761766
762
- dev_info->bat = power_supply_register(&pdev->dev, &dev_info->bat_desc,
763
- &psy_cfg);
767
+ dev_info->bat = devm_power_supply_register(&pdev->dev,
768
+ &dev_info->bat_desc,
769
+ &psy_cfg);
764770 if (IS_ERR(dev_info->bat)) {
765771 dev_err(dev_info->dev, "failed to register battery\n");
766
- ret = PTR_ERR(dev_info->bat);
767
- goto fail;
772
+ return PTR_ERR(dev_info->bat);
768773 }
769
-
770
- ret = sysfs_create_group(&dev_info->bat->dev.kobj, &ds2780_attr_group);
771
- if (ret) {
772
- dev_err(dev_info->dev, "failed to create sysfs group\n");
773
- goto fail_unregister;
774
- }
775
-
776
- ret = sysfs_create_bin_file(&dev_info->bat->dev.kobj,
777
- &ds2780_param_eeprom_bin_attr);
778
- if (ret) {
779
- dev_err(dev_info->dev,
780
- "failed to create param eeprom bin file");
781
- goto fail_remove_group;
782
- }
783
-
784
- ret = sysfs_create_bin_file(&dev_info->bat->dev.kobj,
785
- &ds2780_user_eeprom_bin_attr);
786
- if (ret) {
787
- dev_err(dev_info->dev,
788
- "failed to create user eeprom bin file");
789
- goto fail_remove_bin_file;
790
- }
791
-
792
- return 0;
793
-
794
-fail_remove_bin_file:
795
- sysfs_remove_bin_file(&dev_info->bat->dev.kobj,
796
- &ds2780_param_eeprom_bin_attr);
797
-fail_remove_group:
798
- sysfs_remove_group(&dev_info->bat->dev.kobj, &ds2780_attr_group);
799
-fail_unregister:
800
- power_supply_unregister(dev_info->bat);
801
-fail:
802
- return ret;
803
-}
804
-
805
-static int ds2780_battery_remove(struct platform_device *pdev)
806
-{
807
- struct ds2780_device_info *dev_info = platform_get_drvdata(pdev);
808
-
809
- /*
810
- * Remove attributes before unregistering power supply
811
- * because 'bat' will be freed on power_supply_unregister() call.
812
- */
813
- sysfs_remove_group(&dev_info->bat->dev.kobj, &ds2780_attr_group);
814
-
815
- power_supply_unregister(dev_info->bat);
816774
817775 return 0;
818776 }
....@@ -822,12 +780,11 @@
822780 .name = "ds2780-battery",
823781 },
824782 .probe = ds2780_battery_probe,
825
- .remove = ds2780_battery_remove,
826783 };
827784
828785 module_platform_driver(ds2780_battery_driver);
829786
830787 MODULE_LICENSE("GPL");
831788 MODULE_AUTHOR("Clifton Barnes <cabarnes@indesign-llc.com>");
832
-MODULE_DESCRIPTION("Maxim/Dallas DS2780 Stand-Alone Fuel Gauage IC driver");
789
+MODULE_DESCRIPTION("Maxim/Dallas DS2780 Stand-Alone Fuel Gauge IC driver");
833790 MODULE_ALIAS("platform:ds2780-battery");