[U-Boot] [PATCH] gpio: Add MT7621 GPIO support
Stefan Roese
sr at denx.de
Mon Oct 8 09:38:13 UTC 2018
On 07.10.2018 20:23, Daniel Schwierzeck wrote:
>
>
> On 04.10.2018 13:39, Stefan Roese wrote:
>> This patch adds GPIO support for the Mediatek MT7621 SoC, tested on
>> MT7688 (Gardena smart-gateway). The driver is loosly based on the
>> Linux kernel version.
>>
>> Signed-off-by: Stefan Roese <sr at denx.de>
>> Cc: Daniel Schwierzeck <daniel.schwierzeck at gmail.com>
>> ---
>> drivers/gpio/Kconfig | 8 ++
>> drivers/gpio/Makefile | 1 +
>> drivers/gpio/mt7621_gpio.c | 212 +++++++++++++++++++++++++++++++++++++
>> 3 files changed, 221 insertions(+)
>> create mode 100644 drivers/gpio/mt7621_gpio.c
>>
>> diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
>> index 5cd8b34400..35344e57c6 100644
>> --- a/drivers/gpio/Kconfig
>> +++ b/drivers/gpio/Kconfig
>> @@ -314,4 +314,12 @@ config MPC8XXX_GPIO
>> Aside from the standard functions of input/output mode, and output
>> value setting, the open-drain feature, which can configure individual
>> GPIOs to work as open-drain outputs, is supported.
>> +
>> +config MT7621_GPIO
>> + bool "MediaTek MT7621 GPIO driver"
>> + depends on DM_GPIO && ARCH_MT7620
>> + default y
>> + help
>> + Say yes here to support MediaTek MT7621 compatible GPIOs.
>> +
>> endmenu
>> diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile
>> index f186120684..7ed9a4ec42 100644
>> --- a/drivers/gpio/Makefile
>> +++ b/drivers/gpio/Makefile
>> @@ -58,3 +58,4 @@ obj-$(CONFIG_MVEBU_GPIO) += mvebu_gpio.o
>> obj-$(CONFIG_MSM_GPIO) += msm_gpio.o
>> obj-$(CONFIG_$(SPL_)PCF8575_GPIO) += pcf8575_gpio.o
>> obj-$(CONFIG_PM8916_GPIO) += pm8916_gpio.o
>> +obj-$(CONFIG_MT7621_GPIO) += mt7621_gpio.o
>> diff --git a/drivers/gpio/mt7621_gpio.c b/drivers/gpio/mt7621_gpio.c
>> new file mode 100644
>> index 0000000000..a467b21f2a
>> --- /dev/null
>> +++ b/drivers/gpio/mt7621_gpio.c
>> @@ -0,0 +1,212 @@
>> +// SPDX-License-Identifier: GPL-2.0+
>> +/*
>> + * Copyright (C) 2018 Stefan Roese <sr at denx.de>
>> + *
>> + * Based on the Linux driver version which is:
>> + * Copyright (C) 2009-2011 Gabor Juhos <juhosg at openwrt.org>
>> + * Copyright (C) 2013 John Crispin <blogic at openwrt.org>
>> + */
>> +
>> +#include <common.h>
>> +#include <dm.h>
>> +#include <errno.h>
>> +#include <fdtdec.h>
>> +#include <malloc.h>
>> +#include <linux/io.h>
>> +#include <asm/io.h>
>> +#include <asm/gpio.h>
>> +#include <dm/device-internal.h>
>> +#include <dt-bindings/gpio/gpio.h>
>> +
>> +#define MTK_MAX_BANK 3
>> +#define MTK_BANK_WIDTH 32
>> +
>> +enum mediatek_gpio_reg {
>> + GPIO_REG_CTRL = 0,
>> + GPIO_REG_POL,
>> + GPIO_REG_DATA,
>> + GPIO_REG_DSET,
>> + GPIO_REG_DCLR,
>> + GPIO_REG_REDGE,
>> + GPIO_REG_FEDGE,
>> + GPIO_REG_HLVL,
>> + GPIO_REG_LLVL,
>> + GPIO_REG_STAT,
>> + GPIO_REG_EDGE,
>> +};
>> +
>> +static void __iomem *mediatek_gpio_membase;
>> +
>> +struct mediatek_gpio_platdata {
>> + const char *bank_name; /* Name of bank, e.g. "B" */
>> + int gpio_count;
>> + int bank;
>> +};
>> +
>> +static void mtk_gpio_w32(int bank, u8 reg, u32 val)
>> +{
>> + iowrite32(val, mediatek_gpio_membase + (reg * 0x10) + (bank * 0x4));
>> +}
>> +
>> +static u32 mtk_gpio_r32(int bank, u8 reg)
>> +{
>> + return ioread32(mediatek_gpio_membase + (reg * 0x10) + (bank * 0x4));
>> +}
>> +
>> +static int mediatek_gpio_get_value(struct udevice *dev, unsigned offset)
>> +{
>> + struct mediatek_gpio_platdata *plat = dev_get_platdata(dev);
>> +
>> + return !!(mtk_gpio_r32(plat->bank, GPIO_REG_DATA) & BIT(offset));
>> +}
>> +
>> +static int mediatek_gpio_set_value(struct udevice *dev, unsigned offset,
>> + int value)
>> +{
>> + struct mediatek_gpio_platdata *plat = dev_get_platdata(dev);
>> +
>> + mtk_gpio_w32(plat->bank, (value) ? GPIO_REG_DSET :
>> + GPIO_REG_DCLR, BIT(offset));
>> +
>> + return 0;
>> +}
>> +
>> +static int mediatek_gpio_direction_input(struct udevice *dev, unsigned offset)
>> +{
>> + struct mediatek_gpio_platdata *plat = dev_get_platdata(dev);
>> + u32 t;
>> +
>> + t = mtk_gpio_r32(plat->bank, GPIO_REG_CTRL);
>> + t &= ~BIT(offset);
>> + mtk_gpio_w32(plat->bank, GPIO_REG_CTRL, t);
>
> I would only wrap the "(reg * 0x10) + (bank * 0x4)" into a function and
> directly use the I/O functions. Then you could also use clrbits, setbits
> etc.
As you might have guessed, the current implementation with its
IO wrappers is copied from the Linux source. But I agree, that it
makes sense to drop those wrappers. Will do in v2 - including the
other review comments.
Thanks,
Stefan
More information about the U-Boot
mailing list