Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * arch/sh/boards/superh/microdev/irq.c |
| 3 | * |
| 4 | * Copyright (C) 2003 Sean McGoogan (Sean.McGoogan@superh.com) |
| 5 | * |
| 6 | * SuperH SH4-202 MicroDev board support. |
| 7 | * |
| 8 | * May be copied or modified under the terms of the GNU General Public |
| 9 | * License. See linux/COPYING for more information. |
| 10 | */ |
| 11 | |
| 12 | #include <linux/config.h> |
| 13 | #include <linux/init.h> |
| 14 | #include <linux/irq.h> |
| 15 | |
| 16 | #include <asm/system.h> |
| 17 | #include <asm/io.h> |
| 18 | #include <asm/mach/irq.h> |
| 19 | |
| 20 | #define NUM_EXTERNAL_IRQS 16 /* IRL0 .. IRL15 */ |
| 21 | |
| 22 | |
| 23 | static const struct { |
| 24 | unsigned char fpgaIrq; |
| 25 | unsigned char mapped; |
| 26 | const char *name; |
| 27 | } fpgaIrqTable[NUM_EXTERNAL_IRQS] = { |
| 28 | { 0, 0, "unused" }, /* IRQ #0 IRL=15 0x200 */ |
| 29 | { MICRODEV_FPGA_IRQ_KEYBOARD, 1, "keyboard" }, /* IRQ #1 IRL=14 0x220 */ |
| 30 | { MICRODEV_FPGA_IRQ_SERIAL1, 1, "Serial #1"}, /* IRQ #2 IRL=13 0x240 */ |
| 31 | { MICRODEV_FPGA_IRQ_ETHERNET, 1, "Ethernet" }, /* IRQ #3 IRL=12 0x260 */ |
| 32 | { MICRODEV_FPGA_IRQ_SERIAL2, 0, "Serial #2"}, /* IRQ #4 IRL=11 0x280 */ |
| 33 | { 0, 0, "unused" }, /* IRQ #5 IRL=10 0x2a0 */ |
| 34 | { 0, 0, "unused" }, /* IRQ #6 IRL=9 0x2c0 */ |
| 35 | { MICRODEV_FPGA_IRQ_USB_HC, 1, "USB" }, /* IRQ #7 IRL=8 0x2e0 */ |
| 36 | { MICRODEV_IRQ_PCI_INTA, 1, "PCI INTA" }, /* IRQ #8 IRL=7 0x300 */ |
| 37 | { MICRODEV_IRQ_PCI_INTB, 1, "PCI INTB" }, /* IRQ #9 IRL=6 0x320 */ |
| 38 | { MICRODEV_IRQ_PCI_INTC, 1, "PCI INTC" }, /* IRQ #10 IRL=5 0x340 */ |
| 39 | { MICRODEV_IRQ_PCI_INTD, 1, "PCI INTD" }, /* IRQ #11 IRL=4 0x360 */ |
| 40 | { MICRODEV_FPGA_IRQ_MOUSE, 1, "mouse" }, /* IRQ #12 IRL=3 0x380 */ |
| 41 | { MICRODEV_FPGA_IRQ_IDE2, 1, "IDE #2" }, /* IRQ #13 IRL=2 0x3a0 */ |
| 42 | { MICRODEV_FPGA_IRQ_IDE1, 1, "IDE #1" }, /* IRQ #14 IRL=1 0x3c0 */ |
| 43 | { 0, 0, "unused" }, /* IRQ #15 IRL=0 0x3e0 */ |
| 44 | }; |
| 45 | |
| 46 | #if (MICRODEV_LINUX_IRQ_KEYBOARD != 1) |
| 47 | # error Inconsistancy in defining the IRQ# for Keyboard! |
| 48 | #endif |
| 49 | |
| 50 | #if (MICRODEV_LINUX_IRQ_ETHERNET != 3) |
| 51 | # error Inconsistancy in defining the IRQ# for Ethernet! |
| 52 | #endif |
| 53 | |
| 54 | #if (MICRODEV_LINUX_IRQ_USB_HC != 7) |
| 55 | # error Inconsistancy in defining the IRQ# for USB! |
| 56 | #endif |
| 57 | |
| 58 | #if (MICRODEV_LINUX_IRQ_MOUSE != 12) |
| 59 | # error Inconsistancy in defining the IRQ# for PS/2 Mouse! |
| 60 | #endif |
| 61 | |
| 62 | #if (MICRODEV_LINUX_IRQ_IDE2 != 13) |
| 63 | # error Inconsistancy in defining the IRQ# for secondary IDE! |
| 64 | #endif |
| 65 | |
| 66 | #if (MICRODEV_LINUX_IRQ_IDE1 != 14) |
| 67 | # error Inconsistancy in defining the IRQ# for primary IDE! |
| 68 | #endif |
| 69 | |
| 70 | static void enable_microdev_irq(unsigned int irq); |
| 71 | static void disable_microdev_irq(unsigned int irq); |
| 72 | |
| 73 | /* shutdown is same as "disable" */ |
| 74 | #define shutdown_microdev_irq disable_microdev_irq |
| 75 | |
| 76 | static void mask_and_ack_microdev(unsigned int); |
| 77 | static void end_microdev_irq(unsigned int irq); |
| 78 | |
| 79 | static unsigned int startup_microdev_irq(unsigned int irq) |
| 80 | { |
| 81 | enable_microdev_irq(irq); |
| 82 | return 0; /* never anything pending */ |
| 83 | } |
| 84 | |
| 85 | static struct hw_interrupt_type microdev_irq_type = { |
Thomas Gleixner | 08d0fd0 | 2005-09-10 00:26:42 -0700 | [diff] [blame^] | 86 | .typename = "MicroDev-IRQ", |
| 87 | .startup = startup_microdev_irq, |
| 88 | .shutdown = shutdown_microdev_irq, |
| 89 | .enable = enable_microdev_irq, |
| 90 | .disable = disable_microdev_irq, |
| 91 | .ack = mask_and_ack_microdev, |
| 92 | .end = end_microdev_irq |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | }; |
| 94 | |
| 95 | static void disable_microdev_irq(unsigned int irq) |
| 96 | { |
| 97 | unsigned int flags; |
| 98 | unsigned int fpgaIrq; |
| 99 | |
| 100 | if (irq >= NUM_EXTERNAL_IRQS) return; |
| 101 | if (!fpgaIrqTable[irq].mapped) return; |
| 102 | |
| 103 | fpgaIrq = fpgaIrqTable[irq].fpgaIrq; |
| 104 | |
| 105 | /* disable interrupts */ |
| 106 | local_irq_save(flags); |
| 107 | |
| 108 | /* disable interupts on the FPGA INTC register */ |
| 109 | ctrl_outl(MICRODEV_FPGA_INTC_MASK(fpgaIrq), MICRODEV_FPGA_INTDSB_REG); |
| 110 | |
| 111 | /* restore interrupts */ |
| 112 | local_irq_restore(flags); |
| 113 | } |
| 114 | |
| 115 | static void enable_microdev_irq(unsigned int irq) |
| 116 | { |
| 117 | unsigned long priorityReg, priorities, pri; |
| 118 | unsigned int flags; |
| 119 | unsigned int fpgaIrq; |
| 120 | |
| 121 | |
| 122 | if (irq >= NUM_EXTERNAL_IRQS) return; |
| 123 | if (!fpgaIrqTable[irq].mapped) return; |
| 124 | |
| 125 | pri = 15 - irq; |
| 126 | |
| 127 | fpgaIrq = fpgaIrqTable[irq].fpgaIrq; |
| 128 | priorityReg = MICRODEV_FPGA_INTPRI_REG(fpgaIrq); |
| 129 | |
| 130 | /* disable interrupts */ |
| 131 | local_irq_save(flags); |
| 132 | |
| 133 | /* set priority for the interrupt */ |
| 134 | priorities = ctrl_inl(priorityReg); |
| 135 | priorities &= ~MICRODEV_FPGA_INTPRI_MASK(fpgaIrq); |
| 136 | priorities |= MICRODEV_FPGA_INTPRI_LEVEL(fpgaIrq, pri); |
| 137 | ctrl_outl(priorities, priorityReg); |
| 138 | |
| 139 | /* enable interupts on the FPGA INTC register */ |
| 140 | ctrl_outl(MICRODEV_FPGA_INTC_MASK(fpgaIrq), MICRODEV_FPGA_INTENB_REG); |
| 141 | |
| 142 | /* restore interrupts */ |
| 143 | local_irq_restore(flags); |
| 144 | } |
| 145 | |
| 146 | /* This functions sets the desired irq handler to be a MicroDev type */ |
| 147 | static void __init make_microdev_irq(unsigned int irq) |
| 148 | { |
| 149 | disable_irq_nosync(irq); |
| 150 | irq_desc[irq].handler = µdev_irq_type; |
| 151 | disable_microdev_irq(irq); |
| 152 | } |
| 153 | |
| 154 | static void mask_and_ack_microdev(unsigned int irq) |
| 155 | { |
| 156 | disable_microdev_irq(irq); |
| 157 | } |
| 158 | |
| 159 | static void end_microdev_irq(unsigned int irq) |
| 160 | { |
| 161 | if (!(irq_desc[irq].status & (IRQ_DISABLED|IRQ_INPROGRESS))) |
| 162 | { |
| 163 | enable_microdev_irq(irq); |
| 164 | } |
| 165 | } |
| 166 | |
| 167 | extern void __init init_microdev_irq(void) |
| 168 | { |
| 169 | int i; |
| 170 | |
| 171 | /* disable interupts on the FPGA INTC register */ |
| 172 | ctrl_outl(~0ul, MICRODEV_FPGA_INTDSB_REG); |
| 173 | |
| 174 | for (i = 0; i < NUM_EXTERNAL_IRQS; i++) |
| 175 | { |
| 176 | make_microdev_irq(i); |
| 177 | } |
| 178 | } |
| 179 | |
| 180 | extern void microdev_print_fpga_intc_status(void) |
| 181 | { |
| 182 | volatile unsigned int * const intenb = (unsigned int*)MICRODEV_FPGA_INTENB_REG; |
| 183 | volatile unsigned int * const intdsb = (unsigned int*)MICRODEV_FPGA_INTDSB_REG; |
| 184 | volatile unsigned int * const intpria = (unsigned int*)MICRODEV_FPGA_INTPRI_REG(0); |
| 185 | volatile unsigned int * const intprib = (unsigned int*)MICRODEV_FPGA_INTPRI_REG(8); |
| 186 | volatile unsigned int * const intpric = (unsigned int*)MICRODEV_FPGA_INTPRI_REG(16); |
| 187 | volatile unsigned int * const intprid = (unsigned int*)MICRODEV_FPGA_INTPRI_REG(24); |
| 188 | volatile unsigned int * const intsrc = (unsigned int*)MICRODEV_FPGA_INTSRC_REG; |
| 189 | volatile unsigned int * const intreq = (unsigned int*)MICRODEV_FPGA_INTREQ_REG; |
| 190 | |
| 191 | printk("-------------------------- microdev_print_fpga_intc_status() ------------------\n"); |
| 192 | printk("FPGA_INTENB = 0x%08x\n", *intenb); |
| 193 | printk("FPGA_INTDSB = 0x%08x\n", *intdsb); |
| 194 | printk("FPGA_INTSRC = 0x%08x\n", *intsrc); |
| 195 | printk("FPGA_INTREQ = 0x%08x\n", *intreq); |
| 196 | printk("FPGA_INTPRI[3..0] = %08x:%08x:%08x:%08x\n", *intprid, *intpric, *intprib, *intpria); |
| 197 | printk("-------------------------------------------------------------------------------\n"); |
| 198 | } |
| 199 | |
| 200 | |