sh: VoyagerGX cleanups and 8250 UART support.
[linux-2.6.git] / arch / sh / cchips / voyagergx / irq.c
1 /* -------------------------------------------------------------------- */
2 /* setup_voyagergx.c:                                                     */
3 /* -------------------------------------------------------------------- */
4 /*  This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18     Copyright 2003 (c) Lineo uSolutions,Inc.
19 */
20 /* -------------------------------------------------------------------- */
21
22 #undef DEBUG
23
24 #include <linux/sched.h>
25 #include <linux/module.h>
26 #include <linux/kernel.h>
27 #include <linux/param.h>
28 #include <linux/ioport.h>
29 #include <linux/interrupt.h>
30 #include <linux/init.h>
31 #include <linux/irq.h>
32
33 #include <asm/io.h>
34 #include <asm/irq.h>
35 #include <asm/mach/voyagergx_reg.h>
36
37 static void disable_voyagergx_irq(unsigned int irq)
38 {
39         unsigned long flags, val;
40         unsigned long  mask = 1 << (irq - VOYAGER_IRQ_BASE);
41
42         pr_debug("disable_voyagergx_irq(%d): mask=%x\n", irq, mask);
43         local_irq_save(flags);
44         val = inl(VOYAGER_INT_MASK);
45         val &= ~mask;
46         outl(val, VOYAGER_INT_MASK);
47         local_irq_restore(flags);
48 }
49
50
51 static void enable_voyagergx_irq(unsigned int irq)
52 {
53         unsigned long flags, val;
54         unsigned long  mask = 1 << (irq - VOYAGER_IRQ_BASE);
55
56         pr_debug("disable_voyagergx_irq(%d): mask=%x\n", irq, mask);
57         local_irq_save(flags);
58         val = inl(VOYAGER_INT_MASK);
59         val |= mask;
60         outl(val, VOYAGER_INT_MASK);
61         local_irq_restore(flags);
62 }
63
64
65 static void mask_and_ack_voyagergx(unsigned int irq)
66 {
67         disable_voyagergx_irq(irq);
68 }
69
70 static void end_voyagergx_irq(unsigned int irq)
71 {
72         if (!(irq_desc[irq].status & (IRQ_DISABLED|IRQ_INPROGRESS)))
73                 enable_voyagergx_irq(irq);
74 }
75
76 static unsigned int startup_voyagergx_irq(unsigned int irq)
77 {
78         enable_voyagergx_irq(irq);
79         return 0;
80 }
81
82 static void shutdown_voyagergx_irq(unsigned int irq)
83 {
84         disable_voyagergx_irq(irq);
85 }
86
87 static struct hw_interrupt_type voyagergx_irq_type = {
88         .typename = "VOYAGERGX-IRQ",
89         .startup = startup_voyagergx_irq,
90         .shutdown = shutdown_voyagergx_irq,
91         .enable = enable_voyagergx_irq,
92         .disable = disable_voyagergx_irq,
93         .ack = mask_and_ack_voyagergx,
94         .end = end_voyagergx_irq,
95 };
96
97 static irqreturn_t voyagergx_interrupt(int irq, void *dev_id, struct pt_regs *regs)
98 {
99         printk(KERN_INFO
100                "VoyagerGX: spurious interrupt, status: 0x%x\n",
101                         inl(INT_STATUS));
102         return IRQ_HANDLED;
103 }
104
105
106 /*====================================================*/
107
108 static struct {
109         int (*func)(int, void *);
110         void *dev;
111 } voyagergx_demux[VOYAGER_IRQ_NUM];
112
113 void voyagergx_register_irq_demux(int irq,
114                 int (*demux)(int irq, void *dev), void *dev)
115 {
116         voyagergx_demux[irq - VOYAGER_IRQ_BASE].func = demux;
117         voyagergx_demux[irq - VOYAGER_IRQ_BASE].dev = dev;
118 }
119
120 void voyagergx_unregister_irq_demux(int irq)
121 {
122         voyagergx_demux[irq - VOYAGER_IRQ_BASE].func = 0;
123 }
124
125 int voyagergx_irq_demux(int irq)
126 {
127
128         if (irq == IRQ_VOYAGER ) {
129                 unsigned long i = 0, bit __attribute__ ((unused));
130                 unsigned long val  = inl(INT_STATUS);
131 #if 1
132                 if ( val & ( 1 << 1 )){
133                         i = 1;
134                 } else if ( val & ( 1 << 2 )){
135                         i = 2;
136                 } else if ( val & ( 1 << 6 )){
137                         i = 6;
138                 } else if( val & ( 1 << 10 )){
139                         i = 10;
140                 } else if( val & ( 1 << 11 )){
141                         i = 11;
142                 } else if( val & ( 1 << 12 )){
143                         i = 12;
144                 } else if( val & ( 1 << 17 )){
145                         i = 17;
146                 } else {
147                         printk("Unexpected IRQ irq = %d status = 0x%08lx\n", irq, val);
148                 }
149                 pr_debug("voyagergx_irq_demux %d \n", i);
150 #else
151                 for (bit = 1, i = 0 ; i < VOYAGER_IRQ_NUM ; bit <<= 1, i++)
152                         if (val & bit)
153                                 break;
154 #endif
155                 if (i < VOYAGER_IRQ_NUM) {
156                         irq = VOYAGER_IRQ_BASE + i;
157                         if (voyagergx_demux[i].func != 0)
158                                 irq = voyagergx_demux[i].func(irq, voyagergx_demux[i].dev);
159                 }
160         }
161         return irq;
162 }
163
164 static struct irqaction irq0  = {
165         .name           = "voyagergx",
166         .handler        = voyagergx_interrupt,
167         .flags          = IRQF_DISABLED,
168         .mask           = CPU_MASK_NONE,
169 };
170
171 void __init setup_voyagergx_irq(void)
172 {
173         int i, flag;
174
175         printk(KERN_INFO "VoyagerGX configured at 0x%x on irq %d(mapped into %d to %d)\n",
176                VOYAGER_BASE,
177                IRQ_VOYAGER,
178                VOYAGER_IRQ_BASE,
179                VOYAGER_IRQ_BASE + VOYAGER_IRQ_NUM - 1);
180
181         for (i=0; i<VOYAGER_IRQ_NUM; i++) {
182                 flag = 0;
183                 switch (VOYAGER_IRQ_BASE + i) {
184                 case VOYAGER_USBH_IRQ:
185                 case VOYAGER_8051_IRQ:
186                 case VOYAGER_UART0_IRQ:
187                 case VOYAGER_UART1_IRQ:
188                 case VOYAGER_AC97_IRQ:
189                         flag = 1;
190                 }
191                 if (flag == 1)
192                         irq_desc[VOYAGER_IRQ_BASE + i].chip = &voyagergx_irq_type;
193         }
194
195         setup_irq(IRQ_VOYAGER, &irq0);
196 }
197