blob: 1aac5ebaace43c2fc8373d4c5391fc895628c19e [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
Steven Miao4f6b6002012-05-16 17:56:51 +080030#ifndef CONFIG_BF60x
31# 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
Steven Miao4f6b6002012-05-16 17:56:51 +080059#ifndef CONFIG_BF60x
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();
Steven Miao4f6b6002012-05-16 17:56:51 +0800146#ifndef CONFIG_BF60x
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
Steven Miao4f6b6002012-05-16 17:56:51 +0800178#ifndef CONFIG_BF60x
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
202#ifdef CONFIG_BF60x
203static 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
Steven Miao0fbd88c2012-05-17 17:29:54 +0800422#if defined(CONFIG_PM) && !defined(CONFIG_BF60x)
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
Steven Miao4f6b6002012-05-16 17:56:51 +0800506#ifdef CONFIG_BF60x
507static 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,
Bob Liu357351b2012-06-01 14:04:02 +0800515 .irq_set_wake = bfin_internal_set_wake,
Steven Miao4f6b6002012-05-16 17:56:51 +0800516};
517#endif
518
Mike Frysingerf58c3272011-04-15 03:08:20 -0400519void bfin_handle_irq(unsigned irq)
Yi Li6a01f232009-01-07 23:14:39 +0800520{
521#ifdef CONFIG_IPIPE
522 struct pt_regs regs; /* Contents not used. */
523 ipipe_trace_irq_entry(irq);
524 __ipipe_handle_irq(irq, &regs);
525 ipipe_trace_irq_exit(irq);
526#else /* !CONFIG_IPIPE */
Thomas Gleixnerb10bbbb2011-02-06 18:23:25 +0000527 generic_handle_irq(irq);
Yi Li6a01f232009-01-07 23:14:39 +0800528#endif /* !CONFIG_IPIPE */
529}
530
Michael Hennerichaec59c92010-02-19 15:09:10 +0000531#if defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE)
532static int mac_stat_int_mask;
533
534static void bfin_mac_status_ack_irq(unsigned int irq)
535{
536 switch (irq) {
537 case IRQ_MAC_MMCINT:
538 bfin_write_EMAC_MMC_TIRQS(
539 bfin_read_EMAC_MMC_TIRQE() &
540 bfin_read_EMAC_MMC_TIRQS());
541 bfin_write_EMAC_MMC_RIRQS(
542 bfin_read_EMAC_MMC_RIRQE() &
543 bfin_read_EMAC_MMC_RIRQS());
544 break;
545 case IRQ_MAC_RXFSINT:
546 bfin_write_EMAC_RX_STKY(
547 bfin_read_EMAC_RX_IRQE() &
548 bfin_read_EMAC_RX_STKY());
549 break;
550 case IRQ_MAC_TXFSINT:
551 bfin_write_EMAC_TX_STKY(
552 bfin_read_EMAC_TX_IRQE() &
553 bfin_read_EMAC_TX_STKY());
554 break;
555 case IRQ_MAC_WAKEDET:
556 bfin_write_EMAC_WKUP_CTL(
557 bfin_read_EMAC_WKUP_CTL() | MPKS | RWKS);
558 break;
559 default:
560 /* These bits are W1C */
561 bfin_write_EMAC_SYSTAT(1L << (irq - IRQ_MAC_PHYINT));
562 break;
563 }
564}
565
Thomas Gleixner172d2d12011-02-06 18:23:34 +0000566static void bfin_mac_status_mask_irq(struct irq_data *d)
Michael Hennerichaec59c92010-02-19 15:09:10 +0000567{
Thomas Gleixner172d2d12011-02-06 18:23:34 +0000568 unsigned int irq = d->irq;
569
Michael Hennerichaec59c92010-02-19 15:09:10 +0000570 mac_stat_int_mask &= ~(1L << (irq - IRQ_MAC_PHYINT));
Mike Frysingerf58c3272011-04-15 03:08:20 -0400571#ifdef BF537_FAMILY
Michael Hennerichaec59c92010-02-19 15:09:10 +0000572 switch (irq) {
573 case IRQ_MAC_PHYINT:
574 bfin_write_EMAC_SYSCTL(bfin_read_EMAC_SYSCTL() & ~PHYIE);
575 break;
576 default:
577 break;
578 }
579#else
580 if (!mac_stat_int_mask)
581 bfin_internal_mask_irq(IRQ_MAC_ERROR);
582#endif
583 bfin_mac_status_ack_irq(irq);
584}
585
Thomas Gleixner172d2d12011-02-06 18:23:34 +0000586static void bfin_mac_status_unmask_irq(struct irq_data *d)
Michael Hennerichaec59c92010-02-19 15:09:10 +0000587{
Thomas Gleixner172d2d12011-02-06 18:23:34 +0000588 unsigned int irq = d->irq;
589
Mike Frysingerf58c3272011-04-15 03:08:20 -0400590#ifdef BF537_FAMILY
Michael Hennerichaec59c92010-02-19 15:09:10 +0000591 switch (irq) {
592 case IRQ_MAC_PHYINT:
593 bfin_write_EMAC_SYSCTL(bfin_read_EMAC_SYSCTL() | PHYIE);
594 break;
595 default:
596 break;
597 }
598#else
599 if (!mac_stat_int_mask)
600 bfin_internal_unmask_irq(IRQ_MAC_ERROR);
601#endif
602 mac_stat_int_mask |= 1L << (irq - IRQ_MAC_PHYINT);
603}
604
605#ifdef CONFIG_PM
Thomas Gleixner172d2d12011-02-06 18:23:34 +0000606int bfin_mac_status_set_wake(struct irq_data *d, unsigned int state)
Michael Hennerichaec59c92010-02-19 15:09:10 +0000607{
Mike Frysingerf58c3272011-04-15 03:08:20 -0400608#ifdef BF537_FAMILY
Michael Hennerichaec59c92010-02-19 15:09:10 +0000609 return bfin_internal_set_wake(IRQ_GENERIC_ERROR, state);
610#else
611 return bfin_internal_set_wake(IRQ_MAC_ERROR, state);
612#endif
613}
Mike Frysingerfc6bd7b2011-04-15 01:35:53 -0400614#else
615# define bfin_mac_status_set_wake NULL
Michael Hennerichaec59c92010-02-19 15:09:10 +0000616#endif
617
618static struct irq_chip bfin_mac_status_irqchip = {
619 .name = "MACST",
Thomas Gleixner172d2d12011-02-06 18:23:34 +0000620 .irq_mask = bfin_mac_status_mask_irq,
621 .irq_unmask = bfin_mac_status_unmask_irq,
Thomas Gleixner172d2d12011-02-06 18:23:34 +0000622 .irq_set_wake = bfin_mac_status_set_wake,
Michael Hennerichaec59c92010-02-19 15:09:10 +0000623};
624
Mike Frysingerf58c3272011-04-15 03:08:20 -0400625void bfin_demux_mac_status_irq(unsigned int int_err_irq,
626 struct irq_desc *inta_desc)
Michael Hennerichaec59c92010-02-19 15:09:10 +0000627{
628 int i, irq = 0;
629 u32 status = bfin_read_EMAC_SYSTAT();
630
Michael Hennerichbedeea62010-08-20 11:59:27 +0000631 for (i = 0; i <= (IRQ_MAC_STMDONE - IRQ_MAC_PHYINT); i++)
Michael Hennerichaec59c92010-02-19 15:09:10 +0000632 if (status & (1L << i)) {
633 irq = IRQ_MAC_PHYINT + i;
634 break;
635 }
636
637 if (irq) {
638 if (mac_stat_int_mask & (1L << (irq - IRQ_MAC_PHYINT))) {
639 bfin_handle_irq(irq);
640 } else {
641 bfin_mac_status_ack_irq(irq);
642 pr_debug("IRQ %d:"
Steven Miao4f6b6002012-05-16 17:56:51 +0800643 " MASKED MAC ERROR INTERRUPT ASSERTED\n",
644 irq);
Michael Hennerichaec59c92010-02-19 15:09:10 +0000645 }
646 } else
647 printk(KERN_ERR
Steven Miao4f6b6002012-05-16 17:56:51 +0800648 "%s : %s : LINE %d :\nIRQ ?: MAC ERROR"
649 " INTERRUPT ASSERTED BUT NO SOURCE FOUND"
650 "(EMAC_SYSTAT=0x%X)\n",
651 __func__, __FILE__, __LINE__, status);
Michael Hennerichaec59c92010-02-19 15:09:10 +0000652}
653#endif
654
Graf Yangbfd15112008-10-08 18:02:44 +0800655static inline void bfin_set_irq_handler(unsigned irq, irq_flow_handler_t handle)
656{
Yi Li6a01f232009-01-07 23:14:39 +0800657#ifdef CONFIG_IPIPE
Philippe Gerum5b5da4c2011-03-17 02:12:48 -0400658 handle = handle_level_irq;
Yi Li6a01f232009-01-07 23:14:39 +0800659#endif
Thomas Gleixner43f2f112011-03-24 17:22:30 +0100660 __irq_set_handler_locked(irq, handle);
Graf Yangbfd15112008-10-08 18:02:44 +0800661}
662
Michael Hennerich8d022372008-11-18 17:48:22 +0800663static DECLARE_BITMAP(gpio_enabled, MAX_BLACKFIN_GPIOS);
Michael Hennerichaffee2b2008-04-24 08:10:10 +0800664extern void bfin_gpio_irq_prepare(unsigned gpio);
Michael Hennerich6fce6a82007-12-24 16:56:12 +0800665
Mike Frysinger01f8e342011-06-26 13:56:23 -0400666#if !BFIN_GPIO_PINT
Michael Hennerich8d022372008-11-18 17:48:22 +0800667
Thomas Gleixnere9502852011-02-06 18:23:36 +0000668static void bfin_gpio_ack_irq(struct irq_data *d)
Bryan Wu1394f032007-05-06 14:50:22 -0700669{
Michael Hennerich8d022372008-11-18 17:48:22 +0800670 /* AFAIK ack_irq in case mask_ack is provided
671 * get's only called for edge sense irqs
672 */
Thomas Gleixnere9502852011-02-06 18:23:36 +0000673 set_gpio_data(irq_to_gpio(d->irq), 0);
Bryan Wu1394f032007-05-06 14:50:22 -0700674}
675
Thomas Gleixnere9502852011-02-06 18:23:36 +0000676static void bfin_gpio_mask_ack_irq(struct irq_data *d)
Bryan Wu1394f032007-05-06 14:50:22 -0700677{
Thomas Gleixnere9502852011-02-06 18:23:36 +0000678 unsigned int irq = d->irq;
Michael Hennerich8d022372008-11-18 17:48:22 +0800679 u32 gpionr = irq_to_gpio(irq);
Bryan Wu1394f032007-05-06 14:50:22 -0700680
Thomas Gleixner1907d8b2011-03-24 17:21:01 +0100681 if (!irqd_is_level_type(d))
Bryan Wu1394f032007-05-06 14:50:22 -0700682 set_gpio_data(gpionr, 0);
Bryan Wu1394f032007-05-06 14:50:22 -0700683
684 set_gpio_maska(gpionr, 0);
Bryan Wu1394f032007-05-06 14:50:22 -0700685}
686
Thomas Gleixnere9502852011-02-06 18:23:36 +0000687static void bfin_gpio_mask_irq(struct irq_data *d)
Bryan Wu1394f032007-05-06 14:50:22 -0700688{
Thomas Gleixnere9502852011-02-06 18:23:36 +0000689 set_gpio_maska(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_unmask_irq(struct irq_data *d)
Bryan Wu1394f032007-05-06 14:50:22 -0700693{
Thomas Gleixnere9502852011-02-06 18:23:36 +0000694 set_gpio_maska(irq_to_gpio(d->irq), 1);
Bryan Wu1394f032007-05-06 14:50:22 -0700695}
696
Thomas Gleixnere9502852011-02-06 18:23:36 +0000697static unsigned int bfin_gpio_irq_startup(struct irq_data *d)
Bryan Wu1394f032007-05-06 14:50:22 -0700698{
Thomas Gleixnere9502852011-02-06 18:23:36 +0000699 u32 gpionr = irq_to_gpio(d->irq);
Bryan Wu1394f032007-05-06 14:50:22 -0700700
Michael Hennerich8d022372008-11-18 17:48:22 +0800701 if (__test_and_set_bit(gpionr, gpio_enabled))
Michael Hennerichaffee2b2008-04-24 08:10:10 +0800702 bfin_gpio_irq_prepare(gpionr);
Bryan Wu1394f032007-05-06 14:50:22 -0700703
Thomas Gleixnere9502852011-02-06 18:23:36 +0000704 bfin_gpio_unmask_irq(d);
Bryan Wu1394f032007-05-06 14:50:22 -0700705
Michael Hennerichaffee2b2008-04-24 08:10:10 +0800706 return 0;
Bryan Wu1394f032007-05-06 14:50:22 -0700707}
708
Thomas Gleixnere9502852011-02-06 18:23:36 +0000709static void bfin_gpio_irq_shutdown(struct irq_data *d)
Bryan Wu1394f032007-05-06 14:50:22 -0700710{
Thomas Gleixnere9502852011-02-06 18:23:36 +0000711 u32 gpionr = irq_to_gpio(d->irq);
Graf Yang30af6d42008-11-18 17:48:21 +0800712
Thomas Gleixnere9502852011-02-06 18:23:36 +0000713 bfin_gpio_mask_irq(d);
Graf Yang30af6d42008-11-18 17:48:21 +0800714 __clear_bit(gpionr, gpio_enabled);
Graf Yang9570ff42009-01-07 23:14:38 +0800715 bfin_gpio_irq_free(gpionr);
Bryan Wu1394f032007-05-06 14:50:22 -0700716}
717
Thomas Gleixnere9502852011-02-06 18:23:36 +0000718static int bfin_gpio_irq_type(struct irq_data *d, unsigned int type)
Bryan Wu1394f032007-05-06 14:50:22 -0700719{
Thomas Gleixnere9502852011-02-06 18:23:36 +0000720 unsigned int irq = d->irq;
Graf Yang8eb3e3b2008-11-18 17:48:22 +0800721 int ret;
722 char buf[16];
Michael Hennerich8d022372008-11-18 17:48:22 +0800723 u32 gpionr = irq_to_gpio(irq);
Bryan Wu1394f032007-05-06 14:50:22 -0700724
725 if (type == IRQ_TYPE_PROBE) {
726 /* only probe unenabled GPIO interrupt lines */
Mike Frysingerc3695342009-06-13 10:32:29 -0400727 if (test_bit(gpionr, gpio_enabled))
Bryan Wu1394f032007-05-06 14:50:22 -0700728 return 0;
729 type = IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING;
730 }
731
732 if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING |
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800733 IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW)) {
Michael Hennerich8d022372008-11-18 17:48:22 +0800734
Graf Yang9570ff42009-01-07 23:14:38 +0800735 snprintf(buf, 16, "gpio-irq%d", irq);
736 ret = bfin_gpio_irq_request(gpionr, buf);
737 if (ret)
738 return ret;
739
Michael Hennerich8d022372008-11-18 17:48:22 +0800740 if (__test_and_set_bit(gpionr, gpio_enabled))
Michael Hennerichaffee2b2008-04-24 08:10:10 +0800741 bfin_gpio_irq_prepare(gpionr);
Bryan Wu1394f032007-05-06 14:50:22 -0700742
Bryan Wu1394f032007-05-06 14:50:22 -0700743 } else {
Michael Hennerich8d022372008-11-18 17:48:22 +0800744 __clear_bit(gpionr, gpio_enabled);
Bryan Wu1394f032007-05-06 14:50:22 -0700745 return 0;
746 }
747
Michael Hennerichf1bceb42008-02-02 16:17:52 +0800748 set_gpio_inen(gpionr, 0);
Bryan Wu1394f032007-05-06 14:50:22 -0700749 set_gpio_dir(gpionr, 0);
Bryan Wu1394f032007-05-06 14:50:22 -0700750
751 if ((type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING))
752 == (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING))
753 set_gpio_both(gpionr, 1);
754 else
755 set_gpio_both(gpionr, 0);
756
757 if ((type & (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_LEVEL_LOW)))
758 set_gpio_polar(gpionr, 1); /* low or falling edge denoted by one */
759 else
760 set_gpio_polar(gpionr, 0); /* high or rising edge denoted by zero */
761
Michael Hennerichf1bceb42008-02-02 16:17:52 +0800762 if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING)) {
763 set_gpio_edge(gpionr, 1);
764 set_gpio_inen(gpionr, 1);
Michael Hennerichf1bceb42008-02-02 16:17:52 +0800765 set_gpio_data(gpionr, 0);
766
767 } else {
768 set_gpio_edge(gpionr, 0);
Michael Hennerichf1bceb42008-02-02 16:17:52 +0800769 set_gpio_inen(gpionr, 1);
770 }
771
Bryan Wu1394f032007-05-06 14:50:22 -0700772 if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING))
Graf Yangbfd15112008-10-08 18:02:44 +0800773 bfin_set_irq_handler(irq, handle_edge_irq);
Bryan Wu1394f032007-05-06 14:50:22 -0700774 else
Graf Yangbfd15112008-10-08 18:02:44 +0800775 bfin_set_irq_handler(irq, handle_level_irq);
Bryan Wu1394f032007-05-06 14:50:22 -0700776
777 return 0;
778}
779
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800780#ifdef CONFIG_PM
Mike Frysingerdd8cb372011-04-15 03:19:22 -0400781static int bfin_gpio_set_wake(struct irq_data *d, unsigned int state)
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800782{
Thomas Gleixnere9502852011-02-06 18:23:36 +0000783 return gpio_pm_wakeup_ctrl(irq_to_gpio(d->irq), state);
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800784}
Mike Frysingerfc6bd7b2011-04-15 01:35:53 -0400785#else
786# define bfin_gpio_set_wake NULL
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800787#endif
788
Mike Frysingere2a80922011-04-15 12:51:33 -0400789static void bfin_demux_gpio_block(unsigned int irq)
790{
791 unsigned int gpio, mask;
792
793 gpio = irq_to_gpio(irq);
794 mask = get_gpiop_data(gpio) & get_gpiop_maska(gpio);
795
796 while (mask) {
797 if (mask & 1)
798 bfin_handle_irq(irq);
799 irq++;
800 mask >>= 1;
801 }
802}
803
Mike Frysinger8c054102011-04-15 13:04:59 -0400804void bfin_demux_gpio_irq(unsigned int inta_irq,
Steven Miao4f6b6002012-05-16 17:56:51 +0800805 struct irq_desc *desc)
Bryan Wu1394f032007-05-06 14:50:22 -0700806{
Mike Frysingere2a80922011-04-15 12:51:33 -0400807 unsigned int irq;
Bryan Wu1394f032007-05-06 14:50:22 -0700808
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800809 switch (inta_irq) {
Mike Frysingere2a80922011-04-15 12:51:33 -0400810#if defined(BF537_FAMILY)
Mike Frysinger8c054102011-04-15 13:04:59 -0400811 case IRQ_PF_INTA_PG_INTA:
Mike Frysingere2a80922011-04-15 12:51:33 -0400812 bfin_demux_gpio_block(IRQ_PF0);
813 irq = IRQ_PG0;
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800814 break;
Mike Frysinger8c054102011-04-15 13:04:59 -0400815 case IRQ_PH_INTA_MAC_RX:
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800816 irq = IRQ_PH0;
817 break;
Mike Frysingere2a80922011-04-15 12:51:33 -0400818#elif defined(BF533_FAMILY)
819 case IRQ_PROG_INTA:
820 irq = IRQ_PF0;
821 break;
Mike Frysingerfc6bd7b2011-04-15 01:35:53 -0400822#elif defined(BF538_FAMILY)
Michael Hennerichdc26aec2008-11-18 17:48:22 +0800823 case IRQ_PORTF_INTA:
824 irq = IRQ_PF0;
825 break;
Bryan Wu2f6f4bc2008-11-18 17:48:21 +0800826#elif defined(CONFIG_BF52x) || defined(CONFIG_BF51x)
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800827 case IRQ_PORTF_INTA:
828 irq = IRQ_PF0;
829 break;
830 case IRQ_PORTG_INTA:
831 irq = IRQ_PG0;
832 break;
833 case IRQ_PORTH_INTA:
834 irq = IRQ_PH0;
835 break;
836#elif defined(CONFIG_BF561)
837 case IRQ_PROG0_INTA:
838 irq = IRQ_PF0;
839 break;
840 case IRQ_PROG1_INTA:
841 irq = IRQ_PF16;
842 break;
843 case IRQ_PROG2_INTA:
844 irq = IRQ_PF32;
845 break;
846#endif
847 default:
848 BUG();
849 return;
Bryan Wu1394f032007-05-06 14:50:22 -0700850 }
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800851
Mike Frysingere2a80922011-04-15 12:51:33 -0400852 bfin_demux_gpio_block(irq);
Bryan Wu1394f032007-05-06 14:50:22 -0700853}
854
Mike Frysinger01f8e342011-06-26 13:56:23 -0400855#else
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800856
Steven Miao4f6b6002012-05-16 17:56:51 +0800857# ifndef CONFIG_BF60x
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800858#define NR_PINT_SYS_IRQS 4
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800859#define NR_PINTS 160
Steven Miao4f6b6002012-05-16 17:56:51 +0800860# else
861#define NR_PINT_SYS_IRQS 6
862#define NR_PINTS 112
863#endif
864
865#define NR_PINT_BITS 32
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800866#define IRQ_NOT_AVAIL 0xFF
867
868#define PINT_2_BANK(x) ((x) >> 5)
869#define PINT_2_BIT(x) ((x) & 0x1F)
870#define PINT_BIT(x) (1 << (PINT_2_BIT(x)))
871
872static unsigned char irq2pint_lut[NR_PINTS];
Michael Henneriche3f23002007-07-12 16:39:29 +0800873static unsigned char pint2irq_lut[NR_PINT_SYS_IRQS * NR_PINT_BITS];
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800874
Mike Frysinger82ed5f72011-06-26 13:22:05 -0400875static struct bfin_pint_regs * const pint[NR_PINT_SYS_IRQS] = {
876 (struct bfin_pint_regs *)PINT0_MASK_SET,
877 (struct bfin_pint_regs *)PINT1_MASK_SET,
878 (struct bfin_pint_regs *)PINT2_MASK_SET,
879 (struct bfin_pint_regs *)PINT3_MASK_SET,
Steven Miao4f6b6002012-05-16 17:56:51 +0800880#ifdef CONFIG_BF60x
881 (struct bfin_pint_regs *)PINT4_MASK_SET,
882 (struct bfin_pint_regs *)PINT5_MASK_SET,
883#endif
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800884};
885
Steven Miao4f6b6002012-05-16 17:56:51 +0800886#ifndef CONFIG_BF60x
Michael Hennerich8d022372008-11-18 17:48:22 +0800887inline unsigned int get_irq_base(u32 bank, u8 bmap)
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800888{
Michael Hennerich8d022372008-11-18 17:48:22 +0800889 unsigned int irq_base;
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800890
891 if (bank < 2) { /*PA-PB */
892 irq_base = IRQ_PA0 + bmap * 16;
893 } else { /*PC-PJ */
894 irq_base = IRQ_PC0 + bmap * 16;
895 }
896
897 return irq_base;
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800898}
Steven Miao4f6b6002012-05-16 17:56:51 +0800899#else
900inline unsigned int get_irq_base(u32 bank, u8 bmap)
901{
902 unsigned int irq_base;
903
904 irq_base = IRQ_PA0 + bank * 16 + bmap * 16;
905
906 return irq_base;
907}
908#endif
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
1141static int sec_suspend(void)
1142{
1143 u32 bank;
1144
1145 for (bank = 0; bank < NR_PINT_SYS_IRQS; bank++)
1146 save_pint_sec_ctl[bank] = bfin_read_SEC_SCTL(bank + SIC_SYSIRQ(IRQ_PINT0));
1147 return 0;
1148}
1149
1150static void sec_resume(void)
1151{
1152 u32 bank;
1153
1154 bfin_write_SEC_SCI(0, SEC_CCTL, SEC_CCTL_RESET);
1155 udelay(100);
1156 bfin_write_SEC_GCTL(SEC_GCTL_EN);
1157 bfin_write_SEC_SCI(0, SEC_CCTL, SEC_CCTL_EN | SEC_CCTL_NMI_EN);
1158
1159 for (bank = 0; bank < NR_PINT_SYS_IRQS; bank++)
1160 bfin_write_SEC_SCTL(bank + SIC_SYSIRQ(IRQ_PINT0), save_pint_sec_ctl[bank]);
1161}
1162
1163static struct syscore_ops sec_pm_syscore_ops = {
1164 .suspend = sec_suspend,
1165 .resume = sec_resume,
1166};
Mike Frysingerfc6bd7b2011-04-15 01:35:53 -04001167#else
1168# define bfin_gpio_set_wake NULL
Michael Hennerichcfefe3c2008-02-09 04:12:37 +08001169#endif
1170
Mike Frysinger8c054102011-04-15 13:04:59 -04001171void bfin_demux_gpio_irq(unsigned int inta_irq,
Steven Miao4f6b6002012-05-16 17:56:51 +08001172 struct irq_desc *desc)
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001173{
Michael Hennerich8d022372008-11-18 17:48:22 +08001174 u32 bank, pint_val;
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001175 u32 request, irq;
Steven Miao4f6b6002012-05-16 17:56:51 +08001176 u32 level_mask;
1177 int umask = 0;
1178 struct irq_chip *chip = irq_desc_get_chip(desc);
1179
1180 if (chip->irq_mask_ack) {
1181 chip->irq_mask_ack(&desc->irq_data);
1182 } else {
1183 chip->irq_mask(&desc->irq_data);
1184 if (chip->irq_ack)
1185 chip->irq_ack(&desc->irq_data);
1186 }
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001187
Michael Hennerich2c4f8292008-02-09 04:11:14 +08001188 switch (inta_irq) {
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001189 case IRQ_PINT0:
1190 bank = 0;
1191 break;
1192 case IRQ_PINT2:
1193 bank = 2;
1194 break;
1195 case IRQ_PINT3:
1196 bank = 3;
1197 break;
1198 case IRQ_PINT1:
1199 bank = 1;
1200 break;
Steven Miao4f6b6002012-05-16 17:56:51 +08001201#ifdef CONFIG_BF60x
1202 case IRQ_PINT4:
1203 bank = 4;
1204 break;
1205 case IRQ_PINT5:
1206 bank = 5;
1207 break;
1208#endif
Michael Henneriche3f23002007-07-12 16:39:29 +08001209 default:
1210 return;
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001211 }
1212
1213 pint_val = bank * NR_PINT_BITS;
1214
1215 request = pint[bank]->request;
1216
Steven Miao4f6b6002012-05-16 17:56:51 +08001217 level_mask = pint[bank]->edge_set & request;
1218
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001219 while (request) {
1220 if (request & 1) {
Michael Henneriche3f23002007-07-12 16:39:29 +08001221 irq = pint2irq_lut[pint_val] + SYS_IRQS;
Steven Miao4f6b6002012-05-16 17:56:51 +08001222 if (level_mask & PINT_BIT(pint_val)) {
1223 umask = 1;
1224 chip->irq_unmask(&desc->irq_data);
1225 }
Yi Li6a01f232009-01-07 23:14:39 +08001226 bfin_handle_irq(irq);
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001227 }
1228 pint_val++;
1229 request >>= 1;
1230 }
1231
Steven Miao4f6b6002012-05-16 17:56:51 +08001232 if (!umask)
1233 chip->irq_unmask(&desc->irq_data);
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001234}
Mike Frysingera055b2b2007-11-15 21:12:32 +08001235#endif
Bryan Wu1394f032007-05-06 14:50:22 -07001236
Michael Hennerich8d022372008-11-18 17:48:22 +08001237static struct irq_chip bfin_gpio_irqchip = {
1238 .name = "GPIO",
Thomas Gleixnere9502852011-02-06 18:23:36 +00001239 .irq_ack = bfin_gpio_ack_irq,
1240 .irq_mask = bfin_gpio_mask_irq,
1241 .irq_mask_ack = bfin_gpio_mask_ack_irq,
1242 .irq_unmask = bfin_gpio_unmask_irq,
1243 .irq_disable = bfin_gpio_mask_irq,
1244 .irq_enable = bfin_gpio_unmask_irq,
1245 .irq_set_type = bfin_gpio_irq_type,
1246 .irq_startup = bfin_gpio_irq_startup,
1247 .irq_shutdown = bfin_gpio_irq_shutdown,
Thomas Gleixnere9502852011-02-06 18:23:36 +00001248 .irq_set_wake = bfin_gpio_set_wake,
Michael Hennerich8d022372008-11-18 17:48:22 +08001249};
1250
Graf Yang6b3087c2009-01-07 23:14:39 +08001251void __cpuinit init_exception_vectors(void)
Bernd Schmidt8be80ed2007-07-25 14:44:49 +08001252{
Mike Frysingerf0b5d122007-08-05 17:03:59 +08001253 /* cannot program in software:
1254 * evt0 - emulation (jtag)
1255 * evt1 - reset
1256 */
1257 bfin_write_EVT2(evt_nmi);
Bernd Schmidt8be80ed2007-07-25 14:44:49 +08001258 bfin_write_EVT3(trap);
1259 bfin_write_EVT5(evt_ivhw);
1260 bfin_write_EVT6(evt_timer);
1261 bfin_write_EVT7(evt_evt7);
1262 bfin_write_EVT8(evt_evt8);
1263 bfin_write_EVT9(evt_evt9);
1264 bfin_write_EVT10(evt_evt10);
1265 bfin_write_EVT11(evt_evt11);
1266 bfin_write_EVT12(evt_evt12);
1267 bfin_write_EVT13(evt_evt13);
Philippe Gerum9703a732009-06-22 18:23:48 +02001268 bfin_write_EVT14(evt_evt14);
Bernd Schmidt8be80ed2007-07-25 14:44:49 +08001269 bfin_write_EVT15(evt_system_call);
1270 CSYNC();
1271}
1272
Bryan Wu1394f032007-05-06 14:50:22 -07001273/*
1274 * This function should be called during kernel startup to initialize
1275 * the BFin IRQ handling routines.
1276 */
Michael Hennerich8d022372008-11-18 17:48:22 +08001277
Bryan Wu1394f032007-05-06 14:50:22 -07001278int __init init_arch_irq(void)
1279{
1280 int irq;
1281 unsigned long ilat = 0;
Mike Frysingerfc6bd7b2011-04-15 01:35:53 -04001282
Steven Miao4f6b6002012-05-16 17:56:51 +08001283#ifndef CONFIG_BF60x
Bryan Wu1394f032007-05-06 14:50:22 -07001284 /* Disable all the peripheral intrs - page 4-29 HW Ref manual */
Mike Frysingerfc6bd7b2011-04-15 01:35:53 -04001285#ifdef SIC_IMASK0
Roy Huang24a07a12007-07-12 22:41:45 +08001286 bfin_write_SIC_IMASK0(SIC_UNMASK_ALL);
1287 bfin_write_SIC_IMASK1(SIC_UNMASK_ALL);
Mike Frysingerfc6bd7b2011-04-15 01:35:53 -04001288# ifdef SIC_IMASK2
Michael Hennerich59003142007-10-21 16:54:27 +08001289 bfin_write_SIC_IMASK2(SIC_UNMASK_ALL);
Mike Frysingera055b2b2007-11-15 21:12:32 +08001290# endif
Steven Miao4f6b6002012-05-16 17:56:51 +08001291# if defined(CONFIG_SMP) || defined(CONFIG_ICC)
Graf Yang6b3087c2009-01-07 23:14:39 +08001292 bfin_write_SICB_IMASK0(SIC_UNMASK_ALL);
1293 bfin_write_SICB_IMASK1(SIC_UNMASK_ALL);
1294# endif
Roy Huang24a07a12007-07-12 22:41:45 +08001295#else
Bryan Wu1394f032007-05-06 14:50:22 -07001296 bfin_write_SIC_IMASK(SIC_UNMASK_ALL);
Roy Huang24a07a12007-07-12 22:41:45 +08001297#endif
Steven Miao4f6b6002012-05-16 17:56:51 +08001298#else /* CONFIG_BF60x */
1299 bfin_write_SEC_GCTL(SEC_GCTL_RESET);
1300#endif
Bryan Wu1394f032007-05-06 14:50:22 -07001301
1302 local_irq_disable();
1303
Mike Frysinger01f8e342011-06-26 13:56:23 -04001304#if BFIN_GPIO_PINT
Mike Frysingera055b2b2007-11-15 21:12:32 +08001305# ifdef CONFIG_PINTx_REASSIGN
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001306 pint[0]->assign = CONFIG_PINT0_ASSIGN;
1307 pint[1]->assign = CONFIG_PINT1_ASSIGN;
1308 pint[2]->assign = CONFIG_PINT2_ASSIGN;
1309 pint[3]->assign = CONFIG_PINT3_ASSIGN;
Steven Miao4f6b6002012-05-16 17:56:51 +08001310# ifdef CONFIG_BF60x
1311 pint[4]->assign = CONFIG_PINT4_ASSIGN;
1312 pint[5]->assign = CONFIG_PINT5_ASSIGN;
1313# endif
Mike Frysingera055b2b2007-11-15 21:12:32 +08001314# endif
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001315 /* Whenever PINTx_ASSIGN is altered init_pint_lut() must be executed! */
1316 init_pint_lut();
1317#endif
1318
1319 for (irq = 0; irq <= SYS_IRQS; irq++) {
Bryan Wu1394f032007-05-06 14:50:22 -07001320 if (irq <= IRQ_CORETMR)
Thomas Gleixner43f2f112011-03-24 17:22:30 +01001321 irq_set_chip(irq, &bfin_core_irqchip);
Bryan Wu1394f032007-05-06 14:50:22 -07001322 else
Thomas Gleixner43f2f112011-03-24 17:22:30 +01001323 irq_set_chip(irq, &bfin_internal_irqchip);
Bryan Wu1394f032007-05-06 14:50:22 -07001324
Michael Hennerich464abc52008-02-25 13:50:20 +08001325 switch (irq) {
Steven Miao4f6b6002012-05-16 17:56:51 +08001326#ifndef CONFIG_BF60x
Mike Frysinger01f8e342011-06-26 13:56:23 -04001327#if BFIN_GPIO_PINT
Michael Hennerich464abc52008-02-25 13:50:20 +08001328 case IRQ_PINT0:
1329 case IRQ_PINT1:
1330 case IRQ_PINT2:
1331 case IRQ_PINT3:
Mike Frysinger01f8e342011-06-26 13:56:23 -04001332#elif defined(BF537_FAMILY)
1333 case IRQ_PH_INTA_MAC_RX:
1334 case IRQ_PF_INTA_PG_INTA:
1335#elif defined(BF533_FAMILY)
1336 case IRQ_PROG_INTA:
Bryan Wu2f6f4bc2008-11-18 17:48:21 +08001337#elif defined(CONFIG_BF52x) || defined(CONFIG_BF51x)
Michael Hennerich464abc52008-02-25 13:50:20 +08001338 case IRQ_PORTF_INTA:
1339 case IRQ_PORTG_INTA:
1340 case IRQ_PORTH_INTA:
Michael Hennerich2c4f8292008-02-09 04:11:14 +08001341#elif defined(CONFIG_BF561)
Michael Hennerich464abc52008-02-25 13:50:20 +08001342 case IRQ_PROG0_INTA:
1343 case IRQ_PROG1_INTA:
1344 case IRQ_PROG2_INTA:
Mike Frysingerfc6bd7b2011-04-15 01:35:53 -04001345#elif defined(BF538_FAMILY)
Michael Hennerichdc26aec2008-11-18 17:48:22 +08001346 case IRQ_PORTF_INTA:
Michael Hennerich59003142007-10-21 16:54:27 +08001347#endif
Thomas Gleixner43f2f112011-03-24 17:22:30 +01001348 irq_set_chained_handler(irq, bfin_demux_gpio_irq);
Michael Hennerich464abc52008-02-25 13:50:20 +08001349 break;
Michael Hennerichaec59c92010-02-19 15:09:10 +00001350#if defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE)
1351 case IRQ_MAC_ERROR:
Thomas Gleixner43f2f112011-03-24 17:22:30 +01001352 irq_set_chained_handler(irq,
1353 bfin_demux_mac_status_irq);
Michael Hennerichaec59c92010-02-19 15:09:10 +00001354 break;
1355#endif
Steven Miao4f6b6002012-05-16 17:56:51 +08001356#if defined(CONFIG_SMP) || defined(CONFIG_ICC)
Graf Yang6b3087c2009-01-07 23:14:39 +08001357 case IRQ_SUPPLE_0:
1358 case IRQ_SUPPLE_1:
Thomas Gleixner43f2f112011-03-24 17:22:30 +01001359 irq_set_handler(irq, handle_percpu_irq);
Graf Yang6b3087c2009-01-07 23:14:39 +08001360 break;
1361#endif
Steven Miao4f6b6002012-05-16 17:56:51 +08001362#endif
Graf Yang179413142009-08-18 04:29:33 +00001363
Yi Licb191712009-12-30 07:12:50 +00001364#ifdef CONFIG_TICKSOURCE_CORETMR
1365 case IRQ_CORETMR:
1366# ifdef CONFIG_SMP
Thomas Gleixner43f2f112011-03-24 17:22:30 +01001367 irq_set_handler(irq, handle_percpu_irq);
Yi Licb191712009-12-30 07:12:50 +00001368# else
Thomas Gleixner43f2f112011-03-24 17:22:30 +01001369 irq_set_handler(irq, handle_simple_irq);
Yi Licb191712009-12-30 07:12:50 +00001370# endif
Mike Frysingerfc6bd7b2011-04-15 01:35:53 -04001371 break;
Yi Licb191712009-12-30 07:12:50 +00001372#endif
1373
1374#ifdef CONFIG_TICKSOURCE_GPTMR0
Philippe Geruma40494a2009-06-16 05:25:42 +02001375 case IRQ_TIMER0:
Thomas Gleixner43f2f112011-03-24 17:22:30 +01001376 irq_set_handler(irq, handle_simple_irq);
Michael Hennerich464abc52008-02-25 13:50:20 +08001377 break;
Graf Yang179413142009-08-18 04:29:33 +00001378#endif
Yi Licb191712009-12-30 07:12:50 +00001379
Mike Frysingerfc6bd7b2011-04-15 01:35:53 -04001380 default:
Yi Licb191712009-12-30 07:12:50 +00001381#ifdef CONFIG_IPIPE
Thomas Gleixner43f2f112011-03-24 17:22:30 +01001382 irq_set_handler(irq, handle_level_irq);
Mike Frysingerfc6bd7b2011-04-15 01:35:53 -04001383#else
Thomas Gleixner43f2f112011-03-24 17:22:30 +01001384 irq_set_handler(irq, handle_simple_irq);
Mike Frysingerfc6bd7b2011-04-15 01:35:53 -04001385#endif
Philippe Geruma40494a2009-06-16 05:25:42 +02001386 break;
Bryan Wu1394f032007-05-06 14:50:22 -07001387 }
Bryan Wu1394f032007-05-06 14:50:22 -07001388 }
Michael Hennerich464abc52008-02-25 13:50:20 +08001389
Mike Frysingerf58c3272011-04-15 03:08:20 -04001390 init_mach_irq();
Bryan Wu1394f032007-05-06 14:50:22 -07001391
Steven Miao4f6b6002012-05-16 17:56:51 +08001392#ifndef CONFIG_BF60x
1393#if (defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE)) && !defined(CONFIG_BF60x)
Michael Hennerichaec59c92010-02-19 15:09:10 +00001394 for (irq = IRQ_MAC_PHYINT; irq <= IRQ_MAC_STMDONE; irq++)
Thomas Gleixner43f2f112011-03-24 17:22:30 +01001395 irq_set_chip_and_handler(irq, &bfin_mac_status_irqchip,
Michael Hennerichaec59c92010-02-19 15:09:10 +00001396 handle_level_irq);
1397#endif
Michael Hennerich464abc52008-02-25 13:50:20 +08001398 /* if configured as edge, then will be changed to do_edge_IRQ */
Michael Hennerichaec59c92010-02-19 15:09:10 +00001399 for (irq = GPIO_IRQ_BASE;
1400 irq < (GPIO_IRQ_BASE + MAX_BLACKFIN_GPIOS); irq++)
Thomas Gleixner43f2f112011-03-24 17:22:30 +01001401 irq_set_chip_and_handler(irq, &bfin_gpio_irqchip,
Michael Hennerich464abc52008-02-25 13:50:20 +08001402 handle_level_irq);
Steven Miao4f6b6002012-05-16 17:56:51 +08001403#else
1404 for (irq = BFIN_IRQ(0); irq <= SYS_IRQS; irq++) {
Steven Miaoa5b4d4b2012-05-30 18:04:02 +08001405 if (irq < CORE_IRQS && irq != IRQ_CGU_EVT) {
Steven Miao4f6b6002012-05-16 17:56:51 +08001406 irq_set_chip(irq, &bfin_sec_irqchip);
1407 __irq_set_handler(irq, handle_sec_fault, 0, NULL);
1408 } else if (irq >= BFIN_IRQ(21) && irq <= BFIN_IRQ(26)) {
1409 irq_set_chip(irq, &bfin_sec_irqchip);
1410 irq_set_chained_handler(irq, bfin_demux_gpio_irq);
1411 } else if (irq >= BFIN_IRQ(34) && irq <= BFIN_IRQ(37)) {
1412 irq_set_chip(irq, &bfin_sec_irqchip);
1413 irq_set_handler(irq, handle_percpu_irq);
1414 } else {
1415 irq_set_chip_and_handler(irq, &bfin_sec_irqchip,
1416 handle_fasteoi_irq);
1417 __irq_set_preflow_handler(irq, bfin_sec_preflow_handler);
1418 }
1419 }
1420 for (irq = GPIO_IRQ_BASE;
1421 irq < (GPIO_IRQ_BASE + MAX_BLACKFIN_GPIOS); irq++)
1422 irq_set_chip_and_handler(irq, &bfin_gpio_irqchip,
1423 handle_level_irq);
1424#endif
Bryan Wu1394f032007-05-06 14:50:22 -07001425 bfin_write_IMASK(0);
1426 CSYNC();
1427 ilat = bfin_read_ILAT();
1428 CSYNC();
1429 bfin_write_ILAT(ilat);
1430 CSYNC();
1431
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001432 printk(KERN_INFO "Configuring Blackfin Priority Driven Interrupts\n");
Mike Frysinger40059782008-11-18 17:48:22 +08001433 /* IMASK=xxx is equivalent to STI xx or bfin_irq_flags=xx,
Bryan Wu1394f032007-05-06 14:50:22 -07001434 * local_irq_enable()
1435 */
Steven Miao4f6b6002012-05-16 17:56:51 +08001436#ifndef CONFIG_BF60x
Bryan Wu1394f032007-05-06 14:50:22 -07001437 program_IAR();
1438 /* Therefore it's better to setup IARs before interrupts enabled */
1439 search_IAR();
1440
1441 /* Enable interrupts IVG7-15 */
Mike Frysinger40059782008-11-18 17:48:22 +08001442 bfin_irq_flags |= IMASK_IVG15 |
Steven Miao4f6b6002012-05-16 17:56:51 +08001443 IMASK_IVG14 | IMASK_IVG13 | IMASK_IVG12 | IMASK_IVG11 |
1444 IMASK_IVG10 | IMASK_IVG9 | IMASK_IVG8 | IMASK_IVG7 | IMASK_IVGHW;
1445
1446 bfin_sti(bfin_irq_flags);
Bryan Wu1394f032007-05-06 14:50:22 -07001447
Michael Hennerich349ebbc2009-04-15 08:48:08 +00001448 /* This implicitly covers ANOMALY_05000171
1449 * Boot-ROM code modifies SICA_IWRx wakeup registers
1450 */
Mike Frysingerbe1d8542009-02-04 16:49:45 +08001451#ifdef SIC_IWR0
Michael Hennerich56f5f592008-08-06 17:55:32 +08001452 bfin_write_SIC_IWR0(IWR_DISABLE_ALL);
Mike Frysingerbe1d8542009-02-04 16:49:45 +08001453# ifdef SIC_IWR1
Bryan Wu2f6f4bc2008-11-18 17:48:21 +08001454 /* BF52x/BF51x system reset does not properly reset SIC_IWR1 which
Michael Hennerich55546ac2008-08-13 17:41:13 +08001455 * will screw up the bootrom as it relies on MDMA0/1 waking it
1456 * up from IDLE instructions. See this report for more info:
1457 * http://blackfin.uclinux.org/gf/tracker/4323
1458 */
Mike Frysingerb7e11292008-11-18 17:48:22 +08001459 if (ANOMALY_05000435)
1460 bfin_write_SIC_IWR1(IWR_ENABLE(10) | IWR_ENABLE(11));
1461 else
1462 bfin_write_SIC_IWR1(IWR_DISABLE_ALL);
Mike Frysingerbe1d8542009-02-04 16:49:45 +08001463# endif
1464# ifdef SIC_IWR2
Michael Hennerich56f5f592008-08-06 17:55:32 +08001465 bfin_write_SIC_IWR2(IWR_DISABLE_ALL);
Michael Hennerichfe9ec9b2008-02-25 12:04:57 +08001466# endif
1467#else
Michael Hennerich56f5f592008-08-06 17:55:32 +08001468 bfin_write_SIC_IWR(IWR_DISABLE_ALL);
Michael Hennerichfe9ec9b2008-02-25 12:04:57 +08001469#endif
Steven Miao4f6b6002012-05-16 17:56:51 +08001470#else /* CONFIG_BF60x */
1471 /* Enable interrupts IVG7-15 */
1472 bfin_irq_flags |= IMASK_IVG15 |
1473 IMASK_IVG14 | IMASK_IVG13 | IMASK_IVG12 | IMASK_IVG11 |
1474 IMASK_IVG10 | IMASK_IVG9 | IMASK_IVG8 | IMASK_IVG7 | IMASK_IVGHW;
Michael Hennerichfe9ec9b2008-02-25 12:04:57 +08001475
Steven Miao4f6b6002012-05-16 17:56:51 +08001476
1477 bfin_write_SEC_FCTL(SEC_FCTL_EN | SEC_FCTL_SYSRST_EN | SEC_FCTL_FLTIN_EN);
1478 bfin_sec_enable_sci(SIC_SYSIRQ(IRQ_WATCH0));
1479 bfin_sec_enable_ssi(SIC_SYSIRQ(IRQ_WATCH0));
1480 bfin_write_SEC_SCI(0, SEC_CCTL, SEC_CCTL_RESET);
1481 udelay(100);
1482 bfin_write_SEC_GCTL(SEC_GCTL_EN);
1483 bfin_write_SEC_SCI(0, SEC_CCTL, SEC_CCTL_EN | SEC_CCTL_NMI_EN);
1484 init_software_driven_irq();
1485 register_syscore_ops(&sec_pm_syscore_ops);
1486#endif
Bryan Wu1394f032007-05-06 14:50:22 -07001487 return 0;
1488}
1489
1490#ifdef CONFIG_DO_IRQ_L1
Mike Frysingera055b2b2007-11-15 21:12:32 +08001491__attribute__((l1_text))
Bryan Wu1394f032007-05-06 14:50:22 -07001492#endif
Mike Frysinger6b108042011-03-30 01:35:41 -04001493static int vec_to_irq(int vec)
1494{
Steven Miao4f6b6002012-05-16 17:56:51 +08001495#ifndef CONFIG_BF60x
Mike Frysinger6b108042011-03-30 01:35:41 -04001496 struct ivgx *ivg = ivg7_13[vec - IVG7].ifirst;
1497 struct ivgx *ivg_stop = ivg7_13[vec - IVG7].istop;
1498 unsigned long sic_status[3];
Steven Miao4f6b6002012-05-16 17:56:51 +08001499#endif
Mike Frysinger6b108042011-03-30 01:35:41 -04001500 if (likely(vec == EVT_IVTMR_P))
1501 return IRQ_CORETMR;
Steven Miao4f6b6002012-05-16 17:56:51 +08001502#ifndef CONFIG_BF60x
Mike Frysinger6b108042011-03-30 01:35:41 -04001503#ifdef SIC_ISR
1504 sic_status[0] = bfin_read_SIC_IMASK() & bfin_read_SIC_ISR();
1505#else
1506 if (smp_processor_id()) {
1507# ifdef SICB_ISR0
1508 /* This will be optimized out in UP mode. */
1509 sic_status[0] = bfin_read_SICB_ISR0() & bfin_read_SICB_IMASK0();
1510 sic_status[1] = bfin_read_SICB_ISR1() & bfin_read_SICB_IMASK1();
1511# endif
1512 } else {
1513 sic_status[0] = bfin_read_SIC_ISR0() & bfin_read_SIC_IMASK0();
1514 sic_status[1] = bfin_read_SIC_ISR1() & bfin_read_SIC_IMASK1();
1515 }
1516#endif
1517#ifdef SIC_ISR2
1518 sic_status[2] = bfin_read_SIC_ISR2() & bfin_read_SIC_IMASK2();
1519#endif
1520
1521 for (;; ivg++) {
1522 if (ivg >= ivg_stop)
1523 return -1;
1524#ifdef SIC_ISR
1525 if (sic_status[0] & ivg->isrflag)
1526#else
1527 if (sic_status[(ivg->irqno - IVG7) / 32] & ivg->isrflag)
1528#endif
1529 return ivg->irqno;
1530 }
Steven Miao4f6b6002012-05-16 17:56:51 +08001531#else
1532 /* for bf60x read */
1533 return BFIN_IRQ(bfin_read_SEC_SCI(0, SEC_CSID));
1534#endif /* end of CONFIG_BF60x */
Mike Frysinger6b108042011-03-30 01:35:41 -04001535}
1536
1537#ifdef CONFIG_DO_IRQ_L1
1538__attribute__((l1_text))
1539#endif
Bryan Wu1394f032007-05-06 14:50:22 -07001540void do_irq(int vec, struct pt_regs *fp)
1541{
Mike Frysinger6b108042011-03-30 01:35:41 -04001542 int irq = vec_to_irq(vec);
1543 if (irq == -1)
1544 return;
1545 asm_do_IRQ(irq, fp);
Bryan Wu1394f032007-05-06 14:50:22 -07001546}
Yi Li6a01f232009-01-07 23:14:39 +08001547
1548#ifdef CONFIG_IPIPE
1549
1550int __ipipe_get_irq_priority(unsigned irq)
1551{
1552 int ient, prio;
1553
1554 if (irq <= IRQ_CORETMR)
1555 return irq;
1556
1557 for (ient = 0; ient < NR_PERI_INTS; ient++) {
1558 struct ivgx *ivg = ivg_table + ient;
1559 if (ivg->irqno == irq) {
1560 for (prio = 0; prio <= IVG13-IVG7; prio++) {
1561 if (ivg7_13[prio].ifirst <= ivg &&
1562 ivg7_13[prio].istop > ivg)
1563 return IVG7 + prio;
1564 }
1565 }
1566 }
1567
1568 return IVG15;
1569}
1570
Yi Li6a01f232009-01-07 23:14:39 +08001571/* Hw interrupts are disabled on entry (check SAVE_CONTEXT). */
1572#ifdef CONFIG_DO_IRQ_L1
1573__attribute__((l1_text))
1574#endif
1575asmlinkage int __ipipe_grab_irq(int vec, struct pt_regs *regs)
1576{
Philippe Gerum9bd50df2009-03-04 16:52:38 +08001577 struct ipipe_percpu_domain_data *p = ipipe_root_cpudom_ptr();
Philippe Geruma40494a2009-06-16 05:25:42 +02001578 struct ipipe_domain *this_domain = __ipipe_current_domain;
Yi Li6a01f232009-01-07 23:14:39 +08001579 struct ivgx *ivg_stop = ivg7_13[vec-IVG7].istop;
1580 struct ivgx *ivg = ivg7_13[vec-IVG7].ifirst;
Philippe Gerum5b5da4c2011-03-17 02:12:48 -04001581 int irq, s = 0;
Yi Li6a01f232009-01-07 23:14:39 +08001582
Mike Frysinger6b108042011-03-30 01:35:41 -04001583 irq = vec_to_irq(vec);
1584 if (irq == -1)
1585 return 0;
Yi Li6a01f232009-01-07 23:14:39 +08001586
1587 if (irq == IRQ_SYSTMR) {
Philippe Geruma40494a2009-06-16 05:25:42 +02001588#if !defined(CONFIG_GENERIC_CLOCKEVENTS) || defined(CONFIG_TICKSOURCE_GPTMR0)
Yi Li6a01f232009-01-07 23:14:39 +08001589 bfin_write_TIMER_STATUS(1); /* Latch TIMIL0 */
Philippe Gerum9bd50df2009-03-04 16:52:38 +08001590#endif
Yi Li6a01f232009-01-07 23:14:39 +08001591 /* This is basically what we need from the register frame. */
1592 __raw_get_cpu_var(__ipipe_tick_regs).ipend = regs->ipend;
1593 __raw_get_cpu_var(__ipipe_tick_regs).pc = regs->pc;
Philippe Gerum9bd50df2009-03-04 16:52:38 +08001594 if (this_domain != ipipe_root_domain)
Yi Li6a01f232009-01-07 23:14:39 +08001595 __raw_get_cpu_var(__ipipe_tick_regs).ipend &= ~0x10;
Philippe Gerum9bd50df2009-03-04 16:52:38 +08001596 else
1597 __raw_get_cpu_var(__ipipe_tick_regs).ipend |= 0x10;
Yi Li6a01f232009-01-07 23:14:39 +08001598 }
1599
Philippe Gerum5b5da4c2011-03-17 02:12:48 -04001600 /*
1601 * We don't want Linux interrupt handlers to run at the
1602 * current core priority level (i.e. < EVT15), since this
1603 * might delay other interrupts handled by a high priority
1604 * domain. Here is what we do instead:
1605 *
1606 * - we raise the SYNCDEFER bit to prevent
1607 * __ipipe_handle_irq() to sync the pipeline for the root
1608 * stage for the incoming interrupt. Upon return, that IRQ is
1609 * pending in the interrupt log.
1610 *
1611 * - we raise the TIF_IRQ_SYNC bit for the current thread, so
1612 * that _schedule_and_signal_from_int will eventually sync the
1613 * pipeline from EVT15.
1614 */
Philippe Gerum9bd50df2009-03-04 16:52:38 +08001615 if (this_domain == ipipe_root_domain) {
1616 s = __test_and_set_bit(IPIPE_SYNCDEFER_FLAG, &p->status);
1617 barrier();
1618 }
Yi Li6a01f232009-01-07 23:14:39 +08001619
1620 ipipe_trace_irq_entry(irq);
1621 __ipipe_handle_irq(irq, regs);
Philippe Gerum9bd50df2009-03-04 16:52:38 +08001622 ipipe_trace_irq_exit(irq);
Yi Li6a01f232009-01-07 23:14:39 +08001623
Philippe Gerum5b5da4c2011-03-17 02:12:48 -04001624 if (user_mode(regs) &&
1625 !ipipe_test_foreign_stack() &&
1626 (current->ipipe_flags & PF_EVTRET) != 0) {
1627 /*
1628 * Testing for user_regs() does NOT fully eliminate
1629 * foreign stack contexts, because of the forged
1630 * interrupt returns we do through
1631 * __ipipe_call_irqtail. In that case, we might have
1632 * preempted a foreign stack context in a high
1633 * priority domain, with a single interrupt level now
1634 * pending after the irqtail unwinding is done. In
1635 * which case user_mode() is now true, and the event
1636 * gets dispatched spuriously.
1637 */
1638 current->ipipe_flags &= ~PF_EVTRET;
1639 __ipipe_dispatch_event(IPIPE_EVENT_RETURN, regs);
1640 }
1641
Philippe Gerum9bd50df2009-03-04 16:52:38 +08001642 if (this_domain == ipipe_root_domain) {
1643 set_thread_flag(TIF_IRQ_SYNC);
1644 if (!s) {
1645 __clear_bit(IPIPE_SYNCDEFER_FLAG, &p->status);
1646 return !test_bit(IPIPE_STALL_FLAG, &p->status);
1647 }
1648 }
Yi Li6a01f232009-01-07 23:14:39 +08001649
Graf Yang1fa9be72009-05-15 11:01:59 +00001650 return 0;
Yi Li6a01f232009-01-07 23:14:39 +08001651}
1652
1653#endif /* CONFIG_IPIPE */