
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")
Signed-off-by: Aren Moynihan aren@peacevolution.org --- 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(+)
diff --git a/drivers/usb/musb-new/sunxi.c b/drivers/usb/musb-new/sunxi.c index 91f082fe05e..9b06f49ce47 100644 --- a/drivers/usb/musb-new/sunxi.c +++ b/drivers/usb/musb-new/sunxi.c @@ -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);