Skip to contentSkip to conversation

usb: dwc3: sync code with Linux v6.16

PATCH In review Anders Roxell 5 participants 150 messages Jul 16 – Aug 13 2 messages not in the archive Page 3 of 3

Subsystems (9)
lore
Share & tools
lore
#139 lore raw

PATCH v5 70/75 usb: gadget: ci_udc: drop code we do not use

In reply to Anders Roxell

After the resync a big part of ci_udc.c is not used in u-boot. Remove it.

---
 drivers/usb/gadget/ci_udc.c | 470 ------------------------------------
 1 file changed, 470 deletions(-)
drivers/usb/gadget/ci_udc.c +0 -470
index 4729570c5257..95efa4ae1644 100644
@@ -84,62 +84,15 @@ static struct usb_endpoint_descriptor ep0_desc = {
 };
 
 static int ci_pullup(struct usb_gadget *gadget, int is_on);
-static int ci_ep_enable(struct usb_ep *ep,
-		const struct usb_endpoint_descriptor *desc);
-static int ci_ep_disable(struct usb_ep *ep);
-static int ci_ep_queue(struct usb_ep *ep,
-		struct usb_request *req, gfp_t gfp_flags);
-static int ci_ep_dequeue(struct usb_ep *ep, struct usb_request *req);
-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);
 
 static const struct usb_gadget_ops ci_udc_ops = {
 	.pullup = ci_pullup,
 };
 
-static const struct usb_ep_ops ci_ep_ops = {
-	.enable         = ci_ep_enable,
-	.disable        = ci_ep_disable,
-	.queue          = ci_ep_queue,
-	.dequeue	= ci_ep_dequeue,
-	.alloc_request  = ci_ep_alloc_request,
-	.free_request   = ci_ep_free_request,
-};
-
 __weak void ci_init_after_reset(struct ehci_ctrl *ctrl)
 {
 }
 
