blob: 5a109a184021e3145c8aa2cbbb2d94b88c44a72a [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
Sonic Zhange0a59312012-06-29 18:19:29 +0800313static void bfin_sec_set_priority(unsigned int sec_int_levels, u8 *sec_int_priority)
314{
315 unsigned long flags = hard_local_irq_save();
316 uint32_t reg_sctl;
317 int i;
318
319 bfin_write_SEC_SCI(0, SEC_CPLVL, sec_int_levels);
320
321 for (i = 0; i < SYS_IRQS - BFIN_IRQ(0); i++) {
322 reg_sctl = bfin_read_SEC_SCTL(i) & ~SEC_SCTL_PRIO;
323 reg_sctl |= sec_int_priority[i] << SEC_SCTL_PRIO_OFFSET;
324 bfin_write_SEC_SCTL(i, reg_sctl);
325 }
326
327 hard_local_irq_restore(flags);
328}
329
Steven Miao4f6b6002012-05-16 17:56:51 +0800330static void bfin_sec_raise_irq(unsigned int sid)
331{
332 unsigned long flags = hard_local_irq_save();
333
334 bfin_write32(SEC_RAISE, sid);
335
336 hard_local_irq_restore(flags);
337}
338
339static void init_software_driven_irq(void)
340{
341 bfin_sec_set_ssi_coreid(34, 0);
342 bfin_sec_set_ssi_coreid(35, 1);
343 bfin_sec_set_ssi_coreid(36, 0);
344 bfin_sec_set_ssi_coreid(37, 1);
345}
346
347void bfin_sec_resume(void)
348{
349 bfin_write_SEC_SCI(0, SEC_CCTL, SEC_CCTL_RESET);
350 udelay(100);
351 bfin_write_SEC_GCTL(SEC_GCTL_EN);
352 bfin_write_SEC_SCI(0, SEC_CCTL, SEC_CCTL_EN | SEC_CCTL_NMI_EN);
353}
354
355void handle_sec_sfi_fault(uint32_t gstat)
356{
357
358}
359
360void handle_sec_sci_fault(uint32_t gstat)
361{
362 uint32_t core_id;
363 uint32_t cstat;
364
365 core_id = gstat & SEC_GSTAT_SCI;
366 cstat = bfin_read_SEC_SCI(core_id, SEC_CSTAT);
367 if (cstat & SEC_CSTAT_ERR) {
368 switch (cstat & SEC_CSTAT_ERRC) {
369 case SEC_CSTAT_ACKERR:
370 printk(KERN_DEBUG "sec ack err\n");
371 break;
372 default:
373 printk(KERN_DEBUG "sec sci unknow err\n");
374 }
375 }
376
377}
378
379void handle_sec_ssi_fault(uint32_t gstat)
380{
381 uint32_t sid;
382 uint32_t sstat;
383
384 sid = gstat & SEC_GSTAT_SID;
385 sstat = bfin_read_SEC_SSTAT(sid);
386
387}
388
389void handle_sec_fault(unsigned int irq, struct irq_desc *desc)
390{
391 uint32_t sec_gstat;
392
393 raw_spin_lock(&desc->lock);
394
395 sec_gstat = bfin_read32(SEC_GSTAT);
396 if (sec_gstat & SEC_GSTAT_ERR) {
397
398 switch (sec_gstat & SEC_GSTAT_ERRC) {
399 case 0:
400 handle_sec_sfi_fault(sec_gstat);
401 break;
402 case SEC_GSTAT_SCIERR:
403 handle_sec_sci_fault(sec_gstat);
404 break;
405 case SEC_GSTAT_SSIERR:
406 handle_sec_ssi_fault(sec_gstat);
407 break;
408 }
409
410
411 }
412
413 raw_spin_unlock(&desc->lock);
414}
415
Steven Miao4f6b6002012-05-16 17:56:51 +0800416#endif
417
Sonic Zhang0325f252009-12-28 07:29:57 +0000418#ifdef CONFIG_SMP
Thomas Gleixnerff43a672011-02-06 18:23:29 +0000419static void bfin_internal_unmask_irq_chip(struct irq_data *d)
Sonic Zhang0325f252009-12-28 07:29:57 +0000420{
Thomas Gleixnerff43a672011-02-06 18:23:29 +0000421 bfin_internal_unmask_irq_affinity(d->irq, d->affinity);
Sonic Zhang0325f252009-12-28 07:29:57 +0000422}
423
Thomas Gleixnerff43a672011-02-06 18:23:29 +0000424static int bfin_internal_set_affinity(struct irq_data *d,
425 const struct cpumask *mask, bool force)
Sonic Zhang0325f252009-12-28 07:29:57 +0000426{
Thomas Gleixnerff43a672011-02-06 18:23:29 +0000427 bfin_internal_mask_irq(d->irq);
428 bfin_internal_unmask_irq_affinity(d->irq, mask);
Sonic Zhang0325f252009-12-28 07:29:57 +0000429
430 return 0;
431}
Thomas Gleixnerff43a672011-02-06 18:23:29 +0000432#else
433static void bfin_internal_unmask_irq_chip(struct irq_data *d)
434{
435 bfin_internal_unmask_irq(d->irq);
436}
Sonic Zhang0325f252009-12-28 07:29:57 +0000437#endif
438
Sonic Zhang11b27cb2012-06-28 19:16:48 +0800439#if defined(CONFIG_PM) && !defined(SEC_GCTL)
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800440int bfin_internal_set_wake(unsigned int irq, unsigned int state)
441{
Michael Hennerich8d022372008-11-18 17:48:22 +0800442 u32 bank, bit, wakeup = 0;
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800443 unsigned long flags;
Michael Hennerich464abc52008-02-25 13:50:20 +0800444 bank = SIC_SYSIRQ(irq) / 32;
445 bit = SIC_SYSIRQ(irq) % 32;
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800446
Michael Hennerich4a88d0c2008-08-05 17:38:41 +0800447 switch (irq) {
448#ifdef IRQ_RTC
449 case IRQ_RTC:
450 wakeup |= WAKE;
451 break;
452#endif
453#ifdef IRQ_CAN0_RX
454 case IRQ_CAN0_RX:
455 wakeup |= CANWE;
456 break;
457#endif
458#ifdef IRQ_CAN1_RX
459 case IRQ_CAN1_RX:
460 wakeup |= CANWE;
461 break;
462#endif
463#ifdef IRQ_USB_INT0
464 case IRQ_USB_INT0:
465 wakeup |= USBWE;
466 break;
467#endif
Michael Hennerichd310fb42008-08-28 17:32:01 +0800468#ifdef CONFIG_BF54x
Michael Hennerich4a88d0c2008-08-05 17:38:41 +0800469 case IRQ_CNT:
470 wakeup |= ROTWE;
471 break;
472#endif
473 default:
474 break;
475 }
476
David Howells3b139cd2010-10-07 14:08:52 +0100477 flags = hard_local_irq_save();
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800478
Michael Hennerich4a88d0c2008-08-05 17:38:41 +0800479 if (state) {
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800480 bfin_sic_iwr[bank] |= (1 << bit);
Michael Hennerich4a88d0c2008-08-05 17:38:41 +0800481 vr_wakeup |= wakeup;
482
483 } else {
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800484 bfin_sic_iwr[bank] &= ~(1 << bit);
Michael Hennerich4a88d0c2008-08-05 17:38:41 +0800485 vr_wakeup &= ~wakeup;
486 }
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800487
David Howells3b139cd2010-10-07 14:08:52 +0100488 hard_local_irq_restore(flags);
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800489
490 return 0;
491}
Thomas Gleixnerff43a672011-02-06 18:23:29 +0000492
493static int bfin_internal_set_wake_chip(struct irq_data *d, unsigned int state)
494{
495 return bfin_internal_set_wake(d->irq, state);
496}
Mike Frysingerfc6bd7b2011-04-15 01:35:53 -0400497#else
Bob Liu357351b2012-06-01 14:04:02 +0800498inline int bfin_internal_set_wake(unsigned int irq, unsigned int state)
499{
500 return 0;
501}
Mike Frysingerfc6bd7b2011-04-15 01:35:53 -0400502# define bfin_internal_set_wake_chip NULL
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800503#endif
504
Bryan Wu1394f032007-05-06 14:50:22 -0700505static struct irq_chip bfin_core_irqchip = {
Graf Yang763e63c2008-10-08 17:08:15 +0800506 .name = "CORE",
Thomas Gleixner4f19ea42011-02-06 18:23:27 +0000507 .irq_mask = bfin_core_mask_irq,
508 .irq_unmask = bfin_core_unmask_irq,
Bryan Wu1394f032007-05-06 14:50:22 -0700509};
510
511static struct irq_chip bfin_internal_irqchip = {
Graf Yang763e63c2008-10-08 17:08:15 +0800512 .name = "INTN",
Thomas Gleixnerff43a672011-02-06 18:23:29 +0000513 .irq_mask = bfin_internal_mask_irq_chip,
514 .irq_unmask = bfin_internal_unmask_irq_chip,
Thomas Gleixnerff43a672011-02-06 18:23:29 +0000515 .irq_disable = bfin_internal_mask_irq_chip,
516 .irq_enable = bfin_internal_unmask_irq_chip,
Sonic Zhang0325f252009-12-28 07:29:57 +0000517#ifdef CONFIG_SMP
Thomas Gleixnerff43a672011-02-06 18:23:29 +0000518 .irq_set_affinity = bfin_internal_set_affinity,
Sonic Zhang0325f252009-12-28 07:29:57 +0000519#endif
Thomas Gleixnerff43a672011-02-06 18:23:29 +0000520 .irq_set_wake = bfin_internal_set_wake_chip,
Bryan Wu1394f032007-05-06 14:50:22 -0700521};
522
Sonic Zhang11b27cb2012-06-28 19:16:48 +0800523#ifdef SEC_GCTL
Steven Miao4f6b6002012-05-16 17:56:51 +0800524static struct irq_chip bfin_sec_irqchip = {
525 .name = "SEC",
526 .irq_mask_ack = bfin_sec_mask_ack_irq,
527 .irq_mask = bfin_sec_mask_ack_irq,
528 .irq_unmask = bfin_sec_unmask_irq,
529 .irq_eoi = bfin_sec_unmask_irq,
530 .irq_disable = bfin_sec_disable,
531 .irq_enable = bfin_sec_enable,
532};
533#endif
534
Mike Frysingerf58c3272011-04-15 03:08:20 -0400535void bfin_handle_irq(unsigned irq)
Yi Li6a01f232009-01-07 23:14:39 +0800536{
537#ifdef CONFIG_IPIPE
538 struct pt_regs regs; /* Contents not used. */
539 ipipe_trace_irq_entry(irq);
540 __ipipe_handle_irq(irq, &regs);
541 ipipe_trace_irq_exit(irq);
542#else /* !CONFIG_IPIPE */
Thomas Gleixnerb10bbbb2011-02-06 18:23:25 +0000543 generic_handle_irq(irq);
Yi Li6a01f232009-01-07 23:14:39 +0800544#endif /* !CONFIG_IPIPE */
545}
546
Michael Hennerichaec59c92010-02-19 15:09:10 +0000547#if defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE)
548static int mac_stat_int_mask;
549
550static void bfin_mac_status_ack_irq(unsigned int irq)
551{
552 switch (irq) {
553 case IRQ_MAC_MMCINT:
554 bfin_write_EMAC_MMC_TIRQS(
555 bfin_read_EMAC_MMC_TIRQE() &
556 bfin_read_EMAC_MMC_TIRQS());
557 bfin_write_EMAC_MMC_RIRQS(
558 bfin_read_EMAC_MMC_RIRQE() &
559 bfin_read_EMAC_MMC_RIRQS());
560 break;
561 case IRQ_MAC_RXFSINT:
562 bfin_write_EMAC_RX_STKY(
563 bfin_read_EMAC_RX_IRQE() &
564 bfin_read_EMAC_RX_STKY());
565 break;
566 case IRQ_MAC_TXFSINT:
567 bfin_write_EMAC_TX_STKY(
568 bfin_read_EMAC_TX_IRQE() &
569 bfin_read_EMAC_TX_STKY());
570 break;
571 case IRQ_MAC_WAKEDET:
572 bfin_write_EMAC_WKUP_CTL(
573 bfin_read_EMAC_WKUP_CTL() | MPKS | RWKS);
574 break;
575 default:
576 /* These bits are W1C */
577 bfin_write_EMAC_SYSTAT(1L << (irq - IRQ_MAC_PHYINT));
578 break;
579 }
580}
581
Thomas Gleixner172d2d12011-02-06 18:23:34 +0000582static void bfin_mac_status_mask_irq(struct irq_data *d)
Michael Hennerichaec59c92010-02-19 15:09:10 +0000583{
Thomas Gleixner172d2d12011-02-06 18:23:34 +0000584 unsigned int irq = d->irq;
585
Michael Hennerichaec59c92010-02-19 15:09:10 +0000586 mac_stat_int_mask &= ~(1L << (irq - IRQ_MAC_PHYINT));
Mike Frysingerf58c3272011-04-15 03:08:20 -0400587#ifdef BF537_FAMILY
Michael Hennerichaec59c92010-02-19 15:09:10 +0000588 switch (irq) {
589 case IRQ_MAC_PHYINT:
590 bfin_write_EMAC_SYSCTL(bfin_read_EMAC_SYSCTL() & ~PHYIE);
591 break;
592 default:
593 break;
594 }
595#else
596 if (!mac_stat_int_mask)
597 bfin_internal_mask_irq(IRQ_MAC_ERROR);
598#endif
599 bfin_mac_status_ack_irq(irq);
600}
601
Thomas Gleixner172d2d12011-02-06 18:23:34 +0000602static void bfin_mac_status_unmask_irq(struct irq_data *d)
Michael Hennerichaec59c92010-02-19 15:09:10 +0000603{
Thomas Gleixner172d2d12011-02-06 18:23:34 +0000604 unsigned int irq = d->irq;
605
Mike Frysingerf58c3272011-04-15 03:08:20 -0400606#ifdef BF537_FAMILY
Michael Hennerichaec59c92010-02-19 15:09:10 +0000607 switch (irq) {
608 case IRQ_MAC_PHYINT:
609 bfin_write_EMAC_SYSCTL(bfin_read_EMAC_SYSCTL() | PHYIE);
610 break;
611 default:
612 break;
613 }
614#else
615 if (!mac_stat_int_mask)
616 bfin_internal_unmask_irq(IRQ_MAC_ERROR);
617#endif
618 mac_stat_int_mask |= 1L << (irq - IRQ_MAC_PHYINT);
619}
620
621#ifdef CONFIG_PM
Thomas Gleixner172d2d12011-02-06 18:23:34 +0000622int bfin_mac_status_set_wake(struct irq_data *d, unsigned int state)
Michael Hennerichaec59c92010-02-19 15:09:10 +0000623{
Mike Frysingerf58c3272011-04-15 03:08:20 -0400624#ifdef BF537_FAMILY
Michael Hennerichaec59c92010-02-19 15:09:10 +0000625 return bfin_internal_set_wake(IRQ_GENERIC_ERROR, state);
626#else
627 return bfin_internal_set_wake(IRQ_MAC_ERROR, state);
628#endif
629}
Mike Frysingerfc6bd7b2011-04-15 01:35:53 -0400630#else
631# define bfin_mac_status_set_wake NULL
Michael Hennerichaec59c92010-02-19 15:09:10 +0000632#endif
633
634static struct irq_chip bfin_mac_status_irqchip = {
635 .name = "MACST",
Thomas Gleixner172d2d12011-02-06 18:23:34 +0000636 .irq_mask = bfin_mac_status_mask_irq,
637 .irq_unmask = bfin_mac_status_unmask_irq,
Thomas Gleixner172d2d12011-02-06 18:23:34 +0000638 .irq_set_wake = bfin_mac_status_set_wake,
Michael Hennerichaec59c92010-02-19 15:09:10 +0000639};
640
Mike Frysingerf58c3272011-04-15 03:08:20 -0400641void bfin_demux_mac_status_irq(unsigned int int_err_irq,
642 struct irq_desc *inta_desc)
Michael Hennerichaec59c92010-02-19 15:09:10 +0000643{
644 int i, irq = 0;
645 u32 status = bfin_read_EMAC_SYSTAT();
646
Michael Hennerichbedeea62010-08-20 11:59:27 +0000647 for (i = 0; i <= (IRQ_MAC_STMDONE - IRQ_MAC_PHYINT); i++)
Michael Hennerichaec59c92010-02-19 15:09:10 +0000648 if (status & (1L << i)) {
649 irq = IRQ_MAC_PHYINT + i;
650 break;
651 }
652
653 if (irq) {
654 if (mac_stat_int_mask & (1L << (irq - IRQ_MAC_PHYINT))) {
655 bfin_handle_irq(irq);
656 } else {
657 bfin_mac_status_ack_irq(irq);
658 pr_debug("IRQ %d:"
Steven Miao4f6b6002012-05-16 17:56:51 +0800659 " MASKED MAC ERROR INTERRUPT ASSERTED\n",
660 irq);
Michael Hennerichaec59c92010-02-19 15:09:10 +0000661 }
662 } else
663 printk(KERN_ERR
Steven Miao4f6b6002012-05-16 17:56:51 +0800664 "%s : %s : LINE %d :\nIRQ ?: MAC ERROR"
665 " INTERRUPT ASSERTED BUT NO SOURCE FOUND"
666 "(EMAC_SYSTAT=0x%X)\n",
667 __func__, __FILE__, __LINE__, status);
Michael Hennerichaec59c92010-02-19 15:09:10 +0000668}
669#endif
670
Graf Yangbfd15112008-10-08 18:02:44 +0800671static inline void bfin_set_irq_handler(unsigned irq, irq_flow_handler_t handle)
672{
Yi Li6a01f232009-01-07 23:14:39 +0800673#ifdef CONFIG_IPIPE
Philippe Gerum5b5da4c2011-03-17 02:12:48 -0400674 handle = handle_level_irq;
Yi Li6a01f232009-01-07 23:14:39 +0800675#endif
Thomas Gleixner43f2f112011-03-24 17:22:30 +0100676 __irq_set_handler_locked(irq, handle);
Graf Yangbfd15112008-10-08 18:02:44 +0800677}
678
Michael Hennerich8d022372008-11-18 17:48:22 +0800679static DECLARE_BITMAP(gpio_enabled, MAX_BLACKFIN_GPIOS);
Michael Hennerichaffee2b2008-04-24 08:10:10 +0800680extern void bfin_gpio_irq_prepare(unsigned gpio);
Michael Hennerich6fce6a82007-12-24 16:56:12 +0800681
Mike Frysinger01f8e342011-06-26 13:56:23 -0400682#if !BFIN_GPIO_PINT
Michael Hennerich8d022372008-11-18 17:48:22 +0800683
Thomas Gleixnere9502852011-02-06 18:23:36 +0000684static void bfin_gpio_ack_irq(struct irq_data *d)
Bryan Wu1394f032007-05-06 14:50:22 -0700685{
Michael Hennerich8d022372008-11-18 17:48:22 +0800686 /* AFAIK ack_irq in case mask_ack is provided
687 * get's only called for edge sense irqs
688 */
Thomas Gleixnere9502852011-02-06 18:23:36 +0000689 set_gpio_data(irq_to_gpio(d->irq), 0);
Bryan Wu1394f032007-05-06 14:50:22 -0700690}
691
Thomas Gleixnere9502852011-02-06 18:23:36 +0000692static void bfin_gpio_mask_ack_irq(struct irq_data *d)
Bryan Wu1394f032007-05-06 14:50:22 -0700693{
Thomas Gleixnere9502852011-02-06 18:23:36 +0000694 unsigned int irq = d->irq;
Michael Hennerich8d022372008-11-18 17:48:22 +0800695 u32 gpionr = irq_to_gpio(irq);
Bryan Wu1394f032007-05-06 14:50:22 -0700696
Thomas Gleixner1907d8b2011-03-24 17:21:01 +0100697 if (!irqd_is_level_type(d))
Bryan Wu1394f032007-05-06 14:50:22 -0700698 set_gpio_data(gpionr, 0);
Bryan Wu1394f032007-05-06 14:50:22 -0700699
700 set_gpio_maska(gpionr, 0);
Bryan Wu1394f032007-05-06 14:50:22 -0700701}
702
Thomas Gleixnere9502852011-02-06 18:23:36 +0000703static void bfin_gpio_mask_irq(struct irq_data *d)
Bryan Wu1394f032007-05-06 14:50:22 -0700704{
Thomas Gleixnere9502852011-02-06 18:23:36 +0000705 set_gpio_maska(irq_to_gpio(d->irq), 0);
Bryan Wu1394f032007-05-06 14:50:22 -0700706}
707
Thomas Gleixnere9502852011-02-06 18:23:36 +0000708static void bfin_gpio_unmask_irq(struct irq_data *d)
Bryan Wu1394f032007-05-06 14:50:22 -0700709{
Thomas Gleixnere9502852011-02-06 18:23:36 +0000710 set_gpio_maska(irq_to_gpio(d->irq), 1);
Bryan Wu1394f032007-05-06 14:50:22 -0700711}
712
Thomas Gleixnere9502852011-02-06 18:23:36 +0000713static unsigned int bfin_gpio_irq_startup(struct irq_data *d)
Bryan Wu1394f032007-05-06 14:50:22 -0700714{
Thomas Gleixnere9502852011-02-06 18:23:36 +0000715 u32 gpionr = irq_to_gpio(d->irq);
Bryan Wu1394f032007-05-06 14:50:22 -0700716
Michael Hennerich8d022372008-11-18 17:48:22 +0800717 if (__test_and_set_bit(gpionr, gpio_enabled))
Michael Hennerichaffee2b2008-04-24 08:10:10 +0800718 bfin_gpio_irq_prepare(gpionr);
Bryan Wu1394f032007-05-06 14:50:22 -0700719
Thomas Gleixnere9502852011-02-06 18:23:36 +0000720 bfin_gpio_unmask_irq(d);
Bryan Wu1394f032007-05-06 14:50:22 -0700721
Michael Hennerichaffee2b2008-04-24 08:10:10 +0800722 return 0;
Bryan Wu1394f032007-05-06 14:50:22 -0700723}
724
Thomas Gleixnere9502852011-02-06 18:23:36 +0000725static void bfin_gpio_irq_shutdown(struct irq_data *d)
Bryan Wu1394f032007-05-06 14:50:22 -0700726{
Thomas Gleixnere9502852011-02-06 18:23:36 +0000727 u32 gpionr = irq_to_gpio(d->irq);
Graf Yang30af6d42008-11-18 17:48:21 +0800728
Thomas Gleixnere9502852011-02-06 18:23:36 +0000729 bfin_gpio_mask_irq(d);
Graf Yang30af6d42008-11-18 17:48:21 +0800730 __clear_bit(gpionr, gpio_enabled);
Graf Yang9570ff42009-01-07 23:14:38 +0800731 bfin_gpio_irq_free(gpionr);
Bryan Wu1394f032007-05-06 14:50:22 -0700732}
733
Thomas Gleixnere9502852011-02-06 18:23:36 +0000734static int bfin_gpio_irq_type(struct irq_data *d, unsigned int type)
Bryan Wu1394f032007-05-06 14:50:22 -0700735{
Thomas Gleixnere9502852011-02-06 18:23:36 +0000736 unsigned int irq = d->irq;
Graf Yang8eb3e3b2008-11-18 17:48:22 +0800737 int ret;
738 char buf[16];
Michael Hennerich8d022372008-11-18 17:48:22 +0800739 u32 gpionr = irq_to_gpio(irq);
Bryan Wu1394f032007-05-06 14:50:22 -0700740
741 if (type == IRQ_TYPE_PROBE) {
742 /* only probe unenabled GPIO interrupt lines */
Mike Frysingerc3695342009-06-13 10:32:29 -0400743 if (test_bit(gpionr, gpio_enabled))
Bryan Wu1394f032007-05-06 14:50:22 -0700744 return 0;
745 type = IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING;
746 }
747
748 if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING |
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800749 IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW)) {
Michael Hennerich8d022372008-11-18 17:48:22 +0800750
Graf Yang9570ff42009-01-07 23:14:38 +0800751 snprintf(buf, 16, "gpio-irq%d", irq);
752 ret = bfin_gpio_irq_request(gpionr, buf);
753 if (ret)
754 return ret;
755
Michael Hennerich8d022372008-11-18 17:48:22 +0800756 if (__test_and_set_bit(gpionr, gpio_enabled))
Michael Hennerichaffee2b2008-04-24 08:10:10 +0800757 bfin_gpio_irq_prepare(gpionr);
Bryan Wu1394f032007-05-06 14:50:22 -0700758
Bryan Wu1394f032007-05-06 14:50:22 -0700759 } else {
Michael Hennerich8d022372008-11-18 17:48:22 +0800760 __clear_bit(gpionr, gpio_enabled);
Bryan Wu1394f032007-05-06 14:50:22 -0700761 return 0;
762 }
763
Michael Hennerichf1bceb42008-02-02 16:17:52 +0800764 set_gpio_inen(gpionr, 0);
Bryan Wu1394f032007-05-06 14:50:22 -0700765 set_gpio_dir(gpionr, 0);
Bryan Wu1394f032007-05-06 14:50:22 -0700766
767 if ((type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING))
768 == (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING))
769 set_gpio_both(gpionr, 1);
770 else
771 set_gpio_both(gpionr, 0);
772
773 if ((type & (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_LEVEL_LOW)))
774 set_gpio_polar(gpionr, 1); /* low or falling edge denoted by one */
775 else
776 set_gpio_polar(gpionr, 0); /* high or rising edge denoted by zero */
777
Michael Hennerichf1bceb42008-02-02 16:17:52 +0800778 if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING)) {
779 set_gpio_edge(gpionr, 1);
780 set_gpio_inen(gpionr, 1);
Michael Hennerichf1bceb42008-02-02 16:17:52 +0800781 set_gpio_data(gpionr, 0);
782
783 } else {
784 set_gpio_edge(gpionr, 0);
Michael Hennerichf1bceb42008-02-02 16:17:52 +0800785 set_gpio_inen(gpionr, 1);
786 }
787
Bryan Wu1394f032007-05-06 14:50:22 -0700788 if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING))
Graf Yangbfd15112008-10-08 18:02:44 +0800789 bfin_set_irq_handler(irq, handle_edge_irq);
Bryan Wu1394f032007-05-06 14:50:22 -0700790 else
Graf Yangbfd15112008-10-08 18:02:44 +0800791 bfin_set_irq_handler(irq, handle_level_irq);
Bryan Wu1394f032007-05-06 14:50:22 -0700792
793 return 0;
794}
795
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800796#ifdef CONFIG_PM
Mike Frysingerdd8cb372011-04-15 03:19:22 -0400797static int bfin_gpio_set_wake(struct irq_data *d, unsigned int state)
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800798{
Thomas Gleixnere9502852011-02-06 18:23:36 +0000799 return gpio_pm_wakeup_ctrl(irq_to_gpio(d->irq), state);
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800800}
Mike Frysingerfc6bd7b2011-04-15 01:35:53 -0400801#else
802# define bfin_gpio_set_wake NULL
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800803#endif
804
Mike Frysingere2a80922011-04-15 12:51:33 -0400805static void bfin_demux_gpio_block(unsigned int irq)
806{
807 unsigned int gpio, mask;
808
809 gpio = irq_to_gpio(irq);
810 mask = get_gpiop_data(gpio) & get_gpiop_maska(gpio);
811
812 while (mask) {
813 if (mask & 1)
814 bfin_handle_irq(irq);
815 irq++;
816 mask >>= 1;
817 }
818}
819
Mike Frysinger8c054102011-04-15 13:04:59 -0400820void bfin_demux_gpio_irq(unsigned int inta_irq,
Steven Miao4f6b6002012-05-16 17:56:51 +0800821 struct irq_desc *desc)
Bryan Wu1394f032007-05-06 14:50:22 -0700822{
Mike Frysingere2a80922011-04-15 12:51:33 -0400823 unsigned int irq;
Bryan Wu1394f032007-05-06 14:50:22 -0700824
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800825 switch (inta_irq) {
Mike Frysingere2a80922011-04-15 12:51:33 -0400826#if defined(BF537_FAMILY)
Mike Frysinger8c054102011-04-15 13:04:59 -0400827 case IRQ_PF_INTA_PG_INTA:
Mike Frysingere2a80922011-04-15 12:51:33 -0400828 bfin_demux_gpio_block(IRQ_PF0);
829 irq = IRQ_PG0;
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800830 break;
Mike Frysinger8c054102011-04-15 13:04:59 -0400831 case IRQ_PH_INTA_MAC_RX:
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800832 irq = IRQ_PH0;
833 break;
Mike Frysingere2a80922011-04-15 12:51:33 -0400834#elif defined(BF533_FAMILY)
835 case IRQ_PROG_INTA:
836 irq = IRQ_PF0;
837 break;
Mike Frysingerfc6bd7b2011-04-15 01:35:53 -0400838#elif defined(BF538_FAMILY)
Michael Hennerichdc26aec2008-11-18 17:48:22 +0800839 case IRQ_PORTF_INTA:
840 irq = IRQ_PF0;
841 break;
Bryan Wu2f6f4bc2008-11-18 17:48:21 +0800842#elif defined(CONFIG_BF52x) || defined(CONFIG_BF51x)
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800843 case IRQ_PORTF_INTA:
844 irq = IRQ_PF0;
845 break;
846 case IRQ_PORTG_INTA:
847 irq = IRQ_PG0;
848 break;
849 case IRQ_PORTH_INTA:
850 irq = IRQ_PH0;
851 break;
852#elif defined(CONFIG_BF561)
853 case IRQ_PROG0_INTA:
854 irq = IRQ_PF0;
855 break;
856 case IRQ_PROG1_INTA:
857 irq = IRQ_PF16;
858 break;
859 case IRQ_PROG2_INTA:
860 irq = IRQ_PF32;
861 break;
862#endif
863 default:
864 BUG();
865 return;
Bryan Wu1394f032007-05-06 14:50:22 -0700866 }
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800867
Mike Frysingere2a80922011-04-15 12:51:33 -0400868 bfin_demux_gpio_block(irq);
Bryan Wu1394f032007-05-06 14:50:22 -0700869}
870
Mike Frysinger01f8e342011-06-26 13:56:23 -0400871#else
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800872
Steven Miao4f6b6002012-05-16 17:56:51 +0800873#define NR_PINT_BITS 32
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800874#define IRQ_NOT_AVAIL 0xFF
875
876#define PINT_2_BANK(x) ((x) >> 5)
877#define PINT_2_BIT(x) ((x) & 0x1F)
878#define PINT_BIT(x) (1 << (PINT_2_BIT(x)))
879
880static unsigned char irq2pint_lut[NR_PINTS];
Michael Henneriche3f23002007-07-12 16:39:29 +0800881static unsigned char pint2irq_lut[NR_PINT_SYS_IRQS * NR_PINT_BITS];
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800882
Mike Frysinger82ed5f72011-06-26 13:22:05 -0400883static struct bfin_pint_regs * const pint[NR_PINT_SYS_IRQS] = {
884 (struct bfin_pint_regs *)PINT0_MASK_SET,
885 (struct bfin_pint_regs *)PINT1_MASK_SET,
886 (struct bfin_pint_regs *)PINT2_MASK_SET,
887 (struct bfin_pint_regs *)PINT3_MASK_SET,
Steven Miao4f6b6002012-05-16 17:56:51 +0800888#ifdef CONFIG_BF60x
889 (struct bfin_pint_regs *)PINT4_MASK_SET,
890 (struct bfin_pint_regs *)PINT5_MASK_SET,
891#endif
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800892};
893
Michael Hennerich8d022372008-11-18 17:48:22 +0800894inline unsigned int get_irq_base(u32 bank, u8 bmap)
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800895{
Michael Hennerich8d022372008-11-18 17:48:22 +0800896 unsigned int irq_base;
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800897
Sonic Zhang11b27cb2012-06-28 19:16:48 +0800898#ifndef CONFIG_BF60x
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800899 if (bank < 2) { /*PA-PB */
900 irq_base = IRQ_PA0 + bmap * 16;
901 } else { /*PC-PJ */
902 irq_base = IRQ_PC0 + bmap * 16;
903 }
Steven Miao4f6b6002012-05-16 17:56:51 +0800904#else
Steven Miao4f6b6002012-05-16 17:56:51 +0800905 irq_base = IRQ_PA0 + bank * 16 + bmap * 16;
Sonic Zhang11b27cb2012-06-28 19:16:48 +0800906#endif
Steven Miao4f6b6002012-05-16 17:56:51 +0800907 return irq_base;
908}
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800909
910 /* Whenever PINTx_ASSIGN is altered init_pint_lut() must be executed! */
911void init_pint_lut(void)
912{
913 u16 bank, bit, irq_base, bit_pos;
914 u32 pint_assign;
915 u8 bmap;
916
917 memset(irq2pint_lut, IRQ_NOT_AVAIL, sizeof(irq2pint_lut));
918
919 for (bank = 0; bank < NR_PINT_SYS_IRQS; bank++) {
920
921 pint_assign = pint[bank]->assign;
922
923 for (bit = 0; bit < NR_PINT_BITS; bit++) {
924
925 bmap = (pint_assign >> ((bit / 8) * 8)) & 0xFF;
926
927 irq_base = get_irq_base(bank, bmap);
928
929 irq_base += (bit % 8) + ((bit / 8) & 1 ? 8 : 0);
930 bit_pos = bit + bank * NR_PINT_BITS;
931
Michael Henneriche3f23002007-07-12 16:39:29 +0800932 pint2irq_lut[bit_pos] = irq_base - SYS_IRQS;
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800933 irq2pint_lut[irq_base - SYS_IRQS] = bit_pos;
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800934 }
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800935 }
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800936}
937
Thomas Gleixnere9502852011-02-06 18:23:36 +0000938static void bfin_gpio_ack_irq(struct irq_data *d)
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800939{
Thomas Gleixnere9502852011-02-06 18:23:36 +0000940 u32 pint_val = irq2pint_lut[d->irq - SYS_IRQS];
Michael Hennerich8baf5602007-12-24 18:51:34 +0800941 u32 pintbit = PINT_BIT(pint_val);
Michael Hennerich8d022372008-11-18 17:48:22 +0800942 u32 bank = PINT_2_BANK(pint_val);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800943
Thomas Gleixner1907d8b2011-03-24 17:21:01 +0100944 if (irqd_get_trigger_type(d) == IRQ_TYPE_EDGE_BOTH) {
Michael Hennerich8baf5602007-12-24 18:51:34 +0800945 if (pint[bank]->invert_set & pintbit)
946 pint[bank]->invert_clear = pintbit;
947 else
948 pint[bank]->invert_set = pintbit;
949 }
950 pint[bank]->request = pintbit;
951
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800952}
953
Thomas Gleixnere9502852011-02-06 18:23:36 +0000954static void bfin_gpio_mask_ack_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 Henneriche3f23002007-07-12 16:39:29 +0800957 u32 pintbit = PINT_BIT(pint_val);
Michael Hennerich8d022372008-11-18 17:48:22 +0800958 u32 bank = PINT_2_BANK(pint_val);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800959
Thomas Gleixner1907d8b2011-03-24 17:21:01 +0100960 if (irqd_get_trigger_type(d) == IRQ_TYPE_EDGE_BOTH) {
Michael Hennerich8baf5602007-12-24 18:51:34 +0800961 if (pint[bank]->invert_set & pintbit)
962 pint[bank]->invert_clear = pintbit;
963 else
964 pint[bank]->invert_set = pintbit;
965 }
966
Michael Henneriche3f23002007-07-12 16:39:29 +0800967 pint[bank]->request = pintbit;
968 pint[bank]->mask_clear = pintbit;
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800969}
970
Thomas Gleixnere9502852011-02-06 18:23:36 +0000971static void bfin_gpio_mask_irq(struct irq_data *d)
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800972{
Thomas Gleixnere9502852011-02-06 18:23:36 +0000973 u32 pint_val = irq2pint_lut[d->irq - SYS_IRQS];
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800974
975 pint[PINT_2_BANK(pint_val)]->mask_clear = PINT_BIT(pint_val);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800976}
977
Thomas Gleixnere9502852011-02-06 18:23:36 +0000978static void bfin_gpio_unmask_irq(struct irq_data *d)
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800979{
Thomas Gleixnere9502852011-02-06 18:23:36 +0000980 u32 pint_val = irq2pint_lut[d->irq - SYS_IRQS];
Michael Henneriche3f23002007-07-12 16:39:29 +0800981 u32 pintbit = PINT_BIT(pint_val);
Michael Hennerich8d022372008-11-18 17:48:22 +0800982 u32 bank = PINT_2_BANK(pint_val);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800983
Michael Henneriche3f23002007-07-12 16:39:29 +0800984 pint[bank]->mask_set = pintbit;
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800985}
986
Thomas Gleixnere9502852011-02-06 18:23:36 +0000987static unsigned int bfin_gpio_irq_startup(struct irq_data *d)
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800988{
Thomas Gleixnere9502852011-02-06 18:23:36 +0000989 unsigned int irq = d->irq;
Michael Hennerich8d022372008-11-18 17:48:22 +0800990 u32 gpionr = irq_to_gpio(irq);
991 u32 pint_val = irq2pint_lut[irq - SYS_IRQS];
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800992
Michael Hennerich50e163c2007-07-24 16:17:28 +0800993 if (pint_val == IRQ_NOT_AVAIL) {
994 printk(KERN_ERR
995 "GPIO IRQ %d :Not in PINT Assign table "
996 "Reconfigure Interrupt to Port Assignemt\n", irq);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800997 return -ENODEV;
Michael Hennerich50e163c2007-07-24 16:17:28 +0800998 }
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800999
Michael Hennerich8d022372008-11-18 17:48:22 +08001000 if (__test_and_set_bit(gpionr, gpio_enabled))
Michael Hennerichaffee2b2008-04-24 08:10:10 +08001001 bfin_gpio_irq_prepare(gpionr);
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001002
Thomas Gleixnere9502852011-02-06 18:23:36 +00001003 bfin_gpio_unmask_irq(d);
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001004
Michael Hennerichaffee2b2008-04-24 08:10:10 +08001005 return 0;
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001006}
1007
Thomas Gleixnere9502852011-02-06 18:23:36 +00001008static void bfin_gpio_irq_shutdown(struct irq_data *d)
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001009{
Thomas Gleixnere9502852011-02-06 18:23:36 +00001010 u32 gpionr = irq_to_gpio(d->irq);
Michael Hennerich8baf5602007-12-24 18:51:34 +08001011
Thomas Gleixnere9502852011-02-06 18:23:36 +00001012 bfin_gpio_mask_irq(d);
Michael Hennerich8d022372008-11-18 17:48:22 +08001013 __clear_bit(gpionr, gpio_enabled);
Graf Yang9570ff42009-01-07 23:14:38 +08001014 bfin_gpio_irq_free(gpionr);
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001015}
1016
Thomas Gleixnere9502852011-02-06 18:23:36 +00001017static int bfin_gpio_irq_type(struct irq_data *d, unsigned int type)
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001018{
Thomas Gleixnere9502852011-02-06 18:23:36 +00001019 unsigned int irq = d->irq;
Graf Yang8eb3e3b2008-11-18 17:48:22 +08001020 int ret;
1021 char buf[16];
Michael Hennerich8d022372008-11-18 17:48:22 +08001022 u32 gpionr = irq_to_gpio(irq);
1023 u32 pint_val = irq2pint_lut[irq - SYS_IRQS];
Michael Henneriche3f23002007-07-12 16:39:29 +08001024 u32 pintbit = PINT_BIT(pint_val);
Michael Hennerich8d022372008-11-18 17:48:22 +08001025 u32 bank = PINT_2_BANK(pint_val);
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001026
1027 if (pint_val == IRQ_NOT_AVAIL)
1028 return -ENODEV;
1029
1030 if (type == IRQ_TYPE_PROBE) {
1031 /* only probe unenabled GPIO interrupt lines */
Mike Frysingerc3695342009-06-13 10:32:29 -04001032 if (test_bit(gpionr, gpio_enabled))
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001033 return 0;
1034 type = IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING;
1035 }
1036
1037 if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING |
1038 IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW)) {
Graf Yang9570ff42009-01-07 23:14:38 +08001039
1040 snprintf(buf, 16, "gpio-irq%d", irq);
1041 ret = bfin_gpio_irq_request(gpionr, buf);
1042 if (ret)
1043 return ret;
1044
Michael Hennerich8d022372008-11-18 17:48:22 +08001045 if (__test_and_set_bit(gpionr, gpio_enabled))
Michael Hennerichaffee2b2008-04-24 08:10:10 +08001046 bfin_gpio_irq_prepare(gpionr);
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001047
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001048 } else {
Michael Hennerich8d022372008-11-18 17:48:22 +08001049 __clear_bit(gpionr, gpio_enabled);
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001050 return 0;
1051 }
1052
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001053 if ((type & (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_LEVEL_LOW)))
Michael Henneriche3f23002007-07-12 16:39:29 +08001054 pint[bank]->invert_set = pintbit; /* low or falling edge denoted by one */
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001055 else
Michael Hennerich8baf5602007-12-24 18:51:34 +08001056 pint[bank]->invert_clear = pintbit; /* high or rising edge denoted by zero */
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001057
Michael Hennerich8baf5602007-12-24 18:51:34 +08001058 if ((type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING))
1059 == (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING)) {
Michael Hennerich8baf5602007-12-24 18:51:34 +08001060 if (gpio_get_value(gpionr))
1061 pint[bank]->invert_set = pintbit;
1062 else
1063 pint[bank]->invert_clear = pintbit;
Michael Hennerich8baf5602007-12-24 18:51:34 +08001064 }
1065
1066 if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING)) {
1067 pint[bank]->edge_set = pintbit;
Graf Yangbfd15112008-10-08 18:02:44 +08001068 bfin_set_irq_handler(irq, handle_edge_irq);
Michael Hennerich8baf5602007-12-24 18:51:34 +08001069 } else {
1070 pint[bank]->edge_clear = pintbit;
Graf Yangbfd15112008-10-08 18:02:44 +08001071 bfin_set_irq_handler(irq, handle_level_irq);
Michael Hennerich8baf5602007-12-24 18:51:34 +08001072 }
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001073
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001074 return 0;
1075}
1076
Michael Hennerichcfefe3c2008-02-09 04:12:37 +08001077#ifdef CONFIG_PM
Steven Miaod49cdf8402012-06-14 18:04:01 +08001078static struct bfin_pm_pint_save save_pint_reg[NR_PINT_SYS_IRQS];
1079static u32 save_pint_sec_ctl[NR_PINT_SYS_IRQS];
1080
Mike Frysingerdd8cb372011-04-15 03:19:22 -04001081static int bfin_gpio_set_wake(struct irq_data *d, unsigned int state)
Michael Hennerichcfefe3c2008-02-09 04:12:37 +08001082{
1083 u32 pint_irq;
Thomas Gleixnere9502852011-02-06 18:23:36 +00001084 u32 pint_val = irq2pint_lut[d->irq - SYS_IRQS];
Michael Hennerichcfefe3c2008-02-09 04:12:37 +08001085 u32 bank = PINT_2_BANK(pint_val);
Michael Hennerichcfefe3c2008-02-09 04:12:37 +08001086
1087 switch (bank) {
1088 case 0:
1089 pint_irq = IRQ_PINT0;
1090 break;
1091 case 2:
1092 pint_irq = IRQ_PINT2;
1093 break;
1094 case 3:
1095 pint_irq = IRQ_PINT3;
1096 break;
1097 case 1:
1098 pint_irq = IRQ_PINT1;
1099 break;
Bob Liu494b7942012-04-27 14:13:01 +08001100#ifdef CONFIG_BF60x
Steven Miao4f6b6002012-05-16 17:56:51 +08001101 case 4:
1102 pint_irq = IRQ_PINT4;
1103 break;
1104 case 5:
1105 pint_irq = IRQ_PINT5;
1106 break;
Bob Liu494b7942012-04-27 14:13:01 +08001107#endif
Michael Hennerichcfefe3c2008-02-09 04:12:37 +08001108 default:
1109 return -EINVAL;
1110 }
1111
1112 bfin_internal_set_wake(pint_irq, state);
1113
Michael Hennerichcfefe3c2008-02-09 04:12:37 +08001114 return 0;
1115}
Steven Miaod49cdf8402012-06-14 18:04:01 +08001116
1117void bfin_pint_suspend(void)
1118{
1119 u32 bank;
1120
1121 for (bank = 0; bank < NR_PINT_SYS_IRQS; bank++) {
1122 save_pint_reg[bank].mask_set = pint[bank]->mask_set;
1123 save_pint_reg[bank].assign = pint[bank]->assign;
1124 save_pint_reg[bank].edge_set = pint[bank]->edge_set;
1125 save_pint_reg[bank].invert_set = pint[bank]->invert_set;
1126 }
1127}
1128
1129void bfin_pint_resume(void)
1130{
1131 u32 bank;
1132
1133 for (bank = 0; bank < NR_PINT_SYS_IRQS; bank++) {
1134 pint[bank]->mask_set = save_pint_reg[bank].mask_set;
1135 pint[bank]->assign = save_pint_reg[bank].assign;
1136 pint[bank]->edge_set = save_pint_reg[bank].edge_set;
1137 pint[bank]->invert_set = save_pint_reg[bank].invert_set;
1138 }
1139}
1140
Sonic Zhang11b27cb2012-06-28 19:16:48 +08001141#ifdef SEC_GCTL
Steven Miaod49cdf8402012-06-14 18:04:01 +08001142static int sec_suspend(void)
1143{
1144 u32 bank;
1145
1146 for (bank = 0; bank < NR_PINT_SYS_IRQS; bank++)
1147 save_pint_sec_ctl[bank] = bfin_read_SEC_SCTL(bank + SIC_SYSIRQ(IRQ_PINT0));
1148 return 0;
1149}
1150
1151static void sec_resume(void)
1152{
1153 u32 bank;
1154
1155 bfin_write_SEC_SCI(0, SEC_CCTL, SEC_CCTL_RESET);
1156 udelay(100);
1157 bfin_write_SEC_GCTL(SEC_GCTL_EN);
1158 bfin_write_SEC_SCI(0, SEC_CCTL, SEC_CCTL_EN | SEC_CCTL_NMI_EN);
1159
1160 for (bank = 0; bank < NR_PINT_SYS_IRQS; bank++)
1161 bfin_write_SEC_SCTL(bank + SIC_SYSIRQ(IRQ_PINT0), save_pint_sec_ctl[bank]);
1162}
1163
1164static struct syscore_ops sec_pm_syscore_ops = {
1165 .suspend = sec_suspend,
1166 .resume = sec_resume,
1167};
Steven Miao3375a432012-06-15 12:59:19 +08001168#endif
Mike Frysingerfc6bd7b2011-04-15 01:35:53 -04001169#else
1170# define bfin_gpio_set_wake NULL
Michael Hennerichcfefe3c2008-02-09 04:12:37 +08001171#endif
1172
Mike Frysinger8c054102011-04-15 13:04:59 -04001173void bfin_demux_gpio_irq(unsigned int inta_irq,
Steven Miao4f6b6002012-05-16 17:56:51 +08001174 struct irq_desc *desc)
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001175{
Michael Hennerich8d022372008-11-18 17:48:22 +08001176 u32 bank, pint_val;
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001177 u32 request, irq;
Steven Miao4f6b6002012-05-16 17:56:51 +08001178 u32 level_mask;
1179 int umask = 0;
1180 struct irq_chip *chip = irq_desc_get_chip(desc);
1181
1182 if (chip->irq_mask_ack) {
1183 chip->irq_mask_ack(&desc->irq_data);
1184 } else {
1185 chip->irq_mask(&desc->irq_data);
1186 if (chip->irq_ack)
1187 chip->irq_ack(&desc->irq_data);
1188 }
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001189
Michael Hennerich2c4f8292008-02-09 04:11:14 +08001190 switch (inta_irq) {
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001191 case IRQ_PINT0:
1192 bank = 0;
1193 break;
1194 case IRQ_PINT2:
1195 bank = 2;
1196 break;
1197 case IRQ_PINT3:
1198 bank = 3;
1199 break;
1200 case IRQ_PINT1:
1201 bank = 1;
1202 break;
Steven Miao4f6b6002012-05-16 17:56:51 +08001203#ifdef CONFIG_BF60x
1204 case IRQ_PINT4:
1205 bank = 4;
1206 break;
1207 case IRQ_PINT5:
1208 bank = 5;
1209 break;
1210#endif
Michael Henneriche3f23002007-07-12 16:39:29 +08001211 default:
1212 return;
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001213 }
1214
1215 pint_val = bank * NR_PINT_BITS;
1216
1217 request = pint[bank]->request;
1218
Steven Miao4f6b6002012-05-16 17:56:51 +08001219 level_mask = pint[bank]->edge_set & request;
1220
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001221 while (request) {
1222 if (request & 1) {
Michael Henneriche3f23002007-07-12 16:39:29 +08001223 irq = pint2irq_lut[pint_val] + SYS_IRQS;
Steven Miao4f6b6002012-05-16 17:56:51 +08001224 if (level_mask & PINT_BIT(pint_val)) {
1225 umask = 1;
1226 chip->irq_unmask(&desc->irq_data);
1227 }
Yi Li6a01f232009-01-07 23:14:39 +08001228 bfin_handle_irq(irq);
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001229 }
1230 pint_val++;
1231 request >>= 1;
1232 }
1233
Steven Miao4f6b6002012-05-16 17:56:51 +08001234 if (!umask)
1235 chip->irq_unmask(&desc->irq_data);
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001236}
Mike Frysingera055b2b2007-11-15 21:12:32 +08001237#endif
Bryan Wu1394f032007-05-06 14:50:22 -07001238
Michael Hennerich8d022372008-11-18 17:48:22 +08001239static struct irq_chip bfin_gpio_irqchip = {
1240 .name = "GPIO",
Thomas Gleixnere9502852011-02-06 18:23:36 +00001241 .irq_ack = bfin_gpio_ack_irq,
1242 .irq_mask = bfin_gpio_mask_irq,
1243 .irq_mask_ack = bfin_gpio_mask_ack_irq,
1244 .irq_unmask = bfin_gpio_unmask_irq,
1245 .irq_disable = bfin_gpio_mask_irq,
1246 .irq_enable = bfin_gpio_unmask_irq,
1247 .irq_set_type = bfin_gpio_irq_type,
1248 .irq_startup = bfin_gpio_irq_startup,
1249 .irq_shutdown = bfin_gpio_irq_shutdown,
Thomas Gleixnere9502852011-02-06 18:23:36 +00001250 .irq_set_wake = bfin_gpio_set_wake,
Michael Hennerich8d022372008-11-18 17:48:22 +08001251};
1252
Graf Yang6b3087c2009-01-07 23:14:39 +08001253void __cpuinit init_exception_vectors(void)
Bernd Schmidt8be80ed2007-07-25 14:44:49 +08001254{
Mike Frysingerf0b5d122007-08-05 17:03:59 +08001255 /* cannot program in software:
1256 * evt0 - emulation (jtag)
1257 * evt1 - reset
1258 */
1259 bfin_write_EVT2(evt_nmi);
Bernd Schmidt8be80ed2007-07-25 14:44:49 +08001260 bfin_write_EVT3(trap);
1261 bfin_write_EVT5(evt_ivhw);
1262 bfin_write_EVT6(evt_timer);
1263 bfin_write_EVT7(evt_evt7);
1264 bfin_write_EVT8(evt_evt8);
1265 bfin_write_EVT9(evt_evt9);
1266 bfin_write_EVT10(evt_evt10);
1267 bfin_write_EVT11(evt_evt11);
1268 bfin_write_EVT12(evt_evt12);
1269 bfin_write_EVT13(evt_evt13);
Philippe Gerum9703a732009-06-22 18:23:48 +02001270 bfin_write_EVT14(evt_evt14);
Bernd Schmidt8be80ed2007-07-25 14:44:49 +08001271 bfin_write_EVT15(evt_system_call);
1272 CSYNC();
1273}
1274
Sonic Zhang11b27cb2012-06-28 19:16:48 +08001275#ifndef SEC_GCTL
Bryan Wu1394f032007-05-06 14:50:22 -07001276/*
1277 * This function should be called during kernel startup to initialize
1278 * the BFin IRQ handling routines.
1279 */
Michael Hennerich8d022372008-11-18 17:48:22 +08001280
Bryan Wu1394f032007-05-06 14:50:22 -07001281int __init init_arch_irq(void)
1282{
1283 int irq;
1284 unsigned long ilat = 0;
Mike Frysingerfc6bd7b2011-04-15 01:35:53 -04001285
Bryan Wu1394f032007-05-06 14:50:22 -07001286 /* Disable all the peripheral intrs - page 4-29 HW Ref manual */
Mike Frysingerfc6bd7b2011-04-15 01:35:53 -04001287#ifdef SIC_IMASK0
Roy Huang24a07a12007-07-12 22:41:45 +08001288 bfin_write_SIC_IMASK0(SIC_UNMASK_ALL);
1289 bfin_write_SIC_IMASK1(SIC_UNMASK_ALL);
Mike Frysingerfc6bd7b2011-04-15 01:35:53 -04001290# ifdef SIC_IMASK2
Michael Hennerich59003142007-10-21 16:54:27 +08001291 bfin_write_SIC_IMASK2(SIC_UNMASK_ALL);
Mike Frysingera055b2b2007-11-15 21:12:32 +08001292# endif
Steven Miao4f6b6002012-05-16 17:56:51 +08001293# if defined(CONFIG_SMP) || defined(CONFIG_ICC)
Graf Yang6b3087c2009-01-07 23:14:39 +08001294 bfin_write_SICB_IMASK0(SIC_UNMASK_ALL);
1295 bfin_write_SICB_IMASK1(SIC_UNMASK_ALL);
1296# endif
Roy Huang24a07a12007-07-12 22:41:45 +08001297#else
Bryan Wu1394f032007-05-06 14:50:22 -07001298 bfin_write_SIC_IMASK(SIC_UNMASK_ALL);
Roy Huang24a07a12007-07-12 22:41:45 +08001299#endif
Bryan Wu1394f032007-05-06 14:50:22 -07001300
1301 local_irq_disable();
1302
Mike Frysinger01f8e342011-06-26 13:56:23 -04001303#if BFIN_GPIO_PINT
Mike Frysingera055b2b2007-11-15 21:12:32 +08001304# ifdef CONFIG_PINTx_REASSIGN
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001305 pint[0]->assign = CONFIG_PINT0_ASSIGN;
1306 pint[1]->assign = CONFIG_PINT1_ASSIGN;
1307 pint[2]->assign = CONFIG_PINT2_ASSIGN;
1308 pint[3]->assign = CONFIG_PINT3_ASSIGN;
Mike Frysingera055b2b2007-11-15 21:12:32 +08001309# endif
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001310 /* Whenever PINTx_ASSIGN is altered init_pint_lut() must be executed! */
1311 init_pint_lut();
1312#endif
1313
1314 for (irq = 0; irq <= SYS_IRQS; irq++) {
Bryan Wu1394f032007-05-06 14:50:22 -07001315 if (irq <= IRQ_CORETMR)
Thomas Gleixner43f2f112011-03-24 17:22:30 +01001316 irq_set_chip(irq, &bfin_core_irqchip);
Bryan Wu1394f032007-05-06 14:50:22 -07001317 else
Thomas Gleixner43f2f112011-03-24 17:22:30 +01001318 irq_set_chip(irq, &bfin_internal_irqchip);
Bryan Wu1394f032007-05-06 14:50:22 -07001319
Michael Hennerich464abc52008-02-25 13:50:20 +08001320 switch (irq) {
Mike Frysinger01f8e342011-06-26 13:56:23 -04001321#if BFIN_GPIO_PINT
Michael Hennerich464abc52008-02-25 13:50:20 +08001322 case IRQ_PINT0:
1323 case IRQ_PINT1:
1324 case IRQ_PINT2:
1325 case IRQ_PINT3:
Mike Frysinger01f8e342011-06-26 13:56:23 -04001326#elif defined(BF537_FAMILY)
1327 case IRQ_PH_INTA_MAC_RX:
1328 case IRQ_PF_INTA_PG_INTA:
1329#elif defined(BF533_FAMILY)
1330 case IRQ_PROG_INTA:
Bryan Wu2f6f4bc2008-11-18 17:48:21 +08001331#elif defined(CONFIG_BF52x) || defined(CONFIG_BF51x)
Michael Hennerich464abc52008-02-25 13:50:20 +08001332 case IRQ_PORTF_INTA:
1333 case IRQ_PORTG_INTA:
1334 case IRQ_PORTH_INTA:
Michael Hennerich2c4f8292008-02-09 04:11:14 +08001335#elif defined(CONFIG_BF561)
Michael Hennerich464abc52008-02-25 13:50:20 +08001336 case IRQ_PROG0_INTA:
1337 case IRQ_PROG1_INTA:
1338 case IRQ_PROG2_INTA:
Mike Frysingerfc6bd7b2011-04-15 01:35:53 -04001339#elif defined(BF538_FAMILY)
Michael Hennerichdc26aec2008-11-18 17:48:22 +08001340 case IRQ_PORTF_INTA:
Michael Hennerich59003142007-10-21 16:54:27 +08001341#endif
Thomas Gleixner43f2f112011-03-24 17:22:30 +01001342 irq_set_chained_handler(irq, bfin_demux_gpio_irq);
Michael Hennerich464abc52008-02-25 13:50:20 +08001343 break;
Michael Hennerichaec59c92010-02-19 15:09:10 +00001344#if defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE)
1345 case IRQ_MAC_ERROR:
Thomas Gleixner43f2f112011-03-24 17:22:30 +01001346 irq_set_chained_handler(irq,
1347 bfin_demux_mac_status_irq);
Michael Hennerichaec59c92010-02-19 15:09:10 +00001348 break;
1349#endif
Steven Miao4f6b6002012-05-16 17:56:51 +08001350#if defined(CONFIG_SMP) || defined(CONFIG_ICC)
Graf Yang6b3087c2009-01-07 23:14:39 +08001351 case IRQ_SUPPLE_0:
1352 case IRQ_SUPPLE_1:
Thomas Gleixner43f2f112011-03-24 17:22:30 +01001353 irq_set_handler(irq, handle_percpu_irq);
Graf Yang6b3087c2009-01-07 23:14:39 +08001354 break;
1355#endif
Graf Yang179413142009-08-18 04:29:33 +00001356
Yi Licb191712009-12-30 07:12:50 +00001357#ifdef CONFIG_TICKSOURCE_CORETMR
1358 case IRQ_CORETMR:
1359# ifdef CONFIG_SMP
Thomas Gleixner43f2f112011-03-24 17:22:30 +01001360 irq_set_handler(irq, handle_percpu_irq);
Yi Licb191712009-12-30 07:12:50 +00001361# else
Thomas Gleixner43f2f112011-03-24 17:22:30 +01001362 irq_set_handler(irq, handle_simple_irq);
Yi Licb191712009-12-30 07:12:50 +00001363# endif
Mike Frysingerfc6bd7b2011-04-15 01:35:53 -04001364 break;
Yi Licb191712009-12-30 07:12:50 +00001365#endif
1366
1367#ifdef CONFIG_TICKSOURCE_GPTMR0
Philippe Geruma40494a2009-06-16 05:25:42 +02001368 case IRQ_TIMER0:
Thomas Gleixner43f2f112011-03-24 17:22:30 +01001369 irq_set_handler(irq, handle_simple_irq);
Michael Hennerich464abc52008-02-25 13:50:20 +08001370 break;
Graf Yang179413142009-08-18 04:29:33 +00001371#endif
Yi Licb191712009-12-30 07:12:50 +00001372
Mike Frysingerfc6bd7b2011-04-15 01:35:53 -04001373 default:
Yi Licb191712009-12-30 07:12:50 +00001374#ifdef CONFIG_IPIPE
Thomas Gleixner43f2f112011-03-24 17:22:30 +01001375 irq_set_handler(irq, handle_level_irq);
Mike Frysingerfc6bd7b2011-04-15 01:35:53 -04001376#else
Thomas Gleixner43f2f112011-03-24 17:22:30 +01001377 irq_set_handler(irq, handle_simple_irq);
Mike Frysingerfc6bd7b2011-04-15 01:35:53 -04001378#endif
Philippe Geruma40494a2009-06-16 05:25:42 +02001379 break;
Bryan Wu1394f032007-05-06 14:50:22 -07001380 }
Bryan Wu1394f032007-05-06 14:50:22 -07001381 }
Michael Hennerich464abc52008-02-25 13:50:20 +08001382
Mike Frysingerf58c3272011-04-15 03:08:20 -04001383 init_mach_irq();
Bryan Wu1394f032007-05-06 14:50:22 -07001384
Sonic Zhang11b27cb2012-06-28 19:16:48 +08001385#if (defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE))
Michael Hennerichaec59c92010-02-19 15:09:10 +00001386 for (irq = IRQ_MAC_PHYINT; irq <= IRQ_MAC_STMDONE; irq++)
Thomas Gleixner43f2f112011-03-24 17:22:30 +01001387 irq_set_chip_and_handler(irq, &bfin_mac_status_irqchip,
Michael Hennerichaec59c92010-02-19 15:09:10 +00001388 handle_level_irq);
1389#endif
Michael Hennerich464abc52008-02-25 13:50:20 +08001390 /* if configured as edge, then will be changed to do_edge_IRQ */
Michael Hennerichaec59c92010-02-19 15:09:10 +00001391 for (irq = GPIO_IRQ_BASE;
1392 irq < (GPIO_IRQ_BASE + MAX_BLACKFIN_GPIOS); irq++)
Thomas Gleixner43f2f112011-03-24 17:22:30 +01001393 irq_set_chip_and_handler(irq, &bfin_gpio_irqchip,
Michael Hennerich464abc52008-02-25 13:50:20 +08001394 handle_level_irq);
Bryan Wu1394f032007-05-06 14:50:22 -07001395 bfin_write_IMASK(0);
1396 CSYNC();
1397 ilat = bfin_read_ILAT();
1398 CSYNC();
1399 bfin_write_ILAT(ilat);
1400 CSYNC();
1401
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001402 printk(KERN_INFO "Configuring Blackfin Priority Driven Interrupts\n");
Mike Frysinger40059782008-11-18 17:48:22 +08001403 /* IMASK=xxx is equivalent to STI xx or bfin_irq_flags=xx,
Bryan Wu1394f032007-05-06 14:50:22 -07001404 * local_irq_enable()
1405 */
1406 program_IAR();
1407 /* Therefore it's better to setup IARs before interrupts enabled */
1408 search_IAR();
1409
1410 /* Enable interrupts IVG7-15 */
Mike Frysinger40059782008-11-18 17:48:22 +08001411 bfin_irq_flags |= IMASK_IVG15 |
Steven Miao4f6b6002012-05-16 17:56:51 +08001412 IMASK_IVG14 | IMASK_IVG13 | IMASK_IVG12 | IMASK_IVG11 |
1413 IMASK_IVG10 | IMASK_IVG9 | IMASK_IVG8 | IMASK_IVG7 | IMASK_IVGHW;
1414
1415 bfin_sti(bfin_irq_flags);
Bryan Wu1394f032007-05-06 14:50:22 -07001416
Michael Hennerich349ebbc2009-04-15 08:48:08 +00001417 /* This implicitly covers ANOMALY_05000171
1418 * Boot-ROM code modifies SICA_IWRx wakeup registers
1419 */
Mike Frysingerbe1d8542009-02-04 16:49:45 +08001420#ifdef SIC_IWR0
Michael Hennerich56f5f592008-08-06 17:55:32 +08001421 bfin_write_SIC_IWR0(IWR_DISABLE_ALL);
Mike Frysingerbe1d8542009-02-04 16:49:45 +08001422# ifdef SIC_IWR1
Bryan Wu2f6f4bc2008-11-18 17:48:21 +08001423 /* BF52x/BF51x system reset does not properly reset SIC_IWR1 which
Michael Hennerich55546ac2008-08-13 17:41:13 +08001424 * will screw up the bootrom as it relies on MDMA0/1 waking it
1425 * up from IDLE instructions. See this report for more info:
1426 * http://blackfin.uclinux.org/gf/tracker/4323
1427 */
Mike Frysingerb7e11292008-11-18 17:48:22 +08001428 if (ANOMALY_05000435)
1429 bfin_write_SIC_IWR1(IWR_ENABLE(10) | IWR_ENABLE(11));
1430 else
1431 bfin_write_SIC_IWR1(IWR_DISABLE_ALL);
Mike Frysingerbe1d8542009-02-04 16:49:45 +08001432# endif
1433# ifdef SIC_IWR2
Michael Hennerich56f5f592008-08-06 17:55:32 +08001434 bfin_write_SIC_IWR2(IWR_DISABLE_ALL);
Michael Hennerichfe9ec9b2008-02-25 12:04:57 +08001435# endif
1436#else
Michael Hennerich56f5f592008-08-06 17:55:32 +08001437 bfin_write_SIC_IWR(IWR_DISABLE_ALL);
Michael Hennerichfe9ec9b2008-02-25 12:04:57 +08001438#endif
Bryan Wu1394f032007-05-06 14:50:22 -07001439 return 0;
1440}
1441
1442#ifdef CONFIG_DO_IRQ_L1
Mike Frysingera055b2b2007-11-15 21:12:32 +08001443__attribute__((l1_text))
Bryan Wu1394f032007-05-06 14:50:22 -07001444#endif
Mike Frysinger6b108042011-03-30 01:35:41 -04001445static int vec_to_irq(int vec)
1446{
1447 struct ivgx *ivg = ivg7_13[vec - IVG7].ifirst;
1448 struct ivgx *ivg_stop = ivg7_13[vec - IVG7].istop;
1449 unsigned long sic_status[3];
Mike Frysinger6b108042011-03-30 01:35:41 -04001450 if (likely(vec == EVT_IVTMR_P))
1451 return IRQ_CORETMR;
Mike Frysinger6b108042011-03-30 01:35:41 -04001452#ifdef SIC_ISR
1453 sic_status[0] = bfin_read_SIC_IMASK() & bfin_read_SIC_ISR();
1454#else
1455 if (smp_processor_id()) {
1456# ifdef SICB_ISR0
1457 /* This will be optimized out in UP mode. */
1458 sic_status[0] = bfin_read_SICB_ISR0() & bfin_read_SICB_IMASK0();
1459 sic_status[1] = bfin_read_SICB_ISR1() & bfin_read_SICB_IMASK1();
1460# endif
1461 } else {
1462 sic_status[0] = bfin_read_SIC_ISR0() & bfin_read_SIC_IMASK0();
1463 sic_status[1] = bfin_read_SIC_ISR1() & bfin_read_SIC_IMASK1();
1464 }
1465#endif
1466#ifdef SIC_ISR2
1467 sic_status[2] = bfin_read_SIC_ISR2() & bfin_read_SIC_IMASK2();
1468#endif
1469
1470 for (;; ivg++) {
1471 if (ivg >= ivg_stop)
1472 return -1;
1473#ifdef SIC_ISR
1474 if (sic_status[0] & ivg->isrflag)
1475#else
1476 if (sic_status[(ivg->irqno - IVG7) / 32] & ivg->isrflag)
1477#endif
1478 return ivg->irqno;
1479 }
1480}
1481
Sonic Zhang11b27cb2012-06-28 19:16:48 +08001482#else /* SEC_GCTL */
1483
1484/*
1485 * This function should be called during kernel startup to initialize
1486 * the BFin IRQ handling routines.
1487 */
1488
1489int __init init_arch_irq(void)
1490{
1491 int irq;
1492 unsigned long ilat = 0;
1493
1494 bfin_write_SEC_GCTL(SEC_GCTL_RESET);
1495
1496 local_irq_disable();
1497
1498#if BFIN_GPIO_PINT
1499# ifdef CONFIG_PINTx_REASSIGN
1500 pint[0]->assign = CONFIG_PINT0_ASSIGN;
1501 pint[1]->assign = CONFIG_PINT1_ASSIGN;
1502 pint[2]->assign = CONFIG_PINT2_ASSIGN;
1503 pint[3]->assign = CONFIG_PINT3_ASSIGN;
1504 pint[4]->assign = CONFIG_PINT4_ASSIGN;
1505 pint[5]->assign = CONFIG_PINT5_ASSIGN;
1506# endif
1507 /* Whenever PINTx_ASSIGN is altered init_pint_lut() must be executed! */
1508 init_pint_lut();
1509#endif
1510
1511 for (irq = 0; irq <= SYS_IRQS; irq++) {
1512 if (irq <= IRQ_CORETMR) {
1513 irq_set_chip(irq, &bfin_core_irqchip);
1514#ifdef CONFIG_TICKSOURCE_CORETMR
1515 if (irq == IRQ_CORETMR)
1516# ifdef CONFIG_SMP
1517 irq_set_handler(irq, handle_percpu_irq);
1518# else
1519 irq_set_handler(irq, handle_simple_irq);
1520# endif
1521#endif
1522 } else if (irq < BFIN_IRQ(0)) {
1523 irq_set_chip_and_handler(irq, &bfin_internal_irqchip,
1524 handle_simple_irq);
1525 } else if (irq < CORE_IRQS && irq != IRQ_CGU_EVT) {
1526 irq_set_chip_and_handler(irq, &bfin_sec_irqchip,
1527 handle_sec_fault);
1528 } else if (irq >= BFIN_IRQ(21) && irq <= BFIN_IRQ(26)) {
1529 irq_set_chip(irq, &bfin_sec_irqchip);
1530 irq_set_chained_handler(irq, bfin_demux_gpio_irq);
1531 } else if (irq >= BFIN_IRQ(34) && irq <= BFIN_IRQ(37)) {
1532 irq_set_chip(irq, &bfin_sec_irqchip);
1533 irq_set_handler(irq, handle_percpu_irq);
1534 } else {
1535 irq_set_chip_and_handler(irq, &bfin_sec_irqchip,
1536 handle_fasteoi_irq);
1537 __irq_set_preflow_handler(irq, bfin_sec_preflow_handler);
1538 }
1539 }
1540 for (irq = GPIO_IRQ_BASE;
1541 irq < (GPIO_IRQ_BASE + MAX_BLACKFIN_GPIOS); irq++)
1542 irq_set_chip_and_handler(irq, &bfin_gpio_irqchip,
1543 handle_level_irq);
1544
1545 bfin_write_IMASK(0);
1546 CSYNC();
1547 ilat = bfin_read_ILAT();
1548 CSYNC();
1549 bfin_write_ILAT(ilat);
1550 CSYNC();
1551
1552 printk(KERN_INFO "Configuring Blackfin Priority Driven Interrupts\n");
1553
Sonic Zhange0a59312012-06-29 18:19:29 +08001554 bfin_sec_set_priority(CONFIG_SEC_IRQ_PRIORITY_LEVELS, sec_int_priority);
1555
1556 bfin_sec_set_priority(CONFIG_SEC_IRQ_PRIORITY_LEVELS, sec_int_priority);
1557
Sonic Zhang11b27cb2012-06-28 19:16:48 +08001558 /* Enable interrupts IVG7-15 */
1559 bfin_irq_flags |= IMASK_IVG15 |
1560 IMASK_IVG14 | IMASK_IVG13 | IMASK_IVG12 | IMASK_IVG11 |
1561 IMASK_IVG10 | IMASK_IVG9 | IMASK_IVG8 | IMASK_IVG7 | IMASK_IVGHW;
1562
1563
1564 bfin_write_SEC_FCTL(SEC_FCTL_EN | SEC_FCTL_SYSRST_EN | SEC_FCTL_FLTIN_EN);
1565 bfin_sec_enable_sci(SIC_SYSIRQ(IRQ_WATCH0));
1566 bfin_sec_enable_ssi(SIC_SYSIRQ(IRQ_WATCH0));
1567 bfin_write_SEC_SCI(0, SEC_CCTL, SEC_CCTL_RESET);
1568 udelay(100);
1569 bfin_write_SEC_GCTL(SEC_GCTL_EN);
1570 bfin_write_SEC_SCI(0, SEC_CCTL, SEC_CCTL_EN | SEC_CCTL_NMI_EN);
1571 bfin_write_SEC_SCI(1, SEC_CCTL, SEC_CCTL_EN | SEC_CCTL_NMI_EN);
1572
1573 init_software_driven_irq();
1574 register_syscore_ops(&sec_pm_syscore_ops);
1575
1576 return 0;
1577}
1578
1579#ifdef CONFIG_DO_IRQ_L1
1580__attribute__((l1_text))
1581#endif
1582static int vec_to_irq(int vec)
1583{
1584 if (likely(vec == EVT_IVTMR_P))
1585 return IRQ_CORETMR;
1586
1587 return BFIN_IRQ(bfin_read_SEC_SCI(0, SEC_CSID));
1588}
1589#endif /* SEC_GCTL */
1590
Mike Frysinger6b108042011-03-30 01:35:41 -04001591#ifdef CONFIG_DO_IRQ_L1
1592__attribute__((l1_text))
1593#endif
Bryan Wu1394f032007-05-06 14:50:22 -07001594void do_irq(int vec, struct pt_regs *fp)
1595{
Mike Frysinger6b108042011-03-30 01:35:41 -04001596 int irq = vec_to_irq(vec);
1597 if (irq == -1)
1598 return;
1599 asm_do_IRQ(irq, fp);
Bryan Wu1394f032007-05-06 14:50:22 -07001600}
Yi Li6a01f232009-01-07 23:14:39 +08001601
1602#ifdef CONFIG_IPIPE
1603
1604int __ipipe_get_irq_priority(unsigned irq)
1605{
1606 int ient, prio;
1607
1608 if (irq <= IRQ_CORETMR)
1609 return irq;
1610
Sonic Zhang11b27cb2012-06-28 19:16:48 +08001611#ifdef SEC_GCTL
1612 if (irq >= BFIN_IRQ(0))
1613 return IVG11;
1614#else
Yi Li6a01f232009-01-07 23:14:39 +08001615 for (ient = 0; ient < NR_PERI_INTS; ient++) {
1616 struct ivgx *ivg = ivg_table + ient;
1617 if (ivg->irqno == irq) {
1618 for (prio = 0; prio <= IVG13-IVG7; prio++) {
1619 if (ivg7_13[prio].ifirst <= ivg &&
1620 ivg7_13[prio].istop > ivg)
1621 return IVG7 + prio;
1622 }
1623 }
1624 }
Sonic Zhang11b27cb2012-06-28 19:16:48 +08001625#endif
Yi Li6a01f232009-01-07 23:14:39 +08001626
1627 return IVG15;
1628}
1629
Yi Li6a01f232009-01-07 23:14:39 +08001630/* Hw interrupts are disabled on entry (check SAVE_CONTEXT). */
1631#ifdef CONFIG_DO_IRQ_L1
1632__attribute__((l1_text))
1633#endif
1634asmlinkage int __ipipe_grab_irq(int vec, struct pt_regs *regs)
1635{
Philippe Gerum9bd50df2009-03-04 16:52:38 +08001636 struct ipipe_percpu_domain_data *p = ipipe_root_cpudom_ptr();
Philippe Geruma40494a2009-06-16 05:25:42 +02001637 struct ipipe_domain *this_domain = __ipipe_current_domain;
Philippe Gerum5b5da4c2011-03-17 02:12:48 -04001638 int irq, s = 0;
Yi Li6a01f232009-01-07 23:14:39 +08001639
Mike Frysinger6b108042011-03-30 01:35:41 -04001640 irq = vec_to_irq(vec);
1641 if (irq == -1)
1642 return 0;
Yi Li6a01f232009-01-07 23:14:39 +08001643
1644 if (irq == IRQ_SYSTMR) {
Philippe Geruma40494a2009-06-16 05:25:42 +02001645#if !defined(CONFIG_GENERIC_CLOCKEVENTS) || defined(CONFIG_TICKSOURCE_GPTMR0)
Yi Li6a01f232009-01-07 23:14:39 +08001646 bfin_write_TIMER_STATUS(1); /* Latch TIMIL0 */
Philippe Gerum9bd50df2009-03-04 16:52:38 +08001647#endif
Yi Li6a01f232009-01-07 23:14:39 +08001648 /* This is basically what we need from the register frame. */
1649 __raw_get_cpu_var(__ipipe_tick_regs).ipend = regs->ipend;
1650 __raw_get_cpu_var(__ipipe_tick_regs).pc = regs->pc;
Philippe Gerum9bd50df2009-03-04 16:52:38 +08001651 if (this_domain != ipipe_root_domain)
Yi Li6a01f232009-01-07 23:14:39 +08001652 __raw_get_cpu_var(__ipipe_tick_regs).ipend &= ~0x10;
Philippe Gerum9bd50df2009-03-04 16:52:38 +08001653 else
1654 __raw_get_cpu_var(__ipipe_tick_regs).ipend |= 0x10;
Yi Li6a01f232009-01-07 23:14:39 +08001655 }
1656
Philippe Gerum5b5da4c2011-03-17 02:12:48 -04001657 /*
1658 * We don't want Linux interrupt handlers to run at the
1659 * current core priority level (i.e. < EVT15), since this
1660 * might delay other interrupts handled by a high priority
1661 * domain. Here is what we do instead:
1662 *
1663 * - we raise the SYNCDEFER bit to prevent
1664 * __ipipe_handle_irq() to sync the pipeline for the root
1665 * stage for the incoming interrupt. Upon return, that IRQ is
1666 * pending in the interrupt log.
1667 *
1668 * - we raise the TIF_IRQ_SYNC bit for the current thread, so
1669 * that _schedule_and_signal_from_int will eventually sync the
1670 * pipeline from EVT15.
1671 */
Philippe Gerum9bd50df2009-03-04 16:52:38 +08001672 if (this_domain == ipipe_root_domain) {
1673 s = __test_and_set_bit(IPIPE_SYNCDEFER_FLAG, &p->status);
1674 barrier();
1675 }
Yi Li6a01f232009-01-07 23:14:39 +08001676
1677 ipipe_trace_irq_entry(irq);
1678 __ipipe_handle_irq(irq, regs);
Philippe Gerum9bd50df2009-03-04 16:52:38 +08001679 ipipe_trace_irq_exit(irq);
Yi Li6a01f232009-01-07 23:14:39 +08001680
Philippe Gerum5b5da4c2011-03-17 02:12:48 -04001681 if (user_mode(regs) &&
1682 !ipipe_test_foreign_stack() &&
1683 (current->ipipe_flags & PF_EVTRET) != 0) {
1684 /*
1685 * Testing for user_regs() does NOT fully eliminate
1686 * foreign stack contexts, because of the forged
1687 * interrupt returns we do through
1688 * __ipipe_call_irqtail. In that case, we might have
1689 * preempted a foreign stack context in a high
1690 * priority domain, with a single interrupt level now
1691 * pending after the irqtail unwinding is done. In
1692 * which case user_mode() is now true, and the event
1693 * gets dispatched spuriously.
1694 */
1695 current->ipipe_flags &= ~PF_EVTRET;
1696 __ipipe_dispatch_event(IPIPE_EVENT_RETURN, regs);
1697 }
1698
Philippe Gerum9bd50df2009-03-04 16:52:38 +08001699 if (this_domain == ipipe_root_domain) {
1700 set_thread_flag(TIF_IRQ_SYNC);
1701 if (!s) {
1702 __clear_bit(IPIPE_SYNCDEFER_FLAG, &p->status);
1703 return !test_bit(IPIPE_STALL_FLAG, &p->status);
1704 }
1705 }
Yi Li6a01f232009-01-07 23:14:39 +08001706
Graf Yang1fa9be72009-05-15 11:01:59 +00001707 return 0;
Yi Li6a01f232009-01-07 23:14:39 +08001708}
1709
1710#endif /* CONFIG_IPIPE */