linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Nuno Sá via B4 Relay" <devnull+nuno.sa.analog.com@kernel.org>
To: linux-iio@vger.kernel.org, devicetree@vger.kernel.org
Cc: Michael Hennerich <Michael.Hennerich@analog.com>,
	 Jonathan Cameron <jic23@kernel.org>,
	David Lechner <dlechner@baylibre.com>,
	 Andy Shevchenko <andy@kernel.org>,
	Lars-Peter Clausen <lars@metafoo.de>,
	 Rob Herring <robh@kernel.org>,
	Krzysztof Kozlowski <krzk+dt@kernel.org>,
	 Conor Dooley <conor+dt@kernel.org>
Subject: [PATCH v4 02/12] iio: dac: ad5446: Use DMA safe buffer for transfers
Date: Tue, 04 Nov 2025 15:35:07 +0000	[thread overview]
Message-ID: <20251104-dev-add-ad5542-v4-2-6fe35458bf8c@analog.com> (raw)
In-Reply-To: <20251104-dev-add-ad5542-v4-0-6fe35458bf8c@analog.com>

From: Nuno Sá <nuno.sa@analog.com>

Make sure to use DMA safe buffer. While for i2c we could be fine without
them, we need it for spi anyways.

As we now have DMA safe buffers, use i2c_master_send_dmasafe().

Signed-off-by: Nuno Sá <nuno.sa@analog.com>
---
 drivers/iio/dac/ad5446.c | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/drivers/iio/dac/ad5446.c b/drivers/iio/dac/ad5446.c
index ad304b0fec08..de5e4e0e397e 100644
--- a/drivers/iio/dac/ad5446.c
+++ b/drivers/iio/dac/ad5446.c
@@ -47,6 +47,10 @@ struct ad5446_state {
 	unsigned			pwr_down_mode;
 	unsigned			pwr_down;
 	struct mutex			lock;
+	union {
+		__be16 d16;
+		u8 d24[3];
+	} __aligned(IIO_DMA_MINALIGN);
 };
 
 /**
@@ -265,19 +269,18 @@ static int ad5446_probe(struct device *dev, const char *name,
 static int ad5446_write(struct ad5446_state *st, unsigned val)
 {
 	struct spi_device *spi = to_spi_device(st->dev);
-	__be16 data = cpu_to_be16(val);
+	st->d16 = cpu_to_be16(val);
 
-	return spi_write(spi, &data, sizeof(data));
+	return spi_write(spi, &st->d16, sizeof(st->d16));
 }
 
 static int ad5660_write(struct ad5446_state *st, unsigned val)
 {
 	struct spi_device *spi = to_spi_device(st->dev);
-	uint8_t data[3];
 
-	put_unaligned_be24(val, &data[0]);
+	put_unaligned_be24(val, &st->d24[0]);
 
-	return spi_write(spi, data, sizeof(data));
+	return spi_write(spi, st->d24, sizeof(st->d24));
 }
 
 /*
@@ -489,13 +492,13 @@ static inline void ad5446_spi_unregister_driver(void) { }
 static int ad5622_write(struct ad5446_state *st, unsigned val)
 {
 	struct i2c_client *client = to_i2c_client(st->dev);
-	__be16 data = cpu_to_be16(val);
+	st->d16 = cpu_to_be16(val);
 	int ret;
 
-	ret = i2c_master_send(client, (char *)&data, sizeof(data));
+	ret = i2c_master_send_dmasafe(client, (char *)&st->d16, sizeof(st->d16));
 	if (ret < 0)
 		return ret;
-	if (ret != sizeof(data))
+	if (ret != sizeof(st->d16))
 		return -EIO;
 
 	return 0;

-- 
2.51.0



  parent reply	other threads:[~2025-11-04 15:34 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-04 15:35 [PATCH v4 00/12] iio: dac: ad5446: Refactor and add support for AD5542 Nuno Sá via B4 Relay
2025-11-04 15:35 ` [PATCH v4 01/12] dt-bindings: iio: dac: Document AD5446 and similar devices Nuno Sá via B4 Relay
2025-11-04 17:51   ` [PATCH v5 6/7] dt-bindings: clock: rockchip: Add RK3506 clock and reset unit Conor Dooley
2025-11-04 15:35 ` Nuno Sá via B4 Relay [this message]
2025-11-04 17:10   ` [PATCH v4 02/12] iio: dac: ad5446: Use DMA safe buffer for transfers Andy Shevchenko
2025-11-04 15:35 ` [PATCH v4 03/12] iio: dac: ad5446: Drop duplicated spi_id entry Nuno Sá via B4 Relay
2025-11-04 17:12   ` Andy Shevchenko
2025-11-05 10:16     ` Nuno Sá
2025-11-04 15:35 ` [PATCH v4 04/12] iio: dac: ad5446: Don't ignore missing regulator Nuno Sá via B4 Relay
2025-11-04 15:35 ` [PATCH v4 05/12] iio: dac: ad5446: Move to single chip_info structures Nuno Sá via B4 Relay
2025-11-04 15:35 ` [PATCH v4 06/12] iio: dac: ad5456: Add missing DT compatibles Nuno Sá via B4 Relay
2025-11-04 15:35 ` [PATCH v4 07/12] iio: dac: ad5446: Separate I2C/SPI into different drivers Nuno Sá via B4 Relay
2025-11-04 18:20   ` Andy Shevchenko
2025-11-04 15:35 ` [PATCH v4 08/12] iio: dac: ad5446: Make use of devm_mutex_init() Nuno Sá via B4 Relay
2025-11-04 15:35 ` [PATCH v4 09/12] iio: dac: ad5446: Make use of the cleanup helpers Nuno Sá via B4 Relay
2025-11-04 18:23   ` Andy Shevchenko
2025-11-04 15:35 ` [PATCH v4 10/12] iio: dac: ad5446: Refactor header inclusion Nuno Sá via B4 Relay
2025-11-04 18:24   ` Andy Shevchenko
2025-11-04 15:35 ` [PATCH v4 11/12] iio: dac: ad5446: Fix coding style issues Nuno Sá via B4 Relay
2025-11-04 18:26   ` Andy Shevchenko
2025-11-04 15:35 ` [PATCH v4 12/12] iio: dac: ad5446: Add AD5542 to the spi id table Nuno Sá via B4 Relay
2025-11-04 18:30 ` [PATCH v4 00/12] iio: dac: ad5446: Refactor and add support for AD5542 Andy Shevchenko
2025-11-05 10:16   ` Nuno Sá

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20251104-dev-add-ad5542-v4-2-6fe35458bf8c@analog.com \
    --to=devnull+nuno.sa.analog.com@kernel.org \
    --cc=Michael.Hennerich@analog.com \
    --cc=andy@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dlechner@baylibre.com \
    --cc=jic23@kernel.org \
    --cc=krzk+dt@kernel.org \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=nuno.sa@analog.com \
    --cc=robh@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).