Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a7348347 authored by Jonathan Cameron's avatar Jonathan Cameron Committed by Greg Kroah-Hartman
Browse files

staging:iio: Add polling of events on the ring access chrdev.



Staging one of combining the ring chrdevs.

Signed-off-by: default avatarJonathan Cameron <jic23@cam.ac.uk>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent 939606d5
Loading
Loading
Loading
Loading
+24 −5
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@
#include <linux/fs.h>
#include <linux/cdev.h>
#include <linux/slab.h>
#include <linux/poll.h>

#include "iio.h"
#include "ring_generic.h"
@@ -90,10 +91,27 @@ static ssize_t iio_ring_read_first_n_outer(struct file *filp, char __user *buf,
	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,
};
@@ -211,6 +229,7 @@ void iio_ring_buffer_init(struct iio_ring_buffer *ring,
	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);

@@ -392,7 +411,7 @@ int iio_ring_buffer_register_ex(struct iio_ring_buffer *ring, int id,
						      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,
@@ -400,13 +419,13 @@ int iio_ring_buffer_register_ex(struct iio_ring_buffer *ring, int id,
		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;
	}


@@ -424,8 +443,8 @@ int iio_ring_buffer_register_ex(struct iio_ring_buffer *ring, int id,
	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:
+3 −0
Original line number Diff line number Diff line
@@ -139,6 +139,9 @@ struct iio_ring_buffer {

	struct list_head scan_el_dev_attr_list;
	struct list_head scan_el_en_attr_list;

	wait_queue_head_t pollq;
	bool stufftoread;
};

/**
+8 −0
Original line number Diff line number Diff line
@@ -12,6 +12,7 @@
#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"
@@ -136,6 +137,8 @@ static int iio_store_to_sw_ring(struct iio_sw_ring_buffer *ring,
		ret = __iio_push_event(&ring->buf.ev_int,
				       code,
				       timestamp);
		ring->buf.stufftoread = true;
		wake_up_interruptible(&ring->buf.pollq);
	}
	return ret;
}
@@ -261,6 +264,10 @@ int iio_read_first_n_sw_rb(struct iio_ring_buffer *r,
		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:
@@ -310,6 +317,7 @@ int iio_request_update_sw_rb(struct iio_ring_buffer *r)
	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;