Commit edeb67fb authored by David Lechner's avatar David Lechner Committed by Jonathan Cameron
Browse files

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: default avatarNuno Sá <nuno.sa@analog.com>
Signed-off-by: default avatarDavid 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: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent 6d06978f
Loading
Loading
Loading
Loading
+2 −16
Original line number Diff line number Diff line
@@ -58,15 +58,6 @@ enum sca3300_scan_indexes {
	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) {			\
	.type = IIO_ACCEL,						\
	.address = reg,							\
@@ -193,9 +184,6 @@ struct sca3300_chip_info {
 * @spi: SPI device structure
 * @lock: Data buffer lock
 * @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
 * @rxbuf: Receive buffer
 */
@@ -203,7 +191,6 @@ struct sca3300_data {
	struct spi_device *spi;
	struct mutex lock;
	const struct sca3300_chip_info *chip;
	u8 buffer[SCA3300_MAX_BUFFER_SIZE] __aligned(sizeof(s64));
	u8 txbuf[4] __aligned(IIO_DMA_MINALIGN);
	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 sca3300_data *data = iio_priv(indio_dev);
	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) {
		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;
	}

	iio_push_to_buffers_with_ts(indio_dev, data->buffer,
				    sizeof(data->buffer),
	iio_push_to_buffers_with_ts(indio_dev, channels, sizeof(channels),
				    iio_get_time_ns(indio_dev));
out:
	iio_trigger_notify_done(indio_dev->trig);