[PATCH RESEND 07/14] gpio: ts4800: use new generic GPIO chip API

Bartosz Golaszewski posted 14 patches 1 month, 1 week ago
[PATCH RESEND 07/14] gpio: ts4800: use new generic GPIO chip API
Posted by Bartosz Golaszewski 1 month, 1 week ago
From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>

Convert the driver to using the new generic GPIO chip interfaces from
linux/gpio/generic.h.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
---
 drivers/gpio/gpio-ts4800.c | 25 +++++++++++++++++--------
 1 file changed, 17 insertions(+), 8 deletions(-)

diff --git a/drivers/gpio/gpio-ts4800.c b/drivers/gpio/gpio-ts4800.c
index cb3eeeb1e9df9aa687e880b16f8d0a31b04a3b07..844347945e8e71fa0f456be0ba8de7217f6760a3 100644
--- a/drivers/gpio/gpio-ts4800.c
+++ b/drivers/gpio/gpio-ts4800.c
@@ -6,6 +6,7 @@
  */
 
 #include <linux/gpio/driver.h>
+#include <linux/gpio/generic.h>
 #include <linux/module.h>
 #include <linux/platform_device.h>
 #include <linux/property.h>
@@ -17,13 +18,14 @@
 
 static int ts4800_gpio_probe(struct platform_device *pdev)
 {
+	struct gpio_generic_chip_config config;
 	struct device *dev = &pdev->dev;
-	struct gpio_chip *chip;
+	struct gpio_generic_chip *chip;
 	void __iomem *base_addr;
 	int retval;
 	u32 ngpios;
 
-	chip = devm_kzalloc(&pdev->dev, sizeof(struct gpio_chip), GFP_KERNEL);
+	chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
 	if (!chip)
 		return -ENOMEM;
 
@@ -37,15 +39,22 @@ static int ts4800_gpio_probe(struct platform_device *pdev)
 	else if (retval)
 		return retval;
 
-	retval = bgpio_init(chip, &pdev->dev, 2, base_addr + INPUT_REG_OFFSET,
-			    base_addr + OUTPUT_REG_OFFSET, NULL,
-			    base_addr + DIRECTION_REG_OFFSET, NULL, 0);
+	config = (typeof(config)){
+		.dev = dev,
+		.sz = 2,
+		.dat = base_addr + INPUT_REG_OFFSET,
+		.set = base_addr + OUTPUT_REG_OFFSET,
+		.dirout = base_addr + DIRECTION_REG_OFFSET,
+	};
+
+	retval = gpio_generic_chip_init(chip, &config);
 	if (retval)
-		return dev_err_probe(dev, retval, "bgpio_init failed\n");
+		return dev_err_probe(dev, retval,
+				     "failed to initialize the generic GPIO chip\n");
 
-	chip->ngpio = ngpios;
+	chip->gc.ngpio = ngpios;
 
-	return devm_gpiochip_add_data(&pdev->dev, chip, NULL);
+	return devm_gpiochip_add_data(dev, &chip->gc, NULL);
 }
 
 static const struct of_device_id ts4800_gpio_of_match[] = {

-- 
2.48.1
Re: [PATCH RESEND 07/14] gpio: ts4800: use new generic GPIO chip API
Posted by Andy Shevchenko 1 month ago
On Mon, Aug 25, 2025 at 11:48:48AM +0200, Bartosz Golaszewski wrote:
> 
> Convert the driver to using the new generic GPIO chip interfaces from
> linux/gpio/generic.h.

...

> +	config = (typeof(config)){

First of all, what's wrong with the pattern used in the kernel when we
explicitly show the compound literal? Also we put a space before {.

> +		.dev = dev,
> +		.sz = 2,
> +		.dat = base_addr + INPUT_REG_OFFSET,
> +		.set = base_addr + OUTPUT_REG_OFFSET,
> +		.dirout = base_addr + DIRECTION_REG_OFFSET,
> +	};
> +
> +	retval = gpio_generic_chip_init(chip, &config);
>  	if (retval)
> -		return dev_err_probe(dev, retval, "bgpio_init failed\n");
> +		return dev_err_probe(dev, retval,
> +				     "failed to initialize the generic GPIO chip\n");

Second, can't it all be hidden in the GPIOLIB just by passing the pointer to
the above initialised structure? Yes, it will take a pointer space in GPIO chip
for all, but I think it will reduce the burden.

-- 
With Best Regards,
Andy Shevchenko
Re: [PATCH RESEND 07/14] gpio: ts4800: use new generic GPIO chip API
Posted by Andy Shevchenko 1 month ago
On Wed, Sep 03, 2025 at 05:44:59PM +0200, Andy Shevchenko wrote:
> On Mon, Aug 25, 2025 at 11:48:48AM +0200, Bartosz Golaszewski wrote:
> > 
> > Convert the driver to using the new generic GPIO chip interfaces from
> > linux/gpio/generic.h.

...

> > +	config = (typeof(config)){
> 
> First of all, what's wrong with the pattern used in the kernel when we
> explicitly show the compound literal? Also we put a space before {.
> 
> > +		.dev = dev,
> > +		.sz = 2,
> > +		.dat = base_addr + INPUT_REG_OFFSET,
> > +		.set = base_addr + OUTPUT_REG_OFFSET,
> > +		.dirout = base_addr + DIRECTION_REG_OFFSET,
> > +	};
> > +
> > +	retval = gpio_generic_chip_init(chip, &config);
> >  	if (retval)
> > -		return dev_err_probe(dev, retval, "bgpio_init failed\n");
> > +		return dev_err_probe(dev, retval,
> > +				     "failed to initialize the generic GPIO chip\n");
> 
> Second, can't it all be hidden in the GPIOLIB just by passing the pointer to
> the above initialised structure? Yes, it will take a pointer space in GPIO chip
> for all, but I think it will reduce the burden.

Okay, it seems the motivation is to make it in align with, e.g., gpio-regmap.
But why not simply convert the drivers to use gpio-regmap instead?

-- 
With Best Regards,
Andy Shevchenko
Re: [PATCH RESEND 07/14] gpio: ts4800: use new generic GPIO chip API
Posted by Bartosz Golaszewski 1 month ago
On Wed, Sep 3, 2025 at 5:48 PM Andy Shevchenko
<andriy.shevchenko@intel.com> wrote:
>
> On Wed, Sep 03, 2025 at 05:44:59PM +0200, Andy Shevchenko wrote:
> > On Mon, Aug 25, 2025 at 11:48:48AM +0200, Bartosz Golaszewski wrote:
> > >
> > > Convert the driver to using the new generic GPIO chip interfaces from
> > > linux/gpio/generic.h.
>
> ...
>
> > > +   config = (typeof(config)){
> >
> > First of all, what's wrong with the pattern used in the kernel when we
> > explicitly show the compound literal? Also we put a space before {.
> >
> > > +           .dev = dev,
> > > +           .sz = 2,
> > > +           .dat = base_addr + INPUT_REG_OFFSET,
> > > +           .set = base_addr + OUTPUT_REG_OFFSET,
> > > +           .dirout = base_addr + DIRECTION_REG_OFFSET,
> > > +   };
> > > +
> > > +   retval = gpio_generic_chip_init(chip, &config);
> > >     if (retval)
> > > -           return dev_err_probe(dev, retval, "bgpio_init failed\n");
> > > +           return dev_err_probe(dev, retval,
> > > +                                "failed to initialize the generic GPIO chip\n");
> >
> > Second, can't it all be hidden in the GPIOLIB just by passing the pointer to
> > the above initialised structure? Yes, it will take a pointer space in GPIO chip
> > for all, but I think it will reduce the burden.
>
> Okay, it seems the motivation is to make it in align with, e.g., gpio-regmap.
> But why not simply convert the drivers to use gpio-regmap instead?
>

Because the goal of this rework is removing the gpio-mmio fields out
of struct gpio_chip and also I can't test this conversion
functionally. Out of scope basically. But if you want to do the
conversion, I'm absolutely open to it. :)

Bart