* [PATCH v10 0/6] lan966x pci device: Add support for SFPs, i2c part
@ 2026-11-18 13:39 Herve Codina
2026-11-18 13:39 ` [PATCH v10 1/6] media: rtl2832: Use I2C client device as mux device Herve Codina
` (5 more replies)
0 siblings, 6 replies; 7+ messages in thread
From: Herve Codina @ 2026-11-18 13:39 UTC (permalink / raw)
To: Andrew Lunn, Rob Herring, Saravana Kannan, Wolfram Sang,
Tomi Valkeinen, Luca Ceresoli, Andi Shyti, Peter Rosin,
Mauro Carvalho Chehab
Cc: linux-i2c, linux-kernel, linux-media, Allan Nielsen,
Horatiu Vultur, Daniel Machon, Steen Hegelund, Thomas Petazzoni,
Herve Codina
Hi,
Previously, I sent a big picture series adding support for SFP ports
available on the LAN966x PCI device [0].
In this series patches touch several parts and sub-system in the kernel.
Reviews have be done and it makes sense to split the series and send
parts separately.
This current series is the extraction of patches related to issues in
the I2C subsystem. It has to be seen as a continuation of the big
picture series but related to this specific I2C part.
Those patches are related fw_delink issues specific to I2C muxes and
atrs.
They purpose is to correctly set a link between an adapter supplier and
its consumer. Indeed, an i2c mux/atr adapter's parent is not the i2c
mux/atr supplier but the adapter the i2c mux/atr is connected to. Adding
a new link between the adapter supplier involved when i2c muxes/atrs are
used avoid a freeze observed during device removal.
[0] https://lore.kernel.org/all/20260325143555.451852-1-herve.codina@bootlin.com/
During the previous iteration, Sashiko reported some issues [1]. This
new iteration takes them into account.
Also, previously, modification done on muxes and atrs were done in the
same patch. This new iteration split them in several patches. Even if
modification are similar, commit logs are not. For instance, serializer
and deserializer related to issues reported by Sashiko are present in
atrs but not muxes. With that in mind, having specific commits for muxes
and atr makes sense.
[1] https://sashiko.dev/#/patchset/20261104135324.492692-1-herve.codina%40bootlin.com
Still worth noting that I tested modifications done in mux but not in
atr. Indeed, I don't have any atr devices on the different boards I have
to perform a test.
Best regards,
Hervé
Changes:
v9 -> v10
v9: https://lore.kernel.org/all/20261104135324.492692-1-herve.codina@bootlin.com/
Sashiko's review: https://sashiko.dev/#/patchset/20261104135324.492692-1-herve.codina%40bootlin.com
Patch 1 (new patch in v10)
- Update rtl2832 driver to pass &client->dev instead of &i2c->dev
(issue reported by Sashiko).
Patch 2 (patch 1 in v9)
No change
Patch 3 (patch 2 in v9)
- Split v9 patch 2 (mux part)
- No specific mux change
- Keep 'Reviewed-by: Andy' tag
Patch 4 (patch 3 in v9)
- Split v9 patch 3 (mux part)
- Handle issues reported by Shashiko (possible NULL parent_physdev,
possible parent_physdev == mux->dev)
- Handle DVB bridges issue reported by Sashiko (client->dev.driver
NULL pointer dereference). Fix it avoiding the link creation when
the consumer is an i2c client attached to the same adapter as the
supplier.
Patch 5 (patch 2 in v9)
- Split v9 patch 2 (atr part)
- Use desc->parent for chan->adap.physdev (serializer/deserializer
issue reported by Sashiko).
Patch 6 (patch 3 in v9)
- Split patch 3 (atr part)
- Use desc->parent for the devlink consumer (reported by Sashiko)
- Avoid a dangling pointer in atr->adapter[chan_id] (reported by
Sashiko)
- Take into account possible NULL parent_physdev (idem mux)
- Take into account the parent_physdev == desc->parent case (idem
mux).
- Avoid link creation when the consumer is an i2c client attached to
the same adapter as the supplier (idem mux).
v8 -> v9
v8: https://lore.kernel.org/all/20260630103010.413688-1-herve.codina@bootlin.com/
Rebase on top of v7.4-rc1
Patches 2 and 3
- Add same modifications in i2c-atr.c than the ones done in i2c-mux.c.
- Update commit logs accordingly.
v7 -> v8
v7: https://lore.kernel.org/all/20260605083158.28ac874f@bootlin.com/
Rebase on top of v7.2-rc1
No other changes
v6 -> v7
Rebase on top of v7.1-rc1
- Patch 1, 2 and 3
No changes
Older iterations:
Patches 14, 15 and 16in the big picture series
https://lore.kernel.org/all/20260325143555.451852-1-herve.codina@bootlin.com/
Herve Codina (6):
media: rtl2832: Use I2C client device as mux device
i2c: core: Introduce i2c_get_adapter_physdev()
i2c: mux: Set adapter physical device
i2c: mux: Create missing devlink between mux and adapter physical
device
i2c: atr: Set adapter physical device
i2c: atr: Create missing devlink between ATR and adapter physical
device
drivers/i2c/i2c-atr.c | 47 +++++++++++++++++++++++++++
drivers/i2c/i2c-core-base.c | 16 +++++++++
drivers/i2c/i2c-mux.c | 45 +++++++++++++++++++++++++
drivers/media/dvb-frontends/rtl2832.c | 2 +-
include/linux/i2c.h | 3 ++
5 files changed, 112 insertions(+), 1 deletion(-)
--
2.56.0
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v10 1/6] media: rtl2832: Use I2C client device as mux device
2026-11-18 13:39 [PATCH v10 0/6] lan966x pci device: Add support for SFPs, i2c part Herve Codina
@ 2026-11-18 13:39 ` Herve Codina
2026-11-18 13:39 ` [PATCH v10 2/6] i2c: core: Introduce i2c_get_adapter_physdev() Herve Codina
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Herve Codina @ 2026-11-18 13:39 UTC (permalink / raw)
To: Andrew Lunn, Rob Herring, Saravana Kannan, Wolfram Sang,
Tomi Valkeinen, Luca Ceresoli, Andi Shyti, Peter Rosin,
Mauro Carvalho Chehab
Cc: linux-i2c, linux-kernel, linux-media, Allan Nielsen,
Horatiu Vultur, Daniel Machon, Steen Hegelund, Thomas Petazzoni,
Herve Codina
rtl2832_probe() currently passes &i2c->dev, the driverless parent adapter
device, to i2c_mux_alloc().
This leads to the mux device set to this adapter device instead of the
physical device handling the mux, the rtl2832 device.
This is an issue when consumer/supplier devlink are involved. Indeed,
the physical device with a driver attached need to be pointed to by
devlink.
Use the rtl2832 device &client->dev instead, as done by the other DVB
demodulator drivers.
Signed-off-by: Herve Codina <herve.codina@bootlin.com>
---
drivers/media/dvb-frontends/rtl2832.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/media/dvb-frontends/rtl2832.c b/drivers/media/dvb-frontends/rtl2832.c
index b31cdb44b383..57707d84701b 100644
--- a/drivers/media/dvb-frontends/rtl2832.c
+++ b/drivers/media/dvb-frontends/rtl2832.c
@@ -1075,7 +1075,7 @@ static int rtl2832_probe(struct i2c_client *client)
goto err_regmap_exit;
/* create muxed i2c adapter for demod tuner bus */
- dev->muxc = i2c_mux_alloc(i2c, &i2c->dev, 1, 0, I2C_MUX_LOCKED,
+ dev->muxc = i2c_mux_alloc(i2c, &client->dev, 1, 0, I2C_MUX_LOCKED,
rtl2832_select, rtl2832_deselect);
if (!dev->muxc) {
ret = -ENOMEM;
--
2.56.0
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v10 2/6] i2c: core: Introduce i2c_get_adapter_physdev()
2026-11-18 13:39 [PATCH v10 0/6] lan966x pci device: Add support for SFPs, i2c part Herve Codina
2026-11-18 13:39 ` [PATCH v10 1/6] media: rtl2832: Use I2C client device as mux device Herve Codina
@ 2026-11-18 13:39 ` Herve Codina
2026-11-18 13:39 ` [PATCH v10 3/6] i2c: mux: Set adapter physical device Herve Codina
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Herve Codina @ 2026-11-18 13:39 UTC (permalink / raw)
To: Andrew Lunn, Rob Herring, Saravana Kannan, Wolfram Sang,
Tomi Valkeinen, Luca Ceresoli, Andi Shyti, Peter Rosin,
Mauro Carvalho Chehab
Cc: linux-i2c, linux-kernel, linux-media, Allan Nielsen,
Horatiu Vultur, Daniel Machon, Steen Hegelund, Thomas Petazzoni,
Herve Codina
The physical device providing an I2C adapter is the device that calls
i2c_add_adapter() or variants and i2c_del_adapter().
Most of the time this physical device is the parent of the adapter
device.
Exceptions exist with i2c muxes. Indeed, in case of i2c muxes, the
parent of the mux adapter device points to the adapter device the mux is
connected to instead of the physical of this mux adapter.
Introduce i2c_get_adapter_physdev() and a new physdev field in the
adapter structure in order to ease the adapter physical device
retrieval.
Signed-off-by: Herve Codina <herve.codina@bootlin.com>
Reviewed-by: Andi Shyti <andi.shyti@kernel.org>
---
drivers/i2c/i2c-core-base.c | 16 ++++++++++++++++
include/linux/i2c.h | 3 +++
2 files changed, 19 insertions(+)
diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c
index 165ec14260c8..0c08b0e71609 100644
--- a/drivers/i2c/i2c-core-base.c
+++ b/drivers/i2c/i2c-core-base.c
@@ -1956,6 +1956,22 @@ struct i2c_adapter *i2c_get_adapter_by_fwnode(struct fwnode_handle *fwnode)
}
EXPORT_SYMBOL(i2c_get_adapter_by_fwnode);
+/**
+ * i2c_get_adapter_physdev() - Get the physical device of an adapter
+ * @adapter: the adapter to get the physical device from
+ *
+ * Return:
+ * Look up and return the &struct device corresponding to the device supplying
+ * this @adapter.
+ *
+ * The user must call put_device() once done with the physical device returned.
+ */
+struct device *i2c_get_adapter_physdev(struct i2c_adapter *adapter)
+{
+ return get_device(adapter->physdev ?: adapter->dev.parent);
+}
+EXPORT_SYMBOL(i2c_get_adapter_physdev);
+
static void i2c_parse_timing(struct device *dev, char *prop_name, u32 *cur_val_p,
u32 def_val, bool use_def)
{
diff --git a/include/linux/i2c.h b/include/linux/i2c.h
index 6a847fc88d25..bcf2e4e30108 100644
--- a/include/linux/i2c.h
+++ b/include/linux/i2c.h
@@ -762,6 +762,7 @@ struct i2c_adapter {
#endif
int retries;
struct device dev; /* the adapter device */
+ struct device *physdev; /* the physical device */
unsigned long locked_flags; /* owned by the I2C core */
#define I2C_ALF_IS_SUSPENDED 0
#define I2C_ALF_SUSPEND_REPORTED 1
@@ -929,6 +930,8 @@ struct i2c_adapter *i2c_get_adapter(int nr);
void i2c_put_adapter(struct i2c_adapter *adap);
unsigned int i2c_adapter_depth(struct i2c_adapter *adapter);
+struct device *i2c_get_adapter_physdev(struct i2c_adapter *adap);
+
void i2c_parse_fw_timings(struct device *dev, struct i2c_timings *t, bool use_defaults);
#ifdef CONFIG_I2C_DYNAMIC_TIMEOUT
--
2.56.0
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v10 3/6] i2c: mux: Set adapter physical device
2026-11-18 13:39 [PATCH v10 0/6] lan966x pci device: Add support for SFPs, i2c part Herve Codina
2026-11-18 13:39 ` [PATCH v10 1/6] media: rtl2832: Use I2C client device as mux device Herve Codina
2026-11-18 13:39 ` [PATCH v10 2/6] i2c: core: Introduce i2c_get_adapter_physdev() Herve Codina
@ 2026-11-18 13:39 ` Herve Codina
2026-11-18 13:39 ` [PATCH v10 4/6] i2c: mux: Create missing devlink between mux and " Herve Codina
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Herve Codina @ 2026-11-18 13:39 UTC (permalink / raw)
To: Andrew Lunn, Rob Herring, Saravana Kannan, Wolfram Sang,
Tomi Valkeinen, Luca Ceresoli, Andi Shyti, Peter Rosin,
Mauro Carvalho Chehab
Cc: linux-i2c, linux-kernel, linux-media, Allan Nielsen,
Horatiu Vultur, Daniel Machon, Steen Hegelund, Thomas Petazzoni,
Herve Codina
For i2c muxes, the parent of the mux adapter device is the adapter
device the mux is connected to.
This parent is not the physical device related to the mux adapter.
Indeed, the physical device of the mux adapter is the mux device itself.
Fill the adap.physdev with the mux device.
Signed-off-by: Herve Codina <herve.codina@bootlin.com>
Reviewed-by: Andi Shyti <andi.shyti@kernel.org>
---
drivers/i2c/i2c-mux.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/i2c/i2c-mux.c b/drivers/i2c/i2c-mux.c
index 53428098ddc7..c1836114ef56 100644
--- a/drivers/i2c/i2c-mux.c
+++ b/drivers/i2c/i2c-mux.c
@@ -361,6 +361,7 @@ int i2c_mux_add_adapter(struct i2c_mux_core *muxc,
priv->adap.algo = &priv->algo;
priv->adap.algo_data = priv;
priv->adap.dev.parent = &parent->dev;
+ priv->adap.physdev = muxc->dev;
priv->adap.retries = parent->retries;
priv->adap.timeout = parent->timeout;
priv->adap.quirks = parent->quirks;
--
2.56.0
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v10 4/6] i2c: mux: Create missing devlink between mux and adapter physical device
2026-11-18 13:39 [PATCH v10 0/6] lan966x pci device: Add support for SFPs, i2c part Herve Codina
` (2 preceding siblings ...)
2026-11-18 13:39 ` [PATCH v10 3/6] i2c: mux: Set adapter physical device Herve Codina
@ 2026-11-18 13:39 ` Herve Codina
2026-11-18 13:39 ` [PATCH v10 5/6] i2c: atr: Set " Herve Codina
2026-11-18 13:39 ` [PATCH v10 6/6] i2c: atr: Create missing devlink between ATR and " Herve Codina
5 siblings, 0 replies; 7+ messages in thread
From: Herve Codina @ 2026-11-18 13:39 UTC (permalink / raw)
To: Andrew Lunn, Rob Herring, Saravana Kannan, Wolfram Sang,
Tomi Valkeinen, Luca Ceresoli, Andi Shyti, Peter Rosin,
Mauro Carvalho Chehab
Cc: linux-i2c, linux-kernel, linux-media, Allan Nielsen,
Horatiu Vultur, Daniel Machon, Steen Hegelund, Thomas Petazzoni,
Herve Codina
When removing an i2c controller device handling an i2c bus where an i2c
mux is connected to, the removal process hangs and is stuck in the
wait_completion() call done in i2c_del_adapter().
The i2c_del_adapter() tries to removed the i2c adapter related to the
i2c controller device and the wait_completion() is waiting for the i2c
adapter device release. This release is performed when the device is no
more used (i.e. refcount reaches zero).
When an i2c mux is involved in an i2c path, the struct dev topology is
the following:
+----------------+ +-------------------+
| i2c controller | | i2c mux |
| device | | device |
| ^ | | |
| | | | |
| dev's parent | | |
| | | | |
| i2c adapter | | i2c adapter chanX |
| device <---- dev's parent ------ device |
| (no driver) | | (no driver) |
+----------------+ +-------------------+
When an i2c mux device creates an i2c adapter for its downstream
channel, a reference is taken to its adapter dev's parent. This parent
is the i2c mux upstream adapter device.
No relationship exists between the i2c mux device itself and the i2c
controller device (physical device) in order to have the i2c mux device
calling i2c_del_adapter() to remove its downstream adapters and so,
release references taken to the upstream adapter.
This consumer/supplier relationship is typically a devlink relationship.
Also, i2c muxes can be chained and so, the upstream adapter can be
supplied by either an i2c controller device or an other i2c mux device.
In order to get the physical device of the adapter a mux is connected
to, rely on the newly introduced i2c_adapter_get_physdev() and create
the missing devlink between the i2c mux device and the physical device
of the adapter the mux/atr is connected to.
With that done, the i2c mux device is removed before the device handling
the upstream i2c adapter (i2c controller device or i2c mux device). All
references are released and the i2c_del_adapter() call performed by
driver handling the upstream adapter device is not blocking anymore.
Signed-off-by: Herve Codina <herve.codina@bootlin.com>
---
drivers/i2c/i2c-mux.c | 44 +++++++++++++++++++++++++++++++++++++++++++
1 file changed, 44 insertions(+)
diff --git a/drivers/i2c/i2c-mux.c b/drivers/i2c/i2c-mux.c
index c1836114ef56..702ccca22245 100644
--- a/drivers/i2c/i2c-mux.c
+++ b/drivers/i2c/i2c-mux.c
@@ -314,7 +314,10 @@ int i2c_mux_add_adapter(struct i2c_mux_core *muxc,
u32 force_nr, u32 chan_id)
{
struct i2c_adapter *parent = muxc->parent;
+ struct device *parent_physdev;
struct i2c_mux_priv *priv;
+ struct i2c_client *client;
+ struct device_link *dl;
char symlink_name[20];
int ret;
@@ -382,6 +385,47 @@ int i2c_mux_add_adapter(struct i2c_mux_core *muxc,
ACPI_COMPANION(muxc->dev),
chan_id);
+ /*
+ * There is no relationship set between the mux device and the physical
+ * device handling the parent adapter. Create this missing relationship
+ * in order to remove the i2c mux device (consumer) and so the
+ * downstream channel adapters before removing the physical device
+ * (supplier) which handles the i2c mux upstream adapter.
+ */
+ parent_physdev = i2c_get_adapter_physdev(parent);
+ client = i2c_verify_client(muxc->dev);
+ if (!parent_physdev) {
+ dev_warn(muxc->dev,
+ "no physical device for the parent adapter, skip device link\n");
+ } else if (parent_physdev == muxc->dev) {
+ /*
+ * The parent physical device is the mux device itself.
+ * Skip the device link
+ */
+ put_device(parent_physdev);
+ } else if (client && client->adapter == parent) {
+ /*
+ * The mux device is an I2C client on the parent adapter.
+ * i2c_del_adapter(parent) will unregister it and remove
+ * its downstream adapters before waiting for the parent
+ * adapter to be released. No device link is needed, and
+ * adding one would make the driver core unbind the mux
+ * before the parent physical device's .remove() callback.
+ */
+ put_device(parent_physdev);
+ } else {
+ dl = device_link_add(muxc->dev, parent_physdev,
+ DL_FLAG_AUTOREMOVE_CONSUMER);
+ if (!dl) {
+ dev_err(muxc->dev, "failed to create device link to %s\n",
+ dev_name(parent_physdev));
+ put_device(parent_physdev);
+ ret = -EINVAL;
+ goto err_free_priv;
+ }
+ put_device(parent_physdev);
+ }
+
if (force_nr) {
priv->adap.nr = force_nr;
ret = i2c_add_numbered_adapter(&priv->adap);
--
2.56.0
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v10 5/6] i2c: atr: Set adapter physical device
2026-11-18 13:39 [PATCH v10 0/6] lan966x pci device: Add support for SFPs, i2c part Herve Codina
` (3 preceding siblings ...)
2026-11-18 13:39 ` [PATCH v10 4/6] i2c: mux: Create missing devlink between mux and " Herve Codina
@ 2026-11-18 13:39 ` Herve Codina
2026-11-18 13:39 ` [PATCH v10 6/6] i2c: atr: Create missing devlink between ATR and " Herve Codina
5 siblings, 0 replies; 7+ messages in thread
From: Herve Codina @ 2026-11-18 13:39 UTC (permalink / raw)
To: Andrew Lunn, Rob Herring, Saravana Kannan, Wolfram Sang,
Tomi Valkeinen, Luca Ceresoli, Andi Shyti, Peter Rosin,
Mauro Carvalho Chehab
Cc: linux-i2c, linux-kernel, linux-media, Allan Nielsen,
Horatiu Vultur, Daniel Machon, Steen Hegelund, Thomas Petazzoni,
Herve Codina
For i2c atrs, the parent of the atr adapter device is the adapter device
the atr is connected to.
This parent is not necessarily the physical device related to the atr
adapter. An ATR can be used in a split serializer/deserializer topology
where atr->dev is the deserializer, but the ATR channel adapter is owned
by the serializer device passed as desc->parent.
Fill the adap.physdev with the desc->parent device.
Signed-off-by: Herve Codina <herve.codina@bootlin.com>
---
drivers/i2c/i2c-atr.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/i2c/i2c-atr.c b/drivers/i2c/i2c-atr.c
index b98442ffff94..7c599d2d09c4 100644
--- a/drivers/i2c/i2c-atr.c
+++ b/drivers/i2c/i2c-atr.c
@@ -824,6 +824,7 @@ int i2c_atr_add_adapter(struct i2c_atr *atr, struct i2c_atr_adap_desc *desc)
chan->adap.algo = &atr->algo;
chan->adap.algo_data = chan;
chan->adap.dev.parent = desc->parent;
+ chan->adap.physdev = desc->parent;
chan->adap.retries = parent->retries;
chan->adap.timeout = parent->timeout;
chan->adap.quirks = parent->quirks;
--
2.56.0
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v10 6/6] i2c: atr: Create missing devlink between ATR and adapter physical device
2026-11-18 13:39 [PATCH v10 0/6] lan966x pci device: Add support for SFPs, i2c part Herve Codina
` (4 preceding siblings ...)
2026-11-18 13:39 ` [PATCH v10 5/6] i2c: atr: Set " Herve Codina
@ 2026-11-18 13:39 ` Herve Codina
5 siblings, 0 replies; 7+ messages in thread
From: Herve Codina @ 2026-11-18 13:39 UTC (permalink / raw)
To: Andrew Lunn, Rob Herring, Saravana Kannan, Wolfram Sang,
Tomi Valkeinen, Luca Ceresoli, Andi Shyti, Peter Rosin,
Mauro Carvalho Chehab
Cc: linux-i2c, linux-kernel, linux-media, Allan Nielsen,
Horatiu Vultur, Daniel Machon, Steen Hegelund, Thomas Petazzoni,
Herve Codina
When removing an i2c controller device handling an i2c bus where an i2c
ATR (address translator) is connected to, the removal process hangs and
is stuck in the wait_completion() call done in i2c_del_adapter().
The i2c_del_adapter() tries to removed the i2c adapter related to the
i2c controller device and the wait_completion() is waiting for the i2c
adapter device release. This release is performed when the device is no
more used (i.e. refcount reaches zero).
When an i2c ATR is involved in an i2c path, the struct dev topology is
the following:
+----------------+ +-------------------+
| i2c controller | atr->parent | deserializer |
| device | +----------- | device |
| (supplier) | | | (atr->dev) |
| ^ | | +-------------------+
| | | |
| dev's parent | | +-------------------+
| | | | | serializer |
| i2c adapter <-------+ | device |
| device <------------------- | (desc->parent) |
| (no driver) | i2c client | ^ |
+----------------+ | | |
| dev's parent |
| | |
| i2c adapter chanX |
| device |
| (no driver) |
+-------------------+
When an i2c ATR channel adapter is created, a reference is taken to its
adapter dev's parent. This parent is the device owning the channel
adapter (desc->parent), not necessarily atr->dev.
No relationship exists between the device owning the ATR channel adapter
and the i2c controller device (physical device) in order to have that
device calling i2c_del_adapter() to remove its downstream adapters and
so, release references taken to the upstream adapter.
This consumer/supplier relationship is typically a devlink relationship.
Also, i2c ATRs can be chained and so, the upstream adapter can be
supplied by either an i2c controller device or an other i2c ATR or mux
device.
In order to get the physical device of the adapter an ATR is connected
to, rely on the newly introduced i2c_adapter_get_physdev() and create
the missing devlink between the device owning the ATR channel adapter
(desc->parent) and the physical device of the adapter the ATR is
connected to.
With that done, the device owning the ATR channel adapter is removed
before the device handling the upstream i2c adapter (i2c controller
device or i2c mux/ATR device). All references are released and the
i2c_del_adapter() call performed by driver handling the upstream adapter
device is not blocking anymore.
Signed-off-by: Herve Codina <herve.codina@bootlin.com>
---
drivers/i2c/i2c-atr.c | 46 +++++++++++++++++++++++++++++++++++++++++++
1 file changed, 46 insertions(+)
diff --git a/drivers/i2c/i2c-atr.c b/drivers/i2c/i2c-atr.c
index 7c599d2d09c4..5bc7e31ba998 100644
--- a/drivers/i2c/i2c-atr.c
+++ b/drivers/i2c/i2c-atr.c
@@ -788,9 +788,12 @@ int i2c_atr_add_adapter(struct i2c_atr *atr, struct i2c_atr_adap_desc *desc)
struct fwnode_handle *bus_handle = desc->bus_handle;
struct i2c_adapter *parent = atr->parent;
char symlink_name[ATR_MAX_SYMLINK_LEN];
+ struct device *parent_physdev;
struct device *dev = atr->dev;
u32 chan_id = desc->chan_id;
struct i2c_atr_chan *chan;
+ struct i2c_client *client;
+ struct device_link *dl;
int ret, idx;
if (chan_id >= atr->max_adapters) {
@@ -864,6 +867,49 @@ int i2c_atr_add_adapter(struct i2c_atr *atr, struct i2c_atr_adap_desc *desc)
chan->alias_pool = atr->alias_pool;
}
+ /*
+ * There is no relationship set between the device registering the ATR
+ * channel adapter and the physical device handling the parent adapter.
+ * Create this missing relationship so that the consumer device (the one
+ * owning the ATR channel adapter) and the downstream adapters attached
+ * to it are removed before the supplier (the physical device handling
+ * the ATR upstream adapter).
+ */
+ parent_physdev = i2c_get_adapter_physdev(parent);
+ client = i2c_verify_client(desc->parent);
+ if (!parent_physdev) {
+ dev_warn(dev,
+ "no physical device for the parent adapter, skip device link\n");
+ } else if (parent_physdev == desc->parent) {
+ /*
+ * The parent physical device is the parent adapter itself
+ * itself. Skip the device link
+ */
+ put_device(parent_physdev);
+ } else if (client && client->adapter == parent) {
+ /*
+ * The device owning this ATR channel adapter is an I2C
+ * client on the parent adapter. i2c_del_adapter(parent)
+ * will unregister it and remove the channel adapters it
+ * owns before waiting for the parent adapter to be
+ * released. No device link is needed, and adding one
+ * would make the driver core unbind it before the parent
+ * physical device's .remove() callback.
+ */
+ put_device(parent_physdev);
+ } else {
+ dl = device_link_add(desc->parent, parent_physdev,
+ DL_FLAG_AUTOREMOVE_CONSUMER);
+ if (!dl) {
+ dev_err(dev, "failed to create device link to %s\n",
+ dev_name(parent_physdev));
+ put_device(parent_physdev);
+ ret = -EINVAL;
+ goto err_free_alias_pool;
+ }
+ put_device(parent_physdev);
+ }
+
atr->adapter[chan_id] = &chan->adap;
ret = i2c_add_adapter(&chan->adap);
--
2.56.0
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2026-11-18 13:41 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-18 13:39 [PATCH v10 0/6] lan966x pci device: Add support for SFPs, i2c part Herve Codina
2026-11-18 13:39 ` [PATCH v10 1/6] media: rtl2832: Use I2C client device as mux device Herve Codina
2026-11-18 13:39 ` [PATCH v10 2/6] i2c: core: Introduce i2c_get_adapter_physdev() Herve Codina
2026-11-18 13:39 ` [PATCH v10 3/6] i2c: mux: Set adapter physical device Herve Codina
2026-11-18 13:39 ` [PATCH v10 4/6] i2c: mux: Create missing devlink between mux and " Herve Codina
2026-11-18 13:39 ` [PATCH v10 5/6] i2c: atr: Set " Herve Codina
2026-11-18 13:39 ` [PATCH v10 6/6] i2c: atr: Create missing devlink between ATR and " Herve Codina
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®