mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com>
To: "Mark Brown" <broonie@kernel.org>,
	"Michal Simek" <michal.simek@xilinx.com>,
	"Sören Brinkmann" <soren.brinkmann@xilinx.com>,
	linux-spi@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org
Cc: Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com>
Subject: [PATCH v2 01/15] spi/xilinx: Simplify spi_fill_tx_fifo
Date: Wed, 28 Jan 2015 13:23:40 +0100	[thread overview]
Message-ID: <1422447834-23116-2-git-send-email-ricardo.ribalda@gmail.com> (raw)
In-Reply-To: <1422447834-23116-1-git-send-email-ricardo.ribalda@gmail.com>

Instead of checking the TX_FULL flag for every transaction, find out the
size of the buffer at probe time and use it.

To avoid situations where the core had some data on the buffer before
initialization, the core is reseted before the buffer size is detected

Signed-off-by: Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com>
---
v2: Changes Requested by Mark Brown <broonie@kernel.org>

Before discovering the buffer size, reset the core.

 drivers/spi/spi-xilinx.c | 46 +++++++++++++++++++++++++++++++++-------------
 1 file changed, 33 insertions(+), 13 deletions(-)

diff --git a/drivers/spi/spi-xilinx.c b/drivers/spi/spi-xilinx.c
index 416b227..1890af8 100644
--- a/drivers/spi/spi-xilinx.c
+++ b/drivers/spi/spi-xilinx.c
@@ -88,6 +88,7 @@ struct xilinx_spi {
 	const u8 *tx_ptr;	/* pointer in the Rx buffer */
 	int remaining_bytes;	/* the number of bytes left to transfer */
 	u8 bits_per_word;
+	int buffer_size;	/* buffer size in words */
 	unsigned int (*read_fn)(void __iomem *);
 	void (*write_fn)(u32, void __iomem *);
 	void (*tx_fn)(struct xilinx_spi *);
@@ -221,24 +222,16 @@ static int xilinx_spi_setup_transfer(struct spi_device *spi,
 	return 0;
 }
 
-static int xilinx_spi_fill_tx_fifo(struct xilinx_spi *xspi)
+static void xilinx_spi_fill_tx_fifo(struct xilinx_spi *xspi, int n_words)
 {
-	u8 sr;
-	int n_words = 0;
+	xspi->remaining_bytes -= n_words * xspi->bits_per_word / 8;
 
-	/* Fill the Tx FIFO with as many bytes as possible */
-	sr = xspi->read_fn(xspi->regs + XSPI_SR_OFFSET);
-	while ((sr & XSPI_SR_TX_FULL_MASK) == 0 && xspi->remaining_bytes > 0) {
+	while (n_words--)
 		if (xspi->tx_ptr)
 			xspi->tx_fn(xspi);
 		else
 			xspi->write_fn(0, xspi->regs + XSPI_TXD_OFFSET);
-		xspi->remaining_bytes -= xspi->bits_per_word / 8;
-		sr = xspi->read_fn(xspi->regs + XSPI_SR_OFFSET);
-		n_words++;
-	}
-
-	return n_words;
+	return;
 }
 
 static int xilinx_spi_txrx_bufs(struct spi_device *spi, struct spi_transfer *t)
@@ -265,7 +258,10 @@ static int xilinx_spi_txrx_bufs(struct spi_device *spi, struct spi_transfer *t)
 		u16 cr;
 		int n_words;
 
-		n_words = xilinx_spi_fill_tx_fifo(xspi);
+		n_words = (xspi->remaining_bytes * 8) / xspi->bits_per_word;
+		n_words = min(n_words, xspi->buffer_size);
+
+		xilinx_spi_fill_tx_fifo(xspi, n_words);
 
 		/* Start the transfer by not inhibiting the transmitter any
 		 * longer
@@ -322,6 +318,28 @@ static irqreturn_t xilinx_spi_irq(int irq, void *dev_id)
 	return IRQ_HANDLED;
 }
 
+static int xilinx_spi_find_buffer_size(struct xilinx_spi *xspi)
+{
+	u8 sr;
+	int n_words = 0;
+
+	/*
+	 * Before the buffer_size detection we reset the core
+	 * to make sure we start with a clean state.
+	 */
+	xspi->write_fn(XIPIF_V123B_RESET_MASK,
+		xspi->regs + XIPIF_V123B_RESETR_OFFSET);
+
+	/* Fill the Tx FIFO with as many words as possible */
+	do {
+		xspi->write_fn(0, xspi->regs + XSPI_TXD_OFFSET);
+		sr = xspi->read_fn(xspi->regs + XSPI_SR_OFFSET);
+		n_words++;
+	} while (!(sr & XSPI_SR_TX_FULL_MASK));
+
+	return n_words;
+}
+
 static const struct of_device_id xilinx_spi_of_match[] = {
 	{ .compatible = "xlnx,xps-spi-2.00.a", },
 	{ .compatible = "xlnx,xps-spi-2.00.b", },
@@ -413,6 +431,8 @@ static int xilinx_spi_probe(struct platform_device *pdev)
 		goto put_master;
 	}
 
