Merge git://git.infradead.org/hdrinstall-2.6
[linux-2.6] / 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/rts7751r2d/rts7751r2d.h>
36 #include <asm/rts7751r2d/voyagergx_reg.h>
37
38 static void disable_voyagergx_irq(unsigned int irq)
39 {
40         unsigned long flags, val;
41         unsigned long  mask = 1 << (irq - VOYAGER_IRQ_BASE);
42
43         pr_debug("disable_voyagergx_irq(%d): mask=%x\n", irq, mask);
44         local_irq_save(flags);
45         val = inl(VOYAGER_INT_MASK);
46         val &= ~mask;
47         outl(val, VOYAGER_INT_MASK);
48         local_irq_restore(flags);
49 }
50
51
52 static void enable_voyagergx_irq(unsigned int irq)
53 {
54         unsigned long flags, val;
55         unsigned long  mask = 1 << (irq - VOYAGER_IRQ_BASE);
56
57         pr_debug("disable_voyagergx_irq(%d): mask=%x\n", irq, mask);
58         local_irq_save(flags);
59         val = inl(VOYAGER_INT_MASK);
60         val |= mask;
61         outl(val, VOYAGER_INT_MASK);
62         local_irq_restore(flags);
63 }
64
65
66 static void mask_and_ack_voyagergx(unsigned int irq)
67 {
68         disable_voyagergx_irq(irq);
69 }
70
71 static void end_voyagergx_irq(unsigned int irq)
72 {
73         if (!(irq_desc[irq].status & (IRQ_DISABLED|IRQ_INPROGRESS)))
74                 enable_voyagergx_irq(irq);
75 }
76
77 static unsigned int startup_voyagergx_irq(unsigned int irq)
78 {
79         enable_voyagergx_irq(irq);
80         return 0;
81 }
82
83 static void shutdown_voyagergx_irq(unsigned int irq)
84 {
85         disable_voyagergx_irq(irq);
86 }
87
88 static struct hw_interrupt_type voyagergx_irq_type = {
89         .typename = "VOYAGERGX-IRQ",
90         .startup = startup_voyagergx_irq,
91         .shutdown = shutdown_voyagergx_irq,
92         .enable = enable_voyagergx_irq,
93         .disable = disable_voyagergx_irq,
94         .ack = mask_and_ack_voyagergx,
95         .end = end_voyagergx_irq,
96 };
97
98 static irqreturn_t voyagergx_interrupt(int irq, void *dev_id, struct pt_regs *regs)
99 {
100         printk(KERN_INFO
101                "VoyagerGX: spurious interrupt, status: 0x%x\n",
102                         inl(INT_STATUS));
103         return IRQ_HANDLED;
104 }
105
106
107 /*====================================================*/
108
109 static struct {
110         int (*func)(int, void *);
111         void *dev;
112 } voyagergx_demux[VOYAGER_IRQ_NUM];
113
114 void voyagergx_register_irq_demux(int irq,
115                 int (*demux)(int irq, void *dev), void *dev)
116 {
117         voyagergx_demux[irq - VOYAGER_IRQ_BASE].func = demux;
118         voyagergx_demux[irq - VOYAGER_IRQ_BASE].dev = dev;
119 }
120
121 void voyagergx_unregister_irq_demux(int irq)
122 {
123         voyagergx_demux[irq - VOYAGER_IRQ_BASE].func = 0;
124 }
125
126 int voyagergx_irq_demux(int irq)
127 {
128
129         if (irq == IRQ_VOYAGER ) {
130                 unsigned long i = 0, bit __attribute__ ((unused));
131                 unsigned long val  = inl(INT_STATUS);
132 #if 1
133                 if ( val & ( 1 << 1 )){
134                         i = 1;
135                 } else if ( val & ( 1 << 2 )){
136                         i = 2;
137                 } else if ( val & ( 1 << 6 )){
138                         i = 6;
139                 } else if( val & ( 1 << 10 )){
140                         i = 10;
141                 } else if( val & ( 1 << 11 )){
142                         i = 11;
143                 } else if( val & ( 1 << 12 )){
144                         i = 12;
145                 } else if( val & ( 1 << 17 )){
146                         i = 17;
147                 } else {
148                         printk("Unexpected IRQ irq = %d status = 0x%08lx\n", irq, val);
149                 }
150                 pr_debug("voyagergx_irq_demux %d \n", i);
151 #else
152                 for (bit = 1, i = 0 ; i < VOYAGER_IRQ_NUM ; bit <<= 1, i++)
153                         if (val & bit)
154                                 break;
155 #endif
156                 if (i < VOYAGER_IRQ_NUM) {
157                         irq = VOYAGER_IRQ_BASE + i;
158                         if (voyagergx_demux[i].func != 0)
159                                 irq = voyagergx_demux[i].func(irq, voyagergx_demux[i].dev);
160                 }
161         }
162         return irq;
163 }
164
165 static struct irqaction irq0  = {
166         .name           = "voyagergx",
167         .handler        = voyagergx_interrupt,
168         .flags          = IRQF_DISABLED,
169         .mask           = CPU_MASK_NONE,
170 };
171
172 void __init setup_voyagergx_irq(void)
173 {
174         int i, flag;
175
176         printk(KERN_INFO "VoyagerGX configured at 0x%x on irq %d(mapped into %d to %d)\n",
177                VOYAGER_BASE,
178                IRQ_VOYAGER,
179                VOYAGER_IRQ_BASE,
180                VOYAGER_IRQ_BASE + VOYAGER_IRQ_NUM - 1);
181
182         for (i=0; i<VOYAGER_IRQ_NUM; i++) {
183                 flag = 0;
184                 switch (VOYAGER_IRQ_BASE + i) {
185                 case VOYAGER_USBH_IRQ:
186                 case VOYAGER_8051_IRQ:
187                 case VOYAGER_UART0_IRQ:
188                 case VOYAGER_UART1_IRQ:
189                 case VOYAGER_AC97_IRQ:
190                         flag = 1;
191                 }
192                 if (flag == 1)
193                         irq_desc[VOYAGER_IRQ_BASE + i].chip = &voyagergx_irq_type;
194         }
195
196         setup_irq(IRQ_VOYAGER, &irq0);
197 }
198