spi: Add spi_is_bpw_supported()
authorNoralf Trønnes <noralf@tronnes.org>
Fri, 12 Apr 2019 09:41:30 +0000 (11:41 +0200)
committerMark Brown <broonie@kernel.org>
Fri, 12 Apr 2019 10:13:36 +0000 (11:13 +0100)
This let SPI clients check if the controller supports a particular word
width. drivers/gpu/drm/tinydrm/mipi-dbi.c will use this to determine if
the controller supports 16-bit for RGB565 pixels. If it doesn't it will
swap the bytes before transfer on little endian machines.

Signed-off-by: Noralf Trønnes <noralf@tronnes.org>
Signed-off-by: Mark Brown <broonie@kernel.org>
include/linux/spi/spi.h

index 662b336..b30e3d1 100644 (file)
@@ -983,6 +983,26 @@ spi_max_transfer_size(struct spi_device *spi)
        return min(tr_max, msg_max);
 }
 
+/**
+ * spi_is_bpw_supported - Check if bits per word is supported
+ * @spi: SPI device
+ * @bpw: Bits per word
+ *
+ * This function checks to see if the SPI controller supports @bpw.
+ *
+ * Returns:
+ * True if @bpw is supported, false otherwise.
+ */
+static inline bool spi_is_bpw_supported(struct spi_device *spi, u32 bpw)
+{
+       u32 bpw_mask = spi->master->bits_per_word_mask;
+
+       if (bpw == 8 || (bpw <= 32 && bpw_mask & SPI_BPW_MASK(bpw)))
+               return true;
+
+       return false;
+}
+
 /*---------------------------------------------------------------------------*/
 
 /* SPI transfer replacement methods which make use of spi_res */