Skip to contentSkip to conversation

usb: gadget: Add Renesas RZ/N1 USBF driver

PATCH Superseded Romain Gantois via U-Boot 3 participants 10 messages Jul 23 – Nov 30 2 messages not in the archive USB

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v3 cover usb: gadget: Add Renesas RZ/N1 USBF driver

Hello everyone,

This is version three of my series which adds support for the Renesas USBF controller, which is used in the RZ/N1 SoC. This will facilitate exposing USB gadgets from RZ/N1 SoCs in U-Boot.

The driver was ported from the Linux kernel. The following features were removed to reduce the memory footprint of the driver, and to avoid including features not relevant to U-Boot:

- Suspend/resume
- Handling of endpoints > 2
- Dynamic detection of endpoint DMA capability (DMA capability is predetermined for each endpoint anyway).

Best regards,

Romain

---
Changes in v3:
- Mentionned all removed features in commit log.
- Style corrections in Kconfig.
- Added a call to usbf_detach() in remove().
- Matched indents with Linux driver and stubbed spinlock handling.
- Link to v2: https://patch.msgid.link/[email protected]

Changes in v2:
- Provided the original Linux commit hash.
- Corrected a few spelling mistakes.
- Link to v1: https://patch.msgid.link/[email protected]

To: [email protected]
Cc: Thomas Petazzoni <[email protected]>
Cc: Tom Rini <[email protected]>
Cc: Herve Codina <[email protected]>
Cc: Simon Glass <[email protected]>
Cc: Romain Gantois <[email protected]>
Cc: Lukasz Majewski <[email protected]>
Cc: Mattijs Korpershoek <[email protected]>
Cc: Marek Vasut <[email protected]>
Cc: Nobuhiro Iwamatsu <[email protected]>
Cc: Neil Armstrong <[email protected]>
Cc: David Lechner <[email protected]>
Cc: Julien Stephan <[email protected]>
Cc: Peng Fan <[email protected]>
Cc: Kory Maincent <[email protected]>
Cc: Kuan-Wei Chiu <[email protected]>
Cc: Raymond Mao <[email protected]>
Cc: Quentin Schulz <[email protected]>
Cc: Stefan Roese <[email protected]>
Cc: Kever Yang <[email protected]>
Cc: Peter Robinson <[email protected]>
Cc: Jonas Karlman <[email protected]>
Cc: Johan Jonker <[email protected]>
Cc: George Chan <[email protected]>
Cc: Balaji Selvanathan <[email protected]>
Cc: Bastien Curutchet <[email protected]>

---
Herve Codina (1):
usb: gadget: Add Renesas RZ/N1 USBF controller support

Romain Gantois (1):
linux/list.h: Add list_is_first()

 MAINTAINERS                       |    5 +
 drivers/usb/gadget/Kconfig        |    9 +
 drivers/usb/gadget/Makefile       |    1 +
 drivers/usb/gadget/renesas_usbf.c | 3118 +++++++++++++++++++++++++++++++++++++
 include/linux/list.h              |   10 +
 5 files changed, 3143 insertions(+)

---
base-commit: 643502070009f20447e196efe2822f5213076bca
change-id: 20260622-rzn1-usbf-4d364687ae44

Best regards,

Signature · 1 line
Romain Gantois <[email protected]>
#1 lore raw

PATCH v3 1/2 linux/list.h: Add list_is_first()

Include the list_is_first() kernel function, which will be used by the Renesas USBF driver.

---
 include/linux/list.h | 10 ++++++++++
 1 file changed, 10 insertions(+)
include/linux/list.h +10 -0
index 3dc38279716..dc788b1cb69 100644
@@ -153,6 +153,16 @@ static inline void list_move_tail(struct list_head *list,
 	list_add_tail(list, head);
 }
 
+/**
+ * list_is_first -- tests whether @list is the first entry in list @head
+ * @list: the entry to test
+ * @head: the head of the list
+ */
+static inline int list_is_first(const struct list_head *list, const struct list_head *head)
+{
+	return list->prev == head;
+}
+
 /**
  * list_is_last - tests whether @list is the last entry in list @head
  * @list: the entry to test
Signature · 1 line
2.55.0
#3 lore raw

PATCH v3 2/2 usb: gadget: Add Renesas RZ/N1 USBF controller support

In reply to Romain Gantois via U-Boot

From: Herve Codina <[email protected]>

Add support for the Renesas USBF controller. This is an USB2.0 UDC controller available in the RZ/N1 SoC.

This driver was originally written by Hervé Codina for the Linux kernel.

Linux revision this was ported from:

74851fbb6d64 ("usb: gadget: renesas_usbf: Handle devm_pm_runtime_enable() errors")

The following features were removed to reduce the memory footprint of the driver, and to avoid including features not relevant to U-Boot:

- Suspend/resume
- Handling of endpoints > 2
- Dynamic detection of endpoint DMA capability (DMA capability is predetermined for each endpoint anyway).

---
 MAINTAINERS                       |    5 +
 drivers/usb/gadget/Kconfig        |    9 +
 drivers/usb/gadget/Makefile       |    1 +
 drivers/usb/gadget/renesas_usbf.c | 3118 +++++++++++++++++++++++++++++++++++++
 4 files changed, 3133 insertions(+)
MAINTAINERS +5 -0
index f4eb2c13a43..c5f357fc389 100644
@@ -1649,6 +1649,11 @@ S:	Maintained
 T:	git https://source.denx.de/u-boot/custodians/u-boot-nand-flash.git
 F:	drivers/mtd/nand/raw/
 
+RENESAS RZ/N1 USBF CONTROLLER DRIVER
+M:	Romain Gantois <[email protected]>
+S:	Maintained
+F:	drivers/usb/gadget/renesas_usbf.c
+
 RISC-V
 M:	Rick Chen <[email protected]>
 M:	Leo <[email protected]>
drivers/usb/gadget/Kconfig +9 -0
index e42d5a43696..c85c3ea9de4 100644
@@ -159,6 +159,15 @@ config CI_UDC
 	  Say Y here to enable device controller functionality of the
 	  ChipIdea driver.
 
+config USB_GADGET_RENESAS_USBF
+	bool "Renesas USB Function controller"
+	depends on RZN1
+	depends on DM_USB_GADGET
+	select USB_GADGET_DUALSPEED
+	help
+	  Renesas USB Function controller is a USB peripheral controller
+	  available on RZ/N1 Renesas SoCs.
+
 config USB_GADGET_VBUS_DRAW
 	int "Maximum VBUS Power usage (2-500 mA)"
 	range 2 500
drivers/usb/gadget/Makefile +1 -0
index f2aebf4e480..9f0277a3823 100644
@@ -19,6 +19,7 @@ obj-$(CONFIG_USB_GADGET_AT91) += at91_udc.o
 obj-$(CONFIG_USB_GADGET_ATMEL_USBA) += atmel_usba_udc.o
 obj-$(CONFIG_USB_GADGET_DWC2_OTG) += dwc2_udc_otg.o
 obj-$(CONFIG_USB_GADGET_DWC2_OTG_PHY) += dwc2_udc_otg_phy.o
+obj-$(CONFIG_USB_GADGET_RENESAS_USBF) += renesas_usbf.o
 obj-$(CONFIG_USB_RENESAS_USBHS) += rcar/
 ifndef CONFIG_XPL_BUILD
 obj-$(CONFIG_USB_GADGET_DOWNLOAD) += g_dnl.o
drivers/usb/gadget/renesas_usbf.c new file +3118 -0

2,967 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Signature · 1 line
2.55.0

Part of the diff is not shown here. View the raw message.

#4 lore raw

Re: [PATCH v3 2/2] usb: gadget: Add Renesas RZ/N1 USBF controller support

Quoted 9 lines · Romain Gantois

From: Herve Codina <[email protected]>

Add support for the Renesas USBF controller. This is an USB2.0 UDC controller available in the RZ/N1 SoC.

This driver was originally written by Hervé Codina for the Linux kernel.

Linux revision this was ported from:

Quoted 8 lines

74851fbb6d64 ("usb: gadget: renesas_usbf: Handle devm_pm_runtime_enable() errors")

The following features were removed to reduce the memory footprint of the driver, and to avoid including features not relevant to U-Boot:

- Suspend/resume
- Handling of endpoints > 2

The code seems to handle 3 endpoints ?

drivers/usb/gadget/renesas_usbf.c line 27

Quoted 4 lines
drivers/usb/gadget/renesas_usbf.c new file +4 -0
+/* Only handle the first three endpoints for now. This is sufficient to
+ * expose classic bootloader gadgets such as Fastboot or DFU.
+ */
+#define USBF_NUM_ENDPOINTS	3

