]> www.infradead.org Git - users/hch/misc.git/commitdiff
powerpc/44x: Drop legacy-of-mm-gpiochip.h header
authorChristophe Leroy <christophe.leroy@csgroup.eu>
Mon, 18 Aug 2025 12:17:35 +0000 (14:17 +0200)
committerMadhavan Srinivasan <maddy@linux.ibm.com>
Sat, 6 Sep 2025 10:37:11 +0000 (16:07 +0530)
Remove legacy-of-mm-gpiochip.h header file. The above mentioned
file provides an OF API that's deprecated. There is no agnostic
alternatives to it and we have to open code the logic which was
hidden behind of_mm_gpiochip_add_data(). Note, most of the GPIO
drivers are using their own labeling schemas and resource retrieval
that only a few may gain of the code deduplication, so whenever
alternative is appear we can move drivers again to use that one.

As a side effect this change fixes a potential memory leak on
an error path, if of_mm_gpiochip_add_data() fails.

[Text copied from commit 34064c8267a6 ("powerpc/8xx: Drop
legacy-of-mm-gpiochip.h header")]

Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
Signed-off-by: Madhavan Srinivasan <maddy@linux.ibm.com>
Link: https://patch.msgid.link/2f8f16eac72b9ec202b6e593939b44308891a661.1755519343.git.christophe.leroy@csgroup.eu
arch/powerpc/platforms/44x/Kconfig
arch/powerpc/platforms/44x/gpio.c

index 35a1f4b9f8272b678ecfb62e82012e198ea20f4b..fc79f84669335251b5f0274788b46c8cec95af5c 100644 (file)
@@ -231,7 +231,6 @@ config PPC4xx_GPIO
        bool "PPC4xx GPIO support"
        depends on 44x
        select GPIOLIB
-       select OF_GPIO_MM_GPIOCHIP
        help
          Enable gpiolib support for ppc440 based boards
 
index a025b3248342ac40431ea4d6084db23ddfe83d63..aea0d913b59d0b7acc025001bba3ac8024135344 100644 (file)
@@ -14,7 +14,6 @@
 #include <linux/spinlock.h>
 #include <linux/io.h>
 #include <linux/of.h>
-#include <linux/gpio/legacy-of-mm-gpiochip.h>
 #include <linux/gpio/driver.h>
 #include <linux/types.h>
 #include <linux/slab.h>
@@ -46,7 +45,8 @@ struct ppc4xx_gpio {
 };
 
 struct ppc4xx_gpio_chip {
-       struct of_mm_gpio_chip mm_gc;
+       struct gpio_chip gc;
+       void __iomem *regs;
        spinlock_t lock;
 };
 
@@ -58,8 +58,8 @@ struct ppc4xx_gpio_chip {
 
 static int ppc4xx_gpio_get(struct gpio_chip *gc, unsigned int gpio)
 {
-       struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc);
-       struct ppc4xx_gpio __iomem *regs = mm_gc->regs;
+       struct ppc4xx_gpio_chip *chip = gpiochip_get_data(gc);
+       struct ppc4xx_gpio __iomem *regs = chip->regs;
 
        return !!(in_be32(&regs->ir) & GPIO_MASK(gpio));
 }
@@ -67,8 +67,8 @@ static int ppc4xx_gpio_get(struct gpio_chip *gc, unsigned int gpio)
 static inline void
 __ppc4xx_gpio_set(struct gpio_chip *gc, unsigned int gpio, int val)
 {
-       struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc);
-       struct ppc4xx_gpio __iomem *regs = mm_gc->regs;
+       struct ppc4xx_gpio_chip *chip = gpiochip_get_data(gc);
+       struct ppc4xx_gpio __iomem *regs = chip->regs;
 
        if (val)
                setbits32(&regs->or, GPIO_MASK(gpio));
@@ -94,9 +94,8 @@ static int ppc4xx_gpio_set(struct gpio_chip *gc, unsigned int gpio, int val)
 
 static int ppc4xx_gpio_dir_in(struct gpio_chip *gc, unsigned int gpio)
 {
-       struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc);
        struct ppc4xx_gpio_chip *chip = gpiochip_get_data(gc);
-       struct ppc4xx_gpio __iomem *regs = mm_gc->regs;
+       struct ppc4xx_gpio __iomem *regs = chip->regs;
        unsigned long flags;
 
        spin_lock_irqsave(&chip->lock, flags);
@@ -124,9 +123,8 @@ static int ppc4xx_gpio_dir_in(struct gpio_chip *gc, unsigned int gpio)
 static int
 ppc4xx_gpio_dir_out(struct gpio_chip *gc, unsigned int gpio, int val)
 {
-       struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc);
        struct ppc4xx_gpio_chip *chip = gpiochip_get_data(gc);
-       struct ppc4xx_gpio __iomem *regs = mm_gc->regs;
+       struct ppc4xx_gpio __iomem *regs = chip->regs;
        unsigned long flags;
 
        spin_lock_irqsave(&chip->lock, flags);
@@ -161,7 +159,6 @@ static int ppc4xx_gpio_probe(struct platform_device *ofdev)
        struct device *dev = &ofdev->dev;
        struct device_node *np = dev->of_node;
        struct ppc4xx_gpio_chip *chip;
-       struct of_mm_gpio_chip *mm_gc;
        struct gpio_chip *gc;
 
        chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
@@ -170,16 +167,24 @@ static int ppc4xx_gpio_probe(struct platform_device *ofdev)
 
        spin_lock_init(&chip->lock);
 
-       mm_gc = &chip->mm_gc;
-       gc = &mm_gc->gc;
+       gc = &chip->gc;
 
+       gc->base = -1;
        gc->ngpio = 32;
        gc->direction_input = ppc4xx_gpio_dir_in;
        gc->direction_output = ppc4xx_gpio_dir_out;
        gc->get = ppc4xx_gpio_get;
        gc->set = ppc4xx_gpio_set;
 
-       return of_mm_gpiochip_add_data(np, mm_gc, chip);
+       gc->label = devm_kasprintf(dev, GFP_KERNEL, "%pOF", np);
+       if (!gc->label)
+               return -ENOMEM;
+
+       chip->regs = devm_of_iomap(dev, np, 0, NULL);
+       if (IS_ERR(chip->regs))
+               return PTR_ERR(chip->regs);
+
+       return devm_gpiochip_add_data(dev, gc, chip);
 }
 
 static const struct of_device_id ppc4xx_gpio_match[] = {