Commit 8f03aabc authored by Jonathan Cameron's avatar Jonathan Cameron Committed by Greg Kroah-Hartman

staging:iio:adc:ad7298 use iio_sw_buffer_preenable to avoid code repitition.

Here some addition elements are needed, but this generic function cuts
down on the amount of code.
Signed-off-by: default avatarJonathan Cameron <jic23@kernel.org>
Acked-by: default avatarLars-Peter Clausen <lars@metafoo.de>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 2150489f
...@@ -38,7 +38,6 @@ struct ad7298_platform_data { ...@@ -38,7 +38,6 @@ struct ad7298_platform_data {
struct ad7298_state { struct ad7298_state {
struct spi_device *spi; struct spi_device *spi;
struct regulator *reg; struct regulator *reg;
size_t d_size;
u16 int_vref_mv; u16 int_vref_mv;
unsigned ext_ref; unsigned ext_ref;
struct spi_transfer ring_xfer[10]; struct spi_transfer ring_xfer[10];
......
...@@ -28,25 +28,17 @@ ...@@ -28,25 +28,17 @@
static int ad7298_ring_preenable(struct iio_dev *indio_dev) static int ad7298_ring_preenable(struct iio_dev *indio_dev)
{ {
struct ad7298_state *st = iio_priv(indio_dev); struct ad7298_state *st = iio_priv(indio_dev);
struct iio_buffer *ring = indio_dev->buffer;
size_t d_size;
int i, m; int i, m;
unsigned short command; unsigned short command;
int scan_count = bitmap_weight(indio_dev->active_scan_mask, int scan_count, ret;
indio_dev->masklength);
d_size = scan_count * (AD7298_STORAGE_BITS / 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) ret = iio_sw_buffer_preenable(indio_dev);
ring->access->set_bytes_per_datum(ring, d_size); if (ret < 0)
return ret;
st->d_size = d_size; /* Now compute overall size */
scan_count = bitmap_weight(indio_dev->active_scan_mask,
indio_dev->masklength);
command = AD7298_WRITE | st->ext_ref; command = AD7298_WRITE | st->ext_ref;
...@@ -102,7 +94,7 @@ static irqreturn_t ad7298_trigger_handler(int irq, void *p) ...@@ -102,7 +94,7 @@ static irqreturn_t ad7298_trigger_handler(int irq, void *p)
if (ring->scan_timestamp) { if (ring->scan_timestamp) {
time_ns = iio_get_time_ns(); time_ns = iio_get_time_ns();
memcpy((u8 *)buf + st->d_size - sizeof(s64), memcpy((u8 *)buf + indio_dev->scan_bytes - sizeof(s64),
&time_ns, sizeof(time_ns)); &time_ns, sizeof(time_ns));
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment