* [PATCH v2 3/3] gpio: at91: Implement ops get_flags
@ 2024-10-18 21:57 Zixun LI
2024-11-12 13:27 ` Eugen Hristev
0 siblings, 1 reply; 3+ messages in thread
From: Zixun LI @ 2024-10-18 21:57 UTC (permalink / raw)
To: Simon Glass; +Cc: u-boot, Zixun LI
Add ops get_dir_flags() to read status from GPIO registers.
Signed-off-by: Zixun LI <admin@hifiphile.com>
---
Changes in v2:
- Fix pullup read polarity
---
drivers/gpio/at91_gpio.c | 45 ++++++++++++++++++++++++++++++++++++++++
1 file changed, 45 insertions(+)
diff --git a/drivers/gpio/at91_gpio.c b/drivers/gpio/at91_gpio.c
index 7828f9b447..c44e02cd90 100644
--- a/drivers/gpio/at91_gpio.c
+++ b/drivers/gpio/at91_gpio.c
@@ -240,6 +240,24 @@ static void at91_set_port_multi_drive(struct at91_port *at91_port, int offset, i
else
writel(mask, &at91_port->mddr);
}
+
+static bool at91_get_port_multi_drive(struct at91_port *at91_port, int offset)
+{
+ u32 mask, val;
+
+ mask = 1 << offset;
+ val = readl(&at91_port->mdsr);
+ return val & mask;
+}
+
+static bool at91_get_port_pullup(struct at91_port *at91_port, int offset)
+{
+ u32 mask, val;
+
+ mask = 1 << offset;
+ val = readl(&at91_port->pusr);
+ return !(val & mask);
+}
#endif
static void at91_set_port_input(struct at91_port *at91_port, int offset,
@@ -608,6 +626,32 @@ static int at91_gpio_set_flags(struct udevice *dev, unsigned int offset,
return 0;
}
+static int at91_gpio_get_flags(struct udevice *dev, unsigned int offset,
+ ulong *flagsp)
+{
+ struct at91_port_priv *port = dev_get_priv(dev);
+ ulong dir_flags = 0;
+
+ if (at91_get_port_output(port->regs, offset)) {
+ dir_flags |= GPIOD_IS_OUT;
+
+ if (at91_get_port_multi_drive(port->regs, offset))
+ dir_flags |= GPIOD_OPEN_DRAIN;
+
+ if (at91_get_port_value(port->regs, offset))
+ dir_flags |= GPIOD_IS_OUT_ACTIVE;
+ } else {
+ dir_flags |= GPIOD_IS_IN;
+ }
+
+ if (at91_get_port_pullup(port->regs, offset))
+ dir_flags |= GPIOD_PULL_UP;
+
+ *flagsp = dir_flags;
+
+ return 0;
+}
+
static const char *at91_get_bank_name(uint32_t base_addr)
{
switch (base_addr) {
@@ -637,6 +681,7 @@ static const struct dm_gpio_ops gpio_at91_ops = {
.set_value = at91_gpio_set_value,
.get_function = at91_gpio_get_function,
.set_flags = at91_gpio_set_flags,
+ .get_flags = at91_gpio_get_flags,
};
static int at91_gpio_probe(struct udevice *dev)
--
2.46.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2 3/3] gpio: at91: Implement ops get_flags
2024-10-18 21:57 [PATCH v2 3/3] gpio: at91: Implement ops get_flags Zixun LI
@ 2024-11-12 13:27 ` Eugen Hristev
2024-11-12 16:08 ` Zixun LI
0 siblings, 1 reply; 3+ messages in thread
From: Eugen Hristev @ 2024-11-12 13:27 UTC (permalink / raw)
To: Zixun LI; +Cc: u-boot, Simon Glass
On 10/19/24 00:57, Zixun LI wrote:
> Add ops get_dir_flags() to read status from GPIO registers.
>
> Signed-off-by: Zixun LI <admin@hifiphile.com>
>
> ---
> Changes in v2:
> - Fix pullup read polarity
> ---
> drivers/gpio/at91_gpio.c | 45 ++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 45 insertions(+)
>
> diff --git a/drivers/gpio/at91_gpio.c b/drivers/gpio/at91_gpio.c
> index 7828f9b447..c44e02cd90 100644
> --- a/drivers/gpio/at91_gpio.c
> +++ b/drivers/gpio/at91_gpio.c
> @@ -240,6 +240,24 @@ static void at91_set_port_multi_drive(struct at91_port *at91_port, int offset, i
> else
> writel(mask, &at91_port->mddr);
> }
> +
> +static bool at91_get_port_multi_drive(struct at91_port *at91_port, int offset)
> +{
> + u32 mask, val;
> +
> + mask = 1 << offset;
> + val = readl(&at91_port->mdsr);
> + return val & mask;
Use clamp (!!) to turn this into a bool.
> +}
> +
> +static bool at91_get_port_pullup(struct at91_port *at91_port, int offset)
> +{
> + u32 mask, val;
> +
> + mask = 1 << offset;
> + val = readl(&at91_port->pusr);
> + return !(val & mask);
> +}
> #endif
>
> static void at91_set_port_input(struct at91_port *at91_port, int offset,
> @@ -608,6 +626,32 @@ static int at91_gpio_set_flags(struct udevice *dev, unsigned int offset,
> return 0;
> }
>
> +static int at91_gpio_get_flags(struct udevice *dev, unsigned int offset,
> + ulong *flagsp)
> +{
> + struct at91_port_priv *port = dev_get_priv(dev);
> + ulong dir_flags = 0;
> +
> + if (at91_get_port_output(port->regs, offset)) {
> + dir_flags |= GPIOD_IS_OUT;
> +
> + if (at91_get_port_multi_drive(port->regs, offset))
> + dir_flags |= GPIOD_OPEN_DRAIN;
> +
> + if (at91_get_port_value(port->regs, offset))
> + dir_flags |= GPIOD_IS_OUT_ACTIVE;
> + } else {
> + dir_flags |= GPIOD_IS_IN;
> + }
> +
> + if (at91_get_port_pullup(port->regs, offset))
> + dir_flags |= GPIOD_PULL_UP;
> +
> + *flagsp = dir_flags;
> +
> + return 0;
> +}
> +
> static const char *at91_get_bank_name(uint32_t base_addr)
> {
> switch (base_addr) {
> @@ -637,6 +681,7 @@ static const struct dm_gpio_ops gpio_at91_ops = {
> .set_value = at91_gpio_set_value,
> .get_function = at91_gpio_get_function,
> .set_flags = at91_gpio_set_flags,
> + .get_flags = at91_gpio_get_flags,
> };
>
> static int at91_gpio_probe(struct udevice *dev)
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2 3/3] gpio: at91: Implement ops get_flags
2024-11-12 13:27 ` Eugen Hristev
@ 2024-11-12 16:08 ` Zixun LI
0 siblings, 0 replies; 3+ messages in thread
From: Zixun LI @ 2024-11-12 16:08 UTC (permalink / raw)
To: Eugen Hristev; +Cc: u-boot, Simon Glass
Hi,
On Tue, Nov 12, 2024 at 2:27 PM Eugen Hristev <eugen.hristev@linaro.org> wrote:
>
> Use clamp (!!) to turn this into a bool.
>
Should I also fix the existing function at91_get_port_output() ?
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-11-12 18:42 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-18 21:57 [PATCH v2 3/3] gpio: at91: Implement ops get_flags Zixun LI
2024-11-12 13:27 ` Eugen Hristev
2024-11-12 16:08 ` Zixun LI
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox