Bartosz Golaszewski | 2d242aa | 2019-02-14 15:52:04 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
| 2 | // |
| 3 | // Copyright (C) 2006, 2019 Texas Instruments. |
| 4 | // |
| 5 | // Interrupt handler for DaVinci boards. |
| 6 | |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 7 | #include <linux/kernel.h> |
| 8 | #include <linux/init.h> |
| 9 | #include <linux/interrupt.h> |
| 10 | #include <linux/irq.h> |
Bartosz Golaszewski | 06a2871 | 2019-02-14 15:52:11 +0100 | [diff] [blame] | 11 | #include <linux/irqchip/irq-davinci-aintc.h> |
Russell King | fced80c | 2008-09-06 12:10:45 +0100 | [diff] [blame] | 12 | #include <linux/io.h> |
Bartosz Golaszewski | 74b0eac | 2019-02-14 15:51:57 +0100 | [diff] [blame] | 13 | #include <linux/irqdomain.h> |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 14 | |
Bartosz Golaszewski | d006459 | 2019-02-14 15:51:58 +0100 | [diff] [blame] | 15 | #include <asm/exception.h> |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 16 | |
Bartosz Golaszewski | 919da6f1 | 2019-02-14 15:52:07 +0100 | [diff] [blame] | 17 | #define DAVINCI_AINTC_FIQ_REG0 0x00 |
| 18 | #define DAVINCI_AINTC_FIQ_REG1 0x04 |
| 19 | #define DAVINCI_AINTC_IRQ_REG0 0x08 |
| 20 | #define DAVINCI_AINTC_IRQ_REG1 0x0c |
| 21 | #define DAVINCI_AINTC_IRQ_IRQENTRY 0x14 |
| 22 | #define DAVINCI_AINTC_IRQ_ENT_REG0 0x18 |
| 23 | #define DAVINCI_AINTC_IRQ_ENT_REG1 0x1c |
| 24 | #define DAVINCI_AINTC_IRQ_INCTL_REG 0x20 |
| 25 | #define DAVINCI_AINTC_IRQ_EABASE_REG 0x24 |
| 26 | #define DAVINCI_AINTC_IRQ_INTPRI0_REG 0x30 |
| 27 | #define DAVINCI_AINTC_IRQ_INTPRI7_REG 0x4c |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 28 | |
Bartosz Golaszewski | 2b6a2e7 | 2019-02-14 15:52:06 +0100 | [diff] [blame] | 29 | static void __iomem *davinci_aintc_base; |
| 30 | static struct irq_domain *davinci_aintc_irq_domain; |
Bartosz Golaszewski | 74b0eac | 2019-02-14 15:51:57 +0100 | [diff] [blame] | 31 | |
Bartosz Golaszewski | 2b6a2e7 | 2019-02-14 15:52:06 +0100 | [diff] [blame] | 32 | static inline void davinci_aintc_writel(unsigned long value, int offset) |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 33 | { |
Bartosz Golaszewski | f412384 | 2019-02-14 15:52:08 +0100 | [diff] [blame] | 34 | writel_relaxed(value, davinci_aintc_base + offset); |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 35 | } |
| 36 | |
Bartosz Golaszewski | 2b6a2e7 | 2019-02-14 15:52:06 +0100 | [diff] [blame] | 37 | static inline unsigned long davinci_aintc_readl(int offset) |
Bartosz Golaszewski | d006459 | 2019-02-14 15:51:58 +0100 | [diff] [blame] | 38 | { |
Bartosz Golaszewski | 2b6a2e7 | 2019-02-14 15:52:06 +0100 | [diff] [blame] | 39 | return readl_relaxed(davinci_aintc_base + offset); |
Bartosz Golaszewski | d006459 | 2019-02-14 15:51:58 +0100 | [diff] [blame] | 40 | } |
| 41 | |
Thomas Gleixner | aac4dd1 | 2011-04-15 11:19:57 +0200 | [diff] [blame] | 42 | static __init void |
Bartosz Golaszewski | 2b6a2e7 | 2019-02-14 15:52:06 +0100 | [diff] [blame] | 43 | davinci_aintc_setup_gc(void __iomem *base, |
| 44 | unsigned int irq_start, unsigned int num) |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 45 | { |
Thomas Gleixner | aac4dd1 | 2011-04-15 11:19:57 +0200 | [diff] [blame] | 46 | struct irq_chip_generic *gc; |
| 47 | struct irq_chip_type *ct; |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 48 | |
Bartosz Golaszewski | 2b6a2e7 | 2019-02-14 15:52:06 +0100 | [diff] [blame] | 49 | gc = irq_get_domain_generic_chip(davinci_aintc_irq_domain, irq_start); |
Bartosz Golaszewski | 74b0eac | 2019-02-14 15:51:57 +0100 | [diff] [blame] | 50 | gc->reg_base = base; |
| 51 | gc->irq_base = irq_start; |
Todd Poynor | 33e1e5e | 2011-07-16 22:39:35 -0700 | [diff] [blame] | 52 | |
Thomas Gleixner | aac4dd1 | 2011-04-15 11:19:57 +0200 | [diff] [blame] | 53 | ct = gc->chip_types; |
Simon Guinot | 659fb32 | 2011-07-06 12:41:31 -0400 | [diff] [blame] | 54 | ct->chip.irq_ack = irq_gc_ack_set_bit; |
Thomas Gleixner | aac4dd1 | 2011-04-15 11:19:57 +0200 | [diff] [blame] | 55 | ct->chip.irq_mask = irq_gc_mask_clr_bit; |
| 56 | ct->chip.irq_unmask = irq_gc_mask_set_bit; |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 57 | |
Bartosz Golaszewski | 2b6a2e7 | 2019-02-14 15:52:06 +0100 | [diff] [blame] | 58 | ct->regs.ack = DAVINCI_AINTC_IRQ_REG0; |
| 59 | ct->regs.mask = DAVINCI_AINTC_IRQ_ENT_REG0; |
Thomas Gleixner | aac4dd1 | 2011-04-15 11:19:57 +0200 | [diff] [blame] | 60 | irq_setup_generic_chip(gc, IRQ_MSK(num), IRQ_GC_INIT_MASK_CACHE, |
| 61 | IRQ_NOREQUEST | IRQ_NOPROBE, 0); |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 62 | } |
| 63 | |
Bartosz Golaszewski | d006459 | 2019-02-14 15:51:58 +0100 | [diff] [blame] | 64 | static asmlinkage void __exception_irq_entry |
Bartosz Golaszewski | 2b6a2e7 | 2019-02-14 15:52:06 +0100 | [diff] [blame] | 65 | davinci_aintc_handle_irq(struct pt_regs *regs) |
Bartosz Golaszewski | d006459 | 2019-02-14 15:51:58 +0100 | [diff] [blame] | 66 | { |
Bartosz Golaszewski | 2b6a2e7 | 2019-02-14 15:52:06 +0100 | [diff] [blame] | 67 | int irqnr = davinci_aintc_readl(DAVINCI_AINTC_IRQ_IRQENTRY); |
Bartosz Golaszewski | d006459 | 2019-02-14 15:51:58 +0100 | [diff] [blame] | 68 | |
| 69 | /* |
| 70 | * Use the formula for entry vector index generation from section |
| 71 | * 8.3.3 of the manual. |
| 72 | */ |
| 73 | irqnr >>= 2; |
| 74 | irqnr -= 1; |
| 75 | |
Mark Rutland | 0953fb2 | 2021-10-20 20:23:09 +0100 | [diff] [blame] | 76 | generic_handle_domain_irq(davinci_aintc_irq_domain, irqnr); |
Bartosz Golaszewski | d006459 | 2019-02-14 15:51:58 +0100 | [diff] [blame] | 77 | } |
| 78 | |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 79 | /* ARM Interrupt Controller Initialization */ |
Bartosz Golaszewski | 06a2871 | 2019-02-14 15:52:11 +0100 | [diff] [blame] | 80 | void __init davinci_aintc_init(const struct davinci_aintc_config *config) |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 81 | { |
Bartosz Golaszewski | 06a2871 | 2019-02-14 15:52:11 +0100 | [diff] [blame] | 82 | unsigned int irq_off, reg_off, prio, shift; |
Bartosz Golaszewski | 882bed7 | 2019-02-14 15:52:13 +0100 | [diff] [blame] | 83 | void __iomem *req; |
Bartosz Golaszewski | 74b0eac | 2019-02-14 15:51:57 +0100 | [diff] [blame] | 84 | int ret, irq_base; |
Bartosz Golaszewski | 06a2871 | 2019-02-14 15:52:11 +0100 | [diff] [blame] | 85 | const u8 *prios; |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 86 | |
Bartosz Golaszewski | 882bed7 | 2019-02-14 15:52:13 +0100 | [diff] [blame] | 87 | req = request_mem_region(config->reg.start, |
| 88 | resource_size(&config->reg), |
| 89 | "davinci-cp-intc"); |
| 90 | if (!req) { |
| 91 | pr_err("%s: register range busy\n", __func__); |
| 92 | return; |
| 93 | } |
| 94 | |
Bartosz Golaszewski | 06a2871 | 2019-02-14 15:52:11 +0100 | [diff] [blame] | 95 | davinci_aintc_base = ioremap(config->reg.start, |
| 96 | resource_size(&config->reg)); |
Bartosz Golaszewski | a6c0bba | 2019-02-14 15:52:12 +0100 | [diff] [blame] | 97 | if (!davinci_aintc_base) { |
| 98 | pr_err("%s: unable to ioremap register range\n", __func__); |
Cyril Chemparathy | bd80894 | 2010-05-07 17:06:37 -0400 | [diff] [blame] | 99 | return; |
Bartosz Golaszewski | a6c0bba | 2019-02-14 15:52:12 +0100 | [diff] [blame] | 100 | } |
Cyril Chemparathy | bd80894 | 2010-05-07 17:06:37 -0400 | [diff] [blame] | 101 | |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 102 | /* Clear all interrupt requests */ |
Bartosz Golaszewski | 2b6a2e7 | 2019-02-14 15:52:06 +0100 | [diff] [blame] | 103 | davinci_aintc_writel(~0x0, DAVINCI_AINTC_FIQ_REG0); |
| 104 | davinci_aintc_writel(~0x0, DAVINCI_AINTC_FIQ_REG1); |
| 105 | davinci_aintc_writel(~0x0, DAVINCI_AINTC_IRQ_REG0); |
| 106 | davinci_aintc_writel(~0x0, DAVINCI_AINTC_IRQ_REG1); |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 107 | |
| 108 | /* Disable all interrupts */ |
Bartosz Golaszewski | 2b6a2e7 | 2019-02-14 15:52:06 +0100 | [diff] [blame] | 109 | davinci_aintc_writel(0x0, DAVINCI_AINTC_IRQ_ENT_REG0); |
| 110 | davinci_aintc_writel(0x0, DAVINCI_AINTC_IRQ_ENT_REG1); |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 111 | |
| 112 | /* Interrupts disabled immediately, IRQ entry reflects all */ |
Bartosz Golaszewski | 2b6a2e7 | 2019-02-14 15:52:06 +0100 | [diff] [blame] | 113 | davinci_aintc_writel(0x0, DAVINCI_AINTC_IRQ_INCTL_REG); |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 114 | |
| 115 | /* we don't use the hardware vector table, just its entry addresses */ |
Bartosz Golaszewski | 2b6a2e7 | 2019-02-14 15:52:06 +0100 | [diff] [blame] | 116 | davinci_aintc_writel(0, DAVINCI_AINTC_IRQ_EABASE_REG); |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 117 | |
| 118 | /* Clear all interrupt requests */ |
Bartosz Golaszewski | 2b6a2e7 | 2019-02-14 15:52:06 +0100 | [diff] [blame] | 119 | davinci_aintc_writel(~0x0, DAVINCI_AINTC_FIQ_REG0); |
| 120 | davinci_aintc_writel(~0x0, DAVINCI_AINTC_FIQ_REG1); |
| 121 | davinci_aintc_writel(~0x0, DAVINCI_AINTC_IRQ_REG0); |
| 122 | davinci_aintc_writel(~0x0, DAVINCI_AINTC_IRQ_REG1); |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 123 | |
Bartosz Golaszewski | 06a2871 | 2019-02-14 15:52:11 +0100 | [diff] [blame] | 124 | prios = config->prios; |
| 125 | for (reg_off = DAVINCI_AINTC_IRQ_INTPRI0_REG; |
| 126 | reg_off <= DAVINCI_AINTC_IRQ_INTPRI7_REG; reg_off += 4) { |
| 127 | for (shift = 0, prio = 0; shift < 32; shift += 4, prios++) |
| 128 | prio |= (*prios & 0x07) << shift; |
| 129 | davinci_aintc_writel(prio, reg_off); |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 130 | } |
| 131 | |
Bartosz Golaszewski | 06a2871 | 2019-02-14 15:52:11 +0100 | [diff] [blame] | 132 | irq_base = irq_alloc_descs(-1, 0, config->num_irqs, 0); |
Bartosz Golaszewski | a6c0bba | 2019-02-14 15:52:12 +0100 | [diff] [blame] | 133 | if (irq_base < 0) { |
| 134 | pr_err("%s: unable to allocate interrupt descriptors: %d\n", |
| 135 | __func__, irq_base); |
Bartosz Golaszewski | 74b0eac | 2019-02-14 15:51:57 +0100 | [diff] [blame] | 136 | return; |
Bartosz Golaszewski | a6c0bba | 2019-02-14 15:52:12 +0100 | [diff] [blame] | 137 | } |
Bartosz Golaszewski | 74b0eac | 2019-02-14 15:51:57 +0100 | [diff] [blame] | 138 | |
Bartosz Golaszewski | 2b6a2e7 | 2019-02-14 15:52:06 +0100 | [diff] [blame] | 139 | davinci_aintc_irq_domain = irq_domain_add_legacy(NULL, |
Bartosz Golaszewski | 06a2871 | 2019-02-14 15:52:11 +0100 | [diff] [blame] | 140 | config->num_irqs, irq_base, 0, |
| 141 | &irq_domain_simple_ops, NULL); |
Bartosz Golaszewski | a6c0bba | 2019-02-14 15:52:12 +0100 | [diff] [blame] | 142 | if (!davinci_aintc_irq_domain) { |
| 143 | pr_err("%s: unable to create interrupt domain\n", __func__); |
Bartosz Golaszewski | 74b0eac | 2019-02-14 15:51:57 +0100 | [diff] [blame] | 144 | return; |
Bartosz Golaszewski | a6c0bba | 2019-02-14 15:52:12 +0100 | [diff] [blame] | 145 | } |
Bartosz Golaszewski | 74b0eac | 2019-02-14 15:51:57 +0100 | [diff] [blame] | 146 | |
Bartosz Golaszewski | 2b6a2e7 | 2019-02-14 15:52:06 +0100 | [diff] [blame] | 147 | ret = irq_alloc_domain_generic_chips(davinci_aintc_irq_domain, 32, 1, |
| 148 | "AINTC", handle_edge_irq, |
| 149 | IRQ_NOREQUEST | IRQ_NOPROBE, 0, 0); |
Bartosz Golaszewski | a6c0bba | 2019-02-14 15:52:12 +0100 | [diff] [blame] | 150 | if (ret) { |
| 151 | pr_err("%s: unable to allocate generic irq chips for domain\n", |
| 152 | __func__); |
Bartosz Golaszewski | 74b0eac | 2019-02-14 15:51:57 +0100 | [diff] [blame] | 153 | return; |
Bartosz Golaszewski | a6c0bba | 2019-02-14 15:52:12 +0100 | [diff] [blame] | 154 | } |
Bartosz Golaszewski | 74b0eac | 2019-02-14 15:51:57 +0100 | [diff] [blame] | 155 | |
Bartosz Golaszewski | 06a2871 | 2019-02-14 15:52:11 +0100 | [diff] [blame] | 156 | for (irq_off = 0, reg_off = 0; |
| 157 | irq_off < config->num_irqs; |
| 158 | irq_off += 32, reg_off += 0x04) |
| 159 | davinci_aintc_setup_gc(davinci_aintc_base + reg_off, |
| 160 | irq_base + irq_off, 32); |
Thomas Gleixner | aac4dd1 | 2011-04-15 11:19:57 +0200 | [diff] [blame] | 161 | |
Bartosz Golaszewski | 2b6a2e7 | 2019-02-14 15:52:06 +0100 | [diff] [blame] | 162 | set_handle_irq(davinci_aintc_handle_irq); |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 163 | } |