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