blob: 425144cbfa7d7730fa0b70da9bbee893192f96ec [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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>
Geert Uytterhoevenddc7fd22011-07-13 21:48:30 +020014#ifdef CONFIG_GENERIC_HARDIRQS
15#include <linux/irq.h>
16#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070017
18#include <asm/traps.h>
19#include <asm/bootinfo.h>
20#include <asm/macintosh.h>
21#include <asm/macints.h>
22#include <asm/mac_baboon.h>
23
Linus Torvalds1da177e2005-04-16 15:20:36 -070024/* #define DEBUG_IRQS */
25
Finn Thain746e8d32008-11-18 20:45:21 +010026extern void mac_enable_irq(unsigned int);
27extern void mac_disable_irq(unsigned int);
28
Finn Thain217f6712007-05-01 22:32:58 +020029int baboon_present;
Adrian Bunk8dfbdf42008-07-17 21:16:25 +020030static volatile struct baboon *baboon;
Finn Thain746e8d32008-11-18 20:45:21 +010031static unsigned char baboon_disabled;
Linus Torvalds1da177e2005-04-16 15:20:36 -070032
33#if 0
34extern int macide_ack_intr(struct ata_channel *);
35#endif
36
37/*
38 * Baboon initialization.
39 */
40
41void __init baboon_init(void)
42{
43 if (macintosh_config->ident != MAC_MODEL_PB190) {
44 baboon = NULL;
45 baboon_present = 0;
46 return;
47 }
48
49 baboon = (struct baboon *) BABOON_BASE;
50 baboon_present = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -070051
52 printk("Baboon detected at %p\n", baboon);
53}
54
55/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070056 * Baboon interrupt handler. This works a lot like a VIA.
57 */
58
Geert Uytterhoeven9145db52011-08-10 12:48:29 +020059#ifdef CONFIG_GENERIC_HARDIRQS
60static void baboon_irq(unsigned int irq, struct irq_desc *desc)
61{
62 int irq_bit, irq_num;
63 unsigned char events;
64
65#ifdef DEBUG_IRQS
66 printk("baboon_irq: mb_control %02X mb_ifr %02X mb_status %02X\n",
67 (uint) baboon->mb_control, (uint) baboon->mb_ifr,
68 (uint) baboon->mb_status);
69#endif
70
71 events = baboon->mb_ifr & 0x07;
72 if (!events)
73 return;
74
75 irq_num = IRQ_BABOON_0;
76 irq_bit = 1;
77 do {
78 if (events & irq_bit) {
79 baboon->mb_ifr &= ~irq_bit;
80 generic_handle_irq(irq_num);
81 }
82 irq_bit <<= 1;
83 irq_num++;
84 } while(events >= irq_bit);
85#if 0
86 if (baboon->mb_ifr & 0x02) macide_ack_intr(NULL);
87 /* for now we need to smash all interrupts */
88 baboon->mb_ifr &= ~events;
89#endif
90}
91#else
Adrian Bunk8dfbdf42008-07-17 21:16:25 +020092static irqreturn_t baboon_irq(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -070093{
Finn Thain67dfb152007-05-01 22:32:56 +020094 int irq_bit, irq_num;
Linus Torvalds1da177e2005-04-16 15:20:36 -070095 unsigned char events;
96
97#ifdef DEBUG_IRQS
Finn Thain217f6712007-05-01 22:32:58 +020098 printk("baboon_irq: mb_control %02X mb_ifr %02X mb_status %02X\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -070099 (uint) baboon->mb_control, (uint) baboon->mb_ifr,
Finn Thain217f6712007-05-01 22:32:58 +0200100 (uint) baboon->mb_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101#endif
102
103 if (!(events = baboon->mb_ifr & 0x07))
104 return IRQ_NONE;
105
Finn Thain67dfb152007-05-01 22:32:56 +0200106 irq_num = IRQ_BABOON_0;
107 irq_bit = 1;
108 do {
Finn Thain217f6712007-05-01 22:32:58 +0200109 if (events & irq_bit) {
Finn Thain647b8042007-05-01 22:32:55 +0200110 baboon->mb_ifr &= ~irq_bit;
Geert Uytterhoeven1425df82011-07-01 20:39:19 +0200111 generic_handle_irq(irq_num);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112 }
Finn Thain67dfb152007-05-01 22:32:56 +0200113 irq_bit <<= 1;
114 irq_num++;
115 } while(events >= irq_bit);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116#if 0
117 if (baboon->mb_ifr & 0x02) macide_ack_intr(NULL);
118 /* for now we need to smash all interrupts */
119 baboon->mb_ifr &= ~events;
120#endif
121 return IRQ_HANDLED;
122}
Geert Uytterhoeven9145db52011-08-10 12:48:29 +0200123#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124
Adrian Bunk8dfbdf42008-07-17 21:16:25 +0200125/*
126 * Register the Baboon interrupt dispatcher on nubus slot $C.
127 */
128
129void __init baboon_register_interrupts(void)
130{
Finn Thain746e8d32008-11-18 20:45:21 +0100131 baboon_disabled = 0;
Geert Uytterhoeven9145db52011-08-10 12:48:29 +0200132#ifdef CONFIG_GENERIC_HARDIRQS
133 irq_set_chained_handler(IRQ_NUBUS_C, baboon_irq);
134#else
Geert Uytterhoeven92c3dd12008-12-30 14:02:27 +0100135 if (request_irq(IRQ_NUBUS_C, baboon_irq, 0, "baboon", (void *)baboon))
136 pr_err("Couldn't register baboon interrupt\n");
Geert Uytterhoeven9145db52011-08-10 12:48:29 +0200137#endif
Adrian Bunk8dfbdf42008-07-17 21:16:25 +0200138}
139
Finn Thain746e8d32008-11-18 20:45:21 +0100140/*
141 * The means for masking individual baboon interrupts remains a mystery, so
142 * enable the umbrella interrupt only when no baboon interrupt is disabled.
143 */
144
145void baboon_irq_enable(int irq)
146{
147 int irq_idx = IRQ_IDX(irq);
148
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149#ifdef DEBUG_IRQUSE
150 printk("baboon_irq_enable(%d)\n", irq);
151#endif
Finn Thain746e8d32008-11-18 20:45:21 +0100152
153 baboon_disabled &= ~(1 << irq_idx);
154 if (!baboon_disabled)
155 mac_enable_irq(IRQ_NUBUS_C);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156}
157
Finn Thain746e8d32008-11-18 20:45:21 +0100158void baboon_irq_disable(int irq)
159{
160 int irq_idx = IRQ_IDX(irq);
161
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162#ifdef DEBUG_IRQUSE
163 printk("baboon_irq_disable(%d)\n", irq);
164#endif
Finn Thain746e8d32008-11-18 20:45:21 +0100165
166 baboon_disabled |= 1 << irq_idx;
167 if (baboon_disabled)
168 mac_disable_irq(IRQ_NUBUS_C);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169}
170
Finn Thain746e8d32008-11-18 20:45:21 +0100171void baboon_irq_clear(int irq)
172{
173 int irq_idx = IRQ_IDX(irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174
175 baboon->mb_ifr &= ~(1 << irq_idx);
176}
177
178int baboon_irq_pending(int irq)
179{
Finn Thain746e8d32008-11-18 20:45:21 +0100180 int irq_idx = IRQ_IDX(irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181
182 return baboon->mb_ifr & (1 << irq_idx);
183}