]> rtime.felk.cvut.cz Git - sojka/nv-tegra/linux-3.10.git/commitdiff
power: lc709203f: add support for CURRENT_NOW property
authorLaxman Dewangan <ldewangan@nvidia.com>
Sun, 13 Apr 2014 05:49:41 +0000 (11:19 +0530)
committerLaxman Dewangan <ldewangan@nvidia.com>
Sun, 13 Apr 2014 12:39:00 +0000 (05:39 -0700)
Add support for measuring battery current now if the device
node has required properties to read the battery current.

bug 1413219

Change-Id: Ie0e1cf61306ce0f5fdd7611a54781fc003c8156e
Signed-off-by: Laxman Dewangan <ldewangan@nvidia.com>
Reviewed-on: http://git-master/r/395552

drivers/power/lc709203f_battery.c

index d8955ed09b3ce1320bcfcc1f40783d356b1199c4..c7b43639e6e4a72ffebecc7c63606b7d474dadbe 100644 (file)
@@ -63,6 +63,7 @@ struct lc709203f_platform_data {
        u32 maximum_soc;
        u32 alert_low_rsoc;
        u32 alert_low_voltage;
+       bool support_battery_current;
 };
 
 struct lc709203f_chip {
@@ -215,6 +216,7 @@ static enum power_supply_property lc709203f_battery_props[] = {
        POWER_SUPPLY_PROP_PRESENT,
        POWER_SUPPLY_PROP_CAPACITY_LEVEL,
        POWER_SUPPLY_PROP_TEMP,
+       POWER_SUPPLY_PROP_CURRENT_NOW,
 };
 
 static int lc709203f_get_property(struct power_supply *psy,
@@ -224,6 +226,8 @@ static int lc709203f_get_property(struct power_supply *psy,
        struct lc709203f_chip *chip = container_of(psy,
                                struct lc709203f_chip, battery);
        int temperature;
+       int curr_ma;
+       int ret;
 
        switch (psp) {
        case POWER_SUPPLY_PROP_TECHNOLOGY:
@@ -265,6 +269,12 @@ static int lc709203f_get_property(struct power_supply *psy,
                */
                val->intval = temperature - 2732;
                break;
+       case POWER_SUPPLY_PROP_CURRENT_NOW:
+               val->intval = 0;
+               ret = battery_gauge_get_battery_current(chip->bg_dev, &curr_ma);
+               if (!ret)
+                       val->intval = curr_ma;
+               break;
        default:
                return -EINVAL;
        }
@@ -301,6 +311,7 @@ static struct battery_gauge_ops lc709203f_bg_ops = {
 static struct battery_gauge_info lc709203f_bgi = {
        .cell_id = 0,
        .bg_ops = &lc709203f_bg_ops,
+       .current_channel_name = "battery-current",
 };
 
 static irqreturn_t lc709203f_irq(int id, void *dev)
@@ -371,6 +382,9 @@ static void of_lc709203f_parse_platform_data(struct i2c_client *client,
        ret = of_property_read_u32(np, "onsemi,alert-low-voltage", &pval);
        if (!ret)
                pdata->alert_low_voltage = pval;
+
+       pdata->support_battery_current = of_property_read_bool(np,
+                                               "io-channel-names");
 }
 
 #ifdef CONFIG_DEBUG_FS
@@ -544,6 +558,10 @@ skip_thermistor_config:
        chip->lasttime_status           = POWER_SUPPLY_STATUS_DISCHARGING;
        chip->charge_complete           = 0;
 
+       /* Remove current property if it is not supported */
+       if (!chip->pdata->support_battery_current)
+               chip->battery.num_properties--;
+
        ret = power_supply_register(&client->dev, &chip->battery);
        if (ret) {
                dev_err(&client->dev, "failed: power supply register\n");