| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* | 
|  | 2 | *  linux/arch/arm/mach-footbridge/irq.c | 
|  | 3 | * | 
|  | 4 | *  Copyright (C) 1996-2000 Russell King | 
|  | 5 | * | 
|  | 6 | * This program is free software; you can redistribute it and/or modify | 
|  | 7 | * it under the terms of the GNU General Public License version 2 as | 
|  | 8 | * published by the Free Software Foundation. | 
|  | 9 | * | 
|  | 10 | *  Changelog: | 
|  | 11 | *   22-Aug-1998 RMK	Restructured IRQ routines | 
|  | 12 | *   03-Sep-1998 PJB	Merged CATS support | 
|  | 13 | *   20-Jan-1998 RMK	Started merge of EBSA286, CATS and NetWinder | 
|  | 14 | *   26-Jan-1999 PJB	Don't use IACK on CATS | 
|  | 15 | *   16-Mar-1999 RMK	Added autodetect of ISA PICs | 
|  | 16 | */ | 
|  | 17 | #include <linux/ioport.h> | 
|  | 18 | #include <linux/interrupt.h> | 
|  | 19 | #include <linux/list.h> | 
|  | 20 | #include <linux/init.h> | 
| Russell King | fced80c | 2008-09-06 12:10:45 +0100 | [diff] [blame] | 21 | #include <linux/io.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 |  | 
|  | 23 | #include <asm/mach/irq.h> | 
|  | 24 |  | 
| Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 25 | #include <mach/hardware.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | #include <asm/hardware/dec21285.h> | 
|  | 27 | #include <asm/irq.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | #include <asm/mach-types.h> | 
|  | 29 |  | 
|  | 30 | static void isa_mask_pic_lo_irq(unsigned int irq) | 
|  | 31 | { | 
|  | 32 | unsigned int mask = 1 << (irq & 7); | 
|  | 33 |  | 
|  | 34 | outb(inb(PIC_MASK_LO) | mask, PIC_MASK_LO); | 
|  | 35 | } | 
|  | 36 |  | 
|  | 37 | static void isa_ack_pic_lo_irq(unsigned int irq) | 
|  | 38 | { | 
|  | 39 | unsigned int mask = 1 << (irq & 7); | 
|  | 40 |  | 
|  | 41 | outb(inb(PIC_MASK_LO) | mask, PIC_MASK_LO); | 
|  | 42 | outb(0x20, PIC_LO); | 
|  | 43 | } | 
|  | 44 |  | 
|  | 45 | static void isa_unmask_pic_lo_irq(unsigned int irq) | 
|  | 46 | { | 
|  | 47 | unsigned int mask = 1 << (irq & 7); | 
|  | 48 |  | 
|  | 49 | outb(inb(PIC_MASK_LO) & ~mask, PIC_MASK_LO); | 
|  | 50 | } | 
|  | 51 |  | 
| Russell King | 10dd5ce | 2006-11-23 11:41:32 +0000 | [diff] [blame] | 52 | static struct irq_chip isa_lo_chip = { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | .ack	= isa_ack_pic_lo_irq, | 
|  | 54 | .mask	= isa_mask_pic_lo_irq, | 
|  | 55 | .unmask = isa_unmask_pic_lo_irq, | 
|  | 56 | }; | 
|  | 57 |  | 
|  | 58 | static void isa_mask_pic_hi_irq(unsigned int irq) | 
|  | 59 | { | 
|  | 60 | unsigned int mask = 1 << (irq & 7); | 
|  | 61 |  | 
|  | 62 | outb(inb(PIC_MASK_HI) | mask, PIC_MASK_HI); | 
|  | 63 | } | 
|  | 64 |  | 
|  | 65 | static void isa_ack_pic_hi_irq(unsigned int irq) | 
|  | 66 | { | 
|  | 67 | unsigned int mask = 1 << (irq & 7); | 
|  | 68 |  | 
|  | 69 | outb(inb(PIC_MASK_HI) | mask, PIC_MASK_HI); | 
|  | 70 | outb(0x62, PIC_LO); | 
|  | 71 | outb(0x20, PIC_HI); | 
|  | 72 | } | 
|  | 73 |  | 
|  | 74 | static void isa_unmask_pic_hi_irq(unsigned int irq) | 
|  | 75 | { | 
|  | 76 | unsigned int mask = 1 << (irq & 7); | 
|  | 77 |  | 
|  | 78 | outb(inb(PIC_MASK_HI) & ~mask, PIC_MASK_HI); | 
|  | 79 | } | 
|  | 80 |  | 
| Russell King | 10dd5ce | 2006-11-23 11:41:32 +0000 | [diff] [blame] | 81 | static struct irq_chip isa_hi_chip = { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | .ack	= isa_ack_pic_hi_irq, | 
|  | 83 | .mask	= isa_mask_pic_hi_irq, | 
|  | 84 | .unmask = isa_unmask_pic_hi_irq, | 
|  | 85 | }; | 
|  | 86 |  | 
|  | 87 | static void | 
| Russell King | 10dd5ce | 2006-11-23 11:41:32 +0000 | [diff] [blame] | 88 | isa_irq_handler(unsigned int irq, struct irq_desc *desc) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | { | 
|  | 90 | unsigned int isa_irq = *(unsigned char *)PCIIACK_BASE; | 
|  | 91 |  | 
|  | 92 | if (isa_irq < _ISA_IRQ(0) || isa_irq >= _ISA_IRQ(16)) { | 
| Linus Torvalds | 0cd61b6 | 2006-10-06 10:53:39 -0700 | [diff] [blame] | 93 | do_bad_IRQ(isa_irq, desc); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | return; | 
|  | 95 | } | 
|  | 96 |  | 
| Dmitry Baryshkov | d8aa025 | 2008-10-09 13:36:24 +0100 | [diff] [blame] | 97 | generic_handle_irq(isa_irq); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | } | 
|  | 99 |  | 
| Russell King | 020732a | 2006-07-03 13:18:04 +0100 | [diff] [blame] | 100 | static struct irqaction irq_cascade = { | 
|  | 101 | .handler = no_action, | 
|  | 102 | .name = "cascade", | 
|  | 103 | }; | 
|  | 104 |  | 
|  | 105 | static struct resource pic1_resource = { | 
|  | 106 | .name	= "pic1", | 
|  | 107 | .start	= 0x20, | 
|  | 108 | .end	= 0x3f, | 
|  | 109 | }; | 
|  | 110 |  | 
|  | 111 | static struct resource pic2_resource = { | 
|  | 112 | .name	= "pic2", | 
|  | 113 | .start	= 0xa0, | 
|  | 114 | .end	= 0xbf, | 
|  | 115 | }; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 |  | 
|  | 117 | void __init isa_init_irq(unsigned int host_irq) | 
|  | 118 | { | 
|  | 119 | unsigned int irq; | 
|  | 120 |  | 
|  | 121 | /* | 
|  | 122 | * Setup, and then probe for an ISA PIC | 
|  | 123 | * If the PIC is not there, then we | 
|  | 124 | * ignore the PIC. | 
|  | 125 | */ | 
|  | 126 | outb(0x11, PIC_LO); | 
|  | 127 | outb(_ISA_IRQ(0), PIC_MASK_LO);	/* IRQ number		*/ | 
|  | 128 | outb(0x04, PIC_MASK_LO);	/* Slave on Ch2		*/ | 
|  | 129 | outb(0x01, PIC_MASK_LO);	/* x86			*/ | 
|  | 130 | outb(0xf5, PIC_MASK_LO);	/* pattern: 11110101	*/ | 
|  | 131 |  | 
|  | 132 | outb(0x11, PIC_HI); | 
|  | 133 | outb(_ISA_IRQ(8), PIC_MASK_HI);	/* IRQ number		*/ | 
|  | 134 | outb(0x02, PIC_MASK_HI);	/* Slave on Ch1		*/ | 
|  | 135 | outb(0x01, PIC_MASK_HI);	/* x86			*/ | 
|  | 136 | outb(0xfa, PIC_MASK_HI);	/* pattern: 11111010	*/ | 
|  | 137 |  | 
|  | 138 | outb(0x0b, PIC_LO); | 
|  | 139 | outb(0x0b, PIC_HI); | 
|  | 140 |  | 
|  | 141 | if (inb(PIC_MASK_LO) == 0xf5 && inb(PIC_MASK_HI) == 0xfa) { | 
|  | 142 | outb(0xff, PIC_MASK_LO);/* mask all IRQs	*/ | 
|  | 143 | outb(0xff, PIC_MASK_HI);/* mask all IRQs	*/ | 
|  | 144 | } else { | 
|  | 145 | printk(KERN_INFO "IRQ: ISA PIC not found\n"); | 
|  | 146 | host_irq = (unsigned int)-1; | 
|  | 147 | } | 
|  | 148 |  | 
|  | 149 | if (host_irq != (unsigned int)-1) { | 
|  | 150 | for (irq = _ISA_IRQ(0); irq < _ISA_IRQ(8); irq++) { | 
|  | 151 | set_irq_chip(irq, &isa_lo_chip); | 
| Russell King | 10dd5ce | 2006-11-23 11:41:32 +0000 | [diff] [blame] | 152 | set_irq_handler(irq, handle_level_irq); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | set_irq_flags(irq, IRQF_VALID | IRQF_PROBE); | 
|  | 154 | } | 
|  | 155 |  | 
|  | 156 | for (irq = _ISA_IRQ(8); irq < _ISA_IRQ(16); irq++) { | 
|  | 157 | set_irq_chip(irq, &isa_hi_chip); | 
| Russell King | 10dd5ce | 2006-11-23 11:41:32 +0000 | [diff] [blame] | 158 | set_irq_handler(irq, handle_level_irq); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | set_irq_flags(irq, IRQF_VALID | IRQF_PROBE); | 
|  | 160 | } | 
|  | 161 |  | 
|  | 162 | request_resource(&ioport_resource, &pic1_resource); | 
|  | 163 | request_resource(&ioport_resource, &pic2_resource); | 
|  | 164 | setup_irq(IRQ_ISA_CASCADE, &irq_cascade); | 
|  | 165 |  | 
|  | 166 | set_irq_chained_handler(host_irq, isa_irq_handler); | 
|  | 167 |  | 
|  | 168 | /* | 
|  | 169 | * On the NetWinder, don't automatically | 
|  | 170 | * enable ISA IRQ11 when it is requested. | 
|  | 171 | * There appears to be a missing pull-up | 
|  | 172 | * resistor on this line. | 
|  | 173 | */ | 
|  | 174 | if (machine_is_netwinder()) | 
|  | 175 | set_irq_flags(_ISA_IRQ(11), IRQF_VALID | | 
|  | 176 | IRQF_PROBE | IRQF_NOAUTOEN); | 
|  | 177 | } | 
|  | 178 | } | 
|  | 179 |  | 
|  | 180 |  |