mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/7] iio: amplifiers: ad8366: driver update and dt support
@ 2026-01-19 14:36 Rodrigo Alencar via B4 Relay
  2026-01-19 14:36 ` [PATCH 1/7] MAINTAINERS: Add missing maintainer entry for AD8366 driver Rodrigo Alencar via B4 Relay
                   ` (6 more replies)
  0 siblings, 7 replies; 17+ messages in thread
From: Rodrigo Alencar via B4 Relay @ 2026-01-19 14:36 UTC (permalink / raw)
  To: linux-kernel, linux-iio, devicetree
  Cc: Michael Hennerich, Lars-Peter Clausen, Jonathan Cameron,
	David Lechner, Andy Shevchenko, Rob Herring, Krzysztof Kozlowski,
	Conor Dooley, Rodrigo Alencar, Alexandru Ardelean

This patch series updates the AD8366 amplifier/attenuator driver with
modern resource management, including support for additional device
variants.

Device Support Expansion:
- Adds support for multiple digital step attenuators:
- ADRF5720: 0.5 dB LSB, 6-Bit, Digital Attenuator, 9 kHz to 40 GHz
- ADRF5730: 0.5 dB LSB, 6-Bit, Digital Attenuator, 100 MHz to 40 GHz
- ADRF5731: 2 dB LSB, 4-Bit, Digital Attenuator, 100 MHz to 40 GHz
- HMC271A: 1 dB LSB, 5-bit, Digital Attenuator, 0.7 - 3.7 GHz
- HMC1018A: 1.0 dB LSB GaAs MMIC 5-BIT DIGITAL ATTENUATOR, 0.1 - 30 GHz
- HMC1019A: 0.5 dB LSB GaAs MMIC 5-BIT DIGITAL ATTENUATOR, 0.1 - 30 GHz

Device Tree Support:
- Adds device tree binding documentation
- Adds device tree compatible strings for all supported devices
- Favor chip info tables over device type.

Signed-off-by: Rodrigo Alencar <rodrigo.alencar@analog.com>
---
Rodrigo Alencar (7):
      MAINTAINERS: Add missing maintainer entry for AD8366 driver
      dt-bindings: iio: amplifiers: Add AD8366 support
      iio: amplifiers: ad8366: consume enable gpio for applicable parts
      iio: amplifiers: ad8366: Update device support
      iio: amplifiers: ad8366: use cleanup.h mutex guard
      iio: amplifiers: ad8366: simplify resource management
      iio: amplifiers: ad8366: add device tree support

 .../bindings/iio/amplifiers/adi,ad8366.yaml        |  85 +++++
 MAINTAINERS                                        |   9 +
 drivers/iio/amplifiers/Kconfig                     |   6 +
 drivers/iio/amplifiers/ad8366.c                    | 351 +++++++++++----------
 4 files changed, 285 insertions(+), 166 deletions(-)
---
base-commit: c30e80d68a7afb334fde7147ee0106f25dd58d3a
change-id: 20251121-iio-ad8366-update-56abac58bbca

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



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

* [PATCH 1/7] MAINTAINERS: Add missing maintainer entry for AD8366 driver
  2026-01-19 14:36 [PATCH 0/7] iio: amplifiers: ad8366: driver update and dt support Rodrigo Alencar via B4 Relay
@ 2026-01-19 14:36 ` Rodrigo Alencar via B4 Relay
  2026-01-19 14:36 ` [PATCH 2/7] dt-bindings: iio: amplifiers: Add AD8366 support Rodrigo Alencar via B4 Relay
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 17+ messages in thread
From: Rodrigo Alencar via B4 Relay @ 2026-01-19 14:36 UTC (permalink / raw)
  To: linux-kernel, linux-iio, devicetree
  Cc: Michael Hennerich, Lars-Peter Clausen, Jonathan Cameron,
	David Lechner, Andy Shevchenko, Rob Herring, Krzysztof Kozlowski,
	Conor Dooley, Rodrigo Alencar

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

Add maintainers entry for drivers/iio/amplifiers/ad8366.c

Signed-off-by: Rodrigo Alencar <rodrigo.alencar@analog.com>
---
 MAINTAINERS | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index 4dd9f758a871..9c8e83470464 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1583,6 +1583,14 @@ W:	https://ez.analog.com/linux-software-drivers
 F:	Documentation/devicetree/bindings/iio/adc/adi,ad7780.yaml
 F:	drivers/iio/adc/ad7780.c
 
+ANALOG DEVICES INC AD8366 DRIVER
+M:	Michael Hennerich <Michael.Hennerich@analog.com>
+M:	Rodrigo Alencar <rodrigo.alencar@analog.com>
+L:	linux-iio@vger.kernel.org
+S:	Supported
+W:	https://ez.analog.com/linux-software-drivers
+F:	drivers/iio/amplifiers/ad8366.c
+
 ANALOG DEVICES INC AD9467 DRIVER
 M:	Michael Hennerich <Michael.Hennerich@analog.com>
 M:	Nuno Sa <nuno.sa@analog.com>

-- 
2.43.0



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

