usb: gadget: dwc2: Prepare for UDC core migration
cover usb: gadget: dwc2: Prepare for UDC core migration
Jens Wiklander started to migrate the DWC3 driver to a more recent version of linux (v6.16) [1].
This migration also updates the UDC core and most notably how drivers perform their endpoint matching.
While testing Jens' series on a Khadas VIM3 board, I reported [2] that I can no longer bind the fastboot gadget to the dwc2 otg driver.
This series aims to fix the problems I've reported.
They can be applied to master/next (as they should not break anything with the current UDC core). They can also be applied after we merge Jens' work.
It has been tested on khadas-vim3_android_defconfig with the next branch using base commit e800cc67f5b6 ("mtd: spi-nor: Add gd55lb02gf chips")
"""
U-Boot 2026.07-rc5-g89106934d3fb (Jul 03 2026 - 15:16:29 +0200) khadas-vim3
Model: Khadas VIM3 SoC: Amlogic Meson G12B (A311D) Revision 29:b (10:2) DRAM: 2 GiB (total 3.8 GiB) Core: 408 devices, 37 uclasses, devicetree: separate MMC: mmc@ffe03000: 0, mmc@ffe05000: 1, mmc@ffe07000: 2
MMC Device -1 not foundm MMC...
*** Warning - No MMC card found, using default environment
In: usbkbd,serial Out: vidconsole,serial Err: vidconsole,serial Net: eth0: ethernet@ff3f0000
Hit any key to stop autoboot: 0
=> fastboot usb 0
crq->brequest:0x0
"""
[1] https://lore.kernel.org/u-boot/[email protected]/
[2] https://lore.kernel.org/u-boot/[email protected]/
---
Mattijs Korpershoek (2):
usb: gadget: dwc2: Use usb_ep_set_maxpacket_limit() for fifo sizes
usb: gadget: dwc2: Set endpoint capabilities via .caps field
drivers/usb/gadget/dwc2_udc_otg.c | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-)
---
base-commit: e800cc67f5b6cb50a20f37c993ec1cd4063bdbd3
change-id: 20260703-usb-prep-dwc3-sync-f564883ebd14
Best regards,
Signature · 1 line
Mattijs Korpershoek <[email protected]>
PATCH 1/2 usb: gadget: dwc2: Use usb_ep_set_maxpacket_limit() for fifo sizes
More recent versions of usb_ep_autoconfig() use the maxpacket_limit field from struct usb_ep.
This field has been introduced in the linux kernel via commit e117e742d310 ("usb: gadget: add "maxpacket_limit" field to struct usb_ep") And has been ported to U-Boot via commit747a0a5b387f ("usb: dwc3: gadget: make dwc3 gadget build in uboot")
However, the dwc2 gadget driver was not converted to use usb_ep_set_maxpacket_limit().
This is harmless for now, but the driver will break once usb_ep_autoconfig() is updated to a more recent version.
Set maxpacket_limit via the recommended helper function to prepare for a core gadget update.
--- drivers/usb/gadget/dwc2_udc_otg.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
drivers/usb/gadget/dwc2_udc_otg.c +5 -4
@@ -828,7 +828,6 @@ static struct dwc2_udc memory = { .ep = { .name = ep0name, .ops = &dwc2_ep_ops, - .maxpacket = EP0_FIFO_SIZE, }, .dev = &memory,
@@ -843,7 +842,6 @@ static struct dwc2_udc memory = { .ep = { .name = "ep1in-bulk", .ops = &dwc2_ep_ops, - .maxpacket = EP_FIFO_SIZE, }, .dev = &memory,
@@ -858,7 +856,6 @@ static struct dwc2_udc memory = { .ep = { .name = "ep2out-bulk", .ops = &dwc2_ep_ops, - .maxpacket = EP_FIFO_SIZE, }, .dev = &memory,
@@ -873,7 +870,6 @@ static struct dwc2_udc memory = { .ep = { .name = "ep3in-int", .ops = &dwc2_ep_ops, - .maxpacket = EP_FIFO_SIZE, }, .dev = &memory,
@@ -893,6 +889,7 @@ int dwc2_udc_probe(struct dwc2_plat_otg_data *pdata) {struct dwc2_udc *dev = &memory;int retval =0 ; +int i;debug ("%s: %p\n" , __func__, pdata);
@@ -909,6 +906,10 @@ int dwc2_udc_probe(struct dwc2_plat_otg_data *pdata) the_controller = dev; +usb_ep_set_maxpacket_limit (&dev->ep[0 ].ep,EP0_FIFO_SIZE ); +for (i =1 ; i <DWC2_MAX_ENDPOINTS ; i++) +usb_ep_set_maxpacket_limit (&dev->ep[i].ep,EP_FIFO_SIZE ); + usb_ctrl =memalign (CONFIG_SYS_CACHELINE_SIZE ,ROUND (sizeof (struct usb_ctrlrequest ),CONFIG_SYS_CACHELINE_SIZE ));
Signature · 1 line
2.54.0
Re: [PATCH 1/2] usb: gadget: dwc2: Use usb_ep_set_maxpacket_limit() for fifo sizes
Not really an expert on USB but this seems reasonable
Quoted 13 lines · Mattijs Korpershoek
More recent versions of
usb_ep_autoconfig()use themaxpacket_limitfield from structusb_ep.This field has been introduced in the linux kernel via commit
e117e742d310("usb: gadget: add "maxpacket_limit" field to structusb_ep") And has been ported to U-Boot via commit747a0a5b387f("usb: dwc3: gadget: make dwc3 gadget build in uboot")However, the dwc2 gadget driver was not converted to use
usb_ep_set_maxpacket_limit().
This is harmless for now, but the driver will break onceusb_ep_autoconfig()is updated to a more recent version.
Quoted 6 lines
Set
maxpacket_limitvia the recommended helper function to prepare for a core gadget update.Signed-off-by Mattijs Korpershoek <[email protected]>---
Quoted 64 lines
drivers/usb/gadget/dwc2_udc_otg.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)drivers/usb/gadget/dwc2_udc_otg.c +5
-5@@ -828,7 +828,6 @@ static struct dwc2_udc memory = { .ep = { .name = ep0name, .ops = &dwc2_ep_ops, - .maxpacket = EP0_FIFO_SIZE, }, .dev = &memory,@@ -843,7 +842,6 @@ static struct dwc2_udc memory = { .ep = { .name = "ep1in-bulk", .ops = &dwc2_ep_ops, - .maxpacket = EP_FIFO_SIZE, }, .dev = &memory,@@ -858,7 +856,6 @@ static struct dwc2_udc memory = { .ep = { .name = "ep2out-bulk", .ops = &dwc2_ep_ops, - .maxpacket = EP_FIFO_SIZE, }, .dev = &memory,@@ -873,7 +870,6 @@ static struct dwc2_udc memory = { .ep = { .name = "ep3in-int", .ops = &dwc2_ep_ops, - .maxpacket = EP_FIFO_SIZE, }, .dev = &memory,@@ -893,6 +889,7 @@ int dwc2_udc_probe(struct dwc2_plat_otg_data *pdata) {struct dwc2_udc *dev = &memory;int retval =0 ; +int i;debug ("%s: %p\n" , __func__, pdata);@@ -909,6 +906,10 @@ int dwc2_udc_probe(struct dwc2_plat_otg_data *pdata) the_controller = dev; +usb_ep_set_maxpacket_limit (&dev->ep[0 ].ep,EP0_FIFO_SIZE ); +for (i =1 ; i <DWC2_MAX_ENDPOINTS ; i++) +usb_ep_set_maxpacket_limit (&dev->ep[i].ep,EP_FIFO_SIZE ); + usb_ctrl =memalign (CONFIG_SYS_CACHELINE_SIZE ,ROUND (sizeof (struct usb_ctrlrequest ),CONFIG_SYS_CACHELINE_SIZE )); --2.54.0
PATCH 2/2 usb: gadget: dwc2: Set endpoint capabilities via .caps field
In reply to Mattijs KorpershoekEndpoint capabilities can be described via the .caps field of struct usb_ep since commit77dcbdf3c1ce ("usb: gadget: Add match_ep() op to usb_gadget_ops")
In linux, the following commit introduces it:b86f33a3a371 ("usb: gadget: epautoconf: add endpoint capabilities flags verification")
Linux's change also reworks the ep matching function by relying on these new capabilities instead of guessing based on the endpoint name.
Prepare the dwc2 UDC driver for capability-based matching by adding the required capabilities for each endpoint.
--- drivers/usb/gadget/dwc2_udc_otg.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
drivers/usb/gadget/dwc2_udc_otg.c +17 -0
@@ -828,6 +828,11 @@ static struct dwc2_udc memory = { .ep = { .name = ep0name, .ops = &dwc2_ep_ops, + .caps = { + .type_control = 1, + .dir_in = 1, + .dir_out = 1, + }, }, .dev = &memory,
@@ -842,6 +847,10 @@ static struct dwc2_udc memory = { .ep = { .name = "ep1in-bulk", .ops = &dwc2_ep_ops, + .caps = { + .type_bulk = 1, + .dir_in = 1, + }, }, .dev = &memory,
@@ -856,6 +865,10 @@ static struct dwc2_udc memory = { .ep = { .name = "ep2out-bulk", .ops = &dwc2_ep_ops, + .caps = { + .type_bulk = 1, + .dir_out = 1, + }, }, .dev = &memory,
@@ -870,6 +883,10 @@ static struct dwc2_udc memory = { .ep = { .name = "ep3in-int", .ops = &dwc2_ep_ops, + .caps = { + .type_int = 1, + .dir_in = 1, + }, }, .dev = &memory,
Signature · 1 line
2.54.0
Re: [PATCH 2/2] usb: gadget: dwc2: Set endpoint capabilities via .caps field
Quoted 8 lines · Mattijs Korpershoek
Endpoint capabilities can be described via the .caps field of struct
usb_epsince commit77dcbdf3c1ce("usb: gadget: Addmatch_ep()op tousb_gadget_ops")In linux, the following commit introduces it:
b86f33a3a371("usb: gadget: epautoconf: add endpoint capabilities flags verification")
Quoted 8 lines
Linux's change also reworks the ep matching function by relying on these new capabilities instead of guessing based on the endpoint name.
Prepare the dwc2 UDC driver for capability-based matching by adding the required capabilities for each endpoint.
Signed-off-by Mattijs Korpershoek <[email protected]>---
Quoted 56 lines
drivers/usb/gadget/dwc2_udc_otg.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)drivers/usb/gadget/dwc2_udc_otg.c +17
-1@@ -828,6 +828,11 @@ static struct dwc2_udc memory = { .ep = { .name = ep0name, .ops = &dwc2_ep_ops, + .caps = { + .type_control = 1, + .dir_in = 1, + .dir_out = 1, + }, }, .dev = &memory,@@ -842,6 +847,10 @@ static struct dwc2_udc memory = { .ep = { .name = "ep1in-bulk", .ops = &dwc2_ep_ops, + .caps = { + .type_bulk = 1, + .dir_in = 1, + }, }, .dev = &memory,@@ -856,6 +865,10 @@ static struct dwc2_udc memory = { .ep = { .name = "ep2out-bulk", .ops = &dwc2_ep_ops, + .caps = { + .type_bulk = 1, + .dir_out = 1, + }, }, .dev = &memory,@@ -870,6 +883,10 @@ static struct dwc2_udc memory = { .ep = { .name = "ep3in-int", .ops = &dwc2_ep_ops, + .caps = { + .type_int = 1, + .dir_in = 1, + }, }, .dev = &memory, --2.54.0
Hi,
Quoted 10 lines · Mattijs Korpershoek
Jens Wiklander started to migrate the DWC3 driver to a more recent version of linux (v6.16) [1].
This migration also updates the UDC core and most notably how drivers perform their endpoint matching.
While testing Jens' series on a Khadas VIM3 board, I reported [2] that I can no longer bind the fastboot gadget to the dwc2 otg driver.
[...]
Thanks, Applied to https://source.denx.de/u-boot/custodians/u-boot-dfu (u-boot-dfu)
[1/2] usb: gadget: dwc2: Use usb_ep_set_maxpacket_limit() for fifo sizes
https://source.denx.de/u-boot/custodians/u-boot-dfu/-/commit/6f9c431a20627db34e0c41ea865c611f0d2c2016 [2/2] usb: gadget: dwc2: Set endpoint capabilities via .caps field https://source.denx.de/u-boot/custodians/u-boot-dfu/-/commit/c5c4cc4c6b9887858e168d5106f8f1d3dfb6c3e8
--
Mattijs
Quoted 12 lines · Mattijs Korpershoek
Hi,
Quoted 9 lines · Mattijs Korpershoek
Jens Wiklander started to migrate the DWC3 driver to a more recent version of linux (v6.16) [1].
This migration also updates the UDC core and most notably how drivers perform their endpoint matching.
While testing Jens' series on a Khadas VIM3 board, I reported [2] that I can no longer bind the fastboot gadget to the dwc2 otg driver.
Quoted 8 lines
Quoted 1 line
[...]
Thanks, Applied to https://source.denx.de/u-boot/custodians/u-boot-dfu (u-boot-dfu)
[1/2] usb: gadget: dwc2: Use
usb_ep_set_maxpacket_limit()for fifo sizeshttps://source.denx.de/u-boot/custodians/u-boot-dfu/-/commit/6f9c431a20627db34e0c41ea865c611f0d2c2016 [2/2] usb: gadget: dwc2: Set endpoint capabilities via .caps field https://source.denx.de/u-boot/custodians/u-boot-dfu/-/commit/c5c4cc4c6b9887858e168d5106f8f1d3dfb6c3e8
Err, my automation is not up to date.
I can confirm the patches have been applied to the new u-boot location:
https://git.u-boot-project.org/u-boot/custodians/u-boot-dfu/-/commit/6f9c431a20627db34e0c41ea865c611f0d2c2016
https://git.u-boot-project.org/u-boot/custodians/u-boot-dfu/-/commit/c5c4cc4c6b9887858e168d5106f8f1d3dfb6c3e8
Quoted 3 lines
--
Mattijs