blob: c01fca11b224cfbc78f3038f581f9d95f56b3f35 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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 Kingfced80c2008-09-06 12:10:45 +010021#include <linux/io.h>
Russell King70d13e02008-12-06 08:25:16 +000022#include <linux/spinlock.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070023
24#include <asm/mach/irq.h>
25
Russell Kinga09e64f2008-08-05 16:14:15 +010026#include <mach/hardware.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070027#include <asm/hardware/dec21285.h>
28#include <asm/irq.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070029#include <asm/mach-types.h>
30
Ben Dooks39ebfd32009-01-08 15:42:41 +000031#include "common.h"
32
Lennert Buytenhekdc2caf62010-11-29 10:30:13 +010033static void isa_mask_pic_lo_irq(struct irq_data *d)
Linus Torvalds1da177e2005-04-16 15:20:36 -070034{
Lennert Buytenhekdc2caf62010-11-29 10:30:13 +010035 unsigned int mask = 1 << (d->irq & 7);
Linus Torvalds1da177e2005-04-16 15:20:36 -070036
37 outb(inb(PIC_MASK_LO) | mask, PIC_MASK_LO);
38}
39
Lennert Buytenhekdc2caf62010-11-29 10:30:13 +010040static void isa_ack_pic_lo_irq(struct irq_data *d)
Linus Torvalds1da177e2005-04-16 15:20:36 -070041{
Lennert Buytenhekdc2caf62010-11-29 10:30:13 +010042 unsigned int mask = 1 << (d->irq & 7);
Linus Torvalds1da177e2005-04-16 15:20:36 -070043
44 outb(inb(PIC_MASK_LO) | mask, PIC_MASK_LO);
45 outb(0x20, PIC_LO);
46}
47
Lennert Buytenhekdc2caf62010-11-29 10:30:13 +010048static void isa_unmask_pic_lo_irq(struct irq_data *d)
Linus Torvalds1da177e2005-04-16 15:20:36 -070049{
Lennert Buytenhekdc2caf62010-11-29 10:30:13 +010050 unsigned int mask = 1 << (d->irq & 7);
Linus Torvalds1da177e2005-04-16 15:20:36 -070051
52 outb(inb(PIC_MASK_LO) & ~mask, PIC_MASK_LO);
53}
54
Russell King10dd5ce2006-11-23 11:41:32 +000055static struct irq_chip isa_lo_chip = {
Lennert Buytenhekdc2caf62010-11-29 10:30:13 +010056 .irq_ack = isa_ack_pic_lo_irq,
57 .irq_mask = isa_mask_pic_lo_irq,
58 .irq_unmask = isa_unmask_pic_lo_irq,
Linus Torvalds1da177e2005-04-16 15:20:36 -070059};
60
Lennert Buytenhekdc2caf62010-11-29 10:30:13 +010061static void isa_mask_pic_hi_irq(struct irq_data *d)
Linus Torvalds1da177e2005-04-16 15:20:36 -070062{
Lennert Buytenhekdc2caf62010-11-29 10:30:13 +010063 unsigned int mask = 1 << (d->irq & 7);
Linus Torvalds1da177e2005-04-16 15:20:36 -070064
65 outb(inb(PIC_MASK_HI) | mask, PIC_MASK_HI);
66}
67
Lennert Buytenhekdc2caf62010-11-29 10:30:13 +010068static void isa_ack_pic_hi_irq(struct irq_data *d)
Linus Torvalds1da177e2005-04-16 15:20:36 -070069{
Lennert Buytenhekdc2caf62010-11-29 10:30:13 +010070 unsigned int mask = 1 << (d->irq & 7);
Linus Torvalds1da177e2005-04-16 15:20:36 -070071
72 outb(inb(PIC_MASK_HI) | mask, PIC_MASK_HI);
73 outb(0x62, PIC_LO);
74 outb(0x20, PIC_HI);
75}
76
Lennert Buytenhekdc2caf62010-11-29 10:30:13 +010077static void isa_unmask_pic_hi_irq(struct irq_data *d)
Linus Torvalds1da177e2005-04-16 15:20:36 -070078{
Lennert Buytenhekdc2caf62010-11-29 10:30:13 +010079 unsigned int mask = 1 << (d->irq & 7);
Linus Torvalds1da177e2005-04-16 15:20:36 -070080
81 outb(inb(PIC_MASK_HI) & ~mask, PIC_MASK_HI);
82}
83
Russell King10dd5ce2006-11-23 11:41:32 +000084static struct irq_chip isa_hi_chip = {
Lennert Buytenhekdc2caf62010-11-29 10:30:13 +010085 .irq_ack = isa_ack_pic_hi_irq,
86 .irq_mask = isa_mask_pic_hi_irq,
87 .irq_unmask = isa_unmask_pic_hi_irq,
Linus Torvalds1da177e2005-04-16 15:20:36 -070088};
89
Thomas Gleixnerbd0b9ac2015-09-14 10:42:37 +020090static void isa_irq_handler(struct irq_desc *desc)
Linus Torvalds1da177e2005-04-16 15:20:36 -070091{
92 unsigned int isa_irq = *(unsigned char *)PCIIACK_BASE;
93
94 if (isa_irq < _ISA_IRQ(0) || isa_irq >= _ISA_IRQ(16)) {
Thomas Gleixnerbd0b9ac2015-09-14 10:42:37 +020095 do_bad_IRQ(desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -070096 return;
97 }
98
Dmitry Baryshkovd8aa0252008-10-09 13:36:24 +010099 generic_handle_irq(isa_irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100}
101
Russell King020732a2006-07-03 13:18:04 +0100102static struct irqaction irq_cascade = {
103 .handler = no_action,
104 .name = "cascade",
105};
106
107static struct resource pic1_resource = {
108 .name = "pic1",
109 .start = 0x20,
110 .end = 0x3f,
111};
112
113static struct resource pic2_resource = {
114 .name = "pic2",
115 .start = 0xa0,
116 .end = 0xbf,
117};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118
119void __init isa_init_irq(unsigned int host_irq)
120{
121 unsigned int irq;
122
123 /*
124 * Setup, and then probe for an ISA PIC
125 * If the PIC is not there, then we
126 * ignore the PIC.
127 */
128 outb(0x11, PIC_LO);
129 outb(_ISA_IRQ(0), PIC_MASK_LO); /* IRQ number */
130 outb(0x04, PIC_MASK_LO); /* Slave on Ch2 */
131 outb(0x01, PIC_MASK_LO); /* x86 */
132 outb(0xf5, PIC_MASK_LO); /* pattern: 11110101 */
133
134 outb(0x11, PIC_HI);
135 outb(_ISA_IRQ(8), PIC_MASK_HI); /* IRQ number */
136 outb(0x02, PIC_MASK_HI); /* Slave on Ch1 */
137 outb(0x01, PIC_MASK_HI); /* x86 */
138 outb(0xfa, PIC_MASK_HI); /* pattern: 11111010 */
139
140 outb(0x0b, PIC_LO);
141 outb(0x0b, PIC_HI);
142
143 if (inb(PIC_MASK_LO) == 0xf5 && inb(PIC_MASK_HI) == 0xfa) {
144 outb(0xff, PIC_MASK_LO);/* mask all IRQs */
145 outb(0xff, PIC_MASK_HI);/* mask all IRQs */
146 } else {
147 printk(KERN_INFO "IRQ: ISA PIC not found\n");
148 host_irq = (unsigned int)-1;
149 }
150
151 if (host_irq != (unsigned int)-1) {
152 for (irq = _ISA_IRQ(0); irq < _ISA_IRQ(8); irq++) {
Thomas Gleixnerf38c02f2011-03-24 13:35:09 +0100153 irq_set_chip_and_handler(irq, &isa_lo_chip,
154 handle_level_irq);
Rob Herringe8d36d52015-07-27 15:55:13 -0500155 irq_clear_status_flags(irq, IRQ_NOREQUEST | IRQ_NOPROBE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 }
157
158 for (irq = _ISA_IRQ(8); irq < _ISA_IRQ(16); irq++) {
Thomas Gleixnerf38c02f2011-03-24 13:35:09 +0100159 irq_set_chip_and_handler(irq, &isa_hi_chip,
160 handle_level_irq);
Rob Herringe8d36d52015-07-27 15:55:13 -0500161 irq_clear_status_flags(irq, IRQ_NOREQUEST | IRQ_NOPROBE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162 }
163
164 request_resource(&ioport_resource, &pic1_resource);
165 request_resource(&ioport_resource, &pic2_resource);
166 setup_irq(IRQ_ISA_CASCADE, &irq_cascade);
167
Thomas Gleixner6845664a2011-03-24 13:25:22 +0100168 irq_set_chained_handler(host_irq, isa_irq_handler);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169
170 /*
171 * On the NetWinder, don't automatically
172 * enable ISA IRQ11 when it is requested.
173 * There appears to be a missing pull-up
174 * resistor on this line.
175 */
176 if (machine_is_netwinder())
Rob Herringe8d36d52015-07-27 15:55:13 -0500177 irq_modify_status(_ISA_IRQ(11),
178 IRQ_NOREQUEST | IRQ_NOPROBE, IRQ_NOAUTOEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179 }
180}
181
182