spi: Convert drivers to dev_read_* APIs
Subsystems (4)
v2 cover spi: Convert drivers to dev_read_* APIs
This series converts several SPI controller drivers to use the dev_read_* APIs instead of legacy devfdt_* and raw FDT helpers. The dev_read_* APIs provide a unified interface that works with both live device tree and flat device tree backends, avoiding direct dependencies on devfdt_* helpers
---
Changes in v2:
Per Simon:
- Patch 4/6 (cadence_qspi): Update commit log to note the new NULL checks for regbase/ahbbase as a behavior improvement, not "no functional changes".
- Patch 6/6 (ti_qspi): Fix dev_read_phandle_with_args() call to use cell_count=1 instead of 0 so syscon-chipselects offset arg is parsed correctly. Wrap the call to 80 columns.
Add R-b from Simon.
- Link to v1: https://lore.kernel.org/r/[email protected]
---
Peng Fan (5):
spi: spi-aspeed-smc: Use dev_read_addr_index_ptr()
spi: cadence_qspi: Use dev_read_addr_index_ptr()
spi: mtk_snor: Use dev_read_addr_ptr()
spi: nxp: Use dev_read_addr_size_name()
spi: ti_qspi: Use device APIs
drivers/spi/cadence_qspi.c | 7 +++++-- drivers/spi/mtk_snor.c | 2 +- drivers/spi/nxp_fspi.c | 8 ++++---- drivers/spi/nxp_xspi.c | 8 ++++---- drivers/spi/spi-aspeed-smc.c | 4 ++-- drivers/spi/ti_qspi.c | 22 ++++++++++------------ 6 files changed, 26 insertions(+), 25 deletions(-)
---
base-commit: 0a46055d96ac627c05180cdeaa187a9fdf6b7973
change-id: 20260526-devfdt-spi-2911c7201281
Best regards,
Signature · 1 line
Peng Fan <[email protected]>
PATCH v2 1/5 spi: spi-aspeed-smc: Use dev_read_addr_index_ptr()
From: Peng Fan <[email protected]>
Use dev_read_addr_index_ptr() and dev_read_addr_size_index_ptr() which support both live device tree and flat DT backends, avoiding direct dependency on devfdt_* helpers.
No functional changes.
--- drivers/spi/spi-aspeed-smc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/spi/spi-aspeed-smc.c +2 -2
@@ -1123,13 +1123,13 @@ static int apseed_spi_of_to_plat(struct udevice *bus)int ret;struct clk hclk; - priv->regs =devfdt_get_addr_index_ptr (bus,0 ); + priv->regs =dev_read_addr_index_ptr (bus,0 );if (!priv->regs) {dev_err (bus,"wrong ctrl base\n" );return -EINVAL ; } - plat->ahb_base =devfdt_get_addr_size_index_ptr (bus,1 , &plat->ahb_sz); + plat->ahb_base =dev_read_addr_size_index_ptr (bus,1 , &plat->ahb_sz);if (!plat->ahb_base) {dev_err (bus,"wrong AHB base\n" );return -EINVAL ;
Signature · 1 line
2.51.0
PATCH v2 2/5 spi: cadence_qspi: Use dev_read_addr_index_ptr()
In reply to Peng Fan (OSS)From: Peng Fan <[email protected]>
Replace devfdt_get_addr_index_ptr() and devfdt_get_addr_size_index_ptr() with dev_read_addr_index_ptr() and dev_read_addr_size_index_ptr() which support both live device tree and flat DT backends.
Add NULL checks for regbase and ahbbase so the driver returns -EINVAL early when the reg property is missing or cannot be mapped, instead of silently storing NULL and crashing on a later access.
--- drivers/spi/cadence_qspi.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/spi/cadence_qspi.c +5 -2
@@ -418,8 +418,11 @@ static int cadence_spi_of_to_plat(struct udevice *bus)struct cadence_spi_priv *priv =dev_get_priv (bus);ofnode subnode; - plat->regbase =devfdt_get_addr_index_ptr (bus,0 ); - plat->ahbbase =devfdt_get_addr_size_index_ptr (bus,1 , &plat->ahbsize); + plat->regbase =dev_read_addr_index_ptr (bus,0 ); + plat->ahbbase =dev_read_addr_size_index_ptr (bus,1 , &plat->ahbsize); +if (!plat->regbase || !plat->ahbbase) +return -EINVAL ; + plat->is_decoded_cs =dev_read_bool (bus,"cdns,is-decoded-cs" ); plat->fifo_depth =dev_read_u32_default (bus,"cdns,fifo-depth" ,128 ); plat->fifo_width =dev_read_u32_default (bus,"cdns,fifo-width" ,4 );
Signature · 1 line
2.51.0
PATCH v2 3/5 spi: mtk_snor: Use dev_read_addr_ptr()
In reply to Peng Fan (OSS)From: Peng Fan <[email protected]>
Use dev_read_addr_ptr() which supports both live device tree and flat DT backends, avoiding direct dependency on devfdt_* helpers.
No functional changes.
--- drivers/spi/mtk_snor.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/spi/mtk_snor.c +1 -1
@@ -528,7 +528,7 @@ static int mtk_snor_probe(struct udevice *bus)u8 *buffer;int ret; - priv->base =devfdt_get_addr_ptr (bus); + priv->base =dev_read_addr_ptr (bus);if (!priv->base)return -EINVAL ;
Signature · 1 line
2.51.0
Re: [PATCH v2 3/5] spi: mtk_snor: Use dev_read_addr_ptr()
Quoted 20 lines · Peng Fan (OSS)
From: Peng Fan <[email protected]>
Use
dev_read_addr_ptr()which supports both live device tree and flat DT backends, avoiding direct dependency on devfdt_* helpers.No functional changes.
Reviewed-by Simon Glass <[email protected]>Reviewed-by Weijie Gao <[email protected]>Signed-off-by Peng Fan <[email protected]>--- drivers/spi/mtk_snor.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/spi/mtk_snor.c +0
-0
drivers/spi/mtk_snor.c static int mtk_snor_probe(struct udevice *bus) · line 534
Quoted 8 lines
drivers/spi/mtk_snor.c +1
-1@@ -528,7 +528,7 @@ static int mtk_snor_probe(struct udevice *bus)u8 *buffer;int ret; - priv->base =devfdt_get_addr_ptr (bus); + priv->base =dev_read_addr_ptr (bus);if (!priv->base)return -EINVAL ;
PATCH v2 4/5 spi: nxp: Use dev_read_addr_size_name()
In reply to Peng Fan (OSS)From: Peng Fan <[email protected]>
Use dev_read_addr_size_name() which supports both live device tree and flat DT backends, avoiding direct dependency on devfdt_* helpers.
Also correct type of size to 'fdt_size_t'.
No functional changes.
--- drivers/spi/nxp_fspi.c | 8 ++++---- drivers/spi/nxp_xspi.c | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-)
drivers/spi/nxp_fspi.c +4 -4
@@ -1050,20 +1050,20 @@ static int nxp_fspi_of_to_plat(struct udevice *bus)#endif fdt_addr_t iobase; -fdt_addr_t iobase_size; +fdt_size_t iobase_size;fdt_addr_t ahb_addr; -fdt_addr_t ahb_size; +fdt_size_t ahb_size; f->dev = bus; - iobase =devfdt_get_addr_size_name (bus,"fspi_base" , &iobase_size); + iobase =dev_read_addr_size_name (bus,"fspi_base" , &iobase_size);if (iobase ==FDT_ADDR_T_NONE ) {dev_err (bus,"fspi_base regs missing\n" );return -ENODEV ; } f->iobase =map_physmem (iobase, iobase_size,MAP_NOCACHE ); - ahb_addr =devfdt_get_addr_size_name (bus,"fspi_mmap" , &ahb_size); + ahb_addr =dev_read_addr_size_name (bus,"fspi_mmap" , &ahb_size);if (ahb_addr ==FDT_ADDR_T_NONE ) {dev_err (bus,"fspi_mmap regs missing\n" );return -ENODEV ;
drivers/spi/nxp_xspi.c +4 -4
@@ -711,9 +711,9 @@ static int nxp_xspi_of_to_plat(struct udevice *bus) {struct nxp_xspi *x =dev_get_priv (bus);fdt_addr_t iobase; -fdt_addr_t iobase_size; +fdt_size_t iobase_size;fdt_addr_t ahb_addr; -fdt_addr_t ahb_size; +fdt_size_t ahb_size;#if CONFIG_IS_ENABLED (CLK )int ret;
@@ -721,14 +721,14 @@ static int nxp_xspi_of_to_plat(struct udevice *bus) x->dev = bus; - iobase =devfdt_get_addr_size_name (bus,"xspi_base" , &iobase_size); + iobase =dev_read_addr_size_name (bus,"xspi_base" , &iobase_size);if (iobase ==FDT_ADDR_T_NONE ) {dev_err (bus,"xspi_base regs missing\n" );return -ENODEV ; } x->iobase = iobase; - ahb_addr =devfdt_get_addr_size_name (bus,"xspi_mmap" , &ahb_size); + ahb_addr =dev_read_addr_size_name (bus,"xspi_mmap" , &ahb_size);if (ahb_addr ==FDT_ADDR_T_NONE ) {dev_err (bus,"xspi_mmap regs missing\n" );return -ENODEV ;
Signature · 1 line
2.51.0
PATCH v2 5/5 spi: ti_qspi: Use device APIs
In reply to Peng Fan (OSS)From: Peng Fan <[email protected]>
Convert the driver to use driver model APIs for phandle parsing and address handling instead of legacy FDT interfaces.
Replace fdt_getprop() parsing of "syscon-chipselects" with dev_read_phandle_with_args(), and switch address-related helpers from devfdt_*() to dev_read_*() variants.
Also update "num-cs" handling to use dev_read_u32_default().
Remove direct dependencies on gd->fdt_blob and simplify the code while keeping the existing behavior.
No functional changes.
--- drivers/spi/ti_qspi.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-)
drivers/spi/ti_qspi.c +10 -12
@@ -417,10 +417,10 @@ static int ti_qspi_probe(struct udevice *bus)static void *map_syscon_chipselects (struct udevice *bus) {#if CONFIG_IS_ENABLED (SYSCON ) +struct ofnode_phandle_args args;struct udevice *syscon;struct regmap *regmap; -const fdt32_t *cell; -int len, err; +int err; err =uclass_get_device_by_phandle (UCLASS_SYSCON , bus,"syscon-chipselects" , &syscon);
@@ -437,17 +437,17 @@ static void *map_syscon_chipselects(struct udevice *bus) return NULL; } - cell =fdt_getprop (gd->fdt_blob,dev_of_offset (bus), -"syscon-chipselects" , &len); -if (len <2 *sizeof (fdt32_t)) { + err =dev_read_phandle_with_args (bus,"syscon-chipselects" ,NULL , +1 ,0 , &args); +if (err || args.args_count <1 ) {debug ("%s: offset not available\n" , __func__);return NULL ; } -return fdtdec_get_number (cell +1 ,1 ) +regmap_get_range (regmap,0 ); +return args.args[0 ] +regmap_get_range (regmap,0 );#else fdt_addr_t addr; - addr =devfdt_get_addr_index (bus,2 ); + addr =dev_read_addr_index (bus,2 );return (addr ==FDT_ADDR_T_NONE ) ?NULL :map_physmem (addr,0 ,MAP_NOCACHE );#endif
@@ -456,15 +456,13 @@ static void *map_syscon_chipselects(struct udevice *bus)static int ti_qspi_of_to_plat (struct udevice *bus) {struct ti_qspi_priv *priv =dev_get_priv (bus); -const void *blob = gd->fdt_blob; -int node =dev_of_offset (bus);fdt_addr_t mmap_addr; -fdt_addr_t mmap_size; +fdt_size_t mmap_size; priv->ctrl_mod_mmap =map_syscon_chipselects (bus); priv->base =map_physmem (dev_read_addr (bus),sizeof (struct ti_qspi_regs ),MAP_NOCACHE ); - mmap_addr =devfdt_get_addr_size_index (bus,1 , &mmap_size); + mmap_addr =dev_read_addr_size_index (bus,1 , &mmap_size); priv->memory_map =map_physmem (mmap_addr, mmap_size,MAP_NOCACHE ); priv->mmap_size = mmap_size;
@@ -473,7 +471,7 @@ static int ti_qspi_of_to_plat(struct udevice *bus)debug ("Error: Max frequency missing\n" );return -ENODEV ; } - priv->num_cs =fdtdec_get_int (blob, node,"num-cs" ,4 ); + priv->num_cs =dev_read_u32_default (bus,"num-cs" ,4 );debug ("%s: regs=<0x%x>, max-frequency=%d\n" , __func__, (int )priv->base, priv->max_hz);
Signature · 1 line
2.51.0
Re: [PATCH v2 5/5] spi: ti_qspi: Use device APIs
Quoted 14 lines · Peng Fan (OSS)
spi:
ti_qspi: Use device APIsConvert the driver to use driver model APIs for phandle parsing and address handling instead of legacy FDT interfaces.
Replace
fdt_getprop()parsing of 'syscon-chipselects' withdev_read_phandle_with_args(), and switch address-related helpers from devfdt_*() to dev_read_*() variants.Also update 'num-cs' handling to use
dev_read_u32_default().Remove direct dependencies on
gd->fdt_bloband simplify the code while keeping the existing behavior.
Quoted 6 lines
No functional changes.
Signed-off-by Peng Fan <[email protected]>
drivers/spi/ti_qspi.c| 22 ++++++++++------------1 file changed, 10 insertions(+), 12 deletions(-)
Hi Peng,
Quoted 7 lines · Peng Fan (OSS)
Changes in v2:
Per Simon:
- Patch 4/6 (cadence_qspi): Update commit log to note the new NULL checks for regbase/ahbbase as a behavior improvement, not "no functional changes".
- Patch 6/6 (ti_qspi): Fixdev_read_phandle_with_args()call to use cell_count=1 instead of 0 so syscon-chipselects offset arg is parsed correctly. Wrap the call to 80 columns.
BTW these numbers look like leftovers from v1.
Regards,
Simon
Quoted 8 lines · Peng Fan (OSS)
This series converts several SPI controller drivers to use the dev_read_* APIs instead of legacy devfdt_* and raw FDT helpers. The dev_read_* APIs provide a unified interface that works with both live device tree and flat device tree backends, avoiding direct dependencies on devfdt_* helpers
[...]
Applied to u-boot/next, thanks!
[1/5] spi: spi-aspeed-smc: Use dev_read_addr_index_ptr()
commit: 0cfbd5e28625f2a7fe57ed13368015e7b780a7f1
[2/5] spi: cadence_qspi: Use dev_read_addr_index_ptr()
commit: f2d8cf8fd54dd245ce9de2637753345ceb75d382
[3/5] spi: mtk_snor: Use dev_read_addr_ptr()
commit: b6bd9bd4822407d9aa668f88c4c39313e1ba7fe5
[4/5] spi: nxp: Use dev_read_addr_size_name()
commit: 4299c00b6de080beef48e6c1575f7e1d2d82e16c
[5/5] spi: ti_qspi: Use device APIs
commit: 73bc5e1695abb595e65198123df402faa64619ceSignature · 1 line
Tom