Unverified Commit af357a6a authored by Stefan Wahren's avatar Stefan Wahren Committed by Mark Brown
Browse files

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: 77736a98 ("spi: lpspi: add the error info of transfer speed setting")
Signed-off-by: default avatarStefan Wahren <wahrenst@gmx.net>
Link: https://patch.msgid.link/20250807100742.9917-1-wahrenst@gmx.net


Signed-off-by: default avatarMark Brown <broonie@kernel.org>
parent a4f8e70d
Loading
Loading
Loading
Loading
+3 −5
Original line number Diff line number Diff line
@@ -330,12 +330,10 @@ static int fsl_lpspi_set_bitrate(struct fsl_lpspi_data *fsl_lpspi)
	}

	if (config.speed_hz > perclk_rate / 2) {
		dev_err(fsl_lpspi->dev,
		      "per-clk should be at least two times of transfer speed");
		return -EINVAL;
	}

		div = 2;
	} else {
		div = DIV_ROUND_UP(perclk_rate, config.speed_hz);
	}

	for (prescale = 0; prescale <= prescale_max; prescale++) {
		scldiv = div / (1 << prescale) - 2;