Skip to contentSkip to conversation

Add support for AD7091R-2/-4/-8

PATCH Superseded [email protected] 4 participants 13 messages Nov 21, 2023 – Nov 23, 2023

Subsystems (4)

v1 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

[email protected]

author maintainer
#0 lore raw

cover Add support for AD7091R-2/-4/-8

From: Marcelo Schmitt <[email protected]>

This series adds support for AD7091R-2/-4/-8 ADCs which can do single shot or sequenced readings. Threshold events are also supported.
Overall, AD7091R-2/-4/-8 are very similar to AD7091R-5 except they use SPI interface.

This has been tested with raspberrypi and eval board on kernel 6.1 from ADI fork.

Marcelo Schmitt (7):
iio: adc: ad7091r-base: Set alert config and drvdata
MAINTAINERS: Add MAINTAINERS entry for AD7091R
iio: adc: ad7091r: Move defines to header file
iio: adc: ad7091r: Alloc IIO device before generic probe
dt-bindings: iio: Add binding documentation for AD7091R-8
iio: adc: Add support for AD7091R-8
iio: adc: ad7091r-base: Add debugfs reg access

 .../bindings/iio/adc/adi,ad7091r8.yaml        | 101 +++++++
 MAINTAINERS                                   |  12 +
 drivers/iio/adc/Kconfig                       |  16 ++
 drivers/iio/adc/Makefile                      |   4 +-
 drivers/iio/adc/ad7091r-base.c                |  98 ++++---
 drivers/iio/adc/ad7091r-base.h                |  82 +++++-
 drivers/iio/adc/ad7091r5.c                    |  55 ++--
 drivers/iio/adc/ad7091r8.c                    | 272 ++++++++++++++++++
 8 files changed, 551 insertions(+), 89 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/iio/adc/adi,ad7091r8.yaml
 create mode 100644 drivers/iio/adc/ad7091r8.c
Signature · 1 line
2.42.0
author maintainer
#1 lore raw

PATCH 1/7 iio: adc: ad7091r-base: Set alert config and drvdata

From: Marcelo Schmitt <[email protected]>

Write 1 to bit 4 in the configuration register to set ALERT/BUSY/GPO pin to be used as ALERT.
Set device driver data so it can be retrieved when handling alert events, avoiding null pointer dereference.

Fixes <ca69300173b6> (iio: adc: Add support for AD7091R5 ADC)
---
 drivers/iio/adc/ad7091r-base.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
drivers/iio/adc/ad7091r-base.c +10 -2
index 8e252cde735b..3ecac3164446 100644
@@ -28,6 +28,7 @@
 #define AD7091R_REG_RESULT_CONV_RESULT(x)   ((x) & 0xfff)
 
 /* AD7091R_REG_CONF */
+#define AD7091R_REG_CONF_ALERT_EN   BIT(4)
 #define AD7091R_REG_CONF_AUTO   BIT(8)
 #define AD7091R_REG_CONF_CMD    BIT(10)
 
@@ -232,9 +233,16 @@ int ad7091r_probe(struct device *dev, const char *name,
 	iio_dev->channels = chip_info->channels;
 
 	if (irq) {
+		ret = regmap_update_bits(st->map, AD7091R_REG_CONF,
+					 AD7091R_REG_CONF_ALERT_EN, BIT(4));
+		if (ret)
+			return ret;
+
+		dev_set_drvdata(st->dev, iio_dev);
 		ret = devm_request_threaded_irq(dev, irq, NULL,
-				ad7091r_event_handler,
-				IRQF_TRIGGER_FALLING | IRQF_ONESHOT, name, st);
+						ad7091r_event_handler,
+						IRQF_TRIGGER_FALLING |
+						IRQF_ONESHOT, name, st);
 		if (ret)
 			return ret;
 	}
Signature · 1 line
2.42.0
author maintainer
#2 lore raw

PATCH 2/7 MAINTAINERS: Add MAINTAINERS entry for AD7091R

In reply to [email protected]

From: Marcelo Schmitt <[email protected]>

The driver for AD7091R was added in
ca693001: iio: adc: Add support for AD7091R5 ADC but no MAINTAINERS file entry was added for it since then. Add a proper MAINTAINERS file entry for the AD7091R driver.

---
 MAINTAINERS | 10 ++++++++++
 1 file changed, 10 insertions(+)
MAINTAINERS +10 -0
index 8e0a91dc8251..008f0e73bead 100644
@@ -1126,6 +1126,16 @@ F:	Documentation/ABI/testing/sysfs-bus-iio-adc-ad4130
 F:	Documentation/devicetree/bindings/iio/adc/adi,ad4130.yaml
 F:	drivers/iio/adc/ad4130.c
 
+ANALOG DEVICES INC AD7091R DRIVER
+M:	Marcelo Schmitt <[email protected]>
+L:	[email protected]
+S:	Supported
+W:	http://ez.analog.com/community/linux-device-drivers
+F:	Documentation/devicetree/bindings/iio/adc/adi,ad7091r5.yaml
+F:	drivers/iio/adc/drivers/iio/adc/ad7091r-base.c
+F:	drivers/iio/adc/drivers/iio/adc/ad7091r-base.h
+F:	drivers/iio/adc/drivers/iio/adc/ad7091r5.c
+
 ANALOG DEVICES INC AD7192 DRIVER
 M:	Alexandru Tachici <[email protected]>
 L:	[email protected]
Signature · 1 line
2.42.0
author maintainer
#3 lore raw

PATCH 3/7 iio: adc: ad7091r: Move defines to header file

In reply to [email protected]

From: Marcelo Schmitt <[email protected]>

Move AD7091R register, channel and event definitions to the header file so other AD7091R device drivers may use those declaration in follow up patches.

---
 drivers/iio/adc/ad7091r-base.c | 14 +++--------
 drivers/iio/adc/ad7091r-base.h | 45 ++++++++++++++++++++++++++++++++++
 drivers/iio/adc/ad7091r5.c     | 39 +++--------------------------
 3 files changed, 53 insertions(+), 45 deletions(-)
