Improve the suspend and resume handlers to allow the device
to wakeup the system from suspend.

Signed-off-by: Roger Quadros <rog...@ti.com>
Acked-by: Mugunthan V N <mugunthan...@ti.com>
---
 drivers/input/touchscreen/pixcir_i2c_ts.c | 46 ++++++++++++++++++++++++++++---
 1 file changed, 42 insertions(+), 4 deletions(-)

diff --git a/drivers/input/touchscreen/pixcir_i2c_ts.c 
b/drivers/input/touchscreen/pixcir_i2c_ts.c
index b1e92f6..8ca258b 100644
--- a/drivers/input/touchscreen/pixcir_i2c_ts.c
+++ b/drivers/input/touchscreen/pixcir_i2c_ts.c
@@ -345,21 +345,59 @@ static void pixcir_input_close(struct input_dev *dev)
 static int pixcir_i2c_ts_suspend(struct device *dev)
 {
        struct i2c_client *client = to_i2c_client(dev);
+       struct pixcir_i2c_ts_data *ts = i2c_get_clientdata(client);
+       struct input_dev *input = ts->input;
+       int ret = 0;
+
+       mutex_lock(&input->mutex);
+
+       if (device_may_wakeup(&client->dev)) {
+               /* need to start device if not open, to be wakeup source */
+               if (!input->users) {
+                       ret = pixcir_start(ts);
+                       if (ret)
+                               goto unlock;
+               }
 
-       if (device_may_wakeup(&client->dev))
                enable_irq_wake(client->irq);
 
-       return 0;
+       } else if (input->users) {
+               ret = pixcir_stop(ts);
+       }
+
+unlock:
+       mutex_unlock(&input->mutex);
+
+       return ret;
 }
 
 static int pixcir_i2c_ts_resume(struct device *dev)
 {
        struct i2c_client *client = to_i2c_client(dev);
+       struct pixcir_i2c_ts_data *ts = i2c_get_clientdata(client);
+       struct input_dev *input = ts->input;
+       int ret = 0;
+
+       mutex_lock(&input->mutex);
 
-       if (device_may_wakeup(&client->dev))
+       if (device_may_wakeup(&client->dev)) {
                disable_irq_wake(client->irq);
 
-       return 0;
+               /* need to stop device if it was not open on suspend */
+               if (!input->users) {
+                       ret = pixcir_stop(ts);
+                       if (ret)
+                               goto unlock;
+               }
+
+       } else if (input->users) {
+               ret = pixcir_start(ts);
+       }
+
+unlock:
+       mutex_unlock(&input->mutex);
+
+       return ret;
 }
 #endif
 
-- 
1.8.3.2

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Reply via email to