-/* Init values for USB endpoints. */
-static const struct usb_ep ci_ep_init[5] = {
-	[0] = {	/* EP 0 */
-		.maxpacket	= 64,
-		.name		= "ep0",
-		.ops		= &ci_ep_ops,
-	},
-	[1] = {
-		.maxpacket	= 512,
-		.name		= "ep1in-bulk",
-		.ops		= &ci_ep_ops,
-	},
-	[2] = {
-		.maxpacket	= 512,
-		.name		= "ep2out-bulk",
-		.ops		= &ci_ep_ops,
-	},
-	[3] = {
-		.maxpacket	= 512,
-		.name		= "ep3in-int",
-		.ops		= &ci_ep_ops,
-	},
-	[4] = {
-		.maxpacket	= 512,
-		.name		= "ep-",
-		.ops		= &ci_ep_ops,
-	},
-};
-
 static struct ci_drv controller = {
 	.gadget	= {
 		.name	= "ci_udc",
@@ -263,76 +216,6 @@ static void ci_invalidate_td(struct ept_queue_item *td)
 	invalidate_dcache_range(start, end);
 }
 
-static struct usb_request *
-ci_ep_alloc_request(struct usb_ep *ep, unsigned int gfp_flags)
-{
-	struct ci_ep *ci_ep = container_of(ep, struct ci_ep, ep);
-	int num = -1;
-	struct ci_req *ci_req;
-
-	if (ci_ep->desc)
-		num = ci_ep->desc->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK;
-
-	if (num == 0 && controller.ep0_req) {
-		DBG("%s: already got controller.ep0_req = %p\n", __func__, controller.ep0_req);
-		return &controller.ep0_req->req;
-	}
-
-	ci_req = calloc(1, sizeof(*ci_req));
-	if (!ci_req)
-		return NULL;
-
-	INIT_LIST_HEAD(&ci_req->queue);
-
-	if (num == 0)
-		controller.ep0_req = ci_req;
-
-	return &ci_req->req;
-}
-
-static void ci_ep_free_request(struct usb_ep *ep, struct usb_request *req)
-{
-	struct ci_ep *ci_ep = container_of(ep, struct ci_ep, ep);
-	struct ci_req *ci_req = container_of(req, struct ci_req, req);
-	int num = -1;
-
-	if (ci_ep->desc)
-		num = ci_ep->desc->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK;
-	else
-		DBG("%s: no endpoint %p descriptor\n", __func__, ci_ep);
-
-	if (num == 0) {
-		if (!controller.ep0_req)
-			return;
-		controller.ep0_req = 0;
-	}
-
-	if (ci_req->b_buf)
-		free(ci_req->b_buf);
-	free(ci_req);
-}
-
-static void request_complete(struct usb_ep *ep, struct ci_req *req, int status)
-{
-	if (req->req.status == -EINPROGRESS)
-		req->req.status = status;
-
-	DBG("%s: req %p complete: status %d, actual %u\n",
-	    ep->name, req, req->req.status, req->req.actual);
-
-	req->req.complete(ep, &req->req);
-}
-
-static void request_complete_list(struct usb_ep *ep, struct list_head *list, int status)
-{
-	struct ci_req *req, *tmp_req;
-
-	list_for_each_entry_safe(req, tmp_req, list, queue) {
-		list_del_init(&req->queue);
-		request_complete(ep, req, status);
-	}
-}
-
 static void ep_enable(int num, int in, int maxpacket)
 {
 	struct ci_udc *udc = (struct ci_udc *)controller.ctrl->hcor;
@@ -353,145 +236,6 @@ static void ep_enable(int num, int in, int maxpacket)
 	writel(n, &udc->epctrl[num]);
 }
 
-static int ci_ep_enable(struct usb_ep *ep,
-		const struct usb_endpoint_descriptor *desc)
-{
-	struct ci_ep *ci_ep = container_of(ep, struct ci_ep, ep);
-	int num, in;
-	num = desc->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK;
-	in = (desc->bEndpointAddress & USB_DIR_IN) != 0;
-
-	if (ci_ep->desc) {
-		DBG("%s: endpoint num %d in %d already enabled\n", __func__, num, in);
-		return -EBUSY;
-	}
-
-	ci_ep->desc = desc;
-	ep->desc = desc;
-
-	if (num) {
-		int max = get_unaligned_le16(&desc->wMaxPacketSize);
-
-		if ((max > 64) && (controller.gadget.speed == USB_SPEED_FULL))
-			max = 64;
-		if (ep->maxpacket != max) {
-			DBG("%s: from %d to %d\n", __func__,
-			    ep->maxpacket, max);
-			ep->maxpacket = max;
-		}
-	}
-	ep_enable(num, in, ep->maxpacket);
-	DBG("%s: num=%d maxpacket=%d\n", __func__, num, ep->maxpacket);
-	return 0;
-}
-
-static int ep_disable(int num, int in)
-{
-	struct ci_udc *udc = (struct ci_udc *)controller.ctrl->hcor;
-	unsigned int ep_bit, enable_bit;
-	int err;
-
-	if (in) {
-		ep_bit = EPT_TX(num);
-		enable_bit = CTRL_TXE;
-	} else {
-		ep_bit = EPT_RX(num);
-		enable_bit = CTRL_RXE;
-	}
-
-	/* clear primed buffers */
-	do {
-		writel(ep_bit, &udc->epflush);
-		err = wait_for_bit_le32(&udc->epflush, ep_bit, false, 1000, false);
-		if (err)
-			return err;
-	} while (readl(&udc->epstat) & ep_bit);
-
-	/* clear enable bit */
-	clrbits_le32(&udc->epctrl[num], enable_bit);
-
-	return 0;
-}
-
-static int ci_ep_disable(struct usb_ep *ep)
-{
-	struct ci_ep *ci_ep = container_of(ep, struct ci_ep, ep);
-	LIST_HEAD(req_list);
-	int num, in, err;
-
-	if (!ci_ep->desc) {
-		DBG("%s: attempt to disable a not enabled yet endpoint\n", __func__);
-		err = -EBUSY;
-		goto nodesc;
-	}
-
-	num = ci_ep->desc->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK;
-	in = (ci_ep->desc->bEndpointAddress & USB_DIR_IN) != 0;
-
-	list_splice_init(&ci_ep->queue, &req_list);
-	request_complete_list(ep, &req_list, -ESHUTDOWN);
-
-	err = ep_disable(num, in);
-	if (err)
-		return err;
-
-	ci_ep->desc = NULL;
-	err = 0;
-
-nodesc:
-	ep->desc = NULL;
-	ci_ep->req_primed = false;
-	return err;
-}
-
-static int ci_bounce(struct ci_req *ci_req, int in)
-{
-	struct usb_request *req = &ci_req->req;
-	unsigned long addr = (unsigned long)req->buf;
-	unsigned long hwaddr;
-	uint32_t aligned_used_len;
-
-	/* Input buffer address is not aligned. */
-	if (addr & (ARCH_DMA_MINALIGN - 1))
-		goto align;
-
-	/* Input buffer length is not aligned. */
-	if (req->length & (ARCH_DMA_MINALIGN - 1))
-		goto align;
-
-	/* The buffer is well aligned, only flush cache. */
-	ci_req->hw_len = req->length;
-	ci_req->hw_buf = req->buf;
-	goto flush;
-
-align:
-	if (ci_req->b_buf && req->length > ci_req->b_len) {
-		free(ci_req->b_buf);
-		ci_req->b_buf = 0;
-	}
-	if (!ci_req->b_buf) {
-		ci_req->b_len = roundup(req->length, ARCH_DMA_MINALIGN);
-		ci_req->b_buf = memalign(ARCH_DMA_MINALIGN, ci_req->b_len);
-		if (!ci_req->b_buf)
-			return -ENOMEM;
-	}
-	ci_req->hw_len = ci_req->b_len;
-	ci_req->hw_buf = ci_req->b_buf;
-
-	if (in)
-		memcpy(ci_req->hw_buf, req->buf, req->length);
-
-flush:
-	hwaddr = (unsigned long)ci_req->hw_buf;
-	if (!hwaddr)
-		return 0;
-
-	aligned_used_len = roundup(req->length, ARCH_DMA_MINALIGN);
-	flush_dcache_range(hwaddr, hwaddr + aligned_used_len);
-
-	return 0;
-}
-
 static void ci_debounce(struct ci_req *ci_req, int in)
 {
 	struct usb_request *req = &ci_req->req;
@@ -618,77 +362,6 @@ static void ci_ep_submit_next_request(struct ci_ep *ci_ep)
 	writel(bit, &udc->epprime);
 }
 
-static int ci_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req)
-{
-	struct ci_ep *ci_ep = container_of(_ep, struct ci_ep, ep);
-	struct ci_req *ci_req;
-
-	list_for_each_entry(ci_req, &ci_ep->queue, queue) {
-		if (&ci_req->req == _req)
-			break;
-	}
-
-	if (&ci_req->req != _req) {
-		DBG("%s: ci_req not found in the queue\n", __func__);
-		return -EINVAL;
-	}
-
-	list_del_init(&ci_req->queue);
-
-	if (ci_req->req.status == -EINPROGRESS) {
-		ci_req->req.status = -ECONNRESET;
-		if (ci_req->req.complete)
-			ci_req->req.complete(_ep, _req);
-	}
-
-	return 0;
-}
-
-static int ci_ep_queue(struct usb_ep *ep,
-		struct usb_request *req, gfp_t gfp_flags)
-{
-	struct ci_ep *ci_ep = container_of(ep, struct ci_ep, ep);
-	struct ci_req *ci_req = container_of(req, struct ci_req, req);
-	int in, ret;
-	int __maybe_unused num;
-
-	if (!ci_ep->desc) {
-		DBG("%s: ci_ep->desc == NULL, nothing to do!\n", __func__);
-		return -EINVAL;
-	}
-
-	num = ci_ep->desc->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK;
-	in = (ci_ep->desc->bEndpointAddress & USB_DIR_IN) != 0;
-
-	if (!num && ci_ep->req_primed) {
-		/*
-		 * The flipping of ep0 between IN and OUT relies on
-		 * ci_ep_queue consuming the current IN/OUT setting
-		 * immediately. If this is deferred to a later point when the
-		 * req is pulled out of ci_req->queue, then the IN/OUT setting
-		 * may have been changed since the req was queued, and state
-		 * will get out of sync. This condition doesn't occur today,
-		 * but could if bugs were introduced later, and this error
-		 * check will save a lot of debugging time.
-		 */
-		printf("%s: ep0 transaction already in progress\n", __func__);
-		return -EPROTO;
-	}
-
-	ret = ci_bounce(ci_req, in);
-	if (ret)
-		return ret;
-
-	DBG("ept%d %s pre-queue req %p, buffer %p\n",
-	    num, in ? "in" : "out", ci_req, ci_req->hw_buf);
-	list_add_tail(&ci_req->queue, &ci_ep->queue);
-
-	if (!ci_ep->req_primed)
-		ci_ep_submit_next_request(ci_ep);
-
-	return 0;
-}
-
 static void flip_ep0_direction(void)
 {
 	if (ep0_desc.bEndpointAddress == USB_DIR_IN) {
@@ -1034,149 +707,6 @@ static int ci_pullup(struct usb_gadget *gadget, int is_on)
 	return 0;
 }
 
-static int ci_udc_probe(void)
-{
-	struct ept_queue_head *head;
-	int i;
-
-	const int num = 2 * NUM_ENDPOINTS;
-
-	const int eplist_min_align = 4096;
-	const int eplist_align = roundup(eplist_min_align, ARCH_DMA_MINALIGN);
-	const int eplist_raw_sz = num * sizeof(struct ept_queue_head);
-	const int eplist_sz = roundup(eplist_raw_sz, ARCH_DMA_MINALIGN);
-
-	/* The QH list must be aligned to 4096 bytes. */
-	controller.epts = memalign(eplist_align, eplist_sz);
-	if (!controller.epts)
-		return -ENOMEM;
-	memset(controller.epts, 0, eplist_sz);
-
-	controller.items_mem = memalign(ILIST_ALIGN, ILIST_SZ);
-	if (!controller.items_mem) {
-		free(controller.epts);
-		return -ENOMEM;
-	}
-	memset(controller.items_mem, 0, ILIST_SZ);
-
-	for (i = 0; i < 2 * NUM_ENDPOINTS; i++) {
-		/*
-		 * Configure QH for each endpoint. The structure of the QH list
-		 * is such that each two subsequent fields, N and N+1 where N is
-		 * even, in the QH list represent QH for one endpoint. The Nth
-		 * entry represents OUT configuration and the N+1th entry does
-		 * represent IN configuration of the endpoint.
-		 */
-		head = controller.epts + i;
-		if (i < 2)
-			head->config = CFG_MAX_PKT(EP0_MAX_PACKET_SIZE)
-				| CFG_ZLT | CFG_IOS;
-		else
-			head->config = CFG_MAX_PKT(EP_MAX_PACKET_SIZE)
-				| CFG_ZLT;
-		head->next = TERMINATE;
-		head->info = 0;
-
-		if (i & 1) {
-			ci_flush_qh(i / 2);
-			ci_flush_qtd(i / 2);
-		}
-	}
-
-	INIT_LIST_HEAD(&controller.gadget.ep_list);
-
-	/* Init EP 0 */
-	memcpy(&controller.ep[0].ep, &ci_ep_init[0], sizeof(*ci_ep_init));
-	controller.ep[0].desc = &ep0_desc;
-	INIT_LIST_HEAD(&controller.ep[0].queue);
-	controller.ep[0].req_primed = false;
-	controller.gadget.ep0 = &controller.ep[0].ep;
-	INIT_LIST_HEAD(&controller.gadget.ep0->ep_list);
-
-	/* Init EP 1..3 */
-	for (i = 1; i < 4; i++) {
-		memcpy(&controller.ep[i].ep, &ci_ep_init[i],
-		       sizeof(*ci_ep_init));
-		INIT_LIST_HEAD(&controller.ep[i].queue);
-		controller.ep[i].req_primed = false;
-		list_add_tail(&controller.ep[i].ep.ep_list,
-			      &controller.gadget.ep_list);
-	}
-
-	/* Init EP 4..n */
-	for (i = 4; i < NUM_ENDPOINTS; i++) {
-		memcpy(&controller.ep[i].ep, &ci_ep_init[4],
-		       sizeof(*ci_ep_init));
-		INIT_LIST_HEAD(&controller.ep[i].queue);
-		controller.ep[i].req_primed = false;
-		list_add_tail(&controller.ep[i].ep.ep_list,
-			      &controller.gadget.ep_list);
-	}
-
-	ci_ep_alloc_request(&controller.ep[0].ep, 0);
-	if (!controller.ep0_req) {
-		free(controller.items_mem);
-		free(controller.epts);
-		return -ENOMEM;
-	}
-
-	return 0;
-}
-
-int usb_gadget_register_driver(struct usb_gadget_driver *driver)
-{
-	int ret;
-
-	if (!driver)
-		return -EINVAL;
-	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);
-		return ret;
-	}
-
-	ret = driver->bind(&controller.gadget);
-	if (ret) {
-		DBG("driver->bind() returned %d\n", ret);
-		return ret;
-	}
-	controller.driver = driver;
-
-	return 0;
-}
-
-int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
-{
-	udc_disconnect();
-
-	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
-
-	return 0;
-}
-
 bool dfu_usb_get_reset(void)
 {
 	struct ci_udc *udc = (struct ci_udc *)controller.ctrl->hcor;
Signature · 1 line
2.53.0
#140 lore raw

PATCH v5 71/75 usb: gadget: dwc2_udc_otg: fix up after the resync

In reply to Anders Roxell

Adapt dwc2_udc_otg to the gadget API changes from the resync.

---
 drivers/usb/gadget/dwc2_udc_otg.c | 174 +++++++++---------------------
 1 file changed, 50 insertions(+), 124 deletions(-)
drivers/usb/gadget/dwc2_udc_otg.c +50 -124
index 570fed347c9e..b067745cb2e3 100644
@@ -113,9 +113,6 @@ static void dwc2_handle_ep0(struct dwc2_udc *dev);
 static int dwc2_ep0_write(struct dwc2_udc *dev);
 static int write_fifo_ep0(struct dwc2_ep *ep, struct dwc2_request *req);
 static void done(struct dwc2_ep *ep, struct dwc2_request *req, int status);
-static void stop_activity(struct dwc2_udc *dev,
-			  struct usb_gadget_driver *driver);
-static int udc_enable(struct dwc2_udc *dev);
 static void udc_set_address(struct dwc2_udc *dev, unsigned char address);
 static void reconfig_usbd(struct dwc2_udc *dev);
 static void set_max_pktsize(struct dwc2_udc *dev, enum usb_device_speed speed);
@@ -170,22 +167,6 @@ __weak void otg_phy_off(struct dwc2_udc *dev) {}
 
 #include "dwc2_udc_otg_xfer_dma.c"
 
-/*
- *	udc_disable - disable USB device controller
- */
-static void udc_disable(struct dwc2_udc *dev)
-{
-	debug_cond(DEBUG_SETUP != 0, "%s: %p\n", __func__, dev);
-
-	udc_set_address(dev, 0);
-
-	dev->ep0state = WAIT_FOR_SETUP;
-	dev->gadget.speed = USB_SPEED_UNKNOWN;
-	dev->usb_address = 0;
-
-	otg_phy_off(dev);
-}
-
 /*
  *	udc_reinit - initialize software state
  */
@@ -219,6 +200,18 @@ static void udc_reinit(struct dwc2_udc *dev)
 #define BYTES2MAXP(x)	(x / 8)
 #define MAXP2BYTES(x)	(x * 8)
 
+static int dwc2_gadget_pullup(struct usb_gadget *g, int is_on)
+{
+	clrsetbits_le32(&reg->device_regs.dctl, DCTL_SFTDISCON,
+			is_on ? 0 : DCTL_SFTDISCON);
+
+	return 0;
+}
+
+#if !CONFIG_IS_ENABLED(DM_USB_GADGET)
+
+#else /* !CONFIG_IS_ENABLED(DM_USB_GADGET) */
+
 /* until it's enabled, this UDC should be completely invisible
  * to any USB host.
  */
@@ -238,112 +231,73 @@ static int udc_enable(struct dwc2_udc *dev)
 	return 0;
 }
 
-static int dwc2_gadget_pullup(struct usb_gadget *g, int is_on)
-{
-	clrsetbits_le32(&reg->device_regs.dctl, DCTL_SFTDISCON,
-			is_on ? 0 : DCTL_SFTDISCON);
-
-	return 0;
-}
-
-#if !CONFIG_IS_ENABLED(DM_USB_GADGET)
-/*
-  Register entry point for the peripheral controller driver.
-*/
-int usb_gadget_register_driver(struct usb_gadget_driver *driver)
+static int dwc2_gadget_start(struct usb_gadget *g,
+			     struct usb_gadget_driver *driver)
 {
 	struct dwc2_udc *dev = the_controller;
-	int retval = 0;
-	unsigned long flags = 0;
 
 	debug_cond(DEBUG_SETUP != 0, "%s: %s\n", __func__, "no name");
 
-	if (!driver || driver->speed < USB_SPEED_FULL
-	    || !driver->bind || !driver->disconnect || !driver->setup)
+	if (!driver || driver->speed < USB_SPEED_FULL ||
+	    !driver->bind || !driver->disconnect || !driver->setup)
 		return -EINVAL;
+
 	if (!dev)
 		return -ENODEV;
+
 	if (dev->driver)
 		return -EBUSY;
 
-	spin_lock_irqsave(&dev->lock, flags);
 	/* first hook up the driver ... */
 	dev->driver = driver;
-	spin_unlock_irqrestore(&dev->lock, flags);
-
-	if (retval) { /* TODO */
-		printf("target device_add failed, error %d\n", retval);
-		return retval;
-	}
-
-	retval = driver->bind(&dev->gadget);
-	if (retval) {
-		debug_cond(DEBUG_SETUP != 0,
-			   "%s: bind to driver --> error %d\n",
-			    dev->gadget.name, retval);
-		dev->driver = 0;
-		return retval;
-	}
-
-	enable_irq(IRQ_OTG);
 
 	debug_cond(DEBUG_SETUP != 0,
 		   "Registered gadget driver %s\n", dev->gadget.name);
-	udc_enable(dev);
-
-	return 0;
+	return udc_enable(dev);
 }
 
-/*
- * Unregister entry point for the peripheral controller driver.
- */
-int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
+static void stop_activity(struct dwc2_udc *dev,
+			  struct usb_gadget_driver *driver)
 {
-	struct dwc2_udc *dev = the_controller;
-	unsigned long flags = 0;
-
-	if (!dev)
-		return -ENODEV;
-	if (!driver || driver != dev->driver)
-		return -EINVAL;
+	int i;
 
-	spin_lock_irqsave(&dev->lock, flags);
-	dev->driver = 0;
-	stop_activity(dev, driver);
-	spin_unlock_irqrestore(&dev->lock, flags);
+	/* don't disconnect drivers more than once */
+	if (dev->gadget.speed == USB_SPEED_UNKNOWN)
+		driver = 0;
+	dev->gadget.speed = USB_SPEED_UNKNOWN;
 
-	driver->unbind(&dev->gadget);
+	/* prevent new request submissions, kill any outstanding requests  */
+	for (i = 0; i < DWC2_MAX_ENDPOINTS; i++) {
+		struct dwc2_ep *ep = &dev->ep[i];
+		ep->stopped = 1;
+		nuke(ep, -ESHUTDOWN);
+	}
 
-	disable_irq(IRQ_OTG);
+	/* report disconnect; the driver is already quiesced */
+	if (driver) {
+		spin_unlock(&dev->lock);
+		driver->disconnect(&dev->gadget);
+		spin_lock(&dev->lock);
+	}
 
-	udc_disable(dev);
-	return 0;
+	/* re-init driver-visible data structures */
+	udc_reinit(dev);
 }
-#else /* !CONFIG_IS_ENABLED(DM_USB_GADGET) */
 
-static int dwc2_gadget_start(struct usb_gadget *g,
-			     struct usb_gadget_driver *driver)
+/*
+ *	udc_disable - disable USB device controller
+ */
+static void udc_disable(struct dwc2_udc *dev)
 {
-	struct dwc2_udc *dev = the_controller;
-
-	debug_cond(DEBUG_SETUP != 0, "%s: %s\n", __func__, "no name");
-
-	if (!driver || driver->speed < USB_SPEED_FULL ||
-	    !driver->bind || !driver->disconnect || !driver->setup)
-		return -EINVAL;
-
-	if (!dev)
-		return -ENODEV;
+	debug_cond(DEBUG_SETUP != 0, "%s: %p\n", __func__, dev);
 
-	if (dev->driver)
-		return -EBUSY;
+	udc_set_address(dev, 0);
 
-	/* first hook up the driver ... */
-	dev->driver = driver;
+	dev->ep0state = WAIT_FOR_SETUP;
+	dev->gadget.speed = USB_SPEED_UNKNOWN;
+	dev->usb_address = 0;
 
-	debug_cond(DEBUG_SETUP != 0,
-		   "Registered gadget driver %s\n", dev->gadget.name);
-	return udc_enable(dev);
+	otg_phy_off(dev);
 }
 
 static int dwc2_gadget_stop(struct usb_gadget *g)
@@ -433,34 +387,6 @@ static void nuke(struct dwc2_ep *ep, int status)
 	}
 }
 
-static void stop_activity(struct dwc2_udc *dev,
-			  struct usb_gadget_driver *driver)
-{
-	int i;
-
-	/* don't disconnect drivers more than once */
-	if (dev->gadget.speed == USB_SPEED_UNKNOWN)
-		driver = 0;
-	dev->gadget.speed = USB_SPEED_UNKNOWN;
-
-	/* prevent new request submissions, kill any outstanding requests  */
-	for (i = 0; i < DWC2_MAX_ENDPOINTS; i++) {
-		struct dwc2_ep *ep = &dev->ep[i];
-		ep->stopped = 1;
-		nuke(ep, -ESHUTDOWN);
-	}
-
-	/* report disconnect; the driver is already quiesced */
-	if (driver) {
-		spin_unlock(&dev->lock);
-		driver->disconnect(&dev->gadget);
-		spin_lock(&dev->lock);
-	}
-
-	/* re-init driver-visible data structures */
-	udc_reinit(dev);
-}
-
 static void reconfig_usbd(struct dwc2_udc *dev)
 {
 	/* 2. Soft-reset OTG Core and then unreset again. */
Signature · 1 line
2.53.0
#141 lore raw

PATCH v5 72/75 usb: gadget: fix up the function drivers after the resync

In reply to Anders Roxell

Adapt the gadget function drivers (acm, fastboot, mass_storage, rockusb, sdp, thor, ether and composite) to the new gadget API.

---
 drivers/usb/gadget/composite.c      |  2 +-
 drivers/usb/gadget/ether.c          | 21 ++++++++++++++-------
 drivers/usb/gadget/f_acm.c          | 20 +++++++++++---------
 drivers/usb/gadget/f_fastboot.c     | 10 +++++-----
 drivers/usb/gadget/f_mass_storage.c |  5 ++++-
 drivers/usb/gadget/f_rockusb.c      | 11 ++++++-----
 drivers/usb/gadget/f_sdp.c          | 12 ++++++++----
 drivers/usb/gadget/f_thor.c         | 19 +++++++++----------
 8 files changed, 58 insertions(+), 42 deletions(-)
drivers/usb/gadget/composite.c +1 -1
index 04b85419931e..060788419553 100644
@@ -833,7 +833,7 @@ static int bos_desc(struct usb_composite_dev *cdev)
 
 		/* Get Controller configuration */
 		if (cdev->gadget->ops->get_config_params) {
-			cdev->gadget->ops->get_config_params(
+			cdev->gadget->ops->get_config_params(cdev->gadget,
 				&dcd_config_params);
 		} else {
 			dcd_config_params.bU1devExitLat =
drivers/usb/gadget/ether.c +14 -7
index 7973927e8a7f..13a20441419d 100644
@@ -925,8 +925,9 @@ set_ether_config(struct eth_dev *dev, gfp_t gfp_flags)
 		dev->status = ep_desc(gadget, &hs_status_desc,
 						&fs_status_desc);
 		dev->status_ep->driver_data = dev;
+		dev->status_ep->desc = dev->status;
 
-		result = usb_ep_enable(dev->status_ep, dev->status);
+		result = usb_ep_enable(dev->status_ep);
 		if (result != 0) {
 			debug("enable %s --> %d\n",
 				dev->status_ep->name, result);
@@ -951,14 +952,16 @@ set_ether_config(struct eth_dev *dev, gfp_t gfp_flags)
 	 * from REMOTE_NDIS_HALT_MSG, reset from REMOTE_NDIS_RESET_MSG.
 	 */
 	if (!cdc_active(dev)) {
-		result = usb_ep_enable(dev->in_ep, dev->in);
+		dev->in_ep->desc = dev->in;
+		result = usb_ep_enable(dev->in_ep);
 		if (result != 0) {
 			debug("enable %s --> %d\n",
 				dev->in_ep->name, result);
 			goto done;
 		}
 
-		result = usb_ep_enable(dev->out_ep, dev->out);
+		dev->out_ep->desc = dev->out;
+		result = usb_ep_enable(dev->out_ep);
 		if (result != 0) {
 			debug("enable %s --> %d\n",
 				dev->out_ep->name, result);
@@ -1156,7 +1159,8 @@ static void issue_start_status(struct eth_dev *dev)
 	 * FIXME iff req->context != null just dequeue it
 	 */
 	usb_ep_disable(dev->status_ep);
-	usb_ep_enable(dev->status_ep, dev->status);
+	dev->status_ep->desc = dev->status;
+	usb_ep_enable(dev->status_ep);
 
 	/*
 	 * 3.8.1 says to issue first NETWORK_CONNECTION, then
@@ -1314,7 +1318,8 @@ eth_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
 				break;
 			if (dev->status) {
 				usb_ep_disable(dev->status_ep);
-				usb_ep_enable(dev->status_ep, dev->status);
+				dev->status_ep->desc = dev->status;
+				usb_ep_enable(dev->status_ep);
 			}
 
 			value = 0;
@@ -1333,8 +1338,10 @@ eth_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
 			if (wValue == 1) {
 				if (!cdc_active(dev))
 					break;
-				usb_ep_enable(dev->in_ep, dev->in);
-				usb_ep_enable(dev->out_ep, dev->out);
+				dev->in_ep->desc = dev->in;
+				usb_ep_enable(dev->in_ep);
+				dev->out_ep->desc = dev->out;
+				usb_ep_enable(dev->out_ep);
 				dev->cdc_filter = DEFAULT_FILTER;
 				if (dev->status)
 					issue_start_status(dev);
drivers/usb/gadget/f_acm.c +11 -9
index b6c11d97a62d..5f5400bab7ec 100644
@@ -325,20 +325,20 @@ static struct usb_request *acm_start_ep(struct usb_ep *ep, void *complete_cb,
 
 static int acm_start_data(struct f_acm *f_acm, struct usb_gadget *gadget)
 {
-	const struct usb_endpoint_descriptor *d;
 	int ret;
 
 	/* EP IN */
-	d = ep_desc(gadget, &acm_hs_in_desc, &acm_fs_in_desc);
-	ret = usb_ep_enable(f_acm->ep_in, d);
+	f_acm->ep_in->desc = ep_desc(gadget, &acm_hs_in_desc, &acm_fs_in_desc);
+	ret = usb_ep_enable(f_acm->ep_in);
 	if (ret)
 		return ret;
 
 	f_acm->req_in = acm_start_ep(f_acm->ep_in, acm_tx_complete, f_acm);
 
 	/* EP OUT */
-	d = ep_desc(gadget, &acm_hs_out_desc, &acm_fs_out_desc);
-	ret = usb_ep_enable(f_acm->ep_out, d);
+	f_acm->ep_out->desc = ep_desc(gadget, &acm_hs_out_desc,
+				      &acm_fs_out_desc);
+	ret = usb_ep_enable(f_acm->ep_out);
 	if (ret)
 		return ret;
 
@@ -354,12 +354,11 @@ static int acm_start_data(struct f_acm *f_acm, struct usb_gadget *gadget)
 
 static int acm_start_ctrl(struct f_acm *f_acm, struct usb_gadget *gadget)
 {
-	const struct usb_endpoint_descriptor *d;
-
 	usb_ep_disable(f_acm->ep_notify);
 
-	d = ep_desc(gadget, &acm_hs_notify_desc, &acm_fs_notify_desc);
-	usb_ep_enable(f_acm->ep_notify, d);
+	f_acm->ep_notify->desc = ep_desc(gadget, &acm_hs_notify_desc,
+					 &acm_fs_notify_desc);
+	usb_ep_enable(f_acm->ep_notify);
 
 	acm_start_ep(f_acm->ep_notify, acm_notify_complete, f_acm);
 
@@ -454,6 +453,9 @@ static void acm_disable(struct usb_function *f)
 	usb_ep_disable(f_acm->ep_out);
 	usb_ep_disable(f_acm->ep_in);
 	usb_ep_disable(f_acm->ep_notify);
+	f_acm->ep_out->desc = NULL;
+	f_acm->ep_in->desc = NULL;
+	f_acm->ep_notify->desc = NULL;
 
 	if (f_acm->req_out) {
 		free(f_acm->req_out->buf);
drivers/usb/gadget/f_fastboot.c +5 -5
index 8df0e3f331d1..e1eed5fa4cb4 100644
@@ -320,13 +320,13 @@ static int fastboot_set_alt(struct usb_function *f,
 	struct usb_composite_dev *cdev = f->config->cdev;
 	struct usb_gadget *gadget = cdev->gadget;
 	struct f_fastboot *f_fb = func_to_fastboot(f);
-	const struct usb_endpoint_descriptor *d;
 
 	debug("%s: func: %s intf: %d alt: %d\n",
 	      __func__, f->name, interface, alt);
 
-	d = fb_ep_desc(gadget, &fs_ep_out, &hs_ep_out, &ss_ep_out);
-	ret = usb_ep_enable(f_fb->out_ep, d);
+	f_fb->out_ep->desc = fb_ep_desc(gadget, &fs_ep_out, &hs_ep_out,
+					&ss_ep_out);
+	ret = usb_ep_enable(f_fb->out_ep);
 	if (ret) {
 		puts("failed to enable out ep\n");
 		return ret;
@@ -340,8 +340,8 @@ static int fastboot_set_alt(struct usb_function *f,
 	}
 	f_fb->out_req->complete = rx_handler_command;
 
-	d = fb_ep_desc(gadget, &fs_ep_in, &hs_ep_in, &ss_ep_in);
-	ret = usb_ep_enable(f_fb->in_ep, d);
+	f_fb->in_ep->desc = fb_ep_desc(gadget, &fs_ep_in, &hs_ep_in, &ss_ep_in);
+	ret = usb_ep_enable(f_fb->in_ep);
 	if (ret) {
 		puts("failed to enable in ep\n");
 		goto err;
drivers/usb/gadget/f_mass_storage.c +4 -1
index 87ed25e8bb3a..0eb4af993717 100644
@@ -2158,7 +2158,8 @@ static int enable_endpoint(struct fsg_common *common, struct usb_ep *ep,
 	int	rc;
 
 	ep->driver_data = common;
-	rc = usb_ep_enable(ep, d);
+	ep->desc = d;
+	rc = usb_ep_enable(ep);
 	if (rc)
 		ERROR(common, "can't enable %s, result %d\n", ep->name, rc);
 	return rc;
@@ -2205,10 +2206,12 @@ reset:
 		/* Disable the endpoints */
 		if (fsg->bulk_in_enabled) {
 			usb_ep_disable(fsg->bulk_in);
+			fsg->bulk_in->desc = NULL;
 			fsg->bulk_in_enabled = 0;
 		}
 		if (fsg->bulk_out_enabled) {
 			usb_ep_disable(fsg->bulk_out);
+			fsg->bulk_out->desc = NULL;
 			fsg->bulk_out_enabled = 0;
 		}
 
drivers/usb/gadget/f_rockusb.c +6 -5
index d679cdae97c8..37957b202f8c 100644
@@ -202,6 +202,8 @@ static void rockusb_disable(struct usb_function *f)
 
 	usb_ep_disable(f_rkusb->out_ep);
 	usb_ep_disable(f_rkusb->in_ep);
+	f_rkusb->out_ep->desc = NULL;
+	f_rkusb->in_ep->desc = NULL;
 
 	if (f_rkusb->out_req) {
 		free(f_rkusb->out_req->buf);
@@ -246,13 +248,12 @@ static int rockusb_set_alt(struct usb_function *f, unsigned int interface,
 	struct usb_composite_dev *cdev = f->config->cdev;
 	struct usb_gadget *gadget = cdev->gadget;
 	struct f_rockusb *f_rkusb = func_to_rockusb(f);
-	const struct usb_endpoint_descriptor *d;
 
 	debug("%s: func: %s intf: %d alt: %d\n",
 	      __func__, f->name, interface, alt);
 
-	d = rkusb_ep_desc(gadget, &fs_ep_out, &hs_ep_out);
-	ret = usb_ep_enable(f_rkusb->out_ep, d);
+	f_rkusb->out_ep->desc = rkusb_ep_desc(gadget, &fs_ep_out, &hs_ep_out);
+	ret = usb_ep_enable(f_rkusb->out_ep);
 	if (ret) {
 		printf("failed to enable out ep\n");
 		return ret;
@@ -266,8 +267,8 @@ static int rockusb_set_alt(struct usb_function *f, unsigned int interface,
 	}
 	f_rkusb->out_req->complete = rx_handler_command;
 
-	d = rkusb_ep_desc(gadget, &fs_ep_in, &hs_ep_in);
-	ret = usb_ep_enable(f_rkusb->in_ep, d);
+	f_rkusb->in_ep->desc = rkusb_ep_desc(gadget, &fs_ep_in, &hs_ep_in);
+	ret = usb_ep_enable(f_rkusb->in_ep);
 	if (ret) {
 		printf("failed to enable in ep\n");
 		goto err;
drivers/usb/gadget/f_sdp.c +8 -4
index cd2c282247ac..0bb386053258 100644
@@ -625,12 +625,14 @@ static int sdp_set_alt(struct usb_function *f, unsigned intf, unsigned alt)
 	debug("%s: intf: %d alt: %d\n", __func__, intf, alt);
 
 	if (gadget_is_dualspeed(gadget) && gadget->speed == USB_SPEED_HIGH) {
-		result = usb_ep_enable(sdp->in_ep, &in_hs_desc);
-		result |= usb_ep_enable(sdp->out_ep, &out_hs_desc);
+		sdp->in_ep->desc = &in_hs_desc;
+		sdp->out_ep->desc = &out_hs_desc;
 	} else {
-		result = usb_ep_enable(sdp->in_ep, &in_desc);
-		result |= usb_ep_enable(sdp->out_ep, &out_desc);
+		sdp->in_ep->desc = &in_hs_desc;
+		sdp->out_ep->desc = &out_hs_desc;
 	}
+	result = usb_ep_enable(sdp->in_ep);
+	result |= usb_ep_enable(sdp->out_ep);
 	if (result)
 		return result;
 
@@ -662,6 +664,8 @@ static void sdp_disable(struct usb_function *f)
 
 	usb_ep_disable(sdp->in_ep);
 	usb_ep_disable(sdp->out_ep);
+	sdp->in_ep->desc = NULL;
+	sdp->out_ep->desc = NULL;
 
 	if (sdp->in_req) {
 		free(sdp->in_req->buf);
drivers/usb/gadget/f_thor.c +9 -10
index 540b9f882378..210537d51e92 100644
@@ -909,16 +909,15 @@ static int thor_eps_setup(struct usb_function *f)
 	struct usb_composite_dev *cdev = f->config->cdev;
 	struct usb_gadget *gadget = cdev->gadget;
 	struct thor_dev *dev = thor_func->dev;
-	struct usb_endpoint_descriptor *d;
 	struct usb_request *req;
 	struct usb_ep *ep;
 	int result;
 
 	ep = dev->in_ep;
-	d = ep_desc(gadget, &hs_in_desc, &fs_in_desc);
-	debug("(d)bEndpointAddress: 0x%x\n", d->bEndpointAddress);
+	ep->desc = ep_desc(gadget, &hs_in_desc, &fs_in_desc);
+	debug("(d)bEndpointAddress: 0x%x\n", ep->desc->bEndpointAddress);
 
-	result = usb_ep_enable(ep, d);
+	result = usb_ep_enable(ep);
 	if (result)
 		goto err;
 
@@ -933,10 +932,10 @@ static int thor_eps_setup(struct usb_function *f)
 	req->complete = thor_rx_tx_complete;
 	dev->in_req = req;
 	ep = dev->out_ep;
-	d = ep_desc(gadget, &hs_out_desc, &fs_out_desc);
-	debug("(d)bEndpointAddress: 0x%x\n", d->bEndpointAddress);
+	ep->desc = ep_desc(gadget, &hs_out_desc, &fs_out_desc);
+	debug("(d)bEndpointAddress: 0x%x\n", ep->desc->bEndpointAddress);
 
-	result = usb_ep_enable(ep, d);
+	result = usb_ep_enable(ep);
 	if (result)
 		goto err_free_in_req;
 
@@ -951,10 +950,10 @@ static int thor_eps_setup(struct usb_function *f)
 	dev->out_req = req;
 	/* ACM control EP */
 	ep = dev->int_ep;
-	d = ep_desc(gadget, &hs_int_desc, &fs_int_desc);
-	debug("(d)bEndpointAddress: 0x%x\n", d->bEndpointAddress);
+	ep->desc = ep_desc(gadget, &hs_int_desc, &fs_int_desc);
+	debug("(d)bEndpointAddress: 0x%x\n", ep->desc->bEndpointAddress);
 
-	result = usb_ep_enable(ep, d);
+	result = usb_ep_enable(ep);
 	if (result)
 		goto err;
 
Signature · 1 line
2.53.0
#142 lore raw

PATCH v5 73/75 usb: gadget: fix up the last UDC drivers after the resync

In reply to Anders Roxell

Adapt at91_udc, atmel_usba_udc and epautoconf to the new gadget API.

---
 drivers/usb/gadget/at91_udc.c       |  46 -------------
 drivers/usb/gadget/atmel_usba_udc.c | 102 ++++++++--------------------
 drivers/usb/gadget/epautoconf.c     |   2 -
 3 files changed, 28 insertions(+), 122 deletions(-)
drivers/usb/gadget/at91_udc.c +0 -46
index b3c780a4e35c..5b0c55d59c8d 100644
@@ -1435,52 +1435,6 @@ int dm_usb_gadget_handle_interrupts(struct udevice *dev)
 	return at91_udc_irq(udc);
 }
 
-int usb_gadget_register_driver(struct usb_gadget_driver *driver)
-{
-	struct at91_udc *udc = controller;
-	int ret;
-
-	if (!driver || !driver->bind || !driver->setup) {
-		printf("bad paramter\n");
-		return -EINVAL;
-	}
-
-	if (udc->driver) {
-		printf("UDC already has a gadget driver\n");
-		return -EBUSY;
-	}
-
-	at91_start(&udc->gadget, driver);
-
-	udc->driver = driver;
-
-	ret = driver->bind(&udc->gadget);
-	if (ret) {
-		pr_err("driver->bind() returned %d\n", ret);
-		udc->driver = NULL;
-	}
-
-	return ret;
-}
-
-int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
-{
-	struct at91_udc *udc = controller;
-
-	if (!driver || !driver->unbind || !driver->disconnect) {
-		pr_err("bad paramter\n");
-		return -EINVAL;
-	}
-
-	driver->disconnect(&udc->gadget);
-	driver->unbind(&udc->gadget);
-	udc->driver = NULL;
-
-	at91_stop(&udc->gadget);
-
-	return 0;
-}
-
 int at91_udc_probe(struct at91_udc_data *pdata)
 {
 	struct at91_udc	*udc;
drivers/usb/gadget/atmel_usba_udc.c +28 -74

141 lines not on this page · raw message

drivers/usb/gadget/epautoconf.c +0 -2
index 30016b805bfd..93ea70a5d79b 100644
@@ -6,9 +6,7 @@
  */
 
 #include <linux/kernel.h>
-#include <linux/module.h>
 #include <linux/types.h>
-#include <linux/device.h>
 
 #include <linux/ctype.h>
 #include <linux/string.h>
Signature · 1 line
2.53.0
#143 lore raw

PATCH v5 74/75 usb: fix up musb-new and mtu3 after the resync

In reply to Anders Roxell

Adapt the musb-new and mtu3 gadget code to the new gadget API.

---
 drivers/usb/mtu3/mtu3_gadget_ep0.c     | 16 +++++------
 drivers/usb/musb-new/musb_gadget_ep0.c | 24 ++++++----------
 drivers/usb/musb-new/musb_uboot.c      | 39 --------------------------
 3 files changed, 16 insertions(+), 63 deletions(-)
drivers/usb/mtu3/mtu3_gadget_ep0.c +8 -8
index 4b0bc5f02d10..07775d23d508 100644
@@ -300,20 +300,20 @@ static int handle_test_mode(struct mtu3 *mtu, struct usb_ctrlrequest *setup)
 	u32 value = 0;
 
 	switch (le16_to_cpu(setup->wIndex) >> 8) {
-	case TEST_J:
-		dev_dbg(mtu->dev, "TEST_J\n");
+	case USB_TEST_J:
+		dev_dbg(mtu->dev, "USB_TEST_J\n");
 		mtu->test_mode_nr = TEST_J_MODE;
 		break;
-	case TEST_K:
-		dev_dbg(mtu->dev, "TEST_K\n");
+	case USB_TEST_K:
+		dev_dbg(mtu->dev, "USB_TEST_K\n");
 		mtu->test_mode_nr = TEST_K_MODE;
 		break;
-	case TEST_SE0_NAK:
-		dev_dbg(mtu->dev, "TEST_SE0_NAK\n");
+	case USB_TEST_SE0_NAK:
+		dev_dbg(mtu->dev, "USB_TEST_SE0_NAK\n");
 		mtu->test_mode_nr = TEST_SE0_NAK_MODE;
 		break;
-	case TEST_PACKET:
-		dev_dbg(mtu->dev, "TEST_PACKET\n");
+	case USB_TEST_PACKET:
+		dev_dbg(mtu->dev, "USB_TEST_PACKET\n");
 		mtu->test_mode_nr = TEST_PACKET_MODE;
 		break;
 	default:
drivers/usb/musb-new/musb_gadget_ep0.c +8 -16
index 25b1de6e58f9..726864aa7979 100644
@@ -320,51 +320,43 @@ __acquires(musb->lock)
 						goto stall;
 
 					switch (ctrlrequest->wIndex >> 8) {
-					case 1:
-						pr_debug("TEST_J\n");
-						/* TEST_J */
+					case USB_TEST_J:
+						pr_debug("USB_TEST_J\n");
 						musb->test_mode_nr =
 							MUSB_TEST_J;
 						break;
-					case 2:
-						/* TEST_K */
-						pr_debug("TEST_K\n");
+					case USB_TEST_K:
+						pr_debug("USB_TEST_K\n");
 						musb->test_mode_nr =
 							MUSB_TEST_K;
 						break;
-					case 3:
-						/* TEST_SE0_NAK */
-						pr_debug("TEST_SE0_NAK\n");
+					case USB_TEST_SE0_NAK:
+						pr_debug("USB_TEST_SE0_NAK\n");
 						musb->test_mode_nr =
 							MUSB_TEST_SE0_NAK;
 						break;
-					case 4:
-						/* TEST_PACKET */
-						pr_debug("TEST_PACKET\n");
+					case USB_TEST_PACKET:
+						pr_debug("USB_TEST_PACKET\n");
 						musb->test_mode_nr =
 							MUSB_TEST_PACKET;
 						break;
 
 					case 0xc0:
-						/* TEST_FORCE_HS */
 						pr_debug("TEST_FORCE_HS\n");
 						musb->test_mode_nr =
 							MUSB_TEST_FORCE_HS;
 						break;
 					case 0xc1:
-						/* TEST_FORCE_FS */
 						pr_debug("TEST_FORCE_FS\n");
 						musb->test_mode_nr =
 							MUSB_TEST_FORCE_FS;
 						break;
 					case 0xc2:
-						/* TEST_FIFO_ACCESS */
 						pr_debug("TEST_FIFO_ACCESS\n");
 						musb->test_mode_nr =
 							MUSB_TEST_FIFO_ACCESS;
 						break;
 					case 0xc3:
-						/* TEST_FORCE_HOST */
 						pr_debug("TEST_FORCE_HOST\n");
 						musb->test_mode_nr =
 							MUSB_TEST_FORCE_HOST;
drivers/usb/musb-new/musb_uboot.c +0 -39
index 43ab3245e5c3..16907c4681bc 100644
@@ -383,45 +383,6 @@ int dm_usb_gadget_handle_interrupts(struct udevice *dev)
 
 	return gadget->isr(0, gadget);
 }
-
-int usb_gadget_register_driver(struct usb_gadget_driver *driver)
-{
-	int ret;
-
-	if (!driver || driver->speed < USB_SPEED_FULL || !driver->bind ||
-	    !driver->setup) {
-		printf("bad parameter.\n");
-		return -EINVAL;
-	}
-
-	if (!gadget) {
-		printf("Controller uninitialized\n");
-		return -ENXIO;
-	}
-
-	ret = musb_gadget_start(&gadget->g, driver);
-	if (ret < 0) {
-		printf("gadget_start failed with %d\n", ret);
-		return ret;
-	}
-
-	ret = driver->bind(&gadget->g);
-	if (ret < 0) {
-		printf("bind failed with %d\n", ret);
-		return ret;
-	}
-
-	return 0;
-}
-
-int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
-{
-	if (driver->disconnect)
-		driver->disconnect(&gadget->g);
-	if (driver->unbind)
-		driver->unbind(&gadget->g);
-	return 0;
-}
 #endif /* CONFIG_USB_MUSB_GADGET */
 
 struct musb *musb_register(struct musb_hdrc_platform_data *plat, void *bdata,
Signature · 1 line
2.53.0
#144 lore raw

Re: [PATCH v5 74/75] usb: fix up musb-new and mtu3 after the resync

Quoted 7 lines · Anders Roxell

Adapt the musb-new and mtu3 gadget code to the new gadget API.

Quoted 6 lines
---
 drivers/usb/mtu3/mtu3_gadget_ep0.c     | 16 +++++------
 drivers/usb/musb-new/musb_gadget_ep0.c | 24 ++++++----------
 drivers/usb/musb-new/musb_uboot.c      | 39 --------------------------
 3 files changed, 16 insertions(+), 63 deletions(-)

Why are two different controllers changed in the same patch?

#145 lore raw

PATCH v5 75/75 usb: host: fix up xhci and cdns3 after the resync

In reply to Anders Roxell

Adapt the xhci dwc3 and exynos5 glue and the cdns3 ep0 code to the new API.

---
 drivers/usb/cdns3/ep0.c         | 8 ++++----
 drivers/usb/host/xhci-dwc3.c    | 4 ++--
 drivers/usb/host/xhci-exynos5.c | 2 +-
 3 files changed, 7 insertions(+), 7 deletions(-)
drivers/usb/cdns3/ep0.c +4 -4
index acff79ae1ca1..40282cbc3234 100644
@@ -341,10 +341,10 @@ static int cdns3_ep0_feature_handle_device(struct cdns3_device *priv_dev,
 			return -EINVAL;
 
 		switch (tmode >> 8) {
-		case TEST_J:
-		case TEST_K:
-		case TEST_SE0_NAK:
-		case TEST_PACKET:
+		case USB_TEST_J:
+		case USB_TEST_K:
+		case USB_TEST_SE0_NAK:
+		case USB_TEST_PACKET:
 			cdns3_ep0_complete_setup(priv_dev, 0, 1);
 			/**
 			 *  Little delay to give the controller some time
drivers/usb/host/xhci-dwc3.c +2 -2
index 8ad07a4b98c9..1b2fa569ab01 100644
@@ -51,7 +51,7 @@ static void dwc3_phy_reset(struct dwc3 *dwc3_reg)
 	clrbits_le32(&dwc3_reg->g_usb2phycfg, DWC3_GUSB2PHYCFG_PHYSOFTRST);
 }
 
-void dwc3_core_soft_reset(struct dwc3 *dwc3_reg)
+static void _dwc3_core_soft_reset(struct dwc3 *dwc3_reg)
 {
 	/* Before Resetting PHY, put Core in Reset */
 	setbits_le32(&dwc3_reg->g_ctl, DWC3_GCTL_CORESOFTRESET);
@@ -79,7 +79,7 @@ int dwc3_core_init(struct dwc3 *dwc3_reg)
 		return -1;
 	}
 
-	dwc3_core_soft_reset(dwc3_reg);
+	_dwc3_core_soft_reset(dwc3_reg);
 
 	dwc3_hwparams1 = readl(&dwc3_reg->g_hwparams1);
 
drivers/usb/host/xhci-exynos5.c +1 -1
index 500696ccae71..10c38af675cd 100644
@@ -91,7 +91,7 @@ static int xhci_usb_of_to_plat(struct udevice *dev)
 	return 0;
 }
 
-static void exynos5_usb3_phy_init(struct exynos_usb3_phy *phy)
+void exynos5_usb3_phy_init(struct exynos_usb3_phy *phy)
 {
 	u32 reg;
 
Signature · 1 line
2.53.0
#146 lore raw
In reply to Anders Roxell
Quoted 35 lines · Anders Roxell

Hi,

This series syncs the DWC3 USB driver with Linux v6.16.

The driver was forked from the kernel v3.19-rc1 eleven years ago, in commit 85d5e7075f33 ("usb: dwc3: add dwc3 folder from linux kernel to u-boot"). After that almost no kernel changes came back to U-Boot.

I split the work in three steps, so it is easy to follow:

1. Restore drivers/usb/dwc3 to a clean v3.19-rc1 state.

2. Import the dwc3 directory once per major kernel version, from v3.19 up to v6.16. Each commit is a raw snapshot from that kernel.

3. Add back the U-Boot glue, the XHCI/UDC updates and the build fixes. This part builds on Jerome's work.

The import commits are raw kernel snapshots. They do not build on their own, only the full series builds. This is on purpose. It makes it easy to see what comes from which kernel version, and to compare each import with the matching kernel release. The commit messages say this too.

This is compile-tested only.

The series needs the dwc2 endpoint fixes from Mattijs [3]. They are already on the list and should go in first.

The branch is also available at [4].

[1] v4: https://lore.kernel.org/u-boot/[email protected]/
[2] Jerome's adaptation work: https://lore.kernel.org/all/[email protected]/
[3] dwc2 prep: https://lore.kernel.org/all/[email protected]/
[4] https://github.com/roxell/u-boot/tree/usb_dwc3_sync_v5

Quoted 9 lines

v4 -> v5:
- Split the big "fix build after resync" patch into smaller patches, one per area, so it is easier to review. Marek and Mattijs asked for this.
- Dropped the Tested-by tags from the import patches. They were only tested as a full series, not one by one.
- Removed the merge commits from the "import from kernel vN" changelogs.
- Some small cleanups in the new helpers: dropped a dead function, added a missing NULL check and changed spaces to tabs.
- Rebased on latest master.

Has all the other feedback provided on the 64 patches in v4 been addressed ? I recall the v4 series added various glue code drivers which were never even compiled or used ?

A message that is not in the archive (sent off-list or not yet received): 178602223375.3156999.13542339251028864355.b4-review@b4

A message that is not in the archive (sent off-list or not yet received): anmKNYbNQ73Kv3iX@monster

#149 lore raw
Quoted 105 lines · Anders Roxell
Quoted 10 lines · Anshul Dalal
Quoted 7 lines · Anders Roxell

[...]
This is compile-tested only.

The series needs the dwc2 endpoint fixes from Mattijs [3]. They are already on the list and should go in first.

The branch is also available at [4].

Hi Andres,

Hi Anshul,

Thanks for testing on real hardware.

Quoted 7 lines

I was unable to get DFU boot to work on TI devices with this patch series. I tested on AM62p EVM where I don't see any error logs on the console but the DFU device never shows up on the host side (verified with dfu-util and lsusb).

I'm not that familiar with dwc3 but the issue seems to be that dwc3_interrupt doesn't report any interrupts.

The event path is broken in three places. The main one: in the kernel dwc3_check_event_buf() copies the event ring into evt->cache and dwc3_process_event_buf() reads from evt->cache. We took the reader but not the copy, so it walks a buffer nothing fills. Before the resync we read evt->buf directly, so it worked. I think this is what you are hitting, but you have the board.

We also never write the count back to GEVNTCOUNT, and dwc3_thread_interrupt() gets the controller where it wants the event buffer.

Fix below, it follows the kernel dwc3_invalidate_cache() is ours, it was in io.h before the resync and got lost.

drivers/usb/dwc3/io.h +8 -0
@@ -48,4 +48,12 @@ static inline void dwc3_flush_cache(uintptr_t addr, int length)
 	flush_dcache_range((unsigned long)start_addr, (unsigned long)end_addr);
 }
 
+static inline void dwc3_invalidate_cache(uintptr_t addr, int length)
+{
+	uintptr_t start_addr = (uintptr_t)addr & ~(CACHELINE_SIZE - 1);
+	uintptr_t end_addr = ALIGN((uintptr_t)addr + length, CACHELINE_SIZE);
+
+	invalidate_dcache_range((unsigned long)start_addr, (unsigned long)end_addr);
+}
+
 #endif /* __DRIVERS_USB_DWC3_IO_H */
drivers/usb/dwc3/gadget.c +23 -4
@@ -4201,23 +4201,46 @@ static irqreturn_t dwc3_check_event_buf(struct dwc3 *dwc)
 {
 	struct dwc3_event_buffer *evt;
+	u32 amount;
 	u32 count;
-	u32 reg;
 
 	evt = dwc->ev_buf;
 
+	if (evt->flags & DWC3_EVENT_PENDING)
+		return IRQ_HANDLED;
+
 	count = dwc3_readl(dwc->regs, DWC3_GEVNTCOUNT(0));
 	count &= DWC3_GEVNTCOUNT_MASK;
 	if (!count)
 		return IRQ_NONE;
 
+	if (count > evt->length) {
+		dev_err(dwc->dev, "invalid count(%u) > evt->length(%u)\n",
+			count, evt->length);
+		return IRQ_NONE;
+	}
+
 	evt->count = count;
 	evt->flags |= DWC3_EVENT_PENDING;
 
 	/* Mask interrupt */
-	reg = dwc3_readl(dwc->regs, DWC3_GEVNTSIZ(0));
-	reg |= DWC3_GEVNTSIZ_INTMASK;
-	dwc3_writel(dwc->regs, DWC3_GEVNTSIZ(0), reg);
+	dwc3_writel(dwc->regs, DWC3_GEVNTSIZ(0),
+		    DWC3_GEVNTSIZ_INTMASK | DWC3_GEVNTSIZ_SIZE(evt->length));
+
+	/* The controller filled the buffer over DMA, drop our stale lines */
+	dwc3_invalidate_cache((uintptr_t)evt->buf, evt->length);
+
+	amount = min(count, evt->length - evt->lpos);
+	memcpy(evt->cache + evt->lpos, evt->buf + evt->lpos, amount);
+
+	if (amount < count)
+		memcpy(evt->cache, evt->buf, count - amount);
+
+	dwc3_writel(dwc->regs, DWC3_GEVNTCOUNT(0), count);
 
 	return IRQ_WAKE_THREAD;
 }
 

And in dwc3_gadget_uboot_handle_interrupt(), same file:

drivers/usb/dwc3/gadget.c

Quoted 4 lines
drivers/usb/dwc3/gadget.c +2 -2
-		struct dwc3_event_buffer *evt;
-		dwc3_thread_interrupt(0, dwc);
+		struct dwc3_event_buffer *evt = dwc->ev_buf;
+		dwc3_thread_interrupt(0, evt);

Thanks for the pointers Anders but I encounter a similar failure even with the diff you suggested. I enabled some logging for the SPL by defining the DEBUG macro in the following files (dfu.c spl.c spl_ram.c dwc3-am62.c composite.c g_dnl.c).

Failure logs:

	U-Boot SPL 2026.07-00860-g5a9b7a715be2 (Aug 10 2026 - 15:06:27 +0530)
	SYSFW ABI: 4.0 (firmware rev 0x000c '12.1.0--v12.01.00 (Clever Cat)')
	Set clock rates for '/a53@0', CPU: 1250MHz at Speed Grade 'V'
	SPL initial stack usage: 17104 bytes
	SPL malloc() before relocation used 0x64d0 bytes (25 KB)
	>>SPL: board_init_r()
	spl_init
	Trying to boot from DFU
	g_dnl_register: g_dnl_driver.name = usb_dnl_dfu
	g_dnl_bind: gadget: 0x81c44a98 cdev: 0x81c66bc0
	usb_add_config: adding config #1 'usb_dnload'/81c67cc0
	g_dnl_do_config: configuration: 0x81c67cc0 composite dev: 0x81c66bc0
	adding 'dfu'/81c67d34 to config 'usb_dnload'/81c67cc0
	cfg 1/81c67cc0 speeds: high full
	usb_add_config: interface 0 = dfu/81c67d34
	g_dnl_bind: calling usb_gadget_connect for controller 'dwc3-gadget'
	usb_dnl_dfu: ready

<CTRL-C> from user

unbind function 'dfu'/81c67d34
g_dnl_unbind: calling usb_gadget_disconnect for controller 'dwc3-gadget' Legacy image
u_boot_pos = ffffffff
Raw boot image support not enabled, proceeding to other boot methods
Error: -22
SPL: Unsupported Boot Device!
SPL: failed to boot from all boot devices
### ERROR ### Please RESET the board ###

Succes logs (same debug symbols ontop of main branch):

	U-Boot SPL 2026.10-rc1-00209-g0bdd5e5daf95 (Aug 10 2026 - 14:58:28 +0530)
	SYSFW ABI: 4.0 (firmware rev 0x000c '12.1.0--v12.01.00 (Clever Cat)')
	Set clock rates for '/a53@0', CPU: 1250MHz at Speed Grade 'V'
	SPL initial stack usage: 17104 bytes
	SPL malloc() before relocation used 0x64d0 bytes (25 KB)
	>>SPL: board_init_r()
	spl_init
	Trying to boot from DFU
	g_dnl_register: g_dnl_driver.name = usb_dnl_dfu
	g_dnl_bind: gadget: 0x81c44aa4 cdev: 0x81c4af40
	usb_add_config: adding config #1 'usb_dnload'/81c4c040
	g_dnl_do_config: configuration: 0x81c4c040 composite dev: 0x81c4af40
	adding 'dfu'/81c4c0b4 to config 'usb_dnload'/81c4c040
	cfg 1/81c4c040 speeds: high full
	usb_add_config: interface 0 = dfu/81c4c0b4
	g_dnl_bind: calling usb_gadget_connect for controller 'dwc3-gadget'
	usb_dnl_dfu: ready
	composite_suspend: suspend
	set_config: high speed config #1: usb_dnload
	non-core control reqa1.03 v0000 i0000 l6
	non-core control req21.01 v0000 i0000 l4096
...(repeated)
	#non-core control reqa1.03 v0000 i0000 l6
	non-core control reqa1.03 v0000 i0000 l6
	DOWNLOAD ... OK
	Ctrl+C to exit ...

I'm not that familiar with the DW3 driver, let me know if you need me to test with any further changes.

Quoted 6 lines

evt was used there without being set as well.

All of this is in v6 that I plan to send out. I have no AM62p and it is only compile tested, so please try it on your board so we know if it solves your issue before I send out v6.

I was able to reproduce the issue on beagleplay since it uses the same DWC3. You can try it locally if you have that board with you by resetting to DFU mode from U-Boot prompt:

=> mw.w 43000030 53; res

Regards,
Anshul

#150 lore raw
Quoted 4 lines · Anshul Dalal
Quoted 3 lines · Anders Roxell
Quoted 2 lines · Anshul Dalal
Quoted 1 line · Anders Roxell

[...]

[...]

Quoted 12 lines

Review

Quoted 7 lines

And in dwc3_gadget_uboot_handle_interrupt(), same file:

(quoted diff) +2 -2
-		struct dwc3_event_buffer *evt;
-		dwc3_thread_interrupt(0, dwc);
+		struct dwc3_event_buffer *evt = dwc->ev_buf;
+		dwc3_thread_interrupt(0, evt);

Thanks for the pointers Anders but I encounter a similar failure even with the diff you suggested. I enabled some logging for the SPL by defining the DEBUG macro in the following files (dfu.c spl.c spl_ram.c dwc3-am62.c composite.c g_dnl.c).

Hi Anshul,

Good news. I found two more bugs on top of the two I already sent you (the event buffer and allow_connect). With all four the device enumerates.

Quoted 72 lines

Failure logs:

	U-Boot SPL 2026.07-00860-g5a9b7a715be2 (Aug 10 2026 - 15:06:27 +0530)
	SYSFW ABI: 4.0 (firmware rev 0x000c '12.1.0--v12.01.00 (Clever Cat)')
	Set clock rates for '/a53@0', CPU: 1250MHz at Speed Grade 'V'
	SPL initial stack usage: 17104 bytes
	SPL malloc() before relocation used 0x64d0 bytes (25 KB)
	>>SPL: board_init_r()
	spl_init
	Trying to boot from DFU
	g_dnl_register: g_dnl_driver.name = usb_dnl_dfu
	g_dnl_bind: gadget: 0x81c44a98 cdev: 0x81c66bc0
	usb_add_config: adding config #1 'usb_dnload'/81c67cc0
	g_dnl_do_config: configuration: 0x81c67cc0 composite dev: 0x81c66bc0
	adding 'dfu'/81c67d34 to config 'usb_dnload'/81c67cc0
	cfg 1/81c67cc0 speeds: high full
	usb_add_config: interface 0 = dfu/81c67d34
	g_dnl_bind: calling usb_gadget_connect for controller 'dwc3-gadget'
	usb_dnl_dfu: ready

<CTRL-C> from user

unbind function 'dfu'/81c67d34
g_dnl_unbind: calling usb_gadget_disconnect for controller 'dwc3-gadget' Legacy image
u_boot_pos = ffffffff
Raw boot image support not enabled, proceeding to other boot methods
Error: -22
SPL: Unsupported Boot Device!
SPL: failed to boot from all boot devices
### ERROR ### Please RESET the board ###

Succes logs (same debug symbols ontop of main branch):

	U-Boot SPL 2026.10-rc1-00209-g0bdd5e5daf95 (Aug 10 2026 - 14:58:28 +0530)
	SYSFW ABI: 4.0 (firmware rev 0x000c '12.1.0--v12.01.00 (Clever Cat)')
	Set clock rates for '/a53@0', CPU: 1250MHz at Speed Grade 'V'
	SPL initial stack usage: 17104 bytes
	SPL malloc() before relocation used 0x64d0 bytes (25 KB)
	>>SPL: board_init_r()
	spl_init
	Trying to boot from DFU
	g_dnl_register: g_dnl_driver.name = usb_dnl_dfu
	g_dnl_bind: gadget: 0x81c44aa4 cdev: 0x81c4af40
	usb_add_config: adding config #1 'usb_dnload'/81c4c040
	g_dnl_do_config: configuration: 0x81c4c040 composite dev: 0x81c4af40
	adding 'dfu'/81c4c0b4 to config 'usb_dnload'/81c4c040
	cfg 1/81c4c040 speeds: high full
	usb_add_config: interface 0 = dfu/81c4c0b4
	g_dnl_bind: calling usb_gadget_connect for controller 'dwc3-gadget'
	usb_dnl_dfu: ready
	composite_suspend: suspend
	set_config: high speed config #1: usb_dnload
	non-core control reqa1.03 v0000 i0000 l6
	non-core control req21.01 v0000 i0000 l4096
...(repeated)
	#non-core control reqa1.03 v0000 i0000 l6
	non-core control reqa1.03 v0000 i0000 l6
	DOWNLOAD ... OK
	Ctrl+C to exit ...

I'm not that familiar with the DW3 driver, let me know if you need me to test with any further changes.

Quoted 6 lines

evt was used there without being set as well.

All of this is in v6 that I plan to send out. I have no AM62p and it is only compile tested, so please try it on your board so we know if it solves your issue before I send out v6.

Quoted 5 lines

I was able to reproduce the issue on beagleplay since it uses the same DWC3. You can try it locally if you have that board with you by resetting to DFU mode from U-Boot prompt:

=> mw.w 43000030 53; res

I could not use the mw.w 43000030 53; res trick on the BeagleBoard-X15 that I found. But I can run DFU directly, it is the same DWC3 gadget path you hit.

How I tested on x15:

  env set dfu_alt_info "${dfu_alt_info_ram}"
  dfu 0 ram 0

On the host dfu-util finds it:

Found DFU: [0451:d022] ... name="kernel"/"fdt"/"ramdisk"

The two new bugs:

3. udc-core never sets dwc->async_callbacks. So the gadget setup() is never called and every GET_DESCRIPTOR returns -EINVAL.

4. ep0. The trb and the ep0 buffers are normal cached memory. In u-boot dma_alloc_coherent is not coherent, so nothing keeps them in sync with the controller dma. The resync dropped the manual flush and invalidate, so the controller reads a stale trb and stale buffers.

The patch below is only 3 and 4. Keep the first two you already have, this goes on top. It is against v5. I built it and tested it on x15, it works.

Can you test it on BeaglePlay with your reset trick? These fixes will be part of the coming usb_dwc3_sync_v6 branch.

Cheers,
Anders

drivers/usb/dwc3/ep0.c +10 -0
index 0a4f69cbc28a..2ba05fc3f573 100644
@@ -54,6 +54,9 @@ static void dwc3_ep0_prepare_one_trb(struct dwc3_ep *dep,
 	else
 		trb->ctrl |= (DWC3_TRB_CTRL_IOC
 				| DWC3_TRB_CTRL_LST);
+
+	dwc3_flush_cache((uintptr_t)buf_dma, len);
+	dwc3_flush_cache((uintptr_t)trb, sizeof(*trb));
 }
 
 static int dwc3_ep0_start_trans(struct dwc3_ep *dep)
@@ -811,6 +814,8 @@ static void dwc3_ep0_inspect_setup(struct dwc3 *dwc,
 	int ret = -EINVAL;
 	u32 len;
 
+	dwc3_invalidate_cache((uintptr_t)ctrl, sizeof(*ctrl));
+
 	if (!dwc->gadget_driver || !dwc->softconnect || !dwc->connected)
 		goto out;
 
@@ -856,6 +861,8 @@ static void dwc3_ep0_complete_data(struct dwc3 *dwc,
 	dwc->ep0_next_event = DWC3_EP0_NRDY_STATUS;
 	trb = dwc->ep0_trb;
 
+	dwc3_invalidate_cache((uintptr_t)trb, sizeof(*trb) * 2);
+
 	r = next_request(&ep0->pending_list);
 	if (!r)
 		return;
@@ -873,6 +880,9 @@ static void dwc3_ep0_complete_data(struct dwc3 *dwc,
 
 	length = trb->size & DWC3_TRB_SIZE_MASK;
 	transferred = ur->length - length;
+
+	if (ur->buf && !r->direction)
+		dwc3_invalidate_cache((uintptr_t)ur->dma, ur->length);
 	ur->actual += transferred;
 
 	if ((IS_ALIGNED(ur->length, ep0->endpoint.maxpacket) &&
drivers/usb/gadget/udc/udc-core.c +4 -0
index 6355931f9ff1..f03ff937dfde 100644
@@ -941,6 +941,8 @@ static inline void usb_gadget_udc_set_speed(struct usb_udc *udc,
 		gadget->ops->udc_set_speed(gadget, s);
 }
 
+static inline void usb_gadget_enable_async_callbacks(struct usb_udc *udc);
+
 static int udc_bind_to_driver(struct usb_udc *udc, struct usb_gadget_driver *driver)
 {
         int ret;
@@ -960,6 +962,7 @@ static int udc_bind_to_driver(struct usb_udc *udc, struct usb_gadget_driver *dri
                 driver->unbind(udc->gadget);
                 goto err1;
         }
+        usb_gadget_enable_async_callbacks(udc);
         udc->allow_connect = true;
         usb_gadget_connect(udc->gadget);
 
@@ -1156,6 +1159,7 @@ static void usb_gadget_remove_driver(struct usb_udc *udc)
 			udc->driver->function);
 
 	udc->allow_connect = false;
+	usb_gadget_disable_async_callbacks(udc);
 	usb_gadget_disconnect(udc->gadget);
 	udc->driver->disconnect(udc->gadget);
 	udc->driver->unbind(udc->gadget);
#151 lore raw
Quoted 128 lines · Anders Roxell
Quoted 4 lines · Anshul Dalal
Quoted 3 lines · Anders Roxell
Quoted 2 lines · Anshul Dalal
Quoted 1 line · Anders Roxell

[...]

[...]

Quoted 12 lines

Review

Quoted 7 lines

And in dwc3_gadget_uboot_handle_interrupt(), same file:

(quoted diff) +2 -2
-		struct dwc3_event_buffer *evt;
-		dwc3_thread_interrupt(0, dwc);
+		struct dwc3_event_buffer *evt = dwc->ev_buf;
+		dwc3_thread_interrupt(0, evt);

Thanks for the pointers Anders but I encounter a similar failure even with the diff you suggested. I enabled some logging for the SPL by defining the DEBUG macro in the following files (dfu.c spl.c spl_ram.c dwc3-am62.c composite.c g_dnl.c).

Hi Anshul,

Good news. I found two more bugs on top of the two I already sent you (the event buffer and allow_connect). With all four the device enumerates.

Quoted 72 lines

Failure logs:

	U-Boot SPL 2026.07-00860-g5a9b7a715be2 (Aug 10 2026 - 15:06:27 +0530)
	SYSFW ABI: 4.0 (firmware rev 0x000c '12.1.0--v12.01.00 (Clever Cat)')
	Set clock rates for '/a53@0', CPU: 1250MHz at Speed Grade 'V'
	SPL initial stack usage: 17104 bytes
	SPL malloc() before relocation used 0x64d0 bytes (25 KB)
	>>SPL: board_init_r()
	spl_init
	Trying to boot from DFU
	g_dnl_register: g_dnl_driver.name = usb_dnl_dfu
	g_dnl_bind: gadget: 0x81c44a98 cdev: 0x81c66bc0
	usb_add_config: adding config #1 'usb_dnload'/81c67cc0
	g_dnl_do_config: configuration: 0x81c67cc0 composite dev: 0x81c66bc0
	adding 'dfu'/81c67d34 to config 'usb_dnload'/81c67cc0
	cfg 1/81c67cc0 speeds: high full
	usb_add_config: interface 0 = dfu/81c67d34
	g_dnl_bind: calling usb_gadget_connect for controller 'dwc3-gadget'
	usb_dnl_dfu: ready

<CTRL-C> from user

unbind function 'dfu'/81c67d34
g_dnl_unbind: calling usb_gadget_disconnect for controller 'dwc3-gadget' Legacy image
u_boot_pos = ffffffff
Raw boot image support not enabled, proceeding to other boot methods
Error: -22
SPL: Unsupported Boot Device!
SPL: failed to boot from all boot devices
### ERROR ### Please RESET the board ###

Succes logs (same debug symbols ontop of main branch):

	U-Boot SPL 2026.10-rc1-00209-g0bdd5e5daf95 (Aug 10 2026 - 14:58:28 +0530)
	SYSFW ABI: 4.0 (firmware rev 0x000c '12.1.0--v12.01.00 (Clever Cat)')
	Set clock rates for '/a53@0', CPU: 1250MHz at Speed Grade 'V'
	SPL initial stack usage: 17104 bytes
	SPL malloc() before relocation used 0x64d0 bytes (25 KB)
	>>SPL: board_init_r()
	spl_init
	Trying to boot from DFU
	g_dnl_register: g_dnl_driver.name = usb_dnl_dfu
	g_dnl_bind: gadget: 0x81c44aa4 cdev: 0x81c4af40
	usb_add_config: adding config #1 'usb_dnload'/81c4c040
	g_dnl_do_config: configuration: 0x81c4c040 composite dev: 0x81c4af40
	adding 'dfu'/81c4c0b4 to config 'usb_dnload'/81c4c040
	cfg 1/81c4c040 speeds: high full
	usb_add_config: interface 0 = dfu/81c4c0b4
	g_dnl_bind: calling usb_gadget_connect for controller 'dwc3-gadget'
	usb_dnl_dfu: ready
	composite_suspend: suspend
	set_config: high speed config #1: usb_dnload
	non-core control reqa1.03 v0000 i0000 l6
	non-core control req21.01 v0000 i0000 l4096
...(repeated)
	#non-core control reqa1.03 v0000 i0000 l6
	non-core control reqa1.03 v0000 i0000 l6
	DOWNLOAD ... OK
	Ctrl+C to exit ...

I'm not that familiar with the DW3 driver, let me know if you need me to test with any further changes.

Quoted 6 lines

evt was used there without being set as well.

All of this is in v6 that I plan to send out. I have no AM62p and it is only compile tested, so please try it on your board so we know if it solves your issue before I send out v6.

Quoted 5 lines

I was able to reproduce the issue on beagleplay since it uses the same DWC3. You can try it locally if you have that board with you by resetting to DFU mode from U-Boot prompt:

=> mw.w 43000030 53; res

I could not use the mw.w 43000030 53; res trick on the BeagleBoard-X15 that I found. But I can run DFU directly, it is the same DWC3 gadget path you hit.

How I tested on x15:

  env set dfu_alt_info "${dfu_alt_info_ram}"
  dfu 0 ram 0

On the host dfu-util finds it:

Found DFU: [0451:d022] ... name="kernel"/"fdt"/"ramdisk"

The two new bugs:

3. udc-core never sets dwc->async_callbacks. So the gadget setup() is never called and every GET_DESCRIPTOR returns -EINVAL.

4. ep0. The trb and the ep0 buffers are normal cached memory. In u-boot dma_alloc_coherent is not coherent, so nothing keeps them in sync with the controller dma. The resync dropped the manual flush and invalidate, so the controller reads a stale trb and stale buffers.

Quoted 6 lines

The patch below is only 3 and 4. Keep the first two you already have, this goes on top. It is against v5. I built it and tested it on x15, it works.

Can you test it on BeaglePlay with your reset trick? These fixes will be part of the coming usb_dwc3_sync_v6 branch.

Great news! I applied the diff you suggested and DFU boot seems to be working now. I have hosted my working tree here[1] with all 4 bug fixes applied.

Let me know if you would want anything else to be tested before a v6.

[1]: https://github.com/ArchUsr64/u-boot/tree/ti_k3_usb_dwc3_sync_working

Regards,
Anshul

Quoted 76 lines

Cheers,
Anders

drivers/usb/dwc3/ep0.c +10 -0
index 0a4f69cbc28a..2ba05fc3f573 100644
@@ -54,6 +54,9 @@ static void dwc3_ep0_prepare_one_trb(struct dwc3_ep *dep,
 	else
 		trb->ctrl |= (DWC3_TRB_CTRL_IOC
 				| DWC3_TRB_CTRL_LST);
+
+	dwc3_flush_cache((uintptr_t)buf_dma, len);
+	dwc3_flush_cache((uintptr_t)trb, sizeof(*trb));
 }
 
 static int dwc3_ep0_start_trans(struct dwc3_ep *dep)
@@ -811,6 +814,8 @@ static void dwc3_ep0_inspect_setup(struct dwc3 *dwc,
 	int ret = -EINVAL;
 	u32 len;
 
+	dwc3_invalidate_cache((uintptr_t)ctrl, sizeof(*ctrl));
+
 	if (!dwc->gadget_driver || !dwc->softconnect || !dwc->connected)
 		goto out;
 
@@ -856,6 +861,8 @@ static void dwc3_ep0_complete_data(struct dwc3 *dwc,
 	dwc->ep0_next_event = DWC3_EP0_NRDY_STATUS;
 	trb = dwc->ep0_trb;
 
+	dwc3_invalidate_cache((uintptr_t)trb, sizeof(*trb) * 2);
+
 	r = next_request(&ep0->pending_list);
 	if (!r)
 		return;
@@ -873,6 +880,9 @@ static void dwc3_ep0_complete_data(struct dwc3 *dwc,
 
 	length = trb->size & DWC3_TRB_SIZE_MASK;
 	transferred = ur->length - length;
+
+	if (ur->buf && !r->direction)
+		dwc3_invalidate_cache((uintptr_t)ur->dma, ur->length);
 	ur->actual += transferred;
 
 	if ((IS_ALIGNED(ur->length, ep0->endpoint.maxpacket) &&
drivers/usb/gadget/udc/udc-core.c +4 -0
index 6355931f9ff1..f03ff937dfde 100644
@@ -941,6 +941,8 @@ static inline void usb_gadget_udc_set_speed(struct usb_udc *udc,
 		gadget->ops->udc_set_speed(gadget, s);
 }
 
+static inline void usb_gadget_enable_async_callbacks(struct usb_udc *udc);
+
 static int udc_bind_to_driver(struct usb_udc *udc, struct usb_gadget_driver *driver)
 {
         int ret;
@@ -960,6 +962,7 @@ static int udc_bind_to_driver(struct usb_udc *udc, struct usb_gadget_driver *dri
                 driver->unbind(udc->gadget);
                 goto err1;
         }
+        usb_gadget_enable_async_callbacks(udc);
         udc->allow_connect = true;
         usb_gadget_connect(udc->gadget);
 
@@ -1156,6 +1159,7 @@ static void usb_gadget_remove_driver(struct usb_udc *udc)
 			udc->driver->function);
 
 	udc->allow_connect = false;
+	usb_gadget_disable_async_callbacks(udc);
 	usb_gadget_disconnect(udc->gadget);
 	udc->driver->disconnect(udc->gadget);
 	udc->driver->unbind(udc->gadget);