From patchwork Fri Sep 13 10:38:30 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: 828388 Received: from EUR02-VI1-obe.outbound.protection.outlook.com (mail-vi1eur02on2085.outbound.protection.outlook.com [40.107.241.85]) (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 51BCA1D88B4; Fri, 13 Sep 2024 10:38:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.241.85 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726223916; cv=fail; b=A/gxQI3q9Hl8pDmQhzg2ZFsKTTzopyqe8/Iem1f1I1FSH4XMWVSAffYJVa5IbHgbORMa9+P7EiHeYvtnsNIYfaQrnKPSBXAd6xIo1FQS1jiLwz9c0G/o6W6RkrWZe/K2ILNBCQklr/cR+8qlwl8xq0mSia/NzQOGqJ6m/zs0o2w= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726223916; c=relaxed/simple; bh=tRJ2UTlAGm5BrqdzK7SMKu7N9PGcYcsgemuhPIj9PFc=; h=From:To:CC:Subject:Date:Message-ID:Content-Type:MIME-Version; b=awJa9J8E9ucsmuCREDYDUjlWFtBZq5Koos7ls3st+ANM/NjmDpAkWLdIF67v17C5Q6iyl5534Qxmz+/ZxZqzvEBH6WhmohL7AqRWWjMg6r5QcMwGPORJlU81OnjbOysR5RLSgr7cIzcDxpjr5TdplhRKtmk5l/QbzPjGLkQ/KS4= 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=DBGFgInS; arc=fail smtp.client-ip=40.107.241.85 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="DBGFgInS" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=tKGgi/IdiDk+bWObrG7H9KUU6d5vHCRhYzzEn6HS8ISmVh5iH7m0NuqM19ro7bVmme5P9y6SINP+ZYwez+JqUE0fuWQUGe8nmsgcs9lQoTUEFN9RDipEnJZCIgVQIdMNhkKhHzUUnUZ5tvn3xkM3/RKpYLxe72uLxhTmX3NY6PDAE1kDsQ98olr2bexOaaLs14Vqxfv281Vhq+edjpaJ9bGMFaY4ebBC0TN0MLR6aD6tkth9Nx8A8oHutGiq90JoBGqN9/6rMU2Q/dNJnPdZ7pH8tKBW0R1jtcvObHF4j+5g+Ic3EHIkz3Fm+Qu0dZZSJy7JQb0H37UMw701cLBpfA== 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=wzT9tw9W5dxzE7PdMajy/+vF/6QCaliNKemlLeDwevc=; b=JeAPrxxU1o69sSWxDi7XVV12xrrFxd4S7uythfLOvBwaBo7yh9xfAsWWGbrC3agOxW5iN6ACM522CJ/6cwxAoBiyMh0Me5CM+3c5vo6ppGPwjy6x1jCScMISjkH0obBHmufCHBLJVw4QQFbw1VVu11SY0uh088xm4MPgLlB4jKr24yfXdwoEJzXX9mKeWw7WALyX9/pVSk0PXyiy4O4reGGgWrpAZxUTYWqbGDHWTIz6QPOxR/Nsi+Mb/LB10i/8iMFoK1euKO/Z86qHg58ApWc+ahnx3NWJ4fFliCcg5rkiWtKsBWiiVCowVc8ItyZ079/XNPPl+0/JW2OZJ3qCsg== 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=wzT9tw9W5dxzE7PdMajy/+vF/6QCaliNKemlLeDwevc=; b=DBGFgInSXTdsHslt+pAnj3s3orSSA/7fq+9o1OUEpEJc/8gzxHPnaNtr5IQe9ao8j9iT9zvJXFxXd0MPpiagI1piE/O23WINBzHbuVrAWNZYwTpF21kS80c5zsaOugZllugCD1UuHDX23QTVEZxig5y2raObUGsZydMU1uo/PHwLGc/yoRYzoRnjNvZAZIuSWWsChtPUWz6zeutMG4fxjr4Gy0GCvukO+tHP6OGFMKYWDOK5Lsv7jlv6aenafFyt5zhZYDfpEF+eSYW71/UHFJDVsQHeU9G1rhBy3kbiXiGAPKt68GssCuRWNvoT8JBKmBEJqAko4LQVds1fK9VN3g== Received: from DB6PR07MB3509.eurprd07.prod.outlook.com (2603:10a6:6:21::16) by VI1PR07MB9923.eurprd07.prod.outlook.com (2603:10a6:800:1d6::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7962.18; Fri, 13 Sep 2024 10:38:30 +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 10:38:30 +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 v4 2/2] pca954x: Reset if channel select fails Thread-Topic: [PATCH v4 2/2] pca954x: Reset if channel select fails Thread-Index: AQHbBcjsUOspQbnJY0u72i1KC5m03Q== Date: Fri, 13 Sep 2024 10:38:30 +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_|VI1PR07MB9923:EE_ x-ms-office365-filtering-correlation-id: 2bc3298b-68f0-4aef-77a9-08dcd3e03587 x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; ARA:13230040|366016|376014|1800799024|38070700018; x-microsoft-antispam-message-info: =?iso-8859-2?q?dZd6q71qy7Ce459qnafObR/yUU?= =?iso-8859-2?q?qRKFGNplOUKeMZ9WEDOTZ8C8VzvzKq8e3szSfsU1sNqc0TSqg3wa+fIzA1u/?= =?iso-8859-2?q?w1rKHEUWpWrOqVDoy/BNKLjDrfYTgvk1Zu5NVjO/+UoBb7+6EMOnRiQgSeWb?= =?iso-8859-2?q?zHnem6vQvo/WRSHJEQa0TWnlejU/X29wsvHh9zeNMFDqHvZB+CrwXy7etZSA?= =?iso-8859-2?q?raTDOipaHdhVodrb1qnAxkCCjsgyhrzRT/t6A3amaxjdPeo9QlaPOm3ZpTkF?= =?iso-8859-2?q?O5rBm5+SPi2PaRCVg7uZudYmIGi05hUxqeF8mzOmmiAPKADRaTrkbGfAPGiU?= =?iso-8859-2?q?4Xn0z04B4L7UwnCZiMT/7ILC4xIbBIXd1ozInyra+ihP/FT1wSt4XURcEtNF?= =?iso-8859-2?q?HXsRrDubQ1aURnJKjrt9cVWIG8/ekqdQtlSmV+z+6MsCqyvzlu5Za9W7dTrK?= =?iso-8859-2?q?Dm/hduzeyeA8Io0/M1cOuMuguW+n9av4oQNcIPes1dEagNncMwG09/JAl4qU?= =?iso-8859-2?q?6+iJTZ0q/de4k63/oCqS+iT9ylpyPRGSCE87v3f2370/fbISvMnLAA/JU9Gt?= =?iso-8859-2?q?mEdl7lfQiy0rU+6Dn2NryyADzLW4BRm8+1fK6S4fZj1E2jL1nuZFpFxVXRQA?= =?iso-8859-2?q?gS4w4E9nvu3dO5cqOp0n+INsRu07bnmlfTKIEiZyyZbZic80tQR+q4XCISXQ?= =?iso-8859-2?q?9TBSSh+wuGQ8rt6jrcRSL1AzhSu3YB1EC9MbQeKqM9k1kHVp6J+UaXy4JFn3?= =?iso-8859-2?q?Lx/uI93I1+yw6ZWbaV0W8BxSlPnx5hqmOqP/DVMNjp0zXQXg6pmPj1kw0Ry/?= =?iso-8859-2?q?WYfpt8cNmR8R0reFvexO8ykcyWq14iSTPXn0j6EP7sg7n+lzMeS9EdN6nzAm?= =?iso-8859-2?q?6vi9eS+6pKmbl+ZGffec/NY7/N/eD4TJ0a54X/I1nn59QllSH6glSyXUGvj5?= =?iso-8859-2?q?aJEa5pza7qSVj4QQ5vMAPDi0JOBj8eriCTX2KlnAgT3HJ0xa12uFp7TZmzxY?= =?iso-8859-2?q?eL/ZorFZpcZcmzCNUL483dJvMkAlknptyhLmgVCg+NdGhoJdaOR/LHRzYk0x?= =?iso-8859-2?q?p87VjWWENlWcwwipqkyjPOKUONuHxrJjvYuFeUucqREsIwDVI047xo7NJP0V?= =?iso-8859-2?q?EOFXQZTKVgaFyJeD54UEoFKiADSKYuNl7UxM6if2gM//YcgbqQPJgaJUcTb1?= =?iso-8859-2?q?GxEFRACQERh3sln0gRnE2mfH+hw5LxwD6UEecJDpu6oG+rxpUy0q/QvHaZPU?= =?iso-8859-2?q?t2m2XfWyNrn70NJDoamOeQpkuj5k6fGw08h/7M+h/+BXb810igcDl2RA5RnJ?= =?iso-8859-2?q?fw3HuT506GLRwkiroBpQFdm7obEzIZ6x4ukToOyzyaUO8UxQN9eGc56gmAYn?= =?iso-8859-2?q?/hvYjpwG3GnilmX1FtGD6nXDrUywniP4tXuYrL0UM5CdXMlr0ewPm6tTzyPj?= =?iso-8859-2?q?R12ujzSgKNOo8XHNoeiMnLeA=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)(366016)(376014)(1800799024)(38070700018); DIR:OUT; SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-2?q?1ErMnH7RbUwuZtiPthftN9k?= =?iso-8859-2?q?h7Rrd3WtGjjSPvsZPecL2PHVkrf/5WcUa4AjhiqQfwZQTR9bKxU1jHL++zFU?= =?iso-8859-2?q?yWbTzQB/JL01fRp/xqHPhzmbO5mW/tBOS9nZce57kkkQFdy62pGe/5mGiDqZ?= =?iso-8859-2?q?t7CyWS/YNloKSlVIPaU1YbyeWfeQOp4+ufaIgQlDXVzBvvksyfqCIb6Vl6FE?= =?iso-8859-2?q?Ad7SuqtDi6YE/Rcfv5OlMTgQ2SQ7uPXTyHh9i9m/rY4ack+g/jEYcVOUiCQz?= =?iso-8859-2?q?2qMDAVw7gPSdc4oE1SOVvJe2QnYACOMJQYqM4GsPASdVLv3Hi/PJBoFs8aO+?= =?iso-8859-2?q?5rwUZdYTz2Kwa4mI4nY+0u1QUM/5GW0Ss+4F6ywJXXjI7vgPKR7R8b7pO5HT?= =?iso-8859-2?q?bsI8h81IDl5CJBb8q3OTVQvySy37zujTYCVfdtwcx1xo3fp4Vc8t3Q0NxPX8?= =?iso-8859-2?q?bBFsmNNx5u9eVqIcVNalfphtCOkOkHUam5QR86k36+GB95xdVpmQ3fv5ekjV?= =?iso-8859-2?q?Zyet3k4yK+r0+dYhbk8cwlBOMnacKpBGz1C0oZFso2575OttEpjJCJCYwFfz?= =?iso-8859-2?q?jYnHmKWq3zx1tekh42UIJRg+PapkkXoAEa4Oe4ML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859-2?q?Zlx8+2PS1B+YVwpSZkz4BAwHIQkdvHa+CrAAt2mVR8B9iEdenXjqJR3T+qP4?= =?iso-8859-2?q?YIK1VfLbOQlhNjzeKQuHi5/DngX5fQkkw6aubpEzshbDZO0YXumwqiV3N9ix?= =?iso-8859-2?q?iNjgHVk2NVGX3Mau4?= 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: 2bc3298b-68f0-4aef-77a9-08dcd3e03587 X-MS-Exchange-CrossTenant-originalarrivaltime: 13 Sep 2024 10:38:30.3405 (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: eFeh+qDZvc0gKKO4pDOnhzH+iwqwL92zt3opl4DhT1XZlr3oQS6+NWy1NsRuCdgkPT1kewMRdNCOLKcTQDY8vhVti6dE8Se1WtFOMYqTBF4= X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR07MB9923 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 themux 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 v4: * Fix missing condition check from devicetree --- drivers/i2c/muxes/i2c-mux-pca954x.c | 51 ++++++++++++++++++++++------- 1 file changed, 40 insertions(+), 11 deletions(-) diff --git a/drivers/i2c/muxes/i2c-mux-pca954x.c b/drivers/i2c/muxes/i2c-mux-pca954x.c index 6f84018258c4..316048b0011d 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,9 @@ 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) && + data->timeout_reset) + pca954x_reset_mux(data); return ret; } @@ -338,6 +366,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 +376,16 @@ 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) && + data->timeout_reset) + pca954x_reset_mux(data); } /* otherwise leave as-is */ - return 0; + return ret; } static ssize_t idle_state_show(struct device *dev, @@ -543,14 +575,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 +649,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