mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Cc: Gerald Loacker <gerald.loacker@wolfvision.net>
Subject: [PATCH v2 2/3] spi: Add slices for SPI controllers
Date: Fri,  8 Sep 2023 15:11:16 +0200	[thread overview]
Message-ID: <20230908131117.1769957-2-s.hauer@pengutronix.de> (raw)
In-Reply-To: <20230908131117.1769957-1-s.hauer@pengutronix.de>

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@pengutronix.de>
---

Notes:
    Changes since v1:
    - Add forgotten slice_init()

 drivers/spi/spi.c | 12 +++++++++++-
 include/spi/spi.h |  8 ++++++++
 2 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 584d4ab777..83f2b0ee1b 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>
@@ -269,6 +270,8 @@ int spi_register_controller(struct spi_controller *ctrl)
 	if (status)
 		return status;
 
+	slice_init(&ctrl->slice, dev_name(ctrl->dev));
+
 	/* even if it's just one always-selected device, there must
 	 * be at least one chipselect
 	 */
@@ -352,12 +355,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




  reply	other threads:[~2023-09-08 13:12 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-08 13:11 [PATCH v2 1/3] i2c: Add slices for I2C adapters Sascha Hauer
2023-09-08 13:11 ` Sascha Hauer [this message]
2023-09-11 11:49   ` [PATCH v2 2/3] spi: Add slices for SPI controllers Gerald Loacker
2023-09-08 13:11 ` [PATCH v2 3/3] net: ksz9477: Add mdio bus slice dependency to i2c/spi device Sascha Hauer
2023-09-11 11:49   ` Gerald Loacker
2023-09-11 11:48 ` [PATCH v2 1/3] i2c: Add slices for I2C adapters Gerald Loacker

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230908131117.1769957-2-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=gerald.loacker@wolfvision.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox