Skip to contentSkip to conversation

Add support for the AD5754 DAC

PATCH In review Ciprian Regus 3 participants 6 messages Nov 18, 2022 – Nov 23, 2022

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

v3 cover Add support for the AD5754 DAC

These patches implement support for the AD5754 DAC (both dual and quad channel variants).

The AD5724/AD5734/AD5754 are quad, 12-/14-/16-bit, serial input, voltage output DACs. The devices operate from single- supply voltages from +4.5 V up to +16.5 V or dual-supply voltages from ±4.5 V up to ±16.5 V. The input coding is user-selectable twos complement or offset binary for a bipolar output (depending on the state of Pin BIN/2sComp), and straight binary for a unipolar output.

Ciprian Regus (2):
dt-bindings: iio: dac: add adi,ad5754.yaml
drivers: iio: dac: Add AD5754 DAC driver

 .../bindings/iio/dac/adi,ad5754.yaml          | 181 +++++
 MAINTAINERS                                   |   8 +
 drivers/iio/dac/Kconfig                       |  12 +
 drivers/iio/dac/Makefile                      |   1 +
 drivers/iio/dac/ad5754.c                      | 672 ++++++++++++++++++
 5 files changed, 874 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/dac/adi,ad5754.yaml
 create mode 100644 drivers/iio/dac/ad5754.c
Signature · 1 line
2.30.2
#1 lore raw

PATCH v3 1/2 dt-bindings: iio: dac: add adi,ad5754.yaml

Add devicetree bindings documentation for the AD5754 DAC driver.

---
changes in v3:
- added additionalProperties: false to patternProperties
- dropped status in the example.
- added different values for adi,output-range-microvolt in the example. Negative values cannot be set since that will create a dt_bindings_check error.

 .../bindings/iio/dac/adi,ad5754.yaml          | 181 ++++++++++++++++++
 1 file changed, 181 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/dac/adi,ad5754.yaml
