1/* linux/arch/arm/mach-s3c2410/bast-irq.c 2 * 3 * Copyright 2003-2005 Simtec Electronics 4 * 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 21*/ 22 23 24#include <linux/init.h> 25#include <linux/module.h> 26#include <linux/ioport.h> 27#include <linux/sysdev.h> 28#include <linux/io.h> 29 30#include <asm/mach-types.h> 31 32#include <mach/hardware.h> 33#include <asm/irq.h> 34 35#include <asm/mach/irq.h> 36 37#include <mach/regs-irq.h> 38#include <mach/bast-map.h> 39#include <mach/bast-irq.h> 40 41#include <plat/irq.h> 42 43 44#define irqdbf(x...) 45#define irqdbf2(x...) 46 47 48/* handle PC104 ISA interrupts from the system CPLD */ 49 50/* table of ISA irq nos to the relevant mask... zero means 51 * the irq is not implemented 52*/ 53static unsigned char bast_pc104_irqmasks[] = { 54 0, /* 0 */ 55 0, /* 1 */ 56 0, /* 2 */ 57 1, /* 3 */ 58 0, /* 4 */ 59 2, /* 5 */ 60 0, /* 6 */ 61 4, /* 7 */ 62 0, /* 8 */ 63 0, /* 9 */ 64 8, /* 10 */ 65 0, /* 11 */ 66 0, /* 12 */ 67 0, /* 13 */ 68 0, /* 14 */ 69 0, /* 15 */ 70}; 71 72static unsigned char bast_pc104_irqs[] = { 3, 5, 7, 10 }; 73 74static void 75bast_pc104_mask(unsigned int irqno) 76{ 77 unsigned long temp; 78 79 temp = __raw_readb(BAST_VA_PC104_IRQMASK); 80 temp &= ~bast_pc104_irqmasks[irqno]; 81 __raw_writeb(temp, BAST_VA_PC104_IRQMASK); 82} 83 84static void 85bast_pc104_maskack(unsigned int irqno) 86{ 87 struct irq_desc *desc = irq_desc + IRQ_ISA; 88 89 bast_pc104_mask(irqno); 90 desc->chip->ack(IRQ_ISA); 91} 92 93static void 94bast_pc104_unmask(unsigned int irqno) 95{ 96 unsigned long temp; 97 98 temp = __raw_readb(BAST_VA_PC104_IRQMASK); 99 temp |= bast_pc104_irqmasks[irqno]; 100 __raw_writeb(temp, BAST_VA_PC104_IRQMASK); 101} 102 103static struct irq_chip bast_pc104_chip = { 104 .mask = bast_pc104_mask, 105 .unmask = bast_pc104_unmask, 106 .ack = bast_pc104_maskack 107}; 108 109static void 110bast_irq_pc104_demux(unsigned int irq, 111 struct irq_desc *desc) 112{ 113 unsigned int stat; 114 unsigned int irqno; 115 int i; 116 117 stat = __raw_readb(BAST_VA_PC104_IRQREQ) & 0xf; 118 119 if (unlikely(stat == 0)) { 120 /* ack if we get an irq with nothing (ie, startup) */ 121 122 desc = irq_desc + IRQ_ISA; 123 desc->chip->ack(IRQ_ISA); 124 } else { 125 /* handle the IRQ */ 126 127 for (i = 0; stat != 0; i++, stat >>= 1) { 128 if (stat & 1) { 129 irqno = bast_pc104_irqs[i]; 130 generic_handle_irq(irqno); 131 } 132 } 133 } 134} 135 136static __init int bast_irq_init(void) 137{ 138 unsigned int i; 139 140 if (machine_is_bast()) { 141 printk(KERN_INFO "BAST PC104 IRQ routing, Copyright 2005 Simtec Electronics\n"); 142 143 /* zap all the IRQs */ 144 145 __raw_writeb(0x0, BAST_VA_PC104_IRQMASK); 146 147 set_irq_chained_handler(IRQ_ISA, bast_irq_pc104_demux); 148 149 /* register our IRQs */ 150 151 for (i = 0; i < 4; i++) { 152 unsigned int irqno = bast_pc104_irqs[i]; 153 154 set_irq_chip(irqno, &bast_pc104_chip); 155 set_irq_handler(irqno, handle_level_irq); 156 set_irq_flags(irqno, IRQF_VALID); 157 } 158 } 159 160 return 0; 161} 162 163arch_initcall(bast_irq_init); 164