But why not handle the additional endpoints ?

Also, can you test whether 'ums 0 mmc 0.1,0.2,0' works to expose eMMC HW BOOT partitions and HW USER partition as three separate UMS devices over the same USB connection ?

The rest looks good, thank you !

#5 lore raw

Re: [PATCH v3 2/2] usb: gadget: Add Renesas RZ/N1 USBF controller support

Hi Marek,

Quoted 13 lines · On Thursday, 23 July 2026 21:53:08 CEST Marek Vasut wrote:
Quoted 12 lines · Romain Gantois

From: Herve Codina <[email protected]>

Add support for the Renesas USBF controller. This is an USB2.0 UDC controller available in the RZ/N1 SoC.

This driver was originally written by Hervé Codina for the Linux kernel.

Linux revision this was ported from:

74851fbb6d64 ("usb: gadget: renesas_usbf: Handle devm_pm_runtime_enable() errors")

Quoted 8 lines
Quoted 5 lines

The following features were removed to reduce the memory footprint of the

driver, and to avoid including features not relevant to U-Boot:
- Suspend/resume
- Handling of endpoints > 2

The code seems to handle 3 endpoints ?

Yes, I'm talking in terms of USB endpoint numbers here, so endpoints 0-2 are handled.

Quoted 7 lines

drivers/usb/gadget/renesas_usbf.c line 27

Quoted 4 lines
drivers/usb/gadget/renesas_usbf.c new file +4 -0
+/* Only handle the first three endpoints for now. This is sufficient to
+ * expose classic bootloader gadgets such as Fastboot or DFU.
+ */
+#define USBF_NUM_ENDPOINTS	3

But why not handle the additional endpoints ?

Because I didn't see a major use case for them in U-Boot, and removing their handling allowed a reduction in code and program volume which seems relevant for U-Boot.

Quoted 3 lines

Also, can you test whether 'ums 0 mmc 0.1,0.2,0' works to expose eMMC HW BOOT partitions and HW USER partition as three separate UMS devices over the same USB connection ?

Sure, I'll give it a try.

Thanks,

Signature · 3 lines
Romain Gantois, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
#6 lore raw

Re: [PATCH v3 2/2] usb: gadget: Add Renesas RZ/N1 USBF controller support

On 7/24/26 7:15 AM, Romain Gantois wrote:

Hello Romain,

Quoted 24 lines
Quoted 8 lines
Quoted 5 lines

The following features were removed to reduce the memory footprint of the

driver, and to avoid including features not relevant to U-Boot:
- Suspend/resume
- Handling of endpoints > 2

The code seems to handle 3 endpoints ?

Yes, I'm talking in terms of USB endpoint numbers here, so endpoints 0-2 are handled.

Quoted 7 lines

drivers/usb/gadget/renesas_usbf.c line 27

Quoted 4 lines
drivers/usb/gadget/renesas_usbf.c new file +4 -0
+/* Only handle the first three endpoints for now. This is sufficient to
+ * expose classic bootloader gadgets such as Fastboot or DFU.
+ */
+#define USBF_NUM_ENDPOINTS	3

But why not handle the additional endpoints ?

Because I didn't see a major use case for them in U-Boot, and removing their handling allowed a reduction in code and program volume which seems relevant for U-Boot.

Quoted 5 lines
Quoted 3 lines

Also, can you test whether 'ums 0 mmc 0.1,0.2,0' works to expose eMMC HW BOOT partitions and HW USER partition as three separate UMS devices over the same USB connection ?

