Renesas driver updates for v6.20 (take two)

- Add and use for_each_of_imap_item() iterator,
   - Add support for the RZ/N1 GPIO Interrupt Multiplexer.
 -----BEGIN PGP SIGNATURE-----
 
 iHUEABYKAB0WIQQ9qaHoIs/1I4cXmEiKwlD9ZEnxcAUCaWoQbwAKCRCKwlD9ZEnx
 cNnkAQCoPH8r7D2mdA7Uq3LoE3I/f1ewzPt9Dn0lBI73h4PUvwEAjuq3gbtrfvLU
 1s+/9Bf6qjeMcuROWYnAQwqGSxfZ/AA=
 =61rJ
 -----END PGP SIGNATURE-----
gpgsig -----BEGIN PGP SIGNATURE-----
 
 iQIzBAABCgAdFiEEo6/YBQwIrVS28WGKmmx57+YAGNkFAmlw79MACgkQmmx57+YA
 GNkstQ//Tw6kvvYeD1cfqlwc64J38yOm7LMUrsuJztzMZBRFckLKV3nARyhkSPAu
 0r9Jt48zYm/19+ejWeKvjn9uyiQi0lFgOsGV0sK9VIWOaTYdHgCb2NXj0NPUTcHd
 OLHX3HtYXWIEjev+gs+xkQ1Kt13ASVWlBf/Zh0TuRGNkkyn+QX/sR0ZDq7SgOfVy
 tPbpif8w5vHbX7vwDSQZ9QoSxZyluXLSjoLxPMnS0KM+pLW6E3hnnPjwU+pzRQjg
 2OQLJHF6xfPpZsCBxA8X9bElyYZ8hY19NMHXJzzyLhhs4g0ECVzSLfB0l4onlLbB
 +A1adkVFVZAEsOpHDM/AvW1IMsoP4StK9Cmi5ZL62Io5R8URf5HrOzy4xiEbJkvQ
 IIWHipqcZ2tY7bdCbUZthFvnJos5WQn5fvVlFpo/Pk2cca7Lg/VQFTmTvx7nIOgJ
 e3NlpmAQqUee5IN2uuYTpqJaYNndojTBnQOk8Eb06LtHy86uKmqFN/qUSxN/vw1D
 sw1EKpTFlKYOvKkPOmZgr3BpyCqLGg83AkFuW+iFvKFvjlABesJ7+nhx2Potdd0g
 ofFcSj3RERMPfqAIOCvnEWtvrM0TkYHK1SIPowBQZtX4IecFbTd8SrHVFOlHhQZe
 2dUGi1WLltaSLkP7GaCsXv4kL7oVoiGyvkQD2dFm0dgrNhUdEdc=
 =Duc2
 -----END PGP SIGNATURE-----

Merge tag 'renesas-drivers-for-v6.20-tag2' of git://git.kernel.org/pub/scm/linux/kernel/git/geert/renesas-devel into soc/drivers

Renesas driver updates for v6.20 (take two)

  - Add and use for_each_of_imap_item() iterator,
  - Add support for the RZ/N1 GPIO Interrupt Multiplexer.

* tag 'renesas-drivers-for-v6.20-tag2' of git://git.kernel.org/pub/scm/linux/kernel/git/geert/renesas-devel:
  soc: renesas: Add support for RZ/N1 GPIO Interrupt Multiplexer
  irqchip/renesas-rza1: Use for_each_of_imap_item iterator
  irqchip/ls-extirq: Use for_each_of_imap_item iterator
  of: unittest: Add a test case for for_each_of_imap_item iterator
  of/irq: Introduce for_each_of_imap_item

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
This commit is contained in:
Arnd Bergmann 2026-01-21 16:25:01 +01:00
commit f716774b2c
9 changed files with 400 additions and 58 deletions

View file

@ -125,45 +125,32 @@ static const struct irq_domain_ops extirq_domain_ops = {
static int
ls_extirq_parse_map(struct ls_extirq_data *priv, struct device_node *node)
{
const __be32 *map;
u32 mapsize;
struct of_imap_parser imap_parser;
struct of_imap_item imap_item;
int ret;
map = of_get_property(node, "interrupt-map", &mapsize);
if (!map)
return -ENOENT;
if (mapsize % sizeof(*map))
return -EINVAL;
mapsize /= sizeof(*map);
ret = of_imap_parser_init(&imap_parser, node, &imap_item);
if (ret)
return ret;
while (mapsize) {
for_each_of_imap_item(&imap_parser, &imap_item) {
struct device_node *ipar;
u32 hwirq, intsize, j;
u32 hwirq;
int i;
if (mapsize < 3)
return -EINVAL;
hwirq = be32_to_cpup(map);
if (hwirq >= MAXIRQ)
hwirq = imap_item.child_imap[0];
if (hwirq >= MAXIRQ) {
of_node_put(imap_item.parent_args.np);
return -EINVAL;
}
priv->nirq = max(priv->nirq, hwirq + 1);
ipar = of_find_node_by_phandle(be32_to_cpup(map + 2));
map += 3;
mapsize -= 3;
if (!ipar)
return -EINVAL;
priv->map[hwirq].fwnode = &ipar->fwnode;
ret = of_property_read_u32(ipar, "#interrupt-cells", &intsize);
if (ret)
return ret;
ipar = of_node_get(imap_item.parent_args.np);
priv->map[hwirq].fwnode = of_fwnode_handle(ipar);
if (intsize > mapsize)
return -EINVAL;
priv->map[hwirq].param_count = intsize;
for (j = 0; j < intsize; ++j)
priv->map[hwirq].param[j] = be32_to_cpup(map++);
mapsize -= intsize;
priv->map[hwirq].param_count = imap_item.parent_args.args_count;
for (i = 0; i < priv->map[hwirq].param_count; i++)
priv->map[hwirq].param[i] = imap_item.parent_args.args[i];
}
return 0;
}

View file

@ -142,47 +142,36 @@ static const struct irq_domain_ops rza1_irqc_domain_ops = {
static int rza1_irqc_parse_map(struct rza1_irqc_priv *priv,
struct device_node *gic_node)
{
struct of_imap_parser imap_parser;
struct device *dev = priv->dev;
unsigned int imaplen, i, j;
struct of_imap_item imap_item;
struct device_node *ipar;
const __be32 *imap;
u32 intsize;
unsigned int j;
u32 i = 0;
int ret;
imap = of_get_property(dev->of_node, "interrupt-map", &imaplen);
if (!imap)
return -EINVAL;
for (i = 0; i < IRQC_NUM_IRQ; i++) {
if (imaplen < 3)
return -EINVAL;
ret = of_imap_parser_init(&imap_parser, dev->of_node, &imap_item);
if (ret)
return ret;
for_each_of_imap_item(&imap_parser, &imap_item) {
/* Check interrupt number, ignore sense */
if (be32_to_cpup(imap) != i)
if (imap_item.child_imap[0] != i) {
of_node_put(imap_item.parent_args.np);
return -EINVAL;
}
ipar = of_find_node_by_phandle(be32_to_cpup(imap + 2));
ipar = imap_item.parent_args.np;
if (ipar != gic_node) {
of_node_put(ipar);
return -EINVAL;
}
imap += 3;
imaplen -= 3;
priv->map[i].args_count = imap_item.parent_args.args_count;
for (j = 0; j < priv->map[i].args_count; j++)
priv->map[i].args[j] = imap_item.parent_args.args[j];
ret = of_property_read_u32(ipar, "#interrupt-cells", &intsize);
of_node_put(ipar);
if (ret)
return ret;
if (imaplen < intsize)
return -EINVAL;
priv->map[i].args_count = intsize;
for (j = 0; j < intsize; j++)
priv->map[i].args[j] = be32_to_cpup(imap++);
imaplen -= intsize;
i++;
}
return 0;

View file

@ -157,6 +157,76 @@ const __be32 *of_irq_parse_imap_parent(const __be32 *imap, int len, struct of_ph
return imap;
}
int of_imap_parser_init(struct of_imap_parser *parser, struct device_node *node,
struct of_imap_item *item)
{
int imaplen;
u32 tmp;
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)
*/
parser->parent_offset = of_bus_n_addr_cells(node);
ret = of_property_read_u32(node, "#interrupt-cells", &tmp);
if (ret)
return ret;
parser->parent_offset += tmp;
if (WARN(parser->parent_offset > ARRAY_SIZE(item->child_imap),
"child part size = %u, cannot fit in array of %zu items",
parser->parent_offset, ARRAY_SIZE(item->child_imap)))
return -EINVAL;
parser->imap = of_get_property(node, "interrupt-map", &imaplen);
if (!parser->imap)
return -ENOENT;
imaplen /= sizeof(*parser->imap);
parser->imap_end = parser->imap + imaplen;
memset(item, 0, sizeof(*item));
item->child_imap_count = parser->parent_offset;
return 0;
}
EXPORT_SYMBOL_GPL(of_imap_parser_init);
struct of_imap_item *of_imap_parser_one(struct of_imap_parser *parser,
struct of_imap_item *item)
{
const __be32 *imap_parent, *imap_next;
int i;
/* Release previously get parent node */
of_node_put(item->parent_args.np);
if (parser->imap + parser->parent_offset + 1 >= parser->imap_end)
return NULL;
imap_parent = parser->imap + parser->parent_offset;
imap_next = of_irq_parse_imap_parent(imap_parent,
parser->imap_end - imap_parent,
&item->parent_args);
if (!imap_next)
return NULL;
for (i = 0; i < parser->parent_offset; i++)
item->child_imap[i] = be32_to_cpu(*(parser->imap + i));
parser->imap = imap_next;
return item;
}
EXPORT_SYMBOL_GPL(of_imap_parser_one);
/**
* of_irq_parse_raw - Low level interrupt tree parsing
* @addr: address specifier (start of "reg" property of the device) in be32 format

View file

@ -50,6 +50,15 @@
interrupt-map = <0x5000 1 2 &test_intc0 15>;
};
intmap2 {
#interrupt-cells = <2>;
#address-cells = <0>;
interrupt-map = <1 11 &test_intc0 100>,
<2 22 &test_intc1 200 201 202>,
<3 33 &test_intc2 300 301>,
<4 44 &test_intc2 400 401>;
};
test_intc_intmap0: intc-intmap0 {
#interrupt-cells = <1>;
#address-cells = <1>;

View file

@ -1654,6 +1654,121 @@ static void __init of_unittest_parse_interrupts_extended(void)
of_node_put(np);
}
struct of_unittest_expected_imap_item {
u32 child_imap_count;
u32 child_imap[2];
const char *parent_path;
int parent_args_count;
u32 parent_args[3];
};
static const struct of_unittest_expected_imap_item of_unittest_expected_imap_items[] = {
{
.child_imap_count = 2,
.child_imap = {1, 11},
.parent_path = "/testcase-data/interrupts/intc0",
.parent_args_count = 1,
.parent_args = {100},
}, {
.child_imap_count = 2,
.child_imap = {2, 22},
.parent_path = "/testcase-data/interrupts/intc1",
.parent_args_count = 3,
.parent_args = {200, 201, 202},
}, {
.child_imap_count = 2,
.child_imap = {3, 33},
.parent_path = "/testcase-data/interrupts/intc2",
.parent_args_count = 2,
.parent_args = {300, 301},
}, {
.child_imap_count = 2,
.child_imap = {4, 44},
.parent_path = "/testcase-data/interrupts/intc2",
.parent_args_count = 2,
.parent_args = {400, 401},
}
};
static void __init of_unittest_parse_interrupt_map(void)
{
const struct of_unittest_expected_imap_item *expected_item;
struct device_node *imap_np, *expected_parent_np;
struct of_imap_parser imap_parser;
struct of_imap_item imap_item;
int count, ret, i;
if (of_irq_workarounds & (OF_IMAP_NO_PHANDLE | OF_IMAP_OLDWORLD_MAC))
return;
imap_np = of_find_node_by_path("/testcase-data/interrupts/intmap2");
if (!imap_np) {
pr_err("missing testcase data\n");
return;
}
ret = of_imap_parser_init(&imap_parser, imap_np, &imap_item);
if (unittest(!ret, "of_imap_parser_init(%pOF) returned error %d\n",
imap_np, ret))
goto end;
expected_item = of_unittest_expected_imap_items;
count = 0;
for_each_of_imap_item(&imap_parser, &imap_item) {
if (unittest(count < ARRAY_SIZE(of_unittest_expected_imap_items),
"imap item number %d not expected. Max number %zu\n",
count, ARRAY_SIZE(of_unittest_expected_imap_items) - 1)) {
of_node_put(imap_item.parent_args.np);
goto end;
}
expected_parent_np = of_find_node_by_path(expected_item->parent_path);
if (unittest(expected_parent_np,
"missing dependent testcase data (%s)\n",
expected_item->parent_path)) {
of_node_put(imap_item.parent_args.np);
goto end;
}
unittest(imap_item.child_imap_count == expected_item->child_imap_count,
"imap[%d] child_imap_count = %u, expected %u\n",
count, imap_item.child_imap_count,
expected_item->child_imap_count);
for (i = 0; i < expected_item->child_imap_count; i++)
unittest(imap_item.child_imap[i] == expected_item->child_imap[i],
"imap[%d] child_imap[%d] = %u, expected %u\n",
count, i, imap_item.child_imap[i],
expected_item->child_imap[i]);
unittest(imap_item.parent_args.np == expected_parent_np,
"imap[%d] parent np = %pOF, expected %pOF\n",
count, imap_item.parent_args.np, expected_parent_np);
unittest(imap_item.parent_args.args_count == expected_item->parent_args_count,
"imap[%d] parent param_count = %d, expected %d\n",
count, imap_item.parent_args.args_count,
expected_item->parent_args_count);
for (i = 0; i < expected_item->parent_args_count; i++)
unittest(imap_item.parent_args.args[i] == expected_item->parent_args[i],
"imap[%d] parent param[%d] = %u, expected %u\n",
count, i, imap_item.parent_args.args[i],
expected_item->parent_args[i]);
of_node_put(expected_parent_np);
count++;
expected_item++;
}
unittest(count == ARRAY_SIZE(of_unittest_expected_imap_items),
"Missing items. %d parsed, expected %zu\n",
count, ARRAY_SIZE(of_unittest_expected_imap_items));
end:
of_node_put(imap_np);
}
#if IS_ENABLED(CONFIG_OF_DYNAMIC)
static void __init of_unittest_irq_refcount(void)
{
@ -4395,6 +4510,7 @@ static int __init of_unittest(void)
of_unittest_changeset_prop();
of_unittest_parse_interrupts();
of_unittest_parse_interrupts_extended();
of_unittest_parse_interrupt_map();
of_unittest_irq_refcount();
of_unittest_dma_get_max_cpu_address();
of_unittest_parse_dma_ranges();

View file

@ -62,6 +62,7 @@ config ARCH_RZN1
select PM
select PM_GENERIC_DOMAINS
select ARM_AMBA
select RZN1_IRQMUX if GPIO_DWAPB
if ARM && ARCH_RENESAS
@ -460,6 +461,9 @@ config PWC_RZV2M
config RST_RCAR
bool "Reset Controller support for R-Car" if COMPILE_TEST
config RZN1_IRQMUX
bool "Renesas RZ/N1 GPIO IRQ multiplexer support" if COMPILE_TEST
config SYSC_RZ
bool "System controller for RZ SoCs" if COMPILE_TEST
select MFD_SYSCON

View file

@ -14,4 +14,5 @@ obj-$(CONFIG_SYS_R9A09G057) += r9a09g057-sys.o
# Family
obj-$(CONFIG_PWC_RZV2M) += pwc-rzv2m.o
obj-$(CONFIG_RST_RCAR) += rcar-rst.o
obj-$(CONFIG_RZN1_IRQMUX) += rzn1_irqmux.o
obj-$(CONFIG_SYSC_RZ) += rz-sysc.o

View file

@ -0,0 +1,127 @@
// SPDX-License-Identifier: GPL-2.0-only
/*
* RZ/N1 GPIO Interrupt Multiplexer
*
* Copyright 2025 Schneider Electric
* Author: Herve Codina <herve.codina@bootlin.com>
*/
#include <linux/bitmap.h>
#include <linux/bitops.h>
#include <linux/mod_devicetable.h>
#include <linux/module.h>
#include <linux/of.h>
#include <linux/of_irq.h>
#include <linux/platform_device.h>
#include <dt-bindings/interrupt-controller/arm-gic.h>
/*
* Up to 8 output lines are connected to GIC SPI interrupt controller
* starting at IRQ 103.
*/
#define RZN1_IRQMUX_GIC_SPI_BASE 103
#define RZN1_IRQMUX_NUM_OUTPUTS 8
static int rzn1_irqmux_parent_args_to_line_index(struct device *dev,
const struct of_phandle_args *parent_args)
{
/*
* The parent interrupt should be one of the GIC controller.
* Three arguments must be provided.
* - args[0]: GIC_SPI
* - args[1]: The GIC interrupt number
* - args[2]: The interrupt flags
*
* We retrieve the line index based on the GIC interrupt number
* provided.
*/
if (parent_args->args_count != 3 || parent_args->args[0] != GIC_SPI) {
dev_err(dev, "Invalid interrupt-map item\n");
return -EINVAL;
}
if (parent_args->args[1] < RZN1_IRQMUX_GIC_SPI_BASE ||
parent_args->args[1] >= RZN1_IRQMUX_GIC_SPI_BASE + RZN1_IRQMUX_NUM_OUTPUTS) {
dev_err(dev, "Invalid GIC interrupt %u\n", parent_args->args[1]);
return -EINVAL;
}
return parent_args->args[1] - RZN1_IRQMUX_GIC_SPI_BASE;
}
static int rzn1_irqmux_probe(struct platform_device *pdev)
{
DECLARE_BITMAP(index_done, RZN1_IRQMUX_NUM_OUTPUTS) = {};
struct device *dev = &pdev->dev;
struct device_node *np = dev->of_node;
struct of_imap_parser imap_parser;
struct of_imap_item imap_item;
u32 __iomem *regs;
int index;
int ret;
u32 tmp;
regs = devm_platform_ioremap_resource(pdev, 0);
if (IS_ERR(regs))
return PTR_ERR(regs);
/* We support only #interrupt-cells = <1> and #address-cells = <0> */
ret = of_property_read_u32(np, "#interrupt-cells", &tmp);
if (ret)
return ret;
if (tmp != 1)
return -EINVAL;
ret = of_property_read_u32(np, "#address-cells", &tmp);
if (ret)
return ret;
if (tmp != 0)
return -EINVAL;
ret = of_imap_parser_init(&imap_parser, np, &imap_item);
if (ret)
return ret;
for_each_of_imap_item(&imap_parser, &imap_item) {
index = rzn1_irqmux_parent_args_to_line_index(dev, &imap_item.parent_args);
if (index < 0) {
of_node_put(imap_item.parent_args.np);
return index;
}
if (test_and_set_bit(index, index_done)) {
of_node_put(imap_item.parent_args.np);
dev_err(dev, "Mux output line %d already defined in interrupt-map\n",
index);
return -EINVAL;
}
/*
* The child #address-cells is 0 (already checked). The first
* value in imap item is the src hwirq.
*/
writel(imap_item.child_imap[0], regs + index);
}
return 0;
}
static const struct of_device_id rzn1_irqmux_of_match[] = {
{ .compatible = "renesas,rzn1-gpioirqmux", },
{ /* sentinel */ }
};
MODULE_DEVICE_TABLE(of, rzn1_irqmux_of_match);
static struct platform_driver rzn1_irqmux_driver = {
.probe = rzn1_irqmux_probe,
.driver = {
.name = "rzn1_irqmux",
.of_match_table = rzn1_irqmux_of_match,
},
};
module_platform_driver(rzn1_irqmux_driver);
MODULE_AUTHOR("Herve Codina <herve.codina@bootlin.com>");
MODULE_DESCRIPTION("Renesas RZ/N1 GPIO IRQ Multiplexer Driver");
MODULE_LICENSE("GPL");

View file

@ -11,6 +11,30 @@
typedef int (*of_irq_init_cb_t)(struct device_node *, struct device_node *);
struct of_imap_parser {
struct device_node *node;
const __be32 *imap;
const __be32 *imap_end;
u32 parent_offset;
};
struct of_imap_item {
struct of_phandle_args parent_args;
u32 child_imap_count;
u32 child_imap[16]; /* Arbitrary size.
* Should be #address-cells + #interrupt-cells but
* avoid using allocation and so, expect that 16
* should be enough
*/
};
/*
* If the iterator is exited prematurely (break, goto, return) of_node_put() has
* to be called on item.parent_args.np
*/
#define for_each_of_imap_item(parser, item) \
for (; of_imap_parser_one(parser, item);)
/*
* Workarounds only applied to 32bit powermac machines
*/
@ -49,6 +73,11 @@ 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_imap_parser_init(struct of_imap_parser *parser,
struct device_node *node,
struct of_imap_item *item);
extern struct of_imap_item *of_imap_parser_one(struct of_imap_parser *parser,
struct of_imap_item *item);
extern struct irq_domain *of_msi_get_domain(struct device *dev,
const struct device_node *np,
enum irq_domain_bus_token token);
@ -92,7 +121,17 @@ static inline void *of_irq_find_parent(struct device_node *child)
{
return NULL;
}
static inline int of_imap_parser_init(struct of_imap_parser *parser,
struct device_node *node,
struct of_imap_item *item)
{
return -ENOSYS;
}
static inline struct of_imap_item *of_imap_parser_one(struct of_imap_parser *parser,
struct of_imap_item *item)
{
return NULL;
}
static inline struct irq_domain *of_msi_get_domain(struct device *dev,
struct device_node *np,
enum irq_domain_bus_token token)