public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Jagan Teki <jagan@amarulasolutions.com>
To: u-boot@lists.denx.de
Subject: [PATCH 01/11] spi: rk: Limit transfers to (64K - 1) bytes
Date: Sat, 21 Dec 2019 13:24:30 +0530	[thread overview]
Message-ID: <20191221075440.6944-2-jagan@amarulasolutions.com> (raw)
In-Reply-To: <20191221075440.6944-1-jagan@amarulasolutions.com>

The Rockchip SPI controller's length register only supports 16-bits,
yielding a maximum length of 64KiB (the CTRLR1 register holds "length -
1"). Trying to transfer more than that (e.g., with a large SPI flash
read) will cause the driver to hang.

Now, it seems that while theoretically we should be able to program
CTRLR1 with 0xffff, and get a 64KiB transfer, but that also seems to
cause the core to choke, so stick with a maximum of 64K - 1 bytes --
i.e., 0xffff.

Note, that the size is further divided into 'minus 1' while writing
into CTRLR1.

This change fixed two different read issues,

1. sf read failure when with > 0x10000

2. Boot from SPI flash failed during spi_flash_read call in
   common/spl/spl_spi.c

Observed and Tested in
- Rockpro64 with Gigadevice flash
- ROC-RK3399-PC with Winbond flash

Signed-off-by: Jagan Teki <jagan@amarulasolutions.com>
---
 drivers/spi/rk_spi.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/drivers/spi/rk_spi.c b/drivers/spi/rk_spi.c
index c04535ac44..95eeb8307a 100644
--- a/drivers/spi/rk_spi.c
+++ b/drivers/spi/rk_spi.c
@@ -27,6 +27,12 @@
 /* Change to 1 to output registers at the start of each transaction */
 #define DEBUG_RK_SPI	0
 
+/*
+ * ctrlr1 is 16-bits, so we should support lengths of 0xffff + 1. However,
+ * the controller seems to hang when given 0x10000, so stick with this for now.
+ */
+#define ROCKCHIP_SPI_MAX_TRANLEN		0xffff
+
 struct rockchip_spi_params {
 	/* RXFIFO overruns and TXFIFO underruns stop the master clock */
 	bool master_manages_fifo;
@@ -367,7 +373,7 @@ static inline int rockchip_spi_16bit_reader(struct udevice *dev,
 	 * represented in CTRLR1.
 	 */
 	if (data && data->master_manages_fifo)
-		max_chunk_size = 0x10000;
+		max_chunk_size = ROCKCHIP_SPI_MAX_TRANLEN;
 
 	// rockchip_spi_configure(dev, mode, size)
 	rkspi_enable_chip(regs, false);
@@ -451,7 +457,7 @@ static int rockchip_spi_xfer(struct udevice *dev, unsigned int bitlen,
 
 	/* This is the original 8bit reader/writer code */
 	while (len > 0) {
-		int todo = min(len, 0x10000);
+		int todo = min(len, ROCKCHIP_SPI_MAX_TRANLEN);
 
 		rkspi_enable_chip(regs, false);
 		writel(todo - 1, &regs->ctrlr1);
-- 
2.18.0.321.gffc6fa0e3

  reply	other threads:[~2019-12-21  7:54 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-21  7:54 [PATCH 00/11] rk3399: SPI boot support (fixes, updates) Jagan Teki
2019-12-21  7:54 ` Jagan Teki [this message]
2019-12-23  2:30   ` [PATCH 01/11] spi: rk: Limit transfers to (64K - 1) bytes Kever Yang
2019-12-27  5:55     ` Jagan Teki
2019-12-21  7:54 ` [PATCH 02/11] distro_bootcmd: Add SF support Jagan Teki
2019-12-30  3:07   ` Kever Yang
2020-01-20 17:22   ` Tom Rini
2020-01-20 17:40     ` Alexander Graf
2020-01-23 16:55       ` Jagan Teki
2020-01-23 17:03         ` Tom Rini
2020-01-23 17:11           ` Jagan Teki
2020-01-23 17:15             ` Tom Rini
2020-01-23 17:29               ` Jagan Teki
2020-01-23 17:59                 ` Tom Rini
2019-12-21  7:54 ` [PATCH 03/11] rockchip: Include SF on distrocmd devices Jagan Teki
2020-01-07  8:44   ` Kever Yang
2019-12-21  7:54 ` [PATCH 04/11] rk3399: Add boot flash script offet, size Jagan Teki
2019-12-30  3:06   ` Kever Yang
2019-12-21  7:54 ` [PATCH 05/11] rk3399: Check MMC env while defining it Jagan Teki
2019-12-30  3:06   ` Kever Yang
2019-12-21  7:54 ` [PATCH 06/11] env: kconfig: Restrict rockchip env for MMC Jagan Teki
2019-12-30  3:05   ` Kever Yang
2019-12-21  7:54 ` [PATCH 07/11] env: Enable SPI flash env for rockchip Jagan Teki
2019-12-23  2:34   ` Kever Yang
2019-12-27  6:50     ` Jagan Teki
2019-12-27 10:02       ` Kever Yang
2019-12-27 10:10         ` Jagan Teki
2019-12-27 10:30       ` Soeren Moch
2019-12-27 12:04         ` Jagan Teki
2019-12-27 13:19           ` Soeren Moch
2019-12-28 12:08             ` Jagan Teki
2019-12-30  9:04               ` Soeren Moch
2019-12-30  2:59   ` Kever Yang
2019-12-21  7:54 ` [PATCH 08/11] rockchip: dts: Sync ROC-RK3399-PC changes from Linux Jagan Teki
2019-12-30  3:00   ` Kever Yang
2019-12-21  7:54 ` [PATCH 09/11] roc-pc-rk3399: Enable SPI Flash Jagan Teki
2019-12-30  3:00   ` Kever Yang
2019-12-21  7:54 ` [PATCH 10/11] rockpro-rk3399: " Jagan Teki
2019-12-30  3:00   ` Kever Yang
2019-12-30 11:51   ` Emmanuel Vadot
2020-01-08 12:59     ` Jagan Teki
2019-12-21  7:54 ` [PATCH 11/11] roc-rk3399-pc: Add SPI boot support Jagan Teki
2019-12-30  3:05   ` Kever Yang
2019-12-30  7:52     ` Jagan Teki
2020-01-07  8:53       ` Kever Yang

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=20191221075440.6944-2-jagan@amarulasolutions.com \
    --to=jagan@amarulasolutions.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