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,baboon_active;
26 volatile struct baboon *baboon;
27 
28 void baboon_irq(int, void *, struct pt_regs *);
29 
30 extern int macide_ack_intr(ide_hwif_t *);
31 
32 /*
33  * Baboon initialization.
34  */
35 
baboon_init(void)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 	baboon_active = 0;
47 
48 	printk("Baboon detected at %p\n", baboon);
49 }
50 
51 /*
52  * Register the Baboon interrupt dispatcher on nubus slot $C.
53  */
54 
baboon_register_interrupts(void)55 void __init baboon_register_interrupts(void)
56 {
57 	request_irq(IRQ_NUBUS_C, baboon_irq, IRQ_FLG_LOCK|IRQ_FLG_FAST,
58 		    "baboon", (void *) baboon);
59 }
60 
61 /*
62  * Baboon interrupt handler. This works a lot like a VIA.
63  */
64 
baboon_irq(int irq,void * dev_id,struct pt_regs * regs)65 void baboon_irq(int irq, void *dev_id, struct pt_regs *regs)
66 {
67 	int irq_bit,i;
68 	unsigned char events;
69 
70 #ifdef DEBUG_IRQS
71 	printk("baboon_irq: mb_control %02X mb_ifr %02X mb_status %02X active %02X\n",
72 		(uint) baboon->mb_control, (uint) baboon->mb_ifr,
73 		(uint) baboon->mb_status,  baboon_active);
74 #endif
75 
76 	if (!(events = baboon->mb_ifr & 0x07)) return;
77 
78 	for (i = 0, irq_bit = 1 ; i < 3 ; i++, irq_bit <<= 1) {
79 	        if (events & irq_bit/* & baboon_active*/) {
80 			baboon_active &= ~irq_bit;
81 			mac_do_irq_list(IRQ_BABOON_0 + i, regs);
82 			baboon_active |= irq_bit;
83 			baboon->mb_ifr &= ~irq_bit;
84 		}
85 	}
86 #if 0
87 	if (baboon->mb_ifr & 0x02) macide_ack_intr(NULL);
88 	/* for now we need to smash all interrupts */
89 	baboon->mb_ifr &= ~events;
90 #endif
91 }
92 
baboon_irq_enable(int irq)93 void baboon_irq_enable(int irq) {
94 	int irq_idx	= IRQ_IDX(irq);
95 
96 #ifdef DEBUG_IRQUSE
97 	printk("baboon_irq_enable(%d)\n", irq);
98 #endif
99 	baboon_active |= (1 << irq_idx);
100 }
101 
baboon_irq_disable(int irq)102 void baboon_irq_disable(int irq) {
103 	int irq_idx	= IRQ_IDX(irq);
104 
105 #ifdef DEBUG_IRQUSE
106 	printk("baboon_irq_disable(%d)\n", irq);
107 #endif
108 	baboon_active &= ~(1 << irq_idx);
109 }
110 
baboon_irq_clear(int irq)111 void baboon_irq_clear(int irq) {
112 	int irq_idx	= IRQ_IDX(irq);
113 
114 	baboon->mb_ifr &= ~(1 << irq_idx);
115 }
116 
baboon_irq_pending(int irq)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 }
123