Skip to contentSkip to conversation

iio: adc: add new ad7625 driver

PATCH Superseded Trevor Gamblin 5 participants 14 messages Sep 4, 2024 – Sep 9, 2024

Subsystems (5)

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Trevor Gamblin

author reviewer
#0 lore raw

v4 cover iio: adc: add new ad7625 driver

This series adds a new driver for the Analog Devices Inc. AD7625, AD7626, AD7960, and AD7961. These chips are part of a family of LVDS-based SAR ADCs. The initial driver implementation does not support the devices' self-clocked mode, although that can be added later.

The devices make use of two offset PWM signals, one to trigger conversions and the other as a burst signal for transferring data to the host. These rely on the new PWM waveform functionality being reviewed in [1] and also available at [2].

This work is being done by BayLibre and on behalf of Analog Devices Inc., hence the maintainers are @analog.com.

Special thanks to David Lechner for his guidance and reviews.

[1]: https://lore.kernel.org/linux-pwm/[email protected]
[2]: https://git.kernel.org/pub/scm/linux/kernel/git/ukleinek/linux.git/log/?h=pwm/chardev

---
Changes in v4:
- Link to v3: https://lore.kernel.org/r/[email protected]
- Rebase on top of latest pwm/chardev branch at:
https://git.kernel.org/pub/scm/linux/kernel/git/ukleinek/linux.git/log/?h=pwm/chardev

[PATCH 1/3]
- No change

[PATCH 2/3]
- Add 'depends on PWM' under 'CONFIG AD7625' in drivers/iio/adc/Kconfig, based on v3 discussions
- Cleanup whitespace usage in Kconfig, bandwidth logic to match Jonathan's suggestions

[PATCH 3/3]
- No change

Changes in v3:
- Link to v2: https://lore.kernel.org/r/[email protected]

[PATCH 1/3]
- Add gpio bindings header, en0-gpios and en1-gpios to binding example
- Remove unnecessary comments

[PATCH 2/3]
- No change

[PATCH 3/3]
- No change

Changes in v2:
- Link to v1 (marked as RFC): https://lore.kernel.org/r/[email protected]
- Include link to required PWM patch series in cover letter (missing before)
- Include new link to the pwm/chardev branch of Uwe's kernel tree

[PATCH 1/3]
- Rework dt bindings to be compliant using make dt_binding_check
- Add "adi,no-dco" flag to address indication of how DCO lines are configured
- Fix binding patch message
- Remove chip packaging info from binding description
- Move comments around to be clearer

[PATCH 2/3]
- Remove ad7625_pwm_disable(), call pwm_disable() directly
- Add ad7625_buffer_preenable() and ad7625_buffer_postdisable() functions
- Add devm_ad7625_regulator_setup() function, move all regulator logic to it, consolidate the comment blocks related to it above
- Add have_refin flag in ad7625_state struct
- Add pwm_waveform structs to ad7625_state struct for storing requested waveform characteristics
- Refactor ad7625_set_sampling_freq() to set the pwm_waveform struct values in ad7625_state, limiting PWM enable/disable to preenable/postdisable functions
- Remove redundant dev_err_probe() after devm_ad7625_pwm_get()
- Use device_property_read_bool() instead of device_property_present()
- General alignment and line wrapping fixes

[PATCH 3/3]
- No change

---
Trevor Gamblin (3):
dt-bindings: iio: adc: add AD762x/AD796x ADCs
iio: adc: ad7625: add driver
docs: iio: new docs for ad7625 driver

 .../devicetree/bindings/iio/adc/adi,ad7625.yaml    | 176 ++++++
 Documentation/iio/ad7625.rst                       |  91 +++
 MAINTAINERS                                        |  11 +
 drivers/iio/adc/Kconfig                            |  16 +
 drivers/iio/adc/Makefile                           |   1 +
 drivers/iio/adc/ad7625.c                           | 684 +++++++++++++++++++++
 6 files changed, 979 insertions(+)

---
base-commit: 1ebd3850421749eb44bd040b249bd4db88d35b33
change-id: 20240730-ad7625_r1-60d17ea28958

Best regards,

Signature · 1 line
Trevor Gamblin <[email protected]>
author reviewer
#1 lore raw

PATCH v4 1/3 dt-bindings: iio: adc: add AD762x/AD796x ADCs

Add a binding specification for the Analog Devices Inc. AD7625, AD7626, AD7960, and AD7961 ADCs.

---
 .../devicetree/bindings/iio/adc/adi,ad7625.yaml    | 176 +++++++++++++++++++++
 MAINTAINERS                                        |   9 ++
 2 files changed, 185 insertions(+)
