U-Boot Archive on 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

* Re: [PATCH v3] usb: mtu3: support the current devicetree binding
  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
  0 siblings, 1 reply; 3+ messages in thread
From: David Lechner via U-Boot @ 2026-07-20 23:47 UTC (permalink / raw)
  To: Carlo Caione, GSS_MTK_Uboot_upstream, u-boot
  Cc: Ryder Lee, Weijie Gao, Chunfeng Yun, Igor Belwon, Julien Stephan,
	Marek Vasut, Tom Rini

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 <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");

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 <ccaione@baylibre.com>
> 

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.

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

* Re: [PATCH v3] usb: mtu3: support the current devicetree binding
  2026-07-20 23:47 ` David Lechner via U-Boot
@ 2026-07-21  7:25   ` Carlo Caione via U-Boot
  0 siblings, 0 replies; 3+ messages in thread
From: Carlo Caione via U-Boot @ 2026-07-21  7:25 UTC (permalink / raw)
  To: David Lechner, Carlo Caione, GSS_MTK_Uboot_upstream, u-boot
  Cc: Ryder Lee, Weijie Gao, Chunfeng Yun, Igor Belwon, Julien Stephan,
	Marek Vasut, Tom Rini

On Tue Jul 21, 2026 at 1:47 AM CEST, David Lechner wrote:
> On 7/20/26 2:53 AM, Carlo Caione wrote:

>> -	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.

Yes, indeed, I'll fix it.

>>  
>> -	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.

Nicely spotted, thanks.

>> +	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>
>> 
>
> 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.

I'll do.

> 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.

Yes, for MT8512 we should first add that to the linux bindings side and
later apply the change here, so for now I'm going only to fix MT8183.
I'll try to push a patch to modify the linux bindings to address MT8512
as well.

> And we should be able to remove doc/device-tree-bindings/usb/mediatek,mtu3.txt
> since there are upstream bindings now.

That would be a followup patch when also the MT8512 is fixed.

thanks,

--
Carlo Caione

^ permalink raw reply	[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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox