summaryrefslogtreecommitdiff
path: root/include/linux/spi
diff options
context:
space:
mode:
authorMark Brown <broonie@kernel.org>2025-04-18 05:11:47 +0100
committerMark Brown <broonie@kernel.org>2025-04-18 05:11:47 +0100
commitcbc9d9e108f4f2a3c061ac6233a424accde8b564 (patch)
tree69b3521b2bbc023ca7e9ac55dffae9a2695d9a12 /include/linux/spi
parent4cc9cf2f437ccf6915100c2f38f63cfb1abad6f9 (diff)
parente30b7a75666b3f444abfabed6a144642fa9994d8 (diff)
downloadlwn-cbc9d9e108f4f2a3c061ac6233a424accde8b564.tar.gz
lwn-cbc9d9e108f4f2a3c061ac6233a424accde8b564.zip
spi: Introduce and use spi_bpw_to_bytes()
Merge series from Andy Shevchenko <andriy.shevchenko@linux.intel.com>: Recently in the discussion with David the idea of having a common helper popped up. The helper converts the given bits per word to bytes. The result will always be power-of-two (e.g. for 37 bits it returns 8 bytes) or 0 for 0 input. More details are in the respective code comment. This mini-series introduces it and replaces current users under drivers/spi and we expect more (and possibly some lurking in other subsystems).
Diffstat (limited to 'include/linux/spi')
-rw-r--r--include/linux/spi/spi.h26
1 files changed, 26 insertions, 0 deletions
diff --git a/include/linux/spi/spi.h b/include/linux/spi/spi.h
index 834a09bd8ccc..c921ff902f0c 100644
--- a/include/linux/spi/spi.h
+++ b/include/linux/spi/spi.h
@@ -1341,6 +1341,32 @@ static inline bool spi_is_bpw_supported(struct spi_device *spi, u32 bpw)
}
/**
+ * spi_bpw_to_bytes - Covert bits per word to bytes
+ * @bpw: Bits per word
+ *
+ * This function converts the given @bpw to bytes. The result is always
+ * power-of-two, e.g.,
+ *
+ * =============== =================
+ * Input (in bits) Output (in bytes)
+ * =============== =================
+ * 5 1
+ * 9 2
+ * 21 4
+ * 37 8
+ * =============== =================
+ *
+ * It will return 0 for the 0 input.
+ *
+ * Returns:
+ * Bytes for the given @bpw.
+ */
+static inline u32 spi_bpw_to_bytes(u32 bpw)
+{
+ return roundup_pow_of_two(BITS_TO_BYTES(bpw));
+}
+
+/**
* spi_controller_xfer_timeout - Compute a suitable timeout value
* @ctlr: SPI device
* @xfer: Transfer descriptor