blob: 37d106202b83a7695cb0614013693bb57d5a2bbd [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Copyright 2002 Momentum Computer
3 * Author: mdharm@momenco.com
Ralf Baechle27f76812006-10-09 00:03:05 +01004 * Copyright (C) 2004, 06 Ralf Baechle <ralf@linux-mips.org>
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version.
10 */
11#include <linux/module.h>
12#include <linux/interrupt.h>
13#include <linux/kernel.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include <linux/kernel_stat.h>
Ralf Baechle3367fd52006-03-08 14:22:27 +000015#include <linux/mv643xx.h>
16#include <linux/sched.h>
17
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#include <asm/io.h>
19#include <asm/irq.h>
Ralf Baechle3367fd52006-03-08 14:22:27 +000020#include <asm/marvell.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070021
22static unsigned int irq_base;
23
24static inline int ls1bit32(unsigned int x)
25{
26 int b = 31, s;
27
28 s = 16; if (x << 16 == 0) s = 0; b -= s; x <<= s;
29 s = 8; if (x << 8 == 0) s = 0; b -= s; x <<= s;
30 s = 4; if (x << 4 == 0) s = 0; b -= s; x <<= s;
31 s = 2; if (x << 2 == 0) s = 0; b -= s; x <<= s;
32 s = 1; if (x << 1 == 0) s = 0; b -= s;
33
34 return b;
35}
36
37/* mask off an interrupt -- 1 is enable, 0 is disable */
38static inline void mask_mv64340_irq(unsigned int irq)
39{
40 uint32_t value;
41
42 if (irq < (irq_base + 32)) {
43 value = MV_READ(MV64340_INTERRUPT0_MASK_0_LOW);
44 value &= ~(1 << (irq - irq_base));
45 MV_WRITE(MV64340_INTERRUPT0_MASK_0_LOW, value);
46 } else {
47 value = MV_READ(MV64340_INTERRUPT0_MASK_0_HIGH);
48 value &= ~(1 << (irq - irq_base - 32));
49 MV_WRITE(MV64340_INTERRUPT0_MASK_0_HIGH, value);
50 }
51}
52
53/* unmask an interrupt -- 1 is enable, 0 is disable */
54static inline void unmask_mv64340_irq(unsigned int irq)
55{
56 uint32_t value;
57
58 if (irq < (irq_base + 32)) {
59 value = MV_READ(MV64340_INTERRUPT0_MASK_0_LOW);
60 value |= 1 << (irq - irq_base);
61 MV_WRITE(MV64340_INTERRUPT0_MASK_0_LOW, value);
62 } else {
63 value = MV_READ(MV64340_INTERRUPT0_MASK_0_HIGH);
64 value |= 1 << (irq - irq_base - 32);
65 MV_WRITE(MV64340_INTERRUPT0_MASK_0_HIGH, value);
66 }
67}
68
69/*
70 * Enables the IRQ on Marvell Chip
71 */
72static void enable_mv64340_irq(unsigned int irq)
73{
74 unmask_mv64340_irq(irq);
75}
76
77/*
78 * Initialize the IRQ on Marvell Chip
79 */
80static unsigned int startup_mv64340_irq(unsigned int irq)
81{
82 unmask_mv64340_irq(irq);
83 return 0;
84}
85
86/*
87 * Disables the IRQ on Marvell Chip
88 */
89static void disable_mv64340_irq(unsigned int irq)
90{
91 mask_mv64340_irq(irq);
92}
93
94/*
95 * Masks and ACKs an IRQ
96 */
97static void mask_and_ack_mv64340_irq(unsigned int irq)
98{
99 mask_mv64340_irq(irq);
100}
101
102/*
103 * End IRQ processing
104 */
105static void end_mv64340_irq(unsigned int irq)
106{
107 if (!(irq_desc[irq].status & (IRQ_DISABLED|IRQ_INPROGRESS)))
108 unmask_mv64340_irq(irq);
109}
110
111/*
112 * Interrupt handler for interrupts coming from the Marvell chip.
113 * It could be built in ethernet ports etc...
114 */
Ralf Baechle937a8012006-10-07 19:44:33 +0100115void ll_mv64340_irq(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116{
117 unsigned int irq_src_low, irq_src_high;
118 unsigned int irq_mask_low, irq_mask_high;
119
120 /* read the interrupt status registers */
121 irq_mask_low = MV_READ(MV64340_INTERRUPT0_MASK_0_LOW);
122 irq_mask_high = MV_READ(MV64340_INTERRUPT0_MASK_0_HIGH);
123 irq_src_low = MV_READ(MV64340_MAIN_INTERRUPT_CAUSE_LOW);
124 irq_src_high = MV_READ(MV64340_MAIN_INTERRUPT_CAUSE_HIGH);
125
126 /* mask for just the interrupts we want */
127 irq_src_low &= irq_mask_low;
128 irq_src_high &= irq_mask_high;
129
130 if (irq_src_low)
Ralf Baechle937a8012006-10-07 19:44:33 +0100131 do_IRQ(ls1bit32(irq_src_low) + irq_base);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132 else
Ralf Baechle937a8012006-10-07 19:44:33 +0100133 do_IRQ(ls1bit32(irq_src_high) + irq_base + 32);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134}
135
136#define shutdown_mv64340_irq disable_mv64340_irq
137
Ralf Baechle94dee172006-07-02 14:41:42 +0100138struct irq_chip mv64340_irq_type = {
Ralf Baechle8ab00b92005-02-28 13:39:57 +0000139 .typename = "MV-64340",
140 .startup = startup_mv64340_irq,
141 .shutdown = shutdown_mv64340_irq,
142 .enable = enable_mv64340_irq,
143 .disable = disable_mv64340_irq,
144 .ack = mask_and_ack_mv64340_irq,
145 .end = end_mv64340_irq,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146};
147
148void __init mv64340_irq_init(unsigned int base)
149{
150 int i;
151
152 /* Reset irq handlers pointers to NULL */
153 for (i = base; i < base + 64; i++) {
154 irq_desc[i].status = IRQ_DISABLED;
155 irq_desc[i].action = 0;
156 irq_desc[i].depth = 2;
Ingo Molnard1bef4e2006-06-29 02:24:36 -0700157 irq_desc[i].chip = &mv64340_irq_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158 }
159
160 irq_base = base;
161}