power: max17048: Add 18-bit model SOC calculate.
Hyongbin Kim [Fri, 24 May 2013 06:48:11 +0000 (15:48 +0900)]
When model data is 18-bit, 1LSb=1%SOC.

Bug 1293141

Change-Id: I247bfa1fa5a6ee1c442a5e7f5cb647df4cdda0f0
Signed-off-by: Hyongbin Kim <hyongbink@nvidia.com>
Reviewed-on: http://git-master/r/232468
Reviewed-by: Riham Haidar <rhaidar@nvidia.com>
Tested-by: Riham Haidar <rhaidar@nvidia.com>

drivers/power/max17048_battery.c

index a74cfe2..f72d518 100644 (file)
@@ -261,13 +261,18 @@ static void max17048_get_vcell(struct i2c_client *client)
 static void max17048_get_soc(struct i2c_client *client)
 {
        struct max17048_chip *chip = i2c_get_clientdata(client);
+       struct max17048_battery_model *mdata = chip->pdata->model_data;
        int soc;
 
        soc = max17048_read_word(client, MAX17048_SOC);
        if (soc < 0)
                dev_err(&client->dev, "%s: err %d\n", __func__, soc);
-       else
-               chip->soc = (uint16_t)soc >> 9;
+       else {
+               if (mdata->bits == 18)
+                       chip->soc = (uint16_t)soc >> 8;
+               else
+                       chip->soc = (uint16_t)soc >> 9;
+       }
 
        if (chip->soc >= MAX17048_BATTERY_FULL && chip->charge_complete != 1)
                chip->soc = MAX17048_BATTERY_FULL-1;