From nobody Tue Dec 30 13:27:22 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5A3FDC47072 for ; Wed, 15 Nov 2023 03:58:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234457AbjKOD6K (ORCPT ); Tue, 14 Nov 2023 22:58:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33642 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233763AbjKOD6G (ORCPT ); Tue, 14 Nov 2023 22:58:06 -0500 Received: from gate2.alliedtelesis.co.nz (gate2.alliedtelesis.co.nz [202.36.163.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 764D2D9 for ; Tue, 14 Nov 2023 19:58:02 -0800 (PST) Received: from svr-chch-seg1.atlnz.lc (mmarshal3.atlnz.lc [10.32.18.43]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by gate2.alliedtelesis.co.nz (Postfix) with ESMTPS id AE1BA2C04EC; Wed, 15 Nov 2023 16:58:00 +1300 (NZDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alliedtelesis.co.nz; s=mail181024; t=1700020680; bh=nuXpiTc5KMpjZuPeua6pFPuqtUeESCBp8Bsq5TMv/zA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HTiTsnjBRTpO1kHK8Er+ewHNb1qLDldNdo1MZw1o2NC2shsZST2/I9A8G4bWxupD6 g6zHS66yUo+NeDI/XK/IAYEdFA289XW5ZIGvy61tiJ8EtINa5s85k9T/26dLNM7SAp gdLs/UWHUEuMO7nxFFPlLh920rHCTb65HK7Qwul969gDuYJremElHOmwm4nM9YDQq1 RH8TfUmsAEGYymH3d5EMjyHp/OEKRK3qsqQvVoVXGj3H2yHwKSYmM4X2cFj3ae0C3z X2nJ/crrzmzZ5U+HIF2bGmXU0zFY8aCEfQsqu7Zhb3VrS6h5DuQbEc/3e07KMLWoyH 7+RntO4QVgKng== Received: from pat.atlnz.lc (Not Verified[10.32.16.33]) by svr-chch-seg1.atlnz.lc with Trustwave SEG (v8,2,6,11305) id ; Wed, 15 Nov 2023 16:58:00 +1300 Received: from chrisp-dl.ws.atlnz.lc (chrisp-dl.ws.atlnz.lc [10.33.22.30]) by pat.atlnz.lc (Postfix) with ESMTP id 6267F13EE3F; Wed, 15 Nov 2023 16:58:00 +1300 (NZDT) Received: by chrisp-dl.ws.atlnz.lc (Postfix, from userid 1030) id 5F8D3280590; Wed, 15 Nov 2023 16:58:00 +1300 (NZDT) From: Chris Packham To: wsa@kernel.org, andi.shyti@kernel.org, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, conor+dt@kernel.org, gregory.clement@bootlin.com Cc: linux-i2c@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Chris Packham Subject: [PATCH v6 1/2] dt-bindings: i2c: add bus-reset-gpios property Date: Wed, 15 Nov 2023 16:57:52 +1300 Message-ID: <20231115035753.925534-2-chris.packham@alliedtelesis.co.nz> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231115035753.925534-1-chris.packham@alliedtelesis.co.nz> References: <20231115035753.925534-1-chris.packham@alliedtelesis.co.nz> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-SEG-SpamProfiler-Analysis: v=2.3 cv=L6ZjvNb8 c=1 sm=1 tr=0 a=KLBiSEs5mFS1a/PbTCJxuA==:117 a=BNY50KLci1gA:10 a=k44-534mOdnrxw8nBDMA:9 X-SEG-SpamProfiler-Score: 0 x-atlnz-ls: pat Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Add bus-reset-gpios and bus-reset-duration-us properties to the binding description for i2c busses. These can be used to describe hardware where a common reset GPIO is connected to all downstream devices on and I2C bus. This reset will be asserted then released before the downstream devices on the bus are probed. Signed-off-by: Chris Packham --- Notes: I expect the first reaction to this will be a request to convert the binding to dtschema. I can attempt such a conversion but given it's one of the more core bindings I expect others may have strong opinions. I didn't want to start a conversion without hearing those opinions (or if I could get away without doing the conversion). It's also likely to spin off a whole lot of work to bring existing device trees into line. =20 Changes in v6: - Retarget changes at the i2c core instead of an individual driver Changes in v5: - Rename reset-gpios and reset-duration-us to bus-reset-gpios and bus-reset-duration-us as requested by Wolfram Changes in v4: - Add r-by from Krzysztof Changes in v3: - Rename reset-delay-us to reset-duration-us to better reflect its purpose - Add default: for reset-duration-us - Add description: for reset-gpios Changes in v2: - Update commit message - Add reset-delay-us property Documentation/devicetree/bindings/i2c/i2c.txt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Documentation/devicetree/bindings/i2c/i2c.txt b/Documentation/= devicetree/bindings/i2c/i2c.txt index fc3dd7ec0445..3f95d71b9985 100644 --- a/Documentation/devicetree/bindings/i2c/i2c.txt +++ b/Documentation/devicetree/bindings/i2c/i2c.txt @@ -99,6 +99,14 @@ wants to support one of the below features, it should ad= apt these bindings. indicates that the system is accessible via this bus as an endpoint for MCTP over I2C transport. =20 +- bus-reset-gpios: + GPIO pin providing a common reset for all downstream devices. This GPIO + will be asserted then released before the downstream devices are probed. + +- bus-reset-duration-us: + Reset duration in us. + default: 1 + Required properties (per child device) -------------------------------------- =20 --=20 2.42.0 From nobody Tue Dec 30 13:27:22 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7A4B7C07548 for ; Wed, 15 Nov 2023 03:58:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234490AbjKOD6L (ORCPT ); Tue, 14 Nov 2023 22:58:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33656 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234301AbjKOD6H (ORCPT ); Tue, 14 Nov 2023 22:58:07 -0500 Received: from gate2.alliedtelesis.co.nz (gate2.alliedtelesis.co.nz [202.36.163.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 14F7BE9 for ; Tue, 14 Nov 2023 19:58:03 -0800 (PST) Received: from svr-chch-seg1.atlnz.lc (mmarshal3.atlnz.lc [10.32.18.43]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by gate2.alliedtelesis.co.nz (Postfix) with ESMTPS id C1B3D2C055C; Wed, 15 Nov 2023 16:58:01 +1300 (NZDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alliedtelesis.co.nz; s=mail181024; t=1700020681; bh=E87HizE9/9FKT3+PRq4a/YTBi7Vqzm0FPPXc+Gzrz9E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ntLv+Dz878py+2soWrYS51MmXx2ooRk1pH7DoEiAWVaPIa9Ksg80P8NmPMUY8APJl TDnMXpBmi/f46b7g/Y0zAiuMgTZnNszq6fNUSU1PspkvpgMFqJE4kvM1r3jo0nsGQx +trrUw9Bk9qDbPf0MTq37VhuevSHv5Vq4qu7IeO0b6QFR5rNVQ0SD1/pyca06z+qxa fDY0yUMsGQzrSlby3BA5T4UsotAsWyrv62gy747En72ZavE2lpMDXxLHgemDYxy3My ZH/NgHaYhOgc7esBnueZ4JwigFmVT369rORg1l2q5hvAj6eDXSy+DfmSnHqKM3UZVN qoCuz2+5cSi1A== Received: from pat.atlnz.lc (Not Verified[10.32.16.33]) by svr-chch-seg1.atlnz.lc with Trustwave SEG (v8,2,6,11305) id ; Wed, 15 Nov 2023 16:58:01 +1300 Received: from chrisp-dl.ws.atlnz.lc (chrisp-dl.ws.atlnz.lc [10.33.22.30]) by pat.atlnz.lc (Postfix) with ESMTP id 9A27413EE3F; Wed, 15 Nov 2023 16:58:01 +1300 (NZDT) Received: by chrisp-dl.ws.atlnz.lc (Postfix, from userid 1030) id 975F0280590; Wed, 15 Nov 2023 16:58:01 +1300 (NZDT) From: Chris Packham To: wsa@kernel.org, andi.shyti@kernel.org, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, conor+dt@kernel.org, gregory.clement@bootlin.com Cc: linux-i2c@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Chris Packham Subject: [PATCH v6 2/2] i2c: add an optional bus-reset-gpios property Date: Wed, 15 Nov 2023 16:57:53 +1300 Message-ID: <20231115035753.925534-3-chris.packham@alliedtelesis.co.nz> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231115035753.925534-1-chris.packham@alliedtelesis.co.nz> References: <20231115035753.925534-1-chris.packham@alliedtelesis.co.nz> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-SEG-SpamProfiler-Analysis: v=2.3 cv=L6ZjvNb8 c=1 sm=1 tr=0 a=KLBiSEs5mFS1a/PbTCJxuA==:117 a=BNY50KLci1gA:10 a=O0QBSH250_l-ktZWyFgA:9 X-SEG-SpamProfiler-Score: 0 x-atlnz-ls: pat Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Some hardware designs have a GPIO used to control the reset of all the devices on and I2C bus. It's not possible for every child node to declare a reset-gpios property as only the first device probed would be able to successfully request it. Represent this kind of hardware design by associating the bus-reset-gpios with the parent I2C bus. The reset line will be released prior to the child I2C devices being probed. Signed-off-by: Chris Packham --- Notes: Changes in v6: - Retarget changes at the i2c core instead of an individual driver Changes in v5: - Rename reset-gpios and reset-duration-us to bus-reset-gpios and bus-reset-duration-us as requested by Wolfram Changes in v4: - Add missing gpio/consumer.h - use fsleep() for enforcing reset-duration Changes in v3: - Rename reset-delay to reset-duration - Use reset-duration-us property to control the reset pulse rather than delaying after the reset Changes in v2: - Add a property to cover the length of delay after releasing the reset GPIO - Use dev_err_probe() when requesing the GPIO fails drivers/i2c/i2c-core-base.c | 39 +++++++++++++++++++++++++++++++++++++ include/linux/i2c.h | 3 +++ 2 files changed, 42 insertions(+) diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c index 60746652fd52..d7f53272487b 100644 --- a/drivers/i2c/i2c-core-base.c +++ b/drivers/i2c/i2c-core-base.c @@ -1468,6 +1468,39 @@ int i2c_handle_smbus_host_notify(struct i2c_adapter = *adap, unsigned short addr) } EXPORT_SYMBOL_GPL(i2c_handle_smbus_host_notify); =20 +static int i2c_setup_bus_reset_gpio(struct i2c_adapter *adap) +{ + int res; + + adap->reset_gpios =3D devm_gpiod_get_array_optional(&adap->dev, "bus-rese= t", GPIOD_OUT_HIGH); + if (IS_ERR(adap->reset_gpios)) + return dev_err_probe(&adap->dev, PTR_ERR(adap->reset_gpios), + "Cannot get reset gpio\n"); + res =3D device_property_read_u32(&adap->dev, "bus-reset-duration-us", &ad= ap->reset_duration); + if (res) + adap->reset_duration =3D 1; + + return 0; +} + +static void i2c_deassert_bus_reset_gpio(struct i2c_adapter *adap) +{ + unsigned long *values; + + if (!adap->reset_gpios) + return; + + values =3D bitmap_zalloc(adap->reset_gpios->ndescs, GFP_KERNEL); + if (!values) + return; + + gpiod_set_array_value_cansleep(adap->reset_gpios->ndescs, + adap->reset_gpios->desc, adap->reset_gpios->info, + values); + + bitmap_free(values); +} + static int i2c_register_adapter(struct i2c_adapter *adap) { int res =3D -EINVAL; @@ -1521,6 +1554,10 @@ static int i2c_register_adapter(struct i2c_adapter *= adap) if (res) goto out_reg; =20 + res =3D i2c_setup_bus_reset_gpio(adap); + if (res) + goto out_reg; + device_enable_async_suspend(&adap->dev); pm_runtime_no_callbacks(&adap->dev); pm_suspend_ignore_children(&adap->dev, true); @@ -1539,6 +1576,8 @@ static int i2c_register_adapter(struct i2c_adapter *a= dap) dev_warn(&adap->dev, "Failed to create compatibility class link\n"); #endif + /* bring downstream devices out of reset */ + i2c_deassert_bus_reset_gpio(adap); =20 /* create pre-declared device nodes */ of_i2c_register_devices(adap); diff --git a/include/linux/i2c.h b/include/linux/i2c.h index 0dae9db27538..1110a49dcdaf 100644 --- a/include/linux/i2c.h +++ b/include/linux/i2c.h @@ -746,6 +746,9 @@ struct i2c_adapter { =20 struct irq_domain *host_notify_domain; struct regulator *bus_regulator; + + struct gpio_descs *reset_gpios; + u32 reset_duration; }; #define to_i2c_adapter(d) container_of(d, struct i2c_adapter, dev) =20 --=20 2.42.0