From 6db4e941e2942fc1da10f151594ec5d61935b9ad Mon Sep 17 00:00:00 2001
From: Quentin Berthet <quentin.berthet@hesge.ch>
Date: Mon, 9 May 2022 16:25:17 +0200
Subject: [PATCH] Add required kernel config and device tree modification to
 support host-mode usb on scalp

---
 .../device-tree/files/system-user.dtsi        | 18 ++++++----
 .../linux/linux-xlnx/devtool-fragment.cfg     | 36 +++++++++++++++++++
 2 files changed, 48 insertions(+), 6 deletions(-)

diff --git a/scalp_user_petalinux/project-spec/meta-user/recipes-bsp/device-tree/files/system-user.dtsi b/scalp_user_petalinux/project-spec/meta-user/recipes-bsp/device-tree/files/system-user.dtsi
index 2c0e8cc..88c41a0 100644
--- a/scalp_user_petalinux/project-spec/meta-user/recipes-bsp/device-tree/files/system-user.dtsi
+++ b/scalp_user_petalinux/project-spec/meta-user/recipes-bsp/device-tree/files/system-user.dtsi
@@ -28,6 +28,14 @@
         //gpio0     = &gpio0;                    /*          MIO  0, 7, 8, 43, 44              */
 	};
 
+    usb_phy0: phy0 {
+        compatible = "ulpi-phy";
+        #phy-cells = <0>;
+        reg = <0xe0002000 0x1000>;
+        view-port = <0x170>;
+        drv-vbus;
+    };
+
     /* 256 MB DDR3 */
 	memory@0 {
 		device_type = "memory";
@@ -280,12 +288,10 @@
 	status = "okay";
 };
 
-/* usb0 */
-/*&usb0 {
-    u-boot,dm-pre-reloc;
-    phy_type = "ulpi";
-	status = "okay";
-};*/
+&usb0 {
+    dr_mode = "host";
+    usb-phy = <&usb_phy0>;
+};
 
 /* i2c0 */
 &i2c0 {
diff --git a/scalp_user_petalinux/project-spec/meta-user/recipes-kernel/linux/linux-xlnx/devtool-fragment.cfg b/scalp_user_petalinux/project-spec/meta-user/recipes-kernel/linux/linux-xlnx/devtool-fragment.cfg
index f8de3f1..bd899b4 100644
--- a/scalp_user_petalinux/project-spec/meta-user/recipes-kernel/linux/linux-xlnx/devtool-fragment.cfg
+++ b/scalp_user_petalinux/project-spec/meta-user/recipes-kernel/linux/linux-xlnx/devtool-fragment.cfg
@@ -134,3 +134,39 @@ CONFIG_ZSTD_DECOMPRESS=y
 CONFIG_ASSOCIATIVE_ARRAY=y
 CONFIG_SGL_ALLOC=y
 CONFIG_OID_REGISTRY=y
+
+# USB Stuff, not all may be required
+CONFIG_USB_HID=y
+CONFIG_USB_OHCI_LITTLE_ENDIAN=y
+CONFIG_USB_SUPPORT=y
+CONFIG_USB_COMMON=y
+CONFIG_USB_ULPI_BUS=y
+CONFIG_USB_ARCH_HAS_HCD=y
+CONFIG_USB=y
+CONFIG_USB_PCI=y
+CONFIG_USB_DEFAULT_PERSIST=y
+CONFIG_USB_AUTOSUSPEND_DELAY=2
+CONFIG_USB_EHCI_HCD=y
+CONFIG_USB_EHCI_ROOT_HUB_TT=y
+CONFIG_USB_EHCI_PCI=y
+CONFIG_USB_STORAGE=y
+CONFIG_USB_CHIPIDEA=y
+CONFIG_USB_CHIPIDEA_OF=y
+CONFIG_USB_CHIPIDEA_PCI=y
+CONFIG_USB_CHIPIDEA_UDC=y
+CONFIG_USB_CHIPIDEA_HOST=y
+CONFIG_USB_PHY=y
+CONFIG_NOP_USB_XCEIV=y
+CONFIG_USB_ULPI=y
+CONFIG_USB_ULPI_VIEWPORT=y
+CONFIG_USB_GADGET=y
+CONFIG_USB_GADGET_VBUS_DRAW=2
+CONFIG_USB_GADGET_STORAGE_NUM_BUFFERS=2
+CONFIG_USB_GADGET_XILINX=y
+CONFIG_USB_LIBCOMPOSITE=m
+CONFIG_USB_F_SS_LB=m
+CONFIG_USB_F_MASS_STORAGE=m
+CONFIG_USB_CONFIGFS=m
+CONFIG_USB_CONFIGFS_MASS_STORAGE=y
+CONFIG_USB_ZERO=m
+CONFIG_USB_ROLE_SWITCH=y
\ No newline at end of file
-- 
GitLab