Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | |
| 15 | #include <asm/traps.h> |
| 16 | #include <asm/bootinfo.h> |
| 17 | #include <asm/macintosh.h> |
| 18 | #include <asm/macints.h> |
| 19 | #include <asm/mac_baboon.h> |
| 20 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | /* #define DEBUG_IRQS */ |
| 22 | |
Finn Thain | 746e8d3 | 2008-11-18 20:45:21 +0100 | [diff] [blame] | 23 | extern void mac_enable_irq(unsigned int); |
| 24 | extern void mac_disable_irq(unsigned int); |
| 25 | |
Finn Thain | 217f671 | 2007-05-01 22:32:58 +0200 | [diff] [blame] | 26 | int baboon_present; |
Adrian Bunk | 8dfbdf4 | 2008-07-17 21:16:25 +0200 | [diff] [blame] | 27 | static volatile struct baboon *baboon; |
Finn Thain | 746e8d3 | 2008-11-18 20:45:21 +0100 | [diff] [blame] | 28 | static unsigned char baboon_disabled; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | |
| 30 | #if 0 |
| 31 | extern int macide_ack_intr(struct ata_channel *); |
| 32 | #endif |
| 33 | |
| 34 | /* |
| 35 | * Baboon initialization. |
| 36 | */ |
| 37 | |
| 38 | void __init baboon_init(void) |
| 39 | { |
| 40 | if (macintosh_config->ident != MAC_MODEL_PB190) { |
| 41 | baboon = NULL; |
| 42 | baboon_present = 0; |
| 43 | return; |
| 44 | } |
| 45 | |
| 46 | baboon = (struct baboon *) BABOON_BASE; |
| 47 | baboon_present = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | |
| 49 | printk("Baboon detected at %p\n", baboon); |
| 50 | } |
| 51 | |
| 52 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | * Baboon interrupt handler. This works a lot like a VIA. |
| 54 | */ |
| 55 | |
Adrian Bunk | 8dfbdf4 | 2008-07-17 21:16:25 +0200 | [diff] [blame] | 56 | static irqreturn_t baboon_irq(int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | { |
Finn Thain | 67dfb15 | 2007-05-01 22:32:56 +0200 | [diff] [blame] | 58 | int irq_bit, irq_num; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | unsigned char events; |
| 60 | |
| 61 | #ifdef DEBUG_IRQS |
Finn Thain | 217f671 | 2007-05-01 22:32:58 +0200 | [diff] [blame] | 62 | printk("baboon_irq: mb_control %02X mb_ifr %02X mb_status %02X\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | (uint) baboon->mb_control, (uint) baboon->mb_ifr, |
Finn Thain | 217f671 | 2007-05-01 22:32:58 +0200 | [diff] [blame] | 64 | (uint) baboon->mb_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | #endif |
| 66 | |
| 67 | if (!(events = baboon->mb_ifr & 0x07)) |
| 68 | return IRQ_NONE; |
| 69 | |
Finn Thain | 67dfb15 | 2007-05-01 22:32:56 +0200 | [diff] [blame] | 70 | irq_num = IRQ_BABOON_0; |
| 71 | irq_bit = 1; |
| 72 | do { |
Finn Thain | 217f671 | 2007-05-01 22:32:58 +0200 | [diff] [blame] | 73 | if (events & irq_bit) { |
Finn Thain | 647b804 | 2007-05-01 22:32:55 +0200 | [diff] [blame] | 74 | baboon->mb_ifr &= ~irq_bit; |
Finn Thain | 67dfb15 | 2007-05-01 22:32:56 +0200 | [diff] [blame] | 75 | m68k_handle_int(irq_num); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | } |
Finn Thain | 67dfb15 | 2007-05-01 22:32:56 +0200 | [diff] [blame] | 77 | irq_bit <<= 1; |
| 78 | irq_num++; |
| 79 | } while(events >= irq_bit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | #if 0 |
| 81 | if (baboon->mb_ifr & 0x02) macide_ack_intr(NULL); |
| 82 | /* for now we need to smash all interrupts */ |
| 83 | baboon->mb_ifr &= ~events; |
| 84 | #endif |
| 85 | return IRQ_HANDLED; |
| 86 | } |
| 87 | |
Adrian Bunk | 8dfbdf4 | 2008-07-17 21:16:25 +0200 | [diff] [blame] | 88 | /* |
| 89 | * Register the Baboon interrupt dispatcher on nubus slot $C. |
| 90 | */ |
| 91 | |
| 92 | void __init baboon_register_interrupts(void) |
| 93 | { |
Finn Thain | 746e8d3 | 2008-11-18 20:45:21 +0100 | [diff] [blame] | 94 | baboon_disabled = 0; |
| 95 | request_irq(IRQ_NUBUS_C, baboon_irq, 0, "baboon", (void *)baboon); |
Adrian Bunk | 8dfbdf4 | 2008-07-17 21:16:25 +0200 | [diff] [blame] | 96 | } |
| 97 | |
Finn Thain | 746e8d3 | 2008-11-18 20:45:21 +0100 | [diff] [blame] | 98 | /* |
| 99 | * The means for masking individual baboon interrupts remains a mystery, so |
| 100 | * enable the umbrella interrupt only when no baboon interrupt is disabled. |
| 101 | */ |
| 102 | |
| 103 | void baboon_irq_enable(int irq) |
| 104 | { |
| 105 | int irq_idx = IRQ_IDX(irq); |
| 106 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | #ifdef DEBUG_IRQUSE |
| 108 | printk("baboon_irq_enable(%d)\n", irq); |
| 109 | #endif |
Finn Thain | 746e8d3 | 2008-11-18 20:45:21 +0100 | [diff] [blame] | 110 | |
| 111 | baboon_disabled &= ~(1 << irq_idx); |
| 112 | if (!baboon_disabled) |
| 113 | mac_enable_irq(IRQ_NUBUS_C); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | } |
| 115 | |
Finn Thain | 746e8d3 | 2008-11-18 20:45:21 +0100 | [diff] [blame] | 116 | void baboon_irq_disable(int irq) |
| 117 | { |
| 118 | int irq_idx = IRQ_IDX(irq); |
| 119 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | #ifdef DEBUG_IRQUSE |
| 121 | printk("baboon_irq_disable(%d)\n", irq); |
| 122 | #endif |
Finn Thain | 746e8d3 | 2008-11-18 20:45:21 +0100 | [diff] [blame] | 123 | |
| 124 | baboon_disabled |= 1 << irq_idx; |
| 125 | if (baboon_disabled) |
| 126 | mac_disable_irq(IRQ_NUBUS_C); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | } |
| 128 | |
Finn Thain | 746e8d3 | 2008-11-18 20:45:21 +0100 | [diff] [blame] | 129 | void baboon_irq_clear(int irq) |
| 130 | { |
| 131 | int irq_idx = IRQ_IDX(irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | |
| 133 | baboon->mb_ifr &= ~(1 << irq_idx); |
| 134 | } |
| 135 | |
| 136 | int baboon_irq_pending(int irq) |
| 137 | { |
Finn Thain | 746e8d3 | 2008-11-18 20:45:21 +0100 | [diff] [blame] | 138 | int irq_idx = IRQ_IDX(irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | |
| 140 | return baboon->mb_ifr & (1 << irq_idx); |
| 141 | } |