mfd: Wake-up from Suspend MAX8997 support
authorMyungJoo Ham <myungjoo.ham@samsung.com>
Fri, 19 Aug 2011 05:39:40 +0000 (14:39 +0900)
committerSamuel Ortiz <sameo@linux.intel.com>
Mon, 24 Oct 2011 12:09:11 +0000 (14:09 +0200)
- Support wake-up from suspend-to-ram.
- Handle pending interrupt after a resume.
- If pdata->wakeup is enabled, by default, the device is assumed to be
capable of wakeup (the interrupt pin is connected to a wakeup-source GPIO)
and may wakeup the system (MAX8997 has a power button input pin).

Signed-off-by: MyungJoo Ham <myungjoo.ham@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
drivers/mfd/max8997.c
include/linux/mfd/max8997-private.h

index f83103b..dc58750 100644 (file)
@@ -23,6 +23,7 @@
 
 #include <linux/slab.h>
 #include <linux/i2c.h>
 
 #include <linux/slab.h>
 #include <linux/i2c.h>
+#include <linux/interrupt.h>
 #include <linux/pm_runtime.h>
 #include <linux/mutex.h>
 #include <linux/mfd/core.h>
 #include <linux/pm_runtime.h>
 #include <linux/mutex.h>
 #include <linux/mfd/core.h>
@@ -142,7 +143,6 @@ static int max8997_i2c_probe(struct i2c_client *i2c,
 
        max8997->irq_base = pdata->irq_base;
        max8997->ono = pdata->ono;
 
        max8997->irq_base = pdata->irq_base;
        max8997->ono = pdata->ono;
-       max8997->wakeup = pdata->wakeup;
 
        mutex_init(&max8997->iolock);
 
 
        mutex_init(&max8997->iolock);
 
@@ -169,6 +169,9 @@ static int max8997_i2c_probe(struct i2c_client *i2c,
        if (ret < 0)
                goto err_mfd;
 
        if (ret < 0)
                goto err_mfd;
 
+       /* MAX8997 has a power button input. */
+       device_init_wakeup(max8997->dev, pdata->wakeup);
+
        return ret;
 
 err_mfd:
        return ret;
 
 err_mfd:
@@ -398,7 +401,29 @@ static int max8997_restore(struct device *dev)
        return 0;
 }
 
        return 0;
 }
 
+static int max8997_suspend(struct device *dev)
+{
+       struct i2c_client *i2c = container_of(dev, struct i2c_client, dev);
+       struct max8997_dev *max8997 = i2c_get_clientdata(i2c);
+
+       if (device_may_wakeup(dev))
+               irq_set_irq_wake(max8997->irq, 1);
+       return 0;
+}
+
+static int max8997_resume(struct device *dev)
+{
+       struct i2c_client *i2c = container_of(dev, struct i2c_client, dev);
+       struct max8997_dev *max8997 = i2c_get_clientdata(i2c);
+
+       if (device_may_wakeup(dev))
+               irq_set_irq_wake(max8997->irq, 0);
+       return max8997_irq_resume(max8997);
+}
+
 const struct dev_pm_ops max8997_pm = {
 const struct dev_pm_ops max8997_pm = {
+       .suspend = max8997_suspend,
+       .resume = max8997_resume,
        .freeze = max8997_freeze,
        .restore = max8997_restore,
 };
        .freeze = max8997_freeze,
        .restore = max8997_restore,
 };
index 5ff2400..3f4deb6 100644 (file)
@@ -326,7 +326,6 @@ struct max8997_dev {
        int irq;
        int ono;
        int irq_base;
        int irq;
        int ono;
        int irq_base;
-       bool wakeup;
        struct mutex irqlock;
        int irq_masks_cur[MAX8997_IRQ_GROUP_NR];
        int irq_masks_cache[MAX8997_IRQ_GROUP_NR];
        struct mutex irqlock;
        int irq_masks_cur[MAX8997_IRQ_GROUP_NR];
        int irq_masks_cache[MAX8997_IRQ_GROUP_NR];