phy: Use device API to replace devfdt_ helpers
cover phy: Use device API to replace devfdt_ helpers
The goal is to remove the direct usage of devfdt_ APIs in drivers. The device APIs supports both live device tree and flat DT backends, avoiding direct dependency on devfdt_* helpers.
---
Peng Fan (3):
phy: ti-pipe3: Use device API for DT parsing
phy: marvell: comphy: Use dev_read_addr_index_ptr()
phy: cadence: Use device API
drivers/phy/cadence/phy-cadence-sierra.c | 4 ++-- drivers/phy/cadence/phy-cadence-torrent.c | 8 ++++---- drivers/phy/marvell/comphy_core.c | 4 ++-- drivers/phy/ti-pipe3-phy.c | 23 ++++++++++++++--------- 4 files changed, 22 insertions(+), 17 deletions(-)
---
base-commit: bb354d04459f5425318aeb8a70bae995ee573f1d
change-id: 20260526-devfdt-phy-f2894541e3ad
Best regards,
Signature · 1 line
Peng Fan <[email protected]>
PATCH 1/3 phy: ti-pipe3: Use device API for DT parsing
From: Peng Fan <[email protected]>
Replace legacy FDT parsing in get_reg() with the device API dev_read_phandle_with_args() which removes direct access to gd->fdt_blob and aligns the driver with modern U-Boot DT handling.
The offset is retrieved from the phandle argument instead of manually parsing the property cells. Add validation for the argument count to avoid out-of-bounds access on malformed DTs.
Also switch from devfdt_get_addr_size_index() to dev_read_addr_size_index() for consistency with the DM API.
No functional changes.
--- drivers/phy/ti-pipe3-phy.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-)
drivers/phy/ti-pipe3-phy.c +14 -9
@@ -6,6 +6,7 @@#include <dm.h> #include <dm/device.h> +#include <dm/device_compat.h> #include <generic-phy.h> #include <asm/global_data.h> #include <asm/io.h>
@@ -428,10 +429,10 @@ static int pipe3_exit(struct phy *phy)static void *get_reg (struct udevice *dev,const char *name) { +struct ofnode_phandle_args phandle;struct udevice *syscon;struct regmap *regmap; -const fdt32_t *cell; -int len, err; +int err;void *base; err = uclass_get_device_by_phandle(UCLASS_SYSCON, dev,
@@ -449,10 +450,14 @@ static void *get_reg(struct udevice *dev, const char *name)return NULL ; } - cell =fdt_getprop (gd->fdt_blob,dev_of_offset (dev), name, - &len); -if (len <2 *sizeof (fdt32_t)) { -pr_err ("offset not available for %s\n" , name); + err =dev_read_phandle_with_args (dev, name,NULL ,0 ,0 , &phandle); +if (err) { +dev_err (dev,"parse %s failed: %d\n" , name, err); +return NULL ; + } + +if (phandle.args_count <1 ) { +dev_err (dev,"%s: missing args\n" , name);return NULL ; }
@@ -460,7 +465,7 @@ static void *get_reg(struct udevice *dev, const char *name)if (!base)return NULL ; -return fdtdec_get_number (cell +1 ,1 ) + base; +return base + phandle.args[0 ]; }static int pipe3_phy_probe (struct udevice *dev)
@@ -471,7 +476,7 @@ static int pipe3_phy_probe(struct udevice *dev)struct pipe3_data *data;/* PHY_RX */ - addr =devfdt_get_addr_size_index (dev,0 , &sz); + addr =dev_read_addr_size_index (dev,0 , &sz);if (addr ==FDT_ADDR_T_NONE ) {pr_err ("missing phy_rx address\n" );return -EINVAL ;
@@ -484,7 +489,7 @@ static int pipe3_phy_probe(struct udevice *dev) }/* PLLCTRL */ - addr =devfdt_get_addr_size_index (dev,2 , &sz); + addr =dev_read_addr_size_index (dev,2 , &sz);if (addr ==FDT_ADDR_T_NONE ) {pr_err ("missing pll ctrl address\n" );return -EINVAL ;
Signature · 1 line
2.51.0
Re: [PATCH 1/3] phy: ti-pipe3: Use device API for DT parsing
Quoted 10 lines · Peng Fan (OSS)
From: Peng Fan <[email protected]>
Replace legacy FDT parsing in
get_reg()with the device APIdev_read_phandle_with_args()which removes direct access togd->fdt_bloband aligns the driver with modern U-Boot DT handling.The offset is retrieved from the phandle argument instead of manually parsing the property cells. Add validation for the argument count to avoid out-of-bounds access on malformed DTs.
Quoted 6 lines
Also switch from
devfdt_get_addr_size_index()todev_read_addr_size_index()for consistency with the DM API.No functional changes.
Signed-off-by Peng Fan <[email protected]>
Thanks,
Stefan
Quoted 76 lines
--- drivers/phy/ti-pipe3-phy.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-)drivers/phy/ti-pipe3-phy.c +14
-9@@ -6,6 +6,7 @@#include <dm.h> #include <dm/device.h> +#include <dm/device_compat.h> #include <generic-phy.h> #include <asm/global_data.h> #include <asm/io.h> @@ -428,10 +429,10 @@ static int pipe3_exit(struct phy *phy)static void *get_reg (struct udevice *dev,const char *name) { +struct ofnode_phandle_args phandle;struct udevice *syscon;struct regmap *regmap; -const fdt32_t *cell; -int len, err; +int err;void *base; err = uclass_get_device_by_phandle(UCLASS_SYSCON, dev,@@ -449,10 +450,14 @@ static void *get_reg(struct udevice *dev, const char *name)return NULL ; } - cell =fdt_getprop (gd->fdt_blob,dev_of_offset (dev), name, - &len); -if (len <2 *sizeof (fdt32_t)) { -pr_err ("offset not available for %s\n" , name); + err =dev_read_phandle_with_args (dev, name,NULL ,0 ,0 , &phandle); +if (err) { +dev_err (dev,"parse %s failed: %d\n" , name, err); +return NULL ; + } + +if (phandle.args_count <1 ) { +dev_err (dev,"%s: missing args\n" , name);return NULL ; }@@ -460,7 +465,7 @@ static void *get_reg(struct udevice *dev, const char *name)if (!base)return NULL ; -return fdtdec_get_number (cell +1 ,1 ) + base; +return base + phandle.args[0 ]; }static int pipe3_phy_probe (struct udevice *dev)@@ -471,7 +476,7 @@ static int pipe3_phy_probe(struct udevice *dev)struct pipe3_data *data;/* PHY_RX */ - addr =devfdt_get_addr_size_index (dev,0 , &sz); + addr =dev_read_addr_size_index (dev,0 , &sz);if (addr ==FDT_ADDR_T_NONE ) {pr_err ("missing phy_rx address\n" );return -EINVAL ;@@ -484,7 +489,7 @@ static int pipe3_phy_probe(struct udevice *dev) }/* PLLCTRL */ - addr =devfdt_get_addr_size_index (dev,2 , &sz); + addr =dev_read_addr_size_index (dev,2 , &sz);if (addr ==FDT_ADDR_T_NONE ) {pr_err ("missing pll ctrl address\n" );return -EINVAL ;
PATCH 2/3 phy: marvell: comphy: Use dev_read_addr_index_ptr()
In reply to Peng Fan (OSS)From: Peng Fan <[email protected]>
Use dev_read_addr_index_ptr() which supports both live device tree and flat DT backends, avoiding direct dependency on devfdt_* helpers.
No functional changes.
--- drivers/phy/marvell/comphy_core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/phy/marvell/comphy_core.c +2 -2
@@ -84,11 +84,11 @@ static int comphy_probe(struct udevice *dev)int res;/* Save base addresses for later use */ - chip_cfg->comphy_base_addr =devfdt_get_addr_index_ptr (dev,0 ); + chip_cfg->comphy_base_addr =dev_read_addr_index_ptr (dev,0 );if (!chip_cfg->comphy_base_addr)return -EINVAL ; - chip_cfg->hpipe3_base_addr =devfdt_get_addr_index_ptr (dev,1 ); + chip_cfg->hpipe3_base_addr =dev_read_addr_index_ptr (dev,1 );if (!chip_cfg->hpipe3_base_addr)return -EINVAL ;
Signature · 1 line
2.51.0
Re: [PATCH 2/3] phy: marvell: comphy: Use dev_read_addr_index_ptr()
Quoted 8 lines · Peng Fan (OSS)
From: Peng Fan <[email protected]>
Use
dev_read_addr_index_ptr()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]>
Thanks,
Stefan
Quoted 23 lines
--- drivers/phy/marvell/comphy_core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/phy/marvell/comphy_core.c +2
-2@@ -84,11 +84,11 @@ static int comphy_probe(struct udevice *dev)int res;/* Save base addresses for later use */ - chip_cfg->comphy_base_addr =devfdt_get_addr_index_ptr (dev,0 ); + chip_cfg->comphy_base_addr =dev_read_addr_index_ptr (dev,0 );if (!chip_cfg->comphy_base_addr)return -EINVAL ; - chip_cfg->hpipe3_base_addr =devfdt_get_addr_index_ptr (dev,1 ); + chip_cfg->hpipe3_base_addr =dev_read_addr_index_ptr (dev,1 );if (!chip_cfg->hpipe3_base_addr)return -EINVAL ;
PATCH 3/3 phy: cadence: Use device API
In reply to Peng Fan (OSS)From: Peng Fan <[email protected]>
Use dev_remap_addr_index() and dev_read_addr_size_index() which support both live device tree and flat DT backends, avoiding direct dependency on devfdt_* helpers.
No functional changes.
--- drivers/phy/cadence/phy-cadence-sierra.c | 4 ++-- drivers/phy/cadence/phy-cadence-torrent.c | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-)
drivers/phy/cadence/phy-cadence-sierra.c +2 -2
@@ -1068,12 +1068,12 @@ static int cdns_sierra_phy_probe(struct udevice *dev) sp->dev = dev; - sp->base =devfdt_remap_addr_index (dev,0 ); + sp->base =dev_remap_addr_index (dev,0 );if (!sp->base) {dev_err (dev,"unable to map regs\n" );return -ENOMEM ; } -devfdt_get_addr_size_index (dev,0 , (fdt_size_t *)&sp->size); +dev_read_addr_size_index (dev,0 , (fdt_size_t *)&sp->size);/* Get init data for this PHY */ data = (struct cdns_sierra_data *)dev_get_driver_data (dev);
drivers/phy/cadence/phy-cadence-torrent.c +4 -4
@@ -791,10 +791,10 @@ static int cdns_torrent_phy_probe(struct udevice *dev)return ret; } - cdns_phy->sd_base =devfdt_remap_addr_index (dev,0 ); -if (IS_ERR (cdns_phy->sd_base)) -return PTR_ERR (cdns_phy->sd_base); -devfdt_get_addr_size_index (dev,0 , (fdt_size_t *)&cdns_phy->size); + cdns_phy->sd_base =dev_remap_addr_index (dev,0 ); +if (!cdns_phy->sd_base) +return -EINVAL ; +dev_read_addr_size_index (dev,0 , (fdt_size_t *)&cdns_phy->size);dev_for_each_subnode (child, dev) subnodes++;
Signature · 1 line
2.51.0
Re: [PATCH 3/3] phy: cadence: Use device API
Quoted 9 lines · Peng Fan (OSS)
From: Peng Fan <[email protected]>
Use
dev_remap_addr_index()anddev_read_addr_size_index()which support both live device tree and flat DT backends, avoiding direct dependency on devfdt_* helpers.No functional changes.
Signed-off-by Peng Fan <[email protected]>
Thanks,
Stefan
Quoted 44 lines
--- drivers/phy/cadence/phy-cadence-sierra.c | 4 ++-- drivers/phy/cadence/phy-cadence-torrent.c | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-)drivers/phy/cadence/phy-cadence-sierra.c +2
-2@@ -1068,12 +1068,12 @@ static int cdns_sierra_phy_probe(struct udevice *dev) sp->dev = dev; - sp->base =devfdt_remap_addr_index (dev,0 ); + sp->base =dev_remap_addr_index (dev,0 );if (!sp->base) {dev_err (dev,"unable to map regs\n" );return -ENOMEM ; } -devfdt_get_addr_size_index (dev,0 , (fdt_size_t *)&sp->size); +dev_read_addr_size_index (dev,0 , (fdt_size_t *)&sp->size);/* Get init data for this PHY */ data = (struct cdns_sierra_data *)dev_get_driver_data (dev);drivers/phy/cadence/phy-cadence-torrent.c +4
-4@@ -791,10 +791,10 @@ static int cdns_torrent_phy_probe(struct udevice *dev)return ret; } - cdns_phy->sd_base =devfdt_remap_addr_index (dev,0 ); -if (IS_ERR (cdns_phy->sd_base)) -return PTR_ERR (cdns_phy->sd_base); -devfdt_get_addr_size_index (dev,0 , (fdt_size_t *)&cdns_phy->size); + cdns_phy->sd_base =dev_remap_addr_index (dev,0 ); +if (!cdns_phy->sd_base) +return -EINVAL ; +dev_read_addr_size_index (dev,0 , (fdt_size_t *)&cdns_phy->size);dev_for_each_subnode (child, dev) subnodes++;
Quoted 16 lines · Peng Fan (OSS)
The goal is to remove the direct usage of
devfdt_APIs in drivers. The device APIs supports both live device tree and flat DT backends, avoiding direct dependency on devfdt_* helpers.Signed-off-by Peng Fan <[email protected]>---
Peng Fan (3):
phy: ti-pipe3: Use device API for DT parsing
phy: marvell: comphy: Usedev_read_addr_index_ptr()
phy: cadence: Use device APIdrivers/phy/cadence/phy-cadence-sierra.c | 4 ++-- drivers/phy/cadence/phy-cadence-torrent.c | 8 ++++---- drivers/phy/marvell/comphy_core.c | 4 ++-- drivers/phy/ti-pipe3-phy.c | 23 ++++++++++++++--------- 4 files changed, 22 insertions(+), 17 deletions(-)
Quoted 5 lines
---
base-commit:bb354d04459f5425318aeb8a70bae995ee573f1d
change-id: 20260526-devfdt-phy-f2894541e3adBest regards,
Series added to net-next, thanks!
Signature · 1 line
Jerome