[PATCH v4] gpiolib: support parsing gpio three-cell interrupts scheme
Alex Elder
elder at riscstar.com
Tue Apr 8 09:05:15 PDT 2025
On 4/8/25 10:11 AM, 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 at gentoo.org>
> ---
> In this patch [1], the GPIO controller add support for describing
> hardware with a three-cell scheme:
>
> gpios = <&gpio instance offset flags>;
>
> It also result describing interrupts in three-cell as this in DT:
>
> node {
> interrupt-parent = <&gpio>;
> interrupts = <instance hwirq irqflag>;
> }
>
> This series try to extend describing interrupts with three-cell scheme.
>
> The first patch will add capability for parsing irq number and flag
> from last two cells which eventually will support the three-cells
> interrupt, the second patch support finding irqdomain according to
> interrupt instance index.
Did you intend to send more than just one patch? -Alex
>
> Link: https://lore.kernel.org/all/20250225-gpio-ranges-fourcell-v3-0-860382ba4713@linaro.org [1]
> ---
> Changes in v4:
> - rebase patch [2/2] to gpio's for-next branch, no changes
> - drop [1/2] of patch v3 which merged into irq tree
> - Link to v3: https://lore.kernel.org/r/20250326-04-gpio-irq-threecell-v3-0-aab006ab0e00@gentoo.org
>
> Changes in v3:
> - explicitly introduce *_twothreecell() to support 3 cell interrupt
> - Link to v2: https://lore.kernel.org/r/20250302-04-gpio-irq-threecell-v2-0-34f13ad37ea4@gentoo.org
>
> Changes in v2:
> - introduce generic irq_domain_translate_cells(), other inline cells function
> - hide the OF-specific things into gpiolib-of.c|h
> - Link to v1: https://lore.kernel.org/r/20250227-04-gpio-irq-threecell-v1-0-4ae4d91baadc@gentoo.org
> ---
> drivers/gpio/gpiolib-of.c | 8 ++++++++
> drivers/gpio/gpiolib-of.h | 6 ++++++
> drivers/gpio/gpiolib.c | 22 ++++++++++++++++++----
> 3 files changed, 32 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c
> index f29143c71e9db61a6ad6d45d64e88a3f3f2d4fa7..3651c4178b81a1346809ec43b91a532e9f48af2b 100644
> --- a/drivers/gpio/gpiolib-of.c
> +++ b/drivers/gpio/gpiolib-of.c
> @@ -1285,3 +1285,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 8252a671d7208105a315bdc914acb092d5f95e79..ed8397a88dea1d92c3d4cb3cc9a6b30be29d31f6 100644
> --- a/drivers/gpio/gpiolib.c
> +++ b/drivers/gpio/gpiolib.c
> @@ -1507,9 +1507,8 @@ static int gpiochip_hierarchy_irq_domain_translate(struct irq_domain *d,
> 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);
> - }
> + if (is_of_node(fwspec->fwnode))
> + return irq_domain_translate_twothreecell(d, fwspec, hwirq, type);
>
> /* This is for board files and others not using DT */
> if (is_fwnode_irqchip(fwspec->fwnode)) {
> @@ -1811,11 +1810,26 @@ 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 && (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,
> + .xlate = irq_domain_xlate_twothreecell,
> };
>
> static struct irq_domain *gpiochip_simple_create_domain(struct gpio_chip *gc)
>
> ---
> base-commit: 9ed74dfa0822ba58eacaec61fb16bd4feb34a5a6
> change-id: 20250227-04-gpio-irq-threecell-66e1e073c806
>
> Best regards,
More information about the linux-riscv
mailing list