diff options
author | Manuel Stahl <manuel.stahl@iis.fraunhofer.de> | 2010-08-31 11:32:52 +0200 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2010-08-31 11:42:02 -0700 |
commit | bf32963cbeb5d34fa32a4c1eeed1163ab1b4501c (patch) | |
tree | 221c5e12d26142d6b8b5a3cfff844c9ed9ad3899 /drivers/staging/iio/accel/lis3l02dq_ring.c | |
parent | 07e6229e42e4d679cdbaada8f7966491c69710e7 (diff) | |
download | op-kernel-dev-bf32963cbeb5d34fa32a4c1eeed1163ab1b4501c.zip op-kernel-dev-bf32963cbeb5d34fa32a4c1eeed1163ab1b4501c.tar.gz |
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/iio/accel/lis3l02dq_ring.c')
-rw-r--r-- | drivers/staging/iio/accel/lis3l02dq_ring.c | 43 |
1 files changed, 23 insertions, 20 deletions
diff --git a/drivers/staging/iio/accel/lis3l02dq_ring.c b/drivers/staging/iio/accel/lis3l02dq_ring.c index 9ad04f0..a68a381 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, int ret, len = 0, i = 0; struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); struct iio_dev *dev_info = dev_get_drvdata(dev); + struct iio_ring_buffer *ring = dev_info->ring; + struct attribute_group *scan_el_attrs = ring->scan_el_attrs; s16 *data; - while (dev_info->scan_el_attrs->attrs[i]) { + while (scan_el_attrs->attrs[i]) { el = to_iio_scan_el((struct device_attribute *) - (dev_info->scan_el_attrs->attrs[i])); + (scan_el_attrs->attrs[i])); /* label is in fact the address */ if (el->label == this_attr->address) break; i++; } - if (!dev_info->scan_el_attrs->attrs[i]) { + if (!scan_el_attrs->attrs[i]) { ret = -EINVAL; goto error_ret; } /* If this element is in the scan mask */ - ret = iio_scan_mask_query(dev_info, el->number); + ret = iio_scan_mask_query(ring, el->number); if (ret < 0) goto error_ret; if (ret) { - data = kmalloc(dev_info->ring->access.get_bytes_per_datum(dev_info->ring), + data = kmalloc(ring->access.get_bytes_per_datum(ring), GFP_KERNEL); if (data == NULL) return -ENOMEM; - ret = dev_info->ring->access.read_last(dev_info->ring, - (u8 *)data); + ret = ring->access.read_last(ring, + (u8 *)data); if (ret) goto error_free_data; } else { ret = -EINVAL; goto error_ret; } - len = iio_scan_mask_count_to_right(dev_info, el->number); + len = iio_scan_mask_count_to_right(ring, el->number); if (len < 0) { ret = len; goto error_free_data; @@ -211,11 +213,12 @@ static const u8 read_all_tx_array[] = { **/ static int lis3l02dq_read_all(struct lis3l02dq_state *st, u8 *rx_array) { + struct iio_ring_buffer *ring = st->help.indio_dev->ring; struct spi_transfer *xfers; struct spi_message msg; int ret, i, j = 0; - xfers = kzalloc((st->help.indio_dev->scan_count) * 2 + xfers = kzalloc((ring->scan_count) * 2 * sizeof(*xfers), GFP_KERNEL); if (!xfers) return -ENOMEM; @@ -223,7 +226,7 @@ static int lis3l02dq_read_all(struct lis3l02dq_state *st, u8 *rx_array) mutex_lock(&st->buf_lock); for (i = 0; i < ARRAY_SIZE(read_all_tx_array)/4; i++) { - if (st->help.indio_dev->scan_mask & (1 << i)) { + if (ring->scan_mask & (1 << i)) { /* lower byte */ xfers[j].tx_buf = st->tx + 2*j; 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) * values in alternate bytes */ spi_message_init(&msg); - for (j = 0; j < st->help.indio_dev->scan_count * 2; j++) + for (j = 0; j < ring->scan_count * 2; j++) spi_message_add_tail(&xfers[j], &msg); ret = spi_sync(st->us, &msg); @@ -279,13 +282,13 @@ static int lis3l02dq_get_ring_element(struct iio_sw_ring_helper_state *h, u8 *rx_array ; s16 *data = (s16 *)buf; - rx_array = kzalloc(4 * (h->indio_dev->scan_count), GFP_KERNEL); + rx_array = kzalloc(4 * (h->indio_dev->ring->scan_count), GFP_KERNEL); if (rx_array == NULL) return -ENOMEM; ret = lis3l02dq_read_all(lis3l02dq_h_to_s(h), rx_array); if (ret < 0) return ret; - for (i = 0; i < h->indio_dev->scan_count; i++) + for (i = 0; i < h->indio_dev->ring->scan_count; i++) data[i] = combine_8_to_16(rx_array[i*4+1], rx_array[i*4+3]); kfree(rx_array); @@ -481,14 +484,7 @@ int lis3l02dq_configure_ring(struct iio_dev *indio_dev) struct iio_sw_ring_helper_state *h = iio_dev_get_devdata(indio_dev); struct iio_ring_buffer *ring; INIT_WORK(&h->work_trigger_to_ring, lis3l02dq_trigger_bh_to_ring); - /* Set default scan mode */ h->get_ring_element = &lis3l02dq_get_ring_element; - iio_scan_mask_set(indio_dev, iio_scan_el_accel_x.number); - iio_scan_mask_set(indio_dev, iio_scan_el_accel_y.number); - iio_scan_mask_set(indio_dev, iio_scan_el_accel_z.number); - indio_dev->scan_timestamp = true; - - indio_dev->scan_el_attrs = &lis3l02dq_scan_el_group; ring = iio_sw_rb_allocate(indio_dev); if (!ring) @@ -498,11 +494,18 @@ int lis3l02dq_configure_ring(struct iio_dev *indio_dev) /* Effectively select the ring buffer implementation */ iio_ring_sw_register_funcs(&ring->access); ring->bpe = 2; + ring->scan_el_attrs = &lis3l02dq_scan_el_group; + ring->scan_timestamp = true; ring->preenable = &iio_sw_ring_preenable; ring->postenable = &iio_triggered_ring_postenable; ring->predisable = &iio_triggered_ring_predisable; ring->owner = THIS_MODULE; + /* Set default scan mode */ + iio_scan_mask_set(ring, iio_scan_el_accel_x.number); + iio_scan_mask_set(ring, iio_scan_el_accel_y.number); + iio_scan_mask_set(ring, iio_scan_el_accel_z.number); + ret = iio_alloc_pollfunc(indio_dev, NULL, &lis3l02dq_poll_func_th); if (ret) goto error_iio_sw_rb_free;; |