[PATCH v2 2/8] spi: cadence-xspi: wait for the controller initialization on resume

From: Nuno Sá

Date: Wed Nov 11 2026 - 08:27:36 EST


The controller IP might lose power across a system suspend (e.g. its
power domain being gated). In that case, it goes through its reset and
initialization process again on resume, which is only done when the
INIT_COMPLETED bit is set in the controller status register. However,
the resume path reconfigures the controller right away.

Add a helper to wait for the controller to complete its initialization
and use it on resume before configuring anything. If the controller did
not lose power, the bit is already set and there is nothing to wait for.

The helper will also be used after the optional hardware reset, added
in a following patch.

Signed-off-by: Nuno Sá <nuno.sa@xxxxxxxxxx>
---
drivers/spi/spi-cadence-xspi.c | 25 +++++++++++++++++++++++++
1 file changed, 25 insertions(+)

diff --git a/drivers/spi/spi-cadence-xspi.c b/drivers/spi/spi-cadence-xspi.c
index 85cf5cf81c9e..c02069715153 100644
--- a/drivers/spi/spi-cadence-xspi.c
+++ b/drivers/spi/spi-cadence-xspi.c
@@ -367,6 +367,22 @@ static int cdns_xspi_wait_for_controller_idle(struct cdns_xspi_dev *cdns_xspi)
100, 1000);
}

+static int cdns_xspi_wait_for_init(struct cdns_xspi_dev *cdns_xspi)
+{
+ u32 ctrl_stat;
+ int ret;
+
+ ret = readl_relaxed_poll_timeout(cdns_xspi->iobase +
+ CDNS_XSPI_CTRL_STATUS_REG,
+ ctrl_stat,
+ ctrl_stat & CDNS_XSPI_INIT_COMPLETED,
+ 100, 100 * USEC_PER_MSEC);
+ if (ret)
+ dev_err(cdns_xspi->dev, "Controller initialization timeout\n");
+
+ return ret;
+}
+
static void cdns_xspi_trigger_command(struct cdns_xspi_dev *cdns_xspi,
u32 cmd_regs[6])
{
@@ -1355,6 +1371,15 @@ static int cdns_xspi_suspend(struct device *dev)
static int cdns_xspi_resume(struct device *dev)
{
struct cdns_xspi_dev *cdns_xspi = dev_get_drvdata(dev);
+ int ret;
+
+ /*
+ * The controller might have lost power and so, be going through its
+ * reset and initialization process again.
+ */
+ ret = cdns_xspi_wait_for_init(cdns_xspi);
+ if (ret)
+ return ret;

#ifdef CONFIG_64BIT
if (cdns_xspi->driver_data->mrvl_hw_overlay) {

--
2.56.0