From patchwork Fri Sep 13 06:51:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wojciech Siudy \(Nokia\)" X-Patchwork-Id: 828394 Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on2064.outbound.protection.outlook.com [40.107.22.64]) (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 EAD7D143C40; Fri, 13 Sep 2024 06:51:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.22.64 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726210281; cv=fail; b=q9aaQDq2aaPUB8dS/4qVbLOvbX06K8W4Zqt9mq7NPQdbPDfRoM1McIAKXCZKB7/7GAo91mfkqkTb8d0sCCmnGfxmlVImGdRW3p5krQO6yRp7GvuNWl2V6l9WckwokMonQ8HCx4McnKXCw0cxHCX9oIJa0qFiqiDQfUM5JnMk9O0= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726210281; c=relaxed/simple; bh=XijObxYKpViX/FYJIkOJQgsO6XAgOLcvV6WB+2B2j7Y=; h=From:To:CC:Subject:Date:Message-ID:Content-Type:MIME-Version; b=rFo2YFptrpnmiGp+eg58jWVu7DpDjbOZUBiA3Dw+TJFGI5qisMWjcbKcn4hzRMgP5LZS5MS4XMFFfd1QqLVzqL9E0luYokSt4cyWV1CoVLGyFaN68UHrSW77bpjmsJJHa4c1GmHEdD1QddTnBHKqyrMzU+KYAEnbBdrg5dwjan8= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nokia.com; spf=fail smtp.mailfrom=nokia.com; dkim=pass (2048-bit key) header.d=nokia.com header.i=@nokia.com header.b=Rczl38sz; arc=fail smtp.client-ip=40.107.22.64 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nokia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nokia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=nokia.com header.i=@nokia.com header.b="Rczl38sz" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=IFfQmkj5KFRshuogHxwMTHnhGh/wo7Rhwd6JlgIv4COlF54LZOqo9TgAXbdxq3ovVGFv3pHsomZSYW9ZcU/7o/UsX/5KZrUKp68oFYRXZUIkXqtvIAWHN+o5BLS0xELl0OGzg//bmw7edcLo96Qz0QR42dpfSIjZVLJEmBtLCQADuuDxdhwmkOLsCGp78Dl4nfU/wwwxwHzP8dDQ9F7uBgGNQ53fjflmxhBx1R2oaxWPOyqQY6BjO+ibHfQqpBl7SkyRC+OO7VqDwTHkvvs2sgrnS7jNh047UHvOdGQlOWrAoZj10QoHKr/d3yF5+pRTbkOVwhsLHHKZokRgr93Ccg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=4muBqgwpc+a4z5zH5aZ38iY0RdBI2H3bvcBnTChOaIk=; b=A+U2B09Rch/LH1jbGJrSSppqOWyPsN6oQQ7SWpoR8kLwBU4NvmKNPZpTHDLO3Xqbd6bVvs8Gvj/XXJH/ty7e1Z7ccr3jm0n1/vW+LAgPIAf6sP68FlQMapd5eh/71wOecME1S332aiqZR34x5QAKFs1ykuKKiUKD7pwX6WA06iyKDSwlmrUF/3eRQf0A/DfSHWx8zXFLpWUperKpxLtUWG7iPER9L9qV++oYv9gX941VYFvq6kyFeEoowKOjBhMZlMx2R9VnX//DLyjmYZm8ZFhDZkp24zWsS8PZv2VWu/D4iPOMVaTdeszRF0xoW9g/ruYCk281NCylY4cECQscjw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nokia.com; dmarc=pass action=none header.from=nokia.com; dkim=pass header.d=nokia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nokia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=4muBqgwpc+a4z5zH5aZ38iY0RdBI2H3bvcBnTChOaIk=; b=Rczl38szBE4sOeEadEsxNoqsI4ppxSF8NLOG0N2jiKesqecUSE6rUfqXVfnUHsctG2UE/2PF/uTQftzzbtBfWy3Zu6cwR41deAdr7TVJ+Lg9HscoTNLw8bmDaQsSGcAX4sLerSYqz++vabJJHlu+Dbp4SYC09j5YIIfyQx0npEZ3oje4NYEwbuwF1IBzZy/dG2DlQgZw+tefsjn+MInwtiLM3K05fIp01nIwwZaICd3C+lsehk0UelkQhi10EaqeC8U4hAdB+9yMstMDva5yNcfoEybuY6ZTh8nk6+4D7pm/g9LEHr6U+Amm8vzXCYDNUFc354x9LbqnFszNDm6vVg== Received: from DB6PR07MB3509.eurprd07.prod.outlook.com (2603:10a6:6:21::16) by PA4PR07MB8389.eurprd07.prod.outlook.com (2603:10a6:102:2a0::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7962.19; Fri, 13 Sep 2024 06:51:17 +0000 Received: from DB6PR07MB3509.eurprd07.prod.outlook.com ([fe80::5484:a966:1322:f78b]) by DB6PR07MB3509.eurprd07.prod.outlook.com ([fe80::5484:a966:1322:f78b%6]) with mapi id 15.20.7962.017; Fri, 13 Sep 2024 06:51:16 +0000 From: "Wojciech Siudy (Nokia)" To: "linux-i2c@vger.kernel.org" , "devicetree@vger.kernel.org" CC: Peter Rosin , Andi Shyti , "laurent.pinchart@ideasonboard.com" Subject: [PATCH v3 2/2] pca954x: Reset if channel select fails Thread-Topic: [PATCH v3 2/2] pca954x: Reset if channel select fails Thread-Index: AQHbBakvQJCOfWHDv0+K266wlnTGWw== Date: Fri, 13 Sep 2024 06:51:16 +0000 Message-ID: Accept-Language: pl-PL, en-US Content-Language: pl-PL X-MS-Has-Attach: X-MS-TNEF-Correlator: msip_labels: authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nokia.com; x-ms-publictraffictype: Email x-ms-traffictypediagnostic: DB6PR07MB3509:EE_|PA4PR07MB8389:EE_ x-ms-office365-filtering-correlation-id: d906e9f5-e771-4830-a434-08dcd3c0775a x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; ARA:13230040|376014|366016|1800799024|38070700018; x-microsoft-antispam-message-info: =?iso-8859-2?q?ba8Gj28x0Xsv8f1QVV4CIYXi1x?= =?iso-8859-2?q?gz29xvUw5BE/la+6+x2aRHpTDsI6ET9CScYlSD0FyOz7jEUISB1N2CzHUp+Z?= =?iso-8859-2?q?UdnPODydGFFr1y2pxK28O3n+QaORN2aLX5I5RA0pQHWwA4wnyHztFoyC4geM?= =?iso-8859-2?q?lItlSFS86Vo7VHHtkpBpxVUqPjvOQigZmprzGqePn49UVymB7bMQwwBCABCk?= =?iso-8859-2?q?EfD9GEJoFOIN8le40M6e0ANvowy7br01HUP2GuU+RN/vzSSPnRreOE44zwVj?= =?iso-8859-2?q?HnlBwsbqOqj59NbmGRWEmah87+5lcVtrLjqxWkGvLPtaW4tC/jlh8bhLLuIk?= =?iso-8859-2?q?ruLDn0YOY6rL5QjAUroiCWpHZlH8bABppPoxKCMkqcxLuAUCOYXSDYi3gqgZ?= =?iso-8859-2?q?ap0aFgoSYtC8+Q2AbUTASEY1OQRVbOmwaIywdRYOP6S1Cpo7drcXiOm7I6vv?= =?iso-8859-2?q?pSl+1/a1xI3KnXcNo8keO+G8F+fetjA36woaFEHYlkZE8X2pdMsuFp+IeWGL?= =?iso-8859-2?q?tvn8b3LNmKFWTk4gs96iWvsJDvZqH54KIcr9tA7BAIuoqA/WsnlYHbuWHqAk?= =?iso-8859-2?q?dpYYYAkLLCsVYi9Zixoa0/ocnmqDAUChz0/0q4JzXy2XiEEM2PGTBaGTyJuN?= =?iso-8859-2?q?JSq/Cgkxxy9tojVtvE4Ebw/g/UnsgZsPx4GhqykYPkUti2/GzElKGzgChzNS?= =?iso-8859-2?q?rXc1ltPoon7qD2OJZLsm2/2DPxuN3io3+w8xEBAKq7RvTmwk4VFad+hXn/E/?= =?iso-8859-2?q?zDXh3U3eA8gcKYQDD8InJZX8BabZOVqo7KxBlmKYAxigqV+UfwLYOHwzX8Pp?= =?iso-8859-2?q?aM64qhO3B2rYVoWMclnKoUMvgHn0I1R8XeQGitwKiJFIuH/0+ImbTFA2iPOp?= =?iso-8859-2?q?+yPLR8w9bpQApJd55HnDuSoFdQYCGIZ+ePEfJZoIG7pZ7XI8A6RKqvwkrT5e?= =?iso-8859-2?q?PHkO0aaAQqtNKVSD4m19SnzEXfVX45JTG6yJwXVsZYE3Rige0EYz62Sirhdu?= =?iso-8859-2?q?vEyXZhtdctcTT78YLmWor6x5tXYFDJqQcMOJPTCt1M/68z8QCaLysS3N3Ghu?= =?iso-8859-2?q?u1CHHZXlm6/BGdBILYC+XApSq8k5Px79uuxNWC26L2OkBKVoo/MxR2QbWorv?= =?iso-8859-2?q?jDTNxbf7nM0977wMJcpBI4CKJezhs+vEK9Vpm5V3QR9C62RtrqJu487LCXPI?= =?iso-8859-2?q?0E2LfArDTBrsCs9f7jmPXLe0SaKxIOesPdznkAwaEE2rPo9XfGTsXNzfSx2h?= =?iso-8859-2?q?am9Ip0VNhKmTNG761WczPj4E6vsX/GKSIwt70/34wuq4/h15k8UHuPyjCJK2?= =?iso-8859-2?q?8wUq0KMqLd8dAl9caUj1KlC7vYRAoyS7ot+cux4raLN1q6edCmFUNLIEYZFB?= =?iso-8859-2?q?cpIbzr9qbloAUAxZN+jA=3D=3D?= x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DB6PR07MB3509.eurprd07.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(376014)(366016)(1800799024)(38070700018); DIR:OUT; SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-2?q?tPCv5iEqtPOGtVHIl12E1us?= =?iso-8859-2?q?ZKa4nFjX7fMxwvAFUG757k/91TLfEu/xFmzGkiitfFeRb6MMIgwqVh/V4V5+?= =?iso-8859-2?q?nt+wr1SifMGqKBfqmd4//1QZK7DrOE1aN+hpBMvISBigJQ9ir1wSl4OHvg9Y?= =?iso-8859-2?q?r8WJw+dG64zghDK/QOuE+q+xeV9WxYclDCmrwxoItoiqyoCjPSQfbM6qVMWr?= =?iso-8859-2?q?CoOg7+fj5D2vTvEbbtbviT4ijiYk5wYLRYq1Gvm7ul9bDKZx8LH5HlGFlzyK?= =?iso-8859-2?q?r1BjCXsfi4Q68BSnit/aJ/0KZX8TMCItAunzWEOovgByk2pyEahUJmPm3/ky?= =?iso-8859-2?q?KzRNsL8pfSuCraVL24mQIK40oHrFjxv53yr/SKX7RE0y0OJpV9Mhbmw5vf/H?= =?iso-8859-2?q?BJgHh//N9eHQsi96fBheQKRvujI6tMTdsDgmi5lFxBJCK+9YE4Ne4pc17evU?= =?iso-8859-2?q?w+uNjst+pqtiJNZ8/D9PfPAYzz1iAGO5vNFtQMz+Ajx6eFVNJqZLakBVB5/W?= =?iso-8859-2?q?O4xN1aqxU/7tSXem3M56hOjTBVoa2LEo9TYPXtUWy6bDLRvM+QB77BAmMddA?= =?iso-8859-2?q?mO2lVF4eSQs2sdZUUG8LWEBwNIzqeMKDahHgblqqiiBjjLtfJoSwQM8cxbg1?= =?iso-8859-2?q?v8x8XICH2i8pLQ6hQSfdIFdFL34stVnb62/du+Cg5LdN5aELVxMAYXY9stBK?= =?iso-8859-2?q?wIbxGFUwD9z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ffewgz9kPFsSmUx0lmdRUMT7pQs?= =?iso-8859-2?q?Q1LW0Q/aiBMbdlTAm?= Precedence: bulk X-Mailing-List: linux-i2c@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-OriginatorOrg: nokia.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: DB6PR07MB3509.eurprd07.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: d906e9f5-e771-4830-a434-08dcd3c0775a X-MS-Exchange-CrossTenant-originalarrivaltime: 13 Sep 2024 06:51:16.8831 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 5d471751-9675-428d-917b-70f44f9630b0 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: mIcARrNaB1MpFpN+9lOz0A/NGJallFc66C2EpF3MDaW3FQ/ntkD5yoN9MmTcSb3r+La41t31Xcz7Zx0YDP7uPze8G+xa8CRVNLOtnBrCLjo= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA4PR07MB8389 From: Wojciech Siudy If the channel selection or deselection times out, it indicates a failure in the mux's I2C subsystem. Without sending a reset pulse, a power-on-reset of the entire device would be required to restore communication. The datasheet specifies a minimum hold time of 4 ns for the reset pulse, but due to the path's capacitance and the mux having its own clock, it is recommended to extend this to approximately 1 us. This option can be enabled using the i2c-mux-timeout-reset property in the device tree and should only be used if the reset line is not shared with other devices. Signed-off-by: Wojciech Siudy --- Changelog: v2: * Removed mail header from the commit log * Decreased reset pulse hold time from 10 to 1 ms v3: * Make this functionality enabled by appropriate property in devicetree --- drivers/i2c/muxes/i2c-mux-pca954x.c | 48 ++++++++++++++++++++++------- 1 file changed, 37 insertions(+), 11 deletions(-) diff --git a/drivers/i2c/muxes/i2c-mux-pca954x.c b/drivers/i2c/muxes/i2c-mux-pca954x.c index 6f84018258c4..c9ac0f9c9408 100644 --- a/drivers/i2c/muxes/i2c-mux-pca954x.c +++ b/drivers/i2c/muxes/i2c-mux-pca954x.c @@ -110,6 +110,7 @@ struct pca954x { u8 last_chan; /* last register value */ /* MUX_IDLE_AS_IS, MUX_IDLE_DISCONNECT or >= 0 for channel */ s32 idle_state; + u8 timeout_reset; struct i2c_client *client; @@ -316,6 +317,30 @@ static u8 pca954x_regval(struct pca954x *data, u8 chan) return 1 << chan; } +static void pca954x_reset_deassert(struct pca954x *data) +{ + if (data->reset_cont) + reset_control_deassert(data->reset_cont); + else + gpiod_set_value_cansleep(data->reset_gpio, 0); +} + +static void pca954x_reset_assert(struct pca954x *data) +{ + if (data->reset_cont) + reset_control_assert(data->reset_cont); + else + gpiod_set_value_cansleep(data->reset_gpio, 1); +} + +static void pca954x_reset_mux(struct pca954x *data) +{ + dev_warn(&data->client->dev, "resetting the device\n"); + pca954x_reset_assert(data); + udelay(1); + pca954x_reset_deassert(data); +} + static int pca954x_select_chan(struct i2c_mux_core *muxc, u32 chan) { struct pca954x *data = i2c_mux_priv(muxc); @@ -329,6 +354,8 @@ static int pca954x_select_chan(struct i2c_mux_core *muxc, u32 chan) ret = pca954x_reg_write(muxc->parent, client, regval); data->last_chan = ret < 0 ? 0 : regval; } + if (ret == -ETIMEDOUT && (data->reset_cont || data->reset_gpio)) + pca954x_reset_mux(data); return ret; } @@ -338,6 +365,7 @@ static int pca954x_deselect_mux(struct i2c_mux_core *muxc, u32 chan) struct pca954x *data = i2c_mux_priv(muxc); struct i2c_client *client = data->client; s32 idle_state; + int ret = 0; idle_state = READ_ONCE(data->idle_state); if (idle_state >= 0) @@ -347,13 +375,14 @@ static int pca954x_deselect_mux(struct i2c_mux_core *muxc, u32 chan) if (idle_state == MUX_IDLE_DISCONNECT) { /* Deselect active channel */ data->last_chan = 0; - return pca954x_reg_write(muxc->parent, client, - data->last_chan); + ret = pca954x_reg_write(muxc->parent, client, data->last_chan); + if (ret == -ETIMEDOUT && (data->reset_cont || data->reset_gpio)) + pca954x_reset_mux(data); } /* otherwise leave as-is */ - return 0; + return ret; } static ssize_t idle_state_show(struct device *dev, @@ -543,14 +572,6 @@ static int pca954x_get_reset(struct device *dev, struct pca954x *data) return 0; } -static void pca954x_reset_deassert(struct pca954x *data) -{ - if (data->reset_cont) - reset_control_deassert(data->reset_cont); - else - gpiod_set_value_cansleep(data->reset_gpio, 0); -} - /* * I2C init/probing/exit functions */ @@ -625,6 +646,11 @@ static int pca954x_probe(struct i2c_client *client) data->idle_state = MUX_IDLE_DISCONNECT; } + if (device_property_read_bool(dev, "i2c-mux-timeout-reset")) + data->timeout_reset = 1; + else + data->timeout_reset = 0; + /* * Write the mux register at addr to verify * that the mux is in fact present. This also