public inbox for linux-iio@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 00/11] Fixes and cleanups for the AD5686 IIO driver
@ 2026-04-27 11:30 Rodrigo Alencar via B4 Relay
  2026-04-27 11:30 ` [PATCH v2 01/11] iio: dac: ad5686: fix ref bit initialization for single-channel parts Rodrigo Alencar via B4 Relay
                   ` (11 more replies)
  0 siblings, 12 replies; 19+ messages in thread
From: Rodrigo Alencar via B4 Relay @ 2026-04-27 11:30 UTC (permalink / raw)
  To: linux-iio, linux-kernel, Stefan Popa, Jonathan Cameron,
	Greg Kroah-Hartman, Michael Auchter, Jonathan Cameron
  Cc: Lars-Peter Clausen, Michael Hennerich, Jonathan Cameron,
	David Lechner, Andy Shevchenko, Rodrigo Alencar, Andy Shevchenko

This is the first series of three on updating the AD5686 driver.

A bigger patch series was sent before ("Extend device support for AD5686 driver"),
but this is not exactly a v2:

https://lore.kernel.org/r/20260422-ad5313r-iio-support-v1-0-ed7dca001d1b@analog.com

This one adds a number of cleanups and fixes, like:
- Refactor include headers (IWYU);
- Remove redundant register definition;
- Drop enum chip id in favor of per-device chip_info structs;
- Fix internal voltage reference control for single-channel devices;
- Acquire lock when doing power down control;
- Fix powerdown control for dual-channel devices;

Signed-off-by: Rodrigo Alencar <rodrigo.alencar@analog.com>
---
Changes in v2:
- Bring fixes first and cleanups later
- Link to v1: https://lore.kernel.org/r/20260426-ad5686-fixes-v1-0-7c946a77794e@analog.com

---
Rodrigo Alencar (11):
      iio: dac: ad5686: fix ref bit initialization for single-channel parts
      iio: dac: ad5686: fix input raw value check
      iio: dac: ad5686: acquire lock when doing powerdown control
      iio: dac: ad5686: fix powerdown control on dual-channel devices
      iio: dac: ad5686: refactor include headers
      iio: dac: ad5686: remove redundant register definition
      iio: dac: ad5686: drop enum id
      iio: dac: ad5686: add of_match table to the spi driver
      iio: dac: ad5686: add control_sync() for single-channel devices
      iio: dac: ad5686: cleanup doc header of local structs
      iio: dac: ad5686: create bus ops struct

 drivers/iio/dac/ad5686-spi.c |  73 ++++--
 drivers/iio/dac/ad5686.c     | 521 +++++++++++++++++++++----------------------
 drivers/iio/dac/ad5686.h     | 116 +++++-----
 drivers/iio/dac/ad5696-i2c.c |  80 ++++---
 4 files changed, 409 insertions(+), 381 deletions(-)
---
base-commit: d86db1905add39f905cf9f04252804b359914ed6
change-id: 20260426-ad5686-fixes-63ea68811bdb

Best regards,
-- 
Rodrigo Alencar <rodrigo.alencar@analog.com>



^ permalink raw reply	[flat|nested] 19+ messages in thread

* [PATCH v2 01/11] iio: dac: ad5686: fix ref bit initialization for single-channel parts
  2026-04-27 11:30 [PATCH v2 00/11] Fixes and cleanups for the AD5686 IIO driver Rodrigo Alencar via B4 Relay
@ 2026-04-27 11:30 ` Rodrigo Alencar via B4 Relay
  2026-04-27 17:53   ` Andy Shevchenko
  2026-04-27 11:30 ` [PATCH v2 02/11] iio: dac: ad5686: fix input raw value check Rodrigo Alencar via B4 Relay
                   ` (10 subsequent siblings)
  11 siblings, 1 reply; 19+ messages in thread
From: Rodrigo Alencar via B4 Relay @ 2026-04-27 11:30 UTC (permalink / raw)
  To: linux-iio, linux-kernel, Stefan Popa, Jonathan Cameron,
	Greg Kroah-Hartman, Michael Auchter, Jonathan Cameron
  Cc: Lars-Peter Clausen, Michael Hennerich, Jonathan Cameron,
	David Lechner, Andy Shevchenko, Rodrigo Alencar

From: Rodrigo Alencar <rodrigo.alencar@analog.com>

The reference bit position was ignored when writing the register at the
probe() function (!!val was used). When such bit is 1, internal voltage
reference is disabled so that an external one can be used. For
multi-channel devices, bit 0 of the Internal Reference Setup command
behaves the same way, so AD5686_REF_BIT_MSK is created. The issue exists
since support for single-channel devices were first introduced.

Fixes: be1b24d24541 ("iio:dac:ad5686: Add AD5691R/AD5692R/AD5693/AD5693R support")
Signed-off-by: Rodrigo Alencar <rodrigo.alencar@analog.com>
---
 drivers/iio/dac/ad5686.c | 6 +++---
 drivers/iio/dac/ad5686.h | 1 +
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/iio/dac/ad5686.c b/drivers/iio/dac/ad5686.c
index 9a384c50929b..3b48ddf8dd3c 100644
--- a/drivers/iio/dac/ad5686.c
+++ b/drivers/iio/dac/ad5686.c
@@ -511,7 +511,7 @@ int ad5686_probe(struct device *dev,
 		break;
 	case AD5686_REGMAP:
 		cmd = AD5686_CMD_INTERNAL_REFER_SETUP;
-		ref_bit_msk = 0;
+		ref_bit_msk = AD5686_REF_BIT_MSK;
 		break;
 	case AD5693_REGMAP:
 		cmd = AD5686_CMD_CONTROL_REG;
@@ -522,9 +522,9 @@ int ad5686_probe(struct device *dev,
 		return -EINVAL;
 	}
 
-	val = (has_external_vref | ref_bit_msk);
+	val = (has_external_vref) ? ref_bit_msk : 0;
 
-	ret = st->write(st, cmd, 0, !!val);
+	ret = st->write(st, cmd, 0, val);
 	if (ret)
 		return ret;
 
diff --git a/drivers/iio/dac/ad5686.h b/drivers/iio/dac/ad5686.h
index e7d36bae3e59..36e16c5c4581 100644
--- a/drivers/iio/dac/ad5686.h
+++ b/drivers/iio/dac/ad5686.h
@@ -46,6 +46,7 @@
 
 #define AD5310_REF_BIT_MSK			BIT(8)
 #define AD5683_REF_BIT_MSK			BIT(12)
+#define AD5686_REF_BIT_MSK			BIT(0)
 #define AD5693_REF_BIT_MSK			BIT(12)
 
 /**

-- 
2.43.0



^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH v2 02/11] iio: dac: ad5686: fix input raw value check
  2026-04-27 11:30 [PATCH v2 00/11] Fixes and cleanups for the AD5686 IIO driver Rodrigo Alencar via B4 Relay
  2026-04-27 11:30 ` [PATCH v2 01/11] iio: dac: ad5686: fix ref bit initialization for single-channel parts Rodrigo Alencar via B4 Relay
@ 2026-04-27 11:30 ` Rodrigo Alencar via B4 Relay
  2026-04-27 11:30 ` [PATCH v2 03/11] iio: dac: ad5686: acquire lock when doing powerdown control Rodrigo Alencar via B4 Relay
                   ` (9 subsequent siblings)
  11 siblings, 0 replies; 19+ messages in thread
From: Rodrigo Alencar via B4 Relay @ 2026-04-27 11:30 UTC (permalink / raw)
  To: linux-iio, linux-kernel, Stefan Popa, Jonathan Cameron,
	Greg Kroah-Hartman, Michael Auchter, Jonathan Cameron
  Cc: Lars-Peter Clausen, Michael Hennerich, Jonathan Cameron,
	David Lechner, Andy Shevchenko, Rodrigo Alencar

From: Rodrigo Alencar <rodrigo.alencar@analog.com>

Fix range check for input raw value, which is off by one, i.e., for a
10-bit DAC the max valid value is 1023, but 1 << 10 equals 1024, which
passes the previous check, allowing an out-of-range write. The issue
exists since the ad5686 driver was first introduced.

Fixes: c2f37c8dcadc ("iio: dac: New driver for AD5686R, AD5685R, AD5684R Digital to analog converters")
Signed-off-by: Rodrigo Alencar <rodrigo.alencar@analog.com>
---
 drivers/iio/dac/ad5686.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/iio/dac/ad5686.c b/drivers/iio/dac/ad5686.c
index 3b48ddf8dd3c..24f928ea2b91 100644
--- a/drivers/iio/dac/ad5686.c
+++ b/drivers/iio/dac/ad5686.c
@@ -154,7 +154,7 @@ static int ad5686_write_raw(struct iio_dev *indio_dev,
 
 	switch (mask) {
 	case IIO_CHAN_INFO_RAW:
-		if (val > (1 << chan->scan_type.realbits) || val < 0)
+		if (val >= (1 << chan->scan_type.realbits) || val < 0)
 			return -EINVAL;
 
 		mutex_lock(&st->lock);

-- 
2.43.0



^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH v2 03/11] iio: dac: ad5686: acquire lock when doing powerdown control
  2026-04-27 11:30 [PATCH v2 00/11] Fixes and cleanups for the AD5686 IIO driver Rodrigo Alencar via B4 Relay
  2026-04-27 11:30 ` [PATCH v2 01/11] iio: dac: ad5686: fix ref bit initialization for single-channel parts Rodrigo Alencar via B4 Relay
  2026-04-27 11:30 ` [PATCH v2 02/11] iio: dac: ad5686: fix input raw value check Rodrigo Alencar via B4 Relay
@ 2026-04-27 11:30 ` Rodrigo Alencar via B4 Relay
  2026-04-27 17:56   ` Andy Shevchenko
  2026-04-27 11:30 ` [PATCH v2 04/11] iio: dac: ad5686: fix powerdown control on dual-channel devices Rodrigo Alencar via B4 Relay
                   ` (8 subsequent siblings)
  11 siblings, 1 reply; 19+ messages in thread
From: Rodrigo Alencar via B4 Relay @ 2026-04-27 11:30 UTC (permalink / raw)
  To: linux-iio, linux-kernel, Stefan Popa, Jonathan Cameron,
	Greg Kroah-Hartman, Michael Auchter, Jonathan Cameron
  Cc: Lars-Peter Clausen, Michael Hennerich, Jonathan Cameron,
	David Lechner, Andy Shevchenko, Rodrigo Alencar

From: Rodrigo Alencar <rodrigo.alencar@analog.com>

Protect write access of pwr_down_mode and pwr_down_mask fields with
existing mutex lock. Each channel exposes their own attributes for
controlling powerdown modes and powerdown state. This fixes potential race
conditions as those functions perform non-atomic read-modify-write
operations to those pwr_down_* fields. This issue exists since the ad5686
driver was first introduced.

Fixes: c2f37c8dcadc ("iio: dac: New driver for AD5686R, AD5685R, AD5684R Digital to analog converters")
Signed-off-by: Rodrigo Alencar <rodrigo.alencar@analog.com>
---
 drivers/iio/dac/ad5686.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/iio/dac/ad5686.c b/drivers/iio/dac/ad5686.c
index 24f928ea2b91..aa17ed6aee43 100644
--- a/drivers/iio/dac/ad5686.c
+++ b/drivers/iio/dac/ad5686.c
@@ -39,6 +39,8 @@ static int ad5686_set_powerdown_mode(struct iio_dev *indio_dev,
 {
 	struct ad5686_state *st = iio_priv(indio_dev);
 
+	guard(mutex)(&st->lock);
+
 	st->pwr_down_mode &= ~(0x3 << (chan->channel * 2));
 	st->pwr_down_mode |= ((mode + 1) << (chan->channel * 2));
 
@@ -77,6 +79,8 @@ static ssize_t ad5686_write_dac_powerdown(struct iio_dev *indio_dev,
 	if (ret)
 		return ret;
 
+	guard(mutex)(&st->lock);
+
 	if (readin)
 		st->pwr_down_mask |= (0x3 << (chan->channel * 2));
 	else

-- 
2.43.0



^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH v2 04/11] iio: dac: ad5686: fix powerdown control on dual-channel devices
  2026-04-27 11:30 [PATCH v2 00/11] Fixes and cleanups for the AD5686 IIO driver Rodrigo Alencar via B4 Relay
                   ` (2 preceding siblings ...)
  2026-04-27 11:30 ` [PATCH v2 03/11] iio: dac: ad5686: acquire lock when doing powerdown control Rodrigo Alencar via B4 Relay
@ 2026-04-27 11:30 ` Rodrigo Alencar via B4 Relay
  2026-04-27 18:02   ` Andy Shevchenko
  2026-04-27 11:30 ` [PATCH v2 05/11] iio: dac: ad5686: refactor include headers Rodrigo Alencar via B4 Relay
                   ` (7 subsequent siblings)
  11 siblings, 1 reply; 19+ messages in thread
From: Rodrigo Alencar via B4 Relay @ 2026-04-27 11:30 UTC (permalink / raw)
  To: linux-iio, linux-kernel, Stefan Popa, Jonathan Cameron,
	Greg Kroah-Hartman, Michael Auchter, Jonathan Cameron
  Cc: Lars-Peter Clausen, Michael Hennerich, Jonathan Cameron,
	David Lechner, Andy Shevchenko, Rodrigo Alencar

From: Rodrigo Alencar <rodrigo.alencar@analog.com>

Fix powerdown control by using a proper bit shift for the powerdown mask
values. During initialization, powerdown bits are initialized so that
unused bits are set to 1 and the correct bit shift is used. Dual-channel
devices use one-hot encoding in the address and that reflects on the
position of the powerdown bits, which are not channel-index based
for that case. Quad-channel devices also use one-hot encoding for the
channel address but the result of log2(address) coincides with the channel
index value. The issue was introduced when first adding support for
dual-channel devices, which overlooked powerdown control differences.

Fixes: 7dc8faeab3e3 ("iio: dac: ad5686: add support for AD5338R")
Signed-off-by: Rodrigo Alencar <rodrigo.alencar@analog.com>
---
 drivers/iio/dac/ad5686.c | 37 +++++++++++++++++++++++++++----------
 1 file changed, 27 insertions(+), 10 deletions(-)

diff --git a/drivers/iio/dac/ad5686.c b/drivers/iio/dac/ad5686.c
index aa17ed6aee43..04a5568f2cbe 100644
--- a/drivers/iio/dac/ad5686.c
+++ b/drivers/iio/dac/ad5686.c
@@ -25,24 +25,35 @@ static const char * const ad5686_powerdown_modes[] = {
 	"three_state"
 };
 
+static inline unsigned int ad5686_pd_mask_shift(const struct iio_chan_spec *chan)
+{
+	if (chan->channel == chan->address)
+		return chan->channel * 2;
+
+	/* one-hot encoding is used in dual/quad channel devices */
+	return __ffs(chan->address) * 2;
+}
+
 static int ad5686_get_powerdown_mode(struct iio_dev *indio_dev,
 				     const struct iio_chan_spec *chan)
 {
+	unsigned int shift = ad5686_pd_mask_shift(chan);
 	struct ad5686_state *st = iio_priv(indio_dev);
 
-	return ((st->pwr_down_mode >> (chan->channel * 2)) & 0x3) - 1;
+	return ((st->pwr_down_mode >> shift) & 0x3) - 1;
 }
 
 static int ad5686_set_powerdown_mode(struct iio_dev *indio_dev,
 				     const struct iio_chan_spec *chan,
 				     unsigned int mode)
 {
+	unsigned int shift = ad5686_pd_mask_shift(chan);
 	struct ad5686_state *st = iio_priv(indio_dev);
 
 	guard(mutex)(&st->lock);
 
-	st->pwr_down_mode &= ~(0x3 << (chan->channel * 2));
-	st->pwr_down_mode |= ((mode + 1) << (chan->channel * 2));
+	st->pwr_down_mode &= ~(0x3 << shift);
+	st->pwr_down_mode |= ((mode + 1) << shift);
 
 	return 0;
 }