Sure, I'll give it a try.

Thank you !

#7 lore raw

Re: [PATCH v3 2/2] usb: gadget: Add Renesas RZ/N1 USBF controller support

Hi Marek,

Quoted 6 lines · Marek Vasut via U-Boot
Quoted 5 lines
Quoted 3 lines

Also, can you test whether 'ums 0 mmc 0.1,0.2,0' works to expose eMMC HW BOOT partitions and HW USER partition as three separate UMS devices over the same USB connection ?

Sure, I'll give it a try.

Thank you !

I've finally gotten around to testing this. I didn't have any usable block devices on this device so I used blkmaps instead of eMMC partitions:

ums 0 blkmap 0,1,2

The three block devices were exposed successfully over the same UMS gadget and I was able to read from them.

Thanks,

Signature · 3 lines
Romain Gantois, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
#8 lore raw

Re: [PATCH v3 2/2] usb: gadget: Add Renesas RZ/N1 USBF controller support

In reply to Romain Gantois via U-Boot

Hi Romain,

Thank you for the patch.
I've diffed this against the linux driver, and have some comments below.

Quoted 31 lines · Romain Gantois

From: Herve Codina <[email protected]>

Add support for the Renesas USBF controller. This is an USB2.0 UDC controller available in the RZ/N1 SoC.

This driver was originally written by Hervé Codina for the Linux kernel.

Linux revision this was ported from:

74851fbb6d64 ("usb: gadget: renesas_usbf: Handle devm_pm_runtime_enable() errors")

The following features were removed to reduce the memory footprint of the driver, and to avoid including features not relevant to U-Boot:

- Suspend/resume
- Handling of endpoints > 2
- Dynamic detection of endpoint DMA capability (DMA capability is predetermined for each endpoint anyway).

---
 MAINTAINERS                       |    5 +
 drivers/usb/gadget/Kconfig        |    9 +
 drivers/usb/gadget/Makefile       |    1 +
 drivers/usb/gadget/renesas_usbf.c | 3118 +++++++++++++++++++++++++++++++++++++
 4 files changed, 3133 insertions(+)

[...]

drivers/usb/gadget/renesas_usbf.c line 335

Quoted 11 lines
drivers/usb/gadget/renesas_usbf.c new file +11 -0
+};
+
+#define USBF_SINGLE_BUFFER 0
+#define USBF_DOUBLE_BUFFER 1
+#define USBF_EP_INFO(_name, _base_addr, _is_double, _maxpacket_limit)  \
+	{                                                                     \
+		.name            = _name,                                     \
+		.base_addr       = _base_addr,                                \
+		.is_double       = _is_double,                                \
+		.maxpacket_limit = _maxpacket_limit,                          \
+	}

When comparing with the linux driver, I've noticed that we dropped the .caps field here.
This is fine for now, but at some point we will be updating the UDC core in U-Boot, and capabilities might be required.

See the following for some background:
* https://lore.kernel.org/all/[email protected]/
* https://lore.kernel.org/u-boot/[email protected]/

To be clear: I don't think you need to put endpoint capabilities back in the driver right now, but keep this in mind once we merge the UDC core upgrade.

Quoted 17 lines
drivers/usb/gadget/renesas_usbf.c new file +17 -0
+
+/* This table is computed from the recommended values provided in the SOC
+ * datasheet. The buffer type (single/double) and the endpoint type cannot
+ * be changed. The mapping in internal RAM (base_addr and number of words)
+ * for each endpoints depends on the max packet size and the buffer type.
+ */
+static const struct usbf_ep_info usbf_ep_info[USBF_NUM_ENDPOINTS] = {
+	/* ep0: buf @0x0000 64 bytes, fixed 32 words */
+	[0] = USBF_EP_INFO("ep0-ctrl",
+			   0x0000, USBF_SINGLE_BUFFER, USBF_EP0_MAX_PCKT_SIZE),
+	/* ep1: buf @0x0020, 2 buffers 512 bytes -> (512 * 2 / 4) words */
+	[1] = USBF_EP_INFO("ep1-bulk",
+			   0x0020, USBF_DOUBLE_BUFFER, 512),
+	/* ep2: buf @0x0120, 2 buffers 512 bytes -> (512 * 2 / 4) words */
+	[2] = USBF_EP_INFO("ep2-bulk",
+			   0x0120, USBF_DOUBLE_BUFFER, 512),
+};

[..]

Quoted 8 lines
drivers/usb/gadget/renesas_usbf.c new file +8 -0
+
+	spin_unlock_irqrestore(&udc->lock, flags);
+}
+
+static void usbf_ahb_epc_irq(struct usbf_udc *udc)
+{
+	unsigned long flags;
+	struct usbf_ep *epn;

drivers/usb/gadget/renesas_usbf.c line 2833

Quoted 10 lines
drivers/usb/gadget/renesas_usbf.c new file +10 -0
+	u32 sysbint, sysben;
+	void (*ep_action)(struct usbf_ep *epn);
+	int i;
+
+	spin_lock_irqsave(&udc->lock, flags);
+
+	/* Read and ack interrupts */
+	sysbint = usbf_reg_readl(udc, USBF_REG_AHBBINT);
+	sysben = usbf_reg_readl(udc, USBF_REG_AHBBINTEN);
+	sysbint &= sysben;

In the linux driver, we don't read USBF_REG_AHBBINTEN. Can you explain why this is needed here?

drivers/usb/gadget/renesas_usbf.c line 2838

Quoted 5 lines
drivers/usb/gadget/renesas_usbf.c new file +5 -0
+	usbf_reg_writel(udc, USBF_REG_AHBBINT, sysbint);
+
+	if ((sysbint & USBF_SYS_VBUS_INT) == USBF_SYS_VBUS_INT) {
+		if (usbf_reg_readl(udc, USBF_REG_EPCTR) & USBF_SYS_VBUS_LEVEL) {
+			g_dnl_clear_detach();

Why do we need to depend on g_dnl_*() ?
This is the only gadget driver that does this. It seems wrong (g_dnl* is usually called from higher up (in u-boot commands or function drivers)

drivers/usb/gadget/renesas_usbf.c line 2843

Quoted 5 lines
drivers/usb/gadget/renesas_usbf.c new file +5 -0
+			spin_unlock(&udc->lock);
+			usb_gadget_set_state(&udc->gadget, USB_STATE_POWERED);
+			spin_lock(&udc->lock);
+		} else {
+			g_dnl_trigger_detach();

The linux driver has some dev_dbg() statements here. Why are they removed?
If we want to clean up dev_dbg(), why don't we remove the others in this function as well?

For consistency, I'd prefer for them to stay, please.

Quoted 19 lines
drivers/usb/gadget/renesas_usbf.c new file +19 -0
+			spin_unlock(&udc->lock);
+			usb_gadget_set_state(&udc->gadget,
+					     USB_STATE_NOTATTACHED);
+			spin_lock(&udc->lock);
+		}
+	}
+
+	for (i = 1; i < ARRAY_SIZE(udc->ep); i++) {
+		if (sysbint & USBF_SYS_DMA_ENDINT_EPN(i)) {
+			epn = &udc->ep[i];
+			dev_dbg(epn->udc->dev,
+				"ep%u handle DMA complete. action=%ps\n",
+				epn->id, epn->bridge_on_dma_end);
+			ep_action = epn->bridge_on_dma_end;
+			if (ep_action) {
+				epn->bridge_on_dma_end = NULL;
+				ep_action(epn);
+			}
+		}

drivers/usb/gadget/renesas_usbf.c line 2872

Quoted 10 lines
drivers/usb/gadget/renesas_usbf.c new file +10 -0
+	}
+
+	spin_unlock_irqrestore(&udc->lock, flags);
+}
+
+static int usbf_udc_start(struct usb_gadget *gadget,
+			  struct usb_gadget_driver *driver)
+{
+	struct usbf_udc *udc = container_of(gadget, struct usbf_udc, gadget);
+	unsigned long flags;

Missing dev_info() from linux here. Please keep it or justify why it absolutely needs to be removed.

Quoted 17 lines
drivers/usb/gadget/renesas_usbf.c new file +17 -0
+
+	spin_lock_irqsave(&udc->lock, flags);
+
+	/* hook up the driver */
+	udc->driver = driver;
+
+	/* Enable VBUS interrupt */
+	usbf_reg_writel(udc, USBF_REG_AHBBINTEN, USBF_SYS_VBUS_INTEN);
+
+	spin_unlock_irqrestore(&udc->lock, flags);
+
+	return 0;
+}
+
+static int usbf_udc_stop(struct usb_gadget *gadget)
+{
+	struct usbf_udc *udc = container_of(gadget, struct usbf_udc, gadget);

drivers/usb/gadget/renesas_usbf.c line 2899

Quoted 10 lines
drivers/usb/gadget/renesas_usbf.c new file +10 -0
+	unsigned long flags;
+
+	spin_lock_irqsave(&udc->lock, flags);
+
+	/* Disable VBUS interrupt */
+	usbf_reg_writel(udc, USBF_REG_AHBBINTEN, 0);
+
+	udc->driver = NULL;
+
+	spin_unlock_irqrestore(&udc->lock, flags);

Same here

Quoted 11 lines
drivers/usb/gadget/renesas_usbf.c new file +11 -0
+
+	return 0;
+}
+
+static int usbf_get_frame(struct usb_gadget *gadget)
+{
+	struct usbf_udc *udc = container_of(gadget, struct usbf_udc, gadget);
+
+	return USBF_USB_GET_FRAME(usbf_reg_readl(udc, USBF_REG_USB_ADDRESS));
+}
+

[...]

drivers/usb/gadget/renesas_usbf.c line 2978

Quoted 11 lines
drivers/usb/gadget/renesas_usbf.c new file +11 -0
+
+static struct usb_gadget_ops usbf_gadget_ops = {
+	.get_frame = usbf_get_frame,
+	.pullup = usbf_pullup,
+	.udc_start = usbf_udc_start,
+	.udc_stop = usbf_udc_stop,
+};
+
+static int usbf_epn_check(struct usbf_ep *epn)
+{
+	u32 ctrl;

Why can't we keep the same error handling as linux, which contains a dev_dbg() statement with some information about the endpoint?

Quoted 47 lines
drivers/usb/gadget/renesas_usbf.c new file +47 -0
+
+	ctrl = usbf_ep_reg_readl(epn, USBF_REG_EPN_CONTROL);
+
+	if ((ctrl & USBF_EPN_MODE_MASK) != USBF_EPN_MODE_BULK) {
+		dev_err(epn->udc->dev, "ep%u unknown type\n", epn->id);
+		return -EINVAL;
+	}
+
+	if (!(ctrl & USBF_EPN_BUF_TYPE_DOUBLE)) {
+		dev_err(epn->udc->dev,
+			"ep%u buffer mismatch, single expected\n",
+			epn->id);
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
+static int usbf_probe(struct udevice *dev)
+{
+	struct usbf_udc *udc;
+	struct usbf_ep *ep;
+	unsigned int i;
+	int ret;
+
+	udc = dev_get_priv(dev);
+	udc->dev = dev;
+	spin_lock_init(&udc->lock);
+
+	udc->regs = dev_read_addr_ptr(dev);
+	if (!udc->regs)
+		return -EINVAL;
+
+	/* Resetting the PLL is handled via the clock driver as it has common
+	 * registers with USB Host
+	 */
+	usbf_reg_bitclr(udc, USBF_REG_EPCTR, USBF_SYS_EPC_RST);
+
+	/* modify in register gadget process */
+	udc->gadget.speed = USB_SPEED_FULL;
+	udc->gadget.max_speed = USB_SPEED_HIGH;
+	udc->gadget.is_dualspeed = 1;
+	udc->gadget.ops = &usbf_gadget_ops;
+
+	udc->gadget.name = dev->driver->name;
+	udc->gadget.ep0 = &udc->ep[0].ep;
+

drivers/usb/gadget/renesas_usbf.c line 3035

Quoted 10 lines
drivers/usb/gadget/renesas_usbf.c new file +10 -0
+	INIT_LIST_HEAD(&udc->gadget.ep_list);
+	/* we have a canned request structure to allow sending packets as reply
+	 * to get_status requests
+	 */
+	INIT_LIST_HEAD(&udc->setup_reply.queue);
+
+	for (i = 0; i < ARRAY_SIZE(udc->ep); i++) {
+		ep = &udc->ep[i];
+
+		ep->disabled = 1;

Why has the ep->disabled been moved to a an earler place compared with linux?

In linux it's lower, part with the other assignments.

Quoted 9 lines
drivers/usb/gadget/renesas_usbf.c new file +9 -0
+
+		if (!(usbf_reg_readl(udc, USBF_REG_USBSSCONF) &
+		      USBF_SYS_EP_AVAILABLE(i))) {
+			continue;
+		}
+
+		INIT_LIST_HEAD(&ep->queue);
+
+		ep->id = i;

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

#11 lore raw

Re: [PATCH v3 2/2] usb: gadget: Add Renesas RZ/N1 USBF controller support

Hi Mattijs,

On Tuesday, 25 August 2026 14:11:41 CET Mattijs Korpershoek wrote:
...

Quoted 30 lines
Quoted 24 lines
Quoted 10 lines
Quoted 10 lines
(quoted diff) +9 -0
+static void usbf_ahb_epc_irq(struct usbf_udc *udc)
+{
+	unsigned long flags;
+	struct usbf_ep *epn;
+	u32 sysbint, sysben;
+	void (*ep_action)(struct usbf_ep *epn);
+	int i;
+
+	spin_lock_irqsave(&udc->lock, flags);
Quoted 8 lines

Review

Quoted 5 lines
(quoted diff) +5 -0
+
+	/* Read and ack interrupts */
+	sysbint = usbf_reg_readl(udc, USBF_REG_AHBBINT);
+	sysben = usbf_reg_readl(udc, USBF_REG_AHBBINTEN);
+	sysbint &= sysben;

In the linux driver, we don't read USBF_REG_AHBBINTEN. Can you explain why this is needed here?

This is due to the fact that U-Boot calls this handler in a polling manner. In Linux, when we disable bridge interrupts e.g. during DMA transfer operations, we can be sure that the handler won't get called, since the AHBBINTEN register masks interrupts.

Quoted 6 lines

However in U-Boot, the contents of AHBBINTEN do not prevent the handler from being called since we're continuously calling it in polling mode. We've actually ran into bugs because of this while testing initial versions of the driver port. Therefore, we mask AHBBINT with the contents of AHBBINTEN to prevent bridge events from being serviced when we don't want them to.

Quoted 4 lines

Ok, since this is a deliberate (and necessary) change because we operate in polling mode, can we please document this in a comment in the driver? That will make it more clear when others read/diff the code against linux.

ACK, I'll add a comment in v4.

Quoted 13 lines
Quoted 13 lines
Quoted 4 lines

Review

Quoted 4 lines
(quoted diff) +4 -0
+	usbf_reg_writel(udc, USBF_REG_AHBBINT, sysbint);
+
+	if ((sysbint & USBF_SYS_VBUS_INT) == USBF_SYS_VBUS_INT) {
+		if (usbf_reg_readl(udc, USBF_REG_EPCTR) & USBF_SYS_VBUS_LEVEL)

{

Quoted 5 lines

Review

Quoted 1 line
(quoted diff) +1 -0
+			g_dnl_clear_detach();

Why do we need to depend on g_dnl_*() ?
This is the only gadget driver that does this. It seems wrong (g_dnl* is usually called from higher up (in u-boot commands or function drivers)

Quoted 8 lines
Quoted 5 lines

The purpose of this is to signal to function drivers that the VBUS status has changed (presumably because of a cable removal) and that they should stop polling the UDC interrupt handler and exit cleanly. This seems like a correct use of this mechanism to me, but indeed I don't know why other UDC drivers don't use it this way.

I see. Why can't we implement the .vbus_session operation then? See at91_udc.c for example.

I'll have a look, thanks for the tip!

Thanks,

Signature · 3 lines
Romain Gantois, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com