2 * arch/sh/boards/superh/microdev/irq.c
4 * Copyright (C) 2003 Sean McGoogan (Sean.McGoogan@superh.com)
6 * SuperH SH4-202 MicroDev board support.
8 * May be copied or modified under the terms of the GNU General Public
9 * License. See linux/COPYING for more information.
12 #include <linux/init.h>
13 #include <linux/irq.h>
14 #include <linux/interrupt.h>
15 #include <asm/system.h>
17 #include <mach/microdev.h>
19 #define NUM_EXTERNAL_IRQS 16 /* IRL0 .. IRL15 */
22 unsigned char fpgaIrq;
25 } fpgaIrqTable[NUM_EXTERNAL_IRQS] = {
26 { 0, 0, "unused" }, /* IRQ #0 IRL=15 0x200 */
27 { MICRODEV_FPGA_IRQ_KEYBOARD, 1, "keyboard" }, /* IRQ #1 IRL=14 0x220 */
28 { MICRODEV_FPGA_IRQ_SERIAL1, 1, "Serial #1"}, /* IRQ #2 IRL=13 0x240 */
29 { MICRODEV_FPGA_IRQ_ETHERNET, 1, "Ethernet" }, /* IRQ #3 IRL=12 0x260 */
30 { MICRODEV_FPGA_IRQ_SERIAL2, 0, "Serial #2"}, /* IRQ #4 IRL=11 0x280 */
31 { 0, 0, "unused" }, /* IRQ #5 IRL=10 0x2a0 */
32 { 0, 0, "unused" }, /* IRQ #6 IRL=9 0x2c0 */
33 { MICRODEV_FPGA_IRQ_USB_HC, 1, "USB" }, /* IRQ #7 IRL=8 0x2e0 */
34 { MICRODEV_IRQ_PCI_INTA, 1, "PCI INTA" }, /* IRQ #8 IRL=7 0x300 */
35 { MICRODEV_IRQ_PCI_INTB, 1, "PCI INTB" }, /* IRQ #9 IRL=6 0x320 */
36 { MICRODEV_IRQ_PCI_INTC, 1, "PCI INTC" }, /* IRQ #10 IRL=5 0x340 */
37 { MICRODEV_IRQ_PCI_INTD, 1, "PCI INTD" }, /* IRQ #11 IRL=4 0x360 */
38 { MICRODEV_FPGA_IRQ_MOUSE, 1, "mouse" }, /* IRQ #12 IRL=3 0x380 */
39 { MICRODEV_FPGA_IRQ_IDE2, 1, "IDE #2" }, /* IRQ #13 IRL=2 0x3a0 */
40 { MICRODEV_FPGA_IRQ_IDE1, 1, "IDE #1" }, /* IRQ #14 IRL=1 0x3c0 */
41 { 0, 0, "unused" }, /* IRQ #15 IRL=0 0x3e0 */
44 #if (MICRODEV_LINUX_IRQ_KEYBOARD != 1)
45 # error Inconsistancy in defining the IRQ# for Keyboard!
48 #if (MICRODEV_LINUX_IRQ_ETHERNET != 3)
49 # error Inconsistancy in defining the IRQ# for Ethernet!
52 #if (MICRODEV_LINUX_IRQ_USB_HC != 7)
53 # error Inconsistancy in defining the IRQ# for USB!
56 #if (MICRODEV_LINUX_IRQ_MOUSE != 12)
57 # error Inconsistancy in defining the IRQ# for PS/2 Mouse!
60 #if (MICRODEV_LINUX_IRQ_IDE2 != 13)
61 # error Inconsistancy in defining the IRQ# for secondary IDE!
64 #if (MICRODEV_LINUX_IRQ_IDE1 != 14)
65 # error Inconsistancy in defining the IRQ# for primary IDE!
68 static void enable_microdev_irq(unsigned int irq);
69 static void disable_microdev_irq(unsigned int irq);
70 static void mask_and_ack_microdev(unsigned int);
72 static struct irq_chip microdev_irq_type = {
73 .name = "MicroDev-IRQ",
74 .unmask = enable_microdev_irq,
75 .mask = disable_microdev_irq,
76 .ack = mask_and_ack_microdev,
79 static void disable_microdev_irq(unsigned int irq)
83 if (irq >= NUM_EXTERNAL_IRQS)
85 if (!fpgaIrqTable[irq].mapped)
88 fpgaIrq = fpgaIrqTable[irq].fpgaIrq;
90 /* disable interrupts on the FPGA INTC register */
91 ctrl_outl(MICRODEV_FPGA_INTC_MASK(fpgaIrq), MICRODEV_FPGA_INTDSB_REG);
94 static void enable_microdev_irq(unsigned int irq)
96 unsigned long priorityReg, priorities, pri;
99 if (unlikely(irq >= NUM_EXTERNAL_IRQS))
101 if (unlikely(!fpgaIrqTable[irq].mapped))
106 fpgaIrq = fpgaIrqTable[irq].fpgaIrq;
107 priorityReg = MICRODEV_FPGA_INTPRI_REG(fpgaIrq);
109 /* set priority for the interrupt */
110 priorities = ctrl_inl(priorityReg);
111 priorities &= ~MICRODEV_FPGA_INTPRI_MASK(fpgaIrq);
112 priorities |= MICRODEV_FPGA_INTPRI_LEVEL(fpgaIrq, pri);
113 ctrl_outl(priorities, priorityReg);
115 /* enable interrupts on the FPGA INTC register */
116 ctrl_outl(MICRODEV_FPGA_INTC_MASK(fpgaIrq), MICRODEV_FPGA_INTENB_REG);
119 /* This function sets the desired irq handler to be a MicroDev type */
120 static void __init make_microdev_irq(unsigned int irq)
122 disable_irq_nosync(irq);
123 set_irq_chip_and_handler(irq, µdev_irq_type, handle_level_irq);
124 disable_microdev_irq(irq);
127 static void mask_and_ack_microdev(unsigned int irq)
129 disable_microdev_irq(irq);
132 extern void __init init_microdev_irq(void)
136 /* disable interrupts on the FPGA INTC register */
137 ctrl_outl(~0ul, MICRODEV_FPGA_INTDSB_REG);
139 for (i = 0; i < NUM_EXTERNAL_IRQS; i++)
140 make_microdev_irq(i);
143 extern void microdev_print_fpga_intc_status(void)
145 volatile unsigned int * const intenb = (unsigned int*)MICRODEV_FPGA_INTENB_REG;
146 volatile unsigned int * const intdsb = (unsigned int*)MICRODEV_FPGA_INTDSB_REG;
147 volatile unsigned int * const intpria = (unsigned int*)MICRODEV_FPGA_INTPRI_REG(0);
148 volatile unsigned int * const intprib = (unsigned int*)MICRODEV_FPGA_INTPRI_REG(8);
149 volatile unsigned int * const intpric = (unsigned int*)MICRODEV_FPGA_INTPRI_REG(16);
150 volatile unsigned int * const intprid = (unsigned int*)MICRODEV_FPGA_INTPRI_REG(24);
151 volatile unsigned int * const intsrc = (unsigned int*)MICRODEV_FPGA_INTSRC_REG;
152 volatile unsigned int * const intreq = (unsigned int*)MICRODEV_FPGA_INTREQ_REG;
154 printk("-------------------------- microdev_print_fpga_intc_status() ------------------\n");
155 printk("FPGA_INTENB = 0x%08x\n", *intenb);
156 printk("FPGA_INTDSB = 0x%08x\n", *intdsb);
157 printk("FPGA_INTSRC = 0x%08x\n", *intsrc);
158 printk("FPGA_INTREQ = 0x%08x\n", *intreq);
159 printk("FPGA_INTPRI[3..0] = %08x:%08x:%08x:%08x\n", *intprid, *intpric, *intprib, *intpria);
160 printk("-------------------------------------------------------------------------------\n");