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