Documentation/devicetree/bindings/iio/dac/adi,ad5754.yaml new file +181 -0
new file mode 100644
index 000000000000..de0f6fab82b8
@@ -0,0 +1,181 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/iio/dac/adi,ad5754.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Analog Devices AD5754 DAC
+
+maintainers:
+  - Ciprian Regus <[email protected]>
+
+description: |
+  Bindings for the AD5754 and other chip variants digital-to-analog
+  converters.
+
+  https://www.analog.com/media/en/technical-documentation/data-sheets/AD5724_5734_5754.pdf
+  https://www.analog.com/media/en/technical-documentation/data-sheets/ad5722_5732_5752.pdf
+  https://www.analog.com/media/en/technical-documentation/data-sheets/ad5724r_5734r_5754r.pdf
+  https://www.analog.com/media/en/technical-documentation/data-sheets/AD5722R_5732R_5752R.pdf
+
+properties:
+  compatible:
+    enum:
+      - adi,ad5722
+      - adi,ad5732
+      - adi,ad5752
+      - adi,ad5724
+      - adi,ad5734
+      - adi,ad5754
+      - adi,ad5722r
+      - adi,ad5732r
+      - adi,ad5752r
+      - adi,ad5724r
+      - adi,ad5734r
+      - adi,ad5754r
+
+  reg:
+    maxItems: 1
+
+  spi-max-frequency:
+    maximum: 30000000
+
+  spi-cpol: true
+
+  vref-supply:
+    description:
+      The regulator to use as an external reference. If this is not provided,
+      the internal reference will be used for chips that have this feature.
+      The external reference must be 2.5V.
+
+  clr-gpios:
+    description: DAC output clear GPIO (CLR pin). If specified, it will be set
+      to high during probe, thus allowing the DAC output to be updated.
+    maxItems: 1
+
+  '#address-cells':
+    const: 1
+
+  '#size-cells':
+    const: 0
+
+patternProperties:
+  "^channel@([0-3])$":
+    type: object
+    additionalProperties: false
+    description: Configurations for the DAC channels
+
+    properties:
+      reg:
+        description: Channel number
+        maxItems: 1
+
+      adi,output-range-microvolt:
+        description: |
+          Voltage range of a channel as <minimum, maximum>.
+        oneOf:
+          - items:
+              - const: 0
+              - enum: [5000000, 10000000, 10800000]
+          - items:
+              - const: -5000000
+              - const: 5000000
+          - items:
+              - const: -10000000
+              - const: 10000000
+          - items:
+              - const: -10800000
+              - const: 10800000
+
+    required:
+      - reg
+      - adi,output-range-microvolt
+
+allOf:
+  - $ref: /schemas/spi/spi-peripheral-props.yaml#
+
+  - if:
+      properties:
+        compatible:
+          contains:
+            enum:
+              - adi,ad5722
+              - adi,ad5732
+              - adi,ad5752
+              - adi,ad5722r
+              - adi,ad5732r
+              - adi,ad5752r
+    then:
+      patternProperties:
+        "^channel@([0-3])$":
+          type: object
+          properties:
+            reg:
+              description: Channel number
+              enum: [0, 1]
+
+  - if:
+      properties:
+        compatible:
+          contains:
+            enum:
+              - adi,ad5724
+              - adi,ad5734
+              - adi,ad5754
+              - adi,ad5724r
+              - adi,ad5734r
+              - adi,ad5754r
+    then:
+      patternProperties:
+        "^channel@([0-3])$":
+          type: object
+          properties:
+            reg:
+              description: Channel number
+              enum: [0, 1, 2, 3]
+
+required:
+  - compatible
+  - reg
+  - spi-max-frequency
+  - spi-cpol
+
+unevaluatedProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/gpio/gpio.h>
+
+    spi {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        dac@0 {
+            compatible = "adi,ad5754r";
+            reg = <0>;
+            spi-max-frequency = <1000000>;
+            spi-cpol;
+
+            clr-gpios = <&gpio 25 GPIO_ACTIVE_LOW>;
+
+            #address-cells = <1>;
+            #size-cells = <0>;
+
+            channel@0 {
+                reg = <0>;
+                adi,output-range-microvolt = <0 5000000>;
+            };
+            channel@1 {
+                reg = <1>;
+                adi,output-range-microvolt = <0 10000000>;
+            };
+            channel@2 {
+                reg = <2>;
+                adi,output-range-microvolt = <0 5000000>;
+            };
+            channel@3 {
+                reg = <3>;
+                adi,output-range-microvolt = <0 10000000>;
+            };
+        };
+    };
Signature · 1 line
2.30.2
#2 lore raw

Re: [PATCH v3 1/2] dt-bindings: iio: dac: add adi,ad5754.yaml

Quoted 38 lines · Ciprian Regus

Add devicetree bindings documentation for the AD5754 DAC driver.

---
changes in v3:
- added additionalProperties: false to patternProperties
- dropped status in the example.
- added different values for adi,output-range-microvolt in the example. Negative values cannot be set since that will create a dt_bindings_check error.

 .../bindings/iio/dac/adi,ad5754.yaml          | 181 ++++++++++++++++++
 1 file changed, 181 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/dac/adi,ad5754.yaml
Documentation/devicetree/bindings/iio/dac/adi,ad5754.yaml new file +19 -0
new file mode 100644
index 000000000000..de0f6fab82b8
@@ -0,0 +1,181 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/iio/dac/adi,ad5754.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Analog Devices AD5754 DAC
+
+maintainers:
+  - Ciprian Regus <[email protected]>
+
+description: |
+  Bindings for the AD5754 and other chip variants digital-to-analog
+  converters.
+
+  https://www.analog.com/media/en/technical-documentation/data-sheets/AD5724_5734_5754.pdf
+  https://www.analog.com/media/en/technical-documentation/data-sheets/ad5722_5732_5752.pdf
+  https://www.analog.com/media/en/technical-documentation/data-sheets/ad5724r_5734r_5754r.pdf
+  https://www.analog.com/media/en/technical-documentation/data-sheets/AD5722R_5732R_5752R.pdf

Documentation/devicetree/bindings/iio/dac/adi,ad5754.yaml line 29

Quoted 10 lines
Documentation/devicetree/bindings/iio/dac/adi,ad5754.yaml new file +10 -0
+
+properties:
+  compatible:
+    enum:
+      - adi,ad5722
+      - adi,ad5732
+      - adi,ad5752
+      - adi,ad5724
+      - adi,ad5734
+      - adi,ad5754

Keep the list sorted.

Documentation/devicetree/bindings/iio/dac/adi,ad5754.yaml line 30

Quoted 1 line
Documentation/devicetree/bindings/iio/dac/adi,ad5754.yaml new file +1 -0
+      - adi,ad5722r

I would even suggest sorted entirely, so 5722r follows 5722, but I don't mind some combo-sorting (logical + alphabetical).

Quoted 23 lines
Documentation/devicetree/bindings/iio/dac/adi,ad5754.yaml new file +23 -0
+      - adi,ad5732r
+      - adi,ad5752r
+      - adi,ad5724r
+      - adi,ad5734r
+      - adi,ad5754r
+
+  reg:
+    maxItems: 1
+
+  spi-max-frequency:
+    maximum: 30000000
+
+  spi-cpol: true
+
+  vref-supply:
+    description:
+      The regulator to use as an external reference. If this is not provided,
+      the internal reference will be used for chips that have this feature.
+      The external reference must be 2.5V.
+
+  clr-gpios:
+    description: DAC output clear GPIO (CLR pin). If specified, it will be set
+      to high during probe, thus allowing the DAC output to be updated.

Documentation/devicetree/bindings/iio/dac/adi,ad5754.yaml line 63

Quoted 10 lines
Documentation/devicetree/bindings/iio/dac/adi,ad5754.yaml new file +10 -0
+    maxItems: 1
+
+  '#address-cells':
+    const: 1
+
+  '#size-cells':
+    const: 0
+
+patternProperties:
+  "^channel@([0-3])$":

No need for ().

Quoted 37 lines
Documentation/devicetree/bindings/iio/dac/adi,ad5754.yaml new file +37 -0
+    type: object
+    additionalProperties: false
+    description: Configurations for the DAC channels
+
+    properties:
+      reg:
+        description: Channel number
+        maxItems: 1
+
+      adi,output-range-microvolt:
+        description: |
+          Voltage range of a channel as <minimum, maximum>.
+        oneOf:
+          - items:
+              - const: 0
+              - enum: [5000000, 10000000, 10800000]
+          - items:
+              - const: -5000000
+              - const: 5000000
+          - items:
+              - const: -10000000
+              - const: 10000000
+          - items:
+              - const: -10800000
+              - const: 10800000
+
+    required:
+      - reg
+      - adi,output-range-microvolt
+
+allOf:
+  - $ref: /schemas/spi/spi-peripheral-props.yaml#
+
+  - if:
+      properties:
+        compatible:
+          contains:

Documentation/devicetree/bindings/iio/dac/adi,ad5754.yaml line 110

Quoted 10 lines
Documentation/devicetree/bindings/iio/dac/adi,ad5754.yaml new file +10 -0
+            enum:
+              - adi,ad5722
+              - adi,ad5732
+              - adi,ad5752
+              - adi,ad5722r
+              - adi,ad5732r
+              - adi,ad5752r
+    then:
+      patternProperties:
+        "^channel@([0-3])$":

No need for ().

Quoted 10 lines
Documentation/devicetree/bindings/iio/dac/adi,ad5754.yaml new file +10 -0
+          type: object
+          properties:
+            reg:
+              description: Channel number
+              enum: [0, 1]
+
+  - if:
+      properties:
+        compatible:
+          contains:

Documentation/devicetree/bindings/iio/dac/adi,ad5754.yaml line 130

Quoted 10 lines
Documentation/devicetree/bindings/iio/dac/adi,ad5754.yaml new file +10 -0
+            enum:
+              - adi,ad5724
+              - adi,ad5734
+              - adi,ad5754
+              - adi,ad5724r
+              - adi,ad5734r
+              - adi,ad5754r
+    then:
+      patternProperties:
+        "^channel@([0-3])$":

No need for ().

Documentation/devicetree/bindings/iio/dac/adi,ad5754.yaml line 136

