Skip to content

Commit 5f0c75e

Browse files
gclementMarc Zyngier
authored and
Marc Zyngier
committed
irqchip/ocelot: prepare to support more SoC
This patch extends irqchip driver for oceleot to be used with other vcoreiii base platforms. Signed-off-by: Gregory CLEMENT <gregory.clement@bootlin.com> Signed-off-by: Marc Zyngier <maz@kernel.org> Acked-by: Alexandre Belloni <alexandre.belloni@bootlin.com> Link: https://lore.kernel.org/r/20201125103206.136498-4-gregory.clement@bootlin.com
1 parent b307ee8 commit 5f0c75e

File tree

1 file changed

+54
-22
lines changed

1 file changed

+54
-22
lines changed

drivers/irqchip/irq-mscc-ocelot.c

Lines changed: 54 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,39 +12,61 @@
1212
#include <linux/irqchip/chained_irq.h>
1313
#include <linux/interrupt.h>
1414

15-
#define ICPU_CFG_INTR_INTR_STICKY 0x10
16-
#define ICPU_CFG_INTR_INTR_ENA 0x18
17-
#define ICPU_CFG_INTR_INTR_ENA_CLR 0x1c
18-
#define ICPU_CFG_INTR_INTR_ENA_SET 0x20
19-
#define ICPU_CFG_INTR_DST_INTR_IDENT(x) (0x38 + 0x4 * (x))
20-
#define ICPU_CFG_INTR_INTR_TRIGGER(x) (0x5c + 0x4 * (x))
21-
22-
#define OCELOT_NR_IRQ 24
15+
#define ICPU_CFG_INTR_DST_INTR_IDENT(_p, x) ((_p)->reg_off_ident + 0x4 * (x))
16+
#define ICPU_CFG_INTR_INTR_TRIGGER(_p, x) ((_p)->reg_off_trigger + 0x4 * (x))
17+
18+
#define FLAGS_HAS_TRIGGER BIT(0)
19+
20+
struct chip_props {
21+
u8 flags;
22+
u8 reg_off_sticky;
23+
u8 reg_off_ena;
24+
u8 reg_off_ena_clr;
25+
u8 reg_off_ena_set;
26+
u8 reg_off_ident;
27+
u8 reg_off_trigger;
28+
u8 reg_off_ena_irq0;
29+
u8 n_irq;
30+
};
31+
32+
static struct chip_props ocelot_props = {
33+
.flags = FLAGS_HAS_TRIGGER,
34+
.reg_off_sticky = 0x10,
35+
.reg_off_ena = 0x18,
36+
.reg_off_ena_clr = 0x1c,
37+
.reg_off_ena_set = 0x20,
38+
.reg_off_ident = 0x38,
39+
.reg_off_trigger = 0x5c,
40+
.n_irq = 24,
41+
};
2342

2443
static void ocelot_irq_unmask(struct irq_data *data)
2544
{
2645
struct irq_chip_generic *gc = irq_data_get_irq_chip_data(data);
46+
struct irq_domain *d = data->domain;
47+
struct chip_props *p = d->host_data;
2748
struct irq_chip_type *ct = irq_data_get_chip_type(data);
2849
unsigned int mask = data->mask;
2950
u32 val;
3051

3152
irq_gc_lock(gc);
32-
val = irq_reg_readl(gc, ICPU_CFG_INTR_INTR_TRIGGER(0)) |
33-
irq_reg_readl(gc, ICPU_CFG_INTR_INTR_TRIGGER(1));
53+
val = irq_reg_readl(gc, ICPU_CFG_INTR_INTR_TRIGGER(p, 0)) |
54+
irq_reg_readl(gc, ICPU_CFG_INTR_INTR_TRIGGER(p, 1));
3455
if (!(val & mask))
35-
irq_reg_writel(gc, mask, ICPU_CFG_INTR_INTR_STICKY);
56+
irq_reg_writel(gc, mask, p->reg_off_sticky);
3657

3758
*ct->mask_cache &= ~mask;
38-
irq_reg_writel(gc, mask, ICPU_CFG_INTR_INTR_ENA_SET);
59+
irq_reg_writel(gc, mask, p->reg_off_ena_set);
3960
irq_gc_unlock(gc);
4061
}
4162

