power: max17048: get max17408 changes from rel-roth
Hayden Du [Wed, 8 May 2013 14:22:23 +0000 (14:22 +0000)]
this change include following cl form rel-roth
* 4661889 power: max17048: Fix SOC update
* 6039c5a power: max17048: Correcting the rcompseg value
* 1a3d63e power: max17048: update charge full status to GUI
* 0ab023f power: max17048: fix compilation warning
* ce48a3d power: max17048: schedule initial work immediatly
* 985f1af power: max17048: update only when soc changes
* c27312c power: max17048: display correct charging status
* 73cf40a power: max17048: resolve charging status update issue

bug 1283546

Change-Id: I4431d28f973f117b2bcbf29e95f6be8f183dcaec
Signed-off-by: Hayden Du <haydend@nvidia.com>
Reviewed-on: http://git-master/r/226723
Reviewed-by: Riham Haidar <rhaidar@nvidia.com>
Tested-by: Riham Haidar <rhaidar@nvidia.com>

drivers/power/max17048_battery.c

index 495aca8..51c146f 100644 (file)
@@ -22,6 +22,7 @@
 #include <linux/power_supply.h>
 #include <linux/slab.h>
 #include <linux/max17048_battery.h>
+#include <linux/jiffies.h>
 
 #define MAX17048_VCELL         0x02
 #define MAX17048_SOC           0x04
@@ -39,7 +40,7 @@
 #define MAX17048_CMD           0xFF
 #define MAX17048_UNLOCK_VALUE  0x4a57
 #define MAX17048_RESET_VALUE   0x5400
-#define MAX17048_DELAY         1000
+#define MAX17048_DELAY      (30*HZ)
 #define MAX17048_BATTERY_FULL  100
 #define MAX17048_BATTERY_LOW   15
 #define MAX17048_VERSION_NO    0x11
@@ -66,12 +67,12 @@ struct max17048_chip {
        /* battery capacity */
        int capacity_level;
 
-       int lasttime_vcell;
        int lasttime_soc;
        int lasttime_status;
        int use_usb:1;
        int use_ac:1;
        int shutdown_complete;
+       int charge_complete;
        struct mutex mutex;
 };
 struct max17048_chip *max17048_data;
@@ -256,15 +257,20 @@ static void max17048_get_soc(struct i2c_client *client)
        else
                chip->soc = (uint16_t)soc >> 9;
 
-       if (chip->soc >= MAX17048_BATTERY_FULL) {
-               chip->soc = MAX17048_BATTERY_FULL;
+       if (chip->soc >= MAX17048_BATTERY_FULL && chip->charge_complete != 1)
+               chip->soc = MAX17048_BATTERY_FULL-1;
+
+       if (chip->soc >= MAX17048_BATTERY_FULL && chip->charge_complete) {
                chip->status = POWER_SUPPLY_STATUS_FULL;
+               chip->soc = MAX17048_BATTERY_FULL;
                chip->capacity_level = POWER_SUPPLY_CAPACITY_LEVEL_FULL;
                chip->health = POWER_SUPPLY_HEALTH_GOOD;
        } else if (chip->soc < MAX17048_BATTERY_LOW) {
+               chip->status = chip->lasttime_status;
                chip->health = POWER_SUPPLY_HEALTH_DEAD;
                chip->capacity_level = POWER_SUPPLY_CAPACITY_LEVEL_CRITICAL;
        } else {
+               chip->status = chip->lasttime_status;
                chip->health = POWER_SUPPLY_HEALTH_GOOD;
                chip->capacity_level = POWER_SUPPLY_CAPACITY_LEVEL_NORMAL;
        }
@@ -284,14 +290,9 @@ static void max17048_work(struct work_struct *work)
        max17048_get_vcell(chip->client);
        max17048_get_soc(chip->client);
 
-       if (chip->vcell != chip->lasttime_vcell ||
-               chip->soc != chip->lasttime_soc ||
+       if (chip->soc != chip->lasttime_soc ||
                chip->status != chip->lasttime_status) {
-
-               chip->lasttime_vcell = chip->vcell;
                chip->lasttime_soc = chip->soc;
-               chip->lasttime_status = chip->status;
-
                power_supply_changed(&chip->battery);
        }
 
@@ -303,7 +304,6 @@ void max17048_battery_status(int status,
 {
        if (!max17048_data)
                return;
-
        max17048_data->ac_online = 0;
        max17048_data->usb_online = 0;
 
@@ -313,10 +313,19 @@ void max17048_battery_status(int status,
                        max17048_data->ac_online = 1;
                else if (chrg_type == USB)
                        max17048_data->usb_online = 1;
-       } else
+       } else if (status == 4) {
+               max17048_data->charge_complete = 1;
+               max17048_data->soc = MAX17048_BATTERY_FULL;
+               max17048_data->status = POWER_SUPPLY_STATUS_FULL;
+               power_supply_changed(&max17048_data->battery);
+               return;
+       } else {
                max17048_data->status = POWER_SUPPLY_STATUS_DISCHARGING;
-
+               max17048_data->charge_complete = 0;
+       }
        power_supply_changed(&max17048_data->battery);
+
+       max17048_data->lasttime_status = max17048_data->status;
        if (max17048_data->use_usb)
                power_supply_changed(&max17048_data->usb);
        if (max17048_data->use_ac)
@@ -348,8 +357,8 @@ static int max17048_write_rcomp_seg(struct i2c_client *client,
        int ret;
        uint8_t rcomp_seg_table[16];
 
-       rs2 = (rcomp_seg >> 8) & 0xff;
-       rs1 = rcomp_seg & 0xff;
+       rs1 = (rcomp_seg >> 8) & 0xff;
+       rs2 = rcomp_seg & 0xff;
 
        rcomp_seg_table[0] = rcomp_seg_table[2] = rcomp_seg_table[4] =
                rcomp_seg_table[6] = rcomp_seg_table[8] = rcomp_seg_table[10] =
@@ -692,6 +701,8 @@ static int __devinit max17048_probe(struct i2c_client *client,
        chip->battery.properties        = max17048_battery_props;
        chip->battery.num_properties    = ARRAY_SIZE(max17048_battery_props);
        chip->status                    = POWER_SUPPLY_STATUS_DISCHARGING;
+       chip->lasttime_status   = POWER_SUPPLY_STATUS_DISCHARGING;
+       chip->charge_complete   = 0;
 
        ret = power_supply_register(&client->dev, &chip->battery);
        if (ret) {
@@ -728,7 +739,7 @@ static int __devinit max17048_probe(struct i2c_client *client,
        }
 
        INIT_DELAYED_WORK_DEFERRABLE(&chip->work, max17048_work);
-       schedule_delayed_work(&chip->work, MAX17048_DELAY);
+       schedule_delayed_work(&chip->work, 0);
 
        return 0;
 error: