Linux-2.6.12-rc2
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / arch / mips / momentum / ocelot_c / cpci-irq.c
blobdea48b3ad6874f9399a145776bcd1c74a97f60bd
1 /*
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
12 * interrupt flood.
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>
27 #include <asm/io.h>
28 #include "ocelot_c_fpga.h"
30 #define CPCI_IRQ_BASE 8
32 static inline int ls1bit8(unsigned int x)
34 int b = 7, s;
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;
40 return b;
43 /* mask off an interrupt -- 0 is enable, 1 is disable */
44 static inline void mask_cpci_irq(unsigned int irq)
46 uint32_t value;
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)
59 uint32_t value;
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)
74 unmask_cpci_irq(irq);
78 * Initialize the IRQ in the FPGA
80 static unsigned int startup_cpci_irq(unsigned int irq)
82 unmask_cpci_irq(irq);
83 return 0;
87 * Disables the IRQ in the FPGA
89 static void disable_cpci_irq(unsigned int irq)
91 mask_cpci_irq(irq);
95 * Masks and ACKs an IRQ
97 static void mask_and_ack_cpci_irq(unsigned int irq)
99 mask_cpci_irq(irq);
103 * End IRQ processing
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 = {
132 "CPCI/FPGA",
133 startup_cpci_irq,
134 shutdown_cpci_irq,
135 enable_cpci_irq,
136 disable_cpci_irq,
137 mask_and_ack_cpci_irq,
138 end_cpci_irq,
139 NULL
142 void cpci_irq_init(void)
144 int i;
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;