From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Cc: Gerald Loacker <gerald.loacker@wolfvision.net>
Subject: [PATCH 2/3] spi: Add slices for SPI controllers
Date: Fri, 8 Sep 2023 15:04:00 +0200 [thread overview]
Message-ID: <20230908130401.1735831-2-s.hauer@pengutronix.de> (raw)
In-Reply-To: <20230908130401.1735831-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>
---
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
next prev parent reply other threads:[~2023-09-08 13:05 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-08 13:03 [PATCH 1/3] i2c: Add slices for I2C adapters Sascha Hauer
2023-09-08 13:04 ` Sascha Hauer [this message]
2023-09-08 13:04 ` [PATCH 3/3] net: ksz9477: Add mdio bus slice dependency to i2c/spi device Sascha Hauer
2023-09-12 12:21 ` Ahmad Fatoum
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=20230908130401.1735831-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