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

title: Freescale MC13xxx Power Management Integrated Circuits (PMIC)

maintainers:
  - Alexander Kurz <akurz@blala.de>

description: >
  The MC13xxx PMIC series consists of the three models MC13783, MC13892
  and MC34708 and provide regulators and other features like RTC, ADC,
  LED, touchscreen, codec and input buttons.

  Link to datasheets
    https://www.nxp.com/docs/en/data-sheet/MC13783.pdf
    https://www.nxp.com/docs/en/data-sheet/MC13892.pdf
    https://www.nxp.com/docs/en/data-sheet/MC34708.pdf

properties:
  compatible:
    enum:
      - fsl,mc13783
      - fsl,mc13892
      - fsl,mc34708

  reg:
    description: I2C slave address or SPI chip select number.
    maxItems: 1

  spi-max-frequency: true

  spi-cs-high: true

  system-power-controller: true

  interrupts:
    maxItems: 1

  buttons:
    type: object
    properties:
      "#address-cells":
        const: 1

      "#size-cells":
        const: 0

    patternProperties:
      "^onkey@[0-2]$":
        $ref: /schemas/input/input.yaml#
        unevaluatedProperties: false
        type: object

        properties:
          reg:
            description: |
              One of
              MC13783 BUTTON IDs:
                0: ONOFD1
                1: ONOFD2
                2: ONOFD3

              MC13892 BUTTON IDs:
                0: PWRON1
                1: PWRON2
                2: PWRON3

              MC34708 BUTTON IDs:
                0: PWRON1
                1: PWRON2
            maximum: 2

          debounce-delay-ms:
            enum: [0, 30, 150, 750]
            default: 30

          active-low:
            description: Set active when pin is pulled low.

          linux,code: true

          fsl,enable-reset:
            description:
              Setting of the global reset option.
            type: boolean

    unevaluatedProperties: false

  leds:
    type: object
    additionalProperties: false

    properties:
      '#address-cells':
        const: 1

      '#size-cells':
        const: 0

      led-control:
        $ref: /schemas/types.yaml#/definitions/uint32-array
        description: |
          Setting for LED-Control register array length depends on model,
          mc13783: 6, mc13892: 4, mc34708: 1

    patternProperties:
      '^led@[0-9a-b]$':
        $ref: /schemas/leds/common.yaml#
        unevaluatedProperties: false

        properties:
          reg:
            description: |
              One of
              MC13783 LED IDs
                0: Main display
                1: AUX display
                2: Keypad
                3: Red 1
                4: Green 1
                5: Blue 1
                6: Red 2
                7: Green 2
                8: Blue 2
                9: Red 3
                10: Green 3
                11: Blue 3

              MC13892 LED IDs
                0: Main display
                1: AUX display
                2: Keypad
                3: Red
                4: Green
                5: Blue

              MC34708 LED IDs
                0: Charger Red
                1: Charger Green
            maxItems: 1

  regulators:
    type: object

    additionalProperties:
      type: object

    description: |
      List of child nodes specifying the regulators, depending on chip variant.
      Each child node is defined using the standard binding for regulators and
      the optional regulator properties defined below.

  fsl,mc13xxx-uses-adc:
    type: boolean
    description: Indicate the ADC is being used

  fsl,mc13xxx-uses-codec:
    type: boolean
    description: Indicate the Audio Codec is being used

  fsl,mc13xxx-uses-rtc:
    type: boolean
    description: Indicate the RTC is being used

  fsl,mc13xxx-uses-touch:
    type: boolean
    description: Indicate the touchscreen controller is being used

required:
  - compatible
  - reg

allOf:
  - if:
      properties:
        compatible:
          contains:
            const: fsl,mc13783
    then:
      properties:
        leds:
          properties:
            led-control:
              minItems: 6
              maxItems: 6
        regulators:
          patternProperties:
            "^gpo[1-4]|pwgt[12]spi|sw[12][ab]|sw3|vaudio|vcam|vdig|vesim|vgen|viohi|violo|vmmc[12]|vrf[12]|vrfbg|vrfcp|vrfdig|vrfref|vsim|vvib$":
              type: object
              $ref: /schemas/regulator/regulator.yaml#

              unevaluatedProperties: false

  - if:
      properties:
        compatible:
          contains:
            const: fsl,mc13892
    then:
      properties:
        leds:
          properties:
            led-control:
              minItems: 4
              maxItems: 4
        regulators:
          patternProperties:
            "^gpo[1-4]|pwgt[12]spi|sw[1-4]|swbst|vaudio|vcam|vcoincell|vdig|vgen[1-3]|viohi|vpll|vsd|vusb|vusb2|vvideo$":
              type: object
              $ref: /schemas/regulator/regulator.yaml#

              unevaluatedProperties: false

  - if:
      properties:
        compatible:
          contains:
            const: fsl,mc34708
    then:
      properties:
        buttons:
          patternProperties:
            "^onkey@[0-2]$":
              properties:
                reg:
                  maximum: 1
        leds:
          properties:
            led-control:
              minItems: 1
              maxItems: 1

additionalProperties: false

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

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

        pmic: mc13892@0 {
            compatible = "fsl,mc13892";
            reg = <0>;
            spi-max-frequency = <1000000>;
            spi-cs-high;
            interrupt-parent = <&gpio0>;
            interrupts = <8 IRQ_TYPE_LEVEL_HIGH>;
            fsl,mc13xxx-uses-rtc;
            fsl,mc13xxx-uses-adc;

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

                onkey@0 {
                    reg = <0>;
                    debounce-delay-ms = <30>;
                    active-low;
                    fsl,enable-reset;
                };
            };

            leds {
                #address-cells = <1>;
                #size-cells = <0>;
                led-control = <0x000 0x000 0x0e0 0x000>;

                led@3 {
                    reg = <3>;
                    label = "system:red:live";
                    linux,default-trigger = "heartbeat";
                };
            };

            regulators {
                sw1_reg: sw1 {
                    regulator-min-microvolt = <600000>;
                    regulator-max-microvolt = <1375000>;
                    regulator-boot-on;
                    regulator-always-on;
                };

                sw2_reg: sw2 {
                    regulator-min-microvolt = <900000>;
                    regulator-max-microvolt = <1850000>;
                    regulator-boot-on;
                    regulator-always-on;
                };
            };
        };
    };