public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Sean Anderson <seanga2@gmail.com>
To: u-boot@lists.denx.de
Subject: [PATCH v2 10/10] spi: dw: Support clock stretching
Date: Fri,  2 Apr 2021 19:05:15 -0400	[thread overview]
Message-ID: <20210402230515.177825-11-seanga2@gmail.com> (raw)
In-Reply-To: <20210402230515.177825-1-seanga2@gmail.com>

We don't always read/write to the FIFO fast enough. Enable clock stretching
for enhanced SPI transfers. This is only possible with DWC SSI devices more
recent than 1.01a. We also need to set the RXFTLR register to tell the
device when to start reciving again. In particular, the default of 0 will
result in the device never restarting reception if there is an overflow. On
the transmit side, we need to set CTRL1 so that the device knows when to
keep stretching the clock if the FIFO is empty.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
---

(no changes since v1)

 drivers/spi/designware_spi.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/spi/designware_spi.c b/drivers/spi/designware_spi.c
index 64a3a8556b..44fb679fdb 100644
--- a/drivers/spi/designware_spi.c
+++ b/drivers/spi/designware_spi.c
@@ -258,6 +258,7 @@ static u32 dw_spi_update_spi_cr0(const struct spi_mem_op *op)
 	       | FIELD_PREP(SPI_CTRLR0_ADDR_L_MASK, op->addr.nbytes * 2)
 	       | FIELD_PREP(SPI_CTRLR0_INST_L_MASK, INST_L_8)
 	       | FIELD_PREP(SPI_CTRLR0_WAIT_CYCLES_MASK, wait_cycles)
+	       | SPI_CTRLR0_CLK_STRETCH_EN;
 }
 
 static int request_gpio_cs(struct udevice *bus)
@@ -360,6 +361,9 @@ static void spi_hw_init(struct udevice *bus, struct dw_spi_priv *priv)
 		priv->fifo_len = (fifo == 1) ? 0 : fifo;
 		dw_write(priv, DW_SPI_TXFTLR, 0);
 	}
+
+	/* Set receive fifo interrupt level register for clock stretching */
+	dw_write(priv, DW_SPI_RXFTLR, priv->fifo_len - 1);
 }
 
 /*
@@ -782,8 +786,7 @@ static int dw_spi_exec_op(struct spi_slave *slave, const struct spi_mem_op *op)
 
 	dw_write(priv, DW_SPI_SSIENR, 0);
 	dw_write(priv, DW_SPI_CTRLR0, cr0);
-	if (read)
-		dw_write(priv, DW_SPI_CTRLR1, op->data.nbytes - 1);
+	dw_write(priv, DW_SPI_CTRLR1, op->data.nbytes - 1);
 	if (priv->spi_frf != CTRLR0_SPI_FRF_BYTE)
 		dw_write(priv, DW_SPI_SPI_CTRL0, spi_cr0);
 	dw_write(priv, DW_SPI_SSIENR, 1);
-- 
2.31.0

  parent reply	other threads:[~2021-04-02 23:05 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-02 23:05 [PATCH v2 00/10] spi: dw: Add support for DUAL/QUAD/OCTAL modes Sean Anderson
2021-04-02 23:05 ` [PATCH v2 01/10] mtd: spi-mem: Export spi_mem_default_supports_op Sean Anderson
2021-04-02 23:05 ` [PATCH v2 02/10] spi: spi-mem: Add debug message for spi-mem ops Sean Anderson
2021-04-02 23:05 ` [PATCH v2 03/10] spi: dw: Log status register on timeout Sean Anderson
2021-04-02 23:05 ` [PATCH v2 04/10] spi: dw: Actually mask interrupts Sean Anderson
2021-04-02 23:05 ` [PATCH v2 05/10] spi: dw: Switch to capabilities Sean Anderson
2021-04-02 23:05 ` [PATCH v2 06/10] spi: dw: Rewrite poll_transfer logic Sean Anderson
2021-04-05  0:47   ` Damien Le Moal
2021-04-05  1:11     ` Sean Anderson
2021-04-02 23:05 ` [PATCH v2 07/10] spi: dw: Add ENHANCED cap Sean Anderson
2021-04-02 23:05 ` [PATCH v2 08/10] spi: dw: Define registers for enhanced mode Sean Anderson
2021-04-02 23:05 ` [PATCH v2 09/10] spi: dw: Support enhanced SPI Sean Anderson
2021-04-02 23:05 ` Sean Anderson [this message]
2021-04-02 23:07 ` [PATCH v2 00/10] spi: dw: Add support for DUAL/QUAD/OCTAL modes Sean Anderson
2021-04-19  7:06   ` Jagan Teki
2021-04-19 13:19     ` Sean Anderson
2021-04-19 13:45       ` Jagan Teki

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=20210402230515.177825-11-seanga2@gmail.com \
    --to=seanga2@gmail.com \
    --cc=u-boot@lists.denx.de \
    /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