Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Interrupt handler for DaVinci boards. |
| 3 | * |
| 4 | * Copyright (C) 2006 Texas Instruments. |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 19 | * |
| 20 | */ |
| 21 | #include <linux/kernel.h> |
| 22 | #include <linux/init.h> |
| 23 | #include <linux/interrupt.h> |
| 24 | #include <linux/irq.h> |
Russell King | fced80c | 2008-09-06 12:10:45 +0100 | [diff] [blame] | 25 | #include <linux/io.h> |
Bartosz Golaszewski | 74b0eac | 2019-02-14 15:51:57 +0100 | [diff] [blame] | 26 | #include <linux/irqdomain.h> |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 27 | |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 28 | #include <mach/hardware.h> |
Sudhakar Rajashekhara | 9e16469 | 2009-04-14 07:53:02 -0500 | [diff] [blame] | 29 | #include <mach/cputype.h> |
Mark A. Greer | 673dd36 | 2009-04-15 12:40:00 -0700 | [diff] [blame] | 30 | #include <mach/common.h> |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 31 | #include <asm/mach/irq.h> |
Bartosz Golaszewski | d006459 | 2019-02-14 15:51:58 +0100 | [diff] [blame] | 32 | #include <asm/exception.h> |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 33 | |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 34 | #define FIQ_REG0_OFFSET 0x0000 |
| 35 | #define FIQ_REG1_OFFSET 0x0004 |
| 36 | #define IRQ_REG0_OFFSET 0x0008 |
| 37 | #define IRQ_REG1_OFFSET 0x000C |
Bartosz Golaszewski | d006459 | 2019-02-14 15:51:58 +0100 | [diff] [blame] | 38 | #define IRQ_IRQENTRY_OFFSET 0x0014 |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 39 | #define IRQ_ENT_REG0_OFFSET 0x0018 |
| 40 | #define IRQ_ENT_REG1_OFFSET 0x001C |
| 41 | #define IRQ_INCTL_REG_OFFSET 0x0020 |
| 42 | #define IRQ_EABASE_REG_OFFSET 0x0024 |
| 43 | #define IRQ_INTPRI0_REG_OFFSET 0x0030 |
| 44 | #define IRQ_INTPRI7_REG_OFFSET 0x004C |
| 45 | |
Bartosz Golaszewski | fb74684 | 2019-02-14 15:52:00 +0100 | [diff] [blame] | 46 | static void __iomem *davinci_intc_base; |
Bartosz Golaszewski | 74b0eac | 2019-02-14 15:51:57 +0100 | [diff] [blame] | 47 | static struct irq_domain *davinci_irq_domain; |
| 48 | |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 49 | static inline void davinci_irq_writel(unsigned long value, int offset) |
| 50 | { |
Mark A. Greer | 673dd36 | 2009-04-15 12:40:00 -0700 | [diff] [blame] | 51 | __raw_writel(value, davinci_intc_base + offset); |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 52 | } |
| 53 | |
Bartosz Golaszewski | d006459 | 2019-02-14 15:51:58 +0100 | [diff] [blame] | 54 | static inline unsigned long davinci_irq_readl(int offset) |
| 55 | { |
| 56 | return readl_relaxed(davinci_intc_base + offset); |
| 57 | } |
| 58 | |
Thomas Gleixner | aac4dd1 | 2011-04-15 11:19:57 +0200 | [diff] [blame] | 59 | static __init void |
Bartosz Golaszewski | 74b0eac | 2019-02-14 15:51:57 +0100 | [diff] [blame] | 60 | davinci_irq_setup_gc(void __iomem *base, |
| 61 | unsigned int irq_start, unsigned int num) |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 62 | { |
Thomas Gleixner | aac4dd1 | 2011-04-15 11:19:57 +0200 | [diff] [blame] | 63 | struct irq_chip_generic *gc; |
| 64 | struct irq_chip_type *ct; |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 65 | |
Bartosz Golaszewski | 74b0eac | 2019-02-14 15:51:57 +0100 | [diff] [blame] | 66 | gc = irq_get_domain_generic_chip(davinci_irq_domain, irq_start); |
| 67 | gc->reg_base = base; |
| 68 | gc->irq_base = irq_start; |
Todd Poynor | 33e1e5e | 2011-07-16 22:39:35 -0700 | [diff] [blame] | 69 | |
Thomas Gleixner | aac4dd1 | 2011-04-15 11:19:57 +0200 | [diff] [blame] | 70 | ct = gc->chip_types; |
Simon Guinot | 659fb32 | 2011-07-06 12:41:31 -0400 | [diff] [blame] | 71 | ct->chip.irq_ack = irq_gc_ack_set_bit; |
Thomas Gleixner | aac4dd1 | 2011-04-15 11:19:57 +0200 | [diff] [blame] | 72 | ct->chip.irq_mask = irq_gc_mask_clr_bit; |
| 73 | ct->chip.irq_unmask = irq_gc_mask_set_bit; |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 74 | |
Thomas Gleixner | aac4dd1 | 2011-04-15 11:19:57 +0200 | [diff] [blame] | 75 | ct->regs.ack = IRQ_REG0_OFFSET; |
| 76 | ct->regs.mask = IRQ_ENT_REG0_OFFSET; |
| 77 | irq_setup_generic_chip(gc, IRQ_MSK(num), IRQ_GC_INIT_MASK_CACHE, |
| 78 | IRQ_NOREQUEST | IRQ_NOPROBE, 0); |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 79 | } |
| 80 | |
Bartosz Golaszewski | d006459 | 2019-02-14 15:51:58 +0100 | [diff] [blame] | 81 | static asmlinkage void __exception_irq_entry |
| 82 | davinci_handle_irq(struct pt_regs *regs) |
| 83 | { |
| 84 | int irqnr = davinci_irq_readl(IRQ_IRQENTRY_OFFSET); |
| 85 | |
| 86 | /* |
| 87 | * Use the formula for entry vector index generation from section |
| 88 | * 8.3.3 of the manual. |
| 89 | */ |
| 90 | irqnr >>= 2; |
| 91 | irqnr -= 1; |
| 92 | |
| 93 | handle_domain_irq(davinci_irq_domain, irqnr, regs); |
| 94 | } |
| 95 | |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 96 | /* ARM Interrupt Controller Initialization */ |
| 97 | void __init davinci_irq_init(void) |
| 98 | { |
Thomas Gleixner | aac4dd1 | 2011-04-15 11:19:57 +0200 | [diff] [blame] | 99 | unsigned i, j; |
Mark A. Greer | 673dd36 | 2009-04-15 12:40:00 -0700 | [diff] [blame] | 100 | const u8 *davinci_def_priorities = davinci_soc_info.intc_irq_prios; |
Bartosz Golaszewski | 74b0eac | 2019-02-14 15:51:57 +0100 | [diff] [blame] | 101 | int ret, irq_base; |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 102 | |
Cyril Chemparathy | bd80894 | 2010-05-07 17:06:37 -0400 | [diff] [blame] | 103 | davinci_intc_base = ioremap(davinci_soc_info.intc_base, SZ_4K); |
| 104 | if (WARN_ON(!davinci_intc_base)) |
| 105 | return; |
| 106 | |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 107 | /* Clear all interrupt requests */ |
| 108 | davinci_irq_writel(~0x0, FIQ_REG0_OFFSET); |
| 109 | davinci_irq_writel(~0x0, FIQ_REG1_OFFSET); |
| 110 | davinci_irq_writel(~0x0, IRQ_REG0_OFFSET); |
| 111 | davinci_irq_writel(~0x0, IRQ_REG1_OFFSET); |
| 112 | |
| 113 | /* Disable all interrupts */ |
| 114 | davinci_irq_writel(0x0, IRQ_ENT_REG0_OFFSET); |
| 115 | davinci_irq_writel(0x0, IRQ_ENT_REG1_OFFSET); |
| 116 | |
| 117 | /* Interrupts disabled immediately, IRQ entry reflects all */ |
| 118 | davinci_irq_writel(0x0, IRQ_INCTL_REG_OFFSET); |
| 119 | |
| 120 | /* we don't use the hardware vector table, just its entry addresses */ |
| 121 | davinci_irq_writel(0, IRQ_EABASE_REG_OFFSET); |
| 122 | |
| 123 | /* Clear all interrupt requests */ |
| 124 | davinci_irq_writel(~0x0, FIQ_REG0_OFFSET); |
| 125 | davinci_irq_writel(~0x0, FIQ_REG1_OFFSET); |
| 126 | davinci_irq_writel(~0x0, IRQ_REG0_OFFSET); |
| 127 | davinci_irq_writel(~0x0, IRQ_REG1_OFFSET); |
| 128 | |
| 129 | for (i = IRQ_INTPRI0_REG_OFFSET; i <= IRQ_INTPRI7_REG_OFFSET; i += 4) { |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 130 | u32 pri; |
| 131 | |
Sudhakar Rajashekhara | 9e16469 | 2009-04-14 07:53:02 -0500 | [diff] [blame] | 132 | for (j = 0, pri = 0; j < 32; j += 4, davinci_def_priorities++) |
| 133 | pri |= (*davinci_def_priorities & 0x07) << j; |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 134 | davinci_irq_writel(pri, i); |
| 135 | } |
| 136 | |
Bartosz Golaszewski | 74b0eac | 2019-02-14 15:51:57 +0100 | [diff] [blame] | 137 | irq_base = irq_alloc_descs(-1, 0, davinci_soc_info.intc_irq_num, 0); |
| 138 | if (WARN_ON(irq_base < 0)) |
| 139 | return; |
| 140 | |
| 141 | davinci_irq_domain = irq_domain_add_legacy(NULL, |
| 142 | davinci_soc_info.intc_irq_num, |
| 143 | irq_base, 0, &irq_domain_simple_ops, |
| 144 | NULL); |
| 145 | if (WARN_ON(!davinci_irq_domain)) |
| 146 | return; |
| 147 | |
| 148 | ret = irq_alloc_domain_generic_chips(davinci_irq_domain, 32, 1, |
| 149 | "AINTC", handle_edge_irq, |
| 150 | IRQ_NOREQUEST | IRQ_NOPROBE, 0, 0); |
| 151 | if (WARN_ON(ret)) |
| 152 | return; |
| 153 | |
Thomas Gleixner | aac4dd1 | 2011-04-15 11:19:57 +0200 | [diff] [blame] | 154 | for (i = 0, j = 0; i < davinci_soc_info.intc_irq_num; i += 32, j += 0x04) |
Bartosz Golaszewski | 74b0eac | 2019-02-14 15:51:57 +0100 | [diff] [blame] | 155 | davinci_irq_setup_gc(davinci_intc_base + j, irq_base + i, 32); |
Thomas Gleixner | aac4dd1 | 2011-04-15 11:19:57 +0200 | [diff] [blame] | 156 | |
Bartosz Golaszewski | a98ca73 | 2019-02-14 15:52:01 +0100 | [diff] [blame^] | 157 | irq_set_handler(DAVINCI_INTC_IRQ(IRQ_TINT1_TINT34), handle_level_irq); |
Bartosz Golaszewski | d006459 | 2019-02-14 15:51:58 +0100 | [diff] [blame] | 158 | set_handle_irq(davinci_handle_irq); |
Kevin Hilman | 7c6337e | 2007-04-30 19:37:19 +0100 | [diff] [blame] | 159 | } |