usb: Migrate drivers to use dev/ofnode APIs
Subsystems (4)
v2 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.
---
Changes in v2:
- Add R-b from Simon
- Per Simon, for patch 2 and 3, updated commit log.
in patch 2, drop DECLARE_GLOBAL_DATA_PTR and the including of asm/global_data.h
- Link to v1: https://lore.kernel.org/r/[email protected]
---
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 | 48 +++++++++++++++++++----------------------- 4 files changed, 27 insertions(+), 31 deletions(-)
---
base-commit: 0a46055d96ac627c05180cdeaa187a9fdf6b7973
change-id: 20260526-devfdt-usb-8a17a2383cd6
Best regards,
Signature · 1 line
Peng Fan <[email protected]>
PATCH v2 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
PATCH v2 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 from legacy FDT interfaces to ofnode and dev APIs to support both live device tree and flat DT backends.
In ti_musb_get_usb_index(), replace fdt_get_path()/fdt_get_alias() based string comparison with ofnode_get_aliases_node()/ofnode_equal() to match USB alias by ofnode identity rather than path strings.
In ti_musb_of_to_plat(), replace devfdt_get_addr_index_ptr() with dev_read_addr_index_ptr() and add a NULL check on the result. Convert four fdtdec_get_int() calls reading "mentor,multipoint", "mentor,num-eps", "mentor,ram-bits", and "mentor,power" properties to dev_read_s32_default().
Remove DECLARE_GLOBAL_DATA_PTR and the asm/global_data.h include as gd->fdt_blob is no longer referenced.
--- drivers/usb/musb-new/ti-musb.c | 34 ++++++++++++++-------------------- 1 file changed, 14 insertions(+), 20 deletions(-)
drivers/usb/musb-new/ti-musb.c +14 -20
@@ -10,7 +10,6 @@#include <dm.h> #include <log.h> #include <malloc.h> -#include <asm/global_data.h> #include <linux/printk.h> #include <linux/usb/otg.h> #include <dm/device-internal.h>
@@ -20,8 +19,6 @@#include <asm/omap_musb.h> #include "musb_uboot.h" -DECLARE_GLOBAL_DATA_PTR ; -#if CONFIG_IS_ENABLED (DM_USB )/* USB 2.0 PHY Control */ #define CM_PHY_PWRDN (1 << 0)
@@ -51,29 +48,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 (1 );return -ENOENT ; }
@@ -81,15 +74,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 +103,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 +113,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 +121,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 +131,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 v2 2/6] usb: musb-new: Use ofnode and dev APIs
Hi Peng,
Quoted 14 lines · Peng Fan (OSS)
usb: musb-new: Use ofnode and dev APIs
Convert the TI MUSB driver from legacy FDT interfaces to ofnode and dev APIs to support both live device tree and flat DT backends.
In
ti_musb_get_usb_index(), replace fdt_get_path()/fdt_get_alias() based string comparison with ofnode_get_aliases_node()/ofnode_equal() to match USB alias by ofnode identity rather than path strings.In
ti_musb_of_to_plat(), replacedevfdt_get_addr_index_ptr()withdev_read_addr_index_ptr()and add a NULL check on the result. Convert fourfdtdec_get_int()calls reading 'mentor,multipoint', 'mentor,num-eps', 'mentor,ram-bits', and 'mentor,power' properties todev_read_s32_default().
Quoted 7 lines
Remove
DECLARE_GLOBAL_DATA_PTRand theasm/global_data.hinclude asgd->fdt_blobis no longer referenced.Signed-off-by Peng Fan <[email protected]>
drivers/usb/musb-new/ti-musb.c| 34 ++++++++++++++--------------------1 file changed, 14 insertions(+), 20 deletions(-)
nit below
drivers/usb/musb-new/ti-musb.c static void ti_musb_set_phy_power(struct udevice *dev, u8 on) · line 52
Quoted 8 lines
drivers/usb/musb-new/ti-musb.c +1
-1@@ -51,29 +48,25 @@ static void ti_musb_set_phy_power(struct udevice *dev, u8 on) i++; - }while (alias_path); + }while (1 );return -ENOENT ; }
The trailing return -ENOENT is now unreachable. Please drop it, or restructure as for (i = 0; ; i++) so the intent is clearer. Some toolchains warn on unreachable code.
Regards,
Simon
PATCH v2 3/6 usb: musb-new: Update phandle handling
In reply to Peng Fan (OSS)From: Peng Fan <[email protected]>
Replace ofnode_get_by_phandle(dev_read_u32_default()) with ofnode_parse_phandle() for resolving the "phys" and "ti,ctrl_mod" phandle references in ti_musb_of_to_plat().
ofnode_parse_phandle() handles the phandle lookup in a single call and works with both live and flat device trees. Add ofnode_valid() checks after each resolution so the driver returns -EINVAL early instead of operating on invalid nodes.
--- drivers/usb/musb-new/ti-musb.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/usb/musb-new/ti-musb.c +8 -2
@@ -85,8 +85,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 v2 3/6] usb: musb-new: Update phandle handling
Quoted 11 lines · Peng Fan (OSS)
usb: musb-new: Update phandle handling
Replace ofnode_get_by_phandle(dev_read_u32_default()) with
ofnode_parse_phandle()for resolving the 'phys' and 'ti,ctrl_mod' phandle references inti_musb_of_to_plat().
ofnode_parse_phandle()handles the phandle lookup in a single call and works with both live and flat device trees. Addofnode_valid()checks after each resolution so the driver returns-EINVALearly instead of operating on invalid nodes.
Quoted 4 lines
Signed-off-by Peng Fan <[email protected]>
drivers/usb/musb-new/ti-musb.c| 10 ++++++++--1 file changed, 8 insertions(+), 2 deletions(-)
PATCH v2 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
PATCH v2 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
PATCH v2 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