blob: 8c64baa30364719da119296f487daeb9d8298426 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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 Torvalds1da177e2005-04-16 15:20:36 -070012#include <linux/init.h>
13#include <linux/irq.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include <asm/system.h>
15#include <asm/io.h>
Paul Mundt74017292006-02-01 03:05:59 -080016#include <asm/microdev.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017
18#define NUM_EXTERNAL_IRQS 16 /* IRL0 .. IRL15 */
19
Linus Torvalds1da177e2005-04-16 15:20:36 -070020static 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
67static void enable_microdev_irq(unsigned int irq);
68static void disable_microdev_irq(unsigned int irq);
69
70 /* shutdown is same as "disable" */
71#define shutdown_microdev_irq disable_microdev_irq
72
73static void mask_and_ack_microdev(unsigned int);
74static void end_microdev_irq(unsigned int irq);
75
76static unsigned int startup_microdev_irq(unsigned int irq)
77{
78 enable_microdev_irq(irq);
79 return 0; /* never anything pending */
80}
81
82static struct hw_interrupt_type microdev_irq_type = {
Thomas Gleixner08d0fd02005-09-10 00:26:42 -070083 .typename = "MicroDev-IRQ",
84 .startup = startup_microdev_irq,
85 .shutdown = shutdown_microdev_irq,
86 .enable = enable_microdev_irq,
87 .disable = disable_microdev_irq,
88 .ack = mask_and_ack_microdev,
89 .end = end_microdev_irq
Linus Torvalds1da177e2005-04-16 15:20:36 -070090};
91
92static void disable_microdev_irq(unsigned int irq)
93{
Linus Torvalds1da177e2005-04-16 15:20:36 -070094 unsigned int fpgaIrq;
95
Paul Mundt8599cf02006-09-27 18:03:34 +090096 if (irq >= NUM_EXTERNAL_IRQS)
97 return;
98 if (!fpgaIrqTable[irq].mapped)
99 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100
101 fpgaIrq = fpgaIrqTable[irq].fpgaIrq;
102
Paul Mundt8599cf02006-09-27 18:03:34 +0900103 /* disable interupts on the FPGA INTC register */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104 ctrl_outl(MICRODEV_FPGA_INTC_MASK(fpgaIrq), MICRODEV_FPGA_INTDSB_REG);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105}
106
107static void enable_microdev_irq(unsigned int irq)
108{
109 unsigned long priorityReg, priorities, pri;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110 unsigned int fpgaIrq;
111
Paul Mundt8599cf02006-09-27 18:03:34 +0900112 if (unlikely(irq >= NUM_EXTERNAL_IRQS))
113 return;
114 if (unlikely(!fpgaIrqTable[irq].mapped))
115 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116
117 pri = 15 - irq;
118
119 fpgaIrq = fpgaIrqTable[irq].fpgaIrq;
120 priorityReg = MICRODEV_FPGA_INTPRI_REG(fpgaIrq);
121
Paul Mundt8599cf02006-09-27 18:03:34 +0900122 /* set priority for the interrupt */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123 priorities = ctrl_inl(priorityReg);
124 priorities &= ~MICRODEV_FPGA_INTPRI_MASK(fpgaIrq);
125 priorities |= MICRODEV_FPGA_INTPRI_LEVEL(fpgaIrq, pri);
126 ctrl_outl(priorities, priorityReg);
127
Paul Mundt8599cf02006-09-27 18:03:34 +0900128 /* enable interupts on the FPGA INTC register */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129 ctrl_outl(MICRODEV_FPGA_INTC_MASK(fpgaIrq), MICRODEV_FPGA_INTENB_REG);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130}
131
132 /* This functions sets the desired irq handler to be a MicroDev type */
133static void __init make_microdev_irq(unsigned int irq)
134{
135 disable_irq_nosync(irq);
Ingo Molnard1bef4e2006-06-29 02:24:36 -0700136 irq_desc[irq].chip = &microdev_irq_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 disable_microdev_irq(irq);
138}
139
140static void mask_and_ack_microdev(unsigned int irq)
141{
142 disable_microdev_irq(irq);
143}
144
145static void end_microdev_irq(unsigned int irq)
146{
147 if (!(irq_desc[irq].status & (IRQ_DISABLED|IRQ_INPROGRESS)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148 enable_microdev_irq(irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149}
150
151extern void __init init_microdev_irq(void)
152{
153 int i;
154
155 /* disable interupts on the FPGA INTC register */
156 ctrl_outl(~0ul, MICRODEV_FPGA_INTDSB_REG);
157
158 for (i = 0; i < NUM_EXTERNAL_IRQS; i++)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159 make_microdev_irq(i);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160}
161
162extern void microdev_print_fpga_intc_status(void)
163{
164 volatile unsigned int * const intenb = (unsigned int*)MICRODEV_FPGA_INTENB_REG;
165 volatile unsigned int * const intdsb = (unsigned int*)MICRODEV_FPGA_INTDSB_REG;
166 volatile unsigned int * const intpria = (unsigned int*)MICRODEV_FPGA_INTPRI_REG(0);
167 volatile unsigned int * const intprib = (unsigned int*)MICRODEV_FPGA_INTPRI_REG(8);
168 volatile unsigned int * const intpric = (unsigned int*)MICRODEV_FPGA_INTPRI_REG(16);
169 volatile unsigned int * const intprid = (unsigned int*)MICRODEV_FPGA_INTPRI_REG(24);
170 volatile unsigned int * const intsrc = (unsigned int*)MICRODEV_FPGA_INTSRC_REG;
171 volatile unsigned int * const intreq = (unsigned int*)MICRODEV_FPGA_INTREQ_REG;
172
173 printk("-------------------------- microdev_print_fpga_intc_status() ------------------\n");
174 printk("FPGA_INTENB = 0x%08x\n", *intenb);
175 printk("FPGA_INTDSB = 0x%08x\n", *intdsb);
176 printk("FPGA_INTSRC = 0x%08x\n", *intsrc);
177 printk("FPGA_INTREQ = 0x%08x\n", *intreq);
178 printk("FPGA_INTPRI[3..0] = %08x:%08x:%08x:%08x\n", *intprid, *intpric, *intprib, *intpria);
179 printk("-------------------------------------------------------------------------------\n");
180}
181
182