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>pull/1309/head
parent
47ecff3839
commit
bd9a0dec2d
|
|
@ -8,6 +8,7 @@
|
||||||
#include <linux/bits.h>
|
#include <linux/bits.h>
|
||||||
#include <linux/err.h>
|
#include <linux/err.h>
|
||||||
#include <linux/gpio/driver.h>
|
#include <linux/gpio/driver.h>
|
||||||
|
#include <linux/gpio/generic.h>
|
||||||
#include <linux/mod_devicetable.h>
|
#include <linux/mod_devicetable.h>
|
||||||
#include <linux/module.h>
|
#include <linux/module.h>
|
||||||
#include <linux/platform_device.h>
|
#include <linux/platform_device.h>
|
||||||
|
|
@ -18,8 +19,8 @@
|
||||||
#define MMIO_74XX_BIT_CNT(x) ((x) & GENMASK(7, 0))
|
#define MMIO_74XX_BIT_CNT(x) ((x) & GENMASK(7, 0))
|
||||||
|
|
||||||
struct mmio_74xx_gpio_priv {
|
struct mmio_74xx_gpio_priv {
|
||||||
struct gpio_chip gc;
|
struct gpio_generic_chip gen_gc;
|
||||||
unsigned flags;
|
unsigned int flags;
|
||||||
};
|
};
|
||||||
|
|
||||||
static const struct of_device_id mmio_74xx_gpio_ids[] = {
|
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);
|
struct mmio_74xx_gpio_priv *priv = gpiochip_get_data(gc);
|
||||||
|
|
||||||
if (priv->flags & MMIO_74XX_DIR_OUT) {
|
if (priv->flags & MMIO_74XX_DIR_OUT)
|
||||||
gc->set_rv(gc, gpio, val);
|
return gpio_generic_chip_set(&priv->gen_gc, gpio, val);
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return -ENOTSUPP;
|
return -ENOTSUPP;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int mmio_74xx_gpio_probe(struct platform_device *pdev)
|
static int mmio_74xx_gpio_probe(struct platform_device *pdev)
|
||||||
{
|
{
|
||||||
|
struct gpio_generic_chip_config config = { };
|
||||||
struct mmio_74xx_gpio_priv *priv;
|
struct mmio_74xx_gpio_priv *priv;
|
||||||
void __iomem *dat;
|
void __iomem *dat;
|
||||||
int err;
|
int err;
|
||||||
|
|
@ -123,19 +123,21 @@ static int mmio_74xx_gpio_probe(struct platform_device *pdev)
|
||||||
if (IS_ERR(dat))
|
if (IS_ERR(dat))
|
||||||
return PTR_ERR(dat);
|
return PTR_ERR(dat);
|
||||||
|
|
||||||
err = bgpio_init(&priv->gc, &pdev->dev,
|
config.dev = &pdev->dev;
|
||||||
DIV_ROUND_UP(MMIO_74XX_BIT_CNT(priv->flags), 8),
|
config.sz = DIV_ROUND_UP(MMIO_74XX_BIT_CNT(priv->flags), 8);
|
||||||
dat, NULL, NULL, NULL, NULL, 0);
|
config.dat = dat;
|
||||||
|
|
||||||
|
err = gpio_generic_chip_init(&priv->gen_gc, &config);
|
||||||
if (err)
|
if (err)
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
priv->gc.direction_input = mmio_74xx_dir_in;
|
priv->gen_gc.gc.direction_input = mmio_74xx_dir_in;
|
||||||
priv->gc.direction_output = mmio_74xx_dir_out;
|
priv->gen_gc.gc.direction_output = mmio_74xx_dir_out;
|
||||||
priv->gc.get_direction = mmio_74xx_get_direction;
|
priv->gen_gc.gc.get_direction = mmio_74xx_get_direction;
|
||||||
priv->gc.ngpio = MMIO_74XX_BIT_CNT(priv->flags);
|
priv->gen_gc.gc.ngpio = MMIO_74XX_BIT_CNT(priv->flags);
|
||||||
priv->gc.owner = THIS_MODULE;
|
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 = {
|
static struct platform_driver mmio_74xx_gpio_driver = {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue