Skip to content

Commit d54d63d

Browse files
decsnykartben
authored andcommitted
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 <[email protected]>
1 parent 0cc535e commit d54d63d

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

drivers/spi/spi_nxp_lpspi/spi_nxp_lpspi.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,8 @@ static int transceive(const struct device *dev, const struct spi_config *spi_cfg
279279

280280
spi_context_lock(&data->ctx, asynchronous, cb, userdata, spi_cfg);
281281

282-
lpspi_data->word_size_bytes = SPI_WORD_SIZE_GET(spi_cfg->operation) / BITS_PER_BYTE;
282+
lpspi_data->word_size_bytes =
283+
DIV_ROUND_UP(SPI_WORD_SIZE_GET(spi_cfg->operation), BITS_PER_BYTE);
283284
if (lpspi_data->word_size_bytes > 4) {
284285
LOG_ERR("Maximum 4 byte word size");
285286
ret = -EINVAL;

drivers/spi/spi_nxp_lpspi/spi_nxp_lpspi_common.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ static inline int lpspi_validate_xfer_args(const struct spi_config *spi_cfg)
8181
return -ENOTSUP;
8282
}
8383

84-
if (word_size < 8 || (word_size % 32 == 1)) {
84+
if (word_size < 2 || (word_size % 32 == 1)) {
8585
/* Zephyr word size == hardware FRAME size (not word size)
8686
* Max frame size: 4096 bits
8787
* (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
154154

155155
LPSPI_MasterGetDefaultConfig(&master_config);
156156

157-
master_config.bitsPerFrame = word_size;
157+
master_config.bitsPerFrame = word_size < 8 ? 8 : word_size; /* minimum FRAMSZ is 8 */
158158
master_config.cpol = (SPI_MODE_GET(spi_cfg->operation) & SPI_MODE_CPOL)
159159
? kLPSPI_ClockPolarityActiveLow
160160
: kLPSPI_ClockPolarityActiveHigh;

0 commit comments

Comments
 (0)