From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtpout-03.galae.net (smtpout-03.galae.net [185.246.85.4]) (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 E299340B6EA for ; Fri, 27 Feb 2026 13:59:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.85.4 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772200766; cv=none; b=Ee9OqMBezNR/fxgVbG9qv51V331hn7bikJLh2gtM8ymSyCIQ5WznI1RdbxwCFscoA1RO3m9bzbR1KsmCQnA9dKeW+Fnl3mlB2lqNhEa2n6p1lry+8lbqiasTCMC+iGsSLbsaIosZ5anMMMwaySv6upg6yvvPg6VWR6wLKjsAJBU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772200766; c=relaxed/simple; bh=a6PXb9i+X1sA4Or6Y0E0jaWxGpVSsTki8LaE/KXqa6Y=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CCsoQgROTk1v8RcZsz8UEYXFrVGKR37W1tHTh8V1tR37Ob1z8aQACQ2l2KX6yplvuWmf7NEGRQKRk/b46pMLMLfGVeajdgfbZeZCpeuvNiY4QMHemyZUykwnXaEu3FqjF45EbjuOCPRk9dRrgaMsZe1J/5kTDna7BhmO0CmaSHE= 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=w4eum9Fv; arc=none smtp.client-ip=185.246.85.4 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="w4eum9Fv" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-03.galae.net (Postfix) with ESMTPS id C78984E41922; Fri, 27 Feb 2026 13:59:23 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 9B9205FE74; Fri, 27 Feb 2026 13:59:23 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 89B991036944D; Fri, 27 Feb 2026 14:59:06 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1772200760; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=d6GGxvV9pG6IJ1z9yk6YAUQbBDjX/c3f4oqsz6zyCeA=; b=w4eum9Fv6LvEcDP17xGgtJmhQFEqh4dMU1qVvpHKgx0UdviP8T2rRlJE1uCx60GcOKm3W6 mMd6tPj3uYXoPHPT7e9qrC7MzGR2PWAWQlEEfuPi+9SXYT1Z/SXtLQRqYCwAxrGBnFygZ+ gm3xpEiDnuTrpz7nX+B2ntYGZkVym4XUeJSq19QHBx/nYfRWFtD+NH0wjMOy92HJ/k9o86 zyEMOMMZ4b6guUeRDpnHFAjQH9gMaBlgH17YpLBS1SXjyLvhmkBUNMjIBDJzt5GS2a7rNw bTqF8kKp8OY0J7hArYrrVXKYELUYXDDN8kRt3p/YGW8Mhn92CVDVKLqBNRcITQ== From: Herve Codina To: Andrew Lunn , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Geert Uytterhoeven , Kalle Niemi , Matti Vaittinen , Greg Kroah-Hartman , "Rafael J. Wysocki" , Danilo Krummrich , Frank Li , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , Michael Turquette , Stephen Boyd , Andi Shyti , Wolfram Sang , Peter Rosin , Arnd Bergmann , Herve Codina , Saravana Kannan , Bjorn Helgaas , Charles Keepax , Richard Fitzgerald , David Rhodes , Linus Walleij , Ulf Hansson , Mark Brown , Len Brown , Andy Shevchenko , Daniel Scally , Heikki Krogerus , Sakari Ailus , Davidlohr Bueso , Jonathan Cameron , Dave Jiang , Alison Schofield , Vishal Verma , Ira Weiny , Dan Williams , Shawn Guo Cc: Wolfram Sang , linux-kernel@vger.kernel.org, driver-core@lists.linux.dev, imx@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-clk@vger.kernel.org, linux-i2c@vger.kernel.org, devicetree@vger.kernel.org, linux-pci@vger.kernel.org, linux-sound@vger.kernel.org, patches@opensource.cirrus.com, linux-gpio@vger.kernel.org, linux-pm@vger.kernel.org, linux-spi@vger.kernel.org, linux-acpi@vger.kernel.org, linux-cxl@vger.kernel.org, Allan Nielsen , Horatiu Vultur , Steen Hegelund , Luca Ceresoli , Thomas Petazzoni Subject: [PATCH v5 15/28] i2c: core: Introduce i2c_get_adapter_physdev() Date: Fri, 27 Feb 2026 14:54:12 +0100 Message-ID: <20260227135428.783983-16-herve.codina@bootlin.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260227135428.783983-1-herve.codina@bootlin.com> References: <20260227135428.783983-1-herve.codina@bootlin.com> Precedence: bulk X-Mailing-List: devicetree@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.53.0