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

title: Qualcomm PMIC based USB Type-C block

maintainers:
  - Bryan O'Donoghue <bryan.odonoghue@linaro.org>

description:
  Qualcomm PMIC Type-C block

properties:
  compatible:
    oneOf:
      - enum:
          - qcom,pmi632-typec
          - qcom,pm8150b-typec
      - items:
          - enum:
              - qcom,pm6150-typec
              - qcom,pm7250b-typec
          - const: qcom,pm8150b-typec
      - items:
          - enum:
              - qcom,pm4125-typec
          - const: qcom,pmi632-typec


  connector:
    type: object
    $ref: /schemas/connector/usb-connector.yaml#
    unevaluatedProperties: false

  reg:
    description: Type-C port and pdphy SPMI register base offsets
    minItems: 1
    maxItems: 2

  interrupts:
    minItems: 8
    items:
      - description: Type-C CC attach notification, VBUS error, tCCDebounce done
      - description: Type-C VCONN powered
      - description: Type-C CC state change
      - description: Type-C VCONN over-current
      - description: Type-C VBUS state change
      - description: Type-C Attach/detach notification
      - description: Type-C Legacy cable detect
      - description: Type-C Try.Src Try.Snk state change
      - description: Power Domain Signal TX - HardReset or CableReset signal TX
      - description: Power Domain Signal RX - HardReset or CableReset signal RX
      - description: Power Domain TX complete
      - description: Power Domain RX complete
      - description: Power Domain TX fail
      - description: Power Domain TX message discard
      - description: Power Domain RX message discard
      - description: Power Domain Fast Role Swap event

  interrupt-names:
    minItems: 8
    items:
      - const: or-rid-detect-change
      - const: vpd-detect
      - const: cc-state-change
      - const: vconn-oc
      - const: vbus-change
      - const: attach-detach
      - const: legacy-cable-detect
      - const: try-snk-src-detect
      - const: sig-tx
      - const: sig-rx
      - const: msg-tx
      - const: msg-rx
      - const: msg-tx-failed
      - const: msg-tx-discarded
      - const: msg-rx-discarded
      - const: fr-swap

  vdd-vbus-supply:
    description: VBUS power supply.

  vdd-pdphy-supply:
    description: VDD regulator supply to the PDPHY.

  port:
    $ref: /schemas/graph.yaml#/properties/port
    description:
      Contains a port which produces data-role switching messages.

required:
  - compatible
  - reg
  - interrupts
  - interrupt-names
  - vdd-vbus-supply

allOf:
  - if:
      properties:
        compatible:
          contains:
            enum:
              - qcom,pmi632-typec
    then:
      properties:
        reg:
          maxItems: 1
        interrupts:
          maxItems: 8
        interrupt-names:
          maxItems: 8
        vdd-pdphy-supply: false
    else:
      properties:
        reg:
          maxItems: 2
        interrupts:
          minItems: 16
        interrupt-names:
          maxItems: 16
      required:
        - vdd-pdphy-supply

additionalProperties: false

examples:
  - |
    #include <dt-bindings/interrupt-controller/arm-gic.h>
    #include <dt-bindings/usb/pd.h>

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

        pm8150b_typec: typec@1500 {
            compatible = "qcom,pm8150b-typec";
            reg = <0x1500>,
                  <0x1700>;

            interrupts = <0x2 0x15 0x00 IRQ_TYPE_EDGE_RISING>,
                         <0x2 0x15 0x01 IRQ_TYPE_EDGE_BOTH>,
                         <0x2 0x15 0x02 IRQ_TYPE_EDGE_RISING>,
                         <0x2 0x15 0x03 IRQ_TYPE_EDGE_BOTH>,
                         <0x2 0x15 0x04 IRQ_TYPE_EDGE_RISING>,
                         <0x2 0x15 0x05 IRQ_TYPE_EDGE_RISING>,
                         <0x2 0x15 0x06 IRQ_TYPE_EDGE_BOTH>,
                         <0x2 0x15 0x07 IRQ_TYPE_EDGE_RISING>,
                         <0x2 0x17 0x00 IRQ_TYPE_EDGE_RISING>,
                         <0x2 0x17 0x01 IRQ_TYPE_EDGE_RISING>,
                         <0x2 0x17 0x02 IRQ_TYPE_EDGE_RISING>,
                         <0x2 0x17 0x03 IRQ_TYPE_EDGE_RISING>,
                         <0x2 0x17 0x04 IRQ_TYPE_EDGE_RISING>,
                         <0x2 0x17 0x05 IRQ_TYPE_EDGE_RISING>,
                         <0x2 0x17 0x06 IRQ_TYPE_EDGE_RISING>,
                         <0x2 0x17 0x07 IRQ_TYPE_EDGE_RISING>;

            interrupt-names = "or-rid-detect-change",
                              "vpd-detect",
                              "cc-state-change",
                              "vconn-oc",
                              "vbus-change",
                              "attach-detach",
                              "legacy-cable-detect",
                              "try-snk-src-detect",
                              "sig-tx",
                              "sig-rx",
                              "msg-tx",
                              "msg-rx",
                              "msg-tx-failed",
                              "msg-tx-discarded",
                              "msg-rx-discarded",
                              "fr-swap";

            vdd-vbus-supply = <&pm8150b_vbus>;
            vdd-pdphy-supply = <&vreg_l2a_3p1>;

            connector {
                compatible = "usb-c-connector";

                power-role = "source";
                data-role = "dual";
                self-powered;

                source-pdos = <PDO_FIXED(5000, 3000, PDO_FIXED_DUAL_ROLE |
                               PDO_FIXED_USB_COMM | PDO_FIXED_DATA_SWAP)>;

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

                    port@0 {
                        reg = <0>;
                        pmic_typec_hs_in: endpoint {
                            remote-endpoint = <&usb_hs_out>;
                        };
                    };

                    port@1 {
                        reg = <1>;
                        pmic_typec_ss_in: endpoint {
                            remote-endpoint = <&usb_phy_typec_ss_out>;
                        };
                    };

                    port@2 {
                        reg = <2>;
                        pmic_typec_sbu: endpoint {
                            remote-endpoint = <&usb_mux_sbu>;
                        };
                    };
                };
            };
        };
    };

    usb {
        dr_mode = "otg";
        usb-role-switch;
        port {
            usb_hs_out: endpoint {
                remote-endpoint = <&pmic_typec_hs_in>;
            };
        };
    };

    usb-phy {
        orientation-switch;
        port {
            usb_phy_typec_ss_out: endpoint {
                remote-endpoint = <&pmic_typec_ss_in>;
            };
        };
    };

    usb-mux {
        orientation-switch;
        mode-switch;

        port {
            usb_mux_sbu: endpoint {
                remote-endpoint = <&pmic_typec_sbu>;
            };
        };
    };

...
