From: David Lechner Date: Mon, 28 Apr 2025 20:23:04 +0000 (-0500) Subject: iio: adc: ad4695: use u16 for buffer elements X-Git-Tag: v6.16-rc1~30^2~4^2~38 X-Git-Url: https://git.kernel.dk/?a=commitdiff_plain;h=15c82338b3640daab2b7a2718a9eed93cfd8537a;p=linux-block.git iio: adc: ad4695: use u16 for buffer elements Change the type of the buffer elements to u16 since we currently only support 16-bit word size. The code was originally written to also allow for 32-bit word size when oversampling is enabled, but so far, oversampling is only implemented when using SPI offload and therefore doesn't use this buffer. AD4695_MAX_CHANNEL_SIZE macro is dropped since it no longer adds any value. AD4695_MAX_CHANNELS + 2 is changed to AD4695_MAX_CHANNELS + 1 because previously we were overallocating. AD4695_MAX_CHANNELS is the number of of voltage channels and + 1 is for the temperature channel. Signed-off-by: David Lechner Reviewed-by: Trevor Gamblin Link: https://patch.msgid.link/20250428-iio-introduce-iio_declare_buffer_with_ts-v4-2-6f7f6126f1cb@baylibre.com Signed-off-by: Jonathan Cameron --- diff --git a/drivers/iio/adc/ad4695.c b/drivers/iio/adc/ad4695.c index 68c6625db0d7..0c633d43e480 100644 --- a/drivers/iio/adc/ad4695.c +++ b/drivers/iio/adc/ad4695.c @@ -106,8 +106,6 @@ /* Max number of voltage input channels. */ #define AD4695_MAX_CHANNELS 16 -/* Max size of 1 raw sample in bytes. */ -#define AD4695_MAX_CHANNEL_SIZE 2 enum ad4695_in_pair { AD4695_IN_PAIR_REFGND, @@ -162,8 +160,8 @@ struct ad4695_state { struct spi_transfer buf_read_xfer[AD4695_MAX_CHANNELS * 2 + 3]; struct spi_message buf_read_msg; /* Raw conversion data received. */ - u8 buf[ALIGN((AD4695_MAX_CHANNELS + 2) * AD4695_MAX_CHANNEL_SIZE, - sizeof(s64)) + sizeof(s64)] __aligned(IIO_DMA_MINALIGN); + u16 buf[ALIGN((AD4695_MAX_CHANNELS + 1) * sizeof(u16), + sizeof(s64)) + sizeof(s64)] __aligned(IIO_DMA_MINALIGN); u16 raw_data; /* Commands to send for single conversion. */ u16 cnv_cmd; @@ -660,9 +658,8 @@ static int ad4695_buffer_preenable(struct iio_dev *indio_dev) iio_for_each_active_channel(indio_dev, bit) { xfer = &st->buf_read_xfer[num_xfer]; xfer->bits_per_word = 16; - xfer->rx_buf = &st->buf[rx_buf_offset]; + xfer->rx_buf = &st->buf[rx_buf_offset++]; xfer->len = 2; - rx_buf_offset += xfer->len; if (bit == temp_chan_bit) { temp_en = 1;