panjit_touch: add early suspend support to panjit I2C touchscreen
authorGary King <gking@nvidia.com>
Wed, 4 Aug 2010 00:56:37 +0000 (17:56 -0700)
committerColin Cross <ccross@android.com>
Wed, 13 Oct 2010 01:35:54 +0000 (18:35 -0700)
Change-Id: I1adc2bb646269f17480718a7efb3dc14e6325fbc
Signed-off-by: Gary King <gking@nvidia.com>
drivers/input/touchscreen/panjit_i2c.c

index 16df9313a10f3be2a222b3404eb3d9621d1d04f4..4fccebc52ea8e4033956506e95e91d027e247a19 100644 (file)
@@ -24,6 +24,7 @@
 #include <linux/device.h>
 #include <linux/input.h>
 #include <linux/delay.h>
+#include <linux/earlysuspend.h>
 #include <linux/i2c.h>
 #include <linux/i2c/panjit_ts.h>
 #include <linux/interrupt.h>
 
 #define DRIVER_NAME    "panjit_touch"
 
+#ifdef CONFIG_HAS_EARLYSUSPEND
+static void pj_early_suspend(struct early_suspend *h);
+static void pj_late_resume(struct early_suspend *h);
+#endif
+
 struct pj_data {
        struct input_dev        *input_dev;
        struct i2c_client       *client;
        int                     gpio_reset;
+       struct early_suspend    early_suspend;
 };
 
 struct pj_event {
@@ -208,6 +215,12 @@ static int pj_probe(struct i2c_client *client,
                goto fail_irq;
        }
 
+#ifdef CONFIG_HAS_EARLYSUSPEND
+       touch->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 1;
+       touch->early_suspend.suspend = pj_early_suspend;
+       touch->early_suspend.resume = pj_late_resume;
+       register_early_suspend(&touch->early_suspend);
+#endif
        dev_info(&client->dev, "%s: initialized\n", __func__);
        return 0;
 
@@ -267,6 +280,26 @@ static int pj_resume(struct i2c_client *client)
        return 0;
 }
 
+#ifdef CONFIG_HAS_EARLYSUSPEND
+static void pj_early_suspend(struct early_suspend *es)
+{
+       struct pj_data *touch;
+       touch = container_of(es, struct pj_data, early_suspend);
+
+       if (pj_suspend(touch->client, PMSG_SUSPEND) != 0)
+               dev_err(&touch->client->dev, "%s: failed\n", __func__);
+}
+
+static void pj_late_resume(struct early_suspend *es)
+{
+       struct pj_data *touch;
+       touch = container_of(es, struct pj_data, early_suspend);
+
+       if (pj_resume(touch->client) != 0)
+               dev_err(&touch->client->dev, "%s: failed\n", __func__);
+}
+#endif
+
 static int pj_remove(struct i2c_client *client)
 {
        struct pj_data *touch = i2c_get_clientdata(client);
@@ -274,6 +307,9 @@ static int pj_remove(struct i2c_client *client)
        if (!touch)
                return -EINVAL;
 
+#ifdef CONFIG_HAS_EARLYSUSPEND
+       unregister_early_suspend(&touch->early_suspend);
+#endif
        free_irq(touch->client->irq, touch);
        if (touch->gpio_reset >= 0)
                gpio_free(touch->gpio_reset);
@@ -291,8 +327,10 @@ static const struct i2c_device_id panjit_ts_id[] = {
 static struct i2c_driver panjit_driver = {
        .probe          = pj_probe,
        .remove         = pj_remove,
+#ifndef CONFIG_HAS_EARLYSUSPEND
        .suspend        = pj_suspend,
        .resume         = pj_resume,
+#endif
        .id_table       = panjit_ts_id,
        .driver         = {
                .name   = DRIVER_NAME,