Input: evdev - Add ioctl to block suspend while event queue is not empty.
Arve Hjønnevåg [Fri, 17 Oct 2008 22:20:55 +0000 (15:20 -0700)]
Add an ioctl, EVIOCSSUSPENDBLOCK, to enable a wakelock that will block
suspend while the event queue is not empty. This allows userspace code to
process input events while the device appears to be asleep.

The current code holds the wakelock for up 5 seconds for every input
device and client. This can prevent suspend if sensor with a high data
rate is active, even when that sensor is not capable of waking the
device once it is suspended.

Change-Id: I624d66ef30a0b3abb543685c343382b8419b42b9
Signed-off-by: Arve Hjønnevåg <arve@android.com>

drivers/input/evdev.c

index d7f2e30..bd34e44 100644 (file)
@@ -697,6 +697,35 @@ static int evdev_handle_mt_request(struct input_dev *dev,
        return 0;
 }
 
+static int evdev_enable_suspend_block(struct evdev *evdev,
+                                     struct evdev_client *client)
+{
+       if (client->use_wake_lock)
+               return 0;
+
+       spin_lock_irq(&client->buffer_lock);
+       wake_lock_init(&client->wake_lock, WAKE_LOCK_SUSPEND, client->name);
+       client->use_wake_lock = true;
+       if (client->packet_head != client->tail)
+               wake_lock(&client->wake_lock);
+       spin_unlock_irq(&client->buffer_lock);
+       return 0;
+}
+
+static int evdev_disable_suspend_block(struct evdev *evdev,
+                                      struct evdev_client *client)
+{
+       if (!client->use_wake_lock)
+               return 0;
+
+       spin_lock_irq(&client->buffer_lock);
+       client->use_wake_lock = false;
+       wake_lock_destroy(&client->wake_lock);
+       spin_unlock_irq(&client->buffer_lock);
+
+       return 0;
+}
+
 static long evdev_do_ioctl(struct file *file, unsigned int cmd,
                           void __user *p, int compat_mode)
 {