mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 3/3] gpio: pca953x: add optional support for regulator and reset GPIO
Date: Tue,  7 Mar 2023 11:23:20 +0100	[thread overview]
Message-ID: <20230307102320.2084684-3-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20230307102320.2084684-1-a.fatoum@pengutronix.de>

Traditionally, pca953x have a Power-On Reset mechanism that activates
once supply voltage rises over threshold. Newer chips additionally
feature a reset input. Add support for both. To not break existing
boards, we will ignore failure to claim GPIO or regulator, even
if it's just probe deferral. Boards wanting to make use of the newly
parsed DT properties should enable deep probe.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 drivers/gpio/gpio-pca953x.c | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)

diff --git a/drivers/gpio/gpio-pca953x.c b/drivers/gpio/gpio-pca953x.c
index 2a1822ef3bcc..2fafa0325663 100644
--- a/drivers/gpio/gpio-pca953x.c
+++ b/drivers/gpio/gpio-pca953x.c
@@ -12,6 +12,8 @@
 #include <common.h>
 #include <malloc.h>
 #include <driver.h>
+#include <gpiod.h>
+#include <regulator.h>
 #include <xfuncs.h>
 #include <errno.h>
 #include <i2c/i2c.h>
@@ -414,7 +416,8 @@ static int pca953x_probe(struct device *dev)
 	unsigned long driver_data;
 	struct pca953x_platform_data *pdata;
 	struct pca953x_chip *chip;
-	int ret;
+	struct regulator *reg;
+	int reset_gpio, ret;
 	u32 invert = 0;
 
 	chip = xzalloc(sizeof(struct pca953x_chip));
@@ -437,6 +440,20 @@ static int pca953x_probe(struct device *dev)
 
 	chip->client = client;
 
+	reset_gpio = gpiod_get(dev, "reset", GPIOD_OUT_LOW);
+	if (!gpio_is_valid(reset_gpio) && reset_gpio != -ENOENT)
+		dev_warn(dev, "Failed to get 'reset' GPIO (ignored)\n");
+
+	reg = regulator_get(dev, "vcc");
+	if (IS_ERR(reg)) {
+		dev_warn(dev, "Failed to get 'vcc' regulator (ignored).\n");
+		reg = NULL;
+	}
+
+	ret = regulator_enable(reg);
+	if (ret)
+		return dev_err_probe(dev, ret, "failed to enable register\n");
+
 	chip->chip_type = driver_data & (PCA953X_TYPE | PCA957X_TYPE);
 
 	/* initialize cached registers from their original values.
-- 
2.30.2




  parent reply	other threads:[~2023-03-07 10:24 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-07 10:23 [PATCH 1/3] gpio: gpioinfo: use dev_name to get device name Ahmad Fatoum
2023-03-07 10:23 ` [PATCH 2/3] gpio: pca953x: sync DT compatibles with Linux Ahmad Fatoum
2023-03-07 10:23 ` Ahmad Fatoum [this message]
2023-03-09 10:51 ` [PATCH 1/3] gpio: gpioinfo: use dev_name to get device name Sascha Hauer

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=20230307102320.2084684-3-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /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