Documentation/devicetree/bindings/iio/adc/adi,ad7625.yaml new file +176 -0
new file mode 100644
index 000000000000..8848562af28f
@@ -0,0 +1,176 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/iio/adc/adi,ad7625.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Analog Devices Fast PulSAR Analog to Digital Converters
+
+maintainers:
+  - Michael Hennerich <[email protected]>
+  - Nuno Sá <[email protected]>
+
+description: |
+  A family of single channel differential analog to digital converters.
+
+  * https://www.analog.com/en/products/ad7625.html
+  * https://www.analog.com/en/products/ad7626.html
+  * https://www.analog.com/en/products/ad7960.html
+  * https://www.analog.com/en/products/ad7961.html
+
+properties:
+  compatible:
+    enum:
+      - adi,ad7625
+      - adi,ad7626
+      - adi,ad7960
+      - adi,ad7961
+
+  vdd1-supply: true
+  vdd2-supply: true
+  vio-supply: true
+
+  ref-supply:
+    description:
+      Voltage regulator for the external reference voltage (REF).
+
+  refin-supply:
+    description:
+      Voltage regulator for the reference buffer input (REFIN).
+
+  clocks:
+    description:
+      The clock connected to the CLK pins, gated by the clk_gate PWM.
+    maxItems: 1
+
+  pwms:
+    items:
+      - description: PWM connected to the CNV input on the ADC.
+      - description: PWM that gates the clock connected to the ADC's CLK input.
+
+  pwm-names:
+    items:
+      - const: cnv
+      - const: clk_gate
+
+  io-backends:
+    description:
+      The AXI ADC IP block connected to the D+/- and DCO+/- lines of the
+      ADC. An example backend can be found at
+      http://analogdevicesinc.github.io/hdl/projects/pulsar_lvds/index.html.
+    maxItems: 1
+
+  adi,no-dco:
+    $ref: /schemas/types.yaml#/definitions/flag
+    description:
+      Indicates the wiring of the DCO+/- lines. If true, then they are
+      grounded and the device is in self-clocked mode. If this is not
+      present, then the device is in echoed clock mode.
+
+  adi,en0-always-on:
+    $ref: /schemas/types.yaml#/definitions/flag
+    description:
+      Indicates if EN0 is hard-wired to the high state. If neither this
+      nor en0-gpios are present, then EN0 is hard-wired low.
+
+  adi,en1-always-on:
+    $ref: /schemas/types.yaml#/definitions/flag
+    description:
+      Indicates if EN1 is hard-wired to the high state. If neither this
+      nor en1-gpios are present, then EN1 is hard-wired low.
+
+  adi,en2-always-on:
+    $ref: /schemas/types.yaml#/definitions/flag
+    description:
+      Indicates if EN2 is hard-wired to the high state. If neither this
+      nor en2-gpios are present, then EN2 is hard-wired low.
+
+  adi,en3-always-on:
+    $ref: /schemas/types.yaml#/definitions/flag
+    description:
+      Indicates if EN3 is hard-wired to the high state. If neither this
+      nor en3-gpios are present, then EN3 is hard-wired low.
+
+  en0-gpios:
+    description:
+      Configurable EN0 pin.
+
+  en1-gpios:
+    description:
+      Configurable EN1 pin.
+
+  en2-gpios:
+    description:
+      Configurable EN2 pin.
+
+  en3-gpios:
+    description:
+      Configurable EN3 pin.
+
+required:
+  - compatible
+  - vdd1-supply
+  - vdd2-supply
+  - vio-supply
+  - clocks
+  - pwms
+  - pwm-names
+  - io-backends
+
+allOf:
+  - if:
+      required:
+        - ref-supply
+    then:
+      properties:
+        refin-supply: false
+  - if:
+      required:
+        - refin-supply
+    then:
+      properties:
+        ref-supply: false
+  - if:
+      properties:
+        compatible:
+          contains:
+            enum:
+              - adi,ad7625
+              - adi,ad7626
+    then:
+      properties:
+        en2-gpios: false
+        en3-gpios: false
+        adi,en2-always-on: false
+        adi,en3-always-on: false
+
+  - if:
+      properties:
+        compatible:
+          contains:
+            enum:
+              - adi,ad7960
+              - adi,ad7961
+    then:
+      # ad796x parts must have one of the two supplies
+      oneOf:
+        - required: [ref-supply]
+        - required: [refin-supply]
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/gpio/gpio.h>
+    adc {
+        compatible = "adi,ad7625";
+        vdd1-supply = <&supply_5V>;
+        vdd2-supply = <&supply_2_5V>;
+        vio-supply = <&supply_2_5V>;
+        io-backends = <&axi_adc>;
+        clocks = <&ref_clk>;
+        pwms = <&axi_pwm_gen 0 0>, <&axi_pwm_gen 1 0>;
+        pwm-names = "cnv", "clk_gate";
+        en0-gpios = <&gpio0 86 GPIO_ACTIVE_HIGH>;
+        en1-gpios = <&gpio0 87 GPIO_ACTIVE_HIGH>;
+    };
MAINTAINERS +9 -0
index fa2c8d902122..77557e85220e 100644
@@ -1271,6 +1271,15 @@ F:	Documentation/devicetree/bindings/iio/addac/adi,ad74413r.yaml
 F:	drivers/iio/addac/ad74413r.c
 F:	include/dt-bindings/iio/addac/adi,ad74413r.h
 
+ANALOG DEVICES INC AD7625 DRIVER
+M:	Michael Hennerich <[email protected]>
+M:	Nuno Sá <[email protected]>
+R:	Trevor Gamblin <[email protected]>
+S:	Supported
+W:	https://ez.analog.com/linux-software-drivers
+W:	http://analogdevicesinc.github.io/hdl/projects/pulsar_lvds/index.html
+F:	Documentation/devicetree/bindings/iio/adc/adi,ad7625.yaml
+
 ANALOG DEVICES INC AD7768-1 DRIVER
 M:	Michael Hennerich <[email protected]>
 L:	[email protected]
Signature · 1 line
2.39.2
#2 lore raw

Re: [PATCH v4 1/3] dt-bindings: iio: adc: add AD762x/AD796x ADCs

Quoted 9 lines · Trevor Gamblin

Add a binding specification for the Analog Devices Inc. AD7625, AD7626, AD7960, and AD7961 ADCs.

---
 .../devicetree/bindings/iio/adc/adi,ad7625.yaml    | 176 +++++++++++++++++++++
 MAINTAINERS                                        |   9 ++
 2 files changed, 185 insertions(+)

<form letter>
This is a friendly reminder during the review process.

It looks like you received a tag and forgot to add it.

If you do not know the process, here is a short explanation: Please add Acked-by/Reviewed-by/Tested-by tags when posting new versions, under or above your Signed-off-by tag. Tag is "received", when provided in a message replied to you on the mailing list. Tools like b4 can help here. However, there's no need to repost patches *only* to add the tags. The upstream maintainer will do that for tags received on the version they apply.

https://elixir.bootlin.com/linux/v6.5-rc3/source/Documentation/process/submitting-patches.rst#L577

If a tag was not added on purpose, please state why and what changed. </form letter>

Best regards,
Krzysztof

maintainer
#3 lore raw

Re: [PATCH v4 1/3] dt-bindings: iio: adc: add AD762x/AD796x ADCs

In reply to Trevor Gamblin
Quoted 4 lines · On Wed, 04 Sep 2024 15:14:18 -0400 Trevor Gamblin <[email protected]> wrote:

Add a binding specification for the Analog Devices Inc. AD7625, AD7626, AD7960, and AD7961 ADCs.

Just one minor thing inline. I think the description of the gpios is currently 'backwards'.

Documentation/devicetree/bindings/iio/adc/adi,ad7625.yaml line 96

Quoted 4 lines
Documentation/devicetree/bindings/iio/adc/adi,ad7625.yaml new file +4 -0
+
+  en0-gpios:
+    description:
+      Configurable EN0 pin.

Normally when we say a pin is configurable we mean the driver gets to change what it means. Here there is no bus over which to configure it. So this is a way of configuring what the device is doing.
EN0 pin used to configure XYZ..

author reviewer
#4 lore raw

PATCH v4 2/3 iio: adc: ad7625: add driver

In reply to Trevor Gamblin

Add a driver for the AD762x and AD796x family of ADCs. These are pin-compatible devices using an LVDS interface for data transfer, capable of sampling at rates of 6 (AD7625), 10 (AD7626), and 5 (AD7960/AD7961) MSPS, respectively. They also feature multiple voltage reference options based on the configuration of the EN1/EN0 pins, which can be set in the devicetree.

---
 MAINTAINERS              |   1 +
 drivers/iio/adc/Kconfig  |  16 ++
 drivers/iio/adc/Makefile |   1 +
 drivers/iio/adc/ad7625.c | 684 +++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 702 insertions(+)
MAINTAINERS +1 -0
index 77557e85220e..7f77a1c1110b 100644
@@ -1279,6 +1279,7 @@ S:	Supported
 W:	https://ez.analog.com/linux-software-drivers
 W:	http://analogdevicesinc.github.io/hdl/projects/pulsar_lvds/index.html
 F:	Documentation/devicetree/bindings/iio/adc/adi,ad7625.yaml
+F:	drivers/iio/adc/ad7625.c
 
 ANALOG DEVICES INC AD7768-1 DRIVER
 M:	Michael Hennerich <[email protected]>
drivers/iio/adc/Kconfig +16 -0
index f60fe85a30d5..2e743c95e900 100644
@@ -219,6 +219,22 @@ config AD7606_IFACE_SPI
 	  To compile this driver as a module, choose M here: the
 	  module will be called ad7606_spi.
 
