Magnus Damm | 4435804 | 2013-02-18 23:28:34 +0900 | [diff] [blame] | 1 | /* |
| 2 | * Renesas INTC External IRQ Pin Driver |
| 3 | * |
| 4 | * Copyright (C) 2013 Magnus Damm |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 18 | */ |
| 19 | |
| 20 | #include <linux/init.h> |
| 21 | #include <linux/platform_device.h> |
| 22 | #include <linux/spinlock.h> |
| 23 | #include <linux/interrupt.h> |
| 24 | #include <linux/ioport.h> |
| 25 | #include <linux/io.h> |
| 26 | #include <linux/irq.h> |
| 27 | #include <linux/irqdomain.h> |
| 28 | #include <linux/err.h> |
| 29 | #include <linux/slab.h> |
| 30 | #include <linux/module.h> |
| 31 | #include <linux/platform_data/irq-renesas-intc-irqpin.h> |
| 32 | |
| 33 | #define INTC_IRQPIN_MAX 8 /* maximum 8 interrupts per driver instance */ |
| 34 | |
| 35 | #define INTC_IRQPIN_REG_SENSE 0 /* ICRn */ |
| 36 | #define INTC_IRQPIN_REG_PRIO 1 /* INTPRInn */ |
| 37 | #define INTC_IRQPIN_REG_SOURCE 2 /* INTREQnn */ |
| 38 | #define INTC_IRQPIN_REG_MASK 3 /* INTMSKnn */ |
| 39 | #define INTC_IRQPIN_REG_CLEAR 4 /* INTMSKCLRnn */ |
| 40 | #define INTC_IRQPIN_REG_NR 5 |
| 41 | |
| 42 | /* INTC external IRQ PIN hardware register access: |
| 43 | * |
| 44 | * SENSE is read-write 32-bit with 2-bits or 4-bits per IRQ (*) |
| 45 | * PRIO is read-write 32-bit with 4-bits per IRQ (**) |
| 46 | * SOURCE is read-only 32-bit or 8-bit with 1-bit per IRQ (***) |
| 47 | * MASK is write-only 32-bit or 8-bit with 1-bit per IRQ (***) |
| 48 | * CLEAR is write-only 32-bit or 8-bit with 1-bit per IRQ (***) |
| 49 | * |
| 50 | * (*) May be accessed by more than one driver instance - lock needed |
| 51 | * (**) Read-modify-write access by one driver instance - lock needed |
| 52 | * (***) Accessed by one driver instance only - no locking needed |
| 53 | */ |
| 54 | |
| 55 | struct intc_irqpin_iomem { |
| 56 | void __iomem *iomem; |
| 57 | unsigned long (*read)(void __iomem *iomem); |
| 58 | void (*write)(void __iomem *iomem, unsigned long data); |
| 59 | int width; |
Magnus Damm | 862d309 | 2013-02-26 20:58:44 +0900 | [diff] [blame] | 60 | }; |
Magnus Damm | 4435804 | 2013-02-18 23:28:34 +0900 | [diff] [blame] | 61 | |
| 62 | struct intc_irqpin_irq { |
| 63 | int hw_irq; |
Magnus Damm | 33f958f | 2013-02-26 20:58:54 +0900 | [diff] [blame] | 64 | int requested_irq; |
| 65 | int domain_irq; |
Magnus Damm | 4435804 | 2013-02-18 23:28:34 +0900 | [diff] [blame] | 66 | struct intc_irqpin_priv *p; |
Magnus Damm | 862d309 | 2013-02-26 20:58:44 +0900 | [diff] [blame] | 67 | }; |
Magnus Damm | 4435804 | 2013-02-18 23:28:34 +0900 | [diff] [blame] | 68 | |
| 69 | struct intc_irqpin_priv { |
| 70 | struct intc_irqpin_iomem iomem[INTC_IRQPIN_REG_NR]; |
| 71 | struct intc_irqpin_irq irq[INTC_IRQPIN_MAX]; |
| 72 | struct renesas_intc_irqpin_config config; |
| 73 | unsigned int number_of_irqs; |
| 74 | struct platform_device *pdev; |
| 75 | struct irq_chip irq_chip; |
| 76 | struct irq_domain *irq_domain; |
| 77 | }; |
| 78 | |
| 79 | static unsigned long intc_irqpin_read32(void __iomem *iomem) |
| 80 | { |
| 81 | return ioread32(iomem); |
| 82 | } |
| 83 | |
| 84 | static unsigned long intc_irqpin_read8(void __iomem *iomem) |
| 85 | { |
| 86 | return ioread8(iomem); |
| 87 | } |
| 88 | |
| 89 | static void intc_irqpin_write32(void __iomem *iomem, unsigned long data) |
| 90 | { |
| 91 | iowrite32(data, iomem); |
| 92 | } |
| 93 | |
| 94 | static void intc_irqpin_write8(void __iomem *iomem, unsigned long data) |
| 95 | { |
| 96 | iowrite8(data, iomem); |
| 97 | } |
| 98 | |
| 99 | static inline unsigned long intc_irqpin_read(struct intc_irqpin_priv *p, |
| 100 | int reg) |
| 101 | { |
| 102 | struct intc_irqpin_iomem *i = &p->iomem[reg]; |
Magnus Damm | 862d309 | 2013-02-26 20:58:44 +0900 | [diff] [blame] | 103 | |
Magnus Damm | 4435804 | 2013-02-18 23:28:34 +0900 | [diff] [blame] | 104 | return i->read(i->iomem); |
| 105 | } |
| 106 | |
| 107 | static inline void intc_irqpin_write(struct intc_irqpin_priv *p, |
| 108 | int reg, unsigned long data) |
| 109 | { |
| 110 | struct intc_irqpin_iomem *i = &p->iomem[reg]; |
Magnus Damm | 862d309 | 2013-02-26 20:58:44 +0900 | [diff] [blame] | 111 | |
Magnus Damm | 4435804 | 2013-02-18 23:28:34 +0900 | [diff] [blame] | 112 | i->write(i->iomem, data); |
| 113 | } |
| 114 | |
| 115 | static inline unsigned long intc_irqpin_hwirq_mask(struct intc_irqpin_priv *p, |
| 116 | int reg, int hw_irq) |
| 117 | { |
| 118 | return BIT((p->iomem[reg].width - 1) - hw_irq); |
| 119 | } |
| 120 | |
| 121 | static inline void intc_irqpin_irq_write_hwirq(struct intc_irqpin_priv *p, |
| 122 | int reg, int hw_irq) |
| 123 | { |
| 124 | intc_irqpin_write(p, reg, intc_irqpin_hwirq_mask(p, reg, hw_irq)); |
| 125 | } |
| 126 | |
| 127 | static DEFINE_RAW_SPINLOCK(intc_irqpin_lock); /* only used by slow path */ |
| 128 | |
| 129 | static void intc_irqpin_read_modify_write(struct intc_irqpin_priv *p, |
| 130 | int reg, int shift, |
| 131 | int width, int value) |
| 132 | { |
| 133 | unsigned long flags; |
| 134 | unsigned long tmp; |
| 135 | |
| 136 | raw_spin_lock_irqsave(&intc_irqpin_lock, flags); |
| 137 | |
| 138 | tmp = intc_irqpin_read(p, reg); |
| 139 | tmp &= ~(((1 << width) - 1) << shift); |
| 140 | tmp |= value << shift; |
| 141 | intc_irqpin_write(p, reg, tmp); |
| 142 | |
| 143 | raw_spin_unlock_irqrestore(&intc_irqpin_lock, flags); |
| 144 | } |
| 145 | |
| 146 | static void intc_irqpin_mask_unmask_prio(struct intc_irqpin_priv *p, |
| 147 | int irq, int do_mask) |
| 148 | { |
| 149 | int bitfield_width = 4; /* PRIO assumed to have fixed bitfield width */ |
| 150 | int shift = (7 - irq) * bitfield_width; /* PRIO assumed to be 32-bit */ |
| 151 | |
| 152 | intc_irqpin_read_modify_write(p, INTC_IRQPIN_REG_PRIO, |
| 153 | shift, bitfield_width, |
| 154 | do_mask ? 0 : (1 << bitfield_width) - 1); |
| 155 | } |
| 156 | |
| 157 | static int intc_irqpin_set_sense(struct intc_irqpin_priv *p, int irq, int value) |
| 158 | { |
| 159 | int bitfield_width = p->config.sense_bitfield_width; |
| 160 | int shift = (7 - irq) * bitfield_width; /* SENSE assumed to be 32-bit */ |
| 161 | |
| 162 | dev_dbg(&p->pdev->dev, "sense irq = %d, mode = %d\n", irq, value); |
| 163 | |
| 164 | if (value >= (1 << bitfield_width)) |
| 165 | return -EINVAL; |
| 166 | |
| 167 | intc_irqpin_read_modify_write(p, INTC_IRQPIN_REG_SENSE, shift, |
| 168 | bitfield_width, value); |
| 169 | return 0; |
| 170 | } |
| 171 | |
| 172 | static void intc_irqpin_dbg(struct intc_irqpin_irq *i, char *str) |
| 173 | { |
| 174 | dev_dbg(&i->p->pdev->dev, "%s (%d:%d:%d)\n", |
Magnus Damm | 33f958f | 2013-02-26 20:58:54 +0900 | [diff] [blame] | 175 | str, i->requested_irq, i->hw_irq, i->domain_irq); |
Magnus Damm | 4435804 | 2013-02-18 23:28:34 +0900 | [diff] [blame] | 176 | } |
| 177 | |
| 178 | static void intc_irqpin_irq_enable(struct irq_data *d) |
| 179 | { |
| 180 | struct intc_irqpin_priv *p = irq_data_get_irq_chip_data(d); |
| 181 | int hw_irq = irqd_to_hwirq(d); |
| 182 | |
| 183 | intc_irqpin_dbg(&p->irq[hw_irq], "enable"); |
| 184 | intc_irqpin_irq_write_hwirq(p, INTC_IRQPIN_REG_CLEAR, hw_irq); |
| 185 | } |
| 186 | |
| 187 | static void intc_irqpin_irq_disable(struct irq_data *d) |
| 188 | { |
| 189 | struct intc_irqpin_priv *p = irq_data_get_irq_chip_data(d); |
| 190 | int hw_irq = irqd_to_hwirq(d); |
| 191 | |
| 192 | intc_irqpin_dbg(&p->irq[hw_irq], "disable"); |
| 193 | intc_irqpin_irq_write_hwirq(p, INTC_IRQPIN_REG_MASK, hw_irq); |
| 194 | } |
| 195 | |
| 196 | static void intc_irqpin_irq_enable_force(struct irq_data *d) |
| 197 | { |
| 198 | struct intc_irqpin_priv *p = irq_data_get_irq_chip_data(d); |
Magnus Damm | 33f958f | 2013-02-26 20:58:54 +0900 | [diff] [blame] | 199 | int irq = p->irq[irqd_to_hwirq(d)].requested_irq; |
Magnus Damm | 4435804 | 2013-02-18 23:28:34 +0900 | [diff] [blame] | 200 | |
| 201 | intc_irqpin_irq_enable(d); |
Magnus Damm | d1b6aec | 2013-02-26 20:59:04 +0900 | [diff] [blame] | 202 | |
| 203 | /* enable interrupt through parent interrupt controller, |
| 204 | * assumes non-shared interrupt with 1:1 mapping |
| 205 | * needed for busted IRQs on some SoCs like sh73a0 |
| 206 | */ |
Magnus Damm | 4435804 | 2013-02-18 23:28:34 +0900 | [diff] [blame] | 207 | irq_get_chip(irq)->irq_unmask(irq_get_irq_data(irq)); |
| 208 | } |
| 209 | |
| 210 | static void intc_irqpin_irq_disable_force(struct irq_data *d) |
| 211 | { |
| 212 | struct intc_irqpin_priv *p = irq_data_get_irq_chip_data(d); |
Magnus Damm | 33f958f | 2013-02-26 20:58:54 +0900 | [diff] [blame] | 213 | int irq = p->irq[irqd_to_hwirq(d)].requested_irq; |
Magnus Damm | 4435804 | 2013-02-18 23:28:34 +0900 | [diff] [blame] | 214 | |
Magnus Damm | d1b6aec | 2013-02-26 20:59:04 +0900 | [diff] [blame] | 215 | /* disable interrupt through parent interrupt controller, |
| 216 | * assumes non-shared interrupt with 1:1 mapping |
| 217 | * needed for busted IRQs on some SoCs like sh73a0 |
| 218 | */ |
Magnus Damm | 4435804 | 2013-02-18 23:28:34 +0900 | [diff] [blame] | 219 | irq_get_chip(irq)->irq_mask(irq_get_irq_data(irq)); |
| 220 | intc_irqpin_irq_disable(d); |
| 221 | } |
| 222 | |
| 223 | #define INTC_IRQ_SENSE_VALID 0x10 |
| 224 | #define INTC_IRQ_SENSE(x) (x + INTC_IRQ_SENSE_VALID) |
| 225 | |
| 226 | static unsigned char intc_irqpin_sense[IRQ_TYPE_SENSE_MASK + 1] = { |
| 227 | [IRQ_TYPE_EDGE_FALLING] = INTC_IRQ_SENSE(0x00), |
| 228 | [IRQ_TYPE_EDGE_RISING] = INTC_IRQ_SENSE(0x01), |
| 229 | [IRQ_TYPE_LEVEL_LOW] = INTC_IRQ_SENSE(0x02), |
| 230 | [IRQ_TYPE_LEVEL_HIGH] = INTC_IRQ_SENSE(0x03), |
| 231 | [IRQ_TYPE_EDGE_BOTH] = INTC_IRQ_SENSE(0x04), |
| 232 | }; |
| 233 | |
| 234 | static int intc_irqpin_irq_set_type(struct irq_data *d, unsigned int type) |
| 235 | { |
| 236 | unsigned char value = intc_irqpin_sense[type & IRQ_TYPE_SENSE_MASK]; |
| 237 | struct intc_irqpin_priv *p = irq_data_get_irq_chip_data(d); |
| 238 | |
| 239 | if (!(value & INTC_IRQ_SENSE_VALID)) |
| 240 | return -EINVAL; |
| 241 | |
| 242 | return intc_irqpin_set_sense(p, irqd_to_hwirq(d), |
| 243 | value ^ INTC_IRQ_SENSE_VALID); |
| 244 | } |
| 245 | |
| 246 | static irqreturn_t intc_irqpin_irq_handler(int irq, void *dev_id) |
| 247 | { |
| 248 | struct intc_irqpin_irq *i = dev_id; |
| 249 | struct intc_irqpin_priv *p = i->p; |
| 250 | unsigned long bit; |
| 251 | |
| 252 | intc_irqpin_dbg(i, "demux1"); |
| 253 | bit = intc_irqpin_hwirq_mask(p, INTC_IRQPIN_REG_SOURCE, i->hw_irq); |
| 254 | |
| 255 | if (intc_irqpin_read(p, INTC_IRQPIN_REG_SOURCE) & bit) { |
| 256 | intc_irqpin_write(p, INTC_IRQPIN_REG_SOURCE, ~bit); |
| 257 | intc_irqpin_dbg(i, "demux2"); |
Magnus Damm | 33f958f | 2013-02-26 20:58:54 +0900 | [diff] [blame] | 258 | generic_handle_irq(i->domain_irq); |
Magnus Damm | 4435804 | 2013-02-18 23:28:34 +0900 | [diff] [blame] | 259 | return IRQ_HANDLED; |
| 260 | } |
| 261 | return IRQ_NONE; |
| 262 | } |
| 263 | |
| 264 | static int intc_irqpin_irq_domain_map(struct irq_domain *h, unsigned int virq, |
| 265 | irq_hw_number_t hw) |
| 266 | { |
| 267 | struct intc_irqpin_priv *p = h->host_data; |
| 268 | |
Magnus Damm | 33f958f | 2013-02-26 20:58:54 +0900 | [diff] [blame] | 269 | p->irq[hw].domain_irq = virq; |
| 270 | p->irq[hw].hw_irq = hw; |
| 271 | |
Magnus Damm | 4435804 | 2013-02-18 23:28:34 +0900 | [diff] [blame] | 272 | intc_irqpin_dbg(&p->irq[hw], "map"); |
| 273 | irq_set_chip_data(virq, h->host_data); |
| 274 | irq_set_chip_and_handler(virq, &p->irq_chip, handle_level_irq); |
| 275 | set_irq_flags(virq, IRQF_VALID); /* kill me now */ |
| 276 | return 0; |
| 277 | } |
| 278 | |
| 279 | static struct irq_domain_ops intc_irqpin_irq_domain_ops = { |
| 280 | .map = intc_irqpin_irq_domain_map, |
| 281 | }; |
| 282 | |
| 283 | static int intc_irqpin_probe(struct platform_device *pdev) |
| 284 | { |
| 285 | struct renesas_intc_irqpin_config *pdata = pdev->dev.platform_data; |
| 286 | struct intc_irqpin_priv *p; |
| 287 | struct intc_irqpin_iomem *i; |
| 288 | struct resource *io[INTC_IRQPIN_REG_NR]; |
| 289 | struct resource *irq; |
| 290 | struct irq_chip *irq_chip; |
| 291 | void (*enable_fn)(struct irq_data *d); |
| 292 | void (*disable_fn)(struct irq_data *d); |
| 293 | const char *name = dev_name(&pdev->dev); |
| 294 | int ret; |
| 295 | int k; |
| 296 | |
Magnus Damm | 08eba5b | 2013-02-26 20:59:13 +0900 | [diff] [blame^] | 297 | p = devm_kzalloc(&pdev->dev, sizeof(*p), GFP_KERNEL); |
Magnus Damm | 4435804 | 2013-02-18 23:28:34 +0900 | [diff] [blame] | 298 | if (!p) { |
| 299 | dev_err(&pdev->dev, "failed to allocate driver data\n"); |
| 300 | ret = -ENOMEM; |
| 301 | goto err0; |
| 302 | } |
| 303 | |
| 304 | /* deal with driver instance configuration */ |
| 305 | if (pdata) |
| 306 | memcpy(&p->config, pdata, sizeof(*pdata)); |
| 307 | if (!p->config.sense_bitfield_width) |
| 308 | p->config.sense_bitfield_width = 4; /* default to 4 bits */ |
| 309 | |
| 310 | p->pdev = pdev; |
| 311 | platform_set_drvdata(pdev, p); |
| 312 | |
| 313 | /* get hold of manadatory IOMEM */ |
| 314 | for (k = 0; k < INTC_IRQPIN_REG_NR; k++) { |
| 315 | io[k] = platform_get_resource(pdev, IORESOURCE_MEM, k); |
| 316 | if (!io[k]) { |
| 317 | dev_err(&pdev->dev, "not enough IOMEM resources\n"); |
| 318 | ret = -EINVAL; |
Magnus Damm | 08eba5b | 2013-02-26 20:59:13 +0900 | [diff] [blame^] | 319 | goto err0; |
Magnus Damm | 4435804 | 2013-02-18 23:28:34 +0900 | [diff] [blame] | 320 | } |
| 321 | } |
| 322 | |
| 323 | /* allow any number of IRQs between 1 and INTC_IRQPIN_MAX */ |
| 324 | for (k = 0; k < INTC_IRQPIN_MAX; k++) { |
| 325 | irq = platform_get_resource(pdev, IORESOURCE_IRQ, k); |
| 326 | if (!irq) |
| 327 | break; |
| 328 | |
Magnus Damm | 4435804 | 2013-02-18 23:28:34 +0900 | [diff] [blame] | 329 | p->irq[k].p = p; |
Magnus Damm | 33f958f | 2013-02-26 20:58:54 +0900 | [diff] [blame] | 330 | p->irq[k].requested_irq = irq->start; |
Magnus Damm | 4435804 | 2013-02-18 23:28:34 +0900 | [diff] [blame] | 331 | } |
| 332 | |
| 333 | p->number_of_irqs = k; |
| 334 | if (p->number_of_irqs < 1) { |
| 335 | dev_err(&pdev->dev, "not enough IRQ resources\n"); |
| 336 | ret = -EINVAL; |
Magnus Damm | 08eba5b | 2013-02-26 20:59:13 +0900 | [diff] [blame^] | 337 | goto err0; |
Magnus Damm | 4435804 | 2013-02-18 23:28:34 +0900 | [diff] [blame] | 338 | } |
| 339 | |
| 340 | /* ioremap IOMEM and setup read/write callbacks */ |
| 341 | for (k = 0; k < INTC_IRQPIN_REG_NR; k++) { |
| 342 | i = &p->iomem[k]; |
| 343 | |
| 344 | switch (resource_size(io[k])) { |
| 345 | case 1: |
| 346 | i->width = 8; |
| 347 | i->read = intc_irqpin_read8; |
| 348 | i->write = intc_irqpin_write8; |
| 349 | break; |
| 350 | case 4: |
| 351 | i->width = 32; |
| 352 | i->read = intc_irqpin_read32; |
| 353 | i->write = intc_irqpin_write32; |
| 354 | break; |
| 355 | default: |
| 356 | dev_err(&pdev->dev, "IOMEM size mismatch\n"); |
| 357 | ret = -EINVAL; |
Magnus Damm | 08eba5b | 2013-02-26 20:59:13 +0900 | [diff] [blame^] | 358 | goto err0; |
Magnus Damm | 4435804 | 2013-02-18 23:28:34 +0900 | [diff] [blame] | 359 | } |
| 360 | |
Magnus Damm | 08eba5b | 2013-02-26 20:59:13 +0900 | [diff] [blame^] | 361 | i->iomem = devm_ioremap_nocache(&pdev->dev, io[k]->start, |
| 362 | resource_size(io[k])); |
Magnus Damm | 4435804 | 2013-02-18 23:28:34 +0900 | [diff] [blame] | 363 | if (!i->iomem) { |
| 364 | dev_err(&pdev->dev, "failed to remap IOMEM\n"); |
| 365 | ret = -ENXIO; |
Magnus Damm | 08eba5b | 2013-02-26 20:59:13 +0900 | [diff] [blame^] | 366 | goto err0; |
Magnus Damm | 4435804 | 2013-02-18 23:28:34 +0900 | [diff] [blame] | 367 | } |
| 368 | } |
| 369 | |
| 370 | /* mask all interrupts using priority */ |
| 371 | for (k = 0; k < p->number_of_irqs; k++) |
| 372 | intc_irqpin_mask_unmask_prio(p, k, 1); |
| 373 | |
| 374 | /* use more severe masking method if requested */ |
| 375 | if (p->config.control_parent) { |
| 376 | enable_fn = intc_irqpin_irq_enable_force; |
| 377 | disable_fn = intc_irqpin_irq_disable_force; |
| 378 | } else { |
| 379 | enable_fn = intc_irqpin_irq_enable; |
| 380 | disable_fn = intc_irqpin_irq_disable; |
| 381 | } |
| 382 | |
| 383 | irq_chip = &p->irq_chip; |
| 384 | irq_chip->name = name; |
| 385 | irq_chip->irq_mask = disable_fn; |
| 386 | irq_chip->irq_unmask = enable_fn; |
| 387 | irq_chip->irq_enable = enable_fn; |
| 388 | irq_chip->irq_disable = disable_fn; |
| 389 | irq_chip->irq_set_type = intc_irqpin_irq_set_type; |
| 390 | irq_chip->flags = IRQCHIP_SKIP_SET_WAKE; |
| 391 | |
| 392 | p->irq_domain = irq_domain_add_simple(pdev->dev.of_node, |
| 393 | p->number_of_irqs, |
| 394 | p->config.irq_base, |
| 395 | &intc_irqpin_irq_domain_ops, p); |
| 396 | if (!p->irq_domain) { |
| 397 | ret = -ENXIO; |
| 398 | dev_err(&pdev->dev, "cannot initialize irq domain\n"); |
Magnus Damm | 08eba5b | 2013-02-26 20:59:13 +0900 | [diff] [blame^] | 399 | goto err0; |
Magnus Damm | 4435804 | 2013-02-18 23:28:34 +0900 | [diff] [blame] | 400 | } |
| 401 | |
| 402 | /* request and set priority on interrupts one by one */ |
| 403 | for (k = 0; k < p->number_of_irqs; k++) { |
Magnus Damm | 08eba5b | 2013-02-26 20:59:13 +0900 | [diff] [blame^] | 404 | if (devm_request_irq(&pdev->dev, p->irq[k].requested_irq, |
| 405 | intc_irqpin_irq_handler, |
| 406 | 0, name, &p->irq[k])) { |
Magnus Damm | 4435804 | 2013-02-18 23:28:34 +0900 | [diff] [blame] | 407 | dev_err(&pdev->dev, "failed to request low IRQ\n"); |
| 408 | ret = -ENOENT; |
Magnus Damm | 08eba5b | 2013-02-26 20:59:13 +0900 | [diff] [blame^] | 409 | goto err1; |
Magnus Damm | 4435804 | 2013-02-18 23:28:34 +0900 | [diff] [blame] | 410 | } |
| 411 | intc_irqpin_mask_unmask_prio(p, k, 0); |
| 412 | } |
| 413 | |
| 414 | dev_info(&pdev->dev, "driving %d irqs\n", p->number_of_irqs); |
| 415 | |
| 416 | /* warn in case of mismatch if irq base is specified */ |
| 417 | if (p->config.irq_base) { |
Magnus Damm | 33f958f | 2013-02-26 20:58:54 +0900 | [diff] [blame] | 418 | if (p->config.irq_base != p->irq[0].domain_irq) |
Magnus Damm | 4435804 | 2013-02-18 23:28:34 +0900 | [diff] [blame] | 419 | dev_warn(&pdev->dev, "irq base mismatch (%d/%d)\n", |
Magnus Damm | 33f958f | 2013-02-26 20:58:54 +0900 | [diff] [blame] | 420 | p->config.irq_base, p->irq[0].domain_irq); |
Magnus Damm | 4435804 | 2013-02-18 23:28:34 +0900 | [diff] [blame] | 421 | } |
Magnus Damm | 862d309 | 2013-02-26 20:58:44 +0900 | [diff] [blame] | 422 | |
Magnus Damm | 4435804 | 2013-02-18 23:28:34 +0900 | [diff] [blame] | 423 | return 0; |
| 424 | |
Magnus Damm | 4435804 | 2013-02-18 23:28:34 +0900 | [diff] [blame] | 425 | err1: |
Magnus Damm | 08eba5b | 2013-02-26 20:59:13 +0900 | [diff] [blame^] | 426 | irq_domain_remove(p->irq_domain); |
Magnus Damm | 4435804 | 2013-02-18 23:28:34 +0900 | [diff] [blame] | 427 | err0: |
| 428 | return ret; |
| 429 | } |
| 430 | |
| 431 | static int intc_irqpin_remove(struct platform_device *pdev) |
| 432 | { |
| 433 | struct intc_irqpin_priv *p = platform_get_drvdata(pdev); |
Magnus Damm | 4435804 | 2013-02-18 23:28:34 +0900 | [diff] [blame] | 434 | |
| 435 | irq_domain_remove(p->irq_domain); |
| 436 | |
Magnus Damm | 4435804 | 2013-02-18 23:28:34 +0900 | [diff] [blame] | 437 | return 0; |
| 438 | } |
| 439 | |
| 440 | static struct platform_driver intc_irqpin_device_driver = { |
| 441 | .probe = intc_irqpin_probe, |
| 442 | .remove = intc_irqpin_remove, |
| 443 | .driver = { |
| 444 | .name = "renesas_intc_irqpin", |
| 445 | } |
| 446 | }; |
| 447 | |
| 448 | static int __init intc_irqpin_init(void) |
| 449 | { |
| 450 | return platform_driver_register(&intc_irqpin_device_driver); |
| 451 | } |
| 452 | postcore_initcall(intc_irqpin_init); |
| 453 | |
| 454 | static void __exit intc_irqpin_exit(void) |
| 455 | { |
| 456 | platform_driver_unregister(&intc_irqpin_device_driver); |
| 457 | } |
| 458 | module_exit(intc_irqpin_exit); |
| 459 | |
| 460 | MODULE_AUTHOR("Magnus Damm"); |
| 461 | MODULE_DESCRIPTION("Renesas INTC External IRQ Pin Driver"); |
| 462 | MODULE_LICENSE("GPL v2"); |