Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* irq-mb93093.c: MB93093 FPGA interrupt handling |
| 2 | * |
| 3 | * Copyright (C) 2004 Red Hat, Inc. All Rights Reserved. |
| 4 | * Written by David Howells (dhowells@redhat.com) |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License |
| 8 | * as published by the Free Software Foundation; either version |
| 9 | * 2 of the License, or (at your option) any later version. |
| 10 | */ |
| 11 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | #include <linux/ptrace.h> |
| 13 | #include <linux/errno.h> |
| 14 | #include <linux/signal.h> |
| 15 | #include <linux/sched.h> |
| 16 | #include <linux/ioport.h> |
| 17 | #include <linux/interrupt.h> |
| 18 | #include <linux/init.h> |
| 19 | #include <linux/irq.h> |
| 20 | |
| 21 | #include <asm/io.h> |
| 22 | #include <asm/system.h> |
| 23 | #include <asm/bitops.h> |
| 24 | #include <asm/delay.h> |
| 25 | #include <asm/irq.h> |
| 26 | #include <asm/irc-regs.h> |
| 27 | #include <asm/irq-routing.h> |
| 28 | |
| 29 | #define __reg16(ADDR) (*(volatile unsigned short *)(__region_CS2 + (ADDR))) |
| 30 | |
| 31 | #define __get_IMR() ({ __reg16(0x0a); }) |
| 32 | #define __set_IMR(M) do { __reg16(0x0a) = (M); wmb(); } while(0) |
| 33 | #define __get_IFR() ({ __reg16(0x02); }) |
| 34 | #define __clr_IFR(M) do { __reg16(0x02) = ~(M); wmb(); } while(0) |
| 35 | |
| 36 | static void frv_fpga_doirq(struct irq_source *source); |
| 37 | static void frv_fpga_control(struct irq_group *group, int irq, int on); |
| 38 | |
| 39 | /*****************************************************************************/ |
| 40 | /* |
| 41 | * FPGA IRQ multiplexor |
| 42 | */ |
| 43 | static struct irq_source frv_fpga[4] = { |
| 44 | #define __FPGA(X, M) \ |
| 45 | [X] = { \ |
| 46 | .muxname = "fpga."#X, \ |
| 47 | .irqmask = M, \ |
| 48 | .doirq = frv_fpga_doirq, \ |
| 49 | } |
| 50 | |
| 51 | __FPGA(0, 0x0700), |
| 52 | }; |
| 53 | |
| 54 | static struct irq_group frv_fpga_irqs = { |
| 55 | .first_irq = IRQ_BASE_FPGA, |
| 56 | .control = frv_fpga_control, |
| 57 | .sources = { |
| 58 | [ 8] = &frv_fpga[0], |
| 59 | [ 9] = &frv_fpga[0], |
| 60 | [10] = &frv_fpga[0], |
| 61 | }, |
| 62 | }; |
| 63 | |
| 64 | |
| 65 | static void frv_fpga_control(struct irq_group *group, int index, int on) |
| 66 | { |
| 67 | uint16_t imr = __get_IMR(); |
| 68 | |
| 69 | if (on) |
| 70 | imr &= ~(1 << index); |
| 71 | else |
| 72 | imr |= 1 << index; |
| 73 | |
| 74 | __set_IMR(imr); |
| 75 | } |
| 76 | |
| 77 | static void frv_fpga_doirq(struct irq_source *source) |
| 78 | { |
| 79 | uint16_t mask, imr; |
| 80 | |
| 81 | imr = __get_IMR(); |
| 82 | mask = source->irqmask & ~imr & __get_IFR(); |
| 83 | if (mask) { |
| 84 | __set_IMR(imr | mask); |
| 85 | __clr_IFR(mask); |
| 86 | distribute_irqs(&frv_fpga_irqs, mask); |
| 87 | __set_IMR(imr); |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | void __init fpga_init(void) |
| 92 | { |
| 93 | __set_IMR(0x0700); |
| 94 | __clr_IFR(0x0000); |
| 95 | |
| 96 | frv_irq_route_external(&frv_fpga[0], IRQ_CPU_EXTERNAL2); |
| 97 | frv_irq_set_group(&frv_fpga_irqs); |
| 98 | } |