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

From: Paul Cercueil

Date: Thu Nov 12 2026 - 09:48:48 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>

---

v2: - Drop warnings. devm_ioremap_resource() already warns.

v3: No change
---
drivers/spi/spi-cadence-xspi.c | 56 ++++++++++++++++------------------
1 file changed, 27 insertions(+), 29 deletions(-)

diff --git a/drivers/spi/spi-cadence-xspi.c b/drivers/spi/spi-cadence-xspi.c
index f4ce4820b08f..8fa58a0412e3 100644
--- a/drivers/spi/spi-cadence-xspi.c
+++ b/drivers/spi/spi-cadence-xspi.c
@@ -1276,44 +1276,42 @@ static int cdns_xspi_probe(struct platform_device *pdev)
if (ret)
return -ENODEV;

- cdns_xspi->iobase = devm_platform_ioremap_resource_byname(pdev, "io");
- 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);
- }
- }
+ 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))
+ return PTR_ERR(cdns_xspi->iobase);

res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "sdma");
- cdns_xspi->sdmabase = devm_ioremap_resource(dev, res);
- if (IS_ERR(cdns_xspi->sdmabase)) {
+ if (!res)
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);
- }
+
+ cdns_xspi->sdmabase = devm_ioremap_resource(dev, res);
+ if (IS_ERR(cdns_xspi->sdmabase))
+ return PTR_ERR(cdns_xspi->sdmabase);
cdns_xspi->sdmasize = resource_size(res);

- cdns_xspi->auxbase = devm_platform_ioremap_resource_byname(pdev, "aux");
- 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);
- }
- }
+ 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))
+ 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