Merge ../torvalds-2.6/
[sfrench/cifs-2.6.git] / arch / sh / boards / cqreek / irq.c
1 /* $Id: irq.c,v 1.1.2.4 2002/11/04 20:33:56 lethal Exp $
2  *
3  * arch/sh/boards/cqreek/irq.c
4  *
5  * Copyright (C) 2000  Niibe Yutaka
6  *
7  * CqREEK IDE/ISA Bridge Support.
8  *
9  */
10
11 #include <linux/irq.h>
12 #include <linux/init.h>
13
14 #include <asm/cqreek/cqreek.h>
15 #include <asm/io.h>
16 #include <asm/io_generic.h>
17 #include <asm/irq.h>
18 #include <asm/machvec.h>
19 #include <asm/machvec_init.h>
20 #include <asm/rtc.h>
21
22 struct cqreek_irq_data {
23         unsigned short mask_port;       /* Port of Interrupt Mask Register */
24         unsigned short stat_port;       /* Port of Interrupt Status Register */
25         unsigned short bit;             /* Value of the bit */
26 };
27 static struct cqreek_irq_data cqreek_irq_data[NR_IRQS];
28
29 static void disable_cqreek_irq(unsigned int irq)
30 {
31         unsigned long flags;
32         unsigned short mask;
33         unsigned short mask_port = cqreek_irq_data[irq].mask_port;
34         unsigned short bit = cqreek_irq_data[irq].bit;
35
36         local_irq_save(flags);
37         /* Disable IRQ */
38         mask = inw(mask_port) & ~bit;
39         outw_p(mask, mask_port);
40         local_irq_restore(flags);
41 }
42
43 static void enable_cqreek_irq(unsigned int irq)
44 {
45         unsigned long flags;
46         unsigned short mask;
47         unsigned short mask_port = cqreek_irq_data[irq].mask_port;
48         unsigned short bit = cqreek_irq_data[irq].bit;
49
50         local_irq_save(flags);
51         /* Enable IRQ */
52         mask = inw(mask_port) | bit;
53         outw_p(mask, mask_port);
54         local_irq_restore(flags);
55 }
56
57 static void mask_and_ack_cqreek(unsigned int irq)
58 {
59         unsigned short stat_port = cqreek_irq_data[irq].stat_port;
60         unsigned short bit = cqreek_irq_data[irq].bit;
61
62         disable_cqreek_irq(irq);
63         /* Clear IRQ (it might be edge IRQ) */
64         inw(stat_port);
65         outw_p(bit, stat_port);
66 }
67
68 static void end_cqreek_irq(unsigned int irq)
69 {
70         if (!(irq_desc[irq].status & (IRQ_DISABLED|IRQ_INPROGRESS)))
71                 enable_cqreek_irq(irq);
72 }
73
74 static unsigned int startup_cqreek_irq(unsigned int irq)
75
76         enable_cqreek_irq(irq);
77         return 0;
78 }
79
80 static void shutdown_cqreek_irq(unsigned int irq)
81 {
82         disable_cqreek_irq(irq);
83 }
84
85 static struct hw_interrupt_type cqreek_irq_type = {
86         .typename = "CqREEK-IRQ",
87         .startup = startup_cqreek_irq,
88         .shutdown = shutdown_cqreek_irq,
89         .enable = enable_cqreek_irq,
90         .disable = disable_cqreek_irq,
91         .ack = mask_and_ack_cqreek,
92         .end = end_cqreek_irq
93 };
94
95 int cqreek_has_ide, cqreek_has_isa;
96
97 /* XXX: This is just for test for my NE2000 ISA board
98    What we really need is virtualized IRQ and demultiplexer like HP600 port */
99 void __init init_cqreek_IRQ(void)
100 {
101         if (cqreek_has_ide) {
102                 cqreek_irq_data[14].mask_port = BRIDGE_IDE_INTR_MASK;
103                 cqreek_irq_data[14].stat_port = BRIDGE_IDE_INTR_STAT;
104                 cqreek_irq_data[14].bit = 1;
105
106                 irq_desc[14].handler = &cqreek_irq_type;
107                 irq_desc[14].status = IRQ_DISABLED;
108                 irq_desc[14].action = 0;
109                 irq_desc[14].depth = 1;
110
111                 disable_cqreek_irq(14);
112         }
113
114         if (cqreek_has_isa) {
115                 cqreek_irq_data[10].mask_port = BRIDGE_ISA_INTR_MASK;
116                 cqreek_irq_data[10].stat_port = BRIDGE_ISA_INTR_STAT;
117                 cqreek_irq_data[10].bit = (1 << 10);
118
119                 /* XXX: Err... we may need demultiplexer for ISA irq... */
120                 irq_desc[10].handler = &cqreek_irq_type;
121                 irq_desc[10].status = IRQ_DISABLED;
122                 irq_desc[10].action = 0;
123                 irq_desc[10].depth = 1;
124
125                 disable_cqreek_irq(10);
126         }
127 }
128