diff options
author | Andreas Dannenberg <dannenberg@ti.com> | 2015-09-28 18:34:00 -0400 |
---|---|---|
committer | Sebastian Reichel <sre@kernel.org> | 2015-09-29 10:55:03 -0400 |
commit | 007ee5f65693fd7370c0f6e70269175ac2ed1a28 (patch) | |
tree | 7e97b2e6dc1dea9c58236c095d6d417813aaf329 | |
parent | 0cfbfde65aec4cd9ae4e7971f8a3e42c69e8e24f (diff) |
power: bq24257: Add various device-specific sysfs properties
This patch adds support for enabling/disabling optional device specific
features through sysfs properties at runtime.
* High-impedance mode enable/disable
* Sysoff enable/disable
Refer to the respective device datasheets for more information:
http://www.ti.com/product/bq24250
http://www.ti.com/product/bq24251
http://www.ti.com/product/bq24257
Signed-off-by: Andreas Dannenberg <dannenberg@ti.com>
Reviewed-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>
Signed-off-by: Sebastian Reichel <sre@kernel.org>
-rw-r--r-- | drivers/power/bq24257_charger.c | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/drivers/power/bq24257_charger.c b/drivers/power/bq24257_charger.c index db719bf96452..1fea2c7ef97f 100644 --- a/drivers/power/bq24257_charger.c +++ b/drivers/power/bq24257_charger.c | |||
@@ -791,12 +791,65 @@ static ssize_t bq24257_show_in_dpm_voltage(struct device *dev, | |||
791 | bq24257_vindpm_map[bq->init_data.vindpm]); | 791 | bq24257_vindpm_map[bq->init_data.vindpm]); |
792 | } | 792 | } |
793 | 793 | ||
794 | static ssize_t bq24257_sysfs_show_enable(struct device *dev, | ||
795 | struct device_attribute *attr, | ||
796 | char *buf) | ||
797 | { | ||
798 | struct power_supply *psy = dev_get_drvdata(dev); | ||
799 | struct bq24257_device *bq = power_supply_get_drvdata(psy); | ||
800 | int ret; | ||
801 | |||
802 | if (strcmp(attr->attr.name, "high_impedance_enable") == 0) | ||
803 | ret = bq24257_field_read(bq, F_HZ_MODE); | ||
804 | else if (strcmp(attr->attr.name, "sysoff_enable") == 0) | ||
805 | ret = bq24257_field_read(bq, F_SYSOFF); | ||
806 | else | ||
807 | return -EINVAL; | ||
808 | |||
809 | if (ret < 0) | ||
810 | return ret; | ||
811 | |||
812 | return scnprintf(buf, PAGE_SIZE, "%d\n", ret); | ||
813 | } | ||
814 | |||
815 | static ssize_t bq24257_sysfs_set_enable(struct device *dev, | ||
816 | struct device_attribute *attr, | ||
817 | const char *buf, | ||
818 | size_t count) | ||
819 | { | ||
820 | struct power_supply *psy = dev_get_drvdata(dev); | ||
821 | struct bq24257_device *bq = power_supply_get_drvdata(psy); | ||
822 | long val; | ||
823 | int ret; | ||
824 | |||
825 | if (kstrtol(buf, 10, &val) < 0) | ||
826 | return -EINVAL; | ||
827 | |||
828 | if (strcmp(attr->attr.name, "high_impedance_enable") == 0) | ||
829 | ret = bq24257_field_write(bq, F_HZ_MODE, (bool)val); | ||
830 | else if (strcmp(attr->attr.name, "sysoff_enable") == 0) | ||
831 | ret = bq24257_field_write(bq, F_SYSOFF, (bool)val); | ||
832 | else | ||
833 | return -EINVAL; | ||
834 | |||
835 | if (ret < 0) | ||
836 | return ret; | ||
837 | |||
838 | return count; | ||
839 | } | ||
840 | |||
794 | static DEVICE_ATTR(ovp_voltage, S_IRUGO, bq24257_show_ovp_voltage, NULL); | 841 | static DEVICE_ATTR(ovp_voltage, S_IRUGO, bq24257_show_ovp_voltage, NULL); |
795 | static DEVICE_ATTR(in_dpm_voltage, S_IRUGO, bq24257_show_in_dpm_voltage, NULL); | 842 | static DEVICE_ATTR(in_dpm_voltage, S_IRUGO, bq24257_show_in_dpm_voltage, NULL); |
843 | static DEVICE_ATTR(high_impedance_enable, S_IWUSR | S_IRUGO, | ||
844 | bq24257_sysfs_show_enable, bq24257_sysfs_set_enable); | ||
845 | static DEVICE_ATTR(sysoff_enable, S_IWUSR | S_IRUGO, | ||
846 | bq24257_sysfs_show_enable, bq24257_sysfs_set_enable); | ||
796 | 847 | ||
797 | static struct attribute *bq24257_charger_attr[] = { | 848 | static struct attribute *bq24257_charger_attr[] = { |
798 | &dev_attr_ovp_voltage.attr, | 849 | &dev_attr_ovp_voltage.attr, |
799 | &dev_attr_in_dpm_voltage.attr, | 850 | &dev_attr_in_dpm_voltage.attr, |
851 | &dev_attr_high_impedance_enable.attr, | ||
852 | &dev_attr_sysoff_enable.attr, | ||
800 | NULL, | 853 | NULL, |
801 | }; | 854 | }; |
802 | 855 | ||