arcnet: Add and remove blank lines
[linux-2.6/btrfs-unstable.git] / drivers / irqchip / irq-tegra.c
blob2fd89eb88f3a29bc716ec1daf76ad4085e6a743d
1 /*
2 * Driver code for Tegra's Legacy Interrupt Controller
4 * Author: Marc Zyngier <marc.zyngier@arm.com>
6 * Heavily based on the original arch/arm/mach-tegra/irq.c code:
7 * Copyright (C) 2011 Google, Inc.
9 * Author:
10 * Colin Cross <ccross@android.com>
12 * Copyright (C) 2010,2013, NVIDIA Corporation
14 * This software is licensed under the terms of the GNU General Public
15 * License version 2, as published by the Free Software Foundation, and
16 * may be copied, distributed, and modified under those terms.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
25 #include <linux/io.h>
26 #include <linux/irq.h>
27 #include <linux/irqchip.h>
28 #include <linux/irqdomain.h>
29 #include <linux/of_address.h>
30 #include <linux/slab.h>
31 #include <linux/syscore_ops.h>
33 #include <dt-bindings/interrupt-controller/arm-gic.h>
35 #define ICTLR_CPU_IEP_VFIQ 0x08
36 #define ICTLR_CPU_IEP_FIR 0x14
37 #define ICTLR_CPU_IEP_FIR_SET 0x18
38 #define ICTLR_CPU_IEP_FIR_CLR 0x1c
40 #define ICTLR_CPU_IER 0x20
41 #define ICTLR_CPU_IER_SET 0x24
42 #define ICTLR_CPU_IER_CLR 0x28
43 #define ICTLR_CPU_IEP_CLASS 0x2C
45 #define ICTLR_COP_IER 0x30
46 #define ICTLR_COP_IER_SET 0x34
47 #define ICTLR_COP_IER_CLR 0x38
48 #define ICTLR_COP_IEP_CLASS 0x3c
50 #define TEGRA_MAX_NUM_ICTLRS 6
52 static unsigned int num_ictlrs;
54 struct tegra_ictlr_soc {
55 unsigned int num_ictlrs;
58 static const struct tegra_ictlr_soc tegra20_ictlr_soc = {
59 .num_ictlrs = 4,
62 static const struct tegra_ictlr_soc tegra30_ictlr_soc = {
63 .num_ictlrs = 5,
66 static const struct tegra_ictlr_soc tegra210_ictlr_soc = {
67 .num_ictlrs = 6,
70 static const struct of_device_id ictlr_matches[] = {
71 { .compatible = "nvidia,tegra210-ictlr", .data = &tegra210_ictlr_soc },
72 { .compatible = "nvidia,tegra30-ictlr", .data = &tegra30_ictlr_soc },
73 { .compatible = "nvidia,tegra20-ictlr", .data = &tegra20_ictlr_soc },
74 { }
77 struct tegra_ictlr_info {
78 void __iomem *base[TEGRA_MAX_NUM_ICTLRS];
79 #ifdef CONFIG_PM_SLEEP
80 u32 cop_ier[TEGRA_MAX_NUM_ICTLRS];
81 u32 cop_iep[TEGRA_MAX_NUM_ICTLRS];
82 u32 cpu_ier[TEGRA_MAX_NUM_ICTLRS];
83 u32 cpu_iep[TEGRA_MAX_NUM_ICTLRS];
85 u32 ictlr_wake_mask[TEGRA_MAX_NUM_ICTLRS];
86 #endif
89 static struct tegra_ictlr_info *lic;
91 static inline void tegra_ictlr_write_mask(struct irq_data *d, unsigned long reg)
93 void __iomem *base = d->chip_data;
94 u32 mask;
96 mask = BIT(d->hwirq % 32);
97 writel_relaxed(mask, base + reg);
100 static void tegra_mask(struct irq_data *d)
102 tegra_ictlr_write_mask(d, ICTLR_CPU_IER_CLR);
103 irq_chip_mask_parent(d);
106 static void tegra_unmask(struct irq_data *d)
108 tegra_ictlr_write_mask(d, ICTLR_CPU_IER_SET);
109 irq_chip_unmask_parent(d);
112 static void tegra_eoi(struct irq_data *d)
114 tegra_ictlr_write_mask(d, ICTLR_CPU_IEP_FIR_CLR);
115 irq_chip_eoi_parent(d);
118 static int tegra_retrigger(struct irq_data *d)
120 tegra_ictlr_write_mask(d, ICTLR_CPU_IEP_FIR_SET);
121 return irq_chip_retrigger_hierarchy(d);
124 #ifdef CONFIG_PM_SLEEP
125 static int tegra_set_wake(struct irq_data *d, unsigned int enable)
127 u32 irq = d->hwirq;
128 u32 index, mask;
130 index = (irq / 32);
131 mask = BIT(irq % 32);
132 if (enable)
133 lic->ictlr_wake_mask[index] |= mask;
134 else
135 lic->ictlr_wake_mask[index] &= ~mask;
138 * Do *not* call into the parent, as the GIC doesn't have any
139 * wake-up facility...
141 return 0;
144 static int tegra_ictlr_suspend(void)
146 unsigned long flags;
147 unsigned int i;
149 local_irq_save(flags);
150 for (i = 0; i < num_ictlrs; i++) {
151 void __iomem *ictlr = lic->base[i];
153 /* Save interrupt state */
154 lic->cpu_ier[i] = readl_relaxed(ictlr + ICTLR_CPU_IER);
155 lic->cpu_iep[i] = readl_relaxed(ictlr + ICTLR_CPU_IEP_CLASS);
156 lic->cop_ier[i] = readl_relaxed(ictlr + ICTLR_COP_IER);
157 lic->cop_iep[i] = readl_relaxed(ictlr + ICTLR_COP_IEP_CLASS);
159 /* Disable COP interrupts */
160 writel_relaxed(~0ul, ictlr + ICTLR_COP_IER_CLR);
162 /* Disable CPU interrupts */
163 writel_relaxed(~0ul, ictlr + ICTLR_CPU_IER_CLR);
165 /* Enable the wakeup sources of ictlr */
166 writel_relaxed(lic->ictlr_wake_mask[i], ictlr + ICTLR_CPU_IER_SET);
168 local_irq_restore(flags);
170 return 0;
173 static void tegra_ictlr_resume(void)
175 unsigned long flags;
176 unsigned int i;
178 local_irq_save(flags);
179 for (i = 0; i < num_ictlrs; i++) {
180 void __iomem *ictlr = lic->base[i];
182 writel_relaxed(lic->cpu_iep[i],
183 ictlr + ICTLR_CPU_IEP_CLASS);
184 writel_relaxed(~0ul, ictlr + ICTLR_CPU_IER_CLR);
185 writel_relaxed(lic->cpu_ier[i],
186 ictlr + ICTLR_CPU_IER_SET);
187 writel_relaxed(lic->cop_iep[i],
188 ictlr + ICTLR_COP_IEP_CLASS);
189 writel_relaxed(~0ul, ictlr + ICTLR_COP_IER_CLR);
190 writel_relaxed(lic->cop_ier[i],
191 ictlr + ICTLR_COP_IER_SET);
193 local_irq_restore(flags);
196 static struct syscore_ops tegra_ictlr_syscore_ops = {
197 .suspend = tegra_ictlr_suspend,
198 .resume = tegra_ictlr_resume,
201 static void tegra_ictlr_syscore_init(void)
203 register_syscore_ops(&tegra_ictlr_syscore_ops);
205 #else
206 #define tegra_set_wake NULL
207 static inline void tegra_ictlr_syscore_init(void) {}
208 #endif
210 static struct irq_chip tegra_ictlr_chip = {
211 .name = "LIC",
212 .irq_eoi = tegra_eoi,
213 .irq_mask = tegra_mask,
214 .irq_unmask = tegra_unmask,
215 .irq_retrigger = tegra_retrigger,
216 .irq_set_wake = tegra_set_wake,
217 .flags = IRQCHIP_MASK_ON_SUSPEND,
218 #ifdef CONFIG_SMP
219 .irq_set_affinity = irq_chip_set_affinity_parent,
220 #endif
223 static int tegra_ictlr_domain_xlate(struct irq_domain *domain,
224 struct device_node *controller,
225 const u32 *intspec,
226 unsigned int intsize,
227 unsigned long *out_hwirq,
228 unsigned int *out_type)
230 if (domain->of_node != controller)
231 return -EINVAL; /* Shouldn't happen, really... */
232 if (intsize != 3)
233 return -EINVAL; /* Not GIC compliant */
234 if (intspec[0] != GIC_SPI)
235 return -EINVAL; /* No PPI should point to this domain */
237 *out_hwirq = intspec[1];
238 *out_type = intspec[2];
239 return 0;
242 static int tegra_ictlr_domain_alloc(struct irq_domain *domain,
243 unsigned int virq,
244 unsigned int nr_irqs, void *data)
246 struct of_phandle_args *args = data;
247 struct of_phandle_args parent_args;
248 struct tegra_ictlr_info *info = domain->host_data;
249 irq_hw_number_t hwirq;
250 unsigned int i;
252 if (args->args_count != 3)
253 return -EINVAL; /* Not GIC compliant */
254 if (args->args[0] != GIC_SPI)
255 return -EINVAL; /* No PPI should point to this domain */
257 hwirq = args->args[1];
258 if (hwirq >= (num_ictlrs * 32))
259 return -EINVAL;
261 for (i = 0; i < nr_irqs; i++) {
262 int ictlr = (hwirq + i) / 32;
264 irq_domain_set_hwirq_and_chip(domain, virq + i, hwirq + i,
265 &tegra_ictlr_chip,
266 info->base[ictlr]);
269 parent_args = *args;
270 parent_args.np = domain->parent->of_node;
271 return irq_domain_alloc_irqs_parent(domain, virq, nr_irqs, &parent_args);
274 static void tegra_ictlr_domain_free(struct irq_domain *domain,
275 unsigned int virq,
276 unsigned int nr_irqs)
278 unsigned int i;
280 for (i = 0; i < nr_irqs; i++) {
281 struct irq_data *d = irq_domain_get_irq_data(domain, virq + i);
282 irq_domain_reset_irq_data(d);
286 static const struct irq_domain_ops tegra_ictlr_domain_ops = {
287 .xlate = tegra_ictlr_domain_xlate,
288 .alloc = tegra_ictlr_domain_alloc,
289 .free = tegra_ictlr_domain_free,
292 static int __init tegra_ictlr_init(struct device_node *node,
293 struct device_node *parent)
295 struct irq_domain *parent_domain, *domain;
296 const struct of_device_id *match;
297 const struct tegra_ictlr_soc *soc;
298 unsigned int i;
299 int err;
301 if (!parent) {
302 pr_err("%s: no parent, giving up\n", node->full_name);
303 return -ENODEV;
306 parent_domain = irq_find_host(parent);
307 if (!parent_domain) {
308 pr_err("%s: unable to obtain parent domain\n", node->full_name);
309 return -ENXIO;
312 match = of_match_node(ictlr_matches, node);
313 if (!match) /* Should never happen... */
314 return -ENODEV;
316 soc = match->data;
318 lic = kzalloc(sizeof(*lic), GFP_KERNEL);
319 if (!lic)
320 return -ENOMEM;
322 for (i = 0; i < TEGRA_MAX_NUM_ICTLRS; i++) {
323 void __iomem *base;
325 base = of_iomap(node, i);
326 if (!base)
327 break;
329 lic->base[i] = base;
331 /* Disable all interrupts */
332 writel_relaxed(~0UL, base + ICTLR_CPU_IER_CLR);
333 /* All interrupts target IRQ */
334 writel_relaxed(0, base + ICTLR_CPU_IEP_CLASS);
336 num_ictlrs++;
339 if (!num_ictlrs) {
340 pr_err("%s: no valid regions, giving up\n", node->full_name);
341 err = -ENOMEM;
342 goto out_free;
345 WARN(num_ictlrs != soc->num_ictlrs,
346 "%s: Found %u interrupt controllers in DT; expected %u.\n",
347 node->full_name, num_ictlrs, soc->num_ictlrs);
350 domain = irq_domain_add_hierarchy(parent_domain, 0, num_ictlrs * 32,
351 node, &tegra_ictlr_domain_ops,
352 lic);
353 if (!domain) {
354 pr_err("%s: failed to allocated domain\n", node->full_name);
355 err = -ENOMEM;
356 goto out_unmap;
359 tegra_ictlr_syscore_init();
361 pr_info("%s: %d interrupts forwarded to %s\n",
362 node->full_name, num_ictlrs * 32, parent->full_name);
364 return 0;
366 out_unmap:
367 for (i = 0; i < num_ictlrs; i++)
368 iounmap(lic->base[i]);
369 out_free:
370 kfree(lic);
371 return err;
374 IRQCHIP_DECLARE(tegra20_ictlr, "nvidia,tegra20-ictlr", tegra_ictlr_init);
375 IRQCHIP_DECLARE(tegra30_ictlr, "nvidia,tegra30-ictlr", tegra_ictlr_init);
376 IRQCHIP_DECLARE(tegra210_ictlr, "nvidia,tegra210-ictlr", tegra_ictlr_init);