Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>

authored by

Andy Shevchenko and committed by
Bartosz Golaszewski
944f4b0a 67196fea

+13 -15
+13 -15
drivers/gpio/gpiolib.c
··· 3684 3684 */ 3685 3685 int gpiod_count(struct device *dev, const char *con_id) 3686 3686 { 3687 + const struct fwnode_handle *fwnode = dev ? dev_fwnode(dev) : NULL; 3687 3688 int count = -ENOENT; 3688 3689 3689 - if (IS_ENABLED(CONFIG_OF) && dev && dev->of_node) 3690 + if (is_of_node(fwnode)) 3690 3691 count = of_gpio_get_count(dev, con_id); 3691 - else if (IS_ENABLED(CONFIG_ACPI) && dev && ACPI_HANDLE(dev)) 3692 + else if (is_acpi_node(fwnode)) 3692 3693 count = acpi_gpio_count(dev, con_id); 3693 3694 3694 3695 if (count < 0) ··· 3827 3826 int ret; 3828 3827 /* Maybe we have a device name, maybe not */ 3829 3828 const char *devname = dev ? dev_name(dev) : "?"; 3829 + const struct fwnode_handle *fwnode = dev ? dev_fwnode(dev) : NULL; 3830 3830 3831 3831 dev_dbg(dev, "GPIO lookup for consumer %s\n", con_id); 3832 3832 3833 - if (dev) { 3834 - /* Using device tree? */ 3835 - if (IS_ENABLED(CONFIG_OF) && dev->of_node) { 3836 - dev_dbg(dev, "using device tree for GPIO lookup\n"); 3837 - desc = of_find_gpio(dev, con_id, idx, &lookupflags); 3838 - } else if (ACPI_COMPANION(dev)) { 3839 - dev_dbg(dev, "using ACPI for GPIO lookup\n"); 3840 - desc = acpi_find_gpio(dev, con_id, idx, &flags, &lookupflags); 3841 - } 3833 + /* Using device tree? */ 3834 + if (is_of_node(fwnode)) { 3835 + dev_dbg(dev, "using device tree for GPIO lookup\n"); 3836 + desc = of_find_gpio(dev, con_id, idx, &lookupflags); 3837 + } else if (is_acpi_node(fwnode)) { 3838 + dev_dbg(dev, "using ACPI for GPIO lookup\n"); 3839 + desc = acpi_find_gpio(dev, con_id, idx, &flags, &lookupflags); 3842 3840 } 3843 3841 3844 3842 /* ··· 3921 3921 struct gpio_desc *desc = ERR_PTR(-ENODEV); 3922 3922 int ret; 3923 3923 3924 - if (!fwnode) 3925 - return ERR_PTR(-EINVAL); 3926 - 3927 3924 if (is_of_node(fwnode)) { 3928 3925 desc = gpiod_get_from_of_node(to_of_node(fwnode), 3929 3926 propname, index, ··· 3936 3939 3937 3940 acpi_gpio_update_gpiod_flags(&dflags, &info); 3938 3941 acpi_gpio_update_gpiod_lookup_flags(&lflags, &info); 3939 - } 3942 + } else 3943 + return ERR_PTR(-EINVAL); 3940 3944 3941 3945 /* Currently only ACPI takes this path */ 3942 3946 ret = gpiod_request(desc, label);