All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3] usb: mtu3: support the current devicetree binding
@ 2026-07-20  7:53 Carlo Caione
  2026-07-20 23:47 ` David Lechner via U-Boot
  0 siblings, 1 reply; 3+ messages in thread
From: Carlo Caione @ 2026-07-20  7:53 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 v3:
- Remove the temporary platform data and derive the binding during probe
- Use dev_read_addr_name() for the MAC resource
- Link to v2: https://patch.msgid.link/20260718-ccaione-upstream-mtu3-spl-gadget-v2-1-7f69ca462559@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 | 23 ++++++++++++++++++++---
 1 file changed, 20 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/mtu3/mtu3_plat.c b/drivers/usb/mtu3/mtu3_plat.c
index 26fee141f6e..f5c00cd5a8d 100644
--- a/drivers/usb/mtu3/mtu3_plat.c
+++ b/drivers/usb/mtu3/mtu3_plat.c
@@ -136,6 +136,7 @@ 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;
+	fdt_addr_t mac_addr;
 	int ret;
 
 	ret = device_get_supply_regulator(dev, "vusb33-supply",
@@ -166,7 +167,17 @@ static int get_ssusb_rscs(struct udevice *dev, struct ssusb_mtk *ssusb)
 		return ret;
 	}
 
-	ssusb->mac_base = devfdt_remap_addr_name(child, "mac");
+	mac_addr = dev_read_addr_name(child, "mac");
+	if (mac_addr == FDT_ADDR_T_NONE) {
+		dev_err(dev, "error mapping memory for mac\n");
+		return -ENODEV;
+	}
+
+	/* Current bindings describe the device block, not the whole MAC. */
+	if (ofnode_equal(dev_ofnode(dev), dev_ofnode(child)))
+		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;
@@ -317,9 +328,15 @@ static int mtu3_glue_bind(struct udevice *parent)
 	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;
+	}
+
+	/* 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);

---
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-21  7:25 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-20  7:53 [PATCH v3] usb: mtu3: support the current devicetree binding Carlo Caione
2026-07-20 23:47 ` David Lechner via U-Boot
2026-07-21  7:25   ` Carlo Caione via U-Boot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.