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> |
| 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 | |
Finn Thain | 217f671 | 2007-05-01 22:32:58 +0200 | [diff] [blame] | 25 | int baboon_present; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | volatile struct baboon *baboon; |
| 27 | |
Al Viro | 2850bc2 | 2006-10-07 14:16:45 +0100 | [diff] [blame] | 28 | irqreturn_t baboon_irq(int, void *); |
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 | /* |
| 53 | * Register the Baboon interrupt dispatcher on nubus slot $C. |
| 54 | */ |
| 55 | |
| 56 | void __init baboon_register_interrupts(void) |
| 57 | { |
| 58 | request_irq(IRQ_NUBUS_C, baboon_irq, IRQ_FLG_LOCK|IRQ_FLG_FAST, |
| 59 | "baboon", (void *) baboon); |
| 60 | } |
| 61 | |
| 62 | /* |
| 63 | * Baboon interrupt handler. This works a lot like a VIA. |
| 64 | */ |
| 65 | |
Al Viro | 2850bc2 | 2006-10-07 14:16:45 +0100 | [diff] [blame] | 66 | irqreturn_t baboon_irq(int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | { |
Finn Thain | 67dfb15 | 2007-05-01 22:32:56 +0200 | [diff] [blame] | 68 | int irq_bit, irq_num; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | unsigned char events; |
| 70 | |
| 71 | #ifdef DEBUG_IRQS |
Finn Thain | 217f671 | 2007-05-01 22:32:58 +0200 | [diff] [blame] | 72 | 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] | 73 | (uint) baboon->mb_control, (uint) baboon->mb_ifr, |
Finn Thain | 217f671 | 2007-05-01 22:32:58 +0200 | [diff] [blame] | 74 | (uint) baboon->mb_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | #endif |
| 76 | |
| 77 | if (!(events = baboon->mb_ifr & 0x07)) |
| 78 | return IRQ_NONE; |
| 79 | |
Finn Thain | 67dfb15 | 2007-05-01 22:32:56 +0200 | [diff] [blame] | 80 | irq_num = IRQ_BABOON_0; |
| 81 | irq_bit = 1; |
| 82 | do { |
Finn Thain | 217f671 | 2007-05-01 22:32:58 +0200 | [diff] [blame] | 83 | if (events & irq_bit) { |
Finn Thain | 647b804 | 2007-05-01 22:32:55 +0200 | [diff] [blame] | 84 | baboon->mb_ifr &= ~irq_bit; |
Finn Thain | 67dfb15 | 2007-05-01 22:32:56 +0200 | [diff] [blame] | 85 | m68k_handle_int(irq_num); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | } |
Finn Thain | 67dfb15 | 2007-05-01 22:32:56 +0200 | [diff] [blame] | 87 | irq_bit <<= 1; |
| 88 | irq_num++; |
| 89 | } while(events >= irq_bit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | #if 0 |
| 91 | if (baboon->mb_ifr & 0x02) macide_ack_intr(NULL); |
| 92 | /* for now we need to smash all interrupts */ |
| 93 | baboon->mb_ifr &= ~events; |
| 94 | #endif |
| 95 | return IRQ_HANDLED; |
| 96 | } |
| 97 | |
| 98 | void baboon_irq_enable(int irq) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | #ifdef DEBUG_IRQUSE |
| 100 | printk("baboon_irq_enable(%d)\n", irq); |
| 101 | #endif |
Finn Thain | 217f671 | 2007-05-01 22:32:58 +0200 | [diff] [blame] | 102 | /* FIXME: figure out how to mask and unmask baboon interrupt sources */ |
| 103 | enable_irq(IRQ_NUBUS_C); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | void baboon_irq_disable(int irq) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | #ifdef DEBUG_IRQUSE |
| 108 | printk("baboon_irq_disable(%d)\n", irq); |
| 109 | #endif |
Finn Thain | 217f671 | 2007-05-01 22:32:58 +0200 | [diff] [blame] | 110 | disable_irq(IRQ_NUBUS_C); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | void baboon_irq_clear(int irq) { |
| 114 | int irq_idx = IRQ_IDX(irq); |
| 115 | |
| 116 | baboon->mb_ifr &= ~(1 << irq_idx); |
| 117 | } |
| 118 | |
| 119 | int baboon_irq_pending(int irq) |
| 120 | { |
| 121 | int irq_idx = IRQ_IDX(irq); |
| 122 | |
| 123 | return baboon->mb_ifr & (1 << irq_idx); |
| 124 | } |