* [PATCH] usb: gadget: renesas: add support for RZ/G2L SoC
@ 2026-04-15 17:21 Michele Bisogno
2026-04-15 22:38 ` Marek Vasut
0 siblings, 1 reply; 6+ messages in thread
From: Michele Bisogno @ 2026-04-15 17:21 UTC (permalink / raw)
To: u-boot
Cc: marek.vasut+renesas, paul, jh80.chung, peng.fan, lukma,
mkorpershoek, trini, Michele Bisogno
Support the Renesas RZ/G2L (r9a07g044) USBHS IP by addressing
platform-specific reset, glue logic, and FIFO access requirements.
- regulator: rzg2l: Implement CON_CTRL manual connectivity notification.
By setting SEL_CONNECT and CONNECT_1, the UTM+ core is notified of
connection status in peripheral mode.
- gadget: common: Add "renesas,rzg2l-usbhs" compatible and support
reset deassertion. Fix a re-entrancy bug by calling usb_del_gadget_udc()
in the remove callback to prevent stale UDC list entries.
- gadget: fifo: Refactor PIO push/pop logic to handle trailing bytes
using iowrite8/ioread8. This ensures correct data alignment on
RZ/G2L and simplifies the data transfer loop.
Signed-off-by: Michele Bisogno <micbis.openwrt@gmail.com>
---
.../power/regulator/rzg2l-usbphy-regulator.c | 10 ++++++--
drivers/usb/gadget/rcar/common.c | 15 ++++++++++++
drivers/usb/gadget/rcar/fifo.c | 23 +++++++++++--------
3 files changed, 36 insertions(+), 12 deletions(-)
diff --git a/drivers/power/regulator/rzg2l-usbphy-regulator.c b/drivers/power/regulator/rzg2l-usbphy-regulator.c
index 0354555d0b5..03f8dec4f08 100644
--- a/drivers/power/regulator/rzg2l-usbphy-regulator.c
+++ b/drivers/power/regulator/rzg2l-usbphy-regulator.c
@@ -9,16 +9,22 @@
#include <renesas/rzg2l-usbphy.h>
#define VBENCTL 0x03c
+#define CON_CTRL 0x020
#define VBENCTL_VBUS_SEL BIT(0)
+#define SEL_CONNECT BIT(4)
+#define CONNECT_1 BIT(0)
static int rzg2l_usbphy_regulator_set_enable(struct udevice *dev, bool enable)
{
struct rzg2l_usbphy_ctrl_priv *priv = dev_get_priv(dev->parent);
- if (enable)
+ if (enable) {
clrbits_le32(priv->regs + VBENCTL, VBENCTL_VBUS_SEL);
- else
+ setbits_le32(priv->regs + CON_CTRL, SEL_CONNECT | CONNECT_1);
+ } else {
setbits_le32(priv->regs + VBENCTL, VBENCTL_VBUS_SEL);
+ clrbits_le32(priv->regs + CON_CTRL, SEL_CONNECT | CONNECT_1);
+ }
return 0;
}
diff --git a/drivers/usb/gadget/rcar/common.c b/drivers/usb/gadget/rcar/common.c
index 2ba022a3f2c..1f266ae5ac9 100644
--- a/drivers/usb/gadget/rcar/common.c
+++ b/drivers/usb/gadget/rcar/common.c
@@ -16,6 +16,7 @@
#include <linux/usb/ch9.h>
#include <linux/usb/gadget.h>
#include <usb.h>
+#include <reset.h>
#include "common.h"
@@ -397,6 +398,7 @@ static int usbhs_udc_otg_probe(struct udevice *dev)
struct usbhs_priv_otg_data *priv = dev_get_priv(dev);
struct usb_gadget *gadget;
struct clk_bulk clk_bulk;
+ struct reset_ctl_bulk reset_bulk;
int ret = -EINVAL;
priv->base = dev_read_addr_ptr(dev);
@@ -411,6 +413,14 @@ static int usbhs_udc_otg_probe(struct udevice *dev)
if (ret)
return ret;
+ ret = reset_get_bulk(dev, &reset_bulk);
+ if (ret)
+ return ret;
+
+ ret = reset_deassert_bulk(&reset_bulk);
+ if (ret)
+ return ret;
+
clrsetbits_le32(priv->base + UGCTRL2, UGCTRL2_USB0SEL_MASK, UGCTRL2_USB0SEL_EHCI);
clrsetbits_le16(priv->base + LPSTS, LPSTS_SUSPM, LPSTS_SUSPM);
@@ -447,7 +457,11 @@ err_clk:
static int usbhs_udc_otg_remove(struct udevice *dev)
{
struct usbhs_priv_otg_data *priv = dev_get_priv(dev);
+ struct usb_gadget *gadget;
+ gadget = usbhsg_get_gadget(&priv->usbhs_priv);
+ if (gadget)
+ usb_del_gadget_udc(gadget);
usbhs_rcar3_power_ctrl(&priv->usbhs_priv, false);
usbhs_mod_remove(&priv->usbhs_priv);
usbhs_fifo_remove(&priv->usbhs_priv);
@@ -460,6 +474,7 @@ static int usbhs_udc_otg_remove(struct udevice *dev)
static const struct udevice_id usbhs_udc_otg_ids[] = {
{ .compatible = "renesas,rcar-gen3-usbhs" },
+ { .compatible = "renesas,rzg2l-usbhs"},
{},
};
diff --git a/drivers/usb/gadget/rcar/fifo.c b/drivers/usb/gadget/rcar/fifo.c
index 6016b2987d5..b5340b4d860 100644
--- a/drivers/usb/gadget/rcar/fifo.c
+++ b/drivers/usb/gadget/rcar/fifo.c
@@ -535,18 +535,21 @@ static int usbhsf_pio_try_push(struct usbhs_pkt *pkt, int *is_done)
* 32-bit access only
*/
if (len >= 4 && !((unsigned long)buf & 0x03)) {
- iowrite32_rep(addr, buf, len / 4);
- len %= 4;
- buf += total_len - len;
+ int words = len / 4;
+
+ iowrite32_rep(addr, buf, words);
+ buf += (words * 4);
+ len -= (words * 4);
}
/* the rest operation */
- if (usbhs_get_dparam(priv, cfifo_byte_addr)) {
- for (i = 0; i < len; i++)
- iowrite8(buf[i], addr + (i & 0x03));
- } else {
- for (i = 0; i < len; i++)
- iowrite8(buf[i], addr + (0x03 - (i & 0x03)));
+ if (len > 0) {
+ if (len == 2 && !((unsigned long)buf & 0x01)) {
+ iowrite16(*(u16 *)buf, addr);
+ } else {
+ for (i = 0; i < len; i++)
+ iowrite8(buf[i], addr);
+ }
}
/*
@@ -716,7 +719,7 @@ static int usbhsf_pio_try_pop(struct usbhs_pkt *pkt, int *is_done)
if (!(i & 0x03))
data = ioread32(addr);
- buf[i] = (data >> ((i & 0x03) * 8)) & 0xff;
+ buf[i] = ioread8(addr);
}
usbhs_fifo_read_end:
--
2.34.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] usb: gadget: renesas: add support for RZ/G2L SoC
2026-04-15 17:21 [PATCH] usb: gadget: renesas: add support for RZ/G2L SoC Michele Bisogno
@ 2026-04-15 22:38 ` Marek Vasut
2026-04-16 14:14 ` Michele Bisogno
0 siblings, 1 reply; 6+ messages in thread
From: Marek Vasut @ 2026-04-15 22:38 UTC (permalink / raw)
To: Michele Bisogno, u-boot
Cc: marek.vasut+renesas, paul, jh80.chung, peng.fan, lukma,
mkorpershoek, trini
On 4/15/26 7:21 PM, Michele Bisogno wrote:
> Support the Renesas RZ/G2L (r9a07g044) USBHS IP by addressing
> platform-specific reset, glue logic, and FIFO access requirements.
>
> - regulator: rzg2l: Implement CON_CTRL manual connectivity notification.
> By setting SEL_CONNECT and CONNECT_1, the UTM+ core is notified of
> connection status in peripheral mode.
> - gadget: common: Add "renesas,rzg2l-usbhs" compatible and support
> reset deassertion. Fix a re-entrancy bug by calling usb_del_gadget_udc()
> in the remove callback to prevent stale UDC list entries.
> - gadget: fifo: Refactor PIO push/pop logic to handle trailing bytes
> using iowrite8/ioread8. This ensures correct data alignment on
> RZ/G2L and simplifies the data transfer loop.
>
> Signed-off-by: Michele Bisogno <micbis.openwrt@gmail.com>
> ---
> .../power/regulator/rzg2l-usbphy-regulator.c | 10 ++++++--
Regulator change should be a separate patch please.
> drivers/usb/gadget/rcar/common.c | 15 ++++++++++++
> drivers/usb/gadget/rcar/fifo.c | 23 +++++++++++--------
drivers/usb/gadget/rcar is pulled from Linux 1b4861e32e46 ("Linux
6.9.3") , but none of these changes in this patch are even in Linux
next. Is there at least a submitted Linux kernel patch which adds these
matching changes ? I would very much like to keep the USBHS drivers
synchronized between U-Boot and Linux.
The addition of RZ/G2L into USBHS driver in Linux was much simpler:
https://lore.kernel.org/r/20240319105356.87287-5-biju.das.jz@bp.renesas.com
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] usb: gadget: renesas: add support for RZ/G2L SoC
2026-04-15 22:38 ` Marek Vasut
@ 2026-04-16 14:14 ` Michele Bisogno
2026-04-20 23:15 ` Marek Vasut
0 siblings, 1 reply; 6+ messages in thread
From: Michele Bisogno @ 2026-04-16 14:14 UTC (permalink / raw)
To: Marek Vasut
Cc: u-boot, marek.vasut+renesas, paul, jh80.chung, peng.fan, lukma,
mkorpershoek, trini
Hi Marek,
Thank you for the review and the link to the Linux implementation.
> Regulator change should be a separate patch please.
I agree. I will split the regulator changes into a separate patch
for the v2 series to keep the subsystem changes distinct.
> drivers/usb/gadget/rcar is pulled from Linux 1b4861e32e46...
> but none of these changes in this patch are even in Linux next.
The RZ/G2L support in Linux relies heavily on DMA for data transfers.
In U-Boot, we are primarily using the PIO path. The refactoring
in fifo.c (switching to ioread8/iowrite8) was found to be necessary
to handle trailing bytes and alignment specifically for the RZ/G2L
bus when DMA is not active.
Additionally, the usb_del_gadget_udc() change in common.c addresses
a re-entrancy bug unique to U-Boot's gadget lifecycle. Without
this, the UDC list becomes stale, causing the board to crash if
a command like 'ums' is executed more than once.
> The addition of RZ/G2L into USBHS driver in Linux was much simpler
I agree that moving the RZ/G2L specifics in common.c to a platform
dependent file (similar to Linux) would be the cleaner long-term
architecture. However, doing so would require a much more invasive
refactoring of the existing driver structure. I opted for these
minimal changes to maintain stability for existing R-Car Gen3
users while enabling RZ/G2L support.
I will prepare a v2 series with the patches split as requested.
Kind regards,
Michele
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] usb: gadget: renesas: add support for RZ/G2L SoC
2026-04-16 14:14 ` Michele Bisogno
@ 2026-04-20 23:15 ` Marek Vasut
2026-04-21 7:32 ` Michele Bisogno
0 siblings, 1 reply; 6+ messages in thread
From: Marek Vasut @ 2026-04-20 23:15 UTC (permalink / raw)
To: Michele Bisogno
Cc: u-boot, marek.vasut+renesas, paul, jh80.chung, peng.fan, lukma,
mkorpershoek, trini
On 4/16/26 4:14 PM, Michele Bisogno wrote:
Hello Michele,
> Thank you for the review and the link to the Linux implementation.
>
>> Regulator change should be a separate patch please.
>
> I agree. I will split the regulator changes into a separate patch
> for the v2 series to keep the subsystem changes distinct.
>
>> drivers/usb/gadget/rcar is pulled from Linux 1b4861e32e46...
>> but none of these changes in this patch are even in Linux next.
>
> The RZ/G2L support in Linux relies heavily on DMA for data transfers.
> In U-Boot, we are primarily using the PIO path. The refactoring
> in fifo.c (switching to ioread8/iowrite8) was found to be necessary
> to handle trailing bytes and alignment specifically for the RZ/G2L
> bus when DMA is not active.
If Linux also contains the PIO code, it would also benefit from matching
improvement, right ?
> Additionally, the usb_del_gadget_udc() change in common.c addresses
> a re-entrancy bug unique to U-Boot's gadget lifecycle. Without
> this, the UDC list becomes stale, causing the board to crash if
> a command like 'ums' is executed more than once.
This should be a separate bugfix patch.
>> The addition of RZ/G2L into USBHS driver in Linux was much simpler
>
> I agree that moving the RZ/G2L specifics in common.c to a platform
> dependent file (similar to Linux) would be the cleaner long-term
> architecture. However, doing so would require a much more invasive
> refactoring of the existing driver structure. I opted for these
> minimal changes to maintain stability for existing R-Car Gen3
> users while enabling RZ/G2L support.
>
> I will prepare a v2 series with the patches split as requested.
Ideally, let's try to keep the Linux and U-Boot driver code base
synchronized as much as possible.
Thank you !
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] usb: gadget: renesas: add support for RZ/G2L SoC
2026-04-20 23:15 ` Marek Vasut
@ 2026-04-21 7:32 ` Michele Bisogno
2026-04-22 1:16 ` Marek Vasut
0 siblings, 1 reply; 6+ messages in thread
From: Michele Bisogno @ 2026-04-21 7:32 UTC (permalink / raw)
To: Marek Vasut
Cc: u-boot, marek.vasut+renesas, paul, jh80.chung, peng.fan, lukma,
mkorpershoek, trini
Hi Marek,
thank you for your comments and suggestions.
> If Linux also contains the PIO code, it would also benefit from matching
> improvement, right ?
Yes, though I have found the fix is not strictly required. We can maintain
synchronization between both repositories by utilizing the cfifo_byte_addr
parameter for the RZ/G2L and similar devices, allowing us to leave the
existing PIO code untouched.
> This should be a separate bugfix patch.
Agreed.
> Ideally, let's try to keep the Linux and U-Boot driver code base
> synchronized as much as possible.
Understood. I am currently preparing a revised patch set that aligns with
this approach to ensure consistency between the codebases.
Kind regards,
Michele
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] usb: gadget: renesas: add support for RZ/G2L SoC
2026-04-21 7:32 ` Michele Bisogno
@ 2026-04-22 1:16 ` Marek Vasut
0 siblings, 0 replies; 6+ messages in thread
From: Marek Vasut @ 2026-04-22 1:16 UTC (permalink / raw)
To: Michele Bisogno
Cc: u-boot, marek.vasut+renesas, paul, jh80.chung, peng.fan, lukma,
mkorpershoek, trini
On 4/21/26 9:32 AM, Michele Bisogno wrote:
Hello Michele,
> thank you for your comments and suggestions.
>
>> If Linux also contains the PIO code, it would also benefit from matching
>> improvement, right ?
>
> Yes, though I have found the fix is not strictly required. We can maintain
> synchronization between both repositories by utilizing the cfifo_byte_addr
> parameter for the RZ/G2L and similar devices, allowing us to leave the
> existing PIO code untouched.
>
>> This should be a separate bugfix patch.
>
> Agreed.
>
>> Ideally, let's try to keep the Linux and U-Boot driver code base
>> synchronized as much as possible.
>
> Understood. I am currently preparing a revised patch set that aligns with
> this approach to ensure consistency between the codebases.
Thank you !
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-04-22 1:46 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-15 17:21 [PATCH] usb: gadget: renesas: add support for RZ/G2L SoC Michele Bisogno
2026-04-15 22:38 ` Marek Vasut
2026-04-16 14:14 ` Michele Bisogno
2026-04-20 23:15 ` Marek Vasut
2026-04-21 7:32 ` Michele Bisogno
2026-04-22 1:16 ` Marek Vasut
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox