# SPDX-License-Identifier: GPL-2.0
%YAML 1.2
---
$id: http://devicetree.org/schemas/mfd/x-powers,axp152.yaml#
$schema: http://devicetree.org/meta-schemas/core.yaml#

title: X-Powers AXP PMIC

maintainers:
  - Chen-Yu Tsai <wens@csie.org>

allOf:
  - if:
      properties:
        compatible:
          contains:
            enum:
              - x-powers,axp152
              - x-powers,axp202
              - x-powers,axp209

    then:
      properties:
        regulators:
          properties:
            x-powers,dcdc-freq:
              minimum: 750
              maximum: 1875
              default: 1500

    else:
      properties:
        regulators:
          properties:
            x-powers,dcdc-freq:
              minimum: 1800
              maximum: 4050
              default: 3000

  - if:
      properties:
        compatible:
          contains:
            enum:
              - x-powers,axp152
              - x-powers,axp202
              - x-powers,axp209

    then:
      properties:
        x-powers,drive-vbus-en: false

  - if:
      not:
        properties:
          compatible:
            contains:
              const: x-powers,axp806

    then:
      properties:
        x-powers,self-working-mode: false
        x-powers,master-mode: false

  - if:
      not:
        properties:
          compatible:
            contains:
              enum:
                - x-powers,axp15060
                - x-powers,axp305
                - x-powers,axp313a

    then:
      required:
        - interrupts

  - if:
      properties:
        compatible:
          contains:
            enum:
              - x-powers,axp313a
              - x-powers,axp15060
              - x-powers,axp717

    then:
      properties:
        x-powers,dcdc-freq: false

properties:
  compatible:
    oneOf:
      - enum:
          - x-powers,axp152
          - x-powers,axp192
          - x-powers,axp202
          - x-powers,axp209
          - x-powers,axp221
          - x-powers,axp223
          - x-powers,axp313a
          - x-powers,axp717
          - x-powers,axp803
          - x-powers,axp806
          - x-powers,axp809
          - x-powers,axp813
          - x-powers,axp15060
      - items:
          - const: x-powers,axp228
          - const: x-powers,axp221
      - items:
          - const: x-powers,axp805
          - const: x-powers,axp806
      - items:
          - const: x-powers,axp305
          - const: x-powers,axp805
          - const: x-powers,axp806
      - items:
          - const: x-powers,axp818
          - const: x-powers,axp813

  reg:
    maxItems: 1

  interrupts:
    maxItems: 1

  interrupt-controller: true

  "#interrupt-cells":
    const: 1

  x-powers,drive-vbus-en:
    type: boolean
    description: >
      Set this when the N_VBUSEN pin is used as an output pin to control an
      external regulator to drive the OTG VBus, rather then as an input pin
      which signals whether the board is driving OTG VBus or not.

  x-powers,self-working-mode:
    type: boolean
    description: >
      Set this when the PMIC is wired for self-working mode through the MODESET
      pin.

  x-powers,master-mode:
    type: boolean
    description: >
      Set this when the PMIC is wired for master mode through the MODESET pin.

  vin1-supply:
    description: >
      DCDC1 power supply node, if present.

  vin2-supply:
    description: >
      DCDC2 power supply node, if present.

  vin3-supply:
    description: >
      DCDC3 power supply node, if present.

  vin4-supply:
    description: >
      DCDC4 power supply node, if present.

  vin5-supply:
    description: >
      DCDC5 power supply node, if present.

  vin6-supply:
    description: >
      DCDC6 power supply node, if present.

  vin7-supply:
    description: >
      DCDC7 power supply node, if present.

  vina-supply:
    description: >
      DCDCA power supply node, if present.

  vinb-supply:
    description: >
      DCDCB power supply node, if present.

  vinc-supply:
    description: >
      DCDCC power supply node, if present.

  vind-supply:
    description: >
      DCDCD power supply node, if present.

  vine-supply:
    description: >
      DCDCE power supply node, if present.

  acin-supply:
    description: >
      LDO1 power supply node, if present.

  ldo24in-supply:
    description: >
      LDO2 and LDO4 power supply node, if present.

  ldo3in-supply:
    description: >
      LDO3 power supply node, if present.

  ldo5in-supply:
    description: >
      LDO5 power supply node, if present.

  aldoin-supply:
    description: >
      ALDO* power supply node, if present.

  bldoin-supply:
    description: >
      BLDO* power supply node, if present.

  cldoin-supply:
    description: >
      CLDO* power supply node, if present.

  dldoin-supply:
    description: >
      DLDO* power supply node, if present.

  eldoin-supply:
    description: >
      ELDO* power supply node, if present.

  fldoin-supply:
    description: >
      FLDO* power supply node, if present.

  ips-supply:
    description: >
      LDO_IO0, LDO_IO1 and RTC_LDO power supply node, if present.

  drivevbus-supply:
    description: >
      DRIVEVBUS power supply node, if present.

  swin-supply:
    description: >
      SW power supply node, if present.

  adc:
    $ref: /schemas/iio/adc/x-powers,axp209-adc.yaml#

  gpio:
    $ref: /schemas/gpio/x-powers,axp209-gpio.yaml#

  ac-power:
    $ref: /schemas/power/supply/x-powers,axp20x-ac-power-supply.yaml#

  battery-power:
    $ref: /schemas/power/supply/x-powers,axp20x-battery-power-supply.yaml#

  usb-power:
    $ref: /schemas/power/supply/x-powers,axp20x-usb-power-supply.yaml#

  regulators:
    type: object

    properties:
      x-powers,dcdc-freq:
        $ref: /schemas/types.yaml#/definitions/uint32
        description: >
          Defines the work frequency of DC-DC in kHz.

    patternProperties:
      "^(([a-f])?ldo[0-9]|dcdc[0-7a-e]|ldo(_|-)io(0|1)|(dc1)?sw|rtc(_|-)ldo|cpusldo|drivevbus|dc5ldo|boost)$":
        $ref: /schemas/regulator/regulator.yaml#
        type: object
        unevaluatedProperties: false

        properties:
          regulator-ramp-delay:
            description: >
              Only 800 and 1600 are valid for the DCDC2 and LDO3 regulators on
              the AXP209.

          regulator-soft-start:
            description: >
              Only valid for the LDO3 regulator.

          x-powers,dcdc-workmode:
            $ref: /schemas/types.yaml#/definitions/uint32
            enum: [0, 1]
            description: >
              Only valid for DCDC regulators. Setup 1 for PWM mode, 0
              for AUTO (PWM/PFM) mode. The DCDC regulators work in a
              mixed PWM/PFM mode, using PFM under light loads and
              switching to PWM for heavier loads. Forcing PWM mode
              trades efficiency under light loads for lower output
              noise. This probably makes sense for HiFi audio related
              applications that aren't battery constrained.

    additionalProperties: false

required:
  - compatible
  - reg
  - "#interrupt-cells"
  - interrupt-controller

additionalProperties: false

examples:
  - |
      i2c {
          #address-cells = <1>;
          #size-cells = <0>;

          pmic@30 {
              compatible = "x-powers,axp152";
              reg = <0x30>;
              interrupts = <0>;
              interrupt-controller;
              #interrupt-cells = <1>;
          };
      };

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

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

          pmic@34 {
              compatible = "x-powers,axp209";
              reg = <0x34>;
              interrupt-parent = <&nmi_intc>;
              interrupts = <0 IRQ_TYPE_LEVEL_LOW>;
              interrupt-controller;
              #interrupt-cells = <1>;

              ac_power_supply: ac-power {
                  compatible = "x-powers,axp202-ac-power-supply";
              };

              axp_adc: adc {
                  compatible = "x-powers,axp209-adc";
                  #io-channel-cells = <1>;
              };

              axp_gpio: gpio {
                  compatible = "x-powers,axp209-gpio";
                  gpio-controller;
                  #gpio-cells = <2>;

                  gpio0-adc-pin {
                      pins = "GPIO0";
                      function = "adc";
                  };
              };

              battery_power_supply: battery-power {
                  compatible = "x-powers,axp209-battery-power-supply";
              };

              regulators {
                  /* Default work frequency for buck regulators */
                  x-powers,dcdc-freq = <1500>;

                  reg_dcdc2: dcdc2 {
                      regulator-always-on;
                      regulator-min-microvolt = <1000000>;
                      regulator-max-microvolt = <1450000>;
                      regulator-name = "vdd-cpu";
                  };

                  reg_dcdc3: dcdc3 {
                      regulator-always-on;
                      regulator-min-microvolt = <1000000>;
                      regulator-max-microvolt = <1400000>;
                      regulator-name = "vdd-int-dll";
                  };

                  reg_ldo1: ldo1 {
                      /* LDO1 is a fixed output regulator */
                      regulator-always-on;
                      regulator-min-microvolt = <1300000>;
                      regulator-max-microvolt = <1300000>;
                      regulator-name = "vdd-rtc";
                  };

                  reg_ldo2: ldo2 {
                      regulator-always-on;
                      regulator-min-microvolt = <3000000>;
                      regulator-max-microvolt = <3000000>;
                      regulator-name = "avcc";
                  };

                  reg_ldo3: ldo3 {
                      regulator-name = "ldo3";
                  };

                  reg_ldo4: ldo4 {
                      regulator-name = "ldo4";
                  };

                  reg_ldo5: ldo5 {
                      regulator-name = "ldo5";
                  };
              };

              usb_power_supply: usb-power {
                  compatible = "x-powers,axp202-usb-power-supply";
              };
          };
      };
