From: Yixun Lan <dlan@gentoo.org>
To: Linus Walleij <linus.walleij@linaro.org>,
Bartosz Golaszewski <brgl@bgdev.pl>,
Thomas Gleixner <tglx@linutronix.de>
Cc: Alex Elder <elder@riscstar.com>,
Inochi Amaoto <inochiama@gmail.com>,
linux-kernel@vger.kernel.org, linux-gpio@vger.kernel.org,
linux-riscv@lists.infradead.org, spacemit@lists.linux.dev
Subject: Re: [PATCH v2 2/2] gpiolib: support parsing gpio three-cell interrupts scheme
Date: Sat, 1 Mar 2025 23:29:44 +0000 [thread overview]
Message-ID: <20250301232944-GYA55471@gentoo> (raw)
In-Reply-To: <20250302-04-gpio-irq-threecell-v2-2-34f13ad37ea4@gentoo.org>
Hi Linus, Thomas:
On 07:15 Sun 02 Mar , Yixun Lan wrote:
> gpio irq which using three-cell scheme should always call
> instance_match() function to find the correct irqdomain.
>
> The select() function will be called with !DOMAIN_BUS_ANY,
> so for specific gpio irq driver, it need to set bus token
> explicitly, something like:
> irq_domain_update_bus_token(girq->domain, DOMAIN_BUS_WIRED);
>
> Signed-off-by: Yixun Lan <dlan@gentoo.org>
> ---
> drivers/gpio/gpiolib-of.c | 8 ++++++++
> drivers/gpio/gpiolib-of.h | 6 ++++++
> drivers/gpio/gpiolib.c | 23 +++++++++++++++++++----
> 3 files changed, 33 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c
> index 2e537ee979f3e2b6e8d5f86f3e121a66f2a8e083..e19904569fb1b71c1fff237132d17050ef02b074 100644
> --- a/drivers/gpio/gpiolib-of.c
> +++ b/drivers/gpio/gpiolib-of.c
> @@ -1187,3 +1187,11 @@ void of_gpiochip_remove(struct gpio_chip *chip)
> {
> of_node_put(dev_of_node(&chip->gpiodev->dev));
> }
> +
> +bool of_gpiochip_instance_match(struct gpio_chip *gc, unsigned int index)
> +{
> + if (gc->of_node_instance_match)
> + return gc->of_node_instance_match(gc, index);
> +
> + return false;
> +}
> diff --git a/drivers/gpio/gpiolib-of.h b/drivers/gpio/gpiolib-of.h
> index 16d6ac8cb156c02232ea868b755bbdc46c78e3c7..3eebfac290c571e3b90e4437295db8eaacb021a3 100644
> --- a/drivers/gpio/gpiolib-of.h
> +++ b/drivers/gpio/gpiolib-of.h
> @@ -22,6 +22,7 @@ struct gpio_desc *of_find_gpio(struct device_node *np,
> unsigned long *lookupflags);
> int of_gpiochip_add(struct gpio_chip *gc);
> void of_gpiochip_remove(struct gpio_chip *gc);
> +bool of_gpiochip_instance_match(struct gpio_chip *gc, unsigned int index);
> int of_gpio_count(const struct fwnode_handle *fwnode, const char *con_id);
> #else
> static inline struct gpio_desc *of_find_gpio(struct device_node *np,
> @@ -33,6 +34,11 @@ static inline struct gpio_desc *of_find_gpio(struct device_node *np,
> }
> static inline int of_gpiochip_add(struct gpio_chip *gc) { return 0; }
> static inline void of_gpiochip_remove(struct gpio_chip *gc) { }
> +static inline bool of_gpiochip_instance_match(struct gpio_chip *gc,
> + unsigned int index)
> +{
> + return false;
> +}
> static inline int of_gpio_count(const struct fwnode_handle *fwnode,
> const char *con_id)
> {
> diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
> index 679ed764cb143c4b3357106de1570e8d38441372..266be465b9103c17861a0d76f2dfbf1f1de3a073 100644
> --- a/drivers/gpio/gpiolib.c
> +++ b/drivers/gpio/gpiolib.c
> @@ -1449,10 +1449,9 @@ static int gpiochip_hierarchy_irq_domain_translate(struct irq_domain *d,
> unsigned long *hwirq,
> unsigned int *type)
> {
> - /* We support standard DT translation */
> - if (is_of_node(fwspec->fwnode) && fwspec->param_count == 2) {
> - return irq_domain_translate_twocell(d, fwspec, hwirq, type);
> - }
> + /* We support standard DT translation up to three cells */
> + if (is_of_node(fwspec->fwnode))
> + return irq_domain_translate_cells(d, fwspec, hwirq, type);
I'm not sure if you like this way for calling generic cells parser here,
as it should work for 1, 2, 3 cells model, which save a few lines meanwhile
otherwise we end something like
if (is_of_node(fwspec->fwnode) {
if (fwspec->param_count == 2) {
return irq_domain_translate_twocell(d, fwspec, hwirq, type);
if (fwspec->param_count == 3) {
return irq_domain_translate_threecell(d, fwspec, hwirq, type);
}
>
> /* This is for board files and others not using DT */
> if (is_fwnode_irqchip(fwspec->fwnode)) {
> @@ -1754,9 +1753,25 @@ static void gpiochip_irq_unmap(struct irq_domain *d, unsigned int irq)
> irq_set_chip_data(irq, NULL);
> }
>
> +static int gpiochip_irq_select(struct irq_domain *d, struct irq_fwspec *fwspec,
> + enum irq_domain_bus_token bus_token)
> +{
> + struct fwnode_handle *fwnode = fwspec->fwnode;
> + struct gpio_chip *gc = d->host_data;
> + unsigned int index = fwspec->param[0];
> +
> + if (fwspec->param_count == 3 && is_of_node(fwnode))
> + return of_gpiochip_instance_match(gc, index);
> +
> + /* Fallback for twocells */
> + return ((fwnode != NULL) && (d->fwnode == fwnode) &&
> + (d->bus_token == bus_token));
> +}
> +
> static const struct irq_domain_ops gpiochip_domain_ops = {
> .map = gpiochip_irq_map,
> .unmap = gpiochip_irq_unmap,
> + .select = gpiochip_irq_select,
> /* Virtually all GPIO irqchips are twocell:ed */
> .xlate = irq_domain_xlate_twocell,
> };
>
> --
> 2.48.1
>
--
Yixun Lan (dlan)
Gentoo Linux Developer
GPG Key ID AABEFD55
next prev parent reply other threads:[~2025-03-01 23:29 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-01 23:15 [PATCH v2 0/2] gpio: irq: support describing three-cell interrupts Yixun Lan
2025-03-01 23:15 ` [PATCH v2 1/2] irqdomain: support three-cell scheme interrupts Yixun Lan
2025-03-02 18:30 ` Thomas Gleixner
2025-03-03 12:40 ` Yixun Lan
2025-03-04 7:31 ` Linus Walleij
2025-03-04 7:39 ` Yixun Lan
2025-03-25 9:51 ` Yixun Lan
2025-03-01 23:15 ` [PATCH v2 2/2] gpiolib: support parsing gpio three-cell interrupts scheme Yixun Lan
2025-03-01 23:29 ` Yixun Lan [this message]
2025-03-04 7:40 ` Linus Walleij
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=20250301232944-GYA55471@gentoo \
--to=dlan@gentoo.org \
--cc=brgl@bgdev.pl \
--cc=elder@riscstar.com \
--cc=inochiama@gmail.com \
--cc=linus.walleij@linaro.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=spacemit@lists.linux.dev \
--cc=tglx@linutronix.de \
/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