Skip to content

Commit f716774

Browse files
committed
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>
2 parents 34f60ff + 49261f4 commit f716774

9 files changed

Lines changed: 400 additions & 58 deletions

File tree

drivers/irqchip/irq-ls-extirq.c

Lines changed: 17 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -125,45 +125,32 @@ static const struct irq_domain_ops extirq_domain_ops = {
125125
static int
126126
ls_extirq_parse_map(struct ls_extirq_data *priv, struct device_node *node)
127127
{
128-
const __be32 *map;
129-
u32 mapsize;
128+
struct of_imap_parser imap_parser;
129+
struct of_imap_item imap_item;
130130
int ret;
131131

132-
map = of_get_property(node, "interrupt-map", &mapsize);
133-
if (!map)
134-
return -ENOENT;
135-
if (mapsize % sizeof(*map))
136-
return -EINVAL;
137-
mapsize /= sizeof(*map);
132+
ret = of_imap_parser_init(&imap_parser, node, &imap_item);
133+
if (ret)
134+
return ret;
138135

139-
while (mapsize) {
136+
for_each_of_imap_item(&imap_parser, &imap_item) {
140137
struct device_node *ipar;
141-
u32 hwirq, intsize, j;
138+
u32 hwirq;
139+
int i;
142140

143-
if (mapsize < 3)
144-
return -EINVAL;
145-
hwirq = be32_to_cpup(map);
146-
if (hwirq >= MAXIRQ)
141+
hwirq = imap_item.child_imap[0];
142+
if (hwirq >= MAXIRQ) {
143+
of_node_put(imap_item.parent_args.np);
147144
return -EINVAL;
145+
}
148146
priv->nirq = max(priv->nirq, hwirq + 1);
149147

150-
ipar = of_find_node_by_phandle(be32_to_cpup(map + 2));
151-
map += 3;
152-
mapsize -= 3;
153-
if (!ipar)
154-
return -EINVAL;
155-
priv->map[hwirq].fwnode = &ipar->fwnode;
156-
ret = of_property_read_u32(ipar, "#interrupt-cells", &intsize);
157-
if (ret)
158-
return ret;
159-
160-
if (intsize > mapsize)
161-
return -EINVAL;
148+
ipar = of_node_get(imap_item.parent_args.np);
149+
priv->map[hwirq].fwnode = of_fwnode_handle(ipar);
162150

163-
priv->map[hwirq].param_count = intsize;
164-
for (j = 0; j < intsize; ++j)
165-
priv->map[hwirq].param[j] = be32_to_cpup(map++);
166-
mapsize -= intsize;
151+
priv->map[hwirq].param_count = imap_item.parent_args.args_count;
152+
for (i = 0; i < priv->map[hwirq].param_count; i++)
153+
priv->map[hwirq].param[i] = imap_item.parent_args.args[i];
167154
}
168155
return 0;
169156
}

drivers/irqchip/irq-renesas-rza1.c

Lines changed: 16 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -142,47 +142,36 @@ static const struct irq_domain_ops rza1_irqc_domain_ops = {
142142
static int rza1_irqc_parse_map(struct rza1_irqc_priv *priv,
143143
struct device_node *gic_node)
144144
{
145+
struct of_imap_parser imap_parser;
145146
struct device *dev = priv->dev;
146-
unsigned int imaplen, i, j;
147+
struct of_imap_item imap_item;
147148
struct device_node *ipar;
148-
const __be32 *imap;
149-
u32 intsize;
149+
unsigned int j;
150+
u32 i = 0;
150151
int ret;
151152

152-
imap = of_get_property(dev->of_node, "interrupt-map", &imaplen);
153-
if (!imap)
154-
return -EINVAL;
155-
156-
for (i = 0; i < IRQC_NUM_IRQ; i++) {
157-
if (imaplen < 3)
158-
return -EINVAL;
153+
ret = of_imap_parser_init(&imap_parser, dev->of_node, &imap_item);
154+
if (ret)
155+
return ret;
159156

157+
for_each_of_imap_item(&imap_parser, &imap_item) {
160158
/* Check interrupt number, ignore sense */
161-
if (be32_to_cpup(imap) != i)
159+
if (imap_item.child_imap[0] != i) {
160+
of_node_put(imap_item.parent_args.np);
162161
return -EINVAL;
162+
}
163163

164-
ipar = of_find_node_by_phandle(be32_to_cpup(imap + 2));
164+
ipar = imap_item.parent_args.np;
165165
if (ipar != gic_node) {
166166
of_node_put(ipar);
167167
return -EINVAL;
168168
}
169169

170-
imap += 3;
171-
imaplen -= 3;
172-
173-
ret = of_property_read_u32(ipar, "#interrupt-cells", &intsize);
174-
of_node_put(ipar);
175-
if (ret)
176-
return ret;
177-
178-
if (imaplen < intsize)
179-
return -EINVAL;
180-
181-
priv->map[i].args_count = intsize;
182-
for (j = 0; j < intsize; j++)
183-
priv->map[i].args[j] = be32_to_cpup(imap++);
170+
priv->map[i].args_count = imap_item.parent_args.args_count;
171+
for (j = 0; j < priv->map[i].args_count; j++)
172+
priv->map[i].args[j] = imap_item.parent_args.args[j];
184173

185-
imaplen -= intsize;
174+
i++;
186175
}
187176

188177
return 0;

drivers/of/irq.c

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,76 @@ const __be32 *of_irq_parse_imap_parent(const __be32 *imap, int len, struct of_ph
157157
return imap;
158158
}
159159

160+
int of_imap_parser_init(struct of_imap_parser *parser, struct device_node *node,
161+
struct of_imap_item *item)
162+
{
163+
int imaplen;
164+
u32 tmp;
165+
int ret;
166+
167+
/*
168+
* parent_offset is the offset where the parent part is starting.
169+
* In other words, the offset where the parent interrupt controller
170+
* phandle is present.
171+
*
172+
* Compute this offset (child #interrupt-cells + child #address-cells)
173+
*/
174+
parser->parent_offset = of_bus_n_addr_cells(node);
175+
176+
ret = of_property_read_u32(node, "#interrupt-cells", &tmp);
177+
if (ret)
178+
return ret;
179+
180+
parser->parent_offset += tmp;
181+
182+
if (WARN(parser->parent_offset > ARRAY_SIZE(item->child_imap),
183+
"child part size = %u, cannot fit in array of %zu items",
184+
parser->parent_offset, ARRAY_SIZE(item->child_imap)))
185+
return -EINVAL;
186+
187+
parser->imap = of_get_property(node, "interrupt-map", &imaplen);
188+
if (!parser->imap)
189+
return -ENOENT;
190+
191+
imaplen /= sizeof(*parser->imap);
192+
parser->imap_end = parser->imap + imaplen;
193+
194+
memset(item, 0, sizeof(*item));
195+
item->child_imap_count = parser->parent_offset;
196+
197+
return 0;
198+
}
199+
EXPORT_SYMBOL_GPL(of_imap_parser_init);
200+
201+
struct of_imap_item *of_imap_parser_one(struct of_imap_parser *parser,
202+
struct of_imap_item *item)
203+
{
204+
const __be32 *imap_parent, *imap_next;
205+
int i;
206+
207+
/* Release previously get parent node */
208+
of_node_put(item->parent_args.np);
209+
210+
if (parser->imap + parser->parent_offset + 1 >= parser->imap_end)
211+
return NULL;
212+
213+
imap_parent = parser->imap + parser->parent_offset;
214+
215+
imap_next = of_irq_parse_imap_parent(imap_parent,
216+
parser->imap_end - imap_parent,
217+
&item->parent_args);
218+
if (!imap_next)
219+
return NULL;
220+
221+
for (i = 0; i < parser->parent_offset; i++)
222+
item->child_imap[i] = be32_to_cpu(*(parser->imap + i));
223+
224+
parser->imap = imap_next;
225+
226+
return item;
227+
}
228+
EXPORT_SYMBOL_GPL(of_imap_parser_one);
229+
160230
/**
161231
* of_irq_parse_raw - Low level interrupt tree parsing
162232
* @addr: address specifier (start of "reg" property of the device) in be32 format

drivers/of/unittest-data/tests-interrupts.dtsi

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,15 @@
5050
interrupt-map = <0x5000 1 2 &test_intc0 15>;
5151
};
5252

53+
intmap2 {
54+
#interrupt-cells = <2>;
55+
#address-cells = <0>;
56+
interrupt-map = <1 11 &test_intc0 100>,
57+
<2 22 &test_intc1 200 201 202>,
58+
<3 33 &test_intc2 300 301>,
59+
<4 44 &test_intc2 400 401>;
60+
};
61+
5362
test_intc_intmap0: intc-intmap0 {
5463
#interrupt-cells = <1>;
5564
#address-cells = <1>;

drivers/of/unittest.c

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1654,6 +1654,121 @@ static void __init of_unittest_parse_interrupts_extended(void)
16541654
of_node_put(np);
16551655
}
16561656

1657+
struct of_unittest_expected_imap_item {
1658+
u32 child_imap_count;
1659+
u32 child_imap[2];
1660+
const char *parent_path;
1661+
int parent_args_count;
1662+
u32 parent_args[3];
1663+
};
1664+
1665+
static const struct of_unittest_expected_imap_item of_unittest_expected_imap_items[] = {
1666+
{
1667+
.child_imap_count = 2,
1668+
.child_imap = {1, 11},
1669+
.parent_path = "/testcase-data/interrupts/intc0",
1670+
.parent_args_count = 1,
1671+
.parent_args = {100},
1672+
}, {
1673+
.child_imap_count = 2,
1674+
.child_imap = {2, 22},
1675+
.parent_path = "/testcase-data/interrupts/intc1",
1676+
.parent_args_count = 3,
1677+
.parent_args = {200, 201, 202},
1678+
}, {
1679+
.child_imap_count = 2,
1680+
.child_imap = {3, 33},
1681+
.parent_path = "/testcase-data/interrupts/intc2",
1682+
.parent_args_count = 2,
1683+
.parent_args = {300, 301},
1684+
}, {
1685+
.child_imap_count = 2,
1686+
.child_imap = {4, 44},
1687+
.parent_path = "/testcase-data/interrupts/intc2",
1688+
.parent_args_count = 2,
1689+
.parent_args = {400, 401},
1690+
}
1691+
};
1692+
1693+
static void __init of_unittest_parse_interrupt_map(void)
1694+
{
1695+
const struct of_unittest_expected_imap_item *expected_item;
1696+
struct device_node *imap_np, *expected_parent_np;
1697+
struct of_imap_parser imap_parser;
1698+
struct of_imap_item imap_item;
1699+
int count, ret, i;
1700+
1701+
if (of_irq_workarounds & (OF_IMAP_NO_PHANDLE | OF_IMAP_OLDWORLD_MAC))
1702+
return;
1703+
1704+
imap_np = of_find_node_by_path("/testcase-data/interrupts/intmap2");
1705+
if (!imap_np) {
1706+
pr_err("missing testcase data\n");
1707+
return;
1708+
}
1709+
1710+
ret = of_imap_parser_init(&imap_parser, imap_np, &imap_item);
1711+
if (unittest(!ret, "of_imap_parser_init(%pOF) returned error %d\n",
1712+
imap_np, ret))
1713+
goto end;
1714+
1715+
expected_item = of_unittest_expected_imap_items;
1716+
count = 0;
1717+
1718+
for_each_of_imap_item(&imap_parser, &imap_item) {
1719+
if (unittest(count < ARRAY_SIZE(of_unittest_expected_imap_items),
1720+
"imap item number %d not expected. Max number %zu\n",
1721+
count, ARRAY_SIZE(of_unittest_expected_imap_items) - 1)) {
1722+
of_node_put(imap_item.parent_args.np);
1723+
goto end;
1724+
}
1725+
1726+
expected_parent_np = of_find_node_by_path(expected_item->parent_path);
1727+
if (unittest(expected_parent_np,
1728+
"missing dependent testcase data (%s)\n",
1729+
expected_item->parent_path)) {
1730+
of_node_put(imap_item.parent_args.np);
1731+
goto end;
1732+
}
1733+
1734+
unittest(imap_item.child_imap_count == expected_item->child_imap_count,
1735+
"imap[%d] child_imap_count = %u, expected %u\n",
1736+
count, imap_item.child_imap_count,
1737+
expected_item->child_imap_count);
1738+
1739+
for (i = 0; i < expected_item->child_imap_count; i++)
1740+
unittest(imap_item.child_imap[i] == expected_item->child_imap[i],
1741+
"imap[%d] child_imap[%d] = %u, expected %u\n",
1742+
count, i, imap_item.child_imap[i],
1743+
expected_item->child_imap[i]);
1744+
1745+
unittest(imap_item.parent_args.np == expected_parent_np,
1746+
"imap[%d] parent np = %pOF, expected %pOF\n",
1747+
count, imap_item.parent_args.np, expected_parent_np);
1748+
1749+
unittest(imap_item.parent_args.args_count == expected_item->parent_args_count,
1750+
"imap[%d] parent param_count = %d, expected %d\n",
1751+
count, imap_item.parent_args.args_count,
1752+
expected_item->parent_args_count);
1753+
1754+
for (i = 0; i < expected_item->parent_args_count; i++)
1755+
unittest(imap_item.parent_args.args[i] == expected_item->parent_args[i],
1756+
"imap[%d] parent param[%d] = %u, expected %u\n",
1757+
count, i, imap_item.parent_args.args[i],
1758+
expected_item->parent_args[i]);
1759+
1760+
of_node_put(expected_parent_np);
1761+
count++;
1762+
expected_item++;
1763+
}
1764+
1765+
unittest(count == ARRAY_SIZE(of_unittest_expected_imap_items),
1766+
"Missing items. %d parsed, expected %zu\n",
1767+
count, ARRAY_SIZE(of_unittest_expected_imap_items));
1768+
end:
1769+
of_node_put(imap_np);
1770+
}
1771+
16571772
#if IS_ENABLED(CONFIG_OF_DYNAMIC)
16581773
static void __init of_unittest_irq_refcount(void)
16591774
{
@@ -4395,6 +4510,7 @@ static int __init of_unittest(void)
43954510
of_unittest_changeset_prop();
43964511
of_unittest_parse_interrupts();
43974512
of_unittest_parse_interrupts_extended();
4513+
of_unittest_parse_interrupt_map();
43984514
of_unittest_irq_refcount();
43994515
of_unittest_dma_get_max_cpu_address();
44004516
of_unittest_parse_dma_ranges();

drivers/soc/renesas/Kconfig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ config ARCH_RZN1
6262
select PM
6363
select PM_GENERIC_DOMAINS
6464
select ARM_AMBA
65+
select RZN1_IRQMUX if GPIO_DWAPB
6566

6667
if ARM && ARCH_RENESAS
6768

@@ -460,6 +461,9 @@ config PWC_RZV2M
460461
config RST_RCAR
461462
bool "Reset Controller support for R-Car" if COMPILE_TEST
462463

464+
config RZN1_IRQMUX
465+
bool "Renesas RZ/N1 GPIO IRQ multiplexer support" if COMPILE_TEST
466+
463467
config SYSC_RZ
464468
bool "System controller for RZ SoCs" if COMPILE_TEST
465469
select MFD_SYSCON

drivers/soc/renesas/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@ obj-$(CONFIG_SYS_R9A09G057) += r9a09g057-sys.o
1414
# Family
1515
obj-$(CONFIG_PWC_RZV2M) += pwc-rzv2m.o
1616
obj-$(CONFIG_RST_RCAR) += rcar-rst.o
17+
obj-$(CONFIG_RZN1_IRQMUX) += rzn1_irqmux.o
1718
obj-$(CONFIG_SYSC_RZ) += rz-sysc.o

0 commit comments

Comments
 (0)