public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Michele Bisogno <micbis.openwrt@gmail.com>
To: u-boot@lists.denx.de
Cc: marek.vasut+renesas@mailbox.org, paul@pbarker.dev,
	jh80.chung@samsung.com, peng.fan@nxp.com, lukma@denx.de,
	mkorpershoek@kernel.org, trini@konsulko.com,
	Michele Bisogno <micbis.openwrt@gmail.com>
Subject: [PATCH v2 2/2] usb: gadget: renesas: add support for RZ/G2L SoC
Date: Thu, 16 Apr 2026 16:44:26 +0200	[thread overview]
Message-ID: <20260416144426.12728-3-micbis.openwrt@gmail.com> (raw)
In-Reply-To: <20260416144426.12728-1-micbis.openwrt@gmail.com>

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.
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.
---
 drivers/usb/gadget/rcar/common.c | 15 +++++++++++++++
 drivers/usb/gadget/rcar/fifo.c   | 23 +++++++++++++----------
 2 files changed, 28 insertions(+), 10 deletions(-)

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


      parent reply	other threads:[~2026-04-17 12:44 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-16 14:44 [PATCH v2 0/2] This is version 2 of the RZ/G2L support Michele Bisogno
2026-04-16 14:44 ` [PATCH v2 1/2] regulator: rzg2l: implement connectivity notification Michele Bisogno
2026-04-16 14:44 ` Michele Bisogno [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260416144426.12728-3-micbis.openwrt@gmail.com \
    --to=micbis.openwrt@gmail.com \
    --cc=jh80.chung@samsung.com \
    --cc=lukma@denx.de \
    --cc=marek.vasut+renesas@mailbox.org \
    --cc=mkorpershoek@kernel.org \
    --cc=paul@pbarker.dev \
    --cc=peng.fan@nxp.com \
    --cc=trini@konsulko.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox