Input: Hold wake lock while event queue is not empty.
authorArve Hjønnevåg <arve@android.com>
Fri, 17 Oct 2008 22:20:55 +0000 (15:20 -0700)
committerColin Cross <ccross@android.com>
Thu, 30 Sep 2010 00:49:09 +0000 (17:49 -0700)
Allows userspace code to process input events while
the device appears to be asleep.

Signed-off-by: Arve Hjønnevåg <arve@android.com>
drivers/input/evdev.c

index c908c5f83645c901f87823e2a587ba65d9b5ee97..98bb5be0a6d1fe4011a939e5492b253df4853d6e 100644 (file)
@@ -21,6 +21,7 @@
 #include <linux/input.h>
 #include <linux/major.h>
 #include <linux/device.h>
+#include <linux/wakelock.h>
 #include "input-compat.h"
 
 struct evdev {
@@ -40,6 +41,7 @@ struct evdev_client {
        int head;
        int tail;
        spinlock_t buffer_lock; /* protects access to buffer, head and tail */
+       struct wake_lock wake_lock;
        struct fasync_struct *fasync;
        struct evdev *evdev;
        struct list_head node;
@@ -59,6 +61,7 @@ static void evdev_pass_event(struct evdev_client *client,
         * "empty" by having client->head == client->tail.
         */
        spin_lock(&client->buffer_lock);
+       wake_lock_timeout(&client->wake_lock, 5 * HZ);
        do {
                client->buffer[client->head++] = *event;
                client->head &= client->bufsize - 1;
@@ -240,6 +243,7 @@ static int evdev_release(struct inode *inode, struct file *file)
        mutex_unlock(&evdev->mutex);
 
        evdev_detach_client(evdev, client);
+       wake_lock_destroy(&client->wake_lock);
        kfree(client);
 
        evdev_close_device(evdev);
@@ -291,6 +295,7 @@ static int evdev_open(struct inode *inode, struct file *file)
 
        client->bufsize = bufsize;
        spin_lock_init(&client->buffer_lock);
+       wake_lock_init(&client->wake_lock, WAKE_LOCK_SUSPEND, "evdev");
        client->evdev = evdev;
        evdev_attach_client(evdev, client);
 
@@ -356,6 +361,8 @@ static int evdev_fetch_next_event(struct evdev_client *client,
        if (have_event) {
                *event = client->buffer[client->tail++];
                client->tail &= client->bufsize - 1;
+               if (client->head == client->tail)
+                       wake_unlock(&client->wake_lock);
        }
 
        spin_unlock_irq(&client->buffer_lock);