.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | /* |
---|
2 | 3 | * 1-wire client/driver for the Maxim/Dallas DS2781 Stand-Alone Fuel Gauge IC |
---|
3 | 4 | * |
---|
4 | 5 | * Author: Renata Sayakhova <renata@oktetlabs.ru> |
---|
5 | 6 | * |
---|
6 | 7 | * 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 | | - * |
---|
12 | 8 | */ |
---|
13 | 9 | |
---|
14 | 10 | #include <linux/module.h> |
---|
.. | .. |
---|
172 | 168 | return ret; |
---|
173 | 169 | /* |
---|
174 | 170 | * 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 |
---|
176 | 172 | * Sign bit of the voltage value is in bit 7 of the voltage MSB register |
---|
177 | 173 | * Bits 9 - 3 of the voltage value are in bits 6 - 0 of the |
---|
178 | 174 | * voltage MSB register |
---|
.. | .. |
---|
201 | 197 | return ret; |
---|
202 | 198 | /* |
---|
203 | 199 | * 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 |
---|
205 | 201 | * Sign bit of the temperature value is in bit 7 of the temperature |
---|
206 | 202 | * MSB register |
---|
207 | 203 | * Bits 9 - 3 of the temperature value are in bits 6 - 0 of the |
---|
.. | .. |
---|
246 | 242 | |
---|
247 | 243 | /* |
---|
248 | 244 | * 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 |
---|
250 | 246 | * Sign bit of the current value is in bit 7 of the current MSB register |
---|
251 | 247 | * Bits 14 - 8 of the current value are in bits 6 - 0 of the current |
---|
252 | 248 | * MSB register |
---|
.. | .. |
---|
660 | 656 | return count; |
---|
661 | 657 | } |
---|
662 | 658 | |
---|
663 | | -static const struct bin_attribute ds2781_param_eeprom_bin_attr = { |
---|
| 659 | +static struct bin_attribute ds2781_param_eeprom_bin_attr = { |
---|
664 | 660 | .attr = { |
---|
665 | 661 | .name = "param_eeprom", |
---|
666 | 662 | .mode = S_IRUGO | S_IWUSR, |
---|
.. | .. |
---|
706 | 702 | return count; |
---|
707 | 703 | } |
---|
708 | 704 | |
---|
709 | | -static const struct bin_attribute ds2781_user_eeprom_bin_attr = { |
---|
| 705 | +static struct bin_attribute ds2781_user_eeprom_bin_attr = { |
---|
710 | 706 | .attr = { |
---|
711 | 707 | .name = "user_eeprom", |
---|
712 | 708 | .mode = S_IRUGO | S_IWUSR, |
---|
.. | .. |
---|
725 | 721 | static DEVICE_ATTR(pio_pin, S_IRUGO | S_IWUSR, ds2781_get_pio_pin, |
---|
726 | 722 | ds2781_set_pio_pin); |
---|
727 | 723 | |
---|
728 | | - |
---|
729 | | -static struct attribute *ds2781_attributes[] = { |
---|
| 724 | +static struct attribute *ds2781_sysfs_attrs[] = { |
---|
730 | 725 | &dev_attr_pmod_enabled.attr, |
---|
731 | 726 | &dev_attr_sense_resistor_value.attr, |
---|
732 | 727 | &dev_attr_rsgain_setting.attr, |
---|
.. | .. |
---|
734 | 729 | NULL |
---|
735 | 730 | }; |
---|
736 | 731 | |
---|
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, |
---|
739 | 747 | }; |
---|
740 | 748 | |
---|
741 | 749 | static int ds2781_battery_probe(struct platform_device *pdev) |
---|
742 | 750 | { |
---|
743 | 751 | struct power_supply_config psy_cfg = {}; |
---|
744 | | - int ret = 0; |
---|
745 | 752 | struct ds2781_device_info *dev_info; |
---|
746 | 753 | |
---|
747 | 754 | dev_info = devm_kzalloc(&pdev->dev, sizeof(*dev_info), GFP_KERNEL); |
---|
.. | .. |
---|
759 | 766 | dev_info->bat_desc.get_property = ds2781_battery_get_property; |
---|
760 | 767 | |
---|
761 | 768 | psy_cfg.drv_data = dev_info; |
---|
| 769 | + psy_cfg.attr_grp = ds2781_sysfs_groups; |
---|
762 | 770 | |
---|
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); |
---|
765 | 774 | if (IS_ERR(dev_info->bat)) { |
---|
766 | 775 | 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); |
---|
769 | 777 | } |
---|
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); |
---|
817 | 778 | |
---|
818 | 779 | return 0; |
---|
819 | 780 | } |
---|
.. | .. |
---|
823 | 784 | .name = "ds2781-battery", |
---|
824 | 785 | }, |
---|
825 | 786 | .probe = ds2781_battery_probe, |
---|
826 | | - .remove = ds2781_battery_remove, |
---|
827 | 787 | }; |
---|
828 | 788 | module_platform_driver(ds2781_battery_driver); |
---|
829 | 789 | |
---|
830 | 790 | MODULE_LICENSE("GPL"); |
---|
831 | 791 | 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"); |
---|
833 | 793 | MODULE_ALIAS("platform:ds2781-battery"); |
---|
834 | 794 | |
---|