power: max17048: disable SC alert in LP0
Hyongbin Kim [Fri, 26 Jul 2013 02:44:58 +0000 (11:44 +0900)]
For prevent system wakeup when SOC changed, clear CONFIG.ALSC when enter
suspend and re-set to 1 when resume.
In low SOC, we can wakeup from HD(SOC low) alert.

Bug 1333630

Change-Id: I535b6a29311d61a76c2984b8e413db50f3eced64
Signed-off-by: Hyongbin Kim <hyongbink@nvidia.com>
Reviewed-on: http://git-master/r/253969
(cherry picked from commit c9663967a8a691be0d9d08f01d764697bacd7980)
Reviewed-on: http://git-master/r/289146
Reviewed-by: Automatic_Commit_Validation_User
GVS: Gerrit_Virtual_Submit
Reviewed-by: Gabby Lee <galee@nvidia.com>

drivers/power/max17048_battery.c

index 5f90ea6..a3e8a7b 100644 (file)
@@ -1082,6 +1082,25 @@ static int max17048_suspend(struct i2c_client *client,
 {
        struct max17048_chip *chip = i2c_get_clientdata(client);
        int ret;
+       struct max17048_battery_model *mdata = chip->pdata->model_data;
+       u16 val;
+
+       /* clear CONFIG.ALSC */
+       if (mdata->one_percent_alerts) {
+               val = max17048_read_word(client, MAX17048_CONFIG);
+               if (val < 0) {
+                       dev_err(&client->dev,
+                                       "%s(): Failed in reading register" \
+                                       "MAX17048_CONFIG err %d\n",
+                                               __func__, val);
+               } else {
+                       val &= ~(mdata->one_percent_alerts);
+                       ret = max17048_write_word(client, MAX17048_CONFIG, val);
+                       if (ret < 0)
+                               dev_err(&client->dev,
+                                       "failed clear CONFIG.ALSC\n");
+               }
+       }
 
        if (device_may_wakeup(&client->dev)) {
                enable_irq_wake(chip->client->irq);
@@ -1101,6 +1120,7 @@ static int max17048_resume(struct i2c_client *client)
        struct max17048_chip *chip = i2c_get_clientdata(client);
        int ret;
        struct max17048_battery_model *mdata = chip->pdata->model_data;
+       u16 val;
 
        ret = max17048_write_word(client, MAX17048_HIBRT, mdata->hibernate);
        if (ret < 0) {
@@ -1113,6 +1133,23 @@ static int max17048_resume(struct i2c_client *client)
                disable_irq_wake(client->irq);
        }
 
+       /* set CONFIG.ALSC */
+       if (mdata->one_percent_alerts) {
+               val = max17048_read_word(client, MAX17048_CONFIG);
+               if (val < 0) {
+                       dev_err(&client->dev,
+                                       "%s(): Failed in reading register" \
+                                       "MAX17048_CONFIG err %d\n",
+                                               __func__, val);
+               } else {
+                       val |= mdata->one_percent_alerts;
+                       ret = max17048_write_word(client, MAX17048_CONFIG, val);
+                       if (ret < 0)
+                               dev_err(&client->dev,
+                                       "failed set CONFIG.ALSC\n");
+               }
+       }
+
        return 0;
 }