From: David Lechner Date: Fri, 18 Apr 2025 18:16:13 +0000 (-0500) Subject: iio: amplifiers: ada4250: use DMA-safe memory for regmap_bulk_read() X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=c5858465a695c88fd427d1930c868750321b0409;p=users%2Fjedix%2Flinux-maple.git iio: amplifiers: ada4250: use DMA-safe memory for regmap_bulk_read() Use DMA-safe memory instead of stack-allocated memory for the call to regmap_bulk_read() in the ada4250_init() function as this could be used directly by a SPI controller. Also remove unnecessary use of get_unaligned_le16() and explicitly include linux/types.h e.g. for __le16 while we are fixing this up. Note this is DMA issue does not appear to be an actual bug due to internals of the regmap SPI implementation. However, for IIO we are following guidance that we should not make that assumption. Signed-off-by: David Lechner Link: https://patch.msgid.link/20250418-iio-amplifiers-ada4250-simplify-data-buffer-in-init-v1-1-7e7bd6dad423@baylibre.com Signed-off-by: Jonathan Cameron --- diff --git a/drivers/iio/amplifiers/ada4250.c b/drivers/iio/amplifiers/ada4250.c index 74f8429d652b1..f81438460aa51 100644 --- a/drivers/iio/amplifiers/ada4250.c +++ b/drivers/iio/amplifiers/ada4250.c @@ -13,8 +13,7 @@ #include #include #include - -#include +#include /* ADA4250 Register Map */ #define ADA4250_REG_GAIN_MUX 0x00 @@ -63,6 +62,7 @@ struct ada4250_state { u8 gain; int offset_uv; bool refbuf_en; + __le16 reg_val_16 __aligned(IIO_DMA_MINALIGN); }; /* ADA4250 Current Bias Source Settings: Disabled, Bandgap Reference, AVDD */ @@ -301,7 +301,6 @@ static int ada4250_init(struct ada4250_state *st) { int ret; u16 chip_id; - u8 data[2] __aligned(8) = {}; struct spi_device *spi = st->spi; st->refbuf_en = device_property_read_bool(&spi->dev, "adi,refbuf-enable"); @@ -326,11 +325,12 @@ static int ada4250_init(struct ada4250_state *st) if (ret) return ret; - ret = regmap_bulk_read(st->regmap, ADA4250_REG_CHIP_ID, data, 2); + ret = regmap_bulk_read(st->regmap, ADA4250_REG_CHIP_ID, &st->reg_val_16, + sizeof(st->reg_val_16)); if (ret) return ret; - chip_id = get_unaligned_le16(data); + chip_id = le16_to_cpu(st->reg_val_16); if (chip_id != ADA4250_CHIP_ID) { dev_err(&spi->dev, "Invalid chip ID.\n");