[PATCH 07/10] gpiolib: introduce of_gpiochip_add to bundle all of functions

Ahmad Fatoum a.fatoum at pengutronix.de
Tue Jun 13 00:46:01 PDT 2023


On 02.06.23 09:49, Marco Felsch wrote:
> Introduce a common OF related function which does all the OF related
> part. This allow us to drop the santity checks and harmonizes the code
> with the linux kernel.
> 
> Signed-off-by: Marco Felsch <m.felsch at pengutronix.de>

Reviewed-by: Ahmad Fatoum <a.fatoum at pengutronix.de>

> ---
>  drivers/gpio/gpiolib.c | 32 ++++++++++++++++++--------------
>  1 file changed, 18 insertions(+), 14 deletions(-)
> 
> diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
> index 127cc60abd..d1087aa583 100644
> --- a/drivers/gpio/gpiolib.c
> +++ b/drivers/gpio/gpiolib.c
> @@ -517,9 +517,6 @@ static int of_gpiochip_scan_hogs(struct gpio_chip *chip)
>  	struct device_node *np;
>  	int ret, i;
>  
> -	if (!IS_ENABLED(CONFIG_OFDEVICE) || !chip->dev->of_node)
> -		return 0;
> -
>  	for_each_available_child_of_node(chip->dev->of_node, np) {
>  		if (!of_property_read_bool(np, "gpio-hog"))
>  			continue;
> @@ -550,15 +547,11 @@ static int of_gpiochip_scan_hogs(struct gpio_chip *chip)
>   */
>  static int of_gpiochip_set_names(struct gpio_chip *chip)
>  {
> +	struct device_node *np = dev_of_node(chip->dev);
>  	struct device *dev = chip->dev;
> -	struct device_node *np;
>  	const char **names;
>  	int ret, i, count;
>  
> -	np = dev_of_node(dev);
> -	if (!np)
> -		return 0;
> -
>  	count = of_property_count_strings(np, "gpio-line-names");
>  	if (count < 0)
>  		return 0;
> @@ -599,6 +592,22 @@ static int of_gpiochip_set_names(struct gpio_chip *chip)
>  	return 0;
>  }
>  
> +static int of_gpiochip_add(struct gpio_chip *chip)
> +{
> +	struct device_node *np;
> +	int ret;
> +
> +	np = dev_of_node(chip->dev);
> +	if (!np)
> +		return 0;
> +
> +	ret = of_gpiochip_set_names(chip);
> +	if (ret)
> +		return ret;
> +
> +	return of_gpiochip_scan_hogs(chip);
> +}
> +
>  #ifdef CONFIG_OFDEVICE
>  static const char *gpio_suffixes[] = {
>  	"gpios",
> @@ -660,7 +669,6 @@ int dev_gpiod_get_index(struct device *dev,
>  
>  int gpiochip_add(struct gpio_chip *chip)
>  {
> -	int ret;
>  	int i;
>  
>  	if (chip->base >= 0) {
> @@ -680,11 +688,7 @@ int gpiochip_add(struct gpio_chip *chip)
>  	for (i = chip->base; i < chip->base + chip->ngpio; i++)
>  		gpio_desc[i].chip = chip;
>  
> -	ret = of_gpiochip_set_names(chip);
> -	if (ret)
> -		return ret;
> -
> -	return of_gpiochip_scan_hogs(chip);
> +	return of_gpiochip_add(chip);
>  }
>  
>  void gpiochip_remove(struct gpio_chip *chip)

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |




More information about the barebox mailing list