Merge branch 'upstream-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/ieee13...
[pandora-kernel.git] / arch / sh / kernel / cpu / irq / pint.c
1 /*
2  * arch/sh/kernel/cpu/irq/pint.c - Interrupt handling for PINT-based IRQs.
3  *
4  * Copyright (C) 1999  Niibe Yutaka & Takeshi Yaegashi
5  * Copyright (C) 2000  Kazumoto Kojima
6  * Copyright (C) 2003 Takashi Kusuda <kusuda-takashi@hitachi-ul.co.jp>
7  *
8  * This file is subject to the terms and conditions of the GNU General Public
9  * License.  See the file "COPYING" in the main directory of this archive
10  * for more details.
11  */
12
13 #include <linux/init.h>
14 #include <linux/irq.h>
15 #include <linux/module.h>
16
17 #include <asm/system.h>
18 #include <asm/io.h>
19 #include <asm/machvec.h>
20
21 static unsigned char pint_map[256];
22 static unsigned long portcr_mask;
23
24 static void enable_pint_irq(unsigned int irq);
25 static void disable_pint_irq(unsigned int irq);
26
27 /* shutdown is same as "disable" */
28 #define shutdown_pint_irq disable_pint_irq
29
30 static void mask_and_ack_pint(unsigned int);
31 static void end_pint_irq(unsigned int irq);
32
33 static unsigned int startup_pint_irq(unsigned int irq)
34 {
35         enable_pint_irq(irq);
36         return 0; /* never anything pending */
37 }
38
39 static struct hw_interrupt_type pint_irq_type = {
40         .typename = "PINT-IRQ",
41         .startup = startup_pint_irq,
42         .shutdown = shutdown_pint_irq,
43         .enable = enable_pint_irq,
44         .disable = disable_pint_irq,
45         .ack = mask_and_ack_pint,
46         .end = end_pint_irq
47 };
48
49 static void disable_pint_irq(unsigned int irq)
50 {
51         unsigned long val;
52
53         val = ctrl_inw(INTC_INTER);
54         val &= ~(1 << (irq - PINT_IRQ_BASE));
55         ctrl_outw(val, INTC_INTER);     /* disable PINTn */
56         portcr_mask &= ~(3 << (irq - PINT_IRQ_BASE)*2);
57 }
58
59 static void enable_pint_irq(unsigned int irq)
60 {
61         unsigned long val;
62
63         val = ctrl_inw(INTC_INTER);
64         val |= 1 << (irq - PINT_IRQ_BASE);
65         ctrl_outw(val, INTC_INTER);     /* enable PINTn */
66         portcr_mask |= 3 << (irq - PINT_IRQ_BASE)*2;
67 }
68
69 static void mask_and_ack_pint(unsigned int irq)
70 {
71         disable_pint_irq(irq);
72 }
73
74 static void end_pint_irq(unsigned int irq)
75 {
76         if (!(irq_desc[irq].status & (IRQ_DISABLED|IRQ_INPROGRESS)))
77                 enable_pint_irq(irq);
78 }
79
80 void make_pint_irq(unsigned int irq)
81 {
82         disable_irq_nosync(irq);
83         irq_desc[irq].chip = &pint_irq_type;
84         disable_pint_irq(irq);
85 }
86
87 void __init init_IRQ_pint(void)
88 {
89         int i;
90
91         make_ipr_irq(PINT0_IRQ, PINT0_IPR_ADDR, PINT0_IPR_POS, PINT0_PRIORITY);
92         make_ipr_irq(PINT8_IRQ, PINT8_IPR_ADDR, PINT8_IPR_POS, PINT8_PRIORITY);
93
94         enable_irq(PINT0_IRQ);
95         enable_irq(PINT8_IRQ);
96
97         for(i = 0; i < 16; i++)
98                 make_pint_irq(PINT_IRQ_BASE + i);
99
100         for(i = 0; i < 256; i++) {
101                 if (i & 1)
102                         pint_map[i] = 0;
103                 else if (i & 2)
104                         pint_map[i] = 1;
105                 else if (i & 4)
106                         pint_map[i] = 2;
107                 else if (i & 8)
108                         pint_map[i] = 3;
109                 else if (i & 0x10)
110                         pint_map[i] = 4;
111                 else if (i & 0x20)
112                         pint_map[i] = 5;
113                 else if (i & 0x40)
114                         pint_map[i] = 6;
115                 else if (i & 0x80)
116                         pint_map[i] = 7;
117         }
118 }
119
120 int ipr_irq_demux(int irq)
121 {
122         unsigned long creg, dreg, d, sav;
123
124         if (irq == PINT0_IRQ) {
125 #if defined(CONFIG_CPU_SUBTYPE_SH7707)
126                 creg = PORT_PACR;
127                 dreg = PORT_PADR;
128 #else
129                 creg = PORT_PCCR;
130                 dreg = PORT_PCDR;
131 #endif
132                 sav = ctrl_inw(creg);
133                 ctrl_outw(sav | portcr_mask, creg);
134                 d = (~ctrl_inb(dreg) ^ ctrl_inw(INTC_ICR2)) &
135                         ctrl_inw(INTC_INTER) & 0xff;
136                 ctrl_outw(sav, creg);
137
138                 if (d == 0)
139                         return irq;
140
141                 return PINT_IRQ_BASE + pint_map[d];
142         } else if (irq == PINT8_IRQ) {
143 #if defined(CONFIG_CPU_SUBTYPE_SH7707)
144                 creg = PORT_PBCR;
145                 dreg = PORT_PBDR;
146 #else
147                 creg = PORT_PFCR;
148                 dreg = PORT_PFDR;
149 #endif
150                 sav = ctrl_inw(creg);
151                 ctrl_outw(sav | (portcr_mask >> 16), creg);
152                 d = (~ctrl_inb(dreg) ^ (ctrl_inw(INTC_ICR2) >> 8)) &
153                         (ctrl_inw(INTC_INTER) >> 8) & 0xff;
154                 ctrl_outw(sav, creg);
155
156                 if (d == 0)
157                         return irq;
158
159                 return PINT_IRQ_BASE + 8 + pint_map[d];
160         }
161
162         return irq;
163 }
164