1
2
3
4
5
6
7
8
9
10
11
12#include <linux/init.h>
13#include <linux/irq.h>
14#include <linux/interrupt.h>
15#include <asm/io.h>
16#include <mach/microdev.h>
17
18#define NUM_EXTERNAL_IRQS 16
19
20static const struct {
21 unsigned char fpgaIrq;
22 unsigned char mapped;
23 const char *name;
24} fpgaIrqTable[NUM_EXTERNAL_IRQS] = {
25 { 0, 0, "unused" },
26 { MICRODEV_FPGA_IRQ_KEYBOARD, 1, "keyboard" },
27 { MICRODEV_FPGA_IRQ_SERIAL1, 1, "Serial #1"},
28 { MICRODEV_FPGA_IRQ_ETHERNET, 1, "Ethernet" },
29 { MICRODEV_FPGA_IRQ_SERIAL2, 0, "Serial #2"},
30 { 0, 0, "unused" },
31 { 0, 0, "unused" },
32 { MICRODEV_FPGA_IRQ_USB_HC, 1, "USB" },
33 { MICRODEV_IRQ_PCI_INTA, 1, "PCI INTA" },
34 { MICRODEV_IRQ_PCI_INTB, 1, "PCI INTB" },
35 { MICRODEV_IRQ_PCI_INTC, 1, "PCI INTC" },
36 { MICRODEV_IRQ_PCI_INTD, 1, "PCI INTD" },
37 { MICRODEV_FPGA_IRQ_MOUSE, 1, "mouse" },
38 { MICRODEV_FPGA_IRQ_IDE2, 1, "IDE #2" },
39 { MICRODEV_FPGA_IRQ_IDE1, 1, "IDE #1" },
40 { 0, 0, "unused" },
41};
42
43#if (MICRODEV_LINUX_IRQ_KEYBOARD != 1)
44# error Inconsistancy in defining the IRQ# for Keyboard!
45#endif
46
47#if (MICRODEV_LINUX_IRQ_ETHERNET != 3)
48# error Inconsistancy in defining the IRQ# for Ethernet!
49#endif
50
51#if (MICRODEV_LINUX_IRQ_USB_HC != 7)
52# error Inconsistancy in defining the IRQ# for USB!
53#endif
54
55#if (MICRODEV_LINUX_IRQ_MOUSE != 12)
56# error Inconsistancy in defining the IRQ# for PS/2 Mouse!
57#endif
58
59#if (MICRODEV_LINUX_IRQ_IDE2 != 13)
60# error Inconsistancy in defining the IRQ# for secondary IDE!
61#endif
62
63#if (MICRODEV_LINUX_IRQ_IDE1 != 14)
64# error Inconsistancy in defining the IRQ# for primary IDE!
65#endif
66
67static void disable_microdev_irq(struct irq_data *data)
68{
69 unsigned int irq = data->irq;
70 unsigned int fpgaIrq;
71
72 if (irq >= NUM_EXTERNAL_IRQS)
73 return;
74 if (!fpgaIrqTable[irq].mapped)
75 return;
76
77 fpgaIrq = fpgaIrqTable[irq].fpgaIrq;
78
79
80 __raw_writel(MICRODEV_FPGA_INTC_MASK(fpgaIrq), MICRODEV_FPGA_INTDSB_REG);
81}
82
83static void enable_microdev_irq(struct irq_data *data)
84{
85 unsigned int irq = data->irq;
86 unsigned long priorityReg, priorities, pri;
87 unsigned int fpgaIrq;
88
89 if (unlikely(irq >= NUM_EXTERNAL_IRQS))
90 return;
91 if (unlikely(!fpgaIrqTable[irq].mapped))
92 return;
93
94 pri = 15 - irq;
95
96 fpgaIrq = fpgaIrqTable[irq].fpgaIrq;
97 priorityReg = MICRODEV_FPGA_INTPRI_REG(fpgaIrq);
98
99
100 priorities = __raw_readl(priorityReg);
101 priorities &= ~MICRODEV_FPGA_INTPRI_MASK(fpgaIrq);
102 priorities |= MICRODEV_FPGA_INTPRI_LEVEL(fpgaIrq, pri);
103 __raw_writel(priorities, priorityReg);
104
105
106 __raw_writel(MICRODEV_FPGA_INTC_MASK(fpgaIrq), MICRODEV_FPGA_INTENB_REG);
107}
108
109static struct irq_chip microdev_irq_type = {
110 .name = "MicroDev-IRQ",
111 .irq_unmask = enable_microdev_irq,
112 .irq_mask = disable_microdev_irq,
113};
114
115
116static void __init make_microdev_irq(unsigned int irq)
117{
118 disable_irq_nosync(irq);
119 irq_set_chip_and_handler(irq, µdev_irq_type, handle_level_irq);
120 disable_microdev_irq(irq_get_irq_data(irq));
121}
122
123extern void __init init_microdev_irq(void)
124{
125 int i;
126
127
128 __raw_writel(~0ul, MICRODEV_FPGA_INTDSB_REG);
129
130 for (i = 0; i < NUM_EXTERNAL_IRQS; i++)
131 make_microdev_irq(i);
132}
133
134extern void microdev_print_fpga_intc_status(void)
135{
136 volatile unsigned int * const intenb = (unsigned int*)MICRODEV_FPGA_INTENB_REG;
137 volatile unsigned int * const intdsb = (unsigned int*)MICRODEV_FPGA_INTDSB_REG;
138 volatile unsigned int * const intpria = (unsigned int*)MICRODEV_FPGA_INTPRI_REG(0);
139 volatile unsigned int * const intprib = (unsigned int*)MICRODEV_FPGA_INTPRI_REG(8);
140 volatile unsigned int * const intpric = (unsigned int*)MICRODEV_FPGA_INTPRI_REG(16);
141 volatile unsigned int * const intprid = (unsigned int*)MICRODEV_FPGA_INTPRI_REG(24);
142 volatile unsigned int * const intsrc = (unsigned int*)MICRODEV_FPGA_INTSRC_REG;
143 volatile unsigned int * const intreq = (unsigned int*)MICRODEV_FPGA_INTREQ_REG;
144
145 printk("-------------------------- microdev_print_fpga_intc_status() ------------------\n");
146 printk("FPGA_INTENB = 0x%08x\n", *intenb);
147 printk("FPGA_INTDSB = 0x%08x\n", *intdsb);
148 printk("FPGA_INTSRC = 0x%08x\n", *intsrc);
149 printk("FPGA_INTREQ = 0x%08x\n", *intreq);
150 printk("FPGA_INTPRI[3..0] = %08x:%08x:%08x:%08x\n", *intprid, *intpric, *intprib, *intpria);
151 printk("-------------------------------------------------------------------------------\n");
152}
153