[PATCH v2 2/3] spi: Add slices for SPI controllers
Gerald Loacker
gerald.loacker at wolfvision.net
Mon Sep 11 04:49:23 PDT 2023
Am 08.09.2023 um 15:11 schrieb Sascha Hauer:
> 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>
Tested-by: Gerald Loacker <gerald.loacker at wolfvision.net>
> ---
>
> 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)
More information about the barebox
mailing list