[PATCH v7 3/3] usb: mtu3: add SPL support

Carlo Caione <[email protected]>
Newsgroups org.u-boot-project.lists.u-boot
Message-ID <20260808-ccaione-upstream-mtu3-spl-gadget-v7-3-ed659a79a918@baylibre.com>
MediaTek platforms may need the MTU3 controller before U-Boot proper is
available, but the driver is currently selected and built only with the
main U-Boot configuration symbols.

Add an explicit SPL controller option with host and gadget modes. Make
the driver build and its role checks phase-aware so each phase can select
the MTU3 role it needs without coupling it to the U-Boot proper controller
configuration.

The upstream binding locates the xHCI child registers through the parent
ranges property. Select SPL_OF_TRANSLATE for host mode so SPL can resolve
that address before mapping it.

Signed-off-by: Julien Masson <[email protected]>
Signed-off-by: Carlo Caione <[email protected]>
---
 drivers/Makefile             |  3 ++-
 drivers/usb/mtu3/Kconfig     | 39 +++++++++++++++++++++++++++++++++++++++
 drivers/usb/mtu3/Makefile    | 10 +++++-----
 drivers/usb/mtu3/mtu3_dr.h   |  4 ++--
 drivers/usb/mtu3/mtu3_plat.c |  8 ++++----
 5 files changed, 52 insertions(+), 12 deletions(-)

diff --git a/drivers/Makefile b/drivers/Makefile
index 43d0ba33281..4c7ba741acb 100644
--- a/drivers/Makefile
+++ b/drivers/Makefile
@@ -66,7 +66,8 @@ obj-$(CONFIG_DRAM_SUN20I_D1) += ram/
 obj-$(CONFIG_SPL_DM_RESET) += reset/
 obj-$(CONFIG_SPL_MUSB_NEW) += usb/musb-new/
 obj-$(CONFIG_SPL_USB_GADGET) += usb/gadget/
-obj-$(CONFIG_SPL_USB_GADGET) += usb/common/
+obj-$(CONFIG_SPL_DM_USB) += usb/common/
+obj-$(CONFIG_SPL_USB_MTU3) += usb/mtu3/
 obj-$(CONFIG_SPL_USB_GADGET) += usb/gadget/udc/
 obj-$(CONFIG_SPL_WATCHDOG) += watchdog/
 obj-$(CONFIG_SPL_USB_HOST) += usb/host/
diff --git a/drivers/usb/mtu3/Kconfig b/drivers/usb/mtu3/Kconfig
index 5ec498ec953..8623adfdf51 100644
--- a/drivers/usb/mtu3/Kconfig
+++ b/drivers/usb/mtu3/Kconfig
@@ -42,3 +42,42 @@ config USB_MTU3_DEBUG
 	  Say Y here to enable debugging messages in the MTU3 Driver.
 
 endif
+
+config SPL_USB_MTU3
+	bool "MediaTek USB3 controller support in SPL"
+	depends on ARCH_MEDIATEK
+	depends on SPL_DM_USB
+	depends on SPL_USB_HOST || (SPL_DM_USB_GADGET && SPL_USB_GADGET)
+	help
+	  Enable the MediaTek USB3 controller in SPL. Select host or peripheral
+	  mode below.
+
+if SPL_USB_MTU3
+
+choice
+	bool "MTU3 SPL Mode Selection"
+	default SPL_USB_MTU3_GADGET if SPL_USB_GADGET
+	default SPL_USB_MTU3_HOST if (SPL_USB_HOST && !SPL_USB_GADGET)
+	help
+	  Select whether the MTU3 controller operates as an xHCI host or a USB
+	  peripheral in SPL.
+
+config SPL_USB_MTU3_HOST
+	bool "Host mode in SPL"
+	depends on SPL_USB_HOST && USB_XHCI_HCD
+	select SPL_OF_TRANSLATE
+	help
+	  Enable the MTU3 xHCI host controller in SPL so USB devices can be
+	  accessed before U-Boot proper starts.
+
+config SPL_USB_MTU3_GADGET
+	bool "Gadget mode in SPL"
+	depends on SPL_DM_USB_GADGET && SPL_USB_GADGET
+	select USB_GADGET_DUALSPEED
+	help
+	  Enable the MTU3 peripheral controller in SPL so USB gadget
+	  functions can use it before U-Boot proper starts.
+
+endchoice
+
+endif
diff --git a/drivers/usb/mtu3/Makefile b/drivers/usb/mtu3/Makefile
index 234f3a380a3..d1f0cd24875 100644
--- a/drivers/usb/mtu3/Makefile
+++ b/drivers/usb/mtu3/Makefile
@@ -1,11 +1,11 @@
 # SPDX-License-Identifier: GPL-2.0
 
-ccflags-$(CONFIG_USB_MTU3_DEBUG)	+= -DDEBUG
+ccflags-$(CONFIG_$(PHASE_)USB_MTU3_DEBUG)	+= -DDEBUG
 
-obj-$(CONFIG_USB_MTU3)	+= mtu3.o
+obj-$(CONFIG_$(PHASE_)USB_MTU3)	+= mtu3.o
 
 mtu3-y	:= mtu3_plat.o
 
-obj-$(CONFIG_USB_MTU3_GADGET)	+= mtu3_core.o mtu3_gadget_ep0.o mtu3_gadget.o
-obj-$(CONFIG_USB_MTU3_GADGET)	+= mtu3_qmu.o
-obj-$(CONFIG_USB_MTU3_HOST)	+= mtu3_host.o
+obj-$(CONFIG_$(PHASE_)USB_MTU3_GADGET) += mtu3_core.o mtu3_gadget_ep0.o
+obj-$(CONFIG_$(PHASE_)USB_MTU3_GADGET) += mtu3_gadget.o mtu3_qmu.o
+obj-$(CONFIG_$(PHASE_)USB_MTU3_HOST) += mtu3_host.o
diff --git a/drivers/usb/mtu3/mtu3_dr.h b/drivers/usb/mtu3/mtu3_dr.h
index ec0e50c04ca..89fbde03625 100644
--- a/drivers/usb/mtu3/mtu3_dr.h
+++ b/drivers/usb/mtu3/mtu3_dr.h
@@ -10,7 +10,7 @@
 #ifndef _MTU3_DR_H_
 #define _MTU3_DR_H_
 
-#if IS_ENABLED(CONFIG_USB_MTU3_HOST)
+#if CONFIG_IS_ENABLED(USB_MTU3_HOST)
 
 int ssusb_host_init(struct ssusb_mtk *ssusb);
 void ssusb_host_exit(struct ssusb_mtk *ssusb);
@@ -27,7 +27,7 @@ static inline void ssusb_host_exit(struct ssusb_mtk *ssusb)
 
 #endif
 
-#if IS_ENABLED(CONFIG_USB_MTU3_GADGET)
+#if CONFIG_IS_ENABLED(USB_MTU3_GADGET)
 int ssusb_gadget_init(struct ssusb_mtk *ssusb);
 void ssusb_gadget_exit(struct ssusb_mtk *ssusb);
 irqreturn_t mtu3_irq(int irq, void *data);
diff --git a/drivers/usb/mtu3/mtu3_plat.c b/drivers/usb/mtu3/mtu3_plat.c
index ec920eaf166..73107167ada 100644
--- a/drivers/usb/mtu3/mtu3_plat.c
+++ b/drivers/usb/mtu3/mtu3_plat.c
@@ -439,17 +439,17 @@ static int mtu3_glue_bind(struct udevice *parent)
 
 	switch (dr_mode) {
 	case USB_DR_MODE_PERIPHERAL:
-		if (IS_ENABLED(CONFIG_USB_MTU3_GADGET))
+		if (CONFIG_IS_ENABLED(USB_MTU3_GADGET))
 			return mtu3_bind_gadget(parent);
 		break;
 	case USB_DR_MODE_HOST:
-		if (IS_ENABLED(CONFIG_USB_MTU3_HOST))
+		if (CONFIG_IS_ENABLED(USB_MTU3_HOST))
 			return mtu3_bind_host(parent);
 		break;
 	case USB_DR_MODE_OTG:
-		if (IS_ENABLED(CONFIG_USB_MTU3_GADGET))
+		if (CONFIG_IS_ENABLED(USB_MTU3_GADGET))
 			return mtu3_bind_gadget(parent);
-		if (IS_ENABLED(CONFIG_USB_MTU3_HOST))
+		if (CONFIG_IS_ENABLED(USB_MTU3_HOST))
 			return mtu3_bind_host(parent);
 		break;
 	default:

-- 
2.55.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.