aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/staging/iio
diff options
context:
space:
mode:
authorLars-Peter Clausen <lars@metafoo.de>2012-01-03 08:59:41 -0500
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2012-02-09 13:05:06 -0500
commite18045ed75ec682a26a385b0072dcc030fd12a7e (patch)
treeb8c95b13d9a9b295d64acba66c38f4952871d889 /drivers/staging/iio
parent43ba1100af11f34cc67bdf6b359667cfa851e6a8 (diff)
staging:iio:events: Add poll support
Add poll support to the event queue. This will allow us to check for pending events in a application's event loop using poll() or similar. Since we already have support for blocking reads adding poll support as well is trivial. Signed-off-by: Lars-Peter Clausen <lars@metafoo.de> Acked-by: Jonathan Cameron <jic23@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/staging/iio')
-rw-r--r--drivers/staging/iio/industrialio-event.c23
1 files changed, 22 insertions, 1 deletions
diff --git a/drivers/staging/iio/industrialio-event.c b/drivers/staging/iio/industrialio-event.c
index f0c41f1f505..800f67d4cce 100644
--- a/drivers/staging/iio/industrialio-event.c
+++ b/drivers/staging/iio/industrialio-event.c
@@ -15,6 +15,7 @@
15#include <linux/kernel.h> 15#include <linux/kernel.h>
16#include <linux/kfifo.h> 16#include <linux/kfifo.h>
17#include <linux/module.h> 17#include <linux/module.h>
18#include <linux/poll.h>
18#include <linux/sched.h> 19#include <linux/sched.h>
19#include <linux/slab.h> 20#include <linux/slab.h>
20#include <linux/uaccess.h> 21#include <linux/uaccess.h>
@@ -57,7 +58,7 @@ int iio_push_event(struct iio_dev *indio_dev, u64 ev_code, s64 timestamp)
57 58
58 copied = kfifo_put(&ev_int->det_events, &ev); 59 copied = kfifo_put(&ev_int->det_events, &ev);
59 if (copied != 0) 60 if (copied != 0)
60 wake_up_locked(&ev_int->wait); 61 wake_up_locked_poll(&ev_int->wait, POLLIN);
61 } 62 }
62 spin_unlock(&ev_int->wait.lock); 63 spin_unlock(&ev_int->wait.lock);
63 64
@@ -65,6 +66,25 @@ int iio_push_event(struct iio_dev *indio_dev, u64 ev_code, s64 timestamp)
65} 66}
66EXPORT_SYMBOL(iio_push_event); 67EXPORT_SYMBOL(iio_push_event);
67 68
69/**
70 * iio_event_poll() - poll the event queue to find out if it has data
71 */
72static unsigned int iio_event_poll(struct file *filep,
73 struct poll_table_struct *wait)
74{
75 struct iio_event_interface *ev_int = filep->private_data;
76 unsigned int events = 0;
77
78 poll_wait(filep, &ev_int->wait, wait);
79
80 spin_lock(&ev_int->wait.lock);
81 if (!kfifo_is_empty(&ev_int->det_events))
82 events = POLLIN | POLLRDNORM;
83 spin_unlock(&ev_int->wait.lock);
84
85 return events;
86}
87
68static ssize_t iio_event_chrdev_read(struct file *filep, 88static ssize_t iio_event_chrdev_read(struct file *filep,
69 char __user *buf, 89 char __user *buf,
70 size_t count, 90 size_t count,
@@ -118,6 +138,7 @@ static int iio_event_chrdev_release(struct inode *inode, struct file *filep)
118 138
119static const struct file_operations iio_event_chrdev_fileops = { 139static const struct file_operations iio_event_chrdev_fileops = {
120 .read = iio_event_chrdev_read, 140 .read = iio_event_chrdev_read,
141 .poll = iio_event_poll,
121 .release = iio_event_chrdev_release, 142 .release = iio_event_chrdev_release,
122 .owner = THIS_MODULE, 143 .owner = THIS_MODULE,
123 .llseek = noop_llseek, 144 .llseek = noop_llseek,