Skip to content
/ linux Public

Commit 50e8aac

Browse files
deepak-STMSasha Levin
authored andcommitted
spi: stm32: fix Overrun issue at < 8bpw
[ Upstream commit 1ac3be2 ] When SPI communication is suspended by hardware automatically, it could happen that few bits of next frame are already clocked out due to internal synchronization delay. To achieve a safe suspension, we need to ensure that each word must be at least 8 SPI clock cycles long. That's why, if bpw is less than 8 bits, we need to use midi to reach 8 SPI clock cycles at least. This will ensure that each word achieve safe suspension and prevent overrun condition. Signed-off-by: Deepak Kumar <deepak.kumar01@st.com> Signed-off-by: Alain Volmat <alain.volmat@foss.st.com> Link: https://patch.msgid.link/20251218-stm32-spi-enhancements-v2-2-3b69901ca9fe@foss.st.com Signed-off-by: Mark Brown <broonie@kernel.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 8b971c2 commit 50e8aac

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

drivers/spi/spi-stm32.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1507,11 +1507,12 @@ static void stm32h7_spi_data_idleness(struct stm32_spi *spi, u32 len)
15071507
cfg2_clrb |= STM32H7_SPI_CFG2_MIDI;
15081508
if ((len > 1) && (spi->cur_midi > 0)) {
15091509
u32 sck_period_ns = DIV_ROUND_UP(NSEC_PER_SEC, spi->cur_speed);
1510-
u32 midi = min_t(u32,
1511-
DIV_ROUND_UP(spi->cur_midi, sck_period_ns),
1512-
FIELD_GET(STM32H7_SPI_CFG2_MIDI,
1513-
STM32H7_SPI_CFG2_MIDI));
1510+
u32 midi = DIV_ROUND_UP(spi->cur_midi, sck_period_ns);
15141511

1512+
if ((spi->cur_bpw + midi) < 8)
1513+
midi = 8 - spi->cur_bpw;
1514+
1515+
midi = min_t(u32, midi, FIELD_MAX(STM32H7_SPI_CFG2_MIDI));
15151516

15161517
dev_dbg(spi->dev, "period=%dns, midi=%d(=%dns)\n",
15171518
sck_period_ns, midi, midi * sck_period_ns);

0 commit comments

Comments
 (0)