mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-04 10:40:15 +02:00 
			
		
		
		
	gpio: of: remove of_gpiochip_and_xlate() and struct gg_data
The usage of gpiochip_find(&gg_data, of_gpiochip_and_xlate) is odd. Usually gpiochip_find() is used to find a gpio_chip. Here, however, the return value from gpiochip_find() is just discarded. Instead, gpiochip_find(&gg_data, of_gpiochip_and_xlate) is called for the side-effect of the match function. The match function, of_gpiochip_find_and_xlate(), fills the given struct gg_data, but a match function should be simply called to judge the matching. This commit fixes this distortion and makes the code more readable. Remove of_gpiochip_find_and_xlate() and struct gg_data. Instead, this adds a very simple helper function of_find_gpiochip_by_node(). Now, of_get_named_gpiod_flags() is implemented more straight-forward. Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
This commit is contained in:
		
							parent
							
								
									1020dfd15b
								
							
						
					
					
						commit
						762c2e46c0
					
				
					 1 changed files with 35 additions and 46 deletions
				
			
		| 
						 | 
					@ -26,38 +26,14 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "gpiolib.h"
 | 
					#include "gpiolib.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* Private data structure for of_gpiochip_find_and_xlate */
 | 
					static int of_gpiochip_match_node(struct gpio_chip *chip, void *data)
 | 
				
			||||||
struct gg_data {
 | 
					 | 
				
			||||||
	enum of_gpio_flags *flags;
 | 
					 | 
				
			||||||
	struct of_phandle_args gpiospec;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	struct gpio_desc *out_gpio;
 | 
					 | 
				
			||||||
};
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* Private function for resolving node pointer to gpio_chip */
 | 
					 | 
				
			||||||
static int of_gpiochip_find_and_xlate(struct gpio_chip *gc, void *data)
 | 
					 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	struct gg_data *gg_data = data;
 | 
						return chip->gpiodev->dev.of_node == data;
 | 
				
			||||||
	int ret;
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if ((gc->of_node != gg_data->gpiospec.np) ||
 | 
					static struct gpio_chip *of_find_gpiochip_by_node(struct device_node *np)
 | 
				
			||||||
	    (gc->of_gpio_n_cells != gg_data->gpiospec.args_count) ||
 | 
					{
 | 
				
			||||||
	    (!gc->of_xlate))
 | 
						return gpiochip_find(np, of_gpiochip_match_node);
 | 
				
			||||||
		return false;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	ret = gc->of_xlate(gc, &gg_data->gpiospec, gg_data->flags);
 | 
					 | 
				
			||||||
	if (ret < 0) {
 | 
					 | 
				
			||||||
		/* We've found a gpio chip, but the translation failed.
 | 
					 | 
				
			||||||
		 * Store translation error in out_gpio.
 | 
					 | 
				
			||||||
		 * Return false to keep looking, as more than one gpio chip
 | 
					 | 
				
			||||||
		 * could be registered per of-node.
 | 
					 | 
				
			||||||
		 */
 | 
					 | 
				
			||||||
		gg_data->out_gpio = ERR_PTR(ret);
 | 
					 | 
				
			||||||
		return false;
 | 
					 | 
				
			||||||
	 }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	gg_data->out_gpio = gpiochip_get_desc(gc, ret);
 | 
					 | 
				
			||||||
	return true;
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
| 
						 | 
					@ -74,34 +50,47 @@ static int of_gpiochip_find_and_xlate(struct gpio_chip *gc, void *data)
 | 
				
			||||||
struct gpio_desc *of_get_named_gpiod_flags(struct device_node *np,
 | 
					struct gpio_desc *of_get_named_gpiod_flags(struct device_node *np,
 | 
				
			||||||
		     const char *propname, int index, enum of_gpio_flags *flags)
 | 
							     const char *propname, int index, enum of_gpio_flags *flags)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	/* Return -EPROBE_DEFER to support probe() functions to be called
 | 
						struct of_phandle_args gpiospec;
 | 
				
			||||||
	 * later when the GPIO actually becomes available
 | 
						struct gpio_chip *chip;
 | 
				
			||||||
	 */
 | 
						struct gpio_desc *desc;
 | 
				
			||||||
	struct gg_data gg_data = {
 | 
					 | 
				
			||||||
		.flags = flags,
 | 
					 | 
				
			||||||
		.out_gpio = ERR_PTR(-EPROBE_DEFER)
 | 
					 | 
				
			||||||
	};
 | 
					 | 
				
			||||||
	int ret;
 | 
						int ret;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* .of_xlate might decide to not fill in the flags, so clear it. */
 | 
					 | 
				
			||||||
	if (flags)
 | 
					 | 
				
			||||||
		*flags = 0;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	ret = of_parse_phandle_with_args(np, propname, "#gpio-cells", index,
 | 
						ret = of_parse_phandle_with_args(np, propname, "#gpio-cells", index,
 | 
				
			||||||
					 &gg_data.gpiospec);
 | 
										 &gpiospec);
 | 
				
			||||||
	if (ret) {
 | 
						if (ret) {
 | 
				
			||||||
		pr_debug("%s: can't parse '%s' property of node '%s[%d]'\n",
 | 
							pr_debug("%s: can't parse '%s' property of node '%s[%d]'\n",
 | 
				
			||||||
			__func__, propname, np->full_name, index);
 | 
								__func__, propname, np->full_name, index);
 | 
				
			||||||
		return ERR_PTR(ret);
 | 
							return ERR_PTR(ret);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	gpiochip_find(&gg_data, of_gpiochip_find_and_xlate);
 | 
						chip = of_find_gpiochip_by_node(gpiospec.np);
 | 
				
			||||||
 | 
						if (!chip) {
 | 
				
			||||||
 | 
							desc = ERR_PTR(-EPROBE_DEFER);
 | 
				
			||||||
 | 
							goto out;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if (chip->of_gpio_n_cells != gpiospec.args_count) {
 | 
				
			||||||
 | 
							desc = ERR_PTR(-EINVAL);
 | 
				
			||||||
 | 
							goto out;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						ret = chip->of_xlate(chip, &gpiospec, flags);
 | 
				
			||||||
 | 
						if (ret < 0) {
 | 
				
			||||||
 | 
							desc = ERR_PTR(ret);
 | 
				
			||||||
 | 
							goto out;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						desc = gpiochip_get_desc(chip, ret);
 | 
				
			||||||
 | 
						if (IS_ERR(desc))
 | 
				
			||||||
 | 
							goto out;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	of_node_put(gg_data.gpiospec.np);
 | 
					 | 
				
			||||||
	pr_debug("%s: parsed '%s' property of node '%s[%d]' - status (%d)\n",
 | 
						pr_debug("%s: parsed '%s' property of node '%s[%d]' - status (%d)\n",
 | 
				
			||||||
		 __func__, propname, np->full_name, index,
 | 
							 __func__, propname, np->full_name, index,
 | 
				
			||||||
		 PTR_ERR_OR_ZERO(gg_data.out_gpio));
 | 
							 PTR_ERR_OR_ZERO(desc));
 | 
				
			||||||
	return gg_data.out_gpio;
 | 
					
 | 
				
			||||||
 | 
					out:
 | 
				
			||||||
 | 
						of_node_put(gpiospec.np);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return desc;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int of_get_named_gpio_flags(struct device_node *np, const char *list_name,
 | 
					int of_get_named_gpio_flags(struct device_node *np, const char *list_name,
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue