mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] spi: i.MX: optimize transfers for ECSPI v2.3
@ 2015-11-23 11:14 Sascha Hauer
  2015-11-24  7:07 ` Uwe Kleine-König
  0 siblings, 1 reply; 3+ messages in thread
From: Sascha Hauer @ 2015-11-23 11:14 UTC (permalink / raw)
  To: Barebox List

Instead of writing one word to the txfifo and then wait until
one is received in the rxfifo we can write until the txfifos
are not full and read as long the rxfifos contain data. This
makes transfers for the m25p80 driver around 7 times faster
here.

Unlike the last version this time we only optimize the common
case with 8 bits per word and SPI_LSB_FIRST cleared. The other
cases would require more bit shuffling of the data.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/spi/imx_spi.c | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++-
 include/spi/imx-spi.h |  3 ++-
 2 files changed, 74 insertions(+), 2 deletions(-)

diff --git a/drivers/spi/imx_spi.c b/drivers/spi/imx_spi.c
index 9a3f05c..2e48967 100644
--- a/drivers/spi/imx_spi.c
+++ b/drivers/spi/imx_spi.c
@@ -380,6 +380,77 @@ static void imx_spi_do_transfer(struct spi_device *spi)
 	}
 }
 
+static int cspi_2_3_xchg_burst(struct spi_device *spi)
+{
+	struct imx_spi *imx = container_of(spi->master, struct imx_spi, master);
+	int now, txlen, rxlen;
+	u32 ctrl;
+	void __iomem *base = imx->regs;
+
+	now = min(imx->xfer_len, 512);
+	now >>= 2;
+
+	if (!now)
+		return 0;
+
+	txlen = rxlen = now;
+
+	ctrl = readl(base + CSPI_2_3_CTRL);
+	ctrl &= ~(0xfff << CSPI_2_3_CTRL_BL_OFFSET);
+	ctrl |= ((txlen * 32) - 1) << CSPI_2_3_CTRL_BL_OFFSET;
+	ctrl |= 1 << 3;
+	writel(ctrl, base + CSPI_2_3_CTRL);
+
+	while (txlen || rxlen) {
+		u32 status = readl(base + CSPI_2_3_STAT);
+
+		if (txlen && !(status & CSPI_2_3_STAT_TF)) {
+			if (imx->tx_buf) {
+				u32 data = swab32(*(u32 *)imx->tx_buf);
+				writel(data, base + CSPI_2_3_TXDATA);
+				imx->tx_buf += sizeof(u32);
+			} else {
+				writel(0, base + CSPI_2_3_TXDATA);
+			}
+			txlen--;
+		}
+
+		if (rxlen && (status & CSPI_2_3_STAT_RR)) {
+			u32 data = readl(base + CSPI_2_3_RXDATA);
+
+			if (imx->rx_buf) {
+				*(u32 *)imx->rx_buf = swab32(data);
+				imx->rx_buf += sizeof(u32);
+			}
+
+			rxlen--;
+		}
+	}
+
+	imx->xfer_len -= now * 4;
+
+	return now;
+}
+
+static void cspi_2_3_do_transfer(struct spi_device *spi)
+{
+	struct imx_spi *imx = container_of(spi->master, struct imx_spi, master);
+	u32 ctrl;
+
+	if (imx->bits_per_word == 8 && !(spi->mode & SPI_LSB_FIRST))
+		while (cspi_2_3_xchg_burst(spi) > 0);
+
+	if (!imx->xfer_len)
+		return;
+
+	ctrl = readl(imx->regs + CSPI_2_3_CTRL);
+	ctrl &= ~(0xfff << CSPI_2_3_CTRL_BL_OFFSET);
+	ctrl |= (spi->bits_per_word - 1) << CSPI_2_3_CTRL_BL_OFFSET;
+	writel(ctrl, imx->regs + CSPI_2_3_CTRL);
+
+	imx_spi_do_transfer(spi);
+}
+
 static int imx_spi_transfer(struct spi_device *spi, struct spi_message *mesg)
 {
 	struct imx_spi *imx = container_of(spi->master, struct imx_spi, master);
@@ -437,7 +508,7 @@ static __maybe_unused struct spi_imx_devtype_data spi_imx_devtype_data_0_7 = {
 
 static __maybe_unused struct spi_imx_devtype_data spi_imx_devtype_data_2_3 = {
 	.chipselect = cspi_2_3_chipselect,
-	.do_transfer = imx_spi_do_transfer,
+	.do_transfer = cspi_2_3_do_transfer,
 	.xchg_single = cspi_2_3_xchg_single,
 };
 
diff --git a/include/spi/imx-spi.h b/include/spi/imx-spi.h
index 5c89634..221c665 100644
--- a/include/spi/imx-spi.h
+++ b/include/spi/imx-spi.h
@@ -79,6 +79,7 @@
 #define CSPI_2_3_INT_RREN		(1 <<  3)
 
 #define CSPI_2_3_STAT		0x18
-#define CSPI_2_3_STAT_RR		(1 <<  3)
+#define CSPI_2_3_STAT_TF		(1 << 2)
+#define CSPI_2_3_STAT_RR		(1 << 3)
 
 #endif /* __SPI_IMX_SPI_H */
-- 
2.6.2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] spi: i.MX: optimize transfers for ECSPI v2.3
  2015-11-23 11:14 [PATCH] spi: i.MX: optimize transfers for ECSPI v2.3 Sascha Hauer
@ 2015-11-24  7:07 ` Uwe Kleine-König
  2015-11-24  7:55   ` Sascha Hauer
  0 siblings, 1 reply; 3+ messages in thread
From: Uwe Kleine-König @ 2015-11-24  7:07 UTC (permalink / raw)
  To: Sascha Hauer; +Cc: Barebox List

Hello Sascha,

On Mon, Nov 23, 2015 at 12:14:41PM +0100, Sascha Hauer wrote:
> Instead of writing one word to the txfifo and then wait until
> one is received in the rxfifo we can write until the txfifos

My German feeling for English recommends s/until/while/

> are not full and read as long the rxfifos contain data. This
> makes transfers for the m25p80 driver around 7 times faster
> here.

Best regards
Uwe

-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] spi: i.MX: optimize transfers for ECSPI v2.3
  2015-11-24  7:07 ` Uwe Kleine-König
@ 2015-11-24  7:55   ` Sascha Hauer
  0 siblings, 0 replies; 3+ messages in thread
From: Sascha Hauer @ 2015-11-24  7:55 UTC (permalink / raw)
  To: Uwe Kleine-König; +Cc: Barebox List

On Tue, Nov 24, 2015 at 08:07:26AM +0100, Uwe Kleine-König wrote:
> Hello Sascha,
> 
> On Mon, Nov 23, 2015 at 12:14:41PM +0100, Sascha Hauer wrote:
> > Instead of writing one word to the txfifo and then wait until
> > one is received in the rxfifo we can write until the txfifos
> 
> My German feeling for English recommends s/until/while/

If you mean the second 'until' then I am with you.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-11-24  7:55 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-11-23 11:14 [PATCH] spi: i.MX: optimize transfers for ECSPI v2.3 Sascha Hauer
2015-11-24  7:07 ` Uwe Kleine-König
2015-11-24  7:55   ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox