tpm_tis: fix potential buffer overruns caused by bit glitches on the bus
[pandora-kernel.git] / drivers / mfd / max8997.c
index f83103b..1926a54 100644 (file)
@@ -23,7 +23,9 @@
 
 #include <linux/slab.h>
 #include <linux/i2c.h>
+#include <linux/interrupt.h>
 #include <linux/pm_runtime.h>
+#include <linux/module.h>
 #include <linux/mutex.h>
 #include <linux/mfd/core.h>
 #include <linux/mfd/max8997.h>
@@ -142,15 +144,30 @@ static int max8997_i2c_probe(struct i2c_client *i2c,
 
        max8997->irq_base = pdata->irq_base;
        max8997->ono = pdata->ono;
-       max8997->wakeup = pdata->wakeup;
 
        mutex_init(&max8997->iolock);
 
        max8997->rtc = i2c_new_dummy(i2c->adapter, I2C_ADDR_RTC);
+       if (!max8997->rtc) {
+               dev_err(max8997->dev, "Failed to allocate I2C device for RTC\n");
+               return -ENODEV;
+       }
        i2c_set_clientdata(max8997->rtc, max8997);
+
        max8997->haptic = i2c_new_dummy(i2c->adapter, I2C_ADDR_HAPTIC);
+       if (!max8997->haptic) {
+               dev_err(max8997->dev, "Failed to allocate I2C device for Haptic\n");
+               ret = -ENODEV;
+               goto err_i2c_haptic;
+       }
        i2c_set_clientdata(max8997->haptic, max8997);
+
        max8997->muic = i2c_new_dummy(i2c->adapter, I2C_ADDR_MUIC);
+       if (!max8997->muic) {
+               dev_err(max8997->dev, "Failed to allocate I2C device for MUIC\n");
+               ret = -ENODEV;
+               goto err_i2c_muic;
+       }
        i2c_set_clientdata(max8997->muic, max8997);
 
        pm_runtime_set_active(max8997->dev);
@@ -169,12 +186,17 @@ static int max8997_i2c_probe(struct i2c_client *i2c,
        if (ret < 0)
                goto err_mfd;
 
+       /* MAX8997 has a power button input. */
+       device_init_wakeup(max8997->dev, pdata->wakeup);
+
        return ret;
 
 err_mfd:
        mfd_remove_devices(max8997->dev);
        i2c_unregister_device(max8997->muic);
+err_i2c_muic:
        i2c_unregister_device(max8997->haptic);
+err_i2c_haptic:
        i2c_unregister_device(max8997->rtc);
 err:
        kfree(max8997);
@@ -398,7 +420,29 @@ static int max8997_restore(struct device *dev)
        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 = {
+       .suspend = max8997_suspend,
+       .resume = max8997_resume,
        .freeze = max8997_freeze,
        .restore = max8997_restore,
 };