lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20220822105830.22790-3-farbere@amazon.com>
Date:   Mon, 22 Aug 2022 10:58:30 +0000
From:   Eliav Farber <farbere@...zon.com>
To:     <brgl@...ev.pl>, <robh+dt@...nel.org>, <mark.rutland@....com>,
        <arnd@...db.de>, <gregkh@...uxfoundation.org>,
        <linux-i2c@...r.kernel.org>, <devicetree@...r.kernel.org>,
        <linux-kernel@...r.kernel.org>
CC:     <farbere@...zon.com>, <talel@...zon.com>, <hhhawa@...zon.com>,
        <jonnyc@...zon.com>, <hanochu@...zon.com>, <ronenk@...zon.com>,
        <itamark@...zon.com>, <shellykz@...zon.com>, <shorer@...zon.com>,
        <amitlavi@...zon.com>, <almogbs@...zon.com>, <dkl@...zon.com>,
        <dwmw@...zon.co.uk>
Subject: [PATCH v2 2/2] eeprom: at24: add support for power-supply control

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 <farbere@...zon.com>
---
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 <linux/platform_data/at24.h>
 #include <linux/pm_runtime.h>
 #include <linux/gpio/consumer.h>
+#include <linux/regulator/consumer.h>
 
 /*
  * I2C EEPROMs from most vendors are inexpensive and mostly interchangeable.
@@ -78,6 +79,8 @@ struct at24_data {
 
 	struct gpio_desc *wp_gpio;
 
+	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, 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 = { };
@@ -674,6 +684,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 adction to disable power-supply regulator: %d\n",
+				err);
+			return err;
+		}
+
+		usleep_range(2000, 3000);
+	}
+
 	mutex_init(&at24->lock);
 	at24->byte_len = pdata.byte_len;
 	at24->page_size = pdata.page_size;
-- 
2.37.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