Blame view
drivers/irqchip/irq-vt8500.c
6.48 KB
21f47fbc5 ARM: 6597/1: Add ... |
1 2 3 |
/* * arch/arm/mach-vt8500/irq.c * |
e9a91de76 arm: vt8500: Upda... |
4 |
* Copyright (C) 2012 Tony Prisk <linux@prisktech.co.nz> |
21f47fbc5 ARM: 6597/1: Add ... |
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
* Copyright (C) 2010 Alexey Charkov <alchark@gmail.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ |
e9a91de76 arm: vt8500: Upda... |
21 22 23 24 25 26 |
/* * This file is copied and modified from the original irq.c provided by * Alexey Charkov. Minor changes have been made for Device Tree Support. */ #include <linux/slab.h> |
21f47fbc5 ARM: 6597/1: Add ... |
27 28 |
#include <linux/io.h> #include <linux/irq.h> |
41a83e06e irqchip: Prepare ... |
29 |
#include <linux/irqchip.h> |
e9a91de76 arm: vt8500: Upda... |
30 |
#include <linux/irqdomain.h> |
21f47fbc5 ARM: 6597/1: Add ... |
31 |
#include <linux/interrupt.h> |
e9a91de76 arm: vt8500: Upda... |
32 33 34 35 36 |
#include <linux/bitops.h> #include <linux/of.h> #include <linux/of_irq.h> #include <linux/of_address.h> |
21f47fbc5 ARM: 6597/1: Add ... |
37 38 |
#include <asm/irq.h> |
0c464d588 arm: vt8500: Conv... |
39 |
#include <asm/exception.h> |
06ff14c05 irqchip: vt8500: ... |
40 |
#include <asm/mach/irq.h> |
e9a91de76 arm: vt8500: Upda... |
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
#define VT8500_ICPC_IRQ 0x20 #define VT8500_ICPC_FIQ 0x24 #define VT8500_ICDC 0x40 /* Destination Control 64*u32 */ #define VT8500_ICIS 0x80 /* Interrupt status, 16*u32 */ /* ICPC */ #define ICPC_MASK 0x3F #define ICPC_ROTATE BIT(6) /* IC_DCTR */ #define ICDC_IRQ 0x00 #define ICDC_FIQ 0x01 #define ICDC_DSS0 0x02 #define ICDC_DSS1 0x03 #define ICDC_DSS2 0x04 #define ICDC_DSS3 0x05 #define ICDC_DSS4 0x06 #define ICDC_DSS5 0x07 #define VT8500_INT_DISABLE 0 #define VT8500_INT_ENABLE BIT(3) #define VT8500_TRIGGER_HIGH 0 #define VT8500_TRIGGER_RISING BIT(5) #define VT8500_TRIGGER_FALLING BIT(6) |
21f47fbc5 ARM: 6597/1: Add ... |
66 67 |
#define VT8500_EDGE ( VT8500_TRIGGER_RISING \ | VT8500_TRIGGER_FALLING) |
21f47fbc5 ARM: 6597/1: Add ... |
68 |
|
0c464d588 arm: vt8500: Conv... |
69 70 |
/* vt8500 has 1 intc, wm8505 and wm8650 have 2 */ #define VT8500_INTC_MAX 2 |
e9a91de76 arm: vt8500: Upda... |
71 |
|
0c464d588 arm: vt8500: Conv... |
72 73 74 |
struct vt8500_irq_data { void __iomem *base; /* IO Memory base address */ struct irq_domain *domain; /* Domain for this controller */ |
e9a91de76 arm: vt8500: Upda... |
75 |
}; |
21f47fbc5 ARM: 6597/1: Add ... |
76 |
|
0c464d588 arm: vt8500: Conv... |
77 78 79 |
/* Global variable for accessing io-mem addresses */ static struct vt8500_irq_data intc[VT8500_INTC_MAX]; static u32 active_cnt = 0; |
2eb5af44b ARM: 6979/1: mach... |
80 |
static void vt8500_irq_mask(struct irq_data *d) |
21f47fbc5 ARM: 6597/1: Add ... |
81 |
{ |
0c464d588 arm: vt8500: Conv... |
82 |
struct vt8500_irq_data *priv = d->domain->host_data; |
e9a91de76 arm: vt8500: Upda... |
83 |
void __iomem *base = priv->base; |
0c464d588 arm: vt8500: Conv... |
84 85 86 |
void __iomem *stat_reg = base + VT8500_ICIS + (d->hwirq < 32 ? 0 : 4); u8 edge, dctr; u32 status; |
21f47fbc5 ARM: 6597/1: Add ... |
87 |
|
e9a91de76 arm: vt8500: Upda... |
88 |
edge = readb(base + VT8500_ICDC + d->hwirq) & VT8500_EDGE; |
21f47fbc5 ARM: 6597/1: Add ... |
89 |
if (edge) { |
0c464d588 arm: vt8500: Conv... |
90 |
status = readl(stat_reg); |
21f47fbc5 ARM: 6597/1: Add ... |
91 |
|
e9a91de76 arm: vt8500: Upda... |
92 |
status |= (1 << (d->hwirq & 0x1f)); |
21f47fbc5 ARM: 6597/1: Add ... |
93 94 |
writel(status, stat_reg); } else { |
0c464d588 arm: vt8500: Conv... |
95 |
dctr = readb(base + VT8500_ICDC + d->hwirq); |
21f47fbc5 ARM: 6597/1: Add ... |
96 |
dctr &= ~VT8500_INT_ENABLE; |
e9a91de76 arm: vt8500: Upda... |
97 |
writeb(dctr, base + VT8500_ICDC + d->hwirq); |
21f47fbc5 ARM: 6597/1: Add ... |
98 99 |
} } |
2eb5af44b ARM: 6979/1: mach... |
100 |
static void vt8500_irq_unmask(struct irq_data *d) |
21f47fbc5 ARM: 6597/1: Add ... |
101 |
{ |
0c464d588 arm: vt8500: Conv... |
102 |
struct vt8500_irq_data *priv = d->domain->host_data; |
e9a91de76 arm: vt8500: Upda... |
103 |
void __iomem *base = priv->base; |
21f47fbc5 ARM: 6597/1: Add ... |
104 |
u8 dctr; |
e9a91de76 arm: vt8500: Upda... |
105 |
dctr = readb(base + VT8500_ICDC + d->hwirq); |
21f47fbc5 ARM: 6597/1: Add ... |
106 |
dctr |= VT8500_INT_ENABLE; |
e9a91de76 arm: vt8500: Upda... |
107 |
writeb(dctr, base + VT8500_ICDC + d->hwirq); |
21f47fbc5 ARM: 6597/1: Add ... |
108 |
} |
2eb5af44b ARM: 6979/1: mach... |
109 |
static int vt8500_irq_set_type(struct irq_data *d, unsigned int flow_type) |
21f47fbc5 ARM: 6597/1: Add ... |
110 |
{ |
0c464d588 arm: vt8500: Conv... |
111 |
struct vt8500_irq_data *priv = d->domain->host_data; |
e9a91de76 arm: vt8500: Upda... |
112 |
void __iomem *base = priv->base; |
21f47fbc5 ARM: 6597/1: Add ... |
113 |
u8 dctr; |
e9a91de76 arm: vt8500: Upda... |
114 |
dctr = readb(base + VT8500_ICDC + d->hwirq); |
21f47fbc5 ARM: 6597/1: Add ... |
115 116 117 118 119 120 121 |
dctr &= ~VT8500_EDGE; switch (flow_type) { case IRQF_TRIGGER_LOW: return -EINVAL; case IRQF_TRIGGER_HIGH: dctr |= VT8500_TRIGGER_HIGH; |
d2aa914d2 irqchip/vt8500: U... |
122 |
irq_set_handler_locked(d, handle_level_irq); |
21f47fbc5 ARM: 6597/1: Add ... |
123 124 125 |
break; case IRQF_TRIGGER_FALLING: dctr |= VT8500_TRIGGER_FALLING; |
d2aa914d2 irqchip/vt8500: U... |
126 |
irq_set_handler_locked(d, handle_edge_irq); |
21f47fbc5 ARM: 6597/1: Add ... |
127 128 129 |
break; case IRQF_TRIGGER_RISING: dctr |= VT8500_TRIGGER_RISING; |
d2aa914d2 irqchip/vt8500: U... |
130 |
irq_set_handler_locked(d, handle_edge_irq); |
21f47fbc5 ARM: 6597/1: Add ... |
131 132 |
break; } |
e9a91de76 arm: vt8500: Upda... |
133 |
writeb(dctr, base + VT8500_ICDC + d->hwirq); |
21f47fbc5 ARM: 6597/1: Add ... |
134 135 136 137 138 |
return 0; } static struct irq_chip vt8500_irq_chip = { |
2eb5af44b ARM: 6979/1: mach... |
139 140 141 142 143 |
.name = "vt8500", .irq_ack = vt8500_irq_mask, .irq_mask = vt8500_irq_mask, .irq_unmask = vt8500_irq_unmask, .irq_set_type = vt8500_irq_set_type, |
21f47fbc5 ARM: 6597/1: Add ... |
144 |
}; |
e9a91de76 arm: vt8500: Upda... |
145 |
static void __init vt8500_init_irq_hw(void __iomem *base) |
21f47fbc5 ARM: 6597/1: Add ... |
146 |
{ |
0c464d588 arm: vt8500: Conv... |
147 |
u32 i; |
21f47fbc5 ARM: 6597/1: Add ... |
148 |
|
e9a91de76 arm: vt8500: Upda... |
149 150 151 |
/* Enable rotating priority for IRQ */ writel(ICPC_ROTATE, base + VT8500_ICPC_IRQ); writel(0x00, base + VT8500_ICPC_FIQ); |
21f47fbc5 ARM: 6597/1: Add ... |
152 |
|
0c464d588 arm: vt8500: Conv... |
153 154 155 |
/* Disable all interrupts and route them to IRQ */ for (i = 0; i < 64; i++) writeb(VT8500_INT_DISABLE | ICDC_IRQ, base + VT8500_ICDC + i); |
e9a91de76 arm: vt8500: Upda... |
156 |
} |
21f47fbc5 ARM: 6597/1: Add ... |
157 |
|
e9a91de76 arm: vt8500: Upda... |
158 159 160 161 |
static int vt8500_irq_map(struct irq_domain *h, unsigned int virq, irq_hw_number_t hw) { irq_set_chip_and_handler(virq, &vt8500_irq_chip, handle_level_irq); |
21f47fbc5 ARM: 6597/1: Add ... |
162 |
|
e9a91de76 arm: vt8500: Upda... |
163 |
return 0; |
21f47fbc5 ARM: 6597/1: Add ... |
164 |
} |
960097365 irqchip: Constify... |
165 |
static const struct irq_domain_ops vt8500_irq_domain_ops = { |
e9a91de76 arm: vt8500: Upda... |
166 167 168 |
.map = vt8500_irq_map, .xlate = irq_domain_xlate_onecell, }; |
8783dd3a3 irqchip: Remove a... |
169 |
static void __exception_irq_entry vt8500_handle_irq(struct pt_regs *regs) |
0c464d588 arm: vt8500: Conv... |
170 171 |
{ u32 stat, i; |
0beb65041 irqchip: vt8500: ... |
172 |
int irqnr; |
0c464d588 arm: vt8500: Conv... |
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
void __iomem *base; /* Loop through each active controller */ for (i=0; i<active_cnt; i++) { base = intc[i].base; irqnr = readl_relaxed(base) & 0x3F; /* Highest Priority register default = 63, so check that this is a real interrupt by checking the status register */ if (irqnr == 63) { stat = readl_relaxed(base + VT8500_ICIS + 4); if (!(stat & BIT(31))) continue; } |
0beb65041 irqchip: vt8500: ... |
188 |
handle_domain_irq(intc[i].domain, irqnr, regs); |
0c464d588 arm: vt8500: Conv... |
189 190 |
} } |
e658718e4 irqchip: vt8500: ... |
191 192 |
static int __init vt8500_irq_init(struct device_node *node, struct device_node *parent) |
21f47fbc5 ARM: 6597/1: Add ... |
193 |
{ |
e9a91de76 arm: vt8500: Upda... |
194 195 |
int irq, i; struct device_node *np = node; |
0c464d588 arm: vt8500: Conv... |
196 197 198 199 200 201 202 203 204 205 |
if (active_cnt == VT8500_INTC_MAX) { pr_err("%s: Interrupt controllers > VT8500_INTC_MAX ", __func__); goto out; } intc[active_cnt].base = of_iomap(np, 0); intc[active_cnt].domain = irq_domain_add_linear(node, 64, &vt8500_irq_domain_ops, &intc[active_cnt]); |
e9a91de76 arm: vt8500: Upda... |
206 |
|
0c464d588 arm: vt8500: Conv... |
207 208 209 210 211 212 213 214 215 216 217 |
if (!intc[active_cnt].base) { pr_err("%s: Unable to map IO memory ", __func__); goto out; } if (!intc[active_cnt].domain) { pr_err("%s: Unable to add irq domain! ", __func__); goto out; } |
e9a91de76 arm: vt8500: Upda... |
218 |
|
06ff14c05 irqchip: vt8500: ... |
219 |
set_handle_irq(vt8500_handle_irq); |
0c464d588 arm: vt8500: Conv... |
220 |
vt8500_init_irq_hw(intc[active_cnt].base); |
e9a91de76 arm: vt8500: Upda... |
221 |
|
0c464d588 arm: vt8500: Conv... |
222 223 |
pr_info("vt8500-irq: Added interrupt controller "); |
21f47fbc5 ARM: 6597/1: Add ... |
224 |
|
0c464d588 arm: vt8500: Conv... |
225 |
active_cnt++; |
e9a91de76 arm: vt8500: Upda... |
226 227 228 229 230 |
/* check if this is a slaved controller */ if (of_irq_count(np) != 0) { /* check that we have the correct number of interrupts */ if (of_irq_count(np) != 8) { |
0c464d588 arm: vt8500: Conv... |
231 232 |
pr_err("%s: Incorrect IRQ map for slaved controller ", |
e9a91de76 arm: vt8500: Upda... |
233 234 |
__func__); return -EINVAL; |
21f47fbc5 ARM: 6597/1: Add ... |
235 |
} |
e9a91de76 arm: vt8500: Upda... |
236 237 238 239 240 241 242 243 |
for (i = 0; i < 8; i++) { irq = irq_of_parse_and_map(np, i); enable_irq(irq); } pr_info("vt8500-irq: Enabled slave->parent interrupts "); |
21f47fbc5 ARM: 6597/1: Add ... |
244 |
} |
0c464d588 arm: vt8500: Conv... |
245 |
out: |
e9a91de76 arm: vt8500: Upda... |
246 |
return 0; |
21f47fbc5 ARM: 6597/1: Add ... |
247 |
} |
e9a91de76 arm: vt8500: Upda... |
248 |
|
06ff14c05 irqchip: vt8500: ... |
249 |
IRQCHIP_DECLARE(vt8500_irq, "via,vt8500-intc", vt8500_irq_init); |