blob: 392c8b12ce36789dea7dbe0b8b3a25084f49371b [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* -------------------------------------------------------------------- */
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
Linus Torvalds1da177e2005-04-16 15:20:36 -070024#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>
Paul Mundtadf18902006-09-27 17:17:27 +090035#include <asm/voyagergx.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036
37static void disable_voyagergx_irq(unsigned int irq)
38{
Paul Mundt8599cf02006-09-27 18:03:34 +090039 unsigned long val;
40 unsigned long mask = 1 << (irq - VOYAGER_IRQ_BASE);
Linus Torvalds1da177e2005-04-16 15:20:36 -070041
42 pr_debug("disable_voyagergx_irq(%d): mask=%x\n", irq, mask);
Linus Torvalds1da177e2005-04-16 15:20:36 -070043 val = inl(VOYAGER_INT_MASK);
44 val &= ~mask;
45 outl(val, VOYAGER_INT_MASK);
Linus Torvalds1da177e2005-04-16 15:20:36 -070046}
47
Linus Torvalds1da177e2005-04-16 15:20:36 -070048static void enable_voyagergx_irq(unsigned int irq)
49{
Paul Mundt8599cf02006-09-27 18:03:34 +090050 unsigned long val;
51 unsigned long mask = 1 << (irq - VOYAGER_IRQ_BASE);
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
53 pr_debug("disable_voyagergx_irq(%d): mask=%x\n", irq, mask);
Linus Torvalds1da177e2005-04-16 15:20:36 -070054 val = inl(VOYAGER_INT_MASK);
55 val |= mask;
56 outl(val, VOYAGER_INT_MASK);
Linus Torvalds1da177e2005-04-16 15:20:36 -070057}
58
Linus Torvalds1da177e2005-04-16 15:20:36 -070059static void mask_and_ack_voyagergx(unsigned int irq)
60{
61 disable_voyagergx_irq(irq);
62}
63
64static void end_voyagergx_irq(unsigned int irq)
65{
66 if (!(irq_desc[irq].status & (IRQ_DISABLED|IRQ_INPROGRESS)))
67 enable_voyagergx_irq(irq);
68}
69
70static unsigned int startup_voyagergx_irq(unsigned int irq)
71{
72 enable_voyagergx_irq(irq);
73 return 0;
74}
75
76static void shutdown_voyagergx_irq(unsigned int irq)
77{
78 disable_voyagergx_irq(irq);
79}
80
81static struct hw_interrupt_type voyagergx_irq_type = {
Thomas Gleixner08d0fd02005-09-10 00:26:42 -070082 .typename = "VOYAGERGX-IRQ",
83 .startup = startup_voyagergx_irq,
84 .shutdown = shutdown_voyagergx_irq,
85 .enable = enable_voyagergx_irq,
86 .disable = disable_voyagergx_irq,
87 .ack = mask_and_ack_voyagergx,
88 .end = end_voyagergx_irq,
Linus Torvalds1da177e2005-04-16 15:20:36 -070089};
90
Paul Mundt8599cf02006-09-27 18:03:34 +090091static irqreturn_t voyagergx_interrupt(int irq, void *dev_id,
92 struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -070093{
94 printk(KERN_INFO
95 "VoyagerGX: spurious interrupt, status: 0x%x\n",
96 inl(INT_STATUS));
97 return IRQ_HANDLED;
98}
99
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100static struct {
101 int (*func)(int, void *);
102 void *dev;
103} voyagergx_demux[VOYAGER_IRQ_NUM];
104
105void voyagergx_register_irq_demux(int irq,
106 int (*demux)(int irq, void *dev), void *dev)
107{
108 voyagergx_demux[irq - VOYAGER_IRQ_BASE].func = demux;
109 voyagergx_demux[irq - VOYAGER_IRQ_BASE].dev = dev;
110}
111
112void voyagergx_unregister_irq_demux(int irq)
113{
114 voyagergx_demux[irq - VOYAGER_IRQ_BASE].func = 0;
115}
116
117int voyagergx_irq_demux(int irq)
118{
119
120 if (irq == IRQ_VOYAGER ) {
121 unsigned long i = 0, bit __attribute__ ((unused));
122 unsigned long val = inl(INT_STATUS);
123#if 1
124 if ( val & ( 1 << 1 )){
125 i = 1;
126 } else if ( val & ( 1 << 2 )){
127 i = 2;
128 } else if ( val & ( 1 << 6 )){
129 i = 6;
130 } else if( val & ( 1 << 10 )){
131 i = 10;
132 } else if( val & ( 1 << 11 )){
133 i = 11;
134 } else if( val & ( 1 << 12 )){
135 i = 12;
136 } else if( val & ( 1 << 17 )){
137 i = 17;
138 } else {
139 printk("Unexpected IRQ irq = %d status = 0x%08lx\n", irq, val);
140 }
141 pr_debug("voyagergx_irq_demux %d \n", i);
142#else
143 for (bit = 1, i = 0 ; i < VOYAGER_IRQ_NUM ; bit <<= 1, i++)
144 if (val & bit)
145 break;
146#endif
147 if (i < VOYAGER_IRQ_NUM) {
148 irq = VOYAGER_IRQ_BASE + i;
149 if (voyagergx_demux[i].func != 0)
150 irq = voyagergx_demux[i].func(irq, voyagergx_demux[i].dev);
151 }
152 }
153 return irq;
154}
155
Paul Mundt37cc7942006-02-01 03:06:05 -0800156static struct irqaction irq0 = {
157 .name = "voyagergx",
158 .handler = voyagergx_interrupt,
Thomas Gleixner6d208192006-07-01 19:29:25 -0700159 .flags = IRQF_DISABLED,
Paul Mundt37cc7942006-02-01 03:06:05 -0800160 .mask = CPU_MASK_NONE,
161};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162
163void __init setup_voyagergx_irq(void)
164{
165 int i, flag;
166
167 printk(KERN_INFO "VoyagerGX configured at 0x%x on irq %d(mapped into %d to %d)\n",
168 VOYAGER_BASE,
169 IRQ_VOYAGER,
170 VOYAGER_IRQ_BASE,
171 VOYAGER_IRQ_BASE + VOYAGER_IRQ_NUM - 1);
172
173 for (i=0; i<VOYAGER_IRQ_NUM; i++) {
174 flag = 0;
175 switch (VOYAGER_IRQ_BASE + i) {
176 case VOYAGER_USBH_IRQ:
177 case VOYAGER_8051_IRQ:
178 case VOYAGER_UART0_IRQ:
179 case VOYAGER_UART1_IRQ:
180 case VOYAGER_AC97_IRQ:
181 flag = 1;
182 }
183 if (flag == 1)
Ingo Molnard1bef4e2006-06-29 02:24:36 -0700184 irq_desc[VOYAGER_IRQ_BASE + i].chip = &voyagergx_irq_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185 }
186
187 setup_irq(IRQ_VOYAGER, &irq0);
188}
189