diff mbox series

[1/3] spi: s3c64xx: support spi polling mode using devicetree

Message ID 20230404060011.108561-2-jaewon02.kim@samsung.com
State New
Headers show
Series spi: s3c64xx: improve SPI polling mode | expand

Commit Message

Jaewon Kim April 4, 2023, 6 a.m. UTC
This patch adds new 'samsung,spi-polling' property to support polling mode.
In some environments, polling mode is required even if DMA is supported.
Changed it to support not only with quick but also optinally with
devicetree.

Signed-off-by: Jaewon Kim <jaewon02.kim@samsung.com>
---
 drivers/spi/spi-s3c64xx.c                 | 23 +++++++++++++++++------
 include/linux/platform_data/spi-s3c64xx.h |  1 +
 2 files changed, 18 insertions(+), 6 deletions(-)
diff mbox series

Patch

diff --git a/drivers/spi/spi-s3c64xx.c b/drivers/spi/spi-s3c64xx.c
index 71d324ec9a70..bf1f3dcca202 100644
--- a/drivers/spi/spi-s3c64xx.c
+++ b/drivers/spi/spi-s3c64xx.c
@@ -116,7 +116,6 @@ 
 #define S3C64XX_SPI_TRAILCNT		S3C64XX_SPI_MAX_TRAILCNT
 
 #define msecs_to_loops(t) (loops_per_jiffy / 1000 * HZ * t)
-#define is_polling(x)	(x->port_conf->quirks & S3C64XX_SPI_QUIRK_POLL)
 
 #define RXBUSY    (1<<2)
 #define TXBUSY    (1<<3)
@@ -198,6 +197,17 @@  struct s3c64xx_spi_driver_data {
 	unsigned int			port_id;
 };
 
+static bool s3c64xx_is_polling(struct s3c64xx_spi_driver_data *sdd)
+{
+	if (sdd->port_conf->quirks & S3C64XX_SPI_QUIRK_POLL)
+		return true;
+
+	if (sdd->cntrlr_info->polling)
+		return true;
+
+	return false;
+}
+
 static void s3c64xx_flush_fifo(struct s3c64xx_spi_driver_data *sdd)
 {
 	void __iomem *regs = sdd->regs;
@@ -353,7 +363,7 @@  static int s3c64xx_spi_prepare_transfer(struct spi_master *spi)
 {
 	struct s3c64xx_spi_driver_data *sdd = spi_master_get_devdata(spi);
 
-	if (is_polling(sdd))
+	if (s3c64xx_is_polling(sdd))
 		return 0;
 
 	/* Requests DMA channels */
@@ -383,7 +393,7 @@  static int s3c64xx_spi_unprepare_transfer(struct spi_master *spi)
 {
 	struct s3c64xx_spi_driver_data *sdd = spi_master_get_devdata(spi);
 
-	if (is_polling(sdd))
+	if (s3c64xx_is_polling(sdd))
 		return 0;
 
 	/* Releases DMA channels if they are allocated */
@@ -749,7 +759,7 @@  static int s3c64xx_spi_transfer_one(struct spi_master *master,
 			return status;
 	}
 
-	if (!is_polling(sdd) && (xfer->len > fifo_len) &&
+	if (!s3c64xx_is_polling(sdd) && (xfer->len > fifo_len) &&
 	    sdd->rx_dma.ch && sdd->tx_dma.ch) {
 		use_dma = 1;
 
@@ -1067,6 +1077,7 @@  static struct s3c64xx_spi_info *s3c64xx_spi_parse_dt(struct device *dev)
 		sci->num_cs = temp;
 	}
 
+	sci->polling = of_property_read_bool(dev->of_node, "samsung,spi-polling");
 	sci->no_cs = of_property_read_bool(dev->of_node, "no-cs-readback");
 
 	return sci;
@@ -1171,7 +1182,7 @@  static int s3c64xx_spi_probe(struct platform_device *pdev)
 	if (sdd->port_conf->has_loopback)
 		master->mode_bits |= SPI_LOOP;
 	master->auto_runtime_pm = true;
-	if (!is_polling(sdd))
+	if (!s3c64xx_is_polling(sdd))
 		master->can_dma = s3c64xx_spi_can_dma;
 
 	sdd->regs = devm_ioremap_resource(&pdev->dev, mem_res);
@@ -1295,7 +1306,7 @@  static int s3c64xx_spi_remove(struct platform_device *pdev)
 
 	writel(0, sdd->regs + S3C64XX_SPI_INT_EN);
 
-	if (!is_polling(sdd)) {
+	if (!s3c64xx_is_polling(sdd)) {
 		dma_release_channel(sdd->rx_dma.ch);
 		dma_release_channel(sdd->tx_dma.ch);
 	}
diff --git a/include/linux/platform_data/spi-s3c64xx.h b/include/linux/platform_data/spi-s3c64xx.h
index 5df1ace6d2c9..cb7b8ddc899f 100644
--- a/include/linux/platform_data/spi-s3c64xx.h
+++ b/include/linux/platform_data/spi-s3c64xx.h
@@ -35,6 +35,7 @@  struct s3c64xx_spi_info {
 	int src_clk_nr;
 	int num_cs;
 	bool no_cs;
+	bool polling;
 	int (*cfg_gpio)(void);
 };