18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Copyright (C) 2009-2011 Gabor Juhos <juhosg@openwrt.org>
48c2ecf20Sopenharmony_ci * Copyright (C) 2013 John Crispin <blogic@openwrt.org>
58c2ecf20Sopenharmony_ci */
68c2ecf20Sopenharmony_ci
78c2ecf20Sopenharmony_ci#include <linux/err.h>
88c2ecf20Sopenharmony_ci#include <linux/gpio/driver.h>
98c2ecf20Sopenharmony_ci#include <linux/interrupt.h>
108c2ecf20Sopenharmony_ci#include <linux/io.h>
118c2ecf20Sopenharmony_ci#include <linux/module.h>
128c2ecf20Sopenharmony_ci#include <linux/of_irq.h>
138c2ecf20Sopenharmony_ci#include <linux/platform_device.h>
148c2ecf20Sopenharmony_ci#include <linux/spinlock.h>
158c2ecf20Sopenharmony_ci
168c2ecf20Sopenharmony_ci#define MTK_BANK_CNT	3
178c2ecf20Sopenharmony_ci#define MTK_BANK_WIDTH	32
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_ci#define GPIO_BANK_STRIDE	0x04
208c2ecf20Sopenharmony_ci#define GPIO_REG_CTRL		0x00
218c2ecf20Sopenharmony_ci#define GPIO_REG_POL		0x10
228c2ecf20Sopenharmony_ci#define GPIO_REG_DATA		0x20
238c2ecf20Sopenharmony_ci#define GPIO_REG_DSET		0x30
248c2ecf20Sopenharmony_ci#define GPIO_REG_DCLR		0x40
258c2ecf20Sopenharmony_ci#define GPIO_REG_REDGE		0x50
268c2ecf20Sopenharmony_ci#define GPIO_REG_FEDGE		0x60
278c2ecf20Sopenharmony_ci#define GPIO_REG_HLVL		0x70
288c2ecf20Sopenharmony_ci#define GPIO_REG_LLVL		0x80
298c2ecf20Sopenharmony_ci#define GPIO_REG_STAT		0x90
308c2ecf20Sopenharmony_ci#define GPIO_REG_EDGE		0xA0
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_cistruct mtk_gc {
338c2ecf20Sopenharmony_ci	struct irq_chip irq_chip;
348c2ecf20Sopenharmony_ci	struct gpio_chip chip;
358c2ecf20Sopenharmony_ci	spinlock_t lock;
368c2ecf20Sopenharmony_ci	int bank;
378c2ecf20Sopenharmony_ci	u32 rising;
388c2ecf20Sopenharmony_ci	u32 falling;
398c2ecf20Sopenharmony_ci	u32 hlevel;
408c2ecf20Sopenharmony_ci	u32 llevel;
418c2ecf20Sopenharmony_ci};
428c2ecf20Sopenharmony_ci
438c2ecf20Sopenharmony_ci/**
448c2ecf20Sopenharmony_ci * struct mtk - state container for
458c2ecf20Sopenharmony_ci * data of the platform driver. It is 3
468c2ecf20Sopenharmony_ci * separate gpio-chip each one with its
478c2ecf20Sopenharmony_ci * own irq_chip.
488c2ecf20Sopenharmony_ci * @dev: device instance
498c2ecf20Sopenharmony_ci * @base: memory base address
508c2ecf20Sopenharmony_ci * @gpio_irq: irq number from the device tree
518c2ecf20Sopenharmony_ci * @gc_map: array of the gpio chips
528c2ecf20Sopenharmony_ci */
538c2ecf20Sopenharmony_cistruct mtk {
548c2ecf20Sopenharmony_ci	struct device *dev;
558c2ecf20Sopenharmony_ci	void __iomem *base;
568c2ecf20Sopenharmony_ci	int gpio_irq;
578c2ecf20Sopenharmony_ci	struct mtk_gc gc_map[MTK_BANK_CNT];
588c2ecf20Sopenharmony_ci};
598c2ecf20Sopenharmony_ci
608c2ecf20Sopenharmony_cistatic inline struct mtk_gc *
618c2ecf20Sopenharmony_cito_mediatek_gpio(struct gpio_chip *chip)
628c2ecf20Sopenharmony_ci{
638c2ecf20Sopenharmony_ci	return container_of(chip, struct mtk_gc, chip);
648c2ecf20Sopenharmony_ci}
658c2ecf20Sopenharmony_ci
668c2ecf20Sopenharmony_cistatic inline void
678c2ecf20Sopenharmony_cimtk_gpio_w32(struct mtk_gc *rg, u32 offset, u32 val)
688c2ecf20Sopenharmony_ci{
698c2ecf20Sopenharmony_ci	struct gpio_chip *gc = &rg->chip;
708c2ecf20Sopenharmony_ci	struct mtk *mtk = gpiochip_get_data(gc);
718c2ecf20Sopenharmony_ci
728c2ecf20Sopenharmony_ci	offset = (rg->bank * GPIO_BANK_STRIDE) + offset;
738c2ecf20Sopenharmony_ci	gc->write_reg(mtk->base + offset, val);
748c2ecf20Sopenharmony_ci}
758c2ecf20Sopenharmony_ci
768c2ecf20Sopenharmony_cistatic inline u32
778c2ecf20Sopenharmony_cimtk_gpio_r32(struct mtk_gc *rg, u32 offset)
788c2ecf20Sopenharmony_ci{
798c2ecf20Sopenharmony_ci	struct gpio_chip *gc = &rg->chip;
808c2ecf20Sopenharmony_ci	struct mtk *mtk = gpiochip_get_data(gc);
818c2ecf20Sopenharmony_ci
828c2ecf20Sopenharmony_ci	offset = (rg->bank * GPIO_BANK_STRIDE) + offset;
838c2ecf20Sopenharmony_ci	return gc->read_reg(mtk->base + offset);
848c2ecf20Sopenharmony_ci}
858c2ecf20Sopenharmony_ci
868c2ecf20Sopenharmony_cistatic irqreturn_t
878c2ecf20Sopenharmony_cimediatek_gpio_irq_handler(int irq, void *data)
888c2ecf20Sopenharmony_ci{
898c2ecf20Sopenharmony_ci	struct gpio_chip *gc = data;
908c2ecf20Sopenharmony_ci	struct mtk_gc *rg = to_mediatek_gpio(gc);
918c2ecf20Sopenharmony_ci	irqreturn_t ret = IRQ_NONE;
928c2ecf20Sopenharmony_ci	unsigned long pending;
938c2ecf20Sopenharmony_ci	int bit;
948c2ecf20Sopenharmony_ci
958c2ecf20Sopenharmony_ci	pending = mtk_gpio_r32(rg, GPIO_REG_STAT);
968c2ecf20Sopenharmony_ci
978c2ecf20Sopenharmony_ci	for_each_set_bit(bit, &pending, MTK_BANK_WIDTH) {
988c2ecf20Sopenharmony_ci		u32 map = irq_find_mapping(gc->irq.domain, bit);
998c2ecf20Sopenharmony_ci
1008c2ecf20Sopenharmony_ci		generic_handle_irq(map);
1018c2ecf20Sopenharmony_ci		mtk_gpio_w32(rg, GPIO_REG_STAT, BIT(bit));
1028c2ecf20Sopenharmony_ci		ret |= IRQ_HANDLED;
1038c2ecf20Sopenharmony_ci	}
1048c2ecf20Sopenharmony_ci
1058c2ecf20Sopenharmony_ci	return ret;
1068c2ecf20Sopenharmony_ci}
1078c2ecf20Sopenharmony_ci
1088c2ecf20Sopenharmony_cistatic void
1098c2ecf20Sopenharmony_cimediatek_gpio_irq_unmask(struct irq_data *d)
1108c2ecf20Sopenharmony_ci{
1118c2ecf20Sopenharmony_ci	struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
1128c2ecf20Sopenharmony_ci	struct mtk_gc *rg = to_mediatek_gpio(gc);
1138c2ecf20Sopenharmony_ci	int pin = d->hwirq;
1148c2ecf20Sopenharmony_ci	unsigned long flags;
1158c2ecf20Sopenharmony_ci	u32 rise, fall, high, low;
1168c2ecf20Sopenharmony_ci
1178c2ecf20Sopenharmony_ci	spin_lock_irqsave(&rg->lock, flags);
1188c2ecf20Sopenharmony_ci	rise = mtk_gpio_r32(rg, GPIO_REG_REDGE);
1198c2ecf20Sopenharmony_ci	fall = mtk_gpio_r32(rg, GPIO_REG_FEDGE);
1208c2ecf20Sopenharmony_ci	high = mtk_gpio_r32(rg, GPIO_REG_HLVL);
1218c2ecf20Sopenharmony_ci	low = mtk_gpio_r32(rg, GPIO_REG_LLVL);
1228c2ecf20Sopenharmony_ci	mtk_gpio_w32(rg, GPIO_REG_REDGE, rise | (BIT(pin) & rg->rising));
1238c2ecf20Sopenharmony_ci	mtk_gpio_w32(rg, GPIO_REG_FEDGE, fall | (BIT(pin) & rg->falling));
1248c2ecf20Sopenharmony_ci	mtk_gpio_w32(rg, GPIO_REG_HLVL, high | (BIT(pin) & rg->hlevel));
1258c2ecf20Sopenharmony_ci	mtk_gpio_w32(rg, GPIO_REG_LLVL, low | (BIT(pin) & rg->llevel));
1268c2ecf20Sopenharmony_ci	spin_unlock_irqrestore(&rg->lock, flags);
1278c2ecf20Sopenharmony_ci}
1288c2ecf20Sopenharmony_ci
1298c2ecf20Sopenharmony_cistatic void
1308c2ecf20Sopenharmony_cimediatek_gpio_irq_mask(struct irq_data *d)
1318c2ecf20Sopenharmony_ci{
1328c2ecf20Sopenharmony_ci	struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
1338c2ecf20Sopenharmony_ci	struct mtk_gc *rg = to_mediatek_gpio(gc);
1348c2ecf20Sopenharmony_ci	int pin = d->hwirq;
1358c2ecf20Sopenharmony_ci	unsigned long flags;
1368c2ecf20Sopenharmony_ci	u32 rise, fall, high, low;
1378c2ecf20Sopenharmony_ci
1388c2ecf20Sopenharmony_ci	spin_lock_irqsave(&rg->lock, flags);
1398c2ecf20Sopenharmony_ci	rise = mtk_gpio_r32(rg, GPIO_REG_REDGE);
1408c2ecf20Sopenharmony_ci	fall = mtk_gpio_r32(rg, GPIO_REG_FEDGE);
1418c2ecf20Sopenharmony_ci	high = mtk_gpio_r32(rg, GPIO_REG_HLVL);
1428c2ecf20Sopenharmony_ci	low = mtk_gpio_r32(rg, GPIO_REG_LLVL);
1438c2ecf20Sopenharmony_ci	mtk_gpio_w32(rg, GPIO_REG_FEDGE, fall & ~BIT(pin));
1448c2ecf20Sopenharmony_ci	mtk_gpio_w32(rg, GPIO_REG_REDGE, rise & ~BIT(pin));
1458c2ecf20Sopenharmony_ci	mtk_gpio_w32(rg, GPIO_REG_HLVL, high & ~BIT(pin));
1468c2ecf20Sopenharmony_ci	mtk_gpio_w32(rg, GPIO_REG_LLVL, low & ~BIT(pin));
1478c2ecf20Sopenharmony_ci	spin_unlock_irqrestore(&rg->lock, flags);
1488c2ecf20Sopenharmony_ci}
1498c2ecf20Sopenharmony_ci
1508c2ecf20Sopenharmony_cistatic int
1518c2ecf20Sopenharmony_cimediatek_gpio_irq_type(struct irq_data *d, unsigned int type)
1528c2ecf20Sopenharmony_ci{
1538c2ecf20Sopenharmony_ci	struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
1548c2ecf20Sopenharmony_ci	struct mtk_gc *rg = to_mediatek_gpio(gc);
1558c2ecf20Sopenharmony_ci	int pin = d->hwirq;
1568c2ecf20Sopenharmony_ci	u32 mask = BIT(pin);
1578c2ecf20Sopenharmony_ci
1588c2ecf20Sopenharmony_ci	if (type == IRQ_TYPE_PROBE) {
1598c2ecf20Sopenharmony_ci		if ((rg->rising | rg->falling |
1608c2ecf20Sopenharmony_ci		     rg->hlevel | rg->llevel) & mask)
1618c2ecf20Sopenharmony_ci			return 0;
1628c2ecf20Sopenharmony_ci
1638c2ecf20Sopenharmony_ci		type = IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING;
1648c2ecf20Sopenharmony_ci	}
1658c2ecf20Sopenharmony_ci
1668c2ecf20Sopenharmony_ci	rg->rising &= ~mask;
1678c2ecf20Sopenharmony_ci	rg->falling &= ~mask;
1688c2ecf20Sopenharmony_ci	rg->hlevel &= ~mask;
1698c2ecf20Sopenharmony_ci	rg->llevel &= ~mask;
1708c2ecf20Sopenharmony_ci
1718c2ecf20Sopenharmony_ci	switch (type & IRQ_TYPE_SENSE_MASK) {
1728c2ecf20Sopenharmony_ci	case IRQ_TYPE_EDGE_BOTH:
1738c2ecf20Sopenharmony_ci		rg->rising |= mask;
1748c2ecf20Sopenharmony_ci		rg->falling |= mask;
1758c2ecf20Sopenharmony_ci		break;
1768c2ecf20Sopenharmony_ci	case IRQ_TYPE_EDGE_RISING:
1778c2ecf20Sopenharmony_ci		rg->rising |= mask;
1788c2ecf20Sopenharmony_ci		break;
1798c2ecf20Sopenharmony_ci	case IRQ_TYPE_EDGE_FALLING:
1808c2ecf20Sopenharmony_ci		rg->falling |= mask;
1818c2ecf20Sopenharmony_ci		break;
1828c2ecf20Sopenharmony_ci	case IRQ_TYPE_LEVEL_HIGH:
1838c2ecf20Sopenharmony_ci		rg->hlevel |= mask;
1848c2ecf20Sopenharmony_ci		break;
1858c2ecf20Sopenharmony_ci	case IRQ_TYPE_LEVEL_LOW:
1868c2ecf20Sopenharmony_ci		rg->llevel |= mask;
1878c2ecf20Sopenharmony_ci		break;
1888c2ecf20Sopenharmony_ci	}
1898c2ecf20Sopenharmony_ci
1908c2ecf20Sopenharmony_ci	return 0;
1918c2ecf20Sopenharmony_ci}
1928c2ecf20Sopenharmony_ci
1938c2ecf20Sopenharmony_cistatic int
1948c2ecf20Sopenharmony_cimediatek_gpio_xlate(struct gpio_chip *chip,
1958c2ecf20Sopenharmony_ci		    const struct of_phandle_args *spec, u32 *flags)
1968c2ecf20Sopenharmony_ci{
1978c2ecf20Sopenharmony_ci	int gpio = spec->args[0];
1988c2ecf20Sopenharmony_ci	struct mtk_gc *rg = to_mediatek_gpio(chip);
1998c2ecf20Sopenharmony_ci
2008c2ecf20Sopenharmony_ci	if (rg->bank != gpio / MTK_BANK_WIDTH)
2018c2ecf20Sopenharmony_ci		return -EINVAL;
2028c2ecf20Sopenharmony_ci
2038c2ecf20Sopenharmony_ci	if (flags)
2048c2ecf20Sopenharmony_ci		*flags = spec->args[1];
2058c2ecf20Sopenharmony_ci
2068c2ecf20Sopenharmony_ci	return gpio % MTK_BANK_WIDTH;
2078c2ecf20Sopenharmony_ci}
2088c2ecf20Sopenharmony_ci
2098c2ecf20Sopenharmony_cistatic int
2108c2ecf20Sopenharmony_cimediatek_gpio_bank_probe(struct device *dev,
2118c2ecf20Sopenharmony_ci			 struct device_node *node, int bank)
2128c2ecf20Sopenharmony_ci{
2138c2ecf20Sopenharmony_ci	struct mtk *mtk = dev_get_drvdata(dev);
2148c2ecf20Sopenharmony_ci	struct mtk_gc *rg;
2158c2ecf20Sopenharmony_ci	void __iomem *dat, *set, *ctrl, *diro;
2168c2ecf20Sopenharmony_ci	int ret;
2178c2ecf20Sopenharmony_ci
2188c2ecf20Sopenharmony_ci	rg = &mtk->gc_map[bank];
2198c2ecf20Sopenharmony_ci	memset(rg, 0, sizeof(*rg));
2208c2ecf20Sopenharmony_ci
2218c2ecf20Sopenharmony_ci	spin_lock_init(&rg->lock);
2228c2ecf20Sopenharmony_ci	rg->chip.of_node = node;
2238c2ecf20Sopenharmony_ci	rg->bank = bank;
2248c2ecf20Sopenharmony_ci
2258c2ecf20Sopenharmony_ci	dat = mtk->base + GPIO_REG_DATA + (rg->bank * GPIO_BANK_STRIDE);
2268c2ecf20Sopenharmony_ci	set = mtk->base + GPIO_REG_DSET + (rg->bank * GPIO_BANK_STRIDE);
2278c2ecf20Sopenharmony_ci	ctrl = mtk->base + GPIO_REG_DCLR + (rg->bank * GPIO_BANK_STRIDE);
2288c2ecf20Sopenharmony_ci	diro = mtk->base + GPIO_REG_CTRL + (rg->bank * GPIO_BANK_STRIDE);
2298c2ecf20Sopenharmony_ci
2308c2ecf20Sopenharmony_ci	ret = bgpio_init(&rg->chip, dev, 4, dat, set, ctrl, diro, NULL,
2318c2ecf20Sopenharmony_ci			 BGPIOF_NO_SET_ON_INPUT);
2328c2ecf20Sopenharmony_ci	if (ret) {
2338c2ecf20Sopenharmony_ci		dev_err(dev, "bgpio_init() failed\n");
2348c2ecf20Sopenharmony_ci		return ret;
2358c2ecf20Sopenharmony_ci	}
2368c2ecf20Sopenharmony_ci
2378c2ecf20Sopenharmony_ci	rg->chip.of_gpio_n_cells = 2;
2388c2ecf20Sopenharmony_ci	rg->chip.of_xlate = mediatek_gpio_xlate;
2398c2ecf20Sopenharmony_ci	rg->chip.label = devm_kasprintf(dev, GFP_KERNEL, "%s-bank%d",
2408c2ecf20Sopenharmony_ci					dev_name(dev), bank);
2418c2ecf20Sopenharmony_ci	if (!rg->chip.label)
2428c2ecf20Sopenharmony_ci		return -ENOMEM;
2438c2ecf20Sopenharmony_ci
2448c2ecf20Sopenharmony_ci	rg->irq_chip.name = dev_name(dev);
2458c2ecf20Sopenharmony_ci	rg->irq_chip.parent_device = dev;
2468c2ecf20Sopenharmony_ci	rg->irq_chip.irq_unmask = mediatek_gpio_irq_unmask;
2478c2ecf20Sopenharmony_ci	rg->irq_chip.irq_mask = mediatek_gpio_irq_mask;
2488c2ecf20Sopenharmony_ci	rg->irq_chip.irq_mask_ack = mediatek_gpio_irq_mask;
2498c2ecf20Sopenharmony_ci	rg->irq_chip.irq_set_type = mediatek_gpio_irq_type;
2508c2ecf20Sopenharmony_ci
2518c2ecf20Sopenharmony_ci	if (mtk->gpio_irq) {
2528c2ecf20Sopenharmony_ci		struct gpio_irq_chip *girq;
2538c2ecf20Sopenharmony_ci
2548c2ecf20Sopenharmony_ci		/*
2558c2ecf20Sopenharmony_ci		 * Directly request the irq here instead of passing
2568c2ecf20Sopenharmony_ci		 * a flow-handler because the irq is shared.
2578c2ecf20Sopenharmony_ci		 */
2588c2ecf20Sopenharmony_ci		ret = devm_request_irq(dev, mtk->gpio_irq,
2598c2ecf20Sopenharmony_ci				       mediatek_gpio_irq_handler, IRQF_SHARED,
2608c2ecf20Sopenharmony_ci				       rg->chip.label, &rg->chip);
2618c2ecf20Sopenharmony_ci
2628c2ecf20Sopenharmony_ci		if (ret) {
2638c2ecf20Sopenharmony_ci			dev_err(dev, "Error requesting IRQ %d: %d\n",
2648c2ecf20Sopenharmony_ci				mtk->gpio_irq, ret);
2658c2ecf20Sopenharmony_ci			return ret;
2668c2ecf20Sopenharmony_ci		}
2678c2ecf20Sopenharmony_ci
2688c2ecf20Sopenharmony_ci		girq = &rg->chip.irq;
2698c2ecf20Sopenharmony_ci		girq->chip = &rg->irq_chip;
2708c2ecf20Sopenharmony_ci		/* This will let us handle the parent IRQ in the driver */
2718c2ecf20Sopenharmony_ci		girq->parent_handler = NULL;
2728c2ecf20Sopenharmony_ci		girq->num_parents = 0;
2738c2ecf20Sopenharmony_ci		girq->parents = NULL;
2748c2ecf20Sopenharmony_ci		girq->default_type = IRQ_TYPE_NONE;
2758c2ecf20Sopenharmony_ci		girq->handler = handle_simple_irq;
2768c2ecf20Sopenharmony_ci	}
2778c2ecf20Sopenharmony_ci
2788c2ecf20Sopenharmony_ci	ret = devm_gpiochip_add_data(dev, &rg->chip, mtk);
2798c2ecf20Sopenharmony_ci	if (ret < 0) {
2808c2ecf20Sopenharmony_ci		dev_err(dev, "Could not register gpio %d, ret=%d\n",
2818c2ecf20Sopenharmony_ci			rg->chip.ngpio, ret);
2828c2ecf20Sopenharmony_ci		return ret;
2838c2ecf20Sopenharmony_ci	}
2848c2ecf20Sopenharmony_ci
2858c2ecf20Sopenharmony_ci	/* set polarity to low for all gpios */
2868c2ecf20Sopenharmony_ci	mtk_gpio_w32(rg, GPIO_REG_POL, 0);
2878c2ecf20Sopenharmony_ci
2888c2ecf20Sopenharmony_ci	dev_info(dev, "registering %d gpios\n", rg->chip.ngpio);
2898c2ecf20Sopenharmony_ci
2908c2ecf20Sopenharmony_ci	return 0;
2918c2ecf20Sopenharmony_ci}
2928c2ecf20Sopenharmony_ci
2938c2ecf20Sopenharmony_cistatic int
2948c2ecf20Sopenharmony_cimediatek_gpio_probe(struct platform_device *pdev)
2958c2ecf20Sopenharmony_ci{
2968c2ecf20Sopenharmony_ci	struct device *dev = &pdev->dev;
2978c2ecf20Sopenharmony_ci	struct device_node *np = dev->of_node;
2988c2ecf20Sopenharmony_ci	struct mtk *mtk;
2998c2ecf20Sopenharmony_ci	int i;
3008c2ecf20Sopenharmony_ci	int ret;
3018c2ecf20Sopenharmony_ci
3028c2ecf20Sopenharmony_ci	mtk = devm_kzalloc(dev, sizeof(*mtk), GFP_KERNEL);
3038c2ecf20Sopenharmony_ci	if (!mtk)
3048c2ecf20Sopenharmony_ci		return -ENOMEM;
3058c2ecf20Sopenharmony_ci
3068c2ecf20Sopenharmony_ci	mtk->base = devm_platform_ioremap_resource(pdev, 0);
3078c2ecf20Sopenharmony_ci	if (IS_ERR(mtk->base))
3088c2ecf20Sopenharmony_ci		return PTR_ERR(mtk->base);
3098c2ecf20Sopenharmony_ci
3108c2ecf20Sopenharmony_ci	mtk->gpio_irq = irq_of_parse_and_map(np, 0);
3118c2ecf20Sopenharmony_ci	mtk->dev = dev;
3128c2ecf20Sopenharmony_ci	platform_set_drvdata(pdev, mtk);
3138c2ecf20Sopenharmony_ci
3148c2ecf20Sopenharmony_ci	for (i = 0; i < MTK_BANK_CNT; i++) {
3158c2ecf20Sopenharmony_ci		ret = mediatek_gpio_bank_probe(dev, np, i);
3168c2ecf20Sopenharmony_ci		if (ret)
3178c2ecf20Sopenharmony_ci			return ret;
3188c2ecf20Sopenharmony_ci	}
3198c2ecf20Sopenharmony_ci
3208c2ecf20Sopenharmony_ci	return 0;
3218c2ecf20Sopenharmony_ci}
3228c2ecf20Sopenharmony_ci
3238c2ecf20Sopenharmony_cistatic const struct of_device_id mediatek_gpio_match[] = {
3248c2ecf20Sopenharmony_ci	{ .compatible = "mediatek,mt7621-gpio" },
3258c2ecf20Sopenharmony_ci	{},
3268c2ecf20Sopenharmony_ci};
3278c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(of, mediatek_gpio_match);
3288c2ecf20Sopenharmony_ci
3298c2ecf20Sopenharmony_cistatic struct platform_driver mediatek_gpio_driver = {
3308c2ecf20Sopenharmony_ci	.probe = mediatek_gpio_probe,
3318c2ecf20Sopenharmony_ci	.driver = {
3328c2ecf20Sopenharmony_ci		.name = "mt7621_gpio",
3338c2ecf20Sopenharmony_ci		.of_match_table = mediatek_gpio_match,
3348c2ecf20Sopenharmony_ci	},
3358c2ecf20Sopenharmony_ci};
3368c2ecf20Sopenharmony_ci
3378c2ecf20Sopenharmony_cibuiltin_platform_driver(mediatek_gpio_driver);
338