power: bq24257: Add various device-specific sysfs properties
authorAndreas Dannenberg <dannenberg@ti.com>
Mon, 28 Sep 2015 22:34:00 +0000 (17:34 -0500)
committerSebastian Reichel <sre@kernel.org>
Tue, 29 Sep 2015 14:55:03 +0000 (16:55 +0200)
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>
drivers/power/bq24257_charger.c

index db719bf96452991a62bb6d6a80049d494640f4dd..1fea2c7ef97feda56cfc71f9b1ab82e7d3d35351 100644 (file)
@@ -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,
 };