power: max17042: update status contineously
Syed Rafiuddin [Fri, 28 Sep 2012 12:00:25 +0000 (17:00 +0530)]
update battery characterstics contineously so that
the status gets updated in gui

Change-Id: I50ccc6484825a730edf7e7b01f6ea187bf7215db
Signed-off-by: Syed Rafiuddin <srafiuddin@nvidia.com>
Reviewed-on: http://git-master/r/135118
(cherry picked from commit 7200ea672e9c4569bb26773ba5c68ca802fd2182)
Signed-off-by: Gaurav Batra <gbatra@nvidia.com>
Reviewed-on: http://git-master/r/146691
Reviewed-by: Simone Willett <swillett@nvidia.com>
Tested-by: Simone Willett <swillett@nvidia.com>

drivers/power/max17042_battery.c
include/linux/power/max17042_battery.h

index 74abc6c..a86ba64 100644 (file)
 
 #define MAX17042_IC_VERSION    0x0092
 #define MAX17047_IC_VERSION    0x00AC  /* same for max17050 */
+#define MAX17047_DELAY         1000
 
 struct max17042_chip {
        struct i2c_client *client;
        struct power_supply battery;
        enum max170xx_chip_type chip_type;
        struct max17042_platform_data *pdata;
-       struct work_struct work;
+       struct delayed_work work;
        int    init_complete;
 };
 
+struct i2c_client *temp_client;
+
 static int max17042_write_reg(struct i2c_client *client, u8 reg, u16 value)
 {
        int ret = i2c_smbus_write_word_data(client, reg, value);
@@ -119,6 +122,27 @@ static enum power_supply_property max17042_battery_props[] = {
        POWER_SUPPLY_PROP_CURRENT_AVG,
 };
 
+int maxim_get_temp()
+{
+       int ret = 0xff;
+       if (temp_client != NULL) {
+               ret = max17042_read_reg(temp_client, MAX17042_TEMP);
+               if (ret < 0)
+                       return ret;
+
+               /* The value is signed. */
+               if (ret & 0x8000) {
+                       ret = (0x7fff & ~ret) + 1;
+                       ret *= -1;
+               }
+               /* The value is converted into deci-centigrade scale */
+               /* Units of LSB = 1 / 256 degree Celsius */
+               ret = ret * 10 / 256;
+       }
+       return ret;
+}
+EXPORT_SYMBOL_GPL(maxim_get_temp);
+
 static int max17042_get_property(struct power_supply *psy,
                            enum power_supply_property psp,
                            union power_supply_propval *val)
@@ -634,17 +658,10 @@ static irqreturn_t max17042_thread_handler(int id, void *dev)
 static void max17042_init_worker(struct work_struct *work)
 {
        struct max17042_chip *chip = container_of(work,
-                               struct max17042_chip, work);
+                               struct max17042_chip, work.work);
        int ret;
-
-       /* Initialize registers according to values from the platform data */
-       if (chip->pdata->enable_por_init && chip->pdata->config_data) {
-               ret = max17042_init_chip(chip);
-               if (ret)
-                       return;
-       }
-
-       chip->init_complete = 1;
+       power_supply_changed(&chip->battery);
+       schedule_delayed_work(&chip->work, MAX17047_DELAY);
 }
 
 #ifdef CONFIG_OF
@@ -697,6 +714,7 @@ static int __devinit max17042_probe(struct i2c_client *client,
                return -ENOMEM;
 
        chip->client = client;
+       temp_client = client;
        chip->pdata = max17042_get_pdata(&client->dev);
        if (!chip->pdata) {
                dev_err(&client->dev, "no platform data provided\n");
@@ -766,12 +784,18 @@ static int __devinit max17042_probe(struct i2c_client *client,
 
        reg = max17042_read_reg(chip->client, MAX17042_STATUS);
        if (reg & STATUS_POR_BIT) {
-               INIT_WORK(&chip->work, max17042_init_worker);
-               schedule_work(&chip->work);
+               if (chip->pdata->enable_por_init && chip->pdata->config_data) {
+                       ret = max17042_init_chip(chip);
+                       if (ret)
+                               return ret;
+               }
        } else {
                chip->init_complete = 1;
        }
 
+       INIT_DELAYED_WORK_DEFERRABLE(&chip->work, max17042_init_worker);
+       schedule_work(&chip->work);
+
        return 0;
 }
 
index 89dd84f..37c8702 100644 (file)
@@ -210,4 +210,5 @@ struct max17042_platform_data {
        unsigned int r_sns;
 };
 
+extern int maxim_get_temp(void);
 #endif /* __MAX17042_BATTERY_H_ */