From patchwork Tue Jun 11 11:43:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Farouk Bouabid X-Patchwork-Id: 803344 Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on2109.outbound.protection.outlook.com [40.107.22.109]) (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 B0C3617B50C; Tue, 11 Jun 2024 11:44:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.22.109 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718106279; cv=fail; b=dIeGhXgIisfkxICpF/kbE5tc/rQIQ9X5AWqfkLXLjC+PERqFY5DOQT4NCrUrei6cLjINLIUWHBXOQWGNulZkRsujpy9sHVI7vuKcvTKFupAD+FaNIuGI1OetlOi+Nq2eRQtejDTimkBK8hJ2rUmJOv2kWsc2vTNOfxbxcQYGUp8= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718106279; c=relaxed/simple; bh=zDdD8wtsbTpMmr0rrs62WkFCQORGAaRR0UXrpm2Y/lI=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=jj8LT9Z3R7xbjT3Pz0Hz+PUxzbsJveFmJlVU8r9ZE3EUmL0P5O8xR3JaN8G7ICXU4G3/BDWx6sAf38/MJuLlFJ4AOL9+aJl2MoWvCYVN1bvibf39610v2lrvXXXeOv9lYieHisNmbijRZf03rbpGjMdsw3MZMeFfkiWPOAZCD1w= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=cherry.de; spf=pass smtp.mailfrom=cherry.de; dkim=pass (1024-bit key) header.d=cherry.de header.i=@cherry.de header.b=dRk9zqjz; arc=fail smtp.client-ip=40.107.22.109 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=cherry.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=cherry.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=cherry.de header.i=@cherry.de header.b="dRk9zqjz" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DWHgEvPAJd2yM9bK0zmCvYMEh3qbQWME5imT9GM/LMbu6j4S2TP1teNDJKd73ALZIJJCWistRYCXPHLy7sOwAEVRWRYW9DL9RKP62JMmFF4SHYU2oSbazIf3490LTUfnBoEG9w01p+ONn8IP7424HkA6frYZDSzXgHbkLe7YsTzySr1FMjfmyeb0zsgy6Uva2H0vbeBGHNWwQTzSsGF6MddiyXgWKx5eaVvsJy1HHBsJU/1U6/Icg7pR+lgt9HbZ/+5/q7uOYQTFQzNBwpuINXmPAoWMTntHh6i+1CxrxlvJxJSi4DoGfeI5vZniidYGWuyNwxWyZ6fTtMJsubA3UQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=7ZFfJkKfmoyi3DJyI1piww+xaO26rxcAoVa8TjmN66A=; b=DQdEnoP/WQoyYISsVELSzsuxCrNxHMyYc+GE6WyrKdsmtQs8MXy1Tx+7CwrY4BUz65TWXctWlGvuTWgU1tbv0dJpasPgXyMqKmBx7G/nO4/lLMDaKnnxtoLelASW+N6ZJeNmT6AihZO6Mx6xeZOhjH4kuqDc1N0dX+UW/8PRqXr5w1CqXn1kdfF5oJfnGUGUoKoduagbgWyR8IkOX599wSAm741WUhZKn7zHWxEutdKLbTRn9TO8iYPbQ8RnBKiHDcdItKSOmsJJTwIwzTZK6lA26hLyz42SlpSm8kd8cTzJLfnYJx662mesEeaNOpcXY2PqlHfK3J/dNM9A5DLdEw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=cherry.de; dmarc=pass action=none header.from=cherry.de; dkim=pass header.d=cherry.de; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cherry.de; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=7ZFfJkKfmoyi3DJyI1piww+xaO26rxcAoVa8TjmN66A=; b=dRk9zqjzN0dDiNZaWi/vBbQYxQwM03VQgGlBiyX3DDwMI2C+vQz39U8ZUyhcbvZCpKdDKISgFySGDXGnPkBGh0+yX4AyR45ymUZK7rigoJHsapo+injk5+YKlBzM4o+KUKlgwCZ2IYyW81pPzkOIK3aAfl/muTu5Ex6V1fKiOwk= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=cherry.de; Received: from VE1PR04MB6382.eurprd04.prod.outlook.com (2603:10a6:803:122::31) by GVXPR04MB10301.eurprd04.prod.outlook.com (2603:10a6:150:1dd::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.36; Tue, 11 Jun 2024 11:44:28 +0000 Received: from VE1PR04MB6382.eurprd04.prod.outlook.com ([fe80::2a24:328:711:5cd6]) by VE1PR04MB6382.eurprd04.prod.outlook.com ([fe80::2a24:328:711:5cd6%5]) with mapi id 15.20.7633.036; Tue, 11 Jun 2024 11:44:28 +0000 From: Farouk Bouabid Date: Tue, 11 Jun 2024 13:43:52 +0200 Subject: [PATCH v3 1/7] i2c: mux: add the ability to share mux address with child nodes Message-Id: <20240611-dev-mule-i2c-mux-v3-1-08d26a28e001@cherry.de> References: <20240611-dev-mule-i2c-mux-v3-0-08d26a28e001@cherry.de> In-Reply-To: <20240611-dev-mule-i2c-mux-v3-0-08d26a28e001@cherry.de> To: Wolfram Sang , Peter Rosin , Andi Shyti , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Farouk Bouabid , Quentin Schulz , Heiko Stuebner Cc: linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-rockchip@lists.infradead.org X-Mailer: b4 0.13.0 X-ClientProxiedBy: VI1PR0902CA0050.eurprd09.prod.outlook.com (2603:10a6:802:1::39) To VE1PR04MB6382.eurprd04.prod.outlook.com (2603:10a6:803:122::31) Precedence: bulk X-Mailing-List: linux-i2c@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: VE1PR04MB6382:EE_|GVXPR04MB10301:EE_ X-MS-Office365-Filtering-Correlation-Id: 0814496d-f05e-4105-39fe-08dc8a0bd91f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230031|52116005|1800799015|376005|7416005|366007|38350700005; X-Microsoft-Antispam-Message-Info: =?utf-8?q?zLNW9Jw5/hl987Ee+1OycTXO00w9/w8?= =?utf-8?q?Fi936cb4d+3aFfcwsMQ5i3ClOOLSRKtIC0Byr7sHjYJ1BGvqCA1Wmom/mKIHX66ae?= =?utf-8?q?MVtyeqSLj1qbtRflv2XBrUrOAn/psNJJ2MmyuATetGJ7Mx9I7943KroQHTFEyaAtw?= =?utf-8?q?QDWUJ6Vv3kmOUKq0AUFjbVpRaMjCl6X1yQ6yYhEmuHtKmVEju74oRhQgUnWgq5TdF?= =?utf-8?q?xaeX+FUvmB6b6TWnJb6OFsKpwpxrUAn1BYSopHfiJlJ15dwhFXymKHYtmu6vs37TQ?= =?utf-8?q?6Qdk/IOi8WMyL+f5x4A9l25FSJcKCXl3aTIAp2iJT/LLT/5prKK5mCKmw2Xrb35a8?= =?utf-8?q?Exd5x6sSMtN20ICnaDrjW2imeFd8ctCVc7wb0Jocn38xeG6c3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XzgxNnuHDK8ZbIYqM?= =?utf-8?q?xuww8TxmOOgAj+itzdZXHn/G2AEw0zQBkHY65++1TqGU6kUs2QdjYkJQ=3D?= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:VE1PR04MB6382.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230031)(52116005)(1800799015)(376005)(7416005)(366007)(38350700005); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?bn1Nq9k6NRf3XRva0Rup7/NQ0oTb?= =?utf-8?q?MfyimV76WNWyIQblEnYNtPirYwcj8fL1FcHZoNdI8c7nX9Qx5181ZpEd8yX/Lp4hK?= =?utf-8?q?0XddY3NIJ0F4MBJTloH8SIiZTDa3nFSVz4OEUH6lWS9/Ysj1al8RzAOjGYzxuBnkA?= =?utf-8?q?r97CkCHkxcj40F/KsZiRelcLWYfj4O3B6Ny1XoXmrcV81okpIOKISgPPN7NjiAiFh?= =?utf-8?q?oQGrmiWQ9nWANt94pHqCwdDZ58jK/OdzzhhYyx/clMNb3whdCm3yOQF7RgcXDJG+p?= =?utf-8?q?g4f+r2Nw4V6cOCuGI/VzCBhqd5N0pKrQSt3qIPOuc8+b4JkIEaiIcyGt+ysHC9P2X?= =?utf-8?q?beWQVhU5c6ziYmIvOsAzpIfHg9Luka3TsH0v9QAgahfZDVHbF+UhuacbRqzkIVMCj?= =?utf-8?q?ECmrHSzm3rYJaYbHUWa6ndfwy49cRTGZ4uygx2XB+lEc5miqYiXKLOEFL+MnaXYoH?= =?utf-8?q?rnzrvIWVzycbf+hDnZsDbCeWJnhNEofxX3mTDXBrRkjNtSamtmbAMPrL7xPMvt06v?= =?utf-8?q?NUgS0usWYwYYPohvwYFoUaYFvtqHC7hTPGioVQXaVexZ2mbT9dlhAoUvv4x/WOrMn?= =?utf-8?q?I9bZMKwV8N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GDryE/jLhs5VcyUcl5Bh16a5x5ty9h7cfn+YMLy3LzwJ3bqjDEsyxTi61T?= =?utf-8?q?n7MXNwqXKFBg/SswwLxMm/flM+G0S26pZw=3D=3D?= X-OriginatorOrg: cherry.de X-MS-Exchange-CrossTenant-Network-Message-Id: 0814496d-f05e-4105-39fe-08dc8a0bd91f X-MS-Exchange-CrossTenant-AuthSource: VE1PR04MB6382.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Jun 2024 11:44:27.9652 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 5e0e1b52-21b5-4e7b-83bb-514ec460677e X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: y19ThY51X7XaV+vhhBxcIi80JZQ2bMkktYb+xDdIYaksx7+6UqaBQ4BbNycmCFx19OqWgRkd8SB4PFPfh4tgba2DK5sOvsJQO6Zkn/KFPgA= X-MS-Exchange-Transport-CrossTenantHeadersStamped: GVXPR04MB10301 Allow the mux (if it's an I2C device) to have the same address as a child device. This is useful when the mux can only use an I2C address that is used by a child device because no other addresses are free to use. eg. the mux can only use address 0x18 which is used by amc6821 connected to the mux. Signed-off-by: Farouk Bouabid --- drivers/i2c/i2c-core-base.c | 6 +++++- drivers/i2c/i2c-mux.c | 48 ++++++++++++++++++++++++++++++++++++++++++++- include/linux/i2c-mux.h | 1 + include/linux/i2c.h | 7 +++++++ 4 files changed, 60 insertions(+), 2 deletions(-) diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c index ff5c486a1dbb..ce2425b0486d 100644 --- a/drivers/i2c/i2c-core-base.c +++ b/drivers/i2c/i2c-core-base.c @@ -821,9 +821,13 @@ static int i2c_check_mux_children(struct device *dev, void *addrp) static int i2c_check_addr_busy(struct i2c_adapter *adapter, int addr) { struct i2c_adapter *parent = i2c_parent_is_i2c_adapter(adapter); + bool skip_check = false; int result = 0; - if (parent) + if (adapter->quirks && adapter->quirks->flags & I2C_AQ_SKIP_ADDR_CHECK) + skip_check = adapter->quirks->skip_addr_in_parent == addr; + + if (parent && !skip_check) result = i2c_check_mux_parents(parent, addr); if (!result) diff --git a/drivers/i2c/i2c-mux.c b/drivers/i2c/i2c-mux.c index 57ff09f18c37..644509bc3496 100644 --- a/drivers/i2c/i2c-mux.c +++ b/drivers/i2c/i2c-mux.c @@ -334,7 +334,53 @@ int i2c_mux_add_adapter(struct i2c_mux_core *muxc, priv->adap.dev.parent = &parent->dev; priv->adap.retries = parent->retries; priv->adap.timeout = parent->timeout; - priv->adap.quirks = parent->quirks; + + struct i2c_adapter_quirks *quirks; + /* + * When creating the adapter, the node devices are checked for I2C address + * match with other devices on the parent adapter, among which is the mux itself. + * If a match is found the node device is not probed successfully. + * Allow the mux to have the same address as a child device by skipping this check. + */ + if (muxc->share_addr_with_children) { + struct i2c_client *client = to_i2c_client(muxc->dev); + + if (muxc->dev->type != &i2c_client_type) + dev_warn_once(muxc->dev, "Mux is not an I2C device\n"); + + quirks = devm_kzalloc(muxc->dev, sizeof(*quirks), GFP_KERNEL); + if (!quirks) + return -ENOMEM; + + if (parent->quirks) + memcpy(quirks, parent->quirks, sizeof(*quirks)); + + quirks->flags |= I2C_AQ_SKIP_ADDR_CHECK; + quirks->skip_addr_in_parent = client->addr; + priv->adap.quirks = quirks; + + } else if (parent->quirks && + parent->quirks->flags & I2C_AQ_SKIP_ADDR_CHECK) { + /* + * Another I2C mux device can be a child of the Mule I2C mux. + * The former could probably not allow address conflict between + * its address and its own children addresses. + * + * For this purpose, do not propagate this flag unless + * share_addr_with_children is set. + */ + quirks = devm_kzalloc(muxc->dev, sizeof(*quirks), GFP_KERNEL); + if (!quirks) + return -ENOMEM; + + memcpy(quirks, parent->quirks, sizeof(*quirks)); + quirks->flags &= ~I2C_AQ_SKIP_ADDR_CHECK; + priv->adap.quirks = quirks; + + } else { + priv->adap.quirks = parent->quirks; + } + if (muxc->mux_locked) priv->adap.lock_ops = &i2c_mux_lock_ops; else diff --git a/include/linux/i2c-mux.h b/include/linux/i2c-mux.h index 98ef73b7c8fd..17ac68bf1703 100644 --- a/include/linux/i2c-mux.h +++ b/include/linux/i2c-mux.h @@ -21,6 +21,7 @@ struct i2c_mux_core { unsigned int mux_locked:1; unsigned int arbitrator:1; unsigned int gate:1; + unsigned int share_addr_with_children:1; void *priv; diff --git a/include/linux/i2c.h b/include/linux/i2c.h index 5e6cd43a6dbd..c3acbaaadae9 100644 --- a/include/linux/i2c.h +++ b/include/linux/i2c.h @@ -670,6 +670,7 @@ int i2c_generic_scl_recovery(struct i2c_adapter *adap); * @max_read_len: maximum length of a read message * @max_comb_1st_msg_len: maximum length of the first msg in a combined message * @max_comb_2nd_msg_len: maximum length of the second msg in a combined message + * @skip_addr_in_parent: No conflict check on parent adapter for a given address * * Note about combined messages: Some I2C controllers can only send one message * per transfer, plus something called combined message or write-then-read. @@ -690,6 +691,7 @@ struct i2c_adapter_quirks { u16 max_read_len; u16 max_comb_1st_msg_len; u16 max_comb_2nd_msg_len; + unsigned short skip_addr_in_parent; }; /* enforce max_num_msgs = 2 and use max_comb_*_len for length checks */ @@ -711,6 +713,11 @@ struct i2c_adapter_quirks { #define I2C_AQ_NO_ZERO_LEN (I2C_AQ_NO_ZERO_LEN_READ | I2C_AQ_NO_ZERO_LEN_WRITE) /* adapter cannot do repeated START */ #define I2C_AQ_NO_REP_START BIT(7) +/** + * do not check for conflict on a given address + * used accordingly with "struct i2c_adapter_quirks.skip_addr_in_parent" + */ +#define I2C_AQ_SKIP_ADDR_CHECK BIT(8) /* * i2c_adapter is the structure used to identify a physical i2c bus along