1 // SPDX-License-Identifier: GPL-2.0
3 * irqchip for the IXP4xx interrupt controller
4 * Copyright (C) 2019 Linus Walleij <linus.walleij@linaro.org>
6 * Based on arch/arm/mach-ixp4xx/common.c
7 * Copyright 2002 (C) Intel Corporation
8 * Copyright 2003-2004 (C) MontaVista, Software, Inc.
9 * Copyright (C) Deepak Saxena <dsaxena@plexity.net>
11 #include <linux/bitops.h>
12 #include <linux/gpio/driver.h>
13 #include <linux/irq.h>
15 #include <linux/irqchip.h>
16 #include <linux/irqchip/irq-ixp4xx.h>
17 #include <linux/irqdomain.h>
19 #include <linux/of_address.h>
20 #include <linux/of_irq.h>
21 #include <linux/platform_device.h>
22 #include <linux/cpu.h>
24 #include <asm/exception.h>
25 #include <asm/mach/irq.h>
27 #define IXP4XX_ICPR 0x00 /* Interrupt Status */
28 #define IXP4XX_ICMR 0x04 /* Interrupt Enable */
29 #define IXP4XX_ICLR 0x08 /* Interrupt IRQ/FIQ Select */
30 #define IXP4XX_ICIP 0x0C /* IRQ Status */
31 #define IXP4XX_ICFP 0x10 /* FIQ Status */
32 #define IXP4XX_ICHR 0x14 /* Interrupt Priority */
33 #define IXP4XX_ICIH 0x18 /* IRQ Highest Pri Int */
34 #define IXP4XX_ICFH 0x1C /* FIQ Highest Pri Int */
36 /* IXP43x and IXP46x-only */
37 #define IXP4XX_ICPR2 0x20 /* Interrupt Status 2 */
38 #define IXP4XX_ICMR2 0x24 /* Interrupt Enable 2 */
39 #define IXP4XX_ICLR2 0x28 /* Interrupt IRQ/FIQ Select 2 */
40 #define IXP4XX_ICIP2 0x2C /* IRQ Status */
41 #define IXP4XX_ICFP2 0x30 /* FIQ Status */
42 #define IXP4XX_ICEEN 0x34 /* Error High Pri Enable */
45 * struct ixp4xx_irq - state container for the Faraday IRQ controller
46 * @irqbase: IRQ controller memory base in virtual memory
47 * @is_356: if this is an IXP43x, IXP45x or IX46x SoC (with 64 IRQs)
48 * @irqchip: irqchip for this instance
49 * @domain: IRQ domain for this instance
52 void __iomem *irqbase;
54 struct irq_chip irqchip;
55 struct irq_domain *domain;
58 /* Local static state container */
59 static struct ixp4xx_irq ixirq;
62 #define IXP4XX_GPIO_CLK_0 14
63 #define IXP4XX_GPIO_CLK_1 15
65 static int ixp4xx_set_irq_type(struct irq_data *d, unsigned int type)
67 /* All are level active high (asserted) here */
68 if (type != IRQ_TYPE_LEVEL_HIGH)
73 static void ixp4xx_irq_mask(struct irq_data *d)
75 struct ixp4xx_irq *ixi = irq_data_get_irq_chip_data(d);
78 if (ixi->is_356 && d->hwirq >= 32) {
79 val = __raw_readl(ixi->irqbase + IXP4XX_ICMR2);
80 val &= ~BIT(d->hwirq - 32);
81 __raw_writel(val, ixi->irqbase + IXP4XX_ICMR2);
83 val = __raw_readl(ixi->irqbase + IXP4XX_ICMR);
84 val &= ~BIT(d->hwirq);
85 __raw_writel(val, ixi->irqbase + IXP4XX_ICMR);
90 * Level triggered interrupts on GPIO lines can only be cleared when the
91 * interrupt condition disappears.
93 static void ixp4xx_irq_unmask(struct irq_data *d)
95 struct ixp4xx_irq *ixi = irq_data_get_irq_chip_data(d);
98 if (ixi->is_356 && d->hwirq >= 32) {
99 val = __raw_readl(ixi->irqbase + IXP4XX_ICMR2);
100 val |= BIT(d->hwirq - 32);
101 __raw_writel(val, ixi->irqbase + IXP4XX_ICMR2);
103 val = __raw_readl(ixi->irqbase + IXP4XX_ICMR);
104 val |= BIT(d->hwirq);
105 __raw_writel(val, ixi->irqbase + IXP4XX_ICMR);
109 asmlinkage void __exception_irq_entry ixp4xx_handle_irq(struct pt_regs *regs)
111 struct ixp4xx_irq *ixi = &ixirq;
112 unsigned long status;
115 status = __raw_readl(ixi->irqbase + IXP4XX_ICIP);
116 for_each_set_bit(i, &status, 32)
117 handle_domain_irq(ixi->domain, i, regs);
120 * IXP465/IXP435 has an upper IRQ status register
123 status = __raw_readl(ixi->irqbase + IXP4XX_ICIP2);
124 for_each_set_bit(i, &status, 32)
125 handle_domain_irq(ixi->domain, i + 32, regs);
129 static int ixp4xx_irq_domain_translate(struct irq_domain *domain,
130 struct irq_fwspec *fwspec,
131 unsigned long *hwirq,
134 /* We support standard DT translation */
135 if (is_of_node(fwspec->fwnode) && fwspec->param_count == 2) {
136 *hwirq = fwspec->param[0];
137 *type = fwspec->param[1];
141 if (is_fwnode_irqchip(fwspec->fwnode)) {
142 if (fwspec->param_count != 2)
144 *hwirq = fwspec->param[0];
145 *type = fwspec->param[1];
146 WARN_ON(*type == IRQ_TYPE_NONE);
153 static int ixp4xx_irq_domain_alloc(struct irq_domain *d,
154 unsigned int irq, unsigned int nr_irqs,
157 struct ixp4xx_irq *ixi = d->host_data;
158 irq_hw_number_t hwirq;
159 unsigned int type = IRQ_TYPE_NONE;
160 struct irq_fwspec *fwspec = data;
164 ret = ixp4xx_irq_domain_translate(d, fwspec, &hwirq, &type);
168 for (i = 0; i < nr_irqs; i++) {
170 * TODO: after converting IXP4xx to only device tree, set
171 * handle_bad_irq as default handler and assume all consumers
172 * call .set_type() as this is provided in the second cell in
173 * the device tree phandle.
175 irq_domain_set_info(d,
182 irq_set_probe(irq + i);
189 * This needs to be a hierarchical irqdomain to work well with the
190 * GPIO irqchip (which is lower in the hierarchy)
192 static const struct irq_domain_ops ixp4xx_irqdomain_ops = {
193 .translate = ixp4xx_irq_domain_translate,
194 .alloc = ixp4xx_irq_domain_alloc,
195 .free = irq_domain_free_irqs_common,
199 * ixp4xx_get_irq_domain() - retrieve the ixp4xx irq domain
201 * This function will go away when we transition to DT probing.
203 struct irq_domain *ixp4xx_get_irq_domain(void)
205 struct ixp4xx_irq *ixi = &ixirq;
209 EXPORT_SYMBOL_GPL(ixp4xx_get_irq_domain);
212 * This is the Linux IRQ to hwirq mapping table. This goes away when
213 * we have DT support as all IRQ resources are defined in the device
214 * tree. It will register all the IRQs that are not used by the hierarchical
215 * GPIO IRQ chip. The "holes" inbetween these IRQs will be requested by
216 * the GPIO driver using . This is a step-gap solution.
218 struct ixp4xx_irq_chunk {
224 static const struct ixp4xx_irq_chunk ixp4xx_irq_chunks[] = {
240 /* Only on the 436 variants */
249 * ixp4x_irq_setup() - Common setup code for the IXP4xx interrupt controller
250 * @ixi: State container
251 * @irqbase: Virtual memory base for the interrupt controller
252 * @fwnode: Corresponding fwnode abstraction for this controller
253 * @is_356: if this is an IXP43x, IXP45x or IXP46x SoC variant
255 static int __init ixp4xx_irq_setup(struct ixp4xx_irq *ixi,
256 void __iomem *irqbase,
257 struct fwnode_handle *fwnode,
262 ixi->irqbase = irqbase;
263 ixi->is_356 = is_356;
265 /* Route all sources to IRQ instead of FIQ */
266 __raw_writel(0x0, ixi->irqbase + IXP4XX_ICLR);
268 /* Disable all interrupts */
269 __raw_writel(0x0, ixi->irqbase + IXP4XX_ICMR);
272 /* Route upper 32 sources to IRQ instead of FIQ */
273 __raw_writel(0x0, ixi->irqbase + IXP4XX_ICLR2);
275 /* Disable upper 32 interrupts */
276 __raw_writel(0x0, ixi->irqbase + IXP4XX_ICMR2);
283 ixi->irqchip.name = "IXP4xx";
284 ixi->irqchip.irq_mask = ixp4xx_irq_mask;
285 ixi->irqchip.irq_unmask = ixp4xx_irq_unmask;
286 ixi->irqchip.irq_set_type = ixp4xx_set_irq_type;
288 ixi->domain = irq_domain_create_linear(fwnode, nr_irqs,
289 &ixp4xx_irqdomain_ops,
292 pr_crit("IXP4XX: can not add primary irqdomain\n");
296 set_handle_irq(ixp4xx_handle_irq);
302 * ixp4xx_irq_init() - Function to initialize the irqchip from boardfiles
303 * @irqbase: physical base for the irq controller
304 * @is_356: if this is an IXP43x, IXP45x or IXP46x SoC variant
306 void __init ixp4xx_irq_init(resource_size_t irqbase,
309 struct ixp4xx_irq *ixi = &ixirq;
311 struct fwnode_handle *fwnode;
312 struct irq_fwspec fwspec;
317 base = ioremap(irqbase, 0x100);
319 pr_crit("IXP4XX: could not ioremap interrupt controller\n");
322 fwnode = irq_domain_alloc_fwnode(&irqbase);
324 pr_crit("IXP4XX: no domain handle\n");
327 ret = ixp4xx_irq_setup(ixi, base, fwnode, is_356);
329 pr_crit("IXP4XX: failed to set up irqchip\n");
330 irq_domain_free_fwnode(fwnode);
333 nr_chunks = ARRAY_SIZE(ixp4xx_irq_chunks);
338 * After adding OF support, this is no longer needed: irqs
339 * will be allocated for the respective fwnodes.
341 for (i = 0; i < nr_chunks; i++) {
342 const struct ixp4xx_irq_chunk *chunk = &ixp4xx_irq_chunks[i];
344 pr_info("Allocate Linux IRQs %d..%d HW IRQs %d..%d\n",
345 chunk->irq, chunk->irq + chunk->nr_irqs - 1,
346 chunk->hwirq, chunk->hwirq + chunk->nr_irqs - 1);
347 fwspec.fwnode = fwnode;
348 fwspec.param[0] = chunk->hwirq;
349 fwspec.param[1] = IRQ_TYPE_LEVEL_HIGH;
350 fwspec.param_count = 2;
351 ret = __irq_domain_alloc_irqs(ixi->domain,
359 pr_crit("IXP4XX: can not allocate irqs in hierarchy %d\n",
365 EXPORT_SYMBOL_GPL(ixp4xx_irq_init);
368 int __init ixp4xx_of_init_irq(struct device_node *np,
369 struct device_node *parent)
371 struct ixp4xx_irq *ixi = &ixirq;
373 struct fwnode_handle *fwnode;
377 base = of_iomap(np, 0);
379 pr_crit("IXP4XX: could not ioremap interrupt controller\n");
382 fwnode = of_node_to_fwnode(np);
384 /* These chip variants have 64 interrupts */
385 is_356 = of_device_is_compatible(np, "intel,ixp43x-interrupt") ||
386 of_device_is_compatible(np, "intel,ixp45x-interrupt") ||
387 of_device_is_compatible(np, "intel,ixp46x-interrupt");
389 ret = ixp4xx_irq_setup(ixi, base, fwnode, is_356);
391 pr_crit("IXP4XX: failed to set up irqchip\n");
395 IRQCHIP_DECLARE(ixp42x, "intel,ixp42x-interrupt",
397 IRQCHIP_DECLARE(ixp43x, "intel,ixp43x-interrupt",
399 IRQCHIP_DECLARE(ixp45x, "intel,ixp45x-interrupt",
401 IRQCHIP_DECLARE(ixp46x, "intel,ixp46x-interrupt",