blob: 2124f1fc2fbeadc91ad7625dae6dddc95ae82b8a [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>
23
24#include "generic.h"
25
26
27/*
28 * SA1100 GPIO edge detection for IRQs:
29 * IRQs are generated on Falling-Edge, Rising-Edge, or both.
30 * Use this instead of directly setting GRER/GFER.
31 */
32static int GPIO_IRQ_rising_edge;
33static int GPIO_IRQ_falling_edge;
34static int GPIO_IRQ_mask = (1 << 11) - 1;
35
36/*
37 * To get the GPIO number from an IRQ number
38 */
39#define GPIO_11_27_IRQ(i) ((i) - 21)
40#define GPIO11_27_MASK(irq) (1 << GPIO_11_27_IRQ(irq))
41
Lennert Buytenhekc4e89642010-11-29 11:12:06 +010042static int sa1100_gpio_type(struct irq_data *d, unsigned int type)
Linus Torvalds1da177e2005-04-16 15:20:36 -070043{
44 unsigned int mask;
45
Lennert Buytenhekc4e89642010-11-29 11:12:06 +010046 if (d->irq <= 10)
47 mask = 1 << d->irq;
Linus Torvalds1da177e2005-04-16 15:20:36 -070048 else
Lennert Buytenhekc4e89642010-11-29 11:12:06 +010049 mask = GPIO11_27_MASK(d->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -070050
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +010051 if (type == IRQ_TYPE_PROBE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070052 if ((GPIO_IRQ_rising_edge | GPIO_IRQ_falling_edge) & mask)
53 return 0;
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +010054 type = IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING;
Linus Torvalds1da177e2005-04-16 15:20:36 -070055 }
56
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +010057 if (type & IRQ_TYPE_EDGE_RISING) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070058 GPIO_IRQ_rising_edge |= mask;
59 } else
60 GPIO_IRQ_rising_edge &= ~mask;
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +010061 if (type & IRQ_TYPE_EDGE_FALLING) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070062 GPIO_IRQ_falling_edge |= mask;
63 } else
64 GPIO_IRQ_falling_edge &= ~mask;
65
66 GRER = GPIO_IRQ_rising_edge & GPIO_IRQ_mask;
67 GFER = GPIO_IRQ_falling_edge & GPIO_IRQ_mask;
68
69 return 0;
70}
71
72/*
73 * GPIO IRQs must be acknowledged. This is for IRQs from 0 to 10.
74 */
Lennert Buytenhekc4e89642010-11-29 11:12:06 +010075static void sa1100_low_gpio_ack(struct irq_data *d)
Linus Torvalds1da177e2005-04-16 15:20:36 -070076{
Lennert Buytenhekc4e89642010-11-29 11:12:06 +010077 GEDR = (1 << d->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -070078}
79
Lennert Buytenhekc4e89642010-11-29 11:12:06 +010080static void sa1100_low_gpio_mask(struct irq_data *d)
Linus Torvalds1da177e2005-04-16 15:20:36 -070081{
Lennert Buytenhekc4e89642010-11-29 11:12:06 +010082 ICMR &= ~(1 << d->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -070083}
84
Lennert Buytenhekc4e89642010-11-29 11:12:06 +010085static void sa1100_low_gpio_unmask(struct irq_data *d)
Linus Torvalds1da177e2005-04-16 15:20:36 -070086{
Lennert Buytenhekc4e89642010-11-29 11:12:06 +010087 ICMR |= 1 << d->irq;
Linus Torvalds1da177e2005-04-16 15:20:36 -070088}
89
Lennert Buytenhekc4e89642010-11-29 11:12:06 +010090static int sa1100_low_gpio_wake(struct irq_data *d, unsigned int on)
Linus Torvalds1da177e2005-04-16 15:20:36 -070091{
92 if (on)
Lennert Buytenhekc4e89642010-11-29 11:12:06 +010093 PWER |= 1 << d->irq;
Linus Torvalds1da177e2005-04-16 15:20:36 -070094 else
Lennert Buytenhekc4e89642010-11-29 11:12:06 +010095 PWER &= ~(1 << d->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -070096 return 0;
97}
98
David Brownell38c677c2006-08-01 22:26:25 +010099static struct irq_chip sa1100_low_gpio_chip = {
100 .name = "GPIO-l",
Lennert Buytenhekc4e89642010-11-29 11:12:06 +0100101 .irq_ack = sa1100_low_gpio_ack,
102 .irq_mask = sa1100_low_gpio_mask,
103 .irq_unmask = sa1100_low_gpio_unmask,
104 .irq_set_type = sa1100_gpio_type,
105 .irq_set_wake = sa1100_low_gpio_wake,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106};
107
108/*
109 * IRQ11 (GPIO11 through 27) handler. We enter here with the
110 * irq_controller_lock held, and IRQs disabled. Decode the IRQ
111 * and call the handler.
112 */
113static void
Russell King10dd5ce2006-11-23 11:41:32 +0000114sa1100_high_gpio_handler(unsigned int irq, struct irq_desc *desc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115{
116 unsigned int mask;
117
118 mask = GEDR & 0xfffff800;
119 do {
120 /*
121 * clear down all currently active IRQ sources.
122 * We will be processing them all.
123 */
124 GEDR = mask;
125
126 irq = IRQ_GPIO11;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 mask >>= 11;
128 do {
129 if (mask & 1)
Dmitry Baryshkovd8aa0252008-10-09 13:36:24 +0100130 generic_handle_irq(irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131 mask >>= 1;
132 irq++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133 } while (mask);
134
135 mask = GEDR & 0xfffff800;
136 } while (mask);
137}
138
139/*
140 * Like GPIO0 to 10, GPIO11-27 IRQs need to be handled specially.
141 * In addition, the IRQs are all collected up into one bit in the
142 * interrupt controller registers.
143 */
Lennert Buytenhekc4e89642010-11-29 11:12:06 +0100144static void sa1100_high_gpio_ack(struct irq_data *d)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145{
Lennert Buytenhekc4e89642010-11-29 11:12:06 +0100146 unsigned int mask = GPIO11_27_MASK(d->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147
148 GEDR = mask;
149}
150
Lennert Buytenhekc4e89642010-11-29 11:12:06 +0100151static void sa1100_high_gpio_mask(struct irq_data *d)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152{
Lennert Buytenhekc4e89642010-11-29 11:12:06 +0100153 unsigned int mask = GPIO11_27_MASK(d->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154
155 GPIO_IRQ_mask &= ~mask;
156
157 GRER &= ~mask;
158 GFER &= ~mask;
159}
160
Lennert Buytenhekc4e89642010-11-29 11:12:06 +0100161static void sa1100_high_gpio_unmask(struct irq_data *d)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162{
Lennert Buytenhekc4e89642010-11-29 11:12:06 +0100163 unsigned int mask = GPIO11_27_MASK(d->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164
165 GPIO_IRQ_mask |= mask;
166
167 GRER = GPIO_IRQ_rising_edge & GPIO_IRQ_mask;
168 GFER = GPIO_IRQ_falling_edge & GPIO_IRQ_mask;
169}
170
Lennert Buytenhekc4e89642010-11-29 11:12:06 +0100171static int sa1100_high_gpio_wake(struct irq_data *d, unsigned int on)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172{
173 if (on)
Lennert Buytenhekc4e89642010-11-29 11:12:06 +0100174 PWER |= GPIO11_27_MASK(d->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175 else
Lennert Buytenhekc4e89642010-11-29 11:12:06 +0100176 PWER &= ~GPIO11_27_MASK(d->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177 return 0;
178}
179
David Brownell38c677c2006-08-01 22:26:25 +0100180static struct irq_chip sa1100_high_gpio_chip = {
181 .name = "GPIO-h",
Lennert Buytenhekc4e89642010-11-29 11:12:06 +0100182 .irq_ack = sa1100_high_gpio_ack,
183 .irq_mask = sa1100_high_gpio_mask,
184 .irq_unmask = sa1100_high_gpio_unmask,
185 .irq_set_type = sa1100_gpio_type,
186 .irq_set_wake = sa1100_high_gpio_wake,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187};
188
189/*
190 * We don't need to ACK IRQs on the SA1100 unless they're GPIOs
191 * this is for internal IRQs i.e. from 11 to 31.
192 */
Lennert Buytenhekc4e89642010-11-29 11:12:06 +0100193static void sa1100_mask_irq(struct irq_data *d)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194{
Lennert Buytenhekc4e89642010-11-29 11:12:06 +0100195 ICMR &= ~(1 << d->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196}
197
Lennert Buytenhekc4e89642010-11-29 11:12:06 +0100198static void sa1100_unmask_irq(struct irq_data *d)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199{
Lennert Buytenhekc4e89642010-11-29 11:12:06 +0100200 ICMR |= (1 << d->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201}
202
Russell King19ca5d22006-05-06 11:26:30 +0100203/*
204 * Apart form GPIOs, only the RTC alarm can be a wakeup event.
205 */
Lennert Buytenhekc4e89642010-11-29 11:12:06 +0100206static int sa1100_set_wake(struct irq_data *d, unsigned int on)
Russell King19ca5d22006-05-06 11:26:30 +0100207{
Lennert Buytenhekc4e89642010-11-29 11:12:06 +0100208 if (d->irq == IRQ_RTCAlrm) {
Russell King19ca5d22006-05-06 11:26:30 +0100209 if (on)
210 PWER |= PWER_RTC;
211 else
212 PWER &= ~PWER_RTC;
213 return 0;
214 }
215 return -EINVAL;
216}
217
David Brownell38c677c2006-08-01 22:26:25 +0100218static struct irq_chip sa1100_normal_chip = {
219 .name = "SC",
Lennert Buytenhekc4e89642010-11-29 11:12:06 +0100220 .irq_ack = sa1100_mask_irq,
221 .irq_mask = sa1100_mask_irq,
222 .irq_unmask = sa1100_unmask_irq,
223 .irq_set_wake = sa1100_set_wake,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224};
225
Russell Kinga1810992012-01-12 10:25:29 +0000226static struct resource irq_resource =
227 DEFINE_RES_MEM_NAMED(0x90050000, SZ_64K, "irqs");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228
229static struct sa1100irq_state {
230 unsigned int saved;
231 unsigned int icmr;
232 unsigned int iclr;
233 unsigned int iccr;
234} sa1100irq_state;
235
Rafael J. Wysocki90533982011-04-22 22:03:03 +0200236static int sa1100irq_suspend(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237{
238 struct sa1100irq_state *st = &sa1100irq_state;
239
240 st->saved = 1;
241 st->icmr = ICMR;
242 st->iclr = ICLR;
243 st->iccr = ICCR;
244
245 /*
246 * Disable all GPIO-based interrupts.
247 */
248 ICMR &= ~(IC_GPIO11_27|IC_GPIO10|IC_GPIO9|IC_GPIO8|IC_GPIO7|
249 IC_GPIO6|IC_GPIO5|IC_GPIO4|IC_GPIO3|IC_GPIO2|
250 IC_GPIO1|IC_GPIO0);
251
252 /*
253 * Set the appropriate edges for wakeup.
254 */
255 GRER = PWER & GPIO_IRQ_rising_edge;
256 GFER = PWER & GPIO_IRQ_falling_edge;
257
258 /*
259 * Clear any pending GPIO interrupts.
260 */
261 GEDR = GEDR;
262
263 return 0;
264}
265
Rafael J. Wysocki90533982011-04-22 22:03:03 +0200266static void sa1100irq_resume(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267{
268 struct sa1100irq_state *st = &sa1100irq_state;
269
270 if (st->saved) {
271 ICCR = st->iccr;
272 ICLR = st->iclr;
273
274 GRER = GPIO_IRQ_rising_edge & GPIO_IRQ_mask;
275 GFER = GPIO_IRQ_falling_edge & GPIO_IRQ_mask;
276
277 ICMR = st->icmr;
278 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279}
280
Rafael J. Wysocki90533982011-04-22 22:03:03 +0200281static struct syscore_ops sa1100irq_syscore_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282 .suspend = sa1100irq_suspend,
283 .resume = sa1100irq_resume,
284};
285
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286static int __init sa1100irq_init_devicefs(void)
287{
Rafael J. Wysocki90533982011-04-22 22:03:03 +0200288 register_syscore_ops(&sa1100irq_syscore_ops);
289 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290}
291
292device_initcall(sa1100irq_init_devicefs);
293
294void __init sa1100_init_irq(void)
295{
296 unsigned int irq;
297
298 request_resource(&iomem_resource, &irq_resource);
299
300 /* disable all IRQs */
301 ICMR = 0;
302
303 /* all IRQs are IRQ, not FIQ */
304 ICLR = 0;
305
306 /* clear all GPIO edge detects */
307 GFER = 0;
308 GRER = 0;
309 GEDR = -1;
310
311 /*
312 * Whatever the doc says, this has to be set for the wait-on-irq
313 * instruction to work... on a SA1100 rev 9 at least.
314 */
315 ICCR = 1;
316
317 for (irq = 0; irq <= 10; irq++) {
Thomas Gleixnerf38c02f2011-03-24 13:35:09 +0100318 irq_set_chip_and_handler(irq, &sa1100_low_gpio_chip,
319 handle_edge_irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320 set_irq_flags(irq, IRQF_VALID | IRQF_PROBE);
321 }
322
323 for (irq = 12; irq <= 31; irq++) {
Thomas Gleixnerf38c02f2011-03-24 13:35:09 +0100324 irq_set_chip_and_handler(irq, &sa1100_normal_chip,
325 handle_level_irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326 set_irq_flags(irq, IRQF_VALID);
327 }
328
329 for (irq = 32; irq <= 48; irq++) {
Thomas Gleixnerf38c02f2011-03-24 13:35:09 +0100330 irq_set_chip_and_handler(irq, &sa1100_high_gpio_chip,
331 handle_edge_irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332 set_irq_flags(irq, IRQF_VALID | IRQF_PROBE);
333 }
334
335 /*
336 * Install handler for GPIO 11-27 edge detect interrupts
337 */
Thomas Gleixner6845664a2011-03-24 13:25:22 +0100338 irq_set_chip(IRQ_GPIO11_27, &sa1100_normal_chip);
339 irq_set_chained_handler(IRQ_GPIO11_27, sa1100_high_gpio_handler);
Dmitry Baryshkov45528e32008-04-10 13:31:47 +0100340
341 sa1100_init_gpio();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342}