[PATCH 4/5] spi: cadence-xspi: Rework resource discovery

From: Paul Cercueil

Date: Wed Nov 04 2026 - 05:11:47 EST


From: Tanmay Jagdale <tanmay@xxxxxxxxxxx>

The previous code worked, but calling
devm_platform_ioremap_resource_byname() on ACPI where resources aren't
named causes warnings to be printed, one per call:

cadence-xspi PRP0001:02: error -EINVAL: invalid resource (null)
cadence-xspi PRP0001:02: error -EINVAL: invalid resource (null)
cadence-xspi PRP0001:02: error -EINVAL: invalid resource (null)
cadence-xspi PRP0001:02: error -EINVAL: invalid resource (null)

We can avoid these warnings by first obtaining a pointer to the resource
with platform_get_resource_byname() and fallback to
platform_get_resource() if it fails, and then ioremap the resource using
devm_ioremap_resource().

Signed-off-by: Tanmay Jagdale <tanmay@xxxxxxxxxxx>
Co-developed-by: Paul Cercueil <paul.cercueil@xxxxxxxxxxx>
Signed-off-by: Paul Cercueil <paul.cercueil@xxxxxxxxxxx>
---
drivers/spi/spi-cadence-xspi.c | 50 ++++++++++++++++++----------------
1 file changed, 27 insertions(+), 23 deletions(-)

diff --git a/drivers/spi/spi-cadence-xspi.c b/drivers/spi/spi-cadence-xspi.c
index 04c873f28ea6..48a109f3fcdb 100644
--- a/drivers/spi/spi-cadence-xspi.c
+++ b/drivers/spi/spi-cadence-xspi.c
@@ -1269,44 +1269,48 @@ static int cdns_xspi_probe(struct platform_device *pdev)
if (ret)
return -ENODEV;

- cdns_xspi->iobase = devm_platform_ioremap_resource_byname(pdev, "io");
+ res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "io");
+ if (!res)
+ res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+
+ cdns_xspi->iobase = devm_ioremap_resource(dev, res);
if (IS_ERR(cdns_xspi->iobase)) {
- cdns_xspi->iobase = devm_platform_ioremap_resource(pdev, 0);
- if (IS_ERR(cdns_xspi->iobase)) {
- dev_err(dev, "Failed to remap controller base address\n");
- return PTR_ERR(cdns_xspi->iobase);
- }
+ dev_err(dev, "Failed to remap controller base address\n");
+ return PTR_ERR(cdns_xspi->iobase);
}

res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "sdma");
+ if (!res)
+ res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
+
cdns_xspi->sdmabase = devm_ioremap_resource(dev, res);
if (IS_ERR(cdns_xspi->sdmabase)) {
- res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
- cdns_xspi->sdmabase = devm_ioremap_resource(dev, res);
- if (IS_ERR(cdns_xspi->sdmabase))
- return PTR_ERR(cdns_xspi->sdmabase);
+ dev_err(dev, "Failed to remap sdma address\n");
+ return PTR_ERR(cdns_xspi->sdmabase);
}
cdns_xspi->sdmasize = resource_size(res);

- cdns_xspi->auxbase = devm_platform_ioremap_resource_byname(pdev, "aux");
+ res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "aux");
+ if (!res)
+ res = platform_get_resource(pdev, IORESOURCE_MEM, 2);
+
+ cdns_xspi->auxbase = devm_ioremap_resource(dev, res);
if (IS_ERR(cdns_xspi->auxbase)) {
- cdns_xspi->auxbase = devm_platform_ioremap_resource(pdev, 2);
- if (IS_ERR(cdns_xspi->auxbase)) {
- dev_err(dev, "Failed to remap AUX address\n");
- return PTR_ERR(cdns_xspi->auxbase);
- }
+ dev_err(dev, "Failed to remap AUX address\n");
+ return PTR_ERR(cdns_xspi->auxbase);
}

#ifdef CONFIG_64BIT
if (cdns_xspi->driver_data->mrvl_hw_overlay) {
- cdns_xspi->xferbase = devm_platform_ioremap_resource_byname(pdev, "xfer");
+ res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "xfer");
+ if (!res)
+ res = platform_get_resource(pdev, IORESOURCE_MEM, 3);
+
+ cdns_xspi->xferbase = devm_ioremap_resource(dev, res);
if (IS_ERR(cdns_xspi->xferbase)) {
- cdns_xspi->xferbase = devm_platform_ioremap_resource(pdev, 3);
- if (IS_ERR(cdns_xspi->xferbase)) {
- dev_info(dev, "XFER register base not found, set it\n");
- // For compatibility with older firmware
- cdns_xspi->xferbase = cdns_xspi->iobase + 0x8000;
- }
+ dev_info(dev, "XFER register base not found, set it\n");
+ // For compatibility with older firmware
+ cdns_xspi->xferbase = cdns_xspi->iobase + 0x8000;
}
}
#endif
--
2.47.3