blob: a7e97a3607da414f6d4d959a3207f39d73e88987 [file] [log] [blame]
Bryan Wu1394f032007-05-06 14:50:22 -07001/*
Robin Getz96f10502009-09-24 14:11:24 +00002 * Set up the interrupt priorities
Bryan Wu1394f032007-05-06 14:50:22 -07003 *
Robin Getz96f10502009-09-24 14:11:24 +00004 * Copyright 2004-2009 Analog Devices Inc.
5 * 2003 Bas Vermeulen <bas@buyways.nl>
6 * 2002 Arcturus Networks Inc. MaTed <mated@sympatico.ca>
7 * 2000-2001 Lineo, Inc. D. Jefff Dionne <jeff@lineo.ca>
8 * 1999 D. Jeff Dionne <jeff@uclinux.org>
9 * 1996 Roman Zippel
Bryan Wu1394f032007-05-06 14:50:22 -070010 *
Robin Getz96f10502009-09-24 14:11:24 +000011 * Licensed under the GPL-2
Bryan Wu1394f032007-05-06 14:50:22 -070012 */
13
14#include <linux/module.h>
15#include <linux/kernel_stat.h>
16#include <linux/seq_file.h>
17#include <linux/irq.h>
Philippe Gerum5b5da4c2011-03-17 02:12:48 -040018#include <linux/sched.h>
Steven Miao4f6b6002012-05-16 17:56:51 +080019#include <linux/syscore_ops.h>
20#include <asm/delay.h>
Yi Li6a01f232009-01-07 23:14:39 +080021#ifdef CONFIG_IPIPE
22#include <linux/ipipe.h>
23#endif
Bryan Wu1394f032007-05-06 14:50:22 -070024#include <asm/traps.h>
25#include <asm/blackfin.h>
26#include <asm/gpio.h>
27#include <asm/irq_handler.h>
Mike Frysinger761ec442009-10-15 17:12:05 +000028#include <asm/dpmc.h>
Bryan Wu1394f032007-05-06 14:50:22 -070029
Sonic Zhang11b27cb2012-06-28 19:16:48 +080030#ifndef SEC_GCTL
Steven Miao4f6b6002012-05-16 17:56:51 +080031# define SIC_SYSIRQ(irq) (irq - (IRQ_CORETMR + 1))
32#else
33# define SIC_SYSIRQ(irq) ((irq) - IVG15)
34#endif
Mike Frysinger7beb7432008-11-18 17:48:22 +080035
Bryan Wu1394f032007-05-06 14:50:22 -070036/*
37 * NOTES:
38 * - we have separated the physical Hardware interrupt from the
39 * levels that the LINUX kernel sees (see the description in irq.h)
40 * -
41 */
42
Graf Yang6b3087c2009-01-07 23:14:39 +080043#ifndef CONFIG_SMP
Mike Frysingera99bbcc2007-10-22 00:19:31 +080044/* Initialize this to an actual value to force it into the .data
45 * section so that we know it is properly initialized at entry into
46 * the kernel but before bss is initialized to zero (which is where
47 * it would live otherwise). The 0x1f magic represents the IRQs we
48 * cannot actually mask out in hardware.
49 */
Mike Frysinger40059782008-11-18 17:48:22 +080050unsigned long bfin_irq_flags = 0x1f;
51EXPORT_SYMBOL(bfin_irq_flags);
Graf Yang6b3087c2009-01-07 23:14:39 +080052#endif
Bryan Wu1394f032007-05-06 14:50:22 -070053
Michael Hennerichcfefe3c2008-02-09 04:12:37 +080054#ifdef CONFIG_PM
55unsigned long bfin_sic_iwr[3]; /* Up to 3 SIC_IWRx registers */
Michael Hennerich4a88d0c2008-08-05 17:38:41 +080056unsigned vr_wakeup;
Michael Hennerichcfefe3c2008-02-09 04:12:37 +080057#endif
58
Sonic Zhang11b27cb2012-06-28 19:16:48 +080059#ifndef SEC_GCTL
Mike Frysingere9e334c2011-03-30 00:43:52 -040060static struct ivgx {
Michael Hennerich464abc52008-02-25 13:50:20 +080061 /* irq number for request_irq, available in mach-bf5xx/irq.h */
Roy Huang24a07a12007-07-12 22:41:45 +080062 unsigned int irqno;
Bryan Wu1394f032007-05-06 14:50:22 -070063 /* corresponding bit in the SIC_ISR register */
Roy Huang24a07a12007-07-12 22:41:45 +080064 unsigned int isrflag;
Bryan Wu1394f032007-05-06 14:50:22 -070065} ivg_table[NR_PERI_INTS];
66
Mike Frysingere9e334c2011-03-30 00:43:52 -040067static struct ivg_slice {
Bryan Wu1394f032007-05-06 14:50:22 -070068 /* position of first irq in ivg_table for given ivg */
69 struct ivgx *ifirst;
70 struct ivgx *istop;
71} ivg7_13[IVG13 - IVG7 + 1];
72
Bryan Wu1394f032007-05-06 14:50:22 -070073
74/*
75 * Search SIC_IAR and fill tables with the irqvalues
76 * and their positions in the SIC_ISR register.
77 */
78static void __init search_IAR(void)
79{
80 unsigned ivg, irq_pos = 0;
81 for (ivg = 0; ivg <= IVG13 - IVG7; ivg++) {
Mike Frysinger80fcdb92010-04-22 21:15:00 +000082 int irqN;
Bryan Wu1394f032007-05-06 14:50:22 -070083
Michael Hennerich34e0fc82007-07-12 16:17:18 +080084 ivg7_13[ivg].istop = ivg7_13[ivg].ifirst = &ivg_table[irq_pos];
Bryan Wu1394f032007-05-06 14:50:22 -070085
Mike Frysinger80fcdb92010-04-22 21:15:00 +000086 for (irqN = 0; irqN < NR_PERI_INTS; irqN += 4) {
87 int irqn;
Steven Miao4f6b6002012-05-16 17:56:51 +080088 u32 iar =
89 bfin_read32((unsigned long *)SIC_IAR0 +
Mike Frysinger80fcdb92010-04-22 21:15:00 +000090#if defined(CONFIG_BF51x) || defined(CONFIG_BF52x) || \
91 defined(CONFIG_BF538) || defined(CONFIG_BF539)
92 ((irqN % 32) >> 3) + ((irqN / 32) * ((SIC_IAR4 - SIC_IAR0) / 4))
Michael Hennerich59003142007-10-21 16:54:27 +080093#else
Mike Frysinger80fcdb92010-04-22 21:15:00 +000094 (irqN >> 3)
Michael Hennerich59003142007-10-21 16:54:27 +080095#endif
Mike Frysinger80fcdb92010-04-22 21:15:00 +000096 );
Mike Frysinger80fcdb92010-04-22 21:15:00 +000097 for (irqn = irqN; irqn < irqN + 4; ++irqn) {
98 int iar_shift = (irqn & 7) * 4;
99 if (ivg == (0xf & (iar >> iar_shift))) {
100 ivg_table[irq_pos].irqno = IVG7 + irqn;
101 ivg_table[irq_pos].isrflag = 1 << (irqn % 32);
102 ivg7_13[ivg].istop++;
103 irq_pos++;
104 }
Bryan Wu1394f032007-05-06 14:50:22 -0700105 }
106 }
107 }
108}
Steven Miao4f6b6002012-05-16 17:56:51 +0800109#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700110
111/*
Michael Hennerich464abc52008-02-25 13:50:20 +0800112 * This is for core internal IRQs
Bryan Wu1394f032007-05-06 14:50:22 -0700113 */
Mike Frysingerf58c3272011-04-15 03:08:20 -0400114void bfin_ack_noop(struct irq_data *d)
Bryan Wu1394f032007-05-06 14:50:22 -0700115{
116 /* Dummy function. */
117}
118
Thomas Gleixner4f19ea42011-02-06 18:23:27 +0000119static void bfin_core_mask_irq(struct irq_data *d)
Bryan Wu1394f032007-05-06 14:50:22 -0700120{
Thomas Gleixner4f19ea42011-02-06 18:23:27 +0000121 bfin_irq_flags &= ~(1 << d->irq);
David Howells3b139cd2010-10-07 14:08:52 +0100122 if (!hard_irqs_disabled())
123 hard_local_irq_enable();
Bryan Wu1394f032007-05-06 14:50:22 -0700124}
125
Thomas Gleixner4f19ea42011-02-06 18:23:27 +0000126static void bfin_core_unmask_irq(struct irq_data *d)
Bryan Wu1394f032007-05-06 14:50:22 -0700127{
Thomas Gleixner4f19ea42011-02-06 18:23:27 +0000128 bfin_irq_flags |= 1 << d->irq;
Bryan Wu1394f032007-05-06 14:50:22 -0700129 /*
130 * If interrupts are enabled, IMASK must contain the same value
Mike Frysinger40059782008-11-18 17:48:22 +0800131 * as bfin_irq_flags. Make sure that invariant holds. If interrupts
Bryan Wu1394f032007-05-06 14:50:22 -0700132 * are currently disabled we need not do anything; one of the
133 * callers will take care of setting IMASK to the proper value
134 * when reenabling interrupts.
Mike Frysinger40059782008-11-18 17:48:22 +0800135 * local_irq_enable just does "STI bfin_irq_flags", so it's exactly
Bryan Wu1394f032007-05-06 14:50:22 -0700136 * what we need.
137 */
David Howells3b139cd2010-10-07 14:08:52 +0100138 if (!hard_irqs_disabled())
139 hard_local_irq_enable();
Bryan Wu1394f032007-05-06 14:50:22 -0700140 return;
141}
142
Mike Frysingerf58c3272011-04-15 03:08:20 -0400143void bfin_internal_mask_irq(unsigned int irq)
Bryan Wu1394f032007-05-06 14:50:22 -0700144{
Mike Frysingerfc6bd7b2011-04-15 01:35:53 -0400145 unsigned long flags = hard_local_irq_save();
Sonic Zhang11b27cb2012-06-28 19:16:48 +0800146#ifndef SEC_GCTL
Mike Frysingerfc6bd7b2011-04-15 01:35:53 -0400147#ifdef SIC_IMASK0
148 unsigned mask_bank = SIC_SYSIRQ(irq) / 32;
149 unsigned mask_bit = SIC_SYSIRQ(irq) % 32;
Bryan Wuc04d66b2007-07-12 17:26:31 +0800150 bfin_write_SIC_IMASK(mask_bank, bfin_read_SIC_IMASK(mask_bank) &
Steven Miao4f6b6002012-05-16 17:56:51 +0800151 ~(1 << mask_bit));
152# if defined(CONFIG_SMP) || defined(CONFIG_ICC)
Graf Yang6b3087c2009-01-07 23:14:39 +0800153 bfin_write_SICB_IMASK(mask_bank, bfin_read_SICB_IMASK(mask_bank) &
Steven Miao4f6b6002012-05-16 17:56:51 +0800154 ~(1 << mask_bit));
Mike Frysingerfc6bd7b2011-04-15 01:35:53 -0400155# endif
156#else
157 bfin_write_SIC_IMASK(bfin_read_SIC_IMASK() &
Steven Miao4f6b6002012-05-16 17:56:51 +0800158 ~(1 << SIC_SYSIRQ(irq)));
159#endif /* end of SIC_IMASK0 */
Graf Yang6b3087c2009-01-07 23:14:39 +0800160#endif
David Howells3b139cd2010-10-07 14:08:52 +0100161 hard_local_irq_restore(flags);
Bryan Wu1394f032007-05-06 14:50:22 -0700162}
163
Thomas Gleixnerff43a672011-02-06 18:23:29 +0000164static void bfin_internal_mask_irq_chip(struct irq_data *d)
165{
166 bfin_internal_mask_irq(d->irq);
167}
168
Sonic Zhang0325f252009-12-28 07:29:57 +0000169#ifdef CONFIG_SMP
Steven Miao4f6b6002012-05-16 17:56:51 +0800170void bfin_internal_unmask_irq_affinity(unsigned int irq,
Sonic Zhang0325f252009-12-28 07:29:57 +0000171 const struct cpumask *affinity)
172#else
Mike Frysingerf58c3272011-04-15 03:08:20 -0400173void bfin_internal_unmask_irq(unsigned int irq)
Sonic Zhang0325f252009-12-28 07:29:57 +0000174#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700175{
Mike Frysingerfc6bd7b2011-04-15 01:35:53 -0400176 unsigned long flags = hard_local_irq_save();
Philippe Gerum9bd50df2009-03-04 16:52:38 +0800177
Sonic Zhang11b27cb2012-06-28 19:16:48 +0800178#ifndef SEC_GCTL
Mike Frysingerfc6bd7b2011-04-15 01:35:53 -0400179#ifdef SIC_IMASK0
180 unsigned mask_bank = SIC_SYSIRQ(irq) / 32;
181 unsigned mask_bit = SIC_SYSIRQ(irq) % 32;
182# ifdef CONFIG_SMP
Sonic Zhang0325f252009-12-28 07:29:57 +0000183 if (cpumask_test_cpu(0, affinity))
Mike Frysingerfc6bd7b2011-04-15 01:35:53 -0400184# endif
Sonic Zhang0325f252009-12-28 07:29:57 +0000185 bfin_write_SIC_IMASK(mask_bank,
Steven Miao4f6b6002012-05-16 17:56:51 +0800186 bfin_read_SIC_IMASK(mask_bank) |
187 (1 << mask_bit));
Mike Frysingerfc6bd7b2011-04-15 01:35:53 -0400188# ifdef CONFIG_SMP
Sonic Zhang0325f252009-12-28 07:29:57 +0000189 if (cpumask_test_cpu(1, affinity))
190 bfin_write_SICB_IMASK(mask_bank,
Steven Miao4f6b6002012-05-16 17:56:51 +0800191 bfin_read_SICB_IMASK(mask_bank) |
192 (1 << mask_bit));
Mike Frysingerfc6bd7b2011-04-15 01:35:53 -0400193# endif
194#else
195 bfin_write_SIC_IMASK(bfin_read_SIC_IMASK() |
Steven Miao4f6b6002012-05-16 17:56:51 +0800196 (1 << SIC_SYSIRQ(irq)));
Graf Yang6b3087c2009-01-07 23:14:39 +0800197#endif
Steven Miao4f6b6002012-05-16 17:56:51 +0800198#endif
199 hard_local_irq_restore(flags);
200}
201
Sonic Zhang11b27cb2012-06-28 19:16:48 +0800202#ifdef SEC_GCTL
Steven Miao4f6b6002012-05-16 17:56:51 +0800203static void bfin_sec_preflow_handler(struct irq_data *d)
204{
205 unsigned long flags = hard_local_irq_save();
206 unsigned int sid = SIC_SYSIRQ(d->irq);
207
208 bfin_write_SEC_SCI(0, SEC_CSID, sid);
Mike Frysingerfc6bd7b2011-04-15 01:35:53 -0400209
David Howells3b139cd2010-10-07 14:08:52 +0100210 hard_local_irq_restore(flags);
Bryan Wu1394f032007-05-06 14:50:22 -0700211}
212
Steven Miao4f6b6002012-05-16 17:56:51 +0800213static void bfin_sec_mask_ack_irq(struct irq_data *d)
214{
215 unsigned long flags = hard_local_irq_save();
216 unsigned int sid = SIC_SYSIRQ(d->irq);
217
218 bfin_write_SEC_SCI(0, SEC_CSID, sid);
219
220 hard_local_irq_restore(flags);
221}
222
223static void bfin_sec_unmask_irq(struct irq_data *d)
224{
225 unsigned long flags = hard_local_irq_save();
226 unsigned int sid = SIC_SYSIRQ(d->irq);
227
228 bfin_write32(SEC_END, sid);
229
230 hard_local_irq_restore(flags);
231}
232
233static void bfin_sec_enable_ssi(unsigned int sid)
234{
235 unsigned long flags = hard_local_irq_save();
236 uint32_t reg_sctl = bfin_read_SEC_SCTL(sid);
237
238 reg_sctl |= SEC_SCTL_SRC_EN;
239 bfin_write_SEC_SCTL(sid, reg_sctl);
240
241 hard_local_irq_restore(flags);
242}
243
244static void bfin_sec_disable_ssi(unsigned int sid)
245{
246 unsigned long flags = hard_local_irq_save();
247 uint32_t reg_sctl = bfin_read_SEC_SCTL(sid);
248
249 reg_sctl &= ((uint32_t)~SEC_SCTL_SRC_EN);
250 bfin_write_SEC_SCTL(sid, reg_sctl);
251
252 hard_local_irq_restore(flags);
253}
254
255static void bfin_sec_set_ssi_coreid(unsigned int sid, unsigned int coreid)
256{
257 unsigned long flags = hard_local_irq_save();
258 uint32_t reg_sctl = bfin_read_SEC_SCTL(sid);
259
260 reg_sctl &= ((uint32_t)~SEC_SCTL_CTG);
261 bfin_write_SEC_SCTL(sid, reg_sctl | ((coreid << 20) & SEC_SCTL_CTG));
262
263 hard_local_irq_restore(flags);
264}
265
266static void bfin_sec_enable_sci(unsigned int sid)
267{
268 unsigned long flags = hard_local_irq_save();
269 uint32_t reg_sctl = bfin_read_SEC_SCTL(sid);
270
271 if (sid == SIC_SYSIRQ(IRQ_WATCH0))
272 reg_sctl |= SEC_SCTL_FAULT_EN;
273 else
274 reg_sctl |= SEC_SCTL_INT_EN;
275 bfin_write_SEC_SCTL(sid, reg_sctl);
276
277 hard_local_irq_restore(flags);
278}
279
280static void bfin_sec_disable_sci(unsigned int sid)
281{
282 unsigned long flags = hard_local_irq_save();
283 uint32_t reg_sctl = bfin_read_SEC_SCTL(sid);
284
285 reg_sctl &= ((uint32_t)~SEC_SCTL_INT_EN);
286 bfin_write_SEC_SCTL(sid, reg_sctl);
287
288 hard_local_irq_restore(flags);
289}
290
291static void bfin_sec_enable(struct irq_data *d)
292{
293 unsigned long flags = hard_local_irq_save();
294 unsigned int sid = SIC_SYSIRQ(d->irq);
295
296 bfin_sec_enable_sci(sid);
297 bfin_sec_enable_ssi(sid);
298
299 hard_local_irq_restore(flags);
300}
301
302static void bfin_sec_disable(struct irq_data *d)
303{
304 unsigned long flags = hard_local_irq_save();
305 unsigned int sid = SIC_SYSIRQ(d->irq);
306
307 bfin_sec_disable_sci(sid);
308 bfin_sec_disable_ssi(sid);
309
310 hard_local_irq_restore(flags);
311}
312
313static void bfin_sec_raise_irq(unsigned int sid)
314{
315 unsigned long flags = hard_local_irq_save();
316
317 bfin_write32(SEC_RAISE, sid);
318
319 hard_local_irq_restore(flags);
320}
321
322static void init_software_driven_irq(void)
323{
324 bfin_sec_set_ssi_coreid(34, 0);
325 bfin_sec_set_ssi_coreid(35, 1);
326 bfin_sec_set_ssi_coreid(36, 0);
327 bfin_sec_set_ssi_coreid(37, 1);
328}
329
330void bfin_sec_resume(void)
331{
332 bfin_write_SEC_SCI(0, SEC_CCTL, SEC_CCTL_RESET);
333 udelay(100);
334 bfin_write_SEC_GCTL(SEC_GCTL_EN);
335 bfin_write_SEC_SCI(0, SEC_CCTL, SEC_CCTL_EN | SEC_CCTL_NMI_EN);
336}
337
338void handle_sec_sfi_fault(uint32_t gstat)
339{
340
341}
342
343void handle_sec_sci_fault(uint32_t gstat)
344{
345 uint32_t core_id;
346 uint32_t cstat;
347
348 core_id = gstat & SEC_GSTAT_SCI;
349 cstat = bfin_read_SEC_SCI(core_id, SEC_CSTAT);
350 if (cstat & SEC_CSTAT_ERR) {
351 switch (cstat & SEC_CSTAT_ERRC) {
352 case SEC_CSTAT_ACKERR:
353 printk(KERN_DEBUG "sec ack err\n");
354 break;
355 default:
356 printk(KERN_DEBUG "sec sci unknow err\n");
357 }
358 }
359
360}
361
362void handle_sec_ssi_fault(uint32_t gstat)
363{
364 uint32_t sid;
365 uint32_t sstat;
366
367 sid = gstat & SEC_GSTAT_SID;
368 sstat = bfin_read_SEC_SSTAT(sid);
369
370}
371
372void handle_sec_fault(unsigned int irq, struct irq_desc *desc)
373{
374 uint32_t sec_gstat;
375
376 raw_spin_lock(&desc->lock);
377
378 sec_gstat = bfin_read32(SEC_GSTAT);
379 if (sec_gstat & SEC_GSTAT_ERR) {
380
381 switch (sec_gstat & SEC_GSTAT_ERRC) {
382 case 0:
383 handle_sec_sfi_fault(sec_gstat);
384 break;
385 case SEC_GSTAT_SCIERR:
386 handle_sec_sci_fault(sec_gstat);
387 break;
388 case SEC_GSTAT_SSIERR:
389 handle_sec_ssi_fault(sec_gstat);
390 break;
391 }
392
393
394 }
395
396 raw_spin_unlock(&desc->lock);
397}
398
Steven Miao4f6b6002012-05-16 17:56:51 +0800399#endif
400
Sonic Zhang0325f252009-12-28 07:29:57 +0000401#ifdef CONFIG_SMP
Thomas Gleixnerff43a672011-02-06 18:23:29 +0000402static void bfin_internal_unmask_irq_chip(struct irq_data *d)
Sonic Zhang0325f252009-12-28 07:29:57 +0000403{
Thomas Gleixnerff43a672011-02-06 18:23:29 +0000404 bfin_internal_unmask_irq_affinity(d->irq, d->affinity);
Sonic Zhang0325f252009-12-28 07:29:57 +0000405}
406
Thomas Gleixnerff43a672011-02-06 18:23:29 +0000407static int bfin_internal_set_affinity(struct irq_data *d,
408 const struct cpumask *mask, bool force)
Sonic Zhang0325f252009-12-28 07:29:57 +0000409{
Thomas Gleixnerff43a672011-02-06 18:23:29 +0000410 bfin_internal_mask_irq(d->irq);
411 bfin_internal_unmask_irq_affinity(d->irq, mask);
Sonic Zhang0325f252009-12-28 07:29:57 +0000412
413 return 0;
414}
Thomas Gleixnerff43a672011-02-06 18:23:29 +0000415#else
416static void bfin_internal_unmask_irq_chip(struct irq_data *d)
417{
418 bfin_internal_unmask_irq(d->irq);
419}
Sonic Zhang0325f252009-12-28 07:29:57 +0000420#endif
421
Sonic Zhang11b27cb2012-06-28 19:16:48 +0800422#if defined(CONFIG_PM) && !defined(SEC_GCTL)
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800423int bfin_internal_set_wake(unsigned int irq, unsigned int state)
424{
Michael Hennerich8d022372008-11-18 17:48:22 +0800425 u32 bank, bit, wakeup = 0;
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800426 unsigned long flags;
Michael Hennerich464abc52008-02-25 13:50:20 +0800427 bank = SIC_SYSIRQ(irq) / 32;
428 bit = SIC_SYSIRQ(irq) % 32;
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800429
Michael Hennerich4a88d0c2008-08-05 17:38:41 +0800430 switch (irq) {
431#ifdef IRQ_RTC
432 case IRQ_RTC:
433 wakeup |= WAKE;
434 break;
435#endif
436#ifdef IRQ_CAN0_RX
437 case IRQ_CAN0_RX:
438 wakeup |= CANWE;
439 break;
440#endif
441#ifdef IRQ_CAN1_RX
442 case IRQ_CAN1_RX:
443 wakeup |= CANWE;
444 break;
445#endif
446#ifdef IRQ_USB_INT0
447 case IRQ_USB_INT0:
448 wakeup |= USBWE;
449 break;
450#endif
Michael Hennerichd310fb42008-08-28 17:32:01 +0800451#ifdef CONFIG_BF54x
Michael Hennerich4a88d0c2008-08-05 17:38:41 +0800452 case IRQ_CNT:
453 wakeup |= ROTWE;
454 break;
455#endif
456 default:
457 break;
458 }
459
David Howells3b139cd2010-10-07 14:08:52 +0100460 flags = hard_local_irq_save();
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800461
Michael Hennerich4a88d0c2008-08-05 17:38:41 +0800462 if (state) {
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800463 bfin_sic_iwr[bank] |= (1 << bit);
Michael Hennerich4a88d0c2008-08-05 17:38:41 +0800464 vr_wakeup |= wakeup;
465
466 } else {
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800467 bfin_sic_iwr[bank] &= ~(1 << bit);
Michael Hennerich4a88d0c2008-08-05 17:38:41 +0800468 vr_wakeup &= ~wakeup;
469 }
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800470
David Howells3b139cd2010-10-07 14:08:52 +0100471 hard_local_irq_restore(flags);
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800472
473 return 0;
474}
Thomas Gleixnerff43a672011-02-06 18:23:29 +0000475
476static int bfin_internal_set_wake_chip(struct irq_data *d, unsigned int state)
477{
478 return bfin_internal_set_wake(d->irq, state);
479}
Mike Frysingerfc6bd7b2011-04-15 01:35:53 -0400480#else
Bob Liu357351b2012-06-01 14:04:02 +0800481inline int bfin_internal_set_wake(unsigned int irq, unsigned int state)
482{
483 return 0;
484}
Mike Frysingerfc6bd7b2011-04-15 01:35:53 -0400485# define bfin_internal_set_wake_chip NULL
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800486#endif
487
Bryan Wu1394f032007-05-06 14:50:22 -0700488static struct irq_chip bfin_core_irqchip = {
Graf Yang763e63c2008-10-08 17:08:15 +0800489 .name = "CORE",
Thomas Gleixner4f19ea42011-02-06 18:23:27 +0000490 .irq_mask = bfin_core_mask_irq,
491 .irq_unmask = bfin_core_unmask_irq,
Bryan Wu1394f032007-05-06 14:50:22 -0700492};
493
494static struct irq_chip bfin_internal_irqchip = {
Graf Yang763e63c2008-10-08 17:08:15 +0800495 .name = "INTN",
Thomas Gleixnerff43a672011-02-06 18:23:29 +0000496 .irq_mask = bfin_internal_mask_irq_chip,
497 .irq_unmask = bfin_internal_unmask_irq_chip,
Thomas Gleixnerff43a672011-02-06 18:23:29 +0000498 .irq_disable = bfin_internal_mask_irq_chip,
499 .irq_enable = bfin_internal_unmask_irq_chip,
Sonic Zhang0325f252009-12-28 07:29:57 +0000500#ifdef CONFIG_SMP
Thomas Gleixnerff43a672011-02-06 18:23:29 +0000501 .irq_set_affinity = bfin_internal_set_affinity,
Sonic Zhang0325f252009-12-28 07:29:57 +0000502#endif
Thomas Gleixnerff43a672011-02-06 18:23:29 +0000503 .irq_set_wake = bfin_internal_set_wake_chip,
Bryan Wu1394f032007-05-06 14:50:22 -0700504};
505
Sonic Zhang11b27cb2012-06-28 19:16:48 +0800506#ifdef SEC_GCTL
Steven Miao4f6b6002012-05-16 17:56:51 +0800507static struct irq_chip bfin_sec_irqchip = {
508 .name = "SEC",
509 .irq_mask_ack = bfin_sec_mask_ack_irq,
510 .irq_mask = bfin_sec_mask_ack_irq,
511 .irq_unmask = bfin_sec_unmask_irq,
512 .irq_eoi = bfin_sec_unmask_irq,
513 .irq_disable = bfin_sec_disable,
514 .irq_enable = bfin_sec_enable,
515};
516#endif
517
Mike Frysingerf58c3272011-04-15 03:08:20 -0400518void bfin_handle_irq(unsigned irq)
Yi Li6a01f232009-01-07 23:14:39 +0800519{
520#ifdef CONFIG_IPIPE
521 struct pt_regs regs; /* Contents not used. */
522 ipipe_trace_irq_entry(irq);
523 __ipipe_handle_irq(irq, &regs);
524 ipipe_trace_irq_exit(irq);
525#else /* !CONFIG_IPIPE */
Thomas Gleixnerb10bbbb2011-02-06 18:23:25 +0000526 generic_handle_irq(irq);
Yi Li6a01f232009-01-07 23:14:39 +0800527#endif /* !CONFIG_IPIPE */
528}
529
Michael Hennerichaec59c92010-02-19 15:09:10 +0000530#if defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE)
531static int mac_stat_int_mask;
532
533static void bfin_mac_status_ack_irq(unsigned int irq)
534{
535 switch (irq) {
536 case IRQ_MAC_MMCINT:
537 bfin_write_EMAC_MMC_TIRQS(
538 bfin_read_EMAC_MMC_TIRQE() &
539 bfin_read_EMAC_MMC_TIRQS());
540 bfin_write_EMAC_MMC_RIRQS(
541 bfin_read_EMAC_MMC_RIRQE() &
542 bfin_read_EMAC_MMC_RIRQS());
543 break;
544 case IRQ_MAC_RXFSINT:
545 bfin_write_EMAC_RX_STKY(
546 bfin_read_EMAC_RX_IRQE() &
547 bfin_read_EMAC_RX_STKY());
548 break;
549 case IRQ_MAC_TXFSINT:
550 bfin_write_EMAC_TX_STKY(
551 bfin_read_EMAC_TX_IRQE() &
552 bfin_read_EMAC_TX_STKY());
553 break;
554 case IRQ_MAC_WAKEDET:
555 bfin_write_EMAC_WKUP_CTL(
556 bfin_read_EMAC_WKUP_CTL() | MPKS | RWKS);
557 break;
558 default:
559 /* These bits are W1C */
560 bfin_write_EMAC_SYSTAT(1L << (irq - IRQ_MAC_PHYINT));
561 break;
562 }
563}
564
Thomas Gleixner172d2d12011-02-06 18:23:34 +0000565static void bfin_mac_status_mask_irq(struct irq_data *d)
Michael Hennerichaec59c92010-02-19 15:09:10 +0000566{
Thomas Gleixner172d2d12011-02-06 18:23:34 +0000567 unsigned int irq = d->irq;
568
Michael Hennerichaec59c92010-02-19 15:09:10 +0000569 mac_stat_int_mask &= ~(1L << (irq - IRQ_MAC_PHYINT));
Mike Frysingerf58c3272011-04-15 03:08:20 -0400570#ifdef BF537_FAMILY
Michael Hennerichaec59c92010-02-19 15:09:10 +0000571 switch (irq) {
572 case IRQ_MAC_PHYINT:
573 bfin_write_EMAC_SYSCTL(bfin_read_EMAC_SYSCTL() & ~PHYIE);
574 break;
575 default:
576 break;
577 }
578#else
579 if (!mac_stat_int_mask)
580 bfin_internal_mask_irq(IRQ_MAC_ERROR);
581#endif
582 bfin_mac_status_ack_irq(irq);
583}
584
Thomas Gleixner172d2d12011-02-06 18:23:34 +0000585static void bfin_mac_status_unmask_irq(struct irq_data *d)
Michael Hennerichaec59c92010-02-19 15:09:10 +0000586{
Thomas Gleixner172d2d12011-02-06 18:23:34 +0000587 unsigned int irq = d->irq;
588
Mike Frysingerf58c3272011-04-15 03:08:20 -0400589#ifdef BF537_FAMILY
Michael Hennerichaec59c92010-02-19 15:09:10 +0000590 switch (irq) {
591 case IRQ_MAC_PHYINT:
592 bfin_write_EMAC_SYSCTL(bfin_read_EMAC_SYSCTL() | PHYIE);
593 break;
594 default:
595 break;
596 }
597#else
598 if (!mac_stat_int_mask)
599 bfin_internal_unmask_irq(IRQ_MAC_ERROR);
600#endif
601 mac_stat_int_mask |= 1L << (irq - IRQ_MAC_PHYINT);
602}
603
604#ifdef CONFIG_PM
Thomas Gleixner172d2d12011-02-06 18:23:34 +0000605int bfin_mac_status_set_wake(struct irq_data *d, unsigned int state)
Michael Hennerichaec59c92010-02-19 15:09:10 +0000606{
Mike Frysingerf58c3272011-04-15 03:08:20 -0400607#ifdef BF537_FAMILY
Michael Hennerichaec59c92010-02-19 15:09:10 +0000608 return bfin_internal_set_wake(IRQ_GENERIC_ERROR, state);
609#else
610 return bfin_internal_set_wake(IRQ_MAC_ERROR, state);
611#endif
612}
Mike Frysingerfc6bd7b2011-04-15 01:35:53 -0400613#else
614# define bfin_mac_status_set_wake NULL
Michael Hennerichaec59c92010-02-19 15:09:10 +0000615#endif
616
617static struct irq_chip bfin_mac_status_irqchip = {
618 .name = "MACST",
Thomas Gleixner172d2d12011-02-06 18:23:34 +0000619 .irq_mask = bfin_mac_status_mask_irq,
620 .irq_unmask = bfin_mac_status_unmask_irq,
Thomas Gleixner172d2d12011-02-06 18:23:34 +0000621 .irq_set_wake = bfin_mac_status_set_wake,
Michael Hennerichaec59c92010-02-19 15:09:10 +0000622};
623
Mike Frysingerf58c3272011-04-15 03:08:20 -0400624void bfin_demux_mac_status_irq(unsigned int int_err_irq,
625 struct irq_desc *inta_desc)
Michael Hennerichaec59c92010-02-19 15:09:10 +0000626{
627 int i, irq = 0;
628 u32 status = bfin_read_EMAC_SYSTAT();
629
Michael Hennerichbedeea62010-08-20 11:59:27 +0000630 for (i = 0; i <= (IRQ_MAC_STMDONE - IRQ_MAC_PHYINT); i++)
Michael Hennerichaec59c92010-02-19 15:09:10 +0000631 if (status & (1L << i)) {
632 irq = IRQ_MAC_PHYINT + i;
633 break;
634 }
635
636 if (irq) {
637 if (mac_stat_int_mask & (1L << (irq - IRQ_MAC_PHYINT))) {
638 bfin_handle_irq(irq);
639 } else {
640 bfin_mac_status_ack_irq(irq);
641 pr_debug("IRQ %d:"
Steven Miao4f6b6002012-05-16 17:56:51 +0800642 " MASKED MAC ERROR INTERRUPT ASSERTED\n",
643 irq);
Michael Hennerichaec59c92010-02-19 15:09:10 +0000644 }
645 } else
646 printk(KERN_ERR
Steven Miao4f6b6002012-05-16 17:56:51 +0800647 "%s : %s : LINE %d :\nIRQ ?: MAC ERROR"
648 " INTERRUPT ASSERTED BUT NO SOURCE FOUND"
649 "(EMAC_SYSTAT=0x%X)\n",
650 __func__, __FILE__, __LINE__, status);
Michael Hennerichaec59c92010-02-19 15:09:10 +0000651}
652#endif
653
Graf Yangbfd15112008-10-08 18:02:44 +0800654static inline void bfin_set_irq_handler(unsigned irq, irq_flow_handler_t handle)
655{
Yi Li6a01f232009-01-07 23:14:39 +0800656#ifdef CONFIG_IPIPE
Philippe Gerum5b5da4c2011-03-17 02:12:48 -0400657 handle = handle_level_irq;
Yi Li6a01f232009-01-07 23:14:39 +0800658#endif
Thomas Gleixner43f2f112011-03-24 17:22:30 +0100659 __irq_set_handler_locked(irq, handle);
Graf Yangbfd15112008-10-08 18:02:44 +0800660}
661
Michael Hennerich8d022372008-11-18 17:48:22 +0800662static DECLARE_BITMAP(gpio_enabled, MAX_BLACKFIN_GPIOS);
Michael Hennerichaffee2b2008-04-24 08:10:10 +0800663extern void bfin_gpio_irq_prepare(unsigned gpio);
Michael Hennerich6fce6a82007-12-24 16:56:12 +0800664
Mike Frysinger01f8e342011-06-26 13:56:23 -0400665#if !BFIN_GPIO_PINT
Michael Hennerich8d022372008-11-18 17:48:22 +0800666
Thomas Gleixnere9502852011-02-06 18:23:36 +0000667static void bfin_gpio_ack_irq(struct irq_data *d)
Bryan Wu1394f032007-05-06 14:50:22 -0700668{
Michael Hennerich8d022372008-11-18 17:48:22 +0800669 /* AFAIK ack_irq in case mask_ack is provided
670 * get's only called for edge sense irqs
671 */
Thomas Gleixnere9502852011-02-06 18:23:36 +0000672 set_gpio_data(irq_to_gpio(d->irq), 0);
Bryan Wu1394f032007-05-06 14:50:22 -0700673}
674
Thomas Gleixnere9502852011-02-06 18:23:36 +0000675static void bfin_gpio_mask_ack_irq(struct irq_data *d)
Bryan Wu1394f032007-05-06 14:50:22 -0700676{
Thomas Gleixnere9502852011-02-06 18:23:36 +0000677 unsigned int irq = d->irq;
Michael Hennerich8d022372008-11-18 17:48:22 +0800678 u32 gpionr = irq_to_gpio(irq);
Bryan Wu1394f032007-05-06 14:50:22 -0700679
Thomas Gleixner1907d8b2011-03-24 17:21:01 +0100680 if (!irqd_is_level_type(d))
Bryan Wu1394f032007-05-06 14:50:22 -0700681 set_gpio_data(gpionr, 0);
Bryan Wu1394f032007-05-06 14:50:22 -0700682
683 set_gpio_maska(gpionr, 0);
Bryan Wu1394f032007-05-06 14:50:22 -0700684}
685
Thomas Gleixnere9502852011-02-06 18:23:36 +0000686static void bfin_gpio_mask_irq(struct irq_data *d)
Bryan Wu1394f032007-05-06 14:50:22 -0700687{
Thomas Gleixnere9502852011-02-06 18:23:36 +0000688 set_gpio_maska(irq_to_gpio(d->irq), 0);
Bryan Wu1394f032007-05-06 14:50:22 -0700689}
690
Thomas Gleixnere9502852011-02-06 18:23:36 +0000691static void bfin_gpio_unmask_irq(struct irq_data *d)
Bryan Wu1394f032007-05-06 14:50:22 -0700692{
Thomas Gleixnere9502852011-02-06 18:23:36 +0000693 set_gpio_maska(irq_to_gpio(d->irq), 1);
Bryan Wu1394f032007-05-06 14:50:22 -0700694}
695
Thomas Gleixnere9502852011-02-06 18:23:36 +0000696static unsigned int bfin_gpio_irq_startup(struct irq_data *d)
Bryan Wu1394f032007-05-06 14:50:22 -0700697{
Thomas Gleixnere9502852011-02-06 18:23:36 +0000698 u32 gpionr = irq_to_gpio(d->irq);
Bryan Wu1394f032007-05-06 14:50:22 -0700699
Michael Hennerich8d022372008-11-18 17:48:22 +0800700 if (__test_and_set_bit(gpionr, gpio_enabled))
Michael Hennerichaffee2b2008-04-24 08:10:10 +0800701 bfin_gpio_irq_prepare(gpionr);
Bryan Wu1394f032007-05-06 14:50:22 -0700702
Thomas Gleixnere9502852011-02-06 18:23:36 +0000703 bfin_gpio_unmask_irq(d);
Bryan Wu1394f032007-05-06 14:50:22 -0700704
Michael Hennerichaffee2b2008-04-24 08:10:10 +0800705 return 0;
Bryan Wu1394f032007-05-06 14:50:22 -0700706}
707
Thomas Gleixnere9502852011-02-06 18:23:36 +0000708static void bfin_gpio_irq_shutdown(struct irq_data *d)
Bryan Wu1394f032007-05-06 14:50:22 -0700709{
Thomas Gleixnere9502852011-02-06 18:23:36 +0000710 u32 gpionr = irq_to_gpio(d->irq);
Graf Yang30af6d42008-11-18 17:48:21 +0800711
Thomas Gleixnere9502852011-02-06 18:23:36 +0000712 bfin_gpio_mask_irq(d);
Graf Yang30af6d42008-11-18 17:48:21 +0800713 __clear_bit(gpionr, gpio_enabled);
Graf Yang9570ff42009-01-07 23:14:38 +0800714 bfin_gpio_irq_free(gpionr);
Bryan Wu1394f032007-05-06 14:50:22 -0700715}
716
Thomas Gleixnere9502852011-02-06 18:23:36 +0000717static int bfin_gpio_irq_type(struct irq_data *d, unsigned int type)
Bryan Wu1394f032007-05-06 14:50:22 -0700718{
Thomas Gleixnere9502852011-02-06 18:23:36 +0000719 unsigned int irq = d->irq;
Graf Yang8eb3e3b2008-11-18 17:48:22 +0800720 int ret;
721 char buf[16];
Michael Hennerich8d022372008-11-18 17:48:22 +0800722 u32 gpionr = irq_to_gpio(irq);
Bryan Wu1394f032007-05-06 14:50:22 -0700723
724 if (type == IRQ_TYPE_PROBE) {
725 /* only probe unenabled GPIO interrupt lines */
Mike Frysingerc3695342009-06-13 10:32:29 -0400726 if (test_bit(gpionr, gpio_enabled))
Bryan Wu1394f032007-05-06 14:50:22 -0700727 return 0;
728 type = IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING;
729 }
730
731 if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING |
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800732 IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW)) {
Michael Hennerich8d022372008-11-18 17:48:22 +0800733
Graf Yang9570ff42009-01-07 23:14:38 +0800734 snprintf(buf, 16, "gpio-irq%d", irq);
735 ret = bfin_gpio_irq_request(gpionr, buf);
736 if (ret)
737 return ret;
738
Michael Hennerich8d022372008-11-18 17:48:22 +0800739 if (__test_and_set_bit(gpionr, gpio_enabled))
Michael Hennerichaffee2b2008-04-24 08:10:10 +0800740 bfin_gpio_irq_prepare(gpionr);
Bryan Wu1394f032007-05-06 14:50:22 -0700741
Bryan Wu1394f032007-05-06 14:50:22 -0700742 } else {
Michael Hennerich8d022372008-11-18 17:48:22 +0800743 __clear_bit(gpionr, gpio_enabled);
Bryan Wu1394f032007-05-06 14:50:22 -0700744 return 0;
745 }
746
Michael Hennerichf1bceb42008-02-02 16:17:52 +0800747 set_gpio_inen(gpionr, 0);
Bryan Wu1394f032007-05-06 14:50:22 -0700748 set_gpio_dir(gpionr, 0);
Bryan Wu1394f032007-05-06 14:50:22 -0700749
750 if ((type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING))
751 == (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING))
752 set_gpio_both(gpionr, 1);
753 else
754 set_gpio_both(gpionr, 0);
755
756 if ((type & (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_LEVEL_LOW)))
757 set_gpio_polar(gpionr, 1); /* low or falling edge denoted by one */
758 else
759 set_gpio_polar(gpionr, 0); /* high or rising edge denoted by zero */
760
Michael Hennerichf1bceb42008-02-02 16:17:52 +0800761 if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING)) {
762 set_gpio_edge(gpionr, 1);
763 set_gpio_inen(gpionr, 1);
Michael Hennerichf1bceb42008-02-02 16:17:52 +0800764 set_gpio_data(gpionr, 0);
765
766 } else {
767 set_gpio_edge(gpionr, 0);
Michael Hennerichf1bceb42008-02-02 16:17:52 +0800768 set_gpio_inen(gpionr, 1);
769 }
770
Bryan Wu1394f032007-05-06 14:50:22 -0700771 if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING))
Graf Yangbfd15112008-10-08 18:02:44 +0800772 bfin_set_irq_handler(irq, handle_edge_irq);
Bryan Wu1394f032007-05-06 14:50:22 -0700773 else
Graf Yangbfd15112008-10-08 18:02:44 +0800774 bfin_set_irq_handler(irq, handle_level_irq);
Bryan Wu1394f032007-05-06 14:50:22 -0700775
776 return 0;
777}
778
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800779#ifdef CONFIG_PM
Mike Frysingerdd8cb372011-04-15 03:19:22 -0400780static int bfin_gpio_set_wake(struct irq_data *d, unsigned int state)
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800781{
Thomas Gleixnere9502852011-02-06 18:23:36 +0000782 return gpio_pm_wakeup_ctrl(irq_to_gpio(d->irq), state);
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800783}
Mike Frysingerfc6bd7b2011-04-15 01:35:53 -0400784#else
785# define bfin_gpio_set_wake NULL
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800786#endif
787
Mike Frysingere2a80922011-04-15 12:51:33 -0400788static void bfin_demux_gpio_block(unsigned int irq)
789{
790 unsigned int gpio, mask;
791
792 gpio = irq_to_gpio(irq);
793 mask = get_gpiop_data(gpio) & get_gpiop_maska(gpio);
794
795 while (mask) {
796 if (mask & 1)
797 bfin_handle_irq(irq);
798 irq++;
799 mask >>= 1;
800 }
801}
802
Mike Frysinger8c054102011-04-15 13:04:59 -0400803void bfin_demux_gpio_irq(unsigned int inta_irq,
Steven Miao4f6b6002012-05-16 17:56:51 +0800804 struct irq_desc *desc)
Bryan Wu1394f032007-05-06 14:50:22 -0700805{
Mike Frysingere2a80922011-04-15 12:51:33 -0400806 unsigned int irq;
Bryan Wu1394f032007-05-06 14:50:22 -0700807
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800808 switch (inta_irq) {
Mike Frysingere2a80922011-04-15 12:51:33 -0400809#if defined(BF537_FAMILY)
Mike Frysinger8c054102011-04-15 13:04:59 -0400810 case IRQ_PF_INTA_PG_INTA:
Mike Frysingere2a80922011-04-15 12:51:33 -0400811 bfin_demux_gpio_block(IRQ_PF0);
812 irq = IRQ_PG0;
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800813 break;
Mike Frysinger8c054102011-04-15 13:04:59 -0400814 case IRQ_PH_INTA_MAC_RX:
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800815 irq = IRQ_PH0;
816 break;
Mike Frysingere2a80922011-04-15 12:51:33 -0400817#elif defined(BF533_FAMILY)
818 case IRQ_PROG_INTA:
819 irq = IRQ_PF0;
820 break;
Mike Frysingerfc6bd7b2011-04-15 01:35:53 -0400821#elif defined(BF538_FAMILY)
Michael Hennerichdc26aec2008-11-18 17:48:22 +0800822 case IRQ_PORTF_INTA:
823 irq = IRQ_PF0;
824 break;
Bryan Wu2f6f4bc2008-11-18 17:48:21 +0800825#elif defined(CONFIG_BF52x) || defined(CONFIG_BF51x)
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800826 case IRQ_PORTF_INTA:
827 irq = IRQ_PF0;
828 break;
829 case IRQ_PORTG_INTA:
830 irq = IRQ_PG0;
831 break;
832 case IRQ_PORTH_INTA:
833 irq = IRQ_PH0;
834 break;
835#elif defined(CONFIG_BF561)
836 case IRQ_PROG0_INTA:
837 irq = IRQ_PF0;
838 break;
839 case IRQ_PROG1_INTA:
840 irq = IRQ_PF16;
841 break;
842 case IRQ_PROG2_INTA:
843 irq = IRQ_PF32;
844 break;
845#endif
846 default:
847 BUG();
848 return;
Bryan Wu1394f032007-05-06 14:50:22 -0700849 }
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800850
Mike Frysingere2a80922011-04-15 12:51:33 -0400851 bfin_demux_gpio_block(irq);
Bryan Wu1394f032007-05-06 14:50:22 -0700852}
853
Mike Frysinger01f8e342011-06-26 13:56:23 -0400854#else
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800855
Steven Miao4f6b6002012-05-16 17:56:51 +0800856#define NR_PINT_BITS 32
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800857#define IRQ_NOT_AVAIL 0xFF
858
859#define PINT_2_BANK(x) ((x) >> 5)
860#define PINT_2_BIT(x) ((x) & 0x1F)
861#define PINT_BIT(x) (1 << (PINT_2_BIT(x)))
862
863static unsigned char irq2pint_lut[NR_PINTS];
Michael Henneriche3f23002007-07-12 16:39:29 +0800864static unsigned char pint2irq_lut[NR_PINT_SYS_IRQS * NR_PINT_BITS];
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800865
Mike Frysinger82ed5f72011-06-26 13:22:05 -0400866static struct bfin_pint_regs * const pint[NR_PINT_SYS_IRQS] = {
867 (struct bfin_pint_regs *)PINT0_MASK_SET,
868 (struct bfin_pint_regs *)PINT1_MASK_SET,
869 (struct bfin_pint_regs *)PINT2_MASK_SET,
870 (struct bfin_pint_regs *)PINT3_MASK_SET,
Steven Miao4f6b6002012-05-16 17:56:51 +0800871#ifdef CONFIG_BF60x
872 (struct bfin_pint_regs *)PINT4_MASK_SET,
873 (struct bfin_pint_regs *)PINT5_MASK_SET,
874#endif
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800875};
876
Michael Hennerich8d022372008-11-18 17:48:22 +0800877inline unsigned int get_irq_base(u32 bank, u8 bmap)
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800878{
Michael Hennerich8d022372008-11-18 17:48:22 +0800879 unsigned int irq_base;
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800880
Sonic Zhang11b27cb2012-06-28 19:16:48 +0800881#ifndef CONFIG_BF60x
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800882 if (bank < 2) { /*PA-PB */
883 irq_base = IRQ_PA0 + bmap * 16;
884 } else { /*PC-PJ */
885 irq_base = IRQ_PC0 + bmap * 16;
886 }
Steven Miao4f6b6002012-05-16 17:56:51 +0800887#else
Steven Miao4f6b6002012-05-16 17:56:51 +0800888 irq_base = IRQ_PA0 + bank * 16 + bmap * 16;
Sonic Zhang11b27cb2012-06-28 19:16:48 +0800889#endif
Steven Miao4f6b6002012-05-16 17:56:51 +0800890 return irq_base;
891}
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800892
893 /* Whenever PINTx_ASSIGN is altered init_pint_lut() must be executed! */
894void init_pint_lut(void)
895{
896 u16 bank, bit, irq_base, bit_pos;
897 u32 pint_assign;
898 u8 bmap;
899
900 memset(irq2pint_lut, IRQ_NOT_AVAIL, sizeof(irq2pint_lut));
901
902 for (bank = 0; bank < NR_PINT_SYS_IRQS; bank++) {
903
904 pint_assign = pint[bank]->assign;
905
906 for (bit = 0; bit < NR_PINT_BITS; bit++) {
907
908 bmap = (pint_assign >> ((bit / 8) * 8)) & 0xFF;
909
910 irq_base = get_irq_base(bank, bmap);
911
912 irq_base += (bit % 8) + ((bit / 8) & 1 ? 8 : 0);
913 bit_pos = bit + bank * NR_PINT_BITS;
914
Michael Henneriche3f23002007-07-12 16:39:29 +0800915 pint2irq_lut[bit_pos] = irq_base - SYS_IRQS;
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800916 irq2pint_lut[irq_base - SYS_IRQS] = bit_pos;
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800917 }
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800918 }
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800919}
920
Thomas Gleixnere9502852011-02-06 18:23:36 +0000921static void bfin_gpio_ack_irq(struct irq_data *d)
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800922{
Thomas Gleixnere9502852011-02-06 18:23:36 +0000923 u32 pint_val = irq2pint_lut[d->irq - SYS_IRQS];
Michael Hennerich8baf5602007-12-24 18:51:34 +0800924 u32 pintbit = PINT_BIT(pint_val);
Michael Hennerich8d022372008-11-18 17:48:22 +0800925 u32 bank = PINT_2_BANK(pint_val);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800926
Thomas Gleixner1907d8b2011-03-24 17:21:01 +0100927 if (irqd_get_trigger_type(d) == IRQ_TYPE_EDGE_BOTH) {
Michael Hennerich8baf5602007-12-24 18:51:34 +0800928 if (pint[bank]->invert_set & pintbit)
929 pint[bank]->invert_clear = pintbit;
930 else
931 pint[bank]->invert_set = pintbit;
932 }
933 pint[bank]->request = pintbit;
934
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800935}
936
Thomas Gleixnere9502852011-02-06 18:23:36 +0000937static void bfin_gpio_mask_ack_irq(struct irq_data *d)
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800938{
Thomas Gleixnere9502852011-02-06 18:23:36 +0000939 u32 pint_val = irq2pint_lut[d->irq - SYS_IRQS];
Michael Henneriche3f23002007-07-12 16:39:29 +0800940 u32 pintbit = PINT_BIT(pint_val);
Michael Hennerich8d022372008-11-18 17:48:22 +0800941 u32 bank = PINT_2_BANK(pint_val);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800942
Thomas Gleixner1907d8b2011-03-24 17:21:01 +0100943 if (irqd_get_trigger_type(d) == IRQ_TYPE_EDGE_BOTH) {
Michael Hennerich8baf5602007-12-24 18:51:34 +0800944 if (pint[bank]->invert_set & pintbit)
945 pint[bank]->invert_clear = pintbit;
946 else
947 pint[bank]->invert_set = pintbit;
948 }
949
Michael Henneriche3f23002007-07-12 16:39:29 +0800950 pint[bank]->request = pintbit;
951 pint[bank]->mask_clear = pintbit;
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800952}
953
Thomas Gleixnere9502852011-02-06 18:23:36 +0000954static void bfin_gpio_mask_irq(struct irq_data *d)
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800955{
Thomas Gleixnere9502852011-02-06 18:23:36 +0000956 u32 pint_val = irq2pint_lut[d->irq - SYS_IRQS];
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800957
958 pint[PINT_2_BANK(pint_val)]->mask_clear = PINT_BIT(pint_val);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800959}
960
Thomas Gleixnere9502852011-02-06 18:23:36 +0000961static void bfin_gpio_unmask_irq(struct irq_data *d)
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800962{
Thomas Gleixnere9502852011-02-06 18:23:36 +0000963 u32 pint_val = irq2pint_lut[d->irq - SYS_IRQS];
Michael Henneriche3f23002007-07-12 16:39:29 +0800964 u32 pintbit = PINT_BIT(pint_val);
Michael Hennerich8d022372008-11-18 17:48:22 +0800965 u32 bank = PINT_2_BANK(pint_val);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800966
Michael Henneriche3f23002007-07-12 16:39:29 +0800967 pint[bank]->mask_set = pintbit;
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800968}
969
Thomas Gleixnere9502852011-02-06 18:23:36 +0000970static unsigned int bfin_gpio_irq_startup(struct irq_data *d)
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800971{
Thomas Gleixnere9502852011-02-06 18:23:36 +0000972 unsigned int irq = d->irq;
Michael Hennerich8d022372008-11-18 17:48:22 +0800973 u32 gpionr = irq_to_gpio(irq);
974 u32 pint_val = irq2pint_lut[irq - SYS_IRQS];
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800975
Michael Hennerich50e163c2007-07-24 16:17:28 +0800976 if (pint_val == IRQ_NOT_AVAIL) {
977 printk(KERN_ERR
978 "GPIO IRQ %d :Not in PINT Assign table "
979 "Reconfigure Interrupt to Port Assignemt\n", irq);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800980 return -ENODEV;
Michael Hennerich50e163c2007-07-24 16:17:28 +0800981 }
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800982
Michael Hennerich8d022372008-11-18 17:48:22 +0800983 if (__test_and_set_bit(gpionr, gpio_enabled))
Michael Hennerichaffee2b2008-04-24 08:10:10 +0800984 bfin_gpio_irq_prepare(gpionr);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800985
Thomas Gleixnere9502852011-02-06 18:23:36 +0000986 bfin_gpio_unmask_irq(d);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800987
Michael Hennerichaffee2b2008-04-24 08:10:10 +0800988 return 0;
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800989}
990
Thomas Gleixnere9502852011-02-06 18:23:36 +0000991static void bfin_gpio_irq_shutdown(struct irq_data *d)
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800992{
Thomas Gleixnere9502852011-02-06 18:23:36 +0000993 u32 gpionr = irq_to_gpio(d->irq);
Michael Hennerich8baf5602007-12-24 18:51:34 +0800994
Thomas Gleixnere9502852011-02-06 18:23:36 +0000995 bfin_gpio_mask_irq(d);
Michael Hennerich8d022372008-11-18 17:48:22 +0800996 __clear_bit(gpionr, gpio_enabled);
Graf Yang9570ff42009-01-07 23:14:38 +0800997 bfin_gpio_irq_free(gpionr);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800998}
999
Thomas Gleixnere9502852011-02-06 18:23:36 +00001000static int bfin_gpio_irq_type(struct irq_data *d, unsigned int type)
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001001{
Thomas Gleixnere9502852011-02-06 18:23:36 +00001002 unsigned int irq = d->irq;
Graf Yang8eb3e3b2008-11-18 17:48:22 +08001003 int ret;
1004 char buf[16];
Michael Hennerich8d022372008-11-18 17:48:22 +08001005 u32 gpionr = irq_to_gpio(irq);
1006 u32 pint_val = irq2pint_lut[irq - SYS_IRQS];
Michael Henneriche3f23002007-07-12 16:39:29 +08001007 u32 pintbit = PINT_BIT(pint_val);
Michael Hennerich8d022372008-11-18 17:48:22 +08001008 u32 bank = PINT_2_BANK(pint_val);
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001009
1010 if (pint_val == IRQ_NOT_AVAIL)
1011 return -ENODEV;
1012
1013 if (type == IRQ_TYPE_PROBE) {
1014 /* only probe unenabled GPIO interrupt lines */
Mike Frysingerc3695342009-06-13 10:32:29 -04001015 if (test_bit(gpionr, gpio_enabled))
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001016 return 0;
1017 type = IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING;
1018 }
1019
1020 if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING |
1021 IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW)) {
Graf Yang9570ff42009-01-07 23:14:38 +08001022
1023 snprintf(buf, 16, "gpio-irq%d", irq);
1024 ret = bfin_gpio_irq_request(gpionr, buf);
1025 if (ret)
1026 return ret;
1027
Michael Hennerich8d022372008-11-18 17:48:22 +08001028 if (__test_and_set_bit(gpionr, gpio_enabled))
Michael Hennerichaffee2b2008-04-24 08:10:10 +08001029 bfin_gpio_irq_prepare(gpionr);
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001030
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001031 } else {
Michael Hennerich8d022372008-11-18 17:48:22 +08001032 __clear_bit(gpionr, gpio_enabled);
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001033 return 0;
1034 }
1035
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001036 if ((type & (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_LEVEL_LOW)))
Michael Henneriche3f23002007-07-12 16:39:29 +08001037 pint[bank]->invert_set = pintbit; /* low or falling edge denoted by one */
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001038 else
Michael Hennerich8baf5602007-12-24 18:51:34 +08001039 pint[bank]->invert_clear = pintbit; /* high or rising edge denoted by zero */
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001040
Michael Hennerich8baf5602007-12-24 18:51:34 +08001041 if ((type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING))
1042 == (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING)) {
Michael Hennerich8baf5602007-12-24 18:51:34 +08001043 if (gpio_get_value(gpionr))
1044 pint[bank]->invert_set = pintbit;
1045 else
1046 pint[bank]->invert_clear = pintbit;
Michael Hennerich8baf5602007-12-24 18:51:34 +08001047 }
1048
1049 if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING)) {
1050 pint[bank]->edge_set = pintbit;
Graf Yangbfd15112008-10-08 18:02:44 +08001051 bfin_set_irq_handler(irq, handle_edge_irq);
Michael Hennerich8baf5602007-12-24 18:51:34 +08001052 } else {
1053 pint[bank]->edge_clear = pintbit;
Graf Yangbfd15112008-10-08 18:02:44 +08001054 bfin_set_irq_handler(irq, handle_level_irq);
Michael Hennerich8baf5602007-12-24 18:51:34 +08001055 }
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001056
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001057 return 0;
1058}
1059
Michael Hennerichcfefe3c2008-02-09 04:12:37 +08001060#ifdef CONFIG_PM
Steven Miaod49cdf8402012-06-14 18:04:01 +08001061static struct bfin_pm_pint_save save_pint_reg[NR_PINT_SYS_IRQS];
1062static u32 save_pint_sec_ctl[NR_PINT_SYS_IRQS];
1063
Mike Frysingerdd8cb372011-04-15 03:19:22 -04001064static int bfin_gpio_set_wake(struct irq_data *d, unsigned int state)
Michael Hennerichcfefe3c2008-02-09 04:12:37 +08001065{
1066 u32 pint_irq;
Thomas Gleixnere9502852011-02-06 18:23:36 +00001067 u32 pint_val = irq2pint_lut[d->irq - SYS_IRQS];
Michael Hennerichcfefe3c2008-02-09 04:12:37 +08001068 u32 bank = PINT_2_BANK(pint_val);
Michael Hennerichcfefe3c2008-02-09 04:12:37 +08001069
1070 switch (bank) {
1071 case 0:
1072 pint_irq = IRQ_PINT0;
1073 break;
1074 case 2:
1075 pint_irq = IRQ_PINT2;
1076 break;
1077 case 3:
1078 pint_irq = IRQ_PINT3;
1079 break;
1080 case 1:
1081 pint_irq = IRQ_PINT1;
1082 break;
Bob Liu494b7942012-04-27 14:13:01 +08001083#ifdef CONFIG_BF60x
Steven Miao4f6b6002012-05-16 17:56:51 +08001084 case 4:
1085 pint_irq = IRQ_PINT4;
1086 break;
1087 case 5:
1088 pint_irq = IRQ_PINT5;
1089 break;
Bob Liu494b7942012-04-27 14:13:01 +08001090#endif
Michael Hennerichcfefe3c2008-02-09 04:12:37 +08001091 default:
1092 return -EINVAL;
1093 }
1094
1095 bfin_internal_set_wake(pint_irq, state);
1096
Michael Hennerichcfefe3c2008-02-09 04:12:37 +08001097 return 0;
1098}
Steven Miaod49cdf8402012-06-14 18:04:01 +08001099
1100void bfin_pint_suspend(void)
1101{
1102 u32 bank;
1103
1104 for (bank = 0; bank < NR_PINT_SYS_IRQS; bank++) {
1105 save_pint_reg[bank].mask_set = pint[bank]->mask_set;
1106 save_pint_reg[bank].assign = pint[bank]->assign;
1107 save_pint_reg[bank].edge_set = pint[bank]->edge_set;
1108 save_pint_reg[bank].invert_set = pint[bank]->invert_set;
1109 }
1110}
1111
1112void bfin_pint_resume(void)
1113{
1114 u32 bank;
1115
1116 for (bank = 0; bank < NR_PINT_SYS_IRQS; bank++) {
1117 pint[bank]->mask_set = save_pint_reg[bank].mask_set;
1118 pint[bank]->assign = save_pint_reg[bank].assign;
1119 pint[bank]->edge_set = save_pint_reg[bank].edge_set;
1120 pint[bank]->invert_set = save_pint_reg[bank].invert_set;
1121 }
1122}
1123
Sonic Zhang11b27cb2012-06-28 19:16:48 +08001124#ifdef SEC_GCTL
Steven Miaod49cdf8402012-06-14 18:04:01 +08001125static int sec_suspend(void)
1126{
1127 u32 bank;
1128
1129 for (bank = 0; bank < NR_PINT_SYS_IRQS; bank++)
1130 save_pint_sec_ctl[bank] = bfin_read_SEC_SCTL(bank + SIC_SYSIRQ(IRQ_PINT0));
1131 return 0;
1132}
1133
1134static void sec_resume(void)
1135{
1136 u32 bank;
1137
1138 bfin_write_SEC_SCI(0, SEC_CCTL, SEC_CCTL_RESET);
1139 udelay(100);
1140 bfin_write_SEC_GCTL(SEC_GCTL_EN);
1141 bfin_write_SEC_SCI(0, SEC_CCTL, SEC_CCTL_EN | SEC_CCTL_NMI_EN);
1142
1143 for (bank = 0; bank < NR_PINT_SYS_IRQS; bank++)
1144 bfin_write_SEC_SCTL(bank + SIC_SYSIRQ(IRQ_PINT0), save_pint_sec_ctl[bank]);
1145}
1146
1147static struct syscore_ops sec_pm_syscore_ops = {
1148 .suspend = sec_suspend,
1149 .resume = sec_resume,
1150};
Steven Miao3375a432012-06-15 12:59:19 +08001151#endif
Mike Frysingerfc6bd7b2011-04-15 01:35:53 -04001152#else
1153# define bfin_gpio_set_wake NULL
Michael Hennerichcfefe3c2008-02-09 04:12:37 +08001154#endif
1155
Mike Frysinger8c054102011-04-15 13:04:59 -04001156void bfin_demux_gpio_irq(unsigned int inta_irq,
Steven Miao4f6b6002012-05-16 17:56:51 +08001157 struct irq_desc *desc)
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001158{
Michael Hennerich8d022372008-11-18 17:48:22 +08001159 u32 bank, pint_val;
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001160 u32 request, irq;
Steven Miao4f6b6002012-05-16 17:56:51 +08001161 u32 level_mask;
1162 int umask = 0;
1163 struct irq_chip *chip = irq_desc_get_chip(desc);
1164
1165 if (chip->irq_mask_ack) {
1166 chip->irq_mask_ack(&desc->irq_data);
1167 } else {
1168 chip->irq_mask(&desc->irq_data);
1169 if (chip->irq_ack)
1170 chip->irq_ack(&desc->irq_data);
1171 }
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001172
Michael Hennerich2c4f8292008-02-09 04:11:14 +08001173 switch (inta_irq) {
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001174 case IRQ_PINT0:
1175 bank = 0;
1176 break;
1177 case IRQ_PINT2:
1178 bank = 2;
1179 break;
1180 case IRQ_PINT3:
1181 bank = 3;
1182 break;
1183 case IRQ_PINT1:
1184 bank = 1;
1185 break;
Steven Miao4f6b6002012-05-16 17:56:51 +08001186#ifdef CONFIG_BF60x
1187 case IRQ_PINT4:
1188 bank = 4;
1189 break;
1190 case IRQ_PINT5:
1191 bank = 5;
1192 break;
1193#endif
Michael Henneriche3f23002007-07-12 16:39:29 +08001194 default:
1195 return;
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001196 }
1197
1198 pint_val = bank * NR_PINT_BITS;
1199
1200 request = pint[bank]->request;
1201
Steven Miao4f6b6002012-05-16 17:56:51 +08001202 level_mask = pint[bank]->edge_set & request;
1203
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001204 while (request) {
1205 if (request & 1) {
Michael Henneriche3f23002007-07-12 16:39:29 +08001206 irq = pint2irq_lut[pint_val] + SYS_IRQS;
Steven Miao4f6b6002012-05-16 17:56:51 +08001207 if (level_mask & PINT_BIT(pint_val)) {
1208 umask = 1;
1209 chip->irq_unmask(&desc->irq_data);
1210 }
Yi Li6a01f232009-01-07 23:14:39 +08001211 bfin_handle_irq(irq);
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001212 }
1213 pint_val++;
1214 request >>= 1;
1215 }
1216
Steven Miao4f6b6002012-05-16 17:56:51 +08001217 if (!umask)
1218 chip->irq_unmask(&desc->irq_data);
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001219}
Mike Frysingera055b2b2007-11-15 21:12:32 +08001220#endif
Bryan Wu1394f032007-05-06 14:50:22 -07001221
Michael Hennerich8d022372008-11-18 17:48:22 +08001222static struct irq_chip bfin_gpio_irqchip = {
1223 .name = "GPIO",
Thomas Gleixnere9502852011-02-06 18:23:36 +00001224 .irq_ack = bfin_gpio_ack_irq,
1225 .irq_mask = bfin_gpio_mask_irq,
1226 .irq_mask_ack = bfin_gpio_mask_ack_irq,
1227 .irq_unmask = bfin_gpio_unmask_irq,
1228 .irq_disable = bfin_gpio_mask_irq,
1229 .irq_enable = bfin_gpio_unmask_irq,
1230 .irq_set_type = bfin_gpio_irq_type,
1231 .irq_startup = bfin_gpio_irq_startup,
1232 .irq_shutdown = bfin_gpio_irq_shutdown,
Thomas Gleixnere9502852011-02-06 18:23:36 +00001233 .irq_set_wake = bfin_gpio_set_wake,
Michael Hennerich8d022372008-11-18 17:48:22 +08001234};
1235
Graf Yang6b3087c2009-01-07 23:14:39 +08001236void __cpuinit init_exception_vectors(void)
Bernd Schmidt8be80ed2007-07-25 14:44:49 +08001237{
Mike Frysingerf0b5d122007-08-05 17:03:59 +08001238 /* cannot program in software:
1239 * evt0 - emulation (jtag)
1240 * evt1 - reset
1241 */
1242 bfin_write_EVT2(evt_nmi);
Bernd Schmidt8be80ed2007-07-25 14:44:49 +08001243 bfin_write_EVT3(trap);
1244 bfin_write_EVT5(evt_ivhw);
1245 bfin_write_EVT6(evt_timer);
1246 bfin_write_EVT7(evt_evt7);
1247 bfin_write_EVT8(evt_evt8);
1248 bfin_write_EVT9(evt_evt9);
1249 bfin_write_EVT10(evt_evt10);
1250 bfin_write_EVT11(evt_evt11);
1251 bfin_write_EVT12(evt_evt12);
1252 bfin_write_EVT13(evt_evt13);
Philippe Gerum9703a732009-06-22 18:23:48 +02001253 bfin_write_EVT14(evt_evt14);
Bernd Schmidt8be80ed2007-07-25 14:44:49 +08001254 bfin_write_EVT15(evt_system_call);
1255 CSYNC();
1256}
1257
Sonic Zhang11b27cb2012-06-28 19:16:48 +08001258#ifndef SEC_GCTL
Bryan Wu1394f032007-05-06 14:50:22 -07001259/*
1260 * This function should be called during kernel startup to initialize
1261 * the BFin IRQ handling routines.
1262 */
Michael Hennerich8d022372008-11-18 17:48:22 +08001263
Bryan Wu1394f032007-05-06 14:50:22 -07001264int __init init_arch_irq(void)
1265{
1266 int irq;
1267 unsigned long ilat = 0;
Mike Frysingerfc6bd7b2011-04-15 01:35:53 -04001268
Bryan Wu1394f032007-05-06 14:50:22 -07001269 /* Disable all the peripheral intrs - page 4-29 HW Ref manual */
Mike Frysingerfc6bd7b2011-04-15 01:35:53 -04001270#ifdef SIC_IMASK0
Roy Huang24a07a12007-07-12 22:41:45 +08001271 bfin_write_SIC_IMASK0(SIC_UNMASK_ALL);
1272 bfin_write_SIC_IMASK1(SIC_UNMASK_ALL);
Mike Frysingerfc6bd7b2011-04-15 01:35:53 -04001273# ifdef SIC_IMASK2
Michael Hennerich59003142007-10-21 16:54:27 +08001274 bfin_write_SIC_IMASK2(SIC_UNMASK_ALL);
Mike Frysingera055b2b2007-11-15 21:12:32 +08001275# endif
Steven Miao4f6b6002012-05-16 17:56:51 +08001276# if defined(CONFIG_SMP) || defined(CONFIG_ICC)
Graf Yang6b3087c2009-01-07 23:14:39 +08001277 bfin_write_SICB_IMASK0(SIC_UNMASK_ALL);
1278 bfin_write_SICB_IMASK1(SIC_UNMASK_ALL);
1279# endif
Roy Huang24a07a12007-07-12 22:41:45 +08001280#else
Bryan Wu1394f032007-05-06 14:50:22 -07001281 bfin_write_SIC_IMASK(SIC_UNMASK_ALL);
Roy Huang24a07a12007-07-12 22:41:45 +08001282#endif
Bryan Wu1394f032007-05-06 14:50:22 -07001283
1284 local_irq_disable();
1285
Mike Frysinger01f8e342011-06-26 13:56:23 -04001286#if BFIN_GPIO_PINT
Mike Frysingera055b2b2007-11-15 21:12:32 +08001287# ifdef CONFIG_PINTx_REASSIGN
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001288 pint[0]->assign = CONFIG_PINT0_ASSIGN;
1289 pint[1]->assign = CONFIG_PINT1_ASSIGN;
1290 pint[2]->assign = CONFIG_PINT2_ASSIGN;
1291 pint[3]->assign = CONFIG_PINT3_ASSIGN;
Mike Frysingera055b2b2007-11-15 21:12:32 +08001292# endif
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001293 /* Whenever PINTx_ASSIGN is altered init_pint_lut() must be executed! */
1294 init_pint_lut();
1295#endif
1296
1297 for (irq = 0; irq <= SYS_IRQS; irq++) {
Bryan Wu1394f032007-05-06 14:50:22 -07001298 if (irq <= IRQ_CORETMR)
Thomas Gleixner43f2f112011-03-24 17:22:30 +01001299 irq_set_chip(irq, &bfin_core_irqchip);
Bryan Wu1394f032007-05-06 14:50:22 -07001300 else
Thomas Gleixner43f2f112011-03-24 17:22:30 +01001301 irq_set_chip(irq, &bfin_internal_irqchip);
Bryan Wu1394f032007-05-06 14:50:22 -07001302
Michael Hennerich464abc52008-02-25 13:50:20 +08001303 switch (irq) {
Mike Frysinger01f8e342011-06-26 13:56:23 -04001304#if BFIN_GPIO_PINT
Michael Hennerich464abc52008-02-25 13:50:20 +08001305 case IRQ_PINT0:
1306 case IRQ_PINT1:
1307 case IRQ_PINT2:
1308 case IRQ_PINT3:
Mike Frysinger01f8e342011-06-26 13:56:23 -04001309#elif defined(BF537_FAMILY)
1310 case IRQ_PH_INTA_MAC_RX:
1311 case IRQ_PF_INTA_PG_INTA:
1312#elif defined(BF533_FAMILY)
1313 case IRQ_PROG_INTA:
Bryan Wu2f6f4bc2008-11-18 17:48:21 +08001314#elif defined(CONFIG_BF52x) || defined(CONFIG_BF51x)
Michael Hennerich464abc52008-02-25 13:50:20 +08001315 case IRQ_PORTF_INTA:
1316 case IRQ_PORTG_INTA:
1317 case IRQ_PORTH_INTA:
Michael Hennerich2c4f8292008-02-09 04:11:14 +08001318#elif defined(CONFIG_BF561)
Michael Hennerich464abc52008-02-25 13:50:20 +08001319 case IRQ_PROG0_INTA:
1320 case IRQ_PROG1_INTA:
1321 case IRQ_PROG2_INTA:
Mike Frysingerfc6bd7b2011-04-15 01:35:53 -04001322#elif defined(BF538_FAMILY)
Michael Hennerichdc26aec2008-11-18 17:48:22 +08001323 case IRQ_PORTF_INTA:
Michael Hennerich59003142007-10-21 16:54:27 +08001324#endif
Thomas Gleixner43f2f112011-03-24 17:22:30 +01001325 irq_set_chained_handler(irq, bfin_demux_gpio_irq);
Michael Hennerich464abc52008-02-25 13:50:20 +08001326 break;
Michael Hennerichaec59c92010-02-19 15:09:10 +00001327#if defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE)
1328 case IRQ_MAC_ERROR:
Thomas Gleixner43f2f112011-03-24 17:22:30 +01001329 irq_set_chained_handler(irq,
1330 bfin_demux_mac_status_irq);
Michael Hennerichaec59c92010-02-19 15:09:10 +00001331 break;
1332#endif
Steven Miao4f6b6002012-05-16 17:56:51 +08001333#if defined(CONFIG_SMP) || defined(CONFIG_ICC)
Graf Yang6b3087c2009-01-07 23:14:39 +08001334 case IRQ_SUPPLE_0:
1335 case IRQ_SUPPLE_1:
Thomas Gleixner43f2f112011-03-24 17:22:30 +01001336 irq_set_handler(irq, handle_percpu_irq);
Graf Yang6b3087c2009-01-07 23:14:39 +08001337 break;
1338#endif
Graf Yang179413142009-08-18 04:29:33 +00001339
Yi Licb191712009-12-30 07:12:50 +00001340#ifdef CONFIG_TICKSOURCE_CORETMR
1341 case IRQ_CORETMR:
1342# ifdef CONFIG_SMP
Thomas Gleixner43f2f112011-03-24 17:22:30 +01001343 irq_set_handler(irq, handle_percpu_irq);
Yi Licb191712009-12-30 07:12:50 +00001344# else
Thomas Gleixner43f2f112011-03-24 17:22:30 +01001345 irq_set_handler(irq, handle_simple_irq);
Yi Licb191712009-12-30 07:12:50 +00001346# endif
Mike Frysingerfc6bd7b2011-04-15 01:35:53 -04001347 break;
Yi Licb191712009-12-30 07:12:50 +00001348#endif
1349
1350#ifdef CONFIG_TICKSOURCE_GPTMR0
Philippe Geruma40494a2009-06-16 05:25:42 +02001351 case IRQ_TIMER0:
Thomas Gleixner43f2f112011-03-24 17:22:30 +01001352 irq_set_handler(irq, handle_simple_irq);
Michael Hennerich464abc52008-02-25 13:50:20 +08001353 break;
Graf Yang179413142009-08-18 04:29:33 +00001354#endif
Yi Licb191712009-12-30 07:12:50 +00001355
Mike Frysingerfc6bd7b2011-04-15 01:35:53 -04001356 default:
Yi Licb191712009-12-30 07:12:50 +00001357#ifdef CONFIG_IPIPE
Thomas Gleixner43f2f112011-03-24 17:22:30 +01001358 irq_set_handler(irq, handle_level_irq);
Mike Frysingerfc6bd7b2011-04-15 01:35:53 -04001359#else
Thomas Gleixner43f2f112011-03-24 17:22:30 +01001360 irq_set_handler(irq, handle_simple_irq);
Mike Frysingerfc6bd7b2011-04-15 01:35:53 -04001361#endif
Philippe Geruma40494a2009-06-16 05:25:42 +02001362 break;
Bryan Wu1394f032007-05-06 14:50:22 -07001363 }
Bryan Wu1394f032007-05-06 14:50:22 -07001364 }
Michael Hennerich464abc52008-02-25 13:50:20 +08001365
Mike Frysingerf58c3272011-04-15 03:08:20 -04001366 init_mach_irq();
Bryan Wu1394f032007-05-06 14:50:22 -07001367
Sonic Zhang11b27cb2012-06-28 19:16:48 +08001368#if (defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE))
Michael Hennerichaec59c92010-02-19 15:09:10 +00001369 for (irq = IRQ_MAC_PHYINT; irq <= IRQ_MAC_STMDONE; irq++)
Thomas Gleixner43f2f112011-03-24 17:22:30 +01001370 irq_set_chip_and_handler(irq, &bfin_mac_status_irqchip,
Michael Hennerichaec59c92010-02-19 15:09:10 +00001371 handle_level_irq);
1372#endif
Michael Hennerich464abc52008-02-25 13:50:20 +08001373 /* if configured as edge, then will be changed to do_edge_IRQ */
Michael Hennerichaec59c92010-02-19 15:09:10 +00001374 for (irq = GPIO_IRQ_BASE;
1375 irq < (GPIO_IRQ_BASE + MAX_BLACKFIN_GPIOS); irq++)
Thomas Gleixner43f2f112011-03-24 17:22:30 +01001376 irq_set_chip_and_handler(irq, &bfin_gpio_irqchip,
Michael Hennerich464abc52008-02-25 13:50:20 +08001377 handle_level_irq);
Bryan Wu1394f032007-05-06 14:50:22 -07001378 bfin_write_IMASK(0);
1379 CSYNC();
1380 ilat = bfin_read_ILAT();
1381 CSYNC();
1382 bfin_write_ILAT(ilat);
1383 CSYNC();
1384
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001385 printk(KERN_INFO "Configuring Blackfin Priority Driven Interrupts\n");
Mike Frysinger40059782008-11-18 17:48:22 +08001386 /* IMASK=xxx is equivalent to STI xx or bfin_irq_flags=xx,
Bryan Wu1394f032007-05-06 14:50:22 -07001387 * local_irq_enable()
1388 */
1389 program_IAR();
1390 /* Therefore it's better to setup IARs before interrupts enabled */
1391 search_IAR();
1392
1393 /* Enable interrupts IVG7-15 */
Mike Frysinger40059782008-11-18 17:48:22 +08001394 bfin_irq_flags |= IMASK_IVG15 |
Steven Miao4f6b6002012-05-16 17:56:51 +08001395 IMASK_IVG14 | IMASK_IVG13 | IMASK_IVG12 | IMASK_IVG11 |
1396 IMASK_IVG10 | IMASK_IVG9 | IMASK_IVG8 | IMASK_IVG7 | IMASK_IVGHW;
1397
1398 bfin_sti(bfin_irq_flags);
Bryan Wu1394f032007-05-06 14:50:22 -07001399
Michael Hennerich349ebbc2009-04-15 08:48:08 +00001400 /* This implicitly covers ANOMALY_05000171
1401 * Boot-ROM code modifies SICA_IWRx wakeup registers
1402 */
Mike Frysingerbe1d8542009-02-04 16:49:45 +08001403#ifdef SIC_IWR0
Michael Hennerich56f5f592008-08-06 17:55:32 +08001404 bfin_write_SIC_IWR0(IWR_DISABLE_ALL);
Mike Frysingerbe1d8542009-02-04 16:49:45 +08001405# ifdef SIC_IWR1
Bryan Wu2f6f4bc2008-11-18 17:48:21 +08001406 /* BF52x/BF51x system reset does not properly reset SIC_IWR1 which
Michael Hennerich55546ac2008-08-13 17:41:13 +08001407 * will screw up the bootrom as it relies on MDMA0/1 waking it
1408 * up from IDLE instructions. See this report for more info:
1409 * http://blackfin.uclinux.org/gf/tracker/4323
1410 */
Mike Frysingerb7e11292008-11-18 17:48:22 +08001411 if (ANOMALY_05000435)
1412 bfin_write_SIC_IWR1(IWR_ENABLE(10) | IWR_ENABLE(11));
1413 else
1414 bfin_write_SIC_IWR1(IWR_DISABLE_ALL);
Mike Frysingerbe1d8542009-02-04 16:49:45 +08001415# endif
1416# ifdef SIC_IWR2
Michael Hennerich56f5f592008-08-06 17:55:32 +08001417 bfin_write_SIC_IWR2(IWR_DISABLE_ALL);
Michael Hennerichfe9ec9b2008-02-25 12:04:57 +08001418# endif
1419#else
Michael Hennerich56f5f592008-08-06 17:55:32 +08001420 bfin_write_SIC_IWR(IWR_DISABLE_ALL);
Michael Hennerichfe9ec9b2008-02-25 12:04:57 +08001421#endif
Bryan Wu1394f032007-05-06 14:50:22 -07001422 return 0;
1423}
1424
1425#ifdef CONFIG_DO_IRQ_L1
Mike Frysingera055b2b2007-11-15 21:12:32 +08001426__attribute__((l1_text))
Bryan Wu1394f032007-05-06 14:50:22 -07001427#endif
Mike Frysinger6b108042011-03-30 01:35:41 -04001428static int vec_to_irq(int vec)
1429{
1430 struct ivgx *ivg = ivg7_13[vec - IVG7].ifirst;
1431 struct ivgx *ivg_stop = ivg7_13[vec - IVG7].istop;
1432 unsigned long sic_status[3];
Mike Frysinger6b108042011-03-30 01:35:41 -04001433 if (likely(vec == EVT_IVTMR_P))
1434 return IRQ_CORETMR;
Mike Frysinger6b108042011-03-30 01:35:41 -04001435#ifdef SIC_ISR
1436 sic_status[0] = bfin_read_SIC_IMASK() & bfin_read_SIC_ISR();
1437#else
1438 if (smp_processor_id()) {
1439# ifdef SICB_ISR0
1440 /* This will be optimized out in UP mode. */
1441 sic_status[0] = bfin_read_SICB_ISR0() & bfin_read_SICB_IMASK0();
1442 sic_status[1] = bfin_read_SICB_ISR1() & bfin_read_SICB_IMASK1();
1443# endif
1444 } else {
1445 sic_status[0] = bfin_read_SIC_ISR0() & bfin_read_SIC_IMASK0();
1446 sic_status[1] = bfin_read_SIC_ISR1() & bfin_read_SIC_IMASK1();
1447 }
1448#endif
1449#ifdef SIC_ISR2
1450 sic_status[2] = bfin_read_SIC_ISR2() & bfin_read_SIC_IMASK2();
1451#endif
1452
1453 for (;; ivg++) {
1454 if (ivg >= ivg_stop)
1455 return -1;
1456#ifdef SIC_ISR
1457 if (sic_status[0] & ivg->isrflag)
1458#else
1459 if (sic_status[(ivg->irqno - IVG7) / 32] & ivg->isrflag)
1460#endif
1461 return ivg->irqno;
1462 }
1463}
1464
Sonic Zhang11b27cb2012-06-28 19:16:48 +08001465#else /* SEC_GCTL */
1466
1467/*
1468 * This function should be called during kernel startup to initialize
1469 * the BFin IRQ handling routines.
1470 */
1471
1472int __init init_arch_irq(void)
1473{
1474 int irq;
1475 unsigned long ilat = 0;
1476
1477 bfin_write_SEC_GCTL(SEC_GCTL_RESET);
1478
1479 local_irq_disable();
1480
1481#if BFIN_GPIO_PINT
1482# ifdef CONFIG_PINTx_REASSIGN
1483 pint[0]->assign = CONFIG_PINT0_ASSIGN;
1484 pint[1]->assign = CONFIG_PINT1_ASSIGN;
1485 pint[2]->assign = CONFIG_PINT2_ASSIGN;
1486 pint[3]->assign = CONFIG_PINT3_ASSIGN;
1487 pint[4]->assign = CONFIG_PINT4_ASSIGN;
1488 pint[5]->assign = CONFIG_PINT5_ASSIGN;
1489# endif
1490 /* Whenever PINTx_ASSIGN is altered init_pint_lut() must be executed! */
1491 init_pint_lut();
1492#endif
1493
1494 for (irq = 0; irq <= SYS_IRQS; irq++) {
1495 if (irq <= IRQ_CORETMR) {
1496 irq_set_chip(irq, &bfin_core_irqchip);
1497#ifdef CONFIG_TICKSOURCE_CORETMR
1498 if (irq == IRQ_CORETMR)
1499# ifdef CONFIG_SMP
1500 irq_set_handler(irq, handle_percpu_irq);
1501# else
1502 irq_set_handler(irq, handle_simple_irq);
1503# endif
1504#endif
1505 } else if (irq < BFIN_IRQ(0)) {
1506 irq_set_chip_and_handler(irq, &bfin_internal_irqchip,
1507 handle_simple_irq);
1508 } else if (irq < CORE_IRQS && irq != IRQ_CGU_EVT) {
1509 irq_set_chip_and_handler(irq, &bfin_sec_irqchip,
1510 handle_sec_fault);
1511 } else if (irq >= BFIN_IRQ(21) && irq <= BFIN_IRQ(26)) {
1512 irq_set_chip(irq, &bfin_sec_irqchip);
1513 irq_set_chained_handler(irq, bfin_demux_gpio_irq);
1514 } else if (irq >= BFIN_IRQ(34) && irq <= BFIN_IRQ(37)) {
1515 irq_set_chip(irq, &bfin_sec_irqchip);
1516 irq_set_handler(irq, handle_percpu_irq);
1517 } else {
1518 irq_set_chip_and_handler(irq, &bfin_sec_irqchip,
1519 handle_fasteoi_irq);
1520 __irq_set_preflow_handler(irq, bfin_sec_preflow_handler);
1521 }
1522 }
1523 for (irq = GPIO_IRQ_BASE;
1524 irq < (GPIO_IRQ_BASE + MAX_BLACKFIN_GPIOS); irq++)
1525 irq_set_chip_and_handler(irq, &bfin_gpio_irqchip,
1526 handle_level_irq);
1527
1528 bfin_write_IMASK(0);
1529 CSYNC();
1530 ilat = bfin_read_ILAT();
1531 CSYNC();
1532 bfin_write_ILAT(ilat);
1533 CSYNC();
1534
1535 printk(KERN_INFO "Configuring Blackfin Priority Driven Interrupts\n");
1536
1537 /* Enable interrupts IVG7-15 */
1538 bfin_irq_flags |= IMASK_IVG15 |
1539 IMASK_IVG14 | IMASK_IVG13 | IMASK_IVG12 | IMASK_IVG11 |
1540 IMASK_IVG10 | IMASK_IVG9 | IMASK_IVG8 | IMASK_IVG7 | IMASK_IVGHW;
1541
1542
1543 bfin_write_SEC_FCTL(SEC_FCTL_EN | SEC_FCTL_SYSRST_EN | SEC_FCTL_FLTIN_EN);
1544 bfin_sec_enable_sci(SIC_SYSIRQ(IRQ_WATCH0));
1545 bfin_sec_enable_ssi(SIC_SYSIRQ(IRQ_WATCH0));
1546 bfin_write_SEC_SCI(0, SEC_CCTL, SEC_CCTL_RESET);
1547 udelay(100);
1548 bfin_write_SEC_GCTL(SEC_GCTL_EN);
1549 bfin_write_SEC_SCI(0, SEC_CCTL, SEC_CCTL_EN | SEC_CCTL_NMI_EN);
1550 bfin_write_SEC_SCI(1, SEC_CCTL, SEC_CCTL_EN | SEC_CCTL_NMI_EN);
1551
1552 init_software_driven_irq();
1553 register_syscore_ops(&sec_pm_syscore_ops);
1554
1555 return 0;
1556}
1557
1558#ifdef CONFIG_DO_IRQ_L1
1559__attribute__((l1_text))
1560#endif
1561static int vec_to_irq(int vec)
1562{
1563 if (likely(vec == EVT_IVTMR_P))
1564 return IRQ_CORETMR;
1565
1566 return BFIN_IRQ(bfin_read_SEC_SCI(0, SEC_CSID));
1567}
1568#endif /* SEC_GCTL */
1569
Mike Frysinger6b108042011-03-30 01:35:41 -04001570#ifdef CONFIG_DO_IRQ_L1
1571__attribute__((l1_text))
1572#endif
Bryan Wu1394f032007-05-06 14:50:22 -07001573void do_irq(int vec, struct pt_regs *fp)
1574{
Mike Frysinger6b108042011-03-30 01:35:41 -04001575 int irq = vec_to_irq(vec);
1576 if (irq == -1)
1577 return;
1578 asm_do_IRQ(irq, fp);
Bryan Wu1394f032007-05-06 14:50:22 -07001579}
Yi Li6a01f232009-01-07 23:14:39 +08001580
1581#ifdef CONFIG_IPIPE
1582
1583int __ipipe_get_irq_priority(unsigned irq)
1584{
1585 int ient, prio;
1586
1587 if (irq <= IRQ_CORETMR)
1588 return irq;
1589
Sonic Zhang11b27cb2012-06-28 19:16:48 +08001590#ifdef SEC_GCTL
1591 if (irq >= BFIN_IRQ(0))
1592 return IVG11;
1593#else
Yi Li6a01f232009-01-07 23:14:39 +08001594 for (ient = 0; ient < NR_PERI_INTS; ient++) {
1595 struct ivgx *ivg = ivg_table + ient;
1596 if (ivg->irqno == irq) {
1597 for (prio = 0; prio <= IVG13-IVG7; prio++) {
1598 if (ivg7_13[prio].ifirst <= ivg &&
1599 ivg7_13[prio].istop > ivg)
1600 return IVG7 + prio;
1601 }
1602 }
1603 }
Sonic Zhang11b27cb2012-06-28 19:16:48 +08001604#endif
Yi Li6a01f232009-01-07 23:14:39 +08001605
1606 return IVG15;
1607}
1608
Yi Li6a01f232009-01-07 23:14:39 +08001609/* Hw interrupts are disabled on entry (check SAVE_CONTEXT). */
1610#ifdef CONFIG_DO_IRQ_L1
1611__attribute__((l1_text))
1612#endif
1613asmlinkage int __ipipe_grab_irq(int vec, struct pt_regs *regs)
1614{
Philippe Gerum9bd50df2009-03-04 16:52:38 +08001615 struct ipipe_percpu_domain_data *p = ipipe_root_cpudom_ptr();
Philippe Geruma40494a2009-06-16 05:25:42 +02001616 struct ipipe_domain *this_domain = __ipipe_current_domain;
Philippe Gerum5b5da4c2011-03-17 02:12:48 -04001617 int irq, s = 0;
Yi Li6a01f232009-01-07 23:14:39 +08001618
Mike Frysinger6b108042011-03-30 01:35:41 -04001619 irq = vec_to_irq(vec);
1620 if (irq == -1)
1621 return 0;
Yi Li6a01f232009-01-07 23:14:39 +08001622
1623 if (irq == IRQ_SYSTMR) {
Philippe Geruma40494a2009-06-16 05:25:42 +02001624#if !defined(CONFIG_GENERIC_CLOCKEVENTS) || defined(CONFIG_TICKSOURCE_GPTMR0)
Yi Li6a01f232009-01-07 23:14:39 +08001625 bfin_write_TIMER_STATUS(1); /* Latch TIMIL0 */
Philippe Gerum9bd50df2009-03-04 16:52:38 +08001626#endif
Yi Li6a01f232009-01-07 23:14:39 +08001627 /* This is basically what we need from the register frame. */
1628 __raw_get_cpu_var(__ipipe_tick_regs).ipend = regs->ipend;
1629 __raw_get_cpu_var(__ipipe_tick_regs).pc = regs->pc;
Philippe Gerum9bd50df2009-03-04 16:52:38 +08001630 if (this_domain != ipipe_root_domain)
Yi Li6a01f232009-01-07 23:14:39 +08001631 __raw_get_cpu_var(__ipipe_tick_regs).ipend &= ~0x10;
Philippe Gerum9bd50df2009-03-04 16:52:38 +08001632 else
1633 __raw_get_cpu_var(__ipipe_tick_regs).ipend |= 0x10;
Yi Li6a01f232009-01-07 23:14:39 +08001634 }
1635
Philippe Gerum5b5da4c2011-03-17 02:12:48 -04001636 /*
1637 * We don't want Linux interrupt handlers to run at the
1638 * current core priority level (i.e. < EVT15), since this
1639 * might delay other interrupts handled by a high priority
1640 * domain. Here is what we do instead:
1641 *
1642 * - we raise the SYNCDEFER bit to prevent
1643 * __ipipe_handle_irq() to sync the pipeline for the root
1644 * stage for the incoming interrupt. Upon return, that IRQ is
1645 * pending in the interrupt log.
1646 *
1647 * - we raise the TIF_IRQ_SYNC bit for the current thread, so
1648 * that _schedule_and_signal_from_int will eventually sync the
1649 * pipeline from EVT15.
1650 */
Philippe Gerum9bd50df2009-03-04 16:52:38 +08001651 if (this_domain == ipipe_root_domain) {
1652 s = __test_and_set_bit(IPIPE_SYNCDEFER_FLAG, &p->status);
1653 barrier();
1654 }
Yi Li6a01f232009-01-07 23:14:39 +08001655
1656 ipipe_trace_irq_entry(irq);
1657 __ipipe_handle_irq(irq, regs);
Philippe Gerum9bd50df2009-03-04 16:52:38 +08001658 ipipe_trace_irq_exit(irq);
Yi Li6a01f232009-01-07 23:14:39 +08001659
Philippe Gerum5b5da4c2011-03-17 02:12:48 -04001660 if (user_mode(regs) &&
1661 !ipipe_test_foreign_stack() &&
1662 (current->ipipe_flags & PF_EVTRET) != 0) {
1663 /*
1664 * Testing for user_regs() does NOT fully eliminate
1665 * foreign stack contexts, because of the forged
1666 * interrupt returns we do through
1667 * __ipipe_call_irqtail. In that case, we might have
1668 * preempted a foreign stack context in a high
1669 * priority domain, with a single interrupt level now
1670 * pending after the irqtail unwinding is done. In
1671 * which case user_mode() is now true, and the event
1672 * gets dispatched spuriously.
1673 */
1674 current->ipipe_flags &= ~PF_EVTRET;
1675 __ipipe_dispatch_event(IPIPE_EVENT_RETURN, regs);
1676 }
1677
Philippe Gerum9bd50df2009-03-04 16:52:38 +08001678 if (this_domain == ipipe_root_domain) {
1679 set_thread_flag(TIF_IRQ_SYNC);
1680 if (!s) {
1681 __clear_bit(IPIPE_SYNCDEFER_FLAG, &p->status);
1682 return !test_bit(IPIPE_STALL_FLAG, &p->status);
1683 }
1684 }
Yi Li6a01f232009-01-07 23:14:39 +08001685
Graf Yang1fa9be72009-05-15 11:01:59 +00001686 return 0;
Yi Li6a01f232009-01-07 23:14:39 +08001687}
1688
1689#endif /* CONFIG_IPIPE */