Merge branch 'upstream-linus' of master.kernel.org:/pub/scm/linux/kernel/git/jgarzik...
[sfrench/cifs-2.6.git] / arch / sh / boards / se / 7343 / irq.c
1 /*
2  * arch/sh/boards/se/7343/irq.c
3  *
4  */
5 #include <linux/init.h>
6 #include <linux/interrupt.h>
7 #include <linux/irq.h>
8 #include <asm/irq.h>
9 #include <asm/io.h>
10 #include <asm/mach/se7343.h>
11
12 static void
13 disable_intreq_irq(unsigned int irq)
14 {
15         int bit = irq - OFFCHIP_IRQ_BASE;
16         u16 val;
17
18         val = ctrl_inw(PA_CPLD_IMSK);
19         val |= 1 << bit;
20         ctrl_outw(val, PA_CPLD_IMSK);
21 }
22
23 static void
24 enable_intreq_irq(unsigned int irq)
25 {
26         int bit = irq - OFFCHIP_IRQ_BASE;
27         u16 val;
28
29         val = ctrl_inw(PA_CPLD_IMSK);
30         val &= ~(1 << bit);
31         ctrl_outw(val, PA_CPLD_IMSK);
32 }
33
34 static void
35 mask_and_ack_intreq_irq(unsigned int irq)
36 {
37         disable_intreq_irq(irq);
38 }
39
40 static unsigned int
41 startup_intreq_irq(unsigned int irq)
42 {
43         enable_intreq_irq(irq);
44         return 0;
45 }
46
47 static void
48 shutdown_intreq_irq(unsigned int irq)
49 {
50         disable_intreq_irq(irq);
51 }
52
53 static void
54 end_intreq_irq(unsigned int irq)
55 {
56         if (!(irq_desc[irq].status & (IRQ_DISABLED | IRQ_INPROGRESS)))
57                 enable_intreq_irq(irq);
58 }
59
60 static struct hw_interrupt_type intreq_irq_type = {
61         .typename = "FPGA-IRQ",
62         .startup = startup_intreq_irq,
63         .shutdown = shutdown_intreq_irq,
64         .enable = enable_intreq_irq,
65         .disable = disable_intreq_irq,
66         .ack = mask_and_ack_intreq_irq,
67         .end = end_intreq_irq
68 };
69
70 static void
71 make_intreq_irq(unsigned int irq)
72 {
73         disable_irq_nosync(irq);
74         irq_desc[irq].chip = &intreq_irq_type;
75         disable_intreq_irq(irq);
76 }
77
78 int
79 shmse_irq_demux(int irq)
80 {
81         int bit;
82         volatile u16 val;
83
84         if (irq == IRQ5_IRQ) {
85                 /* Read status Register */
86                 val = ctrl_inw(PA_CPLD_ST);
87                 bit = ffs(val);
88                 if (bit != 0)
89                         return OFFCHIP_IRQ_BASE + bit - 1;
90         }
91         return irq;
92 }
93
94 /* IRQ5 is multiplexed between the following sources:
95  * 1. PC Card socket
96  * 2. Extension slot
97  * 3. USB Controller
98  * 4. Serial Controller
99  *
100  * We configure IRQ5 as a cascade IRQ.
101  */
102 static struct irqaction irq5 = { no_action, 0, CPU_MASK_NONE, "IRQ5-cascade",
103                                 NULL, NULL};
104
105 /*
106  * Initialize IRQ setting
107  */
108 void __init
109 init_7343se_IRQ(void)
110 {
111         /* Setup Multiplexed interrupts */
112         ctrl_outw(8, PA_CPLD_MODESET);  /* Set all CPLD interrupts to active
113                                          * low.
114                                          */
115         /* Mask all CPLD controller interrupts */
116         ctrl_outw(0x0fff, PA_CPLD_IMSK);
117
118         /* PC Card interrupts */
119         make_intreq_irq(PC_IRQ0);
120         make_intreq_irq(PC_IRQ1);
121         make_intreq_irq(PC_IRQ2);
122         make_intreq_irq(PC_IRQ3);
123
124         /* Extension Slot Interrupts */
125         make_intreq_irq(EXT_IRQ0);
126         make_intreq_irq(EXT_IRQ1);
127         make_intreq_irq(EXT_IRQ2);
128         make_intreq_irq(EXT_IRQ3);
129
130         /* USB Controller interrupts */
131         make_intreq_irq(USB_IRQ0);
132         make_intreq_irq(USB_IRQ1);
133
134         /* Serial Controller interrupts */
135         make_intreq_irq(UART_IRQ0);
136         make_intreq_irq(UART_IRQ1);
137
138         /* Setup all external interrupts to be active low */
139         ctrl_outw(0xaaaa, INTC_ICR1);
140
141         make_ipr_irq(IRQ5_IRQ, IRQ5_IPR_ADDR+2, IRQ5_IPR_POS, IRQ5_PRIORITY);
142         setup_irq(IRQ5_IRQ, &irq5);
143         /* Set port control to use IRQ5 */
144         *(u16 *)0xA4050108 &= ~0xc;
145
146         make_ipr_irq(SIOF0_IRQ, SIOF0_IPR_ADDR, SIOF0_IPR_POS, SIOF0_PRIORITY);
147         make_ipr_irq(VPU_IRQ, VPU_IPR_ADDR, VPU_IPR_POS, 8);
148
149         ctrl_outb(0x0f, INTC_IMCR5);    /* enable SCIF IRQ */
150
151         make_ipr_irq(DMTE0_IRQ, DMA1_IPR_ADDR, DMA1_IPR_POS, DMA1_PRIORITY);
152         make_ipr_irq(DMTE1_IRQ, DMA1_IPR_ADDR, DMA1_IPR_POS, DMA1_PRIORITY);
153         make_ipr_irq(DMTE2_IRQ, DMA1_IPR_ADDR, DMA1_IPR_POS, DMA1_PRIORITY);
154         make_ipr_irq(DMTE3_IRQ, DMA1_IPR_ADDR, DMA1_IPR_POS, DMA1_PRIORITY);
155         make_ipr_irq(DMTE4_IRQ, DMA2_IPR_ADDR, DMA2_IPR_POS, DMA2_PRIORITY);
156         make_ipr_irq(DMTE5_IRQ, DMA2_IPR_ADDR, DMA2_IPR_POS, DMA2_PRIORITY);
157
158         /* I2C block */
159         make_ipr_irq(IIC0_ALI_IRQ, IIC0_IPR_ADDR, IIC0_IPR_POS, IIC0_PRIORITY);
160         make_ipr_irq(IIC0_TACKI_IRQ, IIC0_IPR_ADDR, IIC0_IPR_POS,
161                      IIC0_PRIORITY);
162         make_ipr_irq(IIC0_WAITI_IRQ, IIC0_IPR_ADDR, IIC0_IPR_POS,
163                      IIC0_PRIORITY);
164         make_ipr_irq(IIC0_DTEI_IRQ, IIC0_IPR_ADDR, IIC0_IPR_POS, IIC0_PRIORITY);
165
166         make_ipr_irq(IIC1_ALI_IRQ, IIC1_IPR_ADDR, IIC1_IPR_POS, IIC1_PRIORITY);
167         make_ipr_irq(IIC1_TACKI_IRQ, IIC1_IPR_ADDR, IIC1_IPR_POS,
168                      IIC1_PRIORITY);
169         make_ipr_irq(IIC1_WAITI_IRQ, IIC1_IPR_ADDR, IIC1_IPR_POS,
170                      IIC1_PRIORITY);
171         make_ipr_irq(IIC1_DTEI_IRQ, IIC1_IPR_ADDR, IIC1_IPR_POS, IIC1_PRIORITY);
172
173         /* SIOF */
174         make_ipr_irq(SIOF0_IRQ, SIOF0_IPR_ADDR, SIOF0_IPR_POS, SIOF0_PRIORITY);
175
176         /* SIU */
177         make_ipr_irq(SIU_IRQ, SIU_IPR_ADDR, SIU_IPR_POS, SIU_PRIORITY);
178
179         /* VIO interrupt */
180         make_ipr_irq(CEU_IRQ, VIO_IPR_ADDR, VIO_IPR_POS, VIO_PRIORITY);
181         make_ipr_irq(BEU_IRQ, VIO_IPR_ADDR, VIO_IPR_POS, VIO_PRIORITY);
182         make_ipr_irq(VEU_IRQ, VIO_IPR_ADDR, VIO_IPR_POS, VIO_PRIORITY);
183
184         /*MFI interrupt*/
185
186         make_ipr_irq(MFI_IRQ, MFI_IPR_ADDR, MFI_IPR_POS, MFI_PRIORITY);
187
188         /* LCD controller */
189         make_ipr_irq(LCDC_IRQ, LCDC_IPR_ADDR, LCDC_IPR_POS, LCDC_PRIORITY);
190         ctrl_outw(0x2000, PA_MRSHPC + 0x0c);    /* mrshpc irq enable */
191 }