iio: accel: sca3300: use IIO_DECLARE_BUFFER_WITH_TS

Use IIO_DECLARE_BUFFER_WITH_TS() to declare the buffer that gets used
with iio_push_to_buffers_with_ts(). This makes the code a bit easier to
read and understand.

Reviewed-by: Nuno Sá <nuno.sa@analog.com>
Signed-off-by: David Lechner <dlechner@baylibre.com>
Link: https://patch.msgid.link/20250507-iio-introduce-iio_declare_buffer_with_ts-v6-6-4aee1b9f1b89@baylibre.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
This commit is contained in:
David Lechner 2025-05-07 15:42:45 -05:00 committed by Jonathan Cameron
parent 6d06978f91
commit edeb67fbbf

View File

@ -58,15 +58,6 @@ enum sca3300_scan_indexes {
SCA3300_SCAN_MAX SCA3300_SCAN_MAX
}; };
/*
* Buffer size max case:
* Three accel channels, two bytes per channel.
* Temperature channel, two bytes.
* Three incli channels, two bytes per channel.
* Timestamp channel, eight bytes.
*/
#define SCA3300_MAX_BUFFER_SIZE (ALIGN(sizeof(s16) * SCA3300_SCAN_MAX, sizeof(s64)) + sizeof(s64))
#define SCA3300_ACCEL_CHANNEL(index, reg, axis) { \ #define SCA3300_ACCEL_CHANNEL(index, reg, axis) { \
.type = IIO_ACCEL, \ .type = IIO_ACCEL, \
.address = reg, \ .address = reg, \
@ -193,9 +184,6 @@ struct sca3300_chip_info {
* @spi: SPI device structure * @spi: SPI device structure
* @lock: Data buffer lock * @lock: Data buffer lock
* @chip: Sensor chip specific information * @chip: Sensor chip specific information
* @buffer: Triggered buffer:
* -SCA3300: 4 channel 16-bit data + 64-bit timestamp
* -SCL3300: 7 channel 16-bit data + 64-bit timestamp
* @txbuf: Transmit buffer * @txbuf: Transmit buffer
* @rxbuf: Receive buffer * @rxbuf: Receive buffer
*/ */
@ -203,7 +191,6 @@ struct sca3300_data {
struct spi_device *spi; struct spi_device *spi;
struct mutex lock; struct mutex lock;
const struct sca3300_chip_info *chip; const struct sca3300_chip_info *chip;
u8 buffer[SCA3300_MAX_BUFFER_SIZE] __aligned(sizeof(s64));
u8 txbuf[4] __aligned(IIO_DMA_MINALIGN); u8 txbuf[4] __aligned(IIO_DMA_MINALIGN);
u8 rxbuf[4]; u8 rxbuf[4];
}; };
@ -492,7 +479,7 @@ static irqreturn_t sca3300_trigger_handler(int irq, void *p)
struct iio_dev *indio_dev = pf->indio_dev; struct iio_dev *indio_dev = pf->indio_dev;
struct sca3300_data *data = iio_priv(indio_dev); struct sca3300_data *data = iio_priv(indio_dev);
int bit, ret, val, i = 0; int bit, ret, val, i = 0;
s16 *channels = (s16 *)data->buffer; IIO_DECLARE_BUFFER_WITH_TS(s16, channels, SCA3300_SCAN_MAX);
iio_for_each_active_channel(indio_dev, bit) { iio_for_each_active_channel(indio_dev, bit) {
ret = sca3300_read_reg(data, indio_dev->channels[bit].address, &val); ret = sca3300_read_reg(data, indio_dev->channels[bit].address, &val);
@ -505,8 +492,7 @@ static irqreturn_t sca3300_trigger_handler(int irq, void *p)
channels[i++] = val; channels[i++] = val;
} }
iio_push_to_buffers_with_ts(indio_dev, data->buffer, iio_push_to_buffers_with_ts(indio_dev, channels, sizeof(channels),
sizeof(data->buffer),
iio_get_time_ns(indio_dev)); iio_get_time_ns(indio_dev));
out: out:
iio_trigger_notify_done(indio_dev->trig); iio_trigger_notify_done(indio_dev->trig);