From: Herve Codina <herve.codina@bootlin.com>
To: Hoan Tran <hoan@os.amperecomputing.com>,
Linus Walleij <linus.walleij@linaro.org>,
Bartosz Golaszewski <brgl@bgdev.pl>,
Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>,
Geert Uytterhoeven <geert+renesas@glider.be>,
Magnus Damm <magnus.damm@gmail.com>,
Saravana Kannan <saravanak@google.com>,
Serge Semin <fancer.lancer@gmail.com>,
Herve Codina <herve.codina@bootlin.com>
Cc: Phil Edworthy <phil.edworthy@renesas.com>,
linux-gpio@vger.kernel.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org, linux-renesas-soc@vger.kernel.org,
Miquel Raynal <miquel.raynal@bootlin.com>,
Thomas Petazzoni <thomas.petazzoni@bootlin.com>
Subject: [PATCH 4/6] of/irq: Introduce of_irq_foreach_imap
Date: Fri, 25 Jul 2025 17:26:13 +0200 [thread overview]
Message-ID: <20250725152618.32886-5-herve.codina@bootlin.com> (raw)
In-Reply-To: <20250725152618.32886-1-herve.codina@bootlin.com>
of_irq_foreach_imap is an iterator designed to help a driver to parse
an interrupt-map property.
Indeed some drivers need to know details about the interrupt mapping
described in the device-tree in order to set internal registers
accordingly.
Signed-off-by: Herve Codina <herve.codina@bootlin.com>
---
drivers/of/irq.c | 70 ++++++++++++++++++++++++++++++++++++++++++
include/linux/of_irq.h | 11 +++++++
2 files changed, 81 insertions(+)
diff --git a/drivers/of/irq.c b/drivers/of/irq.c
index f8ad79b9b1c9..863b31eb3c1a 100644
--- a/drivers/of/irq.c
+++ b/drivers/of/irq.c
@@ -157,6 +157,76 @@ const __be32 *of_irq_parse_imap_parent(const __be32 *imap, int len, struct of_ph
return imap;
}
+/**
+ * of_irq_foreach_imap - Iterate through interrupt-map items
+ * @np: device node where interrupt-map is available
+ * @func: function called on each interrupt-map items
+ * @data: data passe to @func
+ *
+ * This function iterates through interrupt-map items and calls @func on each
+ * item. The parent interrupt described in the interrupt-map item is parsed
+ * and passed to @func using a pointer to a struct of_phandle_args.
+ * Also the imap raw value is passed in order to allow @func to look at other
+ * values of the interrupt-map (child unit address and child interrupt
+ * specificer)
+ *
+ * If @func returns an error, the iteration stops and this error is returned.
+ */
+int of_irq_foreach_imap(struct device_node *np,
+ int (*func)(void *data,
+ const __be32 *imap,
+ const struct of_phandle_args *parent_args),
+ void *data)
+{
+ const __be32 *imap, *imap_end, *imap_parent, *imap_next;
+ struct of_phandle_args parent_args;
+ u32 tmp, parent_offset;
+ int imaplen;
+ int ret;
+
+ /*
+ * parent_offset is the offset where the parent part is starting.
+ * In other words, the offset where the parent interrupt controller
+ * phandle is present.
+ *
+ * Compute this offset (child #interrupt-cells + child #address-cells)
+ */
+ parent_offset = of_bus_n_addr_cells(np);
+
+ ret = of_property_read_u32(np, "#interrupt-cells", &tmp);
+ if (ret)
+ return ret;
+
+ parent_offset += tmp;
+
+ imap = of_get_property(np, "interrupt-map", &imaplen);
+ if (!imap)
+ return -ENOENT;
+
+ imaplen /= sizeof(*imap);
+ imap_end = imap + imaplen;
+
+ while (imap + parent_offset + 1 < imap_end) {
+ imap_parent = imap + parent_offset;
+
+ imap_next = of_irq_parse_imap_parent(imap_parent,
+ imap_end - imap_parent,
+ &parent_args);
+ if (!imap_next)
+ return -EINVAL;
+
+ ret = func(data, imap, &parent_args);
+ of_node_put(parent_args.np);
+ if (ret)
+ return ret;
+
+ imap = imap_next;
+ }
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(of_irq_foreach_imap);
+
/**
* of_irq_parse_raw - Low level interrupt tree parsing
* @addr: address specifier (start of "reg" property of the device) in be32 format
diff --git a/include/linux/of_irq.h b/include/linux/of_irq.h
index 6337ad4e5fe8..b89920c6ab55 100644
--- a/include/linux/of_irq.h
+++ b/include/linux/of_irq.h
@@ -47,6 +47,10 @@ extern int of_irq_get_byname(struct device_node *dev, const char *name);
extern int of_irq_to_resource_table(struct device_node *dev,
struct resource *res, int nr_irqs);
extern struct device_node *of_irq_find_parent(struct device_node *child);
+extern int of_irq_foreach_imap(struct device_node *np,
+ int (*func)(void *data, const __be32 *imap,
+ const struct of_phandle_args *parent_args),
+ void *data);
extern struct irq_domain *of_msi_get_domain(struct device *dev,
const struct device_node *np,
enum irq_domain_bus_token token);
@@ -85,6 +89,13 @@ static inline void *of_irq_find_parent(struct device_node *child)
{
return NULL;
}
+static inline int of_irq_foreach_imap(struct device_node *np,
+ int (*func)(void *data, const __be32 *imap,
+ const struct of_phandle_args *parent_args),
+ void *data)
+{
+ return -EINVAL;
+}
static inline struct irq_domain *of_msi_get_domain(struct device *dev,
struct device_node *np,
--
2.50.1
next prev parent reply other threads:[~2025-07-25 15:26 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-25 15:26 [PATCH 0/6] gpio: renesas: Add support for GPIO and related interrupts in RZ/N1 SoC Herve Codina
2025-07-25 15:26 ` [PATCH 1/6] dt-bindings: gpio: snps,dw-apb: Add support for Renesas RZ/N1 Herve Codina
2025-07-29 18:11 ` Rob Herring
2025-07-30 9:17 ` Herve Codina
2025-07-25 15:26 ` [PATCH 2/6] ARM: dts: r9a06g032: Add GPIO controllers Herve Codina
2025-07-25 15:26 ` [PATCH 3/6] dt-bindings: soc: renesas: Add the Renesas RZ/N1 GPIO Interrupt Multiplexer Herve Codina
2025-07-25 15:26 ` Herve Codina [this message]
2025-07-29 19:51 ` [PATCH 4/6] of/irq: Introduce of_irq_foreach_imap Rob Herring
2025-07-30 9:43 ` Herve Codina
2025-07-25 15:26 ` [PATCH 5/6] soc: renesas: Add support for Renesas RZ/N1 GPIO Interrupt Multiplexer Herve Codina
2025-07-29 19:51 ` Rob Herring
2025-07-30 9:54 ` Herve Codina
2025-07-30 20:47 ` Rob Herring
2025-08-01 9:17 ` Herve Codina
2025-07-25 15:26 ` [PATCH 6/6] ARM: dts: r9a06g032: Add support for GPIO interrupts Herve Codina
2025-07-25 20:17 ` [PATCH 0/6] gpio: renesas: Add support for GPIO and related interrupts in RZ/N1 SoC Rob Herring (Arm)
2025-07-27 11:01 ` Wolfram Sang
2025-07-30 8:10 ` Herve Codina
2025-08-06 18:51 ` Wolfram Sang
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=20250725152618.32886-5-herve.codina@bootlin.com \
--to=herve.codina@bootlin.com \
--cc=brgl@bgdev.pl \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=fancer.lancer@gmail.com \
--cc=geert+renesas@glider.be \
--cc=hoan@os.amperecomputing.com \
--cc=krzk+dt@kernel.org \
--cc=linus.walleij@linaro.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-renesas-soc@vger.kernel.org \
--cc=magnus.damm@gmail.com \
--cc=miquel.raynal@bootlin.com \
--cc=phil.edworthy@renesas.com \
--cc=robh@kernel.org \
--cc=saravanak@google.com \
--cc=thomas.petazzoni@bootlin.com \
/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
all inboxes | Powered by JetHome®