blob: 4a1bd5ebee1cc63b8e6acd3e90c2c8c66196c2e8 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * linux/arch/arm/mach-sa1100/irq.c
3 *
4 * Copyright (C) 1999-2001 Nicolas Pitre
5 *
6 * Generic IRQ handling for the SA11x0, GPIO 11-27 IRQ demultiplexing.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
11 */
12#include <linux/init.h>
13#include <linux/module.h>
Thomas Gleixner119c6412006-07-01 22:32:38 +010014#include <linux/interrupt.h>
Russell King31696632012-06-06 11:42:36 +010015#include <linux/io.h>
Thomas Gleixner119c6412006-07-01 22:32:38 +010016#include <linux/irq.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017#include <linux/ioport.h>
Rafael J. Wysocki90533982011-04-22 22:03:03 +020018#include <linux/syscore_ops.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070019
Russell Kinga09e64f2008-08-05 16:14:15 +010020#include <mach/hardware.h>
Rob Herringf314f332012-02-24 00:06:51 +010021#include <mach/irqs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070022#include <asm/mach/irq.h>
Dmitry Eremin-Solenikovaffcab32014-11-28 15:55:16 +010023#include <asm/exception.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070024
25#include "generic.h"
26
27
28/*
29 * SA1100 GPIO edge detection for IRQs:
30 * IRQs are generated on Falling-Edge, Rising-Edge, or both.
31 * Use this instead of directly setting GRER/GFER.
32 */
33static int GPIO_IRQ_rising_edge;
34static int GPIO_IRQ_falling_edge;
35static int GPIO_IRQ_mask = (1 << 11) - 1;
36
37/*
38 * To get the GPIO number from an IRQ number
39 */
40#define GPIO_11_27_IRQ(i) ((i) - 21)
41#define GPIO11_27_MASK(irq) (1 << GPIO_11_27_IRQ(irq))
42
Lennert Buytenhekc4e89642010-11-29 11:12:06 +010043static int sa1100_gpio_type(struct irq_data *d, unsigned int type)
Linus Torvalds1da177e2005-04-16 15:20:36 -070044{
45 unsigned int mask;
46
Lennert Buytenhekc4e89642010-11-29 11:12:06 +010047 if (d->irq <= 10)
48 mask = 1 << d->irq;
Linus Torvalds1da177e2005-04-16 15:20:36 -070049 else
Lennert Buytenhekc4e89642010-11-29 11:12:06 +010050 mask = GPIO11_27_MASK(d->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -070051
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +010052 if (type == IRQ_TYPE_PROBE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070053 if ((GPIO_IRQ_rising_edge | GPIO_IRQ_falling_edge) & mask)
54 return 0;
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +010055 type = IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING;
Linus Torvalds1da177e2005-04-16 15:20:36 -070056 }
57
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +010058 if (type & IRQ_TYPE_EDGE_RISING) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070059 GPIO_IRQ_rising_edge |= mask;
60 } else
61 GPIO_IRQ_rising_edge &= ~mask;
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +010062 if (type & IRQ_TYPE_EDGE_FALLING) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 GPIO_IRQ_falling_edge |= mask;
64 } else
65 GPIO_IRQ_falling_edge &= ~mask;
66
67 GRER = GPIO_IRQ_rising_edge & GPIO_IRQ_mask;
68 GFER = GPIO_IRQ_falling_edge & GPIO_IRQ_mask;
69
70 return 0;
71}
72
73/*
74 * GPIO IRQs must be acknowledged. This is for IRQs from 0 to 10.
75 */
Lennert Buytenhekc4e89642010-11-29 11:12:06 +010076static void sa1100_low_gpio_ack(struct irq_data *d)
Linus Torvalds1da177e2005-04-16 15:20:36 -070077{
Lennert Buytenhekc4e89642010-11-29 11:12:06 +010078 GEDR = (1 << d->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -070079}
80
Lennert Buytenhekc4e89642010-11-29 11:12:06 +010081static void sa1100_low_gpio_mask(struct irq_data *d)
Linus Torvalds1da177e2005-04-16 15:20:36 -070082{
Lennert Buytenhekc4e89642010-11-29 11:12:06 +010083 ICMR &= ~(1 << d->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -070084}
85
Lennert Buytenhekc4e89642010-11-29 11:12:06 +010086static void sa1100_low_gpio_unmask(struct irq_data *d)
Linus Torvalds1da177e2005-04-16 15:20:36 -070087{
Lennert Buytenhekc4e89642010-11-29 11:12:06 +010088 ICMR |= 1 << d->irq;
Linus Torvalds1da177e2005-04-16 15:20:36 -070089}
90
Lennert Buytenhekc4e89642010-11-29 11:12:06 +010091static int sa1100_low_gpio_wake(struct irq_data *d, unsigned int on)
Linus Torvalds1da177e2005-04-16 15:20:36 -070092{
93 if (on)
Lennert Buytenhekc4e89642010-11-29 11:12:06 +010094 PWER |= 1 << d->irq;
Linus Torvalds1da177e2005-04-16 15:20:36 -070095 else
Lennert Buytenhekc4e89642010-11-29 11:12:06 +010096 PWER &= ~(1 << d->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -070097 return 0;
98}
99
David Brownell38c677c2006-08-01 22:26:25 +0100100static struct irq_chip sa1100_low_gpio_chip = {
101 .name = "GPIO-l",
Lennert Buytenhekc4e89642010-11-29 11:12:06 +0100102 .irq_ack = sa1100_low_gpio_ack,
103 .irq_mask = sa1100_low_gpio_mask,
104 .irq_unmask = sa1100_low_gpio_unmask,
105 .irq_set_type = sa1100_gpio_type,
106 .irq_set_wake = sa1100_low_gpio_wake,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107};
108
109/*
110 * IRQ11 (GPIO11 through 27) handler. We enter here with the
111 * irq_controller_lock held, and IRQs disabled. Decode the IRQ
112 * and call the handler.
113 */
114static void
Russell King10dd5ce2006-11-23 11:41:32 +0000115sa1100_high_gpio_handler(unsigned int irq, struct irq_desc *desc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116{
117 unsigned int mask;
118
119 mask = GEDR & 0xfffff800;
120 do {
121 /*
122 * clear down all currently active IRQ sources.
123 * We will be processing them all.
124 */
125 GEDR = mask;
126
127 irq = IRQ_GPIO11;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 mask >>= 11;
129 do {
130 if (mask & 1)
Dmitry Baryshkovd8aa0252008-10-09 13:36:24 +0100131 generic_handle_irq(irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132 mask >>= 1;
133 irq++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134 } while (mask);
135
136 mask = GEDR & 0xfffff800;
137 } while (mask);
138}
139
140/*
141 * Like GPIO0 to 10, GPIO11-27 IRQs need to be handled specially.
142 * In addition, the IRQs are all collected up into one bit in the
143 * interrupt controller registers.
144 */
Lennert Buytenhekc4e89642010-11-29 11:12:06 +0100145static void sa1100_high_gpio_ack(struct irq_data *d)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146{
Lennert Buytenhekc4e89642010-11-29 11:12:06 +0100147 unsigned int mask = GPIO11_27_MASK(d->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148
149 GEDR = mask;
150}
151
Lennert Buytenhekc4e89642010-11-29 11:12:06 +0100152static void sa1100_high_gpio_mask(struct irq_data *d)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153{
Lennert Buytenhekc4e89642010-11-29 11:12:06 +0100154 unsigned int mask = GPIO11_27_MASK(d->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155
156 GPIO_IRQ_mask &= ~mask;
157
158 GRER &= ~mask;
159 GFER &= ~mask;
160}
161
Lennert Buytenhekc4e89642010-11-29 11:12:06 +0100162static void sa1100_high_gpio_unmask(struct irq_data *d)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163{
Lennert Buytenhekc4e89642010-11-29 11:12:06 +0100164 unsigned int mask = GPIO11_27_MASK(d->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165
166 GPIO_IRQ_mask |= mask;
167
168 GRER = GPIO_IRQ_rising_edge & GPIO_IRQ_mask;
169 GFER = GPIO_IRQ_falling_edge & GPIO_IRQ_mask;
170}
171
Lennert Buytenhekc4e89642010-11-29 11:12:06 +0100172static int sa1100_high_gpio_wake(struct irq_data *d, unsigned int on)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173{
174 if (on)
Lennert Buytenhekc4e89642010-11-29 11:12:06 +0100175 PWER |= GPIO11_27_MASK(d->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176 else
Lennert Buytenhekc4e89642010-11-29 11:12:06 +0100177 PWER &= ~GPIO11_27_MASK(d->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178 return 0;
179}
180
David Brownell38c677c2006-08-01 22:26:25 +0100181static struct irq_chip sa1100_high_gpio_chip = {
182 .name = "GPIO-h",
Lennert Buytenhekc4e89642010-11-29 11:12:06 +0100183 .irq_ack = sa1100_high_gpio_ack,
184 .irq_mask = sa1100_high_gpio_mask,
185 .irq_unmask = sa1100_high_gpio_unmask,
186 .irq_set_type = sa1100_gpio_type,
187 .irq_set_wake = sa1100_high_gpio_wake,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188};
189
190/*
191 * We don't need to ACK IRQs on the SA1100 unless they're GPIOs
192 * this is for internal IRQs i.e. from 11 to 31.
193 */
Lennert Buytenhekc4e89642010-11-29 11:12:06 +0100194static void sa1100_mask_irq(struct irq_data *d)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195{
Lennert Buytenhekc4e89642010-11-29 11:12:06 +0100196 ICMR &= ~(1 << d->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197}
198
Lennert Buytenhekc4e89642010-11-29 11:12:06 +0100199static void sa1100_unmask_irq(struct irq_data *d)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200{
Lennert Buytenhekc4e89642010-11-29 11:12:06 +0100201 ICMR |= (1 << d->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202}
203
Russell King19ca5d22006-05-06 11:26:30 +0100204/*
205 * Apart form GPIOs, only the RTC alarm can be a wakeup event.
206 */
Lennert Buytenhekc4e89642010-11-29 11:12:06 +0100207static int sa1100_set_wake(struct irq_data *d, unsigned int on)
Russell King19ca5d22006-05-06 11:26:30 +0100208{
Lennert Buytenhekc4e89642010-11-29 11:12:06 +0100209 if (d->irq == IRQ_RTCAlrm) {
Russell King19ca5d22006-05-06 11:26:30 +0100210 if (on)
211 PWER |= PWER_RTC;
212 else
213 PWER &= ~PWER_RTC;
214 return 0;
215 }
216 return -EINVAL;
217}
218
David Brownell38c677c2006-08-01 22:26:25 +0100219static struct irq_chip sa1100_normal_chip = {
220 .name = "SC",
Lennert Buytenhekc4e89642010-11-29 11:12:06 +0100221 .irq_ack = sa1100_mask_irq,
222 .irq_mask = sa1100_mask_irq,
223 .irq_unmask = sa1100_unmask_irq,
224 .irq_set_wake = sa1100_set_wake,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225};
226
Russell Kinga1810992012-01-12 10:25:29 +0000227static struct resource irq_resource =
228 DEFINE_RES_MEM_NAMED(0x90050000, SZ_64K, "irqs");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229
230static struct sa1100irq_state {
231 unsigned int saved;
232 unsigned int icmr;
233 unsigned int iclr;
234 unsigned int iccr;
235} sa1100irq_state;
236
Rafael J. Wysocki90533982011-04-22 22:03:03 +0200237static int sa1100irq_suspend(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238{
239 struct sa1100irq_state *st = &sa1100irq_state;
240
241 st->saved = 1;
242 st->icmr = ICMR;
243 st->iclr = ICLR;
244 st->iccr = ICCR;
245
246 /*
247 * Disable all GPIO-based interrupts.
248 */
249 ICMR &= ~(IC_GPIO11_27|IC_GPIO10|IC_GPIO9|IC_GPIO8|IC_GPIO7|
250 IC_GPIO6|IC_GPIO5|IC_GPIO4|IC_GPIO3|IC_GPIO2|
251 IC_GPIO1|IC_GPIO0);
252
253 /*
254 * Set the appropriate edges for wakeup.
255 */
256 GRER = PWER & GPIO_IRQ_rising_edge;
257 GFER = PWER & GPIO_IRQ_falling_edge;
258
259 /*
260 * Clear any pending GPIO interrupts.
261 */
262 GEDR = GEDR;
263
264 return 0;
265}
266
Rafael J. Wysocki90533982011-04-22 22:03:03 +0200267static void sa1100irq_resume(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268{
269 struct sa1100irq_state *st = &sa1100irq_state;
270
271 if (st->saved) {
272 ICCR = st->iccr;
273 ICLR = st->iclr;
274
275 GRER = GPIO_IRQ_rising_edge & GPIO_IRQ_mask;
276 GFER = GPIO_IRQ_falling_edge & GPIO_IRQ_mask;
277
278 ICMR = st->icmr;
279 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280}
281
Rafael J. Wysocki90533982011-04-22 22:03:03 +0200282static struct syscore_ops sa1100irq_syscore_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283 .suspend = sa1100irq_suspend,
284 .resume = sa1100irq_resume,
285};
286
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287static int __init sa1100irq_init_devicefs(void)
288{
Rafael J. Wysocki90533982011-04-22 22:03:03 +0200289 register_syscore_ops(&sa1100irq_syscore_ops);
290 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291}
292
293device_initcall(sa1100irq_init_devicefs);
294
Dmitry Eremin-Solenikovaffcab32014-11-28 15:55:16 +0100295static asmlinkage void __exception_irq_entry
296sa1100_handle_irq(struct pt_regs *regs)
297{
298 uint32_t icip, icmr, mask;
299
300 do {
301 icip = (ICIP);
302 icmr = (ICMR);
303 mask = icip & icmr;
304
305 if (mask == 0)
306 break;
307
308 handle_IRQ(ffs(mask) - 1 + IRQ_GPIO0, regs);
309 } while (1);
310}
311
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312void __init sa1100_init_irq(void)
313{
314 unsigned int irq;
315
316 request_resource(&iomem_resource, &irq_resource);
317
318 /* disable all IRQs */
319 ICMR = 0;
320
321 /* all IRQs are IRQ, not FIQ */
322 ICLR = 0;
323
324 /* clear all GPIO edge detects */
325 GFER = 0;
326 GRER = 0;
327 GEDR = -1;
328
329 /*
330 * Whatever the doc says, this has to be set for the wait-on-irq
331 * instruction to work... on a SA1100 rev 9 at least.
332 */
333 ICCR = 1;
334
335 for (irq = 0; irq <= 10; irq++) {
Thomas Gleixnerf38c02f2011-03-24 13:35:09 +0100336 irq_set_chip_and_handler(irq, &sa1100_low_gpio_chip,
337 handle_edge_irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338 set_irq_flags(irq, IRQF_VALID | IRQF_PROBE);
339 }
340
341 for (irq = 12; irq <= 31; irq++) {
Thomas Gleixnerf38c02f2011-03-24 13:35:09 +0100342 irq_set_chip_and_handler(irq, &sa1100_normal_chip,
343 handle_level_irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344 set_irq_flags(irq, IRQF_VALID);
345 }
346
347 for (irq = 32; irq <= 48; irq++) {
Thomas Gleixnerf38c02f2011-03-24 13:35:09 +0100348 irq_set_chip_and_handler(irq, &sa1100_high_gpio_chip,
349 handle_edge_irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350 set_irq_flags(irq, IRQF_VALID | IRQF_PROBE);
351 }
352
353 /*
354 * Install handler for GPIO 11-27 edge detect interrupts
355 */
Thomas Gleixner6845664a2011-03-24 13:25:22 +0100356 irq_set_chip(IRQ_GPIO11_27, &sa1100_normal_chip);
357 irq_set_chained_handler(IRQ_GPIO11_27, sa1100_high_gpio_handler);
Dmitry Baryshkov45528e32008-04-10 13:31:47 +0100358
Dmitry Eremin-Solenikovaffcab32014-11-28 15:55:16 +0100359 set_handle_irq(sa1100_handle_irq);
360
Dmitry Baryshkov45528e32008-04-10 13:31:47 +0100361 sa1100_init_gpio();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362}