Commit be715343 authored by Masahiro Yamada's avatar Masahiro Yamada Committed by Linus Walleij

gpio: of: drop needless gpio_chip look-up in of_parse_own_gpio()

This function is doing more complicated than needed.  The caller of
this function, of_gpiochip_scan_gpios() already knows the pointer to
the gpio_chip.  It can pass it to of_parse_own_gpio() instead of
looking up the gpio_chip by gpiochip_find().
Signed-off-by: default avatarMasahiro Yamada <yamada.masahiro@socionext.com>
Signed-off-by: default avatarLinus Walleij <linus.walleij@linaro.org>
parent 3f9547e1
...@@ -121,6 +121,7 @@ EXPORT_SYMBOL(of_get_named_gpio_flags); ...@@ -121,6 +121,7 @@ EXPORT_SYMBOL(of_get_named_gpio_flags);
/** /**
* of_parse_own_gpio() - Get a GPIO hog descriptor, names and flags for GPIO API * of_parse_own_gpio() - Get a GPIO hog descriptor, names and flags for GPIO API
* @np: device node to get GPIO from * @np: device node to get GPIO from
* @chip: GPIO chip whose hog is parsed
* @name: GPIO line name * @name: GPIO line name
* @lflags: gpio_lookup_flags - returned from of_find_gpio() or * @lflags: gpio_lookup_flags - returned from of_find_gpio() or
* of_parse_own_gpio() * of_parse_own_gpio()
...@@ -130,19 +131,19 @@ EXPORT_SYMBOL(of_get_named_gpio_flags); ...@@ -130,19 +131,19 @@ EXPORT_SYMBOL(of_get_named_gpio_flags);
* value on the error condition. * value on the error condition.
*/ */
static struct gpio_desc *of_parse_own_gpio(struct device_node *np, static struct gpio_desc *of_parse_own_gpio(struct device_node *np,
struct gpio_chip *chip,
const char **name, const char **name,
enum gpio_lookup_flags *lflags, enum gpio_lookup_flags *lflags,
enum gpiod_flags *dflags) enum gpiod_flags *dflags)
{ {
struct device_node *chip_np; struct device_node *chip_np;
enum of_gpio_flags xlate_flags; enum of_gpio_flags xlate_flags;
struct gg_data gg_data = { struct of_phandle_args gpiospec;
.flags = &xlate_flags, struct gpio_desc *desc;
};
u32 tmp; u32 tmp;
int ret; int ret;
chip_np = np->parent; chip_np = chip->of_node;
if (!chip_np) if (!chip_np)
return ERR_PTR(-EINVAL); return ERR_PTR(-EINVAL);
...@@ -154,23 +155,23 @@ static struct gpio_desc *of_parse_own_gpio(struct device_node *np, ...@@ -154,23 +155,23 @@ static struct gpio_desc *of_parse_own_gpio(struct device_node *np,
if (ret) if (ret)
return ERR_PTR(ret); return ERR_PTR(ret);
if (tmp > MAX_PHANDLE_ARGS) if (tmp > MAX_PHANDLE_ARGS || tmp != chip->of_gpio_n_cells)
return ERR_PTR(-EINVAL); return ERR_PTR(-EINVAL);
gg_data.gpiospec.args_count = tmp; gpiospec.np = chip_np;
gg_data.gpiospec.np = chip_np; gpiospec.args_count = tmp;
ret = of_property_read_u32_array(np, "gpios", gg_data.gpiospec.args,
tmp); ret = of_property_read_u32_array(np, "gpios", gpiospec.args, tmp);
if (ret) if (ret)
return ERR_PTR(ret); return ERR_PTR(ret);
gpiochip_find(&gg_data, of_gpiochip_find_and_xlate); ret = chip->of_xlate(chip, &gpiospec, &xlate_flags);
if (!gg_data.out_gpio) { if (ret < 0)
if (np->parent == np) return ERR_PTR(ret);
return ERR_PTR(-ENXIO);
else desc = gpiochip_get_desc(chip, ret);
return ERR_PTR(-EINVAL); if (IS_ERR(desc))
} return desc;
if (xlate_flags & OF_GPIO_ACTIVE_LOW) if (xlate_flags & OF_GPIO_ACTIVE_LOW)
*lflags |= GPIO_ACTIVE_LOW; *lflags |= GPIO_ACTIVE_LOW;
...@@ -183,14 +184,14 @@ static struct gpio_desc *of_parse_own_gpio(struct device_node *np, ...@@ -183,14 +184,14 @@ static struct gpio_desc *of_parse_own_gpio(struct device_node *np,
*dflags |= GPIOD_OUT_HIGH; *dflags |= GPIOD_OUT_HIGH;
else { else {
pr_warn("GPIO line %d (%s): no hogging state specified, bailing out\n", pr_warn("GPIO line %d (%s): no hogging state specified, bailing out\n",
desc_to_gpio(gg_data.out_gpio), np->name); desc_to_gpio(desc), np->name);
return ERR_PTR(-EINVAL); return ERR_PTR(-EINVAL);
} }
if (name && of_property_read_string(np, "line-name", name)) if (name && of_property_read_string(np, "line-name", name))
*name = np->name; *name = np->name;
return gg_data.out_gpio; return desc;
} }
/** /**
...@@ -259,7 +260,7 @@ static int of_gpiochip_scan_gpios(struct gpio_chip *chip) ...@@ -259,7 +260,7 @@ static int of_gpiochip_scan_gpios(struct gpio_chip *chip)
if (!of_property_read_bool(np, "gpio-hog")) if (!of_property_read_bool(np, "gpio-hog"))
continue; continue;
desc = of_parse_own_gpio(np, &name, &lflags, &dflags); desc = of_parse_own_gpio(np, chip, &name, &lflags, &dflags);
if (IS_ERR(desc)) if (IS_ERR(desc))
continue; continue;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment