Mark Brown | f8beab2 | 2011-10-28 23:50:49 +0200 | [diff] [blame] | 1 | /* |
| 2 | * regmap based irq_chip |
| 3 | * |
| 4 | * Copyright 2011 Wolfson Microelectronics plc |
| 5 | * |
| 6 | * Author: Mark Brown <broonie@opensource.wolfsonmicro.com> |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License version 2 as |
| 10 | * published by the Free Software Foundation. |
| 11 | */ |
| 12 | |
| 13 | #include <linux/export.h> |
Paul Gortmaker | 51990e8 | 2012-01-22 11:23:42 -0500 | [diff] [blame] | 14 | #include <linux/device.h> |
Mark Brown | f8beab2 | 2011-10-28 23:50:49 +0200 | [diff] [blame] | 15 | #include <linux/regmap.h> |
| 16 | #include <linux/irq.h> |
| 17 | #include <linux/interrupt.h> |
Mark Brown | 4af8be6 | 2012-05-13 10:59:56 +0100 | [diff] [blame] | 18 | #include <linux/irqdomain.h> |
Mark Brown | f8beab2 | 2011-10-28 23:50:49 +0200 | [diff] [blame] | 19 | #include <linux/slab.h> |
| 20 | |
| 21 | #include "internal.h" |
| 22 | |
| 23 | struct regmap_irq_chip_data { |
| 24 | struct mutex lock; |
| 25 | |
| 26 | struct regmap *map; |
Mark Brown | b026ddb | 2012-05-31 21:01:46 +0100 | [diff] [blame] | 27 | const struct regmap_irq_chip *chip; |
Mark Brown | f8beab2 | 2011-10-28 23:50:49 +0200 | [diff] [blame] | 28 | |
| 29 | int irq_base; |
Mark Brown | 4af8be6 | 2012-05-13 10:59:56 +0100 | [diff] [blame] | 30 | struct irq_domain *domain; |
Mark Brown | f8beab2 | 2011-10-28 23:50:49 +0200 | [diff] [blame] | 31 | |
Mark Brown | a43fd50 | 2012-06-05 14:34:03 +0100 | [diff] [blame] | 32 | int irq; |
| 33 | int wake_count; |
| 34 | |
Mark Brown | f8beab2 | 2011-10-28 23:50:49 +0200 | [diff] [blame] | 35 | unsigned int *status_buf; |
| 36 | unsigned int *mask_buf; |
| 37 | unsigned int *mask_buf_def; |
Mark Brown | a43fd50 | 2012-06-05 14:34:03 +0100 | [diff] [blame] | 38 | unsigned int *wake_buf; |
Graeme Gregory | 022f926a | 2012-05-14 22:40:43 +0900 | [diff] [blame] | 39 | |
| 40 | unsigned int irq_reg_stride; |
Mark Brown | f8beab2 | 2011-10-28 23:50:49 +0200 | [diff] [blame] | 41 | }; |
| 42 | |
| 43 | static inline const |
| 44 | struct regmap_irq *irq_to_regmap_irq(struct regmap_irq_chip_data *data, |
| 45 | int irq) |
| 46 | { |
Mark Brown | 4af8be6 | 2012-05-13 10:59:56 +0100 | [diff] [blame] | 47 | return &data->chip->irqs[irq]; |
Mark Brown | f8beab2 | 2011-10-28 23:50:49 +0200 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | static void regmap_irq_lock(struct irq_data *data) |
| 51 | { |
| 52 | struct regmap_irq_chip_data *d = irq_data_get_irq_chip_data(data); |
| 53 | |
| 54 | mutex_lock(&d->lock); |
| 55 | } |
| 56 | |
| 57 | static void regmap_irq_sync_unlock(struct irq_data *data) |
| 58 | { |
| 59 | struct regmap_irq_chip_data *d = irq_data_get_irq_chip_data(data); |
Stephen Warren | 5680655 | 2012-04-10 23:37:22 -0600 | [diff] [blame] | 60 | struct regmap *map = d->map; |
Mark Brown | f8beab2 | 2011-10-28 23:50:49 +0200 | [diff] [blame] | 61 | int i, ret; |
Stephen Warren | 1603262 | 2012-07-27 13:01:54 -0600 | [diff] [blame^] | 62 | u32 reg; |
Mark Brown | f8beab2 | 2011-10-28 23:50:49 +0200 | [diff] [blame] | 63 | |
| 64 | /* |
| 65 | * If there's been a change in the mask write it back to the |
| 66 | * hardware. We rely on the use of the regmap core cache to |
| 67 | * suppress pointless writes. |
| 68 | */ |
| 69 | for (i = 0; i < d->chip->num_regs; i++) { |
Stephen Warren | 1603262 | 2012-07-27 13:01:54 -0600 | [diff] [blame^] | 70 | reg = d->chip->mask_base + |
| 71 | (i * map->reg_stride * d->irq_reg_stride); |
| 72 | ret = regmap_update_bits(d->map, reg, |
Mark Brown | f8beab2 | 2011-10-28 23:50:49 +0200 | [diff] [blame] | 73 | d->mask_buf_def[i], d->mask_buf[i]); |
| 74 | if (ret != 0) |
| 75 | dev_err(d->map->dev, "Failed to sync masks in %x\n", |
Stephen Warren | 1603262 | 2012-07-27 13:01:54 -0600 | [diff] [blame^] | 76 | reg); |
Mark Brown | f8beab2 | 2011-10-28 23:50:49 +0200 | [diff] [blame] | 77 | } |
| 78 | |
Mark Brown | a43fd50 | 2012-06-05 14:34:03 +0100 | [diff] [blame] | 79 | /* If we've changed our wakeup count propagate it to the parent */ |
| 80 | if (d->wake_count < 0) |
| 81 | for (i = d->wake_count; i < 0; i++) |
| 82 | irq_set_irq_wake(d->irq, 0); |
| 83 | else if (d->wake_count > 0) |
| 84 | for (i = 0; i < d->wake_count; i++) |
| 85 | irq_set_irq_wake(d->irq, 1); |
| 86 | |
| 87 | d->wake_count = 0; |
| 88 | |
Mark Brown | f8beab2 | 2011-10-28 23:50:49 +0200 | [diff] [blame] | 89 | mutex_unlock(&d->lock); |
| 90 | } |
| 91 | |
| 92 | static void regmap_irq_enable(struct irq_data *data) |
| 93 | { |
| 94 | struct regmap_irq_chip_data *d = irq_data_get_irq_chip_data(data); |
Stephen Warren | 5680655 | 2012-04-10 23:37:22 -0600 | [diff] [blame] | 95 | struct regmap *map = d->map; |
Mark Brown | 4af8be6 | 2012-05-13 10:59:56 +0100 | [diff] [blame] | 96 | const struct regmap_irq *irq_data = irq_to_regmap_irq(d, data->hwirq); |
Mark Brown | f8beab2 | 2011-10-28 23:50:49 +0200 | [diff] [blame] | 97 | |
Stephen Warren | f01ee60 | 2012-04-09 13:40:24 -0600 | [diff] [blame] | 98 | d->mask_buf[irq_data->reg_offset / map->reg_stride] &= ~irq_data->mask; |
Mark Brown | f8beab2 | 2011-10-28 23:50:49 +0200 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | static void regmap_irq_disable(struct irq_data *data) |
| 102 | { |
| 103 | struct regmap_irq_chip_data *d = irq_data_get_irq_chip_data(data); |
Stephen Warren | 5680655 | 2012-04-10 23:37:22 -0600 | [diff] [blame] | 104 | struct regmap *map = d->map; |
Mark Brown | 4af8be6 | 2012-05-13 10:59:56 +0100 | [diff] [blame] | 105 | const struct regmap_irq *irq_data = irq_to_regmap_irq(d, data->hwirq); |
Mark Brown | f8beab2 | 2011-10-28 23:50:49 +0200 | [diff] [blame] | 106 | |
Stephen Warren | f01ee60 | 2012-04-09 13:40:24 -0600 | [diff] [blame] | 107 | d->mask_buf[irq_data->reg_offset / map->reg_stride] |= irq_data->mask; |
Mark Brown | f8beab2 | 2011-10-28 23:50:49 +0200 | [diff] [blame] | 108 | } |
| 109 | |
Mark Brown | a43fd50 | 2012-06-05 14:34:03 +0100 | [diff] [blame] | 110 | static int regmap_irq_set_wake(struct irq_data *data, unsigned int on) |
| 111 | { |
| 112 | struct regmap_irq_chip_data *d = irq_data_get_irq_chip_data(data); |
| 113 | struct regmap *map = d->map; |
| 114 | const struct regmap_irq *irq_data = irq_to_regmap_irq(d, data->hwirq); |
| 115 | |
| 116 | if (!d->chip->wake_base) |
| 117 | return -EINVAL; |
| 118 | |
| 119 | if (on) { |
| 120 | d->wake_buf[irq_data->reg_offset / map->reg_stride] |
| 121 | &= ~irq_data->mask; |
| 122 | d->wake_count++; |
| 123 | } else { |
| 124 | d->wake_buf[irq_data->reg_offset / map->reg_stride] |
| 125 | |= irq_data->mask; |
| 126 | d->wake_count--; |
| 127 | } |
| 128 | |
| 129 | return 0; |
| 130 | } |
| 131 | |
Mark Brown | f8beab2 | 2011-10-28 23:50:49 +0200 | [diff] [blame] | 132 | static struct irq_chip regmap_irq_chip = { |
| 133 | .name = "regmap", |
| 134 | .irq_bus_lock = regmap_irq_lock, |
| 135 | .irq_bus_sync_unlock = regmap_irq_sync_unlock, |
| 136 | .irq_disable = regmap_irq_disable, |
| 137 | .irq_enable = regmap_irq_enable, |
Mark Brown | a43fd50 | 2012-06-05 14:34:03 +0100 | [diff] [blame] | 138 | .irq_set_wake = regmap_irq_set_wake, |
Mark Brown | f8beab2 | 2011-10-28 23:50:49 +0200 | [diff] [blame] | 139 | }; |
| 140 | |
| 141 | static irqreturn_t regmap_irq_thread(int irq, void *d) |
| 142 | { |
| 143 | struct regmap_irq_chip_data *data = d; |
Mark Brown | b026ddb | 2012-05-31 21:01:46 +0100 | [diff] [blame] | 144 | const struct regmap_irq_chip *chip = data->chip; |
Mark Brown | f8beab2 | 2011-10-28 23:50:49 +0200 | [diff] [blame] | 145 | struct regmap *map = data->map; |
| 146 | int ret, i; |
Mark Brown | d23511f | 2011-11-28 18:50:39 +0000 | [diff] [blame] | 147 | bool handled = false; |
Stephen Warren | 1603262 | 2012-07-27 13:01:54 -0600 | [diff] [blame^] | 148 | u32 reg; |
Mark Brown | f8beab2 | 2011-10-28 23:50:49 +0200 | [diff] [blame] | 149 | |
Mark Brown | f8beab2 | 2011-10-28 23:50:49 +0200 | [diff] [blame] | 150 | /* |
| 151 | * Ignore masked IRQs and ack if we need to; we ack early so |
| 152 | * there is no race between handling and acknowleding the |
| 153 | * interrupt. We assume that typically few of the interrupts |
| 154 | * will fire simultaneously so don't worry about overhead from |
| 155 | * doing a write per register. |
| 156 | */ |
| 157 | for (i = 0; i < data->chip->num_regs; i++) { |
Mark Brown | 38e7f5d | 2012-05-17 13:59:40 +0100 | [diff] [blame] | 158 | ret = regmap_read(map, chip->status_base + (i * map->reg_stride |
Graeme Gregory | 022f926a | 2012-05-14 22:40:43 +0900 | [diff] [blame] | 159 | * data->irq_reg_stride), |
| 160 | &data->status_buf[i]); |
| 161 | |
| 162 | if (ret != 0) { |
| 163 | dev_err(map->dev, "Failed to read IRQ status: %d\n", |
| 164 | ret); |
Mark Brown | f8beab2 | 2011-10-28 23:50:49 +0200 | [diff] [blame] | 165 | return IRQ_NONE; |
| 166 | } |
| 167 | |
| 168 | data->status_buf[i] &= ~data->mask_buf[i]; |
| 169 | |
| 170 | if (data->status_buf[i] && chip->ack_base) { |
Stephen Warren | 1603262 | 2012-07-27 13:01:54 -0600 | [diff] [blame^] | 171 | reg = chip->ack_base + |
| 172 | (i * map->reg_stride * data->irq_reg_stride); |
| 173 | ret = regmap_write(map, reg, data->status_buf[i]); |
Mark Brown | f8beab2 | 2011-10-28 23:50:49 +0200 | [diff] [blame] | 174 | if (ret != 0) |
| 175 | dev_err(map->dev, "Failed to ack 0x%x: %d\n", |
Stephen Warren | 1603262 | 2012-07-27 13:01:54 -0600 | [diff] [blame^] | 176 | reg, ret); |
Mark Brown | f8beab2 | 2011-10-28 23:50:49 +0200 | [diff] [blame] | 177 | } |
| 178 | } |
| 179 | |
| 180 | for (i = 0; i < chip->num_irqs; i++) { |
Stephen Warren | f01ee60 | 2012-04-09 13:40:24 -0600 | [diff] [blame] | 181 | if (data->status_buf[chip->irqs[i].reg_offset / |
| 182 | map->reg_stride] & chip->irqs[i].mask) { |
Mark Brown | 4af8be6 | 2012-05-13 10:59:56 +0100 | [diff] [blame] | 183 | handle_nested_irq(irq_find_mapping(data->domain, i)); |
Mark Brown | d23511f | 2011-11-28 18:50:39 +0000 | [diff] [blame] | 184 | handled = true; |
Mark Brown | f8beab2 | 2011-10-28 23:50:49 +0200 | [diff] [blame] | 185 | } |
| 186 | } |
| 187 | |
Mark Brown | d23511f | 2011-11-28 18:50:39 +0000 | [diff] [blame] | 188 | if (handled) |
| 189 | return IRQ_HANDLED; |
| 190 | else |
| 191 | return IRQ_NONE; |
Mark Brown | f8beab2 | 2011-10-28 23:50:49 +0200 | [diff] [blame] | 192 | } |
| 193 | |
Mark Brown | 4af8be6 | 2012-05-13 10:59:56 +0100 | [diff] [blame] | 194 | static int regmap_irq_map(struct irq_domain *h, unsigned int virq, |
| 195 | irq_hw_number_t hw) |
| 196 | { |
| 197 | struct regmap_irq_chip_data *data = h->host_data; |
| 198 | |
| 199 | irq_set_chip_data(virq, data); |
| 200 | irq_set_chip_and_handler(virq, ®map_irq_chip, handle_edge_irq); |
| 201 | irq_set_nested_thread(virq, 1); |
| 202 | |
| 203 | /* ARM needs us to explicitly flag the IRQ as valid |
| 204 | * and will set them noprobe when we do so. */ |
| 205 | #ifdef CONFIG_ARM |
| 206 | set_irq_flags(virq, IRQF_VALID); |
| 207 | #else |
| 208 | irq_set_noprobe(virq); |
| 209 | #endif |
| 210 | |
| 211 | return 0; |
| 212 | } |
| 213 | |
| 214 | static struct irq_domain_ops regmap_domain_ops = { |
| 215 | .map = regmap_irq_map, |
| 216 | .xlate = irq_domain_xlate_twocell, |
| 217 | }; |
| 218 | |
Mark Brown | f8beab2 | 2011-10-28 23:50:49 +0200 | [diff] [blame] | 219 | /** |
| 220 | * regmap_add_irq_chip(): Use standard regmap IRQ controller handling |
| 221 | * |
| 222 | * map: The regmap for the device. |
| 223 | * irq: The IRQ the device uses to signal interrupts |
| 224 | * irq_flags: The IRQF_ flags to use for the primary interrupt. |
| 225 | * chip: Configuration for the interrupt controller. |
| 226 | * data: Runtime data structure for the controller, allocated on success |
| 227 | * |
| 228 | * Returns 0 on success or an errno on failure. |
| 229 | * |
| 230 | * In order for this to be efficient the chip really should use a |
| 231 | * register cache. The chip driver is responsible for restoring the |
| 232 | * register values used by the IRQ controller over suspend and resume. |
| 233 | */ |
| 234 | int regmap_add_irq_chip(struct regmap *map, int irq, int irq_flags, |
Mark Brown | b026ddb | 2012-05-31 21:01:46 +0100 | [diff] [blame] | 235 | int irq_base, const struct regmap_irq_chip *chip, |
Mark Brown | f8beab2 | 2011-10-28 23:50:49 +0200 | [diff] [blame] | 236 | struct regmap_irq_chip_data **data) |
| 237 | { |
| 238 | struct regmap_irq_chip_data *d; |
Mark Brown | 4af8be6 | 2012-05-13 10:59:56 +0100 | [diff] [blame] | 239 | int i; |
Mark Brown | f8beab2 | 2011-10-28 23:50:49 +0200 | [diff] [blame] | 240 | int ret = -ENOMEM; |
Stephen Warren | 1603262 | 2012-07-27 13:01:54 -0600 | [diff] [blame^] | 241 | u32 reg; |
Mark Brown | f8beab2 | 2011-10-28 23:50:49 +0200 | [diff] [blame] | 242 | |
Stephen Warren | f01ee60 | 2012-04-09 13:40:24 -0600 | [diff] [blame] | 243 | for (i = 0; i < chip->num_irqs; i++) { |
| 244 | if (chip->irqs[i].reg_offset % map->reg_stride) |
| 245 | return -EINVAL; |
| 246 | if (chip->irqs[i].reg_offset / map->reg_stride >= |
| 247 | chip->num_regs) |
| 248 | return -EINVAL; |
| 249 | } |
| 250 | |
Mark Brown | 4af8be6 | 2012-05-13 10:59:56 +0100 | [diff] [blame] | 251 | if (irq_base) { |
| 252 | irq_base = irq_alloc_descs(irq_base, 0, chip->num_irqs, 0); |
| 253 | if (irq_base < 0) { |
| 254 | dev_warn(map->dev, "Failed to allocate IRQs: %d\n", |
| 255 | irq_base); |
| 256 | return irq_base; |
| 257 | } |
Mark Brown | f8beab2 | 2011-10-28 23:50:49 +0200 | [diff] [blame] | 258 | } |
| 259 | |
| 260 | d = kzalloc(sizeof(*d), GFP_KERNEL); |
| 261 | if (!d) |
| 262 | return -ENOMEM; |
| 263 | |
Mark Brown | 2431d0a | 2012-05-13 11:18:34 +0100 | [diff] [blame] | 264 | *data = d; |
| 265 | |
Mark Brown | f8beab2 | 2011-10-28 23:50:49 +0200 | [diff] [blame] | 266 | d->status_buf = kzalloc(sizeof(unsigned int) * chip->num_regs, |
| 267 | GFP_KERNEL); |
| 268 | if (!d->status_buf) |
| 269 | goto err_alloc; |
| 270 | |
Mark Brown | f8beab2 | 2011-10-28 23:50:49 +0200 | [diff] [blame] | 271 | d->mask_buf = kzalloc(sizeof(unsigned int) * chip->num_regs, |
| 272 | GFP_KERNEL); |
| 273 | if (!d->mask_buf) |
| 274 | goto err_alloc; |
| 275 | |
| 276 | d->mask_buf_def = kzalloc(sizeof(unsigned int) * chip->num_regs, |
| 277 | GFP_KERNEL); |
| 278 | if (!d->mask_buf_def) |
| 279 | goto err_alloc; |
| 280 | |
Mark Brown | a43fd50 | 2012-06-05 14:34:03 +0100 | [diff] [blame] | 281 | if (chip->wake_base) { |
| 282 | d->wake_buf = kzalloc(sizeof(unsigned int) * chip->num_regs, |
| 283 | GFP_KERNEL); |
| 284 | if (!d->wake_buf) |
| 285 | goto err_alloc; |
| 286 | } |
| 287 | |
| 288 | d->irq = irq; |
Mark Brown | f8beab2 | 2011-10-28 23:50:49 +0200 | [diff] [blame] | 289 | d->map = map; |
| 290 | d->chip = chip; |
| 291 | d->irq_base = irq_base; |
Graeme Gregory | 022f926a | 2012-05-14 22:40:43 +0900 | [diff] [blame] | 292 | |
| 293 | if (chip->irq_reg_stride) |
| 294 | d->irq_reg_stride = chip->irq_reg_stride; |
| 295 | else |
| 296 | d->irq_reg_stride = 1; |
| 297 | |
Mark Brown | f8beab2 | 2011-10-28 23:50:49 +0200 | [diff] [blame] | 298 | mutex_init(&d->lock); |
| 299 | |
| 300 | for (i = 0; i < chip->num_irqs; i++) |
Stephen Warren | f01ee60 | 2012-04-09 13:40:24 -0600 | [diff] [blame] | 301 | d->mask_buf_def[chip->irqs[i].reg_offset / map->reg_stride] |
Mark Brown | f8beab2 | 2011-10-28 23:50:49 +0200 | [diff] [blame] | 302 | |= chip->irqs[i].mask; |
| 303 | |
| 304 | /* Mask all the interrupts by default */ |
| 305 | for (i = 0; i < chip->num_regs; i++) { |
| 306 | d->mask_buf[i] = d->mask_buf_def[i]; |
Stephen Warren | 1603262 | 2012-07-27 13:01:54 -0600 | [diff] [blame^] | 307 | reg = chip->mask_base + |
| 308 | (i * map->reg_stride * d->irq_reg_stride); |
| 309 | ret = regmap_write(map, reg, d->mask_buf[i]); |
Mark Brown | f8beab2 | 2011-10-28 23:50:49 +0200 | [diff] [blame] | 310 | if (ret != 0) { |
| 311 | dev_err(map->dev, "Failed to set masks in 0x%x: %d\n", |
Stephen Warren | 1603262 | 2012-07-27 13:01:54 -0600 | [diff] [blame^] | 312 | reg, ret); |
Mark Brown | f8beab2 | 2011-10-28 23:50:49 +0200 | [diff] [blame] | 313 | goto err_alloc; |
| 314 | } |
| 315 | } |
| 316 | |
Mark Brown | 4af8be6 | 2012-05-13 10:59:56 +0100 | [diff] [blame] | 317 | if (irq_base) |
| 318 | d->domain = irq_domain_add_legacy(map->dev->of_node, |
| 319 | chip->num_irqs, irq_base, 0, |
| 320 | ®map_domain_ops, d); |
| 321 | else |
| 322 | d->domain = irq_domain_add_linear(map->dev->of_node, |
| 323 | chip->num_irqs, |
| 324 | ®map_domain_ops, d); |
| 325 | if (!d->domain) { |
| 326 | dev_err(map->dev, "Failed to create IRQ domain\n"); |
| 327 | ret = -ENOMEM; |
| 328 | goto err_alloc; |
Mark Brown | f8beab2 | 2011-10-28 23:50:49 +0200 | [diff] [blame] | 329 | } |
| 330 | |
| 331 | ret = request_threaded_irq(irq, NULL, regmap_irq_thread, irq_flags, |
| 332 | chip->name, d); |
| 333 | if (ret != 0) { |
| 334 | dev_err(map->dev, "Failed to request IRQ %d: %d\n", irq, ret); |
Mark Brown | 4af8be6 | 2012-05-13 10:59:56 +0100 | [diff] [blame] | 335 | goto err_domain; |
Mark Brown | f8beab2 | 2011-10-28 23:50:49 +0200 | [diff] [blame] | 336 | } |
| 337 | |
| 338 | return 0; |
| 339 | |
Mark Brown | 4af8be6 | 2012-05-13 10:59:56 +0100 | [diff] [blame] | 340 | err_domain: |
| 341 | /* Should really dispose of the domain but... */ |
Mark Brown | f8beab2 | 2011-10-28 23:50:49 +0200 | [diff] [blame] | 342 | err_alloc: |
Mark Brown | a43fd50 | 2012-06-05 14:34:03 +0100 | [diff] [blame] | 343 | kfree(d->wake_buf); |
Mark Brown | f8beab2 | 2011-10-28 23:50:49 +0200 | [diff] [blame] | 344 | kfree(d->mask_buf_def); |
| 345 | kfree(d->mask_buf); |
Mark Brown | f8beab2 | 2011-10-28 23:50:49 +0200 | [diff] [blame] | 346 | kfree(d->status_buf); |
| 347 | kfree(d); |
| 348 | return ret; |
| 349 | } |
| 350 | EXPORT_SYMBOL_GPL(regmap_add_irq_chip); |
| 351 | |
| 352 | /** |
| 353 | * regmap_del_irq_chip(): Stop interrupt handling for a regmap IRQ chip |
| 354 | * |
| 355 | * @irq: Primary IRQ for the device |
| 356 | * @d: regmap_irq_chip_data allocated by regmap_add_irq_chip() |
| 357 | */ |
| 358 | void regmap_del_irq_chip(int irq, struct regmap_irq_chip_data *d) |
| 359 | { |
| 360 | if (!d) |
| 361 | return; |
| 362 | |
| 363 | free_irq(irq, d); |
Mark Brown | 4af8be6 | 2012-05-13 10:59:56 +0100 | [diff] [blame] | 364 | /* We should unmap the domain but... */ |
Mark Brown | a43fd50 | 2012-06-05 14:34:03 +0100 | [diff] [blame] | 365 | kfree(d->wake_buf); |
Mark Brown | f8beab2 | 2011-10-28 23:50:49 +0200 | [diff] [blame] | 366 | kfree(d->mask_buf_def); |
| 367 | kfree(d->mask_buf); |
Mark Brown | f8beab2 | 2011-10-28 23:50:49 +0200 | [diff] [blame] | 368 | kfree(d->status_buf); |
| 369 | kfree(d); |
| 370 | } |
| 371 | EXPORT_SYMBOL_GPL(regmap_del_irq_chip); |
Mark Brown | 209a600 | 2011-12-05 16:10:15 +0000 | [diff] [blame] | 372 | |
| 373 | /** |
| 374 | * regmap_irq_chip_get_base(): Retrieve interrupt base for a regmap IRQ chip |
| 375 | * |
| 376 | * Useful for drivers to request their own IRQs. |
| 377 | * |
| 378 | * @data: regmap_irq controller to operate on. |
| 379 | */ |
| 380 | int regmap_irq_chip_get_base(struct regmap_irq_chip_data *data) |
| 381 | { |
Mark Brown | 4af8be6 | 2012-05-13 10:59:56 +0100 | [diff] [blame] | 382 | WARN_ON(!data->irq_base); |
Mark Brown | 209a600 | 2011-12-05 16:10:15 +0000 | [diff] [blame] | 383 | return data->irq_base; |
| 384 | } |
| 385 | EXPORT_SYMBOL_GPL(regmap_irq_chip_get_base); |
Mark Brown | 4af8be6 | 2012-05-13 10:59:56 +0100 | [diff] [blame] | 386 | |
| 387 | /** |
| 388 | * regmap_irq_get_virq(): Map an interrupt on a chip to a virtual IRQ |
| 389 | * |
| 390 | * Useful for drivers to request their own IRQs. |
| 391 | * |
| 392 | * @data: regmap_irq controller to operate on. |
| 393 | * @irq: index of the interrupt requested in the chip IRQs |
| 394 | */ |
| 395 | int regmap_irq_get_virq(struct regmap_irq_chip_data *data, int irq) |
| 396 | { |
Mark Brown | bfd6185d | 2012-06-05 14:29:36 +0100 | [diff] [blame] | 397 | /* Handle holes in the IRQ list */ |
| 398 | if (!data->chip->irqs[irq].mask) |
| 399 | return -EINVAL; |
| 400 | |
Mark Brown | 4af8be6 | 2012-05-13 10:59:56 +0100 | [diff] [blame] | 401 | return irq_create_mapping(data->domain, irq); |
| 402 | } |
| 403 | EXPORT_SYMBOL_GPL(regmap_irq_get_virq); |