linux-spi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] spi: Add spi_is_bpw_supported()
@ 2019-04-12  9:41 Noralf Trønnes
  2019-04-12  9:41 ` [PATCH 2/2] drm/tinydrm: Use spi_is_bpw_supported() Noralf Trønnes
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Noralf Trønnes @ 2019-04-12  9:41 UTC (permalink / raw)
  To: linux-spi, dri-devel; +Cc: broonie

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(+)

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 */
-- 
2.20.1

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2019-05-12  3:08 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-04-12  9:41 [PATCH 1/2] spi: Add spi_is_bpw_supported() Noralf Trønnes
2019-04-12  9:41 ` [PATCH 2/2] drm/tinydrm: Use spi_is_bpw_supported() Noralf Trønnes
2019-04-12 10:16 ` [PATCH 1/2] spi: Add spi_is_bpw_supported() Mark Brown
2019-04-15  8:53 ` Applied "spi: Add spi_is_bpw_supported()" to the spi tree Mark Brown
2019-05-09 15:50   ` Noralf Trønnes
2019-05-12  3:08     ` Mark Brown
2019-04-17 16:42 ` Mark Brown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).