From: Zixun LI <admin@hifiphile.com>
To: Simon Glass <sjg@chromium.org>
Cc: u-boot@lists.denx.de, Zixun LI <admin@hifiphile.com>
Subject: [PATCH 2/3] gpio: at91: Implement ops set_flags
Date: Fri, 18 Oct 2024 22:27:14 +0200 [thread overview]
Message-ID: <20241018202715.283011-2-admin@hifiphile.com> (raw)
In-Reply-To: <20241018202715.283011-1-admin@hifiphile.com>
Support GPIO configuration with following flags:
- in, out, out_active
- open_drain, pull_up
Signed-off-by: Zixun LI <admin@hifiphile.com>
---
drivers/gpio/at91_gpio.c | 41 ++++++++++++++++++++++++++++++++++++++++
1 file changed, 41 insertions(+)
diff --git a/drivers/gpio/at91_gpio.c b/drivers/gpio/at91_gpio.c
index 64a6e8a4a5..7828f9b447 100644
--- a/drivers/gpio/at91_gpio.c
+++ b/drivers/gpio/at91_gpio.c
@@ -229,6 +229,17 @@ static bool at91_get_port_pio(struct at91_port *at91_port, int offset)
val = readl(&at91_port->psr);
return val & mask;
}
+
+static void at91_set_port_multi_drive(struct at91_port *at91_port, int offset, int is_on)
+{
+ u32 mask;
+
+ mask = 1 << offset;
+ if (is_on)
+ writel(mask, &at91_port->mder);
+ else
+ writel(mask, &at91_port->mddr);
+}
#endif
static void at91_set_port_input(struct at91_port *at91_port, int offset,
@@ -568,6 +579,35 @@ static int at91_gpio_get_function(struct udevice *dev, unsigned offset)
return GPIOF_INPUT;
}
+static int at91_gpio_set_flags(struct udevice *dev, unsigned int offset,
+ ulong flags)
+{
+ struct at91_port_priv *port = dev_get_priv(dev);
+ ulong supported_mask;
+
+ supported_mask = GPIOD_OPEN_DRAIN | GPIOD_MASK_DIR | GPIOD_PULL_UP;
+ if (flags & ~supported_mask)
+ return -EINVAL;
+
+ if (flags & GPIOD_IS_OUT) {
+ bool value = flags & GPIOD_IS_OUT_ACTIVE;
+
+ if (flags & GPIOD_OPEN_DRAIN)
+ at91_set_port_multi_drive(port->regs, offset, true);
+ else
+ at91_set_port_multi_drive(port->regs, offset, false);
+
+ at91_set_port_output(port->regs, offset, value);
+
+ } else if (flags & GPIOD_IS_IN) {
+ at91_set_port_input(port->regs, offset, false);
+ }
+ if (flags & GPIOD_PULL_UP)
+ at91_set_port_pullup(port->regs, offset, true);
+
+ return 0;
+}
+
static const char *at91_get_bank_name(uint32_t base_addr)
{
switch (base_addr) {
@@ -596,6 +636,7 @@ static const struct dm_gpio_ops gpio_at91_ops = {
.get_value = at91_gpio_get_value,
.set_value = at91_gpio_set_value,
.get_function = at91_gpio_get_function,
+ .set_flags = at91_gpio_set_flags,
};
static int at91_gpio_probe(struct udevice *dev)
--
2.46.2
next prev parent reply other threads:[~2024-10-18 20:46 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-18 20:27 [PATCH 1/3] gpio: at91: Implement GPIOF_FUNC in get_function() Zixun LI
2024-10-18 20:27 ` Zixun LI [this message]
2024-11-12 13:21 ` [PATCH 2/3] gpio: at91: Implement ops set_flags Eugen Hristev
2024-11-12 16:06 ` Zixun LI
2024-10-18 20:27 ` [PATCH 3/3] gpio: at91: Implement ops get_flags Zixun LI
2024-11-12 13:13 ` [PATCH 1/3] gpio: at91: Implement GPIOF_FUNC in get_function() Eugen Hristev
2024-11-12 15:57 ` Zixun LI
2024-11-12 15:58 ` Eugen Hristev
2024-11-12 16:17 ` Zixun LI
2024-11-12 16:21 ` Eugen Hristev
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=20241018202715.283011-2-admin@hifiphile.com \
--to=admin@hifiphile.com \
--cc=sjg@chromium.org \
--cc=u-boot@lists.denx.de \
/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