+config AD7625
+	tristate "Analog Devices AD7625/AD7626 High Speed ADC driver"
+	depends on PWM
+	select IIO_BACKEND
+	help
+	  Say yes here to build support for Analog Devices:
+	  * AD7625 16-Bit, 6 MSPS PulSAR Analog-to-Digital Converter
+	  * AD7626 16-Bit, 10 MSPS PulSAR Analog-to-Digital Converter
+	  * AD7960 18-Bit, 5 MSPS PulSAR Analog-to-Digital Converter
+	  * AD7961 16-Bit, 5 MSPS PulSAR Analog-to-Digital Converter
+
+	  The driver requires the assistance of the AXI ADC IP core to operate.
+
+	  To compile this driver as a module, choose M here: the module will be
+	  called ad7625.
+
 config AD7766
 	tristate "Analog Devices AD7766/AD7767 ADC driver"
 	depends on SPI_MASTER
drivers/iio/adc/Makefile +1 -0
index d370e066544e..6bf429ca24ea 100644
@@ -23,6 +23,7 @@ obj-$(CONFIG_AD7476) += ad7476.o
 obj-$(CONFIG_AD7606_IFACE_PARALLEL) += ad7606_par.o
 obj-$(CONFIG_AD7606_IFACE_SPI) += ad7606_spi.o
 obj-$(CONFIG_AD7606) += ad7606.o
+obj-$(CONFIG_AD7625) += ad7625.o
 obj-$(CONFIG_AD7766) += ad7766.o
 obj-$(CONFIG_AD7768_1) += ad7768-1.o
 obj-$(CONFIG_AD7780) += ad7780.o
drivers/iio/adc/ad7625.c new file +684 -0

684 lines not on this page · raw message

Signature · 1 line
2.39.2
Reviewed-by Nuno Sa on v4 2/3
#5 lore raw

Re: [PATCH v4 2/3] iio: adc: ad7625: add driver

Quoted 9 lines · Trevor Gamblin

Add a driver for the AD762x and AD796x family of ADCs. These are pin-compatible devices using an LVDS interface for data transfer, capable of sampling at rates of 6 (AD7625), 10 (AD7626), and 5 (AD7960/AD7961) MSPS, respectively. They also feature multiple voltage reference options based on the configuration of the EN1/EN0 pins, which can be set in the devicetree.

---

Hi Trevor,

It LGTM, just some minor stuff from me...

With that,

Quoted 6 lines

 MAINTAINERS              |   1 +
 drivers/iio/adc/Kconfig  |  16 ++
 drivers/iio/adc/Makefile |   1 +
 drivers/iio/adc/ad7625.c | 684
+++++++++++++++++++++++++++++++++++++++++++++++

...

drivers/iio/adc/ad7625.c line 182

Quoted 8 lines
drivers/iio/adc/ad7625.c new file +8 -0
+
+static int ad7625_set_sampling_freq(struct ad7625_state *st, int freq)
+{
+	u64 target;
+	struct pwm_waveform clk_gate_wf = { }, cnv_wf = { };
+	int ret;
+
+	target = DIV_ROUND_UP_ULL(NSEC_PER_SEC, freq);

Not seeing any reason why it can't be DIV_ROUND_UP()?

Quoted 24 lines
drivers/iio/adc/ad7625.c new file +24 -0
+	cnv_wf.period_length_ns = clamp(target, 100, 10 * KILO);
+
+	/*
+	 * Use the maximum conversion time t_CNVH from the datasheet as
+	 * the duty_cycle for ref_clk, cnv, and clk_gate
+	 */
+	cnv_wf.duty_length_ns = st->info->timing_spec->conv_high_ns;
+
+	ret = pwm_round_waveform_might_sleep(st->cnv_pwm, &cnv_wf);
+	if (ret)
+		return ret;
+
+	/*
+	 * Set up the burst signal for transferring data. period and
+	 * offset should mirror the CNV signal
+	 */
+	clk_gate_wf.period_length_ns = cnv_wf.period_length_ns;
+
+	clk_gate_wf.duty_length_ns = DIV_ROUND_UP_ULL((u64)NSEC_PER_SEC *
+		st->info->chan_spec.scan_type.realbits,
+		st->ref_clk_rate_hz);
+
+	/* max t_MSB from datasheet */
+	clk_gate_wf.duty_offset_ns = st->info->timing_spec->conv_msb_ns;

drivers/iio/adc/ad7625.c line 216

Quoted 10 lines
drivers/iio/adc/ad7625.c new file +10 -0
+
+	ret = pwm_round_waveform_might_sleep(st->clk_gate_pwm, &clk_gate_wf);
+	if (ret)
+		return ret;
+
+	st->cnv_wf = cnv_wf;
+	st->clk_gate_wf = clk_gate_wf;
+
+	/* TODO: Add a rounding API for PWMs that can simplify this */
+	target = DIV_ROUND_CLOSEST_ULL(st->ref_clk_rate_hz, freq);

ditto...

Quoted 7 lines
drivers/iio/adc/ad7625.c new file +6 -0
+	st->sampling_freq_hz = DIV_ROUND_CLOSEST_ULL(st->ref_clk_rate_hz,
+						     target);
+
+	return 0;
+}
+

...

