aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Petazzoni <thomas.petazzoni@free-electrons.com>2017-06-21 09:29:15 -0400
committerMarc Zyngier <marc.zyngier@arm.com>2017-06-23 04:14:57 -0400
commite0de91a977bfe4c199138fa256a211a648ef6999 (patch)
treec9d65f271815054bc821467366d2872b9e9cf4ac
parenta68a63cb4dfc30e8a79b444aabc7747bb7621acf (diff)
irqchip/irq-mvebu-icu: Add new driver for Marvell ICU
The Marvell ICU unit is found in the CP110 block of the Marvell Armada 7K and 8K SoCs. It collects the wired interrupts of the devices located in the CP110 and turns them into SPI interrupts in the GIC located in the AP806 side of the SoC, by using a memory transaction. Until now, the ICU was configured in a static fashion by the firmware, and Linux was relying on this static configuration. By having Linux configure the ICU, we are more flexible, and we can allocate dynamically the GIC SPI interrupts only for devices that are actually in use. The driver was initially written by Hanna Hawa <hannah@marvell.com>. Reviewed-by: Marc Zyngier <marc.zyngier@arm.com> Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com> Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
-rw-r--r--drivers/irqchip/Kconfig3
-rw-r--r--drivers/irqchip/Makefile1
-rw-r--r--drivers/irqchip/irq-mvebu-icu.c289
-rw-r--r--include/dt-bindings/interrupt-controller/mvebu-icu.h15
4 files changed, 308 insertions, 0 deletions
diff --git a/drivers/irqchip/Kconfig b/drivers/irqchip/Kconfig
index e527ee596d54..676232a94f9f 100644
--- a/drivers/irqchip/Kconfig
+++ b/drivers/irqchip/Kconfig
@@ -271,6 +271,9 @@ config IRQ_MXS
271config MVEBU_GICP 271config MVEBU_GICP
272 bool 272 bool
273 273
274config MVEBU_ICU
275 bool
276
274config MVEBU_ODMI 277config MVEBU_ODMI
275 bool 278 bool
276 select GENERIC_MSI_IRQ_DOMAIN 279 select GENERIC_MSI_IRQ_DOMAIN
diff --git a/drivers/irqchip/Makefile b/drivers/irqchip/Makefile
index f214f4573307..e88d856cc09c 100644
--- a/drivers/irqchip/Makefile
+++ b/drivers/irqchip/Makefile
@@ -70,6 +70,7 @@ obj-$(CONFIG_INGENIC_IRQ) += irq-ingenic.o
70obj-$(CONFIG_IMX_GPCV2) += irq-imx-gpcv2.o 70obj-$(CONFIG_IMX_GPCV2) += irq-imx-gpcv2.o
71obj-$(CONFIG_PIC32_EVIC) += irq-pic32-evic.o 71obj-$(CONFIG_PIC32_EVIC) += irq-pic32-evic.o
72obj-$(CONFIG_MVEBU_GICP) += irq-mvebu-gicp.o 72obj-$(CONFIG_MVEBU_GICP) += irq-mvebu-gicp.o
73obj-$(CONFIG_MVEBU_ICU) += irq-mvebu-icu.o
73obj-$(CONFIG_MVEBU_ODMI) += irq-mvebu-odmi.o 74obj-$(CONFIG_MVEBU_ODMI) += irq-mvebu-odmi.o
74obj-$(CONFIG_MVEBU_PIC) += irq-mvebu-pic.o 75obj-$(CONFIG_MVEBU_PIC) += irq-mvebu-pic.o
75obj-$(CONFIG_LS_SCFG_MSI) += irq-ls-scfg-msi.o 76obj-$(CONFIG_LS_SCFG_MSI) += irq-ls-scfg-msi.o
diff --git a/drivers/irqchip/irq-mvebu-icu.c b/drivers/irqchip/irq-mvebu-icu.c
new file mode 100644
index 000000000000..e18c48d3a92e
--- /dev/null
+++ b/drivers/irqchip/irq-mvebu-icu.c
@@ -0,0 +1,289 @@
1/*
2 * Copyright (C) 2017 Marvell
3 *
4 * Hanna Hawa <hannah@marvell.com>
5 * Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
6 *
7 * This file is licensed under the terms of the GNU General Public
8 * License version 2. This program is licensed "as is" without any
9 * warranty of any kind, whether express or implied.
10 */
11
12#include <linux/interrupt.h>
13#include <linux/irq.h>
14#include <linux/irqchip.h>
15#include <linux/irqdomain.h>
16#include <linux/kernel.h>
17#include <linux/msi.h>
18#include <linux/of_irq.h>
19#include <linux/of_platform.h>
20#include <linux/platform_device.h>
21
22#include <dt-bindings/interrupt-controller/mvebu-icu.h>
23
24#include "irq-mvebu-gicp.h"
25
26/* ICU registers */
27#define ICU_SETSPI_NSR_AL 0x10
28#define ICU_SETSPI_NSR_AH 0x14
29#define ICU_CLRSPI_NSR_AL 0x18
30#define ICU_CLRSPI_NSR_AH 0x1c
31#define ICU_INT_CFG(x) (0x100 + 4 * (x))
32#define ICU_INT_ENABLE BIT(24)
33#define ICU_IS_EDGE BIT(28)
34#define ICU_GROUP_SHIFT 29
35
36/* ICU definitions */
37#define ICU_MAX_IRQS 207
38#define ICU_SATA0_ICU_ID 109
39#define ICU_SATA1_ICU_ID 107
40
41struct mvebu_icu {
42 struct irq_chip irq_chip;
43 void __iomem *base;
44 struct irq_domain *domain;
45 struct device *dev;
46};
47
48struct mvebu_icu_irq_data {
49 struct mvebu_icu *icu;
50 unsigned int icu_group;
51 unsigned int type;
52};
53
54static void mvebu_icu_write_msg(struct msi_desc *desc, struct msi_msg *msg)
55{
56 struct irq_data *d = irq_get_irq_data(desc->irq);
57 struct mvebu_icu_irq_data *icu_irqd = d->chip_data;
58 struct mvebu_icu *icu = icu_irqd->icu;
59 unsigned int icu_int;
60
61 if (msg->address_lo || msg->address_hi) {
62 /* Configure the ICU with irq number & type */
63 icu_int = msg->data | ICU_INT_ENABLE;
64 if (icu_irqd->type & IRQ_TYPE_EDGE_RISING)
65 icu_int |= ICU_IS_EDGE;
66 icu_int |= icu_irqd->icu_group << ICU_GROUP_SHIFT;
67 } else {
68 /* De-configure the ICU */
69 icu_int = 0;
70 }
71
72 writel_relaxed(icu_int, icu->base + ICU_INT_CFG(d->hwirq));
73
74 /*
75 * The SATA unit has 2 ports, and a dedicated ICU entry per
76 * port. The ahci sata driver supports only one irq interrupt
77 * per SATA unit. To solve this conflict, we configure the 2
78 * SATA wired interrupts in the south bridge into 1 GIC
79 * interrupt in the north bridge. Even if only a single port
80 * is enabled, if sata node is enabled, both interrupts are
81 * configured (regardless of which port is actually in use).
82 */
83 if (d->hwirq == ICU_SATA0_ICU_ID || d->hwirq == ICU_SATA1_ICU_ID) {
84 writel_relaxed(icu_int,
85 icu->base + ICU_INT_CFG(ICU_SATA0_ICU_ID));
86 writel_relaxed(icu_int,
87 icu->base + ICU_INT_CFG(ICU_SATA1_ICU_ID));
88 }
89}
90
91static int
92mvebu_icu_irq_domain_translate(struct irq_domain *d, struct irq_fwspec *fwspec,
93 unsigned long *hwirq, unsigned int *type)
94{
95 struct mvebu_icu *icu = d->host_data;
96 unsigned int icu_group;
97
98 /* Check the count of the parameters in dt */
99 if (WARN_ON(fwspec->param_count < 3)) {
100 dev_err(icu->dev, "wrong ICU parameter count %d\n",
101 fwspec->param_count);
102 return -EINVAL;
103 }
104
105 /* Only ICU group type is handled */
106 icu_group = fwspec->param[0];
107 if (icu_group != ICU_GRP_NSR && icu_group != ICU_GRP_SR &&
108 icu_group != ICU_GRP_SEI && icu_group != ICU_GRP_REI) {
109 dev_err(icu->dev, "wrong ICU group type %x\n", icu_group);
110 return -EINVAL;
111 }
112
113 *hwirq = fwspec->param[1];
114 if (*hwirq >= ICU_MAX_IRQS) {
115 dev_err(icu->dev, "invalid interrupt number %ld\n", *hwirq);
116 return -EINVAL;
117 }
118
119 /* Mask the type to prevent wrong DT configuration */
120 *type = fwspec->param[2] & IRQ_TYPE_SENSE_MASK;
121
122 return 0;
123}
124
125static int
126mvebu_icu_irq_domain_alloc(struct irq_domain *domain, unsigned int virq,
127 unsigned int nr_irqs, void *args)
128{
129 int err;
130 unsigned long hwirq;
131 struct irq_fwspec *fwspec = args;
132 struct mvebu_icu *icu = platform_msi_get_host_data(domain);
133 struct mvebu_icu_irq_data *icu_irqd;
134
135 icu_irqd = kmalloc(sizeof(*icu_irqd), GFP_KERNEL);
136 if (!icu_irqd)
137 return -ENOMEM;
138
139 err = mvebu_icu_irq_domain_translate(domain, fwspec, &hwirq,
140 &icu_irqd->type);
141 if (err) {
142 dev_err(icu->dev, "failed to translate ICU parameters\n");
143 goto free_irqd;
144 }
145
146 icu_irqd->icu_group = fwspec->param[0];
147 icu_irqd->icu = icu;
148
149 err = platform_msi_domain_alloc(domain, virq, nr_irqs);
150 if (err) {
151 dev_err(icu->dev, "failed to allocate ICU interrupt in parent domain\n");
152 goto free_irqd;
153 }
154
155 /* Make sure there is no interrupt left pending by the firmware */
156 err = irq_set_irqchip_state(virq, IRQCHIP_STATE_PENDING, false);
157 if (err)
158 goto free_msi;
159
160 err = irq_domain_set_hwirq_and_chip(domain, virq, hwirq,
161 &icu->irq_chip, icu_irqd);
162 if (err) {
163 dev_err(icu->dev, "failed to set the data to IRQ domain\n");
164 goto free_msi;
165 }
166
167 return 0;
168
169free_msi:
170 platform_msi_domain_free(domain, virq, nr_irqs);
171free_irqd:
172 kfree(icu_irqd);
173 return err;
174}
175
176static void
177mvebu_icu_irq_domain_free(struct irq_domain *domain, unsigned int virq,
178 unsigned int nr_irqs)
179{
180 struct irq_data *d = irq_get_irq_data(virq);
181 struct mvebu_icu_irq_data *icu_irqd = d->chip_data;
182
183 kfree(icu_irqd);
184
185 platform_msi_domain_free(domain, virq, nr_irqs);
186}
187
188static const struct irq_domain_ops mvebu_icu_domain_ops = {
189 .translate = mvebu_icu_irq_domain_translate,
190 .alloc = mvebu_icu_irq_domain_alloc,
191 .free = mvebu_icu_irq_domain_free,
192};
193
194static int mvebu_icu_probe(struct platform_device *pdev)
195{
196 struct mvebu_icu *icu;
197 struct device_node *node = pdev->dev.of_node;
198 struct device_node *gicp_dn;
199 struct resource *res;
200 phys_addr_t setspi, clrspi;
201 u32 i, icu_int;
202 int ret;
203
204 icu = devm_kzalloc(&pdev->dev, sizeof(struct mvebu_icu),
205 GFP_KERNEL);
206 if (!icu)
207 return -ENOMEM;
208
209 icu->dev = &pdev->dev;
210
211 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
212 icu->base = devm_ioremap_resource(&pdev->dev, res);
213 if (IS_ERR(icu->base)) {
214 dev_err(&pdev->dev, "Failed to map icu base address.\n");
215 return PTR_ERR(icu->base);
216 }
217
218 icu->irq_chip.name = devm_kasprintf(&pdev->dev, GFP_KERNEL,
219 "ICU.%x",
220 (unsigned int)res->start);
221 if (!icu->irq_chip.name)
222 return -ENOMEM;
223
224 icu->irq_chip.irq_mask = irq_chip_mask_parent;
225 icu->irq_chip.irq_unmask = irq_chip_unmask_parent;
226 icu->irq_chip.irq_eoi = irq_chip_eoi_parent;
227 icu->irq_chip.irq_set_type = irq_chip_set_type_parent;
228#ifdef CONFIG_SMP
229 icu->irq_chip.irq_set_affinity = irq_chip_set_affinity_parent;
230#endif
231
232 /*
233 * We're probed after MSI domains have been resolved, so force
234 * resolution here.
235 */
236 pdev->dev.msi_domain = of_msi_get_domain(&pdev->dev, node,
237 DOMAIN_BUS_PLATFORM_MSI);
238 if (!pdev->dev.msi_domain)
239 return -EPROBE_DEFER;
240
241 gicp_dn = irq_domain_get_of_node(pdev->dev.msi_domain);
242 if (!gicp_dn)
243 return -ENODEV;
244
245 ret = mvebu_gicp_get_doorbells(gicp_dn, &setspi, &clrspi);
246 if (ret)
247 return ret;
248
249 /* Set Clear/Set ICU SPI message address in AP */
250 writel_relaxed(upper_32_bits(setspi), icu->base + ICU_SETSPI_NSR_AH);
251 writel_relaxed(lower_32_bits(setspi), icu->base + ICU_SETSPI_NSR_AL);
252 writel_relaxed(upper_32_bits(clrspi), icu->base + ICU_CLRSPI_NSR_AH);
253 writel_relaxed(lower_32_bits(clrspi), icu->base + ICU_CLRSPI_NSR_AL);
254
255 /*
256 * Clean all ICU interrupts with type SPI_NSR, required to
257 * avoid unpredictable SPI assignments done by firmware.
258 */
259 for (i = 0 ; i < ICU_MAX_IRQS ; i++) {
260 icu_int = readl(icu->base + ICU_INT_CFG(i));
261 if ((icu_int >> ICU_GROUP_SHIFT) == ICU_GRP_NSR)
262 writel_relaxed(0x0, icu->base + ICU_INT_CFG(i));
263 }
264
265 icu->domain =
266 platform_msi_create_device_domain(&pdev->dev, ICU_MAX_IRQS,
267 mvebu_icu_write_msg,
268 &mvebu_icu_domain_ops, icu);
269 if (!icu->domain) {
270 dev_err(&pdev->dev, "Failed to create ICU domain\n");
271 return -ENOMEM;
272 }
273
274 return 0;
275}
276
277static const struct of_device_id mvebu_icu_of_match[] = {
278 { .compatible = "marvell,cp110-icu", },
279 {},
280};
281
282static struct platform_driver mvebu_icu_driver = {
283 .probe = mvebu_icu_probe,
284 .driver = {
285 .name = "mvebu-icu",
286 .of_match_table = mvebu_icu_of_match,
287 },
288};
289builtin_platform_driver(mvebu_icu_driver);
diff --git a/include/dt-bindings/interrupt-controller/mvebu-icu.h b/include/dt-bindings/interrupt-controller/mvebu-icu.h
new file mode 100644
index 000000000000..8249558545c7
--- /dev/null
+++ b/include/dt-bindings/interrupt-controller/mvebu-icu.h
@@ -0,0 +1,15 @@
1/*
2 * This header provides constants for the MVEBU ICU driver.
3 */
4
5#ifndef _DT_BINDINGS_INTERRUPT_CONTROLLER_MVEBU_ICU_H
6#define _DT_BINDINGS_INTERRUPT_CONTROLLER_MVEBU_ICU_H
7
8/* interrupt specifier cell 0 */
9
10#define ICU_GRP_NSR 0x0
11#define ICU_GRP_SR 0x1
12#define ICU_GRP_SEI 0x4
13#define ICU_GRP_REI 0x5
14
15#endif