staging:iio:ad7476: Avoid alloc/free for each sample in buffered mode
The ad7476 driver has only support for 1 channel ADCs. So the upper limit for the buffer size is the size of one sample plus the size of the timestamp. Preallocate a buffer large enough to hold this to avoid having to allocate and free a new buffer for each sample being captured. Signed-off-by: Lars-Peter Clausen <lars@metafoo.de> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
This commit is contained in:
parent
fcc7800b65
commit
93e33d7030
2 changed files with 7 additions and 12 deletions
|
@ -33,8 +33,11 @@ struct ad7476_state {
|
||||||
/*
|
/*
|
||||||
* DMA (thus cache coherency maintenance) requires the
|
* DMA (thus cache coherency maintenance) requires the
|
||||||
* transfer buffers to live in their own cache lines.
|
* transfer buffers to live in their own cache lines.
|
||||||
|
* Make the buffer large enough for one 16 bit sample and one 64 bit
|
||||||
|
* aligned 64 bit timestamp.
|
||||||
*/
|
*/
|
||||||
unsigned char data[2] ____cacheline_aligned;
|
unsigned char data[ALIGN(2, sizeof(s64)) + sizeof(s64)]
|
||||||
|
____cacheline_aligned;
|
||||||
};
|
};
|
||||||
|
|
||||||
enum ad7476_supported_device_ids {
|
enum ad7476_supported_device_ids {
|
||||||
|
|
|
@ -26,28 +26,20 @@ static irqreturn_t ad7476_trigger_handler(int irq, void *p)
|
||||||
struct iio_dev *indio_dev = pf->indio_dev;
|
struct iio_dev *indio_dev = pf->indio_dev;
|
||||||
struct ad7476_state *st = iio_priv(indio_dev);
|
struct ad7476_state *st = iio_priv(indio_dev);
|
||||||
s64 time_ns;
|
s64 time_ns;
|
||||||
__u8 *rxbuf;
|
|
||||||
int b_sent;
|
int b_sent;
|
||||||
|
|
||||||
rxbuf = kzalloc(indio_dev->scan_bytes, GFP_KERNEL);
|
b_sent = spi_sync(st->spi, &st->msg);
|
||||||
if (rxbuf == NULL)
|
|
||||||
goto done;
|
|
||||||
|
|
||||||
b_sent = spi_read(st->spi, rxbuf,
|
|
||||||
st->chip_info->channel[0].scan_type.storagebits / 8);
|
|
||||||
if (b_sent < 0)
|
if (b_sent < 0)
|
||||||
goto done;
|
goto done;
|
||||||
|
|
||||||
time_ns = iio_get_time_ns();
|
time_ns = iio_get_time_ns();
|
||||||
|
|
||||||
if (indio_dev->scan_timestamp)
|
if (indio_dev->scan_timestamp)
|
||||||
memcpy(rxbuf + indio_dev->scan_bytes - sizeof(s64),
|
((s64 *)st->data)[1] = time_ns;
|
||||||
&time_ns, sizeof(time_ns));
|
|
||||||
|
|
||||||
iio_push_to_buffer(indio_dev->buffer, rxbuf);
|
iio_push_to_buffer(indio_dev->buffer, st->data);
|
||||||
done:
|
done:
|
||||||
iio_trigger_notify_done(indio_dev->trig);
|
iio_trigger_notify_done(indio_dev->trig);
|
||||||
kfree(rxbuf);
|
|
||||||
|
|
||||||
return IRQ_HANDLED;
|
return IRQ_HANDLED;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue