Skip to contentSkip to conversation

Support MSM8916 USB PHY + UDC in qcom_defconfig

PATCH In review Sam Day 3 participants 8 messages May 27 – Jun 30

Subsystems (2)
lore
Share & tools
lore

Sam Day

author
#0 lore raw

v2 cover Support MSM8916 USB PHY + UDC in qcom_defconfig

The MSM8916 SoC includes a ChipIdea UDC. The U-Boot driver for this UDC is quite old, and did not support USB gadget driver model. As a result, it could not be built alongside the DWC3 driver. This meant that qcom_defconfig could not include support for USB on MSM8916.

This series adds support to build ChipIdea UDC with DM_USB_GADGET and ensures that the newly introduced driver is registered from the MSM EHCI glue driver.

The ChipIdea UDC driver continues to work without DM_USB_GADGET. I tested these changes by building dragonboard410c_defconfig (which does not enable DM_USB_GADGET), booting it, and then chain-booting (via fastboot) another u-boot build built with qcom_defconfig. USB gadget mode worked in both builds.

---
Changes in v2 (thanks Stephan):
- Deduplicate CI UDC setup/teardown paths
- Formatting fix
- Regenerate qcom_defconfig with savedefconfig
- Link to v1: https://lore.kernel.org/r/[email protected]

---
Sam Day (3):
usb: udc: ci: support USB gadget driver model
usb: host: ehci-msm: Register ChipIdea UDC from glue wrapper
qcom_defconfig: Enable MSM8916 USB PHY + ChipIdea UDC

 configs/qcom_defconfig      |   4 +-
 drivers/usb/gadget/Kconfig  |   1 -
 drivers/usb/gadget/ci_udc.c | 118 ++++++++++++++++++++++++++++++++++++--------
 drivers/usb/host/ehci-msm.c |   7 +++
 4 files changed, 107 insertions(+), 23 deletions(-)

---
base-commit: 987907ae4bcc5d6055bdf7d318a3edf53e14d5fa
change-id: 20250412-msm8916-usb-a1dc93c01bd5

Best regards,

Signature · 1 line
Sam Day <[email protected]>
author
#1 lore raw

PATCH v2 1/3 usb: udc: ci: support USB gadget driver model

When CONFIG_DM_USB_GADGET is enabled, a UCLASS_USB_GADGET_GENERIC driver will be defined that wraps the ChipIdea UDC operations. The (dm_)?usb_gadget_.* symbols will no longer be defined (as these are now handled by the UDC uclass).

If CONFIG_DM_USB_GADGET is not enabled, this driver behaves as it previously did.

This new driver does not declare any compatibles of its own. It requires a glue driver to bind it. The ehci_msm driver will be updated in the following commit to do exactly that.

---
 drivers/usb/gadget/Kconfig  |   1 -
 drivers/usb/gadget/ci_udc.c | 118 ++++++++++++++++++++++++++++++++++++--------
 2 files changed, 97 insertions(+), 22 deletions(-)
drivers/usb/gadget/Kconfig +0 -1
index 5390878254a..6ba558cc292 100644
@@ -153,7 +153,6 @@ config USB_GADGET_OS_DESCRIPTORS
 
 config CI_UDC
 	bool "ChipIdea device controller"
-	depends on !DM_USB_GADGET
 	select USB_GADGET_DUALSPEED
 	help
 	  Say Y here to enable device controller functionality of the
drivers/usb/gadget/ci_udc.c +97 -21

178 lines not on this page · raw message

Signature · 1 line
2.54.0
#2 lore raw

Re: [PATCH v2 1/3] usb: udc: ci: support USB gadget driver model

Hi Sam,

Thank you for the patch.
Sorry for the delays in the review for this one.

Quoted 80 lines · Sam Day

When CONFIG_DM_USB_GADGET is enabled, a UCLASS_USB_GADGET_GENERIC driver will be defined that wraps the ChipIdea UDC operations. The (dm_)?usb_gadget_.* symbols will no longer be defined (as these are now handled by the UDC uclass).

If CONFIG_DM_USB_GADGET is not enabled, this driver behaves as it previously did.

This new driver does not declare any compatibles of its own. It requires a glue driver to bind it. The ehci_msm driver will be updated in the following commit to do exactly that.

---
 drivers/usb/gadget/Kconfig  |   1 -
 drivers/usb/gadget/ci_udc.c | 118 ++++++++++++++++++++++++++++++++++++--------
 2 files changed, 97 insertions(+), 22 deletions(-)
drivers/usb/gadget/Kconfig +0 -1
index 5390878254a..6ba558cc292 100644
@@ -153,7 +153,6 @@ config USB_GADGET_OS_DESCRIPTORS
 
 config CI_UDC
 	bool "ChipIdea device controller"
-	depends on !DM_USB_GADGET
 	select USB_GADGET_DUALSPEED
 	help
 	  Say Y here to enable device controller functionality of the
drivers/usb/gadget/ci_udc.c +12 -2
index 4729570c525..42028e11d59 100644
@@ -10,6 +10,7 @@
 #include <command.h>
 #include <config.h>
 #include <cpu_func.h>
+#include <dm.h>
 #include <net.h>
 #include <malloc.h>
 #include <wait_bit.h>
@@ -94,8 +95,17 @@ static struct usb_request *
 ci_ep_alloc_request(struct usb_ep *ep, unsigned int gfp_flags);
 static void ci_ep_free_request(struct usb_ep *ep, struct usb_request *_req);
 
+#if CONFIG_IS_ENABLED(DM_USB_GADGET)
+static int ci_udc_gadget_start(struct usb_gadget *g, struct usb_gadget_driver *driver);
+static int ci_udc_gadget_stop(struct usb_gadget *g);
+#endif
+
 static const struct usb_gadget_ops ci_udc_ops = {
 	.pullup = ci_pullup,
+#if CONFIG_IS_ENABLED(DM_USB_GADGET)
+	.udc_start = ci_udc_gadget_start,
+	.udc_stop = ci_udc_gadget_stop,
+#endif
 };
 
 static const struct usb_ep_ops ci_ep_ops = {
@@ -978,7 +988,7 @@ void udc_irq(void)
 	}
 }
 
