Skip to content

Commit 566f60f

Browse files
lategoodbyegregkh
authored andcommitted
spi: spi-fsl-lpspi: Clamp too high speed_hz
[ Upstream commit af357a6 ] Currently the driver is not able to handle the case that a SPI device specifies a higher spi-max-frequency than half of per-clk: per-clk should be at least two times of transfer speed Fix this by clamping to the max possible value and use the minimum SCK period of 2 cycles. Fixes: 77736a9 ("spi: lpspi: add the error info of transfer speed setting") Signed-off-by: Stefan Wahren <wahrenst@gmx.net> Link: https://patch.msgid.link/20250807100742.9917-1-wahrenst@gmx.net Signed-off-by: Mark Brown <broonie@kernel.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent eb9a497 commit 566f60f

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

drivers/spi/spi-fsl-lpspi.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -331,13 +331,11 @@ static int fsl_lpspi_set_bitrate(struct fsl_lpspi_data *fsl_lpspi)
331331
}
332332

333333
if (config.speed_hz > perclk_rate / 2) {
334-
dev_err(fsl_lpspi->dev,
335-
"per-clk should be at least two times of transfer speed");
336-
return -EINVAL;
334+
div = 2;
335+
} else {
336+
div = DIV_ROUND_UP(perclk_rate, config.speed_hz);
337337
}
338338

339-
div = DIV_ROUND_UP(perclk_rate, config.speed_hz);
340-
341339
for (prescale = 0; prescale <= prescale_max; prescale++) {
342340
scldiv = div / (1 << prescale) - 2;
343341
if (scldiv >= 0 && scldiv < 256) {

0 commit comments

Comments
 (0)