From nobody Sat Jun 13 12:16:46 2026 Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C9BE736492C for ; Tue, 9 Jun 2026 03:11:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780974687; cv=none; b=qoqKFFZc8YV7P7v7uYLy0BA0D8I+8+y/K8ymHa3VFOUdMJBuBwsIAt8oeuOrfFlVdTX3S6oZ8AY2CQC3iFtpVXrvMPCYGDDOxwPnEQoOFKzvvaQd18fCJgL8s8/yL0KSnOeT2p+Wly08V/cB9nO64/IQmaSCuhhSKu+cVA9CnnM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780974687; c=relaxed/simple; bh=g7+DUKM5vFWgzlOgHYZieR2S5TbIS8cALypXSkx7Ibw=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=fwLagwsLTfEMyznFiAHLY4OllxGeJQ0BSUccizQct+OLcgTTMo+r8XVryFZfXMrYzzaFHk/b0/oNoX3NFZwGWV2fPN3+MtMhQbM10rbuTxIsqdfSvS7DnJ+UqJpzac4QTvvep7mqYG4hlF9quTeR0nnqX+UHgSWyuPvWWBEwauA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=eGfRI6w5; arc=none smtp.client-ip=209.85.128.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="eGfRI6w5" Received: by mail-wm1-f44.google.com with SMTP id 5b1f17b1804b1-490aebf33e9so28055005e9.3 for ; Mon, 08 Jun 2026 20:11:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1780974684; x=1781579484; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=8+IbEKoGgDdXtr7lt/KFupAQeSXicrVyIOdVx6P9Yrg=; b=eGfRI6w5SPYaOZLEQxHYi3jjs9Si2d8EDo0BSHlGdnZmqs8rDPg5Z64MupQXw4wBDX hNF2nSnydzcFA2og50QgrzCqdV4I+1E4hCH9raiBnZmqwX5WfswHkdTs9sMYfhUI9GFU rUCi+Y31mp9UFvRNcRSXr2jiA+Br/d82vm8+iqfbaCLk10adpfpUP/zyf6UFq8amBPoa 7GJXuZsqHXQOwnYrh/YfGYDllEA+HbYdhczd3td6KSImjU3u6LjEVmZES1b00CsjxJb7 Dpkj308MRV9PWpfgqAW9vCOhc0pudvPW9ci/qQrG+AZFNfpFSBo59oU74voddIzhJa8u 0RzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780974684; x=1781579484; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=8+IbEKoGgDdXtr7lt/KFupAQeSXicrVyIOdVx6P9Yrg=; b=MZYNsqnavHLTSWO1nNqEZZiFJs8R+5XGm7DVxyOxAIjHhNHgeqMKn98WPRwURoJZj8 uBFD3e2q34o7au3klKw4I+PnX5017Yq21fvEPYCVDAMg1QNJn0k9GqwZyfkiwpc0gExQ v/d7/0tnA8we2vIHDfnWPJQBEfZuGkyoZbzFSqrToR+HT6OfogC9xEcJR6XAhwK4EAga wHFXSlDwiP2k0QMqZX3n8f4bROd5yVsveAlj++W05zNHARznSshnt/dthWsZXyFdcFC0 gu2csGIpwgohPZArSupIOcU6p72TUrpM6iINtTvwLeRoczS0/YN0kPCDXnIpMMMA2t2N Qn1g== X-Forwarded-Encrypted: i=1; AFNElJ8/otiAQZr61hS9e/vG1mcUenJF3VVX5qRsRN6L+xRsey7BZPN5C4yKJsMk5cU2h1sf9CyaeFLGKkNoys8=@vger.kernel.org X-Gm-Message-State: AOJu0YwaensLKvoudwRM0bWOoom97A0mG47LbsSYA+DHa9rRXlK3KjSQ iAbnI/j0V+v1WbH6dXTdhEamcaj7cu9aRCI2MsdI8wJlURXk/PPu3Rhe X-Gm-Gg: Acq92OEJzP8aVS8P5PdRH8p04tZhq4+yrsnXUkyD57JQKfL+3rNM9QyrVq4rqBBWYaN Hws1q+03ou2pQWFqmc9VQgZO4E8T19pyIp8ANhaZnFLigUfVbObMH8Yoj4FYlUm+/INZhHm2Kzu p5riweF7HKQrgM+Aa0gAjc6y+9uMGj11z6auAky462+mgK0Ziy04Hjz1FV+9kQvVOxVfLDnAHpb 09OesiGFjdhr2bJ54xfsi7bvnCcu6hWmhcRPaeAgmpYvBPVxtG77ZeuTN60YNcB3scWQ8lWG9/n 3E1FilYDbn+gMv2Mv/GH1oKU4ZrC9Ez1PvHV0kXx7Qyes4WWEkjN3emS8nH59YeVcAaSonQ4j4z k6EcNkXMfB5JON2RP2STQ2dvyBrv90pZzNshWO2EKzXTPrvHY3SMNy4dVYK7xURIQGqdJs/Alk6 9Lvq5dD/JNeRTyd8RQ9H90qmiPBnmaRRRTP2WvYH24/6DbE+S8pPEVnNsBO2IpUl1g8USJIjZgW 20puW9H X-Received: by 2002:a05:600c:8705:b0:488:ac01:72de with SMTP id 5b1f17b1804b1-490c25898efmr359741905e9.5.1780974683993; Mon, 08 Jun 2026 20:11:23 -0700 (PDT) Received: from camaron.. (147.red-88-9-50.dynamicip.rima-tde.net. [88.9.50.147]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-490bc3918d7sm412152125e9.2.2026.06.08.20.11.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Jun 2026 20:11:23 -0700 (PDT) From: Sergio Paracuellos To: linux-gpio@vger.kernel.org Cc: linusw@kernel.org, brgl@kernel.org, tglx@kernel.org, grant.likely@secretlab.ca, anna-maria@linutronix.de, vicencb@gmail.com, linux-kernel@vger.kernel.org Subject: [PATCH v3] gpio: mt7621: fix interrupt banks mapping on gpio chips Date: Tue, 9 Jun 2026 05:11:18 +0200 Message-ID: <20260609031118.2275735-1-sergio.paracuellos@gmail.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The GPIO controller's registers are organized as sets of eight 32-bit registers with each set controlling a bank of up to 32 pins. A single interrupt is shared for all of the banks handled by the controller. The driver implements this using three gpio chip instances every one with its own irq chip. Every single pin can generate interrupts having a total of 96 possible interrupts here. It looks like there is a problem with interrupts being properly mapped to the gpio bank using this solution. This problem report is in the following lore's link [0]. Device tree is using two cells for this, so only the interrupt pin and the interrupt type are described there. Changing to have three cells to setup also the bank and implement 'of_node_instance_match()' would also work but this would be an ABI breakage and also a bit incoherent since gpios itself are also using two cells and properly mapped in desired bank using through its pin number on 'of_xlate()'. That said, register a linear IRQ domain of the total of 96 interrupts shared with the three gpio chip instances so the bank and the interrupt is properly decoded and devices using gpio IRQs properly work. [0]: https://lore.kernel.org/linux-gpio/CAAMcf8C_A9dJ_v4QRKtb9eGNOpJ7BZNOGs= FP4i2WFOZxOVBPnQ@mail.gmail.com/T/#u Fixes: 4ba9c3afda41 ("gpio: mt7621: Add a driver for MT7621") Co-developed-by: Vicente Bergas Signed-off-by: Vicente Bergas Tested-by: Vicente Bergas Signed-off-by: Sergio Paracuellos --- Changes in v3: - sashiko complains about the removal of gpiochip_enable_irq() and gpiochip_disable_irq() calls on mask and unmask callbacks. The core gpiolib relies on the FLAG_IRQ_IS_ENABLED bit to prevent changi= ng the direction of an actively unmasked IRQ line to output. Avoid the removal since sashiko is correct here. Changes in v2: - Use imperative tone on commit message when talking about solution. - Add missing 'mt7621_gpio_remove()' call on driver's remove path. drivers/gpio/gpio-mt7621.c | 282 ++++++++++++++++++++++++++++--------- 1 file changed, 216 insertions(+), 66 deletions(-) diff --git a/drivers/gpio/gpio-mt7621.c b/drivers/gpio/gpio-mt7621.c index 91230be51587..a814885ccd5d 100644 --- a/drivers/gpio/gpio-mt7621.c +++ b/drivers/gpio/gpio-mt7621.c @@ -29,8 +29,8 @@ #define GPIO_REG_EDGE 0xA0 =20 struct mtk_gc { - struct irq_chip irq_chip; struct gpio_generic_chip chip; + struct mtk *parent_priv; int bank; u32 rising; u32 falling; @@ -41,20 +41,32 @@ struct mtk_gc { /** * struct mtk - state container for * data of the platform driver. It is 3 - * separate gpio-chip each one with its - * own irq_chip. - * @dev: device instance + * separate gpio-chip having an IRQ + * linear domain shared for all of them + * @pdev: platform device instance * @base: memory base address + * @irq_domain: IRQ linear domain shared across the three gpio chips * @gpio_irq: irq number from the device tree + * @num_gpios: total number of gpio pins on the three gpio chips * @gc_map: array of the gpio chips */ struct mtk { - struct device *dev; + struct platform_device *pdev; void __iomem *base; + struct irq_domain *irq_domain; int gpio_irq; + int num_gpios; struct mtk_gc gc_map[MTK_BANK_CNT]; }; =20 +static inline struct mtk * +mt7621_gpio_gc_to_priv(struct gpio_chip *gc) +{ + struct mtk_gc *bank =3D gpiochip_get_data(gc); + + return bank->parent_priv; +} + static inline struct mtk_gc * to_mediatek_gpio(struct gpio_chip *chip) { @@ -67,7 +79,7 @@ static inline void mtk_gpio_w32(struct mtk_gc *rg, u32 offset, u32 val) { struct gpio_chip *gc =3D &rg->chip.gc; - struct mtk *mtk =3D gpiochip_get_data(gc); + struct mtk *mtk =3D mt7621_gpio_gc_to_priv(gc); =20 offset =3D (rg->bank * GPIO_BANK_STRIDE) + offset; gpio_generic_write_reg(&rg->chip, mtk->base + offset, val); @@ -77,41 +89,62 @@ static inline u32 mtk_gpio_r32(struct mtk_gc *rg, u32 offset) { struct gpio_chip *gc =3D &rg->chip.gc; - struct mtk *mtk =3D gpiochip_get_data(gc); + struct mtk *mtk =3D mt7621_gpio_gc_to_priv(gc); =20 offset =3D (rg->bank * GPIO_BANK_STRIDE) + offset; return gpio_generic_read_reg(&rg->chip, mtk->base + offset); } =20 -static irqreturn_t -mediatek_gpio_irq_handler(int irq, void *data) +static void +mt7621_gpio_irq_bank_handler(struct mtk_gc *bank) { - struct gpio_chip *gc =3D data; - struct mtk_gc *rg =3D to_mediatek_gpio(gc); - irqreturn_t ret =3D IRQ_NONE; + struct mtk *priv =3D bank->parent_priv; + struct irq_domain *domain =3D priv->irq_domain; + int hwbase =3D bank->chip.gc.offset; unsigned long pending; - int bit; + unsigned int offset; + + pending =3D mtk_gpio_r32(bank, GPIO_REG_STAT); + if (!pending) + return; + + mtk_gpio_w32(bank, GPIO_REG_STAT, pending); + + for_each_set_bit(offset, &pending, MTK_BANK_WIDTH) + generic_handle_domain_irq(domain, hwbase + offset); +} + +static void +mt7621_gpio_irq_handler(struct irq_desc *desc) +{ + struct mtk *priv =3D irq_desc_get_handler_data(desc); + struct irq_chip *chip =3D irq_desc_get_chip(desc); + int i; =20 - pending =3D mtk_gpio_r32(rg, GPIO_REG_STAT); + chained_irq_enter(chip, desc); + for (i =3D 0; i < MTK_BANK_CNT; i++) { + struct mtk_gc *bank =3D &priv->gc_map[i]; =20 - for_each_set_bit(bit, &pending, MTK_BANK_WIDTH) { - generic_handle_domain_irq(gc->irq.domain, bit); - mtk_gpio_w32(rg, GPIO_REG_STAT, BIT(bit)); - ret |=3D IRQ_HANDLED; + mt7621_gpio_irq_bank_handler(bank); } + chained_irq_exit(chip, desc); +} =20 - return ret; +static int +mt7621_gpio_hwirq_to_offset(irq_hw_number_t hwirq, struct mtk_gc *bank) +{ + return hwirq - bank->chip.gc.offset; } =20 static void mediatek_gpio_irq_unmask(struct irq_data *d) { struct gpio_chip *gc =3D irq_data_get_irq_chip_data(d); - struct mtk_gc *rg =3D to_mediatek_gpio(gc); - int pin =3D d->hwirq; + struct mtk_gc *rg =3D gpiochip_get_data(gc); + u32 mask =3D mt7621_gpio_hwirq_to_offset(d->hwirq, rg); u32 rise, fall, high, low; =20 - gpiochip_enable_irq(gc, d->hwirq); + gpiochip_enable_irq(gc, mask); =20 guard(gpio_generic_lock_irqsave)(&rg->chip); =20 @@ -119,18 +152,18 @@ mediatek_gpio_irq_unmask(struct irq_data *d) fall =3D mtk_gpio_r32(rg, GPIO_REG_FEDGE); high =3D mtk_gpio_r32(rg, GPIO_REG_HLVL); low =3D mtk_gpio_r32(rg, GPIO_REG_LLVL); - mtk_gpio_w32(rg, GPIO_REG_REDGE, rise | (BIT(pin) & rg->rising)); - mtk_gpio_w32(rg, GPIO_REG_FEDGE, fall | (BIT(pin) & rg->falling)); - mtk_gpio_w32(rg, GPIO_REG_HLVL, high | (BIT(pin) & rg->hlevel)); - mtk_gpio_w32(rg, GPIO_REG_LLVL, low | (BIT(pin) & rg->llevel)); + mtk_gpio_w32(rg, GPIO_REG_REDGE, rise | (BIT(mask) & rg->rising)); + mtk_gpio_w32(rg, GPIO_REG_FEDGE, fall | (BIT(mask) & rg->falling)); + mtk_gpio_w32(rg, GPIO_REG_HLVL, high | (BIT(mask) & rg->hlevel)); + mtk_gpio_w32(rg, GPIO_REG_LLVL, low | (BIT(mask) & rg->llevel)); } =20 static void mediatek_gpio_irq_mask(struct irq_data *d) { struct gpio_chip *gc =3D irq_data_get_irq_chip_data(d); - struct mtk_gc *rg =3D to_mediatek_gpio(gc); - int pin =3D d->hwirq; + struct mtk_gc *rg =3D gpiochip_get_data(gc); + u32 mask =3D mt7621_gpio_hwirq_to_offset(d->hwirq, rg); u32 rise, fall, high, low; =20 scoped_guard(gpio_generic_lock_irqsave, &rg->chip) { @@ -138,22 +171,21 @@ mediatek_gpio_irq_mask(struct irq_data *d) fall =3D mtk_gpio_r32(rg, GPIO_REG_FEDGE); high =3D mtk_gpio_r32(rg, GPIO_REG_HLVL); low =3D mtk_gpio_r32(rg, GPIO_REG_LLVL); - mtk_gpio_w32(rg, GPIO_REG_FEDGE, fall & ~BIT(pin)); - mtk_gpio_w32(rg, GPIO_REG_REDGE, rise & ~BIT(pin)); - mtk_gpio_w32(rg, GPIO_REG_HLVL, high & ~BIT(pin)); - mtk_gpio_w32(rg, GPIO_REG_LLVL, low & ~BIT(pin)); + mtk_gpio_w32(rg, GPIO_REG_FEDGE, fall & ~BIT(mask)); + mtk_gpio_w32(rg, GPIO_REG_REDGE, rise & ~BIT(mask)); + mtk_gpio_w32(rg, GPIO_REG_HLVL, high & ~BIT(mask)); + mtk_gpio_w32(rg, GPIO_REG_LLVL, low & ~BIT(mask)); } =20 - gpiochip_disable_irq(gc, d->hwirq); + gpiochip_disable_irq(gc, mask); } =20 static int mediatek_gpio_irq_type(struct irq_data *d, unsigned int type) { struct gpio_chip *gc =3D irq_data_get_irq_chip_data(d); - struct mtk_gc *rg =3D to_mediatek_gpio(gc); - int pin =3D d->hwirq; - u32 mask =3D BIT(pin); + struct mtk_gc *rg =3D gpiochip_get_data(gc); + u32 mask =3D BIT(mt7621_gpio_hwirq_to_offset(d->hwirq, rg)); =20 if (type =3D=3D IRQ_TYPE_PROBE) { if ((rg->rising | rg->falling | @@ -190,6 +222,26 @@ mediatek_gpio_irq_type(struct irq_data *d, unsigned in= t type) return 0; } =20 +static int +mt7621_gpio_irq_reqres(struct irq_data *d) +{ + struct gpio_chip *gc =3D irq_data_get_irq_chip_data(d); + struct mtk_gc *rg =3D gpiochip_get_data(gc); + unsigned int irq =3D mt7621_gpio_hwirq_to_offset(d->hwirq, rg); + + return gpiochip_reqres_irq(gc, irq); +} + +static void +mt7621_gpio_irq_relres(struct irq_data *d) +{ + struct gpio_chip *gc =3D irq_data_get_irq_chip_data(d); + struct mtk_gc *rg =3D gpiochip_get_data(gc); + unsigned int irq =3D mt7621_gpio_hwirq_to_offset(d->hwirq, rg); + + gpiochip_relres_irq(gc, irq); +} + static int mediatek_gpio_xlate(struct gpio_chip *chip, const struct of_phandle_args *spec, u32 *flags) @@ -208,14 +260,123 @@ mediatek_gpio_xlate(struct gpio_chip *chip, =20 static const struct irq_chip mt7621_irq_chip =3D { .name =3D "mt7621-gpio", + .irq_request_resources =3D mt7621_gpio_irq_reqres, + .irq_release_resources =3D mt7621_gpio_irq_relres, .irq_mask_ack =3D mediatek_gpio_irq_mask, .irq_mask =3D mediatek_gpio_irq_mask, .irq_unmask =3D mediatek_gpio_irq_unmask, .irq_set_type =3D mediatek_gpio_irq_type, .flags =3D IRQCHIP_IMMUTABLE, - GPIOCHIP_IRQ_RESOURCE_HELPERS, +}; + +static void +mt7621_gpio_remove(struct platform_device *pdev) +{ + struct mtk *priv =3D platform_get_drvdata(pdev); + int offset, virq; + + if (priv->gpio_irq > 0) + irq_set_chained_handler_and_data(priv->gpio_irq, NULL, NULL); + + /* Remove all IRQ mappings and delete the domain */ + if (priv->irq_domain) { + for (offset =3D 0; offset < priv->num_gpios; offset++) { + virq =3D irq_find_mapping(priv->irq_domain, offset); + irq_dispose_mapping(virq); + } + irq_domain_remove(priv->irq_domain); + } +} + +static struct mtk_gc * +mt7621_gpio_hwirq_to_bank(struct mtk *priv, irq_hw_number_t hwirq) +{ + int i; + + for (i =3D 0; i < MTK_BANK_CNT; i++) { + struct mtk_gc *bank =3D &priv->gc_map[i]; + + if (hwirq >=3D bank->chip.gc.offset && + hwirq < (bank->chip.gc.offset + bank->chip.gc.ngpio)) + return bank; + } + + return NULL; +} + +static int +mt7621_gpio_irq_map(struct irq_domain *d, unsigned int irq, + irq_hw_number_t hwirq) +{ + struct mtk *priv =3D d->host_data; + struct mtk_gc *bank =3D mt7621_gpio_hwirq_to_bank(priv, hwirq); + struct platform_device *pdev =3D priv->pdev; + int ret; + + if (!bank) + return -EINVAL; + + dev_dbg(&pdev->dev, "Mapping irq %d for gpio line %d (bank %d)\n", + irq, (int)hwirq, bank->bank); + + ret =3D irq_set_chip_data(irq, &bank->chip.gc); + if (ret < 0) + return ret; + + irq_set_chip_and_handler(irq, &mt7621_irq_chip, handle_simple_irq); + irq_set_noprobe(irq); + + return 0; +} + +static void +mt7621_gpio_irq_unmap(struct irq_domain *d, unsigned int irq) +{ + irq_set_chip_and_handler(irq, NULL, NULL); + irq_set_chip_data(irq, NULL); +} + +static const struct irq_domain_ops mt7621_gpio_irq_domain_ops =3D { + .map =3D mt7621_gpio_irq_map, + .unmap =3D mt7621_gpio_irq_unmap, + .xlate =3D irq_domain_xlate_twocell, }; =20 +static int +mt7621_gpio_irq_setup(struct platform_device *pdev, + struct mtk *priv) +{ + struct device *dev =3D &pdev->dev; + + priv->irq_domain =3D irq_domain_create_linear(dev_fwnode(dev), + priv->num_gpios, + &mt7621_gpio_irq_domain_ops, + priv); + if (!priv->irq_domain) { + dev_err(dev, "Couldn't allocate IRQ domain\n"); + return -ENXIO; + } + + irq_set_chained_handler_and_data(priv->gpio_irq, + mt7621_gpio_irq_handler, priv); + irq_set_status_flags(priv->gpio_irq, IRQ_DISABLE_UNLAZY); + + return 0; +} + +static int +mt7621_gpio_to_irq(struct gpio_chip *gc, unsigned int offset) +{ + struct mtk *priv =3D mt7621_gpio_gc_to_priv(gc); + /* gc_offset is relative to this gpio_chip; want real offset */ + int hwirq =3D offset + gc->offset; + + if (hwirq >=3D priv->num_gpios) + return -ENXIO; + + return irq_create_mapping(priv->irq_domain, hwirq); +} + static int mediatek_gpio_bank_probe(struct device *dev, int bank) { @@ -228,6 +389,7 @@ mediatek_gpio_bank_probe(struct device *dev, int bank) rg =3D &mtk->gc_map[bank]; memset(rg, 0, sizeof(*rg)); =20 + rg->parent_priv =3D mtk; rg->bank =3D bank; =20 dat =3D mtk->base + GPIO_REG_DATA + (rg->bank * GPIO_BANK_STRIDE); @@ -253,41 +415,17 @@ mediatek_gpio_bank_probe(struct device *dev, int bank) =20 rg->chip.gc.of_gpio_n_cells =3D 2; rg->chip.gc.of_xlate =3D mediatek_gpio_xlate; + rg->chip.gc.ngpio =3D MTK_BANK_WIDTH; rg->chip.gc.label =3D devm_kasprintf(dev, GFP_KERNEL, "%s-bank%d", dev_name(dev), bank); if (!rg->chip.gc.label) return -ENOMEM; =20 rg->chip.gc.offset =3D bank * MTK_BANK_WIDTH; + if (mtk->gpio_irq > 0) + rg->chip.gc.to_irq =3D mt7621_gpio_to_irq; =20 - if (mtk->gpio_irq) { - struct gpio_irq_chip *girq; - - /* - * Directly request the irq here instead of passing - * a flow-handler because the irq is shared. - */ - ret =3D devm_request_irq(dev, mtk->gpio_irq, - mediatek_gpio_irq_handler, IRQF_SHARED, - rg->chip.gc.label, &rg->chip.gc); - - if (ret) { - dev_err(dev, "Error requesting IRQ %d: %d\n", - mtk->gpio_irq, ret); - return ret; - } - - girq =3D &rg->chip.gc.irq; - gpio_irq_chip_set_chip(girq, &mt7621_irq_chip); - /* This will let us handle the parent IRQ in the driver */ - girq->parent_handler =3D NULL; - girq->num_parents =3D 0; - girq->parents =3D NULL; - girq->default_type =3D IRQ_TYPE_NONE; - girq->handler =3D handle_simple_irq; - } - - ret =3D devm_gpiochip_add_data(dev, &rg->chip.gc, mtk); + ret =3D devm_gpiochip_add_data(dev, &rg->chip.gc, rg); if (ret < 0) { dev_err(dev, "Could not register gpio %d, ret=3D%d\n", rg->chip.gc.ngpio, ret); @@ -322,7 +460,8 @@ mediatek_gpio_probe(struct platform_device *pdev) if (mtk->gpio_irq < 0) return mtk->gpio_irq; =20 - mtk->dev =3D dev; + mtk->pdev =3D pdev; + mtk->num_gpios =3D MTK_BANK_WIDTH * MTK_BANK_CNT; platform_set_drvdata(pdev, mtk); =20 for (i =3D 0; i < MTK_BANK_CNT; i++) { @@ -331,7 +470,17 @@ mediatek_gpio_probe(struct platform_device *pdev) return ret; } =20 + if (mtk->gpio_irq > 0) { + ret =3D mt7621_gpio_irq_setup(pdev, mtk); + if (ret) + goto fail; + } + return 0; + +fail: + mt7621_gpio_remove(pdev); + return ret; } =20 static const struct of_device_id mediatek_gpio_match[] =3D { @@ -342,6 +491,7 @@ MODULE_DEVICE_TABLE(of, mediatek_gpio_match); =20 static struct platform_driver mediatek_gpio_driver =3D { .probe =3D mediatek_gpio_probe, + .remove =3D mt7621_gpio_remove, .driver =3D { .name =3D "mt7621_gpio", .of_match_table =3D mediatek_gpio_match, --=20 2.43.0