spi_nxp_lpspi: Support word size < 8

The LPSPI does support word sizes such as 6 or 7, anything as small as 2
bits. So fix the checks and the math to allow for this in the driver.

Signed-off-by: Declan Snyder <declan.snyder@nxp.com>
This commit is contained in:
Declan Snyder 2025-03-27 10:25:26 -05:00 committed by Benjamin Cabé
commit d54d63d518
2 changed files with 4 additions and 3 deletions

View file

@ -279,7 +279,8 @@ static int transceive(const struct device *dev, const struct spi_config *spi_cfg
spi_context_lock(&data->ctx, asynchronous, cb, userdata, spi_cfg);
lpspi_data->word_size_bytes = SPI_WORD_SIZE_GET(spi_cfg->operation) / BITS_PER_BYTE;
lpspi_data->word_size_bytes =
DIV_ROUND_UP(SPI_WORD_SIZE_GET(spi_cfg->operation), BITS_PER_BYTE);
if (lpspi_data->word_size_bytes > 4) {
LOG_ERR("Maximum 4 byte word size");
ret = -EINVAL;

View file

@ -81,7 +81,7 @@ static inline int lpspi_validate_xfer_args(const struct spi_config *spi_cfg)
return -ENOTSUP;
}
if (word_size < 8 || (word_size % 32 == 1)) {
if (word_size < 2 || (word_size % 32 == 1)) {
/* Zephyr word size == hardware FRAME size (not word size)
* Max frame size: 4096 bits
* (zephyr field is 6 bit wide for max 64 bit size, no need to check)
@ -154,7 +154,7 @@ int spi_mcux_configure(const struct device *dev, const struct spi_config *spi_cf
LPSPI_MasterGetDefaultConfig(&master_config);
master_config.bitsPerFrame = word_size;
master_config.bitsPerFrame = word_size < 8 ? 8 : word_size; /* minimum FRAMSZ is 8 */
master_config.cpol = (SPI_MODE_GET(spi_cfg->operation) & SPI_MODE_CPOL)
? kLPSPI_ClockPolarityActiveLow
: kLPSPI_ClockPolarityActiveHigh;