blob: cf5f5f88525c8e6acffe255d7334a9741a38ed2a [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* irq-mb93093.c: MB93093 FPGA interrupt handling
2 *
David Howells1bcbba32006-09-25 23:32:04 -07003 * Copyright (C) 2006 Red Hat, Inc. All Rights Reserved.
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 * 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 Torvalds1da177e2005-04-16 15:20:36 -070012#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 Slaby1977f032007-10-18 23:40:25 -070020#include <linux/bitops.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070021
22#include <asm/io.h>
23#include <asm/system.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070024#include <asm/delay.h>
25#include <asm/irq.h>
26#include <asm/irc-regs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070027
28#define __reg16(ADDR) (*(volatile unsigned short *)(__region_CS2 + (ADDR)))
29
30#define __get_IMR() ({ __reg16(0x0a); })
31#define __set_IMR(M) do { __reg16(0x0a) = (M); wmb(); } while(0)
32#define __get_IFR() ({ __reg16(0x02); })
33#define __clr_IFR(M) do { __reg16(0x02) = ~(M); wmb(); } while(0)
34
Linus Torvalds1da177e2005-04-16 15:20:36 -070035/*
David Howells1bcbba32006-09-25 23:32:04 -070036 * off-CPU FPGA PIC operations
Linus Torvalds1da177e2005-04-16 15:20:36 -070037 */
David Howells88d6e192006-09-25 23:32:06 -070038static void frv_fpga_mask(unsigned int irq)
Linus Torvalds1da177e2005-04-16 15:20:36 -070039{
David Howells1bcbba32006-09-25 23:32:04 -070040 uint16_t imr = __get_IMR();
Linus Torvalds1da177e2005-04-16 15:20:36 -070041
David Howells1bcbba32006-09-25 23:32:04 -070042 imr |= 1 << (irq - IRQ_BASE_FPGA);
David Howells1bcbba32006-09-25 23:32:04 -070043 __set_IMR(imr);
Linus Torvalds1da177e2005-04-16 15:20:36 -070044}
45
David Howells1bcbba32006-09-25 23:32:04 -070046static void frv_fpga_ack(unsigned int irq)
47{
48 __clr_IFR(1 << (irq - IRQ_BASE_FPGA));
49}
50
David Howells88d6e192006-09-25 23:32:06 -070051static void frv_fpga_mask_ack(unsigned int irq)
David Howells1bcbba32006-09-25 23:32:04 -070052{
David Howells88d6e192006-09-25 23:32:06 -070053 uint16_t imr = __get_IMR();
54
55 imr |= 1 << (irq - IRQ_BASE_FPGA);
56 __set_IMR(imr);
57
58 __clr_IFR(1 << (irq - IRQ_BASE_FPGA));
59}
60
61static void frv_fpga_unmask(unsigned int irq)
62{
63 uint16_t imr = __get_IMR();
64
65 imr &= ~(1 << (irq - IRQ_BASE_FPGA));
66
67 __set_IMR(imr);
David Howells1bcbba32006-09-25 23:32:04 -070068}
69
70static struct irq_chip frv_fpga_pic = {
71 .name = "mb93093",
David Howells1bcbba32006-09-25 23:32:04 -070072 .ack = frv_fpga_ack,
David Howells88d6e192006-09-25 23:32:06 -070073 .mask = frv_fpga_mask,
74 .mask_ack = frv_fpga_mask_ack,
75 .unmask = frv_fpga_unmask,
David Howells1bcbba32006-09-25 23:32:04 -070076};
77
78/*
79 * FPGA PIC interrupt handler
80 */
David Howells7d12e782006-10-05 14:55:46 +010081static irqreturn_t fpga_interrupt(int irq, void *_mask)
David Howells1bcbba32006-09-25 23:32:04 -070082{
83 uint16_t imr, mask = (unsigned long) _mask;
David Howells1bcbba32006-09-25 23:32:04 -070084
85 imr = __get_IMR();
86 mask = mask & ~imr & __get_IFR();
87
88 /* poll all the triggered IRQs */
89 while (mask) {
90 int irq;
91
92 asm("scan %1,gr0,%0" : "=r"(irq) : "r"(mask));
93 irq = 31 - irq;
94 mask &= ~(1 << irq);
95
Thomas Gleixner0f421c92011-02-06 20:20:34 +010096 generic_handle_irq(IRQ_BASE_FPGA + irq);
David Howells1bcbba32006-09-25 23:32:04 -070097 }
98
David Howells88d6e192006-09-25 23:32:06 -070099 return IRQ_HANDLED;
David Howells1bcbba32006-09-25 23:32:04 -0700100}
101
102/*
103 * define an interrupt action for each FPGA PIC output
104 * - use dev_id to indicate the FPGA PIC input to output mappings
105 */
106static struct irqaction fpga_irq[1] = {
107 [0] = {
108 .handler = fpga_interrupt,
109 .flags = IRQF_DISABLED,
David Howells1bcbba32006-09-25 23:32:04 -0700110 .name = "fpga.0",
111 .dev_id = (void *) 0x0700UL,
112 }
113};
114
115/*
116 * initialise the motherboard FPGA's PIC
117 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118void __init fpga_init(void)
119{
David Howells1bcbba32006-09-25 23:32:04 -0700120 int irq;
121
122 /* all PIC inputs are all set to be edge triggered */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123 __set_IMR(0x0700);
124 __clr_IFR(0x0000);
125
David Howells1bcbba32006-09-25 23:32:04 -0700126 for (irq = IRQ_BASE_FPGA + 8; irq <= IRQ_BASE_FPGA + 10; irq++)
127 set_irq_chip_and_handler(irq, &frv_fpga_pic, handle_edge_irq);
128
129 /* the FPGA drives external IRQ input #2 on the CPU PIC */
130 setup_irq(IRQ_CPU_EXTERNAL2, &fpga_irq[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131}