linux-spi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] spi: spi-imx: fix off-by-one in mx51 CPU mode burst length
@ 2024-03-10  2:25 Adam Butcher
  0 siblings, 0 replies; 4+ messages in thread
From: Adam Butcher @ 2024-03-10  2:25 UTC (permalink / raw)
  To: linux-kernel; +Cc: linux-spi

From: Adam Butcher <adam@jessamine.co.uk>

992e1211dc91 ("spi: imx: fix the burst length at DMA mode and CPU mode")
corrects three cases of setting the ECSPI burst length but erroneously
leaves the in-range CPU case one bit to big (in that register a value of
0 means 1 bit).  The effect was that transmissions that should have been
8-bit bytes appeared as 9-bit causing failed communication with SPI
devices.

It seems the original patch submission up to v4 did not contain the bug.
It was introduced in the v5 update.

Link: https://lore.kernel.org/all/20240201105451.507005-1-carlos.song@nxp.com/
Link: https://lore.kernel.org/all/20240204091912.36488-1-carlos.song@nxp.com/
Fixes: 992e1211dc91 ("spi: imx: fix the burst length at DMA mode and CPU mode")
Signed-off-by: Adam Butcher <adam@jessamine.co.uk>
---
 drivers/spi/spi-imx.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/spi/spi-imx.c b/drivers/spi/spi-imx.c
index 7c1fcd5ed52f7..100552e6c56bc 100644
--- a/drivers/spi/spi-imx.c
+++ b/drivers/spi/spi-imx.c
@@ -743,8 +743,8 @@ static int mx51_ecspi_prepare_transfer(struct spi_imx_data *spi_imx,
 				ctrl |= (MX51_ECSPI_CTRL_MAX_BURST * BITS_PER_BYTE - 1)
 						<< MX51_ECSPI_CTRL_BL_OFFSET;
 			else
-				ctrl |= spi_imx->count / DIV_ROUND_UP(spi_imx->bits_per_word,
-						BITS_PER_BYTE) * spi_imx->bits_per_word
+				ctrl |= (spi_imx->count / DIV_ROUND_UP(spi_imx->bits_per_word,
+						BITS_PER_BYTE) * spi_imx->bits_per_word - 1)
 						<< MX51_ECSPI_CTRL_BL_OFFSET;
 		}
 	}
-- 
2.43.0




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

* Re: [PATCH] spi: spi-imx: fix off-by-one in mx51 CPU mode burst length
  2024-03-13 18:13 ` Adam Butcher
@ 2024-03-13 18:19   ` Mark Brown
  0 siblings, 0 replies; 4+ messages in thread
From: Mark Brown @ 2024-03-13 18:19 UTC (permalink / raw)
  To: Adam Butcher
  Cc: shawnguo, s.hauer, kernel, linux-imx, benjamin, stefanmoring,
	carlos.song, linux-spi, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 404 bytes --]

On Wed, Mar 13, 2024 at 06:13:54PM -0000, Adam Butcher wrote:
> From: Adam Butcher <adam@jessamine.co.uk>
> 
> [Apologies, rubbish mailer corrupted the previous re-addressed post]

Please put administrative stuff like this after the --- so that it
doesn't end up in the changelog.  Hopefully none of the tooling gets
confused by having the same thing posted twice with two different
contents...

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

* Re: [PATCH] spi: spi-imx: fix off-by-one in mx51 CPU mode burst length
  2024-03-13 18:00 Adam Butcher
@ 2024-03-13 18:13 ` Adam Butcher
  2024-03-13 18:19   ` Mark Brown
  0 siblings, 1 reply; 4+ messages in thread
From: Adam Butcher @ 2024-03-13 18:13 UTC (permalink / raw)
  To: Mark Brown, shawnguo, s.hauer, kernel, linux-imx, benjamin,
	stefanmoring, carlos.song
  Cc: linux-spi, linux-kernel

From: Adam Butcher <adam@jessamine.co.uk>

[Apologies, rubbish mailer corrupted the previous re-addressed post]

992e1211dc91 ("spi: imx: fix the burst length at DMA mode and CPU mode")
corrects three cases of setting the ECSPI burst length but erroneously
leaves the in-range CPU case one bit to big (in that register a value of
0 means 1 bit).  The effect was that transmissions that should have been
8-bit bytes appeared as 9-bit causing failed communication with SPI
devices.

It seems the original patch submission up to v4 did not contain the bug.
It was introduced in the v5 update.

Link: https://lore.kernel.org/all/20240201105451.507005-1-carlos.song@nxp.com/
Link: https://lore.kernel.org/all/20240204091912.36488-1-carlos.song@nxp.com/
Fixes: 992e1211dc91 ("spi: imx: fix the burst length at DMA mode and CPU mode")
Signed-off-by: Adam Butcher <adam@jessamine.co.uk>
---
 drivers/spi/spi-imx.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/spi/spi-imx.c b/drivers/spi/spi-imx.c
index 7c1fcd5ed52f7..100552e6c56bc 100644
--- a/drivers/spi/spi-imx.c
+++ b/drivers/spi/spi-imx.c
@@ -743,8 +743,8 @@ static int mx51_ecspi_prepare_transfer(struct spi_imx_data *spi_imx,
 				ctrl |= (MX51_ECSPI_CTRL_MAX_BURST * BITS_PER_BYTE - 1)
 						<< MX51_ECSPI_CTRL_BL_OFFSET;
 			else
-				ctrl |= spi_imx->count / DIV_ROUND_UP(spi_imx->bits_per_word,
-						BITS_PER_BYTE) * spi_imx->bits_per_word
+				ctrl |= (spi_imx->count / DIV_ROUND_UP(spi_imx->bits_per_word,
+						BITS_PER_BYTE) * spi_imx->bits_per_word - 1)
 						<< MX51_ECSPI_CTRL_BL_OFFSET;
 		}
 	}
-- 
2.43.0





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

* [PATCH] spi: spi-imx: fix off-by-one in mx51 CPU mode burst length
@ 2024-03-13 18:00 Adam Butcher
  2024-03-13 18:13 ` Adam Butcher
  0 siblings, 1 reply; 4+ messages in thread
From: Adam Butcher @ 2024-03-13 18:00 UTC (permalink / raw)
  To: Mark Brown, shawnguo, s.hauer, kernel, linux-imx, benjamin,
	stefanmoring, carlos.song
  Cc: linux-spi, linux-kernel

 From: Adam Butcher <adam@jessamine.co.uk>

992e1211dc91 ("spi: imx: fix the burst length at DMA mode and CPU mode")
corrects three cases of setting the ECSPI burst length but erroneously
leaves the in-range CPU case one bit to big (in that register a value of
0 means 1 bit).  The effect was that transmissions that should have been
8-bit bytes appeared as 9-bit causing failed communication with SPI
devices.

It seems the original patch submission up to v4 did not contain the bug.
It was introduced in the v5 update.

Link: 
https://lore.kernel.org/all/20240201105451.507005-1-carlos.song@nxp.com/
Link: 
https://lore.kernel.org/all/20240204091912.36488-1-carlos.song@nxp.com/
Fixes: 992e1211dc91 ("spi: imx: fix the burst length at DMA mode and CPU 
mode")
Signed-off-by: Adam Butcher <adam@jessamine.co.uk>
---
  drivers/spi/spi-imx.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/spi/spi-imx.c b/drivers/spi/spi-imx.c
index 7c1fcd5ed52f7..100552e6c56bc 100644
--- a/drivers/spi/spi-imx.c
+++ b/drivers/spi/spi-imx.c
@@ -743,8 +743,8 @@ static int mx51_ecspi_prepare_transfer(struct 
spi_imx_data *spi_imx,
  				ctrl |= (MX51_ECSPI_CTRL_MAX_BURST * BITS_PER_BYTE - 1)
  						<< MX51_ECSPI_CTRL_BL_OFFSET;
  			else
-				ctrl |= spi_imx->count / DIV_ROUND_UP(spi_imx->bits_per_word,
-						BITS_PER_BYTE) * spi_imx->bits_per_word
+				ctrl |= (spi_imx->count / DIV_ROUND_UP(spi_imx->bits_per_word,
+						BITS_PER_BYTE) * spi_imx->bits_per_word - 1)
  						<< MX51_ECSPI_CTRL_BL_OFFSET;
  		}
  	}
-- 
2.43.0



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

end of thread, other threads:[~2024-03-13 18:19 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-10  2:25 [PATCH] spi: spi-imx: fix off-by-one in mx51 CPU mode burst length Adam Butcher
2024-03-13 18:00 Adam Butcher
2024-03-13 18:13 ` Adam Butcher
2024-03-13 18:19   ` 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).