All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] spi: stm32: FIFO threshold level - fix align packet size
@ 2020-12-21 12:35 Roman Guskov
  2020-12-21 12:51 ` Marek Vasut
  2020-12-21 17:30 ` Mark Brown
  0 siblings, 2 replies; 3+ messages in thread
From: Roman Guskov @ 2020-12-21 12:35 UTC (permalink / raw)
  To: linux-spi; +Cc: broonie, alexandre.torgue, linux-stm32, marex, Roman Guskov

if cur_bpw <= 8 and xfer_len < 4 then the value of fthlv will be 1 and
SPI registers content may have been lost.

* If SPI data register is accessed as a 16-bit register and DSIZE <= 8bit,
  better to select FTHLV = 2, 4, 6 etc

* If SPI data register is accessed as a 32-bit register and DSIZE > 8bit,
  better to select FTHLV = 2, 4, 6 etc, while if DSIZE <= 8bit,
  better to select FTHLV = 4, 8, 12 etc

Signed-off-by: Roman Guskov <rguskov@dh-electronics.com>
---
 drivers/spi/spi-stm32.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/spi/spi-stm32.c b/drivers/spi/spi-stm32.c
index 9d8ceb63f7db..417c40154477 100644
--- a/drivers/spi/spi-stm32.c
+++ b/drivers/spi/spi-stm32.c
@@ -494,9 +494,9 @@ static u32 stm32h7_spi_prepare_fthlv(struct stm32_spi *spi, u32 xfer_len)
 
 	/* align packet size with data registers access */
 	if (spi->cur_bpw > 8)
-		fthlv -= (fthlv % 2); /* multiple of 2 */
+		fthlv += (fthlv % 2) ? 1 : 0;
 	else
-		fthlv -= (fthlv % 4); /* multiple of 4 */
+		fthlv += (fthlv % 4) ? (4 - (fthlv % 4)) : 0;
 
 	if (!fthlv)
 		fthlv = 1;
-- 
2.11.0


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

* Re: [PATCH] spi: stm32: FIFO threshold level - fix align packet size
  2020-12-21 12:35 [PATCH] spi: stm32: FIFO threshold level - fix align packet size Roman Guskov
@ 2020-12-21 12:51 ` Marek Vasut
  2020-12-21 17:30 ` Mark Brown
  1 sibling, 0 replies; 3+ messages in thread
From: Marek Vasut @ 2020-12-21 12:51 UTC (permalink / raw)
  To: Roman Guskov, linux-spi
  Cc: broonie, alexandre.torgue, linux-stm32, Amelie DELAUNAY

On 12/21/20 1:35 PM, Roman Guskov wrote:
> if cur_bpw <= 8 and xfer_len < 4 then the value of fthlv will be 1 and
> SPI registers content may have been lost.
> 
> * If SPI data register is accessed as a 16-bit register and DSIZE <= 8bit,
>    better to select FTHLV = 2, 4, 6 etc
> 
> * If SPI data register is accessed as a 32-bit register and DSIZE > 8bit,
>    better to select FTHLV = 2, 4, 6 etc, while if DSIZE <= 8bit,
>    better to select FTHLV = 4, 8, 12 etc
> 
> Signed-off-by: Roman Guskov <rguskov@dh-electronics.com>

I think this should also have the following tag:

Fixes: dcbe0d84dfa5 ("spi: add driver for STM32 SPI controller")

> ---
>   drivers/spi/spi-stm32.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/spi/spi-stm32.c b/drivers/spi/spi-stm32.c
> index 9d8ceb63f7db..417c40154477 100644
> --- a/drivers/spi/spi-stm32.c
> +++ b/drivers/spi/spi-stm32.c
> @@ -494,9 +494,9 @@ static u32 stm32h7_spi_prepare_fthlv(struct stm32_spi *spi, u32 xfer_len)
>   
>   	/* align packet size with data registers access */
>   	if (spi->cur_bpw > 8)
> -		fthlv -= (fthlv % 2); /* multiple of 2 */
> +		fthlv += (fthlv % 2) ? 1 : 0;
>   	else
> -		fthlv -= (fthlv % 4); /* multiple of 4 */
> +		fthlv += (fthlv % 4) ? (4 - (fthlv % 4)) : 0;
>   
>   	if (!fthlv)
>   		fthlv = 1;
> 

Reviewed-by: Marek Vasut <marex@denx.de>

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

* Re: [PATCH] spi: stm32: FIFO threshold level - fix align packet size
  2020-12-21 12:35 [PATCH] spi: stm32: FIFO threshold level - fix align packet size Roman Guskov
  2020-12-21 12:51 ` Marek Vasut
@ 2020-12-21 17:30 ` Mark Brown
  1 sibling, 0 replies; 3+ messages in thread
From: Mark Brown @ 2020-12-21 17:30 UTC (permalink / raw)
  To: Roman Guskov, linux-spi; +Cc: linux-stm32, marex, alexandre.torgue

On Mon, 21 Dec 2020 13:35:32 +0100, Roman Guskov wrote:
> if cur_bpw <= 8 and xfer_len < 4 then the value of fthlv will be 1 and
> SPI registers content may have been lost.
> 
> * If SPI data register is accessed as a 16-bit register and DSIZE <= 8bit,
>   better to select FTHLV = 2, 4, 6 etc
> 
> * If SPI data register is accessed as a 32-bit register and DSIZE > 8bit,
>   better to select FTHLV = 2, 4, 6 etc, while if DSIZE <= 8bit,
>   better to select FTHLV = 4, 8, 12 etc

Applied to

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

Thanks!

[1/1] spi: stm32: FIFO threshold level - fix align packet size
      commit: a590370d918fc66c62df6620445791fbe840344a

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] 3+ messages in thread

end of thread, other threads:[~2020-12-21 17:31 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-21 12:35 [PATCH] spi: stm32: FIFO threshold level - fix align packet size Roman Guskov
2020-12-21 12:51 ` Marek Vasut
2020-12-21 17:30 ` Mark Brown

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.