Skip to contentSkip to conversation

usb: gadget: Add Renesas RZ/N1 USBF driver

PATCH Superseded Romain Gantois 5 participants 7 messages Jul 2 – Jul 21 USB

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

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

Hello everyone,

This is version two 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 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]>

---
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 | 3036 +++++++++++++++++++++++++++++++++++++
 include/linux/list.h              |   10 +
 5 files changed, 3061 insertions(+)

---
base-commit: c03e40b49af8d9985a18f04c1218b8c50ce1dd74
change-id: 20260622-rzn1-usbf-4d364687ae44

Best regards,

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

PATCH v2 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.54.0
#2 lore raw

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

In reply to 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. Suspend/resume features have been removed in this U-Boot port.

Linux revision this was ported from:

74851fbb6d64 usb: gadget: renesas_usbf: Handle devm_pm_runtime_...

---
 MAINTAINERS                       |    5 +
 drivers/usb/gadget/Kconfig        |    9 +
 drivers/usb/gadget/Makefile       |    1 +
 drivers/usb/gadget/renesas_usbf.c | 3036 +++++++++++++++++++++++++++++++++++++
 4 files changed, 3051 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..993a0f4d602 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 +3036 -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.54.0

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

#3 lore raw

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

Quoted 11 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. Suspend/resume features have been removed in this U-Boot port.

Linux revision this was ported from:

74851fbb6d64 usb: gadget: renesas_usbf: Handle devm_pm_runtime_...

Please use the canonical short format:

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

But diff between the Linux kernel driver file and this driver shows changes in indent and removed spin lock invocations, can you retain those and possibly stub them with noop functions instead ? At least the spinlocks and indent should be doable.

[...]

Quoted 4 lines
drivers/usb/gadget/renesas_usbf.c new file +4 -0
+static const struct udevice_id usbf_match[] = {
+	{ .compatible = "renesas,rzn1-usbf" },
+	{} /* sentinel */
+};

drivers/usb/gadget/renesas_usbf.c line 3036

Quoted 10 lines
drivers/usb/gadget/renesas_usbf.c new file +10 -0
+
+U_BOOT_DRIVER(usbf_renesas_udc) = {
+	.name	= "usbf_renesas",
+	.id = UCLASS_USB_GADGET_GENERIC,
+	.of_match = usbf_match,
+	.ops = &usbf_gadget_generic_ops,
+	.probe = usbf_probe,
+	.remove = usbf_remove,
+	.priv_auto	= sizeof(struct usbf_udc),
+};

Nitpick, please use either space or tab before = , but use only one and use it consistently.

Thank you !

Tested-by on v2 2/2
#4 lore raw

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

In reply to Romain Gantois
Quoted 8 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. Suspend/resume features have been removed in this U-Boot port.

Quoted 7 lines

Linux revision this was ported from:

74851fbb6d64 usb: gadget: renesas_usbf: Handle devm_pm_runtime_...

I've performed functional testing with this driver, admittedly on the exact same hardware that Romain and Herve are using. With the corresponding configuration options enabled, both DFU and fastboot protocols operate successfully over the USB interface.

Regards,
Ralph

#5 lore raw

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

In reply to Romain Gantois

Hi Romain,

Quoted 17 lines · Romain Gantois

usb: gadget: Add Renesas RZ/N1 USBF controller support

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. Suspend/resume features have been removed in this U-Boot port.

Linux revision this was ported from:

74851fbb6d64 usb: gadget: renesas_usbf: Handle devm_pm_runtime_...

Quoted 8 lines

MAINTAINERS | 5 +

 drivers/usb/gadget/Kconfig        |    9 +
 drivers/usb/gadget/Makefile       |    1 +
 drivers/usb/gadget/renesas_usbf.c | 3036 +++++++++++++++++++++++++++++++++++++
 4 files changed, 3051 insertions(+)

This driver was originally written by Hervé Codina for the Linux kernel. Suspend/resume features have been removed in this U-Boot port.

Please also mention the two other removals noted in the cover letter - handling of endpoints > 2 and dynamic detection of endpoint DMA capability. Otherwise users will be surprised when a gadget needing more than two endpoints fails to bind.

drivers/usb/gadget/renesas_usbf.c line 2960

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

If the availability check fails, INIT_LIST_HEAD() is never called and ep->disabled stays 0. usbf_reset() and usbf_detach() then iterate over all slots and only skip disabled == 1, so they will call usbf_ep_nuke() on an ep whose queue list is uninitialised. On RZ/N1 all three endpoints are always present so this is latent, but please set ep->disabled = 1 before the continue (or at least init the list_head).

drivers/usb/gadget/Kconfig config CI_UDC · line 166

Quoted 10 lines
drivers/usb/gadget/Kconfig +8 -0
@@ -159,6 +159,15 @@ config CI_UDC
+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.

Two Kconfig nits: prompts use double quotes throughout the file. Also, the help text is indented one space more than the tab + two spaces convention used by the neighbouring entries - compare with CI_UDC just above.

drivers/usb/gadget/renesas_usbf.c line 8

Quoted 10 lines
drivers/usb/gadget/renesas_usbf.c +8 -0
@@ -0,0 +1,3036 @@
+static int usbf_remove(struct udevice *dev)
+{
+     struct usbf_udc *udc = dev_get_priv(dev);
+
+     usb_del_gadget_udc(&udc->gadget);
+
+     return 0;
+}

Just to check - if the device is removed while the pull-up is still asserted, D+ stays driven and interrupts remain enabled at the EPC level. Would it be worth calling usbf_detach() here so remove() always leaves the hardware quiescent? What do you think?

Regards,
Simon

#6 lore raw

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

Hi Simon,

Quoted 2 lines · On Monday, 13 July 2026 15:10:48 CEST Simon Glass wrote:

Hi Romain,

...

Quoted 7 lines
Quoted 7 lines
(quoted diff) +0 -0

b/drivers/usb/gadget/renesas_usbf.c @@ -0,0 +1,3036 @@

drivers/usb/gadget/renesas_usbf.c new file +5 -0
+static int usbf_remove(struct udevice *dev)
+{
+     struct usbf_udc *udc = dev_get_priv(dev);
+
+     usb_del_gadget_udc(&udc->gadget);
Quoted 8 lines

drivers/usb/gadget/renesas_usbf.c line 512

Quoted 3 lines
drivers/usb/gadget/renesas_usbf.c new file +3 -0
+
+     return 0;
+}

Just to check - if the device is removed while the pull-up is still asserted, D+ stays driven and interrupts remain enabled at the EPC level. Would it be worth calling usbf_detach() here so remove() always leaves the hardware quiescent? What do you think?

Sorry for the late response, things have been a bit too busy :).

Sure, while the UDC core does call detach on the device, there are other code paths which could call remove() directly, so it's probably better to call detach here just to be safe.

Thanks,

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