* [PATCH 2/7] dt-bindings: iio: amplifiers: Add AD8366 support
  2026-01-19 14:36 [PATCH 0/7] iio: amplifiers: ad8366: driver update and dt support Rodrigo Alencar via B4 Relay
  2026-01-19 14:36 ` [PATCH 1/7] MAINTAINERS: Add missing maintainer entry for AD8366 driver Rodrigo Alencar via B4 Relay
@ 2026-01-19 14:36 ` Rodrigo Alencar via B4 Relay
  2026-01-21  8:10   ` Krzysztof Kozlowski
  2026-01-19 14:36 ` [PATCH 3/7] iio: amplifiers: ad8366: consume enable gpio for applicable parts Rodrigo Alencar via B4 Relay
                   ` (4 subsequent siblings)
  6 siblings, 1 reply; 17+ messages in thread
From: Rodrigo Alencar via B4 Relay @ 2026-01-19 14:36 UTC (permalink / raw)
  To: linux-kernel, linux-iio, devicetree
  Cc: Michael Hennerich, Lars-Peter Clausen, Jonathan Cameron,
	David Lechner, Andy Shevchenko, Rob Herring, Krzysztof Kozlowski,
	Conor Dooley, Rodrigo Alencar

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

Add device tree binding documentation for amplifiers and digital
attenuators. This covers different device variants with similar
SPI control.

Signed-off-by: Rodrigo Alencar <rodrigo.alencar@analog.com>
---
 .../bindings/iio/amplifiers/adi,ad8366.yaml        | 85 ++++++++++++++++++++++
 MAINTAINERS                                        |  1 +
 2 files changed, 86 insertions(+)

diff --git a/Documentation/devicetree/bindings/iio/amplifiers/adi,ad8366.yaml b/Documentation/devicetree/bindings/iio/amplifiers/adi,ad8366.yaml
new file mode 100644
index 000000000000..7477bb9b5071
--- /dev/null
+++ b/Documentation/devicetree/bindings/iio/amplifiers/adi,ad8366.yaml
@@ -0,0 +1,85 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/iio/amplifiers/adi,ad8366.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: AD8366, similar Gain Amplifiers and Digital Attenuators
+
+maintainers:
+  - Michael Hennerich <michael.hennerich@analog.com>
+  - Rodrigo Alencar <rodrigo.alencar@analog.com>
+
+description: |
+  Digital Variable Gain Amplifiers (VGAs) and Digital Attenuators with
+  SPI interface.
+
+properties:
+  compatible:
+    enum:
+      - adi,ad8366
+      - adi,ada4961
+      - adi,adl5240
+      - adi,adrf5720
+      - adi,adrf5730
+      - adi,adrf5731
+      - adi,hmc271a
+      - adi,hmc792a
+      - adi,hmc1018a
+      - adi,hmc1019a
+      - adi,hmc1119
+
+  reg:
+    maxItems: 1
+
+  vcc-supply:
+    description: Regulator that provides power to the device.
+
+  reset-gpios:
+    maxItems: 1
+    description:
+      GPIO pin used to reset the device.
+
+  enable-gpios:
+    maxItems: 1
+    description:
+      GPIO pin used to enable the device.
+
+required:
+  - compatible
+  - reg
+  - vcc-supply
+
+allOf:
+  - $ref: /schemas/spi/spi-peripheral-props.yaml#
+
+unevaluatedProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/gpio/gpio.h>
+    spi {
+      #address-cells = <1>;
+      #size-cells = <0>;
+
+      amplifier@0 {
+        compatible = "adi,ad8366";
+        reg = <0>;
+        spi-max-frequency = <1000000>;
+        vcc-supply = <&vcc_3v3>;
+      };
+    };
+  - |
+    #include <dt-bindings/gpio/gpio.h>
+    spi {
+      #address-cells = <1>;
+      #size-cells = <0>;
+
+      attenuator@1 {
+        compatible = "adi,adrf5730";
+        reg = <1>;
+        spi-max-frequency = <1000000>;
+        vcc-supply = <&vcc_3v3>;
+      };
+    };
+...
diff --git a/MAINTAINERS b/MAINTAINERS
index 9c8e83470464..0bbeea028cc0 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1589,6 +1589,7 @@ M:	Rodrigo Alencar <rodrigo.alencar@analog.com>
 L:	linux-iio@vger.kernel.org
 S:	Supported
 W:	https://ez.analog.com/linux-software-drivers
+F:	Documentation/devicetree/bindings/iio/amplifiers/adi,ad8366.yaml
 F:	drivers/iio/amplifiers/ad8366.c
 
 ANALOG DEVICES INC AD9467 DRIVER

-- 
2.43.0



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

* [PATCH 3/7] iio: amplifiers: ad8366: consume enable gpio for applicable parts
  2026-01-19 14:36 [PATCH 0/7] iio: amplifiers: ad8366: driver update and dt support Rodrigo Alencar via B4 Relay
  2026-01-19 14:36 ` [PATCH 1/7] MAINTAINERS: Add missing maintainer entry for AD8366 driver Rodrigo Alencar via B4 Relay
  2026-01-19 14:36 ` [PATCH 2/7] dt-bindings: iio: amplifiers: Add AD8366 support Rodrigo Alencar via B4 Relay
@ 2026-01-19 14:36 ` Rodrigo Alencar via B4 Relay
  2026-01-23  8:26   ` Jonathan Cameron
  2026-01-19 14:36 ` [PATCH 4/7] iio: amplifiers: ad8366: Update device support Rodrigo Alencar via B4 Relay
                   ` (3 subsequent siblings)
  6 siblings, 1 reply; 17+ messages in thread
From: Rodrigo Alencar via B4 Relay @ 2026-01-19 14:36 UTC (permalink / raw)
  To: linux-kernel, linux-iio, devicetree
  Cc: Michael Hennerich, Lars-Peter Clausen, Jonathan Cameron,
	David Lechner, Andy Shevchenko, Rob Herring, Krzysztof Kozlowski,
	Conor Dooley, Rodrigo Alencar

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

Some parts may consume enable GPIO to set serial mode (PS pin) or
powerup the device (e.g. ADA4961's PWUP pin).

Co-developed-by: Michael Hennerich <michael.hennerich@analog.com>
Signed-off-by: Michael Hennerich <michael.hennerich@analog.com>
Signed-off-by: Rodrigo Alencar <rodrigo.alencar@analog.com>
---
 drivers/iio/amplifiers/ad8366.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/drivers/iio/amplifiers/ad8366.c b/drivers/iio/amplifiers/ad8366.c
index d06ac786501c..63bb9f0179eb 100644
--- a/drivers/iio/amplifiers/ad8366.c
+++ b/drivers/iio/amplifiers/ad8366.c
@@ -43,6 +43,7 @@ struct ad8366_state {
 	struct regulator	*reg;
 	struct mutex            lock; /* protect sensor state */
 	struct gpio_desc	*reset_gpio;
+	struct gpio_desc	*enable_gpio;
 	unsigned char		ch[2];
 	enum ad8366_type	type;
 	const struct ad8366_info *info;
@@ -281,6 +282,13 @@ static int ad8366_probe(struct spi_device *spi)
 			ret = PTR_ERR(st->reset_gpio);
 			goto error_disable_reg;
 		}
+
+		st->enable_gpio = devm_gpiod_get_optional(&spi->dev, "enable", GPIOD_OUT_HIGH);
+		if (IS_ERR(st->enable_gpio)) {
+			ret = PTR_ERR(st->enable_gpio);
+			goto error_disable_reg;
+		}
+
 		indio_dev->channels = ada4961_channels;
 		indio_dev->num_channels = ARRAY_SIZE(ada4961_channels);
 		break;

-- 
2.43.0



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

* [PATCH 4/7] iio: amplifiers: ad8366: Update device support
  2026-01-19 14:36 [PATCH 0/7] iio: amplifiers: ad8366: driver update and dt support Rodrigo Alencar via B4 Relay
                   ` (2 preceding siblings ...)
  2026-01-19 14:36 ` [PATCH 3/7] iio: amplifiers: ad8366: consume enable gpio for applicable parts Rodrigo Alencar via B4 Relay
@ 2026-01-19 14:36 ` Rodrigo Alencar via B4 Relay
  2026-01-23  8:33   ` Jonathan Cameron
  2026-01-19 14:36 ` [PATCH 5/7] iio: amplifiers: ad8366: use cleanup.h mutex guard Rodrigo Alencar via B4 Relay
                   ` (2 subsequent siblings)
  6 siblings, 1 reply; 17+ messages in thread
From: Rodrigo Alencar via B4 Relay @ 2026-01-19 14:36 UTC (permalink / raw)
  To: linux-kernel, linux-iio, devicetree
  Cc: Michael Hennerich, Lars-Peter Clausen, Jonathan Cameron,
	David Lechner, Andy Shevchenko, Rob Herring, Krzysztof Kozlowski,
	Conor Dooley, Rodrigo Alencar, Alexandru Ardelean

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

This patch adds support for following digital step attenuators:

 * HMC271A: 1dB LSB 5-Bit Digital Attenuator SMT, 0.7 - 3.7 GHz
 * ADRF5720: 0.5 dB LSB, 6-Bit, Digital Attenuator, 9 kHz to 40 GHz
 * ADRF5730: 0.5 dB LSB, 6-Bit, Digital Attenuator, 100 MHz to 40 GHz
 * ADRF5731: 2 dB LSB, 4-Bit, Digital Attenuator, 100 MHz to 40 GHz
 * HMC1018A: 1.0 dB LSB GaAs MMIC 5-BIT DIGITAL ATTENUATOR, 0.1 - 30 GHz
 * HMC1019A: 0.5 dB LSB GaAs MMIC 5-BIT DIGITAL ATTENUATOR, 0.1 - 30 GHz

Additionally, copyright notice was updated with current year.

Co-developed-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
Co-developed-by: Michael Hennerich <michael.hennerich@analog.com>
Signed-off-by: Michael Hennerich <michael.hennerich@analog.com>
Signed-off-by: Rodrigo Alencar <rodrigo.alencar@analog.com>
---
 drivers/iio/amplifiers/Kconfig  |  6 +++
 drivers/iio/amplifiers/ad8366.c | 86 ++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 91 insertions(+), 1 deletion(-)

diff --git a/drivers/iio/amplifiers/Kconfig b/drivers/iio/amplifiers/Kconfig
index a8a604863eed..39d280d4d437 100644
--- a/drivers/iio/amplifiers/Kconfig
+++ b/drivers/iio/amplifiers/Kconfig
@@ -18,7 +18,13 @@ config AD8366
 	    AD8366 Dual-Digital Variable Gain Amplifier (VGA)
 	    ADA4961 BiCMOS RF Digital Gain Amplifier (DGA)
 	    ADL5240 Digitally controlled variable gain amplifier (VGA)
+	    ADRF5720: 0.5 dB LSB, 6-Bit, Silicon Digital Attenuator
+	    ADRF5730: 0.5 dB LSB, 6-Bit, Silicon Digital Attenuator
+	    ADRF5731: 2 dB LSB, 4-Bit, Silicon Digital Attenuator
+	    HMC271A: 1dB LSB 5-Bit Digital Attenuator SMT
 	    HMC792A 0.25 dB LSB GaAs MMIC 6-Bit Digital Attenuator
+	    HMC1018A: 1.0 dB LSB GaAs MMIC 5-BIT Digital Attenuator
+	    HMC1019A: 0.5 dB LSB GaAs MMIC 5-BIT Digital Attenuator
 	    HMC1119 0.25 dB LSB, 7-Bit, Silicon Digital Attenuator
 
 	  To compile this driver as a module, choose M here: the
diff --git a/drivers/iio/amplifiers/ad8366.c b/drivers/iio/amplifiers/ad8366.c
index 63bb9f0179eb..160a8ab0c2ee 100644
--- a/drivers/iio/amplifiers/ad8366.c
+++ b/drivers/iio/amplifiers/ad8366.c
@@ -5,10 +5,16 @@
  *   AD8366 Dual-Digital Variable Gain Amplifier (VGA)
  *   ADA4961 BiCMOS RF Digital Gain Amplifier (DGA)
  *   ADL5240 Digitally controlled variable gain amplifier (VGA)
+ *   ADRF5720: 0.5 dB LSB, 6-Bit, Silicon Digital Attenuator, 9 kHz to 40 GHz
+ *   ADRF5730: 0.5 dB LSB, 6-Bit, Silicon Digital Attenuator, 100 MHz to 40 GHz
+ *   ADRF5731: 2 dB LSB, 4-Bit, Silicon Digital Attenuator, 100 MHz to 40 GHz
+ *   HMC271A: 1dB LSB 5-Bit Digital Attenuator SMT, 0.7 - 3.7 GHz
  *   HMC792A 0.25 dB LSB GaAs MMIC 6-Bit Digital Attenuator
+ *   HMC1018A: 1.0 dB LSB GaAs MMIC 5-BIT DIGITAL ATTENUATOR, 0.1 - 30 GHz
+ *   HMC1019A: 0.5 dB LSB GaAs MMIC 5-BIT DIGITAL ATTENUATOR, 0.1 - 30 GHz
  *   HMC1119 0.25 dB LSB, 7-Bit, Silicon Digital Attenuator
  *
- * Copyright 2012-2019 Analog Devices Inc.
+ * Copyright 2012-2026 Analog Devices Inc.
  */
 
 #include <linux/device.h>
@@ -29,7 +35,13 @@ enum ad8366_type {
 	ID_AD8366,
 	ID_ADA4961,
 	ID_ADL5240,
+	ID_ADRF5720,
+	ID_ADRF5730,
+	ID_ADRF5731,
+	ID_HMC271,
 	ID_HMC792,
+	ID_HMC1018,
+	ID_HMC1019,
 	ID_HMC1119,
 };
 
@@ -67,10 +79,34 @@ static const struct ad8366_info ad8366_infos[] = {
 		.gain_min = -11500,
 		.gain_max = 20000,
 	},
+	[ID_ADRF5720] = {
+		.gain_min = -31500,
+		.gain_max = 0,
+	},
+	[ID_ADRF5730] = {
+		.gain_min = -31500,
+		.gain_max = 0,
+	},
+	[ID_ADRF5731] = {
+		.gain_min = -30000,
+		.gain_max = 0,
+	},
+	[ID_HMC271] = {
+		.gain_min = -31000,
+		.gain_max = 0,
+	},
 	[ID_HMC792] = {
 		.gain_min = -15750,
 		.gain_max = 0,
 	},
+	[ID_HMC1018] = {
+		.gain_min = -31000,
+		.gain_max = 0,
+	},
+	[ID_HMC1019] = {
+		.gain_min = -15500,
+		.gain_max = 0,
+	},
 	[ID_HMC1119] = {
 		.gain_min = -31750,
 		.gain_max = 0,
@@ -95,9 +131,17 @@ static int ad8366_write(struct iio_dev *indio_dev,
 		st->data[0] = ch_a & 0x1F;
 		break;
 	case ID_ADL5240:
+	case ID_ADRF5720:
+	case ID_ADRF5730:
+	case ID_ADRF5731:
 		st->data[0] = (ch_a & 0x3F);
 		break;
+	case ID_HMC271:
+		st->data[0] = bitrev8(ch_a & 0x1F) >> 3;
+		break;
 	case ID_HMC792:
+	case ID_HMC1018:
+	case ID_HMC1019:
 	case ID_HMC1119:
 		st->data[0] = ch_a;
 		break;
@@ -135,9 +179,23 @@ static int ad8366_read_raw(struct iio_dev *indio_dev,
 		case ID_ADL5240:
 			gain = 20000 - 31500 + code * 500;
 			break;
+		case ID_ADRF5720:
+		case ID_ADRF5730:
+			gain = -1 * code * 500;
+			break;
+		case ID_ADRF5731:
+			gain = -1 * code * 500;
+			break;
 		case ID_HMC792:
 			gain = -1 * code * 500;
 			break;
+		case ID_HMC271:
+		case ID_HMC1018:
+			gain = -31000 + code * 1000;
+			break;
+		case ID_HMC1019:
+			gain = -15500 + code * 500;
+			break;
 		case ID_HMC1119:
 			gain = -1 * code * 250;
 			break;
@@ -187,9 +245,23 @@ static int ad8366_write_raw(struct iio_dev *indio_dev,
 	case ID_ADL5240:
 		code = ((gain - 500 - 20000) / 500) & 0x3F;
 		break;
+	case ID_ADRF5720:
+	case ID_ADRF5730:
+		code = (abs(gain) / 500) & 0x3F;
+		break;
+	case ID_ADRF5731:
+		code = (abs(gain) / 500) & 0x3C;
+		break;
 	case ID_HMC792:
 		code = (abs(gain) / 500) & 0x3F;
 		break;
+	case ID_HMC271:
+	case ID_HMC1018:
+		code = ((gain - 1000) / 1000) & 0x1F;
+		break;
+	case ID_HMC1019:
+		code = ((gain - 500) / 500) & 0x1F;
+		break;
 	case ID_HMC1119:
 		code = (abs(gain) / 250) & 0x7F;
 		break;
@@ -275,8 +347,14 @@ static int ad8366_probe(struct spi_device *spi)
 		break;
 	case ID_ADA4961:
 	case ID_ADL5240:
+	case ID_HMC271:
 	case ID_HMC792:
 	case ID_HMC1119:
+	case ID_ADRF5720:
+	case ID_ADRF5730:
+	case ID_ADRF5731:
+	case ID_HMC1018:
+	case ID_HMC1019:
 		st->reset_gpio = devm_gpiod_get_optional(&spi->dev, "reset", GPIOD_OUT_HIGH);
 		if (IS_ERR(st->reset_gpio)) {
 			ret = PTR_ERR(st->reset_gpio);
@@ -335,8 +413,14 @@ static void ad8366_remove(struct spi_device *spi)
 static const struct spi_device_id ad8366_id[] = {
 	{"ad8366",  ID_AD8366},
 	{"ada4961", ID_ADA4961},
+	{"adrf5720", ID_ADRF5720},
+	{"adrf5730", ID_ADRF5730},
+	{"adrf5731", ID_ADRF5731},
 	{"adl5240", ID_ADL5240},
+	{"hmc271a", ID_HMC271},
 	{"hmc792a", ID_HMC792},
+	{"hmc1018a", ID_HMC1018},
+	{"hmc1019a", ID_HMC1019},
 	{"hmc1119", ID_HMC1119},
 	{ }
 };

-- 
2.43.0



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

* [PATCH 5/7] iio: amplifiers: ad8366: use cleanup.h mutex guard
  2026-01-19 14:36 [PATCH 0/7] iio: amplifiers: ad8366: driver update and dt support Rodrigo Alencar via B4 Relay
                   ` (3 preceding siblings ...)
  2026-01-19 14:36 ` [PATCH 4/7] iio: amplifiers: ad8366: Update device support Rodrigo Alencar via B4 Relay
@ 2026-01-19 14:36 ` Rodrigo Alencar via B4 Relay
  2026-01-19 14:43   ` Krzysztof Kozlowski
  2026-01-19 14:37 ` [PATCH 6/7] iio: amplifiers: ad8366: simplify resource management Rodrigo Alencar via B4 Relay
  2026-01-19 14:37 ` [PATCH 7/7] iio: amplifiers: ad8366: add device tree support Rodrigo Alencar via B4 Relay
  6 siblings, 1 reply; 17+ messages in thread
From: Rodrigo Alencar via B4 Relay @ 2026-01-19 14:36 UTC (permalink / raw)
  To: linux-kernel, linux-iio, devicetree
  Cc: Michael Hennerich, Lars-Peter Clausen, Jonathan Cameron,
	David Lechner, Andy Shevchenko, Rob Herring, Krzysztof Kozlowski,
	Conor Dooley, Rodrigo Alencar

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

Changes related to mutex handling:
- use guard() from cleanup for mutex locking
- replace mutex_init() for devm_mutex_init()

Signed-off-by: Rodrigo Alencar <rodrigo.alencar@analog.com>
---
 drivers/iio/amplifiers/ad8366.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/drivers/iio/amplifiers/ad8366.c b/drivers/iio/amplifiers/ad8366.c
index 160a8ab0c2ee..26856cb4216e 100644
--- a/drivers/iio/amplifiers/ad8366.c
+++ b/drivers/iio/amplifiers/ad8366.c
@@ -17,6 +17,7 @@
  * Copyright 2012-2026 Analog Devices Inc.
  */
 
+#include <linux/cleanup.h>
 #include <linux/device.h>
 #include <linux/kernel.h>
 #include <linux/slab.h>
@@ -164,7 +165,8 @@ static int ad8366_read_raw(struct iio_dev *indio_dev,
 	int ret;
 	int code, gain = 0;
 
-	mutex_lock(&st->lock);
+	guard(mutex)(&st->lock);
+
 	switch (m) {
 	case IIO_CHAN_INFO_HARDWAREGAIN:
 		code = st->ch[chan->channel];
@@ -210,7 +212,6 @@ static int ad8366_read_raw(struct iio_dev *indio_dev,
 	default:
 		ret = -EINVAL;
 	}
-	mutex_unlock(&st->lock);
 
 	return ret;
 };
@@ -267,7 +268,8 @@ static int ad8366_write_raw(struct iio_dev *indio_dev,
 		break;
 	}
 
-	mutex_lock(&st->lock);
+	guard(mutex)(&st->lock);
+
 	switch (mask) {
 	case IIO_CHAN_INFO_HARDWAREGAIN:
 		st->ch[chan->channel] = code;
@@ -276,7 +278,6 @@ static int ad8366_write_raw(struct iio_dev *indio_dev,
 	default:
 		ret = -EINVAL;
 	}
-	mutex_unlock(&st->lock);
 
 	return ret;
 }
@@ -336,10 +337,13 @@ static int ad8366_probe(struct spi_device *spi)
 	}
 
 	spi_set_drvdata(spi, indio_dev);
-	mutex_init(&st->lock);
 	st->spi = spi;
 	st->type = spi_get_device_id(spi)->driver_data;
 
+	ret = devm_mutex_init(&spi->dev, &st->lock);
+	if (ret)
+		return ret;
+
 	switch (st->type) {
 	case ID_AD8366:
 		indio_dev->channels = ad8366_channels;

-- 
2.43.0



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

* [PATCH 6/7] iio: amplifiers: ad8366: simplify resource management
  2026-01-19 14:36 [PATCH 0/7] iio: amplifiers: ad8366: driver update and dt support Rodrigo Alencar via B4 Relay
                   ` (4 preceding siblings ...)
  2026-01-19 14:36 ` [PATCH 5/7] iio: amplifiers: ad8366: use cleanup.h mutex guard Rodrigo Alencar via B4 Relay
@ 2026-01-19 14:37 ` Rodrigo Alencar via B4 Relay
  2026-01-19 14:45   ` Krzysztof Kozlowski
  2026-01-19 14:37 ` [PATCH 7/7] iio: amplifiers: ad8366: add device tree support Rodrigo Alencar via B4 Relay
  6 siblings, 1 reply; 17+ messages in thread
