[PATCH v2 5/8] spi: cadence-xspi: move platform specifics into driver data

From: Nuno Sá

Date: Wed Nov 11 2026 - 08:23:45 EST


The driver uses a mrvl_hw_overlay boolean in the driver data to decide,
at several points in the common probe and resume paths, whether the
Marvell integration specifics have to be applied. Adding another
integration would mean adding more of these conditionals.

Turn the driver data into a set of per-compatible operations instead,
including two optional callbacks: init(), for one time vendor specific
initialization at probe, and hw_init(), for the vendor specific hardware
setup done both at probe and resume. The probe and resume paths now just
use these.

The Marvell XFER register mapping moves into init() while the clock
setup and PHY configuration move into hw_init(). Since the PHY timing
values were only ever the Marvell ones, drop them from the driver data
and write the constants directly, and rename the helper to
cdns_mrvl_xspi_configure_phy() to make that explicit.

No functional change intended.

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

diff --git a/drivers/spi/spi-cadence-xspi.c b/drivers/spi/spi-cadence-xspi.c
index 5d8d102ef397..d592512dda63 100644
--- a/drivers/spi/spi-cadence-xspi.c
+++ b/drivers/spi/spi-cadence-xspi.c
@@ -306,22 +306,6 @@ enum cdns_xspi_stig_cmd_dir {
CDNS_XSPI_STIG_CMD_DIR_WRITE,
};

-struct cdns_xspi_driver_data {
- bool mrvl_hw_overlay;
- u32 dll_phy_ctrl;
- u32 ctb_rfile_phy_ctrl;
- u32 rfile_phy_tsel;
- u32 rfile_phy_dq_timing;
- u32 rfile_phy_dqs_timing;
- u32 rfile_phy_gate_lpbk_ctrl;
- u32 rfile_phy_dll_master_ctrl;
- u32 rfile_phy_dll_slave_ctrl;
-};
-
-static struct cdns_xspi_driver_data cdns_driver_data = {
- .mrvl_hw_overlay = false,
-};
-
struct cdns_xspi_dev {
struct platform_device *pdev;
struct spi_controller *host;
@@ -357,6 +341,17 @@ struct cdns_xspi_dev {
int current_xfer_qword;
};

+struct cdns_xspi_driver_data {
+ const struct spi_controller_mem_ops *mem_ops;
+ int (*transfer_one_message)(struct spi_controller *ctlr,
+ struct spi_message *msg);
+ int (*sdma_handler)(struct cdns_xspi_dev *cdns_xspi);
+ void (*set_interrupts_handler)(struct cdns_xspi_dev *cdns_xspi,
+ bool enabled);
+ int (*init)(struct cdns_xspi_dev *cdns_xspi);
+ int (*hw_init)(struct cdns_xspi_dev *cdns_xspi);
+};
+
static int cdns_xspi_wait_for_controller_idle(struct cdns_xspi_dev *cdns_xspi)
{
u32 ctrl_stat;
@@ -794,18 +789,6 @@ static void cdns_xspi_print_phy_config(struct cdns_xspi_dev *cdns_xspi)
}

#ifdef CONFIG_64BIT
-static struct cdns_xspi_driver_data marvell_driver_data = {
- .mrvl_hw_overlay = true,
- .dll_phy_ctrl = MARVELL_REGS_DLL_PHY_CTRL,
- .ctb_rfile_phy_ctrl = MARVELL_CTB_RFILE_PHY_CTRL,
- .rfile_phy_tsel = MARVELL_RFILE_PHY_TSEL,
- .rfile_phy_dq_timing = MARVELL_RFILE_PHY_DQ_TIMING,
- .rfile_phy_dqs_timing = MARVELL_RFILE_PHY_DQS_TIMING,
- .rfile_phy_gate_lpbk_ctrl = MARVELL_RFILE_PHY_GATE_LPBK_CTRL,
- .rfile_phy_dll_master_ctrl = MARVELL_RFILE_PHY_DLL_MASTER_CTRL,
- .rfile_phy_dll_slave_ctrl = MARVELL_RFILE_PHY_DLL_SLAVE_CTRL,
-};
-
static const int cdns_mrvl_xspi_clk_div_list[] = {
4, //0x0 = Divide by 4. SPI clock is 200 MHz.
6, //0x1 = Divide by 6. SPI clock is 133.33 MHz.
@@ -844,23 +827,23 @@ static bool cdns_xspi_is_dll_locked(struct cdns_xspi_dev *cdns_xspi)
}

/* Static configuration of PHY */
-static bool cdns_xspi_configure_phy(struct cdns_xspi_dev *cdns_xspi)
+static bool cdns_mrvl_xspi_configure_phy(struct cdns_xspi_dev *cdns_xspi)
{
- writel(cdns_xspi->driver_data->dll_phy_ctrl,
+ writel(MARVELL_REGS_DLL_PHY_CTRL,
cdns_xspi->iobase + CDNS_XSPI_RF_MINICTRL_REGS_DLL_PHY_CTRL);
- writel(cdns_xspi->driver_data->ctb_rfile_phy_ctrl,
+ writel(MARVELL_CTB_RFILE_PHY_CTRL,
cdns_xspi->auxbase + CDNS_XSPI_PHY_CTB_RFILE_PHY_CTRL);
- writel(cdns_xspi->driver_data->rfile_phy_tsel,
+ writel(MARVELL_RFILE_PHY_TSEL,
cdns_xspi->auxbase + CDNS_XSPI_PHY_CTB_RFILE_PHY_TSEL);
- writel(cdns_xspi->driver_data->rfile_phy_dq_timing,
+ writel(MARVELL_RFILE_PHY_DQ_TIMING,
cdns_xspi->auxbase + CDNS_XSPI_PHY_DATASLICE_RFILE_PHY_DQ_TIMING);
- writel(cdns_xspi->driver_data->rfile_phy_dqs_timing,
+ writel(MARVELL_RFILE_PHY_DQS_TIMING,
cdns_xspi->auxbase + CDNS_XSPI_PHY_DATASLICE_RFILE_PHY_DQS_TIMING);
- writel(cdns_xspi->driver_data->rfile_phy_gate_lpbk_ctrl,
+ writel(MARVELL_RFILE_PHY_GATE_LPBK_CTRL,
cdns_xspi->auxbase + CDNS_XSPI_PHY_DATASLICE_RFILE_PHY_GATE_LPBK_CTRL);
- writel(cdns_xspi->driver_data->rfile_phy_dll_master_ctrl,
+ writel(MARVELL_RFILE_PHY_DLL_MASTER_CTRL,
cdns_xspi->auxbase + CDNS_XSPI_PHY_DATASLICE_RFILE_PHY_DLL_MASTER_CTRL);
- writel(cdns_xspi->driver_data->rfile_phy_dll_slave_ctrl,
+ writel(MARVELL_RFILE_PHY_DLL_SLAVE_CTRL,
cdns_xspi->auxbase + CDNS_XSPI_PHY_DATASLICE_RFILE_PHY_DLL_SLAVE_CTRL);

cdns_xspi_reset_dll(cdns_xspi);
@@ -1231,6 +1214,31 @@ static int cdns_xspi_transfer_one_message_b0(struct spi_controller *controller,

return 0;
}
+
+static int cdns_mrvl_xspi_init(struct cdns_xspi_dev *cdns_xspi)
+{
+ struct platform_device *pdev = cdns_xspi->pdev;
+
+ cdns_xspi->xferbase = devm_platform_ioremap_resource_byname(pdev, "xfer");
+ if (IS_ERR(cdns_xspi->xferbase)) {
+ cdns_xspi->xferbase = devm_platform_ioremap_resource(pdev, 3);
+ if (IS_ERR(cdns_xspi->xferbase)) {
+ dev_info(cdns_xspi->dev, "XFER register base not found, set it\n");
+ // For compatibility with older firmware
+ cdns_xspi->xferbase = cdns_xspi->iobase + 0x8000;
+ }
+ }
+
+ return 0;
+}
+
+static int cdns_mrvl_xspi_hw_init(struct cdns_xspi_dev *cdns_xspi)
+{
+ cdns_mrvl_xspi_setup_clock(cdns_xspi, MRVL_DEFAULT_CLK);
+ cdns_mrvl_xspi_configure_phy(cdns_xspi);
+
+ return 0;
+}
#endif

static int cdns_xspi_probe(struct platform_device *pdev)
@@ -1256,17 +1264,10 @@ static int cdns_xspi_probe(struct platform_device *pdev)
if (!cdns_xspi->driver_data)
return -ENODEV;

- host->mem_ops = &cadence_xspi_mem_ops;
- cdns_xspi->sdma_handler = &cdns_xspi_sdma_handle;
- cdns_xspi->set_interrupts_handler = &cdns_xspi_set_interrupts;
-#ifdef CONFIG_64BIT
- if (cdns_xspi->driver_data->mrvl_hw_overlay) {
- host->mem_ops = &marvell_xspi_mem_ops;
- host->transfer_one_message = cdns_xspi_transfer_one_message_b0;
- cdns_xspi->sdma_handler = &marvell_xspi_sdma_handle;
- cdns_xspi->set_interrupts_handler = &marvell_xspi_set_interrupts;
- }
-#endif
+ host->mem_ops = cdns_xspi->driver_data->mem_ops;
+ host->transfer_one_message = cdns_xspi->driver_data->transfer_one_message;
+ cdns_xspi->sdma_handler = cdns_xspi->driver_data->sdma_handler;
+ cdns_xspi->set_interrupts_handler = cdns_xspi->driver_data->set_interrupts_handler;
host->bus_num = -1;

platform_set_drvdata(pdev, cdns_xspi);
@@ -1312,19 +1313,11 @@ static int cdns_xspi_probe(struct platform_device *pdev)
}
}

-#ifdef CONFIG_64BIT
- if (cdns_xspi->driver_data->mrvl_hw_overlay) {
- cdns_xspi->xferbase = devm_platform_ioremap_resource_byname(pdev, "xfer");
- 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;
- }
- }
+ if (cdns_xspi->driver_data->init) {
+ ret = cdns_xspi->driver_data->init(cdns_xspi);
+ if (ret)
+ return ret;
}
-#endif

/* Optional to keep compatibility with existing devicetrees */
clk = devm_clk_get_optional_enabled(dev, NULL);
@@ -1356,12 +1349,11 @@ static int cdns_xspi_probe(struct platform_device *pdev)
return ret;
}

-#ifdef CONFIG_64BIT
- if (cdns_xspi->driver_data->mrvl_hw_overlay) {
- cdns_mrvl_xspi_setup_clock(cdns_xspi, MRVL_DEFAULT_CLK);
- cdns_xspi_configure_phy(cdns_xspi);
+ if (cdns_xspi->driver_data->hw_init) {
+ ret = cdns_xspi->driver_data->hw_init(cdns_xspi);
+ if (ret)
+ return ret;
}
-#endif

cdns_xspi_print_phy_config(cdns_xspi);

@@ -1404,12 +1396,11 @@ static int cdns_xspi_resume(struct device *dev)
if (ret)
return ret;

-#ifdef CONFIG_64BIT
- if (cdns_xspi->driver_data->mrvl_hw_overlay) {
- cdns_mrvl_xspi_setup_clock(cdns_xspi, MRVL_DEFAULT_CLK);
- cdns_xspi_configure_phy(cdns_xspi);
+ if (cdns_xspi->driver_data->hw_init) {
+ ret = cdns_xspi->driver_data->hw_init(cdns_xspi);
+ if (ret)
+ return ret;
}
-#endif

cdns_xspi->set_interrupts_handler(cdns_xspi, false);

@@ -1419,6 +1410,23 @@ static int cdns_xspi_resume(struct device *dev)
static DEFINE_SIMPLE_DEV_PM_OPS(cdns_xspi_pm_ops,
cdns_xspi_suspend, cdns_xspi_resume);

+static const struct cdns_xspi_driver_data cdns_driver_data = {
+ .mem_ops = &cadence_xspi_mem_ops,
+ .sdma_handler = cdns_xspi_sdma_handle,
+ .set_interrupts_handler = cdns_xspi_set_interrupts,
+};
+
+#ifdef CONFIG_64BIT
+static const struct cdns_xspi_driver_data marvell_driver_data = {
+ .mem_ops = &marvell_xspi_mem_ops,
+ .transfer_one_message = cdns_xspi_transfer_one_message_b0,
+ .sdma_handler = marvell_xspi_sdma_handle,
+ .set_interrupts_handler = marvell_xspi_set_interrupts,
+ .init = cdns_mrvl_xspi_init,
+ .hw_init = cdns_mrvl_xspi_hw_init,
+};
+#endif
+
static const struct of_device_id cdns_xspi_of_match[] = {
{
.compatible = "cdns,xspi-nor",

--
2.56.0