All of lore.kernel.org
 help / color / mirror / Atom feed
From: Lukasz Majewski <lukma@denx.de>
To: Mark Brown <broonie@kernel.org>
Cc: linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org,
	krzk@kernel.org, Lukasz Majewski <lukma@denx.de>
Subject: [PATCH 2/2] spi: Introduce dspi_slave_abort() function for NXP's dspi SPI driver
Date: Tue, 24 Sep 2019 13:05:47 +0200	[thread overview]
Message-ID: <20190924110547.14770-3-lukma@denx.de> (raw)
In-Reply-To: <20190924110547.14770-1-lukma@denx.de>

This change provides the dspi_slave_abort() function, which is a callback
for slave_abort() method of SPI controller generic driver.

As in the SPI slave mode the transmission is driven by master, any
distortion may cause the slave to enter undefined internal state.
To avoid this problem the dspi_slave_abort() terminates all pending and
ongoing DMA transactions (with sync) and clears internal FIFOs.

Signed-off-by: Lukasz Majewski <lukma@denx.de>
---
 drivers/spi/spi-fsl-dspi.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/drivers/spi/spi-fsl-dspi.c b/drivers/spi/spi-fsl-dspi.c
index bec758e978fb..2c0f211eed87 100644
--- a/drivers/spi/spi-fsl-dspi.c
+++ b/drivers/spi/spi-fsl-dspi.c
@@ -1006,6 +1006,25 @@ static void dspi_init(struct fsl_dspi *dspi)
 			     SPI_CTARE_FMSZE(0) | SPI_CTARE_DTCP(1));
 }
 
+static int dspi_slave_abort(struct spi_master *master)
+{
+	struct fsl_dspi *dspi = spi_master_get_devdata(master);
+
+	/*
+	 * Terminate all pending DMA transactions for the SPI working
+	 * in SLAVE mode.
+	 */
+	dmaengine_terminate_sync(dspi->dma->chan_rx);
+	dmaengine_terminate_sync(dspi->dma->chan_tx);
+
+	/* Clear the internal DSPI RX and TX FIFO buffers */
+	regmap_update_bits(dspi->regmap, SPI_MCR,
+			   SPI_MCR_CLR_TXF | SPI_MCR_CLR_RXF,
+			   SPI_MCR_CLR_TXF | SPI_MCR_CLR_RXF);
+
+	return 0;
+}
+
 static int dspi_probe(struct platform_device *pdev)
 {
 	struct device_node *np = pdev->dev.of_node;
@@ -1030,6 +1049,7 @@ static int dspi_probe(struct platform_device *pdev)
 	ctlr->dev.of_node = pdev->dev.of_node;
 
 	ctlr->cleanup = dspi_cleanup;
+	ctlr->slave_abort = dspi_slave_abort;
 	ctlr->mode_bits = SPI_CPOL | SPI_CPHA | SPI_LSB_FIRST;
 
 	pdata = dev_get_platdata(&pdev->dev);
-- 
2.20.1


  parent reply	other threads:[~2019-09-24 11:06 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-24 11:05 [PATCH 0/2] spi: Fix problem with interrupted slave transmission Lukasz Majewski
2019-09-24 11:05 ` [PATCH 1/2] spi: Add call to spi_slave_abort() function when spidev driver is released Lukasz Majewski
2019-09-24 20:08   ` Applied "spi: Add call to spi_slave_abort() function when spidev driver is released" to the spi tree Mark Brown
2019-09-24 20:08     ` Mark Brown
2019-09-26  6:52   ` [PATCH 1/2] spi: Add call to spi_slave_abort() function when spidev driver is released Geert Uytterhoeven
2019-09-26  7:59     ` Lukasz Majewski
2019-09-24 11:05 ` Lukasz Majewski [this message]
2019-10-01 11:41   ` Applied "spi: Introduce dspi_slave_abort() function for NXP's dspi SPI driver" to the spi tree Mark Brown
2019-10-01 11:41     ` Mark Brown
2019-09-25  9:11 ` [PATCH v2 0/2] spi: Fix problem with interrupted slave transmission Lukasz Majewski
2019-09-25  9:11   ` [PATCH v2 1/2] spi: Add call to spi_slave_abort() function when spidev driver is released Lukasz Majewski
2019-09-25 16:45     ` Mark Brown
2019-09-25 19:57       ` Lukasz Majewski
2019-09-25 16:47     ` Applied "spi: Add call to spi_slave_abort() function when spidev driver is released" to the spi tree Mark Brown
2019-09-25 16:47       ` Mark Brown
2019-09-25  9:11   ` [PATCH v2 2/2] spi: Introduce dspi_slave_abort() function for NXP's dspi SPI driver Lukasz Majewski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190924110547.14770-3-lukma@denx.de \
    --to=lukma@denx.de \
    --cc=broonie@kernel.org \
    --cc=krzk@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-spi@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.