4263
static void ocelot_irq_handler(struct irq_desc *desc)
4364
{
4465
struct irq_chip *chip = irq_desc_get_chip(desc);
4566
struct irq_domain *d = irq_desc_get_handler_data(desc);
67+
struct chip_props *p = d->host_data;
4668
struct irq_chip_generic *gc = irq_get_domain_generic_chip(d, 0);
47-
u32 reg = irq_reg_readl(gc, ICPU_CFG_INTR_DST_INTR_IDENT(0));
69+
u32 reg = irq_reg_readl(gc, ICPU_CFG_INTR_DST_INTR_IDENT(p, 0));
4870

4971
chained_irq_enter(chip, desc);
5072

@@ -58,8 +80,9 @@ static void ocelot_irq_handler(struct irq_desc *desc)
5880
chained_irq_exit(chip, desc);
5981
}
6082

61-
static int __init ocelot_irq_init(struct device_node *node,
62-
struct device_node *parent)
83+
static int __init vcoreiii_irq_init(struct device_node *node,
84+
struct device_node *parent,
85+
struct chip_props *p)
6386
{
6487
struct irq_domain *domain;
6588
struct irq_chip_generic *gc;
@@ -69,14 +92,14 @@ static int __init ocelot_irq_init(struct device_node *node,
6992
if (!parent_irq)
7093
return -EINVAL;
7194

72-
domain = irq_domain_add_linear(node, OCELOT_NR_IRQ,
95+
domain = irq_domain_add_linear(node, p->n_irq,
7396
&irq_generic_chip_ops, NULL);
7497
if (!domain) {
7598
pr_err("%pOFn: unable to add irq domain\n", node);
7699
return -ENOMEM;
77100
}
78101

79-
ret = irq_alloc_domain_generic_chips(domain, OCELOT_NR_IRQ, 1,
102+
ret = irq_alloc_domain_generic_chips(domain, p->n_irq, 1,
80103
"icpu", handle_level_irq,
81104
0, 0, 0);
82105
if (ret) {
@@ -92,16 +115,18 @@ static int __init ocelot_irq_init(struct device_node *node,
92115
goto err_gc_free;
93116
}
94117

95-
gc->chip_types[0].regs.ack = ICPU_CFG_INTR_INTR_STICKY;
96-
gc->chip_types[0].regs.mask = ICPU_CFG_INTR_INTR_ENA_CLR;
118+
gc->chip_types[0].regs.ack = p->reg_off_sticky;
119+
gc->chip_types[0].regs.mask = p->reg_off_ena_clr;
97120
gc->chip_types[0].chip.irq_ack = irq_gc_ack_set_bit;
98121
gc->chip_types[0].chip.irq_mask = irq_gc_mask_set_bit;
99-
gc->chip_types[0].chip.irq_unmask = ocelot_irq_unmask;
122+
if (p->flags & FLAGS_HAS_TRIGGER)
123+
gc->chip_types[0].chip.irq_unmask = ocelot_irq_unmask;
100124

101125
/* Mask and ack all interrupts */
102-
irq_reg_writel(gc, 0, ICPU_CFG_INTR_INTR_ENA);
103-
irq_reg_writel(gc, 0xffffffff, ICPU_CFG_INTR_INTR_STICKY);
126+
irq_reg_writel(gc, 0, p->reg_off_ena);
127+
irq_reg_writel(gc, 0xffffffff, p->reg_off_sticky);
104128

129+
domain->host_data = p;
105130
irq_set_chained_handler_and_data(parent_irq, ocelot_irq_handler,
106131
domain);
107132

@@ -115,4 +140,11 @@ static int __init ocelot_irq_init(struct device_node *node,
115140

116141
return ret;
117142
}
143+
144+
static int __init ocelot_irq_init(struct device_node *node,
145+
struct device_node *parent)
146+
{
147+
return vcoreiii_irq_init(node, parent, &ocelot_props);
148+
}
149+
118150
IRQCHIP_DECLARE(ocelot_icpu, "mscc,ocelot-icpu-intr", ocelot_irq_init);

0 commit comments

Comments
 (0)