Blame view
drivers/irqchip/irq-nvic.c
3.75 KB
292ec0804 irqchip: Add supp... |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
/* * drivers/irq/irq-nvic.c * * Copyright (C) 2008 ARM Limited, All Rights Reserved. * Copyright (C) 2013 Pengutronix * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. * * Support for the Nested Vectored Interrupt Controller found on the * ARMv7-M CPUs (Cortex-M3/M4) */ #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt #include <linux/init.h> #include <linux/kernel.h> #include <linux/slab.h> #include <linux/err.h> #include <linux/io.h> #include <linux/of.h> #include <linux/of_address.h> #include <linux/irq.h> |
41a83e06e irqchip: Prepare ... |
24 |
#include <linux/irqchip.h> |
292ec0804 irqchip: Add supp... |
25 26 27 28 |
#include <linux/irqdomain.h> #include <asm/v7m.h> #include <asm/exception.h> |
292ec0804 irqchip: Add supp... |
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
#define NVIC_ISER 0x000 #define NVIC_ICER 0x080 #define NVIC_IPR 0x300 #define NVIC_MAX_BANKS 16 /* * Each bank handles 32 irqs. Only the 16th (= last) bank handles only * 16 irqs. */ #define NVIC_MAX_IRQ ((NVIC_MAX_BANKS - 1) * 32 + 16) static struct irq_domain *nvic_irq_domain; asmlinkage void __exception_irq_entry nvic_handle_irq(irq_hw_number_t hwirq, struct pt_regs *regs) { unsigned int irq = irq_linear_revmap(nvic_irq_domain, hwirq); handle_IRQ(irq, regs); } |
f833f57ff irqchip: Convert ... |
49 50 51 52 53 54 55 56 57 58 |
static int nvic_irq_domain_translate(struct irq_domain *d, struct irq_fwspec *fwspec, unsigned long *hwirq, unsigned int *type) { if (WARN_ON(fwspec->param_count < 1)) return -EINVAL; *hwirq = fwspec->param[0]; *type = IRQ_TYPE_NONE; return 0; } |
2d9f59f7b irqchip: nvic: Su... |
59 60 61 62 63 64 |
static int nvic_irq_domain_alloc(struct irq_domain *domain, unsigned int virq, unsigned int nr_irqs, void *arg) { int i, ret; irq_hw_number_t hwirq; unsigned int type = IRQ_TYPE_NONE; |
f833f57ff irqchip: Convert ... |
65 |
struct irq_fwspec *fwspec = arg; |
2d9f59f7b irqchip: nvic: Su... |
66 |
|
f833f57ff irqchip: Convert ... |
67 |
ret = nvic_irq_domain_translate(domain, fwspec, &hwirq, &type); |
2d9f59f7b irqchip: nvic: Su... |
68 69 70 71 72 73 74 75 76 77 |
if (ret) return ret; for (i = 0; i < nr_irqs; i++) irq_map_generic_chip(domain, virq + i, hwirq + i); return 0; } static const struct irq_domain_ops nvic_irq_domain_ops = { |
f833f57ff irqchip: Convert ... |
78 |
.translate = nvic_irq_domain_translate, |
2d9f59f7b irqchip: nvic: Su... |
79 80 81 |
.alloc = nvic_irq_domain_alloc, .free = irq_domain_free_irqs_top, }; |
292ec0804 irqchip: Add supp... |
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
static int __init nvic_of_init(struct device_node *node, struct device_node *parent) { unsigned int clr = IRQ_NOREQUEST | IRQ_NOPROBE | IRQ_NOAUTOEN; unsigned int irqs, i, ret, numbanks; void __iomem *nvic_base; numbanks = (readl_relaxed(V7M_SCS_ICTR) & V7M_SCS_ICTR_INTLINESNUM_MASK) + 1; nvic_base = of_iomap(node, 0); if (!nvic_base) { pr_warn("unable to map nvic registers "); return -ENOMEM; } irqs = numbanks * 32; if (irqs > NVIC_MAX_IRQ) irqs = NVIC_MAX_IRQ; nvic_irq_domain = |
2d9f59f7b irqchip: nvic: Su... |
104 |
irq_domain_add_linear(node, irqs, &nvic_irq_domain_ops, NULL); |
292ec0804 irqchip: Add supp... |
105 106 107 108 109 |
if (!nvic_irq_domain) { pr_warn("Failed to allocate irq domain "); return -ENOMEM; } |
5b8aae489 irqchip: nvic: Fi... |
110 |
ret = irq_alloc_domain_generic_chips(nvic_irq_domain, 32, 1, |
292ec0804 irqchip: Add supp... |
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
"nvic_irq", handle_fasteoi_irq, clr, 0, IRQ_GC_INIT_MASK_CACHE); if (ret) { pr_warn("Failed to allocate irq chips "); irq_domain_remove(nvic_irq_domain); return ret; } for (i = 0; i < numbanks; ++i) { struct irq_chip_generic *gc; gc = irq_get_domain_generic_chip(nvic_irq_domain, 32 * i); gc->reg_base = nvic_base + 4 * i; gc->chip_types[0].regs.enable = NVIC_ISER; gc->chip_types[0].regs.disable = NVIC_ICER; gc->chip_types[0].chip.irq_mask = irq_gc_mask_disable_reg; gc->chip_types[0].chip.irq_unmask = irq_gc_unmask_enable_reg; |
8b53ec260 irqchip: nvic: Us... |
129 130 131 132 |
/* This is a no-op as end of interrupt is signaled by the * exception return sequence. */ gc->chip_types[0].chip.irq_eoi = irq_gc_noop; |
292ec0804 irqchip: Add supp... |
133 134 135 136 137 138 139 140 141 142 143 144 |
/* disable interrupts */ writel_relaxed(~0, gc->reg_base + NVIC_ICER); } /* Set priority on all interrupts */ for (i = 0; i < irqs; i += 4) writel_relaxed(0, nvic_base + NVIC_IPR + i); return 0; } IRQCHIP_DECLARE(armv7m_nvic, "arm,armv7m-nvic", nvic_of_init); |