From 5a83cae32d9a1f29209d4f171a8de18bf82fd630 Mon Sep 17 00:00:00 2001 From: Boon Khai Ng Date: Thu, 12 Mar 2026 12:46:33 +0800 Subject: spi: dw: Allow bits_per_word to be configured by device drivers The DesignWare SPI controller supports configurable bits_per_word (typically 4-32 bits), but this was previously hardcoded to 8 bits in the driver initialization. This patch enables bits_per_word to be set dynamically by upper-level device drivers, matching the approach used in Linux. The controller reads the bits_per_word value from the spi_slave structure during each transfer, allowing different SPI devices on the same bus to use different word sizes. Implementation details: - Read slave->bits_per_word in dw_spi_xfer() before each transfer - Validate requested value against controller capabilities (4 to max_xfer) - Default to 8 bits if not set (maintains backward compatibility) This follows the Linux model where spi_device drivers set bits_per_word, and the controller driver reads it in the transfer function. Device drivers can now set slave->bits_per_word before calling spi_xfer(). Example usage in device driver: slave->bits_per_word = 16; spi_xfer(slave, ...); Backward compatible: Existing drivers that don't set bits_per_word will continue to work with the default 8-bit transfers. Signed-off-by: Boon Khai Ng --- include/spi.h | 1 + 1 file changed, 1 insertion(+) (limited to 'include') diff --git a/include/spi.h b/include/spi.h index 7eaf0aa69b8..97096a77526 100644 --- a/include/spi.h +++ b/include/spi.h @@ -161,6 +161,7 @@ struct spi_slave { unsigned int max_write_size; void *memory_map; + u8 bits_per_word; u8 flags; #define SPI_XFER_BEGIN BIT(0) /* Assert CS before transfer */ #define SPI_XFER_END BIT(1) /* Deassert CS after transfer */ -- cgit v1.3.1