Skip to content

Commit 6de8a70

Browse files
VCASTMbroonie
authored andcommitted
spi: stm32: add a delay before SPI disable
As explained in errata sheet, in section "2.14.5 Truncation of SPI output signals after EOT event": On STM32MP1x, EOT interrupt can be thrown before the true end of communication. So we add a delay of a half period to wait the real end of the transmission. Link: https://www.st.com/resource/en/errata_sheet/es0539-stm32mp131x3x5x-device-errata-stmicroelectronics.pdf Signed-off-by: Valentin Caron <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent 1849567 commit 6de8a70

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

drivers/spi/spi-stm32.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@ struct stm32_spi_cfg {
277277
* @fifo_size: size of the embedded fifo in bytes
278278
* @cur_midi: master inter-data idleness in ns
279279
* @cur_speed: speed configured in Hz
280+
* @cur_half_period: time of a half bit in us
280281
* @cur_bpw: number of bits in a single SPI data frame
281282
* @cur_fthlv: fifo threshold level (data frames in a single data packet)
282283
* @cur_comm: SPI communication mode
@@ -304,6 +305,7 @@ struct stm32_spi {
304305

305306
unsigned int cur_midi;
306307
unsigned int cur_speed;
308+
unsigned int cur_half_period;
307309
unsigned int cur_bpw;
308310
unsigned int cur_fthlv;
309311
unsigned int cur_comm;
@@ -468,6 +470,8 @@ static int stm32_spi_prepare_mbr(struct stm32_spi *spi, u32 speed_hz,
468470

469471
spi->cur_speed = spi->clk_rate / (1 << mbrdiv);
470472

473+
spi->cur_half_period = DIV_ROUND_CLOSEST(USEC_PER_SEC, 2 * spi->cur_speed);
474+
471475
return mbrdiv - 1;
472476
}
473477

@@ -709,6 +713,10 @@ static void stm32h7_spi_disable(struct stm32_spi *spi)
709713
return;
710714
}
711715

716+
/* Add a delay to make sure that transmission is ended. */
717+
if (spi->cur_half_period)
718+
udelay(spi->cur_half_period);
719+
712720
if (spi->cur_usedma && spi->dma_tx)
713721
dmaengine_terminate_async(spi->dma_tx);
714722
if (spi->cur_usedma && spi->dma_rx)

0 commit comments

Comments
 (0)