Quoted 6 lines
Documentation/devicetree/bindings/iio/dac/adi,ad5754.yaml new file +6 -0
+          type: object
+          properties:
+            reg:
+              description: Channel number
+              enum: [0, 1, 2, 3]
+

Best regards,
Krzysztof

#3 lore raw

Re: [PATCH v3 1/2] dt-bindings: iio: dac: add adi,ad5754.yaml

Quoted 52 lines · On Mon, 21 Nov 2022 12:20:39 +0100 Krzysztof Kozlowski…
Quoted 38 lines · Ciprian Regus

Add devicetree bindings documentation for the AD5754 DAC driver.

---
changes in v3:
- added additionalProperties: false to patternProperties
- dropped status in the example.
- added different values for adi,output-range-microvolt in the example. Negative values cannot be set since that will create a dt_bindings_check error.

 .../bindings/iio/dac/adi,ad5754.yaml          | 181 ++++++++++++++++++
 1 file changed, 181 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/dac/adi,ad5754.yaml
Documentation/devicetree/bindings/iio/dac/adi,ad5754.yaml new file +19 -0
new file mode 100644
index 000000000000..de0f6fab82b8
@@ -0,0 +1,181 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/iio/dac/adi,ad5754.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Analog Devices AD5754 DAC
+
+maintainers:
+  - Ciprian Regus <[email protected]>
+
+description: |
+  Bindings for the AD5754 and other chip variants digital-to-analog
+  converters.
+
+  https://www.analog.com/media/en/technical-documentation/data-sheets/AD5724_5734_5754.pdf
+  https://www.analog.com/media/en/technical-documentation/data-sheets/ad5722_5732_5752.pdf
+  https://www.analog.com/media/en/technical-documentation/data-sheets/ad5724r_5734r_5754r.pdf
+  https://www.analog.com/media/en/technical-documentation/data-sheets/AD5722R_5732R_5752R.pdf

Documentation/devicetree/bindings/iio/dac/adi,ad5754.yaml line 29

Quoted 10 lines
Documentation/devicetree/bindings/iio/dac/adi,ad5754.yaml new file +10 -0
+
+properties:
+  compatible:
+    enum:
+      - adi,ad5722
+      - adi,ad5732
+      - adi,ad5752
+      - adi,ad5724
+      - adi,ad5734
+      - adi,ad5754  

Keep the list sorted.

Quoted 4 lines

Documentation/devicetree/bindings/iio/dac/adi,ad5754.yaml line 30

Quoted 1 line
Documentation/devicetree/bindings/iio/dac/adi,ad5754.yaml new file +1 -0
+      - adi,ad5722r  

I would even suggest sorted entirely, so 5722r follows 5722, but I don't mind some combo-sorting (logical + alphabetical).

I was curious about this as well, so went digging.

Wonderfully they are grouped by logical set here - with each group of 3 being on a different datasheet (visible datasheet names above), with associated commonality.

Still I'm fine with whatever ordering makes sense. Maybe it's just easier to smash them into simple alphabetical order both here and in the driver and not worry about where the order comes from.

If doing that, make sure you also do it for the sub lists below.

Quoted 121 lines
Quoted 24 lines
Documentation/devicetree/bindings/iio/dac/adi,ad5754.yaml new file +23 -0
+      - adi,ad5732r
+      - adi,ad5752r
+      - adi,ad5724r
+      - adi,ad5734r
+      - adi,ad5754r
+
+  reg:
+    maxItems: 1
+
+  spi-max-frequency:
+    maximum: 30000000
+
+  spi-cpol: true
+
+  vref-supply:
+    description:
+      The regulator to use as an external reference. If this is not provided,
+      the internal reference will be used for chips that have this feature.
+      The external reference must be 2.5V.
+
+  clr-gpios:
+    description: DAC output clear GPIO (CLR pin). If specified, it will be set
+      to high during probe, thus allowing the DAC output to be updated.

Documentation/devicetree/bindings/iio/dac/adi,ad5754.yaml line 63

Quoted 10 lines
Documentation/devicetree/bindings/iio/dac/adi,ad5754.yaml new file +10 -0
+    maxItems: 1
+
+  '#address-cells':
+    const: 1
+
+  '#size-cells':
+    const: 0
+
+patternProperties:
+  "^channel@([0-3])$":  

