Blame view
drivers/irqchip/irq-sunxi-nmi.c
7.2 KB
6058bb362 ARM: sun7i/sun6i:... |
1 2 3 4 5 6 7 8 9 |
/* * Allwinner A20/A31 SoCs NMI IRQ chip driver. * * Carlo Caione <carlo.caione@gmail.com> * * This file is licensed under the terms of the GNU General Public * License version 2. This program is licensed "as is" without any * warranty of any kind, whether express or implied. */ |
2d6caaed0 irqchip/sunxi-nmi... |
10 11 |
#define DRV_NAME "sunxi-nmi" #define pr_fmt(fmt) DRV_NAME ": " fmt |
6058bb362 ARM: sun7i/sun6i:... |
12 13 14 15 16 17 18 19 20 |
#include <linux/bitops.h> #include <linux/device.h> #include <linux/io.h> #include <linux/irq.h> #include <linux/interrupt.h> #include <linux/irqdomain.h> #include <linux/of_irq.h> #include <linux/of_address.h> #include <linux/of_platform.h> |
41a83e06e irqchip: Prepare ... |
21 |
#include <linux/irqchip.h> |
6058bb362 ARM: sun7i/sun6i:... |
22 |
#include <linux/irqchip/chained_irq.h> |
6058bb362 ARM: sun7i/sun6i:... |
23 24 |
#define SUNXI_NMI_SRC_TYPE_MASK 0x00000003 |
9ce18f6f0 irqchip/sunxi-nmi... |
25 |
#define SUNXI_NMI_IRQ_BIT BIT(0) |
173bda53b irqchip/sunxi-nmi... |
26 27 28 29 30 31 32 33 34 35 36 37 |
#define SUN6I_R_INTC_CTRL 0x0c #define SUN6I_R_INTC_PENDING 0x10 #define SUN6I_R_INTC_ENABLE 0x40 /* * For deprecated sun6i-a31-sc-nmi compatible. * Registers are offset by 0x0c. */ #define SUN6I_R_INTC_NMI_OFFSET 0x0c #define SUN6I_NMI_CTRL (SUN6I_R_INTC_CTRL - SUN6I_R_INTC_NMI_OFFSET) #define SUN6I_NMI_PENDING (SUN6I_R_INTC_PENDING - SUN6I_R_INTC_NMI_OFFSET) #define SUN6I_NMI_ENABLE (SUN6I_R_INTC_ENABLE - SUN6I_R_INTC_NMI_OFFSET) |
9ce18f6f0 irqchip/sunxi-nmi... |
38 39 40 41 42 43 44 45 |
#define SUN7I_NMI_CTRL 0x00 #define SUN7I_NMI_PENDING 0x04 #define SUN7I_NMI_ENABLE 0x08 #define SUN9I_NMI_CTRL 0x00 #define SUN9I_NMI_ENABLE 0x04 #define SUN9I_NMI_PENDING 0x08 |
6058bb362 ARM: sun7i/sun6i:... |
46 47 48 49 50 51 52 53 54 55 56 57 |
enum { SUNXI_SRC_TYPE_LEVEL_LOW = 0, SUNXI_SRC_TYPE_EDGE_FALLING, SUNXI_SRC_TYPE_LEVEL_HIGH, SUNXI_SRC_TYPE_EDGE_RISING, }; struct sunxi_sc_nmi_reg_offs { u32 ctrl; u32 pend; u32 enable; }; |
173bda53b irqchip/sunxi-nmi... |
58 59 60 61 62 |
static const struct sunxi_sc_nmi_reg_offs sun6i_r_intc_reg_offs __initconst = { .ctrl = SUN6I_R_INTC_CTRL, .pend = SUN6I_R_INTC_PENDING, .enable = SUN6I_R_INTC_ENABLE, }; |
11b345ab7 irqchip/sunxi-nmi... |
63 |
static const struct sunxi_sc_nmi_reg_offs sun6i_reg_offs __initconst = { |
9ce18f6f0 irqchip/sunxi-nmi... |
64 65 66 |
.ctrl = SUN6I_NMI_CTRL, .pend = SUN6I_NMI_PENDING, .enable = SUN6I_NMI_ENABLE, |
6058bb362 ARM: sun7i/sun6i:... |
67 |
}; |
11b345ab7 irqchip/sunxi-nmi... |
68 |
static const struct sunxi_sc_nmi_reg_offs sun7i_reg_offs __initconst = { |
c81a24806 irqchip/sunxi-nmi... |
69 70 71 72 |
.ctrl = SUN7I_NMI_CTRL, .pend = SUN7I_NMI_PENDING, .enable = SUN7I_NMI_ENABLE, }; |
11b345ab7 irqchip/sunxi-nmi... |
73 |
static const struct sunxi_sc_nmi_reg_offs sun9i_reg_offs __initconst = { |
9ce18f6f0 irqchip/sunxi-nmi... |
74 75 76 |
.ctrl = SUN9I_NMI_CTRL, .pend = SUN9I_NMI_PENDING, .enable = SUN9I_NMI_ENABLE, |
bbbb03c1a irqchip/sunxi-nmi... |
77 |
}; |
6058bb362 ARM: sun7i/sun6i:... |
78 79 80 |
static inline void sunxi_sc_nmi_write(struct irq_chip_generic *gc, u32 off, u32 val) { |
332fd7c4f genirq: Generic c... |
81 |
irq_reg_writel(gc, val, off); |
6058bb362 ARM: sun7i/sun6i:... |
82 83 84 85 |
} static inline u32 sunxi_sc_nmi_read(struct irq_chip_generic *gc, u32 off) { |
332fd7c4f genirq: Generic c... |
86 |
return irq_reg_readl(gc, off); |
6058bb362 ARM: sun7i/sun6i:... |
87 |
} |
bd0b9ac40 genirq: Remove ir... |
88 |
static void sunxi_sc_nmi_handle_irq(struct irq_desc *desc) |
6058bb362 ARM: sun7i/sun6i:... |
89 90 |
{ struct irq_domain *domain = irq_desc_get_handler_data(desc); |
5b29264c6 irqchip: Use irq_... |
91 |
struct irq_chip *chip = irq_desc_get_chip(desc); |
6058bb362 ARM: sun7i/sun6i:... |
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
unsigned int virq = irq_find_mapping(domain, 0); chained_irq_enter(chip, desc); generic_handle_irq(virq); chained_irq_exit(chip, desc); } static int sunxi_sc_nmi_set_type(struct irq_data *data, unsigned int flow_type) { struct irq_chip_generic *gc = irq_data_get_irq_chip_data(data); struct irq_chip_type *ct = gc->chip_types; u32 src_type_reg; u32 ctrl_off = ct->regs.type; unsigned int src_type; unsigned int i; irq_gc_lock(gc); switch (flow_type & IRQF_TRIGGER_MASK) { case IRQ_TYPE_EDGE_FALLING: src_type = SUNXI_SRC_TYPE_EDGE_FALLING; break; case IRQ_TYPE_EDGE_RISING: src_type = SUNXI_SRC_TYPE_EDGE_RISING; break; case IRQ_TYPE_LEVEL_HIGH: src_type = SUNXI_SRC_TYPE_LEVEL_HIGH; break; case IRQ_TYPE_NONE: case IRQ_TYPE_LEVEL_LOW: src_type = SUNXI_SRC_TYPE_LEVEL_LOW; break; default: irq_gc_unlock(gc); |
2d6caaed0 irqchip/sunxi-nmi... |
126 127 128 |
pr_err("Cannot assign multiple trigger modes to IRQ %d. ", data->irq); |
6058bb362 ARM: sun7i/sun6i:... |
129 130 131 132 133 |
return -EBADR; } irqd_set_trigger_type(data, flow_type); irq_setup_alt_chip(data, flow_type); |
febe06962 irqchip: sunxi-nm... |
134 |
for (i = 0; i < gc->num_ct; i++, ct++) |
6058bb362 ARM: sun7i/sun6i:... |
135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
if (ct->type & flow_type) ctrl_off = ct->regs.type; src_type_reg = sunxi_sc_nmi_read(gc, ctrl_off); src_type_reg &= ~SUNXI_NMI_SRC_TYPE_MASK; src_type_reg |= src_type; sunxi_sc_nmi_write(gc, ctrl_off, src_type_reg); irq_gc_unlock(gc); return IRQ_SET_MASK_OK; } static int __init sunxi_sc_nmi_irq_init(struct device_node *node, |
11b345ab7 irqchip/sunxi-nmi... |
149 |
const struct sunxi_sc_nmi_reg_offs *reg_offs) |
6058bb362 ARM: sun7i/sun6i:... |
150 151 152 153 154 155 156 157 158 159 |
{ struct irq_domain *domain; struct irq_chip_generic *gc; unsigned int irq; unsigned int clr = IRQ_NOREQUEST | IRQ_NOPROBE | IRQ_NOAUTOEN; int ret; domain = irq_domain_add_linear(node, 1, &irq_generic_chip_ops, NULL); if (!domain) { |
2d6caaed0 irqchip/sunxi-nmi... |
160 161 |
pr_err("Could not register interrupt domain. "); |
6058bb362 ARM: sun7i/sun6i:... |
162 163 |
return -ENOMEM; } |
2d6caaed0 irqchip/sunxi-nmi... |
164 |
ret = irq_alloc_domain_generic_chips(domain, 1, 2, DRV_NAME, |
6058bb362 ARM: sun7i/sun6i:... |
165 166 167 |
handle_fasteoi_irq, clr, 0, IRQ_GC_INIT_MASK_CACHE); if (ret) { |
2d6caaed0 irqchip/sunxi-nmi... |
168 169 170 |
pr_err("Could not allocate generic interrupt chip. "); goto fail_irqd_remove; |
6058bb362 ARM: sun7i/sun6i:... |
171 172 173 174 |
} irq = irq_of_parse_and_map(node, 0); if (irq <= 0) { |
2d6caaed0 irqchip/sunxi-nmi... |
175 176 |
pr_err("unable to parse irq "); |
6058bb362 ARM: sun7i/sun6i:... |
177 178 179 180 181 |
ret = -EINVAL; goto fail_irqd_remove; } gc = irq_get_domain_generic_chip(domain, 0); |
0e841b04c irqchip/sunxi-nmi... |
182 |
gc->reg_base = of_io_request_and_map(node, 0, of_node_full_name(node)); |
cfe199afe irqchip/sunxi-nmi... |
183 |
if (IS_ERR(gc->reg_base)) { |
2d6caaed0 irqchip/sunxi-nmi... |
184 185 |
pr_err("unable to map resource "); |
cfe199afe irqchip/sunxi-nmi... |
186 |
ret = PTR_ERR(gc->reg_base); |
6058bb362 ARM: sun7i/sun6i:... |
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 |
goto fail_irqd_remove; } gc->chip_types[0].type = IRQ_TYPE_LEVEL_MASK; gc->chip_types[0].chip.irq_mask = irq_gc_mask_clr_bit; gc->chip_types[0].chip.irq_unmask = irq_gc_mask_set_bit; gc->chip_types[0].chip.irq_eoi = irq_gc_ack_set_bit; gc->chip_types[0].chip.irq_set_type = sunxi_sc_nmi_set_type; gc->chip_types[0].chip.flags = IRQCHIP_EOI_THREADED | IRQCHIP_EOI_IF_HANDLED; gc->chip_types[0].regs.ack = reg_offs->pend; gc->chip_types[0].regs.mask = reg_offs->enable; gc->chip_types[0].regs.type = reg_offs->ctrl; gc->chip_types[1].type = IRQ_TYPE_EDGE_BOTH; gc->chip_types[1].chip.name = gc->chip_types[0].chip.name; gc->chip_types[1].chip.irq_ack = irq_gc_ack_set_bit; gc->chip_types[1].chip.irq_mask = irq_gc_mask_clr_bit; gc->chip_types[1].chip.irq_unmask = irq_gc_mask_set_bit; gc->chip_types[1].chip.irq_set_type = sunxi_sc_nmi_set_type; gc->chip_types[1].regs.ack = reg_offs->pend; gc->chip_types[1].regs.mask = reg_offs->enable; gc->chip_types[1].regs.type = reg_offs->ctrl; gc->chip_types[1].handler = handle_edge_irq; |
e3ece0d5a irqchip/sunxi-nmi... |
210 |
/* Disable any active interrupts */ |
6058bb362 ARM: sun7i/sun6i:... |
211 |
sunxi_sc_nmi_write(gc, reg_offs->enable, 0); |
e3ece0d5a irqchip/sunxi-nmi... |
212 213 |
/* Clear any pending NMI interrupts */ |
9ce18f6f0 irqchip/sunxi-nmi... |
214 |
sunxi_sc_nmi_write(gc, reg_offs->pend, SUNXI_NMI_IRQ_BIT); |
6058bb362 ARM: sun7i/sun6i:... |
215 |
|
3200a7120 irqchip/sunxi-nmi... |
216 |
irq_set_chained_handler_and_data(irq, sunxi_sc_nmi_handle_irq, domain); |
1b422ecd2 irqchip: sun7i/su... |
217 |
|
6058bb362 ARM: sun7i/sun6i:... |
218 219 220 221 222 223 224 |
return 0; fail_irqd_remove: irq_domain_remove(domain); return ret; } |
173bda53b irqchip/sunxi-nmi... |
225 226 227 228 229 230 231 |
static int __init sun6i_r_intc_irq_init(struct device_node *node, struct device_node *parent) { return sunxi_sc_nmi_irq_init(node, &sun6i_r_intc_reg_offs); } IRQCHIP_DECLARE(sun6i_r_intc, "allwinner,sun6i-a31-r-intc", sun6i_r_intc_irq_init); |
6058bb362 ARM: sun7i/sun6i:... |
232 233 234 235 236 237 238 239 240 241 242 243 244 |
static int __init sun6i_sc_nmi_irq_init(struct device_node *node, struct device_node *parent) { return sunxi_sc_nmi_irq_init(node, &sun6i_reg_offs); } IRQCHIP_DECLARE(sun6i_sc_nmi, "allwinner,sun6i-a31-sc-nmi", sun6i_sc_nmi_irq_init); static int __init sun7i_sc_nmi_irq_init(struct device_node *node, struct device_node *parent) { return sunxi_sc_nmi_irq_init(node, &sun7i_reg_offs); } IRQCHIP_DECLARE(sun7i_sc_nmi, "allwinner,sun7i-a20-sc-nmi", sun7i_sc_nmi_irq_init); |
bbbb03c1a irqchip/sunxi-nmi... |
245 246 247 248 249 250 251 |
static int __init sun9i_nmi_irq_init(struct device_node *node, struct device_node *parent) { return sunxi_sc_nmi_irq_init(node, &sun9i_reg_offs); } IRQCHIP_DECLARE(sun9i_nmi, "allwinner,sun9i-a80-nmi", sun9i_nmi_irq_init); |