Quoted 21 lines
drivers/iio/adc/ad7625.c new file +21 -0
+
+static int ad7625_buffer_preenable(struct iio_dev *indio_dev)
+{
+	struct ad7625_state *st = iio_priv(indio_dev);
+	int ret;
+
+	ret = pwm_set_waveform_might_sleep(st->cnv_pwm, &st->cnv_wf, false);
+	if (ret)
+		return ret;
+
+	ret = pwm_set_waveform_might_sleep(st->clk_gate_pwm,
+					   &st->clk_gate_wf, false);
+	if (ret) {
+		/* Disable cnv PWM if clk_gate setup failed */
+		pwm_disable(st->cnv_pwm);
+		return ret;
+	}
+
+	return 0;
+}
+

drivers/iio/adc/ad7625.c line 444

Quoted 10 lines
drivers/iio/adc/ad7625.c new file +10 -0
+static int ad7625_buffer_postdisable(struct iio_dev *indio_dev)
+{
+	struct ad7625_state *st = iio_priv(indio_dev);
+
+	pwm_disable(st->cnv_pwm);
+	pwm_disable(st->clk_gate_pwm);
+
+	return 0;
+}
+

Might not matter but it is a good practise to disable things in the reverse order.

- Nuno Sá

author reviewer
#6 lore raw

Re: [PATCH v4 2/3] iio: adc: ad7625: add driver

Quoted 26 lines · Nuno Sá
Quoted 9 lines · Trevor Gamblin

Add a driver for the AD762x and AD796x family of ADCs. These are pin-compatible devices using an LVDS interface for data transfer, capable of sampling at rates of 6 (AD7625), 10 (AD7626), and 5 (AD7960/AD7961) MSPS, respectively. They also feature multiple voltage reference options based on the configuration of the EN1/EN0 pins, which can be set in the devicetree.

---

Hi Trevor,

It LGTM, just some minor stuff from me...

With that,

Quoted 6 lines
  MAINTAINERS              |   1 +
  drivers/iio/adc/Kconfig  |  16 ++
  drivers/iio/adc/Makefile |   1 +
  drivers/iio/adc/ad7625.c | 684

+++++++++++++++++++++++++++++++++++++++++++++++

...

Quoted 9 lines

drivers/iio/adc/ad7625.c line 182

Quoted 8 lines
drivers/iio/adc/ad7625.c new file +8 -0
+
+static int ad7625_set_sampling_freq(struct ad7625_state *st, int freq)
+{
+	u64 target;
+	struct pwm_waveform clk_gate_wf = { }, cnv_wf = { };
+	int ret;
+
+	target = DIV_ROUND_UP_ULL(NSEC_PER_SEC, freq);

Not seeing any reason why it can't be DIV_ROUND_UP()?

Uwe rightly pointed out (internally) that freq probably shouldn't be signed, so I'll adjust that instead and resubmit.

Quoted 71 lines
Quoted 25 lines
drivers/iio/adc/ad7625.c new file +24 -0
+	cnv_wf.period_length_ns = clamp(target, 100, 10 * KILO);
+
+	/*
+	 * Use the maximum conversion time t_CNVH from the datasheet as
+	 * the duty_cycle for ref_clk, cnv, and clk_gate
+	 */
+	cnv_wf.duty_length_ns = st->info->timing_spec->conv_high_ns;
+
+	ret = pwm_round_waveform_might_sleep(st->cnv_pwm, &cnv_wf);
+	if (ret)
+		return ret;
+
+	/*
+	 * Set up the burst signal for transferring data. period and
+	 * offset should mirror the CNV signal
+	 */
+	clk_gate_wf.period_length_ns = cnv_wf.period_length_ns;
+
+	clk_gate_wf.duty_length_ns = DIV_ROUND_UP_ULL((u64)NSEC_PER_SEC *
+		st->info->chan_spec.scan_type.realbits,
+		st->ref_clk_rate_hz);
+
+	/* max t_MSB from datasheet */
+	clk_gate_wf.duty_offset_ns = st->info->timing_spec->conv_msb_ns;

drivers/iio/adc/ad7625.c line 216

Quoted 10 lines
drivers/iio/adc/ad7625.c new file +10 -0
+
+	ret = pwm_round_waveform_might_sleep(st->clk_gate_pwm, &clk_gate_wf);
+	if (ret)
+		return ret;
+
+	st->cnv_wf = cnv_wf;
+	st->clk_gate_wf = clk_gate_wf;
+
+	/* TODO: Add a rounding API for PWMs that can simplify this */
+	target = DIV_ROUND_CLOSEST_ULL(st->ref_clk_rate_hz, freq);

ditto...

Quoted 7 lines
drivers/iio/adc/ad7625.c new file +6 -0
+	st->sampling_freq_hz = DIV_ROUND_CLOSEST_ULL(st->ref_clk_rate_hz,
+						     target);
+
+	return 0;
+}
+

...

