summaryrefslogtreecommitdiffstats
path: root/include/asm-arm/arch-sa1100/irq.h
blob: 3289801ac77744ced07ca6a31efc8a3a4e86719f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
/*
 * linux/include/asm-arm/arch-sa1100/irq.h
 *
 * Copyright (C) 1996-1999 Russell king
 * Copyright (C) 1999 Hugo Fiennes
 *
 * Changelog:
 *   22-08-1998	RMK	Restructured IRQ routines
 *   06-01-1999	HBF	SA1100 twiddles
 *   12-02-1999	NP	added ICCR
 *   17-02-1999	NP	empeg henry ugly hacks now in a separate file ;)
 *   11-08-1999	PD	SA1101 support added
 *   25-09-1999	RMK	Merged into main ARM tree, cleaned up
 */
#include <linux/config.h>

static inline unsigned int fixup_irq(unsigned int irq)
{
#ifdef CONFIG_SA1101
	if (irq == SA1101_IRQ) {
		unsigned long mask;
		mask = INTSTATCLR0 & INTENABLE0;
		irq  = 32;
		if (!mask) {
			mask = IRQSTATCLR1 & INTENABLE1;
			irq  = 64;
		}
		if (mask)
			while ((mask & 1) == 0) {
				mask >>= 1;
				irq += 1;
			}
	}
#endif
	return irq;
}

/* We don't need to ACK IRQs on the SA1100 unless they're <= 10,
 * ie, an edge-detect.
 */
static void sa1100_mask_and_ack_irq(unsigned int irq)
{
	ICMR &= ~(1 << irq);
	if (irq <= 10)
		GEDR = 1 << irq;
}

static void sa1100_mask_irq(unsigned int irq)
{
	ICMR &= ~(1 << irq);
}

static void sa1100_unmask_irq(unsigned int irq)
{
	ICMR |= 1 << irq;
}

#ifdef CONFIG_SA1101

static void sa1101_mask_and_ack_lowirq(unsigned int irq)
{
	unsigned int mask = 1 << (irq & 31);

	INTENABLE0 &= ~mask;
	GEDR = 1 << SA1101_IRQ;
	INTSTATCLR0 = mask;
}

static void sa1101_mask_and_ack_highirq(unsigned int irq)
{
	unsigned int mask = 1 << (irq & 31);

	INTENABLE1 &= ~mask;
	GEDR = 1 << SA1101_IRQ;
	INTSTATCLR1 = mask;
}

static void sa1101_mask_lowirq(unsigned int irq)
{
	unsigned int mask = 1 << (irq & 31);

	INTENABLE0 &= ~mask;
}

static void sa1101_mask_highirq(unsigned int irq)
{
	unsigned int mask = 1 << (irq & 31);

	INTENABLE1 &= ~mask;
}

/*
 * unmasking an IRq with the wrong polarity can be
 * fatal, but there is no need to check this in the
 * interrupt code - it will be spotted anyway ;-)
 */
static void sa1101_unmask_lowirq(unsigned int irq)
{
	unsigned int mask = 1 << (irq & 31);

	INTENABLE0 |= mask;
	ICMR |= 1 << SA1101_IRQ;
}

static void sa1101_unmask_highirq(unsigned int irq)
{
	unsigned int mask = 1 << (irq & 31);

	INTENABLE1 |= mask;
	ICMR |= 1 << SA1101_IRQ;
}
#endif

static __inline__ void irq_init_irq(void)
{
	int irq;

	/* disable all IRQs */
	ICMR = 0;

	/* all IRQs are IRQ, not FIQ */
	ICLR = 0;

	/* clear all GPIO edge detects */
	GEDR = -1;

#ifdef CONFIG_SA1101
	/* turn on interrupt controller */
	SKPCR |= 4;

	/* disable all IRQs */
	INTENABLE0 = 0;
	INTENABLE1 = 0;

	/* detect on rising edge */
	INTPOL0 = 0;
	INTPOL1 = 0;

	/* clear all IRQs */
	INTSTATCLR0 = -1;
	INTSTATCLR1 = -1;

	/* SA1101 generates a rising edge */
	GRER |= 1 << SA1101_IRQ;
	GPER &= ~(1 << SA1101_IRQ);
#endif

	/*
	 * Whatever the doc says, this has to be set for the wait-on-irq
	 * instruction to work... on a SA1100 rev 9 at least.
	 */
	ICCR = 1;

#ifndef CONFIG_SA1101
	for (irq = 0; irq < NR_IRQS; irq++) {
		irq_desc[irq].valid	= 1;
		irq_desc[irq].probe_ok	= 1;
		irq_desc[irq].mask_ack	= sa1100_mask_and_ack_irq;
		irq_desc[irq].mask	= sa1100_mask_irq;
		irq_desc[irq].unmask	= sa1100_unmask_irq;
	}
#else
	for (irq = 0; irq < 31; irq++) {
		irq_desc[irq].valid	= 1;
		irq_desc[irq].probe_ok	= 1;
		irq_desc[irq].mask_ack	= sa1100_mask_and_ack_irq;
		irq_desc[irq].mask	= sa1100_mask_irq;
		irq_desc[irq].unmask	= sa1100_unmask_irq;
	}
	for (irq = 32; irq < 63; irq++) {
		irq_desc[irq].valid	= 1;
		irq_desc[irq].probe_ok	= 1;
		irq_desc[irq].mask_ack	= sa1101_mask_and_ack_lowirq;
		irq_desc[irq].mask	= sa1101_mask_lowirq;
		irq_desc[irq].unmask	= sa1101_unmask_lowirq;
	}
	for (irq = 64; irq < NR_IRQS; irq++) {
		irq_desc[irq].valid	= 1;
		irq_desc[irq].probe_ok	= 1;
		irq_desc[irq].mask_ack	= sa1101_mask_and_ack_highirq;
		irq_desc[irq].mask	= sa1101_mask_highirq;
		irq_desc[irq].unmask	= sa1101_unmask_highirq;
	}
#endif
}