1 /*
2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive
4 * for more details.
5 *
6 * arch/sh64/kernel/irq_cayman.c
7 *
8 * SH-5 Cayman Interrupt Support
9 *
10 * This file handles the board specific parts of the Cayman interrupt system
11 *
12 * Copyright (C) 2002 Stuart Menefy
13 */
14
15 #include <linux/config.h>
16 #include <asm/irq.h>
17 #include <asm/page.h>
18 #include <asm/io.h>
19 #include <linux/irq.h>
20 #include <linux/interrupt.h>
21 #include <linux/signal.h>
22 #include <asm/cayman.h>
23
24 unsigned long epld_virt;
25
26 #define EPLD_BASE 0x04002000
27 #define EPLD_STATUS_BASE (epld_virt + 0x10)
28 #define EPLD_MASK_BASE (epld_virt + 0x20)
29
30 /* Note the SMSC SuperIO chip and SMSC LAN chip interrupts are all muxed onto
31 the same SH-5 interrupt */
32
cayman_interrupt_smsc(int irq,void * dev_id,struct pt_regs * regs)33 static void cayman_interrupt_smsc(int irq, void *dev_id, struct pt_regs *regs)
34 {
35 printk(KERN_INFO "CAYMAN: spurious SMSC interrupt\n");
36 }
37
cayman_interrupt_pci2(int irq,void * dev_id,struct pt_regs * regs)38 static void cayman_interrupt_pci2(int irq, void *dev_id, struct pt_regs *regs)
39 {
40 printk(KERN_INFO "CAYMAN: spurious PCI interrupt, IRQ %d\n", irq);
41 }
42
43 static struct irqaction cayman_action_smsc = {
44 .name = "Cayman SMSC Mux",
45 .handler = cayman_interrupt_smsc,
46 .flags = SA_INTERRUPT,
47 };
48
49 static struct irqaction cayman_action_pci2 = {
50 .name = "Cayman PCI2 Mux",
51 .handler = cayman_interrupt_pci2,
52 .flags = SA_INTERRUPT,
53 };
54
enable_cayman_irq(unsigned int irq)55 static void enable_cayman_irq(unsigned int irq)
56 {
57 unsigned long flags;
58 unsigned long mask;
59 unsigned int reg;
60 unsigned char bit;
61
62 irq -= START_EXT_IRQS;
63 reg = EPLD_MASK_BASE + ((irq / 8) << 2);
64 bit = 1<<(irq % 8);
65 save_and_cli(flags);
66 mask = ctrl_inl(reg);
67 mask |= bit;
68 ctrl_outl(mask, reg);
69 restore_flags(flags);
70 }
71
disable_cayman_irq(unsigned int irq)72 void disable_cayman_irq(unsigned int irq)
73 {
74 unsigned long flags;
75 unsigned long mask;
76 unsigned int reg;
77 unsigned char bit;
78
79 irq -= START_EXT_IRQS;
80 reg = EPLD_MASK_BASE + ((irq / 8) << 2);
81 bit = 1<<(irq % 8);
82 save_and_cli(flags);
83 mask = ctrl_inl(reg);
84 mask &= ~bit;
85 ctrl_outl(mask, reg);
86 restore_flags(flags);
87 }
88
ack_cayman_irq(unsigned int irq)89 static void ack_cayman_irq(unsigned int irq)
90 {
91 disable_cayman_irq(irq);
92 }
93
end_cayman_irq(unsigned int irq)94 static void end_cayman_irq(unsigned int irq)
95 {
96 if (!(irq_desc[irq].status & (IRQ_DISABLED|IRQ_INPROGRESS)))
97 enable_cayman_irq(irq);
98 }
99
startup_cayman_irq(unsigned int irq)100 static unsigned int startup_cayman_irq(unsigned int irq)
101 {
102 enable_cayman_irq(irq);
103 return 0; /* never anything pending */
104 }
105
shutdown_cayman_irq(unsigned int irq)106 static void shutdown_cayman_irq(unsigned int irq)
107 {
108 disable_cayman_irq(irq);
109 }
110
111 struct hw_interrupt_type cayman_irq_type = {
112 .typename = "Cayman-IRQ",
113 .startup = startup_cayman_irq,
114 .shutdown = shutdown_cayman_irq,
115 .enable = enable_cayman_irq,
116 .disable = disable_cayman_irq,
117 .ack = ack_cayman_irq,
118 .end = end_cayman_irq,
119 };
120
cayman_irq_demux(int evt)121 int cayman_irq_demux(int evt)
122 {
123 int irq = intc_evt_to_irq[evt];
124
125 if (irq == SMSC_IRQ) {
126 unsigned long status;
127 int i;
128
129 status = ctrl_inl(EPLD_STATUS_BASE) &
130 ctrl_inl(EPLD_MASK_BASE) & 0xff;
131 if (status == 0) {
132 irq = -1;
133 } else {
134 for (i=0; i<8; i++) {
135 if (status & (1<<i))
136 break;
137 }
138 irq = START_EXT_IRQS + i;
139 }
140 }
141
142 if (irq == PCI2_IRQ) {
143 unsigned long status;
144 int i;
145
146 status = ctrl_inl(EPLD_STATUS_BASE + 3 * sizeof(u32)) &
147 ctrl_inl(EPLD_MASK_BASE + 3 * sizeof(u32)) & 0xff;
148 if (status == 0) {
149 irq = -1;
150 } else {
151 for (i=0; i<8; i++) {
152 if (status & (1<<i))
153 break;
154 }
155 irq = START_EXT_IRQS + (3 * 8) + i;
156 }
157 }
158
159 return irq;
160 }
161
162 #if defined(CONFIG_PROC_FS) && defined(CONFIG_SYSCTL)
cayman_irq_describe(char * p,int irq)163 int cayman_irq_describe(char* p, int irq)
164 {
165 if (irq < NR_INTC_IRQS) {
166 return intc_irq_describe(p, irq);
167 } else if (irq < NR_INTC_IRQS + 8) {
168 return sprintf(p, "(SMSC %d)", irq - NR_INTC_IRQS);
169 } else if ((irq >= NR_INTC_IRQS + 24) && (irq < NR_INTC_IRQS + 32)) {
170 return sprintf(p, "(PCI2 %d)", irq - (NR_INTC_IRQS + 24));
171 }
172
173 return 0;
174 }
175 #endif
176
init_cayman_irq(void)177 void init_cayman_irq(void)
178 {
179 int i;
180
181 epld_virt = onchip_remap(EPLD_BASE, 1024, "EPLD");
182 if (!epld_virt) {
183 printk(KERN_ERR "Cayman IRQ: Unable to remap EPLD\n");
184 return;
185 }
186
187 for (i=0; i<NR_EXT_IRQS; i++) {
188 irq_desc[START_EXT_IRQS + i].handler = &cayman_irq_type;
189 }
190
191 /* Setup the SMSC interrupt */
192 setup_irq(SMSC_IRQ, &cayman_action_smsc);
193 setup_irq(PCI2_IRQ, &cayman_action_pci2);
194 }
195