From: Herve Codina <herve.codina@bootlin.com>
To: Andrew Lunn <andrew@lunn.ch>, Rob Herring <robh@kernel.org>,
Saravana Kannan <saravanak@kernel.org>,
Wolfram Sang <wsa+renesas@sang-engineering.com>,
Andi Shyti <andi.shyti@kernel.org>,
Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>,
Luca Ceresoli <luca.ceresoli@bootlin.com>,
Peter Rosin <peda@lysator.liu.se>
Cc: linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org,
Allan Nielsen <allan.nielsen@microchip.com>,
Horatiu Vultur <horatiu.vultur@microchip.com>,
Daniel Machon <daniel.machon@microchip.com>,
Steen Hegelund <steen.hegelund@microchip.com>,
Thomas Petazzoni <thomas.petazzoni@bootlin.com>,
Herve Codina <herve.codina@bootlin.com>
Subject: [PATCH v9 1/3] i2c: core: Introduce i2c_get_adapter_physdev()
Date: Wed, 4 Nov 2026 14:53:04 +0100 [thread overview]
Message-ID: <20261104135324.492692-2-herve.codina@bootlin.com> (raw)
In-Reply-To: <20261104135324.492692-1-herve.codina@bootlin.com>
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
next prev parent reply other threads:[~2026-11-04 13:54 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-04 13:53 [PATCH v9 0/3] lan966x pci device: Add support for SFPs, i2c part Herve Codina
2026-11-04 13:53 ` Herve Codina [this message]
2026-11-04 13:53 ` [PATCH v9 2/3] i2c: {mux,atr}: Set adapter physical device Herve Codina
2026-11-04 13:53 ` [PATCH v9 3/3] i2c: {mux,atr}: Create missing devlink between mux/atr and " Herve Codina
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=20261104135324.492692-2-herve.codina@bootlin.com \
--to=herve.codina@bootlin.com \
--cc=allan.nielsen@microchip.com \
--cc=andi.shyti@kernel.org \
--cc=andrew@lunn.ch \
--cc=daniel.machon@microchip.com \
--cc=horatiu.vultur@microchip.com \
--cc=linux-i2c@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=luca.ceresoli@bootlin.com \
--cc=peda@lysator.liu.se \
--cc=robh@kernel.org \
--cc=saravanak@kernel.org \
--cc=steen.hegelund@microchip.com \
--cc=thomas.petazzoni@bootlin.com \
--cc=tomi.valkeinen@ideasonboard.com \
--cc=wsa+renesas@sang-engineering.com \
/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
all inboxes | Powered by JetHome®