linux-spi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 1/3] spi: rockchip: Config spi rx dma burst size depend on xfer length
@ 2020-07-22  8:37 Jon Lin
  2020-07-22  8:37 ` [PATCH v2 2/3] spi: rockchip: Support 64-location deep FIFOs Jon Lin
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Jon Lin @ 2020-07-22  8:37 UTC (permalink / raw)
  To: broonie
  Cc: heiko, linux-spi, linux-arm-kernel, linux-rockchip, linux-kernel,
	Jon Lin

The burst length can be adjusted according to the transmission
length to improve the transmission rate

Signed-off-by: Jon Lin <jon.lin@rock-chips.com>
---
 drivers/spi/spi-rockchip.c | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/drivers/spi/spi-rockchip.c b/drivers/spi/spi-rockchip.c
index 9b8a5e1233c0..63593a5b87fa 100644
--- a/drivers/spi/spi-rockchip.c
+++ b/drivers/spi/spi-rockchip.c
@@ -384,6 +384,19 @@ static void rockchip_spi_dma_txcb(void *data)
 	spi_finalize_current_transfer(ctlr);
 }
 
+static u32 rockchip_spi_calc_burst_size(u32 data_len)
+{
+	u32 i;
+
+	/* burst size: 1, 2, 4, 8 */
+	for (i = 1; i < 8; i <<= 1) {
+		if (data_len & i)
+			break;
+	}
+
+	return i;
+}
+
 static int rockchip_spi_prepare_dma(struct rockchip_spi *rs,
 		struct spi_controller *ctlr, struct spi_transfer *xfer)
 {
@@ -397,7 +410,8 @@ static int rockchip_spi_prepare_dma(struct rockchip_spi *rs,
 			.direction = DMA_DEV_TO_MEM,
 			.src_addr = rs->dma_addr_rx,
 			.src_addr_width = rs->n_bytes,
-			.src_maxburst = 1,
+			.src_maxburst = rockchip_spi_calc_burst_size(xfer->len /
+								     rs->n_bytes),
 		};
 
 		dmaengine_slave_config(ctlr->dma_rx, &rxconf);
@@ -525,7 +539,8 @@ static void rockchip_spi_config(struct rockchip_spi *rs,
 		writel_relaxed(rs->fifo_len / 2 - 1, rs->regs + ROCKCHIP_SPI_RXFTLR);
 
 	writel_relaxed(rs->fifo_len / 2, rs->regs + ROCKCHIP_SPI_DMATDLR);
-	writel_relaxed(0, rs->regs + ROCKCHIP_SPI_DMARDLR);
+	writel_relaxed(rockchip_spi_calc_burst_size(xfer->len / rs->n_bytes) - 1,
+		       rs->regs + ROCKCHIP_SPI_DMARDLR);
 	writel_relaxed(dmacr, rs->regs + ROCKCHIP_SPI_DMACR);
 
 	/* the hardware only supports an even clock divisor, so
-- 
2.17.1




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

* [PATCH v2 2/3] spi: rockchip: Support 64-location deep FIFOs
  2020-07-22  8:37 [PATCH v2 1/3] spi: rockchip: Config spi rx dma burst size depend on xfer length Jon Lin
@ 2020-07-22  8:37 ` Jon Lin
  2020-07-22  8:37 ` [PATCH v2 3/3] spi: rockchip: Fix error in SPI slave pio read Jon Lin
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: Jon Lin @ 2020-07-22  8:37 UTC (permalink / raw)
  To: broonie
  Cc: heiko, linux-spi, linux-arm-kernel, linux-rockchip, linux-kernel,
	Jon Lin

The FIFO depth of SPI V2 is 64 instead of 32, add support for it.

Signed-off-by: Jon Lin <jon.lin@rock-chips.com>
---
 drivers/spi/spi-rockchip.c | 25 ++++++++++++++-----------
 1 file changed, 14 insertions(+), 11 deletions(-)

diff --git a/drivers/spi/spi-rockchip.c b/drivers/spi/spi-rockchip.c
index 63593a5b87fa..a451dacab5cf 100644
--- a/drivers/spi/spi-rockchip.c
+++ b/drivers/spi/spi-rockchip.c
@@ -39,8 +39,9 @@
 #define ROCKCHIP_SPI_RISR			0x0034
 #define ROCKCHIP_SPI_ICR			0x0038
 #define ROCKCHIP_SPI_DMACR			0x003c
-#define ROCKCHIP_SPI_DMATDLR		0x0040
-#define ROCKCHIP_SPI_DMARDLR		0x0044
+#define ROCKCHIP_SPI_DMATDLR			0x0040
+#define ROCKCHIP_SPI_DMARDLR			0x0044
+#define ROCKCHIP_SPI_VERSION			0x0048
 #define ROCKCHIP_SPI_TXDR			0x0400
 #define ROCKCHIP_SPI_RXDR			0x0800
 
@@ -156,6 +157,8 @@
 #define ROCKCHIP_SPI_MAX_TRANLEN		0xffff
 
 #define ROCKCHIP_SPI_MAX_CS_NUM			2
+#define ROCKCHIP_SPI_VER2_TYPE1			0x05EC0002
+#define ROCKCHIP_SPI_VER2_TYPE2			0x00110002
 
 struct rockchip_spi {
 	struct device *dev;
@@ -206,17 +209,17 @@ static inline void wait_for_idle(struct rockchip_spi *rs)
 
 static u32 get_fifo_len(struct rockchip_spi *rs)
 {
-	u32 fifo;
+	u32 ver;
 
-	for (fifo = 2; fifo < 32; fifo++) {
-		writel_relaxed(fifo, rs->regs + ROCKCHIP_SPI_TXFTLR);
-		if (fifo != readl_relaxed(rs->regs + ROCKCHIP_SPI_TXFTLR))
-			break;
-	}
-
-	writel_relaxed(0, rs->regs + ROCKCHIP_SPI_TXFTLR);
+	ver = readl_relaxed(rs->regs + ROCKCHIP_SPI_VERSION);
 
-	return (fifo == 31) ? 0 : fifo;
+	switch (ver) {
+	case ROCKCHIP_SPI_VER2_TYPE1:
+	case ROCKCHIP_SPI_VER2_TYPE2:
+		return 64;
+	default:
+		return 32;
+	}
 }
 
 static void rockchip_spi_set_cs(struct spi_device *spi, bool enable)
-- 
2.17.1




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

* [PATCH v2 3/3] spi: rockchip: Fix error in SPI slave pio read
  2020-07-22  8:37 [PATCH v2 1/3] spi: rockchip: Config spi rx dma burst size depend on xfer length Jon Lin
  2020-07-22  8:37 ` [PATCH v2 2/3] spi: rockchip: Support 64-location deep FIFOs Jon Lin
@ 2020-07-22  8:37 ` Jon Lin
  2020-07-22 12:11   ` Emil Renner Berthing
  2020-07-22 12:08 ` [PATCH v2 1/3] spi: rockchip: Config spi rx dma burst size depend on xfer length Emil Renner Berthing
  2020-07-30 22:28 ` Mark Brown
  3 siblings, 1 reply; 6+ messages in thread
From: Jon Lin @ 2020-07-22  8:37 UTC (permalink / raw)
  To: broonie
  Cc: heiko, linux-spi, linux-arm-kernel, linux-rockchip, linux-kernel,
	Jon Lin

The RXFLR is possible larger than rx_left in Rockchip SPI, fix it.

Signed-off-by: Jon Lin <jon.lin@rock-chips.com>
Reviewed-by: Heiko Stuebner <heiko@sntech.de>
---
 drivers/spi/spi-rockchip.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/spi/spi-rockchip.c b/drivers/spi/spi-rockchip.c
index a451dacab5cf..75a8a9428ff8 100644
--- a/drivers/spi/spi-rockchip.c
+++ b/drivers/spi/spi-rockchip.c
@@ -291,7 +291,7 @@ static void rockchip_spi_pio_writer(struct rockchip_spi *rs)
 static void rockchip_spi_pio_reader(struct rockchip_spi *rs)
 {
 	u32 words = readl_relaxed(rs->regs + ROCKCHIP_SPI_RXFLR);
-	u32 rx_left = rs->rx_left - words;
+	u32 rx_left = (rs->rx_left > words) ? rs->rx_left - words : 0;
 
 	/* the hardware doesn't allow us to change fifo threshold
 	 * level while spi is enabled, so instead make sure to leave
-- 
2.17.1




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

* Re: [PATCH v2 1/3] spi: rockchip: Config spi rx dma burst size depend on xfer length
  2020-07-22  8:37 [PATCH v2 1/3] spi: rockchip: Config spi rx dma burst size depend on xfer length Jon Lin
  2020-07-22  8:37 ` [PATCH v2 2/3] spi: rockchip: Support 64-location deep FIFOs Jon Lin
  2020-07-22  8:37 ` [PATCH v2 3/3] spi: rockchip: Fix error in SPI slave pio read Jon Lin
@ 2020-07-22 12:08 ` Emil Renner Berthing
  2020-07-30 22:28 ` Mark Brown
  3 siblings, 0 replies; 6+ messages in thread
From: Emil Renner Berthing @ 2020-07-22 12:08 UTC (permalink / raw)
  To: Jon Lin
  Cc: Mark Brown, Heiko Stuebner, Linux Kernel Mailing List, linux-spi,
	open list:ARM/Rockchip SoC...,
	linux-arm-kernel

On Wed, 22 Jul 2020 at 10:41, Jon Lin <jon.lin@rock-chips.com> wrote:
>
> The burst length can be adjusted according to the transmission
> length to improve the transmission rate
>
> Signed-off-by: Jon Lin <jon.lin@rock-chips.com>

For the whole series you can add
Reviewed-by: Emil Renner Berthing <kernel@esmil.dk>
Tested-by: Emil Renner Berthing <kernel@esmil.dk>

> ---
>  drivers/spi/spi-rockchip.c | 19 +++++++++++++++++--
>  1 file changed, 17 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/spi/spi-rockchip.c b/drivers/spi/spi-rockchip.c
> index 9b8a5e1233c0..63593a5b87fa 100644
> --- a/drivers/spi/spi-rockchip.c
> +++ b/drivers/spi/spi-rockchip.c
> @@ -384,6 +384,19 @@ static void rockchip_spi_dma_txcb(void *data)
>         spi_finalize_current_transfer(ctlr);
>  }
>
> +static u32 rockchip_spi_calc_burst_size(u32 data_len)
> +{
> +       u32 i;
> +
> +       /* burst size: 1, 2, 4, 8 */
> +       for (i = 1; i < 8; i <<= 1) {
> +               if (data_len & i)
> +                       break;
> +       }
> +
> +       return i;
> +}
> +
>  static int rockchip_spi_prepare_dma(struct rockchip_spi *rs,
>                 struct spi_controller *ctlr, struct spi_transfer *xfer)
>  {
> @@ -397,7 +410,8 @@ static int rockchip_spi_prepare_dma(struct rockchip_spi *rs,
>                         .direction = DMA_DEV_TO_MEM,
>                         .src_addr = rs->dma_addr_rx,
>                         .src_addr_width = rs->n_bytes,
> -                       .src_maxburst = 1,
> +                       .src_maxburst = rockchip_spi_calc_burst_size(xfer->len /
> +                                                                    rs->n_bytes),
>                 };
>
>                 dmaengine_slave_config(ctlr->dma_rx, &rxconf);
> @@ -525,7 +539,8 @@ static void rockchip_spi_config(struct rockchip_spi *rs,
>                 writel_relaxed(rs->fifo_len / 2 - 1, rs->regs + ROCKCHIP_SPI_RXFTLR);
>
>         writel_relaxed(rs->fifo_len / 2, rs->regs + ROCKCHIP_SPI_DMATDLR);
> -       writel_relaxed(0, rs->regs + ROCKCHIP_SPI_DMARDLR);
> +       writel_relaxed(rockchip_spi_calc_burst_size(xfer->len / rs->n_bytes) - 1,
> +                      rs->regs + ROCKCHIP_SPI_DMARDLR);
>         writel_relaxed(dmacr, rs->regs + ROCKCHIP_SPI_DMACR);
>
>         /* the hardware only supports an even clock divisor, so
> --
> 2.17.1
>
>
>
>
> _______________________________________________
> Linux-rockchip mailing list
> Linux-rockchip@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-rockchip

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

* Re: [PATCH v2 3/3] spi: rockchip: Fix error in SPI slave pio read
  2020-07-22  8:37 ` [PATCH v2 3/3] spi: rockchip: Fix error in SPI slave pio read Jon Lin
@ 2020-07-22 12:11   ` Emil Renner Berthing
  0 siblings, 0 replies; 6+ messages in thread
From: Emil Renner Berthing @ 2020-07-22 12:11 UTC (permalink / raw)
  To: Jon Lin
  Cc: Mark Brown, Heiko Stuebner, Linux Kernel Mailing List, linux-spi,
	open list:ARM/Rockchip SoC...,
	linux-arm-kernel

On Wed, 22 Jul 2020 at 10:38, Jon Lin <jon.lin@rock-chips.com> wrote:
>
> The RXFLR is possible larger than rx_left in Rockchip SPI, fix it.
>
> Signed-off-by: Jon Lin <jon.lin@rock-chips.com>
> Reviewed-by: Heiko Stuebner <heiko@sntech.de>

In addition to my review and test you should probably also add
Fixes: 01b59ce5dac8 ("spi: rockchip: use irq rather than polling")
..so this will be picked up in the stable trees

/Emil

> ---
>  drivers/spi/spi-rockchip.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/spi/spi-rockchip.c b/drivers/spi/spi-rockchip.c
> index a451dacab5cf..75a8a9428ff8 100644
> --- a/drivers/spi/spi-rockchip.c
> +++ b/drivers/spi/spi-rockchip.c
> @@ -291,7 +291,7 @@ static void rockchip_spi_pio_writer(struct rockchip_spi *rs)
>  static void rockchip_spi_pio_reader(struct rockchip_spi *rs)
>  {
>         u32 words = readl_relaxed(rs->regs + ROCKCHIP_SPI_RXFLR);
> -       u32 rx_left = rs->rx_left - words;
> +       u32 rx_left = (rs->rx_left > words) ? rs->rx_left - words : 0;
>
>         /* the hardware doesn't allow us to change fifo threshold
>          * level while spi is enabled, so instead make sure to leave
> --
> 2.17.1
>
>
>
>
> _______________________________________________
> Linux-rockchip mailing list
> Linux-rockchip@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-rockchip

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

* Re: [PATCH v2 1/3] spi: rockchip: Config spi rx dma burst size depend on xfer length
  2020-07-22  8:37 [PATCH v2 1/3] spi: rockchip: Config spi rx dma burst size depend on xfer length Jon Lin
                   ` (2 preceding siblings ...)
  2020-07-22 12:08 ` [PATCH v2 1/3] spi: rockchip: Config spi rx dma burst size depend on xfer length Emil Renner Berthing
@ 2020-07-30 22:28 ` Mark Brown
  3 siblings, 0 replies; 6+ messages in thread
From: Mark Brown @ 2020-07-30 22:28 UTC (permalink / raw)
  To: Jon Lin; +Cc: linux-arm-kernel, heiko, linux-rockchip, linux-spi, linux-kernel

On Wed, 22 Jul 2020 16:37:35 +0800, Jon Lin wrote:
> The burst length can be adjusted according to the transmission
> length to improve the transmission rate

Applied to

   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git for-next

Thanks!

[1/3] spi: rockchip: Config spi rx dma burst size depend on xfer length
      commit: 4d9ca632c847ab88f2f7e7e2747aea966f1390ce
[2/3] spi: rockchip: Support 64-location deep FIFOs
      commit: 13a96935e6f66bafb6da92791120546a4bf20889
[3/3] spi: rockchip: Fix error in SPI slave pio read
      commit: 4294e4accf8d695ea5605f6b189008b692e3e82c

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark

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

end of thread, other threads:[~2020-07-30 22:29 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-22  8:37 [PATCH v2 1/3] spi: rockchip: Config spi rx dma burst size depend on xfer length Jon Lin
2020-07-22  8:37 ` [PATCH v2 2/3] spi: rockchip: Support 64-location deep FIFOs Jon Lin
2020-07-22  8:37 ` [PATCH v2 3/3] spi: rockchip: Fix error in SPI slave pio read Jon Lin
2020-07-22 12:11   ` Emil Renner Berthing
2020-07-22 12:08 ` [PATCH v2 1/3] spi: rockchip: Config spi rx dma burst size depend on xfer length Emil Renner Berthing
2020-07-30 22:28 ` Mark Brown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).