diff options
author | Andreas Dannenberg <dannenberg@ti.com> | 2015-09-29 01:34:00 +0300 |
---|---|---|
committer | Sebastian Reichel <sre@kernel.org> | 2015-09-29 17:55:03 +0300 |
commit | 007ee5f65693fd7370c0f6e70269175ac2ed1a28 (patch) | |
tree | 7e97b2e6dc1dea9c58236c095d6d417813aaf329 /drivers/power/bq24257_charger.c | |
parent | 0cfbfde65aec4cd9ae4e7971f8a3e42c69e8e24f (diff) | |
download | linux-007ee5f65693fd7370c0f6e70269175ac2ed1a28.tar.xz |
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>
Diffstat (limited to 'drivers/power/bq24257_charger.c')
-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, bq24257_vindpm_map[bq->init_data.vindpm]); } +static ssize_t bq24257_sysfs_show_enable(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + struct power_supply *psy = dev_get_drvdata(dev); + struct bq24257_device *bq = power_supply_get_drvdata(psy); + int ret; + + if (strcmp(attr->attr.name, "high_impedance_enable") == 0) + ret = bq24257_field_read(bq, F_HZ_MODE); + else if (strcmp(attr->attr.name, "sysoff_enable") == 0) + ret = bq24257_field_read(bq, F_SYSOFF); + else + return -EINVAL; + + if (ret < 0) + return ret; + + return scnprintf(buf, PAGE_SIZE, "%d\n", ret); +} + +static ssize_t bq24257_sysfs_set_enable(struct device *dev, + struct device_attribute *attr, + const char *buf, + size_t count) +{ + struct power_supply *psy = dev_get_drvdata(dev); + struct bq24257_device *bq = power_supply_get_drvdata(psy); + long val; + int ret; + + if (kstrtol(buf, 10, &val) < 0) + return -EINVAL; + + if (strcmp(attr->attr.name, "high_impedance_enable") == 0) + ret = bq24257_field_write(bq, F_HZ_MODE, (bool)val); + else if (strcmp(attr->attr.name, "sysoff_enable") == 0) + ret = bq24257_field_write(bq, F_SYSOFF, (bool)val); + else + return -EINVAL; + + if (ret < 0) + return ret; + + return count; +} + static DEVICE_ATTR(ovp_voltage, S_IRUGO, bq24257_show_ovp_voltage, NULL); static DEVICE_ATTR(in_dpm_voltage, S_IRUGO, bq24257_show_in_dpm_voltage, NULL); +static DEVICE_ATTR(high_impedance_enable, S_IWUSR | S_IRUGO, + bq24257_sysfs_show_enable, bq24257_sysfs_set_enable); +static DEVICE_ATTR(sysoff_enable, S_IWUSR | S_IRUGO, + bq24257_sysfs_show_enable, bq24257_sysfs_set_enable); static struct attribute *bq24257_charger_attr[] = { &dev_attr_ovp_voltage.attr, &dev_attr_in_dpm_voltage.attr, + &dev_attr_high_impedance_enable.attr, + &dev_attr_sysoff_enable.attr, NULL, }; |