From: Rodrigo Alencar via B4 Relay @ 2026-01-19 14:37 UTC (permalink / raw)
  To: linux-kernel, linux-iio, devicetree
  Cc: Michael Hennerich, Lars-Peter Clausen, Jonathan Cameron,
	David Lechner, Andy Shevchenko, Rob Herring, Krzysztof Kozlowski,
	Conor Dooley, Rodrigo Alencar

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

Device resource managed simplified with:
- voltage regulator managed internally by the device.
- IIO device registration handled with devm_iio_device_register().
- removal of goto's from the probe function.
- ad8366_remove() removed as it is not needed anymore.

Also, dev_err_probe() is used to report probe errors with created local
device pointer.

Signed-off-by: Rodrigo Alencar <rodrigo.alencar@analog.com>
---
 drivers/iio/amplifiers/ad8366.c | 68 +++++++++++------------------------------
 1 file changed, 18 insertions(+), 50 deletions(-)

diff --git a/drivers/iio/amplifiers/ad8366.c b/drivers/iio/amplifiers/ad8366.c
index 26856cb4216e..d3fd8d44eae7 100644
--- a/drivers/iio/amplifiers/ad8366.c
+++ b/drivers/iio/amplifiers/ad8366.c
@@ -53,7 +53,6 @@ struct ad8366_info {
 
 struct ad8366_state {
 	struct spi_device	*spi;
-	struct regulator	*reg;
 	struct mutex            lock; /* protect sensor state */
 	struct gpio_desc	*reset_gpio;
 	struct gpio_desc	*enable_gpio;
@@ -321,26 +320,22 @@ static int ad8366_probe(struct spi_device *spi)
 {
 	struct iio_dev *indio_dev;
 	struct ad8366_state *st;
+	struct device *dev = &spi->dev;
 	int ret;
 
-	indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st));
+	indio_dev = devm_iio_device_alloc(dev, sizeof(*st));
 	if (indio_dev == NULL)
 		return -ENOMEM;
 
 	st = iio_priv(indio_dev);
-
-	st->reg = devm_regulator_get(&spi->dev, "vcc");
-	if (!IS_ERR(st->reg)) {
-		ret = regulator_enable(st->reg);
-		if (ret)
-			return ret;
-	}
-
-	spi_set_drvdata(spi, indio_dev);
 	st->spi = spi;
 	st->type = spi_get_device_id(spi)->driver_data;
 
-	ret = devm_mutex_init(&spi->dev, &st->lock);
+	ret = devm_regulator_get_enable(dev, "vcc");
+	if (ret)
+		return dev_err_probe(dev, ret, "Failed to get regulator\n");
+
+	ret = devm_mutex_init(dev, &st->lock);
 	if (ret)
 		return ret;
 
@@ -359,25 +354,21 @@ static int ad8366_probe(struct spi_device *spi)
 	case ID_ADRF5731:
 	case ID_HMC1018:
 	case ID_HMC1019:
-		st->reset_gpio = devm_gpiod_get_optional(&spi->dev, "reset", GPIOD_OUT_HIGH);
-		if (IS_ERR(st->reset_gpio)) {
-			ret = PTR_ERR(st->reset_gpio);
-			goto error_disable_reg;
-		}
+		st->reset_gpio = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH);
+		if (IS_ERR(st->reset_gpio))
+			return dev_err_probe(dev, PTR_ERR(st->reset_gpio),
+					     "Failed to get reset GPIO\n");
 
-		st->enable_gpio = devm_gpiod_get_optional(&spi->dev, "enable", GPIOD_OUT_HIGH);
-		if (IS_ERR(st->enable_gpio)) {
-			ret = PTR_ERR(st->enable_gpio);
-			goto error_disable_reg;
-		}
+		st->enable_gpio = devm_gpiod_get_optional(dev, "enable", GPIOD_OUT_HIGH);
+		if (IS_ERR(st->enable_gpio))
+			return dev_err_probe(dev, PTR_ERR(st->enable_gpio),
+					     "Failed to get enable GPIO\n");
 
 		indio_dev->channels = ada4961_channels;
 		indio_dev->num_channels = ARRAY_SIZE(ada4961_channels);
 		break;
 	default:
-		dev_err(&spi->dev, "Invalid device ID\n");
-		ret = -EINVAL;
-		goto error_disable_reg;
+		return dev_err_probe(dev, -EINVAL, "Invalid device ID\n");
 	}
 
 	st->info = &ad8366_infos[st->type];
@@ -387,31 +378,9 @@ static int ad8366_probe(struct spi_device *spi)
 
 	ret = ad8366_write(indio_dev, 0, 0);
 	if (ret < 0)
-		goto error_disable_reg;
+		return dev_err_probe(dev, ret, "failed to write initial gain\n");
 
-	ret = iio_device_register(indio_dev);
-	if (ret)
-		goto error_disable_reg;
-
-	return 0;
-
-error_disable_reg:
-	if (!IS_ERR(st->reg))
-		regulator_disable(st->reg);
-
-	return ret;
-}
-
-static void ad8366_remove(struct spi_device *spi)
-{
-	struct iio_dev *indio_dev = spi_get_drvdata(spi);
-	struct ad8366_state *st = iio_priv(indio_dev);
-	struct regulator *reg = st->reg;
-
-	iio_device_unregister(indio_dev);
-
-	if (!IS_ERR(reg))
-		regulator_disable(reg);
+	return devm_iio_device_register(dev, indio_dev);
 }
 
 static const struct spi_device_id ad8366_id[] = {
@@ -435,7 +404,6 @@ static struct spi_driver ad8366_driver = {
 		.name	= KBUILD_MODNAME,
 	},
 	.probe		= ad8366_probe,
-	.remove		= ad8366_remove,
 	.id_table	= ad8366_id,
 };
 

-- 
2.43.0



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

* [PATCH 7/7] iio: amplifiers: ad8366: add device tree support
  2026-01-19 14:36 [PATCH 0/7] iio: amplifiers: ad8366: driver update and dt support Rodrigo Alencar via B4 Relay
                   ` (5 preceding siblings ...)
  2026-01-19 14:37 ` [PATCH 6/7] iio: amplifiers: ad8366: simplify resource management Rodrigo Alencar via B4 Relay
@ 2026-01-19 14:37 ` Rodrigo Alencar via B4 Relay
  2026-01-19 14:47   ` Krzysztof Kozlowski
  6 siblings, 1 reply; 17+ messages in thread
From: Rodrigo Alencar via B4 Relay @ 2026-01-19 14:37 UTC (permalink / raw)
  To: linux-kernel, linux-iio, devicetree
  Cc: Michael Hennerich, Lars-Peter Clausen, Jonathan Cameron,
	David Lechner, Andy Shevchenko, Rob Herring, Krzysztof Kozlowski,
	Conor Dooley, Rodrigo Alencar

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

Device-tree support achieved dropping the enum ID in favor of an extended
chip info table:
- gain step and number of channels moved to chip info
- pack_code function added to describe how SPI buffer is populated

With this, switch cases on the device type were dropped:
- simplified read_raw and write_raw callbacks
- number of channels retrieved from chip info in probe function

Signed-off-by: Rodrigo Alencar <rodrigo.alencar@analog.com>
---
 drivers/iio/amplifiers/ad8366.c | 303 +++++++++++++++++-----------------------
 1 file changed, 129 insertions(+), 174 deletions(-)

diff --git a/drivers/iio/amplifiers/ad8366.c b/drivers/iio/amplifiers/ad8366.c
index d3fd8d44eae7..484ab2b6196c 100644
--- a/drivers/iio/amplifiers/ad8366.c
+++ b/drivers/iio/amplifiers/ad8366.c
@@ -27,6 +27,7 @@
 #include <linux/gpio/consumer.h>
 #include <linux/err.h>
 #include <linux/module.h>
+#include <linux/mod_devicetable.h>
 #include <linux/bitrev.h>
 
 #include <linux/iio/iio.h>
@@ -46,9 +47,14 @@ enum ad8366_type {
 	ID_HMC1119,
 };
 
