Skip to contentSkip to conversation

usb: musb-new: sunxi: support usage with DM_USB_GADGET

PATCH In review Aren Moynihan 4 participants 5 messages Dec 31, 2023 – Apr 16, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 usb: musb-new: sunxi: support usage with DM_USB_GADGET

Add support for building the sunxi-musb driver with DM_USB_GADGET including adding a separate IRQ handling function and registering the driver with the musb system differently.

The implementation of usb_gadget_register_driver from musb-new/musb_uboot.c only works when the gadget driver for the device has already been probed and has called musb_register. On the pinephone (using a allwinner a64 processor) this causes issues when trying to use usb gadget mode (such as from the ums command) and CONFIG_USB_ETHER is disabled.

The implementation of usb_gadget_register_driver provided when DM_USB_GADGET is enabled will probe the necessary drivers when it's called.

Without the patch, this is what the error condition looks like:
=> ums 0 mmc 1
UMS: LUN 0, dev mmc 1, hwpart 0, sector 0x0, count 0x3a3e000 Controller uninitialized
g_dnl_register: failed!, error: -6
g_dnl_register failed

based on:
commit 2e4865bc6486 ("musb-new: omap2430: fix compiling in DM_USB_GADGET config")

---
I don't fully understand what's going on here. Some gadget mode drivers, such as usb ether (in usb_ether_init) will initialize the usb gadget driver, but others (ums, fastboot) don't seem to do this, or don't do it early enough, so they don't work.

 drivers/usb/musb-new/sunxi.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
drivers/usb/musb-new/sunxi.c +20 -0
index 91f082fe05e..9b06f49ce47 100644
@@ -429,6 +429,17 @@ static struct musb_hdrc_config musb_config_h3 = {
 	.ram_bits	= SUNXI_MUSB_RAM_BITS,
 };
 