@@ -57,10 +68,10 @@ static const struct iio_enum ad5686_powerdown_mode_enum = {
 static ssize_t ad5686_read_dac_powerdown(struct iio_dev *indio_dev,
 		uintptr_t private, const struct iio_chan_spec *chan, char *buf)
 {
+	unsigned int shift = ad5686_pd_mask_shift(chan);
 	struct ad5686_state *st = iio_priv(indio_dev);
 
-	return sysfs_emit(buf, "%d\n", !!(st->pwr_down_mask &
-				       (0x3 << (chan->channel * 2))));
+	return sysfs_emit(buf, "%d\n", !!(st->pwr_down_mask & (0x3 << shift)));
 }
 
 static ssize_t ad5686_write_dac_powerdown(struct iio_dev *indio_dev,
@@ -82,9 +93,9 @@ static ssize_t ad5686_write_dac_powerdown(struct iio_dev *indio_dev,
 	guard(mutex)(&st->lock);
 
 	if (readin)
-		st->pwr_down_mask |= (0x3 << (chan->channel * 2));
+		st->pwr_down_mask |= (0x3 << ad5686_pd_mask_shift(chan));
 	else
-		st->pwr_down_mask &= ~(0x3 << (chan->channel * 2));
+		st->pwr_down_mask &= ~(0x3 << ad5686_pd_mask_shift(chan));
 
 	switch (st->chip_info->regmap_type) {
 	case AD5310_REGMAP:
@@ -464,7 +475,7 @@ int ad5686_probe(struct device *dev,
 {
 	struct ad5686_state *st;
 	struct iio_dev *indio_dev;
-	unsigned int val, ref_bit_msk;
+	unsigned int val, ref_bit_msk, shift;
 	bool has_external_vref;
 	u8 cmd;
 	int ret, i;
@@ -489,8 +500,14 @@ int ad5686_probe(struct device *dev,
 	st->vref_mv = has_external_vref ? ret / 1000 : st->chip_info->int_vref_mv;
 
 	/* Set all the power down mode for all channels to 1K pulldown */
-	for (i = 0; i < st->chip_info->num_channels; i++)
-		st->pwr_down_mode |= (0x01 << (i * 2));
+	st->pwr_down_mode = ~0U;
+	st->pwr_down_mask = ~0U;
+	for (i = 0; i < st->chip_info->num_channels; i++) {
+		shift = ad5686_pd_mask_shift(&st->chip_info->channels[i]);
+		st->pwr_down_mask &= ~(0x3 << shift); /* powered up state */
+		st->pwr_down_mode &= ~(0x3 << shift);
+		st->pwr_down_mode |= (0x01 << shift);
+	}
 
 	indio_dev->name = name;
 	indio_dev->info = &ad5686_info;

-- 
2.43.0



^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH v2 05/11] iio: dac: ad5686: refactor include headers
  2026-04-27 11:30 [PATCH v2 00/11] Fixes and cleanups for the AD5686 IIO driver Rodrigo Alencar via B4 Relay
                   ` (3 preceding siblings ...)
  2026-04-27 11:30 ` [PATCH v2 04/11] iio: dac: ad5686: fix powerdown control on dual-channel devices Rodrigo Alencar via B4 Relay
@ 2026-04-27 11:30 ` Rodrigo Alencar via B4 Relay
  2026-04-27 11:30 ` [PATCH v2 06/11] iio: dac: ad5686: remove redundant register definition Rodrigo Alencar via B4 Relay
                   ` (6 subsequent siblings)
  11 siblings, 0 replies; 19+ messages in thread
From: Rodrigo Alencar via B4 Relay @ 2026-04-27 11:30 UTC (permalink / raw)
  To: linux-iio, linux-kernel, Stefan Popa, Jonathan Cameron,
	Greg Kroah-Hartman, Michael Auchter, Jonathan Cameron
  Cc: Lars-Peter Clausen, Michael Hennerich, Jonathan Cameron,
	David Lechner, Andy Shevchenko, Rodrigo Alencar

From: Rodrigo Alencar <rodrigo.alencar@analog.com>

Apply IWYU principle, replacing unused/generic headers for
specific/missing headers. The resulting include directive lists are sorted
accordingly.

Signed-off-by: Rodrigo Alencar <rodrigo.alencar@analog.com>
---
 drivers/iio/dac/ad5686-spi.c |  9 +++++++--
 drivers/iio/dac/ad5686.c     | 11 ++++-------
 drivers/iio/dac/ad5686.h     |  5 ++---
 drivers/iio/dac/ad5696-i2c.c | 10 +++++++---
 4 files changed, 20 insertions(+), 15 deletions(-)

diff --git a/drivers/iio/dac/ad5686-spi.c b/drivers/iio/dac/ad5686-spi.c
index df8619e0c092..695125238633 100644
--- a/drivers/iio/dac/ad5686-spi.c
+++ b/drivers/iio/dac/ad5686-spi.c
@@ -8,11 +8,16 @@
  * Copyright 2018 Analog Devices Inc.
  */
 
-#include "ad5686.h"
-
+#include <linux/array_size.h>
+#include <linux/err.h>
+#include <linux/mod_devicetable.h>
 #include <linux/module.h>
 #include <linux/spi/spi.h>
 
+#include <asm/byteorder.h>
+
+#include "ad5686.h"
+
 static int ad5686_spi_write(struct ad5686_state *st,
 			    u8 cmd, u8 addr, u16 val)
 {
diff --git a/drivers/iio/dac/ad5686.c b/drivers/iio/dac/ad5686.c
index 04a5568f2cbe..2c1692097c0c 100644
--- a/drivers/iio/dac/ad5686.c
+++ b/drivers/iio/dac/ad5686.c
@@ -5,17 +5,14 @@
  * Copyright 2011 Analog Devices Inc.
  */
 
-#include <linux/interrupt.h>
-#include <linux/fs.h>
-#include <linux/device.h>
+#include <linux/array_size.h>
+#include <linux/err.h>
+#include <linux/export.h>
 #include <linux/module.h>
-#include <linux/kernel.h>
-#include <linux/slab.h>
-#include <linux/sysfs.h>
 #include <linux/regulator/consumer.h>
+#include <linux/sysfs.h>
 
 #include <linux/iio/iio.h>
-#include <linux/iio/sysfs.h>
 
 #include "ad5686.h"
 
diff --git a/drivers/iio/dac/ad5686.h b/drivers/iio/dac/ad5686.h
index 36e16c5c4581..d08160e7fad9 100644
--- a/drivers/iio/dac/ad5686.h
+++ b/drivers/iio/dac/ad5686.h
@@ -8,10 +8,9 @@
 #ifndef __DRIVERS_IIO_DAC_AD5686_H__
 #define __DRIVERS_IIO_DAC_AD5686_H__
 
-#include <linux/types.h>
-#include <linux/cache.h>
+#include <linux/bits.h>
 #include <linux/mutex.h>
-#include <linux/kernel.h>
+#include <linux/types.h>
 
 #include <linux/iio/iio.h>
 
diff --git a/drivers/iio/dac/ad5696-i2c.c b/drivers/iio/dac/ad5696-i2c.c
index d3327bca0e07..e7e1b8a6fc71 100644
--- a/drivers/iio/dac/ad5696-i2c.c
+++ b/drivers/iio/dac/ad5696-i2c.c
@@ -7,10 +7,14 @@
  * Copyright 2018 Analog Devices Inc.
  */
 
-#include "ad5686.h"
-
-#include <linux/module.h>
+#include <linux/err.h>
 #include <linux/i2c.h>
+#include <linux/mod_devicetable.h>
+#include <linux/module.h>
+
+#include <asm/byteorder.h>
+
+#include "ad5686.h"
 
 static int ad5686_i2c_read(struct ad5686_state *st, u8 addr)
 {

-- 
2.43.0



^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH v2 06/11] iio: dac: ad5686: remove redundant register definition
  2026-04-27 11:30 [PATCH v2 00/11] Fixes and cleanups for the AD5686 IIO driver Rodrigo Alencar via B4 Relay
                   ` (4 preceding siblings ...)
  2026-04-27 11:30 ` [PATCH v2 05/11] iio: dac: ad5686: refactor include headers Rodrigo Alencar via B4 Relay
@ 2026-04-27 11:30 ` Rodrigo Alencar via B4 Relay
  2026-04-27 11:30 ` [PATCH v2 07/11] iio: dac: ad5686: drop enum id Rodrigo Alencar via B4 Relay
                   ` (5 subsequent siblings)
  11 siblings, 0 replies; 19+ messages in thread
From: Rodrigo Alencar via B4 Relay @ 2026-04-27 11:30 UTC (permalink / raw)
  To: linux-iio, linux-kernel, Stefan Popa, Jonathan Cameron,
	Greg Kroah-Hartman, Michael Auchter, Jonathan Cameron
  Cc: Lars-Peter Clausen, Michael Hennerich, Jonathan Cameron,
	David Lechner, Andy Shevchenko, Rodrigo Alencar, Andy Shevchenko

From: Rodrigo Alencar <rodrigo.alencar@analog.com>

AD5683_REGMAP and AD5693_REGMAP behave the same way in the common code,
and that is because they target single channel devices from the same
sub-family. There is no reason to separate them and it will make things
simpler when refactoring the chip info table.

Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
Signed-off-by: Rodrigo Alencar <rodrigo.alencar@analog.com>
---
 drivers/iio/dac/ad5686.c | 19 +++++--------------
 drivers/iio/dac/ad5686.h |  2 --
 2 files changed, 5 insertions(+), 16 deletions(-)

diff --git a/drivers/iio/dac/ad5686.c b/drivers/iio/dac/ad5686.c
index 2c1692097c0c..53d58f0af16e 100644
--- a/drivers/iio/dac/ad5686.c
+++ b/drivers/iio/dac/ad5686.c
@@ -110,10 +110,6 @@ static ssize_t ad5686_write_dac_powerdown(struct iio_dev *indio_dev,
 		if (chan->channel > 0x7)
 			address = 0x8;
 		break;
-	case AD5693_REGMAP:
-		shift = 13;
-		ref_bit_msk = AD5693_REF_BIT_MSK;
-		break;
 	default:
 		return -EINVAL;
 	}
@@ -294,7 +290,7 @@ static const struct ad5686_chip_info ad5686_chip_info_tbl[] = {
 		.channels = ad5311r_channels,
 		.int_vref_mv = 2500,
 		.num_channels = 1,
-		.regmap_type = AD5693_REGMAP,
+		.regmap_type = AD5683_REGMAP,
 	},
 	[ID_AD5337R] = {
 		.channels = ad5337r_channels,
@@ -416,24 +412,24 @@ static const struct ad5686_chip_info ad5686_chip_info_tbl[] = {
 		.channels = ad5691r_channels,
 		.int_vref_mv = 2500,
 		.num_channels = 1,
-		.regmap_type = AD5693_REGMAP,
+		.regmap_type = AD5683_REGMAP,
 	},
 	[ID_AD5692R] = {
 		.channels = ad5692r_channels,
 		.int_vref_mv = 2500,
 		.num_channels = 1,
-		.regmap_type = AD5693_REGMAP,
+		.regmap_type = AD5683_REGMAP,
 	},
 	[ID_AD5693] = {
 		.channels = ad5693_channels,
 		.num_channels = 1,
-		.regmap_type = AD5693_REGMAP,
+		.regmap_type = AD5683_REGMAP,
 	},
 	[ID_AD5693R] = {
 		.channels = ad5693_channels,
 		.int_vref_mv = 2500,
 		.num_channels = 1,
-		.regmap_type = AD5693_REGMAP,
+		.regmap_type = AD5683_REGMAP,
 	},
 	[ID_AD5694] = {
 		.channels = ad5684_channels,
@@ -531,11 +527,6 @@ int ad5686_probe(struct device *dev,
 		cmd = AD5686_CMD_INTERNAL_REFER_SETUP;
 		ref_bit_msk = AD5686_REF_BIT_MSK;
 		break;
-	case AD5693_REGMAP:
-		cmd = AD5686_CMD_CONTROL_REG;
-		ref_bit_msk = AD5693_REF_BIT_MSK;
-		st->use_internal_vref = !has_external_vref;
-		break;
 	default:
 		return -EINVAL;
 	}
diff --git a/drivers/iio/dac/ad5686.h b/drivers/iio/dac/ad5686.h
index d08160e7fad9..af15994c01ad 100644
--- a/drivers/iio/dac/ad5686.h
+++ b/drivers/iio/dac/ad5686.h
@@ -46,7 +46,6 @@
 #define AD5310_REF_BIT_MSK			BIT(8)
 #define AD5683_REF_BIT_MSK			BIT(12)
 #define AD5686_REF_BIT_MSK			BIT(0)
-#define AD5693_REF_BIT_MSK			BIT(12)
 
 /**
  * ad5686_supported_device_ids:
@@ -89,7 +88,6 @@ enum ad5686_regmap_type {
 	AD5310_REGMAP,
 	AD5683_REGMAP,
 	AD5686_REGMAP,
-	AD5693_REGMAP
 };
 
 struct ad5686_state;

-- 
2.43.0



^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH v2 07/11] iio: dac: ad5686: drop enum id
  2026-04-27 11:30 [PATCH v2 00/11] Fixes and cleanups for the AD5686 IIO driver Rodrigo Alencar via B4 Relay
                   ` (5 preceding siblings ...)
  2026-04-27 11:30 ` [PATCH v2 06/11] iio: dac: ad5686: remove redundant register definition Rodrigo Alencar via B4 Relay
@ 2026-04-27 11:30 ` Rodrigo Alencar via B4 Relay
  2026-04-27 11:30 ` [PATCH v2 08/11] iio: dac: ad5686: add of_match table to the spi driver Rodrigo Alencar via B4 Relay
                   ` (4 subsequent siblings)
  11 siblings, 0 replies; 19+ messages in thread
From: Rodrigo Alencar via B4 Relay @ 2026-04-27 11:30 UTC (permalink / raw)
  To: linux-iio, linux-kernel, Stefan Popa, Jonathan Cameron,
	Greg Kroah-Hartman, Michael Auchter, Jonathan Cameron
  Cc: Lars-Peter Clausen, Michael Hennerich, Jonathan Cameron,
	David Lechner, Andy Shevchenko, Rodrigo Alencar

From: Rodrigo Alencar <rodrigo.alencar@analog.com>

Split chip info table into separate structs and expose them to the spi
i2c drivers. That is the preferrable approach and allows for the drivers
to have knowledge of the device info before the common probe function gets
called. Those chip info structs may be shared by SPI and I2C driver
variants.
Channel declaration definitions are grouped according to channel count and
DECLARE_AD5693_CHANNELS() macro is renamed to DECLARE_AD5683_CHANNELS() to
match the regmap_type enum.
Use spi_get_device_match_data() and i2c_get_match_data() to get chip info
struct reference, passing it as parameter to the core probe function.

Signed-off-by: Rodrigo Alencar <rodrigo.alencar@analog.com>
---
 drivers/iio/dac/ad5686-spi.c |  38 +++--
 drivers/iio/dac/ad5686.c     | 358 ++++++++++++++++++++-----------------------
 drivers/iio/dac/ad5686.h     |  66 ++++----
 drivers/iio/dac/ad5696-i2c.c |  65 ++++----
 4 files changed, 241 insertions(+), 286 deletions(-)

diff --git a/drivers/iio/dac/ad5686-spi.c b/drivers/iio/dac/ad5686-spi.c
index 695125238633..73e6c998add0 100644
--- a/drivers/iio/dac/ad5686-spi.c
+++ b/drivers/iio/dac/ad5686-spi.c
@@ -94,29 +94,27 @@ static int ad5686_spi_read(struct ad5686_state *st, u8 addr)
 
 static int ad5686_spi_probe(struct spi_device *spi)
 {
-	const struct spi_device_id *id = spi_get_device_id(spi);
-
-	return ad5686_probe(&spi->dev, id->driver_data, id->name,
-			    ad5686_spi_write, ad5686_spi_read);
+	return ad5686_probe(&spi->dev, spi_get_device_match_data(spi),
+			    spi->modalias, ad5686_spi_write, ad5686_spi_read);
 }
 
 static const struct spi_device_id ad5686_spi_id[] = {
-	{"ad5310r", ID_AD5310R},
-	{"ad5672r", ID_AD5672R},
-	{"ad5674r", ID_AD5674R},
-	{"ad5676", ID_AD5676},
-	{"ad5676r", ID_AD5676R},
-	{"ad5679r", ID_AD5679R},
-	{"ad5681r", ID_AD5681R},
-	{"ad5682r", ID_AD5682R},
-	{"ad5683", ID_AD5683},
-	{"ad5683r", ID_AD5683R},
-	{"ad5684", ID_AD5684},
-	{"ad5684r", ID_AD5684R},
-	{"ad5685", ID_AD5685R}, /* Does not exist */
-	{"ad5685r", ID_AD5685R},
-	{"ad5686", ID_AD5686},
-	{"ad5686r", ID_AD5686R},
+	{ "ad5310r",  (kernel_ulong_t)&ad5310r_chip_info },
+	{ "ad5672r",  (kernel_ulong_t)&ad5672r_chip_info },
+	{ "ad5674r",  (kernel_ulong_t)&ad5674r_chip_info },
+	{ "ad5676",   (kernel_ulong_t)&ad5676_chip_info },
+	{ "ad5676r",  (kernel_ulong_t)&ad5676r_chip_info },
+	{ "ad5679r",  (kernel_ulong_t)&ad5679r_chip_info },
+	{ "ad5681r",  (kernel_ulong_t)&ad5681r_chip_info },
+	{ "ad5682r",  (kernel_ulong_t)&ad5682r_chip_info },
+	{ "ad5683",   (kernel_ulong_t)&ad5683_chip_info },
+	{ "ad5683r",  (kernel_ulong_t)&ad5683r_chip_info },
+	{ "ad5684",   (kernel_ulong_t)&ad5684_chip_info },
+	{ "ad5684r",  (kernel_ulong_t)&ad5684r_chip_info },
+	{ "ad5685",   (kernel_ulong_t)&ad5685r_chip_info }, /* Does not exist */
+	{ "ad5685r",  (kernel_ulong_t)&ad5685r_chip_info },
+	{ "ad5686",   (kernel_ulong_t)&ad5686_chip_info },
+	{ "ad5686r",  (kernel_ulong_t)&ad5686r_chip_info },
 	{ }
 };
 MODULE_DEVICE_TABLE(spi, ad5686_spi_id);
diff --git a/drivers/iio/dac/ad5686.c b/drivers/iio/dac/ad5686.c
index 53d58f0af16e..4015ffdf7ad4 100644
--- a/drivers/iio/dac/ad5686.c
+++ b/drivers/iio/dac/ad5686.c
@@ -213,7 +213,7 @@ static const struct iio_chan_spec_ext_info ad5686_ext_info[] = {
 		.ext_info = ad5686_ext_info,			\
 }
 
-#define DECLARE_AD5693_CHANNELS(name, bits, _shift)		\
+#define DECLARE_AD5683_CHANNELS(name, bits, _shift)		\
 static const struct iio_chan_spec name[] = {			\
 		AD5868_CHANNEL(0, 0, bits, _shift),		\
 }
@@ -264,205 +264,172 @@ static const struct iio_chan_spec name[] = {			\
 		AD5868_CHANNEL(15, 15, bits, _shift),		\
 }
 
-DECLARE_AD5693_CHANNELS(ad5310r_channels, 10, 2);
-DECLARE_AD5693_CHANNELS(ad5311r_channels, 10, 6);
+/* single-channel */
+DECLARE_AD5683_CHANNELS(ad5310r_channels, 10, 2);
+DECLARE_AD5683_CHANNELS(ad5311r_channels, 10, 6);
+DECLARE_AD5683_CHANNELS(ad5681r_channels, 12, 4);
+DECLARE_AD5683_CHANNELS(ad5682r_channels, 14, 2);
+DECLARE_AD5683_CHANNELS(ad5683r_channels, 16, 0);
+
+/* dual-channel */
 DECLARE_AD5338_CHANNELS(ad5337r_channels, 8, 8);
 DECLARE_AD5338_CHANNELS(ad5338r_channels, 10, 6);
-DECLARE_AD5676_CHANNELS(ad5672_channels, 12, 4);
-DECLARE_AD5679_CHANNELS(ad5674r_channels, 12, 4);
-DECLARE_AD5676_CHANNELS(ad5676_channels, 16, 0);
-DECLARE_AD5679_CHANNELS(ad5679r_channels, 16, 0);
-DECLARE_AD5686_CHANNELS(ad5684_channels, 12, 4);
-DECLARE_AD5686_CHANNELS(ad5685r_channels, 14, 2);
-DECLARE_AD5686_CHANNELS(ad5686_channels, 16, 0);
-DECLARE_AD5693_CHANNELS(ad5693_channels, 16, 0);
-DECLARE_AD5693_CHANNELS(ad5692r_channels, 14, 2);
-DECLARE_AD5693_CHANNELS(ad5691r_channels, 12, 4);
 
-static const struct ad5686_chip_info ad5686_chip_info_tbl[] = {
-	[ID_AD5310R] = {
-		.channels = ad5310r_channels,
-		.int_vref_mv = 2500,
-		.num_channels = 1,
-		.regmap_type = AD5310_REGMAP,
-	},
-	[ID_AD5311R] = {
-		.channels = ad5311r_channels,
-		.int_vref_mv = 2500,
-		.num_channels = 1,
-		.regmap_type = AD5683_REGMAP,
-	},
-	[ID_AD5337R] = {
-		.channels = ad5337r_channels,
-		.int_vref_mv = 2500,
-		.num_channels = 2,
-		.regmap_type = AD5686_REGMAP,
-	},
-	[ID_AD5338R] = {
-		.channels = ad5338r_channels,
-		.int_vref_mv = 2500,
-		.num_channels = 2,
-		.regmap_type = AD5686_REGMAP,
-	},
-	[ID_AD5671R] = {
-		.channels = ad5672_channels,
-		.int_vref_mv = 2500,
-		.num_channels = 8,
-		.regmap_type = AD5686_REGMAP,
-	},
-	[ID_AD5672R] = {
-		.channels = ad5672_channels,
-		.int_vref_mv = 2500,
-		.num_channels = 8,
-		.regmap_type = AD5686_REGMAP,
-	},
-	[ID_AD5673R] = {
-		.channels = ad5674r_channels,
-		.int_vref_mv = 2500,
-		.num_channels = 16,
-		.regmap_type = AD5686_REGMAP,
-	},
-	[ID_AD5674R] = {
-		.channels = ad5674r_channels,
-		.int_vref_mv = 2500,
-		.num_channels = 16,
-		.regmap_type = AD5686_REGMAP,
-	},
-	[ID_AD5675R] = {
-		.channels = ad5676_channels,
-		.int_vref_mv = 2500,
-		.num_channels = 8,
-		.regmap_type = AD5686_REGMAP,
-	},
-	[ID_AD5676] = {
-		.channels = ad5676_channels,
-		.num_channels = 8,
-		.regmap_type = AD5686_REGMAP,
-	},
-	[ID_AD5676R] = {
-		.channels = ad5676_channels,
-		.int_vref_mv = 2500,
-		.num_channels = 8,
-		.regmap_type = AD5686_REGMAP,
-	},
-	[ID_AD5677R] = {
-		.channels = ad5679r_channels,
-		.int_vref_mv = 2500,
-		.num_channels = 16,
-		.regmap_type = AD5686_REGMAP,
-	},
-	[ID_AD5679R] = {
-		.channels = ad5679r_channels,
-		.int_vref_mv = 2500,
-		.num_channels = 16,
-		.regmap_type = AD5686_REGMAP,
-	},
-	[ID_AD5681R] = {
-		.channels = ad5691r_channels,
-		.int_vref_mv = 2500,
-		.num_channels = 1,
-		.regmap_type = AD5683_REGMAP,
-	},
-	[ID_AD5682R] = {
-		.channels = ad5692r_channels,
-		.int_vref_mv = 2500,
-		.num_channels = 1,
-		.regmap_type = AD5683_REGMAP,
-	},
-	[ID_AD5683] = {
-		.channels = ad5693_channels,
-		.num_channels = 1,
-		.regmap_type = AD5683_REGMAP,
-	},
-	[ID_AD5683R] = {
-		.channels = ad5693_channels,
-		.int_vref_mv = 2500,
-		.num_channels = 1,
-		.regmap_type = AD5683_REGMAP,
-	},
-	[ID_AD5684] = {
-		.channels = ad5684_channels,
-		.num_channels = 4,
-		.regmap_type = AD5686_REGMAP,
-	},
-	[ID_AD5684R] = {
-		.channels = ad5684_channels,
-		.int_vref_mv = 2500,
-		.num_channels = 4,
-		.regmap_type = AD5686_REGMAP,
-	},
-	[ID_AD5685R] = {
-		.channels = ad5685r_channels,
-		.int_vref_mv = 2500,
-		.num_channels = 4,
-		.regmap_type = AD5686_REGMAP,
-	},
-	[ID_AD5686] = {
-		.channels = ad5686_channels,
-		.num_channels = 4,
-		.regmap_type = AD5686_REGMAP,
-	},
-	[ID_AD5686R] = {
-		.channels = ad5686_channels,
-		.int_vref_mv = 2500,
-		.num_channels = 4,
-		.regmap_type = AD5686_REGMAP,
-	},
-	[ID_AD5691R] = {
-		.channels = ad5691r_channels,
-		.int_vref_mv = 2500,
-		.num_channels = 1,
-		.regmap_type = AD5683_REGMAP,
-	},
-	[ID_AD5692R] = {
-		.channels = ad5692r_channels,
-		.int_vref_mv = 2500,
-		.num_channels = 1,
-		.regmap_type = AD5683_REGMAP,
-	},
-	[ID_AD5693] = {
-		.channels = ad5693_channels,
-		.num_channels = 1,
-		.regmap_type = AD5683_REGMAP,
-	},
-	[ID_AD5693R] = {
-		.channels = ad5693_channels,
-		.int_vref_mv = 2500,
-		.num_channels = 1,
-		.regmap_type = AD5683_REGMAP,
-	},
-	[ID_AD5694] = {
-		.channels = ad5684_channels,
-		.num_channels = 4,
-		.regmap_type = AD5686_REGMAP,
-	},
-	[ID_AD5694R] = {
-		.channels = ad5684_channels,
-		.int_vref_mv = 2500,
-		.num_channels = 4,
-		.regmap_type = AD5686_REGMAP,
-	},
-	[ID_AD5695R] = {
-		.channels = ad5685r_channels,
-		.int_vref_mv = 2500,
-		.num_channels = 4,
-		.regmap_type = AD5686_REGMAP,
-	},
-	[ID_AD5696] = {
-		.channels = ad5686_channels,
-		.num_channels = 4,
-		.regmap_type = AD5686_REGMAP,
-	},
-	[ID_AD5696R] = {
-		.channels = ad5686_channels,
-		.int_vref_mv = 2500,
-		.num_channels = 4,
-		.regmap_type = AD5686_REGMAP,
-	},
+/* quad-channel */
+DECLARE_AD5686_CHANNELS(ad5684r_channels, 12, 4);
+DECLARE_AD5686_CHANNELS(ad5685r_channels, 14, 2);
+DECLARE_AD5686_CHANNELS(ad5686r_channels, 16, 0);
+
+/* 8-channel */
+DECLARE_AD5676_CHANNELS(ad5672r_channels, 12, 4);
+DECLARE_AD5676_CHANNELS(ad5676r_channels, 16, 0);
+
+/* 16-channel */
+DECLARE_AD5679_CHANNELS(ad5674r_channels, 12, 4);
+DECLARE_AD5679_CHANNELS(ad5679r_channels, 16, 0);
+
+const struct ad5686_chip_info ad5310r_chip_info = {
+	.channels = ad5310r_channels,
+	.int_vref_mv = 2500,
+	.num_channels = 1,
+	.regmap_type = AD5310_REGMAP,
 };
+EXPORT_SYMBOL_NS_GPL(ad5310r_chip_info, "IIO_AD5686");
+
+const struct ad5686_chip_info ad5311r_chip_info = {
+	.channels = ad5311r_channels,
+	.int_vref_mv = 2500,
+	.num_channels = 1,
+	.regmap_type = AD5683_REGMAP,
+};
+EXPORT_SYMBOL_NS_GPL(ad5311r_chip_info, "IIO_AD5686");
+
+const struct ad5686_chip_info ad5681r_chip_info = {
+	.channels = ad5681r_channels,
+	.int_vref_mv = 2500,
+	.num_channels = 1,
+	.regmap_type = AD5683_REGMAP,
+};
+EXPORT_SYMBOL_NS_GPL(ad5681r_chip_info, "IIO_AD5686");
+
+const struct ad5686_chip_info ad5682r_chip_info = {
+	.channels = ad5682r_channels,
+	.int_vref_mv = 2500,
+	.num_channels = 1,
+	.regmap_type = AD5683_REGMAP,
+};
+EXPORT_SYMBOL_NS_GPL(ad5682r_chip_info, "IIO_AD5686");
+
+const struct ad5686_chip_info ad5683_chip_info = {
+	.channels = ad5683r_channels,
+	.num_channels = 1,
+	.regmap_type = AD5683_REGMAP,
+};
+EXPORT_SYMBOL_NS_GPL(ad5683_chip_info, "IIO_AD5686");
+
+const struct ad5686_chip_info ad5683r_chip_info = {
+	.channels = ad5683r_channels,
+	.int_vref_mv = 2500,
+	.num_channels = 1,
+	.regmap_type = AD5683_REGMAP,
+};
+EXPORT_SYMBOL_NS_GPL(ad5683r_chip_info, "IIO_AD5686");
+
+const struct ad5686_chip_info ad5337r_chip_info = {
+	.channels = ad5337r_channels,
+	.int_vref_mv = 2500,
+	.num_channels = 2,
+	.regmap_type = AD5686_REGMAP,
+};
+EXPORT_SYMBOL_NS_GPL(ad5337r_chip_info, "IIO_AD5686");
+
+const struct ad5686_chip_info ad5338r_chip_info = {
+	.channels = ad5338r_channels,
+	.int_vref_mv = 2500,
+	.num_channels = 2,
+	.regmap_type = AD5686_REGMAP,
+};
+EXPORT_SYMBOL_NS_GPL(ad5338r_chip_info, "IIO_AD5686");
+
+const struct ad5686_chip_info ad5684_chip_info = {
+	.channels = ad5684r_channels,
+	.num_channels = 4,
+	.regmap_type = AD5686_REGMAP,
+};
+EXPORT_SYMBOL_NS_GPL(ad5684_chip_info, "IIO_AD5686");
+
+const struct ad5686_chip_info ad5684r_chip_info = {
+	.channels = ad5684r_channels,
+	.int_vref_mv = 2500,
+	.num_channels = 4,
+	.regmap_type = AD5686_REGMAP,
+};
+EXPORT_SYMBOL_NS_GPL(ad5684r_chip_info, "IIO_AD5686");
+
+const struct ad5686_chip_info ad5685r_chip_info = {
+	.channels = ad5685r_channels,
+	.int_vref_mv = 2500,
+	.num_channels = 4,
+	.regmap_type = AD5686_REGMAP,
+};
+EXPORT_SYMBOL_NS_GPL(ad5685r_chip_info, "IIO_AD5686");
+
+const struct ad5686_chip_info ad5686_chip_info = {
+	.channels = ad5686r_channels,
+	.num_channels = 4,
+	.regmap_type = AD5686_REGMAP,
+};
+EXPORT_SYMBOL_NS_GPL(ad5686_chip_info, "IIO_AD5686");
+
+const struct ad5686_chip_info ad5686r_chip_info = {
+	.channels = ad5686r_channels,
+	.int_vref_mv = 2500,
+	.num_channels = 4,
+	.regmap_type = AD5686_REGMAP,
+};
+EXPORT_SYMBOL_NS_GPL(ad5686r_chip_info, "IIO_AD5686");
+
+const struct ad5686_chip_info ad5672r_chip_info = {
+	.channels = ad5672r_channels,
+	.int_vref_mv = 2500,
+	.num_channels = 8,
+	.regmap_type = AD5686_REGMAP,
+};
+EXPORT_SYMBOL_NS_GPL(ad5672r_chip_info, "IIO_AD5686");
+
+const struct ad5686_chip_info ad5676_chip_info = {
+	.channels = ad5676r_channels,
+	.num_channels = 8,
+	.regmap_type = AD5686_REGMAP,
+};
+EXPORT_SYMBOL_NS_GPL(ad5676_chip_info, "IIO_AD5686");
+
+const struct ad5686_chip_info ad5676r_chip_info = {
+	.channels = ad5676r_channels,
+	.int_vref_mv = 2500,
+	.num_channels = 8,
+	.regmap_type = AD5686_REGMAP,
+};
+EXPORT_SYMBOL_NS_GPL(ad5676r_chip_info, "IIO_AD5686");
+
+const struct ad5686_chip_info ad5674r_chip_info = {
+	.channels = ad5674r_channels,
+	.int_vref_mv = 2500,
+	.num_channels = 16,
+	.regmap_type = AD5686_REGMAP,
+};
+EXPORT_SYMBOL_NS_GPL(ad5674r_chip_info, "IIO_AD5686");
+
+const struct ad5686_chip_info ad5679r_chip_info = {
+	.channels = ad5679r_channels,
+	.int_vref_mv = 2500,
+	.num_channels = 16,
+	.regmap_type = AD5686_REGMAP,
+};
+EXPORT_SYMBOL_NS_GPL(ad5679r_chip_info, "IIO_AD5686");
 
 int ad5686_probe(struct device *dev,
-		 enum ad5686_supported_device_ids chip_type,
+		 const struct ad5686_chip_info *chip_info,
 		 const char *name, ad5686_write_func write,
 		 ad5686_read_func read)
 {
@@ -482,8 +449,7 @@ int ad5686_probe(struct device *dev,
 	st->dev = dev;
 	st->write = write;
 	st->read = read;
-
-	st->chip_info = &ad5686_chip_info_tbl[chip_type];
+	st->chip_info = chip_info;
 
 	ret = devm_regulator_get_enable_read_voltage(dev, "vcc");
 	if (ret < 0 && ret != -ENODEV)
diff --git a/drivers/iio/dac/ad5686.h b/drivers/iio/dac/ad5686.h
index af15994c01ad..caadc7403da1 100644
--- a/drivers/iio/dac/ad5686.h
+++ b/drivers/iio/dac/ad5686.h
@@ -47,42 +47,6 @@
 #define AD5683_REF_BIT_MSK			BIT(12)
 #define AD5686_REF_BIT_MSK			BIT(0)
 
-/**
- * ad5686_supported_device_ids:
- */
-enum ad5686_supported_device_ids {
-	ID_AD5310R,
-	ID_AD5311R,
-	ID_AD5337R,
-	ID_AD5338R,
-	ID_AD5671R,
-	ID_AD5672R,
-	ID_AD5673R,
-	ID_AD5674R,
-	ID_AD5675R,
-	ID_AD5676,
-	ID_AD5676R,
-	ID_AD5677R,
-	ID_AD5679R,
-	ID_AD5681R,
-	ID_AD5682R,
-	ID_AD5683,
-	ID_AD5683R,
-	ID_AD5684,
-	ID_AD5684R,
-	ID_AD5685R,
-	ID_AD5686,
-	ID_AD5686R,
-	ID_AD5691R,
-	ID_AD5692R,
-	ID_AD5693,
-	ID_AD5693R,
-	ID_AD5694,
-	ID_AD5694R,
-	ID_AD5695R,
-	ID_AD5696,
-	ID_AD5696R,
-};
 
 enum ad5686_regmap_type {
 	AD5310_REGMAP,
@@ -112,6 +76,34 @@ struct ad5686_chip_info {
 	enum ad5686_regmap_type		regmap_type;
 };
 
+/* single-channel instances */
+extern const struct ad5686_chip_info ad5310r_chip_info;
+extern const struct ad5686_chip_info ad5311r_chip_info;
+extern const struct ad5686_chip_info ad5681r_chip_info;
+extern const struct ad5686_chip_info ad5682r_chip_info;
+extern const struct ad5686_chip_info ad5683_chip_info;
+extern const struct ad5686_chip_info ad5683r_chip_info;
+
+/* dual-channel instances */
+extern const struct ad5686_chip_info ad5337r_chip_info;
+extern const struct ad5686_chip_info ad5338r_chip_info;
+
+/* quad-channel instances */
+extern const struct ad5686_chip_info ad5684_chip_info;
+extern const struct ad5686_chip_info ad5684r_chip_info;
+extern const struct ad5686_chip_info ad5685r_chip_info;
+extern const struct ad5686_chip_info ad5686_chip_info;
+extern const struct ad5686_chip_info ad5686r_chip_info;
+
+/* 8-channel instances */
+extern const struct ad5686_chip_info ad5672r_chip_info;
+extern const struct ad5686_chip_info ad5676_chip_info;
+extern const struct ad5686_chip_info ad5676r_chip_info;
+
+/* 16-channel instances */
+extern const struct ad5686_chip_info ad5674r_chip_info;
+extern const struct ad5686_chip_info ad5679r_chip_info;
+
 /**
  * struct ad5686_state - driver instance specific data
  * @spi:		spi_device
@@ -149,7 +141,7 @@ struct ad5686_state {
 
 
 int ad5686_probe(struct device *dev,
-		 enum ad5686_supported_device_ids chip_type,
+		 const struct ad5686_chip_info *chip_info,
 		 const char *name, ad5686_write_func write,
 		 ad5686_read_func read);
 
diff --git a/drivers/iio/dac/ad5696-i2c.c b/drivers/iio/dac/ad5696-i2c.c
index e7e1b8a6fc71..fd047c01f8f6 100644
--- a/drivers/iio/dac/ad5696-i2c.c
+++ b/drivers/iio/dac/ad5696-i2c.c
@@ -64,47 +64,46 @@ static int ad5686_i2c_write(struct ad5686_state *st,
 
 static int ad5686_i2c_probe(struct i2c_client *i2c)
 {
-	const struct i2c_device_id *id = i2c_client_get_device_id(i2c);
-	return ad5686_probe(&i2c->dev, id->driver_data, id->name,
-			    ad5686_i2c_write, ad5686_i2c_read);
+	return ad5686_probe(&i2c->dev, i2c_get_match_data(i2c),
+			    i2c->name, ad5686_i2c_write, ad5686_i2c_read);
 }
 
 static const struct i2c_device_id ad5686_i2c_id[] = {
-	{"ad5311r", ID_AD5311R},
-	{"ad5337r", ID_AD5337R},
-	{"ad5338r", ID_AD5338R},
-	{"ad5671r", ID_AD5671R},
-	{"ad5673r", ID_AD5673R},
-	{"ad5675r", ID_AD5675R},
-	{"ad5677r", ID_AD5677R},
-	{"ad5691r", ID_AD5691R},
-	{"ad5692r", ID_AD5692R},
-	{"ad5693", ID_AD5693},
-	{"ad5693r", ID_AD5693R},
-	{"ad5694", ID_AD5694},
-	{"ad5694r", ID_AD5694R},
-	{"ad5695r", ID_AD5695R},
-	{"ad5696", ID_AD5696},
-	{"ad5696r", ID_AD5696R},
+	{ "ad5311r",  (kernel_ulong_t)&ad5311r_chip_info },
+	{ "ad5337r",  (kernel_ulong_t)&ad5337r_chip_info },
+	{ "ad5338r",  (kernel_ulong_t)&ad5338r_chip_info },
+	{ "ad5671r",  (kernel_ulong_t)&ad5672r_chip_info },
+	{ "ad5673r",  (kernel_ulong_t)&ad5674r_chip_info },
+	{ "ad5675r",  (kernel_ulong_t)&ad5676r_chip_info },
+	{ "ad5677r",  (kernel_ulong_t)&ad5679r_chip_info },
+	{ "ad5691r",  (kernel_ulong_t)&ad5681r_chip_info },
+	{ "ad5692r",  (kernel_ulong_t)&ad5682r_chip_info },
+	{ "ad5693",   (kernel_ulong_t)&ad5683_chip_info },
+	{ "ad5693r",  (kernel_ulong_t)&ad5683r_chip_info },
+	{ "ad5694",   (kernel_ulong_t)&ad5684_chip_info },
+	{ "ad5694r",  (kernel_ulong_t)&ad5684r_chip_info },
+	{ "ad5695r",  (kernel_ulong_t)&ad5685r_chip_info },
+	{ "ad5696",   (kernel_ulong_t)&ad5686_chip_info },
+	{ "ad5696r",  (kernel_ulong_t)&ad5686r_chip_info },
 	{ }
 };
 MODULE_DEVICE_TABLE(i2c, ad5686_i2c_id);
 
 static const struct of_device_id ad5686_of_match[] = {
-	{ .compatible = "adi,ad5311r" },
-	{ .compatible = "adi,ad5337r" },
-	{ .compatible = "adi,ad5338r" },
-	{ .compatible = "adi,ad5671r" },
-	{ .compatible = "adi,ad5675r" },
-	{ .compatible = "adi,ad5691r" },
-	{ .compatible = "adi,ad5692r" },
-	{ .compatible = "adi,ad5693" },
-	{ .compatible = "adi,ad5693r" },
-	{ .compatible = "adi,ad5694" },
-	{ .compatible = "adi,ad5694r" },
-	{ .compatible = "adi,ad5695r" },
-	{ .compatible = "adi,ad5696" },
-	{ .compatible = "adi,ad5696r" },
+	{ .compatible = "adi,ad5311r", .data = &ad5311r_chip_info },
+	{ .compatible = "adi,ad5337r", .data = &ad5337r_chip_info },
+	{ .compatible = "adi,ad5338r", .data = &ad5338r_chip_info },
+	{ .compatible = "adi,ad5671r", .data = &ad5672r_chip_info },
+	{ .compatible = "adi,ad5675r", .data = &ad5676r_chip_info },
+	{ .compatible = "adi,ad5691r", .data = &ad5681r_chip_info },
+	{ .compatible = "adi,ad5692r", .data = &ad5682r_chip_info },
+	{ .compatible = "adi,ad5693",  .data = &ad5683_chip_info },
+	{ .compatible = "adi,ad5693r", .data = &ad5683r_chip_info },
+	{ .compatible = "adi,ad5694",  .data = &ad5684_chip_info },
+	{ .compatible = "adi,ad5694r", .data = &ad5684r_chip_info },
+	{ .compatible = "adi,ad5695r", .data = &ad5685r_chip_info },
+	{ .compatible = "adi,ad5696",  .data = &ad5686_chip_info },
+	{ .compatible = "adi,ad5696r", .data = &ad5686r_chip_info },
 	{ }
 };
 MODULE_DEVICE_TABLE(of, ad5686_of_match);

-- 
2.43.0



^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH v2 08/11] iio: dac: ad5686: add of_match table to the spi driver
  2026-04-27 11:30 [PATCH v2 00/11] Fixes and cleanups for the AD5686 IIO driver Rodrigo Alencar via B4 Relay
                   ` (6 preceding siblings ...)
  2026-04-27 11:30 ` [PATCH v2 07/11] iio: dac: ad5686: drop enum id Rodrigo Alencar via B4 Relay
@ 2026-04-27 11:30 ` Rodrigo Alencar via B4 Relay
  2026-04-27 11:30 ` [PATCH v2 09/11] iio: dac: ad5686: add control_sync() for single-channel devices Rodrigo Alencar via B4 Relay
                   ` (3 subsequent siblings)
  11 siblings, 0 replies; 19+ messages in thread
From: Rodrigo Alencar via B4 Relay @ 2026-04-27 11:30 UTC (permalink / raw)
  To: linux-iio, linux-kernel, Stefan Popa, Jonathan Cameron,
	Greg Kroah-Hartman, Michael Auchter, Jonathan Cameron
  Cc: Lars-Peter Clausen, Michael Hennerich, Jonathan Cameron,
	David Lechner, Andy Shevchenko, Rodrigo Alencar

From: Rodrigo Alencar <rodrigo.alencar@analog.com>

Add of_match table for the SPI device variants to be consistent with the
AD5696 I2C driver.

Signed-off-by: Rodrigo Alencar <rodrigo.alencar@analog.com>
---
 drivers/iio/dac/ad5686-spi.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/drivers/iio/dac/ad5686-spi.c b/drivers/iio/dac/ad5686-spi.c
index 73e6c998add0..8fef0e6d33ff 100644
--- a/drivers/iio/dac/ad5686-spi.c
+++ b/drivers/iio/dac/ad5686-spi.c
@@ -119,9 +119,30 @@ static const struct spi_device_id ad5686_spi_id[] = {
 };
 MODULE_DEVICE_TABLE(spi, ad5686_spi_id);
 
+static const struct of_device_id ad5686_of_match[] = {
+	{ .compatible = "adi,ad5310r", .data = &ad5310r_chip_info },
+	{ .compatible = "adi,ad5672r", .data = &ad5672r_chip_info },
+	{ .compatible = "adi,ad5674r", .data = &ad5674r_chip_info },
+	{ .compatible = "adi,ad5676",  .data = &ad5676_chip_info },
+	{ .compatible = "adi,ad5676r", .data = &ad5676r_chip_info },
+	{ .compatible = "adi,ad5679r", .data = &ad5679r_chip_info },
+	{ .compatible = "adi,ad5681r", .data = &ad5681r_chip_info },
+	{ .compatible = "adi,ad5682r", .data = &ad5682r_chip_info },
+	{ .compatible = "adi,ad5683",  .data = &ad5683_chip_info },
+	{ .compatible = "adi,ad5683r", .data = &ad5683r_chip_info },
+	{ .compatible = "adi,ad5684",  .data = &ad5684_chip_info },
+	{ .compatible = "adi,ad5684r", .data = &ad5684r_chip_info },
+	{ .compatible = "adi,ad5685r", .data = &ad5685r_chip_info },
+	{ .compatible = "adi,ad5686",  .data = &ad5686_chip_info },
+	{ .compatible = "adi,ad5686r", .data = &ad5686r_chip_info },
+	{ }
+};
+MODULE_DEVICE_TABLE(of, ad5686_of_match);
+
 static struct spi_driver ad5686_spi_driver = {
 	.driver = {
 		.name = "ad5686",
+		.of_match_table = ad5686_of_match,
 	},
 	.probe = ad5686_spi_probe,
 	.id_table = ad5686_spi_id,

-- 
2.43.0



^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH v2 09/11] iio: dac: ad5686: add control_sync() for single-channel devices
  2026-04-27 11:30 [PATCH v2 00/11] Fixes and cleanups for the AD5686 IIO driver Rodrigo Alencar via B4 Relay
                   ` (7 preceding siblings ...)
  2026-04-27 11:30 ` [PATCH v2 08/11] iio: dac: ad5686: add of_match table to the spi driver Rodrigo Alencar via B4 Relay
@ 2026-04-27 11:30 ` Rodrigo Alencar via B4 Relay
  2026-04-27 18:09   ` Andy Shevchenko
  2026-04-27 11:30 ` [PATCH v2 10/11] iio: dac: ad5686: cleanup doc header of local structs Rodrigo Alencar via B4 Relay
                   ` (2 subsequent siblings)
  11 siblings, 1 reply; 19+ messages in thread
From: Rodrigo Alencar via B4 Relay @ 2026-04-27 11:30 UTC (permalink / raw)
  To: linux-iio, linux-kernel, Stefan Popa, Jonathan Cameron,
	Greg Kroah-Hartman, Michael Auchter, Jonathan Cameron
  Cc: Lars-Peter Clausen, Michael Hennerich, Jonathan Cameron,
	David Lechner, Andy Shevchenko, Rodrigo Alencar

From: Rodrigo Alencar <rodrigo.alencar@analog.com>

Create ad5310_control_sync() and ad5683_control_sync() functions that
properly consumes the mask definitions with FIELD_PREP(). This allows to
reuse a function that updates the control register with cached values,
without relying on confusing logic that depends on st->use_internal_vref,
which is initialized earlier in ad5686_probe() because it is also
applicable to the AD5686_REGMAP case, removing the need for the
has_external_vref. The change cleans up ad5686_write_dac_powerdown() and
ad5686_probe(), organizing the code for feature extension, e.g. gain
control support for single-channel devices.

Signed-off-by: Rodrigo Alencar <rodrigo.alencar@analog.com>
---
 drivers/iio/dac/ad5686.c | 88 ++++++++++++++++++++++++++++--------------------
 drivers/iio/dac/ad5686.h |  2 ++
 2 files changed, 54 insertions(+), 36 deletions(-)

diff --git a/drivers/iio/dac/ad5686.c b/drivers/iio/dac/ad5686.c
index 4015ffdf7ad4..c5795141f483 100644
--- a/drivers/iio/dac/ad5686.c
+++ b/drivers/iio/dac/ad5686.c
@@ -6,11 +6,13 @@
  */
 
 #include <linux/array_size.h>
+#include <linux/bitfield.h>
 #include <linux/err.h>
 #include <linux/export.h>
 #include <linux/module.h>
 #include <linux/regulator/consumer.h>
 #include <linux/sysfs.h>
+#include <linux/wordpart.h>
 
 #include <linux/iio/iio.h>
 
@@ -22,6 +24,24 @@ static const char * const ad5686_powerdown_modes[] = {
 	"three_state"
 };
 
+static int ad5310_control_sync(struct ad5686_state *st)
+{
+	unsigned int pd_val = st->pwr_down_mask & st->pwr_down_mode;
+
+	return st->write(st, AD5686_CMD_CONTROL_REG, 0,
+			 FIELD_PREP(AD5310_PD_MSK, pd_val) |
+			 FIELD_PREP(AD5310_REF_BIT_MSK, st->use_internal_vref ? 0 : 1));
+}
+
+static int ad5683_control_sync(struct ad5686_state *st)
+{
+	unsigned int pd_val = st->pwr_down_mask & st->pwr_down_mode;
+
+	return st->write(st, AD5686_CMD_CONTROL_REG, 0,
+			 FIELD_PREP(AD5683_PD_MSK, pd_val) |
+			 FIELD_PREP(AD5683_REF_BIT_MSK, st->use_internal_vref ? 0 : 1));
+}
+
 static inline unsigned int ad5686_pd_mask_shift(const struct iio_chan_spec *chan)
 {
 	if (chan->channel == chan->address)
@@ -80,8 +100,8 @@ static ssize_t ad5686_write_dac_powerdown(struct iio_dev *indio_dev,
 	bool readin;
 	int ret;
 	struct ad5686_state *st = iio_priv(indio_dev);
-	unsigned int val, ref_bit_msk;
-	u8 shift, address = 0;
+	unsigned int val;
+	u8 address;
 
 	ret = kstrtobool(buf, &readin);
 	if (ret)
@@ -96,32 +116,34 @@ static ssize_t ad5686_write_dac_powerdown(struct iio_dev *indio_dev,
 
 	switch (st->chip_info->regmap_type) {
 	case AD5310_REGMAP:
-		shift = 9;
-		ref_bit_msk = AD5310_REF_BIT_MSK;
+		ret = ad5310_control_sync(st);
+		if (ret)
+			return ret;
 		break;
 	case AD5683_REGMAP:
-		shift = 13;
-		ref_bit_msk = AD5683_REF_BIT_MSK;
+		ret = ad5683_control_sync(st);
+		if (ret)
+			return ret;
 		break;
 	case AD5686_REGMAP:
-		shift = 0;
-		ref_bit_msk = 0;
 		/* AD5674R/AD5679R have 16 channels and 2 powerdown registers */
-		if (chan->channel > 0x7)
+		val = st->pwr_down_mask & st->pwr_down_mode;
+		if (chan->channel > 0x7) {
 			address = 0x8;
+			val = upper_16_bits(val);
+		} else {
+			address = 0x0;
+			val = lower_16_bits(val);
+		}
+		ret = st->write(st, AD5686_CMD_POWERDOWN_DAC, address, val);
+		if (ret)
+			return ret;
 		break;
 	default:
 		return -EINVAL;
 	}
 
-	val = ((st->pwr_down_mask & st->pwr_down_mode) << shift);
-	if (!st->use_internal_vref)
-		val |= ref_bit_msk;
-
-	ret = st->write(st, AD5686_CMD_POWERDOWN_DAC,
-			address, val >> (address * 2));
-
-	return ret ? ret : len;
+	return len;
 }
 
 static int ad5686_read_raw(struct iio_dev *indio_dev,
@@ -435,9 +457,7 @@ int ad5686_probe(struct device *dev,
 {
 	struct ad5686_state *st;
 	struct iio_dev *indio_dev;
-	unsigned int val, ref_bit_msk, shift;
-	bool has_external_vref;
-	u8 cmd;
+	unsigned int shift;
 	int ret, i;
 
 	indio_dev = devm_iio_device_alloc(dev, sizeof(*st));
@@ -455,8 +475,8 @@ int ad5686_probe(struct device *dev,
 	if (ret < 0 && ret != -ENODEV)
 		return ret;
 
-	has_external_vref = ret != -ENODEV;
-	st->vref_mv = has_external_vref ? ret / 1000 : st->chip_info->int_vref_mv;
+	st->use_internal_vref = ret == -ENODEV;
+	st->vref_mv = st->use_internal_vref ? st->chip_info->int_vref_mv : ret / 1000;
 
 	/* Set all the power down mode for all channels to 1K pulldown */
 	st->pwr_down_mode = ~0U;
@@ -480,29 +500,25 @@ int ad5686_probe(struct device *dev,
 
 	switch (st->chip_info->regmap_type) {
 	case AD5310_REGMAP:
-		cmd = AD5686_CMD_CONTROL_REG;
-		ref_bit_msk = AD5310_REF_BIT_MSK;
-		st->use_internal_vref = !has_external_vref;
+		ret = ad5310_control_sync(st);
+		if (ret)
+			return ret;
 		break;
 	case AD5683_REGMAP:
-		cmd = AD5686_CMD_CONTROL_REG;
-		ref_bit_msk = AD5683_REF_BIT_MSK;
-		st->use_internal_vref = !has_external_vref;
+		ret = ad5683_control_sync(st);
+		if (ret)
+			return ret;
 		break;
 	case AD5686_REGMAP:
-		cmd = AD5686_CMD_INTERNAL_REFER_SETUP;
-		ref_bit_msk = AD5686_REF_BIT_MSK;
+		ret = st->write(st, AD5686_CMD_INTERNAL_REFER_SETUP, 0,
+				st->use_internal_vref ? 0 : AD5686_REF_BIT_MSK);
+		if (ret)
+			return ret;
 		break;
 	default:
 		return -EINVAL;
 	}
 
-	val = (has_external_vref) ? ref_bit_msk : 0;
-
-	ret = st->write(st, cmd, 0, val);
-	if (ret)
-		return ret;
-
 	return devm_iio_device_register(dev, indio_dev);
 }
 EXPORT_SYMBOL_NS_GPL(ad5686_probe, "IIO_AD5686");
diff --git a/drivers/iio/dac/ad5686.h b/drivers/iio/dac/ad5686.h
index caadc7403da1..2f5c1f2c67bf 100644
--- a/drivers/iio/dac/ad5686.h
+++ b/drivers/iio/dac/ad5686.h
@@ -44,7 +44,9 @@
 #define AD5686_CMD_READBACK_ENABLE_V2		0x5
 
 #define AD5310_REF_BIT_MSK			BIT(8)
+#define AD5310_PD_MSK				GENMASK(10, 9)
 #define AD5683_REF_BIT_MSK			BIT(12)
+#define AD5683_PD_MSK				GENMASK(14, 13)
 #define AD5686_REF_BIT_MSK			BIT(0)
 
 

-- 
2.43.0



^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH v2 10/11] iio: dac: ad5686: cleanup doc header of local structs
  2026-04-27 11:30 [PATCH v2 00/11] Fixes and cleanups for the AD5686 IIO driver Rodrigo Alencar via B4 Relay
                   ` (8 preceding siblings ...)
  2026-04-27 11:30 ` [PATCH v2 09/11] iio: dac: ad5686: add control_sync() for single-channel devices Rodrigo Alencar via B4 Relay
@ 2026-04-27 11:30 ` Rodrigo Alencar via B4 Relay
  2026-04-27 11:30 ` [PATCH v2 11/11] iio: dac: ad5686: create bus ops struct Rodrigo Alencar via B4 Relay
  2026-04-27 18:12 ` [PATCH v2 00/11] Fixes and cleanups for the AD5686 IIO driver Andy Shevchenko
  11 siblings, 0 replies; 19+ messages in thread
From: Rodrigo Alencar via B4 Relay @ 2026-04-27 11:30 UTC (permalink / raw)
  To: linux-iio, linux-kernel, Stefan Popa, Jonathan Cameron,
	Greg Kroah-Hartman, Michael Auchter, Jonathan Cameron
  Cc: Lars-Peter Clausen, Michael Hennerich, Jonathan Cameron,
	David Lechner, Andy Shevchenko, Rodrigo Alencar

From: Rodrigo Alencar <rodrigo.alencar@analog.com>

Review documentation comment header for ad5686_chip_info and ad5686_state.
Update variable names and description and remove unnecessary blank line
between comment and struct declaration.

Signed-off-by: Rodrigo Alencar <rodrigo.alencar@analog.com>
---
 drivers/iio/dac/ad5686.h | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/drivers/iio/dac/ad5686.h b/drivers/iio/dac/ad5686.h
index 2f5c1f2c67bf..135935265c10 100644
--- a/drivers/iio/dac/ad5686.h
+++ b/drivers/iio/dac/ad5686.h
@@ -65,12 +65,11 @@ typedef int (*ad5686_read_func)(struct ad5686_state *st, u8 addr);
 
 /**
  * struct ad5686_chip_info - chip specific information
- * @int_vref_mv:	AD5620/40/60: the internal reference voltage
+ * @int_vref_mv:	the internal reference voltage
  * @num_channels:	number of channels
  * @channel:		channel specification
  * @regmap_type:	register map layout variant
  */
-
 struct ad5686_chip_info {
 	u16				int_vref_mv;
 	unsigned int			num_channels;
@@ -108,16 +107,16 @@ extern const struct ad5686_chip_info ad5679r_chip_info;
 
 /**
  * struct ad5686_state - driver instance specific data
- * @spi:		spi_device
+ * @dev:		device instance
  * @chip_info:		chip model specific constants, available modes etc
  * @vref_mv:		actual reference voltage used
  * @pwr_down_mask:	power down mask
  * @pwr_down_mode:	current power down mode
  * @use_internal_vref:	set to true if the internal reference voltage is used
- * @lock		lock to protect the data buffer during regmap ops
- * @data:		spi transfer buffers
+ * @lock:		lock to protect access to state fields, which includes
+ *			the data buffer during regmap ops
+ * @data:		transfer buffers
  */
-
 struct ad5686_state {
 	struct device			*dev;
 	const struct ad5686_chip_info	*chip_info;

-- 
2.43.0



^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH v2 11/11] iio: dac: ad5686: create bus ops struct
  2026-04-27 11:30 [PATCH v2 00/11] Fixes and cleanups for the AD5686 IIO driver Rodrigo Alencar via B4 Relay
                   ` (9 preceding siblings ...)
  2026-04-27 11:30 ` [PATCH v2 10/11] iio: dac: ad5686: cleanup doc header of local structs Rodrigo Alencar via B4 Relay
@ 2026-04-27 11:30 ` Rodrigo Alencar via B4 Relay
  2026-04-27 18:12 ` [PATCH v2 00/11] Fixes and cleanups for the AD5686 IIO driver Andy Shevchenko
  11 siblings, 0 replies; 19+ messages in thread
From: Rodrigo Alencar via B4 Relay @ 2026-04-27 11:30 UTC (permalink / raw)
  To: linux-iio, linux-kernel, Stefan Popa, Jonathan Cameron,
	Greg Kroah-Hartman, Michael Auchter, Jonathan Cameron
  Cc: Lars-Peter Clausen, Michael Hennerich, Jonathan Cameron,
	David Lechner, Andy Shevchenko, Rodrigo Alencar

From: Rodrigo Alencar <rodrigo.alencar@analog.com>

Create struct with bus operations, which will be used to extend bus
implementation features. Auxiliary functions ad5686_write() and
ad5686_read() are created and ad5686_probe() now receives an ops struct
pointer rather than individual read and write functions.

Signed-off-by: Rodrigo Alencar <rodrigo.alencar@analog.com>
---
 drivers/iio/dac/ad5686-spi.c |  7 ++++++-
 drivers/iio/dac/ad5686.c     | 32 ++++++++++++++------------------
 drivers/iio/dac/ad5686.h     | 29 +++++++++++++++++++++--------
 drivers/iio/dac/ad5696-i2c.c |  7 ++++++-
 4 files changed, 47 insertions(+), 28 deletions(-)

diff --git a/drivers/iio/dac/ad5686-spi.c b/drivers/iio/dac/ad5686-spi.c
index 8fef0e6d33ff..857b9e4f54ab 100644
--- a/drivers/iio/dac/ad5686-spi.c
+++ b/drivers/iio/dac/ad5686-spi.c
@@ -92,10 +92,15 @@ static int ad5686_spi_read(struct ad5686_state *st, u8 addr)
 	return be32_to_cpu(st->data[2].d32);
 }
 
+static const struct ad5686_bus_ops ad5686_spi_ops = {
+	.write = ad5686_spi_write,
+	.read = ad5686_spi_read,
+};
+
 static int ad5686_spi_probe(struct spi_device *spi)
 {
 	return ad5686_probe(&spi->dev, spi_get_device_match_data(spi),
-			    spi->modalias, ad5686_spi_write, ad5686_spi_read);
+			    spi->modalias, &ad5686_spi_ops);
 }
 
 static const struct spi_device_id ad5686_spi_id[] = {
diff --git a/drivers/iio/dac/ad5686.c b/drivers/iio/dac/ad5686.c
index c5795141f483..05b0857364bb 100644
--- a/drivers/iio/dac/ad5686.c
+++ b/drivers/iio/dac/ad5686.c
@@ -28,18 +28,18 @@ static int ad5310_control_sync(struct ad5686_state *st)
 {
 	unsigned int pd_val = st->pwr_down_mask & st->pwr_down_mode;
 
-	return st->write(st, AD5686_CMD_CONTROL_REG, 0,
-			 FIELD_PREP(AD5310_PD_MSK, pd_val) |
-			 FIELD_PREP(AD5310_REF_BIT_MSK, st->use_internal_vref ? 0 : 1));
+	return ad5686_write(st, AD5686_CMD_CONTROL_REG, 0,
+			    FIELD_PREP(AD5310_PD_MSK, pd_val) |
+			    FIELD_PREP(AD5310_REF_BIT_MSK, st->use_internal_vref ? 0 : 1));
 }
 
 static int ad5683_control_sync(struct ad5686_state *st)
 {
 	unsigned int pd_val = st->pwr_down_mask & st->pwr_down_mode;
 
-	return st->write(st, AD5686_CMD_CONTROL_REG, 0,
-			 FIELD_PREP(AD5683_PD_MSK, pd_val) |
-			 FIELD_PREP(AD5683_REF_BIT_MSK, st->use_internal_vref ? 0 : 1));
+	return ad5686_write(st, AD5686_CMD_CONTROL_REG, 0,
+			    FIELD_PREP(AD5683_PD_MSK, pd_val) |
+			    FIELD_PREP(AD5683_REF_BIT_MSK, st->use_internal_vref ? 0 : 1));
 }
 
 static inline unsigned int ad5686_pd_mask_shift(const struct iio_chan_spec *chan)
@@ -135,7 +135,7 @@ static ssize_t ad5686_write_dac_powerdown(struct iio_dev *indio_dev,
 			address = 0x0;
 			val = lower_16_bits(val);
 		}
-		ret = st->write(st, AD5686_CMD_POWERDOWN_DAC, address, val);
+		ret = ad5686_write(st, AD5686_CMD_POWERDOWN_DAC, address, val);
 		if (ret)
 			return ret;
 		break;
@@ -158,7 +158,7 @@ static int ad5686_read_raw(struct iio_dev *indio_dev,
 	switch (m) {
 	case IIO_CHAN_INFO_RAW:
 		mutex_lock(&st->lock);
-		ret = st->read(st, chan->address);
+		ret = ad5686_read(st, chan->address);
 		mutex_unlock(&st->lock);
 		if (ret < 0)
 			return ret;
@@ -188,10 +188,8 @@ static int ad5686_write_raw(struct iio_dev *indio_dev,
 			return -EINVAL;
 
 		mutex_lock(&st->lock);
-		ret = st->write(st,
-				AD5686_CMD_WRITE_INPUT_N_UPDATE_N,
-				chan->address,
-				val << chan->scan_type.shift);
+		ret = ad5686_write(st, AD5686_CMD_WRITE_INPUT_N_UPDATE_N,
+				   chan->address, val << chan->scan_type.shift);
 		mutex_unlock(&st->lock);
 		break;
 	default:
@@ -452,8 +450,7 @@ EXPORT_SYMBOL_NS_GPL(ad5679r_chip_info, "IIO_AD5686");
 
 int ad5686_probe(struct device *dev,
 		 const struct ad5686_chip_info *chip_info,
-		 const char *name, ad5686_write_func write,
-		 ad5686_read_func read)
+		 const char *name, const struct ad5686_bus_ops *ops)
 {
 	struct ad5686_state *st;
 	struct iio_dev *indio_dev;
@@ -467,8 +464,7 @@ int ad5686_probe(struct device *dev,
 	st = iio_priv(indio_dev);
 
 	st->dev = dev;
-	st->write = write;
-	st->read = read;
+	st->ops = ops;
 	st->chip_info = chip_info;
 
 	ret = devm_regulator_get_enable_read_voltage(dev, "vcc");
@@ -510,8 +506,8 @@ int ad5686_probe(struct device *dev,
 			return ret;
 		break;
 	case AD5686_REGMAP:
-		ret = st->write(st, AD5686_CMD_INTERNAL_REFER_SETUP, 0,
-				st->use_internal_vref ? 0 : AD5686_REF_BIT_MSK);
+		ret = ad5686_write(st, AD5686_CMD_INTERNAL_REFER_SETUP, 0,
+				   st->use_internal_vref ? 0 : AD5686_REF_BIT_MSK);
 		if (ret)
 			return ret;
 		break;
diff --git a/drivers/iio/dac/ad5686.h b/drivers/iio/dac/ad5686.h
index 135935265c10..a9d9472425a7 100644
--- a/drivers/iio/dac/ad5686.h
+++ b/drivers/iio/dac/ad5686.h
@@ -58,10 +58,15 @@ enum ad5686_regmap_type {
 
 struct ad5686_state;
 
-typedef int (*ad5686_write_func)(struct ad5686_state *st,
-				 u8 cmd, u8 addr, u16 val);
-
-typedef int (*ad5686_read_func)(struct ad5686_state *st, u8 addr);
+/**
+ * struct ad5686_bus_ops - bus specific read/write operations
+ * @read: read a register value at the given address
+ * @write: write a command, address and value to the device
+ */
+struct ad5686_bus_ops {
+	int (*read)(struct ad5686_state *st, u8 addr);
+	int (*write)(struct ad5686_state *st, u8 cmd, u8 addr, u16 val);
+};
 
 /**
  * struct ad5686_chip_info - chip specific information
@@ -109,6 +114,7 @@ extern const struct ad5686_chip_info ad5679r_chip_info;
  * struct ad5686_state - driver instance specific data
  * @dev:		device instance
  * @chip_info:		chip model specific constants, available modes etc
+ * @ops:		bus specific operations
  * @vref_mv:		actual reference voltage used
  * @pwr_down_mask:	power down mask
  * @pwr_down_mode:	current power down mode
@@ -120,11 +126,10 @@ extern const struct ad5686_chip_info ad5679r_chip_info;
 struct ad5686_state {
 	struct device			*dev;
 	const struct ad5686_chip_info	*chip_info;
+	const struct ad5686_bus_ops	*ops;
 	unsigned short			vref_mv;
 	unsigned int			pwr_down_mask;
 	unsigned int			pwr_down_mode;
-	ad5686_write_func		write;
-	ad5686_read_func		read;
 	bool				use_internal_vref;
 	struct mutex			lock;
 
@@ -143,8 +148,16 @@ struct ad5686_state {
 
 int ad5686_probe(struct device *dev,
 		 const struct ad5686_chip_info *chip_info,
-		 const char *name, ad5686_write_func write,
-		 ad5686_read_func read);
+		 const char *name, const struct ad5686_bus_ops *ops);
 
+static inline int ad5686_write(struct ad5686_state *st, u8 cmd, u8 addr, u16 val)
+{
+	return st->ops->write(st, cmd, addr, val);
+}
+
+static inline int ad5686_read(struct ad5686_state *st, u8 addr)
+{
+	return st->ops->read(st, addr);
+}
 
 #endif /* __DRIVERS_IIO_DAC_AD5686_H__ */
diff --git a/drivers/iio/dac/ad5696-i2c.c b/drivers/iio/dac/ad5696-i2c.c
index fd047c01f8f6..30c48d937a38 100644
--- a/drivers/iio/dac/ad5696-i2c.c
+++ b/drivers/iio/dac/ad5696-i2c.c
@@ -62,10 +62,15 @@ static int ad5686_i2c_write(struct ad5686_state *st,
 	return (ret != 3) ? -EIO : 0;
 }
 
+static const struct ad5686_bus_ops ad5686_i2c_ops = {
+	.write = ad5686_i2c_write,
+	.read = ad5686_i2c_read,
+};
+
 static int ad5686_i2c_probe(struct i2c_client *i2c)
 {
 	return ad5686_probe(&i2c->dev, i2c_get_match_data(i2c),
-			    i2c->name, ad5686_i2c_write, ad5686_i2c_read);
+			    i2c->name, &ad5686_i2c_ops);
 }
 
 static const struct i2c_device_id ad5686_i2c_id[] = {

-- 
2.43.0



^ permalink raw reply related	[flat|nested] 19+ messages in thread

* Re: [PATCH v2 01/11] iio: dac: ad5686: fix ref bit initialization for single-channel parts
  2026-04-27 11:30 ` [PATCH v2 01/11] iio: dac: ad5686: fix ref bit initialization for single-channel parts Rodrigo Alencar via B4 Relay
@ 2026-04-27 17:53   ` Andy Shevchenko
  0 siblings, 0 replies; 19+ messages in thread
From: Andy Shevchenko @ 2026-04-27 17:53 UTC (permalink / raw)
  To: rodrigo.alencar
  Cc: linux-iio, linux-kernel, Stefan Popa, Jonathan Cameron,
	Greg Kroah-Hartman, Michael Auchter, Jonathan Cameron,
	Lars-Peter Clausen, Michael Hennerich, David Lechner,
	Andy Shevchenko

On Mon, Apr 27, 2026 at 12:30:08PM +0100, Rodrigo Alencar via B4 Relay wrote:

> The reference bit position was ignored when writing the register at the
> probe() function (!!val was used). When such bit is 1, internal voltage
> reference is disabled so that an external one can be used. For
> multi-channel devices, bit 0 of the Internal Reference Setup command
> behaves the same way, so AD5686_REF_BIT_MSK is created. The issue exists
> since support for single-channel devices were first introduced.

...

> -	val = (has_external_vref | ref_bit_msk);
> +	val = (has_external_vref) ? ref_bit_msk : 0;

Too many parentheses. If the former had something in mind, the latter really
doesn't need them.

...

Otherwise LGTM!

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH v2 03/11] iio: dac: ad5686: acquire lock when doing powerdown control
  2026-04-27 11:30 ` [PATCH v2 03/11] iio: dac: ad5686: acquire lock when doing powerdown control Rodrigo Alencar via B4 Relay
@ 2026-04-27 17:56   ` Andy Shevchenko
  0 siblings, 0 replies; 19+ messages in thread
From: Andy Shevchenko @ 2026-04-27 17:56 UTC (permalink / raw)
  To: rodrigo.alencar
  Cc: linux-iio, linux-kernel, Stefan Popa, Jonathan Cameron,
	Greg Kroah-Hartman, Michael Auchter, Jonathan Cameron,
	Lars-Peter Clausen, Michael Hennerich, David Lechner,
	Andy Shevchenko

On Mon, Apr 27, 2026 at 12:30:10PM +0100, Rodrigo Alencar via B4 Relay wrote:

> Protect write access of pwr_down_mode and pwr_down_mask fields with
> existing mutex lock. Each channel exposes their own attributes for
> controlling powerdown modes and powerdown state. This fixes potential race
> conditions as those functions perform non-atomic read-modify-write
> operations to those pwr_down_* fields. This issue exists since the ad5686
> driver was first introduced.

General rule, besides trying to occupy as much room as we have to still use
consistent (more or less equal) line lengths. I would rewrap

  Protect write access of pwr_down_mode and pwr_down_mask fields with
  existing mutex lock. Each channel exposes their own attributes for
  controlling powerdown modes and powerdown state. This fixes potential
  race conditions as those functions perform non-atomic read-modify-write
  operations to those pwr_down_* fields. This issue exists since the
  ad5686 driver was first introduced.

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH v2 04/11] iio: dac: ad5686: fix powerdown control on dual-channel devices
  2026-04-27 11:30 ` [PATCH v2 04/11] iio: dac: ad5686: fix powerdown control on dual-channel devices Rodrigo Alencar via B4 Relay
@ 2026-04-27 18:02   ` Andy Shevchenko
  2026-04-28 12:36     ` Rodrigo Alencar
  0 siblings, 1 reply; 19+ messages in thread
From: Andy Shevchenko @ 2026-04-27 18:02 UTC (permalink / raw)
  To: rodrigo.alencar
  Cc: linux-iio, linux-kernel, Stefan Popa, Jonathan Cameron,
	Greg Kroah-Hartman, Michael Auchter, Jonathan Cameron,
	Lars-Peter Clausen, Michael Hennerich, David Lechner,
	Andy Shevchenko

On Mon, Apr 27, 2026 at 12:30:11PM +0100, Rodrigo Alencar via B4 Relay wrote:

> Fix powerdown control by using a proper bit shift for the powerdown mask
> values. During initialization, powerdown bits are initialized so that
> unused bits are set to 1 and the correct bit shift is used. Dual-channel
> devices use one-hot encoding in the address and that reflects on the
> position of the powerdown bits, which are not channel-index based
> for that case. Quad-channel devices also use one-hot encoding for the
> channel address but the result of log2(address) coincides with the channel
> index value. The issue was introduced when first adding support for
> dual-channel devices, which overlooked powerdown control differences.

...

> +static inline unsigned int ad5686_pd_mask_shift(const struct iio_chan_spec *chan)
> +{
> +	if (chan->channel == chan->address)
> +		return chan->channel * 2;
> +
> +	/* one-hot encoding is used in dual/quad channel devices */
> +	return __ffs(chan->address) * 2;

If channel->address guaranteed never be 0? This is UB otherwise.

> +}

...

> +	st->pwr_down_mode &= ~(0x3 << shift);
> +	st->pwr_down_mode |= ((mode + 1) << shift);

Now too many parentheses. Also do you guarantee that mode won't ever saturate
the bits outside of the given mask?

...

> +	return sysfs_emit(buf, "%d\n", !!(st->pwr_down_mask & (0x3 << shift)));

At some point (I understand that this is a fix and probably we want to be less
intrusive) I think we want to see that 0x3 magic being defined and reused. This
GENMASK(1, 0) << shift seems an idiom that may deserve it's own macro / helper
function.

...

> +	st->pwr_down_mode = ~0U;
> +	st->pwr_down_mask = ~0U;
> +	for (i = 0; i < st->chip_info->num_channels; i++) {
> +		shift = ad5686_pd_mask_shift(&st->chip_info->channels[i]);
> +		st->pwr_down_mask &= ~(0x3 << shift); /* powered up state */
> +		st->pwr_down_mode &= ~(0x3 << shift);

> +		st->pwr_down_mode |= (0x01 << shift);

Too many parentheses.

> +	}

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH v2 09/11] iio: dac: ad5686: add control_sync() for single-channel devices
  2026-04-27 11:30 ` [PATCH v2 09/11] iio: dac: ad5686: add control_sync() for single-channel devices Rodrigo Alencar via B4 Relay
@ 2026-04-27 18:09   ` Andy Shevchenko
  0 siblings, 0 replies; 19+ messages in thread
From: Andy Shevchenko @ 2026-04-27 18:09 UTC (permalink / raw)
  To: rodrigo.alencar
  Cc: linux-iio, linux-kernel, Stefan Popa, Jonathan Cameron,
	Greg Kroah-Hartman, Michael Auchter, Jonathan Cameron,
	Lars-Peter Clausen, Michael Hennerich, David Lechner,
	Andy Shevchenko

On Mon, Apr 27, 2026 at 12:30:16PM +0100, Rodrigo Alencar via B4 Relay wrote:

> Create ad5310_control_sync() and ad5683_control_sync() functions that
> properly consumes the mask definitions with FIELD_PREP(). This allows to
> reuse a function that updates the control register with cached values,
> without relying on confusing logic that depends on st->use_internal_vref,
> which is initialized earlier in ad5686_probe() because it is also
> applicable to the AD5686_REGMAP case, removing the need for the
> has_external_vref. The change cleans up ad5686_write_dac_powerdown() and
> ad5686_probe(), organizing the code for feature extension, e.g. gain
> control support for single-channel devices.

...

>  #define AD5310_REF_BIT_MSK			BIT(8)
> +#define AD5310_PD_MSK				GENMASK(10, 9)
>  #define AD5683_REF_BIT_MSK			BIT(12)
> +#define AD5683_PD_MSK				GENMASK(14, 13)
>  #define AD5686_REF_BIT_MSK			BIT(0)

Since now it's a set of groups of the masks, I would add blank lines to make it
clearer (from the first glance I failed to see that, then I have noticed that
there are the same names, but prefixes, made me harder to understand).

#define AD5310_REF_BIT_MSK			BIT(8)
#define AD5310_PD_MSK				GENMASK(10, 9)

#define AD5683_REF_BIT_MSK			BIT(12)
#define AD5683_PD_MSK				GENMASK(14, 13)

#define AD5686_REF_BIT_MSK			BIT(0)

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH v2 00/11] Fixes and cleanups for the AD5686 IIO driver
  2026-04-27 11:30 [PATCH v2 00/11] Fixes and cleanups for the AD5686 IIO driver Rodrigo Alencar via B4 Relay
                   ` (10 preceding siblings ...)
  2026-04-27 11:30 ` [PATCH v2 11/11] iio: dac: ad5686: create bus ops struct Rodrigo Alencar via B4 Relay
@ 2026-04-27 18:12 ` Andy Shevchenko
  2026-04-28 16:56   ` Jonathan Cameron
  11 siblings, 1 reply; 19+ messages in thread
From: Andy Shevchenko @ 2026-04-27 18:12 UTC (permalink / raw)
  To: rodrigo.alencar
  Cc: linux-iio, linux-kernel, Stefan Popa, Jonathan Cameron,
	Greg Kroah-Hartman, Michael Auchter, Jonathan Cameron,
	Lars-Peter Clausen, Michael Hennerich, David Lechner,
	Andy Shevchenko

On Mon, Apr 27, 2026 at 12:30:07PM +0100, Rodrigo Alencar via B4 Relay wrote:
> This is the first series of three on updating the AD5686 driver.
> 
> A bigger patch series was sent before ("Extend device support for AD5686 driver"),
> but this is not exactly a v2:
> 
> https://lore.kernel.org/r/20260422-ad5313r-iio-support-v1-0-ed7dca001d1b@analog.com
> 
> This one adds a number of cleanups and fixes, like:
> - Refactor include headers (IWYU);
> - Remove redundant register definition;
> - Drop enum chip id in favor of per-device chip_info structs;
> - Fix internal voltage reference control for single-channel devices;
> - Acquire lock when doing power down control;
> - Fix powerdown control for dual-channel devices;

I have only a few nit-picks, in general LGTM, thanks!


-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH v2 04/11] iio: dac: ad5686: fix powerdown control on dual-channel devices
  2026-04-27 18:02   ` Andy Shevchenko
@ 2026-04-28 12:36     ` Rodrigo Alencar
  0 siblings, 0 replies; 19+ messages in thread
From: Rodrigo Alencar @ 2026-04-28 12:36 UTC (permalink / raw)
  To: Andy Shevchenko, rodrigo.alencar
  Cc: linux-iio, linux-kernel, Stefan Popa, Jonathan Cameron,
	Greg Kroah-Hartman, Michael Auchter, Jonathan Cameron,
	Lars-Peter Clausen, Michael Hennerich, David Lechner,
	Andy Shevchenko

On 26/04/27 09:02PM, Andy Shevchenko wrote:
> On Mon, Apr 27, 2026 at 12:30:11PM +0100, Rodrigo Alencar via B4 Relay wrote:
> 
> > Fix powerdown control by using a proper bit shift for the powerdown mask
> > values. During initialization, powerdown bits are initialized so that
> > unused bits are set to 1 and the correct bit shift is used. Dual-channel
> > devices use one-hot encoding in the address and that reflects on the
> > position of the powerdown bits, which are not channel-index based
> > for that case. Quad-channel devices also use one-hot encoding for the
> > channel address but the result of log2(address) coincides with the channel
> > index value. The issue was introduced when first adding support for
> > dual-channel devices, which overlooked powerdown control differences.
> 
> ...
> 
> > +static inline unsigned int ad5686_pd_mask_shift(const struct iio_chan_spec *chan)
> > +{
> > +	if (chan->channel == chan->address)
> > +		return chan->channel * 2;
> > +
> > +	/* one-hot encoding is used in dual/quad channel devices */
> > +	return __ffs(chan->address) * 2;
> 
> If channel->address guaranteed never be 0? This is UB otherwise.

All the possible values are managed within this driver, so this would not be 0,
if so, it would fall into the if statement above.
 
> > +}
> 
> ...
> 
> > +	st->pwr_down_mode &= ~(0x3 << shift);
> > +	st->pwr_down_mode |= ((mode + 1) << shift);
> 
> Now too many parentheses. Also do you guarantee that mode won't ever saturate
> the bits outside of the given mask?

ad5686_powerdown_modes enum has num_items = 3, so max value for mode is 2.

...

-- 
Kind regards,

Rodrigo Alencar

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH v2 00/11] Fixes and cleanups for the AD5686 IIO driver
  2026-04-27 18:12 ` [PATCH v2 00/11] Fixes and cleanups for the AD5686 IIO driver Andy Shevchenko
@ 2026-04-28 16:56   ` Jonathan Cameron
  0 siblings, 0 replies; 19+ messages in thread
From: Jonathan Cameron @ 2026-04-28 16:56 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: rodrigo.alencar, linux-iio, linux-kernel, Stefan Popa,
	Jonathan Cameron, Greg Kroah-Hartman, Michael Auchter,
	Lars-Peter Clausen, Michael Hennerich, David Lechner,
	Andy Shevchenko

On Mon, 27 Apr 2026 21:12:07 +0300
Andy Shevchenko <andriy.shevchenko@intel.com> wrote:

> On Mon, Apr 27, 2026 at 12:30:07PM +0100, Rodrigo Alencar via B4 Relay wrote:
> > This is the first series of three on updating the AD5686 driver.
> > 
> > A bigger patch series was sent before ("Extend device support for AD5686 driver"),
> > but this is not exactly a v2:
> > 
> > https://lore.kernel.org/r/20260422-ad5313r-iio-support-v1-0-ed7dca001d1b@analog.com
> > 
> > This one adds a number of cleanups and fixes, like:
> > - Refactor include headers (IWYU);
> > - Remove redundant register definition;
> > - Drop enum chip id in favor of per-device chip_info structs;
> > - Fix internal voltage reference control for single-channel devices;
> > - Acquire lock when doing power down control;
> > - Fix powerdown control for dual-channel devices;  
> 
> I have only a few nit-picks, in general LGTM, thanks!
> 
> 

I had nothing to add :)
Indeed looks good.  Just enough in what Andy raised that, given
we are early in the cycle I'd like a v3 rather than tweaking stuff
as I apply,

No need to hold off for usual week I think given nature of
comments (if you have time to respin earlier obviously!)

Thanks,

Jonathan


^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2026-04-28 16:57 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-27 11:30 [PATCH v2 00/11] Fixes and cleanups for the AD5686 IIO driver Rodrigo Alencar via B4 Relay
2026-04-27 11:30 ` [PATCH v2 01/11] iio: dac: ad5686: fix ref bit initialization for single-channel parts Rodrigo Alencar via B4 Relay
2026-04-27 17:53   ` Andy Shevchenko
2026-04-27 11:30 ` [PATCH v2 02/11] iio: dac: ad5686: fix input raw value check Rodrigo Alencar via B4 Relay
2026-04-27 11:30 ` [PATCH v2 03/11] iio: dac: ad5686: acquire lock when doing powerdown control Rodrigo Alencar via B4 Relay
2026-04-27 17:56   ` Andy Shevchenko
2026-04-27 11:30 ` [PATCH v2 04/11] iio: dac: ad5686: fix powerdown control on dual-channel devices Rodrigo Alencar via B4 Relay
2026-04-27 18:02   ` Andy Shevchenko
2026-04-28 12:36     ` Rodrigo Alencar
2026-04-27 11:30 ` [PATCH v2 05/11] iio: dac: ad5686: refactor include headers Rodrigo Alencar via B4 Relay
2026-04-27 11:30 ` [PATCH v2 06/11] iio: dac: ad5686: remove redundant register definition Rodrigo Alencar via B4 Relay
2026-04-27 11:30 ` [PATCH v2 07/11] iio: dac: ad5686: drop enum id Rodrigo Alencar via B4 Relay
2026-04-27 11:30 ` [PATCH v2 08/11] iio: dac: ad5686: add of_match table to the spi driver Rodrigo Alencar via B4 Relay
2026-04-27 11:30 ` [PATCH v2 09/11] iio: dac: ad5686: add control_sync() for single-channel devices Rodrigo Alencar via B4 Relay
2026-04-27 18:09   ` Andy Shevchenko
2026-04-27 11:30 ` [PATCH v2 10/11] iio: dac: ad5686: cleanup doc header of local structs Rodrigo Alencar via B4 Relay
2026-04-27 11:30 ` [PATCH v2 11/11] iio: dac: ad5686: create bus ops struct Rodrigo Alencar via B4 Relay
2026-04-27 18:12 ` [PATCH v2 00/11] Fixes and cleanups for the AD5686 IIO driver Andy Shevchenko
2026-04-28 16:56   ` Jonathan Cameron

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox