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

title: Microchip MCP4(7/8)F(E/V)B(0/1/2)(1/2/4/8) DAC with I2C/SPI Interface Families

maintainers:
  - Ariana Lazar <ariana.lazar@microchip.com>

description: |
  Datasheets for MCP47F(E/V)B(0/1/2)(1/2/4/8) DAC with I2C Interface Families:
   Datasheet for MCP47FEB01, MCP47FEB02, MCP47FEB11, MCP47FEB12, MCP47FEB21,
   MCP47FEB22 can be found here:
     https://ww1.microchip.com/downloads/aemDocuments/documents/OTH/ProductDocuments/DataSheets/20005375A.pdf
   Datasheet for MCP47FVB01, MCP47FVB02, MCP47FVB11, MCP47FVB12, MCP47FVB21,
   MCP47FVB22 can be found here:
     https://ww1.microchip.com/downloads/aemDocuments/documents/OTH/ProductDocuments/DataSheets/20005405A.pdf
   Datasheet for MCP47FEB04, MCP47FEB08, MCP47FEB14, MCP47FEB18, MCP47FEB24,
   MCP47FEB28, MCP47FVB04, MCP47FVB08, MCP47FVB14, MCP47FVB18, MCP47FVB24,
   MCP47FVB28 can be found here:
     https://ww1.microchip.com/downloads/aemDocuments/documents/MSLD/ProductDocuments/DataSheets/MCP47FXBX48-Data-Sheet-DS200006368A.pdf
   Datasheets for MCP48F(E/V)B(0/1/2)(1/2/4/8) DAC with SPI Interface Families:
   Datasheet for MCP48FEB01, MCP48FEB02, MCP48FEB11, MCP48FEB12, MCP48FEB21,
   MCP48FEB22 can be found here:
     https://ww1.microchip.com/downloads/aemDocuments/documents/OTH/ProductDocuments/DataSheets/20005429B.pdf
   Datasheet for MCP48FVB01, MCP48FVB02, MCP48FVB11, MCP48FVB12, MCP48FVB21,
   MCP48FVB22 can be found here:
     https://ww1.microchip.com/downloads/aemDocuments/documents/OTH/ProductDocuments/DataSheets/20005466A.pdf
   Datasheet for MCP48FEB04, MCP48FEB14, MCP48FEB24, MCP48FEB08, MCP48FEB18,
   MCP48FEB28, MCP48FVB04, MCP48FVB14, MCP48FVB24, MCP48FVB08, MCP48FVB18,
   MCP48FVB28 can be found here:
     https://ww1.microchip.com/downloads/aemDocuments/documents/MSLD/ProductDocuments/DataSheets/MCP48FXBX4-8-Family-Data-Sheet-DS20006362A.pdf

  +------------+--------------+-------------+-------------+------------+------------+
  | Device     |  Resolution  |   Channels  | Vref number |   Memory   | Interface  |
  |------------|--------------|-------------|-------------|------------|------------|
  | MCP47FEB01 |              |      1      |      1      |   EEPROM   |    I2C     |
  | MCP47FEB02 |              |      2      |      1      |   EEPROM   |    I2C     |
  | MCP47FEB04 |              |      4      |      2      |   EEPROM   |    I2C     |
  | MCP47FEB08 |     8-bit    |      8      |      2      |   EEPROM   |    I2C     |
  | MCP48FEB01 |              |      1      |      1      |   EEPROM   |    SPI     |
  | MCP48FEB02 |              |      2      |      1      |   EEPROM   |    SPI     |
  | MCP48FEB04 |              |      4      |      2      |   EEPROM   |    SPI     |
  | MCP48FEB08 |              |      8      |      2      |   EEPROM   |    SPI     |
  |------------|--------------|-------------|-------------|------------|------------|
  | MCP47FEB11 |              |      1      |      1      |   EEPROM   |    I2C     |
  | MCP47FEB12 |              |      2      |      1      |   EEPROM   |    I2C     |
  | MCP47FEB14 |              |      4      |      2      |   EEPROM   |    I2C     |
  | MCP47FEB18 |    10-bit    |      8      |      2      |   EEPROM   |    I2C     |
  | MCP48FEB11 |              |      1      |      1      |   EEPROM   |    SPI     |
  | MCP48FEB12 |              |      2      |      1      |   EEPROM   |    SPI     |
  | MCP48FEB14 |              |      4      |      2      |   EEPROM   |    SPI     |
  | MCP48FEB18 |              |      8      |      2      |   EEPROM   |    SPI     |
  |------------|--------------|-------------|-------------|------------|------------|
  | MCP47FEB21 |              |      1      |      1      |   EEPROM   |    I2C     |
  | MCP47FEB22 |              |      2      |      1      |   EEPROM   |    I2C     |
  | MCP47FEB24 |              |      4      |      2      |   EEPROM   |    I2C     |
  | MCP47FEB28 |    12-bit    |      8      |      2      |   EEPROM   |    I2C     |
  | MCP48FEB21 |              |      1      |      1      |   EEPROM   |    SPI     |
  | MCP48FEB22 |              |      2      |      1      |   EEPROM   |    SPI     |
  | MCP48FEB24 |              |      4      |      2      |   EEPROM   |    SPI     |
  | MCP48FEB28 |              |      8      |      2      |   EEPROM   |    SPI     |
  |------------|--------------|-------------|-------------|------------|------------|
  | MCP47FVB01 |              |      1      |      1      |   RAM      |    I2C     |
  | MCP47FVB02 |              |      2      |      1      |   RAM      |    I2C     |
  | MCP47FVB04 |              |      4      |      2      |   RAM      |    I2C     |
  | MCP47FVB08 |     8-bit    |      8      |      2      |   RAM      |    I2C     |
  | MCP48FVB01 |              |      1      |      1      |   RAM      |    SPI     |
  | MCP48FVB02 |              |      2      |      1      |   RAM      |    SPI     |
  | MCP48FVB04 |              |      4      |      2      |   RAM      |    SPI     |
  | MCP48FVB08 |              |      8      |      2      |   RAM      |    SPI     |
  |------------|--------------|-------------|-------------|------------|------------|
  | MCP47FVB11 |              |      1      |      1      |   RAM      |    I2C     |
  | MCP47FVB12 |              |      2      |      1      |   RAM      |    I2C     |
  | MCP47FVB14 |              |      4      |      2      |   RAM      |    I2C     |
  | MCP47FVB18 |    10-bit    |      8      |      2      |   RAM      |    I2C     |
  | MCP48FVB11 |              |      1      |      1      |   RAM      |    SPI     |
  | MCP48FVB12 |              |      2      |      1      |   RAM      |    SPI     |
  | MCP48FVB14 |              |      4      |      2      |   RAM      |    SPI     |
  | MCP48FVB18 |              |      8      |      2      |   RAM      |    SPI     |
  |------------|--------------|-------------|-------------|------------|------------|
  | MCP47FVB21 |              |      1      |      1      |   RAM      |    I2C     |
  | MCP47FVB22 |              |      2      |      1      |   RAM      |    I2C     |
  | MCP47FVB24 |              |      4      |      2      |   RAM      |    I2C     |
  | MCP47FVB28 |    12-bit    |      8      |      2      |   RAM      |    I2C     |
  | MCP48FVB21 |              |      1      |      1      |   RAM      |    SPI     |
  | MCP48FVB22 |              |      2      |      1      |   RAM      |    SPI     |
  | MCP48FVB24 |              |      4      |      2      |   RAM      |    SPI     |
  | MCP48FVB28 |              |      8      |      2      |   RAM      |    SPI     |
  +------------+--------------+-------------+-------------+------------+------------+

properties:
  compatible:
    enum:
      - microchip,mcp47feb01
      - microchip,mcp47feb11
      - microchip,mcp47feb21
      - microchip,mcp47feb02
      - microchip,mcp47feb12
      - microchip,mcp47feb22
      - microchip,mcp47fvb01
      - microchip,mcp47fvb11
      - microchip,mcp47fvb21
      - microchip,mcp47fvb02
      - microchip,mcp47fvb12
      - microchip,mcp47fvb22
      - microchip,mcp47fvb04
      - microchip,mcp47fvb14
      - microchip,mcp47fvb24
      - microchip,mcp47fvb08
      - microchip,mcp47fvb18
      - microchip,mcp47fvb28
      - microchip,mcp47feb04
      - microchip,mcp47feb14
      - microchip,mcp47feb24
      - microchip,mcp47feb08
      - microchip,mcp47feb18
      - microchip,mcp47feb28
      - microchip,mcp48feb01
      - microchip,mcp48feb02
      - microchip,mcp48feb04
      - microchip,mcp48feb08
      - microchip,mcp48feb11
      - microchip,mcp48feb12
      - microchip,mcp48feb14
      - microchip,mcp48feb18
      - microchip,mcp48feb21
      - microchip,mcp48feb22
      - microchip,mcp48feb24
      - microchip,mcp48feb28
      - microchip,mcp48fvb01
      - microchip,mcp48fvb02
      - microchip,mcp48fvb04
      - microchip,mcp48fvb08
      - microchip,mcp48fvb11
      - microchip,mcp48fvb12
      - microchip,mcp48fvb14
      - microchip,mcp48fvb18
      - microchip,mcp48fvb21
      - microchip,mcp48fvb22
      - microchip,mcp48fvb24
      - microchip,mcp48fvb28

  reg:
    maxItems: 1

  spi-max-frequency:
    maximum: 10000000

  "#address-cells":
    const: 1

  "#size-cells":
    const: 0

  vdd-supply:
    description:
      Provides power to the chip and it could be used as reference voltage. The
      voltage is used to calculate scale. For parts without EEPROM at powerup
      this will be the selected as voltage reference.

  vref-supply:
    description: |
      Vref pin (it could be found as Vref0 into the datasheet) may be used as a
      voltage reference when this supply is specified. The internal reference
      will be taken into account for voltage reference besides VDD if this supply
      does not exist.

      This supply will be voltage reference for the following outputs:
        - for single-channel device: Vout0;
        - for dual-channel device: Vout0, Vout1;
        - for quad-channel device: Vout0, Vout2;
        - for octal-channel device: Vout0, Vout2, Vout6, Vout8;

  vref1-supply:
    description: |
      Vref1 pin may be used as a voltage reference when this supply is specified.
      The internal reference will be taken into account for voltage reference
      beside VDD if this supply does not exist.

      This supply will be voltage reference for the following outputs:
        - for quad-channel device: Vout1, Vout3;
        - for octal-channel device: Vout1, Vout3, Vout5, Vout7;

  lat-gpios:
    description:
      LAT pin to be used as a hardware trigger to synchronously update the DAC
      channels. The pin is active Low. It could be also found as LAT0 in
      datasheet.
    maxItems: 1

  lat1-gpios:
    description:
      LAT1 pin to be used as a hardware trigger to synchronously update the odd
      DAC channels on devices with 4 and 8 channels. The pin is active Low.
    maxItems: 1

  microchip,vref-buffered:
    type: boolean
    description:
      Enable buffering of the external Vref/Vref0 pin in cases where the
      external reference voltage does not have sufficient current capability in
      order not to drop it’s voltage when connected to the internal resistor
      ladder circuit.

  microchip,vref1-buffered:
    type: boolean
    description:
      Enable buffering of the external Vref1 pin in cases where the external
      reference voltage does not have sufficient current capability in order not
      to drop it’s voltage when connected to the internal resistor ladder
      circuit.

patternProperties:
  "^channel@[0-7]$":
    $ref: dac.yaml
    type: object
    description: Voltage output channel.

    properties:
      reg:
        description: The channel number.
        minimum: 0
        maximum: 7

      label:
        description: Unique name to identify which channel this is.

    required:
      - reg

    unevaluatedProperties: false

required:
  - compatible
  - reg
  - vdd-supply

allOf:
  - if:
      properties:
        compatible:
          contains:
            pattern: "^microchip,mcp48f[ev]b[0-2][1248]$"
    then:
      $ref: /schemas/spi/spi-peripheral-props.yaml#
      dependencies:
        spi-cpha: [ spi-cpol ]
        spi-cpol: [ spi-cpha ]
    else:
      properties:
        spi-max-frequency: false
        spi-cpha: false
        spi-cpol: false
  - if:
      properties:
        compatible:
          contains:
            enum:
              - microchip,mcp47feb01
              - microchip,mcp47feb11
              - microchip,mcp47feb21
              - microchip,mcp47fvb01
              - microchip,mcp47fvb11
              - microchip,mcp47fvb21
              - microchip,mcp48feb01
              - microchip,mcp48feb11
              - microchip,mcp48feb21
              - microchip,mcp48fvb01
              - microchip,mcp48fvb11
              - microchip,mcp48fvb21
    then:
      properties:
        lat1-gpios: false
        vref1-supply: false
        microchip,vref1-buffered: false
        channel@0:
          properties:
            reg:
              const: 0
      patternProperties:
        "^channel@[1-7]$": false
  - if:
      properties:
        compatible:
          contains:
            enum:
              - microchip,mcp47feb02
              - microchip,mcp47feb12
              - microchip,mcp47feb22
              - microchip,mcp47fvb02
              - microchip,mcp47fvb12
              - microchip,mcp47fvb22
              - microchip,mcp48feb02
              - microchip,mcp48feb12
              - microchip,mcp48feb22
              - microchip,mcp48fvb02
              - microchip,mcp48fvb12
              - microchip,mcp48fvb22
    then:
      properties:
        lat1-gpios: false
        vref1-supply: false
        microchip,vref1-buffered: false
      patternProperties:
        "^channel@[0-1]$":
          properties:
            reg:
              enum: [0, 1]
        "^channel@[2-7]$": false
  - if:
      properties:
        compatible:
          contains:
            enum:
              - microchip,mcp47fvb04
              - microchip,mcp47fvb14
              - microchip,mcp47fvb24
              - microchip,mcp47feb04
              - microchip,mcp47feb14
              - microchip,mcp47feb24
              - microchip,mcp48feb04
              - microchip,mcp48feb14
              - microchip,mcp48feb24
              - microchip,mcp48fvb04
              - microchip,mcp48fvb14
              - microchip,mcp48fvb24
    then:
      patternProperties:
        "^channel@[0-3]$":
          properties:
            reg:
              enum: [0, 1, 2, 3]
        "^channel@[4-7]$": false
  - if:
      properties:
        compatible:
          contains:
            enum:
              - microchip,mcp47fvb08
              - microchip,mcp47fvb18
              - microchip,mcp47fvb28
              - microchip,mcp47feb08
              - microchip,mcp47feb18
              - microchip,mcp47feb28
              - microchip,mcp48feb08
              - microchip,mcp48feb18
              - microchip,mcp48feb28
              - microchip,mcp48fvb08
              - microchip,mcp48fvb18
              - microchip,mcp48fvb28
    then:
      patternProperties:
        "^channel@[0-7]$":
          properties:
            reg:
              enum: [0, 1, 2, 3, 4, 5, 6, 7]
  - if:
      not:
        required:
          - vref-supply
    then:
      properties:
        microchip,vref-buffered: false
  - if:
      not:
        required:
          - vref1-supply
    then:
      properties:
        microchip,vref1-buffered: false

unevaluatedProperties: false

examples:
  - |
    i2c {

        #address-cells = <1>;
        #size-cells = <0>;
        dac@60 {
            compatible = "microchip,mcp47feb02";
            reg = <0x60>;
            vdd-supply = <&vdac_vdd>;
            vref-supply = <&vref_reg>;

            #address-cells = <1>;
            #size-cells = <0>;
            channel@0 {
                reg = <0>;
                label = "Adjustable_voltage_ch0";
            };

            channel@1 {
                reg = <0x1>;
                label = "Adjustable_voltage_ch1";
            };
        };
    };
  - |
    spi {
        #address-cells = <1>;
        #size-cells = <0>;

        dac@0 {
          compatible = "microchip,mcp48feb02";
          reg = <0x0>;
          vdd-supply = <&vdac_vdd>;
          vref-supply = <&vref_reg>;
          spi-max-frequency = <10000000>;

          #address-cells = <1>;
          #size-cells = <0>;
          channel@0 {
            reg = <0>;
            label = "Adjustable_voltage_ch0";
          };

          channel@1 {
            reg = <0x1>;
            label = "Adjustable_voltage_ch1";
          };
        };
    };
...