* [PATCH RFC 0/2] Add target mode support for the DesignWare SPI controller
@ 2025-10-02 12:14 Benoît Monin
2025-10-02 12:14 ` [PATCH RFC 1/2] spi: dw: rename the spi controller to ctlr Benoît Monin
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Benoît Monin @ 2025-10-02 12:14 UTC (permalink / raw)
To: Mark Brown
Cc: Thomas Petazzoni, Vladimir Kondratiev, Tawfik Bayouk, linux-spi,
linux-kernel, Benoît Monin
The DesignWare SPI controller can act as a host or a target; the
choice between the two is set in hardware and cannot be changed by
software. When configured in target mode, the controller has a much
reduced set of capabilities. It only has a single chip-select input and
can only run standard SPI mode (no dual, quad, or octal mode). Despite
this, the overall logic of doing an SPI transfer and the register layout
is identical between both modes, so implementing the target mode reuses
much of the existing code.
The first part of this two-patch series renames the spi_controller to
ctlr instead of host and also changes the suffix of the related functions
to controller. This is done to avoid confusion when referring to the
controller in target mode.
The second patch implements the target mode support by allocating an
SPI controller of the correct type based on the spi-slave property. The
controller is then configured differently depending on the mode. For
an SPI transfer, the same transfer_one() callback is used, with the
difference being in dw_spi_update_config() where only the CTRLR0
register is set. The other registers are not relevant in target mode
and are read-only.
I am posting this as an RFC because I could only perform partial testing
on my setup. I am using an SoC with two DesignWare SPI memory-mapped
controllers identified as Synopsys DWC APB SSI v4.03, one in host mode and
the other in target mode. On the evaluation board, a microcontroller acts
as an SPI relay between the two, but it has some limitations. The number
of bits per word is fixed, as are the clock phase and polarity. It also
only copies data from the host to the target. With this limited setup,
I did test that data can be successfully transferred from the host
to the target using spidev_test. I also checked that polling works by
temporarily disabling the IRQ, but I cannot test DMA. Therefore, more
testing on different devices would be welcome.
Signed-off-by: Benoît Monin <benoit.monin@bootlin.com>
---
Benoît Monin (2):
spi: dw: rename the spi controller to ctlr
spi: dw: add target mode support
drivers/spi/spi-dw-bt1.c | 4 +-
drivers/spi/spi-dw-core.c | 188 +++++++++++++++++++++++++++-------------------
drivers/spi/spi-dw-dma.c | 22 +++---
drivers/spi/spi-dw-mmio.c | 9 +--
drivers/spi/spi-dw-pci.c | 8 +-
drivers/spi/spi-dw.h | 12 +--
6 files changed, 135 insertions(+), 108 deletions(-)
---
base-commit: e5f0a698b34ed76002dc5cff3804a61c80233a7a
change-id: 20250910-spi-dw-target-5b299400917b
Best regards,
--
Benoît Monin, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH RFC 1/2] spi: dw: rename the spi controller to ctlr
2025-10-02 12:14 [PATCH RFC 0/2] Add target mode support for the DesignWare SPI controller Benoît Monin
@ 2025-10-02 12:14 ` Benoît Monin
2025-10-02 12:14 ` [PATCH RFC 2/2] spi: dw: add target mode support Benoît Monin
2025-10-15 12:14 ` [PATCH RFC 0/2] Add target mode support for the DesignWare SPI controller Mark Brown
2 siblings, 0 replies; 4+ messages in thread
From: Benoît Monin @ 2025-10-02 12:14 UTC (permalink / raw)
To: Mark Brown
Cc: Thomas Petazzoni, Vladimir Kondratiev, Tawfik Bayouk, linux-spi,
linux-kernel, Benoît Monin
Since the designware SPI controller can act as both a target and a host,
rename spi_controller member of the dw_spi struct to ctlr instead of host.
Similarly, rename the functions handling the controller, using controller
instead of host as the suffix.
No functional changes intended.
Signed-off-by: Benoît Monin <benoit.monin@bootlin.com>
---
drivers/spi/spi-dw-bt1.c | 4 +-
drivers/spi/spi-dw-core.c | 128 +++++++++++++++++++++++-----------------------
drivers/spi/spi-dw-dma.c | 22 ++++----
drivers/spi/spi-dw-mmio.c | 4 +-
drivers/spi/spi-dw-pci.c | 8 +--
drivers/spi/spi-dw.h | 12 ++---
6 files changed, 89 insertions(+), 89 deletions(-)
diff --git a/drivers/spi/spi-dw-bt1.c b/drivers/spi/spi-dw-bt1.c
index 4a5be813efa75e3606b5dd546f0678ed68794d6e..91642e05ac6077cfb68dfd0ef6acf7cca960f211 100644
--- a/drivers/spi/spi-dw-bt1.c
+++ b/drivers/spi/spi-dw-bt1.c
@@ -288,7 +288,7 @@ static int dw_spi_bt1_probe(struct platform_device *pdev)
pm_runtime_enable(&pdev->dev);
- ret = dw_spi_add_host(&pdev->dev, dws);
+ ret = dw_spi_add_controller(&pdev->dev, dws);
if (ret) {
pm_runtime_disable(&pdev->dev);
return ret;
@@ -303,7 +303,7 @@ static void dw_spi_bt1_remove(struct platform_device *pdev)
{
struct dw_spi_bt1 *dwsbt1 = platform_get_drvdata(pdev);
- dw_spi_remove_host(&dwsbt1->dws);
+ dw_spi_remove_controller(&dwsbt1->dws);
pm_runtime_disable(&pdev->dev);
}
diff --git a/drivers/spi/spi-dw-core.c b/drivers/spi/spi-dw-core.c
index b3b883cb954107ea631d12c1ef1074046cff39a7..90dea6f9b3dab773204c667cb12f3ecaef1d7108 100644
--- a/drivers/spi/spi-dw-core.c
+++ b/drivers/spi/spi-dw-core.c
@@ -63,7 +63,7 @@ static void dw_spi_debugfs_init(struct dw_spi *dws)
{
char name[32];
- snprintf(name, 32, "dw_spi%d", dws->host->bus_num);
+ snprintf(name, 32, "dw_spi%d", dws->ctlr->bus_num);
dws->debugfs = debugfs_create_dir(name, NULL);
dws->regset.regs = dw_spi_dbgfs_regs;
@@ -185,25 +185,25 @@ int dw_spi_check_status(struct dw_spi *dws, bool raw)
irq_status = dw_readl(dws, DW_SPI_ISR);
if (irq_status & DW_SPI_INT_RXOI) {
- dev_err(&dws->host->dev, "RX FIFO overflow detected\n");
+ dev_err(&dws->ctlr->dev, "RX FIFO overflow detected\n");
ret = -EIO;
}
if (irq_status & DW_SPI_INT_RXUI) {
- dev_err(&dws->host->dev, "RX FIFO underflow detected\n");
+ dev_err(&dws->ctlr->dev, "RX FIFO underflow detected\n");
ret = -EIO;
}
if (irq_status & DW_SPI_INT_TXOI) {
- dev_err(&dws->host->dev, "TX FIFO overflow detected\n");
+ dev_err(&dws->ctlr->dev, "TX FIFO overflow detected\n");
ret = -EIO;
}
/* Generically handle the erroneous situation */
if (ret) {
dw_spi_reset_chip(dws);
- if (dws->host->cur_msg)
- dws->host->cur_msg->status = ret;
+ if (dws->ctlr->cur_msg)
+ dws->ctlr->cur_msg->status = ret;
}
return ret;
@@ -215,7 +215,7 @@ static irqreturn_t dw_spi_transfer_handler(struct dw_spi *dws)
u16 irq_status = dw_readl(dws, DW_SPI_ISR);
if (dw_spi_check_status(dws, false)) {
- spi_finalize_current_transfer(dws->host);
+ spi_finalize_current_transfer(dws->ctlr);
return IRQ_HANDLED;
}
@@ -229,7 +229,7 @@ static irqreturn_t dw_spi_transfer_handler(struct dw_spi *dws)
dw_reader(dws);
if (!dws->rx_len) {
dw_spi_mask_intr(dws, 0xff);
- spi_finalize_current_transfer(dws->host);
+ spi_finalize_current_transfer(dws->ctlr);
} else if (dws->rx_len <= dw_readl(dws, DW_SPI_RXFTLR)) {
dw_writel(dws, DW_SPI_RXFTLR, dws->rx_len - 1);
}
@@ -250,14 +250,14 @@ static irqreturn_t dw_spi_transfer_handler(struct dw_spi *dws)
static irqreturn_t dw_spi_irq(int irq, void *dev_id)
{
- struct spi_controller *host = dev_id;
- struct dw_spi *dws = spi_controller_get_devdata(host);
+ struct spi_controller *ctlr = dev_id;
+ struct dw_spi *dws = spi_controller_get_devdata(ctlr);
u16 irq_status = dw_readl(dws, DW_SPI_ISR) & DW_SPI_INT_MASK;
if (!irq_status)
return IRQ_NONE;
- if (!host->cur_msg) {
+ if (!ctlr->cur_msg) {
dw_spi_mask_intr(dws, 0xff);
return IRQ_HANDLED;
}
@@ -410,11 +410,11 @@ static int dw_spi_poll_transfer(struct dw_spi *dws,
return 0;
}
-static int dw_spi_transfer_one(struct spi_controller *host,
+static int dw_spi_transfer_one(struct spi_controller *ctlr,
struct spi_device *spi,
struct spi_transfer *transfer)
{
- struct dw_spi *dws = spi_controller_get_devdata(host);
+ struct dw_spi *dws = spi_controller_get_devdata(ctlr);
struct dw_spi_cfg cfg = {
.tmode = DW_SPI_CTRLR0_TMOD_TR,
.dfs = transfer->bits_per_word,
@@ -439,7 +439,7 @@ static int dw_spi_transfer_one(struct spi_controller *host,
transfer->effective_speed_hz = dws->current_freq;
/* Check if current transfer is a DMA transaction */
- dws->dma_mapped = spi_xfer_is_dma_mapped(host, spi, transfer);
+ dws->dma_mapped = spi_xfer_is_dma_mapped(ctlr, spi, transfer);
/* For poll mode just disable all interrupts */
dw_spi_mask_intr(dws, 0xff);
@@ -462,10 +462,10 @@ static int dw_spi_transfer_one(struct spi_controller *host,
return 1;
}
-static void dw_spi_handle_err(struct spi_controller *host,
+static void dw_spi_handle_err(struct spi_controller *ctlr,
struct spi_message *msg)
{
- struct dw_spi *dws = spi_controller_get_devdata(host);
+ struct dw_spi *dws = spi_controller_get_devdata(ctlr);
if (dws->dma_mapped)
dws->dma_ops->dma_stop(dws);
@@ -574,7 +574,7 @@ static int dw_spi_write_then_read(struct dw_spi *dws, struct spi_device *spi)
while (len) {
entries = readl_relaxed(dws->regs + DW_SPI_TXFLR);
if (!entries) {
- dev_err(&dws->host->dev, "CS de-assertion on Tx\n");
+ dev_err(&dws->ctlr->dev, "CS de-assertion on Tx\n");
return -EIO;
}
room = min(dws->fifo_len - entries, len);
@@ -594,7 +594,7 @@ static int dw_spi_write_then_read(struct dw_spi *dws, struct spi_device *spi)
if (!entries) {
sts = readl_relaxed(dws->regs + DW_SPI_RISR);
if (sts & DW_SPI_INT_RXOI) {
- dev_err(&dws->host->dev, "FIFO overflow on Rx\n");
+ dev_err(&dws->ctlr->dev, "FIFO overflow on Rx\n");
return -EIO;
}
continue;
@@ -635,7 +635,7 @@ static int dw_spi_wait_mem_op_done(struct dw_spi *dws)
spi_delay_exec(&delay, NULL);
if (retry < 0) {
- dev_err(&dws->host->dev, "Mem op hanged up\n");
+ dev_err(&dws->ctlr->dev, "Mem op hanged up\n");
return -EIO;
}
@@ -898,60 +898,60 @@ static const struct spi_controller_mem_caps dw_spi_mem_caps = {
.per_op_freq = true,
};
-int dw_spi_add_host(struct device *dev, struct dw_spi *dws)
+int dw_spi_add_controller(struct device *dev, struct dw_spi *dws)
{
- struct spi_controller *host;
+ struct spi_controller *ctlr;
int ret;
if (!dws)
return -EINVAL;
- host = spi_alloc_host(dev, 0);
- if (!host)
+ ctlr = spi_alloc_host(dev, 0);
+ if (!ctlr)
return -ENOMEM;
- device_set_node(&host->dev, dev_fwnode(dev));
+ device_set_node(&ctlr->dev, dev_fwnode(dev));
- dws->host = host;
+ dws->ctlr = ctlr;
dws->dma_addr = (dma_addr_t)(dws->paddr + DW_SPI_DR);
- spi_controller_set_devdata(host, dws);
+ spi_controller_set_devdata(ctlr, dws);
/* Basic HW init */
dw_spi_hw_init(dev, dws);
ret = request_irq(dws->irq, dw_spi_irq, IRQF_SHARED, dev_name(dev),
- host);
+ ctlr);
if (ret < 0 && ret != -ENOTCONN) {
dev_err(dev, "can not get IRQ\n");
- goto err_free_host;
+ goto err_free_ctlr;
}
dw_spi_init_mem_ops(dws);
- host->use_gpio_descriptors = true;
- host->mode_bits = SPI_CPOL | SPI_CPHA | SPI_LOOP;
+ ctlr->use_gpio_descriptors = true;
+ ctlr->mode_bits = SPI_CPOL | SPI_CPHA | SPI_LOOP;
if (dws->caps & DW_SPI_CAP_DFS32)
- host->bits_per_word_mask = SPI_BPW_RANGE_MASK(4, 32);
+ ctlr->bits_per_word_mask = SPI_BPW_RANGE_MASK(4, 32);
else
- host->bits_per_word_mask = SPI_BPW_RANGE_MASK(4, 16);
- host->bus_num = dws->bus_num;
- host->num_chipselect = dws->num_cs;
- host->setup = dw_spi_setup;
- host->cleanup = dw_spi_cleanup;
+ ctlr->bits_per_word_mask = SPI_BPW_RANGE_MASK(4, 16);
+ ctlr->bus_num = dws->bus_num;
+ ctlr->num_chipselect = dws->num_cs;
+ ctlr->setup = dw_spi_setup;
+ ctlr->cleanup = dw_spi_cleanup;
if (dws->set_cs)
- host->set_cs = dws->set_cs;
+ ctlr->set_cs = dws->set_cs;
else
- host->set_cs = dw_spi_set_cs;
- host->transfer_one = dw_spi_transfer_one;
- host->handle_err = dw_spi_handle_err;
+ ctlr->set_cs = dw_spi_set_cs;
+ ctlr->transfer_one = dw_spi_transfer_one;
+ ctlr->handle_err = dw_spi_handle_err;
if (dws->mem_ops.exec_op) {
- host->mem_ops = &dws->mem_ops;
- host->mem_caps = &dw_spi_mem_caps;
+ ctlr->mem_ops = &dws->mem_ops;
+ ctlr->mem_caps = &dw_spi_mem_caps;
}
- host->max_speed_hz = dws->max_freq;
- host->flags = SPI_CONTROLLER_GPIO_SS;
- host->auto_runtime_pm = true;
+ ctlr->max_speed_hz = dws->max_freq;
+ ctlr->flags = SPI_CONTROLLER_GPIO_SS;
+ ctlr->auto_runtime_pm = true;
/* Get default rx sample delay */
device_property_read_u32(dev, "rx-sample-delay-ns",
@@ -964,14 +964,14 @@ int dw_spi_add_host(struct device *dev, struct dw_spi *dws)
} else if (ret) {
dev_warn(dev, "DMA init failed\n");
} else {
- host->can_dma = dws->dma_ops->can_dma;
- host->flags |= SPI_CONTROLLER_MUST_TX;
+ ctlr->can_dma = dws->dma_ops->can_dma;
+ ctlr->flags |= SPI_CONTROLLER_MUST_TX;
}
}
- ret = spi_register_controller(host);
+ ret = spi_register_controller(ctlr);
if (ret) {
- dev_err_probe(dev, ret, "problem registering spi host\n");
+ dev_err_probe(dev, ret, "problem registering spi controller\n");
goto err_dma_exit;
}
@@ -983,47 +983,47 @@ int dw_spi_add_host(struct device *dev, struct dw_spi *dws)
dws->dma_ops->dma_exit(dws);
dw_spi_enable_chip(dws, 0);
err_free_irq:
- free_irq(dws->irq, host);
-err_free_host:
- spi_controller_put(host);
+ free_irq(dws->irq, ctlr);
+err_free_ctlr:
+ spi_controller_put(ctlr);
return ret;
}
-EXPORT_SYMBOL_NS_GPL(dw_spi_add_host, "SPI_DW_CORE");
+EXPORT_SYMBOL_NS_GPL(dw_spi_add_controller, "SPI_DW_CORE");
-void dw_spi_remove_host(struct dw_spi *dws)
+void dw_spi_remove_controller(struct dw_spi *dws)
{
dw_spi_debugfs_remove(dws);
- spi_unregister_controller(dws->host);
+ spi_unregister_controller(dws->ctlr);
if (dws->dma_ops && dws->dma_ops->dma_exit)
dws->dma_ops->dma_exit(dws);
dw_spi_shutdown_chip(dws);
- free_irq(dws->irq, dws->host);
+ free_irq(dws->irq, dws->ctlr);
}
-EXPORT_SYMBOL_NS_GPL(dw_spi_remove_host, "SPI_DW_CORE");
+EXPORT_SYMBOL_NS_GPL(dw_spi_remove_controller, "SPI_DW_CORE");
-int dw_spi_suspend_host(struct dw_spi *dws)
+int dw_spi_suspend_controller(struct dw_spi *dws)
{
int ret;
- ret = spi_controller_suspend(dws->host);
+ ret = spi_controller_suspend(dws->ctlr);
if (ret)
return ret;
dw_spi_shutdown_chip(dws);
return 0;
}
-EXPORT_SYMBOL_NS_GPL(dw_spi_suspend_host, "SPI_DW_CORE");
+EXPORT_SYMBOL_NS_GPL(dw_spi_suspend_controller, "SPI_DW_CORE");
-int dw_spi_resume_host(struct dw_spi *dws)
+int dw_spi_resume_controller(struct dw_spi *dws)
{
- dw_spi_hw_init(&dws->host->dev, dws);
- return spi_controller_resume(dws->host);
+ dw_spi_hw_init(&dws->ctlr->dev, dws);
+ return spi_controller_resume(dws->ctlr);
}
-EXPORT_SYMBOL_NS_GPL(dw_spi_resume_host, "SPI_DW_CORE");
+EXPORT_SYMBOL_NS_GPL(dw_spi_resume_controller, "SPI_DW_CORE");
MODULE_AUTHOR("Feng Tang <feng.tang@intel.com>");
MODULE_DESCRIPTION("Driver for DesignWare SPI controller core");
diff --git a/drivers/spi/spi-dw-dma.c b/drivers/spi/spi-dw-dma.c
index b5bed02b7e5006d399697384c958137649786f1a..65adec7c7524b8362ec63be556a5a6ba8ab53a99 100644
--- a/drivers/spi/spi-dw-dma.c
+++ b/drivers/spi/spi-dw-dma.c
@@ -139,8 +139,8 @@ static int dw_spi_dma_init_mfld(struct device *dev, struct dw_spi *dws)
if (!dws->txchan)
goto free_rxchan;
- dws->host->dma_rx = dws->rxchan;
- dws->host->dma_tx = dws->txchan;
+ dws->ctlr->dma_rx = dws->rxchan;
+ dws->ctlr->dma_tx = dws->txchan;
init_completion(&dws->dma_completion);
@@ -183,8 +183,8 @@ static int dw_spi_dma_init_generic(struct device *dev, struct dw_spi *dws)
goto free_rxchan;
}
- dws->host->dma_rx = dws->rxchan;
- dws->host->dma_tx = dws->txchan;
+ dws->ctlr->dma_rx = dws->rxchan;
+ dws->ctlr->dma_tx = dws->txchan;
init_completion(&dws->dma_completion);
@@ -242,10 +242,10 @@ static enum dma_slave_buswidth dw_spi_dma_convert_width(u8 n_bytes)
}
}
-static bool dw_spi_can_dma(struct spi_controller *host,
+static bool dw_spi_can_dma(struct spi_controller *ctlr,
struct spi_device *spi, struct spi_transfer *xfer)
{
- struct dw_spi *dws = spi_controller_get_devdata(host);
+ struct dw_spi *dws = spi_controller_get_devdata(ctlr);
enum dma_slave_buswidth dma_bus_width;
if (xfer->len <= dws->fifo_len)
@@ -271,7 +271,7 @@ static int dw_spi_dma_wait(struct dw_spi *dws, unsigned int len, u32 speed)
msecs_to_jiffies(ms));
if (ms == 0) {
- dev_err(&dws->host->cur_msg->spi->dev,
+ dev_err(&dws->ctlr->cur_msg->spi->dev,
"DMA transaction timed out\n");
return -ETIMEDOUT;
}
@@ -299,7 +299,7 @@ static int dw_spi_dma_wait_tx_done(struct dw_spi *dws,
spi_delay_exec(&delay, xfer);
if (retry < 0) {
- dev_err(&dws->host->dev, "Tx hanged up\n");
+ dev_err(&dws->ctlr->dev, "Tx hanged up\n");
return -EIO;
}
@@ -400,7 +400,7 @@ static int dw_spi_dma_wait_rx_done(struct dw_spi *dws)
spi_delay_exec(&delay, NULL);
if (retry < 0) {
- dev_err(&dws->host->dev, "Rx hanged up\n");
+ dev_err(&dws->ctlr->dev, "Rx hanged up\n");
return -EIO;
}
@@ -656,13 +656,13 @@ static int dw_spi_dma_transfer(struct dw_spi *dws, struct spi_transfer *xfer)
if (ret)
return ret;
- if (dws->host->cur_msg->status == -EINPROGRESS) {
+ if (dws->ctlr->cur_msg->status == -EINPROGRESS) {
ret = dw_spi_dma_wait_tx_done(dws, xfer);
if (ret)
return ret;
}
- if (xfer->rx_buf && dws->host->cur_msg->status == -EINPROGRESS)
+ if (xfer->rx_buf && dws->ctlr->cur_msg->status == -EINPROGRESS)
ret = dw_spi_dma_wait_rx_done(dws);
return ret;
diff --git a/drivers/spi/spi-dw-mmio.c b/drivers/spi/spi-dw-mmio.c
index f0f576fac77afed6ca2ddc0d31e37bc76462c736..cc16139e121bf2dae29a16e362db56ea8ad3a18b 100644
--- a/drivers/spi/spi-dw-mmio.c
+++ b/drivers/spi/spi-dw-mmio.c
@@ -380,7 +380,7 @@ static int dw_spi_mmio_probe(struct platform_device *pdev)
pm_runtime_enable(&pdev->dev);
- ret = dw_spi_add_host(&pdev->dev, dws);
+ ret = dw_spi_add_controller(&pdev->dev, dws);
if (ret)
goto out;
@@ -399,7 +399,7 @@ static void dw_spi_mmio_remove(struct platform_device *pdev)
{
struct dw_spi_mmio *dwsmmio = platform_get_drvdata(pdev);
- dw_spi_remove_host(&dwsmmio->dws);
+ dw_spi_remove_controller(&dwsmmio->dws);
pm_runtime_disable(&pdev->dev);
reset_control_assert(dwsmmio->rstc);
}
diff --git a/drivers/spi/spi-dw-pci.c b/drivers/spi/spi-dw-pci.c
index b32d6648a32ea251028d2b4ad422941867c71519..72d9f5bc87f75a00f97d9c159a0acb118b0a77ab 100644
--- a/drivers/spi/spi-dw-pci.c
+++ b/drivers/spi/spi-dw-pci.c
@@ -127,7 +127,7 @@ static int dw_spi_pci_probe(struct pci_dev *pdev, const struct pci_device_id *en
goto err_free_irq_vectors;
}
- ret = dw_spi_add_host(&pdev->dev, dws);
+ ret = dw_spi_add_controller(&pdev->dev, dws);
if (ret)
goto err_free_irq_vectors;
@@ -156,7 +156,7 @@ static void dw_spi_pci_remove(struct pci_dev *pdev)
pm_runtime_forbid(&pdev->dev);
pm_runtime_get_noresume(&pdev->dev);
- dw_spi_remove_host(dws);
+ dw_spi_remove_controller(dws);
pci_free_irq_vectors(pdev);
}
@@ -165,14 +165,14 @@ static int dw_spi_pci_suspend(struct device *dev)
{
struct dw_spi *dws = dev_get_drvdata(dev);
- return dw_spi_suspend_host(dws);
+ return dw_spi_suspend_controller(dws);
}
static int dw_spi_pci_resume(struct device *dev)
{
struct dw_spi *dws = dev_get_drvdata(dev);
- return dw_spi_resume_host(dws);
+ return dw_spi_resume_controller(dws);
}
#endif
diff --git a/drivers/spi/spi-dw.h b/drivers/spi/spi-dw.h
index fc267c6437ae095e37de78b480856ca8deb5656e..9cc79c566a70c0ababf01cc73111c14d73a35a98 100644
--- a/drivers/spi/spi-dw.h
+++ b/drivers/spi/spi-dw.h
@@ -142,14 +142,14 @@ struct dw_spi_dma_ops {
int (*dma_init)(struct device *dev, struct dw_spi *dws);
void (*dma_exit)(struct dw_spi *dws);
int (*dma_setup)(struct dw_spi *dws, struct spi_transfer *xfer);
- bool (*can_dma)(struct spi_controller *host, struct spi_device *spi,
+ bool (*can_dma)(struct spi_controller *ctlr, struct spi_device *spi,
struct spi_transfer *xfer);
int (*dma_transfer)(struct dw_spi *dws, struct spi_transfer *xfer);
void (*dma_stop)(struct dw_spi *dws);
};
struct dw_spi {
- struct spi_controller *host;
+ struct spi_controller *ctlr;
u32 ip; /* Synopsys DW SSI IP-core ID */
u32 ver; /* Synopsys component version */
@@ -288,10 +288,10 @@ extern void dw_spi_set_cs(struct spi_device *spi, bool enable);
extern void dw_spi_update_config(struct dw_spi *dws, struct spi_device *spi,
struct dw_spi_cfg *cfg);
extern int dw_spi_check_status(struct dw_spi *dws, bool raw);
-extern int dw_spi_add_host(struct device *dev, struct dw_spi *dws);
-extern void dw_spi_remove_host(struct dw_spi *dws);
-extern int dw_spi_suspend_host(struct dw_spi *dws);
-extern int dw_spi_resume_host(struct dw_spi *dws);
+extern int dw_spi_add_controller(struct device *dev, struct dw_spi *dws);
+extern void dw_spi_remove_controller(struct dw_spi *dws);
+extern int dw_spi_suspend_controller(struct dw_spi *dws);
+extern int dw_spi_resume_controller(struct dw_spi *dws);
#ifdef CONFIG_SPI_DW_DMA
--
2.51.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH RFC 2/2] spi: dw: add target mode support
2025-10-02 12:14 [PATCH RFC 0/2] Add target mode support for the DesignWare SPI controller Benoît Monin
2025-10-02 12:14 ` [PATCH RFC 1/2] spi: dw: rename the spi controller to ctlr Benoît Monin
@ 2025-10-02 12:14 ` Benoît Monin
2025-10-15 12:14 ` [PATCH RFC 0/2] Add target mode support for the DesignWare SPI controller Mark Brown
2 siblings, 0 replies; 4+ messages in thread
From: Benoît Monin @ 2025-10-02 12:14 UTC (permalink / raw)
To: Mark Brown
Cc: Thomas Petazzoni, Vladimir Kondratiev, Tawfik Bayouk, linux-spi,
linux-kernel, Benoît Monin
Implement target mode for the DesignWare controller with the following
changes:
Allocate an SPI controller of the correct type based on the spi-slave
property in dw_spi_add_controller() and set the controller properties
depending on its type. Since they are only relevant when acting as a host
controller, settings related to chip-select control and the set_cs()
callback are only set in host mode, as are the loopback support, the
memory operations and the maximum frequency. The target_abort() callback
is set only when configured in target mode.
The number of chip-select is set to 1 in dw_spi_hw_init() since the
controller only has one CS input in target mode.
In dw_spi_update_config(), return after setting the CTRLR0 register as
the other registers are only relevant in host mode and are read-only
in target mode. This function is called as part of the transfer_one()
callback, which is identical in both the host and target mode.
Move the code implementing the handle_err() callback to a new function
named dw_spi_abort(), and use it to implement both the handle_err()
and the target_abort() callbacks.
Finally, drop the error path on the spi-slave property in
dw_spi_mmio_probe(), as it is now a valid configuration.
Signed-off-by: Benoît Monin <benoit.monin@bootlin.com>
---
drivers/spi/spi-dw-core.c | 82 ++++++++++++++++++++++++++++++++---------------
drivers/spi/spi-dw-mmio.c | 5 ---
2 files changed, 57 insertions(+), 30 deletions(-)
diff --git a/drivers/spi/spi-dw-core.c b/drivers/spi/spi-dw-core.c
index 90dea6f9b3dab773204c667cb12f3ecaef1d7108..9ebf244294f89db1c5f26471d18eb298ae804cd9 100644
--- a/drivers/spi/spi-dw-core.c
+++ b/drivers/spi/spi-dw-core.c
@@ -332,6 +332,9 @@ void dw_spi_update_config(struct dw_spi *dws, struct spi_device *spi,
dw_writel(dws, DW_SPI_CTRLR0, cr0);
+ if (spi_controller_is_target(dws->ctlr))
+ return;
+
if (cfg->tmode == DW_SPI_CTRLR0_TMOD_EPROMREAD ||
cfg->tmode == DW_SPI_CTRLR0_TMOD_RO)
dw_writel(dws, DW_SPI_CTRLR1, cfg->ndf ? cfg->ndf - 1 : 0);
@@ -462,8 +465,7 @@ static int dw_spi_transfer_one(struct spi_controller *ctlr,
return 1;
}
-static void dw_spi_handle_err(struct spi_controller *ctlr,
- struct spi_message *msg)
+static inline void dw_spi_abort(struct spi_controller *ctlr)
{
struct dw_spi *dws = spi_controller_get_devdata(ctlr);
@@ -473,6 +475,19 @@ static void dw_spi_handle_err(struct spi_controller *ctlr,
dw_spi_reset_chip(dws);
}
+static void dw_spi_handle_err(struct spi_controller *ctlr,
+ struct spi_message *msg)
+{
+ dw_spi_abort(ctlr);
+}
+
+static int dw_spi_target_abort(struct spi_controller *ctlr)
+{
+ dw_spi_abort(ctlr);
+
+ return 0;
+}
+
static int dw_spi_adjust_mem_op_size(struct spi_mem *mem, struct spi_mem_op *op)
{
if (op->data.dir == SPI_MEM_DATA_IN)
@@ -834,18 +849,23 @@ static void dw_spi_hw_init(struct device *dev, struct dw_spi *dws)
DW_SPI_GET_BYTE(dws->ver, 1));
}
- /*
- * Try to detect the number of native chip-selects if the platform
- * driver didn't set it up. There can be up to 16 lines configured.
- */
- if (!dws->num_cs) {
- u32 ser;
+ if (spi_controller_is_target(dws->ctlr)) {
+ /* There is only one CS input signal in target mode */
+ dws->num_cs = 1;
+ } else {
+ /*
+ * Try to detect the number of native chip-selects if the platform
+ * driver didn't set it up. There can be up to 16 lines configured.
+ */
+ if (!dws->num_cs) {
+ u32 ser;
- dw_writel(dws, DW_SPI_SER, 0xffff);
- ser = dw_readl(dws, DW_SPI_SER);
- dw_writel(dws, DW_SPI_SER, 0);
+ dw_writel(dws, DW_SPI_SER, 0xffff);
+ ser = dw_readl(dws, DW_SPI_SER);
+ dw_writel(dws, DW_SPI_SER, 0);
- dws->num_cs = hweight16(ser);
+ dws->num_cs = hweight16(ser);
+ }
}
/*
@@ -901,12 +921,18 @@ static const struct spi_controller_mem_caps dw_spi_mem_caps = {
int dw_spi_add_controller(struct device *dev, struct dw_spi *dws)
{
struct spi_controller *ctlr;
+ bool target;
int ret;
if (!dws)
return -EINVAL;
- ctlr = spi_alloc_host(dev, 0);
+ target = device_property_read_bool(dev, "spi-slave");
+ if (target)
+ ctlr = spi_alloc_target(dev, 0);
+ else
+ ctlr = spi_alloc_host(dev, 0);
+
if (!ctlr)
return -ENOMEM;
@@ -929,8 +955,7 @@ int dw_spi_add_controller(struct device *dev, struct dw_spi *dws)
dw_spi_init_mem_ops(dws);
- ctlr->use_gpio_descriptors = true;
- ctlr->mode_bits = SPI_CPOL | SPI_CPHA | SPI_LOOP;
+ ctlr->mode_bits = SPI_CPOL | SPI_CPHA;
if (dws->caps & DW_SPI_CAP_DFS32)
ctlr->bits_per_word_mask = SPI_BPW_RANGE_MASK(4, 32);
else
@@ -939,20 +964,27 @@ int dw_spi_add_controller(struct device *dev, struct dw_spi *dws)
ctlr->num_chipselect = dws->num_cs;
ctlr->setup = dw_spi_setup;
ctlr->cleanup = dw_spi_cleanup;
- if (dws->set_cs)
- ctlr->set_cs = dws->set_cs;
- else
- ctlr->set_cs = dw_spi_set_cs;
ctlr->transfer_one = dw_spi_transfer_one;
ctlr->handle_err = dw_spi_handle_err;
- if (dws->mem_ops.exec_op) {
- ctlr->mem_ops = &dws->mem_ops;
- ctlr->mem_caps = &dw_spi_mem_caps;
- }
- ctlr->max_speed_hz = dws->max_freq;
- ctlr->flags = SPI_CONTROLLER_GPIO_SS;
ctlr->auto_runtime_pm = true;
+ if (!target) {
+ ctlr->use_gpio_descriptors = true;
+ ctlr->mode_bits |= SPI_LOOP;
+ if (dws->set_cs)
+ ctlr->set_cs = dws->set_cs;
+ else
+ ctlr->set_cs = dw_spi_set_cs;
+ if (dws->mem_ops.exec_op) {
+ ctlr->mem_ops = &dws->mem_ops;
+ ctlr->mem_caps = &dw_spi_mem_caps;
+ }
+ ctlr->max_speed_hz = dws->max_freq;
+ ctlr->flags = SPI_CONTROLLER_GPIO_SS;
+ } else {
+ ctlr->target_abort = dw_spi_target_abort;
+ }
+
/* Get default rx sample delay */
device_property_read_u32(dev, "rx-sample-delay-ns",
&dws->def_rx_sample_dly_ns);
diff --git a/drivers/spi/spi-dw-mmio.c b/drivers/spi/spi-dw-mmio.c
index cc16139e121bf2dae29a16e362db56ea8ad3a18b..f2cd675a9a1980fba447e13e356bb81a0395256e 100644
--- a/drivers/spi/spi-dw-mmio.c
+++ b/drivers/spi/spi-dw-mmio.c
@@ -321,11 +321,6 @@ static int dw_spi_mmio_probe(struct platform_device *pdev)
struct dw_spi *dws;
int ret;
- if (device_property_read_bool(&pdev->dev, "spi-slave")) {
- dev_warn(&pdev->dev, "spi-slave is not yet supported\n");
- return -ENODEV;
- }
-
dwsmmio = devm_kzalloc(&pdev->dev, sizeof(struct dw_spi_mmio),
GFP_KERNEL);
if (!dwsmmio)
--
2.51.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH RFC 0/2] Add target mode support for the DesignWare SPI controller
2025-10-02 12:14 [PATCH RFC 0/2] Add target mode support for the DesignWare SPI controller Benoît Monin
2025-10-02 12:14 ` [PATCH RFC 1/2] spi: dw: rename the spi controller to ctlr Benoît Monin
2025-10-02 12:14 ` [PATCH RFC 2/2] spi: dw: add target mode support Benoît Monin
@ 2025-10-15 12:14 ` Mark Brown
2 siblings, 0 replies; 4+ messages in thread
From: Mark Brown @ 2025-10-15 12:14 UTC (permalink / raw)
To: Benoît Monin
Cc: Thomas Petazzoni, Vladimir Kondratiev, Tawfik Bayouk, linux-spi,
linux-kernel
On Thu, 02 Oct 2025 14:14:36 +0200, Benoît Monin wrote:
> The DesignWare SPI controller can act as a host or a target; the
> choice between the two is set in hardware and cannot be changed by
> software. When configured in target mode, the controller has a much
> reduced set of capabilities. It only has a single chip-select input and
> can only run standard SPI mode (no dual, quad, or octal mode). Despite
> this, the overall logic of doing an SPI transfer and the register layout
> is identical between both modes, so implementing the target mode reuses
> much of the existing code.
>
> [...]
Applied to
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git for-next
Thanks!
[1/2] spi: dw: rename the spi controller to ctlr
commit: b926b15547d29a88932de3c24a05c12826fc1dbc
[2/2] spi: dw: add target mode support
commit: fe8cc44dd173cde5788ab4e3730ac61f3d316d9c
All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying
to this mail.
Thanks,
Mark
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-10-15 12:14 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-02 12:14 [PATCH RFC 0/2] Add target mode support for the DesignWare SPI controller Benoît Monin
2025-10-02 12:14 ` [PATCH RFC 1/2] spi: dw: rename the spi controller to ctlr Benoît Monin
2025-10-02 12:14 ` [PATCH RFC 2/2] spi: dw: add target mode support Benoît Monin
2025-10-15 12:14 ` [PATCH RFC 0/2] Add target mode support for the DesignWare SPI controller Mark Brown
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).