spi: Add spi_is_bpw_supported() Lets client drivers check and potentially handle issues.
Showing the changes to include/linux (1 of 1 file). Show all
Unified · Split
| @@ -1005,6 +1005,26 @@ spi_max_transfer_size(struct spi_device *spi) · 1004 unmodified lines | |||
| 1005 | return min(tr_max, msg_max); | 1005 | return min(tr_max, msg_max); |
| 1006 | } | 1006 | } |
| 1007 | 1007 | ||
| 1008 | /** | ||
| 1009 | * spi_is_bpw_supported - Check if bits per word is supported | ||
| 1010 | * @spi: SPI device | ||
| 1011 | * @bpw: Bits per word | ||
| 1012 | * | ||
| 1013 | * This function checks to see if the SPI controller supports @bpw. | ||
| 1014 | * | ||
| 1015 | * Returns: | ||
| 1016 | * True if @bpw is supported, false otherwise. | ||
| 1017 | */ | ||
| 1018 | static inline bool spi_is_bpw_supported(struct spi_device *spi, u32 bpw) | ||
| 1019 | { | ||
| 1020 | u32 bpw_mask = spi->master->bits_per_word_mask; | ||
| 1021 | |||
| 1022 | if (bpw == 8 || (bpw <= 32 && bpw_mask & SPI_BPW_MASK(bpw))) | ||
| 1023 | return true; | ||
| 1024 | |||
| 1025 | return false; | ||
| 1026 | } | ||
| 1027 | |||
| 1008 | /*---------------------------------------------------------------------------*/ | 1028 | /*---------------------------------------------------------------------------*/ |
| 1009 | 1029 | ||
| 1010 | /* SPI transfer replacement methods which make use of spi_res */ | 1030 | /* SPI transfer replacement methods which make use of spi_res */ |