Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6
[pandora-kernel.git] / arch / m68k / mac / baboon.c
1 /*
2  * Baboon Custom IC Management
3  *
4  * The Baboon custom IC controls the IDE, PCMCIA and media bay on the
5  * PowerBook 190. It multiplexes multiple interrupt sources onto the
6  * Nubus slot $C interrupt.
7  */
8
9 #include <linux/types.h>
10 #include <linux/kernel.h>
11 #include <linux/mm.h>
12 #include <linux/delay.h>
13 #include <linux/init.h>
14 #include <linux/ide.h>
15
16 #include <asm/traps.h>
17 #include <asm/bootinfo.h>
18 #include <asm/macintosh.h>
19 #include <asm/macints.h>
20 #include <asm/mac_baboon.h>
21
22 /* #define DEBUG_BABOON */
23 /* #define DEBUG_IRQS */
24
25 int baboon_present;
26 static volatile struct baboon *baboon;
27
28 #if 0
29 extern int macide_ack_intr(struct ata_channel *);
30 #endif
31
32 /*
33  * Baboon initialization.
34  */
35
36 void __init baboon_init(void)
37 {
38         if (macintosh_config->ident != MAC_MODEL_PB190) {
39                 baboon = NULL;
40                 baboon_present = 0;
41                 return;
42         }
43
44         baboon = (struct baboon *) BABOON_BASE;
45         baboon_present = 1;
46
47         printk("Baboon detected at %p\n", baboon);
48 }
49
50 /*
51  * Baboon interrupt handler. This works a lot like a VIA.
52  */
53
54 static irqreturn_t baboon_irq(int irq, void *dev_id)
55 {
56         int irq_bit, irq_num;
57         unsigned char events;
58
59 #ifdef DEBUG_IRQS
60         printk("baboon_irq: mb_control %02X mb_ifr %02X mb_status %02X\n",
61                 (uint) baboon->mb_control, (uint) baboon->mb_ifr,
62                 (uint) baboon->mb_status);
63 #endif
64
65         if (!(events = baboon->mb_ifr & 0x07))
66                 return IRQ_NONE;
67
68         irq_num = IRQ_BABOON_0;
69         irq_bit = 1;
70         do {
71                 if (events & irq_bit) {
72                         baboon->mb_ifr &= ~irq_bit;
73                         m68k_handle_int(irq_num);
74                 }
75                 irq_bit <<= 1;
76                 irq_num++;
77         } while(events >= irq_bit);
78 #if 0
79         if (baboon->mb_ifr & 0x02) macide_ack_intr(NULL);
80         /* for now we need to smash all interrupts */
81         baboon->mb_ifr &= ~events;
82 #endif
83         return IRQ_HANDLED;
84 }
85
86 /*
87  * Register the Baboon interrupt dispatcher on nubus slot $C.
88  */
89
90 void __init baboon_register_interrupts(void)
91 {
92         request_irq(IRQ_NUBUS_C, baboon_irq, IRQ_FLG_LOCK|IRQ_FLG_FAST,
93                     "baboon", (void *) baboon);
94 }
95
96 void baboon_irq_enable(int irq) {
97 #ifdef DEBUG_IRQUSE
98         printk("baboon_irq_enable(%d)\n", irq);
99 #endif
100         /* FIXME: figure out how to mask and unmask baboon interrupt sources */
101         enable_irq(IRQ_NUBUS_C);
102 }
103
104 void baboon_irq_disable(int irq) {
105 #ifdef DEBUG_IRQUSE
106         printk("baboon_irq_disable(%d)\n", irq);
107 #endif
108         disable_irq(IRQ_NUBUS_C);
109 }
110
111 void baboon_irq_clear(int irq) {
112         int irq_idx     = IRQ_IDX(irq);
113
114         baboon->mb_ifr &= ~(1 << irq_idx);
115 }
116
117 int baboon_irq_pending(int irq)
118 {
119         int irq_idx     = IRQ_IDX(irq);
120
121         return baboon->mb_ifr & (1 << irq_idx);
122 }