drivers/iio/adc/ad7091r-base.c +4 -10
index 3ecac3164446..ebf1c8cca25c 100644
@@ -15,14 +15,6 @@
 
 #include "ad7091r-base.h"
 
-#define AD7091R_REG_RESULT  0
-#define AD7091R_REG_CHANNEL 1
-#define AD7091R_REG_CONF    2
-#define AD7091R_REG_ALERT   3
-#define AD7091R_REG_CH_LOW_LIMIT(ch) ((ch) * 3 + 4)
-#define AD7091R_REG_CH_HIGH_LIMIT(ch) ((ch) * 3 + 5)
-#define AD7091R_REG_CH_HYSTERESIS(ch) ((ch) * 3 + 6)
-
 /* AD7091R_REG_RESULT */
 #define AD7091R_REG_RESULT_CH_ID(x)	    (((x) >> 13) & 0x3)
 #define AD7091R_REG_RESULT_CONV_RESULT(x)   ((x) & 0xfff)
@@ -270,7 +262,7 @@ int ad7091r_probe(struct device *dev, const char *name,
 }
 EXPORT_SYMBOL_NS_GPL(ad7091r_probe, IIO_AD7091R);
 
-static bool ad7091r_writeable_reg(struct device *dev, unsigned int reg)
+bool ad7091r_writeable_reg(struct device *dev, unsigned int reg)
 {
 	switch (reg) {
 	case AD7091R_REG_RESULT:
@@ -280,8 +272,9 @@ static bool ad7091r_writeable_reg(struct device *dev, unsigned int reg)
 		return true;
 	}
 }
+EXPORT_SYMBOL_NS_GPL(ad7091r_writeable_reg, IIO_AD7091R);
 
-static bool ad7091r_volatile_reg(struct device *dev, unsigned int reg)
+bool ad7091r_volatile_reg(struct device *dev, unsigned int reg)
 {
 	switch (reg) {
 	case AD7091R_REG_RESULT:
@@ -291,6 +284,7 @@ static bool ad7091r_volatile_reg(struct device *dev, unsigned int reg)
 		return false;
 	}
 }
