Benjamin Gaignard | 8de50dc | 2017-11-30 09:45:00 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Alexandre TORGUE | e0720416 | 2016-09-20 18:00:57 +0200 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) Maxime Coquelin 2015 |
Benjamin Gaignard | 8de50dc | 2017-11-30 09:45:00 +0100 | [diff] [blame] | 4 | * Copyright (C) STMicroelectronics 2017 |
Alexandre TORGUE | e0720416 | 2016-09-20 18:00:57 +0200 | [diff] [blame] | 5 | * Author: Maxime Coquelin <mcoquelin.stm32@gmail.com> |
Alexandre TORGUE | e0720416 | 2016-09-20 18:00:57 +0200 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <linux/bitops.h> |
| 9 | #include <linux/interrupt.h> |
| 10 | #include <linux/io.h> |
| 11 | #include <linux/irq.h> |
| 12 | #include <linux/irqchip.h> |
| 13 | #include <linux/irqchip/chained_irq.h> |
| 14 | #include <linux/irqdomain.h> |
| 15 | #include <linux/of_address.h> |
| 16 | #include <linux/of_irq.h> |
| 17 | |
Ludovic Barre | 6dd64ee | 2017-11-06 18:03:32 +0100 | [diff] [blame] | 18 | #define IRQS_PER_BANK 32 |
| 19 | |
| 20 | struct stm32_exti_bank { |
| 21 | u32 imr_ofst; |
| 22 | u32 emr_ofst; |
| 23 | u32 rtsr_ofst; |
| 24 | u32 ftsr_ofst; |
| 25 | u32 swier_ofst; |
Ludovic Barre | be6230f | 2018-04-26 18:18:26 +0200 | [diff] [blame] | 26 | u32 rpr_ofst; |
| 27 | u32 fpr_ofst; |
Ludovic Barre | 6dd64ee | 2017-11-06 18:03:32 +0100 | [diff] [blame] | 28 | }; |
| 29 | |
Ludovic Barre | be6230f | 2018-04-26 18:18:26 +0200 | [diff] [blame] | 30 | #define UNDEF_REG ~0 |
| 31 | |
Ludovic Barre | f9fc174 | 2018-04-26 18:18:28 +0200 | [diff] [blame^] | 32 | struct stm32_exti_drv_data { |
| 33 | const struct stm32_exti_bank **exti_banks; |
| 34 | u32 bank_nr; |
| 35 | }; |
| 36 | |
Ludovic Barre | d9e2b19b0 | 2018-04-26 18:18:27 +0200 | [diff] [blame] | 37 | struct stm32_exti_chip_data { |
Ludovic Barre | f9fc174 | 2018-04-26 18:18:28 +0200 | [diff] [blame^] | 38 | struct stm32_exti_host_data *host_data; |
Ludovic Barre | d9e2b19b0 | 2018-04-26 18:18:27 +0200 | [diff] [blame] | 39 | const struct stm32_exti_bank *reg_bank; |
| 40 | u32 rtsr_cache; |
| 41 | u32 ftsr_cache; |
| 42 | }; |
| 43 | |
Ludovic Barre | f9fc174 | 2018-04-26 18:18:28 +0200 | [diff] [blame^] | 44 | struct stm32_exti_host_data { |
| 45 | void __iomem *base; |
| 46 | struct stm32_exti_chip_data *chips_data; |
| 47 | const struct stm32_exti_drv_data *drv_data; |
| 48 | }; |
Ludovic Barre | d9e2b19b0 | 2018-04-26 18:18:27 +0200 | [diff] [blame] | 49 | |
Ludovic Barre | 6dd64ee | 2017-11-06 18:03:32 +0100 | [diff] [blame] | 50 | static const struct stm32_exti_bank stm32f4xx_exti_b1 = { |
| 51 | .imr_ofst = 0x00, |
| 52 | .emr_ofst = 0x04, |
| 53 | .rtsr_ofst = 0x08, |
| 54 | .ftsr_ofst = 0x0C, |
| 55 | .swier_ofst = 0x10, |
Ludovic Barre | be6230f | 2018-04-26 18:18:26 +0200 | [diff] [blame] | 56 | .rpr_ofst = 0x14, |
| 57 | .fpr_ofst = UNDEF_REG, |
Ludovic Barre | 6dd64ee | 2017-11-06 18:03:32 +0100 | [diff] [blame] | 58 | }; |
| 59 | |
| 60 | static const struct stm32_exti_bank *stm32f4xx_exti_banks[] = { |
| 61 | &stm32f4xx_exti_b1, |
| 62 | }; |
| 63 | |
Ludovic Barre | f9fc174 | 2018-04-26 18:18:28 +0200 | [diff] [blame^] | 64 | static const struct stm32_exti_drv_data stm32f4xx_drv_data = { |
| 65 | .exti_banks = stm32f4xx_exti_banks, |
| 66 | .bank_nr = ARRAY_SIZE(stm32f4xx_exti_banks), |
| 67 | }; |
| 68 | |
Ludovic Barre | 539c603 | 2017-11-06 18:03:34 +0100 | [diff] [blame] | 69 | static const struct stm32_exti_bank stm32h7xx_exti_b1 = { |
| 70 | .imr_ofst = 0x80, |
| 71 | .emr_ofst = 0x84, |
| 72 | .rtsr_ofst = 0x00, |
| 73 | .ftsr_ofst = 0x04, |
| 74 | .swier_ofst = 0x08, |
Ludovic Barre | be6230f | 2018-04-26 18:18:26 +0200 | [diff] [blame] | 75 | .rpr_ofst = 0x88, |
| 76 | .fpr_ofst = UNDEF_REG, |
Ludovic Barre | 539c603 | 2017-11-06 18:03:34 +0100 | [diff] [blame] | 77 | }; |
| 78 | |
| 79 | static const struct stm32_exti_bank stm32h7xx_exti_b2 = { |
| 80 | .imr_ofst = 0x90, |
| 81 | .emr_ofst = 0x94, |
| 82 | .rtsr_ofst = 0x20, |
| 83 | .ftsr_ofst = 0x24, |
| 84 | .swier_ofst = 0x28, |
Ludovic Barre | be6230f | 2018-04-26 18:18:26 +0200 | [diff] [blame] | 85 | .rpr_ofst = 0x98, |
| 86 | .fpr_ofst = UNDEF_REG, |
Ludovic Barre | 539c603 | 2017-11-06 18:03:34 +0100 | [diff] [blame] | 87 | }; |
| 88 | |
| 89 | static const struct stm32_exti_bank stm32h7xx_exti_b3 = { |
| 90 | .imr_ofst = 0xA0, |
| 91 | .emr_ofst = 0xA4, |
| 92 | .rtsr_ofst = 0x40, |
| 93 | .ftsr_ofst = 0x44, |
| 94 | .swier_ofst = 0x48, |
Ludovic Barre | be6230f | 2018-04-26 18:18:26 +0200 | [diff] [blame] | 95 | .rpr_ofst = 0xA8, |
| 96 | .fpr_ofst = UNDEF_REG, |
Ludovic Barre | 539c603 | 2017-11-06 18:03:34 +0100 | [diff] [blame] | 97 | }; |
| 98 | |
| 99 | static const struct stm32_exti_bank *stm32h7xx_exti_banks[] = { |
| 100 | &stm32h7xx_exti_b1, |
| 101 | &stm32h7xx_exti_b2, |
| 102 | &stm32h7xx_exti_b3, |
| 103 | }; |
| 104 | |
Ludovic Barre | f9fc174 | 2018-04-26 18:18:28 +0200 | [diff] [blame^] | 105 | static const struct stm32_exti_drv_data stm32h7xx_drv_data = { |
| 106 | .exti_banks = stm32h7xx_exti_banks, |
| 107 | .bank_nr = ARRAY_SIZE(stm32h7xx_exti_banks), |
| 108 | }; |
| 109 | |
Ludovic Barre | 6dd64ee | 2017-11-06 18:03:32 +0100 | [diff] [blame] | 110 | static unsigned long stm32_exti_pending(struct irq_chip_generic *gc) |
| 111 | { |
Ludovic Barre | d9e2b19b0 | 2018-04-26 18:18:27 +0200 | [diff] [blame] | 112 | struct stm32_exti_chip_data *chip_data = gc->private; |
| 113 | const struct stm32_exti_bank *stm32_bank = chip_data->reg_bank; |
Ludovic Barre | be6230f | 2018-04-26 18:18:26 +0200 | [diff] [blame] | 114 | unsigned long pending; |
Ludovic Barre | 6dd64ee | 2017-11-06 18:03:32 +0100 | [diff] [blame] | 115 | |
Ludovic Barre | be6230f | 2018-04-26 18:18:26 +0200 | [diff] [blame] | 116 | pending = irq_reg_readl(gc, stm32_bank->rpr_ofst); |
| 117 | if (stm32_bank->fpr_ofst != UNDEF_REG) |
| 118 | pending |= irq_reg_readl(gc, stm32_bank->fpr_ofst); |
| 119 | |
| 120 | return pending; |
Ludovic Barre | 6dd64ee | 2017-11-06 18:03:32 +0100 | [diff] [blame] | 121 | } |
| 122 | |
Alexandre TORGUE | e0720416 | 2016-09-20 18:00:57 +0200 | [diff] [blame] | 123 | static void stm32_irq_handler(struct irq_desc *desc) |
| 124 | { |
| 125 | struct irq_domain *domain = irq_desc_get_handler_data(desc); |
Alexandre TORGUE | e0720416 | 2016-09-20 18:00:57 +0200 | [diff] [blame] | 126 | struct irq_chip *chip = irq_desc_get_chip(desc); |
Ludovic Barre | 6dd64ee | 2017-11-06 18:03:32 +0100 | [diff] [blame] | 127 | unsigned int virq, nbanks = domain->gc->num_chips; |
| 128 | struct irq_chip_generic *gc; |
Alexandre TORGUE | e0720416 | 2016-09-20 18:00:57 +0200 | [diff] [blame] | 129 | unsigned long pending; |
Ludovic Barre | 6dd64ee | 2017-11-06 18:03:32 +0100 | [diff] [blame] | 130 | int n, i, irq_base = 0; |
Alexandre TORGUE | e0720416 | 2016-09-20 18:00:57 +0200 | [diff] [blame] | 131 | |
| 132 | chained_irq_enter(chip, desc); |
| 133 | |
Ludovic Barre | 6dd64ee | 2017-11-06 18:03:32 +0100 | [diff] [blame] | 134 | for (i = 0; i < nbanks; i++, irq_base += IRQS_PER_BANK) { |
| 135 | gc = irq_get_domain_generic_chip(domain, irq_base); |
Ludovic Barre | 6dd64ee | 2017-11-06 18:03:32 +0100 | [diff] [blame] | 136 | |
| 137 | while ((pending = stm32_exti_pending(gc))) { |
| 138 | for_each_set_bit(n, &pending, IRQS_PER_BANK) { |
| 139 | virq = irq_find_mapping(domain, irq_base + n); |
| 140 | generic_handle_irq(virq); |
Ludovic Barre | 6dd64ee | 2017-11-06 18:03:32 +0100 | [diff] [blame] | 141 | } |
Alexandre TORGUE | e0720416 | 2016-09-20 18:00:57 +0200 | [diff] [blame] | 142 | } |
| 143 | } |
| 144 | |
| 145 | chained_irq_exit(chip, desc); |
| 146 | } |
| 147 | |
| 148 | static int stm32_irq_set_type(struct irq_data *data, unsigned int type) |
| 149 | { |
| 150 | struct irq_chip_generic *gc = irq_data_get_irq_chip_data(data); |
Ludovic Barre | d9e2b19b0 | 2018-04-26 18:18:27 +0200 | [diff] [blame] | 151 | struct stm32_exti_chip_data *chip_data = gc->private; |
| 152 | const struct stm32_exti_bank *stm32_bank = chip_data->reg_bank; |
Ludovic Barre | 6dd64ee | 2017-11-06 18:03:32 +0100 | [diff] [blame] | 153 | int pin = data->hwirq % IRQS_PER_BANK; |
Alexandre TORGUE | e0720416 | 2016-09-20 18:00:57 +0200 | [diff] [blame] | 154 | u32 rtsr, ftsr; |
| 155 | |
| 156 | irq_gc_lock(gc); |
| 157 | |
Ludovic Barre | 6dd64ee | 2017-11-06 18:03:32 +0100 | [diff] [blame] | 158 | rtsr = irq_reg_readl(gc, stm32_bank->rtsr_ofst); |
| 159 | ftsr = irq_reg_readl(gc, stm32_bank->ftsr_ofst); |
Alexandre TORGUE | e0720416 | 2016-09-20 18:00:57 +0200 | [diff] [blame] | 160 | |
| 161 | switch (type) { |
| 162 | case IRQ_TYPE_EDGE_RISING: |
| 163 | rtsr |= BIT(pin); |
| 164 | ftsr &= ~BIT(pin); |
| 165 | break; |
| 166 | case IRQ_TYPE_EDGE_FALLING: |
| 167 | rtsr &= ~BIT(pin); |
| 168 | ftsr |= BIT(pin); |
| 169 | break; |
| 170 | case IRQ_TYPE_EDGE_BOTH: |
| 171 | rtsr |= BIT(pin); |
| 172 | ftsr |= BIT(pin); |
| 173 | break; |
| 174 | default: |
| 175 | irq_gc_unlock(gc); |
| 176 | return -EINVAL; |
| 177 | } |
| 178 | |
Ludovic Barre | 6dd64ee | 2017-11-06 18:03:32 +0100 | [diff] [blame] | 179 | irq_reg_writel(gc, rtsr, stm32_bank->rtsr_ofst); |
| 180 | irq_reg_writel(gc, ftsr, stm32_bank->ftsr_ofst); |
Alexandre TORGUE | e0720416 | 2016-09-20 18:00:57 +0200 | [diff] [blame] | 181 | |
| 182 | irq_gc_unlock(gc); |
| 183 | |
| 184 | return 0; |
| 185 | } |
| 186 | |
Ludovic Barre | d9e2b19b0 | 2018-04-26 18:18:27 +0200 | [diff] [blame] | 187 | static void stm32_irq_suspend(struct irq_chip_generic *gc) |
Alexandre TORGUE | e0720416 | 2016-09-20 18:00:57 +0200 | [diff] [blame] | 188 | { |
Ludovic Barre | d9e2b19b0 | 2018-04-26 18:18:27 +0200 | [diff] [blame] | 189 | struct stm32_exti_chip_data *chip_data = gc->private; |
| 190 | const struct stm32_exti_bank *stm32_bank = chip_data->reg_bank; |
Alexandre TORGUE | e0720416 | 2016-09-20 18:00:57 +0200 | [diff] [blame] | 191 | |
| 192 | irq_gc_lock(gc); |
| 193 | |
Ludovic Barre | d9e2b19b0 | 2018-04-26 18:18:27 +0200 | [diff] [blame] | 194 | /* save rtsr, ftsr registers */ |
| 195 | chip_data->rtsr_cache = irq_reg_readl(gc, stm32_bank->rtsr_ofst); |
| 196 | chip_data->ftsr_cache = irq_reg_readl(gc, stm32_bank->ftsr_ofst); |
| 197 | |
| 198 | irq_reg_writel(gc, gc->wake_active, stm32_bank->imr_ofst); |
Alexandre TORGUE | e0720416 | 2016-09-20 18:00:57 +0200 | [diff] [blame] | 199 | |
| 200 | irq_gc_unlock(gc); |
Ludovic Barre | d9e2b19b0 | 2018-04-26 18:18:27 +0200 | [diff] [blame] | 201 | } |
Alexandre TORGUE | e0720416 | 2016-09-20 18:00:57 +0200 | [diff] [blame] | 202 | |
Ludovic Barre | d9e2b19b0 | 2018-04-26 18:18:27 +0200 | [diff] [blame] | 203 | static void stm32_irq_resume(struct irq_chip_generic *gc) |
| 204 | { |
| 205 | struct stm32_exti_chip_data *chip_data = gc->private; |
| 206 | const struct stm32_exti_bank *stm32_bank = chip_data->reg_bank; |
| 207 | |
| 208 | irq_gc_lock(gc); |
| 209 | |
| 210 | /* restore rtsr, ftsr registers */ |
| 211 | irq_reg_writel(gc, chip_data->rtsr_cache, stm32_bank->rtsr_ofst); |
| 212 | irq_reg_writel(gc, chip_data->ftsr_cache, stm32_bank->ftsr_ofst); |
| 213 | |
| 214 | irq_reg_writel(gc, gc->mask_cache, stm32_bank->imr_ofst); |
| 215 | |
| 216 | irq_gc_unlock(gc); |
Alexandre TORGUE | e0720416 | 2016-09-20 18:00:57 +0200 | [diff] [blame] | 217 | } |
| 218 | |
| 219 | static int stm32_exti_alloc(struct irq_domain *d, unsigned int virq, |
| 220 | unsigned int nr_irqs, void *data) |
| 221 | { |
Alexandre TORGUE | e0720416 | 2016-09-20 18:00:57 +0200 | [diff] [blame] | 222 | struct irq_fwspec *fwspec = data; |
| 223 | irq_hw_number_t hwirq; |
| 224 | |
| 225 | hwirq = fwspec->param[0]; |
| 226 | |
| 227 | irq_map_generic_chip(d, virq, hwirq); |
Alexandre TORGUE | e0720416 | 2016-09-20 18:00:57 +0200 | [diff] [blame] | 228 | |
| 229 | return 0; |
| 230 | } |
| 231 | |
| 232 | static void stm32_exti_free(struct irq_domain *d, unsigned int virq, |
| 233 | unsigned int nr_irqs) |
| 234 | { |
| 235 | struct irq_data *data = irq_domain_get_irq_data(d, virq); |
| 236 | |
| 237 | irq_domain_reset_irq_data(data); |
| 238 | } |
| 239 | |
Ludovic Barre | ea80aa2 | 2018-04-26 18:18:25 +0200 | [diff] [blame] | 240 | static const struct irq_domain_ops irq_exti_domain_ops = { |
Alexandre TORGUE | e0720416 | 2016-09-20 18:00:57 +0200 | [diff] [blame] | 241 | .map = irq_map_generic_chip, |
Alexandre TORGUE | e0720416 | 2016-09-20 18:00:57 +0200 | [diff] [blame] | 242 | .alloc = stm32_exti_alloc, |
| 243 | .free = stm32_exti_free, |
| 244 | }; |
| 245 | |
Ludovic Barre | be6230f | 2018-04-26 18:18:26 +0200 | [diff] [blame] | 246 | static void stm32_irq_ack(struct irq_data *d) |
| 247 | { |
| 248 | struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d); |
Ludovic Barre | d9e2b19b0 | 2018-04-26 18:18:27 +0200 | [diff] [blame] | 249 | struct stm32_exti_chip_data *chip_data = gc->private; |
| 250 | const struct stm32_exti_bank *stm32_bank = chip_data->reg_bank; |
Ludovic Barre | be6230f | 2018-04-26 18:18:26 +0200 | [diff] [blame] | 251 | |
| 252 | irq_gc_lock(gc); |
| 253 | |
| 254 | irq_reg_writel(gc, d->mask, stm32_bank->rpr_ofst); |
| 255 | if (stm32_bank->fpr_ofst != UNDEF_REG) |
| 256 | irq_reg_writel(gc, d->mask, stm32_bank->fpr_ofst); |
| 257 | |
| 258 | irq_gc_unlock(gc); |
| 259 | } |
Ludovic Barre | f9fc174 | 2018-04-26 18:18:28 +0200 | [diff] [blame^] | 260 | static struct |
| 261 | stm32_exti_host_data *stm32_exti_host_init(const struct stm32_exti_drv_data *dd, |
| 262 | struct device_node *node) |
Alexandre TORGUE | e0720416 | 2016-09-20 18:00:57 +0200 | [diff] [blame] | 263 | { |
Ludovic Barre | f9fc174 | 2018-04-26 18:18:28 +0200 | [diff] [blame^] | 264 | struct stm32_exti_host_data *host_data; |
Alexandre TORGUE | e0720416 | 2016-09-20 18:00:57 +0200 | [diff] [blame] | 265 | |
Ludovic Barre | f9fc174 | 2018-04-26 18:18:28 +0200 | [diff] [blame^] | 266 | host_data = kzalloc(sizeof(*host_data), GFP_KERNEL); |
| 267 | if (!host_data) |
| 268 | return NULL; |
| 269 | |
| 270 | host_data->drv_data = dd; |
| 271 | host_data->chips_data = kcalloc(dd->bank_nr, |
| 272 | sizeof(struct stm32_exti_chip_data), |
| 273 | GFP_KERNEL); |
| 274 | if (!host_data->chips_data) |
| 275 | return NULL; |
| 276 | |
| 277 | host_data->base = of_iomap(node, 0); |
| 278 | if (!host_data->base) { |
Rob Herring | e81f54c | 2017-07-18 16:43:10 -0500 | [diff] [blame] | 279 | pr_err("%pOF: Unable to map registers\n", node); |
Ludovic Barre | f9fc174 | 2018-04-26 18:18:28 +0200 | [diff] [blame^] | 280 | return NULL; |
Alexandre TORGUE | e0720416 | 2016-09-20 18:00:57 +0200 | [diff] [blame] | 281 | } |
| 282 | |
Ludovic Barre | f9fc174 | 2018-04-26 18:18:28 +0200 | [diff] [blame^] | 283 | return host_data; |
| 284 | } |
Ludovic Barre | d9e2b19b0 | 2018-04-26 18:18:27 +0200 | [diff] [blame] | 285 | |
Ludovic Barre | f9fc174 | 2018-04-26 18:18:28 +0200 | [diff] [blame^] | 286 | static struct |
| 287 | stm32_exti_chip_data *stm32_exti_chip_init(struct stm32_exti_host_data *h_data, |
| 288 | u32 bank_idx, |
| 289 | struct device_node *node) |
| 290 | { |
| 291 | const struct stm32_exti_bank *stm32_bank; |
| 292 | struct stm32_exti_chip_data *chip_data; |
| 293 | void __iomem *base = h_data->base; |
| 294 | u32 irqs_mask; |
| 295 | |
| 296 | stm32_bank = h_data->drv_data->exti_banks[bank_idx]; |
| 297 | chip_data = &h_data->chips_data[bank_idx]; |
| 298 | chip_data->host_data = h_data; |
| 299 | chip_data->reg_bank = stm32_bank; |
| 300 | |
| 301 | /* Determine number of irqs supported */ |
| 302 | writel_relaxed(~0UL, base + stm32_bank->rtsr_ofst); |
| 303 | irqs_mask = readl_relaxed(base + stm32_bank->rtsr_ofst); |
| 304 | |
| 305 | /* |
| 306 | * This IP has no reset, so after hot reboot we should |
| 307 | * clear registers to avoid residue |
| 308 | */ |
| 309 | writel_relaxed(0, base + stm32_bank->imr_ofst); |
| 310 | writel_relaxed(0, base + stm32_bank->emr_ofst); |
| 311 | writel_relaxed(0, base + stm32_bank->rtsr_ofst); |
| 312 | writel_relaxed(0, base + stm32_bank->ftsr_ofst); |
| 313 | writel_relaxed(~0UL, base + stm32_bank->rpr_ofst); |
| 314 | if (stm32_bank->fpr_ofst != UNDEF_REG) |
| 315 | writel_relaxed(~0UL, base + stm32_bank->fpr_ofst); |
| 316 | |
| 317 | pr_info("%s: bank%d, External IRQs available:%#x\n", |
| 318 | node->full_name, bank_idx, irqs_mask); |
| 319 | |
| 320 | return chip_data; |
| 321 | } |
| 322 | |
| 323 | static int __init stm32_exti_init(const struct stm32_exti_drv_data *drv_data, |
| 324 | struct device_node *node) |
| 325 | { |
| 326 | struct stm32_exti_host_data *host_data; |
| 327 | unsigned int clr = IRQ_NOREQUEST | IRQ_NOPROBE | IRQ_NOAUTOEN; |
| 328 | int nr_irqs, ret, i; |
| 329 | struct irq_chip_generic *gc; |
| 330 | struct irq_domain *domain; |
| 331 | |
| 332 | host_data = stm32_exti_host_init(drv_data, node); |
| 333 | if (!host_data) { |
| 334 | ret = -ENOMEM; |
| 335 | goto out_free_mem; |
| 336 | } |
| 337 | |
| 338 | domain = irq_domain_add_linear(node, drv_data->bank_nr * IRQS_PER_BANK, |
Alexandre TORGUE | e0720416 | 2016-09-20 18:00:57 +0200 | [diff] [blame] | 339 | &irq_exti_domain_ops, NULL); |
| 340 | if (!domain) { |
| 341 | pr_err("%s: Could not register interrupt domain.\n", |
Ludovic Barre | 6dd64ee | 2017-11-06 18:03:32 +0100 | [diff] [blame] | 342 | node->name); |
Alexandre TORGUE | e0720416 | 2016-09-20 18:00:57 +0200 | [diff] [blame] | 343 | ret = -ENOMEM; |
| 344 | goto out_unmap; |
| 345 | } |
| 346 | |
Ludovic Barre | 6dd64ee | 2017-11-06 18:03:32 +0100 | [diff] [blame] | 347 | ret = irq_alloc_domain_generic_chips(domain, IRQS_PER_BANK, 1, "exti", |
Alexandre TORGUE | e0720416 | 2016-09-20 18:00:57 +0200 | [diff] [blame] | 348 | handle_edge_irq, clr, 0, 0); |
| 349 | if (ret) { |
Rob Herring | e81f54c | 2017-07-18 16:43:10 -0500 | [diff] [blame] | 350 | pr_err("%pOF: Could not allocate generic interrupt chip.\n", |
Ludovic Barre | ea80aa2 | 2018-04-26 18:18:25 +0200 | [diff] [blame] | 351 | node); |
Alexandre TORGUE | e0720416 | 2016-09-20 18:00:57 +0200 | [diff] [blame] | 352 | goto out_free_domain; |
| 353 | } |
| 354 | |
Ludovic Barre | f9fc174 | 2018-04-26 18:18:28 +0200 | [diff] [blame^] | 355 | for (i = 0; i < drv_data->bank_nr; i++) { |
| 356 | const struct stm32_exti_bank *stm32_bank; |
| 357 | struct stm32_exti_chip_data *chip_data; |
Ludovic Barre | 6dd64ee | 2017-11-06 18:03:32 +0100 | [diff] [blame] | 358 | |
Ludovic Barre | f9fc174 | 2018-04-26 18:18:28 +0200 | [diff] [blame^] | 359 | stm32_bank = drv_data->exti_banks[i]; |
| 360 | chip_data = stm32_exti_chip_init(host_data, i, node); |
Ludovic Barre | d9e2b19b0 | 2018-04-26 18:18:27 +0200 | [diff] [blame] | 361 | |
Ludovic Barre | 6dd64ee | 2017-11-06 18:03:32 +0100 | [diff] [blame] | 362 | gc = irq_get_domain_generic_chip(domain, i * IRQS_PER_BANK); |
| 363 | |
Ludovic Barre | f9fc174 | 2018-04-26 18:18:28 +0200 | [diff] [blame^] | 364 | gc->reg_base = host_data->base; |
Ludovic Barre | 6dd64ee | 2017-11-06 18:03:32 +0100 | [diff] [blame] | 365 | gc->chip_types->type = IRQ_TYPE_EDGE_BOTH; |
Ludovic Barre | be6230f | 2018-04-26 18:18:26 +0200 | [diff] [blame] | 366 | gc->chip_types->chip.irq_ack = stm32_irq_ack; |
Ludovic Barre | 6dd64ee | 2017-11-06 18:03:32 +0100 | [diff] [blame] | 367 | gc->chip_types->chip.irq_mask = irq_gc_mask_clr_bit; |
| 368 | gc->chip_types->chip.irq_unmask = irq_gc_mask_set_bit; |
| 369 | gc->chip_types->chip.irq_set_type = stm32_irq_set_type; |
Ludovic Barre | d9e2b19b0 | 2018-04-26 18:18:27 +0200 | [diff] [blame] | 370 | gc->chip_types->chip.irq_set_wake = irq_gc_set_wake; |
| 371 | gc->suspend = stm32_irq_suspend; |
| 372 | gc->resume = stm32_irq_resume; |
| 373 | gc->wake_enabled = IRQ_MSK(IRQS_PER_BANK); |
| 374 | |
Ludovic Barre | 6dd64ee | 2017-11-06 18:03:32 +0100 | [diff] [blame] | 375 | gc->chip_types->regs.mask = stm32_bank->imr_ofst; |
Ludovic Barre | d9e2b19b0 | 2018-04-26 18:18:27 +0200 | [diff] [blame] | 376 | gc->private = (void *)chip_data; |
Ludovic Barre | 6dd64ee | 2017-11-06 18:03:32 +0100 | [diff] [blame] | 377 | } |
Alexandre TORGUE | e0720416 | 2016-09-20 18:00:57 +0200 | [diff] [blame] | 378 | |
| 379 | nr_irqs = of_irq_count(node); |
| 380 | for (i = 0; i < nr_irqs; i++) { |
| 381 | unsigned int irq = irq_of_parse_and_map(node, i); |
| 382 | |
| 383 | irq_set_handler_data(irq, domain); |
| 384 | irq_set_chained_handler(irq, stm32_irq_handler); |
| 385 | } |
| 386 | |
| 387 | return 0; |
| 388 | |
| 389 | out_free_domain: |
| 390 | irq_domain_remove(domain); |
| 391 | out_unmap: |
Ludovic Barre | f9fc174 | 2018-04-26 18:18:28 +0200 | [diff] [blame^] | 392 | iounmap(host_data->base); |
| 393 | out_free_mem: |
| 394 | kfree(host_data->chips_data); |
| 395 | kfree(host_data); |
Alexandre TORGUE | e0720416 | 2016-09-20 18:00:57 +0200 | [diff] [blame] | 396 | return ret; |
| 397 | } |
| 398 | |
Ludovic Barre | 6dd64ee | 2017-11-06 18:03:32 +0100 | [diff] [blame] | 399 | static int __init stm32f4_exti_of_init(struct device_node *np, |
| 400 | struct device_node *parent) |
| 401 | { |
Ludovic Barre | f9fc174 | 2018-04-26 18:18:28 +0200 | [diff] [blame^] | 402 | return stm32_exti_init(&stm32f4xx_drv_data, np); |
Ludovic Barre | 6dd64ee | 2017-11-06 18:03:32 +0100 | [diff] [blame] | 403 | } |
| 404 | |
| 405 | IRQCHIP_DECLARE(stm32f4_exti, "st,stm32-exti", stm32f4_exti_of_init); |
Ludovic Barre | 539c603 | 2017-11-06 18:03:34 +0100 | [diff] [blame] | 406 | |
| 407 | static int __init stm32h7_exti_of_init(struct device_node *np, |
| 408 | struct device_node *parent) |
| 409 | { |
Ludovic Barre | f9fc174 | 2018-04-26 18:18:28 +0200 | [diff] [blame^] | 410 | return stm32_exti_init(&stm32h7xx_drv_data, np); |
Ludovic Barre | 539c603 | 2017-11-06 18:03:34 +0100 | [diff] [blame] | 411 | } |
| 412 | |
| 413 | IRQCHIP_DECLARE(stm32h7_exti, "st,stm32h7-exti", stm32h7_exti_of_init); |