]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
spi: stm32: fix Overrun issue at < 8bpw
authorDeepak Kumar <deepak.kumar01@st.com>
Thu, 18 Dec 2025 10:48:28 +0000 (11:48 +0100)
committerMark Brown <broonie@kernel.org>
Thu, 18 Dec 2025 10:59:33 +0000 (10:59 +0000)
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>
drivers/spi/spi-stm32.c

index 40651b6050f6865a3dca21d94ffdf27c50653ae0..ced6d7b215b9ae5c0c4a2967d96bd61e19141293 100644 (file)
@@ -1906,11 +1906,12 @@ static void stm32h7_spi_data_idleness(struct stm32_spi *spi, struct spi_transfer
        cfg2_clrb |= STM32H7_SPI_CFG2_MIDI;
        if ((len > 1) && (spi->cur_midi > 0)) {
                u32 sck_period_ns = DIV_ROUND_UP(NSEC_PER_SEC, spi->cur_speed);
-               u32 midi = min_t(u32,
-                                DIV_ROUND_UP(spi->cur_midi, sck_period_ns),
-                                FIELD_GET(STM32H7_SPI_CFG2_MIDI,
-                                STM32H7_SPI_CFG2_MIDI));
+               u32 midi = DIV_ROUND_UP(spi->cur_midi, sck_period_ns);
 
+               if ((spi->cur_bpw + midi) < 8)
+                       midi = 8 - spi->cur_bpw;
+
+               midi = min_t(u32, midi, FIELD_MAX(STM32H7_SPI_CFG2_MIDI));
 
                dev_dbg(spi->dev, "period=%dns, midi=%d(=%dns)\n",
                        sck_period_ns, midi, midi * sck_period_ns);