power: Add property CHARGE_COUNTER_EXT and 64-bit precision properties
authorTodd Poynor <toddpoynor@google.com>
Thu, 12 Dec 2013 23:59:09 +0000 (15:59 -0800)
committerRuchi Kandoi <kandoiruchi@google.com>
Tue, 17 Jun 2014 02:18:07 +0000 (02:18 +0000)
Add POWER_SUPPLY_PROP_CHARGE_COUNTER_EXT that stores accumulated charge
in nAh units as a signed 64-bit value.

Add generic support for signed 64-bit property values.

Change-Id: I2bd34b1e95ffba24e7bfef81f398f22bd2aaf05e
Signed-off-by: Todd Poynor <toddpoynor@google.com>
drivers/power/power_supply_sysfs.c
include/linux/power_supply.h

index 5a5fef4447e35638a9866b3890ae0d0d3df0273c..1f7d79b03725fcb6aad3c8ccfef0549fc7d6e85c 100644 (file)
@@ -105,7 +105,10 @@ static ssize_t power_supply_show_property(struct device *dev,
        else if (off >= POWER_SUPPLY_PROP_MODEL_NAME)
                return sprintf(buf, "%s\n", value.strval);
 
-       return sprintf(buf, "%d\n", value.intval);
+       if (off == POWER_SUPPLY_PROP_CHARGE_COUNTER_EXT)
+               return sprintf(buf, "%lld\n", value.int64val);
+       else
+               return sprintf(buf, "%d\n", value.intval);
 }
 
 static ssize_t power_supply_store_property(struct device *dev,
@@ -193,6 +196,8 @@ static struct device_attribute power_supply_attrs[] = {
        POWER_SUPPLY_ATTR(usb_hc),
        POWER_SUPPLY_ATTR(usb_otg),
        POWER_SUPPLY_ATTR(charge_enabled),
+       /* Local extensions of type int64_t */
+       POWER_SUPPLY_ATTR(charge_counter_ext),
        /* Properties of type `const char *' */
        POWER_SUPPLY_ATTR(model_name),
        POWER_SUPPLY_ATTR(manufacturer),
index 19778d7cb4b47ef40f5761384665376cae5228ab..03d921feb09489060c6afabf2648fd34673a4ab1 100644 (file)
@@ -15,6 +15,7 @@
 
 #include <linux/workqueue.h>
 #include <linux/leds.h>
+#include <linux/types.h>
 
 struct device;
 
@@ -144,6 +145,8 @@ enum power_supply_property {
        POWER_SUPPLY_PROP_USB_HC,
        POWER_SUPPLY_PROP_USB_OTG,
        POWER_SUPPLY_PROP_CHARGE_ENABLED,
+       /* Local extensions of type int64_t */
+       POWER_SUPPLY_PROP_CHARGE_COUNTER_EXT,
        /* Properties of type `const char *' */
        POWER_SUPPLY_PROP_MODEL_NAME,
        POWER_SUPPLY_PROP_MANUFACTURER,
@@ -164,6 +167,7 @@ enum power_supply_type {
 union power_supply_propval {
        int intval;
        const char *strval;
+       int64_t int64val;
 };
 
 struct power_supply {