On 7/20/26 2:53 AM, Carlo Caione wrote:
> 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 <[email protected]>
> ---
> 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-7f69ca462...@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-57a3e2d0a...@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");
This looks like an error reading the address, not mapping the memory.
> + 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() initializes node, so I think setting it here
is dead code.
> + 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 <[email protected]>
>
This would be a bit more clear to me if we change "current bindings"
to "upstream bindings" everywhere (I think that is what you mean?) and
add some comments in the code that "mediatek,ssusb" is a U-Boot-only
thing.
Also, can we remove the obsolete entries from the U-Boot devicetrees?
arch/arm/dts/mt8183.dtsi already has "mac" in reg-names, so should be
safe to remove ssusb child node. arch/arm/dts/mt8512.dtsi needs a bit
more work.
And we should be able to remove doc/device-tree-bindings/usb/mediatek,mtu3.txt
since there are upstream bindings now.