| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * 1-wire client/driver for the Maxim/Dallas DS2780 Stand-Alone Fuel Gauge IC |
|---|
| 3 | 4 | * |
|---|
| .. | .. |
|---|
| 6 | 7 | * Author: Clifton Barnes <cabarnes@indesign-llc.com> |
|---|
| 7 | 8 | * |
|---|
| 8 | 9 | * 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 | | - * |
|---|
| 14 | 10 | */ |
|---|
| 15 | 11 | |
|---|
| 16 | 12 | #include <linux/module.h> |
|---|
| .. | .. |
|---|
| 164 | 160 | |
|---|
| 165 | 161 | /* |
|---|
| 166 | 162 | * 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 |
|---|
| 168 | 164 | * Sign bit of the voltage value is in bit 7 of the voltage MSB register |
|---|
| 169 | 165 | * Bits 9 - 3 of the voltage value are in bits 6 - 0 of the |
|---|
| 170 | 166 | * voltage MSB register |
|---|
| .. | .. |
|---|
| 192 | 188 | |
|---|
| 193 | 189 | /* |
|---|
| 194 | 190 | * 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 |
|---|
| 196 | 192 | * Sign bit of the temperature value is in bit 7 of the temperature |
|---|
| 197 | 193 | * MSB register |
|---|
| 198 | 194 | * Bits 9 - 3 of the temperature value are in bits 6 - 0 of the |
|---|
| .. | .. |
|---|
| 245 | 241 | |
|---|
| 246 | 242 | /* |
|---|
| 247 | 243 | * 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 |
|---|
| 249 | 245 | * Sign bit of the current value is in bit 7 of the current MSB register |
|---|
| 250 | 246 | * Bits 14 - 8 of the current value are in bits 6 - 0 of the current |
|---|
| 251 | 247 | * MSB register |
|---|
| .. | .. |
|---|
| 658 | 654 | return count; |
|---|
| 659 | 655 | } |
|---|
| 660 | 656 | |
|---|
| 661 | | -static const struct bin_attribute ds2780_param_eeprom_bin_attr = { |
|---|
| 657 | +static struct bin_attribute ds2780_param_eeprom_bin_attr = { |
|---|
| 662 | 658 | .attr = { |
|---|
| 663 | 659 | .name = "param_eeprom", |
|---|
| 664 | 660 | .mode = S_IRUGO | S_IWUSR, |
|---|
| .. | .. |
|---|
| 703 | 699 | return count; |
|---|
| 704 | 700 | } |
|---|
| 705 | 701 | |
|---|
| 706 | | -static const struct bin_attribute ds2780_user_eeprom_bin_attr = { |
|---|
| 702 | +static struct bin_attribute ds2780_user_eeprom_bin_attr = { |
|---|
| 707 | 703 | .attr = { |
|---|
| 708 | 704 | .name = "user_eeprom", |
|---|
| 709 | 705 | .mode = S_IRUGO | S_IWUSR, |
|---|
| .. | .. |
|---|
| 722 | 718 | static DEVICE_ATTR(pio_pin, S_IRUGO | S_IWUSR, ds2780_get_pio_pin, |
|---|
| 723 | 719 | ds2780_set_pio_pin); |
|---|
| 724 | 720 | |
|---|
| 725 | | - |
|---|
| 726 | | -static struct attribute *ds2780_attributes[] = { |
|---|
| 721 | +static struct attribute *ds2780_sysfs_attrs[] = { |
|---|
| 727 | 722 | &dev_attr_pmod_enabled.attr, |
|---|
| 728 | 723 | &dev_attr_sense_resistor_value.attr, |
|---|
| 729 | 724 | &dev_attr_rsgain_setting.attr, |
|---|
| .. | .. |
|---|
| 731 | 726 | NULL |
|---|
| 732 | 727 | }; |
|---|
| 733 | 728 | |
|---|
| 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, |
|---|
| 736 | 743 | }; |
|---|
| 737 | 744 | |
|---|
| 738 | 745 | static int ds2780_battery_probe(struct platform_device *pdev) |
|---|
| 739 | 746 | { |
|---|
| 740 | 747 | struct power_supply_config psy_cfg = {}; |
|---|
| 741 | | - int ret = 0; |
|---|
| 742 | 748 | struct ds2780_device_info *dev_info; |
|---|
| 743 | 749 | |
|---|
| 744 | 750 | 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; |
|---|
| 749 | 753 | |
|---|
| 750 | 754 | platform_set_drvdata(pdev, dev_info); |
|---|
| 751 | 755 | |
|---|
| .. | .. |
|---|
| 758 | 762 | dev_info->bat_desc.get_property = ds2780_battery_get_property; |
|---|
| 759 | 763 | |
|---|
| 760 | 764 | psy_cfg.drv_data = dev_info; |
|---|
| 765 | + psy_cfg.attr_grp = ds2780_sysfs_groups; |
|---|
| 761 | 766 | |
|---|
| 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); |
|---|
| 764 | 770 | if (IS_ERR(dev_info->bat)) { |
|---|
| 765 | 771 | 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); |
|---|
| 768 | 773 | } |
|---|
| 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); |
|---|
| 816 | 774 | |
|---|
| 817 | 775 | return 0; |
|---|
| 818 | 776 | } |
|---|
| .. | .. |
|---|
| 822 | 780 | .name = "ds2780-battery", |
|---|
| 823 | 781 | }, |
|---|
| 824 | 782 | .probe = ds2780_battery_probe, |
|---|
| 825 | | - .remove = ds2780_battery_remove, |
|---|
| 826 | 783 | }; |
|---|
| 827 | 784 | |
|---|
| 828 | 785 | module_platform_driver(ds2780_battery_driver); |
|---|
| 829 | 786 | |
|---|
| 830 | 787 | MODULE_LICENSE("GPL"); |
|---|
| 831 | 788 | 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"); |
|---|
| 833 | 790 | MODULE_ALIAS("platform:ds2780-battery"); |
|---|