[U-Boot] [PATCH v2 1/4] usb: dwc3: fix kconfig

Roger Quadros rogerq at ti.com
Thu May 19 16:15:46 CEST 2016


DWC3 can be used as host or as gadget controller and the actual mode
is determined at runtime so USB_DWC3_DUAL_ROLE must be the default
mode when both host and gadget drivers are available.

As DWC3 core implements an XHCI host controller, we use USB_XHCI_HCD to
check if host driver is available.

USB_DWC3_HOST and USB_DWC3_GADGET are only set if a particular mode
needs to be forced or if both host and gadget drivers are not available.

Build the dwc3 gadget drivers only if gadget mode can be used at runtime.

Signed-off-by: Roger Quadros <rogerq at ti.com>
---
v2:
- don't depend on USB as dwc3/kconfig already depends on that
- use USB_XHCI_HCD to decide whether host operation is available.
- Add USB_DWC3_DUAL_ROLE, which means that controller can operate
either in host or gadget mode. The actual mode is decided at runtime
based on dwc3->dr_mode.

 drivers/usb/dwc3/Kconfig  | 18 +++++++++++++-----
 drivers/usb/dwc3/Makefile |  4 +++-
 drivers/usb/dwc3/core.h   |  4 ++--
 3 files changed, 18 insertions(+), 8 deletions(-)

diff --git a/drivers/usb/dwc3/Kconfig b/drivers/usb/dwc3/Kconfig
index e93398f..0db536e 100644
--- a/drivers/usb/dwc3/Kconfig
+++ b/drivers/usb/dwc3/Kconfig
@@ -1,19 +1,20 @@
 config USB_DWC3
 	bool "DesignWare USB3 DRD Core Support"
-	depends on (USB && USB_GADGET)
-	select USB_GADGET_DUALSPEED
+	select USB_GADGET_DUALSPEED if USB_GADGET
 	help
-	  Say Y here if your system has a Dual Role SuperSpeed
-	  USB controller based on the DesignWare USB3 IP Core.
+	  Say Y here if your system has DesignWare USB3 IP Core.
 
 if USB_DWC3
 
 choice
 	bool "DWC3 Mode Selection"
+	default USB_DWC3_DUAL_ROLE if (USB_GADGET && USB_XHCI_HCD)
+	default USB_DWC3_HOST if (!USB_GADGET && USB_XHCI_HCD)
+	default USB_DWC3_GADGET if (USB_GADGET && !USB_XHCI_HCD)
 
 config USB_DWC3_HOST
 	bool "Host only mode"
-	depends on USB
+	depends on USB_XHCI_HCD
 	help
 	  Select this when you want to use DWC3 in host mode only,
 	  thereby the gadget feature will be regressed.
@@ -25,6 +26,13 @@ config USB_DWC3_GADGET
 	  Select this when you want to use DWC3 in gadget mode only,
 	  thereby the host feature will be regressed.
 
+config USB_DWC3_DUAL_ROLE
+	bool "Dual role mode"
+	depends on (USB_XHCI_HCD && USB_GADGET)
+	help
+	 This is the default mode of working of DWC3 controller where
+	 both host and gadget features are enabled.
+
 endchoice
 
 comment "Platform Glue Driver Support"
diff --git a/drivers/usb/dwc3/Makefile b/drivers/usb/dwc3/Makefile
index 0cd7302..d2ad2e9 100644
--- a/drivers/usb/dwc3/Makefile
+++ b/drivers/usb/dwc3/Makefile
@@ -6,7 +6,9 @@ obj-$(CONFIG_USB_DWC3)			+= dwc3.o
 
 dwc3-y					:= core.o
 
-dwc3-y					+= gadget.o ep0.o
+ifneq ($(filter y,$(CONFIG_USB_DWC3_GADGET) $(CONFIG_USB_DWC3_DUAL_ROLE)),)
+dwc3-yi					+= gadget.o ep0.o
+endif
 
 obj-$(CONFIG_USB_DWC3_OMAP)		+= dwc3-omap.o
 obj-$(CONFIG_USB_DWC3_PHY_OMAP)		+= ti_usb_phy.o
diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h
index 72d2fcd..faf0c0f 100644
--- a/drivers/usb/dwc3/core.h
+++ b/drivers/usb/dwc3/core.h
@@ -989,7 +989,7 @@ struct dwc3_gadget_ep_cmd_params {
 /* prototypes */
 int dwc3_gadget_resize_tx_fifos(struct dwc3 *dwc);
 
-#ifdef CONFIG_USB_DWC3_HOST
+#if IS_ENABLED(CONFIG_USB_DWC3_HOST) || IS_ENABLED(CONFIG_USB_DWC3_DUAL_ROLE)
 int dwc3_host_init(struct dwc3 *dwc);
 void dwc3_host_exit(struct dwc3 *dwc);
 #else
@@ -999,7 +999,7 @@ static inline void dwc3_host_exit(struct dwc3 *dwc)
 { }
 #endif
 
-#ifdef CONFIG_USB_DWC3_GADGET
+#if IS_ENABLED(CONFIG_USB_DWC3_GADGET) || IS_ENABLED(CONFIG_USB_DWC3_DUAL_ROLE)
 int dwc3_gadget_init(struct dwc3 *dwc);
 void dwc3_gadget_exit(struct dwc3 *dwc);
 int dwc3_gadget_set_test_mode(struct dwc3 *dwc, int mode);
-- 
2.7.4




More information about the U-Boot mailing list