blob: 14a7633e3cbe0e4b50ab694f37f4e51531f28724 [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>
Dmitry Eremin-Solenikov1eca42b2014-11-28 15:56:54 +010017#include <linux/irqdomain.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#include <linux/ioport.h>
Rafael J. Wysocki90533982011-04-22 22:03:03 +020019#include <linux/syscore_ops.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020
Russell Kinga09e64f2008-08-05 16:14:15 +010021#include <mach/hardware.h>
Rob Herringf314f332012-02-24 00:06:51 +010022#include <mach/irqs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070023#include <asm/mach/irq.h>
Dmitry Eremin-Solenikovaffcab32014-11-28 15:55:16 +010024#include <asm/exception.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070025
26#include "generic.h"
27
28
29/*
30 * SA1100 GPIO edge detection for IRQs:
31 * IRQs are generated on Falling-Edge, Rising-Edge, or both.
32 * Use this instead of directly setting GRER/GFER.
33 */
34static int GPIO_IRQ_rising_edge;
35static int GPIO_IRQ_falling_edge;
36static int GPIO_IRQ_mask = (1 << 11) - 1;
37
38/*
39 * To get the GPIO number from an IRQ number
40 */
Dmitry Eremin-Solenikov0fea30c2014-11-28 15:56:13 +010041#define GPIO_11_27_IRQ(i) ((i) + 11 - IRQ_GPIO11)
Linus Torvalds1da177e2005-04-16 15:20:36 -070042#define GPIO11_27_MASK(irq) (1 << GPIO_11_27_IRQ(irq))
43
Lennert Buytenhekc4e89642010-11-29 11:12:06 +010044static int sa1100_gpio_type(struct irq_data *d, unsigned int type)
Linus Torvalds1da177e2005-04-16 15:20:36 -070045{
46 unsigned int mask;
47
Dmitry Eremin-Solenikov0fea30c2014-11-28 15:56:13 +010048 if (d->irq <= IRQ_GPIO10)
Lennert Buytenhekc4e89642010-11-29 11:12:06 +010049 mask = 1 << d->irq;
Linus Torvalds1da177e2005-04-16 15:20:36 -070050 else
Lennert Buytenhekc4e89642010-11-29 11:12:06 +010051 mask = GPIO11_27_MASK(d->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +010053 if (type == IRQ_TYPE_PROBE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070054 if ((GPIO_IRQ_rising_edge | GPIO_IRQ_falling_edge) & mask)
55 return 0;
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +010056 type = IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING;
Linus Torvalds1da177e2005-04-16 15:20:36 -070057 }
58
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +010059 if (type & IRQ_TYPE_EDGE_RISING) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070060 GPIO_IRQ_rising_edge |= mask;
61 } else
62 GPIO_IRQ_rising_edge &= ~mask;
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +010063 if (type & IRQ_TYPE_EDGE_FALLING) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070064 GPIO_IRQ_falling_edge |= mask;
65 } else
66 GPIO_IRQ_falling_edge &= ~mask;
67
68 GRER = GPIO_IRQ_rising_edge & GPIO_IRQ_mask;
69 GFER = GPIO_IRQ_falling_edge & GPIO_IRQ_mask;
70
71 return 0;
72}
73
74/*
Dmitry Eremin-Solenikov0fea30c2014-11-28 15:56:13 +010075 * GPIO IRQs must be acknowledged. This is for IRQs from GPIO0 to 10.
Linus Torvalds1da177e2005-04-16 15:20:36 -070076 */
Lennert Buytenhekc4e89642010-11-29 11:12:06 +010077static void sa1100_low_gpio_ack(struct irq_data *d)
Linus Torvalds1da177e2005-04-16 15:20:36 -070078{
Lennert Buytenhekc4e89642010-11-29 11:12:06 +010079 GEDR = (1 << d->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -070080}
81
Lennert Buytenhekc4e89642010-11-29 11:12:06 +010082static void sa1100_low_gpio_mask(struct irq_data *d)
Linus Torvalds1da177e2005-04-16 15:20:36 -070083{
Lennert Buytenhekc4e89642010-11-29 11:12:06 +010084 ICMR &= ~(1 << d->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -070085}
86
Lennert Buytenhekc4e89642010-11-29 11:12:06 +010087static void sa1100_low_gpio_unmask(struct irq_data *d)
Linus Torvalds1da177e2005-04-16 15:20:36 -070088{
Lennert Buytenhekc4e89642010-11-29 11:12:06 +010089 ICMR |= 1 << d->irq;
Linus Torvalds1da177e2005-04-16 15:20:36 -070090}
91
Lennert Buytenhekc4e89642010-11-29 11:12:06 +010092static int sa1100_low_gpio_wake(struct irq_data *d, unsigned int on)
Linus Torvalds1da177e2005-04-16 15:20:36 -070093{
94 if (on)
Lennert Buytenhekc4e89642010-11-29 11:12:06 +010095 PWER |= 1 << d->irq;
Linus Torvalds1da177e2005-04-16 15:20:36 -070096 else
Lennert Buytenhekc4e89642010-11-29 11:12:06 +010097 PWER &= ~(1 << d->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 return 0;
99}
100
David Brownell38c677c2006-08-01 22:26:25 +0100101static struct irq_chip sa1100_low_gpio_chip = {
102 .name = "GPIO-l",
Lennert Buytenhekc4e89642010-11-29 11:12:06 +0100103 .irq_ack = sa1100_low_gpio_ack,
104 .irq_mask = sa1100_low_gpio_mask,
105 .irq_unmask = sa1100_low_gpio_unmask,
106 .irq_set_type = sa1100_gpio_type,
107 .irq_set_wake = sa1100_low_gpio_wake,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108};
109
Dmitry Eremin-Solenikov1eca42b2014-11-28 15:56:54 +0100110static int sa1100_low_gpio_irqdomain_map(struct irq_domain *d,
111 unsigned int irq, irq_hw_number_t hwirq)
112{
113 irq_set_chip_and_handler(irq, &sa1100_low_gpio_chip,
114 handle_edge_irq);
115 set_irq_flags(irq, IRQF_VALID | IRQF_PROBE);
116
117 return 0;
118}
119
120static struct irq_domain_ops sa1100_low_gpio_irqdomain_ops = {
121 .map = sa1100_low_gpio_irqdomain_map,
122 .xlate = irq_domain_xlate_onetwocell,
123};
124
125static struct irq_domain *sa1100_low_gpio_irqdomain;
126
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127/*
128 * IRQ11 (GPIO11 through 27) handler. We enter here with the
129 * irq_controller_lock held, and IRQs disabled. Decode the IRQ
130 * and call the handler.
131 */
132static void
Russell King10dd5ce2006-11-23 11:41:32 +0000133sa1100_high_gpio_handler(unsigned int irq, struct irq_desc *desc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134{
135 unsigned int mask;
136
137 mask = GEDR & 0xfffff800;
138 do {
139 /*
140 * clear down all currently active IRQ sources.
141 * We will be processing them all.
142 */
143 GEDR = mask;
144
145 irq = IRQ_GPIO11;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146 mask >>= 11;
147 do {
148 if (mask & 1)
Dmitry Baryshkovd8aa0252008-10-09 13:36:24 +0100149 generic_handle_irq(irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150 mask >>= 1;
151 irq++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152 } while (mask);
153
154 mask = GEDR & 0xfffff800;
155 } while (mask);
156}
157
158/*
159 * Like GPIO0 to 10, GPIO11-27 IRQs need to be handled specially.
160 * In addition, the IRQs are all collected up into one bit in the
161 * interrupt controller registers.
162 */
Lennert Buytenhekc4e89642010-11-29 11:12:06 +0100163static void sa1100_high_gpio_ack(struct irq_data *d)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164{
Lennert Buytenhekc4e89642010-11-29 11:12:06 +0100165 unsigned int mask = GPIO11_27_MASK(d->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166
167 GEDR = mask;
168}
169
Lennert Buytenhekc4e89642010-11-29 11:12:06 +0100170static void sa1100_high_gpio_mask(struct irq_data *d)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171{
Lennert Buytenhekc4e89642010-11-29 11:12:06 +0100172 unsigned int mask = GPIO11_27_MASK(d->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173
174 GPIO_IRQ_mask &= ~mask;
175
176 GRER &= ~mask;
177 GFER &= ~mask;
178}
179
Lennert Buytenhekc4e89642010-11-29 11:12:06 +0100180static void sa1100_high_gpio_unmask(struct irq_data *d)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181{
Lennert Buytenhekc4e89642010-11-29 11:12:06 +0100182 unsigned int mask = GPIO11_27_MASK(d->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183
184 GPIO_IRQ_mask |= mask;
185
186 GRER = GPIO_IRQ_rising_edge & GPIO_IRQ_mask;
187 GFER = GPIO_IRQ_falling_edge & GPIO_IRQ_mask;
188}
189
Lennert Buytenhekc4e89642010-11-29 11:12:06 +0100190static int sa1100_high_gpio_wake(struct irq_data *d, unsigned int on)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191{
192 if (on)
Lennert Buytenhekc4e89642010-11-29 11:12:06 +0100193 PWER |= GPIO11_27_MASK(d->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194 else
Lennert Buytenhekc4e89642010-11-29 11:12:06 +0100195 PWER &= ~GPIO11_27_MASK(d->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196 return 0;
197}
198
David Brownell38c677c2006-08-01 22:26:25 +0100199static struct irq_chip sa1100_high_gpio_chip = {
200 .name = "GPIO-h",
Lennert Buytenhekc4e89642010-11-29 11:12:06 +0100201 .irq_ack = sa1100_high_gpio_ack,
202 .irq_mask = sa1100_high_gpio_mask,
203 .irq_unmask = sa1100_high_gpio_unmask,
204 .irq_set_type = sa1100_gpio_type,
205 .irq_set_wake = sa1100_high_gpio_wake,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206};
207
Dmitry Eremin-Solenikov1eca42b2014-11-28 15:56:54 +0100208static int sa1100_high_gpio_irqdomain_map(struct irq_domain *d,
209 unsigned int irq, irq_hw_number_t hwirq)
210{
211 irq_set_chip_and_handler(irq, &sa1100_high_gpio_chip,
212 handle_edge_irq);
213 set_irq_flags(irq, IRQF_VALID | IRQF_PROBE);
214
215 return 0;
216}
217
218static struct irq_domain_ops sa1100_high_gpio_irqdomain_ops = {
219 .map = sa1100_high_gpio_irqdomain_map,
220 .xlate = irq_domain_xlate_onetwocell,
221};
222
223static struct irq_domain *sa1100_high_gpio_irqdomain;
224
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225/*
226 * We don't need to ACK IRQs on the SA1100 unless they're GPIOs
Dmitry Eremin-Solenikov0fea30c2014-11-28 15:56:13 +0100227 * this is for internal IRQs i.e. from IRQ LCD to RTCAlrm.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 */
Lennert Buytenhekc4e89642010-11-29 11:12:06 +0100229static void sa1100_mask_irq(struct irq_data *d)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230{
Lennert Buytenhekc4e89642010-11-29 11:12:06 +0100231 ICMR &= ~(1 << d->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232}
233
Lennert Buytenhekc4e89642010-11-29 11:12:06 +0100234static void sa1100_unmask_irq(struct irq_data *d)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235{
Lennert Buytenhekc4e89642010-11-29 11:12:06 +0100236 ICMR |= (1 << d->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237}
238
Russell King19ca5d22006-05-06 11:26:30 +0100239/*
240 * Apart form GPIOs, only the RTC alarm can be a wakeup event.
241 */
Lennert Buytenhekc4e89642010-11-29 11:12:06 +0100242static int sa1100_set_wake(struct irq_data *d, unsigned int on)
Russell King19ca5d22006-05-06 11:26:30 +0100243{
Lennert Buytenhekc4e89642010-11-29 11:12:06 +0100244 if (d->irq == IRQ_RTCAlrm) {
Russell King19ca5d22006-05-06 11:26:30 +0100245 if (on)
246 PWER |= PWER_RTC;
247 else
248 PWER &= ~PWER_RTC;
249 return 0;
250 }
251 return -EINVAL;
252}
253
David Brownell38c677c2006-08-01 22:26:25 +0100254static struct irq_chip sa1100_normal_chip = {
255 .name = "SC",
Lennert Buytenhekc4e89642010-11-29 11:12:06 +0100256 .irq_ack = sa1100_mask_irq,
257 .irq_mask = sa1100_mask_irq,
258 .irq_unmask = sa1100_unmask_irq,
259 .irq_set_wake = sa1100_set_wake,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260};
261
Dmitry Eremin-Solenikov1eca42b2014-11-28 15:56:54 +0100262static int sa1100_normal_irqdomain_map(struct irq_domain *d,
263 unsigned int irq, irq_hw_number_t hwirq)
264{
265 irq_set_chip_and_handler(irq, &sa1100_normal_chip,
266 handle_level_irq);
267 set_irq_flags(irq, IRQF_VALID);
268
269 return 0;
270}
271
272static struct irq_domain_ops sa1100_normal_irqdomain_ops = {
273 .map = sa1100_normal_irqdomain_map,
274 .xlate = irq_domain_xlate_onetwocell,
275};
276
277static struct irq_domain *sa1100_normal_irqdomain;
278
Russell Kinga1810992012-01-12 10:25:29 +0000279static struct resource irq_resource =
280 DEFINE_RES_MEM_NAMED(0x90050000, SZ_64K, "irqs");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281
282static struct sa1100irq_state {
283 unsigned int saved;
284 unsigned int icmr;
285 unsigned int iclr;
286 unsigned int iccr;
287} sa1100irq_state;
288
Rafael J. Wysocki90533982011-04-22 22:03:03 +0200289static int sa1100irq_suspend(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290{
291 struct sa1100irq_state *st = &sa1100irq_state;
292
293 st->saved = 1;
294 st->icmr = ICMR;
295 st->iclr = ICLR;
296 st->iccr = ICCR;
297
298 /*
299 * Disable all GPIO-based interrupts.
300 */
301 ICMR &= ~(IC_GPIO11_27|IC_GPIO10|IC_GPIO9|IC_GPIO8|IC_GPIO7|
302 IC_GPIO6|IC_GPIO5|IC_GPIO4|IC_GPIO3|IC_GPIO2|
303 IC_GPIO1|IC_GPIO0);
304
305 /*
306 * Set the appropriate edges for wakeup.
307 */
308 GRER = PWER & GPIO_IRQ_rising_edge;
309 GFER = PWER & GPIO_IRQ_falling_edge;
310
311 /*
312 * Clear any pending GPIO interrupts.
313 */
314 GEDR = GEDR;
315
316 return 0;
317}
318
Rafael J. Wysocki90533982011-04-22 22:03:03 +0200319static void sa1100irq_resume(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320{
321 struct sa1100irq_state *st = &sa1100irq_state;
322
323 if (st->saved) {
324 ICCR = st->iccr;
325 ICLR = st->iclr;
326
327 GRER = GPIO_IRQ_rising_edge & GPIO_IRQ_mask;
328 GFER = GPIO_IRQ_falling_edge & GPIO_IRQ_mask;
329
330 ICMR = st->icmr;
331 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332}
333
Rafael J. Wysocki90533982011-04-22 22:03:03 +0200334static struct syscore_ops sa1100irq_syscore_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335 .suspend = sa1100irq_suspend,
336 .resume = sa1100irq_resume,
337};
338
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339static int __init sa1100irq_init_devicefs(void)
340{
Rafael J. Wysocki90533982011-04-22 22:03:03 +0200341 register_syscore_ops(&sa1100irq_syscore_ops);
342 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343}
344
345device_initcall(sa1100irq_init_devicefs);
346
Dmitry Eremin-Solenikovaffcab32014-11-28 15:55:16 +0100347static asmlinkage void __exception_irq_entry
348sa1100_handle_irq(struct pt_regs *regs)
349{
350 uint32_t icip, icmr, mask;
351
352 do {
353 icip = (ICIP);
354 icmr = (ICMR);
355 mask = icip & icmr;
356
357 if (mask == 0)
358 break;
359
360 handle_IRQ(ffs(mask) - 1 + IRQ_GPIO0, regs);
361 } while (1);
362}
363
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364void __init sa1100_init_irq(void)
365{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366 request_resource(&iomem_resource, &irq_resource);
367
368 /* disable all IRQs */
369 ICMR = 0;
370
371 /* all IRQs are IRQ, not FIQ */
372 ICLR = 0;
373
374 /* clear all GPIO edge detects */
375 GFER = 0;
376 GRER = 0;
377 GEDR = -1;
378
379 /*
380 * Whatever the doc says, this has to be set for the wait-on-irq
381 * instruction to work... on a SA1100 rev 9 at least.
382 */
383 ICCR = 1;
384
Dmitry Eremin-Solenikov1eca42b2014-11-28 15:56:54 +0100385 sa1100_low_gpio_irqdomain = irq_domain_add_legacy(NULL,
386 11, IRQ_GPIO0, 0,
387 &sa1100_low_gpio_irqdomain_ops, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388
Dmitry Eremin-Solenikov1eca42b2014-11-28 15:56:54 +0100389 sa1100_normal_irqdomain = irq_domain_add_legacy(NULL,
Dmitry Eremin-Solenikov0ebd465f2014-11-28 15:57:11 +0100390 21, IRQ_GPIO11_27, 11,
Dmitry Eremin-Solenikov1eca42b2014-11-28 15:56:54 +0100391 &sa1100_normal_irqdomain_ops, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392
Dmitry Eremin-Solenikov1eca42b2014-11-28 15:56:54 +0100393 sa1100_high_gpio_irqdomain = irq_domain_add_legacy(NULL,
394 17, IRQ_GPIO11, 11,
395 &sa1100_high_gpio_irqdomain_ops, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396
397 /*
398 * Install handler for GPIO 11-27 edge detect interrupts
399 */
Thomas Gleixner6845664a2011-03-24 13:25:22 +0100400 irq_set_chained_handler(IRQ_GPIO11_27, sa1100_high_gpio_handler);
Dmitry Baryshkov45528e32008-04-10 13:31:47 +0100401
Dmitry Eremin-Solenikovaffcab32014-11-28 15:55:16 +0100402 set_handle_irq(sa1100_handle_irq);
403
Dmitry Baryshkov45528e32008-04-10 13:31:47 +0100404 sa1100_init_gpio();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405}