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>
18 #include <linux/platform_device.h>
19 #include <linux/cpu.h>
21 #include <asm/exception.h>
22 #include <asm/mach/irq.h>
24 #define IXP4XX_ICPR 0x00 /* Interrupt Status */
25 #define IXP4XX_ICMR 0x04 /* Interrupt Enable */
26 #define IXP4XX_ICLR 0x08 /* Interrupt IRQ/FIQ Select */
27 #define IXP4XX_ICIP 0x0C /* IRQ Status */
28 #define IXP4XX_ICFP 0x10 /* FIQ Status */
29 #define IXP4XX_ICHR 0x14 /* Interrupt Priority */
30 #define IXP4XX_ICIH 0x18 /* IRQ Highest Pri Int */
31 #define IXP4XX_ICFH 0x1C /* FIQ Highest Pri Int */
33 /* IXP43x and IXP46x-only */
34 #define IXP4XX_ICPR2 0x20 /* Interrupt Status 2 */
35 #define IXP4XX_ICMR2 0x24 /* Interrupt Enable 2 */
36 #define IXP4XX_ICLR2 0x28 /* Interrupt IRQ/FIQ Select 2 */
37 #define IXP4XX_ICIP2 0x2C /* IRQ Status */
38 #define IXP4XX_ICFP2 0x30 /* FIQ Status */
39 #define IXP4XX_ICEEN 0x34 /* Error High Pri Enable */
42 * struct ixp4xx_irq - state container for the Faraday IRQ controller
43 * @irqbase: IRQ controller memory base in virtual memory
44 * @is_356: if this is an IXP43x, IXP45x or IX46x SoC (with 64 IRQs)
45 * @irqchip: irqchip for this instance
46 * @domain: IRQ domain for this instance
49 void __iomem
*irqbase
;
51 struct irq_chip irqchip
;
52 struct irq_domain
*domain
;
55 /* Local static state container */
56 static struct ixp4xx_irq ixirq
;
59 #define IXP4XX_GPIO_CLK_0 14
60 #define IXP4XX_GPIO_CLK_1 15
62 static int ixp4xx_set_irq_type(struct irq_data
*d
, unsigned int type
)
64 /* All are level active high (asserted) here */
65 if (type
!= IRQ_TYPE_LEVEL_HIGH
)
70 static void ixp4xx_irq_mask(struct irq_data
*d
)
72 struct ixp4xx_irq
*ixi
= irq_data_get_irq_chip_data(d
);
75 if (ixi
->is_356
&& d
->hwirq
>= 32) {
76 val
= __raw_readl(ixi
->irqbase
+ IXP4XX_ICMR2
);
77 val
&= ~BIT(d
->hwirq
- 32);
78 __raw_writel(val
, ixi
->irqbase
+ IXP4XX_ICMR2
);
80 val
= __raw_readl(ixi
->irqbase
+ IXP4XX_ICMR
);
81 val
&= ~BIT(d
->hwirq
);
82 __raw_writel(val
, ixi
->irqbase
+ IXP4XX_ICMR
);
87 * Level triggered interrupts on GPIO lines can only be cleared when the
88 * interrupt condition disappears.
90 static void ixp4xx_irq_unmask(struct irq_data
*d
)
92 struct ixp4xx_irq
*ixi
= irq_data_get_irq_chip_data(d
);
95 if (ixi
->is_356
&& d
->hwirq
>= 32) {
96 val
= __raw_readl(ixi
->irqbase
+ IXP4XX_ICMR2
);
97 val
|= BIT(d
->hwirq
- 32);
98 __raw_writel(val
, ixi
->irqbase
+ IXP4XX_ICMR2
);
100 val
= __raw_readl(ixi
->irqbase
+ IXP4XX_ICMR
);
101 val
|= BIT(d
->hwirq
);
102 __raw_writel(val
, ixi
->irqbase
+ IXP4XX_ICMR
);
106 asmlinkage
void __exception_irq_entry
ixp4xx_handle_irq(struct pt_regs
*regs
)
108 struct ixp4xx_irq
*ixi
= &ixirq
;
109 unsigned long status
;
112 status
= __raw_readl(ixi
->irqbase
+ IXP4XX_ICIP
);
113 for_each_set_bit(i
, &status
, 32)
114 handle_domain_irq(ixi
->domain
, i
, regs
);
117 * IXP465/IXP435 has an upper IRQ status register
120 status
= __raw_readl(ixi
->irqbase
+ IXP4XX_ICIP2
);
121 for_each_set_bit(i
, &status
, 32)
122 handle_domain_irq(ixi
->domain
, i
+ 32, regs
);
126 static int ixp4xx_irq_domain_translate(struct irq_domain
*domain
,
127 struct irq_fwspec
*fwspec
,
128 unsigned long *hwirq
,
131 /* We support standard DT translation */
132 if (is_of_node(fwspec
->fwnode
) && fwspec
->param_count
== 2) {
133 *hwirq
= fwspec
->param
[0];
134 *type
= fwspec
->param
[1];
138 if (is_fwnode_irqchip(fwspec
->fwnode
)) {
139 if (fwspec
->param_count
!= 2)
141 *hwirq
= fwspec
->param
[0];
142 *type
= fwspec
->param
[1];
143 WARN_ON(*type
== IRQ_TYPE_NONE
);
150 static int ixp4xx_irq_domain_alloc(struct irq_domain
*d
,
151 unsigned int irq
, unsigned int nr_irqs
,
154 struct ixp4xx_irq
*ixi
= d
->host_data
;
155 irq_hw_number_t hwirq
;
156 unsigned int type
= IRQ_TYPE_NONE
;
157 struct irq_fwspec
*fwspec
= data
;
161 ret
= ixp4xx_irq_domain_translate(d
, fwspec
, &hwirq
, &type
);
165 for (i
= 0; i
< nr_irqs
; i
++) {
167 * TODO: after converting IXP4xx to only device tree, set
168 * handle_bad_irq as default handler and assume all consumers
169 * call .set_type() as this is provided in the second cell in
170 * the device tree phandle.
172 irq_domain_set_info(d
,
179 irq_set_probe(irq
+ i
);
186 * This needs to be a hierarchical irqdomain to work well with the
187 * GPIO irqchip (which is lower in the hierarchy)
189 static const struct irq_domain_ops ixp4xx_irqdomain_ops
= {
190 .translate
= ixp4xx_irq_domain_translate
,
191 .alloc
= ixp4xx_irq_domain_alloc
,
192 .free
= irq_domain_free_irqs_common
,
196 * ixp4xx_get_irq_domain() - retrieve the ixp4xx irq domain
198 * This function will go away when we transition to DT probing.
200 struct irq_domain
*ixp4xx_get_irq_domain(void)
202 struct ixp4xx_irq
*ixi
= &ixirq
;
206 EXPORT_SYMBOL_GPL(ixp4xx_get_irq_domain
);
209 * This is the Linux IRQ to hwirq mapping table. This goes away when
210 * we have DT support as all IRQ resources are defined in the device
211 * tree. It will register all the IRQs that are not used by the hierarchical
212 * GPIO IRQ chip. The "holes" inbetween these IRQs will be requested by
213 * the GPIO driver using . This is a step-gap solution.
215 struct ixp4xx_irq_chunk
{
221 static const struct ixp4xx_irq_chunk ixp4xx_irq_chunks
[] = {
237 /* Only on the 436 variants */
246 * ixp4x_irq_setup() - Common setup code for the IXP4xx interrupt controller
247 * @ixi: State container
248 * @irqbase: Virtual memory base for the interrupt controller
249 * @fwnode: Corresponding fwnode abstraction for this controller
250 * @is_356: if this is an IXP43x, IXP45x or IXP46x SoC variant
252 static int ixp4xx_irq_setup(struct ixp4xx_irq
*ixi
,
253 void __iomem
*irqbase
,
254 struct fwnode_handle
*fwnode
,
259 ixi
->irqbase
= irqbase
;
260 ixi
->is_356
= is_356
;
262 /* Route all sources to IRQ instead of FIQ */
263 __raw_writel(0x0, ixi
->irqbase
+ IXP4XX_ICLR
);
265 /* Disable all interrupts */
266 __raw_writel(0x0, ixi
->irqbase
+ IXP4XX_ICMR
);
269 /* Route upper 32 sources to IRQ instead of FIQ */
270 __raw_writel(0x0, ixi
->irqbase
+ IXP4XX_ICLR2
);
272 /* Disable upper 32 interrupts */
273 __raw_writel(0x0, ixi
->irqbase
+ IXP4XX_ICMR2
);
280 ixi
->irqchip
.name
= "IXP4xx";
281 ixi
->irqchip
.irq_mask
= ixp4xx_irq_mask
;
282 ixi
->irqchip
.irq_unmask
= ixp4xx_irq_unmask
;
283 ixi
->irqchip
.irq_set_type
= ixp4xx_set_irq_type
;
285 ixi
->domain
= irq_domain_create_linear(fwnode
, nr_irqs
,
286 &ixp4xx_irqdomain_ops
,
289 pr_crit("IXP4XX: can not add primary irqdomain\n");
293 set_handle_irq(ixp4xx_handle_irq
);
299 * ixp4xx_irq_init() - Function to initialize the irqchip from boardfiles
300 * @irqbase: physical base for the irq controller
301 * @is_356: if this is an IXP43x, IXP45x or IXP46x SoC variant
303 void __init
ixp4xx_irq_init(resource_size_t irqbase
,
306 struct ixp4xx_irq
*ixi
= &ixirq
;
308 struct fwnode_handle
*fwnode
;
309 struct irq_fwspec fwspec
;
314 base
= ioremap(irqbase
, 0x100);
316 pr_crit("IXP4XX: could not ioremap interrupt controller\n");
319 fwnode
= irq_domain_alloc_fwnode(base
);
321 pr_crit("IXP4XX: no domain handle\n");
324 ret
= ixp4xx_irq_setup(ixi
, base
, fwnode
, is_356
);
326 pr_crit("IXP4XX: failed to set up irqchip\n");
327 irq_domain_free_fwnode(fwnode
);
330 nr_chunks
= ARRAY_SIZE(ixp4xx_irq_chunks
);
335 * After adding OF support, this is no longer needed: irqs
336 * will be allocated for the respective fwnodes.
338 for (i
= 0; i
< nr_chunks
; i
++) {
339 const struct ixp4xx_irq_chunk
*chunk
= &ixp4xx_irq_chunks
[i
];
341 pr_info("Allocate Linux IRQs %d..%d HW IRQs %d..%d\n",
342 chunk
->irq
, chunk
->irq
+ chunk
->nr_irqs
- 1,
343 chunk
->hwirq
, chunk
->hwirq
+ chunk
->nr_irqs
- 1);
344 fwspec
.fwnode
= fwnode
;
345 fwspec
.param
[0] = chunk
->hwirq
;
346 fwspec
.param
[1] = IRQ_TYPE_LEVEL_HIGH
;
347 fwspec
.param_count
= 2;
348 ret
= __irq_domain_alloc_irqs(ixi
->domain
,
356 pr_crit("IXP4XX: can not allocate irqs in hierarchy %d\n",
362 EXPORT_SYMBOL_GPL(ixp4xx_irq_init
);