Skip to content

Commit af357a6

Browse files
lategoodbyebroonie
authored andcommitted
spi: spi-fsl-lpspi: Clamp too high speed_hz
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>
1 parent a4f8e70 commit af357a6

1 file changed

Lines changed: 3 additions & 5 deletions

File tree

drivers/spi/spi-fsl-lpspi.c

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

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

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

0 commit comments

Comments
 (0)