+struct ad8366_state;
+
 struct ad8366_info {
 	int gain_min;
 	int gain_max;
+	int gain_step;
+	int num_channels;
+	size_t (*pack_code)(struct ad8366_state *st);
 };
 
 struct ad8366_state {
@@ -66,153 +72,142 @@ struct ad8366_state {
 	unsigned char		data[2] __aligned(IIO_DMA_MINALIGN);
 };
 
+static int ad8366_write_code(struct ad8366_state *st)
+{
+	const struct ad8366_info *inf = st->info;
+
+	return spi_write(st->spi, st->data, inf->pack_code(st));
+}
+
+static size_t ad8366_pack_code(struct ad8366_state *st)
+{
+	u8 ch_a = bitrev8(st->ch[0] & 0x3F);
+	u8 ch_b = bitrev8(st->ch[1] & 0x3F);
+
+	st->data[0] = ch_b >> 4;
+	st->data[1] = (ch_b << 4) | (ch_a >> 2);
+	return 2;
+}
+
+static size_t simple_pack_code(struct ad8366_state *st)
+{
+	st->data[0] = st->ch[0];
+	return 1;
+}
+
+static size_t adrf5731_pack_code(struct ad8366_state *st)
+{
+	st->data[0] = st->ch[0] << 2;
+	return 1;
+}
+
+static size_t hmc271_pack_code(struct ad8366_state *st)
+{
+	st->data[0] = bitrev8(st->ch[0] & 0x1F) >> 3;
+	return 1;
+}
+
 static const struct ad8366_info ad8366_infos[] = {
 	[ID_AD8366] = {
 		.gain_min = 4500,
 		.gain_max = 20500,
+		.gain_step = 253,
+		.num_channels = 2,
+		.pack_code = ad8366_pack_code,
 	},
 	[ID_ADA4961] = {
 		.gain_min = -6000,
 		.gain_max = 15000,
+		.gain_step = -1000,
+		.num_channels = 1,
+		.pack_code = simple_pack_code,
 	},
 	[ID_ADL5240] = {
 		.gain_min = -11500,
 		.gain_max = 20000,
+		.gain_step = 500,
+		.num_channels = 1,
+		.pack_code = simple_pack_code,
 	},
 	[ID_ADRF5720] = {
 		.gain_min = -31500,
 		.gain_max = 0,
+		.gain_step = -500,
+		.num_channels = 1,
+		.pack_code = simple_pack_code,
 	},
 	[ID_ADRF5730] = {
 		.gain_min = -31500,
 		.gain_max = 0,
+		.gain_step = -500,
+		.num_channels = 1,
+		.pack_code = simple_pack_code,
 	},
 	[ID_ADRF5731] = {
 		.gain_min = -30000,
 		.gain_max = 0,
+		.gain_step = -2000,
+		.num_channels = 1,
+		.pack_code = adrf5731_pack_code,
 	},
 	[ID_HMC271] = {
 		.gain_min = -31000,
 		.gain_max = 0,
+		.gain_step = 1000,
+		.num_channels = 1,
+		.pack_code = hmc271_pack_code,
 	},
 	[ID_HMC792] = {
 		.gain_min = -15750,
 		.gain_max = 0,
+		.gain_step = 250,
+		.num_channels = 1,
+		.pack_code = simple_pack_code,
 	},
 	[ID_HMC1018] = {
 		.gain_min = -31000,
 		.gain_max = 0,
+		.gain_step = 1000,
+		.num_channels = 1,
+		.pack_code = simple_pack_code,
 	},
 	[ID_HMC1019] = {
 		.gain_min = -15500,
 		.gain_max = 0,
+		.gain_step = 500,
+		.num_channels = 1,
+		.pack_code = simple_pack_code,
 	},
 	[ID_HMC1119] = {
 		.gain_min = -31750,
 		.gain_max = 0,
+		.gain_step = -250,
+		.num_channels = 1,
+		.pack_code = simple_pack_code,
 	},
 };
 
-static int ad8366_write(struct iio_dev *indio_dev,
-			unsigned char ch_a, unsigned char ch_b)
-{
-	struct ad8366_state *st = iio_priv(indio_dev);
-	int ret;
-
-	switch (st->type) {
-	case ID_AD8366:
-		ch_a = bitrev8(ch_a & 0x3F);
-		ch_b = bitrev8(ch_b & 0x3F);
-
-		st->data[0] = ch_b >> 4;
-		st->data[1] = (ch_b << 4) | (ch_a >> 2);
-		break;
-	case ID_ADA4961:
-		st->data[0] = ch_a & 0x1F;
-		break;
-	case ID_ADL5240:
-	case ID_ADRF5720:
-	case ID_ADRF5730:
-	case ID_ADRF5731:
-		st->data[0] = (ch_a & 0x3F);
-		break;
-	case ID_HMC271:
-		st->data[0] = bitrev8(ch_a & 0x1F) >> 3;
-		break;
-	case ID_HMC792:
-	case ID_HMC1018:
-	case ID_HMC1019:
-	case ID_HMC1119:
-		st->data[0] = ch_a;
-		break;
-	}
-
-	ret = spi_write(st->spi, st->data, indio_dev->num_channels);
-	if (ret < 0)
-		dev_err(&indio_dev->dev, "write failed (%d)", ret);
-
-	return ret;
-}
-
 static int ad8366_read_raw(struct iio_dev *indio_dev,
 			   struct iio_chan_spec const *chan,
 			   int *val,
 			   int *val2,
-			   long m)
+			   long mask)
 {
 	struct ad8366_state *st = iio_priv(indio_dev);
-	int ret;
-	int code, gain = 0;
+	const struct ad8366_info *inf = st->info;
+	int gain = inf->gain_step > 0 ? inf->gain_min : inf->gain_max;
 
 	guard(mutex)(&st->lock);
 
-	switch (m) {
+	switch (mask) {
 	case IIO_CHAN_INFO_HARDWAREGAIN:
-		code = st->ch[chan->channel];
-
-		switch (st->type) {
-		case ID_AD8366:
-			gain = code * 253 + 4500;
-			break;
-		case ID_ADA4961:
-			gain = 15000 - code * 1000;
-			break;
-		case ID_ADL5240:
-			gain = 20000 - 31500 + code * 500;
-			break;
-		case ID_ADRF5720:
-		case ID_ADRF5730:
-			gain = -1 * code * 500;
-			break;
-		case ID_ADRF5731:
-			gain = -1 * code * 500;
-			break;
-		case ID_HMC792:
-			gain = -1 * code * 500;
-			break;
-		case ID_HMC271:
-		case ID_HMC1018:
-			gain = -31000 + code * 1000;
-			break;
-		case ID_HMC1019:
-			gain = -15500 + code * 500;
-			break;
-		case ID_HMC1119:
-			gain = -1 * code * 250;
-			break;
-		}
-
-		/* Values in dB */
+		gain += inf->gain_step * st->ch[chan->channel];
 		*val = gain / 1000;
 		*val2 = (gain % 1000) * 1000;
-
-		ret = IIO_VAL_INT_PLUS_MICRO_DB;
-		break;
+		return IIO_VAL_INT_PLUS_MICRO_DB;
 	default:
-		ret = -EINVAL;
+		return -EINVAL;
 	}
-
-	return ret;
 };
 
 static int ad8366_write_raw(struct iio_dev *indio_dev,
@@ -223,10 +218,8 @@ static int ad8366_write_raw(struct iio_dev *indio_dev,
 {
 	struct ad8366_state *st = iio_priv(indio_dev);
 	const struct ad8366_info *inf = st->info;
-	int code = 0, gain;
-	int ret;
+	int code, gain, gain_base;
 
-	/* Values in dB */
 	if (val < 0)
 		gain = (val * 1000) - (val2 / 1000);
 	else
@@ -235,50 +228,18 @@ static int ad8366_write_raw(struct iio_dev *indio_dev,
 	if (gain > inf->gain_max || gain < inf->gain_min)
 		return -EINVAL;
 
-	switch (st->type) {
-	case ID_AD8366:
-		code = (gain - 4500) / 253;
-		break;
-	case ID_ADA4961:
-		code = (15000 - gain) / 1000;
-		break;
-	case ID_ADL5240:
-		code = ((gain - 500 - 20000) / 500) & 0x3F;
-		break;
-	case ID_ADRF5720:
-	case ID_ADRF5730:
-		code = (abs(gain) / 500) & 0x3F;
-		break;
-	case ID_ADRF5731:
-		code = (abs(gain) / 500) & 0x3C;
-		break;
-	case ID_HMC792:
-		code = (abs(gain) / 500) & 0x3F;
-		break;
-	case ID_HMC271:
-	case ID_HMC1018:
-		code = ((gain - 1000) / 1000) & 0x1F;
-		break;
-	case ID_HMC1019:
-		code = ((gain - 500) / 500) & 0x1F;
-		break;
-	case ID_HMC1119:
-		code = (abs(gain) / 250) & 0x7F;
-		break;
-	}
+	gain_base = inf->gain_step > 0 ? inf->gain_min : inf->gain_max;
+	code = DIV_ROUND_CLOSEST(gain - gain_base, inf->gain_step);
 
 	guard(mutex)(&st->lock);
 
 	switch (mask) {
 	case IIO_CHAN_INFO_HARDWAREGAIN:
 		st->ch[chan->channel] = code;
-		ret = ad8366_write(indio_dev, st->ch[0], st->ch[1]);
-		break;
+		return ad8366_write_code(st);
 	default:
-		ret = -EINVAL;
+		return -EINVAL;
 	}
-
-	return ret;
 }
 
 static int ad8366_write_raw_get_fmt(struct iio_dev *indio_dev,
@@ -312,10 +273,6 @@ static const struct iio_chan_spec ad8366_channels[] = {
 	AD8366_CHAN(1),
 };
 
-static const struct iio_chan_spec ada4961_channels[] = {
-	AD8366_CHAN(0),
-};
-
 static int ad8366_probe(struct spi_device *spi)
 {
 	struct iio_dev *indio_dev;
@@ -329,7 +286,9 @@ static int ad8366_probe(struct spi_device *spi)
 
 	st = iio_priv(indio_dev);
 	st->spi = spi;
-	st->type = spi_get_device_id(spi)->driver_data;
+	st->info = spi_get_device_match_data(spi);
+	if (!st->info)
+		return -EINVAL;
 
 	ret = devm_regulator_get_enable(dev, "vcc");
 	if (ret)
@@ -339,44 +298,23 @@ static int ad8366_probe(struct spi_device *spi)
 	if (ret)
 		return ret;
 
-	switch (st->type) {
-	case ID_AD8366:
-		indio_dev->channels = ad8366_channels;
-		indio_dev->num_channels = ARRAY_SIZE(ad8366_channels);
-		break;
-	case ID_ADA4961:
-	case ID_ADL5240:
-	case ID_HMC271:
-	case ID_HMC792:
-	case ID_HMC1119:
-	case ID_ADRF5720:
-	case ID_ADRF5730:
-	case ID_ADRF5731:
-	case ID_HMC1018:
-	case ID_HMC1019:
-		st->reset_gpio = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH);
-		if (IS_ERR(st->reset_gpio))
-			return dev_err_probe(dev, PTR_ERR(st->reset_gpio),
-					     "Failed to get reset GPIO\n");
+	st->reset_gpio = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH);
+	if (IS_ERR(st->reset_gpio))
+		return dev_err_probe(dev, PTR_ERR(st->reset_gpio),
+				     "Failed to get reset GPIO\n");
 
-		st->enable_gpio = devm_gpiod_get_optional(dev, "enable", GPIOD_OUT_HIGH);
-		if (IS_ERR(st->enable_gpio))
-			return dev_err_probe(dev, PTR_ERR(st->enable_gpio),
-					     "Failed to get enable GPIO\n");
+	st->enable_gpio = devm_gpiod_get_optional(dev, "enable", GPIOD_OUT_HIGH);
+	if (IS_ERR(st->enable_gpio))
+		return dev_err_probe(dev, PTR_ERR(st->enable_gpio),
+				     "Failed to get enable GPIO\n");
 
-		indio_dev->channels = ada4961_channels;
-		indio_dev->num_channels = ARRAY_SIZE(ada4961_channels);
-		break;
-	default:
-		return dev_err_probe(dev, -EINVAL, "Invalid device ID\n");
-	}
-
-	st->info = &ad8366_infos[st->type];
 	indio_dev->name = spi_get_device_id(spi)->name;
 	indio_dev->info = &ad8366_info;
+	indio_dev->channels = ad8366_channels;
+	indio_dev->num_channels = st->info->num_channels;
 	indio_dev->modes = INDIO_DIRECT_MODE;
 
-	ret = ad8366_write(indio_dev, 0, 0);
+	ret = ad8366_write_code(st);
 	if (ret < 0)
 		return dev_err_probe(dev, ret, "failed to write initial gain\n");
 
@@ -384,24 +322,41 @@ static int ad8366_probe(struct spi_device *spi)
 }
 
 static const struct spi_device_id ad8366_id[] = {
-	{"ad8366",  ID_AD8366},
-	{"ada4961", ID_ADA4961},
-	{"adrf5720", ID_ADRF5720},
-	{"adrf5730", ID_ADRF5730},
-	{"adrf5731", ID_ADRF5731},
-	{"adl5240", ID_ADL5240},
-	{"hmc271a", ID_HMC271},
-	{"hmc792a", ID_HMC792},
-	{"hmc1018a", ID_HMC1018},
-	{"hmc1019a", ID_HMC1019},
-	{"hmc1119", ID_HMC1119},
+	{"ad8366", (kernel_ulong_t)&ad8366_infos[ID_AD8366]},
+	{"ada4961", (kernel_ulong_t)&ad8366_infos[ID_ADA4961]},
+	{"adrf5720", (kernel_ulong_t)&ad8366_infos[ID_ADRF5720]},
+	{"adrf5730", (kernel_ulong_t)&ad8366_infos[ID_ADRF5730]},
+	{"adrf5731", (kernel_ulong_t)&ad8366_infos[ID_ADRF5731]},
+	{"adl5240", (kernel_ulong_t)&ad8366_infos[ID_ADL5240]},
+	{"hmc271a", (kernel_ulong_t)&ad8366_infos[ID_HMC271]},
+	{"hmc792a", (kernel_ulong_t)&ad8366_infos[ID_HMC792]},
+	{"hmc1018a", (kernel_ulong_t)&ad8366_infos[ID_HMC1018]},
+	{"hmc1019a", (kernel_ulong_t)&ad8366_infos[ID_HMC1019]},
+	{"hmc1119", (kernel_ulong_t)&ad8366_infos[ID_HMC1119]},
 	{ }
 };
 MODULE_DEVICE_TABLE(spi, ad8366_id);
 
+static const struct of_device_id ad8366_of_match[] = {
+	{ .compatible = "adi,ad8366", .data = &ad8366_infos[ID_AD8366] },
+	{ .compatible = "adi,ada4961", .data = &ad8366_infos[ID_ADA4961] },
+	{ .compatible = "adi,adrf5720", .data = &ad8366_infos[ID_ADRF5720] },
+	{ .compatible = "adi,adrf5730", .data = &ad8366_infos[ID_ADRF5730] },
+	{ .compatible = "adi,adrf5731", .data = &ad8366_infos[ID_ADRF5731] },
+	{ .compatible = "adi,adl5240", .data = &ad8366_infos[ID_ADL5240] },
+	{ .compatible = "adi,hmc271a", .data = &ad8366_infos[ID_HMC271] },
+	{ .compatible = "adi,hmc792a", .data = &ad8366_infos[ID_HMC792] },
+	{ .compatible = "adi,hmc1018a", .data = &ad8366_infos[ID_HMC1018] },
+	{ .compatible = "adi,hmc1019a", .data = &ad8366_infos[ID_HMC1019] },
+	{ .compatible = "adi,hmc1119", .data = &ad8366_infos[ID_HMC1119] },
+	{ }
+};
+MODULE_DEVICE_TABLE(of, ad8366_of_match);
+
 static struct spi_driver ad8366_driver = {
 	.driver = {
-		.name	= KBUILD_MODNAME,
+		.name		= KBUILD_MODNAME,
+		.of_match_table	= ad8366_of_match,
 	},
 	.probe		= ad8366_probe,
 	.id_table	= ad8366_id,

-- 
2.43.0



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

* Re: [PATCH 5/7] iio: amplifiers: ad8366: use cleanup.h mutex guard
  2026-01-19 14:36 ` [PATCH 5/7] iio: amplifiers: ad8366: use cleanup.h mutex guard Rodrigo Alencar via B4 Relay
@ 2026-01-19 14:43   ` Krzysztof Kozlowski
  2026-01-23  8:36     ` Jonathan Cameron
  0 siblings, 1 reply; 17+ messages in thread
From: Krzysztof Kozlowski @ 2026-01-19 14:43 UTC (permalink / raw)
  To: rodrigo.alencar, linux-kernel, linux-iio, devicetree
  Cc: Michael Hennerich, Lars-Peter Clausen, Jonathan Cameron,
	David Lechner, Andy Shevchenko, Rob Herring, Krzysztof Kozlowski,
	Conor Dooley

On 19/01/2026 15:36, Rodrigo Alencar via B4 Relay wrote:
> From: Rodrigo Alencar <rodrigo.alencar@analog.com>
> 
> Changes related to mutex handling:
> - use guard() from cleanup for mutex locking
> - replace mutex_init() for devm_mutex_init()

Why? We see all this from the diff but I do not see benefits.

> 
> Signed-off-by: Rodrigo Alencar <rodrigo.alencar@analog.com>
> ---
>  drivers/iio/amplifiers/ad8366.c | 14 +++++++++-----
>  1 file changed, 9 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/iio/amplifiers/ad8366.c b/drivers/iio/amplifiers/ad8366.c
> index 160a8ab0c2ee..26856cb4216e 100644
> --- a/drivers/iio/amplifiers/ad8366.c
> +++ b/drivers/iio/amplifiers/ad8366.c
> @@ -17,6 +17,7 @@
>   * Copyright 2012-2026 Analog Devices Inc.
>   */
>  
> +#include <linux/cleanup.h>
>  #include <linux/device.h>
>  #include <linux/kernel.h>
>  #include <linux/slab.h>
> @@ -164,7 +165,8 @@ static int ad8366_read_raw(struct iio_dev *indio_dev,
>  	int ret;
>  	int code, gain = 0;
>  
> -	mutex_lock(&st->lock);
> +	guard(mutex)(&st->lock);
> +
>  	switch (m) {
>  	case IIO_CHAN_INFO_HARDWAREGAIN:
>  		code = st->ch[chan->channel];
> @@ -210,7 +212,6 @@ static int ad8366_read_raw(struct iio_dev *indio_dev,
>  	default:
>  		ret = -EINVAL;
>  	}
> -	mutex_unlock(&st->lock);

This does not simplify code.

>  
>  	return ret;
>  };
> @@ -267,7 +268,8 @@ static int ad8366_write_raw(struct iio_dev *indio_dev,
>  		break;
>  	}
>  
> -	mutex_lock(&st->lock);
> +	guard(mutex)(&st->lock);

Neither this.

> +
>  	switch (mask) {
>  	case IIO_CHAN_INFO_HARDWAREGAIN:
>  		st->ch[chan->channel] = code;
> @@ -276,7 +278,6 @@ static int ad8366_write_raw(struct iio_dev *indio_dev,
>  	default:
>  		ret = -EINVAL;
>  	}
> -	mutex_unlock(&st->lock);
>  
>  	return ret;
>  }
> @@ -336,10 +337,13 @@ static int ad8366_probe(struct spi_device *spi)
>  	}
>  
>  	spi_set_drvdata(spi, indio_dev);
> -	mutex_init(&st->lock);
>  	st->spi = spi;
>  	st->type = spi_get_device_id(spi)->driver_data;
>  
> +	ret = devm_mutex_init(&spi->dev, &st->lock);

And this one actually has impact - missing mutex_destroy...

> +	if (ret)
> +		return ret;
> +
>  	switch (st->type) {
>  	case ID_AD8366:
>  		indio_dev->channels = ad8366_channels;
> 


Best regards,
Krzysztof

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

* Re: [PATCH 6/7] iio: amplifiers: ad8366: simplify resource management
  2026-01-19 14:37 ` [PATCH 6/7] iio: amplifiers: ad8366: simplify resource management Rodrigo Alencar via B4 Relay
@ 2026-01-19 14:45   ` Krzysztof Kozlowski
  0 siblings, 0 replies; 17+ messages in thread
From: Krzysztof Kozlowski @ 2026-01-19 14:45 UTC (permalink / raw)
  To: rodrigo.alencar, linux-kernel, linux-iio, devicetree
  Cc: Michael Hennerich, Lars-Peter Clausen, Jonathan Cameron,
	David Lechner, Andy Shevchenko, Rob Herring, Krzysztof Kozlowski,
	Conor Dooley

On 19/01/2026 15:37, Rodrigo Alencar via B4 Relay wrote:
> From: Rodrigo Alencar <rodrigo.alencar@analog.com>
> 
> Device resource managed simplified with:

Use more readable style.
https://elixir.bootlin.com/linux/v6.16/source/Documentation/process/submitting-patches.rst#L94

> - voltage regulator managed internally by the device.
> - IIO device registration handled with devm_iio_device_register().
> - removal of goto's from the probe function.
> - ad8366_remove() removed as it is not needed anymore.
> 
> Also, dev_err_probe() is used to report probe errors with created local
> device pointer.
> 
> Signed-off-by: Rodrigo Alencar <rodrigo.alencar@analog.com>
> ---
>  drivers/iio/amplifiers/ad8366.c | 68 +++++++++++------------------------------
>  1 file changed, 18 insertions(+), 50 deletions(-)
> 
> diff --git a/drivers/iio/amplifiers/ad8366.c b/drivers/iio/amplifiers/ad8366.c
> index 26856cb4216e..d3fd8d44eae7 100644
> --- a/drivers/iio/amplifiers/ad8366.c
> +++ b/drivers/iio/amplifiers/ad8366.c
> @@ -53,7 +53,6 @@ struct ad8366_info {
>  
>  struct ad8366_state {
>  	struct spi_device	*spi;
> -	struct regulator	*reg;
>  	struct mutex            lock; /* protect sensor state */
>  	struct gpio_desc	*reset_gpio;
>  	struct gpio_desc	*enable_gpio;
> @@ -321,26 +320,22 @@ static int ad8366_probe(struct spi_device *spi)
>  {
>  	struct iio_dev *indio_dev;
>  	struct ad8366_state *st;
> +	struct device *dev = &spi->dev;
>  	int ret;
>  
> -	indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st));
> +	indio_dev = devm_iio_device_alloc(dev, sizeof(*st));
>  	if (indio_dev == NULL)
>  		return -ENOMEM;
>  
>  	st = iio_priv(indio_dev);
> -
> -	st->reg = devm_regulator_get(&spi->dev, "vcc");
> -	if (!IS_ERR(st->reg)) {
> -		ret = regulator_enable(st->reg);
> -		if (ret)
> -			return ret;
> -	}
> -
> -	spi_set_drvdata(spi, indio_dev);
>  	st->spi = spi;
>  	st->type = spi_get_device_id(spi)->driver_data;
>  
> -	ret = devm_mutex_init(&spi->dev, &st->lock);

No need to change the line twice. Just use dev in previous commit. Or
re-order commits.

> +	ret = devm_regulator_get_enable(dev, "vcc");
> +	if (ret)
> +		return dev_err_probe(dev, ret, "Failed to get regulator\n");
> +
> +	ret = devm_mutex_init(dev, &st->lock);
>  	if (ret)
>  		return ret;
>  
> @@ -359,25 +354,21 @@ static int ad8366_probe(struct spi_device *spi)
>  	case ID_ADRF5731:
>  	case ID_HMC1018:
>  	case ID_HMC1019:
> -		st->reset_gpio = devm_gpiod_get_optional(&spi->dev, "reset", GPIOD_OUT_HIGH);
> -		if (IS_ERR(st->reset_gpio)) {
> -			ret = PTR_ERR(st->reset_gpio);
> -			goto error_disable_reg;
> -		}
> +		st->reset_gpio = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH);
> +		if (IS_ERR(st->reset_gpio))
> +			return dev_err_probe(dev, PTR_ERR(st->reset_gpio),
> +					     "Failed to get reset GPIO\n");
>  
> -		st->enable_gpio = devm_gpiod_get_optional(&spi->dev, "enable", GPIOD_OUT_HIGH);
> -		if (IS_ERR(st->enable_gpio)) {
> -			ret = PTR_ERR(st->enable_gpio);
> -			goto error_disable_reg;
> -		}
> +		st->enable_gpio = devm_gpiod_get_optional(dev, "enable", GPIOD_OUT_HIGH);

You just added these lines before. Cleanups always go BEFORE new
feature. Always.

> +		if (IS_ERR(st->enable_gpio))
> +			return dev_err_probe(dev, PTR_ERR(st->enable_gpio),
> +					     "Failed to get enable GPIO\n");
>  
>  		indio_dev->channels = ada4961_channels;
>  		indio_dev->num_channels = ARRAY_SIZE(ada4961_channels);
>  		break;
>  	default:
> -		dev_err(&spi->dev, "Invalid device ID\n");
> -		ret = -EINVAL;
> -		goto error_disable_reg;
> +		return dev_err_probe(dev, -EINVAL, "Invalid device ID\n");
>  	}
>  
>  	st->info = &ad8366_infos[st->type];
> @@ -387,31 +378,9 @@ static int ad8366_probe(struct spi_device *spi)
>  
>  	ret = ad8366_write(indio_dev, 0, 0);
>  	if (ret < 0)
> -		goto error_disable_reg;
> +		return dev_err_probe(dev, ret, "failed to write initial gain\n");
>  
Best regards,
Krzysztof

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

* Re: [PATCH 7/7] iio: amplifiers: ad8366: add device tree support
  2026-01-19 14:37 ` [PATCH 7/7] iio: amplifiers: ad8366: add device tree support Rodrigo Alencar via B4 Relay
@ 2026-01-19 14:47   ` Krzysztof Kozlowski
  2026-01-23  8:42     ` Jonathan Cameron
  0 siblings, 1 reply; 17+ messages in thread
From: Krzysztof Kozlowski @ 2026-01-19 14:47 UTC (permalink / raw)
  To: rodrigo.alencar, linux-kernel, linux-iio, devicetree
  Cc: Michael Hennerich, Lars-Peter Clausen, Jonathan Cameron,
	David Lechner, Andy Shevchenko, Rob Herring, Krzysztof Kozlowski,
	Conor Dooley

On 19/01/2026 15:37, Rodrigo Alencar via B4 Relay wrote:
> +	st->reset_gpio = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH);
> +	if (IS_ERR(st->reset_gpio))
> +		return dev_err_probe(dev, PTR_ERR(st->reset_gpio),
> +				     "Failed to get reset GPIO\n");
>  
> -		st->enable_gpio = devm_gpiod_get_optional(dev, "enable", GPIOD_OUT_HIGH);
> -		if (IS_ERR(st->enable_gpio))
> -			return dev_err_probe(dev, PTR_ERR(st->enable_gpio),
> -					     "Failed to get enable GPIO\n");
> +	st->enable_gpio = devm_gpiod_get_optional(dev, "enable", GPIOD_OUT_HIGH);

No, you are changing the same line *third* time. you need to organize
your patchset in logical way but also in a readable. You do not add
incorrect code just to change it later.

I do not see the reason behind removal of switch case. It's really
independent change of OF support which must come with its own
justification of affecting other platforms.


> +	if (IS_ERR(st->enable_gpio))
> +		return dev_err_probe(dev, PTR_ERR(st->enable_gpio),
> +				     "Failed to get enable GPIO\n");
>  
> -		indio_dev->channels = ada4961_channels;
> -		indio_dev->num_channels = ARRAY_SIZE(ada4961_channels);
> -		break;
> -	default:
> -		return dev_err_probe(dev, -EINVAL, "Invalid device ID\n");
> -	}
> -
> -	st->info = &ad8366_infos[st->type];
>  	indio_dev->name = spi_get_device_id(spi)->name;
>  	indio_dev->info = &ad8366_info;
> +	indio_dev->channels = ad8366_channels;
> +	indio_dev->num_channels = st->info->num_channels;
>  	indio_dev->modes = INDIO_DIRECT_MODE;
>  
> -	ret = ad8366_write(indio_dev, 0, 0);
> +	ret = ad8366_write_code(st);
>  	if (ret < 0)
>  		return dev_err_probe(dev, ret, "failed to write initial gain\n");
>  
> @@ -384,24 +322,41 @@ static int ad8366_probe(struct spi_device *spi)
>  }


Best regards,
Krzysztof

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

* Re: [PATCH 2/7] dt-bindings: iio: amplifiers: Add AD8366 support
  2026-01-19 14:36 ` [PATCH 2/7] dt-bindings: iio: amplifiers: Add AD8366 support Rodrigo Alencar via B4 Relay
@ 2026-01-21  8:10   ` Krzysztof Kozlowski
  0 siblings, 0 replies; 17+ messages in thread
From: Krzysztof Kozlowski @ 2026-01-21  8:10 UTC (permalink / raw)
  To: Rodrigo Alencar
  Cc: linux-kernel, linux-iio, devicetree, Michael Hennerich,
	Lars-Peter Clausen, Jonathan Cameron, David Lechner,
	Andy Shevchenko, Rob Herring, Krzysztof Kozlowski, Conor Dooley

On Mon, Jan 19, 2026 at 02:36:56PM +0000, Rodrigo Alencar wrote:
> Add device tree binding documentation for amplifiers and digital
> attenuators. This covers different device variants with similar
> SPI control.
> 
> Signed-off-by: Rodrigo Alencar <rodrigo.alencar@analog.com>
> ---
>  .../bindings/iio/amplifiers/adi,ad8366.yaml        | 85 ++++++++++++++++++++++
>  MAINTAINERS                                        |  1 +
>  2 files changed, 86 insertions(+)
> 
> diff --git a/Documentation/devicetree/bindings/iio/amplifiers/adi,ad8366.yaml b/Documentation/devicetree/bindings/iio/amplifiers/adi,ad8366.yaml
> new file mode 100644
> index 000000000000..7477bb9b5071
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/iio/amplifiers/adi,ad8366.yaml
> @@ -0,0 +1,85 @@
> +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
> +%YAML 1.2
> +---
> +$id: http://devicetree.org/schemas/iio/amplifiers/adi,ad8366.yaml#
> +$schema: http://devicetree.org/meta-schemas/core.yaml#
> +
> +title: AD8366, similar Gain Amplifiers and Digital Attenuators

s/,/and/

> +
> +maintainers:
> +  - Michael Hennerich <michael.hennerich@analog.com>
> +  - Rodrigo Alencar <rodrigo.alencar@analog.com>
> +
> +description: |

Do not need '|' unless you need to preserve formatting.

> +  Digital Variable Gain Amplifiers (VGAs) and Digital Attenuators with
> +  SPI interface.
> +
> +properties:
> +  compatible:
> +    enum:
> +      - adi,ad8366
> +      - adi,ada4961
> +      - adi,adl5240
> +      - adi,adrf5720
> +      - adi,adrf5730
> +      - adi,adrf5731
> +      - adi,hmc271a
> +      - adi,hmc792a
> +      - adi,hmc1018a
> +      - adi,hmc1019a
> +      - adi,hmc1119
> +
> +  reg:
> +    maxItems: 1
> +
> +  vcc-supply:
> +    description: Regulator that provides power to the device.
> +
> +  reset-gpios:
> +    maxItems: 1
> +    description:
> +      GPIO pin used to reset the device.

Drop description, redundant, said nothing more other than what property
already said. This cannot be a something else than GPIO and cannot be
used for something else than resetting device.

> +
> +  enable-gpios:
> +    maxItems: 1
> +    description:
> +      GPIO pin used to enable the device.

Drop description.

> +
> +required:
> +  - compatible
> +  - reg
> +  - vcc-supply
> +
> +allOf:
> +  - $ref: /schemas/spi/spi-peripheral-props.yaml#
> +
> +unevaluatedProperties: false
> +
> +examples:
> +  - |
> +    #include <dt-bindings/gpio/gpio.h>
> +    spi {
> +      #address-cells = <1>;
> +      #size-cells = <0>;
> +
> +      amplifier@0 {
> +        compatible = "adi,ad8366";
> +        reg = <0>;
> +        spi-max-frequency = <1000000>;
> +        vcc-supply = <&vcc_3v3>;
> +      };
> +    };
> +  - |
> +    #include <dt-bindings/gpio/gpio.h>
> +    spi {

Drop second example. It's the same as first.

Best regards,
Krzysztof


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

* Re: [PATCH 3/7] iio: amplifiers: ad8366: consume enable gpio for applicable parts
  2026-01-19 14:36 ` [PATCH 3/7] iio: amplifiers: ad8366: consume enable gpio for applicable parts Rodrigo Alencar via B4 Relay
@ 2026-01-23  8:26   ` Jonathan Cameron
  0 siblings, 0 replies; 17+ messages in thread
From: Jonathan Cameron @ 2026-01-23  8:26 UTC (permalink / raw)
  To: Rodrigo Alencar via B4 Relay
  Cc: rodrigo.alencar, linux-kernel, linux-iio, devicetree,
	Michael Hennerich, Lars-Peter Clausen, David Lechner,
	Andy Shevchenko, Rob Herring, Krzysztof Kozlowski, Conor Dooley

On Mon, 19 Jan 2026 14:36:57 +0000
Rodrigo Alencar via B4 Relay <devnull+rodrigo.alencar.analog.com@kernel.org> wrote:

> From: Rodrigo Alencar <rodrigo.alencar@analog.com>
> 
> Some parts may consume enable GPIO to set serial mode (PS pin) or
> powerup the device (e.g. ADA4961's PWUP pin).
> 
> Co-developed-by: Michael Hennerich <michael.hennerich@analog.com>
> Signed-off-by: Michael Hennerich <michael.hennerich@analog.com>
> Signed-off-by: Rodrigo Alencar <rodrigo.alencar@analog.com>

The patch series is in a less than ideal order.
Can you pull the cleanup in patches 5 and 6 ahead of this new stuff.

That will reduce churn (and stop me writing a reply on why there is
an error path before I check the rest of your thread - which I just
did!)

Jonathan

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

* Re: [PATCH 4/7] iio: amplifiers: ad8366: Update device support
  2026-01-19 14:36 ` [PATCH 4/7] iio: amplifiers: ad8366: Update device support Rodrigo Alencar via B4 Relay
@ 2026-01-23  8:33   ` Jonathan Cameron
  2026-01-23  8:38     ` Jonathan Cameron
  0 siblings, 1 reply; 17+ messages in thread
From: Jonathan Cameron @ 2026-01-23  8:33 UTC (permalink / raw)
  To: Rodrigo Alencar via B4 Relay
  Cc: rodrigo.alencar, linux-kernel, linux-iio, devicetree,
	Michael Hennerich, Lars-Peter Clausen, David Lechner,
	Andy Shevchenko, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Alexandru Ardelean

On Mon, 19 Jan 2026 14:36:58 +0000
Rodrigo Alencar via B4 Relay <devnull+rodrigo.alencar.analog.com@kernel.org> wrote:

> From: Rodrigo Alencar <rodrigo.alencar@analog.com>
> 
> This patch adds support for following digital step attenuators:
> 
>  * HMC271A: 1dB LSB 5-Bit Digital Attenuator SMT, 0.7 - 3.7 GHz
>  * ADRF5720: 0.5 dB LSB, 6-Bit, Digital Attenuator, 9 kHz to 40 GHz
>  * ADRF5730: 0.5 dB LSB, 6-Bit, Digital Attenuator, 100 MHz to 40 GHz
>  * ADRF5731: 2 dB LSB, 4-Bit, Digital Attenuator, 100 MHz to 40 GHz
>  * HMC1018A: 1.0 dB LSB GaAs MMIC 5-BIT DIGITAL ATTENUATOR, 0.1 - 30 GHz
>  * HMC1019A: 0.5 dB LSB GaAs MMIC 5-BIT DIGITAL ATTENUATOR, 0.1 - 30 GHz
> 
> Additionally, copyright notice was updated with current year.
> 
> Co-developed-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
> Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
> Co-developed-by: Michael Hennerich <michael.hennerich@analog.com>
> Signed-off-by: Michael Hennerich <michael.hennerich@analog.com>
> Signed-off-by: Rodrigo Alencar <rodrigo.alencar@analog.com>

I don't want to delay this series if possible (needs to be ready early next
week to meet the merge window cut off) so the stuff below can be in a follow
up series if you prefer.  It is fairly simple so if you want to do it before
these new parts are added, even better.

They will make further additions to this driver simpler and easier to review.
> ---
>  drivers/iio/amplifiers/Kconfig  |  6 +++
>  drivers/iio/amplifiers/ad8366.c | 86 ++++++++++++++++++++++++++++++++++++++++-
>  2 files changed, 91 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/iio/amplifiers/Kconfig b/drivers/iio/amplifiers/Kconfig
> index a8a604863eed..39d280d4d437 100644
> --- a/drivers/iio/amplifiers/Kconfig
> +++ b/drivers/iio/amplifiers/Kconfig
> @@ -18,7 +18,13 @@ config AD8366
>  	    AD8366 Dual-Digital Variable Gain Amplifier (VGA)
>  	    ADA4961 BiCMOS RF Digital Gain Amplifier (DGA)
>  	    ADL5240 Digitally controlled variable gain amplifier (VGA)
> +	    ADRF5720: 0.5 dB LSB, 6-Bit, Silicon Digital Attenuator
> +	    ADRF5730: 0.5 dB LSB, 6-Bit, Silicon Digital Attenuator
> +	    ADRF5731: 2 dB LSB, 4-Bit, Silicon Digital Attenuator
> +	    HMC271A: 1dB LSB 5-Bit Digital Attenuator SMT
>  	    HMC792A 0.25 dB LSB GaAs MMIC 6-Bit Digital Attenuator
> +	    HMC1018A: 1.0 dB LSB GaAs MMIC 5-BIT Digital Attenuator
> +	    HMC1019A: 0.5 dB LSB GaAs MMIC 5-BIT Digital Attenuator
>  	    HMC1119 0.25 dB LSB, 7-Bit, Silicon Digital Attenuator
>  
>  	  To compile this driver as a module, choose M here: the
> diff --git a/drivers/iio/amplifiers/ad8366.c b/drivers/iio/amplifiers/ad8366.c
> index 63bb9f0179eb..160a8ab0c2ee 100644
> --- a/drivers/iio/amplifiers/ad8366.c
> +++ b/drivers/iio/amplifiers/ad8366.c
> @@ -5,10 +5,16 @@
>   *   AD8366 Dual-Digital Variable Gain Amplifier (VGA)
>   *   ADA4961 BiCMOS RF Digital Gain Amplifier (DGA)
>   *   ADL5240 Digitally controlled variable gain amplifier (VGA)
> + *   ADRF5720: 0.5 dB LSB, 6-Bit, Silicon Digital Attenuator, 9 kHz to 40 GHz
> + *   ADRF5730: 0.5 dB LSB, 6-Bit, Silicon Digital Attenuator, 100 MHz to 40 GHz
> + *   ADRF5731: 2 dB LSB, 4-Bit, Silicon Digital Attenuator, 100 MHz to 40 GHz
> + *   HMC271A: 1dB LSB 5-Bit Digital Attenuator SMT, 0.7 - 3.7 GHz
>   *   HMC792A 0.25 dB LSB GaAs MMIC 6-Bit Digital Attenuator
> + *   HMC1018A: 1.0 dB LSB GaAs MMIC 5-BIT DIGITAL ATTENUATOR, 0.1 - 30 GHz
> + *   HMC1019A: 0.5 dB LSB GaAs MMIC 5-BIT DIGITAL ATTENUATOR, 0.1 - 30 GHz
>   *   HMC1119 0.25 dB LSB, 7-Bit, Silicon Digital Attenuator
>   *
> - * Copyright 2012-2019 Analog Devices Inc.
> + * Copyright 2012-2026 Analog Devices Inc.
>   */
>  
>  #include <linux/device.h>
> @@ -29,7 +35,13 @@ enum ad8366_type {
>  	ID_AD8366,
>  	ID_ADA4961,
>  	ID_ADL5240,
> +	ID_ADRF5720,
> +	ID_ADRF5730,
> +	ID_ADRF5731,
> +	ID_HMC271,
>  	ID_HMC792,
> +	ID_HMC1018,
> +	ID_HMC1019,
>  	ID_HMC1119,
>  };
>  
> @@ -67,10 +79,34 @@ static const struct ad8366_info ad8366_infos[] = {

Refactor step 2: Split this up into individual structures and drop
the enum.  The presence of that enum is encouraging us to use
code to cover diffferences in parts where simple data in here would
be cleaner.


>  		.gain_min = -11500,
>  		.gain_max = 20000,
>  	},
> +	[ID_ADRF5720] = {

Refactor step 1:  Add everything in the switch statements based
on ID as data in here.  Looks like the channel arrays, a flag
for gpio presence and a few more constants like the ones already here.


> +		.gain_min = -31500,
> +		.gain_max = 0,
> +	},
> +	[ID_ADRF5730] = {
> +		.gain_min = -31500,
> +		.gain_max = 0,
> +	},
> +	[ID_ADRF5731] = {
> +		.gain_min = -30000,
> +		.gain_max = 0,
> +	},
> +	[ID_HMC271] = {
> +		.gain_min = -31000,
> +		.gain_max = 0,
> +	},
>  	[ID_HMC792] = {
>  		.gain_min = -15750,
>  		.gain_max = 0,
>  	},
> +	[ID_HMC1018] = {
> +		.gain_min = -31000,
> +		.gain_max = 0,
> +	},
> +	[ID_HMC1019] = {
> +		.gain_min = -15500,
> +		.gain_max = 0,
> +	},
>  	[ID_HMC1119] = {
>  		.gain_min = -31750,
>  		.gain_max = 0,
> @@ -95,9 +131,17 @@ static int ad8366_write(struct iio_dev *indio_dev,
>  		st->data[0] = ch_a & 0x1F;
>  		break;
>  	case ID_ADL5240:
> +	case ID_ADRF5720:
> +	case ID_ADRF5730:
> +	case ID_ADRF5731:
>  		st->data[0] = (ch_a & 0x3F);
>  		break;
> +	case ID_HMC271:
> +		st->data[0] = bitrev8(ch_a & 0x1F) >> 3;
> +		break;
>  	case ID_HMC792:
> +	case ID_HMC1018:
> +	case ID_HMC1019:
>  	case ID_HMC1119:
>  		st->data[0] = ch_a;
>  		break;
> @@ -135,9 +179,23 @@ static int ad8366_read_raw(struct iio_dev *indio_dev,
>  		case ID_ADL5240:
>  			gain = 20000 - 31500 + code * 500;
>  			break;
> +		case ID_ADRF5720:
> +		case ID_ADRF5730:
> +			gain = -1 * code * 500;
> +			break;
> +		case ID_ADRF5731:
> +			gain = -1 * code * 500;
> +			break;
>  		case ID_HMC792:
>  			gain = -1 * code * 500;
>  			break;
> +		case ID_HMC271:
> +		case ID_HMC1018:
> +			gain = -31000 + code * 1000;
> +			break;
> +		case ID_HMC1019:
> +			gain = -15500 + code * 500;
> +			break;
>  		case ID_HMC1119:
>  			gain = -1 * code * 250;
>  			break;
> @@ -187,9 +245,23 @@ static int ad8366_write_raw(struct iio_dev *indio_dev,
>  	case ID_ADL5240:
>  		code = ((gain - 500 - 20000) / 500) & 0x3F;
>  		break;
> +	case ID_ADRF5720:
> +	case ID_ADRF5730:
> +		code = (abs(gain) / 500) & 0x3F;
> +		break;
> +	case ID_ADRF5731:
> +		code = (abs(gain) / 500) & 0x3C;
> +		break;
>  	case ID_HMC792:
>  		code = (abs(gain) / 500) & 0x3F;
>  		break;
> +	case ID_HMC271:
> +	case ID_HMC1018:
> +		code = ((gain - 1000) / 1000) & 0x1F;
> +		break;
> +	case ID_HMC1019:
> +		code = ((gain - 500) / 500) & 0x1F;
> +		break;
>  	case ID_HMC1119:
>  		code = (abs(gain) / 250) & 0x7F;
>  		break;
> @@ -275,8 +347,14 @@ static int ad8366_probe(struct spi_device *spi)
>  		break;
>  	case ID_ADA4961:
>  	case ID_ADL5240:
> +	case ID_HMC271:
>  	case ID_HMC792:
>  	case ID_HMC1119:
> +	case ID_ADRF5720:
> +	case ID_ADRF5730:
> +	case ID_ADRF5731:
> +	case ID_HMC1018:
> +	case ID_HMC1019:
>  		st->reset_gpio = devm_gpiod_get_optional(&spi->dev, "reset", GPIOD_OUT_HIGH);
>  		if (IS_ERR(st->reset_gpio)) {
>  			ret = PTR_ERR(st->reset_gpio);
> @@ -335,8 +413,14 @@ static void ad8366_remove(struct spi_device *spi)
>  static const struct spi_device_id ad8366_id[] = {
>  	{"ad8366",  ID_AD8366},
>  	{"ada4961", ID_ADA4961},
> +	{"adrf5720", ID_ADRF5720},
> +	{"adrf5730", ID_ADRF5730},
> +	{"adrf5731", ID_ADRF5731},
>  	{"adl5240", ID_ADL5240},
> +	{"hmc271a", ID_HMC271},
>  	{"hmc792a", ID_HMC792},
> +	{"hmc1018a", ID_HMC1018},
> +	{"hmc1019a", ID_HMC1019},
>  	{"hmc1119", ID_HMC1119},
>  	{ }
>  };
> 


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

* Re: [PATCH 5/7] iio: amplifiers: ad8366: use cleanup.h mutex guard
  2026-01-19 14:43   ` Krzysztof Kozlowski
@ 2026-01-23  8:36     ` Jonathan Cameron
  0 siblings, 0 replies; 17+ messages in thread
From: Jonathan Cameron @ 2026-01-23  8:36 UTC (permalink / raw)
  To: Krzysztof Kozlowski
  Cc: rodrigo.alencar, linux-kernel, linux-iio, devicetree,
	Michael Hennerich, Lars-Peter Clausen, David Lechner,
	Andy Shevchenko, Rob Herring, Krzysztof Kozlowski, Conor Dooley

On Mon, 19 Jan 2026 15:43:07 +0100
Krzysztof Kozlowski <krzk@kernel.org> wrote:

> On 19/01/2026 15:36, Rodrigo Alencar via B4 Relay wrote:
> > From: Rodrigo Alencar <rodrigo.alencar@analog.com>
> > 
> > Changes related to mutex handling:
> > - use guard() from cleanup for mutex locking
> > - replace mutex_init() for devm_mutex_init()  
> 
> Why? We see all this from the diff but I do not see benefits.

Also, 2 patches as two different things.
That should make it easier to say what benefits of each is.

A little more comment on comments inline.


> 
> > 
> > Signed-off-by: Rodrigo Alencar <rodrigo.alencar@analog.com>
> > ---
> >  drivers/iio/amplifiers/ad8366.c | 14 +++++++++-----
> >  1 file changed, 9 insertions(+), 5 deletions(-)
> > 
> > diff --git a/drivers/iio/amplifiers/ad8366.c b/drivers/iio/amplifiers/ad8366.c
> > index 160a8ab0c2ee..26856cb4216e 100644
> > --- a/drivers/iio/amplifiers/ad8366.c
> > +++ b/drivers/iio/amplifiers/ad8366.c
> > @@ -17,6 +17,7 @@
> >   * Copyright 2012-2026 Analog Devices Inc.
> >   */
> >  
> > +#include <linux/cleanup.h>
> >  #include <linux/device.h>
> >  #include <linux/kernel.h>
> >  #include <linux/slab.h>
> > @@ -164,7 +165,8 @@ static int ad8366_read_raw(struct iio_dev *indio_dev,
> >  	int ret;
> >  	int code, gain = 0;
> >  
> > -	mutex_lock(&st->lock);
> > +	guard(mutex)(&st->lock);
> > +
> >  	switch (m) {
> >  	case IIO_CHAN_INFO_HARDWAREGAIN:
> >  		code = st->ch[chan->channel];
> > @@ -210,7 +212,6 @@ static int ad8366_read_raw(struct iio_dev *indio_dev,
> >  	default:
> >  		ret = -EINVAL;
> >  	}
> > -	mutex_unlock(&st->lock);  
> 
> This does not simplify code.
Agreed. Without moving to early returns there is little point in this change.
With early returns the argument of easier code flow can be made
though it isn't particularly strong in this case as only two exit
paths and they are right next to each other.

> 
> >  
> >  	return ret;
> >  };
> > @@ -267,7 +268,8 @@ static int ad8366_write_raw(struct iio_dev *indio_dev,
> >  		break;
> >  	}
> >  
> > -	mutex_lock(&st->lock);
> > +	guard(mutex)(&st->lock);  
> 
> Neither this.
With early returns this one is more obviously useful. Then can argue
above is for consistency.
> 
> > +
> >  	switch (mask) {
> >  	case IIO_CHAN_INFO_HARDWAREGAIN:
> >  		st->ch[chan->channel] = code;
> > @@ -276,7 +278,6 @@ static int ad8366_write_raw(struct iio_dev *indio_dev,
> >  	default:
> >  		ret = -EINVAL;
> >  	}
> > -	mutex_unlock(&st->lock);
> >  
> >  	return ret;
> >  }
> > @@ -336,10 +337,13 @@ static int ad8366_probe(struct spi_device *spi)
> >  	}
> >  
> >  	spi_set_drvdata(spi, indio_dev);
> > -	mutex_init(&st->lock);
> >  	st->spi = spi;
> >  	st->type = spi_get_device_id(spi)->driver_data;
> >  
> > +	ret = devm_mutex_init(&spi->dev, &st->lock);  
> 
> And this one actually has impact - missing mutex_destroy...
> 
> > +	if (ret)
> > +		return ret;
> > +
> >  	switch (st->type) {
> >  	case ID_AD8366:
> >  		indio_dev->channels = ad8366_channels;
> >   
> 
> 
> Best regards,
> Krzysztof


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

* Re: [PATCH 4/7] iio: amplifiers: ad8366: Update device support
  2026-01-23  8:33   ` Jonathan Cameron
@ 2026-01-23  8:38     ` Jonathan Cameron
  0 siblings, 0 replies; 17+ messages in thread
From: Jonathan Cameron @ 2026-01-23  8:38 UTC (permalink / raw)
  To: Rodrigo Alencar via B4 Relay
  Cc: rodrigo.alencar, linux-kernel, linux-iio, devicetree,
	Michael Hennerich, Lars-Peter Clausen, David Lechner,
	Andy Shevchenko, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Alexandru Ardelean

On Fri, 23 Jan 2026 08:33:18 +0000
Jonathan Cameron <jic23@kernel.org> wrote:

> On Mon, 19 Jan 2026 14:36:58 +0000
> Rodrigo Alencar via B4 Relay <devnull+rodrigo.alencar.analog.com@kernel.org> wrote:
> 
> > From: Rodrigo Alencar <rodrigo.alencar@analog.com>
> > 
> > This patch adds support for following digital step attenuators:
> > 
> >  * HMC271A: 1dB LSB 5-Bit Digital Attenuator SMT, 0.7 - 3.7 GHz
> >  * ADRF5720: 0.5 dB LSB, 6-Bit, Digital Attenuator, 9 kHz to 40 GHz
> >  * ADRF5730: 0.5 dB LSB, 6-Bit, Digital Attenuator, 100 MHz to 40 GHz
> >  * ADRF5731: 2 dB LSB, 4-Bit, Digital Attenuator, 100 MHz to 40 GHz
> >  * HMC1018A: 1.0 dB LSB GaAs MMIC 5-BIT DIGITAL ATTENUATOR, 0.1 - 30 GHz
> >  * HMC1019A: 0.5 dB LSB GaAs MMIC 5-BIT DIGITAL ATTENUATOR, 0.1 - 30 GHz
> > 
> > Additionally, copyright notice was updated with current year.
> > 
> > Co-developed-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
> > Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
> > Co-developed-by: Michael Hennerich <michael.hennerich@analog.com>
> > Signed-off-by: Michael Hennerich <michael.hennerich@analog.com>
> > Signed-off-by: Rodrigo Alencar <rodrigo.alencar@analog.com>  
> 
> I don't want to delay this series if possible (needs to be ready early next
> week to meet the merge window cut off) so the stuff below can be in a follow
> up series if you prefer.  It is fairly simple so if you want to do it before
> these new parts are added, even better.

Actually. I changed my mind.  For some reason I thought this was several
versions in and I'd failed to note this earlier!

As a new series, please add this stuff as part of the early cleanup before
adding new devices.

> 
> They will make further additions to this driver simpler and easier to review.
> > ---
> >  drivers/iio/amplifiers/Kconfig  |  6 +++
> >  drivers/iio/amplifiers/ad8366.c | 86 ++++++++++++++++++++++++++++++++++++++++-
> >  2 files changed, 91 insertions(+), 1 deletion(-)
> > 
> > diff --git a/drivers/iio/amplifiers/Kconfig b/drivers/iio/amplifiers/Kconfig
> > index a8a604863eed..39d280d4d437 100644
> > --- a/drivers/iio/amplifiers/Kconfig
> > +++ b/drivers/iio/amplifiers/Kconfig
> > @@ -18,7 +18,13 @@ config AD8366
> >  	    AD8366 Dual-Digital Variable Gain Amplifier (VGA)
> >  	    ADA4961 BiCMOS RF Digital Gain Amplifier (DGA)
> >  	    ADL5240 Digitally controlled variable gain amplifier (VGA)
> > +	    ADRF5720: 0.5 dB LSB, 6-Bit, Silicon Digital Attenuator
> > +	    ADRF5730: 0.5 dB LSB, 6-Bit, Silicon Digital Attenuator
> > +	    ADRF5731: 2 dB LSB, 4-Bit, Silicon Digital Attenuator
> > +	    HMC271A: 1dB LSB 5-Bit Digital Attenuator SMT
> >  	    HMC792A 0.25 dB LSB GaAs MMIC 6-Bit Digital Attenuator
> > +	    HMC1018A: 1.0 dB LSB GaAs MMIC 5-BIT Digital Attenuator
> > +	    HMC1019A: 0.5 dB LSB GaAs MMIC 5-BIT Digital Attenuator
> >  	    HMC1119 0.25 dB LSB, 7-Bit, Silicon Digital Attenuator
> >  
> >  	  To compile this driver as a module, choose M here: the
> > diff --git a/drivers/iio/amplifiers/ad8366.c b/drivers/iio/amplifiers/ad8366.c
> > index 63bb9f0179eb..160a8ab0c2ee 100644
> > --- a/drivers/iio/amplifiers/ad8366.c
> > +++ b/drivers/iio/amplifiers/ad8366.c
> > @@ -5,10 +5,16 @@
> >   *   AD8366 Dual-Digital Variable Gain Amplifier (VGA)
> >   *   ADA4961 BiCMOS RF Digital Gain Amplifier (DGA)
> >   *   ADL5240 Digitally controlled variable gain amplifier (VGA)
> > + *   ADRF5720: 0.5 dB LSB, 6-Bit, Silicon Digital Attenuator, 9 kHz to 40 GHz
> > + *   ADRF5730: 0.5 dB LSB, 6-Bit, Silicon Digital Attenuator, 100 MHz to 40 GHz
> > + *   ADRF5731: 2 dB LSB, 4-Bit, Silicon Digital Attenuator, 100 MHz to 40 GHz
> > + *   HMC271A: 1dB LSB 5-Bit Digital Attenuator SMT, 0.7 - 3.7 GHz
> >   *   HMC792A 0.25 dB LSB GaAs MMIC 6-Bit Digital Attenuator
> > + *   HMC1018A: 1.0 dB LSB GaAs MMIC 5-BIT DIGITAL ATTENUATOR, 0.1 - 30 GHz
> > + *   HMC1019A: 0.5 dB LSB GaAs MMIC 5-BIT DIGITAL ATTENUATOR, 0.1 - 30 GHz
> >   *   HMC1119 0.25 dB LSB, 7-Bit, Silicon Digital Attenuator
> >   *
> > - * Copyright 2012-2019 Analog Devices Inc.
> > + * Copyright 2012-2026 Analog Devices Inc.
> >   */
> >  
> >  #include <linux/device.h>
> > @@ -29,7 +35,13 @@ enum ad8366_type {
> >  	ID_AD8366,
> >  	ID_ADA4961,
> >  	ID_ADL5240,
> > +	ID_ADRF5720,
> > +	ID_ADRF5730,
> > +	ID_ADRF5731,
> > +	ID_HMC271,
> >  	ID_HMC792,
> > +	ID_HMC1018,
> > +	ID_HMC1019,
> >  	ID_HMC1119,
> >  };
> >  
> > @@ -67,10 +79,34 @@ static const struct ad8366_info ad8366_infos[] = {  
> 
> Refactor step 2: Split this up into individual structures and drop
> the enum.  The presence of that enum is encouraging us to use
> code to cover diffferences in parts where simple data in here would
> be cleaner.
> 
> 
> >  		.gain_min = -11500,
> >  		.gain_max = 20000,
> >  	},
> > +	[ID_ADRF5720] = {  
> 
> Refactor step 1:  Add everything in the switch statements based
> on ID as data in here.  Looks like the channel arrays, a flag
> for gpio presence and a few more constants like the ones already here.
> 
> 
> > +		.gain_min = -31500,
> > +		.gain_max = 0,
> > +	},
> > +	[ID_ADRF5730] = {
> > +		.gain_min = -31500,
> > +		.gain_max = 0,
> > +	},
> > +	[ID_ADRF5731] = {
> > +		.gain_min = -30000,
> > +		.gain_max = 0,
> > +	},
> > +	[ID_HMC271] = {
> > +		.gain_min = -31000,
> > +		.gain_max = 0,
> > +	},
> >  	[ID_HMC792] = {
> >  		.gain_min = -15750,
> >  		.gain_max = 0,
> >  	},
> > +	[ID_HMC1018] = {
> > +		.gain_min = -31000,
> > +		.gain_max = 0,
> > +	},
> > +	[ID_HMC1019] = {
> > +		.gain_min = -15500,
> > +		.gain_max = 0,
> > +	},
> >  	[ID_HMC1119] = {
> >  		.gain_min = -31750,
> >  		.gain_max = 0,
> > @@ -95,9 +131,17 @@ static int ad8366_write(struct iio_dev *indio_dev,
> >  		st->data[0] = ch_a & 0x1F;
> >  		break;
> >  	case ID_ADL5240:
> > +	case ID_ADRF5720:
> > +	case ID_ADRF5730:
> > +	case ID_ADRF5731:
> >  		st->data[0] = (ch_a & 0x3F);
> >  		break;
> > +	case ID_HMC271:
> > +		st->data[0] = bitrev8(ch_a & 0x1F) >> 3;
> > +		break;
> >  	case ID_HMC792:
> > +	case ID_HMC1018:
> > +	case ID_HMC1019:
> >  	case ID_HMC1119:
> >  		st->data[0] = ch_a;
> >  		break;
> > @@ -135,9 +179,23 @@ static int ad8366_read_raw(struct iio_dev *indio_dev,
> >  		case ID_ADL5240:
> >  			gain = 20000 - 31500 + code * 500;
> >  			break;
> > +		case ID_ADRF5720:
> > +		case ID_ADRF5730:
> > +			gain = -1 * code * 500;
> > +			break;
> > +		case ID_ADRF5731:
> > +			gain = -1 * code * 500;
> > +			break;
> >  		case ID_HMC792:
> >  			gain = -1 * code * 500;
> >  			break;
> > +		case ID_HMC271:
> > +		case ID_HMC1018:
> > +			gain = -31000 + code * 1000;
> > +			break;
> > +		case ID_HMC1019:
> > +			gain = -15500 + code * 500;
> > +			break;
> >  		case ID_HMC1119:
> >  			gain = -1 * code * 250;
> >  			break;
> > @@ -187,9 +245,23 @@ static int ad8366_write_raw(struct iio_dev *indio_dev,
> >  	case ID_ADL5240:
> >  		code = ((gain - 500 - 20000) / 500) & 0x3F;
> >  		break;
> > +	case ID_ADRF5720:
> > +	case ID_ADRF5730:
> > +		code = (abs(gain) / 500) & 0x3F;
> > +		break;
> > +	case ID_ADRF5731:
> > +		code = (abs(gain) / 500) & 0x3C;
> > +		break;
> >  	case ID_HMC792:
> >  		code = (abs(gain) / 500) & 0x3F;
> >  		break;
> > +	case ID_HMC271:
> > +	case ID_HMC1018:
> > +		code = ((gain - 1000) / 1000) & 0x1F;
> > +		break;
> > +	case ID_HMC1019:
> > +		code = ((gain - 500) / 500) & 0x1F;
> > +		break;
> >  	case ID_HMC1119:
> >  		code = (abs(gain) / 250) & 0x7F;
> >  		break;
> > @@ -275,8 +347,14 @@ static int ad8366_probe(struct spi_device *spi)
> >  		break;
> >  	case ID_ADA4961:
> >  	case ID_ADL5240:
> > +	case ID_HMC271:
> >  	case ID_HMC792:
> >  	case ID_HMC1119:
> > +	case ID_ADRF5720:
> > +	case ID_ADRF5730:
> > +	case ID_ADRF5731:
> > +	case ID_HMC1018:
> > +	case ID_HMC1019:
> >  		st->reset_gpio = devm_gpiod_get_optional(&spi->dev, "reset", GPIOD_OUT_HIGH);
> >  		if (IS_ERR(st->reset_gpio)) {
> >  			ret = PTR_ERR(st->reset_gpio);
> > @@ -335,8 +413,14 @@ static void ad8366_remove(struct spi_device *spi)
> >  static const struct spi_device_id ad8366_id[] = {
> >  	{"ad8366",  ID_AD8366},
> >  	{"ada4961", ID_ADA4961},
> > +	{"adrf5720", ID_ADRF5720},
> > +	{"adrf5730", ID_ADRF5730},
> > +	{"adrf5731", ID_ADRF5731},
> >  	{"adl5240", ID_ADL5240},
> > +	{"hmc271a", ID_HMC271},
> >  	{"hmc792a", ID_HMC792},
> > +	{"hmc1018a", ID_HMC1018},
> > +	{"hmc1019a", ID_HMC1019},
> >  	{"hmc1119", ID_HMC1119},
> >  	{ }
> >  };
> >   
> 


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

* Re: [PATCH 7/7] iio: amplifiers: ad8366: add device tree support
  2026-01-19 14:47   ` Krzysztof Kozlowski
@ 2026-01-23  8:42     ` Jonathan Cameron
  0 siblings, 0 replies; 17+ messages in thread
From: Jonathan Cameron @ 2026-01-23  8:42 UTC (permalink / raw)
  To: Krzysztof Kozlowski
  Cc: rodrigo.alencar, linux-kernel, linux-iio, devicetree,
	Michael Hennerich, Lars-Peter Clausen, David Lechner,
	Andy Shevchenko, Rob Herring, Krzysztof Kozlowski, Conor Dooley

On Mon, 19 Jan 2026 15:47:46 +0100
Krzysztof Kozlowski <krzk@kernel.org> wrote:

> On 19/01/2026 15:37, Rodrigo Alencar via B4 Relay wrote:
> > +	st->reset_gpio = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH);
> > +	if (IS_ERR(st->reset_gpio))
> > +		return dev_err_probe(dev, PTR_ERR(st->reset_gpio),
> > +				     "Failed to get reset GPIO\n");
> >  
> > -		st->enable_gpio = devm_gpiod_get_optional(dev, "enable", GPIOD_OUT_HIGH);
> > -		if (IS_ERR(st->enable_gpio))
> > -			return dev_err_probe(dev, PTR_ERR(st->enable_gpio),
> > -					     "Failed to get enable GPIO\n");
> > +	st->enable_gpio = devm_gpiod_get_optional(dev, "enable", GPIOD_OUT_HIGH);  
> 
> No, you are changing the same line *third* time. you need to organize
> your patchset in logical way but also in a readable. You do not add
> incorrect code just to change it later.
> 
> I do not see the reason behind removal of switch case. It's really
> independent change of OF support which must come with its own
> justification of affecting other platforms.

FWIW, I was about to write the same about this set needing a thorough
reorganize. From a quick look at this last patch I'm probably fine
with everything it contains, but it's 3+ patches rolled into one
and I'd also like the big array of chip_info broken up and the enum
gone as mentioned in earlier patch.

Thanks,

Jonathan


> 
> 
> > +	if (IS_ERR(st->enable_gpio))
> > +		return dev_err_probe(dev, PTR_ERR(st->enable_gpio),
> > +				     "Failed to get enable GPIO\n");
> >  
> > -		indio_dev->channels = ada4961_channels;
> > -		indio_dev->num_channels = ARRAY_SIZE(ada4961_channels);
> > -		break;
> > -	default:
> > -		return dev_err_probe(dev, -EINVAL, "Invalid device ID\n");
> > -	}
> > -
> > -	st->info = &ad8366_infos[st->type];
> >  	indio_dev->name = spi_get_device_id(spi)->name;
> >  	indio_dev->info = &ad8366_info;
> > +	indio_dev->channels = ad8366_channels;
> > +	indio_dev->num_channels = st->info->num_channels;
> >  	indio_dev->modes = INDIO_DIRECT_MODE;
> >  
> > -	ret = ad8366_write(indio_dev, 0, 0);
> > +	ret = ad8366_write_code(st);
> >  	if (ret < 0)
> >  		return dev_err_probe(dev, ret, "failed to write initial gain\n");
> >  
> > @@ -384,24 +322,41 @@ static int ad8366_probe(struct spi_device *spi)
> >  }  
> 
> 
> Best regards,
> Krzysztof
> 


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

end of thread, other threads:[~2026-01-23  8:42 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-01-19 14:36 [PATCH 0/7] iio: amplifiers: ad8366: driver update and dt support Rodrigo Alencar via B4 Relay
2026-01-19 14:36 ` [PATCH 1/7] MAINTAINERS: Add missing maintainer entry for AD8366 driver Rodrigo Alencar via B4 Relay
2026-01-19 14:36 ` [PATCH 2/7] dt-bindings: iio: amplifiers: Add AD8366 support Rodrigo Alencar via B4 Relay
2026-01-21  8:10   ` Krzysztof Kozlowski
2026-01-19 14:36 ` [PATCH 3/7] iio: amplifiers: ad8366: consume enable gpio for applicable parts Rodrigo Alencar via B4 Relay
2026-01-23  8:26   ` Jonathan Cameron
2026-01-19 14:36 ` [PATCH 4/7] iio: amplifiers: ad8366: Update device support Rodrigo Alencar via B4 Relay
2026-01-23  8:33   ` Jonathan Cameron
2026-01-23  8:38     ` Jonathan Cameron
2026-01-19 14:36 ` [PATCH 5/7] iio: amplifiers: ad8366: use cleanup.h mutex guard Rodrigo Alencar via B4 Relay
2026-01-19 14:43   ` Krzysztof Kozlowski
2026-01-23  8:36     ` Jonathan Cameron
2026-01-19 14:37 ` [PATCH 6/7] iio: amplifiers: ad8366: simplify resource management Rodrigo Alencar via B4 Relay
2026-01-19 14:45   ` Krzysztof Kozlowski
2026-01-19 14:37 ` [PATCH 7/7] iio: amplifiers: ad8366: add device tree support Rodrigo Alencar via B4 Relay
2026-01-19 14:47   ` Krzysztof Kozlowski
2026-01-23  8:42     ` Jonathan Cameron

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

all inboxes | Powered by JetHome®