-int dm_usb_gadget_handle_interrupts(struct udevice *dev)
+static int ci_udc_handle_interrupts(struct udevice *dev)
 {
 	struct ci_udc *udc = (struct ci_udc *)controller.ctrl->hcor;
 	u32 value;
@@ -1037,7 +1047,7 @@ static int ci_pullup(struct usb_gadget *gadget, int is_on)
 static int ci_udc_probe(void)
 {
 	struct ept_queue_head *head;
-	int i;
+	int i, ret;
 
 	const int num = 2 * NUM_ENDPOINTS;
 
@@ -1046,6 +1056,14 @@ static int ci_udc_probe(void)
 	const int eplist_raw_sz = num * sizeof(struct ept_queue_head);

drivers/usb/gadget/ci_udc.c static int ci_udc_probe(void) · line 1066

Quoted 10 lines
drivers/usb/gadget/ci_udc.c +8 -0
 	const int eplist_sz = roundup(eplist_raw_sz, ARCH_DMA_MINALIGN);
 
+	if (IS_ENABLED(CONFIG_DM_USB))
+		ret = usb_setup_ehci_gadget(&controller.ctrl);
+	else
+		ret = usb_lowlevel_init(0, USB_INIT_DEVICE, (void **)&controller.ctrl);
+
+	if (ret)
+		return ret;
+

What happens if later down in ci_udc_probe() we fail to finish the function sucessfully?
For example, memalign(ILIST_ALIGN, ILIST_SZ) can return -ENOMEM.

Doesn't that leaves us with an usb that's halfway configured? Shouldn't we add some error handling / do some cleanup in that case?

Quoted 12 lines
drivers/usb/gadget/ci_udc.c +5 -0
 	/* The QH list must be aligned to 4096 bytes. */
 	controller.epts = memalign(eplist_align, eplist_sz);
 	if (!controller.epts)
@@ -1123,6 +1141,73 @@ static int ci_udc_probe(void)
 	return 0;
 }
 
+static void ci_udc_remove(void)
+{
+	if (IS_ENABLED(CONFIG_DM_USB)) {
+		usb_remove_ehci_gadget(&controller.ctrl);
+	} else {

drivers/usb/gadget/ci_udc.c static int ci_udc_probe(void) · line 1158

Quoted 10 lines
drivers/usb/gadget/ci_udc.c +10 -0
+		usb_lowlevel_stop(0);
+		controller.ctrl = NULL;
+	}
+}
+
+static void ci_udc_stop(void)
+{
+	ci_ep_free_request(&controller.ep[0].ep, &controller.ep0_req->req);
+	free(controller.items_mem);
+	free(controller.epts);

It feels a bit weird to free the endpoint request in stop(). Shouldn't we do this in the remove() function to match the ci_ep_alloc_request() which is done in ci_udc_probe()?

drivers/usb/gadget/ci_udc.c static int ci_udc_probe(void) · line 1165

Quoted 7 lines
drivers/usb/gadget/ci_udc.c +7 -0
+}
+
+static int ci_udc_gadget_start(struct usb_gadget *g, struct usb_gadget_driver *driver)
+{
+	controller.driver = driver;
+	return 0;
+}

Nitpick: could we please move this next to ci_udc_gadget_stop() ? I know this would force you to write add controller.driver = driver in usb_gadget_register_driver() but I don't this it's a problem given that we do something similar in usb_gadget_unregister_driver().

Quoted 26 lines
drivers/usb/gadget/ci_udc.c +26 -0
+
+#if CONFIG_IS_ENABLED(DM_USB_GADGET)
+static int ci_udc_generic_probe(struct udevice *dev)
+{
+	int ret = ci_udc_probe();
+
+	if (ret)
+		return ret;
+
+	return usb_add_gadget_udc((struct device *)dev, &controller.gadget);
+}
+
+static int ci_udc_generic_remove(struct udevice *dev)
+{
+	usb_del_gadget_udc(&controller.gadget);
+
+	ci_udc_remove();
+
+	return 0;
+}
+
+static const struct usb_gadget_generic_ops ci_udc_generic_ops = {
+	.handle_interrupts	= ci_udc_handle_interrupts,
+};
+
+U_BOOT_DRIVER(ci_udc_generic) = {

drivers/usb/gadget/ci_udc.c static int ci_udc_probe(void) · line 1201

Quoted 10 lines
drivers/usb/gadget/ci_udc.c +10 -0
+	.name = "ci-udc",
+	.id = UCLASS_USB_GADGET_GENERIC,
+	.ops = &ci_udc_generic_ops,
+	.probe = ci_udc_generic_probe,
+	.remove = ci_udc_generic_remove,
+};
+
+static int ci_udc_gadget_stop(struct usb_gadget *g)
+{
+	/* Avoid calling disconnect() twice; the UDC uclass already did it. */

There is no disconnect in udc-uclass.c? Did you mean "UDC core" here instead of "UDC uclass" ?

Quoted 69 lines
drivers/usb/gadget/ci_udc.c +19 -19
+	controller.driver = NULL;
+	udc_disconnect();
+
+	ci_udc_stop();
+
+	return 0;
+}
+
+#else
 int usb_gadget_register_driver(struct usb_gadget_driver *driver)
 {
 	int ret;
@@ -1132,14 +1217,6 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver)
 	if (!driver->bind || !driver->setup || !driver->disconnect)
 		return -EINVAL;
 
-#if CONFIG_IS_ENABLED(DM_USB)
-	ret = usb_setup_ehci_gadget(&controller.ctrl);
-#else
-	ret = usb_lowlevel_init(0, USB_INIT_DEVICE, (void **)&controller.ctrl);
-#endif
-	if (ret)
-		return ret;
-
 	ret = ci_udc_probe();
 	if (ret) {
 		DBG("udc probe failed, returned %d\n", ret);
@@ -1151,7 +1228,8 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver)
 		DBG("driver->bind() returned %d\n", ret);
 		return ret;
 	}
-	controller.driver = driver;
+
+	ci_udc_gadget_start(&controller.gadget, driver);
 
 	return 0;
 }
@@ -1163,20 +1241,18 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
 	driver->unbind(&controller.gadget);
 	controller.driver = NULL;
 
-	ci_ep_free_request(&controller.ep[0].ep, &controller.ep0_req->req);
-	free(controller.items_mem);
-	free(controller.epts);
-
-#if CONFIG_IS_ENABLED(DM_USB)
-	usb_remove_ehci_gadget(&controller.ctrl);
-#else
-	usb_lowlevel_stop(0);
-	controller.ctrl = NULL;
-#endif
+	ci_udc_stop();
+	ci_udc_remove();
 
 	return 0;
 }
 
+int dm_usb_gadget_handle_interrupts(struct udevice *dev)
+{
+	return ci_udc_handle_interrupts(dev);
+}
+#endif
+
 bool dfu_usb_get_reset(void)
 {
 	struct ci_udc *udc = (struct ci_udc *)controller.ctrl->hcor;
Signature · 2 lines
-- 
2.54.0
author
#3 lore raw

PATCH v2 2/3 usb: host: ehci-msm: Register ChipIdea UDC from glue wrapper

In reply to Sam Day

When CONFIG_DM_USB_GADGET is enabled, the CI UDC driver needs to be explicitly bound. So we do this from the newly introduced glue driver.

---
 drivers/usb/host/ehci-msm.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/usb/host/ehci-msm.c +7 -0
index a58eff7cb9c..00719b7b575 100644
@@ -161,6 +161,13 @@ static int qcom_ci_hdrc_bind(struct udevice *dev)
 	if (ret)
 		return ret;
 
+	if (IS_ENABLED(CONFIG_DM_USB_GADGET) && IS_ENABLED(CONFIG_CI_UDC)) {
+		ret = device_bind_driver_to_node(dev, "ci-udc", "ci-udc",
+						 dev_ofnode(dev), NULL);
+		if (ret)
+			return ret;
+	}
+
 	if (!ofnode_valid(ulpi_node))
 		return 0;
 
Signature · 1 line
2.54.0
author
#5 lore raw

PATCH v2 3/3 qcom_defconfig: Enable MSM8916 USB PHY + ChipIdea UDC

In reply to Sam Day

Now that the ChipIdea UDC driver supports USB Gadget driver model, we can enable it alongside the dwc3 generic driver.

---
 configs/qcom_defconfig | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
configs/qcom_defconfig +3 -1
index d0d54ec5a70..75e22f01f17 100644
@@ -108,7 +108,6 @@ CONFIG_DWC_ETH_QOS_QCOM=y
 CONFIG_RGMII=y
 CONFIG_PHY_MICREL=y
 CONFIG_PHY_MICREL_KSZ90X1=y
-CONFIG_PHY=y
 CONFIG_PHY_QCOM_QMP_UFS=y
 CONFIG_PHY_QCOM_QUSB2=y
 CONFIG_PHY_QCOM_USB_SNPS_FEMTO_V2=y
@@ -139,9 +138,12 @@ CONFIG_SYSRESET_QCOM_PSHOLD=y
 CONFIG_USB=y
 CONFIG_USB_XHCI_HCD=y
 CONFIG_USB_XHCI_DWC3=y
+CONFIG_USB_EHCI_HCD=y
+CONFIG_USB_EHCI_MSM=y
 CONFIG_USB_DWC3=y
 CONFIG_USB_DWC3_GENERIC=y
 CONFIG_USB_GADGET=y
+CONFIG_CI_UDC=y
 CONFIG_UFS=y
 CONFIG_UFS_QCOM=y
 CONFIG_VIDEO=y
Signature · 1 line
2.54.0
#7 lore raw

Re: [PATCH v2 3/3] qcom_defconfig: Enable MSM8916 USB PHY + ChipIdea UDC

In reply to Sam Day

Hi Sam,

Thanks for the patch.

Quoted 13 lines · Sam Day

Now that the ChipIdea UDC driver supports USB Gadget driver model, we can enable it alongside the dwc3 generic driver.

---
  configs/qcom_defconfig | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)
configs/qcom_defconfig +0 -0
index d0d54ec5a70..75e22f01f17 100644

configs/qcom_defconfig CONFIG_DWC_ETH_QOS_QCOM=y · line 111

Quoted 4 lines
configs/qcom_defconfig +0 -1
@@ -108,7 +108,6 @@ CONFIG_DWC_ETH_QOS_QCOM=y
  CONFIG_RGMII=y
  CONFIG_PHY_MICREL=y
  CONFIG_PHY_MICREL_KSZ90X1=y
-CONFIG_PHY=y

Is this change related to the goal of this patch? Maybe we can have this as seperate patch?

Regards,

Balaji

Quoted 17 lines
configs/qcom_defconfig +3 -0
  CONFIG_PHY_QCOM_QMP_UFS=y
  CONFIG_PHY_QCOM_QUSB2=y
  CONFIG_PHY_QCOM_USB_SNPS_FEMTO_V2=y
@@ -139,9 +138,12 @@ CONFIG_SYSRESET_QCOM_PSHOLD=y
  CONFIG_USB=y
  CONFIG_USB_XHCI_HCD=y
  CONFIG_USB_XHCI_DWC3=y
+CONFIG_USB_EHCI_HCD=y
+CONFIG_USB_EHCI_MSM=y
  CONFIG_USB_DWC3=y
  CONFIG_USB_DWC3_GENERIC=y
  CONFIG_USB_GADGET=y
+CONFIG_CI_UDC=y
  CONFIG_UFS=y
  CONFIG_UFS_QCOM=y
  CONFIG_VIDEO=y