diff mbox series

[1/2] spi: Add spi_is_bpw_supported()

Message ID 20190412094131.25616-1-noralf@tronnes.org (mailing list archive)
State New, archived
Headers show
Series [1/2] spi: Add spi_is_bpw_supported() | expand

Commit Message

Noralf Trønnes April 12, 2019, 9:41 a.m. UTC
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>
---
 include/linux/spi/spi.h | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

Comments

Mark Brown April 12, 2019, 10:16 a.m. UTC | #1
On Fri, Apr 12, 2019 at 11:41:30AM +0200, Noralf Trønnes wrote:
> 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.

The following changes since commit 9e98c678c2d6ae3a17cb2de55d17f69dddaa231b:

  Linux 5.1-rc1 (2019-03-17 14:22:26 -0700)

are available in the Git repository at:

  https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git tags/spi-bpw-is-supported

for you to fetch changes up to e6f3f7e4dc76eb8d8a546dc66621a02c5c84f4ac:

  spi: Add spi_is_bpw_supported() (2019-04-12 11:13:36 +0100)

----------------------------------------------------------------
spi: Add spi_is_bpw_supported()

Lets client drivers check and potentially handle issues.

----------------------------------------------------------------
Noralf Trønnes (1):
      spi: Add spi_is_bpw_supported()

 include/linux/spi/spi.h | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
diff mbox series

Patch

diff --git a/include/linux/spi/spi.h b/include/linux/spi/spi.h
index 662b336aa2e4..b30e3d13a5ac 100644
--- a/include/linux/spi/spi.h
+++ b/include/linux/spi/spi.h
@@ -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 */