+EXPORT_SYMBOL_NS_GPL(ad7091r_volatile_reg, IIO_AD7091R);
 
 const struct regmap_config ad7091r_regmap_config = {
 	.reg_bits = 8,
drivers/iio/adc/ad7091r-base.h +45 -0

61 lines not on this page · raw message

drivers/iio/adc/ad7091r5.c +4 -35
index 2f048527b7b7..9d3ccfca94ec 100644
@@ -12,42 +12,11 @@
 
 #include "ad7091r-base.h"
 
-static const struct iio_event_spec ad7091r5_events[] = {
-	{
-		.type = IIO_EV_TYPE_THRESH,
-		.dir = IIO_EV_DIR_RISING,
-		.mask_separate = BIT(IIO_EV_INFO_VALUE) |
-				 BIT(IIO_EV_INFO_ENABLE),
-	},
-	{
-		.type = IIO_EV_TYPE_THRESH,
-		.dir = IIO_EV_DIR_FALLING,
-		.mask_separate = BIT(IIO_EV_INFO_VALUE) |
-				 BIT(IIO_EV_INFO_ENABLE),
-	},
-	{
-		.type = IIO_EV_TYPE_THRESH,
-		.dir = IIO_EV_DIR_EITHER,
-		.mask_separate = BIT(IIO_EV_INFO_HYSTERESIS),
-	},
-};
-
-#define AD7091R_CHANNEL(idx, bits, ev, num_ev) { \
-	.type = IIO_VOLTAGE, \
-	.info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
-	.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \
-	.indexed = 1, \
-	.channel = idx, \
-	.event_spec = ev, \
-	.num_event_specs = num_ev, \
-	.scan_type.storagebits = 16, \
-	.scan_type.realbits = bits, \
-}
 static const struct iio_chan_spec ad7091r5_channels_irq[] = {
-	AD7091R_CHANNEL(0, 12, ad7091r5_events, ARRAY_SIZE(ad7091r5_events)),
-	AD7091R_CHANNEL(1, 12, ad7091r5_events, ARRAY_SIZE(ad7091r5_events)),
-	AD7091R_CHANNEL(2, 12, ad7091r5_events, ARRAY_SIZE(ad7091r5_events)),
-	AD7091R_CHANNEL(3, 12, ad7091r5_events, ARRAY_SIZE(ad7091r5_events)),
+	AD7091R_CHANNEL(0, 12, ad7091r_events, ARRAY_SIZE(ad7091r_events)),
+	AD7091R_CHANNEL(1, 12, ad7091r_events, ARRAY_SIZE(ad7091r_events)),
+	AD7091R_CHANNEL(2, 12, ad7091r_events, ARRAY_SIZE(ad7091r_events)),
+	AD7091R_CHANNEL(3, 12, ad7091r_events, ARRAY_SIZE(ad7091r_events)),
 };
 
 static const struct iio_chan_spec ad7091r5_channels_noirq[] = {
Signature · 1 line
2.42.0
author maintainer
#5 lore raw

PATCH 4/7 iio: adc: ad7091r: Alloc IIO device before generic probe

In reply to [email protected]

From: Marcelo Schmitt <[email protected]>

Rework ad7091r probe functions so the IIO device is allocated before the generic device probe function is called.
This change is needed for a follow up patch that passes a pointer to the IIO device to a couple of regmap callback functions.

---
 drivers/iio/adc/ad7091r-base.c | 35 +++++++---------------------------
 drivers/iio/adc/ad7091r-base.h | 22 +++++++++++++++++----
 drivers/iio/adc/ad7091r5.c     | 14 ++++++++++++--
 3 files changed, 37 insertions(+), 34 deletions(-)
drivers/iio/adc/ad7091r-base.c +7 -28
index ebf1c8cca25c..69cb5ccdbc49 100644
@@ -27,21 +27,6 @@
 #define AD7091R_REG_CONF_MODE_MASK  \
 	(AD7091R_REG_CONF_AUTO | AD7091R_REG_CONF_CMD)
 
-enum ad7091r_mode {
-	AD7091R_MODE_SAMPLE,
-	AD7091R_MODE_COMMAND,
-	AD7091R_MODE_AUTOCYCLE,
-};
-
-struct ad7091r_state {
-	struct device *dev;
-	struct regmap *map;
-	struct regulator *vref;
-	const struct ad7091r_chip_info *chip_info;
-	enum ad7091r_mode mode;
-	struct mutex lock; /*lock to prevent concurent reads */
-};
-
 static int ad7091r_set_mode(struct ad7091r_state *st, enum ad7091r_mode mode)
 {
 	int ret, conf;
@@ -200,20 +185,14 @@ static void ad7091r_remove(void *data)
 	regulator_disable(st->vref);
 }
 
-int ad7091r_probe(struct device *dev, const char *name,
-		const struct ad7091r_chip_info *chip_info,
-		struct regmap *map, int irq)
+int ad7091r_probe(struct iio_dev *iio_dev, const char *name,
+		  const struct ad7091r_chip_info *chip_info,
+		  struct regmap *map, int irq)
 {
-	struct iio_dev *iio_dev;
 	struct ad7091r_state *st;
 	int ret;
 
-	iio_dev = devm_iio_device_alloc(dev, sizeof(*st));
-	if (!iio_dev)
-		return -ENOMEM;
-
 	st = iio_priv(iio_dev);
-	st->dev = dev;
 	st->chip_info = chip_info;
 	st->map = map;
 
@@ -231,7 +210,7 @@ int ad7091r_probe(struct device *dev, const char *name,
 			return ret;
 
 		dev_set_drvdata(st->dev, iio_dev);
-		ret = devm_request_threaded_irq(dev, irq, NULL,
+		ret = devm_request_threaded_irq(st->dev, irq, NULL,
 						ad7091r_event_handler,
 						IRQF_TRIGGER_FALLING |
 						IRQF_ONESHOT, name, st);
@@ -239,7 +218,7 @@ int ad7091r_probe(struct device *dev, const char *name,
 			return ret;
 	}
 
-	st->vref = devm_regulator_get_optional(dev, "vref");
+	st->vref = devm_regulator_get_optional(st->dev, "vref");
 	if (IS_ERR(st->vref)) {
 		if (PTR_ERR(st->vref) == -EPROBE_DEFER)
 			return -EPROBE_DEFER;
@@ -248,7 +227,7 @@ int ad7091r_probe(struct device *dev, const char *name,
 		ret = regulator_enable(st->vref);
 		if (ret)
 			return ret;
-		ret = devm_add_action_or_reset(dev, ad7091r_remove, st);
+		ret = devm_add_action_or_reset(st->dev, ad7091r_remove, st);
 		if (ret)
 			return ret;
 	}
@@ -258,7 +237,7 @@ int ad7091r_probe(struct device *dev, const char *name,
 	if (ret)
 		return ret;
 
-	return devm_iio_device_register(dev, iio_dev);
+	return devm_iio_device_register(st->dev, iio_dev);
 }
 EXPORT_SYMBOL_NS_GPL(ad7091r_probe, IIO_AD7091R);
 
drivers/iio/adc/ad7091r-base.h +18 -4
index 2efed8ddc59a..405939f4eee0 100644
@@ -30,7 +30,21 @@
 }
 
 struct device;
-struct ad7091r_state;
+
+enum ad7091r_mode {
+	AD7091R_MODE_SAMPLE,
+	AD7091R_MODE_COMMAND,
+	AD7091R_MODE_AUTOCYCLE,
+};
+
+struct ad7091r_state {
+	struct device *dev;
+	struct regmap *map;
+	struct regulator *vref;
+	const struct ad7091r_chip_info *chip_info;
+	enum ad7091r_mode mode;
+	struct mutex lock; /*lock to prevent concurent reads */
+};
 
 struct ad7091r_chip_info {
 	unsigned int num_channels;
@@ -60,9 +74,9 @@ static const struct iio_event_spec ad7091r_events[] = {
 
 extern const struct regmap_config ad7091r_regmap_config;
 
-int ad7091r_probe(struct device *dev, const char *name,
-		const struct ad7091r_chip_info *chip_info,
-		struct regmap *map, int irq);
+int ad7091r_probe(struct iio_dev *iio_dev, const char *name,
+		  const struct ad7091r_chip_info *chip_info,
+		  struct regmap *map, int irq);
 
 bool ad7091r_volatile_reg(struct device *dev, unsigned int reg);
 
drivers/iio/adc/ad7091r5.c +12 -2
index 9d3ccfca94ec..1a27841d1bbc 100644
@@ -42,8 +42,18 @@ static int ad7091r5_i2c_probe(struct i2c_client *i2c)
 {
 	const struct i2c_device_id *id = i2c_client_get_device_id(i2c);
 	const struct ad7091r_chip_info *chip_info;
-	struct regmap *map = devm_regmap_init_i2c(i2c, &ad7091r_regmap_config);
+	struct ad7091r_state *st;
+	struct iio_dev *iio_dev;
+	struct regmap *map;
 
+	iio_dev = devm_iio_device_alloc(&i2c->dev, sizeof(*st));
+	if (!iio_dev)
+		return -ENOMEM;
+
+	st = iio_priv(iio_dev);
+	st->dev = &i2c->dev;
+
+	map = devm_regmap_init_i2c(i2c, &ad7091r_regmap_config);
 	if (IS_ERR(map))
 		return PTR_ERR(map);
 
@@ -52,7 +62,7 @@ static int ad7091r5_i2c_probe(struct i2c_client *i2c)
 	else
 		chip_info = &ad7091r5_chip_info_noirq;
 
-	return ad7091r_probe(&i2c->dev, id->name, chip_info, map, i2c->irq);
+	return ad7091r_probe(iio_dev, id->name, chip_info, map, i2c->irq);
 }
 
 static const struct of_device_id ad7091r5_dt_ids[] = {
Signature · 1 line
2.42.0
author maintainer
#6 lore raw

PATCH 5/7 dt-bindings: iio: Add binding documentation for AD7091R-8

In reply to [email protected]

From: Marcelo Schmitt <[email protected]>

Add device tree binding documentation for AD7091R-8.

---
 .../bindings/iio/adc/adi,ad7091r8.yaml        | 101 ++++++++++++++++++
 MAINTAINERS                                   |   1 +
 2 files changed, 102 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/adc/adi,ad7091r8.yaml
Documentation/devicetree/bindings/iio/adc/adi,ad7091r8.yaml new file +101 -0
new file mode 100644
index 000000000000..f10b6727737f
@@ -0,0 +1,101 @@
+# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/iio/adc/adi,ad7091r8.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Analog Devices AD7091R8 8-Channel 12-Bit ADC
+
+maintainers:
+  - Marcelo Schmitt <[email protected]>
+
+description: |
+  Analog Devices AD7091R-8 8-Channel 12-Bit ADC
+  https://www.analog.com/media/en/technical-documentation/data-sheets/AD7091R-2_7091R-4_7091R-8.pdf
+
+properties:
+  compatible:
+    enum:
+      - adi,ad7091r2
+      - adi,ad7091r4
+      - adi,ad7091r8
+
+  reg:
+    maxItems: 1
+
+  vref-supply: true
+
+  spi-max-frequency: true
+
+  adi,conversion-start-gpios:
+    description:
+      Device tree identifier of the CONVST pin.
+      This logic input is used to initiate conversions on the analog
+      input channels.
+    maxItems: 1
+
+  reset-gpios:
+    maxItems: 1
+
+  interrupts:
+    maxItems: 1
+
+required:
+  - compatible
+  - reg
+  - adi,conversion-start-gpios
+
+patternProperties:
+  "^channel@[0-7]$":
+    $ref: "adc.yaml"
+    type: object
+    description: Represents the external channels which are connected to the ADC.
+
+    properties:
+      reg:
+        minimum: 0
+        maximum: 7
+
+    required:
+      - reg
+
+allOf:
+  - $ref: /schemas/spi/spi-peripheral-props.yaml#
+
+  # AD7091R-2 does not have ALERT/BUSY/GPO pin
+  - if:
+      properties:
+        compatible:
+          contains:
+            enum:
+              - adi,ad7091r4
+              - adi,ad7091r8
+    then:
+      properties:
+        interrupts: true
+    else:
+      properties:
+        interrupts: false
+
+unevaluatedProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/irq.h>
+    #include <dt-bindings/gpio/gpio.h>
+    spi {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        adc@0 {
+                compatible = "adi,ad7091r8";
+                reg = <0x0>;
+                spi-max-frequency = <45454545>;
+                vref-supply = <&adc_vref>;
+                adi,conversion-start-gpios = <&gpio 25 GPIO_ACTIVE_LOW>;
+                reset-gpios = <&gpio 27 GPIO_ACTIVE_LOW>;
+                interrupts = <22 IRQ_TYPE_EDGE_FALLING>;
+                interrupt-parent = <&gpio>;
+        };
+    };
+...
MAINTAINERS +1 -0
index 008f0e73bead..6e7c6c866396 100644
@@ -1132,6 +1132,7 @@ L:	[email protected]
 S:	Supported
 W:	http://ez.analog.com/community/linux-device-drivers
 F:	Documentation/devicetree/bindings/iio/adc/adi,ad7091r5.yaml
+F:	Documentation/devicetree/bindings/iio/adc/adi,ad7091r8.yaml
 F:	drivers/iio/adc/drivers/iio/adc/ad7091r-base.c
 F:	drivers/iio/adc/drivers/iio/adc/ad7091r-base.h
 F:	drivers/iio/adc/drivers/iio/adc/ad7091r5.c
Signature · 1 line
2.42.0
author maintainer
#9 lore raw

PATCH 6/7 iio: adc: Add support for AD7091R-8

In reply to [email protected]

From: Marcelo Schmitt <[email protected]>

Add support for Analog Devices AD7091R-2, AD7091R-4, and AD7091R-8 low power 12-Bit SAR ADCs.
Extend ad7091r-base driver so it can be used by AD7091R-8 drivers.

---

Device read/write might look odd due to the transfer protocol for these devices. I'm glad to hear any suggestions on how to make it better.

 MAINTAINERS                    |   1 +
 drivers/iio/adc/Kconfig        |  16 ++
 drivers/iio/adc/Makefile       |   4 +-
 drivers/iio/adc/ad7091r-base.c |  25 ++-
 drivers/iio/adc/ad7091r-base.h |  15 ++
 drivers/iio/adc/ad7091r5.c     |   2 +
 drivers/iio/adc/ad7091r8.c     | 272 +++++++++++++++++++++++++++++++++
 7 files changed, 327 insertions(+), 8 deletions(-)
 create mode 100644 drivers/iio/adc/ad7091r8.c
MAINTAINERS +1 -0
index 6e7c6c866396..54eff6f0c358 100644
@@ -1136,6 +1136,7 @@ F:	Documentation/devicetree/bindings/iio/adc/adi,ad7091r8.yaml
 F:	drivers/iio/adc/drivers/iio/adc/ad7091r-base.c
 F:	drivers/iio/adc/drivers/iio/adc/ad7091r-base.h
 F:	drivers/iio/adc/drivers/iio/adc/ad7091r5.c
+F:	drivers/iio/adc/drivers/iio/adc/ad7091r8.c
 
 ANALOG DEVICES INC AD7192 DRIVER
 M:	Alexandru Tachici <[email protected]>
drivers/iio/adc/Kconfig +16 -0
index 1e2b7a2c67c6..284d898790a2 100644
@@ -36,13 +36,29 @@ config AD4130
 	  To compile this driver as a module, choose M here: the module will be
 	  called ad4130.
 
+config AD7091R
+	tristate
+
 config AD7091R5
 	tristate "Analog Devices AD7091R5 ADC Driver"
 	depends on I2C
+	select AD7091R
 	select REGMAP_I2C
 	help
 	  Say yes here to build support for Analog Devices AD7091R-5 ADC.
 
+config AD7091R8
+	tristate "Analog Devices AD7091R8 ADC Driver"
+	depends on SPI
+	select AD7091R
+	select REGMAP_SPI
+	help
+	  Say yes here to build support for Analog Devices AD7091R-2, AD7091R-4,
+	  and AD7091R-8 ADC.
+
+	  To compile this driver as a module, choose M here: the module will be
+	  called ad7091r8.
+
 config AD7124
 	tristate "Analog Devices AD7124 and similar sigma-delta ADCs driver"
 	depends on SPI_MASTER
drivers/iio/adc/Makefile +3 -1
index c0803383a7cc..d2fda54a3259 100644
@@ -7,7 +7,9 @@
 obj-$(CONFIG_AB8500_GPADC) += ab8500-gpadc.o
 obj-$(CONFIG_AD_SIGMA_DELTA) += ad_sigma_delta.o
 obj-$(CONFIG_AD4130) += ad4130.o
-obj-$(CONFIG_AD7091R5) += ad7091r5.o ad7091r-base.o
+obj-$(CONFIG_AD7091R) += ad7091r-base.o
+obj-$(CONFIG_AD7091R5) += ad7091r5.o
+obj-$(CONFIG_AD7091R8) += ad7091r8.o
 obj-$(CONFIG_AD7124) += ad7124.o
 obj-$(CONFIG_AD7192) += ad7192.o
 obj-$(CONFIG_AD7266) += ad7266.o
drivers/iio/adc/ad7091r-base.c +18 -7
index 69cb5ccdbc49..f9b4f91d1c4f 100644
@@ -6,6 +6,7 @@
  */
 
 #include <linux/bitops.h>
+#include <linux/bitfield.h>
 #include <linux/iio/events.h>
 #include <linux/iio/iio.h>
 #include <linux/interrupt.h>
@@ -16,7 +17,8 @@
 #include "ad7091r-base.h"
 
 /* AD7091R_REG_RESULT */
-#define AD7091R_REG_RESULT_CH_ID(x)	    (((x) >> 13) & 0x3)
+#define AD7091R5_REG_RESULT_CH_ID(x)	    (((x) >> 13) & 0x3)
+#define AD7091R8_REG_RESULT_CH_ID(x)	    (((x) >> 13) & 0x7)
 #define AD7091R_REG_RESULT_CONV_RESULT(x)   ((x) & 0xfff)
 
 /* AD7091R_REG_CONF */
@@ -45,10 +47,14 @@ static int ad7091r_set_mode(struct ad7091r_state *st, enum ad7091r_mode mode)
 		return -EINVAL;
 	}
 
-	ret = regmap_update_bits(st->map, AD7091R_REG_CONF,
-				 AD7091R_REG_CONF_MODE_MASK, conf);
-	if (ret)
-		return ret;
+	/* AD7091R-2/4/8 don't set normal, command, autocycle modes in conf reg */
+	if (st->chip_info->type == AD7091R5) {
+		return 0;
+		ret = regmap_update_bits(st->map, AD7091R_REG_CONF,
+					 AD7091R_REG_CONF_MODE_MASK, conf);
+		if (ret)
+			return ret;
+	}
 
 	st->mode = mode;
 
@@ -88,8 +94,13 @@ static int ad7091r_read_one(struct iio_dev *iio_dev,
 	if (ret)
 		return ret;
 
-	if (AD7091R_REG_RESULT_CH_ID(val) != channel)
-		return -EIO;
+	if (st->chip_info->type == AD7091R5) {
+		if (AD7091R5_REG_RESULT_CH_ID(val) != channel)
+			return -EIO;
+	} else {
+		if (AD7091R8_REG_RESULT_CH_ID(val) != channel)
+			return -EIO;
+	}
 
 	*read_val = AD7091R_REG_RESULT_CONV_RESULT(val);
 
drivers/iio/adc/ad7091r-base.h +15 -0
index 405939f4eee0..99e5053d1f44 100644
@@ -29,6 +29,8 @@
 	.scan_type.realbits = bits,					\
 }
 
+#include <linux/gpio/consumer.h>
+
 struct device;
 
 enum ad7091r_mode {
@@ -40,13 +42,26 @@ enum ad7091r_mode {
 struct ad7091r_state {
 	struct device *dev;
 	struct regmap *map;
+	struct gpio_desc *convst_gpio;
+	struct gpio_desc *reset_gpio;
 	struct regulator *vref;
 	const struct ad7091r_chip_info *chip_info;
 	enum ad7091r_mode mode;
 	struct mutex lock; /*lock to prevent concurent reads */
+	__be16 tx_buf __aligned(IIO_DMA_MINALIGN);
+	__be16 rx_buf;
+};
+
+enum ad7091r_device_type {
+	AD7091R2,
+	AD7091R4,
+	AD7091R5,
+	AD7091R8,
 };
 
 struct ad7091r_chip_info {
+	const char *name;
+	enum ad7091r_device_type type;
 	unsigned int num_channels;
 	const struct iio_chan_spec *channels;
 	unsigned int vref_mV;
drivers/iio/adc/ad7091r5.c +2 -0
index 1a27841d1bbc..5f587e0b55df 100644
@@ -27,12 +27,14 @@ static const struct iio_chan_spec ad7091r5_channels_noirq[] = {
 };
 
 static const struct ad7091r_chip_info ad7091r5_chip_info_irq = {
+	.type = AD7091R5,
 	.channels = ad7091r5_channels_irq,
 	.num_channels = ARRAY_SIZE(ad7091r5_channels_irq),
 	.vref_mV = 2500,
 };
 
 static const struct ad7091r_chip_info ad7091r5_chip_info_noirq = {
+	.type = AD7091R5,
 	.channels = ad7091r5_channels_noirq,
 	.num_channels = ARRAY_SIZE(ad7091r5_channels_noirq),
 	.vref_mV = 2500,
drivers/iio/adc/ad7091r8.c new file +272 -0

272 lines not on this page · raw message

Signature · 1 line
2.42.0
author maintainer
#12 lore raw

PATCH 7/7 iio: adc: ad7091r-base: Add debugfs reg access

In reply to [email protected]

From: Marcelo Schmitt <[email protected]>

Add direct register access support for AD7091R-2/-4/-5/-8 ADCs.

---
 drivers/iio/adc/ad7091r-base.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
drivers/iio/adc/ad7091r-base.c +12 -0
index f9b4f91d1c4f..798f7b3cc7e1 100644
@@ -157,8 +157,20 @@ static int ad7091r_read_raw(struct iio_dev *iio_dev,
 	return ret;
 }
 
+static int ad7091r_reg_access(struct iio_dev *indio_dev, unsigned int reg,
+			      unsigned int writeval, unsigned int *readval)
+{
+	struct ad7091r_state *st  = iio_priv(indio_dev);
+
+	if (readval)
+		return regmap_read(st->map, reg, readval);
+
+	return regmap_write(st->map, reg, writeval);
+}
+
 static const struct iio_info ad7091r_info = {
 	.read_raw = ad7091r_read_raw,
+	.debugfs_reg_access = &ad7091r_reg_access,
 };
 
 static irqreturn_t ad7091r_event_handler(int irq, void *private)
Signature · 1 line
2.42.0
#7 lore raw

Re: [PATCH 5/7] dt-bindings: iio: Add binding documentation for AD7091R-8

In reply to [email protected]
Quoted 3 lines · On 21/11/2023 22:36, [email protected] wrote:

From: Marcelo Schmitt <[email protected]>

Add device tree binding documentation for AD7091R-8.

Please use scripts/get_maintainers.pl to get a list of necessary people and lists to CC. It might happen, that command when run on an older kernel, gives you outdated entries. Therefore please be sure you base your patches on recent Linux kernel.

You missed at least devicetree list (maybe more), so this won't be tested by automated tooling. Performing review on untested code might be a waste of time, thus I will skip this patch entirely till you follow the process allowing the patch to be tested.

Please kindly resend and include all necessary To/Cc entries.

Quoted 47 lines
---
 .../bindings/iio/adc/adi,ad7091r8.yaml        | 101 ++++++++++++++++++
 MAINTAINERS                                   |   1 +
 2 files changed, 102 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/adc/adi,ad7091r8.yaml
Documentation/devicetree/bindings/iio/adc/adi,ad7091r8.yaml new file +33 -0
new file mode 100644
index 000000000000..f10b6727737f
@@ -0,0 +1,101 @@
+# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/iio/adc/adi,ad7091r8.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Analog Devices AD7091R8 8-Channel 12-Bit ADC
+
+maintainers:
+  - Marcelo Schmitt <[email protected]>
+
+description: |
+  Analog Devices AD7091R-8 8-Channel 12-Bit ADC
+  https://www.analog.com/media/en/technical-documentation/data-sheets/AD7091R-2_7091R-4_7091R-8.pdf
+
+properties:
+  compatible:
+    enum:
+      - adi,ad7091r2
+      - adi,ad7091r4
+      - adi,ad7091r8
+
+  reg:
+    maxItems: 1
+
+  vref-supply: true
+
+  spi-max-frequency: true
+
+  adi,conversion-start-gpios:
+    description:
+      Device tree identifier of the CONVST pin.
+      This logic input is used to initiate conversions on the analog

Documentation/devicetree/bindings/iio/adc/adi,ad7091r8.yaml line 43

Quoted 10 lines
Documentation/devicetree/bindings/iio/adc/adi,ad7091r8.yaml new file +10 -0
+      input channels.
+    maxItems: 1
+
+  reset-gpios:
+    maxItems: 1
+
+  interrupts:
+    maxItems: 1
+
+required:

This goes after pattern.

Documentation/devicetree/bindings/iio/adc/adi,ad7091r8.yaml line 50

Quoted 7 lines
Documentation/devicetree/bindings/iio/adc/adi,ad7091r8.yaml new file +7 -0
+  - compatible
+  - reg
+  - adi,conversion-start-gpios
+
+patternProperties:
+  "^channel@[0-7]$":
+    $ref: "adc.yaml"

You never tested this... considering that you opted-out of automated testing, you basically send buggy code. NAK.

Best regards,
Krzysztof

#10 lore raw

Re: [PATCH 6/7] iio: adc: Add support for AD7091R-8

In reply to [email protected]
Quoted 12 lines · On 21/11/2023 22:36, [email protected] wrote:

From: Marcelo Schmitt <[email protected]>

Add support for Analog Devices AD7091R-2, AD7091R-4, and AD7091R-8 low power 12-Bit SAR ADCs.
Extend ad7091r-base driver so it can be used by AD7091R-8 drivers.

---

Device read/write might look odd due to the transfer protocol for these devices. I'm glad to hear any suggestions on how to make it better.

...

drivers/iio/adc/ad7091r8.c line 191

Quoted 9 lines
drivers/iio/adc/ad7091r8.c new file +9 -0
+
+static int ad7091r8_gpio_setup(struct ad7091r_state *st)
+{
+	st->convst_gpio = devm_gpiod_get(st->dev, "adi,conversion-start",
+					 GPIOD_OUT_LOW);
+	if (IS_ERR(st->convst_gpio))
+		return dev_err_probe(st->dev, PTR_ERR(st->convst_gpio),
+				     "Error getting convst GPIO: %ld\n",
+				     PTR_ERR(st->convst_gpio));

Don't print error code twice.

Quoted 30 lines
drivers/iio/adc/ad7091r8.c new file +30 -0
+
+	st->reset_gpio =  devm_gpiod_get_optional(st->dev, "reset",
+						  GPIOD_OUT_HIGH);
+	if (IS_ERR(st->reset_gpio))
+		return PTR_ERR(st->reset_gpio);
+
+	if (st->reset_gpio) {
+		fsleep(20);
+		gpiod_set_value_cansleep(st->reset_gpio, 0);
+	}
+
+	return 0;
+}
+
+static int ad7091r8_spi_probe(struct spi_device *spi)
+{
+	const struct ad7091r_chip_info *chip_info;
+	struct ad7091r_state *st;
+	struct iio_dev *iio_dev;
+	struct regmap *map;
+	int ret;
+
+	chip_info = spi_get_device_match_data(spi);
+	if (!chip_info)
+		return -EINVAL;
+
+	iio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st));
+	if (!iio_dev)
+		return -ENOMEM;
+

drivers/iio/adc/ad7091r8.c line 231

Quoted 10 lines
drivers/iio/adc/ad7091r8.c new file +10 -0
+	st = iio_priv(iio_dev);
+	st->dev = &spi->dev;
+
+	map = devm_regmap_init(&spi->dev, &ad7091r8_regmap_bus, st,
+			       &ad7091r_spi_regmap_config[chip_info->type]);
+
+	if (IS_ERR(map))
+		return dev_err_probe(&spi->dev, PTR_ERR(map),
+				     "Error initializing spi regmap: %ld\n",
+				     PTR_ERR(map));

Don't print error code twice.

Best regards,
Krzysztof

#8 lore raw

Re: [PATCH 5/7] dt-bindings: iio: Add binding documentation for AD7091R-8

In reply to [email protected]
kernel test robot noticed the following build warnings:

Hi,

kernel test robot noticed the following build warnings:

[auto build test WARNING on jic23-iio/togreg]
[also build test WARNING on linus/master v6.7-rc2 next-20231122] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/marcelo-schmitt-analog-com/MAINTAINERS-Add-MAINTAINERS-entry-for-AD7091R/20231122-093706
base:   https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio.git togreg
patch link:    https://lore.kernel.org/r/566503a54feba35178c778a7929bced66ebd8870.1700595310.git.marcelo.schmitt1%40gmail.com
patch subject: [PATCH 5/7] dt-bindings: iio: Add binding documentation for AD7091R-8
compiler: loongarch64-linux-gcc (GCC) 13.2.0
reproduce: (https://download.01.org/0day-ci/archive/20231122/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

dtcheck warnings: (new ones prefixed by >>)

>> Documentation/devicetree/bindings/iio/adc/adi,ad7091r8.yaml:50:11: [error] string value is redundantly quoted with any quotes (quoted-strings)

vim +50 Documentation/devicetree/bindings/iio/adc/adi,ad7091r8.yaml

     8	
     9	maintainers:
    10	  - Marcelo Schmitt <[email protected]>
    11	
    12	description: |
    13	  Analog Devices AD7091R-8 8-Channel 12-Bit ADC
    14	  https://www.analog.com/media/en/technical-documentation/data-sheets/AD7091R-2_7091R-4_7091R-8.pdf
    15	
    16	properties:
    17	  compatible:
    18	    enum:
    19	      - adi,ad7091r2
    20	      - adi,ad7091r4
    21	      - adi,ad7091r8
    22	
    23	  reg:
    24	    maxItems: 1
    25	
    26	  vref-supply: true
    27	
    28	  spi-max-frequency: true
    29	
    30	  adi,conversion-start-gpios:
    31	    description:
    32	      Device tree identifier of the CONVST pin.
    33	      This logic input is used to initiate conversions on the analog
    34	      input channels.
    35	    maxItems: 1
    36	
    37	  reset-gpios:
    38	    maxItems: 1
    39	
    40	  interrupts:
    41	    maxItems: 1
    42	
    43	required:
    44	  - compatible
    45	  - reg
    46	  - adi,conversion-start-gpios
    47	
    48	patternProperties:
    49	  "^channel@[0-7]$":
  > 50	    $ref: "adc.yaml"
    51	    type: object
    52	    description: Represents the external channels which are connected to the ADC.
    53	
    54	    properties:
    55	      reg:
    56	        minimum: 0
    57	        maximum: 7
    58	
    59	    required:
    60	      - reg
    61	
    62	allOf:
    63	  - $ref: /schemas/spi/spi-peripheral-props.yaml#
    64	
    65	  # AD7091R-2 does not have ALERT/BUSY/GPO pin
    66	  - if:
    67	      properties:
    68	        compatible:
    69	          contains:
    70	            enum:
    71	              - adi,ad7091r4
    72	              - adi,ad7091r8
    73	    then:
    74	      properties:
    75	        interrupts: true
    76	    else:
    77	      properties:
    78	        interrupts: false
    79	
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#4 lore raw

Re: [PATCH 3/7] iio: adc: ad7091r: Move defines to header file

In reply to [email protected]
kernel test robot noticed the following build warnings:

Hi,

kernel test robot noticed the following build warnings:

[auto build test WARNING on jic23-iio/togreg]
[also build test WARNING on linus/master v6.7-rc2 next-20231122] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/marcelo-schmitt-analog-com/MAINTAINERS-Add-MAINTAINERS-entry-for-AD7091R/20231122-093706
base:   https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio.git togreg
patch link:    https://lore.kernel.org/r/8aa859817e86408733a81cf31b932f0efa273c71.1700595310.git.marcelo.schmitt1%40gmail.com
patch subject: [PATCH 3/7] iio: adc: ad7091r: Move defines to header file
config: powerpc-randconfig-r071-20231122 (https://download.01.org/0day-ci/archive/20231122/[email protected]/config)
compiler: powerpc-linux-gcc (GCC) 13.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231122/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All warnings (new ones prefixed by >>):

In file included from drivers/iio/adc/ad7091r-base.c:16:

>> drivers/iio/adc/ad7091r-base.h:41:36: warning: 'ad7091r_events' defined but not used [-Wunused-const-variable=]
      41 | static const struct iio_event_spec ad7091r_events[] = {
         |                                    ^~~~~~~~~~~~~~

vim +/ad7091r_events +41 drivers/iio/adc/ad7091r-base.h

    40	
  > 41	static const struct iio_event_spec ad7091r_events[] = {
    42		{
    43			.type = IIO_EV_TYPE_THRESH,
    44			.dir = IIO_EV_DIR_RISING,
    45			.mask_separate = BIT(IIO_EV_INFO_VALUE) |
    46					 BIT(IIO_EV_INFO_ENABLE),
    47		},
    48		{
    49			.type = IIO_EV_TYPE_THRESH,
    50			.dir = IIO_EV_DIR_FALLING,
    51			.mask_separate = BIT(IIO_EV_INFO_VALUE) |
    52					 BIT(IIO_EV_INFO_ENABLE),
    53		},
    54		{
    55			.type = IIO_EV_TYPE_THRESH,
    56			.dir = IIO_EV_DIR_EITHER,
    57			.mask_separate = BIT(IIO_EV_INFO_HYSTERESIS),
    58		},
    59	};
    60	
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#11 lore raw

Re: [PATCH 6/7] iio: adc: Add support for AD7091R-8

In reply to [email protected]

Hi,

kernel test robot noticed the following build warnings:

https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/marcelo-schmitt-analog-com/MAINTAINERS-Add-MAINTAINERS-entry-for-AD7091R/20231122-093706
base:   https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio.git togreg
patch link:    https://lore.kernel.org/r/514295a9b760b44a710425803a41decddd3e8df8.1700595310.git.marcelo.schmitt1%40gmail.com
patch subject: [PATCH 6/7] iio: adc: Add support for AD7091R-8
config: x86_64-randconfig-161-20231122 (https://download.01.org/0day-ci/archive/20231123/[email protected]/config)
compiler: clang version 16.0.4 (https://github.com/llvm/llvm-project.git ae42196bc493ffe877a7e3dff8be32035dea4d07)
reproduce: (https://download.01.org/0day-ci/archive/20231123/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags

| Reported-by: kernel test robot <[email protected]>
| Reported-by: Dan Carpenter <[email protected]>
| Closes: https://lore.kernel.org/r/[email protected]/

smatch warnings:
drivers/iio/adc/ad7091r-base.c:53 ad7091r_set_mode() warn: ignoring unreachable code.

vim +53 drivers/iio/adc/ad7091r-base.c

ca69300173b642 Paul Cercueil   2019-11-15  32  static int ad7091r_set_mode(struct ad7091r_state *st, enum ad7091r_mode mode)
ca69300173b642 Paul Cercueil   2019-11-15  33  {
ca69300173b642 Paul Cercueil   2019-11-15  34  	int ret, conf;
ca69300173b642 Paul Cercueil   2019-11-15  35  
ca69300173b642 Paul Cercueil   2019-11-15  36  	switch (mode) {
ca69300173b642 Paul Cercueil   2019-11-15  37  	case AD7091R_MODE_SAMPLE:
ca69300173b642 Paul Cercueil   2019-11-15  38  		conf = 0;
ca69300173b642 Paul Cercueil   2019-11-15  39  		break;
ca69300173b642 Paul Cercueil   2019-11-15  40  	case AD7091R_MODE_COMMAND:
ca69300173b642 Paul Cercueil   2019-11-15  41  		conf = AD7091R_REG_CONF_CMD;
ca69300173b642 Paul Cercueil   2019-11-15  42  		break;
ca69300173b642 Paul Cercueil   2019-11-15  43  	case AD7091R_MODE_AUTOCYCLE:
ca69300173b642 Paul Cercueil   2019-11-15  44  		conf = AD7091R_REG_CONF_AUTO;
ca69300173b642 Paul Cercueil   2019-11-15  45  		break;
ca69300173b642 Paul Cercueil   2019-11-15  46  	default:
ca69300173b642 Paul Cercueil   2019-11-15  47  		return -EINVAL;
ca69300173b642 Paul Cercueil   2019-11-15  48  	}
ca69300173b642 Paul Cercueil   2019-11-15  49  
fccb9cf346d38a Marcelo Schmitt 2023-11-21  50  	/* AD7091R-2/4/8 don't set normal, command, autocycle modes in conf reg */
fccb9cf346d38a Marcelo Schmitt 2023-11-21  51  	if (st->chip_info->type == AD7091R5) {
fccb9cf346d38a Marcelo Schmitt 2023-11-21  52  		return 0;

I normally ignore when people add a return 0 to stub out code because it's obviously deliberate. But this is a patch to add support for new hardware and it's stubbing out the existing:

ret = regmap_update_bits()

For existing users... It feels like if that's necessary then it should be done in a separate commit.

ca69300173b642 Paul Cercueil   2019-11-15 @53  		ret = regmap_update_bits(st->map, AD7091R_REG_CONF,
ca69300173b642 Paul Cercueil   2019-11-15  54  					 AD7091R_REG_CONF_MODE_MASK, conf);
ca69300173b642 Paul Cercueil   2019-11-15  55  		if (ret)
ca69300173b642 Paul Cercueil   2019-11-15  56  			return ret;
fccb9cf346d38a Marcelo Schmitt 2023-11-21  57  	}
ca69300173b642 Paul Cercueil   2019-11-15  58  
ca69300173b642 Paul Cercueil   2019-11-15  59  	st->mode = mode;
ca69300173b642 Paul Cercueil   2019-11-15  60  
ca69300173b642 Paul Cercueil   2019-11-15  61  	return 0;
ca69300173b642 Paul Cercueil   2019-11-15  62  }
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki