#include "dt-bindings/usb/pd.h"

/ {
        vcc5v0_usb: vcc5v0-usb {
                compatible = "regulator-fixed";
                regulator-name = "vcc5v0_usb";
                regulator-always-on;
                regulator-boot-on;
                regulator-min-microvolt = <5000000>;
                regulator-max-microvolt = <5000000>;
        };

        vbus_typec: vbus5v0-typec {
                compatible = "regulator-fixed";
                regulator-name = "vbus_typec";
                regulator-min-microvolt = <5000000>;
                regulator-max-microvolt = <5000000>;
                enable-active-high;
                gpio = <&gpio4 RK_PD2 GPIO_ACTIVE_HIGH>;
                vin-supply = <&vcc5v0_usb>;
                pinctrl-names = "default";
                pinctrl-0 = <&typec5v_pwren>;
        };
};



&i2c4 {
    status = "okay";

    usbc0: fusb302@22 {
        compatible = "fcs,fusb302";
        reg = <0x22>;
        interrupt-parent = <&gpio1>;
        interrupts = <RK_PA2 IRQ_TYPE_LEVEL_LOW>;
        pinctrl-names = "default";
        pinctrl-0 = <&usbc0_int>;
        vbus-supply = <&vbus_typec>;
        status = "okay";

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

            port@0 {
                reg = <0>;
                usbc0_role_sw: endpoint@0 {
                    remote-endpoint = <&dwc3_0_role_switch>;
                };
            };
        };

        usb_con: connector {
            compatible = "usb-c-connector";
            label = "USB-C";
            data-role = "dual";
            power-role = "dual";
            try-power-role = "sink";
            op-sink-microwatt = <1000000>;
            sink-pdos =
                <PDO_FIXED(5000, 2500, PDO_FIXED_USB_COMM)>;
            source-pdos =
                <PDO_FIXED(5000, 1500, PDO_FIXED_USB_COMM)>;

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

                altmode@0 {
                    reg = <0>;
                    svid = <0xff01>;
                    vdo = <0xffffffff>;
                };
            };

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

                port@0 {
                    reg = <0>;
                    usbc0_orien_sw: endpoint {
                        remote-endpoint = <&usbdp_phy0_orientation_switch>;
                    };
                };
            };
        };
    };
};


&u2phy0 {
        status = "okay";
    
        u2phy0_otg: otg-port {
                status = "okay";
        };

        u2phy0_host: host-port {
                phy-supply = <&vcc5v0_usb>;
                status = "okay";
        };
};

&u2phy1 {
        status = "okay";

        u2phy1_otg: otg-port {
                status = "okay";
        };

        u2phy1_host: host-port {
                status = "okay";
        };
};



&tcphy0 {
        status = "okay";
    svid = <0xff01>;
    orientation-switch;
    port {
        #address-cells = <1>;
        #size-cells = <0>;
        usbdp_phy0_orientation_switch: endpoint@0 {
            reg = <0>;
            remote-endpoint = <&usbc0_orien_sw>;
        };
    };
};

&usbdrd3_0 {
        status = "okay";
};

&usbdrd_dwc3_0 {
    status = "okay";
    usb-role-switch;
    port {
        #address-cells = <1>;
        #size-cells = <0>;
        dwc3_0_role_switch: endpoint@0 {
            reg = <0>;
            remote-endpoint = <&usbc0_role_sw>;
        };
    };
};

&usb_host0_ehci {
        status = "okay";
};

&usb_host0_ohci {
        status = "okay";
};

&usb_host1_ehci {
        status = "okay";
};

&usb_host1_ohci {
        status = "okay";
};


&pinctrl {
        usb-typec {
                usbc0_int: usbc0-int {
                        rockchip,pins = <1 RK_PA2 RK_FUNC_GPIO &pcfg_pull_up>;
                };

                typec5v_pwren: typec5v-pwren {
                        rockchip,pins = <4 RK_PD2 RK_FUNC_GPIO &pcfg_pull_none>;
                };
       };
};
