From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtpout-04.galae.net (smtpout-04.galae.net [185.171.202.116]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4FA85423A6C for ; Mon, 11 May 2026 16:01:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.171.202.116 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778515267; cv=none; b=NAReHXg5Jka5+8qx5OadNNQKzZmyj3EFONtNOinjwk1mvyOi/lN/wkZtiy0zc6FoHtZuqEB2EHoCfc47C1M1yV/6Z5Sjp9qxwvqTfZiV6c2kpZ0d6oBVb1P8W5vb6drftu9KyS3yAvmvnXuVgsbIiZALrKroGtDi+1Me2/Qv4Ig= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778515267; c=relaxed/simple; bh=VE4Q1ZCwZKf4fv9nouGr+jDAoRVmu5G1nUzA/KgWMV0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hfmmrHlaV94O+3hT5nj8SSgePFlzDA2I9o78riMPfrrzXy1asqcOZb3Ve48E+jBrzHMiOuin5g+qifxU4eKWch1X0iaz1sGHCianI396Ou2IjOBJzZrTsuLuJTmOhc3FLQuyR2jAoYx2q2Bkdrxi9qVx/Fm2UtFmcJL8v8U7aMU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=QZhZGqDI; arc=none smtp.client-ip=185.171.202.116 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="QZhZGqDI" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-04.galae.net (Postfix) with ESMTPS id D249BC5E14B; Mon, 11 May 2026 16:01:54 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 45B0D60646; Mon, 11 May 2026 16:01:05 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 0A2A211AF9F2B; Mon, 11 May 2026 18:01:00 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1778515262; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=HbCCxTz9cn4uJyApC9R5AwO+H7RfGmQna7LBbuaMc5s=; b=QZhZGqDIETFQCP9Ud/9yGnt8M4zlCu5hFmlBdbHBWLiJ3AivdMDwOIOjmHO6Sfz1u2DNpv oT+1lFpOjDVmK7iM5eK+QPOht1+84hN8Z3LuR6y2XEzH6zIhuzXHndE0aHyZaTA007P6bm c22qnUt0HogEZTsMlerJlNafHUGlL9w0XVjipHB8NFrTL0MxPh7KGmMaMAb5UGSC5hfJ76 9W8u35+reWOnKVCScvG9xlDyebbiO5kUo7WNL67llRcHFIYCGim7DXOdXpZcBZ95mdoSPG s3MhpfkFKzlGCME7v0AYoaENYiUsv0oNsSQPDLfHfogfl+2GlweLNbSMYZoZ+w== From: Herve Codina To: Andrew Lunn , Rob Herring , Saravana Kannan , Wolfram Sang , Peter Rosin , Andi Shyti Cc: linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org, Allan Nielsen , Horatiu Vultur , Daniel Machon , Steen Hegelund , Luca Ceresoli , Thomas Petazzoni , Herve Codina Subject: [PATCH v7 1/3] i2c: core: Introduce i2c_get_adapter_physdev() Date: Mon, 11 May 2026 18:00:48 +0200 Message-ID: <20260511160051.34700-2-herve.codina@bootlin.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260511160051.34700-1-herve.codina@bootlin.com> References: <20260511160051.34700-1-herve.codina@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Last-TLS-Session-Version: TLSv1.3 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 Reviewed-by: Andi Shyti --- 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 9c46147e3506..59214f0c84ec 100644 --- a/drivers/i2c/i2c-core-base.c +++ b/drivers/i2c/i2c-core-base.c @@ -1919,6 +1919,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 20fd41b51d5c..dff04d20cafe 100644 --- a/include/linux/i2c.h +++ b/include/linux/i2c.h @@ -744,6 +744,7 @@ struct i2c_adapter { int timeout; /* in jiffies */ 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 @@ -911,6 +912,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); /* Return the functionality mask */ -- 2.54.0