# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
%YAML 1.2
---
$id: http://devicetree.org/schemas/iio/adc/adi,ad7380.yaml#
$schema: http://devicetree.org/meta-schemas/core.yaml#

title: Analog Devices Simultaneous Sampling Analog to Digital Converters

maintainers:
  - Michael Hennerich <Michael.Hennerich@analog.com>
  - Nuno Sá <nuno.sa@analog.com>

description: |
  * https://www.analog.com/en/products/ad7380.html
  * https://www.analog.com/en/products/ad7381.html
  * https://www.analog.com/en/products/ad7383.html
  * https://www.analog.com/en/products/ad7384.html
  * https://www.analog.com/en/products/ad7386.html
  * https://www.analog.com/en/products/ad7387.html
  * https://www.analog.com/en/products/ad7388.html
  * https://www.analog.com/en/products/ad7380-4.html
  * https://www.analog.com/en/products/ad7381-4.html
  * https://www.analog.com/en/products/ad7383-4.html
  * https://www.analog.com/en/products/ad7384-4.html
  * https://www.analog.com/en/products/ad7386-4.html
  * https://www.analog.com/en/products/ad7387-4.html
  * https://www.analog.com/en/products/ad7388-4.html
  * https://www.analog.com/en/products/adaq4370-4.html
  * https://www.analog.com/en/products/adaq4380-4.html


$ref: /schemas/spi/spi-peripheral-props.yaml#

properties:
  compatible:
    enum:
      - adi,ad7380
      - adi,ad7381
      - adi,ad7383
      - adi,ad7384
      - adi,ad7386
      - adi,ad7387
      - adi,ad7388
      - adi,ad7380-4
      - adi,ad7381-4
      - adi,ad7383-4
      - adi,ad7384-4
      - adi,ad7386-4
      - adi,ad7387-4
      - adi,ad7388-4
      - adi,adaq4370-4
      - adi,adaq4380-4

  reg:
    maxItems: 1

  spi-max-frequency:
    maximum: 80000000
  spi-cpol: true
  spi-cpha: true

  vcc-supply:
    description: A 3V to 3.6V supply that powers the chip.

  vlogic-supply:
    description:
      A 1.65V to 3.6V supply for the logic pins.

  refio-supply:
    description:
      A 2.5V to 3.3V supply for the external reference voltage. When omitted,
      the internal 2.5V reference is used.

  refin-supply:
    description:
      A 2.5V to 3.3V supply for external reference voltage, for ad7380-4 only.
      For adaq devices, a 5V supply voltage. A 3.3V internal reference is
      derived from it. Connect to vs-p-supply for normal operation.

  vs-p-supply:
    description:
      Amplifiers positive supply.

  vs-n-supply:
    description:
      Amplifiers negative supply.

  ldo-supply:
    description:
      LDO supply. Connect to vs-p-supply or a 3.6 to 5.5 V supply.

  aina-supply:
    description:
      The common mode voltage supply for the AINA- pin on pseudo-differential
      chips.

  ainb-supply:
    description:
      The common mode voltage supply for the AINB- pin on pseudo-differential
      chips.

  ainc-supply:
    description:
      The common mode voltage supply for the AINC- pin on pseudo-differential
      chips.

  aind-supply:
    description:
      The common mode voltage supply for the AIND- pin on pseudo-differential
      chips.

  interrupts:
    description:
      When the device is using 1-wire mode, this property is used to optionally
      specify the ALERT interrupt.
    maxItems: 1

  "#address-cells":
    const: 1

  "#size-cells":
    const: 0

required:
  - compatible
  - reg
  - vcc-supply
  - vlogic-supply

patternProperties:
  "^channel@[0-3]$":
    $ref: adc.yaml
    type: object

    properties:
      reg:
        description:
          The channel number. From 0 to 3 corresponding to channels A,B,C,D
        minimum: 0
        maximum: 3

      adi,gain-milli:
        description:
          The hardware gain applied to the ADC input (in milli units).
          If not present, default to 1000 (no actual gain applied).
          Refer to the typical connection diagrams section of the datasheet for
          pin wiring.
        $ref: /schemas/types.yaml#/definitions/uint16
        enum: [300, 600, 1000, 1600]
        default: 1000

    required:
      - reg

    additionalProperties: false

unevaluatedProperties: false

allOf:
  # pseudo-differential chips require common mode voltage supplies,
  # true differential chips don't use them
  - if:
      properties:
        compatible:
          enum:
            - adi,ad7383
            - adi,ad7384
            - adi,ad7383-4
            - adi,ad7384-4
    then:
      required:
        - aina-supply
        - ainb-supply
    else:
      properties:
        aina-supply: false
        ainb-supply: false
  - if:
      properties:
        compatible:
          enum:
            - adi,ad7383-4
            - adi,ad7384-4
    then:
      required:
        - ainc-supply
        - aind-supply
    else:
      properties:
        ainc-supply: false
        aind-supply: false

  # ad7380-4 uses refin-supply as external reference.
  # adaq devices use internal reference only, derived from refin-supply
  # All other chips from ad738x family use refio as optional external reference.
  # When refio-supply is omitted, internal reference is used.
  - if:
      properties:
        compatible:
          enum:
            - adi,ad7380-4
            - adi,adaq4370-4
            - adi,adaq4380-4
    then:
      properties:
        refio-supply: false
      required:
        - refin-supply
    else:
      properties:
        refin-supply: false

  # adaq devices need more supplies and using channel to declare gain property
  # only applies to adaq devices
  - if:
      properties:
        compatible:
          enum:
            - adi,adaq4370-4
            - adi,adaq4380-4
    then:
      required:
        - vs-p-supply
        - vs-n-supply
        - ldo-supply
    else:
      properties:
        vs-p-supply: false
        vs-n-supply: false
        ldo-supply: false
      patternProperties:
        "^channel@[0-3]$": false

examples:
  - |
    #include <dt-bindings/interrupt-controller/irq.h>

    spi {
        #address-cells = <1>;
        #size-cells = <0>;

        adc@0 {
            compatible = "adi,ad7380";
            reg = <0>;

            spi-cpol;
            spi-cpha;
            spi-max-frequency = <80000000>;

            interrupts = <27 IRQ_TYPE_EDGE_FALLING>;
            interrupt-parent = <&gpio0>;

            vcc-supply = <&supply_3_3V>;
            vlogic-supply = <&supply_3_3V>;
            refio-supply = <&supply_2_5V>;
        };
    };

  - |
    #include <dt-bindings/interrupt-controller/irq.h>

    spi {
        #address-cells = <1>;
        #size-cells = <0>;

        adc@0 {
            compatible = "adi,adaq4380-4";
            reg = <0>;

            spi-cpol;
            spi-cpha;
            spi-max-frequency = <80000000>;

            interrupts = <27 IRQ_TYPE_EDGE_FALLING>;
            interrupt-parent = <&gpio0>;

            vcc-supply = <&supply_3_3V>;
            vlogic-supply = <&supply_3_3V>;
            refin-supply = <&supply_5V>;
            vs-p-supply = <&supply_5V>;
            vs-n-supply = <&supply_0V>;
            ldo-supply = <&supply_5V>;

            #address-cells = <1>;
            #size-cells = <0>;

            channel@0 {
                reg = <0>;
                adi,gain-milli = /bits/ 16 <300>;
            };

            channel@2 {
                reg = <2>;
                adi,gain-milli = /bits/ 16 <600>;
            };

            channel@3 {
                reg = <3>;
                adi,gain-milli = /bits/ 16 <1000>;
            };
        };
    };