From 63525eb6d521e4e526814287d62fec647e725a8b Mon Sep 17 00:00:00 2001
From: Ondrej Jirman <megi@xff.cz>
Date: Mon, 14 Aug 2023 08:18:59 +0200
Subject: [PATCH 410/463] arm64: dts: rk3566-pinetab2: Add Type-C controller
 node for USB OTG port

Type-C port farthest from the buttons has HUSB Type-C controller connected
to it. Enable the controller.

Signed-off-by: Ondrej Jirman <megi@xff.cz>
---
 .../boot/dts/rockchip/rk3566-pinetab2.dtsi    | 58 ++++++++++++++++++-
 1 file changed, 57 insertions(+), 1 deletion(-)

diff --git a/arch/arm64/boot/dts/rockchip/rk3566-pinetab2.dtsi b/arch/arm64/boot/dts/rockchip/rk3566-pinetab2.dtsi
index 1ea2513eaafd8..f3b76cb3b1e3f 100644
--- a/arch/arm64/boot/dts/rockchip/rk3566-pinetab2.dtsi
+++ b/arch/arm64/boot/dts/rockchip/rk3566-pinetab2.dtsi
@@ -561,6 +561,7 @@ charger {
 			rockchip,resistor-sense-micro-ohms = <10000>;
 			rockchip,sleep-enter-current-microamp = <300000>;
 			rockchip,sleep-filter-current-microamp = <100000>;
+			power-supplies = <&usbc0>;
 		};
 	};
 };
@@ -765,7 +766,7 @@ tp_rst_l_pmuio2: tp-rst-l-pmuio2 {
 
 	usb {
 		usbcc_int_l: usbcc-int-l {
-			rockchip,pins = <0 RK_PC5 RK_FUNC_GPIO &pcfg_pull_none>;
+			rockchip,pins = <0 RK_PC5 RK_FUNC_GPIO &pcfg_pull_up>;
 		};
 
 		usb_host_pwren1_h: usb-host-pwren1-h {
@@ -893,8 +894,24 @@ &usb_host0_ohci {
 	status = "okay";
 };
 
+&usb_host1_ehci {
+	status = "okay";
+};
+
+&usb_host1_ohci {
+	status = "okay";
+};
+
+/* OTG port controller */
 &usb_host0_xhci {
+	usb-role-switch;
 	status = "okay";
+
+	port {
+		usb_host0_xhci_typec_hs: endpoint {
+			remote-endpoint = <&typec_hs_usb_host0_xhci>;
+		};
+	};
 };
 
 &usb_host1_xhci {
@@ -910,6 +927,7 @@ &usb2phy0_host {
 	status = "okay";
 };
 
+/* OTG port phy */
 &usb2phy0_otg {
 	status = "okay";
 };
@@ -946,3 +964,41 @@ vp1_out_dsi0: endpoint@ROCKCHIP_VOP2_EP_MIPI0 {
 		remote-endpoint = <&dsi0_in_vp1>;
 	};
 };
+
+&i2c0 {
+	usbc0: usb-typec@4e {
+		compatible = "hynetek,husb311";
+		reg = <0x4e>;
+		interrupt-parent = <&gpio0>;
+		interrupts = <RK_PC5 IRQ_TYPE_LEVEL_LOW>;
+		pinctrl-names = "default";
+		pinctrl-0 = <&usbcc_int_l>;
+		vbus-supply = <&vbus>;
+		usb-role-switch = <&usb_host0_xhci>;
+		extcon = <&usb2phy0>;
+
+		connector {
+			compatible = "usb-c-connector";
+			label = "USB-C";
+			data-role = "dual";
+			power-role = "dual";
+			try-power-role = "source";
+			op-sink-microwatt = <2500000>;
+			sink-pdos = <PDO_FIXED(5000, 3000, PDO_FIXED_USB_COMM)>;
+			source-pdos = <PDO_FIXED(5000, 500, PDO_FIXED_USB_COMM)>;
+
+			ports {
+				#address-cells = <1>;
+				#size-cells = <0>;
+
+				port@0 {
+					reg = <0>;
+
+					typec_hs_usb_host0_xhci: endpoint {
+						remote-endpoint = <&usb_host0_xhci_typec_hs>;
+					};
+				};
+			};
+		};
+	};
+};
-- 
2.46.0

