diff options
author | Manuel Stahl <manuel.stahl@iis.fraunhofer.de> | 2010-08-31 05:32:52 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2010-08-31 14:42:02 -0400 |
commit | bf32963cbeb5d34fa32a4c1eeed1163ab1b4501c (patch) | |
tree | 221c5e12d26142d6b8b5a3cfff844c9ed9ad3899 /drivers/staging | |
parent | 07e6229e42e4d679cdbaada8f7966491c69710e7 (diff) |
staging: iio move scan_elements into ring buffer
tested with sca3000, adis16400
Signed-off-by: Manuel Stahl <manuel.stahl@iis.fraunhofer.de>
Signed-off-by: Jonathan Cameron <jic23@cam.ac.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/staging')
-rw-r--r-- | drivers/staging/iio/accel/adis16209_ring.c | 41 | ||||
-rw-r--r-- | drivers/staging/iio/accel/adis16240_ring.c | 33 | ||||
-rw-r--r-- | drivers/staging/iio/accel/lis3l02dq_ring.c | 43 | ||||
-rw-r--r-- | drivers/staging/iio/accel/sca3000_ring.c | 2 | ||||
-rw-r--r-- | drivers/staging/iio/adc/max1363_core.c | 1 | ||||
-rw-r--r-- | drivers/staging/iio/adc/max1363_ring.c | 18 | ||||
-rw-r--r-- | drivers/staging/iio/gyro/adis16260_ring.c | 31 | ||||
-rw-r--r-- | drivers/staging/iio/iio.h | 98 | ||||
-rw-r--r-- | drivers/staging/iio/imu/adis16300_ring.c | 43 | ||||
-rw-r--r-- | drivers/staging/iio/imu/adis16350_ring.c | 47 | ||||
-rw-r--r-- | drivers/staging/iio/imu/adis16400_ring.c | 49 | ||||
-rw-r--r-- | drivers/staging/iio/industrialio-core.c | 12 | ||||
-rw-r--r-- | drivers/staging/iio/industrialio-ring.c | 38 | ||||
-rw-r--r-- | drivers/staging/iio/ring_generic.h | 100 | ||||
-rw-r--r-- | drivers/staging/iio/ring_sw.c | 25 |
15 files changed, 292 insertions, 289 deletions
diff --git a/drivers/staging/iio/accel/adis16209_ring.c b/drivers/staging/iio/accel/adis16209_ring.c index d40b95f1923..120bf91e0ac 100644 --- a/drivers/staging/iio/accel/adis16209_ring.c +++ b/drivers/staging/iio/accel/adis16209_ring.c | |||
@@ -115,11 +115,11 @@ static void adis16209_trigger_bh_to_ring(struct work_struct *work_s) | |||
115 | struct adis16209_state *st | 115 | struct adis16209_state *st |
116 | = container_of(work_s, struct adis16209_state, | 116 | = container_of(work_s, struct adis16209_state, |
117 | work_trigger_to_ring); | 117 | work_trigger_to_ring); |
118 | struct iio_ring_buffer *ring = st->indio_dev->ring; | ||
118 | 119 | ||
119 | int i = 0; | 120 | int i = 0; |
120 | s16 *data; | 121 | s16 *data; |
121 | size_t datasize = st->indio_dev | 122 | size_t datasize = ring->access.get_bytes_per_datum(ring); |
122 | ->ring->access.get_bytes_per_datum(st->indio_dev->ring); | ||
123 | 123 | ||
124 | data = kmalloc(datasize , GFP_KERNEL); | 124 | data = kmalloc(datasize , GFP_KERNEL); |
125 | if (data == NULL) { | 125 | if (data == NULL) { |
@@ -127,19 +127,19 @@ static void adis16209_trigger_bh_to_ring(struct work_struct *work_s) | |||
127 | return; | 127 | return; |
128 | } | 128 | } |
129 | 129 | ||
130 | if (st->indio_dev->scan_count) | 130 | if (ring->scan_count) |
131 | if (adis16209_read_ring_data(&st->indio_dev->dev, st->rx) >= 0) | 131 | if (adis16209_read_ring_data(&st->indio_dev->dev, st->rx) >= 0) |
132 | for (; i < st->indio_dev->scan_count; i++) | 132 | for (; i < ring->scan_count; i++) |
133 | data[i] = be16_to_cpup( | 133 | data[i] = be16_to_cpup( |
134 | (__be16 *)&(st->rx[i*2])); | 134 | (__be16 *)&(st->rx[i*2])); |
135 | 135 | ||
136 | /* Guaranteed to be aligned with 8 byte boundary */ | 136 | /* Guaranteed to be aligned with 8 byte boundary */ |
137 | if (st->indio_dev->scan_timestamp) | 137 | if (ring->scan_timestamp) |
138 | *((s64 *)(data + ((i + 3)/4)*4)) = st->last_timestamp; | 138 | *((s64 *)(data + ((i + 3)/4)*4)) = st->last_timestamp; |
139 | 139 | ||
140 | st->indio_dev->ring->access.store_to(st->indio_dev->ring, | 140 | ring->access.store_to(ring, |
141 | (u8 *)data, | 141 | (u8 *)data, |
142 | st->last_timestamp); | 142 | st->last_timestamp); |
143 | 143 | ||
144 | iio_trigger_notify_done(st->indio_dev->trig); | 144 | iio_trigger_notify_done(st->indio_dev->trig); |
145 | kfree(data); | 145 | kfree(data); |
@@ -159,19 +159,6 @@ int adis16209_configure_ring(struct iio_dev *indio_dev) | |||
159 | struct adis16209_state *st = indio_dev->dev_data; | 159 | struct adis16209_state *st = indio_dev->dev_data; |
160 | struct iio_ring_buffer *ring; | 160 | struct iio_ring_buffer *ring; |
161 | INIT_WORK(&st->work_trigger_to_ring, adis16209_trigger_bh_to_ring); | 161 | INIT_WORK(&st->work_trigger_to_ring, adis16209_trigger_bh_to_ring); |
162 | /* Set default scan mode */ | ||
163 | |||
164 | iio_scan_mask_set(indio_dev, iio_scan_el_supply.number); | ||
165 | iio_scan_mask_set(indio_dev, iio_scan_el_rot.number); | ||
166 | iio_scan_mask_set(indio_dev, iio_scan_el_accel_x.number); | ||
167 | iio_scan_mask_set(indio_dev, iio_scan_el_accel_y.number); | ||
168 | iio_scan_mask_set(indio_dev, iio_scan_el_temp.number); | ||
169 | iio_scan_mask_set(indio_dev, iio_scan_el_aux_adc.number); | ||
170 | iio_scan_mask_set(indio_dev, iio_scan_el_incli_x.number); | ||
171 | iio_scan_mask_set(indio_dev, iio_scan_el_incli_y.number); | ||
172 | indio_dev->scan_timestamp = true; | ||
173 | |||
174 | indio_dev->scan_el_attrs = &adis16209_scan_el_group; | ||
175 | 162 | ||
176 | ring = iio_sw_rb_allocate(indio_dev); | 163 | ring = iio_sw_rb_allocate(indio_dev); |
177 | if (!ring) { | 164 | if (!ring) { |
@@ -182,11 +169,23 @@ int adis16209_configure_ring(struct iio_dev *indio_dev) | |||
182 | /* Effectively select the ring buffer implementation */ | 169 | /* Effectively select the ring buffer implementation */ |
183 | iio_ring_sw_register_funcs(&ring->access); | 170 | iio_ring_sw_register_funcs(&ring->access); |
184 | ring->bpe = 2; | 171 | ring->bpe = 2; |
172 | ring->scan_el_attrs = &adis16209_scan_el_group; | ||
173 | ring->scan_timestamp = true; | ||
185 | ring->preenable = &iio_sw_ring_preenable; | 174 | ring->preenable = &iio_sw_ring_preenable; |
186 | ring->postenable = &iio_triggered_ring_postenable; | 175 | ring->postenable = &iio_triggered_ring_postenable; |
187 | ring->predisable = &iio_triggered_ring_predisable; | 176 | ring->predisable = &iio_triggered_ring_predisable; |
188 | ring->owner = THIS_MODULE; | 177 | ring->owner = THIS_MODULE; |
189 | 178 | ||
179 | /* Set default scan mode */ | ||
180 | iio_scan_mask_set(ring, iio_scan_el_supply.number); | ||
181 | iio_scan_mask_set(ring, iio_scan_el_rot.number); | ||
182 | iio_scan_mask_set(ring, iio_scan_el_accel_x.number); | ||
183 | iio_scan_mask_set(ring, iio_scan_el_accel_y.number); | ||
184 | iio_scan_mask_set(ring, iio_scan_el_temp.number); | ||
185 | iio_scan_mask_set(ring, iio_scan_el_aux_adc.number); | ||
186 | iio_scan_mask_set(ring, iio_scan_el_incli_x.number); | ||
187 | iio_scan_mask_set(ring, iio_scan_el_incli_y.number); | ||
188 | |||
190 | ret = iio_alloc_pollfunc(indio_dev, NULL, &adis16209_poll_func_th); | 189 | ret = iio_alloc_pollfunc(indio_dev, NULL, &adis16209_poll_func_th); |
191 | if (ret) | 190 | if (ret) |
192 | goto error_iio_sw_rb_free; | 191 | goto error_iio_sw_rb_free; |
diff --git a/drivers/staging/iio/accel/adis16240_ring.c b/drivers/staging/iio/accel/adis16240_ring.c index 462d4520ffc..581d0e50048 100644 --- a/drivers/staging/iio/accel/adis16240_ring.c +++ b/drivers/staging/iio/accel/adis16240_ring.c | |||
@@ -107,11 +107,11 @@ static void adis16240_trigger_bh_to_ring(struct work_struct *work_s) | |||
107 | struct adis16240_state *st | 107 | struct adis16240_state *st |
108 | = container_of(work_s, struct adis16240_state, | 108 | = container_of(work_s, struct adis16240_state, |
109 | work_trigger_to_ring); | 109 | work_trigger_to_ring); |
110 | struct iio_ring_buffer *ring = st->indio_dev->ring; | ||
110 | 111 | ||
111 | int i = 0; | 112 | int i = 0; |
112 | s16 *data; | 113 | s16 *data; |
113 | size_t datasize = st->indio_dev | 114 | size_t datasize = ring->access.get_bytes_per_datum(ring); |
114 | ->ring->access.get_bytes_per_datum(st->indio_dev->ring); | ||
115 | 115 | ||
116 | data = kmalloc(datasize , GFP_KERNEL); | 116 | data = kmalloc(datasize , GFP_KERNEL); |
117 | if (data == NULL) { | 117 | if (data == NULL) { |
@@ -119,17 +119,17 @@ static void adis16240_trigger_bh_to_ring(struct work_struct *work_s) | |||
119 | return; | 119 | return; |
120 | } | 120 | } |
121 | 121 | ||
122 | if (st->indio_dev->scan_count) | 122 | if (ring->scan_count) |
123 | if (adis16240_read_ring_data(&st->indio_dev->dev, st->rx) >= 0) | 123 | if (adis16240_read_ring_data(&st->indio_dev->dev, st->rx) >= 0) |
124 | for (; i < st->indio_dev->scan_count; i++) | 124 | for (; i < ring->scan_count; i++) |
125 | data[i] = be16_to_cpup( | 125 | data[i] = be16_to_cpup( |
126 | (__be16 *)&(st->rx[i*2])); | 126 | (__be16 *)&(st->rx[i*2])); |
127 | 127 | ||
128 | /* Guaranteed to be aligned with 8 byte boundary */ | 128 | /* Guaranteed to be aligned with 8 byte boundary */ |
129 | if (st->indio_dev->scan_timestamp) | 129 | if (ring->scan_timestamp) |
130 | *((s64 *)(data + ((i + 3)/4)*4)) = st->last_timestamp; | 130 | *((s64 *)(data + ((i + 3)/4)*4)) = st->last_timestamp; |
131 | 131 | ||
132 | st->indio_dev->ring->access.store_to(st->indio_dev->ring, | 132 | ring->access.store_to(ring, |
133 | (u8 *)data, | 133 | (u8 *)data, |
134 | st->last_timestamp); | 134 | st->last_timestamp); |
135 | 135 | ||
@@ -151,17 +151,6 @@ int adis16240_configure_ring(struct iio_dev *indio_dev) | |||
151 | struct adis16240_state *st = indio_dev->dev_data; | 151 | struct adis16240_state *st = indio_dev->dev_data; |
152 | struct iio_ring_buffer *ring; | 152 | struct iio_ring_buffer *ring; |
153 | INIT_WORK(&st->work_trigger_to_ring, adis16240_trigger_bh_to_ring); | 153 | INIT_WORK(&st->work_trigger_to_ring, adis16240_trigger_bh_to_ring); |
154 | /* Set default scan mode */ | ||
155 | |||
156 | iio_scan_mask_set(indio_dev, iio_scan_el_supply.number); | ||
157 | iio_scan_mask_set(indio_dev, iio_scan_el_accel_x.number); | ||
158 | iio_scan_mask_set(indio_dev, iio_scan_el_accel_y.number); | ||
159 | iio_scan_mask_set(indio_dev, iio_scan_el_accel_z.number); | ||
160 | iio_scan_mask_set(indio_dev, iio_scan_el_temp.number); | ||
161 | iio_scan_mask_set(indio_dev, iio_scan_el_aux_adc.number); | ||
162 | indio_dev->scan_timestamp = true; | ||
163 | |||
164 | indio_dev->scan_el_attrs = &adis16240_scan_el_group; | ||
165 | 154 | ||
166 | ring = iio_sw_rb_allocate(indio_dev); | 155 | ring = iio_sw_rb_allocate(indio_dev); |
167 | if (!ring) { | 156 | if (!ring) { |
@@ -172,11 +161,21 @@ int adis16240_configure_ring(struct iio_dev *indio_dev) | |||
172 | /* Effectively select the ring buffer implementation */ | 161 | /* Effectively select the ring buffer implementation */ |
173 | iio_ring_sw_register_funcs(&ring->access); | 162 | iio_ring_sw_register_funcs(&ring->access); |
174 | ring->bpe = 2; | 163 | ring->bpe = 2; |
164 | ring->scan_el_attrs = &adis16240_scan_el_group; | ||
165 | ring->scan_timestamp = true; | ||
175 | ring->preenable = &iio_sw_ring_preenable; | 166 | ring->preenable = &iio_sw_ring_preenable; |
176 | ring->postenable = &iio_triggered_ring_postenable; | 167 | ring->postenable = &iio_triggered_ring_postenable; |
177 | ring->predisable = &iio_triggered_ring_predisable; | 168 | ring->predisable = &iio_triggered_ring_predisable; |
178 | ring->owner = THIS_MODULE; | 169 | ring->owner = THIS_MODULE; |
179 | 170 | ||
171 | /* Set default scan mode */ | ||
172 | iio_scan_mask_set(ring, iio_scan_el_supply.number); | ||
173 | iio_scan_mask_set(ring, iio_scan_el_accel_x.number); | ||
174 | iio_scan_mask_set(ring, iio_scan_el_accel_y.number); | ||
175 | iio_scan_mask_set(ring, iio_scan_el_accel_z.number); | ||
176 | iio_scan_mask_set(ring, iio_scan_el_temp.number); | ||
177 | iio_scan_mask_set(ring, iio_scan_el_aux_adc.number); | ||
178 | |||
180 | ret = iio_alloc_pollfunc(indio_dev, NULL, &adis16240_poll_func_th); | 179 | ret = iio_alloc_pollfunc(indio_dev, NULL, &adis16240_poll_func_th); |
181 | if (ret) | 180 | if (ret) |
182 | goto error_iio_sw_rb_free; | 181 | goto error_iio_sw_rb_free; |
diff --git a/drivers/staging/iio/accel/lis3l02dq_ring.c b/drivers/staging/iio/accel/lis3l02dq_ring.c index 9ad04f0bb70..a68a381836e 100644 --- a/drivers/staging/iio/accel/lis3l02dq_ring.c +++ b/drivers/staging/iio/accel/lis3l02dq_ring.c | |||
@@ -150,38 +150,40 @@ ssize_t lis3l02dq_read_accel_from_ring(struct device *dev, | |||
150 | int ret, len = 0, i = 0; | 150 | int ret, len = 0, i = 0; |
151 | struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); | 151 | struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); |
152 | struct iio_dev *dev_info = dev_get_drvdata(dev); | 152 | struct iio_dev *dev_info = dev_get_drvdata(dev); |
153 | struct iio_ring_buffer *ring = dev_info->ring; | ||
154 | struct attribute_group *scan_el_attrs = ring->scan_el_attrs; | ||
153 | s16 *data; | 155 | s16 *data; |
154 | 156 | ||
155 | while (dev_info->scan_el_attrs->attrs[i]) { | 157 | while (scan_el_attrs->attrs[i]) { |
156 | el = to_iio_scan_el((struct device_attribute *) | 158 | el = to_iio_scan_el((struct device_attribute *) |
157 | (dev_info->scan_el_attrs->attrs[i])); | 159 | (scan_el_attrs->attrs[i])); |
158 | /* label is in fact the address */ | 160 | /* label is in fact the address */ |
159 | if (el->label == this_attr->address) | 161 | if (el->label == this_attr->address) |
160 | break; | 162 | break; |
161 | i++; | 163 | i++; |
162 | } | 164 | } |
163 | if (!dev_info->scan_el_attrs->attrs[i]) { | 165 | if (!scan_el_attrs->attrs[i]) { |
164 | ret = -EINVAL; | 166 | ret = -EINVAL; |
165 | goto error_ret; | 167 | goto error_ret; |
166 | } | 168 | } |
167 | /* If this element is in the scan mask */ | 169 | /* If this element is in the scan mask */ |
168 | ret = iio_scan_mask_query(dev_info, el->number); | 170 | ret = iio_scan_mask_query(ring, el->number); |
169 | if (ret < 0) | 171 | if (ret < 0) |
170 | goto error_ret; | 172 | goto error_ret; |
171 | if (ret) { | 173 | if (ret) { |
172 | data = kmalloc(dev_info->ring->access.get_bytes_per_datum(dev_info->ring), | 174 | data = kmalloc(ring->access.get_bytes_per_datum(ring), |
173 | GFP_KERNEL); | 175 | GFP_KERNEL); |
174 | if (data == NULL) | 176 | if (data == NULL) |
175 | return -ENOMEM; | 177 | return -ENOMEM; |
176 | ret = dev_info->ring->access.read_last(dev_info->ring, | 178 | ret = ring->access.read_last(ring, |
177 | (u8 *)data); | 179 | (u8 *)data); |
178 | if (ret) | 180 | if (ret) |
179 | goto error_free_data; | 181 | goto error_free_data; |
180 | } else { | 182 | } else { |
181 | ret = -EINVAL; | 183 | ret = -EINVAL; |
182 | goto error_ret; | 184 | goto error_ret; |
183 | } | 185 | } |
184 | len = iio_scan_mask_count_to_right(dev_info, el->number); | 186 | len = iio_scan_mask_count_to_right(ring, el->number); |
185 | if (len < 0) { | 187 | if (len < 0) { |
186 | ret = len; | 188 | ret = len; |
187 | goto error_free_data; | 189 | goto error_free_data; |
@@ -211,11 +213,12 @@ static const u8 read_all_tx_array[] = { | |||
211 | **/ | 213 | **/ |
212 | static int lis3l02dq_read_all(struct lis3l02dq_state *st, u8 *rx_array) | 214 | static int lis3l02dq_read_all(struct lis3l02dq_state *st, u8 *rx_array) |
213 | { | 215 | { |
216 | struct iio_ring_buffer *ring = st->help.indio_dev->ring; | ||
214 | struct spi_transfer *xfers; | 217 | struct spi_transfer *xfers; |
215 | struct spi_message msg; | 218 | struct spi_message msg; |
216 | int ret, i, j = 0; | 219 | int ret, i, j = 0; |
217 | 220 | ||
218 | xfers = kzalloc((st->help.indio_dev->scan_count) * 2 | 221 | xfers = kzalloc((ring->scan_count) * 2 |
219 | * sizeof(*xfers), GFP_KERNEL); | 222 | * sizeof(*xfers), GFP_KERNEL); |
220 | if (!xfers) | 223 | if (!xfers) |
221 | return -ENOMEM; | 224 | return -ENOMEM; |
@@ -223,7 +226,7 @@ static int lis3l02dq_read_all(struct lis3l02dq_state *st, u8 *rx_array) | |||
223 | mutex_lock(&st->buf_lock); | 226 | mutex_lock(&st->buf_lock); |
224 | 227 | ||
225 | for (i = 0; i < ARRAY_SIZE(read_all_tx_array)/4; i++) { | 228 | for (i = 0; i < ARRAY_SIZE(read_all_tx_array)/4; i++) { |
226 | if (st->help.indio_dev->scan_mask & (1 << i)) { | 229 | if (ring->scan_mask & (1 << i)) { |
227 | /* lower byte */ | 230 | /* lower byte */ |
228 | xfers[j].tx_buf = st->tx + 2*j; | 231 | xfers[j].tx_buf = st->tx + 2*j; |
229 | st->tx[2*j] = read_all_tx_array[i*4]; | 232 | st->tx[2*j] = read_all_tx_array[i*4]; |
@@ -251,7 +254,7 @@ static int lis3l02dq_read_all(struct lis3l02dq_state *st, u8 *rx_array) | |||
251 | * values in alternate bytes | 254 | * values in alternate bytes |
252 | */ | 255 | */ |
253 | spi_message_init(&msg); | 256 | spi_message_init(&msg); |
254 | for (j = 0; j < st->help.indio_dev->scan_count * 2; j++) | 257 | for (j = 0; j < ring->scan_count * 2; j++) |
255 | spi_message_add_tail(&xfers[j], &msg); | 258 | spi_message_add_tail(&xfers[j], &msg); |
256 | 259 | ||
257 | ret = spi_sync(st->us, &msg); | 260 | ret = spi_sync(st->us, &msg); |
@@ -279,13 +282,13 @@ static int lis3l02dq_get_ring_element(struct iio_sw_ring_helper_state *h, | |||
279 | u8 *rx_array ; | 282 | u8 *rx_array ; |
280 | s16 *data = (s16 *)buf; | 283 | s16 *data = (s16 *)buf; |
281 | 284 | ||
282 | rx_array = kzalloc(4 * (h->indio_dev->scan_count), GFP_KERNEL); | 285 | rx_array = kzalloc(4 * (h->indio_dev->ring->scan_count), GFP_KERNEL); |
283 | if (rx_array == NULL) | 286 | if (rx_array == NULL) |
284 | return -ENOMEM; | 287 | return -ENOMEM; |
285 | ret = lis3l02dq_read_all(lis3l02dq_h_to_s(h), rx_array); | 288 | ret = lis3l02dq_read_all(lis3l02dq_h_to_s(h), rx_array); |
286 | if (ret < 0) | 289 | if (ret < 0) |
287 | return ret; | 290 | return ret; |
288 | for (i = 0; i < h->indio_dev->scan_count; i++) | 291 | for (i = 0; i < h->indio_dev->ring->scan_count; i++) |
289 | data[i] = combine_8_to_16(rx_array[i*4+1], | 292 | data[i] = combine_8_to_16(rx_array[i*4+1], |
290 | rx_array[i*4+3]); | 293 | rx_array[i*4+3]); |
291 | kfree(rx_array); | 294 | kfree(rx_array); |
@@ -481,14 +484,7 @@ int lis3l02dq_configure_ring(struct iio_dev *indio_dev) | |||
481 | struct iio_sw_ring_helper_state *h = iio_dev_get_devdata(indio_dev); | 484 | struct iio_sw_ring_helper_state *h = iio_dev_get_devdata(indio_dev); |
482 | struct iio_ring_buffer *ring; | 485 | struct iio_ring_buffer *ring; |
483 | INIT_WORK(&h->work_trigger_to_ring, lis3l02dq_trigger_bh_to_ring); | 486 | INIT_WORK(&h->work_trigger_to_ring, lis3l02dq_trigger_bh_to_ring); |
484 | /* Set default scan mode */ | ||
485 | h->get_ring_element = &lis3l02dq_get_ring_element; | 487 | h->get_ring_element = &lis3l02dq_get_ring_element; |
486 | iio_scan_mask_set(indio_dev, iio_scan_el_accel_x.number); | ||
487 | iio_scan_mask_set(indio_dev, iio_scan_el_accel_y.number); | ||
488 | iio_scan_mask_set(indio_dev, iio_scan_el_accel_z.number); | ||
489 | indio_dev->scan_timestamp = true; | ||
490 | |||
491 | indio_dev->scan_el_attrs = &lis3l02dq_scan_el_group; | ||
492 | 488 | ||
493 | ring = iio_sw_rb_allocate(indio_dev); | 489 | ring = iio_sw_rb_allocate(indio_dev); |
494 | if (!ring) | 490 | if (!ring) |
@@ -498,11 +494,18 @@ int lis3l02dq_configure_ring(struct iio_dev *indio_dev) | |||
498 | /* Effectively select the ring buffer implementation */ | 494 | /* Effectively select the ring buffer implementation */ |
499 | iio_ring_sw_register_funcs(&ring->access); | 495 | iio_ring_sw_register_funcs(&ring->access); |
500 | ring->bpe = 2; | 496 | ring->bpe = 2; |
497 | ring->scan_el_attrs = &lis3l02dq_scan_el_group; | ||
498 | ring->scan_timestamp = true; | ||
501 | ring->preenable = &iio_sw_ring_preenable; | 499 | ring->preenable = &iio_sw_ring_preenable; |
502 | ring->postenable = &iio_triggered_ring_postenable; | 500 | ring->postenable = &iio_triggered_ring_postenable; |
503 | ring->predisable = &iio_triggered_ring_predisable; | 501 | ring->predisable = &iio_triggered_ring_predisable; |
504 | ring->owner = THIS_MODULE; | 502 | ring->owner = THIS_MODULE; |
505 | 503 | ||
504 | /* Set default scan mode */ | ||
505 | iio_scan_mask_set(ring, iio_scan_el_accel_x.number); | ||
506 | iio_scan_mask_set(ring, iio_scan_el_accel_y.number); | ||
507 | iio_scan_mask_set(ring, iio_scan_el_accel_z.number); | ||
508 | |||
506 | ret = iio_alloc_pollfunc(indio_dev, NULL, &lis3l02dq_poll_func_th); | 509 | ret = iio_alloc_pollfunc(indio_dev, NULL, &lis3l02dq_poll_func_th); |
507 | if (ret) | 510 | if (ret) |
508 | goto error_iio_sw_rb_free;; | 511 | goto error_iio_sw_rb_free;; |
diff --git a/drivers/staging/iio/accel/sca3000_ring.c b/drivers/staging/iio/accel/sca3000_ring.c index eff5b9a2de3..6d19d15c6d7 100644 --- a/drivers/staging/iio/accel/sca3000_ring.c +++ b/drivers/staging/iio/accel/sca3000_ring.c | |||
@@ -264,12 +264,12 @@ static inline void sca3000_rb_free(struct iio_ring_buffer *r) | |||
264 | 264 | ||
265 | int sca3000_configure_ring(struct iio_dev *indio_dev) | 265 | int sca3000_configure_ring(struct iio_dev *indio_dev) |
266 | { | 266 | { |
267 | indio_dev->scan_el_attrs = &sca3000_scan_el_group; | ||
268 | indio_dev->ring = sca3000_rb_allocate(indio_dev); | 267 | indio_dev->ring = sca3000_rb_allocate(indio_dev); |
269 | if (indio_dev->ring == NULL) | 268 | if (indio_dev->ring == NULL) |
270 | return -ENOMEM; | 269 | return -ENOMEM; |
271 | indio_dev->modes |= INDIO_RING_HARDWARE_BUFFER; | 270 | indio_dev->modes |= INDIO_RING_HARDWARE_BUFFER; |
272 | 271 | ||
272 | indio_dev->ring->scan_el_attrs = &sca3000_scan_el_group; | ||
273 | indio_dev->ring->access.rip_lots = &sca3000_rip_hw_rb; | 273 | indio_dev->ring->access.rip_lots = &sca3000_rip_hw_rb; |
274 | indio_dev->ring->access.get_length = &sca3000_ring_get_length; | 274 | indio_dev->ring->access.get_length = &sca3000_ring_get_length; |
275 | indio_dev->ring->access.get_bytes_per_datum = &sca3000_ring_get_bytes_per_datum; | 275 | indio_dev->ring->access.get_bytes_per_datum = &sca3000_ring_get_bytes_per_datum; |
diff --git a/drivers/staging/iio/adc/max1363_core.c b/drivers/staging/iio/adc/max1363_core.c index 6435e509dd5..1dc428fc0cc 100644 --- a/drivers/staging/iio/adc/max1363_core.c +++ b/drivers/staging/iio/adc/max1363_core.c | |||
@@ -1631,7 +1631,6 @@ static int __devinit max1363_probe(struct i2c_client *client, | |||
1631 | st->indio_dev->attrs = st->chip_info->dev_attrs; | 1631 | st->indio_dev->attrs = st->chip_info->dev_attrs; |
1632 | 1632 | ||
1633 | /* Todo: this shouldn't be here. */ | 1633 | /* Todo: this shouldn't be here. */ |
1634 | st->indio_dev->scan_el_attrs = st->chip_info->scan_attrs; | ||
1635 | st->indio_dev->dev_data = (void *)(st); | 1634 | st->indio_dev->dev_data = (void *)(st); |
1636 | st->indio_dev->driver_module = THIS_MODULE; | 1635 | st->indio_dev->driver_module = THIS_MODULE; |
1637 | st->indio_dev->modes = INDIO_DIRECT_MODE; | 1636 | st->indio_dev->modes = INDIO_DIRECT_MODE; |
diff --git a/drivers/staging/iio/adc/max1363_ring.c b/drivers/staging/iio/adc/max1363_ring.c index edac0ba6652..1d6ce54e9a8 100644 --- a/drivers/staging/iio/adc/max1363_ring.c +++ b/drivers/staging/iio/adc/max1363_ring.c | |||
@@ -30,6 +30,7 @@ | |||
30 | /* Todo: test this */ | 30 | /* Todo: test this */ |
31 | int max1363_single_channel_from_ring(long mask, struct max1363_state *st) | 31 | int max1363_single_channel_from_ring(long mask, struct max1363_state *st) |
32 | { | 32 | { |
33 | struct iio_ring_buffer *ring = st->indio_dev->ring; | ||
33 | unsigned long numvals; | 34 | unsigned long numvals; |
34 | int count = 0, ret; | 35 | int count = 0, ret; |
35 | u8 *ring_data; | 36 | u8 *ring_data; |
@@ -44,8 +45,7 @@ int max1363_single_channel_from_ring(long mask, struct max1363_state *st) | |||
44 | ret = -ENOMEM; | 45 | ret = -ENOMEM; |
45 | goto error_ret; | 46 | goto error_ret; |
46 | } | 47 | } |
47 | ret = st->indio_dev->ring->access.read_last(st->indio_dev->ring, | 48 | ret = ring->access.read_last(ring, ring_data); |
48 | ring_data); | ||
49 | if (ret) | 49 | if (ret) |
50 | goto error_free_ring_data; | 50 | goto error_free_ring_data; |
51 | /* Need a count of channels prior to this one */ | 51 | /* Need a count of channels prior to this one */ |
@@ -77,6 +77,7 @@ error_ret: | |||
77 | static int max1363_ring_preenable(struct iio_dev *indio_dev) | 77 | static int max1363_ring_preenable(struct iio_dev *indio_dev) |
78 | { | 78 | { |
79 | struct max1363_state *st = indio_dev->dev_data; | 79 | struct max1363_state *st = indio_dev->dev_data; |
80 | struct iio_ring_buffer *ring = indio_dev->ring; | ||
80 | size_t d_size; | 81 | size_t d_size; |
81 | unsigned long numvals; | 82 | unsigned long numvals; |
82 | 83 | ||
@@ -84,7 +85,7 @@ static int max1363_ring_preenable(struct iio_dev *indio_dev) | |||
84 | * Need to figure out the current mode based upon the requested | 85 | * Need to figure out the current mode based upon the requested |
85 | * scan mask in iio_dev | 86 | * scan mask in iio_dev |
86 | */ | 87 | */ |
87 | st->current_mode = max1363_match_mode(st->indio_dev->scan_mask, | 88 | st->current_mode = max1363_match_mode(ring->scan_mask, |
88 | st->chip_info); | 89 | st->chip_info); |
89 | if (!st->current_mode) | 90 | if (!st->current_mode) |
90 | return -EINVAL; | 91 | return -EINVAL; |
@@ -92,14 +93,14 @@ static int max1363_ring_preenable(struct iio_dev *indio_dev) | |||
92 | max1363_set_scan_mode(st); | 93 | max1363_set_scan_mode(st); |
93 | 94 | ||
94 | numvals = hweight_long(st->current_mode->modemask); | 95 | numvals = hweight_long(st->current_mode->modemask); |
95 | if (indio_dev->ring->access.set_bytes_per_datum) { | 96 | if (ring->access.set_bytes_per_datum) { |
96 | if (st->chip_info->bits != 8) | 97 | if (st->chip_info->bits != 8) |
97 | d_size = numvals*2 + sizeof(s64); | 98 | d_size = numvals*2 + sizeof(s64); |
98 | else | 99 | else |
99 | d_size = numvals + sizeof(s64); | 100 | d_size = numvals + sizeof(s64); |
100 | if (d_size % 8) | 101 | if (d_size % 8) |
101 | d_size += 8 - (d_size % 8); | 102 | d_size += 8 - (d_size % 8); |
102 | indio_dev->ring->access.set_bytes_per_datum(indio_dev->ring, d_size); | 103 | ring->access.set_bytes_per_datum(ring, d_size); |
103 | } | 104 | } |
104 | 105 | ||
105 | return 0; | 106 | return 0; |
@@ -135,7 +136,7 @@ static void max1363_poll_bh_to_ring(struct work_struct *work_s) | |||
135 | struct max1363_state *st = container_of(work_s, struct max1363_state, | 136 | struct max1363_state *st = container_of(work_s, struct max1363_state, |
136 | poll_work); | 137 | poll_work); |
137 | struct iio_dev *indio_dev = st->indio_dev; | 138 | struct iio_dev *indio_dev = st->indio_dev; |
138 | struct iio_sw_ring_buffer *ring = iio_to_sw_ring(indio_dev->ring); | 139 | struct iio_sw_ring_buffer *sw_ring = iio_to_sw_ring(indio_dev->ring); |
139 | s64 time_ns; | 140 | s64 time_ns; |
140 | __u8 *rxbuf; | 141 | __u8 *rxbuf; |
141 | int b_sent; | 142 | int b_sent; |
@@ -175,7 +176,7 @@ static void max1363_poll_bh_to_ring(struct work_struct *work_s) | |||
175 | 176 | ||
176 | memcpy(rxbuf + d_size - sizeof(s64), &time_ns, sizeof(time_ns)); | 177 | memcpy(rxbuf + d_size - sizeof(s64), &time_ns, sizeof(time_ns)); |
177 | 178 | ||
178 | indio_dev->ring->access.store_to(&ring->buf, rxbuf, time_ns); | 179 | indio_dev->ring->access.store_to(&sw_ring->buf, rxbuf, time_ns); |
179 | done: | 180 | done: |
180 | kfree(rxbuf); | 181 | kfree(rxbuf); |
181 | atomic_dec(&st->protect_ring); | 182 | atomic_dec(&st->protect_ring); |
@@ -193,12 +194,13 @@ int max1363_register_ring_funcs_and_init(struct iio_dev *indio_dev) | |||
193 | goto error_ret; | 194 | goto error_ret; |
194 | } | 195 | } |
195 | /* Effectively select the ring buffer implementation */ | 196 | /* Effectively select the ring buffer implementation */ |
196 | iio_ring_sw_register_funcs(&st->indio_dev->ring->access); | 197 | iio_ring_sw_register_funcs(&indio_dev->ring->access); |
197 | ret = iio_alloc_pollfunc(indio_dev, NULL, &max1363_poll_func_th); | 198 | ret = iio_alloc_pollfunc(indio_dev, NULL, &max1363_poll_func_th); |
198 | if (ret) | 199 | if (ret) |
199 | goto error_deallocate_sw_rb; | 200 | goto error_deallocate_sw_rb; |
200 | 201 | ||
201 | /* Ring buffer functions - here trigger setup related */ | 202 | /* Ring buffer functions - here trigger setup related */ |
203 | indio_dev->ring->scan_el_attrs = st->chip_info->scan_attrs; | ||
202 | indio_dev->ring->postenable = &iio_triggered_ring_postenable; | 204 | indio_dev->ring->postenable = &iio_triggered_ring_postenable; |
203 | indio_dev->ring->preenable = &max1363_ring_preenable; | 205 | indio_dev->ring->preenable = &max1363_ring_preenable; |
204 | indio_dev->ring->predisable = &iio_triggered_ring_predisable; | 206 | indio_dev->ring->predisable = &iio_triggered_ring_predisable; |
diff --git a/drivers/staging/iio/gyro/adis16260_ring.c b/drivers/staging/iio/gyro/adis16260_ring.c index 055d5e8609e..03348605dd8 100644 --- a/drivers/staging/iio/gyro/adis16260_ring.c +++ b/drivers/staging/iio/gyro/adis16260_ring.c | |||
@@ -110,11 +110,11 @@ static void adis16260_trigger_bh_to_ring(struct work_struct *work_s) | |||
110 | struct adis16260_state *st | 110 | struct adis16260_state *st |
111 | = container_of(work_s, struct adis16260_state, | 111 | = container_of(work_s, struct adis16260_state, |
112 | work_trigger_to_ring); | 112 | work_trigger_to_ring); |
113 | struct iio_ring_buffer *ring = st->indio_dev->ring; | ||
113 | 114 | ||
114 | int i = 0; | 115 | int i = 0; |
115 | s16 *data; | 116 | s16 *data; |
116 | size_t datasize = st->indio_dev | 117 | size_t datasize = ring->access.get_bytes_per_datum(ring); |
117 | ->ring->access.get_bytes_per_datum(st->indio_dev->ring); | ||
118 | 118 | ||
119 | data = kmalloc(datasize , GFP_KERNEL); | 119 | data = kmalloc(datasize , GFP_KERNEL); |
120 | if (data == NULL) { | 120 | if (data == NULL) { |
@@ -122,17 +122,17 @@ static void adis16260_trigger_bh_to_ring(struct work_struct *work_s) | |||
122 | return; | 122 | return; |
123 | } | 123 | } |
124 | 124 | ||
125 | if (st->indio_dev->scan_count) | 125 | if (ring->scan_count) |
126 | if (adis16260_read_ring_data(&st->indio_dev->dev, st->rx) >= 0) | 126 | if (adis16260_read_ring_data(&st->indio_dev->dev, st->rx) >= 0) |
127 | for (; i < st->indio_dev->scan_count; i++) | 127 | for (; i < ring->scan_count; i++) |
128 | data[i] = be16_to_cpup( | 128 | data[i] = be16_to_cpup( |
129 | (__be16 *)&(st->rx[i*2])); | 129 | (__be16 *)&(st->rx[i*2])); |
130 | 130 | ||
131 | /* Guaranteed to be aligned with 8 byte boundary */ | 131 | /* Guaranteed to be aligned with 8 byte boundary */ |
132 | if (st->indio_dev->scan_timestamp) | 132 | if (ring->scan_timestamp) |
133 | *((s64 *)(data + ((i + 3)/4)*4)) = st->last_timestamp; | 133 | *((s64 *)(data + ((i + 3)/4)*4)) = st->last_timestamp; |
134 | 134 | ||
135 | st->indio_dev->ring->access.store_to(st->indio_dev->ring, | 135 | ring->access.store_to(ring, |
136 | (u8 *)data, | 136 | (u8 *)data, |
137 | st->last_timestamp); | 137 | st->last_timestamp); |
138 | 138 | ||
@@ -154,16 +154,6 @@ int adis16260_configure_ring(struct iio_dev *indio_dev) | |||
154 | struct adis16260_state *st = indio_dev->dev_data; | 154 | struct adis16260_state *st = indio_dev->dev_data; |
155 | struct iio_ring_buffer *ring; | 155 | struct iio_ring_buffer *ring; |
156 | INIT_WORK(&st->work_trigger_to_ring, adis16260_trigger_bh_to_ring); | 156 | INIT_WORK(&st->work_trigger_to_ring, adis16260_trigger_bh_to_ring); |
157 | /* Set default scan mode */ | ||
158 | |||
159 | iio_scan_mask_set(indio_dev, iio_scan_el_supply.number); | ||
160 | iio_scan_mask_set(indio_dev, iio_scan_el_gyro.number); | ||
161 | iio_scan_mask_set(indio_dev, iio_scan_el_aux_adc.number); | ||
162 | iio_scan_mask_set(indio_dev, iio_scan_el_temp.number); | ||
163 | iio_scan_mask_set(indio_dev, iio_scan_el_angl.number); | ||
164 | indio_dev->scan_timestamp = true; | ||
165 | |||
166 | indio_dev->scan_el_attrs = &adis16260_scan_el_group; | ||
167 | 157 | ||
168 | ring = iio_sw_rb_allocate(indio_dev); | 158 | ring = iio_sw_rb_allocate(indio_dev); |
169 | if (!ring) { | 159 | if (!ring) { |
@@ -174,11 +164,20 @@ int adis16260_configure_ring(struct iio_dev *indio_dev) | |||
174 | /* Effectively select the ring buffer implementation */ | 164 | /* Effectively select the ring buffer implementation */ |
175 | iio_ring_sw_register_funcs(&ring->access); | 165 | iio_ring_sw_register_funcs(&ring->access); |
176 | ring->bpe = 2; | 166 | ring->bpe = 2; |
167 | ring->scan_el_attrs = &adis16260_scan_el_group; | ||
168 | ring->scan_timestamp = true; | ||
177 | ring->preenable = &iio_sw_ring_preenable; | 169 | ring->preenable = &iio_sw_ring_preenable; |
178 | ring->postenable = &iio_triggered_ring_postenable; | 170 | ring->postenable = &iio_triggered_ring_postenable; |
179 | ring->predisable = &iio_triggered_ring_predisable; | 171 | ring->predisable = &iio_triggered_ring_predisable; |
180 | ring->owner = THIS_MODULE; | 172 | ring->owner = THIS_MODULE; |
181 | 173 | ||
174 | /* Set default scan mode */ | ||
175 | iio_scan_mask_set(ring, iio_scan_el_supply.number); | ||
176 | iio_scan_mask_set(ring, iio_scan_el_gyro.number); | ||
177 | iio_scan_mask_set(ring, iio_scan_el_aux_adc.number); | ||
178 | iio_scan_mask_set(ring, iio_scan_el_temp.number); | ||
179 | iio_scan_mask_set(ring, iio_scan_el_angl.number); | ||
180 | |||
182 | ret = iio_alloc_pollfunc(indio_dev, NULL, &adis16260_poll_func_th); | 181 | ret = iio_alloc_pollfunc(indio_dev, NULL, &adis16260_poll_func_th); |
183 | if (ret) | 182 | if (ret) |
184 | goto error_iio_sw_rb_free; | 183 | goto error_iio_sw_rb_free; |
diff --git a/drivers/staging/iio/iio.h b/drivers/staging/iio/iio.h index 9d0ca128679..3072c456221 100644 --- a/drivers/staging/iio/iio.h +++ b/drivers/staging/iio/iio.h | |||
@@ -90,12 +90,7 @@ void iio_remove_event_from_list(struct iio_event_handler_list *el, | |||
90 | * @ring: [DRIVER] any ring buffer present | 90 | * @ring: [DRIVER] any ring buffer present |
91 | * @mlock: [INTERN] lock used to prevent simultaneous device state | 91 | * @mlock: [INTERN] lock used to prevent simultaneous device state |
92 | * changes | 92 | * changes |
93 | * @scan_el_attrs: [DRIVER] control of scan elements if that scan mode | ||
94 | * control method is used | ||
95 | * @scan_count: [INTERN] the number of elements in the current scan mode | ||
96 | * @scan_mask: [INTERN] bitmask used in masking scan mode elements | ||
97 | * @available_scan_masks: [DRIVER] optional array of allowed bitmasks | 93 | * @available_scan_masks: [DRIVER] optional array of allowed bitmasks |
98 | * @scan_timestamp: [INTERN] does the scan mode include a timestamp | ||
99 | * @trig: [INTERN] current device trigger (ring buffer modes) | 94 | * @trig: [INTERN] current device trigger (ring buffer modes) |
100 | * @pollfunc: [DRIVER] function run on trigger being recieved | 95 | * @pollfunc: [DRIVER] function run on trigger being recieved |
101 | **/ | 96 | **/ |
@@ -118,104 +113,11 @@ struct iio_dev { | |||
118 | struct iio_ring_buffer *ring; | 113 | struct iio_ring_buffer *ring; |
119 | struct mutex mlock; | 114 | struct mutex mlock; |
120 | 115 | ||
121 | struct attribute_group *scan_el_attrs; | ||
122 | int scan_count; | ||
123 | |||
124 | u32 scan_mask; | ||
125 | u32 *available_scan_masks; | 116 | u32 *available_scan_masks; |
126 | bool scan_timestamp; | ||
127 | struct iio_trigger *trig; | 117 | struct iio_trigger *trig; |
128 | struct iio_poll_func *pollfunc; | 118 | struct iio_poll_func *pollfunc; |
129 | }; | 119 | }; |
130 | 120 | ||
131 | /* | ||
132 | * These are mainly provided to allow for a change of implementation if a device | ||
133 | * has a large number of scan elements | ||
134 | */ | ||
135 | #define IIO_MAX_SCAN_LENGTH 31 | ||
136 | |||
137 | /* note 0 used as error indicator as it doesn't make sense. */ | ||
138 | static inline u32 iio_scan_mask_match(u32 *av_masks, u32 mask) | ||
139 | { | ||
140 | while (*av_masks) { | ||
141 | if (!(~*av_masks & mask)) | ||
142 | return *av_masks; | ||
143 | av_masks++; | ||
144 | } | ||
145 | return 0; | ||
146 | } | ||
147 | |||
148 | static inline int iio_scan_mask_query(struct iio_dev *dev_info, int bit) | ||
149 | { | ||
150 | u32 mask; | ||
151 | |||
152 | if (bit > IIO_MAX_SCAN_LENGTH) | ||
153 | return -EINVAL; | ||
154 | |||
155 | if (!dev_info->scan_mask) | ||
156 | return 0; | ||
157 | |||
158 | if (dev_info->available_scan_masks) | ||
159 | mask = iio_scan_mask_match(dev_info->available_scan_masks, | ||
160 | dev_info->scan_mask); | ||
161 | else | ||
162 | mask = dev_info->scan_mask; | ||
163 | |||
164 | if (!mask) | ||
165 | return -EINVAL; | ||
166 | |||
167 | return !!(mask & (1 << bit)); | ||
168 | }; | ||
169 | |||
170 | static inline int iio_scan_mask_set(struct iio_dev *dev_info, int bit) | ||
171 | { | ||
172 | u32 mask; | ||
173 | u32 trialmask = dev_info->scan_mask | (1 << bit); | ||
174 | |||
175 | if (bit > IIO_MAX_SCAN_LENGTH) | ||
176 | return -EINVAL; | ||
177 | if (dev_info->available_scan_masks) { | ||
178 | mask = iio_scan_mask_match(dev_info->available_scan_masks, | ||
179 | trialmask); | ||
180 | if (!mask) | ||
181 | return -EINVAL; | ||
182 | } | ||
183 | dev_info->scan_mask = trialmask; | ||
184 | dev_info->scan_count++; | ||
185 | |||
186 | return 0; | ||
187 | }; | ||
188 | |||
189 | static inline int iio_scan_mask_clear(struct iio_dev *dev_info, int bit) | ||
190 | { | ||
191 | if (bit > IIO_MAX_SCAN_LENGTH) | ||
192 | return -EINVAL; | ||
193 | dev_info->scan_mask &= ~(1 << bit); | ||
194 | dev_info->scan_count--; | ||
195 | return 0; | ||
196 | }; | ||
197 | |||
198 | /** | ||
199 | * iio_scan_mask_count_to_right() - how many scan elements occur before here | ||
200 | * @dev_info: the iio_device whose scan mode we are querying | ||
201 | * @bit: which number scan element is this | ||
202 | **/ | ||
203 | static inline int iio_scan_mask_count_to_right(struct iio_dev *dev_info, | ||
204 | int bit) | ||
205 | { | ||
206 | int count = 0; | ||
207 | int mask = (1 << bit); | ||
208 | if (bit > IIO_MAX_SCAN_LENGTH) | ||
209 | return -EINVAL; | ||
210 | while (mask) { | ||
211 | mask >>= 1; | ||
212 | if (mask & dev_info->scan_mask) | ||
213 | count++; | ||
214 | } | ||
215 | |||
216 | return count; | ||
217 | } | ||
218 | |||
219 | /** | 121 | /** |
220 | * iio_device_register() - register a device with the IIO subsystem | 122 | * iio_device_register() - register a device with the IIO subsystem |
221 | * @dev_info: Device structure filled by the device driver | 123 | * @dev_info: Device structure filled by the device driver |
diff --git a/drivers/staging/iio/imu/adis16300_ring.c b/drivers/staging/iio/imu/adis16300_ring.c index 854183c2825..742cad6163c 100644 --- a/drivers/staging/iio/imu/adis16300_ring.c +++ b/drivers/staging/iio/imu/adis16300_ring.c | |||
@@ -134,11 +134,11 @@ static void adis16300_trigger_bh_to_ring(struct work_struct *work_s) | |||
134 | struct adis16300_state *st | 134 | struct adis16300_state *st |
135 | = container_of(work_s, struct adis16300_state, | 135 | = container_of(work_s, struct adis16300_state, |
136 | work_trigger_to_ring); | 136 | work_trigger_to_ring); |
137 | struct iio_ring_buffer *ring = st->indio_dev->ring; | ||
137 | 138 | ||
138 | int i = 0; | 139 | int i = 0; |
139 | s16 *data; | 140 | s16 *data; |
140 | size_t datasize = st->indio_dev | 141 | size_t datasize = ring->access.get_bytes_per_datum(ring); |
141 | ->ring->access.get_bytes_per_datum(st->indio_dev->ring); | ||
142 | 142 | ||
143 | data = kmalloc(datasize , GFP_KERNEL); | 143 | data = kmalloc(datasize , GFP_KERNEL); |
144 | if (data == NULL) { | 144 | if (data == NULL) { |
@@ -146,19 +146,19 @@ static void adis16300_trigger_bh_to_ring(struct work_struct *work_s) | |||
146 | return; | 146 | return; |
147 | } | 147 | } |
148 | 148 | ||
149 | if (st->indio_dev->scan_count) | 149 | if (ring->scan_count) |
150 | if (adis16300_spi_read_burst(&st->indio_dev->dev, st->rx) >= 0) | 150 | if (adis16300_spi_read_burst(&st->indio_dev->dev, st->rx) >= 0) |
151 | for (; i < st->indio_dev->scan_count; i++) | 151 | for (; i < ring->scan_count; i++) |
152 | data[i] = be16_to_cpup( | 152 | data[i] = be16_to_cpup( |
153 | (__be16 *)&(st->rx[i*2])); | 153 | (__be16 *)&(st->rx[i*2])); |
154 | 154 | ||
155 | /* Guaranteed to be aligned with 8 byte boundary */ | 155 | /* Guaranteed to be aligned with 8 byte boundary */ |
156 | if (st->indio_dev->scan_timestamp) | 156 | if (ring->scan_timestamp) |
157 | *((s64 *)(data + ((i + 3)/4)*4)) = st->last_timestamp; | 157 | *((s64 *)(data + ((i + 3)/4)*4)) = st->last_timestamp; |
158 | 158 | ||
159 | st->indio_dev->ring->access.store_to(st->indio_dev->ring, | 159 | ring->access.store_to(ring, |
160 | (u8 *)data, | 160 | (u8 *)data, |
161 | st->last_timestamp); | 161 | st->last_timestamp); |
162 | 162 | ||
163 | iio_trigger_notify_done(st->indio_dev->trig); | 163 | iio_trigger_notify_done(st->indio_dev->trig); |
164 | kfree(data); | 164 | kfree(data); |
@@ -178,20 +178,6 @@ int adis16300_configure_ring(struct iio_dev *indio_dev) | |||
178 | struct adis16300_state *st = indio_dev->dev_data; | 178 | struct adis16300_state *st = indio_dev->dev_data; |
179 | struct iio_ring_buffer *ring; | 179 | struct iio_ring_buffer *ring; |
180 | INIT_WORK(&st->work_trigger_to_ring, adis16300_trigger_bh_to_ring); | 180 | INIT_WORK(&st->work_trigger_to_ring, adis16300_trigger_bh_to_ring); |
181 | /* Set default scan mode */ | ||
182 | |||
183 | iio_scan_mask_set(indio_dev, iio_scan_el_supply.number); | ||
184 | iio_scan_mask_set(indio_dev, iio_scan_el_gyro_x.number); | ||
185 | iio_scan_mask_set(indio_dev, iio_scan_el_accel_x.number); | ||
186 | iio_scan_mask_set(indio_dev, iio_scan_el_accel_y.number); | ||
187 | iio_scan_mask_set(indio_dev, iio_scan_el_accel_z.number); | ||
188 | iio_scan_mask_set(indio_dev, iio_scan_el_temp.number); | ||
189 | iio_scan_mask_set(indio_dev, iio_scan_el_adc_0.number); | ||
190 | iio_scan_mask_set(indio_dev, iio_scan_el_incli_x.number); | ||
191 | iio_scan_mask_set(indio_dev, iio_scan_el_incli_y.number); | ||
192 | indio_dev->scan_timestamp = true; | ||
193 | |||
194 | indio_dev->scan_el_attrs = &adis16300_scan_el_group; | ||
195 | 181 | ||
196 | ring = iio_sw_rb_allocate(indio_dev); | 182 | ring = iio_sw_rb_allocate(indio_dev); |
197 | if (!ring) { | 183 | if (!ring) { |
@@ -202,11 +188,24 @@ int adis16300_configure_ring(struct iio_dev *indio_dev) | |||
202 | /* Effectively select the ring buffer implementation */ | 188 | /* Effectively select the ring buffer implementation */ |
203 | iio_ring_sw_register_funcs(&ring->access); | 189 | iio_ring_sw_register_funcs(&ring->access); |
204 | ring->bpe = 2; | 190 | ring->bpe = 2; |
191 | ring->scan_el_attrs = &adis16300_scan_el_group; | ||
192 | ring->scan_timestamp = true; | ||
205 | ring->preenable = &iio_sw_ring_preenable; | 193 | ring->preenable = &iio_sw_ring_preenable; |
206 | ring->postenable = &iio_triggered_ring_postenable; | 194 | ring->postenable = &iio_triggered_ring_postenable; |
207 | ring->predisable = &iio_triggered_ring_predisable; | 195 | ring->predisable = &iio_triggered_ring_predisable; |
208 | ring->owner = THIS_MODULE; | 196 | ring->owner = THIS_MODULE; |
209 | 197 | ||
198 | /* Set default scan mode */ | ||
199 | iio_scan_mask_set(ring, iio_scan_el_supply.number); | ||
200 | iio_scan_mask_set(ring, iio_scan_el_gyro_x.number); | ||
201 | iio_scan_mask_set(ring, iio_scan_el_accel_x.number); | ||
202 | iio_scan_mask_set(ring, iio_scan_el_accel_y.number); | ||
203 | iio_scan_mask_set(ring, iio_scan_el_accel_z.number); | ||
204 | iio_scan_mask_set(ring, iio_scan_el_temp.number); | ||
205 | iio_scan_mask_set(ring, iio_scan_el_adc_0.number); | ||
206 | iio_scan_mask_set(ring, iio_scan_el_incli_x.number); | ||
207 | iio_scan_mask_set(ring, iio_scan_el_incli_y.number); | ||
208 | |||
210 | ret = iio_alloc_pollfunc(indio_dev, NULL, &adis16300_poll_func_th); | 209 | ret = iio_alloc_pollfunc(indio_dev, NULL, &adis16300_poll_func_th); |
211 | if (ret) | 210 | if (ret) |
212 | goto error_iio_sw_rb_free; | 211 | goto error_iio_sw_rb_free; |
diff --git a/drivers/staging/iio/imu/adis16350_ring.c b/drivers/staging/iio/imu/adis16350_ring.c index 9620cbe67ed..a0b80e40d12 100644 --- a/drivers/staging/iio/imu/adis16350_ring.c +++ b/drivers/staging/iio/imu/adis16350_ring.c | |||
@@ -134,11 +134,11 @@ static void adis16350_trigger_bh_to_ring(struct work_struct *work_s) | |||
134 | struct adis16350_state *st | 134 | struct adis16350_state *st |
135 | = container_of(work_s, struct adis16350_state, | 135 | = container_of(work_s, struct adis16350_state, |
136 | work_trigger_to_ring); | 136 | work_trigger_to_ring); |
137 | struct iio_ring_buffer *ring = st->indio_dev->ring; | ||
137 | 138 | ||
138 | int i = 0; | 139 | int i = 0; |
139 | s16 *data; | 140 | s16 *data; |
140 | size_t datasize = st->indio_dev | 141 | size_t datasize = ring->access.get_bytes_per_datum(ring); |
141 | ->ring->access.get_bytes_per_datum(st->indio_dev->ring); | ||
142 | 142 | ||
143 | data = kmalloc(datasize , GFP_KERNEL); | 143 | data = kmalloc(datasize , GFP_KERNEL); |
144 | if (data == NULL) { | 144 | if (data == NULL) { |
@@ -146,19 +146,19 @@ static void adis16350_trigger_bh_to_ring(struct work_struct *work_s) | |||
146 | return; | 146 | return; |
147 | } | 147 | } |
148 | 148 | ||
149 | if (st->indio_dev->scan_count) | 149 | if (ring->scan_count) |
150 | if (adis16350_spi_read_burst(&st->indio_dev->dev, st->rx) >= 0) | 150 | if (adis16350_spi_read_burst(&st->indio_dev->dev, st->rx) >= 0) |
151 | for (; i < st->indio_dev->scan_count; i++) | 151 | for (; i < ring->scan_count; i++) |
152 | data[i] = be16_to_cpup( | 152 | data[i] = be16_to_cpup( |
153 | (__be16 *)&(st->rx[i*2])); | 153 | (__be16 *)&(st->rx[i*2])); |
154 | 154 | ||
155 | /* Guaranteed to be aligned with 8 byte boundary */ | 155 | /* Guaranteed to be aligned with 8 byte boundary */ |
156 | if (st->indio_dev->scan_timestamp) | 156 | if (ring->scan_timestamp) |
157 | *((s64 *)(data + ((i + 3)/4)*4)) = st->last_timestamp; | 157 | *((s64 *)(data + ((i + 3)/4)*4)) = st->last_timestamp; |
158 | 158 | ||
159 | st->indio_dev->ring->access.store_to(st->indio_dev->ring, | 159 | ring->access.store_to(ring, |
160 | (u8 *)data, | 160 | (u8 *)data, |
161 | st->last_timestamp); | 161 | st->last_timestamp); |
162 | 162 | ||
163 | iio_trigger_notify_done(st->indio_dev->trig); | 163 | iio_trigger_notify_done(st->indio_dev->trig); |
164 | kfree(data); | 164 | kfree(data); |
@@ -178,22 +178,6 @@ int adis16350_configure_ring(struct iio_dev *indio_dev) | |||
178 | struct adis16350_state *st = indio_dev->dev_data; | 178 | struct adis16350_state *st = indio_dev->dev_data; |
179 | struct iio_ring_buffer *ring; | 179 | struct iio_ring_buffer *ring; |
180 | INIT_WORK(&st->work_trigger_to_ring, adis16350_trigger_bh_to_ring); | 180 | INIT_WORK(&st->work_trigger_to_ring, adis16350_trigger_bh_to_ring); |
181 | /* Set default scan mode */ | ||
182 | |||
183 | iio_scan_mask_set(indio_dev, iio_scan_el_supply.number); | ||
184 | iio_scan_mask_set(indio_dev, iio_scan_el_gyro_x.number); | ||
185 | iio_scan_mask_set(indio_dev, iio_scan_el_gyro_y.number); | ||
186 | iio_scan_mask_set(indio_dev, iio_scan_el_gyro_z.number); | ||
187 | iio_scan_mask_set(indio_dev, iio_scan_el_accel_x.number); | ||
188 | iio_scan_mask_set(indio_dev, iio_scan_el_accel_y.number); | ||
189 | iio_scan_mask_set(indio_dev, iio_scan_el_accel_z.number); | ||
190 | iio_scan_mask_set(indio_dev, iio_scan_el_temp_x.number); | ||
191 | iio_scan_mask_set(indio_dev, iio_scan_el_temp_y.number); | ||
192 | iio_scan_mask_set(indio_dev, iio_scan_el_temp_z.number); | ||
193 | iio_scan_mask_set(indio_dev, iio_scan_el_adc_0.number); | ||
194 | indio_dev->scan_timestamp = true; | ||
195 | |||
196 | indio_dev->scan_el_attrs = &adis16350_scan_el_group; | ||
197 | 181 | ||
198 | ring = iio_sw_rb_allocate(indio_dev); | 182 | ring = iio_sw_rb_allocate(indio_dev); |
199 | if (!ring) { | 183 | if (!ring) { |
@@ -204,11 +188,26 @@ int adis16350_configure_ring(struct iio_dev *indio_dev) | |||
204 | /* Effectively select the ring buffer implementation */ | 188 | /* Effectively select the ring buffer implementation */ |
205 | iio_ring_sw_register_funcs(&ring->access); | 189 | iio_ring_sw_register_funcs(&ring->access); |
206 | ring->bpe = 2; | 190 | ring->bpe = 2; |
191 | ring->scan_el_attrs = &adis16350_scan_el_group; | ||
192 | ring->scan_timestamp = true; | ||
207 | ring->preenable = &iio_sw_ring_preenable; | 193 | ring->preenable = &iio_sw_ring_preenable; |
208 | ring->postenable = &iio_triggered_ring_postenable; | 194 | ring->postenable = &iio_triggered_ring_postenable; |
209 | ring->predisable = &iio_triggered_ring_predisable; | 195 | ring->predisable = &iio_triggered_ring_predisable; |
210 | ring->owner = THIS_MODULE; | 196 | ring->owner = THIS_MODULE; |
211 | 197 | ||
198 | /* Set default scan mode */ | ||
199 | iio_scan_mask_set(ring, iio_scan_el_supply.number); | ||
200 | iio_scan_mask_set(ring, iio_scan_el_gyro_x.number); | ||
201 | iio_scan_mask_set(ring, iio_scan_el_gyro_y.number); | ||
202 | iio_scan_mask_set(ring, iio_scan_el_gyro_z.number); | ||
203 | iio_scan_mask_set(ring, iio_scan_el_accel_x.number); | ||
204 | iio_scan_mask_set(ring, iio_scan_el_accel_y.number); | ||
205 | iio_scan_mask_set(ring, iio_scan_el_accel_z.number); | ||
206 | iio_scan_mask_set(ring, iio_scan_el_temp_x.number); | ||
207 | iio_scan_mask_set(ring, iio_scan_el_temp_y.number); | ||
208 | iio_scan_mask_set(ring, iio_scan_el_temp_z.number); | ||
209 | iio_scan_mask_set(ring, iio_scan_el_adc_0.number); | ||
210 | |||
212 | ret = iio_alloc_pollfunc(indio_dev, NULL, &adis16350_poll_func_th); | 211 | ret = iio_alloc_pollfunc(indio_dev, NULL, &adis16350_poll_func_th); |
213 | if (ret) | 212 | if (ret) |
214 | goto error_iio_sw_rb_free; | 213 | goto error_iio_sw_rb_free; |
diff --git a/drivers/staging/iio/imu/adis16400_ring.c b/drivers/staging/iio/imu/adis16400_ring.c index c8e23161d00..667f77bb7d7 100644 --- a/drivers/staging/iio/imu/adis16400_ring.c +++ b/drivers/staging/iio/imu/adis16400_ring.c | |||
@@ -143,11 +143,11 @@ static void adis16400_trigger_bh_to_ring(struct work_struct *work_s) | |||
143 | struct adis16400_state *st | 143 | struct adis16400_state *st |
144 | = container_of(work_s, struct adis16400_state, | 144 | = container_of(work_s, struct adis16400_state, |
145 | work_trigger_to_ring); | 145 | work_trigger_to_ring); |
146 | struct iio_ring_buffer *ring = st->indio_dev->ring; | ||
146 | 147 | ||
147 | int i = 0; | 148 | int i = 0; |
148 | s16 *data; | 149 | s16 *data; |
149 | size_t datasize = st->indio_dev | 150 | size_t datasize = ring->access.get_bytes_per_datum(ring); |
150 | ->ring->access.get_bytes_per_datum(st->indio_dev->ring); | ||
151 | 151 | ||
152 | data = kmalloc(datasize , GFP_KERNEL); | 152 | data = kmalloc(datasize , GFP_KERNEL); |
153 | if (data == NULL) { | 153 | if (data == NULL) { |
@@ -155,19 +155,19 @@ static void adis16400_trigger_bh_to_ring(struct work_struct *work_s) | |||
155 | return; | 155 | return; |
156 | } | 156 | } |
157 | 157 | ||
158 | if (st->indio_dev->scan_count) | 158 | if (ring->scan_count) |
159 | if (adis16400_spi_read_burst(&st->indio_dev->dev, st->rx) >= 0) | 159 | if (adis16400_spi_read_burst(&st->indio_dev->dev, st->rx) >= 0) |
160 | for (; i < st->indio_dev->scan_count; i++) | 160 | for (; i < ring->scan_count; i++) |
161 | data[i] = be16_to_cpup( | 161 | data[i] = be16_to_cpup( |
162 | (__be16 *)&(st->rx[i*2])); | 162 | (__be16 *)&(st->rx[i*2])); |
163 | 163 | ||
164 | /* Guaranteed to be aligned with 8 byte boundary */ | 164 | /* Guaranteed to be aligned with 8 byte boundary */ |
165 | if (st->indio_dev->scan_timestamp) | 165 | if (ring->scan_timestamp) |
166 | *((s64 *)(data + ((i + 3)/4)*4)) = st->last_timestamp; | 166 | *((s64 *)(data + ((i + 3)/4)*4)) = st->last_timestamp; |
167 | 167 | ||
168 | st->indio_dev->ring->access.store_to(st->indio_dev->ring, | 168 | ring->access.store_to(ring, |
169 | (u8 *)data, | 169 | (u8 *) data, |
170 | st->last_timestamp); | 170 | st->last_timestamp); |
171 | 171 | ||
172 | iio_trigger_notify_done(st->indio_dev->trig); | 172 | iio_trigger_notify_done(st->indio_dev->trig); |
173 | kfree(data); | 173 | kfree(data); |
@@ -187,23 +187,6 @@ int adis16400_configure_ring(struct iio_dev *indio_dev) | |||
187 | struct adis16400_state *st = indio_dev->dev_data; | 187 | struct adis16400_state *st = indio_dev->dev_data; |
188 | struct iio_ring_buffer *ring; | 188 | struct iio_ring_buffer *ring; |
189 | INIT_WORK(&st->work_trigger_to_ring, adis16400_trigger_bh_to_ring); | 189 | INIT_WORK(&st->work_trigger_to_ring, adis16400_trigger_bh_to_ring); |
190 | /* Set default scan mode */ | ||
191 | |||
192 | iio_scan_mask_set(indio_dev, iio_scan_el_supply.number); | ||
193 | iio_scan_mask_set(indio_dev, iio_scan_el_gyro_x.number); | ||
194 | iio_scan_mask_set(indio_dev, iio_scan_el_gyro_y.number); | ||
195 | iio_scan_mask_set(indio_dev, iio_scan_el_gyro_z.number); | ||
196 | iio_scan_mask_set(indio_dev, iio_scan_el_accel_x.number); | ||
197 | iio_scan_mask_set(indio_dev, iio_scan_el_accel_y.number); | ||
198 | iio_scan_mask_set(indio_dev, iio_scan_el_accel_z.number); | ||
199 | iio_scan_mask_set(indio_dev, iio_scan_el_magn_x.number); | ||
200 | iio_scan_mask_set(indio_dev, iio_scan_el_magn_y.number); | ||
201 | iio_scan_mask_set(indio_dev, iio_scan_el_magn_z.number); | ||
202 | iio_scan_mask_set(indio_dev, iio_scan_el_temp.number); | ||
203 | iio_scan_mask_set(indio_dev, iio_scan_el_adc_0.number); | ||
204 | indio_dev->scan_timestamp = true; | ||
205 | |||
206 | indio_dev->scan_el_attrs = &adis16400_scan_el_group; | ||
207 | 190 | ||
208 | ring = iio_sw_rb_allocate(indio_dev); | 191 | ring = iio_sw_rb_allocate(indio_dev); |
209 | if (!ring) { | 192 | if (!ring) { |
@@ -214,11 +197,27 @@ int adis16400_configure_ring(struct iio_dev *indio_dev) | |||
214 | /* Effectively select the ring buffer implementation */ | 197 | /* Effectively select the ring buffer implementation */ |
215 | iio_ring_sw_register_funcs(&ring->access); | 198 | iio_ring_sw_register_funcs(&ring->access); |
216 | ring->bpe = 2; | 199 | ring->bpe = 2; |
200 | ring->scan_el_attrs = &adis16400_scan_el_group; | ||
201 | ring->scan_timestamp = true; | ||
217 | ring->preenable = &iio_sw_ring_preenable; | 202 | ring->preenable = &iio_sw_ring_preenable; |
218 | ring->postenable = &iio_triggered_ring_postenable; | 203 | ring->postenable = &iio_triggered_ring_postenable; |
219 | ring->predisable = &iio_triggered_ring_predisable; | 204 | ring->predisable = &iio_triggered_ring_predisable; |
220 | ring->owner = THIS_MODULE; | 205 | ring->owner = THIS_MODULE; |
221 | 206 | ||
207 | /* Set default scan mode */ | ||
208 | iio_scan_mask_set(ring, iio_scan_el_supply.number); | ||
209 | iio_scan_mask_set(ring, iio_scan_el_gyro_x.number); | ||
210 | iio_scan_mask_set(ring, iio_scan_el_gyro_y.number); | ||
211 | iio_scan_mask_set(ring, iio_scan_el_gyro_z.number); | ||
212 | iio_scan_mask_set(ring, iio_scan_el_accel_x.number); | ||
213 | iio_scan_mask_set(ring, iio_scan_el_accel_y.number); | ||
214 | iio_scan_mask_set(ring, iio_scan_el_accel_z.number); | ||
215 | iio_scan_mask_set(ring, iio_scan_el_magn_x.number); | ||
216 | iio_scan_mask_set(ring, iio_scan_el_magn_y.number); | ||
217 | iio_scan_mask_set(ring, iio_scan_el_magn_z.number); | ||
218 | iio_scan_mask_set(ring, iio_scan_el_temp.number); | ||
219 | iio_scan_mask_set(ring, iio_scan_el_adc_0.number); | ||
220 | |||
222 | ret = iio_alloc_pollfunc(indio_dev, NULL, &adis16400_poll_func_th); | 221 | ret = iio_alloc_pollfunc(indio_dev, NULL, &adis16400_poll_func_th); |
223 | if (ret) | 222 | if (ret) |
224 | goto error_iio_sw_rb_free; | 223 | goto error_iio_sw_rb_free; |
diff --git a/drivers/staging/iio/industrialio-core.c b/drivers/staging/iio/industrialio-core.c index dd4d87a8bca..5c0e56a6935 100644 --- a/drivers/staging/iio/industrialio-core.c +++ b/drivers/staging/iio/industrialio-core.c | |||
@@ -507,24 +507,12 @@ static int iio_device_register_sysfs(struct iio_dev *dev_info) | |||
507 | goto error_ret; | 507 | goto error_ret; |
508 | } | 508 | } |
509 | 509 | ||
510 | if (dev_info->scan_el_attrs) { | ||
511 | ret = sysfs_create_group(&dev_info->dev.kobj, | ||
512 | dev_info->scan_el_attrs); | ||
513 | if (ret) | ||
514 | dev_err(&dev_info->dev, | ||
515 | "Failed to add sysfs scan els\n"); | ||
516 | } | ||
517 | |||
518 | error_ret: | 510 | error_ret: |
519 | return ret; | 511 | return ret; |
520 | } | 512 | } |
521 | 513 | ||
522 | static void iio_device_unregister_sysfs(struct iio_dev *dev_info) | 514 | static void iio_device_unregister_sysfs(struct iio_dev *dev_info) |
523 | { | 515 | { |
524 | if (dev_info->scan_el_attrs) | ||
525 | sysfs_remove_group(&dev_info->dev.kobj, | ||
526 | dev_info->scan_el_attrs); | ||
527 | |||
528 | sysfs_remove_group(&dev_info->dev.kobj, dev_info->attrs); | 516 | sysfs_remove_group(&dev_info->dev.kobj, dev_info->attrs); |
529 | } | 517 | } |
530 | 518 | ||
diff --git a/drivers/staging/iio/industrialio-ring.c b/drivers/staging/iio/industrialio-ring.c index 610c2b6fb67..f3c87edddaf 100644 --- a/drivers/staging/iio/industrialio-ring.c +++ b/drivers/staging/iio/industrialio-ring.c | |||
@@ -279,6 +279,16 @@ int iio_ring_buffer_register(struct iio_ring_buffer *ring, int id) | |||
279 | if (ret) | 279 | if (ret) |
280 | goto error_free_ring_buffer_event_chrdev; | 280 | goto error_free_ring_buffer_event_chrdev; |
281 | 281 | ||
282 | if (ring->scan_el_attrs) { | ||
283 | ret = sysfs_create_group(&ring->dev.kobj, | ||
284 | ring->scan_el_attrs); | ||
285 | if (ret) { | ||
286 | dev_err(&ring->dev, | ||
287 | "Failed to add sysfs scan elements\n"); | ||
288 | goto error_free_ring_buffer_event_chrdev; | ||
289 | } | ||
290 | } | ||
291 | |||
282 | return ret; | 292 | return ret; |
283 | error_free_ring_buffer_event_chrdev: | 293 | error_free_ring_buffer_event_chrdev: |
284 | __iio_free_ring_buffer_event_chrdev(ring); | 294 | __iio_free_ring_buffer_event_chrdev(ring); |
@@ -291,6 +301,10 @@ EXPORT_SYMBOL(iio_ring_buffer_register); | |||
291 | 301 | ||
292 | void iio_ring_buffer_unregister(struct iio_ring_buffer *ring) | 302 | void iio_ring_buffer_unregister(struct iio_ring_buffer *ring) |
293 | { | 303 | { |
304 | if (ring->scan_el_attrs) | ||
305 | sysfs_remove_group(&ring->dev.kobj, | ||
306 | ring->scan_el_attrs); | ||
307 | |||
294 | __iio_free_ring_buffer_access_chrdev(ring); | 308 | __iio_free_ring_buffer_access_chrdev(ring); |
295 | __iio_free_ring_buffer_event_chrdev(ring); | 309 | __iio_free_ring_buffer_event_chrdev(ring); |
296 | device_del(&ring->dev); | 310 | device_del(&ring->dev); |
@@ -465,10 +479,10 @@ ssize_t iio_scan_el_show(struct device *dev, | |||
465 | char *buf) | 479 | char *buf) |
466 | { | 480 | { |
467 | int ret; | 481 | int ret; |
468 | struct iio_dev *indio_dev = dev_get_drvdata(dev); | 482 | struct iio_ring_buffer *ring = dev_get_drvdata(dev); |
469 | struct iio_scan_el *this_el = to_iio_scan_el(attr); | 483 | struct iio_scan_el *this_el = to_iio_scan_el(attr); |
470 | 484 | ||
471 | ret = iio_scan_mask_query(indio_dev, this_el->number); | 485 | ret = iio_scan_mask_query(ring, this_el->number); |
472 | if (ret < 0) | 486 | if (ret < 0) |
473 | return ret; | 487 | return ret; |
474 | return sprintf(buf, "%d\n", ret); | 488 | return sprintf(buf, "%d\n", ret); |
@@ -482,7 +496,8 @@ ssize_t iio_scan_el_store(struct device *dev, | |||
482 | { | 496 | { |
483 | int ret = 0; | 497 | int ret = 0; |
484 | bool state; | 498 | bool state; |
485 | struct iio_dev *indio_dev = dev_get_drvdata(dev); | 499 | struct iio_ring_buffer *ring = dev_get_drvdata(dev); |
500 | struct iio_dev *indio_dev = ring->indio_dev; | ||
486 | struct iio_scan_el *this_el = to_iio_scan_el(attr); | 501 | struct iio_scan_el *this_el = to_iio_scan_el(attr); |
487 | 502 | ||
488 | state = !(buf[0] == '0'); | 503 | state = !(buf[0] == '0'); |
@@ -491,19 +506,17 @@ ssize_t iio_scan_el_store(struct device *dev, | |||
491 | ret = -EBUSY; | 506 | ret = -EBUSY; |
492 | goto error_ret; | 507 | goto error_ret; |
493 | } | 508 | } |
494 | ret = iio_scan_mask_query(indio_dev, this_el->number); | 509 | ret = iio_scan_mask_query(ring, this_el->number); |
495 | if (ret < 0) | 510 | if (ret < 0) |
496 | goto error_ret; | 511 | goto error_ret; |
497 | if (!state && ret) { | 512 | if (!state && ret) { |
498 | ret = iio_scan_mask_clear(indio_dev, this_el->number); | 513 | ret = iio_scan_mask_clear(ring, this_el->number); |
499 | if (ret) | 514 | if (ret) |
500 | goto error_ret; | 515 | goto error_ret; |
501 | indio_dev->scan_count--; | ||
502 | } else if (state && !ret) { | 516 | } else if (state && !ret) { |
503 | ret = iio_scan_mask_set(indio_dev, this_el->number); | 517 | ret = iio_scan_mask_set(ring, this_el->number); |
504 | if (ret) | 518 | if (ret) |
505 | goto error_ret; | 519 | goto error_ret; |
506 | indio_dev->scan_count++; | ||
507 | } | 520 | } |
508 | if (this_el->set_state) | 521 | if (this_el->set_state) |
509 | ret = this_el->set_state(this_el, indio_dev, state); | 522 | ret = this_el->set_state(this_el, indio_dev, state); |
@@ -519,8 +532,8 @@ ssize_t iio_scan_el_ts_show(struct device *dev, | |||
519 | struct device_attribute *attr, | 532 | struct device_attribute *attr, |
520 | char *buf) | 533 | char *buf) |
521 | { | 534 | { |
522 | struct iio_dev *indio_dev = dev_get_drvdata(dev); | 535 | struct iio_ring_buffer *ring = dev_get_drvdata(dev); |
523 | return sprintf(buf, "%d\n", indio_dev->scan_timestamp); | 536 | return sprintf(buf, "%d\n", ring->scan_timestamp); |
524 | } | 537 | } |
525 | EXPORT_SYMBOL(iio_scan_el_ts_show); | 538 | EXPORT_SYMBOL(iio_scan_el_ts_show); |
526 | 539 | ||
@@ -530,7 +543,8 @@ ssize_t iio_scan_el_ts_store(struct device *dev, | |||
530 | size_t len) | 543 | size_t len) |
531 | { | 544 | { |
532 | int ret = 0; | 545 | int ret = 0; |
533 | struct iio_dev *indio_dev = dev_get_drvdata(dev); | 546 | struct iio_ring_buffer *ring = dev_get_drvdata(dev); |
547 | struct iio_dev *indio_dev = ring->indio_dev; | ||
534 | bool state; | 548 | bool state; |
535 | state = !(buf[0] == '0'); | 549 | state = !(buf[0] == '0'); |
536 | mutex_lock(&indio_dev->mlock); | 550 | mutex_lock(&indio_dev->mlock); |
@@ -538,7 +552,7 @@ ssize_t iio_scan_el_ts_store(struct device *dev, | |||
538 | ret = -EBUSY; | 552 | ret = -EBUSY; |
539 | goto error_ret; | 553 | goto error_ret; |
540 | } | 554 | } |
541 | indio_dev->scan_timestamp = state; | 555 | ring->scan_timestamp = state; |
542 | error_ret: | 556 | error_ret: |
543 | mutex_unlock(&indio_dev->mlock); | 557 | mutex_unlock(&indio_dev->mlock); |
544 | 558 | ||
diff --git a/drivers/staging/iio/ring_generic.h b/drivers/staging/iio/ring_generic.h index ac017b13bfb..6124353b2ed 100644 --- a/drivers/staging/iio/ring_generic.h +++ b/drivers/staging/iio/ring_generic.h | |||
@@ -102,6 +102,11 @@ struct iio_ring_access_funcs { | |||
102 | * @bytes_per_datum [DEVICE] size of individual datum including timestamp | 102 | * @bytes_per_datum [DEVICE] size of individual datum including timestamp |
103 | * @bpe: [DEVICE] size of individual channel value | 103 | * @bpe: [DEVICE] size of individual channel value |
104 | * @loopcount: [INTERN] number of times the ring has looped | 104 | * @loopcount: [INTERN] number of times the ring has looped |
105 | * @scan_el_attrs: [DRIVER] control of scan elements if that scan mode | ||
106 | * control method is used | ||
107 | * @scan_count: [INTERN] the number of elements in the current scan mode | ||
108 | * @scan_mask: [INTERN] bitmask used in masking scan mode elements | ||
109 | * @scan_timestamp: [INTERN] does the scan mode include a timestamp | ||
105 | * @access_handler: [INTERN] chrdev access handling | 110 | * @access_handler: [INTERN] chrdev access handling |
106 | * @ev_int: [INTERN] chrdev interface for the event chrdev | 111 | * @ev_int: [INTERN] chrdev interface for the event chrdev |
107 | * @shared_ev_pointer: [INTERN] the shared event pointer to allow escalation of | 112 | * @shared_ev_pointer: [INTERN] the shared event pointer to allow escalation of |
@@ -124,6 +129,10 @@ struct iio_ring_buffer { | |||
124 | int bytes_per_datum; | 129 | int bytes_per_datum; |
125 | int bpe; | 130 | int bpe; |
126 | int loopcount; | 131 | int loopcount; |
132 | struct attribute_group *scan_el_attrs; | ||
133 | int scan_count; | ||
134 | u32 scan_mask; | ||
135 | bool scan_timestamp; | ||
127 | struct iio_handler access_handler; | 136 | struct iio_handler access_handler; |
128 | struct iio_event_interface ev_int; | 137 | struct iio_event_interface ev_int; |
129 | struct iio_shared_ev_pointer shared_ev_pointer; | 138 | struct iio_shared_ev_pointer shared_ev_pointer; |
@@ -258,6 +267,97 @@ ssize_t iio_scan_el_ts_show(struct device *dev, struct device_attribute *attr, | |||
258 | iio_scan_el_ts_store), \ | 267 | iio_scan_el_ts_store), \ |
259 | } | 268 | } |
260 | 269 | ||
270 | /* | ||
271 | * These are mainly provided to allow for a change of implementation if a device | ||
272 | * has a large number of scan elements | ||
273 | */ | ||
274 | #define IIO_MAX_SCAN_LENGTH 31 | ||
275 | |||
276 | /* note 0 used as error indicator as it doesn't make sense. */ | ||
277 | static inline u32 iio_scan_mask_match(u32 *av_masks, u32 mask) | ||
278 | { | ||
279 | while (*av_masks) { | ||
280 | if (!(~*av_masks & mask)) | ||
281 | return *av_masks; | ||
282 | av_masks++; | ||
283 | } | ||
284 | return 0; | ||
285 | } | ||
286 | |||
287 | static inline int iio_scan_mask_query(struct iio_ring_buffer *ring, int bit) | ||
288 | { | ||
289 | struct iio_dev *dev_info = ring->indio_dev; | ||
290 | u32 mask; | ||
291 | |||
292 | if (bit > IIO_MAX_SCAN_LENGTH) | ||
293 | return -EINVAL; | ||
294 | |||
295 | if (!ring->scan_mask) | ||
296 | return 0; | ||
297 | |||
298 | if (dev_info->available_scan_masks) | ||
299 | mask = iio_scan_mask_match(dev_info->available_scan_masks, | ||
300 | ring->scan_mask); | ||
301 | else | ||
302 | mask = ring->scan_mask; | ||
303 | |||
304 | if (!mask) | ||
305 | return -EINVAL; | ||
306 | |||
307 | return !!(mask & (1 << bit)); | ||
308 | }; | ||
309 | |||
310 | static inline int iio_scan_mask_set(struct iio_ring_buffer *ring, int bit) | ||
311 | { | ||
312 | struct iio_dev *dev_info = ring->indio_dev; | ||
313 | u32 mask; | ||
314 | u32 trialmask = ring->scan_mask | (1 << bit); | ||
315 | |||
316 | if (bit > IIO_MAX_SCAN_LENGTH) | ||
317 | return -EINVAL; | ||
318 | if (dev_info->available_scan_masks) { | ||
319 | mask = iio_scan_mask_match(dev_info->available_scan_masks, | ||
320 | trialmask); | ||
321 | if (!mask) | ||
322 | return -EINVAL; | ||
323 | } | ||
324 | ring->scan_mask = trialmask; | ||
325 | ring->scan_count++; | ||
326 | |||
327 | return 0; | ||
328 | }; | ||
329 | |||
330 | static inline int iio_scan_mask_clear(struct iio_ring_buffer *ring, int bit) | ||
331 | { | ||
332 | if (bit > IIO_MAX_SCAN_LENGTH) | ||
333 | return -EINVAL; | ||
334 | ring->scan_mask &= ~(1 << bit); | ||
335 | ring->scan_count--; | ||
336 | return 0; | ||
337 | }; | ||
338 | |||
339 | /** | ||
340 | * iio_scan_mask_count_to_right() - how many scan elements occur before here | ||
341 | * @dev_info: the iio_device whose scan mode we are querying | ||
342 | * @bit: which number scan element is this | ||
343 | **/ | ||
344 | static inline int iio_scan_mask_count_to_right(struct iio_ring_buffer *ring, | ||
345 | int bit) | ||
346 | { | ||
347 | int count = 0; | ||
348 | int mask = (1 << bit); | ||
349 | if (bit > IIO_MAX_SCAN_LENGTH) | ||
350 | return -EINVAL; | ||
351 | while (mask) { | ||
352 | mask >>= 1; | ||
353 | if (mask & ring->scan_mask) | ||
354 | count++; | ||
355 | } | ||
356 | |||
357 | return count; | ||
358 | } | ||
359 | |||
360 | |||
261 | static inline void iio_put_ring_buffer(struct iio_ring_buffer *ring) | 361 | static inline void iio_put_ring_buffer(struct iio_ring_buffer *ring) |
262 | { | 362 | { |
263 | put_device(&ring->dev); | 363 | put_device(&ring->dev); |
diff --git a/drivers/staging/iio/ring_sw.c b/drivers/staging/iio/ring_sw.c index 99efb6b2914..52624ace0bc 100644 --- a/drivers/staging/iio/ring_sw.c +++ b/drivers/staging/iio/ring_sw.c | |||
@@ -435,23 +435,24 @@ EXPORT_SYMBOL(iio_sw_rb_free); | |||
435 | 435 | ||
436 | int iio_sw_ring_preenable(struct iio_dev *indio_dev) | 436 | int iio_sw_ring_preenable(struct iio_dev *indio_dev) |
437 | { | 437 | { |
438 | struct iio_ring_buffer *ring = indio_dev->ring; | ||
438 | size_t size; | 439 | size_t size; |
439 | dev_dbg(&indio_dev->dev, "%s\n", __func__); | 440 | dev_dbg(&indio_dev->dev, "%s\n", __func__); |
440 | /* Check if there are any scan elements enabled, if not fail*/ | 441 | /* Check if there are any scan elements enabled, if not fail*/ |
441 | if (!(indio_dev->scan_count || indio_dev->scan_timestamp)) | 442 | if (!(ring->scan_count || ring->scan_timestamp)) |
442 | return -EINVAL; | 443 | return -EINVAL; |
443 | if (indio_dev->scan_timestamp) | 444 | if (ring->scan_timestamp) |
444 | if (indio_dev->scan_count) | 445 | if (ring->scan_count) |
445 | /* Timestamp (aligned to s64) and data */ | 446 | /* Timestamp (aligned to s64) and data */ |
446 | size = (((indio_dev->scan_count * indio_dev->ring->bpe) | 447 | size = (((ring->scan_count * ring->bpe) |
447 | + sizeof(s64) - 1) | 448 | + sizeof(s64) - 1) |
448 | & ~(sizeof(s64) - 1)) | 449 | & ~(sizeof(s64) - 1)) |
449 | + sizeof(s64); | 450 | + sizeof(s64); |
450 | else /* Timestamp only */ | 451 | else /* Timestamp only */ |
451 | size = sizeof(s64); | 452 | size = sizeof(s64); |
452 | else /* Data only */ | 453 | else /* Data only */ |
453 | size = indio_dev->scan_count * indio_dev->ring->bpe; | 454 | size = ring->scan_count * ring->bpe; |
454 | indio_dev->ring->access.set_bytes_per_datum(indio_dev->ring, size); | 455 | ring->access.set_bytes_per_datum(ring, size); |
455 | 456 | ||
456 | return 0; | 457 | return 0; |
457 | } | 458 | } |
@@ -462,9 +463,9 @@ void iio_sw_trigger_bh_to_ring(struct work_struct *work_s) | |||
462 | struct iio_sw_ring_helper_state *st | 463 | struct iio_sw_ring_helper_state *st |
463 | = container_of(work_s, struct iio_sw_ring_helper_state, | 464 | = container_of(work_s, struct iio_sw_ring_helper_state, |
464 | work_trigger_to_ring); | 465 | work_trigger_to_ring); |
466 | struct iio_ring_buffer *ring = st->indio_dev->ring; | ||
465 | int len = 0; | 467 | int len = 0; |
466 | size_t datasize = st->indio_dev | 468 | size_t datasize = ring->access.get_bytes_per_datum(ring); |
467 | ->ring->access.get_bytes_per_datum(st->indio_dev->ring); | ||
468 | char *data = kmalloc(datasize, GFP_KERNEL); | 469 | char *data = kmalloc(datasize, GFP_KERNEL); |
469 | 470 | ||
470 | if (data == NULL) { | 471 | if (data == NULL) { |
@@ -473,16 +474,16 @@ void iio_sw_trigger_bh_to_ring(struct work_struct *work_s) | |||
473 | return; | 474 | return; |
474 | } | 475 | } |
475 | 476 | ||
476 | if (st->indio_dev->scan_count) | 477 | if (ring->scan_count) |
477 | len = st->get_ring_element(st, data); | 478 | len = st->get_ring_element(st, data); |
478 | 479 | ||
479 | /* Guaranteed to be aligned with 8 byte boundary */ | 480 | /* Guaranteed to be aligned with 8 byte boundary */ |
480 | if (st->indio_dev->scan_timestamp) | 481 | if (ring->scan_timestamp) |
481 | *(s64 *)(((phys_addr_t)data + len | 482 | *(s64 *)(((phys_addr_t)data + len |
482 | + sizeof(s64) - 1) & ~(sizeof(s64) - 1)) | 483 | + sizeof(s64) - 1) & ~(sizeof(s64) - 1)) |
483 | = st->last_timestamp; | 484 | = st->last_timestamp; |
484 | st->indio_dev->ring->access.store_to(st->indio_dev->ring, | 485 | ring->access.store_to(ring, |
485 | (u8 *)data, | 486 | (u8 *)data, |
486 | st->last_timestamp); | 487 | st->last_timestamp); |
487 | 488 | ||
488 | iio_trigger_notify_done(st->indio_dev->trig); | 489 | iio_trigger_notify_done(st->indio_dev->trig); |