From: Eliav Farber <farbere@amazon.com>
To: <brgl@bgdev.pl>, <robh+dt@kernel.org>, <mark.rutland@arm.com>,
<arnd@arndb.de>, <gregkh@linuxfoundation.org>,
<linux-i2c@vger.kernel.org>, <devicetree@vger.kernel.org>,
<linux-kernel@vger.kernel.org>
Cc: <farbere@amazon.com>, <talel@amazon.com>, <hhhawa@amazon.com>,
<jonnyc@amazon.com>, <hanochu@amazon.com>, <ronenk@amazon.com>,
<itamark@amazon.com>, <shellykz@amazon.com>, <shorer@amazon.com>,
<amitlavi@amazon.com>, <almogbs@amazon.com>, <dkl@amazon.com>,
<dwmw@amazon.co.uk>
Subject: [PATCH v3 2/2] eeprom: at24: add support for power-supply control
Date: Sun, 28 Aug 2022 15:49:04 +0000 [thread overview]
Message-ID: <20220828154904.20477-3-farbere@amazon.com> (raw)
In-Reply-To: <20220828154904.20477-1-farbere@amazon.com>
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@amazon.com>
---
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;
--
2.37.1
next prev parent reply other threads:[~2022-08-28 15:49 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-28 15:49 [PATCH v3 0/2] add power-supply control to enable eeprom usage Eliav Farber
2022-08-28 15:49 ` [PATCH v3 1/2] dt-bindings: at24: add new optional power-supply property Eliav Farber
2022-08-29 18:55 ` Rob Herring
2022-08-28 15:49 ` Eliav Farber [this message]
2022-08-31 13:00 ` [PATCH v3 0/2] add power-supply control to enable eeprom usage Bartosz Golaszewski
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220828154904.20477-3-farbere@amazon.com \
--to=farbere@amazon.com \
--cc=almogbs@amazon.com \
--cc=amitlavi@amazon.com \
--cc=arnd@arndb.de \
--cc=brgl@bgdev.pl \
--cc=devicetree@vger.kernel.org \
--cc=dkl@amazon.com \
--cc=dwmw@amazon.co.uk \
--cc=gregkh@linuxfoundation.org \
--cc=hanochu@amazon.com \
--cc=hhhawa@amazon.com \
--cc=itamark@amazon.com \
--cc=jonnyc@amazon.com \
--cc=linux-i2c@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=robh+dt@kernel.org \
--cc=ronenk@amazon.com \
--cc=shellykz@amazon.com \
--cc=shorer@amazon.com \
--cc=talel@amazon.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).