2 * Allwinner A1X SoCs IRQ chip driver.
4 * Copyright (C) 2012 Maxime Ripard
6 * Maxime Ripard <maxime.ripard@free-electrons.com>
9 * Allwinner Technology Co., Ltd. <www.allwinnertech.com>
10 * Benn Huang <benn@allwinnertech.com>
12 * This file is licensed under the terms of the GNU General Public
13 * License version 2. This program is licensed "as is" without any
14 * warranty of any kind, whether express or implied.
18 #include <linux/irq.h>
20 #include <linux/of_address.h>
21 #include <linux/of_irq.h>
23 #include <linux/irqchip/sunxi.h>
25 #define SUNXI_IRQ_VECTOR_REG 0x00
26 #define SUNXI_IRQ_PROTECTION_REG 0x08
27 #define SUNXI_IRQ_NMI_CTRL_REG 0x0c
28 #define SUNXI_IRQ_PENDING_REG(x) (0x10 + 0x4 * x)
29 #define SUNXI_IRQ_FIQ_PENDING_REG(x) (0x20 + 0x4 * x)
30 #define SUNXI_IRQ_ENABLE_REG(x) (0x40 + 0x4 * x)
31 #define SUNXI_IRQ_MASK_REG(x) (0x50 + 0x4 * x)
33 static void __iomem
*sunxi_irq_base
;
34 static struct irq_domain
*sunxi_irq_domain
;
36 void sunxi_irq_ack(struct irq_data
*irqd
)
38 unsigned int irq
= irqd_to_hwirq(irqd
);
39 unsigned int irq_off
= irq
% 32;
43 val
= readl(sunxi_irq_base
+ SUNXI_IRQ_PENDING_REG(reg
));
44 writel(val
| (1 << irq_off
),
45 sunxi_irq_base
+ SUNXI_IRQ_PENDING_REG(reg
));
48 static void sunxi_irq_mask(struct irq_data
*irqd
)
50 unsigned int irq
= irqd_to_hwirq(irqd
);
51 unsigned int irq_off
= irq
% 32;
55 val
= readl(sunxi_irq_base
+ SUNXI_IRQ_ENABLE_REG(reg
));
56 writel(val
& ~(1 << irq_off
),
57 sunxi_irq_base
+ SUNXI_IRQ_ENABLE_REG(reg
));
60 static void sunxi_irq_unmask(struct irq_data
*irqd
)
62 unsigned int irq
= irqd_to_hwirq(irqd
);
63 unsigned int irq_off
= irq
% 32;
67 val
= readl(sunxi_irq_base
+ SUNXI_IRQ_ENABLE_REG(reg
));
68 writel(val
| (1 << irq_off
),
69 sunxi_irq_base
+ SUNXI_IRQ_ENABLE_REG(reg
));
72 static struct irq_chip sunxi_irq_chip
= {
74 .irq_ack
= sunxi_irq_ack
,
75 .irq_mask
= sunxi_irq_mask
,
76 .irq_unmask
= sunxi_irq_unmask
,
79 static int sunxi_irq_map(struct irq_domain
*d
, unsigned int virq
,
82 irq_set_chip_and_handler(virq
, &sunxi_irq_chip
,
84 set_irq_flags(virq
, IRQF_VALID
| IRQF_PROBE
);
89 static struct irq_domain_ops sunxi_irq_ops
= {
91 .xlate
= irq_domain_xlate_onecell
,
94 static int __init
sunxi_of_init(struct device_node
*node
,
95 struct device_node
*parent
)
97 sunxi_irq_base
= of_iomap(node
, 0);
99 panic("%s: unable to map IC registers\n",
102 /* Disable all interrupts */
103 writel(0, sunxi_irq_base
+ SUNXI_IRQ_ENABLE_REG(0));
104 writel(0, sunxi_irq_base
+ SUNXI_IRQ_ENABLE_REG(1));
105 writel(0, sunxi_irq_base
+ SUNXI_IRQ_ENABLE_REG(2));
107 /* Mask all the interrupts */
108 writel(0, sunxi_irq_base
+ SUNXI_IRQ_MASK_REG(0));
109 writel(0, sunxi_irq_base
+ SUNXI_IRQ_MASK_REG(1));
110 writel(0, sunxi_irq_base
+ SUNXI_IRQ_MASK_REG(2));
112 /* Clear all the pending interrupts */
113 writel(0xffffffff, sunxi_irq_base
+ SUNXI_IRQ_PENDING_REG(0));
114 writel(0xffffffff, sunxi_irq_base
+ SUNXI_IRQ_PENDING_REG(1));
115 writel(0xffffffff, sunxi_irq_base
+ SUNXI_IRQ_PENDING_REG(2));
117 /* Enable protection mode */
118 writel(0x01, sunxi_irq_base
+ SUNXI_IRQ_PROTECTION_REG
);
120 /* Configure the external interrupt source type */
121 writel(0x00, sunxi_irq_base
+ SUNXI_IRQ_NMI_CTRL_REG
);
123 sunxi_irq_domain
= irq_domain_add_linear(node
, 3 * 32,
124 &sunxi_irq_ops
, NULL
);
125 if (!sunxi_irq_domain
)
126 panic("%s: unable to create IRQ domain\n", node
->full_name
);
131 static struct of_device_id sunxi_irq_dt_ids
[] __initconst
= {
132 { .compatible
= "allwinner,sunxi-ic", .data
= sunxi_of_init
},
136 void __init
sunxi_init_irq(void)
138 of_irq_init(sunxi_irq_dt_ids
);
141 asmlinkage
void __exception_irq_entry
sunxi_handle_irq(struct pt_regs
*regs
)
145 hwirq
= readl(sunxi_irq_base
+ SUNXI_IRQ_VECTOR_REG
) >> 2;
147 irq
= irq_find_mapping(sunxi_irq_domain
, hwirq
);
148 handle_IRQ(irq
, regs
);
149 hwirq
= readl(sunxi_irq_base
+ SUNXI_IRQ_VECTOR_REG
) >> 2;