Skip to content

Commit

Permalink
spi: stm32: fix stm32_spi_prepare_mbr in case of odd clk_rate
Browse files Browse the repository at this point in the history
[ Upstream commit 9cc6197 ]

Fix spi->clk_rate when it is odd to the nearest lowest even value because
minimum SPI divider is 2.

Signed-off-by: Amelie Delaunay <amelie.delaunay@st.com>
Signed-off-by: Alain Volmat <alain.volmat@st.com>
Link: https://lore.kernel.org/r/1597043558-29668-4-git-send-email-alain.volmat@st.com
Signed-off-by: Mark Brown <broonie@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
ADESTM authored and gregkh committed Sep 3, 2020
1 parent a6daa86 commit 2844685
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion drivers/spi/spi-stm32.c
Expand Up @@ -443,7 +443,8 @@ static int stm32_spi_prepare_mbr(struct stm32_spi *spi, u32 speed_hz,
{
u32 div, mbrdiv;

div = DIV_ROUND_UP(spi->clk_rate, speed_hz);
/* Ensure spi->clk_rate is even */
div = DIV_ROUND_UP(spi->clk_rate & ~0x1, speed_hz);

/*
* SPI framework set xfer->speed_hz to master->max_speed_hz if
Expand Down

0 comments on commit 2844685

Please sign in to comment.