diff options
author | Jonathan Cameron <jic23@cam.ac.uk> | 2011-02-11 13:09:10 +0000 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2011-02-18 13:22:51 -0800 |
commit | b174baf4b79a067b58a77b86893c55d2c018d6f4 (patch) | |
tree | 986bfcbff3fe99fc0de3b9369c543286504029f1 /drivers/staging/iio/kfifo_buf.h | |
parent | d5857d65b5f7fab78c69da4085f0ce85a0399b25 (diff) |
staging:iio:kfifo buffer implementation
A very simple use of a kfifo as an alternative for the ring_sw
Signed-off-by: Jonathan Cameron <jic23@cam.ac.uk>
Tested-by: Michael Hennerich <michael.hennerich@analog.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/staging/iio/kfifo_buf.h')
-rw-r--r-- | drivers/staging/iio/kfifo_buf.h | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/drivers/staging/iio/kfifo_buf.h b/drivers/staging/iio/kfifo_buf.h new file mode 100644 index 000000000000..8064383bf7c3 --- /dev/null +++ b/drivers/staging/iio/kfifo_buf.h @@ -0,0 +1,56 @@ + +#include <linux/kfifo.h> +#include "iio.h" +#include "ring_generic.h" + +struct iio_kfifo { + struct iio_ring_buffer ring; + struct kfifo kf; + int use_count; + int update_needed; + struct mutex use_lock; +}; + +#define iio_to_kfifo(r) container_of(r, struct iio_kfifo, ring) + +int iio_create_kfifo(struct iio_ring_buffer **r); +int iio_init_kfifo(struct iio_ring_buffer *r, struct iio_dev *indio_dev); +void iio_exit_kfifo(struct iio_ring_buffer *r); +void iio_free_kfifo(struct iio_ring_buffer *r); +void iio_mark_kfifo_in_use(struct iio_ring_buffer *r); +void iio_unmark_kfifo_in_use(struct iio_ring_buffer *r); + +int iio_store_to_kfifo(struct iio_ring_buffer *r, u8 *data, s64 timestamp); +int iio_rip_kfifo(struct iio_ring_buffer *r, + size_t count, + char __user *buf, + int *dead_offset); + +int iio_request_update_kfifo(struct iio_ring_buffer *r); +int iio_mark_update_needed_kfifo(struct iio_ring_buffer *r); + +int iio_get_bytes_per_datum_kfifo(struct iio_ring_buffer *r); +int iio_set_bytes_per_datum_kfifo(struct iio_ring_buffer *r, size_t bpd); +int iio_get_length_kfifo(struct iio_ring_buffer *r); +int iio_set_length_kfifo(struct iio_ring_buffer *r, int length); + +static inline void iio_kfifo_register_funcs(struct iio_ring_access_funcs *ra) +{ + ra->mark_in_use = &iio_mark_kfifo_in_use; + ra->unmark_in_use = &iio_unmark_kfifo_in_use; + + ra->store_to = &iio_store_to_kfifo; + ra->rip_lots = &iio_rip_kfifo; + + ra->mark_param_change = &iio_mark_update_needed_kfifo; + ra->request_update = &iio_request_update_kfifo; + + ra->get_bytes_per_datum = &iio_get_bytes_per_datum_kfifo; + ra->set_bytes_per_datum = &iio_set_bytes_per_datum_kfifo; + ra->get_length = &iio_get_length_kfifo; + ra->set_length = &iio_set_length_kfifo; +}; + +struct iio_ring_buffer *iio_kfifo_allocate(struct iio_dev *indio_dev); +void iio_kfifo_free(struct iio_ring_buffer *r); + |