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

title: Analog Devices AD5529R 16-Channel 12/16-bit High Voltage DAC

maintainers:
  - Janani Sunil <janani.sunil@analog.com>

description: |
  The AD5529R is a 16-channel, 12-bit or 16-bit, high voltage, buffered voltage
  output digital-to-analog converter (DAC) with an integrated precision reference.
  The device operates from unipolar and bipolar supplies. It is guaranteed
  monotonic and has built-in rail-to-rail output buffers that can source or
  sink up to 25mA.

  Specifications:
  * 16 independent 12-bit or 16-bit DAC channels
  * Independently programmable output ranges: 0V to 5V, 0V to 10V, 0V to 20V,
    0V to 40V, ±5V, ±10V, ±15V, and ±20V
  * The device supports SPI communication with Mode 0 and Mode 3.
  * 4.096V precision reference, 12ppm/°C maximum
  * Built-in function generation: Toggle, Sinusoidal Dither, and Ramp waveforms
  * Multiplexer for output voltage, load current sense and die temperature

  Datasheet: https://www.analog.com/media/en/technical-documentation/data-sheets/ad5529r.pdf

properties:
  compatible:
    enum:
      - adi,ad5529r-16   # 16-bit variant
      - adi,ad5529r-12   # 12-bit variant

  reg:
    maxItems: 1

  spi-max-frequency:
    maximum: 25000000
    description:
      Maximum SPI frequency. The device supports SPI Mode 0 and Mode 3.
      Read operations are limited to 25MHz maximum.

  reset-gpios:
    maxItems: 1
    description:
      GPIO connected to the RESET pin. Active low. When asserted low,
      performs a power-on reset and initializes the device to its default state.

  clear-gpios:
    maxItems: 1
    description:
      GPIO connected to the CLEAR pin. Active low. When asserted low,
      clears all DAC data registers without affecting configuration settings.

  interrupts:
    maxItems: 1
    description:
      Interrupt connected to the ALARM pin. Active low interrupt output
      for overtemperature conditions, SPI CRC errors, and function completion.

  pwms:
    minItems: 1
    maxItems: 4
    description:
      PWM signals connected to the TG0-TG3 toggle pins. Pulsing these pins
      based on trigger edge settings allows selected DACs to be updated
      synchronously for digital function generation.

  pwm-names:
    minItems: 1
    maxItems: 4
    items:
      enum: [ tg0, tg1, tg2, tg3 ]

  io-channels:
    maxItems: 1
    description:
      ADC channel connected to the MUXOUT pin for monitoring output voltage,
      load current sense, and die temperature.

  io-channel-names:
    const: muxout

  vdd-io-supply:
    description: Digital power supply (1.08V to 1.98V)

  vdd-5v-supply:
    description: Analog power supply (4.75V to 5.25V)

  vdd-hv0-supply:
    description:
      High voltage positive supply (7V to 45V) for channels 0 to 3.

  vdd-hv1-supply:
    description:
      High voltage positive supply (7V to 45V) for channels 4 to 7.

  vdd-hv2-supply:
    description:
      High voltage positive supply (7V to 45V) for channels 8 to 11.

  vdd-hv3-supply:
    description:
      High voltage positive supply (7V to 45V) for channels 12 to 15.

  vss-hv0-supply:
    description:
      High voltage negative supply (-22.5V to 0V) for channels 0 to 3.

  vss-hv1-supply:
    description:
      High voltage negative supply (-22.5V to 0V) for channels 4 to 7.

  vss-hv2-supply:
    description:
      High voltage negative supply (-22.5V to 0V) for channels 8 to 11.

  vss-hv3-supply:
    description:
      High voltage negative supply (-22.5V to 0V) for channels 12 to 15.

  vref-supply:
    description:
      External voltage reference supply (4.056V to 4.136V, typically 4.096V).
      When specified, the device uses external reference mode and the VREF pin
      becomes an input. The device uses the internal 4.096V precision reference
      otherwise.

  spi-device-addr:
    minItems: 1
    maxItems: 4
    items:
      enum: [0, 1, 2, 3]
    default: 0
    description:
      Hardware address of each device, selected by the ID0 and ID1 pins.
      Up to four AD5529R devices can share a single SPI chip select.

  "#address-cells":
    const: 1

  "#size-cells":
    const: 0

patternProperties:
  "^channel@([0-9a-f]{1,2})$":
    $ref: dac.yaml
    type: object
    description: Child nodes for individual channel configuration

    properties:
      reg:
        description:
          Flattened channel number across all AD5529R devices sharing the chip
          select. Within each 16-channel block, the physical channel number is reg % 16.
        minimum: 0
        maximum: 63

      output-range-microvolt:
        description:
          Output voltage range for this channel as [min, max] in
          microvolts.
        oneOf:
          - items:
              - const: 0
                default: 0
              - enum: [5000000, 10000000, 20000000, 40000000]
                default: 5000000
          - items:
              - const: -5000000
              - const: 5000000
          - items:
              - const: -10000000
              - const: 10000000
          - items:
              - const: -15000000
              - const: 15000000
          - items:
              - const: -20000000
              - const: 20000000

    required:
      - reg

    additionalProperties: false

required:
  - compatible
  - reg
  - vdd-io-supply
  - vdd-5v-supply
  - vdd-hv0-supply
  - vdd-hv1-supply
  - vdd-hv2-supply
  - vdd-hv3-supply

dependencies:
  spi-cpha: [ spi-cpol ]
  spi-cpol: [ spi-cpha ]

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

unevaluatedProperties: false

examples:
  - |
    #include <dt-bindings/gpio/gpio.h>

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

        dac@0 {
            compatible = "adi,ad5529r-16";
            reg = <0>;
            spi-max-frequency = <25000000>;
            spi-device-addr = <0>;

            vdd-io-supply = <&vdd_io_regulator>;
            vdd-5v-supply = <&vdd_5v_regulator>;
            vdd-hv0-supply = <&vdd_hv0_regulator>;
            vdd-hv1-supply = <&vdd_hv1_regulator>;
            vdd-hv2-supply = <&vdd_hv2_regulator>;
            vdd-hv3-supply = <&vdd_hv3_regulator>;
            vss-hv0-supply = <&vss_hv0_regulator>;
            vss-hv1-supply = <&vss_hv1_regulator>;
            vss-hv2-supply = <&vss_hv2_regulator>;
            vss-hv3-supply = <&vss_hv3_regulator>;

            reset-gpios = <&gpio0 87 GPIO_ACTIVE_LOW>;

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

            channel@0 {
                reg = <0>;
                output-range-microvolt = <0 5000000>;
            };

            channel@1 {
                reg = <1>;
                output-range-microvolt = <(-10000000) 10000000>;
            };

            channel@2 {
                reg = <2>;
                output-range-microvolt = <0 40000000>;
            };
        };
    };
...