2023-12-29 13:08:23

by Emil Renner Berthing

[permalink] [raw]
Subject: [PATCH v1] gpio: dwapb: Use generic request, free and set_config

This way GPIO will be denied on pins already claimed by other devices
and basic pin configuration (pull-up, pull-down etc.) can be done
through the userspace GPIO API.

Signed-off-by: Emil Renner Berthing <[email protected]>
---
drivers/gpio/gpio-dwapb.c | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/drivers/gpio/gpio-dwapb.c b/drivers/gpio/gpio-dwapb.c
index 8c59332429c2..798235791f70 100644
--- a/drivers/gpio/gpio-dwapb.c
+++ b/drivers/gpio/gpio-dwapb.c
@@ -416,11 +416,12 @@ static int dwapb_gpio_set_config(struct gpio_chip *gc, unsigned offset,
{
u32 debounce;

- if (pinconf_to_config_param(config) != PIN_CONFIG_INPUT_DEBOUNCE)
- return -ENOTSUPP;
+ if (pinconf_to_config_param(config) == PIN_CONFIG_INPUT_DEBOUNCE) {
+ debounce = pinconf_to_config_argument(config);
+ return dwapb_gpio_set_debounce(gc, offset, debounce);
+ }

- debounce = pinconf_to_config_argument(config);
- return dwapb_gpio_set_debounce(gc, offset, debounce);
+ return gpiochip_generic_config(gc, offset, config);
}

static int dwapb_convert_irqs(struct dwapb_gpio_port_irqchip *pirq,
@@ -530,10 +531,14 @@ static int dwapb_gpio_add_port(struct dwapb_gpio *gpio,
port->gc.fwnode = pp->fwnode;
port->gc.ngpio = pp->ngpio;
port->gc.base = pp->gpio_base;
+ port->gc.request = gpiochip_generic_request;
+ port->gc.free = gpiochip_generic_free;

/* Only port A support debounce */
if (pp->idx == 0)
port->gc.set_config = dwapb_gpio_set_config;
+ else
+ port->gc.set_config = gpiochip_generic_config;

/* Only port A can provide interrupts in all configurations of the IP */
if (pp->idx == 0)
--
2.43.0



2023-12-29 17:50:47

by Linus Walleij

[permalink] [raw]
Subject: Re: [PATCH v1] gpio: dwapb: Use generic request, free and set_config

On Fri, Dec 29, 2023 at 2:08 PM Emil Renner Berthing
<[email protected]> wrote:

> This way GPIO will be denied on pins already claimed by other devices
> and basic pin configuration (pull-up, pull-down etc.) can be done
> through the userspace GPIO API.
>
> Signed-off-by: Emil Renner Berthing <[email protected]>

This looks like a nice case of a pure pin control back-end for the
generic DW front-end GPIO.
Reviewed-by: Linus Walleij <[email protected]>

Yours,
Linus Walleij

2023-12-29 21:33:53

by Serge Semin

[permalink] [raw]
Subject: Re: [PATCH v1] gpio: dwapb: Use generic request, free and set_config

On Fri, Dec 29, 2023 at 02:07:51PM +0100, Emil Renner Berthing wrote:
> This way GPIO will be denied on pins already claimed by other devices
> and basic pin configuration (pull-up, pull-down etc.) can be done
> through the userspace GPIO API.
>
> Signed-off-by: Emil Renner Berthing <[email protected]>

LGTM. Thanks!
Acked-by: Serge Semin <[email protected]>

-Serge(y)

> ---
> drivers/gpio/gpio-dwapb.c | 13 +++++++++----
> 1 file changed, 9 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/gpio/gpio-dwapb.c b/drivers/gpio/gpio-dwapb.c
> index 8c59332429c2..798235791f70 100644
> --- a/drivers/gpio/gpio-dwapb.c
> +++ b/drivers/gpio/gpio-dwapb.c
> @@ -416,11 +416,12 @@ static int dwapb_gpio_set_config(struct gpio_chip *gc, unsigned offset,
> {
> u32 debounce;
>
> - if (pinconf_to_config_param(config) != PIN_CONFIG_INPUT_DEBOUNCE)
> - return -ENOTSUPP;
> + if (pinconf_to_config_param(config) == PIN_CONFIG_INPUT_DEBOUNCE) {
> + debounce = pinconf_to_config_argument(config);
> + return dwapb_gpio_set_debounce(gc, offset, debounce);
> + }
>
> - debounce = pinconf_to_config_argument(config);
> - return dwapb_gpio_set_debounce(gc, offset, debounce);
> + return gpiochip_generic_config(gc, offset, config);
> }
>
> static int dwapb_convert_irqs(struct dwapb_gpio_port_irqchip *pirq,
> @@ -530,10 +531,14 @@ static int dwapb_gpio_add_port(struct dwapb_gpio *gpio,
> port->gc.fwnode = pp->fwnode;
> port->gc.ngpio = pp->ngpio;
> port->gc.base = pp->gpio_base;
> + port->gc.request = gpiochip_generic_request;
> + port->gc.free = gpiochip_generic_free;
>
> /* Only port A support debounce */
> if (pp->idx == 0)
> port->gc.set_config = dwapb_gpio_set_config;
> + else
> + port->gc.set_config = gpiochip_generic_config;
>
> /* Only port A can provide interrupts in all configurations of the IP */
> if (pp->idx == 0)
> --
> 2.43.0
>

2024-01-02 13:17:13

by Bartosz Golaszewski

[permalink] [raw]
Subject: Re: [PATCH v1] gpio: dwapb: Use generic request, free and set_config

On Fri, Dec 29, 2023 at 2:08 PM Emil Renner Berthing
<[email protected]> wrote:
>
> This way GPIO will be denied on pins already claimed by other devices
> and basic pin configuration (pull-up, pull-down etc.) can be done
> through the userspace GPIO API.
>
> Signed-off-by: Emil Renner Berthing <[email protected]>
> ---

Applied, thanks!

Bart