Quoted 25 lines
drivers/iio/adc/ad7625.c new file +25 -0
+
+static int ad7625_buffer_preenable(struct iio_dev *indio_dev)
+{
+	struct ad7625_state *st = iio_priv(indio_dev);
+	int ret;
+
+	ret = pwm_set_waveform_might_sleep(st->cnv_pwm, &st->cnv_wf, false);
+	if (ret)
+		return ret;
+
+	ret = pwm_set_waveform_might_sleep(st->clk_gate_pwm,
+					   &st->clk_gate_wf, false);
+	if (ret) {
+		/* Disable cnv PWM if clk_gate setup failed */
+		pwm_disable(st->cnv_pwm);
+		return ret;
+	}
+
+	return 0;
+}
+
+static int ad7625_buffer_postdisable(struct iio_dev *indio_dev)
+{
+	struct ad7625_state *st = iio_priv(indio_dev);
+
Quoted 8 lines

drivers/iio/adc/ad7625.c line 444

Quoted 6 lines
drivers/iio/adc/ad7625.c new file +6 -0
+	pwm_disable(st->cnv_pwm);
+	pwm_disable(st->clk_gate_pwm);
+
+	return 0;
+}
+

Might not matter but it is a good practise to disable things in the reverse order.

Good point, I'll change that too.

Thanks!

Quoted 4 lines

- Nuno Sá

#7 lore raw

Re: [PATCH v4 2/3] iio: adc: ad7625: add driver

In reply to Trevor Gamblin
kernel test robot noticed the following build errors:

Hi Trevor,

kernel test robot noticed the following build errors:

[auto build test ERROR on 1ebd3850421749eb44bd040b249bd4db88d35b33]

