| 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 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | #include <linux/init.h> | 
|  | 13 | #include <linux/irq.h> | 
| Paul Mundt | 8b19a7c | 2007-06-04 10:50:42 +0900 | [diff] [blame] | 14 | #include <linux/interrupt.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | #include <asm/io.h> | 
| Paul Mundt | 7639a45 | 2008-10-20 13:02:48 +0900 | [diff] [blame] | 16 | #include <mach/microdev.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 |  | 
|  | 18 | #define NUM_EXTERNAL_IRQS 16	/* IRL0 .. IRL15 */ | 
|  | 19 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | static const struct { | 
|  | 21 | unsigned char fpgaIrq; | 
|  | 22 | unsigned char mapped; | 
|  | 23 | const char *name; | 
|  | 24 | } fpgaIrqTable[NUM_EXTERNAL_IRQS] = { | 
|  | 25 | { 0,				0,	"unused"   },		/* IRQ #0	IRL=15	0x200  */ | 
|  | 26 | { MICRODEV_FPGA_IRQ_KEYBOARD,	1,	"keyboard" },		/* IRQ #1	IRL=14	0x220  */ | 
|  | 27 | { MICRODEV_FPGA_IRQ_SERIAL1,	1,	"Serial #1"},		/* IRQ #2	IRL=13	0x240  */ | 
|  | 28 | { MICRODEV_FPGA_IRQ_ETHERNET,	1,	"Ethernet" },		/* IRQ #3	IRL=12	0x260  */ | 
|  | 29 | { MICRODEV_FPGA_IRQ_SERIAL2,	0,	"Serial #2"},		/* IRQ #4	IRL=11	0x280  */ | 
|  | 30 | { 0,				0,	"unused"   },		/* IRQ #5	IRL=10	0x2a0  */ | 
|  | 31 | { 0,				0,	"unused"   },		/* IRQ #6	IRL=9	0x2c0  */ | 
|  | 32 | { MICRODEV_FPGA_IRQ_USB_HC,	1,	"USB"	   },		/* IRQ #7	IRL=8	0x2e0  */ | 
|  | 33 | { MICRODEV_IRQ_PCI_INTA,	1,	"PCI INTA" },		/* IRQ #8	IRL=7	0x300  */ | 
|  | 34 | { MICRODEV_IRQ_PCI_INTB,	1,	"PCI INTB" },		/* IRQ #9	IRL=6	0x320  */ | 
|  | 35 | { MICRODEV_IRQ_PCI_INTC,	1,	"PCI INTC" },		/* IRQ #10	IRL=5	0x340  */ | 
|  | 36 | { MICRODEV_IRQ_PCI_INTD,	1,	"PCI INTD" },		/* IRQ #11	IRL=4	0x360  */ | 
|  | 37 | { MICRODEV_FPGA_IRQ_MOUSE,	1,	"mouse"    },		/* IRQ #12	IRL=3	0x380  */ | 
|  | 38 | { MICRODEV_FPGA_IRQ_IDE2,	1,	"IDE #2"   },		/* IRQ #13	IRL=2	0x3a0  */ | 
|  | 39 | { MICRODEV_FPGA_IRQ_IDE1,	1,	"IDE #1"   },		/* IRQ #14	IRL=1	0x3c0  */ | 
|  | 40 | { 0,				0,	"unused"   },		/* IRQ #15	IRL=0	0x3e0  */ | 
|  | 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 |  | 
| Paul Mundt | d613883 | 2010-10-27 14:54:10 +0900 | [diff] [blame] | 67 | static void disable_microdev_irq(struct irq_data *data) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | { | 
| Paul Mundt | d613883 | 2010-10-27 14:54:10 +0900 | [diff] [blame] | 69 | unsigned int irq = data->irq; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | unsigned int fpgaIrq; | 
|  | 71 |  | 
| Paul Mundt | 8599cf0 | 2006-09-27 18:03:34 +0900 | [diff] [blame] | 72 | if (irq >= NUM_EXTERNAL_IRQS) | 
|  | 73 | return; | 
|  | 74 | if (!fpgaIrqTable[irq].mapped) | 
|  | 75 | return; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 |  | 
|  | 77 | fpgaIrq = fpgaIrqTable[irq].fpgaIrq; | 
|  | 78 |  | 
| Simon Arlott | e868d61 | 2007-05-14 08:15:10 +0900 | [diff] [blame] | 79 | /* disable interrupts on the FPGA INTC register */ | 
| Paul Mundt | 9d56dd3 | 2010-01-26 12:58:40 +0900 | [diff] [blame] | 80 | __raw_writel(MICRODEV_FPGA_INTC_MASK(fpgaIrq), MICRODEV_FPGA_INTDSB_REG); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | } | 
|  | 82 |  | 
| Paul Mundt | d613883 | 2010-10-27 14:54:10 +0900 | [diff] [blame] | 83 | static void enable_microdev_irq(struct irq_data *data) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | { | 
| Paul Mundt | d613883 | 2010-10-27 14:54:10 +0900 | [diff] [blame] | 85 | unsigned int irq = data->irq; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | unsigned long priorityReg, priorities, pri; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | unsigned int fpgaIrq; | 
|  | 88 |  | 
| Paul Mundt | 8599cf0 | 2006-09-27 18:03:34 +0900 | [diff] [blame] | 89 | if (unlikely(irq >= NUM_EXTERNAL_IRQS)) | 
|  | 90 | return; | 
|  | 91 | if (unlikely(!fpgaIrqTable[irq].mapped)) | 
|  | 92 | return; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 |  | 
|  | 94 | pri = 15 - irq; | 
|  | 95 |  | 
|  | 96 | fpgaIrq = fpgaIrqTable[irq].fpgaIrq; | 
|  | 97 | priorityReg = MICRODEV_FPGA_INTPRI_REG(fpgaIrq); | 
|  | 98 |  | 
| Paul Mundt | 8599cf0 | 2006-09-27 18:03:34 +0900 | [diff] [blame] | 99 | /* set priority for the interrupt */ | 
| Paul Mundt | 9d56dd3 | 2010-01-26 12:58:40 +0900 | [diff] [blame] | 100 | priorities = __raw_readl(priorityReg); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | priorities &= ~MICRODEV_FPGA_INTPRI_MASK(fpgaIrq); | 
|  | 102 | priorities |= MICRODEV_FPGA_INTPRI_LEVEL(fpgaIrq, pri); | 
| Paul Mundt | 9d56dd3 | 2010-01-26 12:58:40 +0900 | [diff] [blame] | 103 | __raw_writel(priorities, priorityReg); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 |  | 
| Simon Arlott | e868d61 | 2007-05-14 08:15:10 +0900 | [diff] [blame] | 105 | /* enable interrupts on the FPGA INTC register */ | 
| Paul Mundt | 9d56dd3 | 2010-01-26 12:58:40 +0900 | [diff] [blame] | 106 | __raw_writel(MICRODEV_FPGA_INTC_MASK(fpgaIrq), MICRODEV_FPGA_INTENB_REG); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | } | 
|  | 108 |  | 
| Paul Mundt | d613883 | 2010-10-27 14:54:10 +0900 | [diff] [blame] | 109 | static struct irq_chip microdev_irq_type = { | 
|  | 110 | .name = "MicroDev-IRQ", | 
|  | 111 | .irq_unmask = enable_microdev_irq, | 
|  | 112 | .irq_mask = disable_microdev_irq, | 
|  | 113 | }; | 
|  | 114 |  | 
| Matt Fleming | be729fd | 2008-12-14 12:02:24 +0000 | [diff] [blame] | 115 | /* This function sets the desired irq handler to be a MicroDev type */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | static void __init make_microdev_irq(unsigned int irq) | 
|  | 117 | { | 
|  | 118 | disable_irq_nosync(irq); | 
| Thomas Gleixner | fcb8918 | 2011-03-24 16:31:17 +0100 | [diff] [blame] | 119 | irq_set_chip_and_handler(irq, µdev_irq_type, handle_level_irq); | 
| Paul Mundt | d613883 | 2010-10-27 14:54:10 +0900 | [diff] [blame] | 120 | disable_microdev_irq(irq_get_irq_data(irq)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | } | 
|  | 122 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | extern void __init init_microdev_irq(void) | 
|  | 124 | { | 
|  | 125 | int i; | 
|  | 126 |  | 
| Matt Fleming | be729fd | 2008-12-14 12:02:24 +0000 | [diff] [blame] | 127 | /* disable interrupts on the FPGA INTC register */ | 
| Paul Mundt | 9d56dd3 | 2010-01-26 12:58:40 +0900 | [diff] [blame] | 128 | __raw_writel(~0ul, MICRODEV_FPGA_INTDSB_REG); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 |  | 
|  | 130 | for (i = 0; i < NUM_EXTERNAL_IRQS; i++) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | make_microdev_irq(i); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | } | 
|  | 133 |  | 
|  | 134 | extern 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 | } |