From 67c089f9d7190333f6883c5aef01cc076f8b9e68 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ond=C5=99ej=20Jirman?= <megi@xff.cz>
Date: Wed, 2 Dec 2020 12:09:45 +0100
Subject: [PATCH 232/463] arm64: dts: rk3399-pinebook-pro: Improve Type-C
 support on Pinebook Pro

This is using the same extcon bridge developed by me for Pinephone Pro.

Signed-off-by: Ondrej Jirman <megi@xff.cz>
---
 .../boot/dts/rockchip/rk3399-pinebook-pro.dts | 57 ++++++++++++++++---
 1 file changed, 50 insertions(+), 7 deletions(-)

diff --git a/arch/arm64/boot/dts/rockchip/rk3399-pinebook-pro.dts b/arch/arm64/boot/dts/rockchip/rk3399-pinebook-pro.dts
index 8e959085e2304..698977db29622 100644
--- a/arch/arm64/boot/dts/rockchip/rk3399-pinebook-pro.dts
+++ b/arch/arm64/boot/dts/rockchip/rk3399-pinebook-pro.dts
@@ -335,7 +335,7 @@ regulator-state-mem {
 
 	/* Regulators supplied by vcc5v0_usb */
 	/* Type C port power supply regulator */
-	vbus_5vout: vbus_typec: vbus-5vout {
+	vbus_5vout: vbus-5vout {
 		compatible = "regulator-fixed";
 		enable-active-high;
 		gpio = <&gpio1 RK_PA3 GPIO_ACTIVE_HIGH>;
@@ -374,6 +374,14 @@ mains_charger: dc-charger {
 		pinctrl-names = "default";
 		pinctrl-0 = <&dc_det_pin>;
 	};
+
+	typec_extcon_bridge: typec-extcon {
+		compatible = "linux,typec-extcon-bridge";
+		usb-role-switch;
+		orientation-switch;
+		mode-switch;
+		svid = /bits/ 16 <0xff01>;
+	};
 };
 
 &cpu_b0 {
@@ -400,6 +408,12 @@ &cpu_l3 {
 	cpu-supply = <&vdd_cpu_l>;
 };
 
+&cdn_dp {
+	status = "okay";
+	extcon = <&typec_extcon_bridge>;
+	phys = <&tcphy0_dp>;
+};
+
 &edp {
 	force-hpd;
 	status = "okay";
@@ -691,7 +705,9 @@ fusb0: fusb30x@22 {
 		interrupts = <RK_PA2 IRQ_TYPE_LEVEL_LOW>;
 		pinctrl-names = "default";
 		pinctrl-0 = <&fusb0_int_pin>;
-		vbus-supply = <&vbus_typec>;
+		vbus-supply = <&vbus_5vout>;
+		usb-role-switch = <&typec_extcon_bridge>;
+		extcon = <&typec_extcon_bridge>;
 
 		connector {
 			compatible = "usb-c-connector";
@@ -700,10 +716,19 @@ connector {
 			op-sink-microwatt = <1000000>;
 			power-role = "dual";
 			sink-pdos =
-				<PDO_FIXED(5000, 2500, PDO_FIXED_USB_COMM)>;
+				<PDO_FIXED(5000, 2500, PDO_FIXED_USB_COMM | PDO_FIXED_DUAL_ROLE | PDO_FIXED_DATA_SWAP)>;
 			source-pdos =
-				<PDO_FIXED(5000, 1400, PDO_FIXED_USB_COMM)>;
+				<PDO_FIXED(5000, 1400, PDO_FIXED_USB_COMM | PDO_FIXED_DUAL_ROLE | PDO_FIXED_DATA_SWAP)>;
 			try-power-role = "sink";
+			mode-switch = <&typec_extcon_bridge>;
+			orientation-switch = <&typec_extcon_bridge>;
+
+			altmodes {
+				dp {
+					svid = /bits/ 16 <0xff01>;
+					vdo = <0x0c46>;
+				};
+			};
 
 			ports {
 				#address-cells = <1>;
@@ -970,6 +995,7 @@ spiflash: flash@0 {
 };
 
 &tcphy0 {
+	extcon = <&typec_extcon_bridge>;
 	status = "okay";
 };
 
@@ -1003,13 +1029,21 @@ &tsadc {
 
 &u2phy0 {
 	status = "okay";
+	extcon = <&typec_extcon_bridge>;
+	extcon,ignore-usb;
 
 	u2phy0_otg: otg-port {
+		/*
+		 * Type-C port on the left side of the chasis.
+		 */
 		status = "okay";
 	};
 
 	u2phy0_host: host-port {
-		phy-supply = <&vcc5v0_otg>;
+		/*
+		 * USB 2.0 host port for the keyboard (internally connected).
+		 */
+		phy-supply = <&vcc5v0_usb>;
 		status = "okay";
 	};
 
@@ -1024,11 +1058,18 @@ &u2phy1 {
 	status = "okay";
 
 	u2phy1_otg: otg-port {
+		/*
+		 * USB 3.0 A port on the left side of the chasis.
+		 */
 		status = "okay";
 	};
 
 	u2phy1_host: host-port {
-		phy-supply = <&vcc5v0_otg>;
+		/*
+		 * To the HUB that has USB camera and USB 2.0 port on the right
+		 * side of the chasis.
+		 */
+		phy-supply = <&vcc5v0_usb>;
 		status = "okay";
 	};
 };
@@ -1079,7 +1120,9 @@ &usbdrd3_0 {
 };
 
 &usbdrd_dwc3_0 {
-	dr_mode = "host";
+	dr_mode = "otg";
+	extcon = <&typec_extcon_bridge>;
+	snps,usb3-phy-reset-quirk;
 	status = "okay";
 };
 
-- 
2.46.0

