Commit 944f4b0a authored by Andy Shevchenko's avatar Andy Shevchenko Committed by Bartosz Golaszewski

gpiolib: Unify the checks on fwnode type

We have (historically) different approaches how we identify the type
of a given fwnode. Let's standardize them across the library code.
Signed-off-by: default avatarAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: default avatarLinus Walleij <linus.walleij@linaro.org>
Signed-off-by: default avatarBartosz Golaszewski <bgolaszewski@baylibre.com>
parent 67196fea
...@@ -3684,11 +3684,12 @@ EXPORT_SYMBOL_GPL(fwnode_gpiod_get_index); ...@@ -3684,11 +3684,12 @@ EXPORT_SYMBOL_GPL(fwnode_gpiod_get_index);
*/ */
int gpiod_count(struct device *dev, const char *con_id) int gpiod_count(struct device *dev, const char *con_id)
{ {
const struct fwnode_handle *fwnode = dev ? dev_fwnode(dev) : NULL;
int count = -ENOENT; int count = -ENOENT;
if (IS_ENABLED(CONFIG_OF) && dev && dev->of_node) if (is_of_node(fwnode))
count = of_gpio_get_count(dev, con_id); count = of_gpio_get_count(dev, con_id);
else if (IS_ENABLED(CONFIG_ACPI) && dev && ACPI_HANDLE(dev)) else if (is_acpi_node(fwnode))
count = acpi_gpio_count(dev, con_id); count = acpi_gpio_count(dev, con_id);
if (count < 0) if (count < 0)
...@@ -3826,18 +3827,17 @@ struct gpio_desc *__must_check gpiod_get_index(struct device *dev, ...@@ -3826,18 +3827,17 @@ struct gpio_desc *__must_check gpiod_get_index(struct device *dev,
int ret; int ret;
/* Maybe we have a device name, maybe not */ /* Maybe we have a device name, maybe not */
const char *devname = dev ? dev_name(dev) : "?"; const char *devname = dev ? dev_name(dev) : "?";
const struct fwnode_handle *fwnode = dev ? dev_fwnode(dev) : NULL;
dev_dbg(dev, "GPIO lookup for consumer %s\n", con_id); dev_dbg(dev, "GPIO lookup for consumer %s\n", con_id);
if (dev) { /* Using device tree? */
/* Using device tree? */ if (is_of_node(fwnode)) {
if (IS_ENABLED(CONFIG_OF) && dev->of_node) { dev_dbg(dev, "using device tree for GPIO lookup\n");
dev_dbg(dev, "using device tree for GPIO lookup\n"); desc = of_find_gpio(dev, con_id, idx, &lookupflags);
desc = of_find_gpio(dev, con_id, idx, &lookupflags); } else if (is_acpi_node(fwnode)) {
} else if (ACPI_COMPANION(dev)) { dev_dbg(dev, "using ACPI for GPIO lookup\n");
dev_dbg(dev, "using ACPI for GPIO lookup\n"); desc = acpi_find_gpio(dev, con_id, idx, &flags, &lookupflags);
desc = acpi_find_gpio(dev, con_id, idx, &flags, &lookupflags);
}
} }
/* /*
...@@ -3921,9 +3921,6 @@ struct gpio_desc *fwnode_get_named_gpiod(struct fwnode_handle *fwnode, ...@@ -3921,9 +3921,6 @@ struct gpio_desc *fwnode_get_named_gpiod(struct fwnode_handle *fwnode,
struct gpio_desc *desc = ERR_PTR(-ENODEV); struct gpio_desc *desc = ERR_PTR(-ENODEV);
int ret; int ret;
if (!fwnode)
return ERR_PTR(-EINVAL);
if (is_of_node(fwnode)) { if (is_of_node(fwnode)) {
desc = gpiod_get_from_of_node(to_of_node(fwnode), desc = gpiod_get_from_of_node(to_of_node(fwnode),
propname, index, propname, index,
...@@ -3939,7 +3936,8 @@ struct gpio_desc *fwnode_get_named_gpiod(struct fwnode_handle *fwnode, ...@@ -3939,7 +3936,8 @@ struct gpio_desc *fwnode_get_named_gpiod(struct fwnode_handle *fwnode,
acpi_gpio_update_gpiod_flags(&dflags, &info); acpi_gpio_update_gpiod_flags(&dflags, &info);
acpi_gpio_update_gpiod_lookup_flags(&lflags, &info); acpi_gpio_update_gpiod_lookup_flags(&lflags, &info);
} } else
return ERR_PTR(-EINVAL);
/* Currently only ACPI takes this path */ /* Currently only ACPI takes this path */
ret = gpiod_request(desc, label); ret = gpiod_request(desc, label);
......
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