mfd: max77663: Add sleep_enable into suspend operation
Jin Park [Tue, 22 Nov 2011 12:50:29 +0000 (21:50 +0900)]
To making robust sleep and wakeup, added sleep_enable into
suspend operation.

Bug 849360
Bug 903301

Reviewed-on: http://git-master/r/66322
(cherry picked from commit ea059cd32c67c72b57000cc5a969741dbf37770d)

Change-Id: I0bafbb3e4d589c0db0842a87132e0cf70e722af3
Signed-off-by: Jin Park <jinyoungp@nvidia.com>
Reviewed-on: http://git-master/r/67381
Reviewed-by: Bharat Nihalani <bnihalani@nvidia.com>

drivers/mfd/max77663-core.c

index d428642..38d1956 100644 (file)
@@ -357,6 +357,9 @@ int max77663_power_off(void)
 {
        struct max77663_chip *chip = max77663_chip;
 
+       if (!chip)
+               return -EINVAL;
+
        dev_info(chip->dev, "%s: Global shutdown\n", __func__);
        return max77663_set_bits(chip->dev, MAX77663_REG_ONOFF_CFG1,
                                 ONOFF_SFT_RST_MASK, ONOFF_SFT_RST_MASK, 0);
@@ -365,18 +368,10 @@ EXPORT_SYMBOL(max77663_power_off);
 
 static int max77663_sleep_enable(struct max77663_chip *chip)
 {
-       int ret;
-
        /* Enable sleep that AP can be placed into sleep mode
         * by pulling EN1 low */
-       ret = max77663_set_bits(chip->dev, MAX77663_REG_ONOFF_CFG1,
-                               ONOFF_SLPEN_MASK, ONOFF_SLPEN_MASK, 0);
-       if (ret < 0)
-               dev_err(chip->dev,
-                       "sleep_enable: Failed to set on/off config1\n",
-                       MAX77663_REG_ONOFF_CFG1);
-
-       return ret;
+       return max77663_set_bits(chip->dev, MAX77663_REG_ONOFF_CFG1,
+                                ONOFF_SLPEN_MASK, ONOFF_SLPEN_MASK, 0);
 }
 
 static inline int max77663_cache_write(struct device *dev, u8 addr, u8 mask,
@@ -1333,23 +1328,34 @@ static int __devexit max77663_remove(struct i2c_client *client)
 static int max77663_suspend(struct device *dev)
 {
        struct i2c_client *client = to_i2c_client(dev);
+       struct max77663_chip *chip = i2c_get_clientdata(client);
+       int ret;
 
        if (client->irq)
                disable_irq(client->irq);
 
-       return 0;
+       ret = max77663_sleep_enable(chip);
+       if (ret < 0)
+               dev_err(dev, "suspend: Failed to enable sleep\n");
+
+       return ret;
 }
 
 static int max77663_resume(struct device *dev)
 {
        struct i2c_client *client = to_i2c_client(dev);
        struct max77663_chip *chip = i2c_get_clientdata(client);
+       int ret;
+
+       ret = max77663_sleep_enable(chip);
+       if (ret < 0) {
+               dev_err(dev, "resume: Failed to enable sleep\n");
+               return ret;
+       }
 
        if (client->irq)
                enable_irq(client->irq);
 
-       max77663_sleep_enable(chip);
-
        return 0;
 }
 #else