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> |
Russell King | fced80c | 2008-09-06 12:10:45 +0100 | [diff] [blame] | 11 | #include <linux/io.h> |
Bartosz Golaszewski | 74b0eac | 2019-02-14 15:51:57 +0100 | [diff] [blame] | 12 | #include <linux/irqdomain.h> |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 13 | |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 14 | #include <mach/hardware.h> |
Sudhakar Rajashekhara | 9e16469 | 2009-04-14 07:53:02 -0500 | [diff] [blame] | 15 | #include <mach/cputype.h> |
Mark A. Greer | 673dd36 | 2009-04-15 12:40:00 -0700 | [diff] [blame] | 16 | #include <mach/common.h> |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 17 | #include <asm/mach/irq.h> |
Bartosz Golaszewski | d006459 | 2019-02-14 15:51:58 +0100 | [diff] [blame] | 18 | #include <asm/exception.h> |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 19 | |
Bartosz Golaszewski | 544ca0b | 2019-02-14 15:52:03 +0100 | [diff] [blame] | 20 | #include "irqs.h" |
| 21 | |
Bartosz Golaszewski | 919da6f1 | 2019-02-14 15:52:07 +0100 | [diff] [blame] | 22 | #define DAVINCI_AINTC_FIQ_REG0 0x00 |
| 23 | #define DAVINCI_AINTC_FIQ_REG1 0x04 |
| 24 | #define DAVINCI_AINTC_IRQ_REG0 0x08 |
| 25 | #define DAVINCI_AINTC_IRQ_REG1 0x0c |
| 26 | #define DAVINCI_AINTC_IRQ_IRQENTRY 0x14 |
| 27 | #define DAVINCI_AINTC_IRQ_ENT_REG0 0x18 |
| 28 | #define DAVINCI_AINTC_IRQ_ENT_REG1 0x1c |
| 29 | #define DAVINCI_AINTC_IRQ_INCTL_REG 0x20 |
| 30 | #define DAVINCI_AINTC_IRQ_EABASE_REG 0x24 |
| 31 | #define DAVINCI_AINTC_IRQ_INTPRI0_REG 0x30 |
| 32 | #define DAVINCI_AINTC_IRQ_INTPRI7_REG 0x4c |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 33 | |
Bartosz Golaszewski | 2b6a2e7 | 2019-02-14 15:52:06 +0100 | [diff] [blame] | 34 | static void __iomem *davinci_aintc_base; |
| 35 | static struct irq_domain *davinci_aintc_irq_domain; |
Bartosz Golaszewski | 74b0eac | 2019-02-14 15:51:57 +0100 | [diff] [blame] | 36 | |
Bartosz Golaszewski | 2b6a2e7 | 2019-02-14 15:52:06 +0100 | [diff] [blame] | 37 | static inline void davinci_aintc_writel(unsigned long value, int offset) |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 38 | { |
Bartosz Golaszewski | f412384 | 2019-02-14 15:52:08 +0100 | [diff] [blame^] | 39 | writel_relaxed(value, davinci_aintc_base + offset); |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 40 | } |
| 41 | |
Bartosz Golaszewski | 2b6a2e7 | 2019-02-14 15:52:06 +0100 | [diff] [blame] | 42 | static inline unsigned long davinci_aintc_readl(int offset) |
Bartosz Golaszewski | d006459 | 2019-02-14 15:51:58 +0100 | [diff] [blame] | 43 | { |
Bartosz Golaszewski | 2b6a2e7 | 2019-02-14 15:52:06 +0100 | [diff] [blame] | 44 | return readl_relaxed(davinci_aintc_base + offset); |
Bartosz Golaszewski | d006459 | 2019-02-14 15:51:58 +0100 | [diff] [blame] | 45 | } |
| 46 | |
Thomas Gleixner | aac4dd1 | 2011-04-15 11:19:57 +0200 | [diff] [blame] | 47 | static __init void |
Bartosz Golaszewski | 2b6a2e7 | 2019-02-14 15:52:06 +0100 | [diff] [blame] | 48 | davinci_aintc_setup_gc(void __iomem *base, |
| 49 | unsigned int irq_start, unsigned int num) |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 50 | { |
Thomas Gleixner | aac4dd1 | 2011-04-15 11:19:57 +0200 | [diff] [blame] | 51 | struct irq_chip_generic *gc; |
| 52 | struct irq_chip_type *ct; |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 53 | |
Bartosz Golaszewski | 2b6a2e7 | 2019-02-14 15:52:06 +0100 | [diff] [blame] | 54 | gc = irq_get_domain_generic_chip(davinci_aintc_irq_domain, irq_start); |
Bartosz Golaszewski | 74b0eac | 2019-02-14 15:51:57 +0100 | [diff] [blame] | 55 | gc->reg_base = base; |
| 56 | gc->irq_base = irq_start; |
Todd Poynor | 33e1e5e | 2011-07-16 22:39:35 -0700 | [diff] [blame] | 57 | |
Thomas Gleixner | aac4dd1 | 2011-04-15 11:19:57 +0200 | [diff] [blame] | 58 | ct = gc->chip_types; |
Simon Guinot | 659fb32 | 2011-07-06 12:41:31 -0400 | [diff] [blame] | 59 | ct->chip.irq_ack = irq_gc_ack_set_bit; |
Thomas Gleixner | aac4dd1 | 2011-04-15 11:19:57 +0200 | [diff] [blame] | 60 | ct->chip.irq_mask = irq_gc_mask_clr_bit; |
| 61 | ct->chip.irq_unmask = irq_gc_mask_set_bit; |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 62 | |
Bartosz Golaszewski | 2b6a2e7 | 2019-02-14 15:52:06 +0100 | [diff] [blame] | 63 | ct->regs.ack = DAVINCI_AINTC_IRQ_REG0; |
| 64 | ct->regs.mask = DAVINCI_AINTC_IRQ_ENT_REG0; |
Thomas Gleixner | aac4dd1 | 2011-04-15 11:19:57 +0200 | [diff] [blame] | 65 | irq_setup_generic_chip(gc, IRQ_MSK(num), IRQ_GC_INIT_MASK_CACHE, |
| 66 | IRQ_NOREQUEST | IRQ_NOPROBE, 0); |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 67 | } |
| 68 | |
Bartosz Golaszewski | d006459 | 2019-02-14 15:51:58 +0100 | [diff] [blame] | 69 | static asmlinkage void __exception_irq_entry |
Bartosz Golaszewski | 2b6a2e7 | 2019-02-14 15:52:06 +0100 | [diff] [blame] | 70 | davinci_aintc_handle_irq(struct pt_regs *regs) |
Bartosz Golaszewski | d006459 | 2019-02-14 15:51:58 +0100 | [diff] [blame] | 71 | { |
Bartosz Golaszewski | 2b6a2e7 | 2019-02-14 15:52:06 +0100 | [diff] [blame] | 72 | int irqnr = davinci_aintc_readl(DAVINCI_AINTC_IRQ_IRQENTRY); |
Bartosz Golaszewski | d006459 | 2019-02-14 15:51:58 +0100 | [diff] [blame] | 73 | |
| 74 | /* |
| 75 | * Use the formula for entry vector index generation from section |
| 76 | * 8.3.3 of the manual. |
| 77 | */ |
| 78 | irqnr >>= 2; |
| 79 | irqnr -= 1; |
| 80 | |
Bartosz Golaszewski | 2b6a2e7 | 2019-02-14 15:52:06 +0100 | [diff] [blame] | 81 | handle_domain_irq(davinci_aintc_irq_domain, irqnr, regs); |
Bartosz Golaszewski | d006459 | 2019-02-14 15:51:58 +0100 | [diff] [blame] | 82 | } |
| 83 | |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 84 | /* ARM Interrupt Controller Initialization */ |
Bartosz Golaszewski | 2b6a2e7 | 2019-02-14 15:52:06 +0100 | [diff] [blame] | 85 | void __init davinci_aintc_init(void) |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 86 | { |
Thomas Gleixner | aac4dd1 | 2011-04-15 11:19:57 +0200 | [diff] [blame] | 87 | unsigned i, j; |
Mark A. Greer | 673dd36 | 2009-04-15 12:40:00 -0700 | [diff] [blame] | 88 | const u8 *davinci_def_priorities = davinci_soc_info.intc_irq_prios; |
Bartosz Golaszewski | 74b0eac | 2019-02-14 15:51:57 +0100 | [diff] [blame] | 89 | int ret, irq_base; |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 90 | |
Bartosz Golaszewski | 2b6a2e7 | 2019-02-14 15:52:06 +0100 | [diff] [blame] | 91 | davinci_aintc_base = ioremap(davinci_soc_info.intc_base, SZ_4K); |
| 92 | if (WARN_ON(!davinci_aintc_base)) |
Cyril Chemparathy | bd80894 | 2010-05-07 17:06:37 -0400 | [diff] [blame] | 93 | return; |
| 94 | |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 95 | /* Clear all interrupt requests */ |
Bartosz Golaszewski | 2b6a2e7 | 2019-02-14 15:52:06 +0100 | [diff] [blame] | 96 | davinci_aintc_writel(~0x0, DAVINCI_AINTC_FIQ_REG0); |
| 97 | davinci_aintc_writel(~0x0, DAVINCI_AINTC_FIQ_REG1); |
| 98 | davinci_aintc_writel(~0x0, DAVINCI_AINTC_IRQ_REG0); |
| 99 | davinci_aintc_writel(~0x0, DAVINCI_AINTC_IRQ_REG1); |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 100 | |
| 101 | /* Disable all interrupts */ |
Bartosz Golaszewski | 2b6a2e7 | 2019-02-14 15:52:06 +0100 | [diff] [blame] | 102 | davinci_aintc_writel(0x0, DAVINCI_AINTC_IRQ_ENT_REG0); |
| 103 | davinci_aintc_writel(0x0, DAVINCI_AINTC_IRQ_ENT_REG1); |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 104 | |
| 105 | /* Interrupts disabled immediately, IRQ entry reflects all */ |
Bartosz Golaszewski | 2b6a2e7 | 2019-02-14 15:52:06 +0100 | [diff] [blame] | 106 | davinci_aintc_writel(0x0, DAVINCI_AINTC_IRQ_INCTL_REG); |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 107 | |
| 108 | /* we don't use the hardware vector table, just its entry addresses */ |
Bartosz Golaszewski | 2b6a2e7 | 2019-02-14 15:52:06 +0100 | [diff] [blame] | 109 | davinci_aintc_writel(0, DAVINCI_AINTC_IRQ_EABASE_REG); |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 110 | |
| 111 | /* Clear all interrupt requests */ |
Bartosz Golaszewski | 2b6a2e7 | 2019-02-14 15:52:06 +0100 | [diff] [blame] | 112 | davinci_aintc_writel(~0x0, DAVINCI_AINTC_FIQ_REG0); |
| 113 | davinci_aintc_writel(~0x0, DAVINCI_AINTC_FIQ_REG1); |
| 114 | davinci_aintc_writel(~0x0, DAVINCI_AINTC_IRQ_REG0); |
| 115 | davinci_aintc_writel(~0x0, DAVINCI_AINTC_IRQ_REG1); |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 116 | |
Bartosz Golaszewski | 2b6a2e7 | 2019-02-14 15:52:06 +0100 | [diff] [blame] | 117 | for (i = DAVINCI_AINTC_IRQ_INTPRI0_REG; |
| 118 | i <= DAVINCI_AINTC_IRQ_INTPRI7_REG; i += 4) { |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 119 | u32 pri; |
| 120 | |
Sudhakar Rajashekhara | 9e16469 | 2009-04-14 07:53:02 -0500 | [diff] [blame] | 121 | for (j = 0, pri = 0; j < 32; j += 4, davinci_def_priorities++) |
| 122 | pri |= (*davinci_def_priorities & 0x07) << j; |
Bartosz Golaszewski | 2b6a2e7 | 2019-02-14 15:52:06 +0100 | [diff] [blame] | 123 | davinci_aintc_writel(pri, i); |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 124 | } |
| 125 | |
Bartosz Golaszewski | 74b0eac | 2019-02-14 15:51:57 +0100 | [diff] [blame] | 126 | irq_base = irq_alloc_descs(-1, 0, davinci_soc_info.intc_irq_num, 0); |
| 127 | if (WARN_ON(irq_base < 0)) |
| 128 | return; |
| 129 | |
Bartosz Golaszewski | 2b6a2e7 | 2019-02-14 15:52:06 +0100 | [diff] [blame] | 130 | davinci_aintc_irq_domain = irq_domain_add_legacy(NULL, |
Bartosz Golaszewski | 74b0eac | 2019-02-14 15:51:57 +0100 | [diff] [blame] | 131 | davinci_soc_info.intc_irq_num, |
| 132 | irq_base, 0, &irq_domain_simple_ops, |
| 133 | NULL); |
Bartosz Golaszewski | 2b6a2e7 | 2019-02-14 15:52:06 +0100 | [diff] [blame] | 134 | if (WARN_ON(!davinci_aintc_irq_domain)) |
Bartosz Golaszewski | 74b0eac | 2019-02-14 15:51:57 +0100 | [diff] [blame] | 135 | return; |
| 136 | |
Bartosz Golaszewski | 2b6a2e7 | 2019-02-14 15:52:06 +0100 | [diff] [blame] | 137 | ret = irq_alloc_domain_generic_chips(davinci_aintc_irq_domain, 32, 1, |
| 138 | "AINTC", handle_edge_irq, |
| 139 | IRQ_NOREQUEST | IRQ_NOPROBE, 0, 0); |
Bartosz Golaszewski | 74b0eac | 2019-02-14 15:51:57 +0100 | [diff] [blame] | 140 | if (WARN_ON(ret)) |
| 141 | return; |
| 142 | |
Bartosz Golaszewski | 2b6a2e7 | 2019-02-14 15:52:06 +0100 | [diff] [blame] | 143 | for (i = 0, j = 0; i < davinci_soc_info.intc_irq_num; |
| 144 | i += 32, j += 0x04) |
| 145 | davinci_aintc_setup_gc(davinci_aintc_base + j, |
| 146 | irq_base + i, 32); |
Thomas Gleixner | aac4dd1 | 2011-04-15 11:19:57 +0200 | [diff] [blame] | 147 | |
Bartosz Golaszewski | a98ca73 | 2019-02-14 15:52:01 +0100 | [diff] [blame] | 148 | irq_set_handler(DAVINCI_INTC_IRQ(IRQ_TINT1_TINT34), handle_level_irq); |
Bartosz Golaszewski | 2b6a2e7 | 2019-02-14 15:52:06 +0100 | [diff] [blame] | 149 | set_handle_irq(davinci_aintc_handle_irq); |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 150 | } |