summaryrefslogtreecommitdiffstats
path: root/drivers/power
diff options
context:
space:
mode:
authorAndreas Dannenberg <dannenberg@ti.com>2015-09-28 17:34:00 -0500
committerSebastian Reichel <sre@kernel.org>2015-09-29 16:55:03 +0200
commit007ee5f65693fd7370c0f6e70269175ac2ed1a28 (patch)
tree7e97b2e6dc1dea9c58236c095d6d417813aaf329 /drivers/power
parent0cfbfde65aec4cd9ae4e7971f8a3e42c69e8e24f (diff)
downloadop-kernel-dev-007ee5f65693fd7370c0f6e70269175ac2ed1a28.zip
op-kernel-dev-007ee5f65693fd7370c0f6e70269175ac2ed1a28.tar.gz
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')
-rw-r--r--drivers/power/bq24257_charger.c53
1 files changed, 53 insertions, 0 deletions
diff --git a/drivers/power/bq24257_charger.c b/drivers/power/bq24257_charger.c
index db719bf..1fea2c7 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,
};
OpenPOWER on IntegriCloud