No need for ().

Quoted 37 lines
Documentation/devicetree/bindings/iio/dac/adi,ad5754.yaml new file +37 -0
+    type: object
+    additionalProperties: false
+    description: Configurations for the DAC channels
+
+    properties:
+      reg:
+        description: Channel number
+        maxItems: 1
+
+      adi,output-range-microvolt:
+        description: |
+          Voltage range of a channel as <minimum, maximum>.
+        oneOf:
+          - items:
+              - const: 0
+              - enum: [5000000, 10000000, 10800000]
+          - items:
+              - const: -5000000
+              - const: 5000000
+          - items:
+              - const: -10000000
+              - const: 10000000
+          - items:
+              - const: -10800000
+              - const: 10800000
+
+    required:
+      - reg
+      - adi,output-range-microvolt
+
+allOf:
+  - $ref: /schemas/spi/spi-peripheral-props.yaml#
+
+  - if:
+      properties:
+        compatible:
+          contains:

Documentation/devicetree/bindings/iio/dac/adi,ad5754.yaml line 110

Quoted 10 lines
Documentation/devicetree/bindings/iio/dac/adi,ad5754.yaml new file +10 -0
+            enum:
+              - adi,ad5722
+              - adi,ad5732
+              - adi,ad5752
+              - adi,ad5722r
+              - adi,ad5732r
+              - adi,ad5752r
+    then:
+      patternProperties:
+        "^channel@([0-3])$":  

No need for ().

Quoted 10 lines
Documentation/devicetree/bindings/iio/dac/adi,ad5754.yaml new file +10 -0
+          type: object
+          properties:
+            reg:
+              description: Channel number
+              enum: [0, 1]
+
+  - if:
+      properties:
+        compatible:
+          contains:

Documentation/devicetree/bindings/iio/dac/adi,ad5754.yaml line 130

Quoted 10 lines
Documentation/devicetree/bindings/iio/dac/adi,ad5754.yaml new file +10 -0
+            enum:
+              - adi,ad5724
+              - adi,ad5734
+              - adi,ad5754
+              - adi,ad5724r
+              - adi,ad5734r
+              - adi,ad5754r
+    then:
+      patternProperties:
+        "^channel@([0-3])$":  

No need for ().

Documentation/devicetree/bindings/iio/dac/adi,ad5754.yaml line 136

Quoted 6 lines
Documentation/devicetree/bindings/iio/dac/adi,ad5754.yaml new file +6 -0
+          type: object
+          properties:
+            reg:
+              description: Channel number
+              enum: [0, 1, 2, 3]
+  

Best regards,
Krzysztof

#4 lore raw

PATCH v3 2/2 drivers: iio: dac: Add AD5754 DAC driver

In reply to Ciprian Regus

The AD5724/AD5734/AD5754 are quad, 12-/14-/16-bit, serial input, voltage output DACs. The devices operate from single-supply voltages from +4.5 V up to +16.5 V or dual-supply voltages from ±4.5 V up to ±16.5 V. The input coding is user-selectable twos complement or offset binary for a bipolar output (depending on the state of Pin BIN/2sComp), and straight binary for a unipolar output.

Datasheet: https://www.analog.com/media/en/technical-documentation/data-sheets/AD5724_5734_5754.pdf
Datasheet: https://www.analog.com/media/en/technical-documentation/data-sheets/ad5722_5732_5752.pdf
Datasheet: https://www.analog.com/media/en/technical-documentation/data-sheets/ad5724r_5734r_5754r.pdf
Datasheet: https://www.analog.com/media/en/technical-documentation/data-sheets/AD5722R_5732R_5752R.pdf

