* [PATCH] iio: amplifiers: ada4250: use DMA-safe memory for regmap_bulk_read()
@ 2025-04-18 18:16 David Lechner
[not found] ` <CAHp75Vdxdbqu6qkbuo5y4jADOH_h9Re6m8icSj3Je4hnVsha0g@mail.gmail.com>
2025-04-21 10:59 ` Jonathan Cameron
0 siblings, 2 replies; 9+ messages in thread
From: David Lechner @ 2025-04-18 18:16 UTC (permalink / raw)
To: Antoniu Miclaus, Lars-Peter Clausen, Michael Hennerich,
Jonathan Cameron, Nuno Sá, Andy Shevchenko
Cc: Jonathan Cameron, linux-iio, linux-kernel, David Lechner
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.
Fixes: 28b4c30bfa5f ("iio: amplifiers: ada4250: add support for ADA4250")
Signed-off-by: David Lechner <dlechner@baylibre.com>
---
drivers/iio/amplifiers/ada4250.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/drivers/iio/amplifiers/ada4250.c b/drivers/iio/amplifiers/ada4250.c
index 74f8429d652b17b4d1f38366e23ce6a2b3e9b218..f81438460aa51ce30f8f605c60ee5be5c8c251d3 100644
--- a/drivers/iio/amplifiers/ada4250.c
+++ b/drivers/iio/amplifiers/ada4250.c
@@ -13,8 +13,7 @@
#include <linux/regmap.h>
#include <linux/regulator/consumer.h>
#include <linux/spi/spi.h>
-
-#include <linux/unaligned.h>
+#include <linux/types.h>
/* 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");
---
base-commit: aff301f37e220970c2f301b5c65a8bfedf52058e
change-id: 20250418-iio-amplifiers-ada4250-simplify-data-buffer-in-init-93ebb1344295
Best regards,
--
David Lechner <dlechner@baylibre.com>
^ permalink raw reply related [flat|nested] 9+ messages in thread[parent not found: <CAHp75Vdxdbqu6qkbuo5y4jADOH_h9Re6m8icSj3Je4hnVsha0g@mail.gmail.com>]
* Re: [PATCH] iio: amplifiers: ada4250: use DMA-safe memory for regmap_bulk_read()
[not found] ` <CAHp75Vdxdbqu6qkbuo5y4jADOH_h9Re6m8icSj3Je4hnVsha0g@mail.gmail.com>
@ 2025-04-18 19:09 ` David Lechner
2025-04-19 15:03 ` Andy Shevchenko
0 siblings, 1 reply; 9+ messages in thread
From: David Lechner @ 2025-04-18 19:09 UTC (permalink / raw)
To: Andy Shevchenko
Cc: Antoniu Miclaus, Lars-Peter Clausen, Michael Hennerich,
Jonathan Cameron, Nuno Sá, Andy Shevchenko, Jonathan Cameron,
linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org
On 4/18/25 1:58 PM, Andy Shevchenko wrote:
>
>
> пʼятниця, 18 квітня 2025 р. David Lechner <dlechner@baylibre.com <mailto:dlechner@baylibre.com>> пише:
>
> 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.
>
>
> Sorry, but can you elaborate more on this? If driver doesn’t override the callbacks the regmap SPI uses spi_write_then_read() which is supposed to be dma safe.
>
>
Ah, I didn't dig that far down. Will send a new patch that just cleans up the
unnecessary alignment and unaligned call.
(Also can't believe you sent HTML mail!)
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: [PATCH] iio: amplifiers: ada4250: use DMA-safe memory for regmap_bulk_read()
2025-04-18 19:09 ` David Lechner
@ 2025-04-19 15:03 ` Andy Shevchenko
2025-04-19 18:07 ` David Lechner
0 siblings, 1 reply; 9+ messages in thread
From: Andy Shevchenko @ 2025-04-19 15:03 UTC (permalink / raw)
To: David Lechner
Cc: Antoniu Miclaus, Lars-Peter Clausen, Michael Hennerich,
Jonathan Cameron, Nuno Sá, Jonathan Cameron,
linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org
On Fri, Apr 18, 2025 at 02:09:04PM -0500, David Lechner wrote:
> On 4/18/25 1:58 PM, Andy Shevchenko wrote:
> > пʼятниця, 18 квітня 2025 р. David Lechner <dlechner@baylibre.com <mailto:dlechner@baylibre.com>> пише:
> >
> > 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.
> >
> > Sorry, but can you elaborate more on this? If driver doesn’t override the
> > callbacks the regmap SPI uses spi_write_then_read() which is supposed to be
> > dma safe.
>
> Ah, I didn't dig that far down. Will send a new patch that just cleans up the
> unnecessary alignment and unaligned call.
But do you have a real life issue with that? Coincidentally we discussed
similar case in another driver with colleague of mine, and he insists that it
might be still broken (somewhere).
> (Also can't believe you sent HTML mail!)
Yeah, Gmail from the phone can't actually send a plain text :-(
Very strange from Google, while I understand that the case most
likely is for business, where HTML is a standard (sic!) for emails.
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] iio: amplifiers: ada4250: use DMA-safe memory for regmap_bulk_read()
2025-04-19 15:03 ` Andy Shevchenko
@ 2025-04-19 18:07 ` David Lechner
2025-04-21 10:57 ` Jonathan Cameron
0 siblings, 1 reply; 9+ messages in thread
From: David Lechner @ 2025-04-19 18:07 UTC (permalink / raw)
To: Andy Shevchenko
Cc: Antoniu Miclaus, Lars-Peter Clausen, Michael Hennerich,
Jonathan Cameron, Nuno Sá, Jonathan Cameron,
linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org
On 4/19/25 10:03 AM, Andy Shevchenko wrote:
> On Fri, Apr 18, 2025 at 02:09:04PM -0500, David Lechner wrote:
>> On 4/18/25 1:58 PM, Andy Shevchenko wrote:
>>> пʼятниця, 18 квітня 2025 р. David Lechner <dlechner@baylibre.com <mailto:dlechner@baylibre.com>> пише:
>>>
>>> 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.
>>>
>>> Sorry, but can you elaborate more on this? If driver doesn’t override the
>>> callbacks the regmap SPI uses spi_write_then_read() which is supposed to be
>>> dma safe.
>>
>> Ah, I didn't dig that far down. Will send a new patch that just cleans up the
>> unnecessary alignment and unaligned call.
>
> But do you have a real life issue with that? Coincidentally we discussed
> similar case in another driver with colleague of mine, and he insists that it
> might be still broken (somewhere).
>
Some drivers that use regmap with SPI implement their own read and write
callbacks if the default one doesn't work, so maybe something like that?
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] iio: amplifiers: ada4250: use DMA-safe memory for regmap_bulk_read()
2025-04-19 18:07 ` David Lechner
@ 2025-04-21 10:57 ` Jonathan Cameron
2025-04-21 13:00 ` Nuno Sá
0 siblings, 1 reply; 9+ messages in thread
From: Jonathan Cameron @ 2025-04-21 10:57 UTC (permalink / raw)
To: David Lechner
Cc: Andy Shevchenko, Antoniu Miclaus, Lars-Peter Clausen,
Michael Hennerich, Nuno Sá, Jonathan Cameron,
linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
Mark Brown
On Sat, 19 Apr 2025 13:07:25 -0500
David Lechner <dlechner@baylibre.com> wrote:
> On 4/19/25 10:03 AM, Andy Shevchenko wrote:
> > On Fri, Apr 18, 2025 at 02:09:04PM -0500, David Lechner wrote:
> >> On 4/18/25 1:58 PM, Andy Shevchenko wrote:
> >>> пʼятниця, 18 квітня 2025 р. David Lechner <dlechner@baylibre.com <mailto:dlechner@baylibre.com>> пише:
> >>>
> >>> 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.
> >>>
> >>> Sorry, but can you elaborate more on this? If driver doesn’t override the
> >>> callbacks the regmap SPI uses spi_write_then_read() which is supposed to be
> >>> dma safe.
> >>
> >> Ah, I didn't dig that far down. Will send a new patch that just cleans up the
> >> unnecessary alignment and unaligned call.
> >
> > But do you have a real life issue with that? Coincidentally we discussed
> > similar case in another driver with colleague of mine, and he insists that it
> > might be still broken (somewhere).
> >
>
> Some drivers that use regmap with SPI implement their own read and write
> callbacks if the default one doesn't work, so maybe something like that?
>
I asked Mark about this long ago. Maybe the guidance has changed, but the request
if my memory is correct was to treat bulk regmap accesses with the same care wrt to
DMA safety that we treat direct use of the underlying bus accessors.
(unfortunately I have no idea what thread this was in!)
The reasoning I think was that it was an implementation detail whether
regmap copied the data or not for bulk accesses. Back then I chased through
the SPI case and couldn't find a path that didn't bounce the data (though some
paths could have been made zero copy).
Anyhow, +CC Mark as maybe I remembered that wrong or his view has
changed!
Jonathan
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] iio: amplifiers: ada4250: use DMA-safe memory for regmap_bulk_read()
2025-04-21 10:57 ` Jonathan Cameron
@ 2025-04-21 13:00 ` Nuno Sá
2025-04-21 13:56 ` Jonathan Cameron
0 siblings, 1 reply; 9+ messages in thread
From: Nuno Sá @ 2025-04-21 13:00 UTC (permalink / raw)
To: Jonathan Cameron, David Lechner
Cc: Andy Shevchenko, Antoniu Miclaus, Lars-Peter Clausen,
Michael Hennerich, Nuno Sá, Jonathan Cameron,
linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
Mark Brown
On Mon, 2025-04-21 at 11:57 +0100, Jonathan Cameron wrote:
> On Sat, 19 Apr 2025 13:07:25 -0500
> David Lechner <dlechner@baylibre.com> wrote:
>
> > On 4/19/25 10:03 AM, Andy Shevchenko wrote:
> > > On Fri, Apr 18, 2025 at 02:09:04PM -0500, David Lechner wrote:
> > > > On 4/18/25 1:58 PM, Andy Shevchenko wrote:
> > > > > пʼятниця, 18 квітня 2025 р. David Lechner
> > > > > <dlechner@baylibre.com <mailto:dlechner@baylibre.com>> пише:
> > > > >
> > > > > 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.
> > > > >
> > > > > Sorry, but can you elaborate more on this? If driver doesn’t override
> > > > > the
> > > > > callbacks the regmap SPI uses spi_write_then_read() which is supposed
> > > > > to be
> > > > > dma safe.
> > > >
> > > > Ah, I didn't dig that far down. Will send a new patch that just cleans
> > > > up the
> > > > unnecessary alignment and unaligned call.
> > >
> > > But do you have a real life issue with that? Coincidentally we discussed
> > > similar case in another driver with colleague of mine, and he insists that
> > > it
> > > might be still broken (somewhere).
> > >
> >
> > Some drivers that use regmap with SPI implement their own read and write
> > callbacks if the default one doesn't work, so maybe something like that?
> >
>
> I asked Mark about this long ago. Maybe the guidance has changed, but the
> request
> if my memory is correct was to treat bulk regmap accesses with the same care
> wrt to
> DMA safety that we treat direct use of the underlying bus accessors.
> (unfortunately I have no idea what thread this was in!)
>
> The reasoning I think was that it was an implementation detail whether
> regmap copied the data or not for bulk accesses. Back then I chased through
> the SPI case and couldn't find a path that didn't bounce the data (though some
> paths could have been made zero copy).
>
Looking on the implementation, indeed it looks like that everything should be
fine... However, IMO, David's reasoning about potential drivers using their own
regmap_bus (or just overriding read and write) is perhaps justification enough
for doing it.
- Nuno Sá
> Anyhow, +CC Mark as maybe I remembered that wrong or his view has
> changed!
>
> Jonathan
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] iio: amplifiers: ada4250: use DMA-safe memory for regmap_bulk_read()
2025-04-21 13:00 ` Nuno Sá
@ 2025-04-21 13:56 ` Jonathan Cameron
2025-05-25 17:31 ` Jonathan Cameron
0 siblings, 1 reply; 9+ messages in thread
From: Jonathan Cameron @ 2025-04-21 13:56 UTC (permalink / raw)
To: Nuno Sá
Cc: David Lechner, Andy Shevchenko, Antoniu Miclaus,
Lars-Peter Clausen, Michael Hennerich, Nuno Sá,
Jonathan Cameron, linux-iio@vger.kernel.org,
linux-kernel@vger.kernel.org, Mark Brown
On Mon, 21 Apr 2025 14:00:30 +0100
Nuno Sá <noname.nuno@gmail.com> wrote:
> On Mon, 2025-04-21 at 11:57 +0100, Jonathan Cameron wrote:
> > On Sat, 19 Apr 2025 13:07:25 -0500
> > David Lechner <dlechner@baylibre.com> wrote:
> >
> > > On 4/19/25 10:03 AM, Andy Shevchenko wrote:
> > > > On Fri, Apr 18, 2025 at 02:09:04PM -0500, David Lechner wrote:
> > > > > On 4/18/25 1:58 PM, Andy Shevchenko wrote:
> > > > > > пʼятниця, 18 квітня 2025 р. David Lechner
> > > > > > <dlechner@baylibre.com <mailto:dlechner@baylibre.com>> пише:
> > > > > >
> > > > > > 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.
> > > > > >
> > > > > > Sorry, but can you elaborate more on this? If driver doesn’t override
> > > > > > the
> > > > > > callbacks the regmap SPI uses spi_write_then_read() which is supposed
> > > > > > to be
> > > > > > dma safe.
> > > > >
> > > > > Ah, I didn't dig that far down. Will send a new patch that just cleans
> > > > > up the
> > > > > unnecessary alignment and unaligned call.
> > > >
> > > > But do you have a real life issue with that? Coincidentally we discussed
> > > > similar case in another driver with colleague of mine, and he insists that
> > > > it
> > > > might be still broken (somewhere).
> > > >
> > >
> > > Some drivers that use regmap with SPI implement their own read and write
> > > callbacks if the default one doesn't work, so maybe something like that?
> > >
> >
> > I asked Mark about this long ago. Maybe the guidance has changed, but the
> > request
> > if my memory is correct was to treat bulk regmap accesses with the same care
> > wrt to
> > DMA safety that we treat direct use of the underlying bus accessors.
> > (unfortunately I have no idea what thread this was in!)
> >
> > The reasoning I think was that it was an implementation detail whether
> > regmap copied the data or not for bulk accesses. Back then I chased through
> > the SPI case and couldn't find a path that didn't bounce the data (though some
> > paths could have been made zero copy).
> >
>
> Looking on the implementation, indeed it looks like that everything should be
> fine... However, IMO, David's reasoning about potential drivers using their own
> regmap_bus (or just overriding read and write) is perhaps justification enough
> for doing it.
That's in a specific driver which is the same one allocating the buffer.
Doing it defensively in other drivers is probably a step too far if we don't
still want to do it everwhere regmap and SPI are combined.
Jonathan
>
> - Nuno Sá
>
> > Anyhow, +CC Mark as maybe I remembered that wrong or his view has
> > changed!
> >
> > Jonathan
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] iio: amplifiers: ada4250: use DMA-safe memory for regmap_bulk_read()
2025-04-21 13:56 ` Jonathan Cameron
@ 2025-05-25 17:31 ` Jonathan Cameron
0 siblings, 0 replies; 9+ messages in thread
From: Jonathan Cameron @ 2025-05-25 17:31 UTC (permalink / raw)
To: Nuno Sá
Cc: David Lechner, Andy Shevchenko, Antoniu Miclaus,
Lars-Peter Clausen, Michael Hennerich, Nuno Sá,
Jonathan Cameron, linux-iio@vger.kernel.org,
linux-kernel@vger.kernel.org, Mark Brown
On Mon, 21 Apr 2025 14:56:06 +0100
Jonathan Cameron <jic23@kernel.org> wrote:
> On Mon, 21 Apr 2025 14:00:30 +0100
> Nuno Sá <noname.nuno@gmail.com> wrote:
>
> > On Mon, 2025-04-21 at 11:57 +0100, Jonathan Cameron wrote:
> > > On Sat, 19 Apr 2025 13:07:25 -0500
> > > David Lechner <dlechner@baylibre.com> wrote:
> > >
> > > > On 4/19/25 10:03 AM, Andy Shevchenko wrote:
> > > > > On Fri, Apr 18, 2025 at 02:09:04PM -0500, David Lechner wrote:
> > > > > > On 4/18/25 1:58 PM, Andy Shevchenko wrote:
> > > > > > > пʼятниця, 18 квітня 2025 р. David Lechner
> > > > > > > <dlechner@baylibre.com <mailto:dlechner@baylibre.com>> пише:
> > > > > > >
> > > > > > > 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.
> > > > > > >
> > > > > > > Sorry, but can you elaborate more on this? If driver doesn’t override
> > > > > > > the
> > > > > > > callbacks the regmap SPI uses spi_write_then_read() which is supposed
> > > > > > > to be
> > > > > > > dma safe.
> > > > > >
> > > > > > Ah, I didn't dig that far down. Will send a new patch that just cleans
> > > > > > up the
> > > > > > unnecessary alignment and unaligned call.
> > > > >
> > > > > But do you have a real life issue with that? Coincidentally we discussed
> > > > > similar case in another driver with colleague of mine, and he insists that
> > > > > it
> > > > > might be still broken (somewhere).
> > > > >
> > > >
> > > > Some drivers that use regmap with SPI implement their own read and write
> > > > callbacks if the default one doesn't work, so maybe something like that?
> > > >
> > >
> > > I asked Mark about this long ago. Maybe the guidance has changed, but the
> > > request
> > > if my memory is correct was to treat bulk regmap accesses with the same care
> > > wrt to
> > > DMA safety that we treat direct use of the underlying bus accessors.
> > > (unfortunately I have no idea what thread this was in!)
> > >
> > > The reasoning I think was that it was an implementation detail whether
> > > regmap copied the data or not for bulk accesses. Back then I chased through
> > > the SPI case and couldn't find a path that didn't bounce the data (though some
> > > paths could have been made zero copy).
> > >
> >
> > Looking on the implementation, indeed it looks like that everything should be
> > fine... However, IMO, David's reasoning about potential drivers using their own
> > regmap_bus (or just overriding read and write) is perhaps justification enough
> > for doing it.
>
> That's in a specific driver which is the same one allocating the buffer.
> Doing it defensively in other drivers is probably a step too far if we don't
> still want to do it everwhere regmap and SPI are combined.
Given we don't believe this to be an active bug and no reply from Mark
on any change on regmap, I'm going to queue this up the slow way and
see if anyone objects. Queued up for 6.17.
I dropped the fixes tag and added a bit of commentary on why.
Jonathan
>
> Jonathan
>
>
> >
> > - Nuno Sá
> >
> > > Anyhow, +CC Mark as maybe I remembered that wrong or his view has
> > > changed!
> > >
> > > Jonathan
>
>
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] iio: amplifiers: ada4250: use DMA-safe memory for regmap_bulk_read()
2025-04-18 18:16 [PATCH] iio: amplifiers: ada4250: use DMA-safe memory for regmap_bulk_read() David Lechner
[not found] ` <CAHp75Vdxdbqu6qkbuo5y4jADOH_h9Re6m8icSj3Je4hnVsha0g@mail.gmail.com>
@ 2025-04-21 10:59 ` Jonathan Cameron
1 sibling, 0 replies; 9+ messages in thread
From: Jonathan Cameron @ 2025-04-21 10:59 UTC (permalink / raw)
To: David Lechner
Cc: Antoniu Miclaus, Lars-Peter Clausen, Michael Hennerich,
Nuno Sá, Andy Shevchenko, Jonathan Cameron, linux-iio,
linux-kernel
On Fri, 18 Apr 2025 13:16:13 -0500
David Lechner <dlechner@baylibre.com> wrote:
> 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.
>
> Fixes: 28b4c30bfa5f ("iio: amplifiers: ada4250: add support for ADA4250")
> Signed-off-by: David Lechner <dlechner@baylibre.com>
Let's wait and see if Mark has a view on this. The switch to an __le16 is
good either way.
Jonathan
> ---
> drivers/iio/amplifiers/ada4250.c | 10 +++++-----
> 1 file changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/iio/amplifiers/ada4250.c b/drivers/iio/amplifiers/ada4250.c
> index 74f8429d652b17b4d1f38366e23ce6a2b3e9b218..f81438460aa51ce30f8f605c60ee5be5c8c251d3 100644
> --- a/drivers/iio/amplifiers/ada4250.c
> +++ b/drivers/iio/amplifiers/ada4250.c
> @@ -13,8 +13,7 @@
> #include <linux/regmap.h>
> #include <linux/regulator/consumer.h>
> #include <linux/spi/spi.h>
> -
> -#include <linux/unaligned.h>
> +#include <linux/types.h>
>
> /* 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");
>
> ---
> base-commit: aff301f37e220970c2f301b5c65a8bfedf52058e
> change-id: 20250418-iio-amplifiers-ada4250-simplify-data-buffer-in-init-93ebb1344295
>
> Best regards,
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2025-05-25 17:32 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-18 18:16 [PATCH] iio: amplifiers: ada4250: use DMA-safe memory for regmap_bulk_read() David Lechner
[not found] ` <CAHp75Vdxdbqu6qkbuo5y4jADOH_h9Re6m8icSj3Je4hnVsha0g@mail.gmail.com>
2025-04-18 19:09 ` David Lechner
2025-04-19 15:03 ` Andy Shevchenko
2025-04-19 18:07 ` David Lechner
2025-04-21 10:57 ` Jonathan Cameron
2025-04-21 13:00 ` Nuno Sá
2025-04-21 13:56 ` Jonathan Cameron
2025-05-25 17:31 ` Jonathan Cameron
2025-04-21 10:59 ` Jonathan Cameron
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox