iio: adc: ad4695: use u16 for buffer elements
authorDavid Lechner <dlechner@baylibre.com>
Mon, 28 Apr 2025 20:23:04 +0000 (15:23 -0500)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Wed, 21 May 2025 13:20:29 +0000 (14:20 +0100)
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 <dlechner@baylibre.com>
Reviewed-by: Trevor Gamblin <tgamblin@baylibre.com>
Link: https://patch.msgid.link/20250428-iio-introduce-iio_declare_buffer_with_ts-v4-2-6f7f6126f1cb@baylibre.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
drivers/iio/adc/ad4695.c

index 68c6625..0c633d4 100644 (file)
 
 /* 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;