Merge master.kernel.org:/pub/scm/linux/kernel/git/davej/cpufreq
[pandora-kernel.git] / arch / frv / kernel / irq-mb93091.c
1 /* irq-mb93091.c: MB93091 FPGA interrupt handling
2  *
3  * Copyright (C) 2003 Red Hat, Inc. All Rights Reserved.
4  * Written by David Howells (dhowells@redhat.com)
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version
9  * 2 of the License, or (at your option) any later version.
10  */
11
12 #include <linux/ptrace.h>
13 #include <linux/errno.h>
14 #include <linux/signal.h>
15 #include <linux/sched.h>
16 #include <linux/ioport.h>
17 #include <linux/interrupt.h>
18 #include <linux/init.h>
19 #include <linux/irq.h>
20
21 #include <asm/io.h>
22 #include <asm/system.h>
23 #include <asm/bitops.h>
24 #include <asm/delay.h>
25 #include <asm/irq.h>
26 #include <asm/irc-regs.h>
27 #include <asm/irq-routing.h>
28
29 #define __reg16(ADDR) (*(volatile unsigned short *)(ADDR))
30
31 #define __get_IMR()     ({ __reg16(0xffc00004); })
32 #define __set_IMR(M)    do { __reg16(0xffc00004) = (M); wmb(); } while(0)
33 #define __get_IFR()     ({ __reg16(0xffc0000c); })
34 #define __clr_IFR(M)    do { __reg16(0xffc0000c) = ~(M); wmb(); } while(0)
35
36 static void frv_fpga_doirq(struct irq_source *source);
37 static void frv_fpga_control(struct irq_group *group, int irq, int on);
38
39 /*****************************************************************************/
40 /*
41  * FPGA IRQ multiplexor
42  */
43 static struct irq_source frv_fpga[4] = {
44 #define __FPGA(X, M)                                    \
45         [X] = {                                         \
46                 .muxname        = "fpga."#X,            \
47                 .irqmask        = M,                    \
48                 .doirq          = frv_fpga_doirq,       \
49         }
50
51         __FPGA(0, 0x0028),
52         __FPGA(1, 0x0050),
53         __FPGA(2, 0x1c00),
54         __FPGA(3, 0x6386),
55 };
56
57 static struct irq_group frv_fpga_irqs = {
58         .first_irq      = IRQ_BASE_FPGA,
59         .control        = frv_fpga_control,
60         .sources = {
61                 [ 1] = &frv_fpga[3],
62                 [ 2] = &frv_fpga[3],
63                 [ 3] = &frv_fpga[0],
64                 [ 4] = &frv_fpga[1],
65                 [ 5] = &frv_fpga[0],
66                 [ 6] = &frv_fpga[1],
67                 [ 7] = &frv_fpga[3],
68                 [ 8] = &frv_fpga[3],
69                 [ 9] = &frv_fpga[3],
70                 [10] = &frv_fpga[2],
71                 [11] = &frv_fpga[2],
72                 [12] = &frv_fpga[2],
73                 [13] = &frv_fpga[3],
74                 [14] = &frv_fpga[3],
75         },
76 };
77
78
79 static void frv_fpga_control(struct irq_group *group, int index, int on)
80 {
81         uint16_t imr = __get_IMR();
82
83         if (on)
84                 imr &= ~(1 << index);
85         else
86                 imr |= 1 << index;
87
88         __set_IMR(imr);
89 }
90
91 static void frv_fpga_doirq(struct irq_source *source)
92 {
93         uint16_t mask, imr;
94
95         imr = __get_IMR();
96         mask = source->irqmask & ~imr & __get_IFR();
97         if (mask) {
98                 __set_IMR(imr | mask);
99                 __clr_IFR(mask);
100                 distribute_irqs(&frv_fpga_irqs, mask);
101                 __set_IMR(imr);
102         }
103 }
104
105 void __init fpga_init(void)
106 {
107         __set_IMR(0x7ffe);
108         __clr_IFR(0x0000);
109
110         frv_irq_route_external(&frv_fpga[0], IRQ_CPU_EXTERNAL0);
111         frv_irq_route_external(&frv_fpga[1], IRQ_CPU_EXTERNAL1);
112         frv_irq_route_external(&frv_fpga[2], IRQ_CPU_EXTERNAL2);
113         frv_irq_route_external(&frv_fpga[3], IRQ_CPU_EXTERNAL3);
114         frv_irq_set_group(&frv_fpga_irqs);
115 }