gpio: of: Make of_gpio_get_count() take firmware node as a parameter
authorAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Thu, 29 Feb 2024 14:51:38 +0000 (16:51 +0200)
committerBartosz Golaszewski <bartosz.golaszewski@linaro.org>
Fri, 1 Mar 2024 08:07:21 +0000 (09:07 +0100)
Make of_gpio_get_count() take firmware node as a parameter in order
to be aligned with other functions and decouple from unused device
pointer. The latter helps to create a common fwnode_gpio_count()
in the future.

While at it, rename to be of_gpio_count() to be aligned with the others.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Reviewed-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
drivers/gpio/gpiolib-of.c
drivers/gpio/gpiolib-of.h
drivers/gpio/gpiolib.c

index e35a9c7da4eef11968898205f4b388f4ebdccc9f..cb0cefaec37e8d1e2d7f74fcec15f8fdcac31ebb 100644 (file)
@@ -68,7 +68,7 @@ static int of_gpio_named_count(const struct device_node *np,
 
 /**
  * of_gpio_spi_cs_get_count() - special GPIO counting for SPI
- * @dev:    Consuming device
+ * @np:    Consuming device node
  * @con_id: Function within the GPIO consumer
  *
  * Some elder GPIO controllers need special quirks. Currently we handle
@@ -78,10 +78,9 @@ static int of_gpio_named_count(const struct device_node *np,
  * the counting of "cs-gpios" to count "gpios" transparent to the
  * driver.
  */
-static int of_gpio_spi_cs_get_count(struct device *dev, const char *con_id)
+static int of_gpio_spi_cs_get_count(const struct device_node *np,
+                                   const char *con_id)
 {
-       struct device_node *np = dev->of_node;
-
        if (!IS_ENABLED(CONFIG_SPI_MASTER))
                return 0;
        if (!con_id || strcmp(con_id, "cs"))
@@ -93,13 +92,14 @@ static int of_gpio_spi_cs_get_count(struct device *dev, const char *con_id)
        return of_gpio_named_count(np, "gpios");
 }
 
-int of_gpio_get_count(struct device *dev, const char *con_id)
+int of_gpio_count(const struct fwnode_handle *fwnode, const char *con_id)
 {
+       const struct device_node *np = to_of_node(fwnode);
        int ret;
        char propname[32];
        unsigned int i;
 
-       ret = of_gpio_spi_cs_get_count(dev, con_id);
+       ret = of_gpio_spi_cs_get_count(np, con_id);
        if (ret > 0)
                return ret;
 
@@ -111,7 +111,7 @@ int of_gpio_get_count(struct device *dev, const char *con_id)
                        snprintf(propname, sizeof(propname), "%s",
                                 gpio_suffixes[i]);
 
-               ret = of_gpio_named_count(dev->of_node, propname);
+               ret = of_gpio_named_count(np, propname);
                if (ret > 0)
                        break;
        }
index 6b3a5347c5d928b6f781030d5f0dc370465e6fe4..16d6ac8cb156c02232ea868b755bbdc46c78e3c7 100644 (file)
@@ -9,6 +9,7 @@
 #include <linux/notifier.h>
 
 struct device;
+struct fwnode_handle;
 
 struct gpio_chip;
 struct gpio_desc;
@@ -21,7 +22,7 @@ struct gpio_desc *of_find_gpio(struct device_node *np,
                               unsigned long *lookupflags);
 int of_gpiochip_add(struct gpio_chip *gc);
 void of_gpiochip_remove(struct gpio_chip *gc);
-int of_gpio_get_count(struct device *dev, const char *con_id);
+int of_gpio_count(const struct fwnode_handle *fwnode, const char *con_id);
 #else
 static inline struct gpio_desc *of_find_gpio(struct device_node *np,
                                             const char *con_id,
@@ -32,7 +33,8 @@ static inline struct gpio_desc *of_find_gpio(struct device_node *np,
 }
 static inline int of_gpiochip_add(struct gpio_chip *gc) { return 0; }
 static inline void of_gpiochip_remove(struct gpio_chip *gc) { }
-static inline int of_gpio_get_count(struct device *dev, const char *con_id)
+static inline int of_gpio_count(const struct fwnode_handle *fwnode,
+                               const char *con_id)
 {
        return 0;
 }
index 3e2cd85673b677f2fe944eea219b04fc00fc6bc8..01016b4c467473f5fe114528260c5c7a0c35f2a7 100644 (file)
@@ -4285,7 +4285,7 @@ int gpiod_count(struct device *dev, const char *con_id)
        int count = -ENOENT;
 
        if (is_of_node(fwnode))
-               count = of_gpio_get_count(dev, con_id);
+               count = of_gpio_count(fwnode, con_id);
        else if (is_acpi_node(fwnode))
                count = acpi_gpio_count(dev, con_id);
        else if (is_software_node(fwnode))