u-boot.lists.denx.de archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] usb: mtu3: support the current devicetree binding
@ 2026-07-18 10:08 Carlo Caione
  2026-07-18 20:20 ` Marek Vasut
  0 siblings, 1 reply; 3+ messages in thread
From: Carlo Caione @ 2026-07-18 10:08 UTC (permalink / raw)
  To: GSS_MTK_Uboot_upstream, u-boot
  Cc: Ryder Lee, Weijie Gao, Chunfeng Yun, Igor Belwon, David Lechner,
	Julien Stephan, Marek Vasut, Tom Rini, Carlo Caione

The MTU3 glue driver requires the legacy U-Boot layout, where a synthetic
mediatek,ssusb child owns the gadget resources and dr_mode:

    usb@112b0000 {
        compatible = "mediatek,mt8188-mtu3", "mediatek,mtu3";

        ssusb@112b0000 {
            compatible = "mediatek,ssusb";
            reg = <0 0x112b0000 0 0x3e00>,
                  <0 0x112b3e00 0 0x0100>;
            reg-names = "mac", "ippc";
            dr_mode = "peripheral";
        };
    };

The current binding requires these properties directly on the controller:

    usb@112b1000 {
        compatible = "mediatek,mt8188-mtu3", "mediatek,mtu3";
        reg = <0 0x112b1000 0 0x2dff>,
              <0 0x112b3e00 0 0x0100>;
        reg-names = "mac", "ippc";
        ranges = <0 0 0 0x112b0000 0 0x3f00>;
        dr_mode = "peripheral";
    };

Modify the driver to look for a legacy node only among direct children
of the controller and bind the gadget device to the controller node when
none is present. This retains support for existing U-Boot devicetrees
without requiring the synthetic node in devicetrees using the current
binding.

There is also a difference in the meaning of the mac resource: normalize
the resource address by SSUSB_DEV_BASE for the current binding and leave
the legacy resource unchanged.

Signed-off-by: Carlo Caione <ccaione@baylibre.com>
---
Changes in v2:
- Removed typecast horror
- Added platform storage to pass around legacy flags and device
- Link to v1: https://patch.msgid.link/20260717-ccaione-upstream-mtu3-spl-gadget-v1-1-57a3e2d0a2b0@baylibre.com
---
 drivers/usb/mtu3/mtu3_plat.c | 41 +++++++++++++++++++++++++++++++----------
 1 file changed, 31 insertions(+), 10 deletions(-)

diff --git a/drivers/usb/mtu3/mtu3_plat.c b/drivers/usb/mtu3/mtu3_plat.c
index 26fee141f6e..f22d047b81e 100644
--- a/drivers/usb/mtu3/mtu3_plat.c
+++ b/drivers/usb/mtu3/mtu3_plat.c
@@ -11,6 +11,11 @@
 #include "mtu3.h"
 #include "mtu3_dr.h"
 
+struct mtu3_glue_plat {
+	struct udevice *child;
+	bool legacy_binding;
+};
+
 void ssusb_set_force_mode(struct ssusb_mtk *ssusb,
 			  enum mtu3_dr_force_mode mode)
 {
@@ -135,7 +140,9 @@ static void ssusb_ip_sw_reset(struct ssusb_mtk *ssusb)
 
 static int get_ssusb_rscs(struct udevice *dev, struct ssusb_mtk *ssusb)
 {
-	struct udevice *child;
+	struct mtu3_glue_plat *plat = dev_get_plat(dev);
+	struct udevice *child = plat->child;
+	fdt_addr_t mac_addr;
 	int ret;
 
 	ret = device_get_supply_regulator(dev, "vusb33-supply",
@@ -160,13 +167,17 @@ static int get_ssusb_rscs(struct udevice *dev, struct ssusb_mtk *ssusb)
 		return -ENODEV;
 	}
 
-	ret = device_find_first_child(dev, &child);
-	if (ret || !child) {
-		dev_err(dev, "failed to get child %d!\n", ret);
-		return ret;
+	mac_addr = devfdt_get_addr_name(child, "mac");
+	if (mac_addr == FDT_ADDR_T_NONE) {
+		dev_err(dev, "error mapping memory for mac\n");
+		return -ENODEV;
 	}
 
-	ssusb->mac_base = devfdt_remap_addr_name(child, "mac");
+	/* Current bindings describe the device block, not the whole MAC. */
+	if (!plat->legacy_binding)
+		mac_addr -= SSUSB_DEV_BASE;
+
+	ssusb->mac_base = map_physmem(mac_addr, 0, MAP_NOCACHE);
 	if (!ssusb->mac_base) {
 		dev_err(dev, "error mapping memory for mac\n");
 		return -ENODEV;
@@ -310,16 +321,24 @@ U_BOOT_DRIVER(mtu3_host) = {
 
 static int mtu3_glue_bind(struct udevice *parent)
 {
-	struct udevice *dev;
+	struct mtu3_glue_plat *plat = dev_get_plat(parent);
 	enum usb_dr_mode dr_mode;
 	const char *driver;
 	const char *name;
 	ofnode node;
 	int ret;
 
-	node = ofnode_by_compatible(dev_ofnode(parent), "mediatek,ssusb");
+	node = ofnode_null();
+	ofnode_for_each_subnode(node, dev_ofnode(parent)) {
+		if (ofnode_device_is_compatible(node, "mediatek,ssusb"))
+			break;
+	}
+
+	plat->legacy_binding = ofnode_valid(node);
+
+	/* Current bindings keep the gadget resources on the parent node. */
 	if (!ofnode_valid(node))
-		return -ENODEV;
+		node = dev_ofnode(parent);
 
 	name = ofnode_get_name(node);
 	dr_mode = usb_get_dr_mode(node);
@@ -349,7 +368,8 @@ static int mtu3_glue_bind(struct udevice *parent)
 	dev_dbg(parent, "%s: node name: %s, driver %s, dr_mode %d\n",
 		__func__, name, driver, dr_mode);
 
-	ret = device_bind_driver_to_node(parent, driver, name, node, &dev);
+	ret = device_bind_driver_to_node(parent, driver, name, node,
+					 &plat->child);
 	if (ret)
 		dev_err(parent, "%s: not able to bind usb device mode\n",
 			__func__);
@@ -369,5 +389,6 @@ U_BOOT_DRIVER(mtu3) = {
 	.bind = mtu3_glue_bind,
 	.probe = mtu3_probe,
 	.remove = mtu3_remove,
+	.plat_auto	= sizeof(struct mtu3_glue_plat),
 	.priv_auto	= sizeof(struct ssusb_mtk),
 };

---
base-commit: 96c308b8d2a6a1496c0a7366db9a7becf42d2454
change-id: 20260717-ccaione-upstream-mtu3-spl-gadget-aa3d39cad06a

Best regards,
--  
Carlo Caione <ccaione@baylibre.com>


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-07-20  7:15 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-18 10:08 [PATCH v2] usb: mtu3: support the current devicetree binding Carlo Caione
2026-07-18 20:20 ` Marek Vasut
2026-07-20  7:15   ` Carlo Caione

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).