From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: Antony Pavlov <antonynpavlov@gmail.com>, barebox@lists.infradead.org
Cc: Alexander Shiyan <shc_work@mail.ru>
Subject: Re: [PATCH 4/9] gpio: add driver for 74xx-ICs with MMIO access
Date: Wed, 5 May 2021 12:35:34 +0200 [thread overview]
Message-ID: <164dc7f9-ffcf-e1a8-1d11-5f6bdfffde34@pengutronix.de> (raw)
In-Reply-To: <20210505100900.88141-5-antonynpavlov@gmail.com>
On 05.05.21 12:08, Antony Pavlov wrote:
> This patch adds driver to support GPIO functionality
> for 74xx-compatible ICs with MMIO access.
>
> Compatible models include:
> 1 bit: 741G125 (Input), 741G74 (Output)
> 2 bits: 742G125 (Input), 7474 (Output)
> 4 bits: 74125 (Input), 74175 (Output)
> 6 bits: 74365 (Input), 74174 (Output)
> 8 bits: 74244 (Input), 74273 (Output)
> 16 bits: 741624 (Input), 7416374 (Output)
>
> Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com>
> Cc: Alexander Shiyan <shc_work@mail.ru>
> ---
> drivers/gpio/Kconfig | 14 +++
> drivers/gpio/Makefile | 1 +
> drivers/gpio/gpio-74xx-mmio.c | 170 ++++++++++++++++++++++++++++++++++
> 3 files changed, 185 insertions(+)
>
> diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
> index 261b6e6662..59cb00ff22 100644
> --- a/drivers/gpio/Kconfig
> +++ b/drivers/gpio/Kconfig
> @@ -21,6 +21,20 @@ config GPIO_74164
> shift registers. This driver can be used to provide access
> to more gpio outputs.
>
> +config GPIO_74XX_MMIO
> + tristate "GPIO driver for 74xx-ICs with MMIO access"
> + depends on OFDEVICE
> + select GPIO_GENERIC
> + help
> + Say yes here to support GPIO functionality for 74xx-compatible ICs
> + with MMIO access. Compatible models include:
> + 1 bit: 741G125 (Input), 741G74 (Output)
> + 2 bits: 742G125 (Input), 7474 (Output)
> + 4 bits: 74125 (Input), 74175 (Output)
> + 6 bits: 74365 (Input), 74174 (Output)
> + 8 bits: 74244 (Input), 74273 (Output)
> + 16 bits: 741624 (Input), 7416374 (Output)
> +
> config GPIO_CLPS711X
> bool "GPIO support for CLPS711X"
> depends on ARCH_CLPS711X || COMPILE_TEST
> diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile
> index 77dcf58f64..7ece8621d2 100644
> --- a/drivers/gpio/Makefile
> +++ b/drivers/gpio/Makefile
> @@ -1,6 +1,7 @@
> obj-$(CONFIG_GPIOLIB) += gpiolib.o
>
> obj-$(CONFIG_GPIO_74164) += gpio-74164.o
> +obj-$(CONFIG_GPIO_74XX_MMIO) += gpio-74xx-mmio.o
> obj-$(CONFIG_MACH_MIPS_ATH79) += gpio-ath79.o
> obj-$(CONFIG_GPIO_DAVINCI) += gpio-davinci.o
> obj-$(CONFIG_GPIO_CLPS711X) += gpio-clps711x.o
> diff --git a/drivers/gpio/gpio-74xx-mmio.c b/drivers/gpio/gpio-74xx-mmio.c
> new file mode 100644
> index 0000000000..2c05d022f1
> --- /dev/null
> +++ b/drivers/gpio/gpio-74xx-mmio.c
> @@ -0,0 +1,170 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * 74xx MMIO GPIO driver
> + *
> + * Copyright (C) 2014 Alexander Shiyan <shc_work@mail.ru>
> + *
> + * Ported to barebox from linux-v5.4-rc6
> + * Copyright (C) 2019-2021 Antony Pavlov <antonynpavlov@gmail.com>
> + *
> + */
> +
> +#include <common.h>
> +#include <driver.h>
> +#include <errno.h>
> +#include <gpio.h>
> +#include <init.h>
> +#include <io.h>
> +#include <malloc.h>
> +
> +#include <linux/err.h>
> +#include <linux/basic_mmio_gpio.h>
> +
> +#define MMIO_74XX_DIR_IN (0 << 8)
> +#define MMIO_74XX_DIR_OUT (1 << 8)
> +#define MMIO_74XX_BIT_CNT(x) ((x) & 0xff)
> +
> +struct mmio_74xx_gpio_priv {
> + struct bgpio_chip bgc;
> + unsigned int flags;
> +};
> +
> +static const struct of_device_id mmio_74xx_gpio_ids[] = {
> + {
> + .compatible = "ti,741g125",
> + .data = (const void *)(MMIO_74XX_DIR_IN | 1),
> + },
> + {
> + .compatible = "ti,742g125",
> + .data = (const void *)(MMIO_74XX_DIR_IN | 2),
> + },
> + {
> + .compatible = "ti,74125",
> + .data = (const void *)(MMIO_74XX_DIR_IN | 4),
> + },
> + {
> + .compatible = "ti,74365",
> + .data = (const void *)(MMIO_74XX_DIR_IN | 6),
> + },
> + {
> + .compatible = "ti,74244",
> + .data = (const void *)(MMIO_74XX_DIR_IN | 8),
> + },
> + {
> + .compatible = "ti,741624",
> + .data = (const void *)(MMIO_74XX_DIR_IN | 16),
> + },
> + {
> + .compatible = "ti,741g74",
> + .data = (const void *)(MMIO_74XX_DIR_OUT | 1),
> + },
> + {
> + .compatible = "ti,7474",
> + .data = (const void *)(MMIO_74XX_DIR_OUT | 2),
> + },
> + {
> + .compatible = "ti,74175",
> + .data = (const void *)(MMIO_74XX_DIR_OUT | 4),
> + },
> + {
> + .compatible = "ti,74174",
> + .data = (const void *)(MMIO_74XX_DIR_OUT | 6),
> + },
> + {
> + .compatible = "ti,74273",
> + .data = (const void *)(MMIO_74XX_DIR_OUT | 8),
> + },
> + {
> + .compatible = "ti,7416374",
> + .data = (const void *)(MMIO_74XX_DIR_OUT | 16),
> + },
> + { }
> +};
> +
> +static inline
> +struct mmio_74xx_gpio_priv *to_mmio_74xx_gpio_priv(struct gpio_chip *gc)
> +{
> + struct bgpio_chip *bgc =
> + container_of(gc, struct bgpio_chip, gc);
> +
> + return container_of(bgc, struct mmio_74xx_gpio_priv, bgc);
> +}
> +
> +static int mmio_74xx_get_direction(struct gpio_chip *gc, unsigned int offset)
> +{
> + struct mmio_74xx_gpio_priv *priv = to_mmio_74xx_gpio_priv(gc);
> +
> + if (priv->flags & MMIO_74XX_DIR_OUT)
> + return GPIOF_DIR_OUT;
> +
> + return GPIOF_DIR_IN;
> +}
> +
> +static int mmio_74xx_dir_in(struct gpio_chip *gc, unsigned int gpio)
> +{
> + struct mmio_74xx_gpio_priv *priv = to_mmio_74xx_gpio_priv(gc);
> +
> + return (priv->flags & MMIO_74XX_DIR_OUT) ? -ENOTSUPP : 0;
> +}
> +
> +static int mmio_74xx_dir_out(struct gpio_chip *gc, unsigned int gpio, int val)
> +{
> + struct mmio_74xx_gpio_priv *priv = to_mmio_74xx_gpio_priv(gc);
> +
> + if (priv->flags & MMIO_74XX_DIR_OUT) {
> + gc->ops->set(gc, gpio, val);
> + return 0;
> + }
> +
> + return -ENOTSUPP;
> +}
> +
> +static int mmio_74xx_gpio_probe(struct device_d *dev)
> +{
> + struct mmio_74xx_gpio_priv *priv;
> + void __iomem *dat;
> + int err;
> + struct gpio_chip *gc;
> +
> + priv = xzalloc(sizeof(*priv));
> +
> + err = dev_get_drvdata(dev, (const void **)&priv->flags);
> + if (err)
> + return err;
Not 64-bit safe. Please use device_get_match_data() instead.
> +
> + dat = dev_request_mem_region(dev, 0);
> + if (IS_ERR(dat))
> + return PTR_ERR(dat);
> +
> + err = bgpio_init(&priv->bgc, dev,
> + DIV_ROUND_UP(MMIO_74XX_BIT_CNT(priv->flags), 8),
> + dat, NULL, NULL, NULL, NULL, 0);
> + if (err)
> + return err;
> +
> + gc = &priv->bgc.gc;
> + gc->ops->direction_input = mmio_74xx_dir_in;
> + gc->ops->direction_output = mmio_74xx_dir_out;
> + gc->ops->get_direction = mmio_74xx_get_direction;
> + gc->ngpio = MMIO_74XX_BIT_CNT(priv->flags);
> +
> + dev->priv = priv;
> +
> + return gpiochip_add(gc);
> +}
> +
> +static struct driver_d mmio_74xx_gpio_driver = {
> + .name = "74xx-mmio-gpio",
> + .of_compatible = DRV_OF_COMPAT(mmio_74xx_gpio_ids),
> + .probe = mmio_74xx_gpio_probe,
> +};
> +
> +static int mmio_74xx_gpio_init(void)
> +{
> + return platform_driver_register(&mmio_74xx_gpio_driver);
> +}
> +coredevice_initcall(mmio_74xx_gpio_init);
You can abbreviate this with coredevice_platform_driver.
Cheers,
Ahmad
> +
> +MODULE_LICENSE("GPL");
> +MODULE_AUTHOR("Alexander Shiyan <shc_work@mail.ru>");
> +MODULE_DESCRIPTION("74xx MMIO GPIO driver");
>
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2021-05-05 10:36 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-05-05 10:08 [PATCH 0/9] RISC-V: add LiteX SoC support; resurrect nmon Antony Pavlov
2021-05-05 10:08 ` [PATCH 1/9] RISC-V: make it possible to run nmon from PBL C code Antony Pavlov
2021-05-05 10:27 ` Ahmad Fatoum
2021-05-05 10:08 ` [PATCH 2/9] RISC-V: boards: erizo: make it possible to use nmon Antony Pavlov
2021-05-05 10:28 ` Ahmad Fatoum
2021-05-05 10:08 ` [PATCH 3/9] serial: add litex UART driver Antony Pavlov
2021-05-05 10:32 ` Ahmad Fatoum
2021-05-05 10:08 ` [PATCH 4/9] gpio: add driver for 74xx-ICs with MMIO access Antony Pavlov
2021-05-05 10:35 ` Ahmad Fatoum [this message]
2021-05-05 10:08 ` [PATCH 5/9] spi: add litex spiflash driver Antony Pavlov
2021-05-05 10:39 ` Ahmad Fatoum
2021-05-05 15:10 ` Antony Pavlov
2021-05-05 10:08 ` [PATCH 6/9] net: add LiteEth driver Antony Pavlov
2021-05-06 10:10 ` Roland Hieber
2021-05-06 11:33 ` Antony Pavlov
2021-05-05 10:08 ` [PATCH 7/9] RISC-V: add initial LiteX SoC support Antony Pavlov
2021-05-05 10:16 ` Ahmad Fatoum
2021-05-05 10:45 ` Jan Lübbe
2021-05-05 15:23 ` Antony Pavlov
2021-05-05 10:08 ` [PATCH 8/9] RISC-V: add litex-linux board support Antony Pavlov
2021-05-05 10:19 ` Ahmad Fatoum
2021-05-05 10:36 ` Antony Pavlov
2021-05-05 10:09 ` [PATCH 9/9] RISC-V: add litex_linux_defconfig Antony Pavlov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=164dc7f9-ffcf-e1a8-1d11-5f6bdfffde34@pengutronix.de \
--to=a.fatoum@pengutronix.de \
--cc=antonynpavlov@gmail.com \
--cc=barebox@lists.infradead.org \
--cc=shc_work@mail.ru \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox