From patchwork Sun Aug 28 15:49:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Farber, Eliav" X-Patchwork-Id: 600798 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 0382EECAAD2 for ; Sun, 28 Aug 2022 15:49:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229973AbiH1PtL (ORCPT ); Sun, 28 Aug 2022 11:49:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46398 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229527AbiH1PtL (ORCPT ); Sun, 28 Aug 2022 11:49:11 -0400 Received: from smtp-fw-80007.amazon.com (smtp-fw-80007.amazon.com [99.78.197.218]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2CBE832EDC; Sun, 28 Aug 2022 08:49:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1661701751; x=1693237751; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=zU4xJPlhx9313yKXJ3gXwqC/qnSgv3tm1Z0eW7nbiHA=; b=jw5SzcPKKHZFFuQWemfNmEb2ugYUBD5m0JEUr9EFz6LpC+4Kaa8VmTMy gn0PhbjIA17kozQpg+cclfNENjKJhsl1Y/Cn5Xk6l/hdsrFgpD8G9RZfa TlC8QgVQC1V3XdtzhhZAR8sO7Wvp2PZmtm/HpvLGGiIIrrEqbo6gRyPFE I=; X-IronPort-AV: E=Sophos;i="5.93,270,1654560000"; d="scan'208";a="124170975" Received: from pdx4-co-svc-p1-lb2-vlan3.amazon.com (HELO email-inbound-relay-iad-1e-26daedd8.us-east-1.amazon.com) ([10.25.36.214]) by smtp-border-fw-80007.pdx80.corp.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Aug 2022 15:49:10 +0000 Received: from EX13MTAUWA001.ant.amazon.com (iad12-ws-svc-p26-lb9-vlan2.iad.amazon.com [10.40.163.34]) by email-inbound-relay-iad-1e-26daedd8.us-east-1.amazon.com (Postfix) with ESMTPS id DC311E110B; Sun, 28 Aug 2022 15:49:06 +0000 (UTC) Received: from EX19D013UWA001.ant.amazon.com (10.13.138.253) by EX13MTAUWA001.ant.amazon.com (10.43.160.58) with Microsoft SMTP Server (TLS) id 15.0.1497.38; Sun, 28 Aug 2022 15:49:05 +0000 Received: from EX13MTAUWA001.ant.amazon.com (10.43.160.58) by EX19D013UWA001.ant.amazon.com (10.13.138.253) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1118.12; Sun, 28 Aug 2022 15:49:05 +0000 Received: from dev-dsk-farbere-1a-46ecabed.eu-west-1.amazon.com (172.19.116.181) by mail-relay.amazon.com (10.43.160.118) with Microsoft SMTP Server id 15.0.1497.38 via Frontend Transport; Sun, 28 Aug 2022 15:49:05 +0000 Received: by dev-dsk-farbere-1a-46ecabed.eu-west-1.amazon.com (Postfix, from userid 14301484) id DAA244B91; Sun, 28 Aug 2022 15:49:04 +0000 (UTC) From: Eliav Farber To: , , , , , , , CC: , , , , , , , , , , , , Subject: [PATCH v3 1/2] dt-bindings: at24: add new optional power-supply property Date: Sun, 28 Aug 2022 15:49:03 +0000 Message-ID: <20220828154904.20477-2-farbere@amazon.com> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220828154904.20477-1-farbere@amazon.com> References: <20220828154904.20477-1-farbere@amazon.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org 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 --- V2 -> V3: Apply on top of v6.0-rc1 Documentation/devicetree/bindings/eeprom/at24.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Documentation/devicetree/bindings/eeprom/at24.yaml b/Documentation/devicetree/bindings/eeprom/at24.yaml index d14e0accbda8..82f0046f67a9 100644 --- a/Documentation/devicetree/bindings/eeprom/at24.yaml +++ b/Documentation/devicetree/bindings/eeprom/at24.yaml @@ -179,6 +179,10 @@ properties: description: phandle of the regulator that provides the supply voltage. + power-supply: + description: + phandle of the gpio regulator that provides the supply voltage. + required: - compatible - reg From patchwork Sun Aug 28 15:49:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Farber, Eliav" X-Patchwork-Id: 600956 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 0C30DECAAD2 for ; Sun, 28 Aug 2022 15:49:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229912AbiH1Pt3 (ORCPT ); Sun, 28 Aug 2022 11:49:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46688 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229527AbiH1Pt3 (ORCPT ); Sun, 28 Aug 2022 11:49:29 -0400 Received: from smtp-fw-80006.amazon.com (smtp-fw-80006.amazon.com [99.78.197.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 53B7D32EDC; Sun, 28 Aug 2022 08:49:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1661701768; x=1693237768; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=o1iCKQTfAzwbHxPpDHXTrrf28wLDUKTFm7EouUfzMlw=; b=U+bDiffVivwcqudIMQrzi4KE1HzSf+Z01akknDuFVptd2oFbYjGj4BfR 38gUZU+YVr5WCDqW7csSS/wtqsNZBJ8R5rK9HYgU3h5atWHjV6EIuEyV8 7Vj8AchWhmJtJMDn0XrXJ3Kf9m6ZnSNwfJ/pyC8aPzZsBu+NQWW9MMw87 0=; X-IronPort-AV: E=Sophos;i="5.93,270,1654560000"; d="scan'208";a="124085810" Received: from pdx4-co-svc-p1-lb2-vlan2.amazon.com (HELO email-inbound-relay-pdx-2a-6fd66c4a.us-west-2.amazon.com) ([10.25.36.210]) by smtp-border-fw-80006.pdx80.corp.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Aug 2022 15:49:12 +0000 Received: from EX13MTAUEB001.ant.amazon.com (pdx1-ws-svc-p6-lb9-vlan2.pdx.amazon.com [10.236.137.194]) by email-inbound-relay-pdx-2a-6fd66c4a.us-west-2.amazon.com (Postfix) with ESMTPS id F020981652; Sun, 28 Aug 2022 15:49:10 +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; Sun, 28 Aug 2022 15:49:05 +0000 Received: from EX13MTAUEA001.ant.amazon.com (10.43.61.82) by EX13D08UEB003.ant.amazon.com (10.43.60.11) with Microsoft SMTP Server (TLS) id 15.0.1497.38; Sun, 28 Aug 2022 15:49:05 +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; Sun, 28 Aug 2022 15:49:05 +0000 Received: by dev-dsk-farbere-1a-46ecabed.eu-west-1.amazon.com (Postfix, from userid 14301484) id DE95D4CA7; Sun, 28 Aug 2022 15:49:04 +0000 (UTC) From: Eliav Farber To: , , , , , , , CC: , , , , , , , , , , , , Subject: [PATCH v3 2/2] eeprom: at24: add support for power-supply control Date: Sun, 28 Aug 2022 15:49:04 +0000 Message-ID: <20220828154904.20477-3-farbere@amazon.com> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220828154904.20477-1-farbere@amazon.com> References: <20220828154904.20477-1-farbere@amazon.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org 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 --- V2 -> V3: Apply on top of v6.0-rc1 drivers/misc/eeprom/at24.c | 40 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c index 633e1cf08d6e..97f16c361474 100644 --- a/drivers/misc/eeprom/at24.c +++ b/drivers/misc/eeprom/at24.c @@ -87,6 +87,8 @@ struct at24_data { struct regulator *vcc_reg; void (*read_post)(unsigned int off, char *buf, size_t count); + struct regulator *supply; + /* * Some chips tie up multiple I2C addresses; dummy devices reserve * them for us. @@ -581,6 +583,13 @@ static unsigned int at24_get_offset_adj(u8 flags, unsigned int byte_len) } } +static void devm_at24_regulator_disable(void *data) +{ + struct at24_data *at24 = data; + + regulator_disable(at24->supply); +} + static int at24_probe(struct i2c_client *client) { struct regmap_config regmap_config = { }; @@ -681,6 +690,37 @@ static int at24_probe(struct i2c_client *client) if (!at24) return -ENOMEM; + at24->supply = devm_regulator_get_optional(dev, "power"); + if (IS_ERR(at24->supply)) { + err = PTR_ERR(at24->supply); + if (err == -ENODEV) + at24->supply = NULL; + else + return dev_err_probe(dev, err, + "failed to get power-supply regulator\n"); + } + + if (at24->supply) { + err = regulator_enable(at24->supply); + if (err < 0) { + dev_err(dev, + "failed to enable power-supply regulator: %d\n", + err); + return err; + } + + err = devm_add_action_or_reset(dev, devm_at24_regulator_disable, + at24); + if (err < 0) { + dev_err(dev, + "failed to add action to disable power-supply regulator: %d\n", + err); + return err; + } + + usleep_range(2000, 3000); + } + mutex_init(&at24->lock); at24->byte_len = byte_len; at24->page_size = page_size;