* [PATCH v2 1/3] i2c: Add slices for I2C adapters
@ 2023-09-08 13:11 Sascha Hauer
2023-09-08 13:11 ` [PATCH v2 2/3] spi: Add slices for SPI controllers Sascha Hauer
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Sascha Hauer @ 2023-09-08 13:11 UTC (permalink / raw)
To: Barebox List; +Cc: Gerald Loacker
Add a slice for I2C adapters so that devices using I2C in the background
can check if a I2C bus is busy.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
Notes:
Changes since v1:
- Add forgotten slice_init()
drivers/i2c/i2c.c | 7 +++++++
include/i2c/i2c.h | 7 +++++++
2 files changed, 14 insertions(+)
diff --git a/drivers/i2c/i2c.c b/drivers/i2c/i2c.c
index 300365bd1f..70d1b810c1 100644
--- a/drivers/i2c/i2c.c
+++ b/drivers/i2c/i2c.c
@@ -23,6 +23,7 @@
#include <init.h>
#include <of.h>
#include <gpio.h>
+#include <slice.h>
#include <i2c/i2c.h>
@@ -62,6 +63,8 @@ int i2c_transfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)
uint64_t start;
int ret, try;
+ slice_acquire(&adap->slice);
+
/*
* REVISIT the fault reporting model here is weak:
*
@@ -96,6 +99,8 @@ int i2c_transfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)
break;
}
+ slice_release(&adap->slice);
+
return ret;
}
EXPORT_SYMBOL(i2c_transfer);
@@ -721,6 +726,8 @@ int i2c_add_numbered_adapter(struct i2c_adapter *adapter)
list_add_tail(&adapter->list, &i2c_adapter_list);
+ slice_init(&adapter->slice, dev_name(&adapter->dev));
+
/* populate children from any i2c device tables */
scan_boardinfo(adapter);
diff --git a/include/i2c/i2c.h b/include/i2c/i2c.h
index b1ab72850c..4fc278f800 100644
--- a/include/i2c/i2c.h
+++ b/include/i2c/i2c.h
@@ -18,6 +18,7 @@
#include <driver.h>
#include <init.h>
+#include <slice.h>
#include <linux/types.h>
struct i2c_adapter;
@@ -121,6 +122,7 @@ int i2c_generic_scl_recovery(struct i2c_adapter *adap);
*/
struct i2c_adapter {
struct device dev; /* ptr to device */
+ struct slice slice;
int nr; /* bus number */
int (*master_xfer)(struct i2c_adapter *adap, struct i2c_msg *msgs, int num);
struct list_head list;
@@ -318,6 +320,11 @@ static inline int i2c_adapter_id(struct i2c_adapter *adap)
return adap->nr;
}
+static inline struct slice *i2c_client_slice(struct i2c_client *client)
+{
+ return &client->adapter->slice;
+}
+
extern int i2c_transfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num);
extern int i2c_master_send(struct i2c_client *client, const char *buf, int count);
extern int i2c_master_recv(struct i2c_client *client, char *buf, int count);
--
2.39.2
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v2 2/3] spi: Add slices for SPI controllers
2023-09-08 13:11 [PATCH v2 1/3] i2c: Add slices for I2C adapters Sascha Hauer
@ 2023-09-08 13:11 ` Sascha Hauer
2023-09-11 11:49 ` 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:48 ` [PATCH v2 1/3] i2c: Add slices for I2C adapters Gerald Loacker
2 siblings, 1 reply; 6+ messages in thread
From: Sascha Hauer @ 2023-09-08 13:11 UTC (permalink / raw)
To: Barebox List; +Cc: Gerald Loacker
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
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v2 3/3] net: ksz9477: Add mdio bus slice dependency to i2c/spi device
2023-09-08 13:11 [PATCH v2 1/3] i2c: Add slices for I2C adapters Sascha Hauer
2023-09-08 13:11 ` [PATCH v2 2/3] spi: Add slices for SPI controllers Sascha Hauer
@ 2023-09-08 13:11 ` 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
2 siblings, 1 reply; 6+ messages in thread
From: Sascha Hauer @ 2023-09-08 13:11 UTC (permalink / raw)
To: Barebox List; +Cc: Gerald Loacker
On mdio busses the attached phys check for link status in a poller.
Add a slice dependency from the mdio bus to the I2C/SPI controller
so that we do not end up doing bus accesses while we are in a
I2C/SPI access on the same bus already.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
drivers/net/ksz9477.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/drivers/net/ksz9477.c b/drivers/net/ksz9477.c
index 9665e0f723..1abea9d040 100644
--- a/drivers/net/ksz9477.c
+++ b/drivers/net/ksz9477.c
@@ -464,6 +464,13 @@ static int microchip_switch_probe(struct device *dev)
if (ret)
return ret;
+ if (priv->i2c)
+ slice_depends_on(mdiobus_slice(ds->slave_mii_bus),
+ i2c_client_slice(priv->i2c));
+ else
+ slice_depends_on(mdiobus_slice(ds->slave_mii_bus),
+ spi_device_slice(priv->spi));
+
return regmap_multi_register_cdev(priv->regmap[0], priv->regmap[1],
priv->regmap[2], NULL);
}
--
2.39.2
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2 1/3] i2c: Add slices for I2C adapters
2023-09-08 13:11 [PATCH v2 1/3] i2c: Add slices for I2C adapters Sascha Hauer
2023-09-08 13:11 ` [PATCH v2 2/3] spi: Add slices for SPI controllers Sascha Hauer
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:48 ` Gerald Loacker
2 siblings, 0 replies; 6+ messages in thread
From: Gerald Loacker @ 2023-09-11 11:48 UTC (permalink / raw)
To: Sascha Hauer, Barebox List
Am 08.09.2023 um 15:11 schrieb Sascha Hauer:
> Add a slice for I2C adapters so that devices using I2C in the background
> can check if a I2C bus is busy.
>
> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Tested-by: Gerald Loacker <gerald.loacker@wolfvision.net>
> ---
>
> Notes:
> Changes since v1:
> - Add forgotten slice_init()
>
> drivers/i2c/i2c.c | 7 +++++++
> include/i2c/i2c.h | 7 +++++++
> 2 files changed, 14 insertions(+)
>
> diff --git a/drivers/i2c/i2c.c b/drivers/i2c/i2c.c
> index 300365bd1f..70d1b810c1 100644
> --- a/drivers/i2c/i2c.c
> +++ b/drivers/i2c/i2c.c
> @@ -23,6 +23,7 @@
> #include <init.h>
> #include <of.h>
> #include <gpio.h>
> +#include <slice.h>
>
> #include <i2c/i2c.h>
>
> @@ -62,6 +63,8 @@ int i2c_transfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)
> uint64_t start;
> int ret, try;
>
> + slice_acquire(&adap->slice);
> +
> /*
> * REVISIT the fault reporting model here is weak:
> *
> @@ -96,6 +99,8 @@ int i2c_transfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)
> break;
> }
>
> + slice_release(&adap->slice);
> +
> return ret;
> }
> EXPORT_SYMBOL(i2c_transfer);
> @@ -721,6 +726,8 @@ int i2c_add_numbered_adapter(struct i2c_adapter *adapter)
>
> list_add_tail(&adapter->list, &i2c_adapter_list);
>
> + slice_init(&adapter->slice, dev_name(&adapter->dev));
> +
> /* populate children from any i2c device tables */
> scan_boardinfo(adapter);
>
> diff --git a/include/i2c/i2c.h b/include/i2c/i2c.h
> index b1ab72850c..4fc278f800 100644
> --- a/include/i2c/i2c.h
> +++ b/include/i2c/i2c.h
> @@ -18,6 +18,7 @@
>
> #include <driver.h>
> #include <init.h>
> +#include <slice.h>
> #include <linux/types.h>
>
> struct i2c_adapter;
> @@ -121,6 +122,7 @@ int i2c_generic_scl_recovery(struct i2c_adapter *adap);
> */
> struct i2c_adapter {
> struct device dev; /* ptr to device */
> + struct slice slice;
> int nr; /* bus number */
> int (*master_xfer)(struct i2c_adapter *adap, struct i2c_msg *msgs, int num);
> struct list_head list;
> @@ -318,6 +320,11 @@ static inline int i2c_adapter_id(struct i2c_adapter *adap)
> return adap->nr;
> }
>
> +static inline struct slice *i2c_client_slice(struct i2c_client *client)
> +{
> + return &client->adapter->slice;
> +}
> +
> extern int i2c_transfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num);
> extern int i2c_master_send(struct i2c_client *client, const char *buf, int count);
> extern int i2c_master_recv(struct i2c_client *client, char *buf, int count);
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2 2/3] spi: Add slices for SPI controllers
2023-09-08 13:11 ` [PATCH v2 2/3] spi: Add slices for SPI controllers Sascha Hauer
@ 2023-09-11 11:49 ` Gerald Loacker
0 siblings, 0 replies; 6+ messages in thread
From: Gerald Loacker @ 2023-09-11 11:49 UTC (permalink / raw)
To: Sascha Hauer, Barebox List
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@pengutronix.de>
Tested-by: Gerald Loacker <gerald.loacker@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)
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2 3/3] net: ksz9477: Add mdio bus slice dependency to i2c/spi device
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
0 siblings, 0 replies; 6+ messages in thread
From: Gerald Loacker @ 2023-09-11 11:49 UTC (permalink / raw)
To: Sascha Hauer, Barebox List
Am 08.09.2023 um 15:11 schrieb Sascha Hauer:
> On mdio busses the attached phys check for link status in a poller.
> Add a slice dependency from the mdio bus to the I2C/SPI controller
> so that we do not end up doing bus accesses while we are in a
> I2C/SPI access on the same bus already.
>
> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Tested-by: Gerald Loacker <gerald.loacker@wolfvision.net>
> ---
> drivers/net/ksz9477.c | 7 +++++++
> 1 file changed, 7 insertions(+)
>
> diff --git a/drivers/net/ksz9477.c b/drivers/net/ksz9477.c
> index 9665e0f723..1abea9d040 100644
> --- a/drivers/net/ksz9477.c
> +++ b/drivers/net/ksz9477.c
> @@ -464,6 +464,13 @@ static int microchip_switch_probe(struct device *dev)
> if (ret)
> return ret;
>
> + if (priv->i2c)
> + slice_depends_on(mdiobus_slice(ds->slave_mii_bus),
> + i2c_client_slice(priv->i2c));
> + else
> + slice_depends_on(mdiobus_slice(ds->slave_mii_bus),
> + spi_device_slice(priv->spi));
> +
> return regmap_multi_register_cdev(priv->regmap[0], priv->regmap[1],
> priv->regmap[2], NULL);
> }
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2023-09-11 11:51 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-08 13:11 [PATCH v2 1/3] i2c: Add slices for I2C adapters Sascha Hauer
2023-09-08 13:11 ` [PATCH v2 2/3] spi: Add slices for SPI controllers Sascha Hauer
2023-09-11 11:49 ` 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
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox