Commit 27986833 authored by Yixun Lan's avatar Yixun Lan Committed by Bartosz Golaszewski
Browse files

gpiolib: support parsing gpio three-cell interrupts scheme



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: default avatarYixun Lan <dlan@gentoo.org>
Link: https://lore.kernel.org/r/20250408-04-gpio-irq-threecell-v4-1-fd170d5e2d2b@gentoo.org


Signed-off-by: default avatarBartosz Golaszewski <bartosz.golaszewski@linaro.org>
parent 9ed74dfa
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -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;
}
+6 −0
Original line number Diff line number Diff line
@@ -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)
{
+18 −4
Original line number Diff line number Diff line
@@ -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)