aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/iio/kfifo_buf.c
diff options
context:
space:
mode:
authorJonathan Cameron <jic23@kernel.org>2012-06-30 08:52:00 -0400
committerJonathan Cameron <jic23@kernel.org>2012-08-27 13:58:37 -0400
commit7c388ec1d4bc55b72802afbddb26ab87bc762438 (patch)
treef938cead3ba869643d80849ef912c71b1497ee83 /drivers/iio/kfifo_buf.c
parent08ce9b44b53c580987b6a63df4e2206e45e20b92 (diff)
iio: kfifo - add poll support.
This buffer implementation was missing poll support. Signed-off-by: Jonathan Cameron <jic23@kernel.org> Tested-by: Lars-Peter Clausen <lars@metafoo.de> Acked-by: srinivas pandruvada <srinivas.pandruvada@intel.com>
Diffstat (limited to 'drivers/iio/kfifo_buf.c')
-rw-r--r--drivers/iio/kfifo_buf.c15
1 files changed, 14 insertions, 1 deletions
diff --git a/drivers/iio/kfifo_buf.c b/drivers/iio/kfifo_buf.c
index 6ec763f1202a..63da42498a9a 100644
--- a/drivers/iio/kfifo_buf.c
+++ b/drivers/iio/kfifo_buf.c
@@ -6,6 +6,7 @@
6#include <linux/kfifo.h> 6#include <linux/kfifo.h>
7#include <linux/mutex.h> 7#include <linux/mutex.h>
8#include <linux/iio/kfifo_buf.h> 8#include <linux/iio/kfifo_buf.h>
9#include <linux/sched.h>
9 10
10struct iio_kfifo { 11struct iio_kfifo {
11 struct iio_buffer buffer; 12 struct iio_buffer buffer;
@@ -36,6 +37,7 @@ static int iio_request_update_kfifo(struct iio_buffer *r)
36 kfifo_free(&buf->kf); 37 kfifo_free(&buf->kf);
37 ret = __iio_allocate_kfifo(buf, buf->buffer.bytes_per_datum, 38 ret = __iio_allocate_kfifo(buf, buf->buffer.bytes_per_datum,
38 buf->buffer.length); 39 buf->buffer.length);
40 r->stufftoread = false;
39error_ret: 41error_ret:
40 return ret; 42 return ret;
41} 43}
@@ -82,6 +84,9 @@ static int iio_set_bytes_per_datum_kfifo(struct iio_buffer *r, size_t bpd)
82 84
83static int iio_set_length_kfifo(struct iio_buffer *r, int length) 85static int iio_set_length_kfifo(struct iio_buffer *r, int length)
84{ 86{
87 /* Avoid an invalid state */
88 if (length < 2)
89 length = 2;
85 if (r->length != length) { 90 if (r->length != length) {
86 r->length = length; 91 r->length = length;
87 iio_mark_update_needed_kfifo(r); 92 iio_mark_update_needed_kfifo(r);
@@ -98,6 +103,8 @@ static int iio_store_to_kfifo(struct iio_buffer *r,
98 ret = kfifo_in(&kf->kf, data, 1); 103 ret = kfifo_in(&kf->kf, data, 1);
99 if (ret != 1) 104 if (ret != 1)
100 return -EBUSY; 105 return -EBUSY;
106 r->stufftoread = true;
107 wake_up_interruptible(&r->pollq);
101 108
102 return 0; 109 return 0;
103} 110}
@@ -115,6 +122,12 @@ static int iio_read_first_n_kfifo(struct iio_buffer *r,
115 if (ret < 0) 122 if (ret < 0)
116 return ret; 123 return ret;
117 124
125 if (kfifo_is_empty(&kf->kf))
126 r->stufftoread = false;
127 /* verify it is still empty to avoid race */
128 if (!kfifo_is_empty(&kf->kf))
129 r->stufftoread = true;
130
118 return copied; 131 return copied;
119} 132}
120 133
@@ -139,7 +152,7 @@ struct iio_buffer *iio_kfifo_allocate(struct iio_dev *indio_dev)
139 iio_buffer_init(&kf->buffer); 152 iio_buffer_init(&kf->buffer);
140 kf->buffer.attrs = &iio_kfifo_attribute_group; 153 kf->buffer.attrs = &iio_kfifo_attribute_group;
141 kf->buffer.access = &kfifo_access_funcs; 154 kf->buffer.access = &kfifo_access_funcs;
142 155 kf->buffer.length = 2;
143 return &kf->buffer; 156 return &kf->buffer;
144} 157}
145EXPORT_SYMBOL(iio_kfifo_allocate); 158EXPORT_SYMBOL(iio_kfifo_allocate);