---
changes in v3:
- wrapped the commit message to 70-75 characters.
- added a lock for the reg_read function in order to synchronize sequential transfers.
- replaced explicit size setting with ARRAY_SIZE() in ad5754_set_dac_code().
- enabled all channels at once, thus also removing the side effects of the

    ad5754_enable_channels().
  - removed the vref field from the ad5754_state struct, since it's not necessary to cache
    the vref value.
  - fixed the scale formula, since the one used in v2 would only work for a 2.5V reference.
  - split the devm_ unwind path into 3 functions (instead of a single one).
 MAINTAINERS              |   8 +
 drivers/iio/dac/Kconfig  |  12 +
 drivers/iio/dac/Makefile |   1 +
 drivers/iio/dac/ad5754.c | 672 +++++++++++++++++++++++++++++++++++++++
 4 files changed, 693 insertions(+)
 create mode 100644 drivers/iio/dac/ad5754.c
MAINTAINERS +8 -0
index 4e5d1d737cfb..6fa48820c969 100644
@@ -1091,6 +1091,14 @@ T:	git git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net.git
 T:	git git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net-next.git
 F:	drivers/net/amt.c
 
+ANALOG DEVICES INC AD5754 DRIVER
+M:	Ciprian Regus <[email protected]>
+L:	[email protected]
+S:	Supported
+W:	https://ez.analog.com/linux-software-drivers
+F:	Documentation/devicetree/bindings/iio/dac/adi,ad5754.yaml
+F:	drivers/iio/dac/ad5754.c
+
 ANALOG DEVICES INC AD7192 DRIVER
 M:	Alexandru Tachici <[email protected]>
 L:	[email protected]
drivers/iio/dac/Kconfig +12 -0
index 80521bd28d0f..561bfbedeecb 100644
@@ -170,6 +170,18 @@ config AD5696_I2C
 	  To compile this driver as a module, choose M here: the module will be
 	  called ad5696.
 
+config AD5754
+	tristate "Analog Devices AD5754 and similar DACs"
+	depends on SPI
+	select REGMAP_SPI
+	help
+	  Say yes here to build support for Analog Devices AD5752, AD5732,
+	  AD5722, AD5754, AD5734, AD5724, AD5752R, AD5732R, AD5722R, AD5754R,
+	  AD5734R, AD5724R dual/quad channel Digital to Analog Converters.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called ad5754.
+
 config AD5755
 	tristate "Analog Devices AD5755/AD5755-1/AD5757/AD5735/AD5737 DAC driver"
 	depends on SPI_MASTER
drivers/iio/dac/Makefile +1 -0
index ec3e42713f00..d6c18deed1f7 100644
@@ -16,6 +16,7 @@ obj-$(CONFIG_AD5449) += ad5449.o
 obj-$(CONFIG_AD5592R_BASE) += ad5592r-base.o
 obj-$(CONFIG_AD5592R) += ad5592r.o
 obj-$(CONFIG_AD5593R) += ad5593r.o
+obj-$(CONFIG_AD5754) += ad5754.o
 obj-$(CONFIG_AD5755) += ad5755.o
 obj-$(CONFIG_AD5755) += ad5758.o
 obj-$(CONFIG_AD5761) += ad5761.o
drivers/iio/dac/ad5754.c new file +672 -0

672 lines not on this page · raw message

Signature · 1 line
2.30.2
#5 lore raw

Re: [PATCH v3 2/2] drivers: iio: dac: Add AD5754 DAC driver

Quoted 7 lines · On Fri, 18 Nov 2022 19:24:07 +0200 Ciprian Regus <[email protected]>…

The AD5724/AD5734/AD5754 are quad, 12-/14-/16-bit, serial input, voltage output DACs. The devices operate from single-supply voltages from +4.5 V up to +16.5 V or dual-supply voltages from ±4.5 V up to ±16.5 V. The input coding is user-selectable twos complement or offset binary for a bipolar output (depending on the state of Pin BIN/2sComp), and straight binary for a unipolar output.

Quoted 5 lines

Datasheet: https://www.analog.com/media/en/technical-documentation/data-sheets/AD5724_5734_5754.pdf
Datasheet: https://www.analog.com/media/en/technical-documentation/data-sheets/ad5722_5732_5752.pdf
Datasheet: https://www.analog.com/media/en/technical-documentation/data-sheets/ad5724r_5734r_5754r.pdf
Datasheet: https://www.analog.com/media/en/technical-documentation/data-sheets/AD5722R_5732R_5752R.pdf

