blob: 47e3fa32b075d30aec910e540e0a94d6b4513330 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Copyright 2002 Momentum Computer
3 * Author: mdharm@momenco.com
4 *
5 * arch/mips/momentum/ocelot_c/cpci-irq.c
6 * Interrupt routines for cpci. Interrupt numbers are assigned from
7 * CPCI_IRQ_BASE to CPCI_IRQ_BASE+8 (8 interrupt sources).
8 *
9 * Note that the high-level software will need to be careful about using
10 * these interrupts. If this board is asserting a cPCI interrupt, it will
11 * also see the asserted interrupt. Care must be taken to avoid an
12 * interrupt flood.
13 *
14 * This program is free software; you can redistribute it and/or modify it
15 * under the terms of the GNU General Public License as published by the
16 * Free Software Foundation; either version 2 of the License, or (at your
17 * option) any later version.
18 */
19
20#include <linux/module.h>
21#include <linux/interrupt.h>
22#include <linux/irq.h>
23#include <linux/kernel.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070024#include <linux/sched.h>
25#include <linux/kernel_stat.h>
26#include <asm/io.h>
27#include "ocelot_c_fpga.h"
28
29#define CPCI_IRQ_BASE 8
30
31static inline int ls1bit8(unsigned int x)
32{
33 int b = 7, s;
34
35 s = 4; if (((unsigned char)(x << 4)) == 0) s = 0; b -= s; x <<= s;
36 s = 2; if (((unsigned char)(x << 2)) == 0) s = 0; b -= s; x <<= s;
37 s = 1; if (((unsigned char)(x << 1)) == 0) s = 0; b -= s;
38
39 return b;
40}
41
42/* mask off an interrupt -- 0 is enable, 1 is disable */
43static inline void mask_cpci_irq(unsigned int irq)
44{
45 uint32_t value;
46
47 value = OCELOT_FPGA_READ(INTMASK);
48 value |= 1 << (irq - CPCI_IRQ_BASE);
49 OCELOT_FPGA_WRITE(value, INTMASK);
50
51 /* read the value back to assure that it's really been written */
52 value = OCELOT_FPGA_READ(INTMASK);
53}
54
55/* unmask an interrupt -- 0 is enable, 1 is disable */
56static inline void unmask_cpci_irq(unsigned int irq)
57{
58 uint32_t value;
59
60 value = OCELOT_FPGA_READ(INTMASK);
61 value &= ~(1 << (irq - CPCI_IRQ_BASE));
62 OCELOT_FPGA_WRITE(value, INTMASK);
63
64 /* read the value back to assure that it's really been written */
65 value = OCELOT_FPGA_READ(INTMASK);
66}
67
68/*
69 * Enables the IRQ in the FPGA
70 */
71static void enable_cpci_irq(unsigned int irq)
72{
73 unmask_cpci_irq(irq);
74}
75
76/*
77 * Initialize the IRQ in the FPGA
78 */
79static unsigned int startup_cpci_irq(unsigned int irq)
80{
81 unmask_cpci_irq(irq);
82 return 0;
83}
84
85/*
86 * Disables the IRQ in the FPGA
87 */
88static void disable_cpci_irq(unsigned int irq)
89{
90 mask_cpci_irq(irq);
91}
92
93/*
94 * Masks and ACKs an IRQ
95 */
96static void mask_and_ack_cpci_irq(unsigned int irq)
97{
98 mask_cpci_irq(irq);
99}
100
101/*
102 * End IRQ processing
103 */
104static void end_cpci_irq(unsigned int irq)
105{
106 if (!(irq_desc[irq].status & (IRQ_DISABLED|IRQ_INPROGRESS)))
107 unmask_cpci_irq(irq);
108}
109
110/*
111 * Interrupt handler for interrupts coming from the FPGA chip.
112 * It could be built in ethernet ports etc...
113 */
Ralf Baechle937a8012006-10-07 19:44:33 +0100114void ll_cpci_irq(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115{
116 unsigned int irq_src, irq_mask;
117
118 /* read the interrupt status registers */
119 irq_src = OCELOT_FPGA_READ(INTSTAT);
120 irq_mask = OCELOT_FPGA_READ(INTMASK);
121
122 /* mask for just the interrupts we want */
123 irq_src &= ~irq_mask;
124
Ralf Baechle937a8012006-10-07 19:44:33 +0100125 do_IRQ(ls1bit8(irq_src) + CPCI_IRQ_BASE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126}
127
128#define shutdown_cpci_irq disable_cpci_irq
129
Ralf Baechle94dee172006-07-02 14:41:42 +0100130struct irq_chip cpci_irq_type = {
Ralf Baechle8ab00b92005-02-28 13:39:57 +0000131 .typename = "CPCI/FPGA",
132 .startup = startup_cpci_irq,
133 .shutdown = shutdown_cpci_irq,
134 .enable = enable_cpci_irq,
135 .disable = disable_cpci_irq,
136 .ack = mask_and_ack_cpci_irq,
137 .end = end_cpci_irq,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138};
139
140void cpci_irq_init(void)
141{
142 int i;
143
144 /* Reset irq handlers pointers to NULL */
145 for (i = CPCI_IRQ_BASE; i < (CPCI_IRQ_BASE + 8); i++) {
146 irq_desc[i].status = IRQ_DISABLED;
147 irq_desc[i].action = 0;
148 irq_desc[i].depth = 2;
Ingo Molnard1bef4e2006-06-29 02:24:36 -0700149 irq_desc[i].chip = &cpci_irq_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150 }
151}