[PATCH 2/3] spi: Add slices for SPI controllers

Sascha Hauer s.hauer at pengutronix.de
Fri Sep 8 06:04:00 PDT 2023


Add a slice for SPI controllers so that devices using SPI in the background
can check if a SPI bus is busy.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 drivers/spi/spi.c | 10 +++++++++-
 include/spi/spi.h |  8 ++++++++
 2 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 584d4ab777..1b8e5f4512 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -12,6 +12,7 @@
 #include <spi/spi.h>
 #include <xfuncs.h>
 #include <malloc.h>
+#include <slice.h>
 #include <errno.h>
 #include <init.h>
 #include <of.h>
@@ -352,12 +353,19 @@ static int __spi_validate(struct spi_device *spi, struct spi_message *message)
 int spi_sync(struct spi_device *spi, struct spi_message *message)
 {
 	int status;
+	int ret;
 
 	status = __spi_validate(spi, message);
 	if (status != 0)
 		return status;
 
-	return spi->controller->transfer(spi, message);
+	slice_acquire(&spi->controller->slice);
+
+	ret = spi->controller->transfer(spi, message);
+
+	slice_release(&spi->controller->slice);
+
+	return ret;
 }
 
 /**
diff --git a/include/spi/spi.h b/include/spi/spi.h
index f806c7a30b..45d6f5931c 100644
--- a/include/spi/spi.h
+++ b/include/spi/spi.h
@@ -3,6 +3,7 @@
 #define __INCLUDE_SPI_H
 
 #include <driver.h>
+#include <slice.h>
 #include <linux/err.h>
 #include <linux/kernel.h>
 #include <linux/string.h>
@@ -161,6 +162,8 @@ struct spi_message;
 struct spi_controller {
 	struct device *dev;
 
+	struct slice		slice;
+
 	/* other than negative (== assign one dynamically), bus_num is fully
 	 * board-specific.  usually that simplifies to being SOC-specific.
 	 * example:  one SOC has three SPI controllers, numbered 0..2,
@@ -601,6 +604,11 @@ static inline int spi_driver_register(struct driver *drv)
 	return register_driver(drv);
 }
 
+static inline struct slice *spi_device_slice(struct spi_device *spi)
+{
+	return &spi->controller->slice;
+}
+
 #ifdef CONFIG_SPI
 #define coredevice_spi_driver(drv)	\
 	register_driver_macro(coredevice,spi,drv)
-- 
2.39.2




More information about the barebox mailing list