blob: 2bb08961e934ca91c704e32b6f0a324516157e17 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* linux/arch/arm/mach-s3c2410/bast-irq.c
2 *
Ben Dooksccae9412009-11-13 22:54:14 +00003 * Copyright 2003-2005 Simtec Electronics
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 * Ben Dooks <ben@simtec.co.uk>
5 *
6 * http://www.simtec.co.uk/products/EB2410ITX/
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Ben Dooksbafa49c2005-09-07 17:24:48 +010021*/
Linus Torvalds1da177e2005-04-16 15:20:36 -070022
23
24#include <linux/init.h>
25#include <linux/module.h>
26#include <linux/ioport.h>
Kay Sieversedbaa602011-12-21 16:26:03 -080027#include <linux/device.h>
Russell Kingfced80c2008-09-06 12:10:45 +010028#include <linux/io.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070029
Linus Torvalds1da177e2005-04-16 15:20:36 -070030#include <asm/irq.h>
Kukjin Kimbbd7e5e2013-01-01 19:56:20 -080031#include <asm/mach-types.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#include <asm/mach/irq.h>
Ben Dooksbafa49c2005-09-07 17:24:48 +010033
Kukjin Kimbbd7e5e2013-01-01 19:56:20 -080034#include <mach/hardware.h>
Russell Kinga09e64f2008-08-05 16:14:15 +010035#include <mach/regs-irq.h>
Ben Dooksbafa49c2005-09-07 17:24:48 +010036
Kukjin Kimbbd7e5e2013-01-01 19:56:20 -080037#include "bast.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070038
39#define irqdbf(x...)
40#define irqdbf2(x...)
41
Linus Torvalds1da177e2005-04-16 15:20:36 -070042/* handle PC104 ISA interrupts from the system CPLD */
43
44/* table of ISA irq nos to the relevant mask... zero means
45 * the irq is not implemented
46*/
47static unsigned char bast_pc104_irqmasks[] = {
48 0, /* 0 */
49 0, /* 1 */
50 0, /* 2 */
51 1, /* 3 */
52 0, /* 4 */
53 2, /* 5 */
54 0, /* 6 */
55 4, /* 7 */
56 0, /* 8 */
57 0, /* 9 */
58 8, /* 10 */
59 0, /* 11 */
60 0, /* 12 */
61 0, /* 13 */
62 0, /* 14 */
63 0, /* 15 */
64};
65
66static unsigned char bast_pc104_irqs[] = { 3, 5, 7, 10 };
67
68static void
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +090069bast_pc104_mask(struct irq_data *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -070070{
71 unsigned long temp;
72
73 temp = __raw_readb(BAST_VA_PC104_IRQMASK);
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +090074 temp &= ~bast_pc104_irqmasks[data->irq];
Linus Torvalds1da177e2005-04-16 15:20:36 -070075 __raw_writeb(temp, BAST_VA_PC104_IRQMASK);
Linus Torvalds1da177e2005-04-16 15:20:36 -070076}
77
78static void
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +090079bast_pc104_maskack(struct irq_data *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -070080{
Kukjin Kimbbd7e5e2013-01-01 19:56:20 -080081 struct irq_desc *desc = irq_desc + BAST_IRQ_ISA;
Ben Dooksbafa49c2005-09-07 17:24:48 +010082
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +090083 bast_pc104_mask(data);
84 desc->irq_data.chip->irq_ack(&desc->irq_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -070085}
86
87static void
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +090088bast_pc104_unmask(struct irq_data *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -070089{
90 unsigned long temp;
91
92 temp = __raw_readb(BAST_VA_PC104_IRQMASK);
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +090093 temp |= bast_pc104_irqmasks[data->irq];
Linus Torvalds1da177e2005-04-16 15:20:36 -070094 __raw_writeb(temp, BAST_VA_PC104_IRQMASK);
Linus Torvalds1da177e2005-04-16 15:20:36 -070095}
96
Russell King10dd5ce2006-11-23 11:41:32 +000097static struct irq_chip bast_pc104_chip = {
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +090098 .irq_mask = bast_pc104_mask,
99 .irq_unmask = bast_pc104_unmask,
100 .irq_ack = bast_pc104_maskack
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101};
102
Thomas Gleixnerbd0b9ac2015-09-14 10:42:37 +0200103static void bast_irq_pc104_demux(struct irq_desc *desc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104{
105 unsigned int stat;
106 unsigned int irqno;
107 int i;
108
109 stat = __raw_readb(BAST_VA_PC104_IRQREQ) & 0xf;
110
Ben Dooksbafa49c2005-09-07 17:24:48 +0100111 if (unlikely(stat == 0)) {
112 /* ack if we get an irq with nothing (ie, startup) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113
Kukjin Kimbbd7e5e2013-01-01 19:56:20 -0800114 desc = irq_desc + BAST_IRQ_ISA;
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +0900115 desc->irq_data.chip->irq_ack(&desc->irq_data);
Ben Dooksbafa49c2005-09-07 17:24:48 +0100116 } else {
117 /* handle the IRQ */
118
119 for (i = 0; stat != 0; i++, stat >>= 1) {
120 if (stat & 1) {
121 irqno = bast_pc104_irqs[i];
Dmitry Baryshkovd8aa0252008-10-09 13:36:24 +0100122 generic_handle_irq(irqno);
Ben Dooksbafa49c2005-09-07 17:24:48 +0100123 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125 }
126}
Ben Dooksbafa49c2005-09-07 17:24:48 +0100127
128static __init int bast_irq_init(void)
129{
130 unsigned int i;
131
132 if (machine_is_bast()) {
Ben Dooks50f430e2009-11-13 22:54:12 +0000133 printk(KERN_INFO "BAST PC104 IRQ routing, Copyright 2005 Simtec Electronics\n");
Ben Dooksbafa49c2005-09-07 17:24:48 +0100134
135 /* zap all the IRQs */
136
137 __raw_writeb(0x0, BAST_VA_PC104_IRQMASK);
138
Kukjin Kimbbd7e5e2013-01-01 19:56:20 -0800139 irq_set_chained_handler(BAST_IRQ_ISA, bast_irq_pc104_demux);
Ben Dooksbafa49c2005-09-07 17:24:48 +0100140
Thomas Gleixner544b46d2006-07-01 22:32:39 +0100141 /* register our IRQs */
Ben Dooksbafa49c2005-09-07 17:24:48 +0100142
143 for (i = 0; i < 4; i++) {
144 unsigned int irqno = bast_pc104_irqs[i];
145
Thomas Gleixnerf38c02f2011-03-24 13:35:09 +0100146 irq_set_chip_and_handler(irqno, &bast_pc104_chip,
147 handle_level_irq);
Rob Herringe8d36d52015-07-27 15:55:13 -0500148 irq_clear_status_flags(irqno, IRQ_NOREQUEST);
Ben Dooksbafa49c2005-09-07 17:24:48 +0100149 }
150 }
151
152 return 0;
153}
154
155arch_initcall(bast_irq_init);