diff mbox series

spi: Increase imx51 ecspi burst length based on transfer length

Message ID 20230628125406.237949-1-stefan.moring@technolution.nl (mailing list archive)
State Accepted
Commit 15a6af94a2779d5dfb42ee4bfac858ea8e964a3f
Headers show
Series spi: Increase imx51 ecspi burst length based on transfer length | expand

Commit Message

Stefan Moring June 28, 2023, 12:54 p.m. UTC
IMX51 supports 4096 bit burst lengths. Using the spi transfer length
instead of bits_per_word increases performance significantly.

Signed-off-by: Stefan Moring <stefan.moring@technolution.nl>
---
 drivers/spi/spi-imx.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

Comments

Fabio Estevam June 28, 2023, 1:16 p.m. UTC | #1
Hi Stefan,

On Wed, Jun 28, 2023 at 9:54 AM Stefan Moring
<stefan.moring@technolution.nl> wrote:
>
> IMX51 supports 4096 bit burst lengths. Using the spi transfer length
> instead of bits_per_word increases performance significantly.

Could you please share the performance increase after this change?

Thanks
Stefan Moring June 28, 2023, 1:20 p.m. UTC | #2
Hi Fabio,

In our application we send ~80kB at 10MHz. The total transfer time
went from ~80ms to 67ms, so that would be a reduction of 15%.
I tested it on an IMX8MM platform.

Kind regards,

Stefan Moring

Op wo 28 jun 2023 om 15:16 schreef Fabio Estevam <festevam@gmail.com>:
>
> Hi Stefan,
>
> On Wed, Jun 28, 2023 at 9:54 AM Stefan Moring
> <stefan.moring@technolution.nl> wrote:
> >
> > IMX51 supports 4096 bit burst lengths. Using the spi transfer length
> > instead of bits_per_word increases performance significantly.
>
> Could you please share the performance increase after this change?
>
> Thanks
Mark Brown July 11, 2023, 10:04 p.m. UTC | #3
On Wed, 28 Jun 2023 14:54:06 +0200, Stefan Moring wrote:
> IMX51 supports 4096 bit burst lengths. Using the spi transfer length
> instead of bits_per_word increases performance significantly.
> 
> 

Applied to

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

Thanks!

[1/1] spi: Increase imx51 ecspi burst length based on transfer length
      commit: 15a6af94a2779d5dfb42ee4bfac858ea8e964a3f

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
Sebastian Reichel Sept. 14, 2023, 10:47 p.m. UTC | #4
Hi,

On Wed, Jun 28, 2023 at 02:54:06PM +0200, Stefan Moring wrote:
> IMX51 supports 4096 bit burst lengths. Using the spi transfer length
> instead of bits_per_word increases performance significantly.
> 
> Signed-off-by: Stefan Moring <stefan.moring@technolution.nl>
> ---

I have an i.MX6ULL system with "inanbo,t28cp45tn89-v17" panel, which
breaks due to this change. Reverting this patch results in working
panel. Note, that the panel driver [0] does 'spi->bits_per_word = 9;'.

[0] drivers/gpu/drm/panel/panel-sitronix-st7789v.c

-- Sebastian

>  drivers/spi/spi-imx.c | 11 ++++++++---
>  1 file changed, 8 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/spi/spi-imx.c b/drivers/spi/spi-imx.c
> index 34e5f81ec431..cbd306c25d28 100644
> --- a/drivers/spi/spi-imx.c
> +++ b/drivers/spi/spi-imx.c
> @@ -644,9 +644,13 @@ static int mx51_ecspi_prepare_transfer(struct spi_imx_data *spi_imx,
>  	if (spi_imx->slave_mode && is_imx53_ecspi(spi_imx))
>  		ctrl |= (spi_imx->slave_burst * 8 - 1)
>  			<< MX51_ECSPI_CTRL_BL_OFFSET;
> -	else
> -		ctrl |= (spi_imx->bits_per_word - 1)
> -			<< MX51_ECSPI_CTRL_BL_OFFSET;
> +	else {
> +		if (spi_imx->count >= 512)
> +			ctrl |= 0xFFF << MX51_ECSPI_CTRL_BL_OFFSET;
> +		else
> +			ctrl |= (spi_imx->count*8 - 1)
> +				<< MX51_ECSPI_CTRL_BL_OFFSET;
> +	}
>  
>  	/* set clock speed */
>  	ctrl &= ~(0xf << MX51_ECSPI_CTRL_POSTDIV_OFFSET |
> @@ -1243,6 +1247,7 @@ static int spi_imx_setupxfer(struct spi_device *spi,
>  		spi_imx->spi_bus_clk = t->speed_hz;
>  
>  	spi_imx->bits_per_word = t->bits_per_word;
> +	spi_imx->count = t->len;
>  
>  	/*
>  	 * Initialize the functions for transfer. To transfer non byte-aligned
> -- 
> 2.34.1
>
Sebastian Reichel Sept. 16, 2023, 11:53 p.m. UTC | #5
Hi,

On Fri, Sep 15, 2023 at 07:55:23AM +0200, Stefan Moring wrote:
> Op vr 15 sep 2023 om 00:47 schreef Sebastian Reichel <sre@kernel.org>:
> > On Wed, Jun 28, 2023 at 02:54:06PM +0200, Stefan Moring wrote:
> > > IMX51 supports 4096 bit burst lengths. Using the spi transfer length
> > > instead of bits_per_word increases performance significantly.
> > >
> > > Signed-off-by: Stefan Moring <stefan.moring@technolution.nl>
> > > ---
> >
> > I have an i.MX6ULL system with "inanbo,t28cp45tn89-v17" panel, which
> > breaks due to this change. Reverting this patch results in working
> > panel. Note, that the panel driver [0] does 'spi->bits_per_word = 9;'.
> >
> > [0] drivers/gpu/drm/panel/panel-sitronix-st7789v.c
>
> Would changing line 665 to ctrl |= (spi_imx->count * spi_imx->bits_per_word
> - 1) fix the issue?

--- a/drivers/spi/spi-imx.c
+++ b/drivers/spi/spi-imx.c
@@ -662,7 +662,7 @@ static int mx51_ecspi_prepare_transfer(struct spi_imx_data *spi_imx,
                if (spi_imx->count >= 512)
                        ctrl |= 0xFFF << MX51_ECSPI_CTRL_BL_OFFSET;
                else
-                       ctrl |= (spi_imx->count*8 - 1)
+                       ctrl |= (spi_imx->count*spi_imx->bits_per_word - 1)
                                << MX51_ECSPI_CTRL_BL_OFFSET;
        }

on top of 6.6-rc1 fixes the problem. Will you send a proper patch with

Reported-by: Sebastian Reichel <sre@kernel.org>
Fixes: 15a6af94a277 ("spi: Increase imx51 ecspi burst length based on transfer length")

or should I do it?

Greetings,

-- Sebastian
diff mbox series

Patch

diff --git a/drivers/spi/spi-imx.c b/drivers/spi/spi-imx.c
index 34e5f81ec431..cbd306c25d28 100644
--- a/drivers/spi/spi-imx.c
+++ b/drivers/spi/spi-imx.c
@@ -644,9 +644,13 @@  static int mx51_ecspi_prepare_transfer(struct spi_imx_data *spi_imx,
 	if (spi_imx->slave_mode && is_imx53_ecspi(spi_imx))
 		ctrl |= (spi_imx->slave_burst * 8 - 1)
 			<< MX51_ECSPI_CTRL_BL_OFFSET;
-	else
-		ctrl |= (spi_imx->bits_per_word - 1)
-			<< MX51_ECSPI_CTRL_BL_OFFSET;
+	else {
+		if (spi_imx->count >= 512)
+			ctrl |= 0xFFF << MX51_ECSPI_CTRL_BL_OFFSET;
+		else
+			ctrl |= (spi_imx->count*8 - 1)
+				<< MX51_ECSPI_CTRL_BL_OFFSET;
+	}
 
 	/* set clock speed */
 	ctrl &= ~(0xf << MX51_ECSPI_CTRL_POSTDIV_OFFSET |
@@ -1243,6 +1247,7 @@  static int spi_imx_setupxfer(struct spi_device *spi,
 		spi_imx->spi_bus_clk = t->speed_hz;
 
 	spi_imx->bits_per_word = t->bits_per_word;
+	spi_imx->count = t->len;
 
 	/*
 	 * Initialize the functions for transfer. To transfer non byte-aligned