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

title: Motorola CPCAP PMIC MFD

maintainers:
  - Svyatoslav Ryhel <clamor95@gmail.com>

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

properties:
  compatible:
    oneOf:
      - enum:
          - motorola,mapphone-cpcap
          - motorola,mot-cpcap

      - items:
          - const: motorola,cpcap
          - const: st,6556002

  reg:
    maxItems: 1

  interrupts:
    maxItems: 1

  interrupt-controller: true

  "#interrupt-cells":
    const: 2

  spi-max-frequency:
    maximum: 9600000

  spi-cs-high: true
  spi-cpol: true
  spi-cpha: true

  adc:
    $ref: /schemas/iio/adc/motorola,cpcap-adc.yaml#

  audio-codec:
    type: object
    additionalProperties: false

    properties:
      interrupts:
        items:
          - description: headset detect interrupt
          - description: microphone bias 2 detect interrupt

      interrupt-names:
        items:
          - const: hs
          - const: mb2

      "#sound-dai-cells":
        const: 1

      VAUDIO-supply:
        description:
          Codec power supply, usually VAUDIO regulator of CPCAP.

      ports:
        $ref: /schemas/graph.yaml#/properties/ports

        properties:
          port@0:
            $ref: /schemas/graph.yaml#/properties/port
            description: port connected to the Stereo HiFi DAC

          port@1:
            $ref: /schemas/graph.yaml#/properties/port
            description: port connected to the Voice DAC

        required:
          - port@0
          - port@1

    required:
      - interrupts
      - interrupt-names
      - "#sound-dai-cells"

  battery:
    $ref: /schemas/power/supply/cpcap-battery.yaml#

  charger:
    $ref: /schemas/power/supply/cpcap-charger.yaml#

  key-power:
    $ref: /schemas/input/motorola,cpcap-pwrbutton.yaml#

  phy:
    $ref: /schemas/phy/motorola,cpcap-usb-phy.yaml#

  regulator:
    $ref: /schemas/regulator/motorola,cpcap-regulator.yaml#

  rtc:
    $ref: /schemas/rtc/motorola,cpcap-rtc.yaml#

patternProperties:
  "^led(-[a-z]+)?$":
    $ref: /schemas/leds/motorola,cpcap-leds.yaml#

required:
  - compatible
  - reg
  - interrupts
  - interrupt-controller
  - "#interrupt-cells"
  - spi-max-frequency

additionalProperties: false

examples:
  - |
    #include <dt-bindings/gpio/gpio.h>
    #include <dt-bindings/interrupt-controller/irq.h>
    #include <dt-bindings/input/linux-event-codes.h>

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

        cpcap: pmic@0 {
            compatible = "motorola,cpcap", "st,6556002";
            reg = <0>; /* cs0 */

            interrupt-parent = <&gpio1>;
            interrupts = <7 IRQ_TYPE_EDGE_RISING>;

            interrupt-controller;
            #interrupt-cells = <2>;

            spi-max-frequency = <3000000>;
            spi-cs-high;

            spi-cpol;
            spi-cpha;

            cpcap_adc: adc {
                compatible = "motorola,cpcap-adc";

                interrupt-parent = <&cpcap>;
                interrupts = <8 IRQ_TYPE_NONE>;
                interrupt-names = "adcdone";

                #io-channel-cells = <1>;
            };

            cpcap_audio: audio-codec {
                interrupt-parent = <&cpcap>;
                interrupts = <9 IRQ_TYPE_NONE>, <10 IRQ_TYPE_NONE>;
                interrupt-names = "hs", "mb2";

                VAUDIO-supply = <&vdd_audio>;

                #sound-dai-cells = <1>;

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

                    /* HiFi */
                    port@0 {
                        reg = <0>;

                        cpcap_audio_codec0: endpoint {
                        };
                    };

                    /* Voice */
                    port@1 {
                        reg = <1>;

                        cpcap_audio_codec1: endpoint {
                        };
                    };
                };
            };

            cpcap_battery: battery {
                compatible = "motorola,cpcap-battery";

                interrupt-parent = <&cpcap>;
                interrupts = <6 IRQ_TYPE_NONE>, <5 IRQ_TYPE_NONE>,
                             <3 IRQ_TYPE_NONE>, <20 IRQ_TYPE_NONE>,
                             <54 IRQ_TYPE_NONE>, <57 IRQ_TYPE_NONE>;
                interrupt-names = "eol", "lowbph", "lowbpl",
                                  "chrgcurr1", "battdetb", "cccal";

                io-channels = <&cpcap_adc 0>, <&cpcap_adc 1>,
                              <&cpcap_adc 5>, <&cpcap_adc 6>;
                io-channel-names = "battdetb", "battp",
                                   "chg_isense", "batti";
                power-supplies = <&cpcap_charger>;
            };

            cpcap_charger: charger {
                compatible = "motorola,mapphone-cpcap-charger";

                interrupt-parent = <&cpcap>;
                interrupts = <13 IRQ_TYPE_NONE>, <12 IRQ_TYPE_NONE>,
                             <29 IRQ_TYPE_NONE>, <28 IRQ_TYPE_NONE>,
                             <22 IRQ_TYPE_NONE>, <21 IRQ_TYPE_NONE>,
                             <20 IRQ_TYPE_NONE>, <19 IRQ_TYPE_NONE>,
                             <54 IRQ_TYPE_NONE>;
                interrupt-names = "chrg_det", "rvrs_chrg", "chrg_se1b",
                                  "se0conn", "rvrs_mode", "chrgcurr2",
                                  "chrgcurr1", "vbusvld", "battdetb";

                mode-gpios = <&gpio3 29 GPIO_ACTIVE_LOW>,
                             <&gpio3 23 GPIO_ACTIVE_LOW>;

                io-channels = <&cpcap_adc 0>, <&cpcap_adc 1>,
                              <&cpcap_adc 2>, <&cpcap_adc 5>,
                              <&cpcap_adc 6>;
                io-channel-names = "battdetb", "battp",
                                   "vbus", "chg_isense",
                                   "batti";
            };

            key-power {
                compatible = "motorola,cpcap-pwrbutton";

                interrupt-parent = <&cpcap>;
                interrupts = <23 IRQ_TYPE_NONE>;
            };

            led-red {
                compatible = "motorola,cpcap-led-red";
                vdd-supply = <&vdd_led>;
                label = "status-led::red";
            };

            led-green {
                compatible = "motorola,cpcap-led-green";
                vdd-supply = <&vdd_led>;
                label = "status-led::green";
            };

            led-blue {
                compatible = "motorola,cpcap-led-blue";
                vdd-supply = <&vdd_led>;
                label = "status-led::blue";
            };

            cpcap_usb2_phy: phy {
                compatible = "motorola,cpcap-usb-phy";

                pinctrl-0 = <&usb_gpio_mux_sel1>, <&usb_gpio_mux_sel2>;
                pinctrl-1 = <&usb_ulpi_pins>;
                pinctrl-2 = <&usb_utmi_pins>;
                pinctrl-3 = <&uart3_pins>;
                pinctrl-names = "default", "ulpi", "utmi", "uart";
                #phy-cells = <0>;

                interrupts-extended =
                    <&cpcap 15 IRQ_TYPE_NONE>, <&cpcap 14 IRQ_TYPE_NONE>,
                    <&cpcap 28 IRQ_TYPE_NONE>, <&cpcap 19 IRQ_TYPE_NONE>,
                    <&cpcap 18 IRQ_TYPE_NONE>, <&cpcap 17 IRQ_TYPE_NONE>,
                    <&cpcap 16 IRQ_TYPE_NONE>, <&cpcap 49 IRQ_TYPE_NONE>,
                    <&cpcap 48 IRQ_TYPE_NONE>;
                interrupt-names = "id_ground", "id_float", "se0conn",
                                  "vbusvld", "sessvld", "sessend",
                                  "se1", "dm", "dp";

                mode-gpios = <&gpio2 28 GPIO_ACTIVE_HIGH>,
                             <&gpio1 0 GPIO_ACTIVE_HIGH>;

                io-channels = <&cpcap_adc 2>, <&cpcap_adc 7>;
                io-channel-names = "vbus", "id";

                vusb-supply = <&avdd_usb>;
            };

            regulator {
                compatible = "motorola,cpcap-regulator";

                regulators {
                    vdd_cpu: SW1 {
                        regulator-name = "vdd_cpu";
                        regulator-min-microvolt = <750000>;
                        regulator-max-microvolt = <1125000>;
                        regulator-enable-ramp-delay = <1500>;
                        regulator-always-on;
                        regulator-boot-on;
                    };

                    vdd_core: SW2 {
                        regulator-name = "vdd_core";
                        regulator-min-microvolt = <950000>;
                        regulator-max-microvolt = <1300000>;
                        regulator-enable-ramp-delay = <1500>;
                        regulator-always-on;
                        regulator-boot-on;
                    };

                    vdd_1v8_vio: SW3 {
                        regulator-name = "vdd_1v8_vio";
                        regulator-min-microvolt = <1800000>;
                        regulator-max-microvolt = <1800000>;
                        regulator-enable-ramp-delay = <0>;
                        regulator-always-on;
                        regulator-boot-on;
                    };

                    vdd_aon: SW4 {
                        regulator-name = "vdd_aon";
                        regulator-min-microvolt = <950000>;
                        regulator-max-microvolt = <1300000>;
                        regulator-enable-ramp-delay = <1500>;
                        regulator-always-on;
                        regulator-boot-on;
                    };

                    vdd_led: SW5 {
                        regulator-name = "vdd_led";
                        regulator-min-microvolt = <5050000>;
                        regulator-max-microvolt = <5050000>;
                        regulator-enable-ramp-delay = <1500>;
                        regulator-boot-on;
                    };

                    vdd_hvio: VHVIO {
                        regulator-name = "vdd_hvio";
                        regulator-min-microvolt = <2775000>;
                        regulator-max-microvolt = <2775000>;
                        regulator-enable-ramp-delay = <1000>;
                    };

                    vcore_emmc: VSDIO {
                        regulator-name = "vcore_emmc";
                        regulator-min-microvolt = <1500000>;
                        regulator-max-microvolt = <3000000>;
                        regulator-enable-ramp-delay = <1000>;
                        regulator-always-on;
                        regulator-boot-on;
                    };

                    avdd_dsi_csi: VCSI {
                        regulator-name = "avdd_dsi_csi";
                        regulator-min-microvolt = <1200000>;
                        regulator-max-microvolt = <1200000>;
                        regulator-enable-ramp-delay = <1000>;
                        regulator-boot-on;
                    };

                    avdd_3v3_periph: VWLAN2 {
                        regulator-name = "avdd_3v3_periph";
                        regulator-min-microvolt = <2775000>;
                        regulator-max-microvolt = <3300000>;
                        regulator-enable-ramp-delay = <1000>;
                        regulator-boot-on;
                    };

                    vddio_usd: VSIMCARD {
                        regulator-name = "vddio_usd";
                        regulator-min-microvolt = <1800000>;
                        regulator-max-microvolt = <2900000>;
                        regulator-enable-ramp-delay = <1000>;
                        regulator-boot-on;
                    };

                    vdd_haptic: VVIB {
                        regulator-name = "vdd_haptic";
                        regulator-min-microvolt = <1300000>;
                        regulator-max-microvolt = <3000000>;
                        regulator-enable-ramp-delay = <1000>;
                    };

                    avdd_usb: VUSB {
                        regulator-name = "avdd_usb";
                        regulator-min-microvolt = <3300000>;
                        regulator-max-microvolt = <3300000>;
                        regulator-enable-ramp-delay = <1000>;
                        regulator-always-on;
                        regulator-boot-on;
                    };

                    vdd_audio: VAUDIO {
                        regulator-name = "vdd_audio";
                        regulator-min-microvolt = <2775000>;
                        regulator-max-microvolt = <2775000>;
                        regulator-enable-ramp-delay = <1000>;
                        regulator-always-on;
                        regulator-boot-on;
                    };
                };
            };

            cpcap_rtc: rtc {
                compatible = "motorola,cpcap-rtc";

                interrupt-parent = <&cpcap>;
                interrupts = <39 IRQ_TYPE_NONE>, <26 IRQ_TYPE_NONE>;
            };
        };
    };

...