Skip to content

Commit e6a767a

Browse files
author
Marc Zyngier
committed
Merge branch irq/mchp-eic into irq/irqchip-next
* irq/mchp-eic: : . : New irqchip driver for the Microchip EIC block : . irqchip/mchp-eic: Fix return value check in mchp_eic_init() irqchip/mchp-eic: Add support for the Microchip EIC dt-bindings: microchip,eic: Add bindings for the Microchip EIC Signed-off-by: Marc Zyngier <[email protected]>
2 parents 1e1d137 + 68a6e0c commit e6a767a

File tree

5 files changed

+368
-0
lines changed

5 files changed

+368
-0
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
2+
%YAML 1.2
3+
---
4+
$id: http://devicetree.org/schemas/interrupt-controller/microchip,eic.yaml#
5+
$schema: http://devicetree.org/meta-schemas/core.yaml#
6+
7+
title: Microchip External Interrupt Controller
8+
9+
maintainers:
10+
- Claudiu Beznea <[email protected]>
11+
12+
description:
13+
This interrupt controller is found in Microchip SoCs (SAMA7G5) and provides
14+
support for handling up to 2 external interrupt lines.
15+
16+
properties:
17+
compatible:
18+
enum:
19+
- microchip,sama7g5-eic
20+
21+
reg:
22+
maxItems: 1
23+
24+
interrupt-controller: true
25+
26+
'#interrupt-cells':
27+
const: 2
28+
description:
29+
The first cell is the input IRQ number (between 0 and 1), the second cell
30+
is the trigger type as defined in interrupt.txt present in this directory.
31+
32+
interrupts:
33+
description: |
34+
Contains the GIC SPI IRQs mapped to the external interrupt lines. They
35+
should be specified sequentially from output 0 to output 1.
36+
minItems: 2
37+
maxItems: 2
38+
39+
clocks:
40+
maxItems: 1
41+
42+
clock-names:
43+
const: pclk
44+
45+
required:
46+
- compatible
47+
- reg
48+
- interrupt-controller
49+
- '#interrupt-cells'
50+
- interrupts
51+
- clocks
52+
- clock-names
53+
54+
additionalProperties: false
55+
56+
examples:
57+
- |
58+
#include <dt-bindings/clock/at91.h>
59+
#include <dt-bindings/interrupt-controller/arm-gic.h>
60+
61+
eic: interrupt-controller@e1628000 {
62+
compatible = "microchip,sama7g5-eic";
63+
reg = <0xe1628000 0x100>;
64+
interrupt-parent = <&gic>;
65+
interrupt-controller;
66+
#interrupt-cells = <2>;
67+
interrupts = <GIC_SPI 153 IRQ_TYPE_LEVEL_HIGH>,
68+
<GIC_SPI 154 IRQ_TYPE_LEVEL_HIGH>;
69+
clocks = <&pmc PMC_TYPE_PERIPHERAL 37>;
70+
clock-names = "pclk";
71+
};
72+
73+
...

MAINTAINERS

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12254,6 +12254,12 @@ L: [email protected]
1225412254
S: Maintained
1225512255
F: drivers/crypto/atmel-ecc.*
1225612256

12257+
MICROCHIP EIC DRIVER
12258+
M: Claudiu Beznea <[email protected]>
12259+
L: [email protected] (moderated for non-subscribers)
12260+
S: Supported
12261+
F: drivers/irqchip/irq-mchp-eic.c
12262+
1225712263
MICROCHIP I2C DRIVER
1225812264
M: Codrin Ciubotariu <[email protected]>
1225912265

drivers/irqchip/Kconfig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -609,4 +609,12 @@ config APPLE_AIC
609609
Support for the Apple Interrupt Controller found on Apple Silicon SoCs,
610610
such as the M1.
611611

612+
config MCHP_EIC
613+
bool "Microchip External Interrupt Controller"
614+
depends on ARCH_AT91 || COMPILE_TEST
615+
select IRQ_DOMAIN
616+
select IRQ_DOMAIN_HIERARCHY
617+
help
618+
Support for Microchip External Interrupt Controller.
619+
612620
endmenu

