blob: 981db9878b27ae6f33e9c51a0e0be7b5c28b5ae7 [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
Lennert Buytenhekc4e89642010-11-29 11:12:06 +010038static int sa1100_gpio_type(struct irq_data *d, unsigned int type)
Linus Torvalds1da177e2005-04-16 15:20:36 -070039{
40 unsigned int mask;
41
Dmitry Eremin-Solenikov1eeec6a2014-11-28 15:57:32 +010042 mask = BIT(d->hwirq);
Linus Torvalds1da177e2005-04-16 15:20:36 -070043
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +010044 if (type == IRQ_TYPE_PROBE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070045 if ((GPIO_IRQ_rising_edge | GPIO_IRQ_falling_edge) & mask)
46 return 0;
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +010047 type = IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING;
Linus Torvalds1da177e2005-04-16 15:20:36 -070048 }
49
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +010050 if (type & IRQ_TYPE_EDGE_RISING) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070051 GPIO_IRQ_rising_edge |= mask;
52 } else
53 GPIO_IRQ_rising_edge &= ~mask;
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +010054 if (type & IRQ_TYPE_EDGE_FALLING) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070055 GPIO_IRQ_falling_edge |= mask;
56 } else
57 GPIO_IRQ_falling_edge &= ~mask;
58
59 GRER = GPIO_IRQ_rising_edge & GPIO_IRQ_mask;
60 GFER = GPIO_IRQ_falling_edge & GPIO_IRQ_mask;
61
62 return 0;
63}
64
65/*
Dmitry Eremin-Solenikov0fea30c2014-11-28 15:56:13 +010066 * GPIO IRQs must be acknowledged. This is for IRQs from GPIO0 to 10.
Linus Torvalds1da177e2005-04-16 15:20:36 -070067 */
Lennert Buytenhekc4e89642010-11-29 11:12:06 +010068static void sa1100_low_gpio_ack(struct irq_data *d)
Linus Torvalds1da177e2005-04-16 15:20:36 -070069{
Dmitry Eremin-Solenikov1eeec6a2014-11-28 15:57:32 +010070 GEDR = BIT(d->hwirq);
Linus Torvalds1da177e2005-04-16 15:20:36 -070071}
72
Lennert Buytenhekc4e89642010-11-29 11:12:06 +010073static void sa1100_low_gpio_mask(struct irq_data *d)
Linus Torvalds1da177e2005-04-16 15:20:36 -070074{
Dmitry Eremin-Solenikov1eeec6a2014-11-28 15:57:32 +010075 ICMR &= ~BIT(d->hwirq);
Linus Torvalds1da177e2005-04-16 15:20:36 -070076}
77
Lennert Buytenhekc4e89642010-11-29 11:12:06 +010078static void sa1100_low_gpio_unmask(struct irq_data *d)
Linus Torvalds1da177e2005-04-16 15:20:36 -070079{
Dmitry Eremin-Solenikov1eeec6a2014-11-28 15:57:32 +010080 ICMR |= BIT(d->hwirq);
Linus Torvalds1da177e2005-04-16 15:20:36 -070081}
82
Lennert Buytenhekc4e89642010-11-29 11:12:06 +010083static int sa1100_low_gpio_wake(struct irq_data *d, unsigned int on)
Linus Torvalds1da177e2005-04-16 15:20:36 -070084{
85 if (on)
Dmitry Eremin-Solenikov1eeec6a2014-11-28 15:57:32 +010086 PWER |= BIT(d->hwirq);
Linus Torvalds1da177e2005-04-16 15:20:36 -070087 else
Dmitry Eremin-Solenikov1eeec6a2014-11-28 15:57:32 +010088 PWER &= ~BIT(d->hwirq);
Linus Torvalds1da177e2005-04-16 15:20:36 -070089 return 0;
90}
91
David Brownell38c677c2006-08-01 22:26:25 +010092static struct irq_chip sa1100_low_gpio_chip = {
93 .name = "GPIO-l",
Lennert Buytenhekc4e89642010-11-29 11:12:06 +010094 .irq_ack = sa1100_low_gpio_ack,
95 .irq_mask = sa1100_low_gpio_mask,
96 .irq_unmask = sa1100_low_gpio_unmask,
97 .irq_set_type = sa1100_gpio_type,
98 .irq_set_wake = sa1100_low_gpio_wake,
Linus Torvalds1da177e2005-04-16 15:20:36 -070099};
100
Dmitry Eremin-Solenikov1eca42b2014-11-28 15:56:54 +0100101static int sa1100_low_gpio_irqdomain_map(struct irq_domain *d,
102 unsigned int irq, irq_hw_number_t hwirq)
103{
104 irq_set_chip_and_handler(irq, &sa1100_low_gpio_chip,
105 handle_edge_irq);
106 set_irq_flags(irq, IRQF_VALID | IRQF_PROBE);
107
108 return 0;
109}
110
111static struct irq_domain_ops sa1100_low_gpio_irqdomain_ops = {
112 .map = sa1100_low_gpio_irqdomain_map,
113 .xlate = irq_domain_xlate_onetwocell,
114};
115
116static struct irq_domain *sa1100_low_gpio_irqdomain;
117
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118/*
119 * IRQ11 (GPIO11 through 27) handler. We enter here with the
120 * irq_controller_lock held, and IRQs disabled. Decode the IRQ
121 * and call the handler.
122 */
123static void
Russell King10dd5ce2006-11-23 11:41:32 +0000124sa1100_high_gpio_handler(unsigned int irq, struct irq_desc *desc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125{
126 unsigned int mask;
127
128 mask = GEDR & 0xfffff800;
129 do {
130 /*
131 * clear down all currently active IRQ sources.
132 * We will be processing them all.
133 */
134 GEDR = mask;
135
136 irq = IRQ_GPIO11;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 mask >>= 11;
138 do {
139 if (mask & 1)
Dmitry Baryshkovd8aa0252008-10-09 13:36:24 +0100140 generic_handle_irq(irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 mask >>= 1;
142 irq++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 } while (mask);
144
145 mask = GEDR & 0xfffff800;
146 } while (mask);
147}
148
149/*
150 * Like GPIO0 to 10, GPIO11-27 IRQs need to be handled specially.
151 * In addition, the IRQs are all collected up into one bit in the
152 * interrupt controller registers.
153 */
Lennert Buytenhekc4e89642010-11-29 11:12:06 +0100154static void sa1100_high_gpio_ack(struct irq_data *d)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155{
Dmitry Eremin-Solenikov1eeec6a2014-11-28 15:57:32 +0100156 unsigned int mask = BIT(d->hwirq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157
158 GEDR = mask;
159}
160
Lennert Buytenhekc4e89642010-11-29 11:12:06 +0100161static void sa1100_high_gpio_mask(struct irq_data *d)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162{
Dmitry Eremin-Solenikov1eeec6a2014-11-28 15:57:32 +0100163 unsigned int mask = BIT(d->hwirq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164
165 GPIO_IRQ_mask &= ~mask;
166
167 GRER &= ~mask;
168 GFER &= ~mask;
169}
170
Lennert Buytenhekc4e89642010-11-29 11:12:06 +0100171static void sa1100_high_gpio_unmask(struct irq_data *d)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172{
Dmitry Eremin-Solenikov1eeec6a2014-11-28 15:57:32 +0100173 unsigned int mask = BIT(d->hwirq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174
175 GPIO_IRQ_mask |= mask;
176
177 GRER = GPIO_IRQ_rising_edge & GPIO_IRQ_mask;
178 GFER = GPIO_IRQ_falling_edge & GPIO_IRQ_mask;
179}
180
Lennert Buytenhekc4e89642010-11-29 11:12:06 +0100181static int sa1100_high_gpio_wake(struct irq_data *d, unsigned int on)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182{
183 if (on)
Dmitry Eremin-Solenikov1eeec6a2014-11-28 15:57:32 +0100184 PWER |= BIT(d->hwirq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185 else
Dmitry Eremin-Solenikov1eeec6a2014-11-28 15:57:32 +0100186 PWER &= ~BIT(d->hwirq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187 return 0;
188}
189
David Brownell38c677c2006-08-01 22:26:25 +0100190static struct irq_chip sa1100_high_gpio_chip = {
191 .name = "GPIO-h",
Lennert Buytenhekc4e89642010-11-29 11:12:06 +0100192 .irq_ack = sa1100_high_gpio_ack,
193 .irq_mask = sa1100_high_gpio_mask,
194 .irq_unmask = sa1100_high_gpio_unmask,
195 .irq_set_type = sa1100_gpio_type,
196 .irq_set_wake = sa1100_high_gpio_wake,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197};
198
Dmitry Eremin-Solenikov1eca42b2014-11-28 15:56:54 +0100199static int sa1100_high_gpio_irqdomain_map(struct irq_domain *d,
200 unsigned int irq, irq_hw_number_t hwirq)
201{
202 irq_set_chip_and_handler(irq, &sa1100_high_gpio_chip,
203 handle_edge_irq);
204 set_irq_flags(irq, IRQF_VALID | IRQF_PROBE);
205
206 return 0;
207}
208
209static struct irq_domain_ops sa1100_high_gpio_irqdomain_ops = {
210 .map = sa1100_high_gpio_irqdomain_map,
211 .xlate = irq_domain_xlate_onetwocell,
212};
213
214static struct irq_domain *sa1100_high_gpio_irqdomain;
215
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216/*
217 * We don't need to ACK IRQs on the SA1100 unless they're GPIOs
Dmitry Eremin-Solenikov0fea30c2014-11-28 15:56:13 +0100218 * this is for internal IRQs i.e. from IRQ LCD to RTCAlrm.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219 */
Lennert Buytenhekc4e89642010-11-29 11:12:06 +0100220static void sa1100_mask_irq(struct irq_data *d)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221{
Dmitry Eremin-Solenikov1eeec6a2014-11-28 15:57:32 +0100222 ICMR &= ~BIT(d->hwirq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223}
224
Lennert Buytenhekc4e89642010-11-29 11:12:06 +0100225static void sa1100_unmask_irq(struct irq_data *d)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226{
Dmitry Eremin-Solenikov1eeec6a2014-11-28 15:57:32 +0100227 ICMR |= BIT(d->hwirq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228}
229
Russell King19ca5d22006-05-06 11:26:30 +0100230/*
231 * Apart form GPIOs, only the RTC alarm can be a wakeup event.
232 */
Lennert Buytenhekc4e89642010-11-29 11:12:06 +0100233static int sa1100_set_wake(struct irq_data *d, unsigned int on)
Russell King19ca5d22006-05-06 11:26:30 +0100234{
Dmitry Eremin-Solenikov1eeec6a2014-11-28 15:57:32 +0100235 if (BIT(d->hwirq) == IC_RTCAlrm) {
Russell King19ca5d22006-05-06 11:26:30 +0100236 if (on)
237 PWER |= PWER_RTC;
238 else
239 PWER &= ~PWER_RTC;
240 return 0;
241 }
242 return -EINVAL;
243}
244
David Brownell38c677c2006-08-01 22:26:25 +0100245static struct irq_chip sa1100_normal_chip = {
246 .name = "SC",
Lennert Buytenhekc4e89642010-11-29 11:12:06 +0100247 .irq_ack = sa1100_mask_irq,
248 .irq_mask = sa1100_mask_irq,
249 .irq_unmask = sa1100_unmask_irq,
250 .irq_set_wake = sa1100_set_wake,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251};
252
Dmitry Eremin-Solenikov1eca42b2014-11-28 15:56:54 +0100253static int sa1100_normal_irqdomain_map(struct irq_domain *d,
254 unsigned int irq, irq_hw_number_t hwirq)
255{
256 irq_set_chip_and_handler(irq, &sa1100_normal_chip,
257 handle_level_irq);
258 set_irq_flags(irq, IRQF_VALID);
259
260 return 0;
261}
262
263static struct irq_domain_ops sa1100_normal_irqdomain_ops = {
264 .map = sa1100_normal_irqdomain_map,
265 .xlate = irq_domain_xlate_onetwocell,
266};
267
268static struct irq_domain *sa1100_normal_irqdomain;
269
Russell Kinga1810992012-01-12 10:25:29 +0000270static struct resource irq_resource =
271 DEFINE_RES_MEM_NAMED(0x90050000, SZ_64K, "irqs");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272
273static struct sa1100irq_state {
274 unsigned int saved;
275 unsigned int icmr;
276 unsigned int iclr;
277 unsigned int iccr;
278} sa1100irq_state;
279
Rafael J. Wysocki90533982011-04-22 22:03:03 +0200280static int sa1100irq_suspend(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281{
282 struct sa1100irq_state *st = &sa1100irq_state;
283
284 st->saved = 1;
285 st->icmr = ICMR;
286 st->iclr = ICLR;
287 st->iccr = ICCR;
288
289 /*
290 * Disable all GPIO-based interrupts.
291 */
292 ICMR &= ~(IC_GPIO11_27|IC_GPIO10|IC_GPIO9|IC_GPIO8|IC_GPIO7|
293 IC_GPIO6|IC_GPIO5|IC_GPIO4|IC_GPIO3|IC_GPIO2|
294 IC_GPIO1|IC_GPIO0);
295
296 /*
297 * Set the appropriate edges for wakeup.
298 */
299 GRER = PWER & GPIO_IRQ_rising_edge;
300 GFER = PWER & GPIO_IRQ_falling_edge;
301
302 /*
303 * Clear any pending GPIO interrupts.
304 */
305 GEDR = GEDR;
306
307 return 0;
308}
309
Rafael J. Wysocki90533982011-04-22 22:03:03 +0200310static void sa1100irq_resume(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311{
312 struct sa1100irq_state *st = &sa1100irq_state;
313
314 if (st->saved) {
315 ICCR = st->iccr;
316 ICLR = st->iclr;
317
318 GRER = GPIO_IRQ_rising_edge & GPIO_IRQ_mask;
319 GFER = GPIO_IRQ_falling_edge & GPIO_IRQ_mask;
320
321 ICMR = st->icmr;
322 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323}
324
Rafael J. Wysocki90533982011-04-22 22:03:03 +0200325static struct syscore_ops sa1100irq_syscore_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326 .suspend = sa1100irq_suspend,
327 .resume = sa1100irq_resume,
328};
329
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330static int __init sa1100irq_init_devicefs(void)
331{
Rafael J. Wysocki90533982011-04-22 22:03:03 +0200332 register_syscore_ops(&sa1100irq_syscore_ops);
333 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334}
335
336device_initcall(sa1100irq_init_devicefs);
337
Dmitry Eremin-Solenikovaffcab32014-11-28 15:55:16 +0100338static asmlinkage void __exception_irq_entry
339sa1100_handle_irq(struct pt_regs *regs)
340{
341 uint32_t icip, icmr, mask;
342
343 do {
344 icip = (ICIP);
345 icmr = (ICMR);
346 mask = icip & icmr;
347
348 if (mask == 0)
349 break;
350
351 handle_IRQ(ffs(mask) - 1 + IRQ_GPIO0, regs);
352 } while (1);
353}
354
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355void __init sa1100_init_irq(void)
356{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357 request_resource(&iomem_resource, &irq_resource);
358
359 /* disable all IRQs */
360 ICMR = 0;
361
362 /* all IRQs are IRQ, not FIQ */
363 ICLR = 0;
364
365 /* clear all GPIO edge detects */
366 GFER = 0;
367 GRER = 0;
368 GEDR = -1;
369
370 /*
371 * Whatever the doc says, this has to be set for the wait-on-irq
372 * instruction to work... on a SA1100 rev 9 at least.
373 */
374 ICCR = 1;
375
Dmitry Eremin-Solenikov1eca42b2014-11-28 15:56:54 +0100376 sa1100_low_gpio_irqdomain = irq_domain_add_legacy(NULL,
377 11, IRQ_GPIO0, 0,
378 &sa1100_low_gpio_irqdomain_ops, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379
Dmitry Eremin-Solenikov1eca42b2014-11-28 15:56:54 +0100380 sa1100_normal_irqdomain = irq_domain_add_legacy(NULL,
Dmitry Eremin-Solenikov0ebd465f2014-11-28 15:57:11 +0100381 21, IRQ_GPIO11_27, 11,
Dmitry Eremin-Solenikov1eca42b2014-11-28 15:56:54 +0100382 &sa1100_normal_irqdomain_ops, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383
Dmitry Eremin-Solenikov1eca42b2014-11-28 15:56:54 +0100384 sa1100_high_gpio_irqdomain = irq_domain_add_legacy(NULL,
385 17, IRQ_GPIO11, 11,
386 &sa1100_high_gpio_irqdomain_ops, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387
388 /*
389 * Install handler for GPIO 11-27 edge detect interrupts
390 */
Thomas Gleixner6845664a2011-03-24 13:25:22 +0100391 irq_set_chained_handler(IRQ_GPIO11_27, sa1100_high_gpio_handler);
Dmitry Baryshkov45528e32008-04-10 13:31:47 +0100392
Dmitry Eremin-Solenikovaffcab32014-11-28 15:55:16 +0100393 set_handle_irq(sa1100_handle_irq);
394
Dmitry Baryshkov45528e32008-04-10 13:31:47 +0100395 sa1100_init_gpio();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396}