usb: Migrate drivers to use dev/ofnode APIs
Subsystems (4)
cover usb: Migrate drivers to use dev/ofnode APIs
Convert several USB drivers to use the dev_* and ofnode_* APIs and removes dependency on fdt/devfdt helpers.
The motivation is to:
- Eliminate direct usage of gd->fdt_blob and fdtdec_* interfaces
- Avoid devfdt_* helpers in favor of backend-agnostic APIs
- Ensure compatibility with both live device tree and flat DT
Summary:
- Clean up unused legacy variables
- Convert MUSB driver to use dev_* and ofnode_* APIs
- Improve phandle parsing with proper validation
- Replace devfdt_remap_addr_* with dev_remap_addr_* in MTK and MTU3
- Replace devfdt_get_addr_* with dev_read_addr_* in MVEBU
Not have the boards to test mainly regarding the musb changes, just best practice for the migration.
---
Peng Fan (6):
usb: musb-new: Drop unused variables
usb: musb-new: Use ofnode and dev APIs
usb: musb-new: Update phandle handling
usb: host: xhci: Use dev_remap_addr_name()
usb: mtu3: Use dev_remap_addr_name()
usb: xhci: mvebu: Use dev_read_addr_index()
drivers/usb/host/xhci-mtk.c | 4 ++-- drivers/usb/host/xhci-mvebu.c | 2 +- drivers/usb/mtu3/mtu3_plat.c | 4 ++-- drivers/usb/musb-new/ti-musb.c | 45 +++++++++++++++++++++--------------------- 4 files changed, 27 insertions(+), 28 deletions(-)
---
base-commit: bb354d04459f5425318aeb8a70bae995ee573f1d
change-id: 20260526-devfdt-usb-8a17a2383cd6
Best regards,
Signature · 1 line
Peng Fan <[email protected]>
PATCH 1/6 usb: musb-new: Drop unused variables
From: Peng Fan <[email protected]>
'node' and 'fdt' are not used, remove them.
--- drivers/usb/musb-new/ti-musb.c | 4 ---- 1 file changed, 4 deletions(-)
drivers/usb/musb-new/ti-musb.c +0 -4
@@ -201,8 +201,6 @@ static int ti_musb_host_bind(struct udevice *dev)static int ti_musb_host_of_to_plat (struct udevice *dev) {struct ti_musb_plat *plat =dev_get_plat (dev); -const void *fdt = gd->fdt_blob; -int node =dev_of_offset (dev);int ret; ret =ti_musb_of_to_plat (dev);
@@ -251,8 +249,6 @@ static int ti_musb_peripheral_bind(struct udevice *dev)static int ti_musb_peripheral_of_to_plat (struct udevice *dev) {struct ti_musb_plat *plat =dev_get_plat (dev); -const void *fdt = gd->fdt_blob; -int node =dev_of_offset (dev);int ret; ret =ti_musb_of_to_plat (dev);
Signature · 1 line
2.51.0
Re: [PATCH 1/6] usb: musb-new: Drop unused variables
Quoted 8 lines · Peng Fan (OSS)
usb: musb-new: Drop unused variables
'node' and 'fdt' are not used, remove them.
Signed-off-by Peng Fan <[email protected]>
drivers/usb/musb-new/ti-musb.c| 4 ----1 file changed, 4 deletions(-)
PATCH 2/6 usb: musb-new: Use ofnode and dev APIs
In reply to Peng Fan (OSS)From: Peng Fan <[email protected]>
Convert the TI MUSB driver to use dev and ofnode-based device tree APIs instead of legacy FDT interfaces.
Replace dev_of_offset(), fdt_get_alias(), fdtdec_get_int(), and related helpers with their ofnode equivalents such asdev_ofnode(), ofnode_get_aliases_node(), ofnode_equal(), and dev_read_s32_default().
The USB index lookup is updated to compare ofnode handles instead of device tree path strings. Also remove direct dependency on gd->fdt_blob.
No functional changes.
--- drivers/usb/musb-new/ti-musb.c | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-)
drivers/usb/musb-new/ti-musb.c +14 -17
@@ -51,29 +51,25 @@ static void ti_musb_set_phy_power(struct udevice *dev, u8 on)#if CONFIG_IS_ENABLED (OF_CONTROL ) -static int ti_musb_get_usb_index (int node) +static int ti_musb_get_usb_index (ofnode node) { -const void *fdt = gd->fdt_blob;int i =0 ; -char path[64 ]; -const char *alias_path; +ofnode alias_path;char alias[16 ]; -fdt_get_path (fdt, node, path,sizeof (path)); -do {snprintf (alias,sizeof (alias),"usb%d" , i); - alias_path =fdt_get_alias (fdt, alias); -if (alias_path ==NULL ) { + alias_path =ofnode_get_aliases_node (alias); +if (!ofnode_valid (alias_path)) {debug ("USB index not found\n" );return -ENOENT ; } -if (!strcmp (path, alias_path)) +if (ofnode_equal (node, alias_path))return i; i++; - }while (alias_path); + }while (ofnode_valid (alias_path));return -ENOENT ; }
@@ -81,15 +77,16 @@ static int ti_musb_get_usb_index(int node)static int ti_musb_of_to_plat (struct udevice *dev) {struct ti_musb_plat *plat =dev_get_plat (dev); -const void *fdt = gd->fdt_blob; -int node =dev_of_offset (dev); +ofnode node =dev_ofnode (dev);ofnode phys_node;ofnode ctrl_mod_node;int usb_index;int ret;struct musb_hdrc_config *musb_config; - plat->base =devfdt_get_addr_index_ptr (dev,1 ); + plat->base =dev_read_addr_index_ptr (dev,1 ); +if (!plat->base) +return -EINVAL ; phys_node =ofnode_get_by_phandle (dev_read_u32_default (dev,"phys" ,0 )); ctrl_mod_node =ofnode_get_by_phandle (ofnode_read_u32_default (phys_node,"ti,ctrl_mod" ,0 ));
@@ -109,7 +106,7 @@ static int ti_musb_of_to_plat(struct udevice *dev) musb_config =malloc (sizeof (struct musb_hdrc_config ));memset (musb_config,0 ,sizeof (struct musb_hdrc_config )); - ret =fdtdec_get_int (fdt, node,"mentor,multipoint" ,-1 ); + ret =dev_read_s32_default (dev,"mentor,multipoint" ,-1 );if (ret <0 ) {pr_err ("MUSB multipoint DT entry missing\n" );return -ENOENT ;
@@ -119,7 +116,7 @@ static int ti_musb_of_to_plat(struct udevice *dev) musb_config->dyn_fifo =1 ; - ret =fdtdec_get_int (fdt, node,"mentor,num-eps" ,-1 ); + ret =dev_read_s32_default (dev,"mentor,num-eps" ,-1 );if (ret <0 ) {pr_err ("MUSB num-eps DT entry missing\n" );return -ENOENT ;
@@ -127,7 +124,7 @@ static int ti_musb_of_to_plat(struct udevice *dev) musb_config->num_eps = ret; } - ret =fdtdec_get_int (fdt, node,"mentor,ram-bits" ,-1 ); + ret =dev_read_s32_default (dev,"mentor,ram-bits" ,-1 );if (ret <0 ) {pr_err ("MUSB ram-bits DT entry missing\n" );return -ENOENT ;
@@ -137,7 +134,7 @@ static int ti_musb_of_to_plat(struct udevice *dev) plat->plat.config = musb_config; - ret =fdtdec_get_int (fdt, node,"mentor,power" ,-1 ); + ret =dev_read_s32_default (dev,"mentor,power" ,-1 );if (ret <0 ) {pr_err ("MUSB mentor,power DT entry missing\n" );return -ENOENT ;
Signature · 1 line
2.51.0
Re: [PATCH 2/6] usb: musb-new: Use ofnode and dev APIs
Hi Peng,
Quoted 22 lines · Peng Fan (OSS)
usb: musb-new: Use ofnode and dev APIs
Convert the TI MUSB driver to use dev and ofnode-based device tree APIs instead of legacy FDT interfaces.
Replace
dev_of_offset(),fdt_get_alias(),fdtdec_get_int(), and related helpers with their ofnode equivalents such asdev_ofnode(),ofnode_get_aliases_node(),ofnode_equal(), anddev_read_s32_default().The USB index lookup is updated to compare ofnode handles instead of device tree path strings. Also remove direct dependency on
gd->fdt_blob.No functional changes.
Signed-off-by Peng Fan <[email protected]>
drivers/usb/musb-new/ti-musb.c| 31 ++++++++++++++-----------------1 file changed, 14 insertions(+), 17 deletions(-)
drivers/usb/musb-new/ti-musb.c static void ti_musb_set_phy_power(struct udevice *dev, u8 on) · line 55
Quoted 9 lines
drivers/usb/musb-new/ti-musb.c +2
-4@@ -51,29 +51,25 @@ static void ti_musb_set_phy_power(struct udevice *dev, u8 on) -static int ti_musb_get_usb_index (int node) +static int ti_musb_get_usb_index (ofnode node) { -const void *fdt = gd->fdt_blob;int i =0 ; -char path[64 ]; -const char *alias_path; +ofnode alias_path;char alias[16 ];
Please rename alias_path to alias_node since it is no longer a path string.
drivers/usb/musb-new/ti-musb.c static void ti_musb_set_phy_power(struct udevice *dev, u8 on) · line 52
Quoted 5 lines
drivers/usb/musb-new/ti-musb.c +1
-1@@ -51,29 +51,25 @@ static void ti_musb_set_phy_power(struct udevice *dev, u8 on) i++; - }while (alias_path); + }while (ofnode_valid (alias_path));
This trailing check has always been dead - alias_path is guaranteed valid here (we returned -ENOENT above otherwise) and the loop only exits via the inner returns. Since you are touching this function, please convert it to while (1) so the control flow is obvious.
drivers/usb/musb-new/ti-musb.c static int ti_musb_get_usb_index(int node) · line 79
Quoted 6 lines
drivers/usb/musb-new/ti-musb.c +3
-1@@ -81,15 +77,16 @@ static int ti_musb_get_usb_index(int node) - plat->base =devfdt_get_addr_index_ptr (dev,1 ); + plat->base =dev_read_addr_index_ptr (dev,1 ); +if (!plat->base) +return -EINVAL ;
The added NULL check is a real behaviour change. Previously a missing reg[1] would silently leave plat->base as NULL and the driver would carry on. Please mention this in the commit message.
drivers/usb/musb-new/ti-musb.c static void ti_musb_set_phy_power(struct udevice *dev, u8 on) · line 51
Quoted 4 lines
drivers/usb/musb-new/ti-musb.c +0
-1@@ -51,29 +51,25 @@ static void ti_musb_set_phy_power(struct udevice *dev, u8 on) -const void *fdt = gd->fdt_blob;int i =0 ;
The last reference to gd in the file is gone (yay!), so DECLARE_GLOBAL_DATA_PTR on line 23 and the #include <asm/global_data.h> are now unused. Please drop them.
Regards,
Simon
PATCH 3/6 usb: musb-new: Update phandle handling
In reply to Peng Fan (OSS)From: Peng Fan <[email protected]>
Switch to ofnode_parse_phandle() and add proper ofnode_valid() checks when resolving "phys" and "ti,ctrl_mod" references to avoid operating on invalid nodes.
No functional changes.
--- drivers/usb/musb-new/ti-musb.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/usb/musb-new/ti-musb.c +8 -2
@@ -88,8 +88,14 @@ static int ti_musb_of_to_plat(struct udevice *dev)if (!plat->base)return -EINVAL ; - phys_node =ofnode_get_by_phandle (dev_read_u32_default (dev,"phys" ,0 )); - ctrl_mod_node =ofnode_get_by_phandle (ofnode_read_u32_default (phys_node,"ti,ctrl_mod" ,0 )); + phys_node =ofnode_parse_phandle (node,"phys" ,0 ); +if (!ofnode_valid (phys_node)) +return -EINVAL ; + + ctrl_mod_node =ofnode_parse_phandle (phys_node,"ti,ctrl_mod" ,0 ); +if (!ofnode_valid (ctrl_mod_node)) +return -EINVAL ; + plat->ctrl_mod_base = (void *)ofnode_get_addr (ctrl_mod_node); usb_index =ti_musb_get_usb_index (node);switch (usb_index) {
Signature · 1 line
2.51.0
Re: [PATCH 3/6] usb: musb-new: Update phandle handling
Hi Peng,
Quoted 15 lines · Peng Fan (OSS)
usb: musb-new: Update phandle handling
Switch to
ofnode_parse_phandle()and add properofnode_valid()checks when resolving 'phys' and 'ti,ctrl_mod' references to avoid operating on invalid nodes.No functional changes.
Signed-off-by Peng Fan <[email protected]>
drivers/usb/musb-new/ti-musb.c| 10 ++++++++--1 file changed, 8 insertions(+), 2 deletions(-)
drivers/usb/musb-new/ti-musb.c static int ti_musb_of_to_plat(struct udevice *dev) · line 95
Quoted 10 lines
drivers/usb/musb-new/ti-musb.c +8
-2@@ -88,8 +88,14 @@ static int ti_musb_of_to_plat(struct udevice *dev) - phys_node =ofnode_get_by_phandle (dev_read_u32_default (dev,'phys' ,0 )); - ctrl_mod_node =ofnode_get_by_phandle (ofnode_read_u32_default (phys_node,'ti,ctrl_mod' ,0 )); + phys_node =ofnode_parse_phandle (node,'phys' ,0 ); +if (!ofnode_valid (phys_node)) +return -EINVAL ; + + ctrl_mod_node =ofnode_parse_phandle (phys_node,'ti,ctrl_mod' ,0 ); +if (!ofnode_valid (ctrl_mod_node)) +return -EINVAL ; +
Not quite no functional change - previously a missing or invalid phys / ti,ctrl_mod left ctrl_mod_base pointing at ofnode_get_addr() on an invalid node and probe carried on; now those cases return -EINVAL and probe fails. That is the right behaviour, but please call it out in the commit message.
Regards,
Simon
PATCH 4/6 usb: host: xhci: Use dev_remap_addr_name()
In reply to Peng Fan (OSS)From: Peng Fan <[email protected]>
Use dev_remap_addr_name() which supports both live device tree and flat DT backends, avoiding direct dependency on devfdt_* helpers.
No functional changes
--- drivers/usb/host/xhci-mtk.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/usb/host/xhci-mtk.c +2 -2
@@ -202,13 +202,13 @@ static int xhci_mtk_ofdata_get(struct mtk_xhci *mtk)struct udevice *dev = mtk->dev;int ret =0 ; - mtk->hcd =devfdt_remap_addr_name (dev,"mac" ); + mtk->hcd =dev_remap_addr_name (dev,"mac" );if (!mtk->hcd) {dev_err (dev,"failed to get xHCI base address\n" );return -ENXIO ; } - mtk->ippc =devfdt_remap_addr_name (dev,"ippc" ); + mtk->ippc =dev_remap_addr_name (dev,"ippc" );if (!mtk->ippc) {dev_err (dev,"failed to get IPPC base address\n" );return -ENXIO ;
Signature · 1 line
2.51.0
Re: [PATCH 4/6] usb: host: xhci: Use dev_remap_addr_name()
Quoted 11 lines · Peng Fan (OSS)
usb: host: xhci: Use
dev_remap_addr_name()Use
dev_remap_addr_name()which supports both live device tree and flat DT backends, avoiding direct dependency on devfdt_* helpers.No functional changes
Signed-off-by Peng Fan <[email protected]>
drivers/usb/host/xhci-mtk.c| 4 ++--1 file changed, 2 insertions(+), 2 deletions(-)
PATCH 5/6 usb: mtu3: Use dev_remap_addr_name()
In reply to Peng Fan (OSS)From: Peng Fan <[email protected]>
Use dev_remap_addr_name() which supports both live device tree and flat DT backends, avoiding direct dependency on devfdt_* helpers.
No functional changes
--- drivers/usb/mtu3/mtu3_plat.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/usb/mtu3/mtu3_plat.c +2 -2
@@ -154,7 +154,7 @@ static int get_ssusb_rscs(struct udevice *dev, struct ssusb_mtk *ssusb)return ret; } - ssusb->ippc_base =devfdt_remap_addr_name (dev,"ippc" ); + ssusb->ippc_base =dev_remap_addr_name (dev,"ippc" );if (!ssusb->ippc_base) {dev_err (dev,"error mapping memory for ippc\n" );return -ENODEV ;
@@ -166,7 +166,7 @@ static int get_ssusb_rscs(struct udevice *dev, struct ssusb_mtk *ssusb)return ret; } - ssusb->mac_base =devfdt_remap_addr_name (child,"mac" ); + ssusb->mac_base =dev_remap_addr_name (child,"mac" );if (!ssusb->mac_base) {dev_err (dev,"error mapping memory for mac\n" );return -ENODEV ;
Signature · 1 line
2.51.0
Re: [PATCH 5/6] usb: mtu3: Use dev_remap_addr_name()
Quoted 11 lines · Peng Fan (OSS)
usb: mtu3: Use
dev_remap_addr_name()Use
dev_remap_addr_name()which supports both live device tree and flat DT backends, avoiding direct dependency on devfdt_* helpers.No functional changes
Signed-off-by Peng Fan <[email protected]>
drivers/usb/mtu3/mtu3_plat.c| 4 ++--1 file changed, 2 insertions(+), 2 deletions(-)
PATCH 6/6 usb: xhci: mvebu: Use dev_read_addr_index()
In reply to Peng Fan (OSS)From: Peng Fan <[email protected]>
Use dev_read_addr_index() which supports both live device tree and flat DT backends, avoiding direct dependency on devfdt_* helpers.
No functional changes.
--- drivers/usb/host/xhci-mvebu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/host/xhci-mvebu.c +1 -1
@@ -59,7 +59,7 @@ static int xhci_usb_probe(struct udevice *dev) }/* Enable USB xHCI (VBUS, reset etc) in board specific code */ -board_xhci_enable (devfdt_get_addr_index (dev,1 )); +board_xhci_enable (dev_read_addr_index (dev,1 ));return xhci_register (dev, ctx->hcd, hcor); }
Signature · 1 line
2.51.0
Re: [PATCH 6/6] usb: xhci: mvebu: Use dev_read_addr_index()
Quoted 11 lines · Peng Fan (OSS)
usb: xhci: mvebu: Use
dev_read_addr_index()Use
dev_read_addr_index()which supports both live device tree and flat DT backends, avoiding direct dependency on devfdt_* helpers.No functional changes.
Signed-off-by Peng Fan <[email protected]>
drivers/usb/host/xhci-mvebu.c| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)