[PATCH] spi: stm32: Simplify stm32h7_spi_prepare_fthlv()

Subsystems: spi subsystem, st stm32 spi driver, the rest

STALE2031d LANDED

Landed in mainline as 970e8eaa0819 on 2021-01-13.

2 messages, 2 authors, 2021-01-13 · open the first message on its own page

[PATCH] spi: stm32: Simplify stm32h7_spi_prepare_fthlv()

From: Marek Vasut <marex@denx.de>
Date: 2021-01-04 12:33:14

Simplify stm32h7_spi_prepare_fthlv() function implementation,
no functional change intended.

Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Alain Volmat <redacted>
Cc: Alexandre Torgue <redacted>
Cc: Amelie Delaunay <redacted>
Cc: Antonio Borneo <redacted>
Cc: Mark Brown <broonie@kernel.org>
Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
Cc: Roman Guskov <redacted>
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-stm32@st-md-mailman.stormreply.com
To: linux-spi@vger.kernel.org
---
NOTE: Please review thoroughly and test
---
 drivers/spi/spi-stm32.c | 28 ++++------------------------
 1 file changed, 4 insertions(+), 24 deletions(-)
diff --git a/drivers/spi/spi-stm32.c b/drivers/spi/spi-stm32.c
index 6017209c6d2f..510738191cd1 100644
--- a/drivers/spi/spi-stm32.c
+++ b/drivers/spi/spi-stm32.c
@@ -473,34 +473,14 @@ static int stm32_spi_prepare_mbr(struct stm32_spi *spi, u32 speed_hz,
  */
 static u32 stm32h7_spi_prepare_fthlv(struct stm32_spi *spi, u32 xfer_len)
 {
-	u32 fthlv, half_fifo, packet;
+	u32 packet, bpw;
 
 	/* data packet should not exceed 1/2 of fifo space */
-	half_fifo = (spi->fifo_size / 2);
-
-	/* data_packet should not exceed transfer length */
-	if (half_fifo > xfer_len)
-		packet = xfer_len;
-	else
-		packet = half_fifo;
-
-	if (spi->cur_bpw <= 8)
-		fthlv = packet;
-	else if (spi->cur_bpw <= 16)
-		fthlv = packet / 2;
-	else
-		fthlv = packet / 4;
+	packet = clamp(xfer_len, 1U, spi->fifo_size / 2);
 
 	/* align packet size with data registers access */
-	if (spi->cur_bpw > 8)
-		fthlv += (fthlv % 2) ? 1 : 0;
-	else
-		fthlv += (fthlv % 4) ? (4 - (fthlv % 4)) : 0;
-
-	if (!fthlv)
-		fthlv = 1;
-
-	return fthlv;
+	bpw = DIV_ROUND_UP(spi->cur_bpw, 8);
+	return DIV_ROUND_UP(packet, bpw);
 }
 
 /**
-- 
2.29.2


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

Re: [PATCH] spi: stm32: Simplify stm32h7_spi_prepare_fthlv()

From: Mark Brown <broonie@kernel.org>
Date: 2021-01-13 15:31:35

On Mon, 4 Jan 2021 13:31:14 +0100, Marek Vasut wrote:
Simplify stm32h7_spi_prepare_fthlv() function implementation,
no functional change intended.
Applied to

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

Thanks!

[1/1] spi: stm32: Simplify stm32h7_spi_prepare_fthlv()
      commit: 970e8eaa08195a26ba99ec0843968cbc7ad8e947

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

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help