Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
irq.c
Go to the documentation of this file.
1 /*
2  * arch/sh/boards/superh/microdev/irq.c
3  *
4  * Copyright (C) 2003 Sean McGoogan ([email protected])
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/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 /* IRL0 .. IRL15 */
19 
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 
67 static 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  /* disable interrupts on the FPGA INTC register */
81 }
82 
83 static 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  /* set priority for the interrupt */
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  /* enable interrupts on the FPGA INTC register */
107 }
108 
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 
115 /* This function sets the desired irq handler to be a MicroDev type */
116 static void __init make_microdev_irq(unsigned int irq)
117 {
118  disable_irq_nosync(irq);
119  irq_set_chip_and_handler(irq, &microdev_irq_type, handle_level_irq);
120  disable_microdev_irq(irq_get_irq_data(irq));
121 }
122 
123 extern void __init init_microdev_irq(void)
124 {
125  int i;
126 
127  /* disable interrupts on the FPGA INTC register */
129 
130  for (i = 0; i < NUM_EXTERNAL_IRQS; i++)
131  make_microdev_irq(i);
132 }
133 
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 }