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