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

staging:iio:adc:ad7887 make use of iio_sw_buffer_preenable.

Using this generic function cuts down on repeated code at the cost
of some computation in a slow path.
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 81a4fc01
...@@ -63,7 +63,6 @@ struct ad7887_state { ...@@ -63,7 +63,6 @@ struct ad7887_state {
struct spi_device *spi; struct spi_device *spi;
const struct ad7887_chip_info *chip_info; const struct ad7887_chip_info *chip_info;
struct regulator *reg; struct regulator *reg;
size_t d_size;
u16 int_vref_mv; u16 int_vref_mv;
struct spi_transfer xfer[4]; struct spi_transfer xfer[4];
struct spi_message msg[3]; struct spi_message msg[3];
......
...@@ -29,22 +29,11 @@ ...@@ -29,22 +29,11 @@
static int ad7887_ring_preenable(struct iio_dev *indio_dev) static int ad7887_ring_preenable(struct iio_dev *indio_dev)
{ {
struct ad7887_state *st = iio_priv(indio_dev); struct ad7887_state *st = iio_priv(indio_dev);
struct iio_buffer *ring = indio_dev->buffer; int ret;
st->d_size = bitmap_weight(indio_dev->active_scan_mask,
indio_dev->masklength) *
st->chip_info->channel[0].scan_type.storagebits / 8;
if (ring->scan_timestamp) {
st->d_size += sizeof(s64);
if (st->d_size % sizeof(s64))
st->d_size += sizeof(s64) - (st->d_size % sizeof(s64));
}
if (indio_dev->buffer->access->set_bytes_per_datum) ret = iio_sw_buffer_preenable(indio_dev);
indio_dev->buffer->access-> if (ret < 0)
set_bytes_per_datum(indio_dev->buffer, st->d_size); return ret;
/* We know this is a single long so can 'cheat' */ /* We know this is a single long so can 'cheat' */
switch (*indio_dev->active_scan_mask) { switch (*indio_dev->active_scan_mask) {
...@@ -92,7 +81,7 @@ static irqreturn_t ad7887_trigger_handler(int irq, void *p) ...@@ -92,7 +81,7 @@ static irqreturn_t ad7887_trigger_handler(int irq, void *p)
indio_dev->masklength) * indio_dev->masklength) *
st->chip_info->channel[0].scan_type.storagebits / 8; st->chip_info->channel[0].scan_type.storagebits / 8;
buf = kzalloc(st->d_size, GFP_KERNEL); buf = kzalloc(indio_dev->scan_bytes, GFP_KERNEL);
if (buf == NULL) if (buf == NULL)
return -ENOMEM; return -ENOMEM;
...@@ -104,7 +93,7 @@ static irqreturn_t ad7887_trigger_handler(int irq, void *p) ...@@ -104,7 +93,7 @@ static irqreturn_t ad7887_trigger_handler(int irq, void *p)
memcpy(buf, st->data, bytes); memcpy(buf, st->data, bytes);
if (ring->scan_timestamp) if (ring->scan_timestamp)
memcpy(buf + st->d_size - sizeof(s64), memcpy(buf + indio_dev->scan_bytes - sizeof(s64),
&time_ns, sizeof(time_ns)); &time_ns, sizeof(time_ns));
indio_dev->buffer->access->store_to(indio_dev->buffer, buf, time_ns); indio_dev->buffer->access->store_to(indio_dev->buffer, buf, 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