url:    https://github.com/intel-lab-lkp/linux/commits/Trevor-Gamblin/dt-bindings-iio-adc-add-AD762x-AD796x-ADCs/20240905-031609
base:   1ebd3850421749eb44bd040b249bd4db88d35b33
patch link:    https://lore.kernel.org/r/20240904-ad7625_r1-v4-2-78bc7dfb2b35%40baylibre.com
patch subject: [PATCH v4 2/3] iio: adc: ad7625: add driver
config: arm-randconfig-002-20240908 (https://download.01.org/0day-ci/archive/20240908/[email protected]/config)
compiler: clang version 20.0.0git (https://github.com/llvm/llvm-project 05f5a91d00b02f4369f46d076411c700755ae041)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240908/[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 errors (new ones prefixed by >>, old ones prefixed by <<):

WARNING: modpost: missing MODULE_DESCRIPTION() in kernel/locking/test-ww_mutex.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/devfreq/governor_performance.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/devfreq/governor_userspace.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/fsi/fsi-core.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/fsi/fsi-master-aspeed.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/fsi/fsi-master-gpio.o

>> ERROR: modpost: "pwm_round_waveform_might_sleep" [drivers/iio/adc/ad7625.ko] undefined!
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
maintainer
#8 lore raw

Re: [PATCH v4 2/3] iio: adc: ad7625: add driver

In reply to Trevor Gamblin
Quoted 8 lines · On Wed, 04 Sep 2024 15:14:19 -0400 Trevor Gamblin <[email protected]> wrote:

Add a driver for the AD762x and AD796x family of ADCs. These are pin-compatible devices using an LVDS interface for data transfer, capable of sampling at rates of 6 (AD7625), 10 (AD7626), and 5 (AD7960/AD7961) MSPS, respectively. They also feature multiple voltage reference options based on the configuration of the EN1/EN0 pins, which can be set in the devicetree.

I took another look and LGTM (subject to the other review responses)

Jonathan

author reviewer
#9 lore raw

Re: [PATCH v4 2/3] iio: adc: ad7625: add driver

Quoted 10 lines · Jonathan Cameron
Quoted 7 lines · On Wed, 04 Sep 2024 15:14:19 -0400 Trevor Gamblin <[email protected]> wrote:

Add a driver for the AD762x and AD796x family of ADCs. These are pin-compatible devices using an LVDS interface for data transfer, capable of sampling at rates of 6 (AD7625), 10 (AD7626), and 5 (AD7960/AD7961) MSPS, respectively. They also feature multiple voltage reference options based on the configuration of the EN1/EN0 pins, which can be set in the devicetree.

Quoted 2 lines
Quoted 1 line

I took another look and LGTM (subject to the other review responses)

Thank you. I'll have a v5 for review shortly to address those.

Quoted 3 lines

Jonathan

author reviewer
#10 lore raw

PATCH v4 3/3 docs: iio: new docs for ad7625 driver

In reply to Trevor Gamblin

Add documentation for the AD7625/AD7626/AD7960/AD7961 ADCs.

---
 Documentation/iio/ad7625.rst | 91 ++++++++++++++++++++++++++++++++++++++++++++
 MAINTAINERS                  |  1 +
 2 files changed, 92 insertions(+)
Documentation/iio/ad7625.rst new file +91 -0
new file mode 100644
index 000000000000..61761e3b75c3
@@ -0,0 +1,91 @@
+.. SPDX-License-Identifier: GPL-2.0-only
+
+====================
+AD7625 driver
+====================
+
+ADC driver for Analog Devices Inc. AD7625, AD7626, AD7960, and AD7961
+devices. The module name is ``ad7625``.
+
+Supported devices
+=================
+
+The following chips are supported by this driver:
+
+* `AD7625 <https://www.analog.com/AD7625>`_
+* `AD7626 <https://www.analog.com/AD7626>`_
+* `AD7960 <https://www.analog.com/AD7960>`_
+* `AD7961 <https://www.analog.com/AD7961>`_
+
+The driver requires use of the Pulsar LVDS HDL project:
+
+* `Pulsar LVDS HDL <http://analogdevicesinc.github.io/hdl/projects/pulsar_lvds/index.html>`_
+
+To trigger conversions and enable subsequent data transfer, the devices
+require coupled PWM signals with a phase offset.
+
+Supported features
+==================
+
+Conversion control modes
+------------------------
+
+The driver currently supports one of two possible LVDS conversion control methods.
+
+Echoed-Clock interface mode
+^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+.. code-block::
+
+                                                +----------------+
+                     +xxxxxxxxxxxxxxxxxxxxxxxxxx| CNV            |
+                     X                          |                |
+                     v                          |    HOST        |
+          +----------------------------+        |                |
+          |      CNV+/CNV-   DCO+/DCO- |xxxxxxx>| CLK_IN         |
+          |                            |        |                |
+          |                            |        |                |
+          |       AD7625         D+/D- |xxxxxxx>| DATA_IN        |
+          |                            |        |                |
+          |                            |        |                |
+          |                  CLK+/CLK- |<xxxxxxx| CLK & CLK_GATE |
+          +----------------------------+        |                |
+                                                +----------------+
+
+Reference voltage
+-----------------
+
+Three possible reference voltage sources are supported:
+
+- Internal reference (only available on AD7625 and AD7626)
+- External reference and internal buffer
+- External reference
+
+The source is determined by the device tree. If ``ref-supply`` is present, then
+the external reference is used. If ``refin-supply`` is present, then the internal
+buffer is used. If neither is present, then the internal reference is used.
+
+Unimplemented features
+----------------------
+
+- Self-clocked mode
+
+
+Device attributes
+=================
+
+The AD762x is a fully-differential ADC and has the following attributes:
+
++---------------------------------------+--------------------------------------------------------------+
+| Attribute                             | Description                                                  |
++=======================================+==============================================================+
+| ``scale``                             | Scale factor to convert raw value from buffered reads to mV. |
++---------------------------------------+--------------------------------------------------------------+
+
+
+Device buffers
+==============
+
+This driver supports IIO triggered buffers.
+
+See :doc:`iio_devbuf` for more information.
MAINTAINERS +1 -0
index 7f77a1c1110b..cd5a18bf5e3a 100644
@@ -1279,6 +1279,7 @@ S:	Supported
 W:	https://ez.analog.com/linux-software-drivers
 W:	http://analogdevicesinc.github.io/hdl/projects/pulsar_lvds/index.html
 F:	Documentation/devicetree/bindings/iio/adc/adi,ad7625.yaml
+F:	Documentation/iio/ad7625.rst
 F:	drivers/iio/adc/ad7625.c
 
 ANALOG DEVICES INC AD7768-1 DRIVER
Signature · 1 line
2.39.2
author reviewer
#11 lore raw
In reply to Trevor Gamblin
Quoted 13 lines · Trevor Gamblin

This series adds a new driver for the Analog Devices Inc. AD7625, AD7626, AD7960, and AD7961. These chips are part of a family of LVDS-based SAR ADCs. The initial driver implementation does not support the devices' self-clocked mode, although that can be added later.

The devices make use of two offset PWM signals, one to trigger conversions and the other as a burst signal for transferring data to the host. These rely on the new PWM waveform functionality being reviewed in [1] and also available at [2].

This work is being done by BayLibre and on behalf of Analog Devices Inc., hence the maintainers are @analog.com.

Quoted 6 lines

Special thanks to David Lechner for his guidance and reviews.

[1]: https://lore.kernel.org/linux-pwm/[email protected]
[2]: https://git.kernel.org/pub/scm/linux/kernel/git/ukleinek/linux.git/log/?h=pwm/chardev

Realizing that I forgot to pick up Conor's Reviewed-by on the v3 binding before sending. Can that be picked up?

Quoted 81 lines

---
Changes in v4:
- Link to v3: https://lore.kernel.org/r/[email protected]
- Rebase on top of latest pwm/chardev branch at:
https://git.kernel.org/pub/scm/linux/kernel/git/ukleinek/linux.git/log/?h=pwm/chardev

[PATCH 1/3]
- No change

[PATCH 2/3]
- Add 'depends on PWM' under 'CONFIG AD7625' in drivers/iio/adc/Kconfig, based on v3 discussions
- Cleanup whitespace usage in Kconfig, bandwidth logic to match Jonathan's suggestions

[PATCH 3/3]
- No change

Changes in v3:
- Link to v2: https://lore.kernel.org/r/[email protected]

[PATCH 1/3]
- Add gpio bindings header, en0-gpios and en1-gpios to binding example
- Remove unnecessary comments

[PATCH 2/3]
- No change

[PATCH 3/3]
- No change

Changes in v2:
- Link to v1 (marked as RFC): https://lore.kernel.org/r/[email protected]
- Include link to required PWM patch series in cover letter (missing before)
- Include new link to the pwm/chardev branch of Uwe's kernel tree

[PATCH 1/3]
- Rework dt bindings to be compliant using make dt_binding_check
- Add "adi,no-dco" flag to address indication of how DCO lines are configured
- Fix binding patch message
- Remove chip packaging info from binding description
- Move comments around to be clearer

[PATCH 2/3]
- Remove ad7625_pwm_disable(), call pwm_disable() directly
- Add ad7625_buffer_preenable() and ad7625_buffer_postdisable() functions
- Add devm_ad7625_regulator_setup() function, move all regulator logic to it, consolidate the comment blocks related to it above
- Add have_refin flag in ad7625_state struct
- Add pwm_waveform structs to ad7625_state struct for storing requested waveform characteristics
- Refactor ad7625_set_sampling_freq() to set the pwm_waveform struct values in ad7625_state, limiting PWM enable/disable to preenable/postdisable functions
- Remove redundant dev_err_probe() after devm_ad7625_pwm_get()
- Use device_property_read_bool() instead of device_property_present()
- General alignment and line wrapping fixes

[PATCH 3/3]
- No change

---
Trevor Gamblin (3):
dt-bindings: iio: adc: add AD762x/AD796x ADCs
iio: adc: ad7625: add driver
docs: iio: new docs for ad7625 driver

  .../devicetree/bindings/iio/adc/adi,ad7625.yaml    | 176 ++++++
  Documentation/iio/ad7625.rst                       |  91 +++
  MAINTAINERS                                        |  11 +
  drivers/iio/adc/Kconfig                            |  16 +
  drivers/iio/adc/Makefile                           |   1 +
  drivers/iio/adc/ad7625.c                           | 684 +++++++++++++++++++++
  6 files changed, 979 insertions(+)

---
base-commit: 1ebd3850421749eb44bd040b249bd4db88d35b33
change-id: 20240730-ad7625_r1-60d17ea28958

Best regards,

#12 lore raw
Quoted 15 lines · Trevor Gamblin
Quoted 13 lines · Trevor Gamblin

This series adds a new driver for the Analog Devices Inc. AD7625, AD7626, AD7960, and AD7961. These chips are part of a family of LVDS-based SAR ADCs. The initial driver implementation does not support the devices' self-clocked mode, although that can be added later.

The devices make use of two offset PWM signals, one to trigger conversions and the other as a burst signal for transferring data to the host. These rely on the new PWM waveform functionality being reviewed in [1] and also available at [2].

This work is being done by BayLibre and on behalf of Analog Devices Inc., hence the maintainers are @analog.com.

Quoted 8 lines
Quoted 6 lines

Special thanks to David Lechner for his guidance and reviews.

[1]: https://lore.kernel.org/linux-pwm/[email protected]
[2]: https://git.kernel.org/pub/scm/linux/kernel/git/ukleinek/linux.git/log/?h=pwm/chardev

Realizing that I forgot to pick up Conor's Reviewed-by on the v3 binding before sending. Can that be picked up?

Only you can run b4 ty -u. We cannot.

Best regards,
Krzysztof

author reviewer
#13 lore raw
Quoted 17 lines · Krzysztof Kozlowski
Quoted 16 lines · Trevor Gamblin
Quoted 15 lines · Trevor Gamblin

This series adds a new driver for the Analog Devices Inc. AD7625, AD7626, AD7960, and AD7961. These chips are part of a family of LVDS-based SAR ADCs. The initial driver implementation does not support the devices' self-clocked mode, although that can be added later.

The devices make use of two offset PWM signals, one to trigger conversions and the other as a burst signal for transferring data to the host. These rely on the new PWM waveform functionality being reviewed in [1] and also available at [2].

This work is being done by BayLibre and on behalf of Analog Devices Inc., hence the maintainers are @analog.com.

Special thanks to David Lechner for his guidance and reviews.

Quoted 7 lines
Quoted 6 lines
Quoted 4 lines

[1]: https://lore.kernel.org/linux-pwm/[email protected]
[2]: https://git.kernel.org/pub/scm/linux/kernel/git/ukleinek/linux.git/log/?h=pwm/chardev

Realizing that I forgot to pick up Conor's Reviewed-by on the v3 binding before sending. Can that be picked up?

Only you can run b4 ty -u. We cannot.

My mistake. I'll make sure they're there for the next revision.

Quoted 4 lines

Best regards,
Krzysztof