gpio: 74xx-mmio: use new generic GPIO chip API

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/20250702-gpio-mmio-rework-v2-7-6b77aab684d8@linaro.org
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
This commit is contained in:
Bartosz Golaszewski 2025-07-02 11:22:14 +02:00
parent 47ecff3839
commit bd9a0dec2d

View file

@ -8,6 +8,7 @@
#include <linux/bits.h>
#include <linux/err.h>
#include <linux/gpio/driver.h>
#include <linux/gpio/generic.h>
#include <linux/mod_devicetable.h>
#include <linux/module.h>
#include <linux/platform_device.h>
@ -18,8 +19,8 @@
#define MMIO_74XX_BIT_CNT(x) ((x) & GENMASK(7, 0))
struct mmio_74xx_gpio_priv {
struct gpio_chip gc;
unsigned flags;
struct gpio_generic_chip gen_gc;
unsigned int flags;
};
static const struct of_device_id mmio_74xx_gpio_ids[] = {
@ -99,16 +100,15 @@ static int mmio_74xx_dir_out(struct gpio_chip *gc, unsigned int gpio, int val)
{
struct mmio_74xx_gpio_priv *priv = gpiochip_get_data(gc);
if (priv->flags & MMIO_74XX_DIR_OUT) {
gc->set_rv(gc, gpio, val);
return 0;
}
if (priv->flags & MMIO_74XX_DIR_OUT)
return gpio_generic_chip_set(&priv->gen_gc, gpio, val);
return -ENOTSUPP;
}
static int mmio_74xx_gpio_probe(struct platform_device *pdev)
{
struct gpio_generic_chip_config config = { };
struct mmio_74xx_gpio_priv *priv;
void __iomem *dat;
int err;
@ -123,19 +123,21 @@ static int mmio_74xx_gpio_probe(struct platform_device *pdev)
if (IS_ERR(dat))
return PTR_ERR(dat);
err = bgpio_init(&priv->gc, &pdev->dev,
DIV_ROUND_UP(MMIO_74XX_BIT_CNT(priv->flags), 8),
dat, NULL, NULL, NULL, NULL, 0);
config.dev = &pdev->dev;
config.sz = DIV_ROUND_UP(MMIO_74XX_BIT_CNT(priv->flags), 8);
config.dat = dat;
err = gpio_generic_chip_init(&priv->gen_gc, &config);
if (err)
return err;
priv->gc.direction_input = mmio_74xx_dir_in;
priv->gc.direction_output = mmio_74xx_dir_out;
priv->gc.get_direction = mmio_74xx_get_direction;
priv->gc.ngpio = MMIO_74XX_BIT_CNT(priv->flags);
priv->gc.owner = THIS_MODULE;
priv->gen_gc.gc.direction_input = mmio_74xx_dir_in;
priv->gen_gc.gc.direction_output = mmio_74xx_dir_out;
priv->gen_gc.gc.get_direction = mmio_74xx_get_direction;
priv->gen_gc.gc.ngpio = MMIO_74XX_BIT_CNT(priv->flags);
priv->gen_gc.gc.owner = THIS_MODULE;
return devm_gpiochip_add_data(&pdev->dev, &priv->gc, priv);
return devm_gpiochip_add_data(&pdev->dev, &priv->gen_gc.gc, priv);
}
static struct platform_driver mmio_74xx_gpio_driver = {