+#ifdef CONFIG_DM_USB_GADGET
+int dm_usb_gadget_handle_interrupts(struct udevice *dev)
+{
+	int n = 0;
+	struct musb_host_data *host = dev_get_priv(dev);
+
+	host->host->isr(0, host->host);
+	return 0;
+}
+#endif
+
 static int musb_usb_probe(struct udevice *dev)
 {
 	struct sunxi_glue *glue = dev_get_priv(dev);
@@ -482,6 +493,15 @@ static int musb_usb_probe(struct udevice *dev)
 	ret = musb_lowlevel_init(host);
 	if (!ret)
 		printf("Allwinner mUSB OTG (Host)\n");
+#elifdef CONFIG_DM_USB_GADGET
+	pdata.mode = MUSB_PERIPHERAL;
+	host->host = musb_init_controller(&pdata, &glue->dev, base);
+	if (!host->host)
+		return -EIO;
+
+	ret = usb_add_gadget_udc(&glue->dev, &host->host->g);
+	if (!ret)
+		printf("Allwinner mUSB OTG (Peripheral)\n");
 #else
 	pdata.mode = MUSB_PERIPHERAL;
 	host->host = musb_register(&pdata, &glue->dev, base);
Signature · 1 line
2.43.0
#1 lore raw
Quoted 3 lines · Aren Moynihan

Add support for building the sunxi-musb driver with DM_USB_GADGET including adding a separate IRQ handling function and registering the driver with the musb system differently.

Hi there,

Were you aware of this similar patch?

https://lore.kernel.org/u-boot/[email protected]/

If not you might want to test it and compare it.

John.

Quoted 22 lines

The implementation of usb_gadget_register_driver from musb-new/musb_uboot.c only works when the gadget driver for the device has already been probed and has called musb_register. On the pinephone (using a allwinner a64 processor) this causes issues when trying to use usb gadget mode (such as from the ums command) and CONFIG_USB_ETHER is disabled.

The implementation of usb_gadget_register_driver provided when DM_USB_GADGET is enabled will probe the necessary drivers when it's called.

Without the patch, this is what the error condition looks like:
=> ums 0 mmc 1
UMS: LUN 0, dev mmc 1, hwpart 0, sector 0x0, count 0x3a3e000 Controller uninitialized
g_dnl_register: failed!, error: -6
g_dnl_register failed

based on:
commit 2e4865bc6486 ("musb-new: omap2430: fix compiling in DM_USB_GADGET config")

author
#2 lore raw
Quoted 7 lines · John Watts
Quoted 3 lines · Aren Moynihan

Add support for building the sunxi-musb driver with DM_USB_GADGET including adding a separate IRQ handling function and registering the driver with the musb system differently.

Hi there,

Quoted 7 lines

Were you aware of this similar patch?

https://lore.kernel.org/u-boot/[email protected]/

If not you might want to test it and compare it.

John.

I was not aware of that patch, it looks like it does the same thing as this one, but without some of the bugs. When comparing with it I realized that my dm_usb_gadget_handle_interrupts function is just plain wrong.

I'll try to find time to test it soon.

Thanks for the link
- Aren

Quoted 22 lines
Quoted 22 lines

The implementation of usb_gadget_register_driver from musb-new/musb_uboot.c only works when the gadget driver for the device has already been probed and has called musb_register. On the pinephone (using a allwinner a64 processor) this causes issues when trying to use usb gadget mode (such as from the ums command) and CONFIG_USB_ETHER is disabled.

The implementation of usb_gadget_register_driver provided when DM_USB_GADGET is enabled will probe the necessary drivers when it's called.

Without the patch, this is what the error condition looks like:
=> ums 0 mmc 1
UMS: LUN 0, dev mmc 1, hwpart 0, sector 0x0, count 0x3a3e000 Controller uninitialized
g_dnl_register: failed!, error: -6
g_dnl_register failed

based on:
commit 2e4865bc6486 ("musb-new: omap2430: fix compiling in DM_USB_GADGET config")

#3 lore raw

Hi,

Quoted 14 lines · Aren
Quoted 13 lines · John Watts
Quoted 3 lines · Aren Moynihan

Add support for building the sunxi-musb driver with DM_USB_GADGET including adding a separate IRQ handling function and registering the driver with the musb system differently.

Hi there,

Were you aware of this similar patch?

https://lore.kernel.org/u-boot/[email protected]/

If not you might want to test it and compare it.

Quoted 8 lines
Quoted 1 line

John.

I was not aware of that patch, it looks like it does the same thing as this one, but without some of the bugs. When comparing with it I realized that my dm_usb_gadget_handle_interrupts function is just plain wrong.

I'll try to find time to test it soon.

Please keep me in the loop for both progress on this one and on testing:

https://lore.kernel.org/u-boot/[email protected]/

Quoted 26 lines

Thanks for the link
- Aren

Quoted 22 lines
Quoted 22 lines

The implementation of usb_gadget_register_driver from musb-new/musb_uboot.c only works when the gadget driver for the device has already been probed and has called musb_register. On the pinephone (using a allwinner a64 processor) this causes issues when trying to use usb gadget mode (such as from the ums command) and CONFIG_USB_ETHER is disabled.

The implementation of usb_gadget_register_driver provided when DM_USB_GADGET is enabled will probe the necessary drivers when it's called.

Without the patch, this is what the error condition looks like:
=> ums 0 mmc 1
UMS: LUN 0, dev mmc 1, hwpart 0, sector 0x0, count 0x3a3e000 Controller uninitialized
g_dnl_register: failed!, error: -6
g_dnl_register failed

based on:
commit 2e4865bc6486 ("musb-new: omap2430: fix compiling in DM_USB_GADGET config")

#4 lore raw
In reply to Aren Moynihan
Quoted 40 lines · Aren Moynihan

Add support for building the sunxi-musb driver with DM_USB_GADGET including adding a separate IRQ handling function and registering the driver with the musb system differently.

The implementation of usb_gadget_register_driver from musb-new/musb_uboot.c only works when the gadget driver for the device has already been probed and has called musb_register. On the pinephone (using a allwinner a64 processor) this causes issues when trying to use usb gadget mode (such as from the ums command) and CONFIG_USB_ETHER is disabled.

The implementation of usb_gadget_register_driver provided when DM_USB_GADGET is enabled will probe the necessary drivers when it's called.

Without the patch, this is what the error condition looks like:
=> ums 0 mmc 1
UMS: LUN 0, dev mmc 1, hwpart 0, sector 0x0, count 0x3a3e000 Controller uninitialized
g_dnl_register: failed!, error: -6
g_dnl_register failed

based on:
commit 2e4865bc6486 ("musb-new: omap2430: fix compiling in DM_USB_GADGET config")

---
I don't fully understand what's going on here. Some gadget mode drivers, such as usb ether (in usb_ether_init) will initialize the usb gadget driver, but others (ums, fastboot) don't seem to do this, or don't do it early enough, so they don't work.

  drivers/usb/musb-new/sunxi.c | 20 ++++++++++++++++++++
  1 file changed, 20 insertions(+)
drivers/usb/musb-new/sunxi.c +0 -0
index 91f082fe05e..9b06f49ce47 100644

drivers/usb/musb-new/sunxi.c static struct musb_hdrc_config musb_config_h3 = { · line 435

Quoted 7 lines
drivers/usb/musb-new/sunxi.c +4 -0
@@ -429,6 +429,17 @@ static struct musb_hdrc_config musb_config_h3 = {
  	.ram_bits	= SUNXI_MUSB_RAM_BITS,
  };
 
+#ifdef CONFIG_DM_USB_GADGET
+int dm_usb_gadget_handle_interrupts(struct udevice *dev)
+{
+	int n = 0;

Is this used for anything?

+CC Mattijs