From nobody Wed Apr 8 07:48:41 2026 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 5ABE4C28D13 for ; Mon, 22 Aug 2022 10:59:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234394AbiHVK7K (ORCPT ); Mon, 22 Aug 2022 06:59:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50106 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234255AbiHVK7A (ORCPT ); Mon, 22 Aug 2022 06:59:00 -0400 Received: from smtp-fw-9103.amazon.com (smtp-fw-9103.amazon.com [207.171.188.200]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6A44431EFB; Mon, 22 Aug 2022 03:58:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1661165939; x=1692701939; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=66oAeRZph3cUpk7JGrtvitrXyII9ZQBHlmp5sOAgu+Q=; b=SHfoSAS5jUQrylU/GaprMy3NxQpD0R20L8IqW8Lyr42QnC+4CjQF/GJq YOhBghD3VpzQX25ZAIjpikGyA222//yRbK84zjKVI7IRGLLSgMKTDwdVI KfWffywYCNyCpKAe/Yocmls+GL2+IhZfI6gfnqpCLXqGcfvduQaYbYoY6 8=; X-IronPort-AV: E=Sophos;i="5.93,254,1654560000"; d="scan'208";a="1046875125" Received: from pdx4-co-svc-p1-lb2-vlan3.amazon.com (HELO email-inbound-relay-iad-1e-41c1ef8b.us-east-1.amazon.com) ([10.25.36.214]) by smtp-border-fw-9103.sea19.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Aug 2022 10:58:35 +0000 Received: from EX13MTAUEB001.ant.amazon.com (iad12-ws-svc-p26-lb9-vlan3.iad.amazon.com [10.40.163.38]) by email-inbound-relay-iad-1e-41c1ef8b.us-east-1.amazon.com (Postfix) with ESMTPS id 1E5A9160CAD; Mon, 22 Aug 2022 10:58:32 +0000 (UTC) Received: from EX13D08UEB003.ant.amazon.com (10.43.60.11) by EX13MTAUEB001.ant.amazon.com (10.43.60.96) with Microsoft SMTP Server (TLS) id 15.0.1497.38; Mon, 22 Aug 2022 10:58:32 +0000 Received: from EX13MTAUEB002.ant.amazon.com (10.43.60.12) by EX13D08UEB003.ant.amazon.com (10.43.60.11) with Microsoft SMTP Server (TLS) id 15.0.1497.38; Mon, 22 Aug 2022 10:58:31 +0000 Received: from dev-dsk-farbere-1a-46ecabed.eu-west-1.amazon.com (172.19.116.181) by mail-relay.amazon.com (10.43.60.234) with Microsoft SMTP Server id 15.0.1497.38 via Frontend Transport; Mon, 22 Aug 2022 10:58:31 +0000 Received: by dev-dsk-farbere-1a-46ecabed.eu-west-1.amazon.com (Postfix, from userid 14301484) id A21BCE52; Mon, 22 Aug 2022 10:58:30 +0000 (UTC) From: Eliav Farber To: , , , , , , , CC: , , , , , , , , , , , , Subject: [PATCH v2 1/2] dt-bindings: at24: add new optional power-supply property Date: Mon, 22 Aug 2022 10:58:29 +0000 Message-ID: <20220822105830.22790-2-farbere@amazon.com> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220822105830.22790-1-farbere@amazon.com> References: <20220822105830.22790-1-farbere@amazon.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Boards using the AT24 EEPROMs might have a GPIO that controls the power supply of the chip, and it must be set to enable the usage of it. Add a new optional property to the device tree binding document, which allows to specify a GPIO regulator for the pin that controls the power. On Linux this means that we need to enable the GPIO at the beginning of probe function, before trying to access the chip. Signed-off-by: Eliav Farber --- V1 -> V2: Change pointed out by Rob Herring: - Use a gpio regulator for power-supply control. Documentation/devicetree/bindings/eeprom/at24.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Documentation/devicetree/bindings/eeprom/at24.txt b/Documentat= ion/devicetree/bindings/eeprom/at24.txt index f9a7c984274c..6d23ceac5fdc 100644 --- a/Documentation/devicetree/bindings/eeprom/at24.txt +++ b/Documentation/devicetree/bindings/eeprom/at24.txt @@ -73,6 +73,9 @@ Optional properties: =20 - wp-gpios: GPIO to which the write-protect pin of the chip is connected. =20 + - power-supply: phandle of the gpio regulator that provides the supply + voltage. + - address-width: number of address bits (one of 8, 16). =20 Example: --=20 2.37.1 From nobody Wed Apr 8 07:48:41 2026 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 22175C32789 for ; Mon, 22 Aug 2022 10:58:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234233AbiHVK6y (ORCPT ); Mon, 22 Aug 2022 06:58:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49992 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230107AbiHVK6w (ORCPT ); Mon, 22 Aug 2022 06:58:52 -0400 Received: from smtp-fw-2101.amazon.com (smtp-fw-2101.amazon.com [72.21.196.25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 71D3031230; Mon, 22 Aug 2022 03:58:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1661165932; x=1692701932; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=jBeEiHk1ILwd7T0QguL62OOtCR2zHUCuW2NIEn5oMQM=; b=K307zDWhyzdo8JNbGA+pMVXol3u123UB0ucPRp3rJwGXlBI+v/yRce8v QmhOGiiVFtWRf2mk5iJ8z29KDJ7LWQ4unDPBekjowEujOMBkZ8W15FC7B kZgV7R56KIAvScLktwL0ClLZvgGV8w8uZIQ7Ol4Kc5iaU6mbjAB9qofrk I=; X-IronPort-AV: E=Sophos;i="5.93,254,1654560000"; d="scan'208";a="232563806" Received: from iad12-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-iad-1e-7dac3c4d.us-east-1.amazon.com) ([10.43.8.6]) by smtp-border-fw-2101.iad2.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Aug 2022 10:58:40 +0000 Received: from EX13MTAUEB001.ant.amazon.com (iad12-ws-svc-p26-lb9-vlan3.iad.amazon.com [10.40.163.38]) by email-inbound-relay-iad-1e-7dac3c4d.us-east-1.amazon.com (Postfix) with ESMTPS id 89DBC3E00E8; Mon, 22 Aug 2022 10:58:38 +0000 (UTC) Received: from EX13D08UEB002.ant.amazon.com (10.43.60.107) by EX13MTAUEB001.ant.amazon.com (10.43.60.129) with Microsoft SMTP Server (TLS) id 15.0.1497.38; Mon, 22 Aug 2022 10:58:32 +0000 Received: from EX13MTAUEA001.ant.amazon.com (10.43.61.82) by EX13D08UEB002.ant.amazon.com (10.43.60.107) with Microsoft SMTP Server (TLS) id 15.0.1497.38; Mon, 22 Aug 2022 10:58:32 +0000 Received: from dev-dsk-farbere-1a-46ecabed.eu-west-1.amazon.com (172.19.116.181) by mail-relay.amazon.com (10.43.61.243) with Microsoft SMTP Server id 15.0.1497.38 via Frontend Transport; Mon, 22 Aug 2022 10:58:31 +0000 Received: by dev-dsk-farbere-1a-46ecabed.eu-west-1.amazon.com (Postfix, from userid 14301484) id A2EA64C68; Mon, 22 Aug 2022 10:58:30 +0000 (UTC) From: Eliav Farber To: , , , , , , , CC: , , , , , , , , , , , , Subject: [PATCH v2 2/2] eeprom: at24: add support for power-supply control Date: Mon, 22 Aug 2022 10:58:30 +0000 Message-ID: <20220822105830.22790-3-farbere@amazon.com> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220822105830.22790-1-farbere@amazon.com> References: <20220822105830.22790-1-farbere@amazon.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Add an optional gpio regulator to support a power-supply control. If a gpio power-supply regulator is supplied in the device tree, the gpio is enabled during probe, and disabled on remove. Signed-off-by: Eliav Farber --- V1 -> V2: Change pointed out by Rob Herring: - Use a gpio regulator for power-supply control. drivers/misc/eeprom/at24.c | 41 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c index dc3537651b80..a5e3fe1403d9 100644 --- a/drivers/misc/eeprom/at24.c +++ b/drivers/misc/eeprom/at24.c @@ -25,6 +25,7 @@ #include #include #include +#include =20 /* * I2C EEPROMs from most vendors are inexpensive and mostly interchangeabl= e. @@ -78,6 +79,8 @@ struct at24_data { =20 struct gpio_desc *wp_gpio; =20 + struct regulator *supply; + /* * Some chips tie up multiple I2C addresses; dummy devices reserve * them for us, and we'll use them with SMBus calls. @@ -615,6 +618,13 @@ static unsigned int at24_get_offset_adj(u8 flags, unsi= gned int byte_len) } } =20 +static void devm_at24_regulator_disable(void *data) +{ + struct at24_data *at24 =3D data; + + regulator_disable(at24->supply); +} + static int at24_probe(struct i2c_client *client) { struct regmap_config regmap_config =3D { }; @@ -674,6 +684,37 @@ static int at24_probe(struct i2c_client *client) if (!at24) return -ENOMEM; =20 + at24->supply =3D devm_regulator_get_optional(dev, "power"); + if (IS_ERR(at24->supply)) { + err =3D PTR_ERR(at24->supply); + if (err =3D=3D -ENODEV) + at24->supply =3D NULL; + else + return dev_err_probe(dev, err, + "failed to get power-supply regulator\n"); + } + + if (at24->supply) { + err =3D regulator_enable(at24->supply); + if (err < 0) { + dev_err(dev, + "failed to enable power-supply regulator: %d\n", + err); + return err; + } + + err =3D devm_add_action_or_reset(dev, devm_at24_regulator_disable, + at24); + if (err < 0) { + dev_err(dev, + "failed to adction to disable power-supply regulator: %d\n", + err); + return err; + } + + usleep_range(2000, 3000); + } + mutex_init(&at24->lock); at24->byte_len =3D pdata.byte_len; at24->page_size =3D pdata.page_size; --=20 2.37.1