Commit 860f9c8e authored by Martin Stumpf's avatar Martin Stumpf Committed by Fabio Baltieri
Browse files

spi_nxp_lpspi: Fix underflow in lpspi sck calculation



If `desired_delay_ns` is `0`, it is much saner to set the delay to `0x00`
than to underflow and set it to `0xff`, which is the current behavior.

Signed-off-by: default avatarMartin Stumpf <finomnis@gmail.com>
parent be385685
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -132,6 +132,9 @@ static uint8_t lpspi_calc_delay_scaler(uint32_t desired_delay_ns,
	delay_cycles = (uint64_t)prescaled_clock * desired_delay_ns;
	delay_cycles = DIV_ROUND_UP(delay_cycles, NSEC_PER_SEC);

	/* clamp to minimally possible cycles to avoid underflow */
	delay_cycles = MAX(delay_cycles, min_cycles);

	/* what the min_cycles parameter is about is that
	* PCSSCK and SCKPSC are +1 cycles of the programmed value,
	* while DBT is +2 cycles of the programmed value.