From: Miao Wang via B4 Relay <devnull+shankerwangmiao.gmail.com@kernel.org>
To: Yinbo Zhu <zhuyinbo@loongson.cn>,
Linus Walleij <linusw@kernel.org>,
Bartosz Golaszewski <brgl@kernel.org>
Cc: Jiaxun Yang <jiaxun.yang@flygoat.com>,
linux-gpio@vger.kernel.org,
Miao Wang <shankerwangmiao@gmail.com>
Subject: [PATCH RFC 1/4] gpio: loongson-64bit: Support for irq controller on 2k2000 and 7a2000
Date: Sat, 26 Sep 2026 00:28:36 +0800 [thread overview]
Message-ID: <20260926-loongsongpio-v1-1-71de7ebebb76@gmail.com> (raw)
In-Reply-To: <20260926-loongsongpio-v1-0-71de7ebebb76@gmail.com>
From: Miao Wang <shankerwangmiao@gmail.com>
According to the User Manual, the GPIO controllers on 2K2000 and 7A2000
include irq controllers, which are similar to those on 2K0300, except
for the support for edge-triggered interrupts on both edges.
This patch makes the requirement for intdual register optional and
links the irq controller to the GPIO controller for 2K2000 and 7A2000.
To make the change compatiable with possible existing firmware code for
2K2000 and 7A2000, the initialization of the irq controller will not
fail when not given enough firmware IRQs. Instead, it will only
initialize the irq controller with the available firmware IRQs.
Signed-off-by: Miao Wang <shankerwangmiao@gmail.com>
---
drivers/gpio/gpio-loongson-64bit.c | 32 ++++++++++++++++++++++++++++----
1 file changed, 28 insertions(+), 4 deletions(-)
diff --git a/drivers/gpio/gpio-loongson-64bit.c b/drivers/gpio/gpio-loongson-64bit.c
index 0fdf15faa344d2db0a1cf52dc52c3f58aabef49c..64eb9f46ce31cc289f236af44311ff39f05de3b0 100644
--- a/drivers/gpio/gpio-loongson-64bit.c
+++ b/drivers/gpio/gpio-loongson-64bit.c
@@ -183,6 +183,8 @@ static int loongson_gpio_irq_set_type(struct irq_data *data, unsigned int type)
u8 pol = 0, edge = 0, dual = 0;
if ((type & IRQ_TYPE_SENSE_MASK) == IRQ_TYPE_EDGE_BOTH) {
+ if (!lgpio->chip_data->intdual_offset)
+ return -EINVAL;
edge = 1;
dual = 1;
irq_set_handler_locked(data, handle_edge_irq);
@@ -210,7 +212,8 @@ static int loongson_gpio_irq_set_type(struct irq_data *data, unsigned int type)
writeb(pol, lgpio->reg_base + lgpio->chip_data->intpol_offset + hwirq);
writeb(edge, lgpio->reg_base + lgpio->chip_data->intedge_offset + hwirq);
- writeb(dual, lgpio->reg_base + lgpio->chip_data->intdual_offset + hwirq);
+ if (lgpio->chip_data->intdual_offset)
+ writeb(dual, lgpio->reg_base + lgpio->chip_data->intdual_offset + hwirq);
return 0;
}
@@ -260,7 +263,7 @@ static int loongson_gpio_init_irqchip(struct platform_device *pdev,
chip->irq.parent_handler_data = lgpio;
gpio_irq_chip_set_chip(&chip->irq, data->girqchip);
- chip->irq.num_parents = data->intr_num;
+ chip->irq.num_parents = 0;
chip->irq.parents = devm_kcalloc(&pdev->dev, data->intr_num,
sizeof(*chip->irq.parents), GFP_KERNEL);
if (!chip->irq.parents)
@@ -269,11 +272,13 @@ static int loongson_gpio_init_irqchip(struct platform_device *pdev,
for (i = 0; i < data->intr_num; i++) {
int ret;
- ret = platform_get_irq(pdev, i);
+ ret = platform_get_irq_optional(pdev, i);
+ if (ret == -ENXIO)
+ continue;
if (ret < 0)
return dev_err_probe(&pdev->dev, ret,
"failed to get IRQ %d\n", i);
- chip->irq.parents[i] = ret;
+ chip->irq.parents[chip->irq.num_parents++] = ret;
}
for (i = 0; i < data->intr_num; i++) {
@@ -281,6 +286,11 @@ static int loongson_gpio_init_irqchip(struct platform_device *pdev,
writeb(0x1, lgpio->reg_base + data->intclr_offset + i);
}
+ if (chip->irq.num_parents == 0) {
+ dev_warn(&pdev->dev, "no parent IRQs have been found, GPIO IRQs will not be available\n");
+ gpio_irq_chip_set_chip(&chip->irq, NULL);
+ }
+
return 0;
}
@@ -413,6 +423,13 @@ static const struct loongson_gpio_chip_data loongson_gpio_ls2k2000_data1 = {
.in_offset = 0xa00,
.out_offset = 0x900,
.inten_offset = 0xb00,
+ .intpol_offset = 0xc00,
+ .intedge_offset = 0xd00,
+ .intclr_offset = 0xe00,
+ .intsts_offset = 0xf00,
+ .intr_num = 8,
+ .irq_handler = loongson_gpio_ls2k0300_irq_handler,
+ .girqchip = &loongson_gpio_ls2k0300_irqchip,
};
static const struct loongson_gpio_chip_data loongson_gpio_ls2k2000_data2 = {
@@ -449,6 +466,13 @@ static const struct loongson_gpio_chip_data loongson_gpio_ls7a2000_data0 = {
.in_offset = 0xa00,
.out_offset = 0x900,
.inten_offset = 0xb00,
+ .intpol_offset = 0xc00,
+ .intedge_offset = 0xd00,
+ .intclr_offset = 0xe00,
+ .intsts_offset = 0xf00,
+ .intr_num = 5,
+ .irq_handler = loongson_gpio_ls2k0300_irq_handler,
+ .girqchip = &loongson_gpio_ls2k0300_irqchip,
};
/* LS7A2000 ACPI GPIO */
--
2.55.0
next prev parent reply other threads:[~2026-09-25 16:28 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-25 16:28 [PATCH RFC 0/4] gpio: loongson-64bit: add interrupt support for more models Miao Wang via B4 Relay
2026-09-25 16:28 ` Miao Wang via B4 Relay [this message]
2026-09-25 16:28 ` [PATCH RFC 2/4] gpio: loongson-64bit: Generalize interrupt controller initialization Miao Wang via B4 Relay
2026-09-25 16:28 ` [PATCH RFC 3/4] gpio: loongson-64bit: Add shared interrupt support Miao Wang via B4 Relay
2026-10-01 8:33 ` Linus Walleij
2026-10-01 8:59 ` Miao Wang
2026-10-01 11:54 ` Linus Walleij
2026-10-01 17:47 ` Miao Wang
2026-10-01 19:43 ` Linus Walleij
2026-10-02 4:03 ` Miao Wang
2026-09-25 16:28 ` [PATCH RFC 4/4] gpio: loongson-64bit: remove gpio_to_irq() handler Miao Wang via B4 Relay
2026-09-29 13:01 ` [PATCH RFC 0/4] gpio: loongson-64bit: add interrupt support for more models Bartosz Golaszewski
2026-09-29 13:18 ` Miao Wang
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=20260926-loongsongpio-v1-1-71de7ebebb76@gmail.com \
--to=devnull+shankerwangmiao.gmail.com@kernel.org \
--cc=brgl@kernel.org \
--cc=jiaxun.yang@flygoat.com \
--cc=linusw@kernel.org \
--cc=linux-gpio@vger.kernel.org \
--cc=shankerwangmiao@gmail.com \
--cc=zhuyinbo@loongson.cn \
/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