drivers/irqchip/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,3 +116,4 @@ obj-$(CONFIG_MACH_REALTEK_RTL) += irq-realtek-rtl.o
116116
obj-$(CONFIG_WPCM450_AIC) += irq-wpcm450-aic.o
117117
obj-$(CONFIG_IRQ_IDT3243X) += irq-idt3243x.o
118118
obj-$(CONFIG_APPLE_AIC) += irq-apple-aic.o
119+
obj-$(CONFIG_MCHP_EIC) += irq-mchp-eic.o

drivers/irqchip/irq-mchp-eic.c

Lines changed: 280 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,280 @@
1+
// SPDX-License-Identifier: GPL-2.0-only
2+
/*
3+
* Microchip External Interrupt Controller driver
4+
*
5+
* Copyright (C) 2021 Microchip Technology Inc. and its subsidiaries
6+
*
7+
* Author: Claudiu Beznea <[email protected]>
8+
*/
9+
#include <linux/clk.h>
10+
#include <linux/delay.h>
11+
#include <linux/interrupt.h>
12+
#include <linux/irqchip.h>
13+
#include <linux/of_address.h>
14+
#include <linux/of_irq.h>
15+
#include <linux/syscore_ops.h>
16+
17+
#include <dt-bindings/interrupt-controller/arm-gic.h>
18+
19+
#define MCHP_EIC_GFCS (0x0)
20+
#define MCHP_EIC_SCFG(x) (0x4 + (x) * 0x4)
21+
#define MCHP_EIC_SCFG_EN BIT(16)
22+
#define MCHP_EIC_SCFG_LVL BIT(9)
23+
#define MCHP_EIC_SCFG_POL BIT(8)
24+
25+
#define MCHP_EIC_NIRQ (2)
26+
27+
/*
28+
* struct mchp_eic - EIC private data structure
29+
* @base: base address
30+
* @clk: peripheral clock
31+
* @domain: irq domain
32+
* @irqs: irqs b/w eic and gic
33+
* @scfg: backup for scfg registers (necessary for backup and self-refresh mode)
34+
* @wakeup_source: wakeup source mask
35+
*/
36+
struct mchp_eic {
37+
void __iomem *base;
38+
struct clk *clk;
39+
struct irq_domain *domain;
40+
u32 irqs[MCHP_EIC_NIRQ];
41+
u32 scfg[MCHP_EIC_NIRQ];
42+
u32 wakeup_source;
43+
};
44+
45+
static struct mchp_eic *eic;
46+
47+
static void mchp_eic_irq_mask(struct irq_data *d)
48+
{
49+
unsigned int tmp;
50+
51+
tmp = readl_relaxed(eic->base + MCHP_EIC_SCFG(d->hwirq));
52+
tmp &= ~MCHP_EIC_SCFG_EN;
53+
writel_relaxed(tmp, eic->base + MCHP_EIC_SCFG(d->hwirq));
54+
55+
irq_chip_mask_parent(d);
56+
}
57+
58+
static void mchp_eic_irq_unmask(struct irq_data *d)
59+
{
60+
unsigned int tmp;
61+
62+
tmp = readl_relaxed(eic->base + MCHP_EIC_SCFG(d->hwirq));
63+
tmp |= MCHP_EIC_SCFG_EN;
64+
writel_relaxed(tmp, eic->base + MCHP_EIC_SCFG(d->hwirq));
65+
66+
irq_chip_unmask_parent(d);
67+
}
68+
69+
static int mchp_eic_irq_set_type(struct irq_data *d, unsigned int type)
70+
{
71+
unsigned int parent_irq_type;
72+
unsigned int tmp;
73+
74+
tmp = readl_relaxed(eic->base + MCHP_EIC_SCFG(d->hwirq));
75+
tmp &= ~(MCHP_EIC_SCFG_POL | MCHP_EIC_SCFG_LVL);
76+
switch (type) {
77+
case IRQ_TYPE_LEVEL_HIGH:
78+
tmp |= MCHP_EIC_SCFG_POL | MCHP_EIC_SCFG_LVL;
79+
parent_irq_type = IRQ_TYPE_LEVEL_HIGH;
80+
break;
81+
case IRQ_TYPE_LEVEL_LOW:
82+
tmp |= MCHP_EIC_SCFG_LVL;
83+
parent_irq_type = IRQ_TYPE_LEVEL_HIGH;
84+
break;
85+
case IRQ_TYPE_EDGE_RISING:
86+
parent_irq_type = IRQ_TYPE_EDGE_RISING;
87+
break;
88+
case IRQ_TYPE_EDGE_FALLING:
89+
tmp |= MCHP_EIC_SCFG_POL;
90+
parent_irq_type = IRQ_TYPE_EDGE_RISING;
91+
break;
92+
default:
93+
return -EINVAL;
94+
}
95+
96+
writel_relaxed(tmp, eic->base + MCHP_EIC_SCFG(d->hwirq));
97+
98+
return irq_chip_set_type_parent(d, parent_irq_type);
99+
}
100+
101+
static int mchp_eic_irq_set_wake(struct irq_data *d, unsigned int on)
102+
{
103+
irq_set_irq_wake(eic->irqs[d->hwirq], on);
104+
if (on)
105+
eic->wakeup_source |= BIT(d->hwirq);
106+
else
107+
eic->wakeup_source &= ~BIT(d->hwirq);
108+
109+
return 0;
110+
}
111+
112+
static int mchp_eic_irq_suspend(void)
113+
{
114+
unsigned int hwirq;
115+
116+
for (hwirq = 0; hwirq < MCHP_EIC_NIRQ; hwirq++)
117+
eic->scfg[hwirq] = readl_relaxed(eic->base +
118+
MCHP_EIC_SCFG(hwirq));
119+
120+
if (!eic->wakeup_source)
121+
clk_disable_unprepare(eic->clk);
122+
123+
return 0;
124+
}
125+
126+
static void mchp_eic_irq_resume(void)
127+
{
128+
unsigned int hwirq;
129+
130+
if (!eic->wakeup_source)
131+
clk_prepare_enable(eic->clk);
132+
133+
for (hwirq = 0; hwirq < MCHP_EIC_NIRQ; hwirq++)
134+
writel_relaxed(eic->scfg[hwirq], eic->base +
135+
MCHP_EIC_SCFG(hwirq));
136+
}
137+
138+
static struct syscore_ops mchp_eic_syscore_ops = {
139+
.suspend = mchp_eic_irq_suspend,
140+
.resume = mchp_eic_irq_resume,
141+
};
142+
143+
static struct irq_chip mchp_eic_chip = {
144+
.name = "eic",
145+
.flags = IRQCHIP_MASK_ON_SUSPEND | IRQCHIP_SET_TYPE_MASKED,
146+
.irq_mask = mchp_eic_irq_mask,
147+
.irq_unmask = mchp_eic_irq_unmask,
148+
.irq_set_type = mchp_eic_irq_set_type,
149+
.irq_ack = irq_chip_ack_parent,
150+
.irq_eoi = irq_chip_eoi_parent,
151+
.irq_retrigger = irq_chip_retrigger_hierarchy,
152+
.irq_set_wake = mchp_eic_irq_set_wake,
153+
};
154+
155+
static int mchp_eic_domain_alloc(struct irq_domain *domain, unsigned int virq,
156+
unsigned int nr_irqs, void *data)
157+
{
158+
struct irq_fwspec *fwspec = data;
159+
struct irq_fwspec parent_fwspec;
160+
irq_hw_number_t hwirq;
161+
unsigned int type;
162+
int ret;
163+
164+
if (WARN_ON(nr_irqs != 1))
165+
return -EINVAL;
166+
167+
ret = irq_domain_translate_twocell(domain, fwspec, &hwirq, &type);
168+
if (ret || hwirq >= MCHP_EIC_NIRQ)
169+
return ret;
170+
171+
switch (type) {
172+
case IRQ_TYPE_EDGE_RISING:
173+
case IRQ_TYPE_LEVEL_HIGH:
174+
break;
175+
case IRQ_TYPE_EDGE_FALLING:
176+
type = IRQ_TYPE_EDGE_RISING;
177+
break;
178+
case IRQ_TYPE_LEVEL_LOW:
179+
type = IRQ_TYPE_LEVEL_HIGH;
180+
break;
181+
default:
182+
return -EINVAL;
183+
}
184+
185+
irq_domain_set_hwirq_and_chip(domain, virq, hwirq, &mchp_eic_chip, eic);
186+
187+
parent_fwspec.fwnode = domain->parent->fwnode;
188+
parent_fwspec.param_count = 3;
189+
parent_fwspec.param[0] = GIC_SPI;
190+
parent_fwspec.param[1] = eic->irqs[hwirq];
191+
parent_fwspec.param[2] = type;
192+
193+
return irq_domain_alloc_irqs_parent(domain, virq, 1, &parent_fwspec);
194+
}
195+
196+
static const struct irq_domain_ops mchp_eic_domain_ops = {
197+
.translate = irq_domain_translate_twocell,
198+
.alloc = mchp_eic_domain_alloc,
199+
.free = irq_domain_free_irqs_common,
200+
};
201+
202+
static int mchp_eic_init(struct device_node *node, struct device_node *parent)
203+
{
204+
struct irq_domain *parent_domain = NULL;
205+
int ret, i;
206+
207+
eic = kzalloc(sizeof(*eic), GFP_KERNEL);
208+
if (!eic)
209+
return -ENOMEM;
210+
211+
eic->base = of_iomap(node, 0);
212+
if (!eic->base) {
213+
ret = -ENOMEM;
214+
goto free;
215+
}
216+
217+
parent_domain = irq_find_host(parent);
218+
if (!parent_domain) {
219+
ret = -ENODEV;
220+
goto unmap;
221+
}
222+
223+
eic->clk = of_clk_get_by_name(node, "pclk");
224+
if (IS_ERR(eic->clk)) {
225+
ret = PTR_ERR(eic->clk);
226+
goto unmap;
227+
}
228+
229+
ret = clk_prepare_enable(eic->clk);
230+
if (ret)
231+
goto unmap;
232+
233+
for (i = 0; i < MCHP_EIC_NIRQ; i++) {
234+
struct of_phandle_args irq;
235+
236+
/* Disable it, if any. */
237+
writel_relaxed(0UL, eic->base + MCHP_EIC_SCFG(i));
238+
239+
ret = of_irq_parse_one(node, i, &irq);
240+
if (ret)
241+
goto clk_unprepare;
242+
243+
if (WARN_ON(irq.args_count != 3)) {
244+
ret = -EINVAL;
245+
goto clk_unprepare;
246+
}
247+
248+
eic->irqs[i] = irq.args[1];
249+
}
250+
251+
eic->domain = irq_domain_add_hierarchy(parent_domain, 0, MCHP_EIC_NIRQ,
252+
node, &mchp_eic_domain_ops, eic);
253+
if (!eic->domain) {
254+
pr_err("%pOF: Failed to add domain\n", node);
255+
ret = -ENODEV;
256+
goto clk_unprepare;
257+
}
258+
259+
register_syscore_ops(&mchp_eic_syscore_ops);
260+
261+
pr_info("%pOF: EIC registered, nr_irqs %u\n", node, MCHP_EIC_NIRQ);
262+
263+
return 0;
264+
265+
clk_unprepare:
266+
clk_disable_unprepare(eic->clk);
267+
unmap:
268+
iounmap(eic->base);
269+
free:
270+
kfree(eic);
271+
return ret;
272+
}
273+
274+
IRQCHIP_PLATFORM_DRIVER_BEGIN(mchp_eic)
275+
IRQCHIP_MATCH("microchip,sama7g5-eic", mchp_eic_init)
276+
IRQCHIP_PLATFORM_DRIVER_END(mchp_eic)
277+
278+
MODULE_DESCRIPTION("Microchip External Interrupt Controller");
279+
MODULE_LICENSE("GPL v2");
280+
MODULE_AUTHOR("Claudiu Beznea <[email protected]>");

0 commit comments

Comments
 (0)