Hi Ciprian,

Took another look and found a few more things given you'll be spinning again for the dt binding.

Only significant one is the handling of error returns form the optional regulator.

Jonathan

Quoted 22 lines
drivers/iio/dac/ad5754.c new file +16 -0
new file mode 100644
index 000000000000..81cfda2efa0f
@@ -0,0 +1,672 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2022 Analog Devices, Inc.
+ * Author: Ciprian Regus <[email protected]>
+ */
+
+#include <linux/bitfield.h>
+#include <linux/device.h>
+#include <linux/err.h>
+#include <linux/gpio/driver.h>
+#include <linux/iio/iio.h>
+#include <linux/kernel.h>
+#include <linux/linear_range.h>
+#include <linux/mod_devicetable.h>
+#include <linux/property.h>
+#include <linux/regmap.h>

drivers/iio/dac/ad5754.c line 26

Quoted 10 lines
drivers/iio/dac/ad5754.c new file +10 -0
+#include <linux/regulator/consumer.h>
+#include <linux/spi/spi.h>
+
+#include <asm/unaligned.h>
+
+#define AD5754_INT_VREF_mV			2500
+#define AD5754_FRAME_SIZE			3
+#define AD5754_MAX_CHANNELS			4
+#define AD5754_MAX_RESOLUTION			16
+#define uV_PER_mV				1000

In common with units.h probably better to spell out than mix case (as someone will come along and 'fix' this for you ;)

#define MICROVOLT_PER_MILLIVOLT

Or just use MICRO/MILLI inline from units.h and rely on compiler work the maths out for you.

drivers/iio/dac/ad5754.c line 107

Quoted 11 lines
drivers/iio/dac/ad5754.c new file +11 -0
+
+static const struct iio_chan_spec ad5754_2_channels[2] = {
+		AD5754_CHANNEL(0),
+		AD5754_CHANNEL(1),
+};
+
+static const struct iio_chan_spec ad5754_4_channels[4] = {
+		AD5754_CHANNEL(0),
+		AD5754_CHANNEL(1),
+		AD5754_CHANNEL(2),
+		AD5754_CHANNEL(3),

Why the double tab for alignment of these?

Quoted 1 line
drivers/iio/dac/ad5754.c new file +1 -0
+};

..

drivers/iio/dac/ad5754.c line 308

Quoted 13 lines
drivers/iio/dac/ad5754.c new file +13 -0
+
+static int ad5754_reg_write(void *context, unsigned int reg, unsigned int val)
+{
+	struct ad5754_state *st = context;
+	struct spi_transfer xfer = {
+		.tx_buf = st->buff,
+		.len = 3,
+	};
+
+	st->buff[0] = reg;
+	put_unaligned_be16(val, &st->buff[1]);
+
+	return spi_sync_transfer(st->spi, &xfer, 1);

spi_write()?
Same thing under the hood but slightly shorter code here.

Quoted 5 lines
drivers/iio/dac/ad5754.c new file +3 -0
+};
 
 
+
+static int ad5754_probe(struct spi_device *spi)

drivers/iio/dac/ad5754.c line 558

Quoted 10 lines
drivers/iio/dac/ad5754.c new file +9 -0
+{
+	struct device *dev = &spi->dev;
+	struct iio_dev *indio_dev;
+	struct ad5754_state *st;
+	int ret;
+
 
+
+	st->vref_reg = devm_regulator_get_optional(dev, "vref");
+	if (IS_ERR(st->vref_reg)) {

Subtle corner here.
The return may not indicate that vref was not provided, it might return -EPROBEDEFER for example to indicate that we need to back off until another driver is loaded.

As such, you need separate handling for -ENODEV (I think that's the return for not specified) which is what you have here, and other error codes which should be a probe failure via a dev_err_probe() to deal with the deferred case debug info.

Quoted 24 lines
drivers/iio/dac/ad5754.c new file +24 -0
+		if (!st->chip_info->internal_vref)
+			return dev_err_probe(dev, PTR_ERR(st->vref_reg),
+					     "Failed to get the vref regulator\n");
+
+		ret = regmap_update_bits(st->regmap,
+					 AD5754_REG_ADDR(AD5754_PWR_REG, AD5754_PU_ADDR),
+					 AD5754_INT_REF_MASK,
+					 FIELD_PREP(AD5754_INT_REF_MASK, 1));
+		if (ret)
+			return ret;
+
+		ret = devm_add_action_or_reset(dev, ad5754_disable_int_ref, st);
+		if (ret)
+			return ret;
+	} else {
+		ret = regulator_enable(st->vref_reg);
+		if (ret)
+			return dev_err_probe(dev, ret,
+					     "Failed to enable the vref regulator\n");
+
+		ret = devm_add_action_or_reset(dev, ad5754_regulator_disable, st->vref_reg);
+		if (ret)
+			return ret;
+	}

...

Quoted 10 lines
drivers/iio/dac/ad5754.c new file +10 -0
+static const struct spi_device_id ad5754_id[] = {
+	{ "ad5722", (kernel_ulong_t)&ad5754_chip_info_data[AD5722], },
+	{ "ad5732", (kernel_ulong_t)&ad5754_chip_info_data[AD5732], },
+	{ "ad5752", (kernel_ulong_t)&ad5754_chip_info_data[AD5752], },
+	{ "ad5724", (kernel_ulong_t)&ad5754_chip_info_data[AD5724], },
+	{ "ad5734", (kernel_ulong_t)&ad5754_chip_info_data[AD5734], },
+	{ "ad5754", (kernel_ulong_t)&ad5754_chip_info_data[AD5754], },
+	{ "ad5722r", (kernel_ulong_t)&ad5754_chip_info_data[AD5722R], },
+	{ "ad5732r", (kernel_ulong_t)&ad5754_chip_info_data[AD5732R], },
+	{ "ad5752r", (kernel_ulong_t)&ad5754_chip_info_data[AD5752R], },

drivers/iio/dac/ad5754.c line 620

Quoted 10 lines
drivers/iio/dac/ad5754.c new file +10 -0
+	{ "ad5724r", (kernel_ulong_t)&ad5754_chip_info_data[AD5724R], },
+	{ "ad5734r", (kernel_ulong_t)&ad5754_chip_info_data[AD5734R], },
+	{ "ad5754r", (kernel_ulong_t)&ad5754_chip_info_data[AD5754R], },
+	{}
+};
+
+static const struct of_device_id ad5754_dt_id[] = {
+	{
+		.compatible = "adi,ad5722",
+		.data = &ad5754_chip_info_data[AD5722],

Whatever order you end up with in the DT binding after Krzysztof's review replicate here and for the spi_device_ids above.

Quoted 37 lines
drivers/iio/dac/ad5754.c new file +37 -0
+	}, {
+		.compatible = "adi,ad5732",
+		.data = &ad5754_chip_info_data[AD5732],
+	}, {
+		.compatible = "adi,ad5752",
+		.data = &ad5754_chip_info_data[AD5752],
+	}, {
+		.compatible = "adi,ad5724",
+		.data = &ad5754_chip_info_data[AD5724],
+	}, {
+		.compatible = "adi,ad5734",
+		.data = &ad5754_chip_info_data[AD5734],
+	}, {
+		.compatible = "adi,ad5754",
+		.data = &ad5754_chip_info_data[AD5754],
+	}, {
+		.compatible = "adi,ad5722r",
+		.data = &ad5754_chip_info_data[AD5722R],
+	}, {
+		.compatible = "adi,ad5732r",
+		.data = &ad5754_chip_info_data[AD5732R],
+	}, {
+		.compatible = "adi,ad5752r",
+		.data = &ad5754_chip_info_data[AD5752R],
+	}, {
+		.compatible = "adi,ad5724r",
+		.data = &ad5754_chip_info_data[AD5724R],
+	}, {
+		.compatible = "adi,ad5734r",
+		.data = &ad5754_chip_info_data[AD5734R],
+	}, {
+		.compatible = "adi,ad5754r",
+		.data = &ad5754_chip_info_data[AD5754R],
+	},
+	{}
+};
+MODULE_DEVICE_TABLE(of, ad5754_dt_id);