2 * Copyright 2002 Momentum Computer
3 * Author: mdharm@momenco.com
5 * arch/mips/momentum/ocelot_c/cpci-irq.c
6 * Interrupt routines for cpci. Interrupt numbers are assigned from
7 * CPCI_IRQ_BASE to CPCI_IRQ_BASE+8 (8 interrupt sources).
9 * Note that the high-level software will need to be careful about using
10 * these interrupts. If this board is asserting a cPCI interrupt, it will
11 * also see the asserted interrupt. Care must be taken to avoid an
14 * This program is free software; you can redistribute it and/or modify it
15 * under the terms of the GNU General Public License as published by the
16 * Free Software Foundation; either version 2 of the License, or (at your
17 * option) any later version.
20 #include <linux/module.h>
21 #include <linux/interrupt.h>
22 #include <linux/irq.h>
23 #include <linux/kernel.h>
24 #include <asm/ptrace.h>
25 #include <linux/sched.h>
26 #include <linux/kernel_stat.h>
28 #include "ocelot_c_fpga.h"
30 #define CPCI_IRQ_BASE 8
32 static inline int ls1bit8(unsigned int x)
36 s = 4; if (((unsigned char)(x << 4)) == 0) s = 0; b -= s; x <<= s;
37 s = 2; if (((unsigned char)(x << 2)) == 0) s = 0; b -= s; x <<= s;
38 s = 1; if (((unsigned char)(x << 1)) == 0) s = 0; b -= s;
43 /* mask off an interrupt -- 0 is enable, 1 is disable */
44 static inline void mask_cpci_irq(unsigned int irq)
48 value = OCELOT_FPGA_READ(INTMASK);
49 value |= 1 << (irq - CPCI_IRQ_BASE);
50 OCELOT_FPGA_WRITE(value, INTMASK);
52 /* read the value back to assure that it's really been written */
53 value = OCELOT_FPGA_READ(INTMASK);
56 /* unmask an interrupt -- 0 is enable, 1 is disable */
57 static inline void unmask_cpci_irq(unsigned int irq)
61 value = OCELOT_FPGA_READ(INTMASK);
62 value &= ~(1 << (irq - CPCI_IRQ_BASE));
63 OCELOT_FPGA_WRITE(value, INTMASK);
65 /* read the value back to assure that it's really been written */
66 value = OCELOT_FPGA_READ(INTMASK);
70 * Enables the IRQ in the FPGA
72 static void enable_cpci_irq(unsigned int irq)
78 * Initialize the IRQ in the FPGA
80 static unsigned int startup_cpci_irq(unsigned int irq)
87 * Disables the IRQ in the FPGA
89 static void disable_cpci_irq(unsigned int irq)
95 * Masks and ACKs an IRQ
97 static void mask_and_ack_cpci_irq(unsigned int irq)
105 static void end_cpci_irq(unsigned int irq)
107 if (!(irq_desc[irq].status & (IRQ_DISABLED|IRQ_INPROGRESS)))
108 unmask_cpci_irq(irq);
112 * Interrupt handler for interrupts coming from the FPGA chip.
113 * It could be built in ethernet ports etc...
115 void ll_cpci_irq(struct pt_regs *regs)
117 unsigned int irq_src, irq_mask;
119 /* read the interrupt status registers */
120 irq_src = OCELOT_FPGA_READ(INTSTAT);
121 irq_mask = OCELOT_FPGA_READ(INTMASK);
123 /* mask for just the interrupts we want */
124 irq_src &= ~irq_mask;
126 do_IRQ(ls1bit8(irq_src) + CPCI_IRQ_BASE, regs);
129 #define shutdown_cpci_irq disable_cpci_irq
131 struct hw_interrupt_type cpci_irq_type = {
137 mask_and_ack_cpci_irq,
142 void cpci_irq_init(void)
146 /* Reset irq handlers pointers to NULL */
147 for (i = CPCI_IRQ_BASE; i < (CPCI_IRQ_BASE + 8); i++) {
148 irq_desc[i].status = IRQ_DISABLED;
149 irq_desc[i].action = 0;
150 irq_desc[i].depth = 2;
151 irq_desc[i].handler = &cpci_irq_type;