+	xspi->buffer_size = xilinx_spi_find_buffer_size(xspi);
+
 	/* SPI controller initializations */
 	xspi_init_hw(xspi);
 
-- 
2.1.4


  reply	other threads:[~2015-01-29  2:06 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-28 12:23 [PATCH v2 00/15] spi/xilinx: Speed-up Ricardo Ribalda Delgado
2015-01-28 12:23 ` Ricardo Ribalda Delgado [this message]
2015-01-28 12:23 ` [PATCH v2 02/15] spi/xilinx: Leave the IRQ always enabled Ricardo Ribalda Delgado
2015-01-28 19:38   ` Mark Brown
2015-01-28 12:23 ` [PATCH v2 03/15] spi/xilinx: Code cleanup Ricardo Ribalda Delgado
2015-01-28 12:23 ` [PATCH v2 04/15] spi/xilinx: Use cached value of register Ricardo Ribalda Delgado
2015-01-28 12:23 ` [PATCH v2 05/15] spi/xilinx: Support cores with no interrupt Ricardo Ribalda Delgado
2015-01-28 12:23 ` [PATCH v2 06/15] spi/xilinx: Do not inhibit transmission in polling mode Ricardo Ribalda Delgado
2015-01-28 12:23 ` [PATCH v2 07/15] spi/xilinx: Support for spi mode CS_HIGH Ricardo Ribalda Delgado
2015-01-28 12:23 ` [PATCH v2 08/15] spi/xilinx: Remove rx_fn and tx_fn pointer Ricardo Ribalda Delgado
2015-01-28 12:23 ` [PATCH v2 09/15] spi/xilinx: Make spi_tx and spi_rx simmetric Ricardo Ribalda Delgado
2015-01-28 12:23 ` [PATCH v2 10/15] spi/xilinx: Convert remainding_bytes in remaining words Ricardo Ribalda Delgado
2015-01-28 12:23 ` [PATCH v2 11/15] spi/xilinx: Convert bits_per_word in bytes_per_word Ricardo Ribalda Delgado
2015-01-28 12:23 ` [PATCH v2 12/15] spi/xilinx: Remove iowrite/ioread wrappers Ricardo Ribalda Delgado
2015-01-30  6:13   ` Ricardo Ribalda Delgado
2015-01-28 12:23 ` [PATCH v2 13/15] spi/xilinx: Remove remaining_words driver data variable Ricardo Ribalda Delgado
2015-01-28 12:23 ` [PATCH v2 14/15] spi/xilinx: Check number of slaves range Ricardo Ribalda Delgado
2015-01-28 19:40   ` Mark Brown
2015-01-28 12:23 ` [PATCH v2 15/15] spi/xilinx: Use polling mode on small transfers Ricardo Ribalda Delgado
2015-01-28 19:43 ` [PATCH v2 00/15] spi/xilinx: Speed-up Mark Brown

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=1422447834-23116-2-git-send-email-ricardo.ribalda@gmail.com \
    --to=ricardo.ribalda@gmail.com \
    --cc=broonie@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-spi@vger.kernel.org \
    --cc=michal.simek@xilinx.com \
    --cc=soren.brinkmann@xilinx.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®