Merge master.kernel.org:/pub/scm/linux/kernel/git/davem/sparc-2.6
[pandora-kernel.git] / arch / sh / boards / renesas / rts7751r2d / irq.c
1 /*
2  * linux/arch/sh/boards/renesas/rts7751r2d/irq.c
3  *
4  * Copyright (C) 2000  Kazumoto Kojima
5  *
6  * Renesas Technology Sales RTS7751R2D Support.
7  *
8  * Modified for RTS7751R2D by
9  * Atom Create Engineering Co., Ltd. 2002.
10  */
11
12 #include <linux/init.h>
13 #include <linux/irq.h>
14 #include <asm/io.h>
15 #include <asm/irq.h>
16 #include <asm/rts7751r2d/rts7751r2d.h>
17
18 #if defined(CONFIG_RTS7751R2D_REV11)
19 static int mask_pos[] = {11, 9, 8, 12, 10, 6, 5, 4, 7, 14, 13, 0, 0, 0, 0};
20 #else
21 static int mask_pos[] = {6, 11, 9, 8, 12, 10, 5, 4, 7, 14, 13, 0, 0, 0, 0};
22 #endif
23
24 extern int voyagergx_irq_demux(int irq);
25 extern void setup_voyagergx_irq(void);
26
27 static void enable_rts7751r2d_irq(unsigned int irq);
28 static void disable_rts7751r2d_irq(unsigned int irq);
29
30 /* shutdown is same as "disable" */
31 #define shutdown_rts7751r2d_irq disable_rts7751r2d_irq
32
33 static void ack_rts7751r2d_irq(unsigned int irq);
34 static void end_rts7751r2d_irq(unsigned int irq);
35
36 static unsigned int startup_rts7751r2d_irq(unsigned int irq)
37 {
38         enable_rts7751r2d_irq(irq);
39         return 0; /* never anything pending */
40 }
41
42 static void disable_rts7751r2d_irq(unsigned int irq)
43 {
44         unsigned long flags;
45         unsigned short val;
46         unsigned short mask = 0xffff ^ (0x0001 << mask_pos[irq]);
47
48         /* Set the priority in IPR to 0 */
49         local_irq_save(flags);
50         val = ctrl_inw(IRLCNTR1);
51         val &= mask;
52         ctrl_outw(val, IRLCNTR1);
53         local_irq_restore(flags);
54 }
55
56 static void enable_rts7751r2d_irq(unsigned int irq)
57 {
58         unsigned long flags;
59         unsigned short val;
60         unsigned short value = (0x0001 << mask_pos[irq]);
61
62         /* Set priority in IPR back to original value */
63         local_irq_save(flags);
64         val = ctrl_inw(IRLCNTR1);
65         val |= value;
66         ctrl_outw(val, IRLCNTR1);
67         local_irq_restore(flags);
68 }
69
70 int rts7751r2d_irq_demux(int irq)
71 {
72         int demux_irq;
73
74         demux_irq = voyagergx_irq_demux(irq);
75         return demux_irq;
76 }
77
78 static void ack_rts7751r2d_irq(unsigned int irq)
79 {
80         disable_rts7751r2d_irq(irq);
81 }
82
83 static void end_rts7751r2d_irq(unsigned int irq)
84 {
85         if (!(irq_desc[irq].status & (IRQ_DISABLED|IRQ_INPROGRESS)))
86                 enable_rts7751r2d_irq(irq);
87 }
88
89 static struct hw_interrupt_type rts7751r2d_irq_type = {
90         .typename = "RTS7751R2D IRQ",
91         .startup = startup_rts7751r2d_irq,
92         .shutdown = shutdown_rts7751r2d_irq,
93         .enable = enable_rts7751r2d_irq,
94         .disable = disable_rts7751r2d_irq,
95         .ack = ack_rts7751r2d_irq,
96         .end = end_rts7751r2d_irq,
97 };
98
99 static void make_rts7751r2d_irq(unsigned int irq)
100 {
101         disable_irq_nosync(irq);
102         irq_desc[irq].chip = &rts7751r2d_irq_type;
103         disable_rts7751r2d_irq(irq);
104 }
105
106 /*
107  * Initialize IRQ setting
108  */
109 void __init init_rts7751r2d_IRQ(void)
110 {
111         int i;
112
113         /* IRL0=KEY Input
114          * IRL1=Ethernet
115          * IRL2=CF Card
116          * IRL3=CF Card Insert
117          * IRL4=PCMCIA
118          * IRL5=VOYAGER
119          * IRL6=RTC Alarm
120          * IRL7=RTC Timer
121          * IRL8=SD Card
122          * IRL9=PCI Slot #1
123          * IRL10=PCI Slot #2
124          * IRL11=Extention #0
125          * IRL12=Extention #1
126          * IRL13=Extention #2
127          * IRL14=Extention #3
128          */
129
130         for (i=0; i<15; i++)
131                 make_rts7751r2d_irq(i);
132
133         setup_voyagergx_irq();
134 }