1 /* irq-mb93091.c: MB93091 FPGA interrupt handling
3 * Copyright (C) 2003 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
12 #include <linux/ptrace.h>
13 #include <linux/errno.h>
14 #include <linux/signal.h>
15 #include <linux/sched.h>
16 #include <linux/ioport.h>
17 #include <linux/interrupt.h>
18 #include <linux/init.h>
19 #include <linux/irq.h>
20 #include <linux/bitops.h>
23 #include <asm/delay.h>
25 #include <asm/irc-regs.h>
27 #define __reg16(ADDR) (*(volatile unsigned short *)(ADDR))
29 #define __get_IMR() ({ __reg16(0xffc00004); })
30 #define __set_IMR(M) do { __reg16(0xffc00004) = (M); wmb(); } while(0)
31 #define __get_IFR() ({ __reg16(0xffc0000c); })
32 #define __clr_IFR(M) do { __reg16(0xffc0000c) = ~(M); wmb(); } while(0)
36 * on-motherboard FPGA PIC operations
38 static void frv_fpga_mask(struct irq_data *d)
40 uint16_t imr = __get_IMR();
42 imr |= 1 << (d->irq - IRQ_BASE_FPGA);
47 static void frv_fpga_ack(struct irq_data *d)
49 __clr_IFR(1 << (d->irq - IRQ_BASE_FPGA));
52 static void frv_fpga_mask_ack(struct irq_data *d)
54 uint16_t imr = __get_IMR();
56 imr |= 1 << (d->irq - IRQ_BASE_FPGA);
59 __clr_IFR(1 << (d->irq - IRQ_BASE_FPGA));
62 static void frv_fpga_unmask(struct irq_data *d)
64 uint16_t imr = __get_IMR();
66 imr &= ~(1 << (d->irq - IRQ_BASE_FPGA));
71 static struct irq_chip frv_fpga_pic = {
73 .irq_ack = frv_fpga_ack,
74 .irq_mask = frv_fpga_mask,
75 .irq_mask_ack = frv_fpga_mask_ack,
76 .irq_unmask = frv_fpga_unmask,
80 * FPGA PIC interrupt handler
82 static irqreturn_t fpga_interrupt(int irq, void *_mask)
84 uint16_t imr, mask = (unsigned long) _mask;
87 mask = mask & ~imr & __get_IFR();
89 /* poll all the triggered IRQs */
93 asm("scan %1,gr0,%0" : "=r"(irq) : "r"(mask));
97 generic_handle_irq(IRQ_BASE_FPGA + irq);
104 * define an interrupt action for each FPGA PIC output
105 * - use dev_id to indicate the FPGA PIC input to output mappings
107 static struct irqaction fpga_irq[4] = {
109 .handler = fpga_interrupt,
110 .flags = IRQF_DISABLED | IRQF_SHARED,
112 .dev_id = (void *) 0x0028UL,
115 .handler = fpga_interrupt,
116 .flags = IRQF_DISABLED | IRQF_SHARED,
118 .dev_id = (void *) 0x0050UL,
121 .handler = fpga_interrupt,
122 .flags = IRQF_DISABLED | IRQF_SHARED,
124 .dev_id = (void *) 0x1c00UL,
127 .handler = fpga_interrupt,
128 .flags = IRQF_DISABLED | IRQF_SHARED,
130 .dev_id = (void *) 0x6386UL,
135 * initialise the motherboard FPGA's PIC
137 void __init fpga_init(void)
141 /* all PIC inputs are all set to be low-level driven, apart from the
142 * NMI button (15) which is fixed at falling-edge
147 for (irq = IRQ_BASE_FPGA + 1; irq <= IRQ_BASE_FPGA + 14; irq++)
148 irq_set_chip_and_handler(irq, &frv_fpga_pic, handle_level_irq);
150 irq_set_chip_and_handler(IRQ_FPGA_NMI, &frv_fpga_pic, handle_edge_irq);
152 /* the FPGA drives the first four external IRQ inputs on the CPU PIC */
153 setup_irq(IRQ_CPU_EXTERNAL0, &fpga_irq[0]);
154 setup_irq(IRQ_CPU_EXTERNAL1, &fpga_irq[1]);
155 setup_irq(IRQ_CPU_EXTERNAL2, &fpga_irq[2]);
156 setup_irq(IRQ_CPU_EXTERNAL3, &fpga_irq[3]);