1 // SPDX-License-Identifier: GPL-2.0-or-later 2 /* 3 * Copyright (C) 2013 Altera Corporation 4 * Copyright (C) 2011 Tobias Klauser <tklauser@distanz.ch> 5 * Copyright (C) 2008 Thomas Chou <thomas@wytron.com.tw> 6 * 7 * based on irq.c from m68k which is: 8 * 9 * Copyright (C) 2007 Greg Ungerer <gerg@snapgear.com> 10 */ 11 12 #include <linux/init.h> 13 #include <linux/interrupt.h> 14 #include <linux/irqdomain.h> 15 #include <linux/of.h> 16 17 static u32 ienable; 18 19 asmlinkage void do_IRQ(int hwirq, struct pt_regs *regs) 20 { 21 struct pt_regs *oldregs = set_irq_regs(regs); 22 int irq; 23 24 irq_enter(); 25 irq = irq_find_mapping(NULL, hwirq); 26 generic_handle_irq(irq); 27 irq_exit(); 28 29 set_irq_regs(oldregs); 30 } 31 32 static void chip_unmask(struct irq_data *d) 33 { 34 ienable |= (1 << d->hwirq); 35 WRCTL(CTL_IENABLE, ienable); 36 } 37 38 static void chip_mask(struct irq_data *d) 39 { 40 ienable &= ~(1 << d->hwirq); 41 WRCTL(CTL_IENABLE, ienable); 42 } 43 44 static struct irq_chip m_irq_chip = { 45 .name = "NIOS2-INTC", 46 .irq_unmask = chip_unmask, 47 .irq_mask = chip_mask, 48 }; 49 50 static int irq_map(struct irq_domain *h, unsigned int virq, 51 irq_hw_number_t hw_irq_num) 52 { 53 irq_set_chip_and_handler(virq, &m_irq_chip, handle_level_irq); 54 55 return 0; 56 } 57 58 static const struct irq_domain_ops irq_ops = { 59 .map = irq_map, 60 .xlate = irq_domain_xlate_onecell, 61 }; 62 63 void __init init_IRQ(void) 64 { 65 struct irq_domain *domain; 66 struct device_node *node; 67 68 node = of_find_compatible_node(NULL, NULL, "altr,nios2-1.0"); 69 if (!node) 70 node = of_find_compatible_node(NULL, NULL, "altr,nios2-1.1"); 71 72 BUG_ON(!node); 73 74 domain = irq_domain_add_linear(node, NIOS2_CPU_NR_IRQS, &irq_ops, NULL); 75 BUG_ON(!domain); 76 77 irq_set_default_host(domain); 78 of_node_put(node); 79 /* Load the initial ienable value */ 80 ienable = RDCTL(CTL_IENABLE); 81 } 82