blob: f7ea700d05ae53c022493c791f601aa25266f7e5 [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*/
Linus Torvalds1da177e2005-04-16 15:20:36 -070020#include <linux/interrupt.h>
21#include <linux/init.h>
Paul Mundt082c44d2006-10-19 16:16:18 +090022#include <linux/io.h>
Paul Mundtadf18902006-09-27 17:17:27 +090023#include <asm/voyagergx.h>
Paul Mundt082c44d2006-10-19 16:16:18 +090024#include <asm/rts7751r2d.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070025
26static void disable_voyagergx_irq(unsigned int irq)
27{
Paul Mundt8599cf02006-09-27 18:03:34 +090028 unsigned long val;
29 unsigned long mask = 1 << (irq - VOYAGER_IRQ_BASE);
Linus Torvalds1da177e2005-04-16 15:20:36 -070030
Paul Mundt082c44d2006-10-19 16:16:18 +090031 pr_debug("disable_voyagergx_irq(%d): mask=%lx\n", irq, mask);
Linus Torvalds1da177e2005-04-16 15:20:36 -070032 val = inl(VOYAGER_INT_MASK);
33 val &= ~mask;
34 outl(val, VOYAGER_INT_MASK);
Linus Torvalds1da177e2005-04-16 15:20:36 -070035}
36
Linus Torvalds1da177e2005-04-16 15:20:36 -070037static void enable_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
Paul Mundt082c44d2006-10-19 16:16:18 +090042 pr_debug("disable_voyagergx_irq(%d): mask=%lx\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 mask_and_ack_voyagergx(unsigned int irq)
49{
50 disable_voyagergx_irq(irq);
51}
52
53static void end_voyagergx_irq(unsigned int irq)
54{
55 if (!(irq_desc[irq].status & (IRQ_DISABLED|IRQ_INPROGRESS)))
56 enable_voyagergx_irq(irq);
57}
58
59static unsigned int startup_voyagergx_irq(unsigned int irq)
60{
61 enable_voyagergx_irq(irq);
62 return 0;
63}
64
65static void shutdown_voyagergx_irq(unsigned int irq)
66{
67 disable_voyagergx_irq(irq);
68}
69
70static struct hw_interrupt_type voyagergx_irq_type = {
Thomas Gleixner08d0fd02005-09-10 00:26:42 -070071 .typename = "VOYAGERGX-IRQ",
72 .startup = startup_voyagergx_irq,
73 .shutdown = shutdown_voyagergx_irq,
74 .enable = enable_voyagergx_irq,
75 .disable = disable_voyagergx_irq,
76 .ack = mask_and_ack_voyagergx,
77 .end = end_voyagergx_irq,
Linus Torvalds1da177e2005-04-16 15:20:36 -070078};
79
Paul Mundt35f3c512006-10-06 15:31:16 +090080static irqreturn_t voyagergx_interrupt(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -070081{
82 printk(KERN_INFO
83 "VoyagerGX: spurious interrupt, status: 0x%x\n",
84 inl(INT_STATUS));
85 return IRQ_HANDLED;
86}
87
Linus Torvalds1da177e2005-04-16 15:20:36 -070088static struct {
89 int (*func)(int, void *);
90 void *dev;
91} voyagergx_demux[VOYAGER_IRQ_NUM];
92
93void voyagergx_register_irq_demux(int irq,
94 int (*demux)(int irq, void *dev), void *dev)
95{
96 voyagergx_demux[irq - VOYAGER_IRQ_BASE].func = demux;
97 voyagergx_demux[irq - VOYAGER_IRQ_BASE].dev = dev;
98}
99
100void voyagergx_unregister_irq_demux(int irq)
101{
102 voyagergx_demux[irq - VOYAGER_IRQ_BASE].func = 0;
103}
104
105int voyagergx_irq_demux(int irq)
106{
107
108 if (irq == IRQ_VOYAGER ) {
109 unsigned long i = 0, bit __attribute__ ((unused));
110 unsigned long val = inl(INT_STATUS);
111#if 1
112 if ( val & ( 1 << 1 )){
113 i = 1;
114 } else if ( val & ( 1 << 2 )){
115 i = 2;
116 } else if ( val & ( 1 << 6 )){
117 i = 6;
118 } else if( val & ( 1 << 10 )){
119 i = 10;
120 } else if( val & ( 1 << 11 )){
121 i = 11;
122 } else if( val & ( 1 << 12 )){
123 i = 12;
124 } else if( val & ( 1 << 17 )){
125 i = 17;
126 } else {
127 printk("Unexpected IRQ irq = %d status = 0x%08lx\n", irq, val);
128 }
Paul Mundt082c44d2006-10-19 16:16:18 +0900129 pr_debug("voyagergx_irq_demux %ld\n", i);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130#else
131 for (bit = 1, i = 0 ; i < VOYAGER_IRQ_NUM ; bit <<= 1, i++)
132 if (val & bit)
133 break;
134#endif
135 if (i < VOYAGER_IRQ_NUM) {
136 irq = VOYAGER_IRQ_BASE + i;
137 if (voyagergx_demux[i].func != 0)
138 irq = voyagergx_demux[i].func(irq, voyagergx_demux[i].dev);
139 }
140 }
141 return irq;
142}
143
Paul Mundt37cc7942006-02-01 03:06:05 -0800144static struct irqaction irq0 = {
145 .name = "voyagergx",
146 .handler = voyagergx_interrupt,
Thomas Gleixner6d208192006-07-01 19:29:25 -0700147 .flags = IRQF_DISABLED,
Paul Mundt37cc7942006-02-01 03:06:05 -0800148 .mask = CPU_MASK_NONE,
149};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150
151void __init setup_voyagergx_irq(void)
152{
153 int i, flag;
154
155 printk(KERN_INFO "VoyagerGX configured at 0x%x on irq %d(mapped into %d to %d)\n",
156 VOYAGER_BASE,
157 IRQ_VOYAGER,
158 VOYAGER_IRQ_BASE,
159 VOYAGER_IRQ_BASE + VOYAGER_IRQ_NUM - 1);
160
161 for (i=0; i<VOYAGER_IRQ_NUM; i++) {
162 flag = 0;
163 switch (VOYAGER_IRQ_BASE + i) {
164 case VOYAGER_USBH_IRQ:
165 case VOYAGER_8051_IRQ:
166 case VOYAGER_UART0_IRQ:
167 case VOYAGER_UART1_IRQ:
168 case VOYAGER_AC97_IRQ:
169 flag = 1;
170 }
171 if (flag == 1)
Ingo Molnard1bef4e2006-06-29 02:24:36 -0700172 irq_desc[VOYAGER_IRQ_BASE + i].chip = &voyagergx_irq_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173 }
174
175 setup_irq(IRQ_VOYAGER, &irq0);
176}