From 038441bbe0f6dab3e701061c514a8d776dbe6523 Mon Sep 17 00:00:00 2001
From: OpenEmbedded <oe.patch@oe>
Date: Sat, 20 May 2023 14:07:47 +0200
Subject: [PATCH] DTS orange pi zero2 enable usb

Signed-off-by: OpenEmbedded <oe.patch@oe>
---
 .../allwinner/sun50i-h616-orangepi-zero2.dts  | 42 +++++++++++++++++++
 1 file changed, 42 insertions(+)

diff --git a/arch/arm64/boot/dts/allwinner/sun50i-h616-orangepi-zero2.dts b/arch/arm64/boot/dts/allwinner/sun50i-h616-orangepi-zero2.dts
index 88234a139..3b836296b 100644
--- a/arch/arm64/boot/dts/allwinner/sun50i-h616-orangepi-zero2.dts
+++ b/arch/arm64/boot/dts/allwinner/sun50i-h616-orangepi-zero2.dts
@@ -50,6 +50,16 @@ reg_vcc5v: vcc5v {
 		regulator-always-on;
 	};
 
+        reg_usb1_vbus: regulator-usb1-vbus {
+                compatible = "regulator-fixed";
+                regulator-name = "usb1-vbus";
+                regulator-min-microvolt = <5000000>;
+                regulator-max-microvolt = <5000000>;
+                vin-supply = <&reg_vcc5v>;
+                enable-active-high;
+                gpio = <&pio 2 16 GPIO_ACTIVE_HIGH>; /* PC16 */
+        };
+
 	reg_vcc33_wifi: vcc33-wifi {
 		/* Always on 3.3V regulator for WiFi and BT */
 		compatible = "regulator-fixed";
@@ -79,6 +89,12 @@ wifi_pwrseq: wifi-pwrseq {
 	};
 };
 
+&ehci1 {
+        status = "okay";
+};
+
+/* USB 2 & 3 are on headers only. */
+
 &mmc1 {
 	vmmc-supply = <&reg_vcc33_wifi>;
 	vqmmc-supply = <&reg_vcc_wifi_io>;
@@ -123,6 +139,11 @@ &mmc0 {
 	status = "okay";
 };
 
+
+&ohci1 {
+	status = "okay";
+};
+
 &r_rsb {
 	status = "okay";
 
@@ -258,3 +279,24 @@ &uart0 {
 	pinctrl-0 = <&uart0_ph_pins>;
 	status = "okay";
 };
+
+&usbotg {
+	/*
+	 * PHY0 pins are connected to a USB-C socket, but a role switch
+	 * is not implemented: both CC pins are pulled to GND.
+	 * The VBUS pins power the device, so a fixed peripheral mode
+	 * is the best choice.
+	 * The board can be powered via GPIOs, in this case port0 *can*
+	 * act as a host (with a cable/adapter ignoring CC), as VBUS is
+	 * then provided by the GPIOs. Any user of this setup would
+	 * need to adjust the DT accordingly: dr_mode set to "host",
+	 * enabling OHCI0 and EHCI0.
+	 */
+	dr_mode = "peripheral";
+	status = "okay";
+};
+
+&usbphy {
+	usb1_vbus-supply = <&reg_usb1_vbus>;
+	status = "okay";
+};
-- 
2.40.1

