The MTU3 glue driver only supports the legacy U-Boot layout, where a
synthetic mediatek,ssusb child owns the gadget resources and dr_mode.
Upstream devicetrees instead place these properties directly on the
controller node. The gadget therefore cannot bind when U-Boot uses an
upstream devicetree.

Search the controller children for the legacy U-Boot-only node and use
the controller itself when none is present. This preserves compatibility
with existing U-Boot devicetrees while allowing the driver to consume the
upstream binding.

The two bindings also use a different base for the mac resource.
Normalize the upstream device-block address by SSUSB_DEV_BASE before
mapping it, while leaving the legacy whole-MAC address unchanged.

Signed-off-by: Carlo Caione <[email protected]>
---
 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..da617d81c30 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, "failed to read mac address\n");
+               return -ENODEV;
+       }
+
+       /* Upstream 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");
+       /* The mediatek,ssusb child is a legacy U-Boot-only binding. */
+       ofnode_for_each_subnode(node, dev_ofnode(parent)) {
+               if (ofnode_device_is_compatible(node, "mediatek,ssusb"))
+                       break;
+       }
+
+       /* Upstream 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);

-- 
2.55.0

Reply via email to