Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* irq-mb93093.c: MB93093 FPGA interrupt handling |
| 2 | * |
David Howells | 1bcbba3 | 2006-09-25 23:32:04 -0700 | [diff] [blame] | 3 | * Copyright (C) 2006 Red Hat, Inc. All Rights Reserved. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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> |
Jiri Slaby | 1977f03 | 2007-10-18 23:40:25 -0700 | [diff] [blame] | 20 | #include <linux/bitops.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | |
| 22 | #include <asm/io.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | #include <asm/delay.h> |
| 24 | #include <asm/irq.h> |
| 25 | #include <asm/irc-regs.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | |
| 27 | #define __reg16(ADDR) (*(volatile unsigned short *)(__region_CS2 + (ADDR))) |
| 28 | |
| 29 | #define __get_IMR() ({ __reg16(0x0a); }) |
| 30 | #define __set_IMR(M) do { __reg16(0x0a) = (M); wmb(); } while(0) |
| 31 | #define __get_IFR() ({ __reg16(0x02); }) |
| 32 | #define __clr_IFR(M) do { __reg16(0x02) = ~(M); wmb(); } while(0) |
| 33 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | /* |
David Howells | 1bcbba3 | 2006-09-25 23:32:04 -0700 | [diff] [blame] | 35 | * off-CPU FPGA PIC operations |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | */ |
Thomas Gleixner | 9741f28 | 2011-02-06 20:20:36 +0100 | [diff] [blame] | 37 | static void frv_fpga_mask(struct irq_data *d) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | { |
David Howells | 1bcbba3 | 2006-09-25 23:32:04 -0700 | [diff] [blame] | 39 | uint16_t imr = __get_IMR(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | |
Thomas Gleixner | 9741f28 | 2011-02-06 20:20:36 +0100 | [diff] [blame] | 41 | imr |= 1 << (d->irq - IRQ_BASE_FPGA); |
David Howells | 1bcbba3 | 2006-09-25 23:32:04 -0700 | [diff] [blame] | 42 | __set_IMR(imr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | } |
| 44 | |
Thomas Gleixner | 9741f28 | 2011-02-06 20:20:36 +0100 | [diff] [blame] | 45 | static void frv_fpga_ack(struct irq_data *d) |
David Howells | 1bcbba3 | 2006-09-25 23:32:04 -0700 | [diff] [blame] | 46 | { |
Thomas Gleixner | 9741f28 | 2011-02-06 20:20:36 +0100 | [diff] [blame] | 47 | __clr_IFR(1 << (d->irq - IRQ_BASE_FPGA)); |
David Howells | 1bcbba3 | 2006-09-25 23:32:04 -0700 | [diff] [blame] | 48 | } |
| 49 | |
Thomas Gleixner | 9741f28 | 2011-02-06 20:20:36 +0100 | [diff] [blame] | 50 | static void frv_fpga_mask_ack(struct irq_data *d) |
David Howells | 1bcbba3 | 2006-09-25 23:32:04 -0700 | [diff] [blame] | 51 | { |
David Howells | 88d6e19 | 2006-09-25 23:32:06 -0700 | [diff] [blame] | 52 | uint16_t imr = __get_IMR(); |
| 53 | |
Thomas Gleixner | 9741f28 | 2011-02-06 20:20:36 +0100 | [diff] [blame] | 54 | imr |= 1 << (d->irq - IRQ_BASE_FPGA); |
David Howells | 88d6e19 | 2006-09-25 23:32:06 -0700 | [diff] [blame] | 55 | __set_IMR(imr); |
| 56 | |
Thomas Gleixner | 9741f28 | 2011-02-06 20:20:36 +0100 | [diff] [blame] | 57 | __clr_IFR(1 << (d->irq - IRQ_BASE_FPGA)); |
David Howells | 88d6e19 | 2006-09-25 23:32:06 -0700 | [diff] [blame] | 58 | } |
| 59 | |
Thomas Gleixner | 9741f28 | 2011-02-06 20:20:36 +0100 | [diff] [blame] | 60 | static void frv_fpga_unmask(struct irq_data *d) |
David Howells | 88d6e19 | 2006-09-25 23:32:06 -0700 | [diff] [blame] | 61 | { |
| 62 | uint16_t imr = __get_IMR(); |
| 63 | |
Thomas Gleixner | 9741f28 | 2011-02-06 20:20:36 +0100 | [diff] [blame] | 64 | imr &= ~(1 << (d->irq - IRQ_BASE_FPGA)); |
David Howells | 88d6e19 | 2006-09-25 23:32:06 -0700 | [diff] [blame] | 65 | |
| 66 | __set_IMR(imr); |
David Howells | 1bcbba3 | 2006-09-25 23:32:04 -0700 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | static struct irq_chip frv_fpga_pic = { |
| 70 | .name = "mb93093", |
Thomas Gleixner | 9741f28 | 2011-02-06 20:20:36 +0100 | [diff] [blame] | 71 | .irq_ack = frv_fpga_ack, |
| 72 | .irq_mask = frv_fpga_mask, |
| 73 | .irq_mask_ack = frv_fpga_mask_ack, |
| 74 | .irq_unmask = frv_fpga_unmask, |
David Howells | 1bcbba3 | 2006-09-25 23:32:04 -0700 | [diff] [blame] | 75 | }; |
| 76 | |
| 77 | /* |
| 78 | * FPGA PIC interrupt handler |
| 79 | */ |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 80 | static irqreturn_t fpga_interrupt(int irq, void *_mask) |
David Howells | 1bcbba3 | 2006-09-25 23:32:04 -0700 | [diff] [blame] | 81 | { |
| 82 | uint16_t imr, mask = (unsigned long) _mask; |
David Howells | 1bcbba3 | 2006-09-25 23:32:04 -0700 | [diff] [blame] | 83 | |
| 84 | imr = __get_IMR(); |
| 85 | mask = mask & ~imr & __get_IFR(); |
| 86 | |
| 87 | /* poll all the triggered IRQs */ |
| 88 | while (mask) { |
| 89 | int irq; |
| 90 | |
| 91 | asm("scan %1,gr0,%0" : "=r"(irq) : "r"(mask)); |
| 92 | irq = 31 - irq; |
| 93 | mask &= ~(1 << irq); |
| 94 | |
Thomas Gleixner | 0f421c9 | 2011-02-06 20:20:34 +0100 | [diff] [blame] | 95 | generic_handle_irq(IRQ_BASE_FPGA + irq); |
David Howells | 1bcbba3 | 2006-09-25 23:32:04 -0700 | [diff] [blame] | 96 | } |
| 97 | |
David Howells | 88d6e19 | 2006-09-25 23:32:06 -0700 | [diff] [blame] | 98 | return IRQ_HANDLED; |
David Howells | 1bcbba3 | 2006-09-25 23:32:04 -0700 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | /* |
| 102 | * define an interrupt action for each FPGA PIC output |
| 103 | * - use dev_id to indicate the FPGA PIC input to output mappings |
| 104 | */ |
| 105 | static struct irqaction fpga_irq[1] = { |
| 106 | [0] = { |
| 107 | .handler = fpga_interrupt, |
| 108 | .flags = IRQF_DISABLED, |
David Howells | 1bcbba3 | 2006-09-25 23:32:04 -0700 | [diff] [blame] | 109 | .name = "fpga.0", |
| 110 | .dev_id = (void *) 0x0700UL, |
| 111 | } |
| 112 | }; |
| 113 | |
| 114 | /* |
| 115 | * initialise the motherboard FPGA's PIC |
| 116 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | void __init fpga_init(void) |
| 118 | { |
David Howells | 1bcbba3 | 2006-09-25 23:32:04 -0700 | [diff] [blame] | 119 | int irq; |
| 120 | |
| 121 | /* all PIC inputs are all set to be edge triggered */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | __set_IMR(0x0700); |
| 123 | __clr_IFR(0x0000); |
| 124 | |
David Howells | 1bcbba3 | 2006-09-25 23:32:04 -0700 | [diff] [blame] | 125 | for (irq = IRQ_BASE_FPGA + 8; irq <= IRQ_BASE_FPGA + 10; irq++) |
Thomas Gleixner | de2e95a | 2011-03-24 16:38:49 +0100 | [diff] [blame] | 126 | irq_set_chip_and_handler(irq, &frv_fpga_pic, handle_edge_irq); |
David Howells | 1bcbba3 | 2006-09-25 23:32:04 -0700 | [diff] [blame] | 127 | |
| 128 | /* the FPGA drives external IRQ input #2 on the CPU PIC */ |
| 129 | setup_irq(IRQ_CPU_EXTERNAL2, &fpga_irq[0]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | } |