[v1] gpio: dwapb: Use generic request, free and set_config

Message ID 20231229130758.84214-1-emil.renner.berthing@canonical.com
State New
Headers
Series [v1] gpio: dwapb: Use generic request, free and set_config |

Commit Message

Emil Renner Berthing Dec. 29, 2023, 1:07 p.m. UTC
  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 <emil.renner.berthing@canonical.com>
---
 drivers/gpio/gpio-dwapb.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)
  

Comments

Linus Walleij Dec. 29, 2023, 5:50 p.m. UTC | #1
On Fri, Dec 29, 2023 at 2:08 PM Emil Renner Berthing
<emil.renner.berthing@canonical.com> 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 <emil.renner.berthing@canonical.com>

This looks like a nice case of a pure pin control back-end for the
generic DW front-end GPIO.
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>

Yours,
Linus Walleij
  
Serge Semin Dec. 29, 2023, 9:33 p.m. UTC | #2
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 <emil.renner.berthing@canonical.com>

LGTM. Thanks!
Acked-by: Serge Semin <fancer.lancer@gmail.com>

-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
>
  
Bartosz Golaszewski Jan. 2, 2024, 1:16 p.m. UTC | #3
On Fri, Dec 29, 2023 at 2:08 PM Emil Renner Berthing
<emil.renner.berthing@canonical.com> 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 <emil.renner.berthing@canonical.com>
> ---

Applied, thanks!

Bart
  

Patch

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)