[PATCH 01/10] spi: dw: Add support for polled operation via no IRQ specified in DT

From: Lars Povlsen
Date: Wed May 13 2020 - 10:00:48 EST


With this change a SPI controller can be added without having a IRQ
associated, and causing all transfers to be polled. For SPI controllers
without DMA, this can significantly improve performance by less
interrupt handling overhead.

Reviewed-by: Alexandre Belloni <alexandre.belloni@xxxxxxxxxxx>
Signed-off-by: Lars Povlsen <lars.povlsen@xxxxxxxxxxxxx>
---
drivers/spi/spi-dw.c | 21 +++++++++++++--------
1 file changed, 13 insertions(+), 8 deletions(-)

diff --git a/drivers/spi/spi-dw.c b/drivers/spi/spi-dw.c
index 31e3f866d11a7..e572eb34a3c1a 100644
--- a/drivers/spi/spi-dw.c
+++ b/drivers/spi/spi-dw.c
@@ -19,6 +19,8 @@
#include <linux/debugfs.h>
#endif

+#define VALID_IRQ(i) (i >= 0)
+
/* Slave spi_dev related */
struct chip_data {
u8 tmode; /* TR/TO/RO/EEPROM */
@@ -359,7 +361,7 @@ static int dw_spi_transfer_one(struct spi_controller *master,
spi_enable_chip(dws, 1);
return ret;
}
- } else if (!chip->poll_mode) {
+ } else if (!chip->poll_mode && VALID_IRQ(dws->irq)) {
txlevel = min_t(u16, dws->fifo_len / 2, dws->len / dws->n_bytes);
dw_writel(dws, DW_SPI_TXFLTR, txlevel);

@@ -379,7 +381,7 @@ static int dw_spi_transfer_one(struct spi_controller *master,
return ret;
}

- if (chip->poll_mode)
+ if (chip->poll_mode || !VALID_IRQ(dws->irq))
return poll_transfer(dws);

return 1;
@@ -487,11 +489,13 @@ int dw_spi_add_host(struct device *dev, struct dw_spi *dws)

spi_controller_set_devdata(master, dws);

- ret = request_irq(dws->irq, dw_spi_irq, IRQF_SHARED, dev_name(dev),
- master);
- if (ret < 0) {
- dev_err(dev, "can not get IRQ\n");
- goto err_free_master;
+ if (VALID_IRQ(dws->irq)) {
+ ret = request_irq(dws->irq, dw_spi_irq, IRQF_SHARED,
+ dev_name(dev), master);
+ if (ret < 0) {
+ dev_err(dev, "can not get IRQ\n");
+ goto err_free_master;
+ }
}

master->use_gpio_descriptors = true;
@@ -539,7 +543,8 @@ int dw_spi_add_host(struct device *dev, struct dw_spi *dws)
if (dws->dma_ops && dws->dma_ops->dma_exit)
dws->dma_ops->dma_exit(dws);
spi_enable_chip(dws, 0);
- free_irq(dws->irq, master);
+ if (VALID_IRQ(dws->irq))
+ free_irq(dws->irq, master);
err_free_master:
spi_controller_put(master);
return ret;
--
2.26.2