* [PATCH v4 0/6] Add support for AD7405/ADUM770x
@ 2025-05-19 14:02 Pop Ioan Daniel
2025-05-19 14:02 ` [PATCH v4 1/6] iio: adc: ad4851: ad4851_set_oversampling_ratio parameters update Pop Ioan Daniel
` (6 more replies)
0 siblings, 7 replies; 21+ messages in thread
From: Pop Ioan Daniel @ 2025-05-19 14:02 UTC (permalink / raw)
To: Lars-Peter Clausen, Michael Hennerich, Jonathan Cameron,
David Lechner, Nuno Sá, Andy Shevchenko, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Sergiu Cuciurean,
Dragos Bogdan, Antoniu Miclaus, Olivier Moysan, Javier Carrasco,
Matti Vaittinen, Tobias Sperling, Alisa-Dariana Roman,
Marcelo Schmitt, Herve Codina, João Paulo Gonçalves,
AngeloGioacchino Del Regno, Ioan Daniel, linux-iio, devicetree,
linux-kernel
The AD7405 is a high performance, second-order, Σ-Δ modulator
that converts an analog input signal into a high speed, single-bit
LVDS data stream, with on-chip digital isolation based on Analog
Devices, Inc., iCoupler technology. The AD7405 operates from a
4.5 V to 5.5 V (VDD1) power supply and accepts a differential input
signal of ±250 mV (±320 mV full-scale). The differential input is ideally
suited to shunt voltage monitoring in high voltage applications
where galvanic isolation is required.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Pop Ioan Daniel (6):
iio: adc: ad4851: ad4851_set_oversampling_ratio parameters update
iio: backend: update iio_backend_oversampling_ratio_set
iio: adc: adi-axi-adc: add axi_adc_oversampling_ratio_set
dt-bindings: iio: adc: add ad7405
dt-bindings: iio: adc: adi-axi-adc: add ad7405 example
iio: adc: ad7405: add ad7405 driver
.../bindings/iio/adc/adi,ad7405.yaml | 60 +++++
.../bindings/iio/adc/adi,axi-adc.yaml | 17 ++
drivers/iio/adc/Kconfig | 10 +
drivers/iio/adc/Makefile | 1 +
drivers/iio/adc/ad4851.c | 7 +-
drivers/iio/adc/ad7405.c | 250 ++++++++++++++++++
drivers/iio/adc/adi-axi-adc.c | 20 +-
drivers/iio/industrialio-backend.c | 3 +-
include/linux/iio/backend.h | 3 +-
9 files changed, 364 insertions(+), 7 deletions(-)
create mode 100644 Documentation/devicetree/bindings/iio/adc/adi,ad7405.yaml
create mode 100644 drivers/iio/adc/ad7405.c
--
2.34.1
^ permalink raw reply [flat|nested] 21+ messages in thread
* [PATCH v4 1/6] iio: adc: ad4851: ad4851_set_oversampling_ratio parameters update
2025-05-19 14:02 [PATCH v4 0/6] Add support for AD7405/ADUM770x Pop Ioan Daniel
@ 2025-05-19 14:02 ` Pop Ioan Daniel
2025-05-19 15:15 ` David Lechner
2025-05-19 14:02 ` [PATCH v4 2/6] iio: backend: update iio_backend_oversampling_ratio_set Pop Ioan Daniel
` (5 subsequent siblings)
6 siblings, 1 reply; 21+ messages in thread
From: Pop Ioan Daniel @ 2025-05-19 14:02 UTC (permalink / raw)
To: Lars-Peter Clausen, Michael Hennerich, Jonathan Cameron,
David Lechner, Nuno Sá, Andy Shevchenko, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Sergiu Cuciurean,
Dragos Bogdan, Antoniu Miclaus, Olivier Moysan, Javier Carrasco,
Matti Vaittinen, Tobias Sperling, Alisa-Dariana Roman,
Marcelo Schmitt, Thomas Bonnefille, Pop Ioan Daniel,
AngeloGioacchino Del Regno, linux-iio, devicetree, linux-kernel
Remove chan parameter from ad4851_set_oversampling_ratio parameters
list.
Signed-off-by: Pop Ioan Daniel <pop.ioan-daniel@analog.com>
---
changes in v4:
- remove chan parameter from parameters list
drivers/iio/adc/ad4851.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/drivers/iio/adc/ad4851.c b/drivers/iio/adc/ad4851.c
index 98ebc853db79..12f90aa3a156 100644
--- a/drivers/iio/adc/ad4851.c
+++ b/drivers/iio/adc/ad4851.c
@@ -294,7 +294,6 @@ static int ad4851_scale_fill(struct iio_dev *indio_dev)
}
static int ad4851_set_oversampling_ratio(struct iio_dev *indio_dev,
- const struct iio_chan_spec *chan,
unsigned int osr)
{
struct ad4851_state *st = iio_priv(indio_dev);
@@ -831,7 +830,7 @@ static int ad4851_write_raw(struct iio_dev *indio_dev,
case IIO_CHAN_INFO_CALIBBIAS:
return ad4851_set_calibbias(st, chan->channel, val);
case IIO_CHAN_INFO_OVERSAMPLING_RATIO:
- return ad4851_set_oversampling_ratio(indio_dev, chan, val);
+ return ad4851_set_oversampling_ratio(indio_dev, val);
default:
return -EINVAL;
}
--
2.34.1
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH v4 2/6] iio: backend: update iio_backend_oversampling_ratio_set
2025-05-19 14:02 [PATCH v4 0/6] Add support for AD7405/ADUM770x Pop Ioan Daniel
2025-05-19 14:02 ` [PATCH v4 1/6] iio: adc: ad4851: ad4851_set_oversampling_ratio parameters update Pop Ioan Daniel
@ 2025-05-19 14:02 ` Pop Ioan Daniel
2025-05-19 15:15 ` David Lechner
2025-05-26 9:54 ` Nuno Sá
2025-05-19 14:02 ` [PATCH v4 3/6] iio: adc: adi-axi-adc: add axi_adc_oversampling_ratio_set Pop Ioan Daniel
` (4 subsequent siblings)
6 siblings, 2 replies; 21+ messages in thread
From: Pop Ioan Daniel @ 2025-05-19 14:02 UTC (permalink / raw)
To: Lars-Peter Clausen, Michael Hennerich, Jonathan Cameron,
David Lechner, Nuno Sá, Andy Shevchenko, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Sergiu Cuciurean,
Dragos Bogdan, Antoniu Miclaus, Olivier Moysan, Javier Carrasco,
Matti Vaittinen, Tobias Sperling, Alisa-Dariana Roman,
Marcelo Schmitt, Herve Codina, Trevor Gamblin, Thomas Bonnefille,
Ioan Daniel, linux-iio, devicetree, linux-kernel
Add chan parameter to iio_backed_oversampling_ration_set() to allow
for contexts where the channel must be specified. Modify all
existing users.
Signed-off-by: Pop Ioan Daniel <pop.ioan-daniel@analog.com>
---
changes in v4:
- pass 0 in the list of parameters instead of chan
drivers/iio/adc/ad4851.c | 4 ++--
drivers/iio/industrialio-backend.c | 3 ++-
include/linux/iio/backend.h | 3 ++-
3 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/drivers/iio/adc/ad4851.c b/drivers/iio/adc/ad4851.c
index 12f90aa3a156..1f975858c496 100644
--- a/drivers/iio/adc/ad4851.c
+++ b/drivers/iio/adc/ad4851.c
@@ -319,8 +319,8 @@ static int ad4851_set_oversampling_ratio(struct iio_dev *indio_dev,
if (ret)
return ret;
}
-
- ret = iio_backend_oversampling_ratio_set(st->back, osr);
+ /* Channel is ignored by the backend being used here */
+ ret = iio_backend_oversampling_ratio_set(st->back, 0, osr);
if (ret)
return ret;
diff --git a/drivers/iio/industrialio-backend.c b/drivers/iio/industrialio-backend.c
index c1eb9ef9db08..a4e3e54fecb1 100644
--- a/drivers/iio/industrialio-backend.c
+++ b/drivers/iio/industrialio-backend.c
@@ -720,9 +720,10 @@ EXPORT_SYMBOL_NS_GPL(iio_backend_data_size_set, "IIO_BACKEND");
* 0 on success, negative error number on failure.
*/
int iio_backend_oversampling_ratio_set(struct iio_backend *back,
+ unsigned int chan,
unsigned int ratio)
{
- return iio_backend_op_call(back, oversampling_ratio_set, ratio);
+ return iio_backend_op_call(back, oversampling_ratio_set, chan, ratio);
}
EXPORT_SYMBOL_NS_GPL(iio_backend_oversampling_ratio_set, "IIO_BACKEND");
diff --git a/include/linux/iio/backend.h b/include/linux/iio/backend.h
index e59d909cb659..dbf4e4a5f4b1 100644
--- a/include/linux/iio/backend.h
+++ b/include/linux/iio/backend.h
@@ -144,7 +144,7 @@ struct iio_backend_ops {
enum iio_backend_interface_type *type);
int (*data_size_set)(struct iio_backend *back, unsigned int size);
int (*oversampling_ratio_set)(struct iio_backend *back,
- unsigned int ratio);
+ unsigned int chan, unsigned int ratio);
int (*read_raw)(struct iio_backend *back,
struct iio_chan_spec const *chan, int *val, int *val2,
long mask);
@@ -209,6 +209,7 @@ int iio_backend_interface_type_get(struct iio_backend *back,
enum iio_backend_interface_type *type);
int iio_backend_data_size_set(struct iio_backend *back, unsigned int size);
int iio_backend_oversampling_ratio_set(struct iio_backend *back,
+ unsigned int chan,
unsigned int ratio);
int iio_backend_read_raw(struct iio_backend *back,
struct iio_chan_spec const *chan, int *val, int *val2,
--
2.34.1
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH v4 3/6] iio: adc: adi-axi-adc: add axi_adc_oversampling_ratio_set
2025-05-19 14:02 [PATCH v4 0/6] Add support for AD7405/ADUM770x Pop Ioan Daniel
2025-05-19 14:02 ` [PATCH v4 1/6] iio: adc: ad4851: ad4851_set_oversampling_ratio parameters update Pop Ioan Daniel
2025-05-19 14:02 ` [PATCH v4 2/6] iio: backend: update iio_backend_oversampling_ratio_set Pop Ioan Daniel
@ 2025-05-19 14:02 ` Pop Ioan Daniel
2025-05-19 15:15 ` David Lechner
2025-05-26 9:54 ` Nuno Sá
2025-05-19 14:02 ` [PATCH v4 4/6] dt-bindings: iio: adc: add ad7405 Pop Ioan Daniel
` (3 subsequent siblings)
6 siblings, 2 replies; 21+ messages in thread
From: Pop Ioan Daniel @ 2025-05-19 14:02 UTC (permalink / raw)
To: Lars-Peter Clausen, Michael Hennerich, Jonathan Cameron,
David Lechner, Nuno Sá, Andy Shevchenko, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Sergiu Cuciurean,
Dragos Bogdan, Antoniu Miclaus, Olivier Moysan, Javier Carrasco,
Matti Vaittinen, Tobias Sperling, Alisa-Dariana Roman,
Marcelo Schmitt, João Paulo Gonçalves,
Thomas Bonnefille, Ioan Daniel, linux-iio, devicetree,
linux-kernel
Add support for setting decimation rate.
Signed-off-by: Pop Ioan Daniel <pop.ioan-daniel@analog.com>
---
no changes in v4.
drivers/iio/adc/adi-axi-adc.c | 20 +++++++++++++++++++-
1 file changed, 19 insertions(+), 1 deletion(-)
diff --git a/drivers/iio/adc/adi-axi-adc.c b/drivers/iio/adc/adi-axi-adc.c
index 4116c44197b8..0b8673668745 100644
--- a/drivers/iio/adc/adi-axi-adc.c
+++ b/drivers/iio/adc/adi-axi-adc.c
@@ -80,6 +80,9 @@
#define ADI_AXI_ADC_REG_CHAN_CTRL_3(c) (0x0418 + (c) * 0x40)
#define ADI_AXI_ADC_CHAN_PN_SEL_MASK GENMASK(19, 16)
+#define ADI_AXI_ADC_REG_CHAN_USR_CTRL_2(c) (0x0424 + (c) * 0x40)
+#define ADI_AXI_ADC_CHAN_USR_CTRL_2_DEC_RATE_N_MASK GENMASK(15, 0)
+
/* IO Delays */
#define ADI_AXI_ADC_REG_DELAY(l) (0x0800 + (l) * 0x4)
#define AXI_ADC_DELAY_CTRL_MASK GENMASK(4, 0)
@@ -242,6 +245,19 @@ static int axi_adc_test_pattern_set(struct iio_backend *back,
}
}
+static int axi_adc_oversampling_ratio_set(struct iio_backend *back,
+ unsigned int chan,
+ unsigned int rate)
+{
+ struct adi_axi_adc_state *st = iio_backend_get_priv(back);
+
+ return regmap_update_bits(st->regmap,
+ ADI_AXI_ADC_REG_CHAN_USR_CTRL_2(chan),
+ ADI_AXI_ADC_CHAN_USR_CTRL_2_DEC_RATE_N_MASK,
+ FIELD_PREP(ADI_AXI_ADC_CHAN_USR_CTRL_2_DEC_RATE_N_MASK,
+ rate));
+}
+
static int axi_adc_read_chan_status(struct adi_axi_adc_state *st, unsigned int chan,
unsigned int *status)
{
@@ -381,7 +397,8 @@ static int axi_adc_ad485x_data_size_set(struct iio_backend *back,
}
static int axi_adc_ad485x_oversampling_ratio_set(struct iio_backend *back,
- unsigned int ratio)
+ unsigned int chan,
+ unsigned int ratio)
{
struct adi_axi_adc_state *st = iio_backend_get_priv(back);
@@ -549,6 +566,7 @@ static const struct iio_backend_ops adi_axi_adc_ops = {
.test_pattern_set = axi_adc_test_pattern_set,
.chan_status = axi_adc_chan_status,
.interface_type_get = axi_adc_interface_type_get,
+ .oversampling_ratio_set = axi_adc_oversampling_ratio_set,
.debugfs_reg_access = iio_backend_debugfs_ptr(axi_adc_reg_access),
.debugfs_print_chan_status = iio_backend_debugfs_ptr(axi_adc_debugfs_print_chan_status),
};
--
2.34.1
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH v4 4/6] dt-bindings: iio: adc: add ad7405
2025-05-19 14:02 [PATCH v4 0/6] Add support for AD7405/ADUM770x Pop Ioan Daniel
` (2 preceding siblings ...)
2025-05-19 14:02 ` [PATCH v4 3/6] iio: adc: adi-axi-adc: add axi_adc_oversampling_ratio_set Pop Ioan Daniel
@ 2025-05-19 14:02 ` Pop Ioan Daniel
2025-05-19 15:16 ` David Lechner
2025-05-20 6:41 ` Krzysztof Kozlowski
2025-05-19 14:02 ` [PATCH v4 5/6] dt-bindings: iio: adc: adi-axi-adc: add ad7405 example Pop Ioan Daniel
` (2 subsequent siblings)
6 siblings, 2 replies; 21+ messages in thread
From: Pop Ioan Daniel @ 2025-05-19 14:02 UTC (permalink / raw)
To: Lars-Peter Clausen, Michael Hennerich, Jonathan Cameron,
David Lechner, Nuno Sá, Andy Shevchenko, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Sergiu Cuciurean,
Dragos Bogdan, Antoniu Miclaus, Olivier Moysan, Javier Carrasco,
Matti Vaittinen, Tobias Sperling, Marcelo Schmitt,
Alisa-Dariana Roman, Pop Ioan Daniel, Ramona Alexandra Nechita,
linux-iio, devicetree, linux-kernel
Add devicetree bindings for ad7405/adum770x family.
Signed-off-by: Pop Ioan Daniel <pop.ioan-daniel@analog.com>
---
no changes in v4.
.../bindings/iio/adc/adi,ad7405.yaml | 60 +++++++++++++++++++
1 file changed, 60 insertions(+)
create mode 100644 Documentation/devicetree/bindings/iio/adc/adi,ad7405.yaml
diff --git a/Documentation/devicetree/bindings/iio/adc/adi,ad7405.yaml b/Documentation/devicetree/bindings/iio/adc/adi,ad7405.yaml
new file mode 100644
index 000000000000..939de3bd6f26
--- /dev/null
+++ b/Documentation/devicetree/bindings/iio/adc/adi,ad7405.yaml
@@ -0,0 +1,60 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+# Copyright 2025 Analog Devices Inc.
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/iio/adc/adi,ad7405.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Analog Devices AD7405 family
+
+maintainers:
+ - Dragos Bogdan <dragos.bogdan@analog.com>
+ - Pop Ioan Daniel <pop.ioan-daniel@analog.com>
+
+description: |
+ Analog Devices AD7405 is a high performance isolated ADC, 1-channel,
+ 16-bit with a second-order Σ-Δ modulator that converts an analog input signal
+ into a high speed, single-bit data stream.
+
+ https://www.analog.com/media/en/technical-documentation/data-sheets/ad7405.pdf
+ https://www.analog.com/media/en/technical-documentation/data-sheets/adum7701.pdf
+ https://www.analog.com/media/en/technical-documentation/data-sheets/adum7702.pdf
+ https://www.analog.com/media/en/technical-documentation/data-sheets/ADuM7703.pdf
+
+properties:
+ compatible:
+ enum:
+ - adi,ad7405
+ - adi,adum7701
+ - adi,adum7702
+ - adi,adum7703
+
+ clocks:
+ maxItems: 1
+
+ vdd1-supply: true
+
+ vdd2-supply: true
+
+ io-backends:
+ maxItems: 1
+
+required:
+ - compatible
+ - clocks
+ - vdd1-supply
+ - vdd2-supply
+ - io-backends
+
+additionalProperties: false
+
+examples:
+ - |
+ adc {
+ compatible = "adi,ad7405";
+ clocks = <&axi_clk_gen 0>;
+ vdd1-supply = <&vdd1>;
+ vdd2-supply = <&vdd2>;
+ io-backends = <&iio_backend>;
+ };
+...
--
2.34.1
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH v4 5/6] dt-bindings: iio: adc: adi-axi-adc: add ad7405 example
2025-05-19 14:02 [PATCH v4 0/6] Add support for AD7405/ADUM770x Pop Ioan Daniel
` (3 preceding siblings ...)
2025-05-19 14:02 ` [PATCH v4 4/6] dt-bindings: iio: adc: add ad7405 Pop Ioan Daniel
@ 2025-05-19 14:02 ` Pop Ioan Daniel
2025-05-19 15:19 ` David Lechner
2025-05-20 6:39 ` Krzysztof Kozlowski
2025-05-19 14:02 ` [PATCH v4 6/6] iio: adc: ad7405: add ad7405 driver Pop Ioan Daniel
2025-05-19 15:22 ` [PATCH v4 0/6] Add support for AD7405/ADUM770x David Lechner
6 siblings, 2 replies; 21+ messages in thread
From: Pop Ioan Daniel @ 2025-05-19 14:02 UTC (permalink / raw)
To: Lars-Peter Clausen, Michael Hennerich, Jonathan Cameron,
David Lechner, Nuno Sá, Andy Shevchenko, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Sergiu Cuciurean,
Dragos Bogdan, Antoniu Miclaus, Olivier Moysan, Javier Carrasco,
Matti Vaittinen, Tobias Sperling, Alisa-Dariana Roman,
Marcelo Schmitt, João Paulo Gonçalves, Pop Ioan Daniel,
Esteban Blanc, linux-iio, devicetree, linux-kernel
The ad7405 device is defined as a child of the AXI ADC.
Signed-off-by: Pop Ioan Daniel <pop.ioan-daniel@analog.com>
---
changes in v4:
- add ad7405 device that is defined as a child of the AXI ADC
.../bindings/iio/adc/adi,axi-adc.yaml | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/Documentation/devicetree/bindings/iio/adc/adi,axi-adc.yaml b/Documentation/devicetree/bindings/iio/adc/adi,axi-adc.yaml
index cf74f84d6103..a6bc8acd101f 100644
--- a/Documentation/devicetree/bindings/iio/adc/adi,axi-adc.yaml
+++ b/Documentation/devicetree/bindings/iio/adc/adi,axi-adc.yaml
@@ -135,4 +135,21 @@ examples:
io-backends = <¶llel_bus_controller>;
};
};
+ - |
+ axi_adc@44a00000 {
+ compatible = "adi,axi-adc-10.0.a";
+ reg = <0x44a00000 0x10000>;
+ dmas = <&rx_dma 0>;
+ dma-names = "rx";
+ clocks = <&axi_clk>;
+ #io-backend-cells = <0>;
+
+ adc@0 {
+ compatible = "adi,ad7405";
+ clocks = <&axi_clk_gen 0>;
+ vdd1-supply = <&vdd1>;
+ vdd2-supply = <&vdd2>;
+ io-backends = <&axi_adc>;
+ };
+ };
...
--
2.34.1
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH v4 6/6] iio: adc: ad7405: add ad7405 driver
2025-05-19 14:02 [PATCH v4 0/6] Add support for AD7405/ADUM770x Pop Ioan Daniel
` (4 preceding siblings ...)
2025-05-19 14:02 ` [PATCH v4 5/6] dt-bindings: iio: adc: adi-axi-adc: add ad7405 example Pop Ioan Daniel
@ 2025-05-19 14:02 ` Pop Ioan Daniel
2025-05-19 15:18 ` David Lechner
` (2 more replies)
2025-05-19 15:22 ` [PATCH v4 0/6] Add support for AD7405/ADUM770x David Lechner
6 siblings, 3 replies; 21+ messages in thread
From: Pop Ioan Daniel @ 2025-05-19 14:02 UTC (permalink / raw)
To: Lars-Peter Clausen, Michael Hennerich, Jonathan Cameron,
David Lechner, Nuno Sá, Andy Shevchenko, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Sergiu Cuciurean,
Dragos Bogdan, Antoniu Miclaus, Olivier Moysan, Javier Carrasco,
Matti Vaittinen, Tobias Sperling, Alisa-Dariana Roman,
Marcelo Schmitt, Pop Ioan Daniel, linux-iio, devicetree,
linux-kernel
Add support for the AD7405/ADUM770x, a high performance isolated ADC,
1-channel, 16-bit with a second-order Σ-Δ modulator that converts an
analog input signal into a high speed, single-bit data stream.
Signed-off-by: Pop Ioan Daniel <pop.ioan-daniel@analog.com>
---
changes in v4:
- changes in "depends on" instead of "select" for IIO_BACKEND in Kconfig
- remove scale_tables variables
- remove sample_frequency_tbl, sample_frequency
- remove ad7405_fill_samp_freq_table function
- rewrite ad7405_get_scale function as suggested
- make sampling_frequency read-only
- implement IIO_CHAN_INFO_OFFSET as suggested
- fix code style
drivers/iio/adc/Kconfig | 10 ++
drivers/iio/adc/Makefile | 1 +
drivers/iio/adc/ad7405.c | 250 +++++++++++++++++++++++++++++++++++++++
3 files changed, 261 insertions(+)
create mode 100644 drivers/iio/adc/ad7405.c
diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig
index ad06cf556785..43af2070e27f 100644
--- a/drivers/iio/adc/Kconfig
+++ b/drivers/iio/adc/Kconfig
@@ -251,6 +251,16 @@ config AD7380
To compile this driver as a module, choose M here: the module will be
called ad7380.
+config AD7405
+ tristate "Analog Device AD7405 ADC Driver"
+ depends on IIO_BACKEND
+ help
+ Say yes here to build support for Analog Devices AD7405, ADUM7701,
+ ADUM7702, ADUM7703 analog to digital converters (ADC).
+
+ To compile this driver as a module, choose M here: the module will be
+ called ad7405.
+
config AD7476
tristate "Analog Devices AD7476 1-channel ADCs driver and other similar devices from AD and TI"
depends on SPI
diff --git a/drivers/iio/adc/Makefile b/drivers/iio/adc/Makefile
index 07d4b832c42e..8115f30b7862 100644
--- a/drivers/iio/adc/Makefile
+++ b/drivers/iio/adc/Makefile
@@ -26,6 +26,7 @@ obj-$(CONFIG_AD7291) += ad7291.o
obj-$(CONFIG_AD7292) += ad7292.o
obj-$(CONFIG_AD7298) += ad7298.o
obj-$(CONFIG_AD7380) += ad7380.o
+obj-$(CONFIG_AD7405) += ad7405.o
obj-$(CONFIG_AD7476) += ad7476.o
obj-$(CONFIG_AD7606_IFACE_PARALLEL) += ad7606_par.o
obj-$(CONFIG_AD7606_IFACE_SPI) += ad7606_spi.o
diff --git a/drivers/iio/adc/ad7405.c b/drivers/iio/adc/ad7405.c
new file mode 100644
index 000000000000..fb249c83b87b
--- /dev/null
+++ b/drivers/iio/adc/ad7405.c
@@ -0,0 +1,250 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Analog Devices AD7405 driver
+ *
+ * Copyright 2025 Analog Devices Inc.
+ */
+
+#include <linux/clk.h>
+#include <linux/module.h>
+#include <linux/mod_devicetable.h>
+#include <linux/platform_device.h>
+#include <linux/property.h>
+#include <linux/regulator/consumer.h>
+#include <linux/util_macros.h>
+
+#include <linux/iio/backend.h>
+#include <linux/iio/iio.h>
+
+static const unsigned int ad7405_dec_rates[] = {
+ 4096, 2048, 1024, 512, 256, 128, 64, 32,
+};
+
+struct ad7405_chip_info {
+ const char *name;
+ struct iio_chan_spec channel;
+ const unsigned int full_scale_mv;
+};
+
+struct ad7405_state {
+ struct iio_backend *back;
+ const struct ad7405_chip_info *info;
+ unsigned int ref_frequency;
+ unsigned int dec_rate;
+};
+
+static int ad7405_set_dec_rate(struct iio_dev *indio_dev,
+ const struct iio_chan_spec *chan,
+ unsigned int dec_rate)
+{
+ struct ad7405_state *st = iio_priv(indio_dev);
+ int ret;
+
+ ret = iio_backend_oversampling_ratio_set(st->back, chan->scan_index, dec_rate);
+ if (ret)
+ return ret;
+
+ st->dec_rate = dec_rate;
+
+ return 0;
+}
+
+static int ad7405_get_scale(struct ad7405_state *st, int *val, int *val2)
+{
+ *val = st->info->full_scale_mv;
+ *val2 = st->info->channel.scan_type.realbits - 1;
+
+ return IIO_VAL_FRACTIONAL_LOG2;
+}
+
+static int ad7405_read_raw(struct iio_dev *indio_dev,
+ const struct iio_chan_spec *chan, int *val,
+ int *val2, long info)
+{
+ struct ad7405_state *st = iio_priv(indio_dev);
+
+ switch (info) {
+ case IIO_CHAN_INFO_SCALE:
+ return ad7405_get_scale(st, val, val2);
+ case IIO_CHAN_INFO_OVERSAMPLING_RATIO:
+ *val = st->dec_rate;
+ return IIO_VAL_INT;
+ case IIO_CHAN_INFO_SAMP_FREQ:
+ *val = DIV_ROUND_CLOSEST_ULL(st->ref_frequency, st->dec_rate);
+ return IIO_VAL_INT;
+ case IIO_CHAN_INFO_OFFSET:
+ *val = 2 << (st->info->channel.scan_type.realbits - 1);
+ return IIO_VAL_INT;
+ default:
+ return -EINVAL;
+ }
+}
+
+static int ad7405_write_raw(struct iio_dev *indio_dev,
+ struct iio_chan_spec const *chan, int val,
+ int val2, long info)
+{
+ switch (info) {
+ case IIO_CHAN_INFO_OVERSAMPLING_RATIO:
+ return ad7405_set_dec_rate(indio_dev, chan, val);
+ default:
+ return -EINVAL;
+ }
+}
+
+static int ad7405_read_avail(struct iio_dev *indio_dev,
+ struct iio_chan_spec const *chan,
+ const int **vals, int *type, int *length,
+ long info)
+{
+ switch (info) {
+ case IIO_CHAN_INFO_OVERSAMPLING_RATIO:
+ *vals = ad7405_dec_rates;
+ *length = ARRAY_SIZE(ad7405_dec_rates);
+ *type = IIO_VAL_INT;
+ return IIO_AVAIL_LIST;
+ default:
+ return -EINVAL;
+ }
+}
+
+static const struct iio_info ad7405_iio_info = {
+ .read_raw = &ad7405_read_raw,
+ .write_raw = &ad7405_write_raw,
+ .read_avail = &ad7405_read_avail,
+};
+
+#define AD7405_IIO_CHANNEL { \
+ .type = IIO_VOLTAGE, \
+ .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) | \
+ BIT(IIO_CHAN_INFO_OFFSET), \
+ .info_mask_shared_by_all = IIO_CHAN_INFO_SAMP_FREQ | \
+ BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), \
+ .info_mask_shared_by_all_available = \
+ BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), \
+ .indexed = 1, \
+ .channel = 0, \
+ .channel2 = 1, \
+ .differential = 1, \
+ .scan_index = 0, \
+ .scan_type = { \
+ .sign = 'u', \
+ .realbits = 16, \
+ .storagebits = 16, \
+ }, \
+}
+
+static const struct ad7405_chip_info ad7405_chip_info = {
+ .name = "AD7405",
+ .full_scale_mv = 320,
+ .channel = AD7405_IIO_CHANNEL,
+};
+
+static const struct ad7405_chip_info adum7701_chip_info = {
+ .name = "ADUM7701",
+ .full_scale_mv = 320,
+ .channel = AD7405_IIO_CHANNEL,
+};
+
+static const struct ad7405_chip_info adum7702_chip_info = {
+ .name = "ADUM7702",
+ .full_scale_mv = 64,
+ .channel = AD7405_IIO_CHANNEL,
+};
+
+static const struct ad7405_chip_info adum7703_chip_info = {
+ .name = "ADUM7703",
+ .full_scale_mv = 320,
+ .channel = AD7405_IIO_CHANNEL,
+};
+
+static const char * const ad7405_power_supplies[] = {
+ "vdd1", "vdd2",
+};
+
+static int ad7405_probe(struct platform_device *pdev)
+{
+ struct device *dev = &pdev->dev;
+ struct iio_dev *indio_dev;
+ struct ad7405_state *st;
+ struct clk *clk;
+ int ret;
+
+ indio_dev = devm_iio_device_alloc(dev, sizeof(*st));
+ if (!indio_dev)
+ return -ENOMEM;
+
+ st = iio_priv(indio_dev);
+
+ st->info = device_get_match_data(dev);
+ if (!st->info)
+ return dev_err_probe(dev, -EINVAL, "no chip info\n");
+
+ ret = devm_regulator_bulk_get_enable(dev, ARRAY_SIZE(ad7405_power_supplies),
+ ad7405_power_supplies);
+ if (ret)
+ return dev_err_probe(dev, ret, "failed to get and enable supplies");
+
+ clk = devm_clk_get_enabled(dev, NULL);
+ if (IS_ERR(clk))
+ return PTR_ERR(clk);
+
+ st->ref_frequency = clk_get_rate(clk);
+ if (!st->ref_frequency)
+ return -EINVAL;
+
+ indio_dev->dev.parent = dev;
+ indio_dev->name = st->info->name;
+ indio_dev->channels = &st->info->channel;
+ indio_dev->num_channels = 1;
+ indio_dev->info = &ad7405_iio_info;
+
+ st->back = devm_iio_backend_get(dev, NULL);
+ if (IS_ERR(st->back))
+ return dev_err_probe(dev, PTR_ERR(st->back),
+ "failed to get IIO backend");
+
+ ret = iio_backend_chan_enable(st->back, 0);
+ if (ret)
+ return ret;
+
+ ret = devm_iio_backend_request_buffer(dev, st->back, indio_dev);
+ if (ret)
+ return ret;
+
+ ret = devm_iio_backend_enable(dev, st->back);
+ if (ret)
+ return ret;
+
+ ret = ad7405_set_dec_rate(indio_dev, &indio_dev->channels[0], 256);
+ if (ret)
+ return ret;
+
+ return devm_iio_device_register(dev, indio_dev);
+}
+
+/* Match table for of_platform binding */
+static const struct of_device_id ad7405_of_match[] = {
+ { .compatible = "adi,ad7405", .data = &ad7405_chip_info, },
+ { .compatible = "adi,adum7701", .data = &adum7701_chip_info, },
+ { .compatible = "adi,adum7702", .data = &adum7702_chip_info, },
+ { .compatible = "adi,adum7703", .data = &adum7703_chip_info, },
+ { }
+};
+MODULE_DEVICE_TABLE(of, ad7405_of_match);
+
+static struct platform_driver ad7405_driver = {
+ .driver = {
+ .name = "ad7405",
+ .owner = THIS_MODULE,
+ .of_match_table = ad7405_of_match,
+ },
+ .probe = ad7405_probe,
+};
+module_platform_driver(ad7405_driver);
+
+MODULE_AUTHOR("Dragos Bogdan <dragos.bogdan@analog.com>");
+MODULE_AUTHOR("Pop Ioan Daniel <pop.ioan-daniel@analog.com>");
+MODULE_DESCRIPTION("Analog Devices AD7405 driver");
+MODULE_LICENSE("GPL");
+MODULE_IMPORT_NS("IIO_BACKEND");
--
2.34.1
^ permalink raw reply related [flat|nested] 21+ messages in thread
* Re: [PATCH v4 1/6] iio: adc: ad4851: ad4851_set_oversampling_ratio parameters update
2025-05-19 14:02 ` [PATCH v4 1/6] iio: adc: ad4851: ad4851_set_oversampling_ratio parameters update Pop Ioan Daniel
@ 2025-05-19 15:15 ` David Lechner
0 siblings, 0 replies; 21+ messages in thread
From: David Lechner @ 2025-05-19 15:15 UTC (permalink / raw)
To: Pop Ioan Daniel, Lars-Peter Clausen, Michael Hennerich,
Jonathan Cameron, Nuno Sá, Andy Shevchenko, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Sergiu Cuciurean,
Dragos Bogdan, Antoniu Miclaus, Olivier Moysan, Javier Carrasco,
Matti Vaittinen, Tobias Sperling, Alisa-Dariana Roman,
Marcelo Schmitt, Thomas Bonnefille, AngeloGioacchino Del Regno,
linux-iio, devicetree, linux-kernel
On 5/19/25 9:02 AM, Pop Ioan Daniel wrote:
> Remove chan parameter from ad4851_set_oversampling_ratio parameters
> list.
Commit messages should explain _why_ we should make this change.
In this case, because the parameter is unused.
>
> Signed-off-by: Pop Ioan Daniel <pop.ioan-daniel@analog.com>
> ---
Reviewed-by: David Lechner <dlechner@baylibre.com>
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH v4 2/6] iio: backend: update iio_backend_oversampling_ratio_set
2025-05-19 14:02 ` [PATCH v4 2/6] iio: backend: update iio_backend_oversampling_ratio_set Pop Ioan Daniel
@ 2025-05-19 15:15 ` David Lechner
2025-05-26 9:54 ` Nuno Sá
1 sibling, 0 replies; 21+ messages in thread
From: David Lechner @ 2025-05-19 15:15 UTC (permalink / raw)
To: Pop Ioan Daniel, Lars-Peter Clausen, Michael Hennerich,
Jonathan Cameron, Nuno Sá, Andy Shevchenko, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Sergiu Cuciurean,
Dragos Bogdan, Antoniu Miclaus, Olivier Moysan, Javier Carrasco,
Matti Vaittinen, Tobias Sperling, Alisa-Dariana Roman,
Marcelo Schmitt, Herve Codina, Trevor Gamblin, Thomas Bonnefille,
linux-iio, devicetree, linux-kernel
On 5/19/25 9:02 AM, Pop Ioan Daniel wrote:
> Add chan parameter to iio_backed_oversampling_ration_set() to allow
s/ration/ratio/
(This is a good commit message because it says _why_ :-)
> for contexts where the channel must be specified. Modify all
> existing users.
>
> Signed-off-by: Pop Ioan Daniel <pop.ioan-daniel@analog.com>
> ---
Reviewed-by: David Lechner <dlechner@baylibre.com>
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH v4 3/6] iio: adc: adi-axi-adc: add axi_adc_oversampling_ratio_set
2025-05-19 14:02 ` [PATCH v4 3/6] iio: adc: adi-axi-adc: add axi_adc_oversampling_ratio_set Pop Ioan Daniel
@ 2025-05-19 15:15 ` David Lechner
2025-05-26 9:53 ` Nuno Sá
2025-05-26 9:54 ` Nuno Sá
1 sibling, 1 reply; 21+ messages in thread
From: David Lechner @ 2025-05-19 15:15 UTC (permalink / raw)
To: Pop Ioan Daniel, Lars-Peter Clausen, Michael Hennerich,
Jonathan Cameron, Nuno Sá, Andy Shevchenko, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Sergiu Cuciurean,
Dragos Bogdan, Antoniu Miclaus, Olivier Moysan, Javier Carrasco,
Matti Vaittinen, Tobias Sperling, Alisa-Dariana Roman,
Marcelo Schmitt, João Paulo Gonçalves,
Thomas Bonnefille, linux-iio, devicetree, linux-kernel
On 5/19/25 9:02 AM, Pop Ioan Daniel wrote:
> Add support for setting decimation rate.
>
> Signed-off-by: Pop Ioan Daniel <pop.ioan-daniel@analog.com>
> ---
With the bit below fixed:
Reviewed-by: David Lechner <dlechner@baylibre.com>
...
> @@ -381,7 +397,8 @@ static int axi_adc_ad485x_data_size_set(struct iio_backend *back,
> }
>
> static int axi_adc_ad485x_oversampling_ratio_set(struct iio_backend *back,
> - unsigned int ratio)
> + unsigned int chan,
> + unsigned int ratio)
I think this change belongs in the previous patch. Most importantly because
it could cause a compile error during a git bisect, but also because that
is where it logically belongs.
> {
> struct adi_axi_adc_state *st = iio_backend_get_priv(back);
>
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH v4 4/6] dt-bindings: iio: adc: add ad7405
2025-05-19 14:02 ` [PATCH v4 4/6] dt-bindings: iio: adc: add ad7405 Pop Ioan Daniel
@ 2025-05-19 15:16 ` David Lechner
2025-05-20 6:41 ` Krzysztof Kozlowski
1 sibling, 0 replies; 21+ messages in thread
From: David Lechner @ 2025-05-19 15:16 UTC (permalink / raw)
To: Pop Ioan Daniel, Lars-Peter Clausen, Michael Hennerich,
Jonathan Cameron, Nuno Sá, Andy Shevchenko, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Sergiu Cuciurean,
Dragos Bogdan, Antoniu Miclaus, Olivier Moysan, Javier Carrasco,
Matti Vaittinen, Tobias Sperling, Marcelo Schmitt,
Alisa-Dariana Roman, Ramona Alexandra Nechita, linux-iio,
devicetree, linux-kernel
On 5/19/25 9:02 AM, Pop Ioan Daniel wrote:
> Add devicetree bindings for ad7405/adum770x family.
>
> Signed-off-by: Pop Ioan Daniel <pop.ioan-daniel@analog.com>
> ---
This patch got a Reviewed-by tag in v3, so that should have been picked
up (or give an explanation why it wasn't if there was a reason for this).
Also, Jonathan had some questions about the clock that didn't get answered.
> It's definitely wired to the ADC as a clock but it's also (I think) either
> wired up to the IP we map to the backend (from software point of view)
> or generated by that.
Yes, the clock is a standalone IP block that is connected to both the backend
and the ADC. There are some diagrams in the link below.
https://analogdevicesinc.github.io/hdl/projects/ad7405_fmc/index.html
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH v4 6/6] iio: adc: ad7405: add ad7405 driver
2025-05-19 14:02 ` [PATCH v4 6/6] iio: adc: ad7405: add ad7405 driver Pop Ioan Daniel
@ 2025-05-19 15:18 ` David Lechner
2025-05-25 11:03 ` Jonathan Cameron
2025-05-26 10:00 ` Nuno Sá
2 siblings, 0 replies; 21+ messages in thread
From: David Lechner @ 2025-05-19 15:18 UTC (permalink / raw)
To: Pop Ioan Daniel, Lars-Peter Clausen, Michael Hennerich,
Jonathan Cameron, Nuno Sá, Andy Shevchenko, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Sergiu Cuciurean,
Dragos Bogdan, Antoniu Miclaus, Olivier Moysan, Javier Carrasco,
Matti Vaittinen, Tobias Sperling, Alisa-Dariana Roman,
Marcelo Schmitt, linux-iio, devicetree, linux-kernel
On 5/19/25 9:02 AM, Pop Ioan Daniel wrote:
> Add support for the AD7405/ADUM770x, a high performance isolated ADC,
> 1-channel, 16-bit with a second-order Σ-Δ modulator that converts an
> analog input signal into a high speed, single-bit data stream.
>
> Signed-off-by: Pop Ioan Daniel <pop.ioan-daniel@analog.com>
> ---
...
> +static int ad7405_set_dec_rate(struct iio_dev *indio_dev,
> + const struct iio_chan_spec *chan,
> + unsigned int dec_rate)
> +{
> + struct ad7405_state *st = iio_priv(indio_dev);
> + int ret;
We probably want some range checking here to make sure dec_rate is exactly one of
ad7405_dec_rates before passing it to the backend.
> +
> + ret = iio_backend_oversampling_ratio_set(st->back, chan->scan_index, dec_rate);
> + if (ret)
> + return ret;
> +
> + st->dec_rate = dec_rate;
Otherwise, this will report back a wrong value to userspace in ad7405_read_raw().
> +
> + return 0;
> +}
> +
> +static int ad7405_get_scale(struct ad7405_state *st, int *val, int *val2)
> +{
> + *val = st->info->full_scale_mv;
> + *val2 = st->info->channel.scan_type.realbits - 1;
> +
> + return IIO_VAL_FRACTIONAL_LOG2;
Probably not worth having a separate function for this. Can just do it inline.
> +}
> +
> +static int ad7405_read_raw(struct iio_dev *indio_dev,
> + const struct iio_chan_spec *chan, int *val,
> + int *val2, long info)
> +{
> + struct ad7405_state *st = iio_priv(indio_dev);
> +
> + switch (info) {
> + case IIO_CHAN_INFO_SCALE:
> + return ad7405_get_scale(st, val, val2);
> + case IIO_CHAN_INFO_OVERSAMPLING_RATIO:
> + *val = st->dec_rate;
> + return IIO_VAL_INT;
> + case IIO_CHAN_INFO_SAMP_FREQ:
> + *val = DIV_ROUND_CLOSEST_ULL(st->ref_frequency, st->dec_rate);
> + return IIO_VAL_INT;
> + case IIO_CHAN_INFO_OFFSET:
> + *val = 2 << (st->info->channel.scan_type.realbits - 1);
Isn't this supposed to be:
*val = -(1 << (st->info->channel.scan_type.realbits - 1));
2 was a typo by me, but hopefully, you are testing this and doing the
math to double-check it is correct! I.e. generate a constant voltage signal
and capture some data, then convert it to mV with (raw + offset) * scale to
make sure it matches the voltage being applied to the input.
(I'm only human, so believe the math if disagrees with what I say. :-p)
> + return IIO_VAL_INT;
> + default:
> + return -EINVAL;
> + }
> +}
> +
> +static int ad7405_write_raw(struct iio_dev *indio_dev,
> + struct iio_chan_spec const *chan, int val,
> + int val2, long info)
> +{
> + switch (info) {
> + case IIO_CHAN_INFO_OVERSAMPLING_RATIO:
val can be negative here, which can cause it to turn into a large positive
number when it gets changed to unsigned since the last parameter of
ad7405_set_dec_rate has unsigned type. So we should either check for negative
first here or change the parameter to signed and check in the function.
> + return ad7405_set_dec_rate(indio_dev, chan, val);
> + default:
> + return -EINVAL;
> + }
> +}
> +
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH v4 5/6] dt-bindings: iio: adc: adi-axi-adc: add ad7405 example
2025-05-19 14:02 ` [PATCH v4 5/6] dt-bindings: iio: adc: adi-axi-adc: add ad7405 example Pop Ioan Daniel
@ 2025-05-19 15:19 ` David Lechner
2025-05-20 6:39 ` Krzysztof Kozlowski
1 sibling, 0 replies; 21+ messages in thread
From: David Lechner @ 2025-05-19 15:19 UTC (permalink / raw)
To: Pop Ioan Daniel, Lars-Peter Clausen, Michael Hennerich,
Jonathan Cameron, Nuno Sá, Andy Shevchenko, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Sergiu Cuciurean,
Dragos Bogdan, Antoniu Miclaus, Olivier Moysan, Javier Carrasco,
Matti Vaittinen, Tobias Sperling, Alisa-Dariana Roman,
Marcelo Schmitt, João Paulo Gonçalves, Esteban Blanc,
linux-iio, devicetree, linux-kernel
On 5/19/25 9:02 AM, Pop Ioan Daniel wrote:
> The ad7405 device is defined as a child of the AXI ADC.
>
> Signed-off-by: Pop Ioan Daniel <pop.ioan-daniel@analog.com>
> ---
> changes in v4:
> - add ad7405 device that is defined as a child of the AXI ADC
> .../bindings/iio/adc/adi,axi-adc.yaml | 17 +++++++++++++++++
> 1 file changed, 17 insertions(+)
>
> diff --git a/Documentation/devicetree/bindings/iio/adc/adi,axi-adc.yaml b/Documentation/devicetree/bindings/iio/adc/adi,axi-adc.yaml
> index cf74f84d6103..a6bc8acd101f 100644
> --- a/Documentation/devicetree/bindings/iio/adc/adi,axi-adc.yaml
> +++ b/Documentation/devicetree/bindings/iio/adc/adi,axi-adc.yaml
> @@ -135,4 +135,21 @@ examples:
> io-backends = <¶llel_bus_controller>;
> };
> };
> + - |
> + axi_adc@44a00000 {
> + compatible = "adi,axi-adc-10.0.a";
> + reg = <0x44a00000 0x10000>;
> + dmas = <&rx_dma 0>;
> + dma-names = "rx";
> + clocks = <&axi_clk>;
> + #io-backend-cells = <0>;
> +
> + adc@0 {
> + compatible = "adi,ad7405";
> + clocks = <&axi_clk_gen 0>;
> + vdd1-supply = <&vdd1>;
> + vdd2-supply = <&vdd2>;
> + io-backends = <&axi_adc>;
> + };
> + };
> ...
I think this example would be better placed in the adi,ad7405 binding.
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH v4 0/6] Add support for AD7405/ADUM770x
2025-05-19 14:02 [PATCH v4 0/6] Add support for AD7405/ADUM770x Pop Ioan Daniel
` (5 preceding siblings ...)
2025-05-19 14:02 ` [PATCH v4 6/6] iio: adc: ad7405: add ad7405 driver Pop Ioan Daniel
@ 2025-05-19 15:22 ` David Lechner
6 siblings, 0 replies; 21+ messages in thread
From: David Lechner @ 2025-05-19 15:22 UTC (permalink / raw)
To: Pop Ioan Daniel, Lars-Peter Clausen, Michael Hennerich,
Jonathan Cameron, Nuno Sá, Andy Shevchenko, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Sergiu Cuciurean,
Dragos Bogdan, Antoniu Miclaus, Olivier Moysan, Javier Carrasco,
Matti Vaittinen, Tobias Sperling, Alisa-Dariana Roman,
Marcelo Schmitt, Herve Codina, João Paulo Gonçalves,
AngeloGioacchino Del Regno, linux-iio, devicetree, linux-kernel
On 5/19/25 9:02 AM, Pop Ioan Daniel wrote:
> The AD7405 is a high performance, second-order, Σ-Δ modulator
> that converts an analog input signal into a high speed, single-bit
> LVDS data stream, with on-chip digital isolation based on Analog
> Devices, Inc., iCoupler technology. The AD7405 operates from a
> 4.5 V to 5.5 V (VDD1) power supply and accepts a differential input
> signal of ±250 mV (±320 mV full-scale). The differential input is ideally
> suited to shunt voltage monitoring in high voltage applications
> where galvanic isolation is required.
>
Adding links to the previous revisions, e.g. on lore here is helpful
for lazy reviewers. It saves time having to manually look them up to
see what was discussed before.
> MIME-Version: 1.0
> Content-Type: text/plain; charset=UTF-8
> Content-Transfer-Encoding: 8bit
Odd to have email headers in the message body.
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH v4 5/6] dt-bindings: iio: adc: adi-axi-adc: add ad7405 example
2025-05-19 14:02 ` [PATCH v4 5/6] dt-bindings: iio: adc: adi-axi-adc: add ad7405 example Pop Ioan Daniel
2025-05-19 15:19 ` David Lechner
@ 2025-05-20 6:39 ` Krzysztof Kozlowski
1 sibling, 0 replies; 21+ messages in thread
From: Krzysztof Kozlowski @ 2025-05-20 6:39 UTC (permalink / raw)
To: Pop Ioan Daniel
Cc: Lars-Peter Clausen, Michael Hennerich, Jonathan Cameron,
David Lechner, Nuno Sá, Andy Shevchenko, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Sergiu Cuciurean,
Dragos Bogdan, Antoniu Miclaus, Olivier Moysan, Javier Carrasco,
Matti Vaittinen, Tobias Sperling, Alisa-Dariana Roman,
Marcelo Schmitt, João Paulo Gonçalves, Esteban Blanc,
linux-iio, devicetree, linux-kernel
On Mon, May 19, 2025 at 05:02:13PM GMT, Pop Ioan Daniel wrote:
> The ad7405 device is defined as a child of the AXI ADC.
1. Why? What we see easily (although not here, because above does not
answer even to what).
2. I do not see any device being added to the binding.
>
> Signed-off-by: Pop Ioan Daniel <pop.ioan-daniel@analog.com>
> ---
> changes in v4:
> - add ad7405 device that is defined as a child of the AXI ADC
> .../bindings/iio/adc/adi,axi-adc.yaml | 17 +++++++++++++++++
> 1 file changed, 17 insertions(+)
>
> diff --git a/Documentation/devicetree/bindings/iio/adc/adi,axi-adc.yaml b/Documentation/devicetree/bindings/iio/adc/adi,axi-adc.yaml
> index cf74f84d6103..a6bc8acd101f 100644
> --- a/Documentation/devicetree/bindings/iio/adc/adi,axi-adc.yaml
> +++ b/Documentation/devicetree/bindings/iio/adc/adi,axi-adc.yaml
> @@ -135,4 +135,21 @@ examples:
> io-backends = <¶llel_bus_controller>;
> };
> };
> + - |
> + axi_adc@44a00000 {
Follow DTS coding style.
> + compatible = "adi,axi-adc-10.0.a";
> + reg = <0x44a00000 0x10000>;
> + dmas = <&rx_dma 0>;
> + dma-names = "rx";
> + clocks = <&axi_clk>;
> + #io-backend-cells = <0>;
This example is already there, so I do not get why you duplicate it.
Skip the patch or with reason add the child to the existing example.
> +
> + adc@0 {
> + compatible = "adi,ad7405";
Best regards,
Krzysztof
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH v4 4/6] dt-bindings: iio: adc: add ad7405
2025-05-19 14:02 ` [PATCH v4 4/6] dt-bindings: iio: adc: add ad7405 Pop Ioan Daniel
2025-05-19 15:16 ` David Lechner
@ 2025-05-20 6:41 ` Krzysztof Kozlowski
1 sibling, 0 replies; 21+ messages in thread
From: Krzysztof Kozlowski @ 2025-05-20 6:41 UTC (permalink / raw)
To: Pop Ioan Daniel
Cc: Lars-Peter Clausen, Michael Hennerich, Jonathan Cameron,
David Lechner, Nuno Sá, Andy Shevchenko, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Sergiu Cuciurean,
Dragos Bogdan, Antoniu Miclaus, Olivier Moysan, Javier Carrasco,
Matti Vaittinen, Tobias Sperling, Marcelo Schmitt,
Alisa-Dariana Roman, Ramona Alexandra Nechita, linux-iio,
devicetree, linux-kernel
On Mon, May 19, 2025 at 05:02:12PM GMT, Pop Ioan Daniel wrote:
> Add devicetree bindings for ad7405/adum770x family.
>
> Signed-off-by: Pop Ioan Daniel <pop.ioan-daniel@analog.com>
> ---
> no changes in v4.
And v3, v2, v1?
What about tag? Can you start using b4, so such problems won't repeat
plus you will have appropriate cover letter with changelog and links?
Best regards,
Krzysztof
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH v4 6/6] iio: adc: ad7405: add ad7405 driver
2025-05-19 14:02 ` [PATCH v4 6/6] iio: adc: ad7405: add ad7405 driver Pop Ioan Daniel
2025-05-19 15:18 ` David Lechner
@ 2025-05-25 11:03 ` Jonathan Cameron
2025-05-26 10:00 ` Nuno Sá
2 siblings, 0 replies; 21+ messages in thread
From: Jonathan Cameron @ 2025-05-25 11:03 UTC (permalink / raw)
To: Pop Ioan Daniel
Cc: Lars-Peter Clausen, Michael Hennerich, David Lechner,
Nuno Sá, Andy Shevchenko, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Sergiu Cuciurean, Dragos Bogdan, Antoniu Miclaus,
Olivier Moysan, Javier Carrasco, Matti Vaittinen, Tobias Sperling,
Alisa-Dariana Roman, Marcelo Schmitt, linux-iio, devicetree,
linux-kernel
On Mon, 19 May 2025 17:02:14 +0300
Pop Ioan Daniel <pop.ioan-daniel@analog.com> wrote:
> Add support for the AD7405/ADUM770x, a high performance isolated ADC,
> 1-channel, 16-bit with a second-order Σ-Δ modulator that converts an
> analog input signal into a high speed, single-bit data stream.
>
> Signed-off-by: Pop Ioan Daniel <pop.ioan-daniel@analog.com>
Hi Pop,
Just one additional trivial comment from me as you are going around
again anyway.
Thanks,
J
> diff --git a/drivers/iio/adc/Makefile b/drivers/iio/adc/Makefile
> index 07d4b832c42e..8115f30b7862 100644
> --- a/drivers/iio/adc/Makefile
> +++ b/drivers/iio/adc/Makefile
> @@ -26,6 +26,7 @@ obj-$(CONFIG_AD7291) += ad7291.o
> obj-$(CONFIG_AD7292) += ad7292.o
> obj-$(CONFIG_AD7298) += ad7298.o
> obj-$(CONFIG_AD7380) += ad7380.o
> +obj-$(CONFIG_AD7405) += ad7405.o
> obj-$(CONFIG_AD7476) += ad7476.o
> obj-$(CONFIG_AD7606_IFACE_PARALLEL) += ad7606_par.o
> obj-$(CONFIG_AD7606_IFACE_SPI) += ad7606_spi.o
> diff --git a/drivers/iio/adc/ad7405.c b/drivers/iio/adc/ad7405.c
> +
> +/* Match table for of_platform binding */
This comment doesn't really add anything useful so I'd drop it.
> +static const struct of_device_id ad7405_of_match[] = {
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH v4 3/6] iio: adc: adi-axi-adc: add axi_adc_oversampling_ratio_set
2025-05-19 15:15 ` David Lechner
@ 2025-05-26 9:53 ` Nuno Sá
0 siblings, 0 replies; 21+ messages in thread
From: Nuno Sá @ 2025-05-26 9:53 UTC (permalink / raw)
To: David Lechner, Pop Ioan Daniel, Lars-Peter Clausen,
Michael Hennerich, Jonathan Cameron, Nuno Sá,
Andy Shevchenko, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Sergiu Cuciurean, Dragos Bogdan, Antoniu Miclaus, Olivier Moysan,
Javier Carrasco, Matti Vaittinen, Tobias Sperling,
Alisa-Dariana Roman, Marcelo Schmitt,
João Paulo Gonçalves, Thomas Bonnefille, linux-iio,
devicetree, linux-kernel
On Mon, 2025-05-19 at 10:15 -0500, David Lechner wrote:
> On 5/19/25 9:02 AM, Pop Ioan Daniel wrote:
> > Add support for setting decimation rate.
> >
> > Signed-off-by: Pop Ioan Daniel <pop.ioan-daniel@analog.com>
> > ---
>
> With the bit below fixed:
>
> Reviewed-by: David Lechner <dlechner@baylibre.com>
>
> ...
> > @@ -381,7 +397,8 @@ static int axi_adc_ad485x_data_size_set(struct
> > iio_backend *back,
> > }
> >
> > static int axi_adc_ad485x_oversampling_ratio_set(struct iio_backend *back,
> > - unsigned int ratio)
> > + unsigned int chan,
> > + unsigned int ratio)
>
> I think this change belongs in the previous patch. Most importantly because
> it could cause a compile error during a git bisect, but also because that
> is where it logically belongs.
I was wondering about this. Definitely needs to be in the previous one...
>
> > {
> > struct adi_axi_adc_state *st = iio_backend_get_priv(back);
> >
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH v4 2/6] iio: backend: update iio_backend_oversampling_ratio_set
2025-05-19 14:02 ` [PATCH v4 2/6] iio: backend: update iio_backend_oversampling_ratio_set Pop Ioan Daniel
2025-05-19 15:15 ` David Lechner
@ 2025-05-26 9:54 ` Nuno Sá
1 sibling, 0 replies; 21+ messages in thread
From: Nuno Sá @ 2025-05-26 9:54 UTC (permalink / raw)
To: Pop Ioan Daniel, Lars-Peter Clausen, Michael Hennerich,
Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
Rob Herring, Krzysztof Kozlowski, Conor Dooley, Sergiu Cuciurean,
Dragos Bogdan, Antoniu Miclaus, Olivier Moysan, Javier Carrasco,
Matti Vaittinen, Tobias Sperling, Alisa-Dariana Roman,
Marcelo Schmitt, Herve Codina, Trevor Gamblin, Thomas Bonnefille,
linux-iio, devicetree, linux-kernel
On Mon, 2025-05-19 at 17:02 +0300, Pop Ioan Daniel wrote:
> Add chan parameter to iio_backed_oversampling_ration_set() to allow
> for contexts where the channel must be specified. Modify all
> existing users.
>
> Signed-off-by: Pop Ioan Daniel <pop.ioan-daniel@analog.com>
> ---
With the change requested by David in the following patch:
Reviewed-by: Nuno Sá <nuno.sa@analog.com>
> changes in v4:
> - pass 0 in the list of parameters instead of chan
> drivers/iio/adc/ad4851.c | 4 ++--
> drivers/iio/industrialio-backend.c | 3 ++-
> include/linux/iio/backend.h | 3 ++-
> 3 files changed, 6 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/iio/adc/ad4851.c b/drivers/iio/adc/ad4851.c
> index 12f90aa3a156..1f975858c496 100644
> --- a/drivers/iio/adc/ad4851.c
> +++ b/drivers/iio/adc/ad4851.c
> @@ -319,8 +319,8 @@ static int ad4851_set_oversampling_ratio(struct iio_dev
> *indio_dev,
> if (ret)
> return ret;
> }
> -
> - ret = iio_backend_oversampling_ratio_set(st->back, osr);
> + /* Channel is ignored by the backend being used here */
> + ret = iio_backend_oversampling_ratio_set(st->back, 0, osr);
> if (ret)
> return ret;
>
> diff --git a/drivers/iio/industrialio-backend.c b/drivers/iio/industrialio-
> backend.c
> index c1eb9ef9db08..a4e3e54fecb1 100644
> --- a/drivers/iio/industrialio-backend.c
> +++ b/drivers/iio/industrialio-backend.c
> @@ -720,9 +720,10 @@ EXPORT_SYMBOL_NS_GPL(iio_backend_data_size_set,
> "IIO_BACKEND");
> * 0 on success, negative error number on failure.
> */
> int iio_backend_oversampling_ratio_set(struct iio_backend *back,
> + unsigned int chan,
> unsigned int ratio)
> {
> - return iio_backend_op_call(back, oversampling_ratio_set, ratio);
> + return iio_backend_op_call(back, oversampling_ratio_set, chan,
> ratio);
> }
> EXPORT_SYMBOL_NS_GPL(iio_backend_oversampling_ratio_set, "IIO_BACKEND");
>
> diff --git a/include/linux/iio/backend.h b/include/linux/iio/backend.h
> index e59d909cb659..dbf4e4a5f4b1 100644
> --- a/include/linux/iio/backend.h
> +++ b/include/linux/iio/backend.h
> @@ -144,7 +144,7 @@ struct iio_backend_ops {
> enum iio_backend_interface_type *type);
> int (*data_size_set)(struct iio_backend *back, unsigned int size);
> int (*oversampling_ratio_set)(struct iio_backend *back,
> - unsigned int ratio);
> + unsigned int chan, unsigned int ratio);
> int (*read_raw)(struct iio_backend *back,
> struct iio_chan_spec const *chan, int *val, int
> *val2,
> long mask);
> @@ -209,6 +209,7 @@ int iio_backend_interface_type_get(struct iio_backend
> *back,
> enum iio_backend_interface_type *type);
> int iio_backend_data_size_set(struct iio_backend *back, unsigned int size);
> int iio_backend_oversampling_ratio_set(struct iio_backend *back,
> + unsigned int chan,
> unsigned int ratio);
> int iio_backend_read_raw(struct iio_backend *back,
> struct iio_chan_spec const *chan, int *val, int
> *val2,
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH v4 3/6] iio: adc: adi-axi-adc: add axi_adc_oversampling_ratio_set
2025-05-19 14:02 ` [PATCH v4 3/6] iio: adc: adi-axi-adc: add axi_adc_oversampling_ratio_set Pop Ioan Daniel
2025-05-19 15:15 ` David Lechner
@ 2025-05-26 9:54 ` Nuno Sá
1 sibling, 0 replies; 21+ messages in thread
From: Nuno Sá @ 2025-05-26 9:54 UTC (permalink / raw)
To: Pop Ioan Daniel, Lars-Peter Clausen, Michael Hennerich,
Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
Rob Herring, Krzysztof Kozlowski, Conor Dooley, Sergiu Cuciurean,
Dragos Bogdan, Antoniu Miclaus, Olivier Moysan, Javier Carrasco,
Matti Vaittinen, Tobias Sperling, Alisa-Dariana Roman,
Marcelo Schmitt, João Paulo Gonçalves,
Thomas Bonnefille, linux-iio, devicetree, linux-kernel
On Mon, 2025-05-19 at 17:02 +0300, Pop Ioan Daniel wrote:
> Add support for setting decimation rate.
>
> Signed-off-by: Pop Ioan Daniel <pop.ioan-daniel@analog.com>
> ---
And with the requested change:
Reviewed-by: Nuno Sá <nuno.sa@analog.com>
> no changes in v4.
> drivers/iio/adc/adi-axi-adc.c | 20 +++++++++++++++++++-
> 1 file changed, 19 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/iio/adc/adi-axi-adc.c b/drivers/iio/adc/adi-axi-adc.c
> index 4116c44197b8..0b8673668745 100644
> --- a/drivers/iio/adc/adi-axi-adc.c
> +++ b/drivers/iio/adc/adi-axi-adc.c
> @@ -80,6 +80,9 @@
> #define ADI_AXI_ADC_REG_CHAN_CTRL_3(c) (0x0418 + (c) * 0x40)
> #define ADI_AXI_ADC_CHAN_PN_SEL_MASK GENMASK(19, 16)
>
> +#define ADI_AXI_ADC_REG_CHAN_USR_CTRL_2(c) (0x0424 + (c) * 0x40)
> +#define ADI_AXI_ADC_CHAN_USR_CTRL_2_DEC_RATE_N_MASK GENMASK(15,
> 0)
> +
> /* IO Delays */
> #define ADI_AXI_ADC_REG_DELAY(l) (0x0800 + (l) * 0x4)
> #define AXI_ADC_DELAY_CTRL_MASK GENMASK(4, 0)
> @@ -242,6 +245,19 @@ static int axi_adc_test_pattern_set(struct iio_backend
> *back,
> }
> }
>
> +static int axi_adc_oversampling_ratio_set(struct iio_backend *back,
> + unsigned int chan,
> + unsigned int rate)
> +{
> + struct adi_axi_adc_state *st = iio_backend_get_priv(back);
> +
> + return regmap_update_bits(st->regmap,
> + ADI_AXI_ADC_REG_CHAN_USR_CTRL_2(chan),
> +
> ADI_AXI_ADC_CHAN_USR_CTRL_2_DEC_RATE_N_MASK,
> +
> FIELD_PREP(ADI_AXI_ADC_CHAN_USR_CTRL_2_DEC_RATE_N_MASK,
> + rate));
> +}
> +
> static int axi_adc_read_chan_status(struct adi_axi_adc_state *st, unsigned
> int chan,
> unsigned int *status)
> {
> @@ -381,7 +397,8 @@ static int axi_adc_ad485x_data_size_set(struct iio_backend
> *back,
> }
>
> static int axi_adc_ad485x_oversampling_ratio_set(struct iio_backend *back,
> - unsigned int ratio)
> + unsigned int chan,
> + unsigned int ratio)
> {
> struct adi_axi_adc_state *st = iio_backend_get_priv(back);
>
> @@ -549,6 +566,7 @@ static const struct iio_backend_ops adi_axi_adc_ops = {
> .test_pattern_set = axi_adc_test_pattern_set,
> .chan_status = axi_adc_chan_status,
> .interface_type_get = axi_adc_interface_type_get,
> + .oversampling_ratio_set = axi_adc_oversampling_ratio_set,
> .debugfs_reg_access = iio_backend_debugfs_ptr(axi_adc_reg_access),
> .debugfs_print_chan_status =
> iio_backend_debugfs_ptr(axi_adc_debugfs_print_chan_status),
> };
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH v4 6/6] iio: adc: ad7405: add ad7405 driver
2025-05-19 14:02 ` [PATCH v4 6/6] iio: adc: ad7405: add ad7405 driver Pop Ioan Daniel
2025-05-19 15:18 ` David Lechner
2025-05-25 11:03 ` Jonathan Cameron
@ 2025-05-26 10:00 ` Nuno Sá
2 siblings, 0 replies; 21+ messages in thread
From: Nuno Sá @ 2025-05-26 10:00 UTC (permalink / raw)
To: Pop Ioan Daniel, Lars-Peter Clausen, Michael Hennerich,
Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
Rob Herring, Krzysztof Kozlowski, Conor Dooley, Sergiu Cuciurean,
Dragos Bogdan, Antoniu Miclaus, Olivier Moysan, Javier Carrasco,
Matti Vaittinen, Tobias Sperling, Alisa-Dariana Roman,
Marcelo Schmitt, linux-iio, devicetree, linux-kernel
On Mon, 2025-05-19 at 17:02 +0300, Pop Ioan Daniel wrote:
> Add support for the AD7405/ADUM770x, a high performance isolated ADC,
> 1-channel, 16-bit with a second-order Σ-Δ modulator that converts an
> analog input signal into a high speed, single-bit data stream.
>
> Signed-off-by: Pop Ioan Daniel <pop.ioan-daniel@analog.com>
> ---
Hi,
Just a couple of notes from me...
> changes in v4:
> - changes in "depends on" instead of "select" for IIO_BACKEND in Kconfig
> - remove scale_tables variables
> - remove sample_frequency_tbl, sample_frequency
> - remove ad7405_fill_samp_freq_table function
> - rewrite ad7405_get_scale function as suggested
> - make sampling_frequency read-only
> - implement IIO_CHAN_INFO_OFFSET as suggested
> - fix code style
>
> drivers/iio/adc/Kconfig | 10 ++
> drivers/iio/adc/Makefile | 1 +
> drivers/iio/adc/ad7405.c | 250 +++++++++++++++++++++++++++++++++++++++
> 3 files changed, 261 insertions(+)
> create mode 100644 drivers/iio/adc/ad7405.c
>
> diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig
> index ad06cf556785..43af2070e27f 100644
> --- a/drivers/iio/adc/Kconfig
> +++ b/drivers/iio/adc/Kconfig
> @@ -251,6 +251,16 @@ config AD7380
> To compile this driver as a module, choose M here: the module will
> be
> called ad7380.
>
> +config AD7405
> + tristate "Analog Device AD7405 ADC Driver"
> + depends on IIO_BACKEND
> + help
> + Say yes here to build support for Analog Devices AD7405, ADUM7701,
> + ADUM7702, ADUM7703 analog to digital converters (ADC).
> +
> + To compile this driver as a module, choose M here: the module will
> be
> + called ad7405.
> +
> config AD7476
> tristate "Analog Devices AD7476 1-channel ADCs driver and other
> similar devices from AD and TI"
> depends on SPI
> diff --git a/drivers/iio/adc/Makefile b/drivers/iio/adc/Makefile
> index 07d4b832c42e..8115f30b7862 100644
> --- a/drivers/iio/adc/Makefile
> +++ b/drivers/iio/adc/Makefile
> @@ -26,6 +26,7 @@ obj-$(CONFIG_AD7291) += ad7291.o
> obj-$(CONFIG_AD7292) += ad7292.o
> obj-$(CONFIG_AD7298) += ad7298.o
> obj-$(CONFIG_AD7380) += ad7380.o
> +obj-$(CONFIG_AD7405) += ad7405.o
> obj-$(CONFIG_AD7476) += ad7476.o
> obj-$(CONFIG_AD7606_IFACE_PARALLEL) += ad7606_par.o
> obj-$(CONFIG_AD7606_IFACE_SPI) += ad7606_spi.o
> diff --git a/drivers/iio/adc/ad7405.c b/drivers/iio/adc/ad7405.c
> new file mode 100644
> index 000000000000..fb249c83b87b
> --- /dev/null
> +++ b/drivers/iio/adc/ad7405.c
> @@ -0,0 +1,250 @@
> +// SPDX-License-Identifier: GPL-2.0-only
> +/*
> + * Analog Devices AD7405 driver
> + *
> + * Copyright 2025 Analog Devices Inc.
> + */
> +
> +#include <linux/clk.h>
> +#include <linux/module.h>
> +#include <linux/mod_devicetable.h>
> +#include <linux/platform_device.h>
> +#include <linux/property.h>
> +#include <linux/regulator/consumer.h>
> +#include <linux/util_macros.h>
> +
> +#include <linux/iio/backend.h>
> +#include <linux/iio/iio.h>
> +
> +static const unsigned int ad7405_dec_rates[] = {
> + 4096, 2048, 1024, 512, 256, 128, 64, 32,
> +};
> +
> +struct ad7405_chip_info {
> + const char *name;
> + struct iio_chan_spec channel;
> + const unsigned int full_scale_mv;
> +};
> +
> +struct ad7405_state {
> + struct iio_backend *back;
> + const struct ad7405_chip_info *info;
> + unsigned int ref_frequency;
> + unsigned int dec_rate;
> +};
> +
> +static int ad7405_set_dec_rate(struct iio_dev *indio_dev,
> + const struct iio_chan_spec *chan,
> + unsigned int dec_rate)
> +{
> + struct ad7405_state *st = iio_priv(indio_dev);
> + int ret;
> +
> + ret = iio_backend_oversampling_ratio_set(st->back, chan->scan_index,
> dec_rate);
> + if (ret)
> + return ret;
> +
> + st->dec_rate = dec_rate;
> +
> + return 0;
> +}
> +
> +static int ad7405_get_scale(struct ad7405_state *st, int *val, int *val2)
> +{
> + *val = st->info->full_scale_mv;
> + *val2 = st->info->channel.scan_type.realbits - 1;
> +
> + return IIO_VAL_FRACTIONAL_LOG2;
> +}
> +
> +static int ad7405_read_raw(struct iio_dev *indio_dev,
> + const struct iio_chan_spec *chan, int *val,
> + int *val2, long info)
> +{
> + struct ad7405_state *st = iio_priv(indio_dev);
> +
> + switch (info) {
> + case IIO_CHAN_INFO_SCALE:
> + return ad7405_get_scale(st, val, val2);
> + case IIO_CHAN_INFO_OVERSAMPLING_RATIO:
> + *val = st->dec_rate;
I'm typically picky with this but I really think that we need a lock to be used
here and in ad7405_set_dec_rate(). Alternatively we could add
iio_backend_oversampling_ratio_get() but I would likely avoid a new op just for
this.
> + return IIO_VAL_INT;
> + case IIO_CHAN_INFO_SAMP_FREQ:
> + *val = DIV_ROUND_CLOSEST_ULL(st->ref_frequency, st-
> >dec_rate);
> + return IIO_VAL_INT;
> + case IIO_CHAN_INFO_OFFSET:
> + *val = 2 << (st->info->channel.scan_type.realbits - 1);
> + return IIO_VAL_INT;
> + default:
> + return -EINVAL;
> + }
> +}
> +
> +static int ad7405_write_raw(struct iio_dev *indio_dev,
> + struct iio_chan_spec const *chan, int val,
> + int val2, long info)
> +{
> + switch (info) {
> + case IIO_CHAN_INFO_OVERSAMPLING_RATIO:
> + return ad7405_set_dec_rate(indio_dev, chan, val);
> + default:
> + return -EINVAL;
> + }
> +}
> +
> +static int ad7405_read_avail(struct iio_dev *indio_dev,
> + struct iio_chan_spec const *chan,
> + const int **vals, int *type, int *length,
> + long info)
> +{
> + switch (info) {
> + case IIO_CHAN_INFO_OVERSAMPLING_RATIO:
> + *vals = ad7405_dec_rates;
> + *length = ARRAY_SIZE(ad7405_dec_rates);
> + *type = IIO_VAL_INT;
> + return IIO_AVAIL_LIST;
> + default:
> + return -EINVAL;
> + }
> +}
> +
> +static const struct iio_info ad7405_iio_info = {
> + .read_raw = &ad7405_read_raw,
> + .write_raw = &ad7405_write_raw,
> + .read_avail = &ad7405_read_avail,
> +};
> +
> +#define AD7405_IIO_CHANNEL { \
> + .type = IIO_VOLTAGE, \
> + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) | \
> + BIT(IIO_CHAN_INFO_OFFSET), \
> + .info_mask_shared_by_all = IIO_CHAN_INFO_SAMP_FREQ | \
> + BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), \
> + .info_mask_shared_by_all_available = \
> + BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), \
> + .indexed = 1, \
> + .channel = 0, \
> + .channel2 = 1, \
> + .differential = 1, \
> + .scan_index = 0, \
> + .scan_type = { \
> + .sign = 'u', \
> + .realbits = 16, \
> + .storagebits = 16, \
> + }, \
> +}
> +
> +static const struct ad7405_chip_info ad7405_chip_info = {
> + .name = "AD7405",
> + .full_scale_mv = 320,
> + .channel = AD7405_IIO_CHANNEL,
> +};
> +
> +static const struct ad7405_chip_info adum7701_chip_info = {
> + .name = "ADUM7701",
> + .full_scale_mv = 320,
> + .channel = AD7405_IIO_CHANNEL,
> +};
> +
> +static const struct ad7405_chip_info adum7702_chip_info = {
> + .name = "ADUM7702",
> + .full_scale_mv = 64,
> + .channel = AD7405_IIO_CHANNEL,
> +};
> +
> +static const struct ad7405_chip_info adum7703_chip_info = {
> + .name = "ADUM7703",
> + .full_scale_mv = 320,
> + .channel = AD7405_IIO_CHANNEL,
> +};
> +
> +static const char * const ad7405_power_supplies[] = {
> + "vdd1", "vdd2",
> +};
> +
> +static int ad7405_probe(struct platform_device *pdev)
> +{
> + struct device *dev = &pdev->dev;
> + struct iio_dev *indio_dev;
> + struct ad7405_state *st;
> + struct clk *clk;
> + int ret;
> +
> + indio_dev = devm_iio_device_alloc(dev, sizeof(*st));
> + if (!indio_dev)
> + return -ENOMEM;
> +
> + st = iio_priv(indio_dev);
> +
> + st->info = device_get_match_data(dev);
> + if (!st->info)
> + return dev_err_probe(dev, -EINVAL, "no chip info\n");
> +
> + ret = devm_regulator_bulk_get_enable(dev,
> ARRAY_SIZE(ad7405_power_supplies),
> + ad7405_power_supplies);
> + if (ret)
> + return dev_err_probe(dev, ret, "failed to get and enable
> supplies");
> +
> + clk = devm_clk_get_enabled(dev, NULL);
> + if (IS_ERR(clk))
> + return PTR_ERR(clk);
> +
> + st->ref_frequency = clk_get_rate(clk);
> + if (!st->ref_frequency)
> + return -EINVAL;
> +
> + indio_dev->dev.parent = dev;
no need for the above
- Nuno Sá
^ permalink raw reply [flat|nested] 21+ messages in thread
end of thread, other threads:[~2025-05-26 10:00 UTC | newest]
Thread overview: 21+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-19 14:02 [PATCH v4 0/6] Add support for AD7405/ADUM770x Pop Ioan Daniel
2025-05-19 14:02 ` [PATCH v4 1/6] iio: adc: ad4851: ad4851_set_oversampling_ratio parameters update Pop Ioan Daniel
2025-05-19 15:15 ` David Lechner
2025-05-19 14:02 ` [PATCH v4 2/6] iio: backend: update iio_backend_oversampling_ratio_set Pop Ioan Daniel
2025-05-19 15:15 ` David Lechner
2025-05-26 9:54 ` Nuno Sá
2025-05-19 14:02 ` [PATCH v4 3/6] iio: adc: adi-axi-adc: add axi_adc_oversampling_ratio_set Pop Ioan Daniel
2025-05-19 15:15 ` David Lechner
2025-05-26 9:53 ` Nuno Sá
2025-05-26 9:54 ` Nuno Sá
2025-05-19 14:02 ` [PATCH v4 4/6] dt-bindings: iio: adc: add ad7405 Pop Ioan Daniel
2025-05-19 15:16 ` David Lechner
2025-05-20 6:41 ` Krzysztof Kozlowski
2025-05-19 14:02 ` [PATCH v4 5/6] dt-bindings: iio: adc: adi-axi-adc: add ad7405 example Pop Ioan Daniel
2025-05-19 15:19 ` David Lechner
2025-05-20 6:39 ` Krzysztof Kozlowski
2025-05-19 14:02 ` [PATCH v4 6/6] iio: adc: ad7405: add ad7405 driver Pop Ioan Daniel
2025-05-19 15:18 ` David Lechner
2025-05-25 11:03 ` Jonathan Cameron
2025-05-26 10:00 ` Nuno Sá
2025-05-19 15:22 ` [PATCH v4 0/6] Add support for AD7405/ADUM770x David Lechner
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).