staging;iio:adc:ad7606 use iio_sw_buffer_preenable rather than local equiv
authorJonathan Cameron <jic23@cam.ac.uk>
Fri, 30 Sep 2011 09:05:41 +0000 (10:05 +0100)
committerGreg Kroah-Hartman <gregkh@suse.de>
Mon, 3 Oct 2011 23:07:04 +0000 (16:07 -0700)
Other than a few slight refactorings the local version was pretty standard
so replace it and rework to get rid of st->d_size which it setup.

Signed-off-by: Jonathan Cameron <jic23@cam.ac.uk>
Acked-by: Michael Hennerich <michael.hennerich@analog.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
drivers/staging/iio/adc/ad7606.h
drivers/staging/iio/adc/ad7606_ring.c

index 8fc259f4b3db6a6723418b166f91a220ec996cec..bc95f09327aacc4f1157c4a064cc84cc6b15e76e 100644 (file)
@@ -68,7 +68,6 @@ struct ad7606_state {
        struct regulator                *reg;
        struct work_struct              poll_work;
        wait_queue_head_t               wq_data_avail;
-       size_t                          d_size;
        const struct ad7606_bus_ops     *bops;
        int                             irq;
        unsigned                        id;
index f0742d6134ff71ca4b0f56981152cbf94c586af6..20927fd537288a7555133bb4a477a8ccf5baad25 100644 (file)
@@ -42,37 +42,6 @@ error_ret:
        return ret;
 }
 
-/**
- * ad7606_ring_preenable() setup the parameters of the ring before enabling
- *
- * The complex nature of the setting of the nuber of bytes per datum is due
- * to this driver currently ensuring that the timestamp is stored at an 8
- * byte boundary.
- **/
-static int ad7606_ring_preenable(struct iio_dev *indio_dev)
-{
-       struct ad7606_state *st = iio_priv(indio_dev);
-       struct iio_buffer *ring = indio_dev->buffer;
-       size_t d_size;
-
-       d_size = st->chip_info->num_channels *
-                st->chip_info->channels[0].scan_type.storagebits / 8;
-
-       if (ring->scan_timestamp) {
-               d_size += sizeof(s64);
-
-               if (d_size % sizeof(s64))
-                       d_size += sizeof(s64) - (d_size % sizeof(s64));
-       }
-
-       if (ring->access->set_bytes_per_datum)
-               ring->access->set_bytes_per_datum(ring, d_size);
-
-       st->d_size = d_size;
-
-       return 0;
-}
-
 /**
  * ad7606_trigger_handler_th() th/bh of trigger launched polling to ring buffer
  *
@@ -106,7 +75,8 @@ static void ad7606_poll_bh_to_ring(struct work_struct *work_s)
        __u8 *buf;
        int ret;
 
-       buf = kzalloc(st->d_size, GFP_KERNEL);
+       buf = kzalloc(ring->access->get_bytes_per_datum(ring),
+                     GFP_KERNEL);
        if (buf == NULL)
                return;
 
@@ -137,8 +107,8 @@ static void ad7606_poll_bh_to_ring(struct work_struct *work_s)
        time_ns = iio_get_time_ns();
 
        if (ring->scan_timestamp)
-               memcpy(buf + st->d_size - sizeof(s64),
-                       &time_ns, sizeof(time_ns));
+               *((s64 *)(buf + ring->access->get_bytes_per_datum(ring) -
+                         sizeof(s64))) = time_ns;
 
        ring->access->store_to(indio_dev->buffer, buf, time_ns);
 done:
@@ -148,7 +118,7 @@ done:
 }
 
 static const struct iio_buffer_setup_ops ad7606_ring_setup_ops = {
-       .preenable = &ad7606_ring_preenable,
+       .preenable = &iio_sw_buffer_preenable,
        .postenable = &iio_triggered_buffer_postenable,
        .predisable = &iio_triggered_buffer_predisable,
 };
@@ -166,6 +136,8 @@ int ad7606_register_ring_funcs_and_init(struct iio_dev *indio_dev)
 
        /* Effectively select the ring buffer implementation */
        indio_dev->buffer->access = &ring_sw_access_funcs;
+       indio_dev->buffer->bpe =
+               st->chip_info->channels[0].scan_type.storagebits / 8;
        indio_dev->pollfunc = iio_alloc_pollfunc(&ad7606_trigger_handler_th_bh,
                                                 &ad7606_trigger_handler_th_bh,
                                                 0,