gpiolib: Get rid of not used of_node member
authorAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Wed, 28 Dec 2022 09:20:44 +0000 (11:20 +0200)
committerBartosz Golaszewski <bartosz.golaszewski@linaro.org>
Mon, 30 Jan 2023 14:55:29 +0000 (15:55 +0100)
All new drivers should use fwnode and / or parent to provide the
necessary information to the GPIO library.

Cc: Thierry Reding <treding@nvidia.com>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
drivers/gpio/gpiolib-acpi.c
drivers/gpio/gpiolib-acpi.h
drivers/gpio/gpiolib-of.c
drivers/gpio/gpiolib-of.h
drivers/gpio/gpiolib.c
include/linux/gpio/driver.h

index 17c53f484280f086d46cb95bf2dd22a978cd96e8..bb583cea366cb242c2158e2edaa4d606b1ba2683 100644 (file)
@@ -1388,16 +1388,6 @@ void acpi_gpiochip_remove(struct gpio_chip *chip)
        kfree(acpi_gpio);
 }
 
-void acpi_gpio_dev_init(struct gpio_chip *gc, struct gpio_device *gdev)
-{
-       /* Set default fwnode to parent's one if present */
-       if (gc->parent)
-               ACPI_COMPANION_SET(&gdev->dev, ACPI_COMPANION(gc->parent));
-
-       if (gc->fwnode)
-               device_set_node(&gdev->dev, gc->fwnode);
-}
-
 static int acpi_gpio_package_count(const union acpi_object *obj)
 {
        const union acpi_object *element = obj->package.elements;
index 9475f99a9694148b0f22a761614fdab7de793053..5fa315b3c912493e26bdff75c643bcf45af8dd87 100644 (file)
@@ -26,8 +26,6 @@ struct gpio_device;
 void acpi_gpiochip_add(struct gpio_chip *chip);
 void acpi_gpiochip_remove(struct gpio_chip *chip);
 
-void acpi_gpio_dev_init(struct gpio_chip *gc, struct gpio_device *gdev);
-
 void acpi_gpiochip_request_interrupts(struct gpio_chip *chip);
 void acpi_gpiochip_free_interrupts(struct gpio_chip *chip);
 
@@ -42,8 +40,6 @@ int acpi_gpio_count(struct device *dev, const char *con_id);
 static inline void acpi_gpiochip_add(struct gpio_chip *chip) { }
 static inline void acpi_gpiochip_remove(struct gpio_chip *chip) { }
 
-static inline void acpi_gpio_dev_init(struct gpio_chip *gc, struct gpio_device *gdev) { }
-
 static inline void
 acpi_gpiochip_request_interrupts(struct gpio_chip *chip) { }
 
index 4a47e71782f3ec905ef6950ca4b353db13808c34..edc769d2d338b78266922a284f42a362efbe90e6 100644 (file)
@@ -651,7 +651,7 @@ static struct gpio_desc *of_parse_own_gpio(struct device_node *np,
        u32 tmp;
        int ret;
 
-       chip_np = chip->of_node;
+       chip_np = dev_of_node(&chip->gpiodev->dev);
        if (!chip_np)
                return ERR_PTR(-EINVAL);
 
@@ -743,7 +743,7 @@ static int of_gpiochip_scan_gpios(struct gpio_chip *chip)
        struct device_node *np;
        int ret;
 
-       for_each_available_child_of_node(chip->of_node, np) {
+       for_each_available_child_of_node(dev_of_node(&chip->gpiodev->dev), np) {
                if (!of_property_read_bool(np, "gpio-hog"))
                        continue;
 
@@ -953,14 +953,15 @@ EXPORT_SYMBOL_GPL(of_mm_gpiochip_remove);
 #ifdef CONFIG_PINCTRL
 static int of_gpiochip_add_pin_range(struct gpio_chip *chip)
 {
-       struct device_node *np = chip->of_node;
        struct of_phandle_args pinspec;
        struct pinctrl_dev *pctldev;
+       struct device_node *np;
        int index = 0, ret;
        const char *name;
        static const char group_names_propname[] = "gpio-ranges-group-names";
        struct property *group_names;
 
+       np = dev_of_node(&chip->gpiodev->dev);
        if (!np)
                return 0;
 
@@ -1046,7 +1047,7 @@ int of_gpiochip_add(struct gpio_chip *chip)
        struct device_node *np;
        int ret;
 
-       np = to_of_node(dev_fwnode(&chip->gpiodev->dev));
+       np = dev_of_node(&chip->gpiodev->dev);
        if (!np)
                return 0;
 
@@ -1075,19 +1076,3 @@ void of_gpiochip_remove(struct gpio_chip *chip)
 {
        fwnode_handle_put(chip->fwnode);
 }
-
-void of_gpio_dev_init(struct gpio_chip *gc, struct gpio_device *gdev)
-{
-       /* Set default OF node to parent's one if present */
-       if (gc->parent)
-               gdev->dev.of_node = gc->parent->of_node;
-
-       if (gc->fwnode)
-               gc->of_node = to_of_node(gc->fwnode);
-
-       /* If the gpiochip has an assigned OF node this takes precedence */
-       if (gc->of_node)
-               gdev->dev.of_node = gc->of_node;
-       else
-               gc->of_node = gdev->dev.of_node;
-}
index a6c593e6766c59d03fc7060beeefbb9b36990763..e5bb065d82eff24cb3904110b172e28e3e9cfdd7 100644 (file)
@@ -23,7 +23,6 @@ struct gpio_desc *of_find_gpio(struct device_node *np,
 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);
-void of_gpio_dev_init(struct gpio_chip *gc, struct gpio_device *gdev);
 #else
 static inline struct gpio_desc *of_find_gpio(struct device_node *np,
                                             const char *con_id,
@@ -38,10 +37,6 @@ static inline int of_gpio_get_count(struct device *dev, const char *con_id)
 {
        return 0;
 }
-static inline void of_gpio_dev_init(struct gpio_chip *gc,
-                                   struct gpio_device *gdev)
-{
-}
 #endif /* CONFIG_OF_GPIO */
 
 extern struct notifier_block gpio_of_notifier;
index ebc2da15ae4ea4b25283c9e91a8d59e2cacea863..3650f4bd92132b9366685ceaf4998beab87c5a4d 100644 (file)
@@ -659,10 +659,12 @@ int gpiochip_add_data_with_key(struct gpio_chip *gc, void *data,
        int base = 0;
        int ret = 0;
 
+       /* If the calling driver did not initialize firmware node, do it here */
        if (gc->fwnode)
                fwnode = gc->fwnode;
        else if (gc->parent)
                fwnode = dev_fwnode(gc->parent);
+       gc->fwnode = fwnode;
 
        /*
         * First: allocate and populate the internal stat container, and
@@ -676,14 +678,7 @@ int gpiochip_add_data_with_key(struct gpio_chip *gc, void *data,
        gdev->chip = gc;
        gc->gpiodev = gdev;
 
-       of_gpio_dev_init(gc, gdev);
-       acpi_gpio_dev_init(gc, gdev);
-
-       /*
-        * Assign fwnode depending on the result of the previous calls,
-        * if none of them succeed, assign it to the parent's one.
-        */
-       gc->fwnode = gdev->dev.fwnode = dev_fwnode(&gdev->dev) ?: fwnode;
+       device_set_node(&gdev->dev, gc->fwnode);
 
        gdev->id = ida_alloc(&gpio_ida, GFP_KERNEL);
        if (gdev->id < 0) {
index 44783fc161254bc14071bf26127dbb35a82cd29e..2316cb7fa667da6c82a466c51cece1c9a5491358 100644 (file)
@@ -503,13 +503,6 @@ struct gpio_chip {
         * the device tree automatically may have an OF translation
         */
 
-       /**
-        * @of_node:
-        *
-        * Pointer to a device tree node representing this GPIO controller.
-        */
-       struct device_node *of_node;
-
        /**
         * @of_gpio_n_cells:
         *