gpio: mmio: use new generic GPIO chip API
authorBartosz Golaszewski <bartosz.golaszewski@linaro.org>
Wed, 10 Sep 2025 07:12:50 +0000 (09:12 +0200)
committerBartosz Golaszewski <bartosz.golaszewski@linaro.org>
Fri, 12 Sep 2025 07:22:45 +0000 (09:22 +0200)
Convert the driver to using the new generic GPIO chip interfaces from
linux/gpio/generic.h.

Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Link: https://lore.kernel.org/r/20250910-gpio-mmio-gpio-conv-part4-v2-14-f3d1a4c57124@linaro.org
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
drivers/gpio/gpio-mmio.c

index 79e1be1..b4f0ab0 100644 (file)
@@ -57,6 +57,7 @@ o        `                     ~~~~\___/~~~~    ` controller in FPGA is ,.`
 #include <linux/types.h>
 
 #include <linux/gpio/driver.h>
+#include <linux/gpio/generic.h>
 
 #include "gpiolib.h"
 
@@ -737,6 +738,8 @@ MODULE_DEVICE_TABLE(of, bgpio_of_match);
 
 static int bgpio_pdev_probe(struct platform_device *pdev)
 {
+       struct gpio_generic_chip_config config;
+       struct gpio_generic_chip *gen_gc;
        struct device *dev = &pdev->dev;
        struct resource *r;
        void __iomem *dat;
@@ -748,7 +751,6 @@ static int bgpio_pdev_probe(struct platform_device *pdev)
        unsigned long flags = 0;
        unsigned int base;
        int err;
-       struct gpio_chip *gc;
        const char *label;
 
        r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "dat");
@@ -777,8 +779,8 @@ static int bgpio_pdev_probe(struct platform_device *pdev)
        if (IS_ERR(dirin))
                return PTR_ERR(dirin);
 
-       gc = devm_kzalloc(&pdev->dev, sizeof(*gc), GFP_KERNEL);
-       if (!gc)
+       gen_gc = devm_kzalloc(&pdev->dev, sizeof(*gen_gc), GFP_KERNEL);
+       if (!gen_gc)
                return -ENOMEM;
 
        if (device_is_big_endian(dev))
@@ -787,13 +789,24 @@ static int bgpio_pdev_probe(struct platform_device *pdev)
        if (device_property_read_bool(dev, "no-output"))
                flags |= BGPIOF_NO_OUTPUT;
 
-       err = bgpio_init(gc, dev, sz, dat, set, clr, dirout, dirin, flags);
+       config = (struct gpio_generic_chip_config) {
+               .dev = dev,
+               .sz = sz,
+               .dat = dat,
+               .set = set,
+               .clr = clr,
+               .dirout = dirout,
+               .dirin = dirin,
+               .flags = flags,
+       };
+
+       err = gpio_generic_chip_init(gen_gc, &config);
        if (err)
                return err;
 
        err = device_property_read_string(dev, "label", &label);
        if (!err)
-               gc->label = label;
+               gen_gc->gc.label = label;
 
        /*
         * This property *must not* be used in device-tree sources, it's only
@@ -801,11 +814,11 @@ static int bgpio_pdev_probe(struct platform_device *pdev)
         */
        err = device_property_read_u32(dev, "gpio-mmio,base", &base);
        if (!err && base <= INT_MAX)
-               gc->base = base;
+               gen_gc->gc.base = base;
 
-       platform_set_drvdata(pdev, gc);
+       platform_set_drvdata(pdev, &gen_gc->gc);
 
-       return devm_gpiochip_add_data(&pdev->dev, gc, NULL);
+       return devm_gpiochip_add_data(&pdev->dev, &gen_gc->gc, NULL);
 }
 
 static const struct platform_device_id bgpio_id_table[] = {