#include <linux/fs.h>
#include <linux/cdev.h>
#include <linux/slab.h>
+#include <linux/poll.h>
#include "iio.h"
#include "ring_generic.h"
return ret;
}
+/**
+ * iio_ring_poll() - poll the ring to find out if it has data
+ */
+static unsigned int iio_ring_poll(struct file *filp,
+ struct poll_table_struct *wait)
+{
+ struct iio_ring_buffer *rb = filp->private_data;
+ int ret = 0;
+
+ poll_wait(filp, &rb->pollq, wait);
+ if (rb->stufftoread)
+ return POLLIN | POLLRDNORM;
+ /* need a way of knowing if there may be enough data... */
+ return ret;
+}
+
static const struct file_operations iio_ring_fileops = {
.read = iio_ring_read_first_n_outer,
.release = iio_ring_release,
.open = iio_ring_open,
+ .poll = iio_ring_poll,
.owner = THIS_MODULE,
.llseek = noop_llseek,
};
ring->indio_dev = dev_info;
ring->ev_int.private = ring;
ring->access_handler.private = ring;
+ init_waitqueue_head(&ring->pollq);
}
EXPORT_SYMBOL(iio_ring_buffer_init);
ring->owner);
if (ret)
- goto error_free_ring_buffer_event_chrdev;
+ goto error_ret;
if (ring->scan_el_attrs) {
ret = sysfs_create_group(&ring->dev.kobj,
if (ret) {
dev_err(&ring->dev,
"Failed to add sysfs scan elements\n");
- goto error_free_ring_buffer_event_chrdev;
+ goto error_free_ring_buffer_access_chrdev;
}
} else if (channels) {
ret = sysfs_create_group(&ring->dev.kobj,
&iio_scan_el_dummy_group);
if (ret)
- goto error_free_ring_buffer_event_chrdev;
+ goto error_free_ring_buffer_access_chrdev;
}
return 0;
error_cleanup_dynamic:
__iio_ring_attr_cleanup(ring);
-error_free_ring_buffer_event_chrdev:
- __iio_free_ring_buffer_event_chrdev(ring);
+error_free_ring_buffer_access_chrdev:
+ __iio_free_ring_buffer_access_chrdev(ring);
error_remove_device:
device_del(&ring->dev);
error_ret:
#include <linux/module.h>
#include <linux/device.h>
#include <linux/workqueue.h>
+#include <linux/sched.h>
#include <linux/poll.h>
#include "ring_sw.h"
#include "trigger.h"
ret = __iio_push_event(&ring->buf.ev_int,
code,
timestamp);
+ ring->buf.stufftoread = true;
+ wake_up_interruptible(&ring->buf.pollq);
}
return ret;
}
ret = -EFAULT;
goto error_free_data_cpy;
}
+
+ if (bytes_to_rip >= ring->buf.length*ring->buf.bytes_per_datum/2)
+ ring->buf.stufftoread = 0;
+
error_free_data_cpy:
kfree(data);
error_ret:
int ret = 0;
struct iio_sw_ring_buffer *ring = iio_to_sw_ring(r);
+ r->stufftoread = false;
spin_lock(&ring->use_lock);
if (!ring->update_needed)
goto error_ret;