From patchwork Mon May 6 11:37: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: 796098 Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on2134.outbound.protection.outlook.com [40.107.22.134]) (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 9FF73143888; Mon, 6 May 2024 12:24:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.22.134 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714998267; cv=fail; b=bKiKx+NfxnYFLdMdE8hANRS3UXRet5BXgnahFe9YY1uE2DQuonhyppow2QPg9OC+wPaRdnDmH6mdssUQpE9kzDNpm0vYsZsdeWRfikIgdSJoxyHfvTJJBM1KSnESqk5giXF1q8CM5r+xcc4ohSdhVMHsjf+zcfLYnsLYXCXOAAA= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714998267; c=relaxed/simple; bh=Ca2uKOFaUFQYmrzz9oCzcU5bwL0LB/x1odz4MSAr75o=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=IZtD6M32S+jZ5YOPzZTLarrTmL8mypekGHbTL1MCpdEB17gadaIO/dWFHnFw+gK4Htm5Ov5cMAl9VORJx7i2pABVczSq3QzODOiDNeVS5TIY0nA60cIWx55yZxepbXA6J+KYEvy83ZSJC+pnQG+E8QLX0E5k1C5kGZdJhPynS3g= 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=Kldl70xV; arc=fail smtp.client-ip=40.107.22.134 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="Kldl70xV" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Fn15/+A6ms0Ev8d4e32AOTwfu2N20rsmmqvVYc5GbbiECpUoYH2hWBDs2pK2MGm30qVgDjZhEO3d37/01+gY1hBRSKMMmWADyE8Srxd+hF9DfswVvCgjWn5ryR29el5RK/CmImc2P6ih91/IgWSdlZg0JEE+R2rKDuNwLO4yV9ZKu3AqoKDvPeWdaf31AQJM9Ddo9wSF37CWULfL7MfzvHAmQuwz+mHOJzIAdTdsbqQHRxVHSId5zsjMmOLbJ3HAWfv11WT0TBAyYszQSi2zIF5LdL6hhIMPziRO1KGtUvGfbDjA+RgH0r8pfmi18HLDHu9naZkD0YPV05e2ZFDFsA== 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=RyeBzbPQltYK0YMrn80XxvYh6a7BPrKE96OfIhxZSaE=; b=g4IoRcW02DNAT+ftwe2ER0YNzrf07HyefAN0vNu5meReG9KCppvPBamUkI69RGehBVzKUdJJazO58IXqQ4P2iaNhAVfNxy4s6sDJXpWdTQ8Pr7ZEXXbD+35I5zsWle1H0zF+XLsCWoy2ICikqBiD6ZDb0MvmZKI9E7aSbSiN/irDVi7eavqOiOrWCcIZUK9yXu43+oZ8GLZCp6zn6kK0ddDAAhGnEZHgEsdjYTOyPMgF6aS76Fa3WbW0jj+eBtsk359RpdUS1R3RlWxqEYhu+rxp4ovacfR7xW2LMv3BWBOltKKB2sk/cS+AgRceWBIvhPCMvfaUskelrDv9farfGQ== 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=RyeBzbPQltYK0YMrn80XxvYh6a7BPrKE96OfIhxZSaE=; b=Kldl70xVGooihM9hneLNi19A8Cg5V0KNY1P5YrBSF2bfwmSGwcRBbcXQiHwWAbkOCVh4mnFHBjDENgitFk9k1i4Qq52sODg9+2zuidPfWzfduLngB/6xRR2e9LMO+ujAkj3WFrC/8YTapRnvyshHASlsHLg6lE14Qth7X3SG7aA= 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 AS8PR04MB9512.eurprd04.prod.outlook.com (2603:10a6:20b:40f::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7544.41; Mon, 6 May 2024 12:24:19 +0000 Received: from VE1PR04MB6382.eurprd04.prod.outlook.com ([fe80::59d9:878d:65f0:3936]) by VE1PR04MB6382.eurprd04.prod.outlook.com ([fe80::59d9:878d:65f0:3936%4]) with mapi id 15.20.7544.029; Mon, 6 May 2024 12:24:19 +0000 From: Farouk Bouabid Date: Mon, 06 May 2024 13:37:52 +0200 Subject: [PATCH v2 1/7] i2c: mux: add the ability to share mux core address with child nodes Message-Id: <20240506-dev-mule-i2c-mux-v2-1-a91c954f65d7@cherry.de> References: <20240506-dev-mule-i2c-mux-v2-0-a91c954f65d7@cherry.de> In-Reply-To: <20240506-dev-mule-i2c-mux-v2-0-a91c954f65d7@cherry.de> To: Wolfram Sang , Peter Rosin , Andi Shyti , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Farouk Bouabid , Quentin Schulz , Heiko Stuebner , Quentin Schulz 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: VI1PR0102CA0103.eurprd01.prod.exchangelabs.com (2603:10a6:803:15::44) 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_|AS8PR04MB9512:EE_ X-MS-Office365-Filtering-Correlation-Id: 6effe2ac-152d-4e1c-0cf6-08dc6dc771b8 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230031|366007|7416005|1800799015|52116005|376005|921011|38350700005; X-Microsoft-Antispam-Message-Info: =?utf-8?q?g6Miu+avHf5nQ7x5T0lDWM58n3w6F5O?= =?utf-8?q?O0uBEMD9skA7+ZVjcEawGVRoMBr5/rJ5QKOuvY5vcEUVmunAjLAiOriTdICLAlwMK?= =?utf-8?q?/Gh5cDVBKW1WDDmiMKE7HlHvDjvnA0CuzjmW3zXcaJn4e4J4eL+JA5ETGwjFxx6UG?= =?utf-8?q?Ssn9XwQrPsftqhSjBdcFeYoY8MRGtBSRd/Pa+0lsAVO/z0iOUWvFFcLWJeLTuExxR?= =?utf-8?q?LLVCJlHEZio6Gutgw9U0+/Xhh6YGkf/198clGVhGuURbeyr6/pDKjlUTCA3TO1lza?= =?utf-8?q?6xCe7LxNciYoxoSJSD6JoeHQz6AEpiWyyCtS7ahxA4CyDkPeSH6yM79s4PuG8FYvU?= =?utf-8?q?iv9f1xPR9uTxGH6UX70H7zPdYt5TAkz2WJCHktCS5W3YWSANh83s5HWO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o9QfBz?= =?utf-8?q?rGq3s011KYZV7S26tjxPppur+7GfVc1StWi89F2MS0FZTuN/pmEc/WFU=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)(366007)(7416005)(1800799015)(52116005)(376005)(921011)(38350700005); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?XAvcczEzc/8S5LNjCAFV3rX3ra60?= =?utf-8?q?PjC/D+Lgrw8j+rgcYOtKvnN98UjAMHgqQSVLk9ZaVz8Iumvk7fXW46GYo/2rTz5L2?= =?utf-8?q?SJxvUz7xA9cRvxZfnjCdZEXhZoJCfiz3AlU3tJLsU613L9xpk23NPiuTOcPM45GZn?= =?utf-8?q?2X9zAVqE8GaYQypEZXb5HiNw48g08UzCG/j4UGFXkwo+JnjTKvzIn2ibQ3KOw1mcC?= =?utf-8?q?kOifb5ZMdbxCn8qqRvcEuttosBKVRm4Xr4f3opDOGaHqyYDT84YeZsqGp4W0YdVRe?= =?utf-8?q?lg0tYHQNnH9GGfhmZToJxanXBGmVmubm/tp6w4/CameYP6QZStbLQi0SSwqQ571Dv?= =?utf-8?q?bog3q2YM8ZEszdHmLWO9i62QUjXEofjJ+do9RduAC+s9MGTsy79PJp2O0ynVXvYD/?= =?utf-8?q?KLjeh1iIQgLc6M5RRn3V5J5mzWo4Nr2dbS6o+04wy6hSlufQNXTLzBUVRXY3Ug7gu?= =?utf-8?q?38Tt8PawGkxTvUznNmMYTdK7FTiUSZaEqFK6EMXSsLMYJM04zjyvL6zT679kxCAsC?= =?utf-8?q?zDAl/ClaGe2QxGMGhz2KLYfvXsgbcT6LcvFp6kcRIjbkSl4M1OHl2aV8bPabxtyqM?= =?utf-8?q?1reaaPNg2rtWRZvZS+Zt09vfQ3O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DomVMG6V+lRO6nCQmJoHLbW?= =?utf-8?q?FPKMaXGIMYdXY2eFivbHBLsRHf+uAFs54Q=3D=3D?= X-OriginatorOrg: cherry.de X-MS-Exchange-CrossTenant-Network-Message-Id: 6effe2ac-152d-4e1c-0cf6-08dc6dc771b8 X-MS-Exchange-CrossTenant-AuthSource: VE1PR04MB6382.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 May 2024 12:24:15.4771 (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: FrzVeorVuNa9d7Gp/GyT+qoUB/NErmzYZ4C/giRA3T3HQVn4NgJo99HGhdYyw451v3aFiS1qr84xV1osZAnqmgbE2fEz5FdXfJ8JDev6RCY= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR04MB9512 Allow the mux core (if it's an i2c device) to have the same address as a child device. This is useful when the mux core can only use an i2c address that is used by a child device because no other addresses are free to use. eg. the mux core 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 | 25 ++++++++++++++++++++++++- include/linux/i2c-mux.h | 1 + include/linux/i2c.h | 7 +++++++ 4 files changed, 37 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..bdb75a130cab 100644 --- a/drivers/i2c/i2c-mux.c +++ b/drivers/i2c/i2c-mux.c @@ -334,7 +334,30 @@ 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; + /* + * 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 core 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 && muxc->dev->type == &i2c_client_type) { + struct i2c_adapter_quirks *quirks = devm_kzalloc(muxc->dev, + sizeof(*quirks), GFP_KERNEL); + struct i2c_client *client = to_i2c_client(muxc->dev); + + 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 { + 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