blob: 83ff311fd6ea413930673fd91adf4a61eefb8fea [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>
Sonic Zhang06051fd2012-07-04 19:22:55 +080029#include <asm/traps.h>
Bryan Wu1394f032007-05-06 14:50:22 -070030
Bryan Wu1394f032007-05-06 14:50:22 -070031/*
32 * NOTES:
33 * - we have separated the physical Hardware interrupt from the
34 * levels that the LINUX kernel sees (see the description in irq.h)
35 * -
36 */
37
Graf Yang6b3087c2009-01-07 23:14:39 +080038#ifndef CONFIG_SMP
Mike Frysingera99bbcc2007-10-22 00:19:31 +080039/* Initialize this to an actual value to force it into the .data
40 * section so that we know it is properly initialized at entry into
41 * the kernel but before bss is initialized to zero (which is where
42 * it would live otherwise). The 0x1f magic represents the IRQs we
43 * cannot actually mask out in hardware.
44 */
Mike Frysinger40059782008-11-18 17:48:22 +080045unsigned long bfin_irq_flags = 0x1f;
46EXPORT_SYMBOL(bfin_irq_flags);
Graf Yang6b3087c2009-01-07 23:14:39 +080047#endif
Bryan Wu1394f032007-05-06 14:50:22 -070048
Michael Hennerichcfefe3c2008-02-09 04:12:37 +080049#ifdef CONFIG_PM
50unsigned long bfin_sic_iwr[3]; /* Up to 3 SIC_IWRx registers */
Michael Hennerich4a88d0c2008-08-05 17:38:41 +080051unsigned vr_wakeup;
Michael Hennerichcfefe3c2008-02-09 04:12:37 +080052#endif
53
Sonic Zhang11b27cb2012-06-28 19:16:48 +080054#ifndef SEC_GCTL
Mike Frysingere9e334c2011-03-30 00:43:52 -040055static struct ivgx {
Michael Hennerich464abc52008-02-25 13:50:20 +080056 /* irq number for request_irq, available in mach-bf5xx/irq.h */
Roy Huang24a07a12007-07-12 22:41:45 +080057 unsigned int irqno;
Bryan Wu1394f032007-05-06 14:50:22 -070058 /* corresponding bit in the SIC_ISR register */
Roy Huang24a07a12007-07-12 22:41:45 +080059 unsigned int isrflag;
Bryan Wu1394f032007-05-06 14:50:22 -070060} ivg_table[NR_PERI_INTS];
61
Mike Frysingere9e334c2011-03-30 00:43:52 -040062static struct ivg_slice {
Bryan Wu1394f032007-05-06 14:50:22 -070063 /* position of first irq in ivg_table for given ivg */
64 struct ivgx *ifirst;
65 struct ivgx *istop;
66} ivg7_13[IVG13 - IVG7 + 1];
67
Bryan Wu1394f032007-05-06 14:50:22 -070068
69/*
70 * Search SIC_IAR and fill tables with the irqvalues
71 * and their positions in the SIC_ISR register.
72 */
73static void __init search_IAR(void)
74{
75 unsigned ivg, irq_pos = 0;
76 for (ivg = 0; ivg <= IVG13 - IVG7; ivg++) {
Mike Frysinger80fcdb92010-04-22 21:15:00 +000077 int irqN;
Bryan Wu1394f032007-05-06 14:50:22 -070078
Michael Hennerich34e0fc82007-07-12 16:17:18 +080079 ivg7_13[ivg].istop = ivg7_13[ivg].ifirst = &ivg_table[irq_pos];
Bryan Wu1394f032007-05-06 14:50:22 -070080
Mike Frysinger80fcdb92010-04-22 21:15:00 +000081 for (irqN = 0; irqN < NR_PERI_INTS; irqN += 4) {
82 int irqn;
Steven Miao4f6b6002012-05-16 17:56:51 +080083 u32 iar =
84 bfin_read32((unsigned long *)SIC_IAR0 +
Mike Frysinger80fcdb92010-04-22 21:15:00 +000085#if defined(CONFIG_BF51x) || defined(CONFIG_BF52x) || \
86 defined(CONFIG_BF538) || defined(CONFIG_BF539)
87 ((irqN % 32) >> 3) + ((irqN / 32) * ((SIC_IAR4 - SIC_IAR0) / 4))
Michael Hennerich59003142007-10-21 16:54:27 +080088#else
Mike Frysinger80fcdb92010-04-22 21:15:00 +000089 (irqN >> 3)
Michael Hennerich59003142007-10-21 16:54:27 +080090#endif
Mike Frysinger80fcdb92010-04-22 21:15:00 +000091 );
Mike Frysinger80fcdb92010-04-22 21:15:00 +000092 for (irqn = irqN; irqn < irqN + 4; ++irqn) {
93 int iar_shift = (irqn & 7) * 4;
94 if (ivg == (0xf & (iar >> iar_shift))) {
95 ivg_table[irq_pos].irqno = IVG7 + irqn;
96 ivg_table[irq_pos].isrflag = 1 << (irqn % 32);
97 ivg7_13[ivg].istop++;
98 irq_pos++;
99 }
Bryan Wu1394f032007-05-06 14:50:22 -0700100 }
101 }
102 }
103}
Steven Miao4f6b6002012-05-16 17:56:51 +0800104#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700105
106/*
Michael Hennerich464abc52008-02-25 13:50:20 +0800107 * This is for core internal IRQs
Bryan Wu1394f032007-05-06 14:50:22 -0700108 */
Mike Frysingerf58c3272011-04-15 03:08:20 -0400109void bfin_ack_noop(struct irq_data *d)
Bryan Wu1394f032007-05-06 14:50:22 -0700110{
111 /* Dummy function. */
112}
113
Thomas Gleixner4f19ea42011-02-06 18:23:27 +0000114static void bfin_core_mask_irq(struct irq_data *d)
Bryan Wu1394f032007-05-06 14:50:22 -0700115{
Thomas Gleixner4f19ea42011-02-06 18:23:27 +0000116 bfin_irq_flags &= ~(1 << d->irq);
David Howells3b139cd2010-10-07 14:08:52 +0100117 if (!hard_irqs_disabled())
118 hard_local_irq_enable();
Bryan Wu1394f032007-05-06 14:50:22 -0700119}
120
Thomas Gleixner4f19ea42011-02-06 18:23:27 +0000121static void bfin_core_unmask_irq(struct irq_data *d)
Bryan Wu1394f032007-05-06 14:50:22 -0700122{
Thomas Gleixner4f19ea42011-02-06 18:23:27 +0000123 bfin_irq_flags |= 1 << d->irq;
Bryan Wu1394f032007-05-06 14:50:22 -0700124 /*
125 * If interrupts are enabled, IMASK must contain the same value
Mike Frysinger40059782008-11-18 17:48:22 +0800126 * as bfin_irq_flags. Make sure that invariant holds. If interrupts
Bryan Wu1394f032007-05-06 14:50:22 -0700127 * are currently disabled we need not do anything; one of the
128 * callers will take care of setting IMASK to the proper value
129 * when reenabling interrupts.
Mike Frysinger40059782008-11-18 17:48:22 +0800130 * local_irq_enable just does "STI bfin_irq_flags", so it's exactly
Bryan Wu1394f032007-05-06 14:50:22 -0700131 * what we need.
132 */
David Howells3b139cd2010-10-07 14:08:52 +0100133 if (!hard_irqs_disabled())
134 hard_local_irq_enable();
Bryan Wu1394f032007-05-06 14:50:22 -0700135 return;
136}
137
Sonic Zhang86794b42012-12-14 11:19:24 +0800138#ifndef SEC_GCTL
Mike Frysingerf58c3272011-04-15 03:08:20 -0400139void bfin_internal_mask_irq(unsigned int irq)
Bryan Wu1394f032007-05-06 14:50:22 -0700140{
Mike Frysingerfc6bd7b2011-04-15 01:35:53 -0400141 unsigned long flags = hard_local_irq_save();
Mike Frysingerfc6bd7b2011-04-15 01:35:53 -0400142#ifdef SIC_IMASK0
Sonic Zhang86794b42012-12-14 11:19:24 +0800143 unsigned mask_bank = BFIN_SYSIRQ(irq) / 32;
144 unsigned mask_bit = BFIN_SYSIRQ(irq) % 32;
Bryan Wuc04d66b2007-07-12 17:26:31 +0800145 bfin_write_SIC_IMASK(mask_bank, bfin_read_SIC_IMASK(mask_bank) &
Steven Miao4f6b6002012-05-16 17:56:51 +0800146 ~(1 << mask_bit));
147# if defined(CONFIG_SMP) || defined(CONFIG_ICC)
Graf Yang6b3087c2009-01-07 23:14:39 +0800148 bfin_write_SICB_IMASK(mask_bank, bfin_read_SICB_IMASK(mask_bank) &
Steven Miao4f6b6002012-05-16 17:56:51 +0800149 ~(1 << mask_bit));
Mike Frysingerfc6bd7b2011-04-15 01:35:53 -0400150# endif
151#else
152 bfin_write_SIC_IMASK(bfin_read_SIC_IMASK() &
Sonic Zhang86794b42012-12-14 11:19:24 +0800153 ~(1 << BFIN_SYSIRQ(irq)));
Steven Miao4f6b6002012-05-16 17:56:51 +0800154#endif /* end of SIC_IMASK0 */
David Howells3b139cd2010-10-07 14:08:52 +0100155 hard_local_irq_restore(flags);
Bryan Wu1394f032007-05-06 14:50:22 -0700156}
157
Thomas Gleixnerff43a672011-02-06 18:23:29 +0000158static void bfin_internal_mask_irq_chip(struct irq_data *d)
159{
160 bfin_internal_mask_irq(d->irq);
161}
162
Sonic Zhang0325f252009-12-28 07:29:57 +0000163#ifdef CONFIG_SMP
Steven Miao4f6b6002012-05-16 17:56:51 +0800164void bfin_internal_unmask_irq_affinity(unsigned int irq,
Sonic Zhang0325f252009-12-28 07:29:57 +0000165 const struct cpumask *affinity)
166#else
Mike Frysingerf58c3272011-04-15 03:08:20 -0400167void bfin_internal_unmask_irq(unsigned int irq)
Sonic Zhang0325f252009-12-28 07:29:57 +0000168#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700169{
Mike Frysingerfc6bd7b2011-04-15 01:35:53 -0400170 unsigned long flags = hard_local_irq_save();
Philippe Gerum9bd50df2009-03-04 16:52:38 +0800171
Mike Frysingerfc6bd7b2011-04-15 01:35:53 -0400172#ifdef SIC_IMASK0
Sonic Zhang86794b42012-12-14 11:19:24 +0800173 unsigned mask_bank = BFIN_SYSIRQ(irq) / 32;
174 unsigned mask_bit = BFIN_SYSIRQ(irq) % 32;
Mike Frysingerfc6bd7b2011-04-15 01:35:53 -0400175# ifdef CONFIG_SMP
Sonic Zhang0325f252009-12-28 07:29:57 +0000176 if (cpumask_test_cpu(0, affinity))
Mike Frysingerfc6bd7b2011-04-15 01:35:53 -0400177# endif
Sonic Zhang0325f252009-12-28 07:29:57 +0000178 bfin_write_SIC_IMASK(mask_bank,
Steven Miao4f6b6002012-05-16 17:56:51 +0800179 bfin_read_SIC_IMASK(mask_bank) |
180 (1 << mask_bit));
Mike Frysingerfc6bd7b2011-04-15 01:35:53 -0400181# ifdef CONFIG_SMP
Sonic Zhang0325f252009-12-28 07:29:57 +0000182 if (cpumask_test_cpu(1, affinity))
183 bfin_write_SICB_IMASK(mask_bank,
Steven Miao4f6b6002012-05-16 17:56:51 +0800184 bfin_read_SICB_IMASK(mask_bank) |
185 (1 << mask_bit));
Mike Frysingerfc6bd7b2011-04-15 01:35:53 -0400186# endif
187#else
188 bfin_write_SIC_IMASK(bfin_read_SIC_IMASK() |
Sonic Zhang86794b42012-12-14 11:19:24 +0800189 (1 << BFIN_SYSIRQ(irq)));
Steven Miao4f6b6002012-05-16 17:56:51 +0800190#endif
191 hard_local_irq_restore(flags);
192}
193
Sonic Zhang86794b42012-12-14 11:19:24 +0800194#ifdef CONFIG_SMP
195static void bfin_internal_unmask_irq_chip(struct irq_data *d)
196{
197 bfin_internal_unmask_irq_affinity(d->irq, d->affinity);
198}
199
200static int bfin_internal_set_affinity(struct irq_data *d,
201 const struct cpumask *mask, bool force)
202{
203 bfin_internal_mask_irq(d->irq);
204 bfin_internal_unmask_irq_affinity(d->irq, mask);
205
206 return 0;
207}
208#else
209static void bfin_internal_unmask_irq_chip(struct irq_data *d)
210{
211 bfin_internal_unmask_irq(d->irq);
212}
213#endif
214
215#if defined(CONFIG_PM)
216int bfin_internal_set_wake(unsigned int irq, unsigned int state)
217{
218 u32 bank, bit, wakeup = 0;
219 unsigned long flags;
220 bank = BFIN_SYSIRQ(irq) / 32;
221 bit = BFIN_SYSIRQ(irq) % 32;
222
223 switch (irq) {
224#ifdef IRQ_RTC
225 case IRQ_RTC:
226 wakeup |= WAKE;
227 break;
228#endif
229#ifdef IRQ_CAN0_RX
230 case IRQ_CAN0_RX:
231 wakeup |= CANWE;
232 break;
233#endif
234#ifdef IRQ_CAN1_RX
235 case IRQ_CAN1_RX:
236 wakeup |= CANWE;
237 break;
238#endif
239#ifdef IRQ_USB_INT0
240 case IRQ_USB_INT0:
241 wakeup |= USBWE;
242 break;
243#endif
244#ifdef CONFIG_BF54x
245 case IRQ_CNT:
246 wakeup |= ROTWE;
247 break;
248#endif
249 default:
250 break;
251 }
252
253 flags = hard_local_irq_save();
254
255 if (state) {
256 bfin_sic_iwr[bank] |= (1 << bit);
257 vr_wakeup |= wakeup;
258
259 } else {
260 bfin_sic_iwr[bank] &= ~(1 << bit);
261 vr_wakeup &= ~wakeup;
262 }
263
264 hard_local_irq_restore(flags);
265
266 return 0;
267}
268
269static int bfin_internal_set_wake_chip(struct irq_data *d, unsigned int state)
270{
271 return bfin_internal_set_wake(d->irq, state);
272}
273#else
274inline int bfin_internal_set_wake(unsigned int irq, unsigned int state)
275{
276 return 0;
277}
278# define bfin_internal_set_wake_chip NULL
279#endif
280
281#else /* SEC_GCTL */
Steven Miao4f6b6002012-05-16 17:56:51 +0800282static void bfin_sec_preflow_handler(struct irq_data *d)
283{
284 unsigned long flags = hard_local_irq_save();
Sonic Zhang86794b42012-12-14 11:19:24 +0800285 unsigned int sid = BFIN_SYSIRQ(d->irq);
Steven Miao4f6b6002012-05-16 17:56:51 +0800286
287 bfin_write_SEC_SCI(0, SEC_CSID, sid);
Mike Frysingerfc6bd7b2011-04-15 01:35:53 -0400288
David Howells3b139cd2010-10-07 14:08:52 +0100289 hard_local_irq_restore(flags);
Bryan Wu1394f032007-05-06 14:50:22 -0700290}
291
Steven Miao4f6b6002012-05-16 17:56:51 +0800292static void bfin_sec_mask_ack_irq(struct irq_data *d)
293{
294 unsigned long flags = hard_local_irq_save();
Sonic Zhang86794b42012-12-14 11:19:24 +0800295 unsigned int sid = BFIN_SYSIRQ(d->irq);
Steven Miao4f6b6002012-05-16 17:56:51 +0800296
297 bfin_write_SEC_SCI(0, SEC_CSID, sid);
298
299 hard_local_irq_restore(flags);
300}
301
302static void bfin_sec_unmask_irq(struct irq_data *d)
303{
304 unsigned long flags = hard_local_irq_save();
Sonic Zhang86794b42012-12-14 11:19:24 +0800305 unsigned int sid = BFIN_SYSIRQ(d->irq);
Steven Miao4f6b6002012-05-16 17:56:51 +0800306
307 bfin_write32(SEC_END, sid);
308
309 hard_local_irq_restore(flags);
310}
311
312static void bfin_sec_enable_ssi(unsigned int sid)
313{
314 unsigned long flags = hard_local_irq_save();
315 uint32_t reg_sctl = bfin_read_SEC_SCTL(sid);
316
317 reg_sctl |= SEC_SCTL_SRC_EN;
318 bfin_write_SEC_SCTL(sid, reg_sctl);
319
320 hard_local_irq_restore(flags);
321}
322
323static void bfin_sec_disable_ssi(unsigned int sid)
324{
325 unsigned long flags = hard_local_irq_save();
326 uint32_t reg_sctl = bfin_read_SEC_SCTL(sid);
327
328 reg_sctl &= ((uint32_t)~SEC_SCTL_SRC_EN);
329 bfin_write_SEC_SCTL(sid, reg_sctl);
330
331 hard_local_irq_restore(flags);
332}
333
334static void bfin_sec_set_ssi_coreid(unsigned int sid, unsigned int coreid)
335{
336 unsigned long flags = hard_local_irq_save();
337 uint32_t reg_sctl = bfin_read_SEC_SCTL(sid);
338
339 reg_sctl &= ((uint32_t)~SEC_SCTL_CTG);
340 bfin_write_SEC_SCTL(sid, reg_sctl | ((coreid << 20) & SEC_SCTL_CTG));
341
342 hard_local_irq_restore(flags);
343}
344
345static void bfin_sec_enable_sci(unsigned int sid)
346{
347 unsigned long flags = hard_local_irq_save();
348 uint32_t reg_sctl = bfin_read_SEC_SCTL(sid);
349
Sonic Zhang86794b42012-12-14 11:19:24 +0800350 if (sid == BFIN_SYSIRQ(IRQ_WATCH0))
Steven Miao4f6b6002012-05-16 17:56:51 +0800351 reg_sctl |= SEC_SCTL_FAULT_EN;
352 else
353 reg_sctl |= SEC_SCTL_INT_EN;
354 bfin_write_SEC_SCTL(sid, reg_sctl);
355
356 hard_local_irq_restore(flags);
357}
358
359static void bfin_sec_disable_sci(unsigned int sid)
360{
361 unsigned long flags = hard_local_irq_save();
362 uint32_t reg_sctl = bfin_read_SEC_SCTL(sid);
363
364 reg_sctl &= ((uint32_t)~SEC_SCTL_INT_EN);
365 bfin_write_SEC_SCTL(sid, reg_sctl);
366
367 hard_local_irq_restore(flags);
368}
369
370static void bfin_sec_enable(struct irq_data *d)
371{
372 unsigned long flags = hard_local_irq_save();
Sonic Zhang86794b42012-12-14 11:19:24 +0800373 unsigned int sid = BFIN_SYSIRQ(d->irq);
Steven Miao4f6b6002012-05-16 17:56:51 +0800374
375 bfin_sec_enable_sci(sid);
376 bfin_sec_enable_ssi(sid);
377
378 hard_local_irq_restore(flags);
379}
380
381static void bfin_sec_disable(struct irq_data *d)
382{
383 unsigned long flags = hard_local_irq_save();
Sonic Zhang86794b42012-12-14 11:19:24 +0800384 unsigned int sid = BFIN_SYSIRQ(d->irq);
Steven Miao4f6b6002012-05-16 17:56:51 +0800385
386 bfin_sec_disable_sci(sid);
387 bfin_sec_disable_ssi(sid);
388
389 hard_local_irq_restore(flags);
390}
391
Sonic Zhange0a59312012-06-29 18:19:29 +0800392static void bfin_sec_set_priority(unsigned int sec_int_levels, u8 *sec_int_priority)
393{
394 unsigned long flags = hard_local_irq_save();
395 uint32_t reg_sctl;
396 int i;
397
398 bfin_write_SEC_SCI(0, SEC_CPLVL, sec_int_levels);
399
400 for (i = 0; i < SYS_IRQS - BFIN_IRQ(0); i++) {
401 reg_sctl = bfin_read_SEC_SCTL(i) & ~SEC_SCTL_PRIO;
402 reg_sctl |= sec_int_priority[i] << SEC_SCTL_PRIO_OFFSET;
403 bfin_write_SEC_SCTL(i, reg_sctl);
404 }
405
406 hard_local_irq_restore(flags);
407}
408
Sonic Zhang86794b42012-12-14 11:19:24 +0800409void bfin_sec_raise_irq(unsigned int irq)
Steven Miao4f6b6002012-05-16 17:56:51 +0800410{
411 unsigned long flags = hard_local_irq_save();
Sonic Zhang86794b42012-12-14 11:19:24 +0800412 unsigned int sid = BFIN_SYSIRQ(irq);
Steven Miao4f6b6002012-05-16 17:56:51 +0800413
414 bfin_write32(SEC_RAISE, sid);
415
416 hard_local_irq_restore(flags);
417}
418
419static void init_software_driven_irq(void)
420{
421 bfin_sec_set_ssi_coreid(34, 0);
422 bfin_sec_set_ssi_coreid(35, 1);
Sonic Zhang86794b42012-12-14 11:19:24 +0800423
424 bfin_sec_enable_sci(35);
425 bfin_sec_enable_ssi(35);
Steven Miao4f6b6002012-05-16 17:56:51 +0800426 bfin_sec_set_ssi_coreid(36, 0);
427 bfin_sec_set_ssi_coreid(37, 1);
Sonic Zhang86794b42012-12-14 11:19:24 +0800428 bfin_sec_enable_sci(37);
429 bfin_sec_enable_ssi(37);
Steven Miao4f6b6002012-05-16 17:56:51 +0800430}
431
432void bfin_sec_resume(void)
433{
434 bfin_write_SEC_SCI(0, SEC_CCTL, SEC_CCTL_RESET);
435 udelay(100);
436 bfin_write_SEC_GCTL(SEC_GCTL_EN);
437 bfin_write_SEC_SCI(0, SEC_CCTL, SEC_CCTL_EN | SEC_CCTL_NMI_EN);
438}
439
440void handle_sec_sfi_fault(uint32_t gstat)
441{
442
443}
444
445void handle_sec_sci_fault(uint32_t gstat)
446{
447 uint32_t core_id;
448 uint32_t cstat;
449
450 core_id = gstat & SEC_GSTAT_SCI;
451 cstat = bfin_read_SEC_SCI(core_id, SEC_CSTAT);
452 if (cstat & SEC_CSTAT_ERR) {
453 switch (cstat & SEC_CSTAT_ERRC) {
454 case SEC_CSTAT_ACKERR:
455 printk(KERN_DEBUG "sec ack err\n");
456 break;
457 default:
458 printk(KERN_DEBUG "sec sci unknow err\n");
459 }
460 }
461
462}
463
464void handle_sec_ssi_fault(uint32_t gstat)
465{
466 uint32_t sid;
467 uint32_t sstat;
468
469 sid = gstat & SEC_GSTAT_SID;
470 sstat = bfin_read_SEC_SSTAT(sid);
471
472}
473
474void handle_sec_fault(unsigned int irq, struct irq_desc *desc)
475{
476 uint32_t sec_gstat;
477
478 raw_spin_lock(&desc->lock);
479
480 sec_gstat = bfin_read32(SEC_GSTAT);
481 if (sec_gstat & SEC_GSTAT_ERR) {
482
483 switch (sec_gstat & SEC_GSTAT_ERRC) {
484 case 0:
485 handle_sec_sfi_fault(sec_gstat);
486 break;
487 case SEC_GSTAT_SCIERR:
488 handle_sec_sci_fault(sec_gstat);
489 break;
490 case SEC_GSTAT_SSIERR:
491 handle_sec_ssi_fault(sec_gstat);
492 break;
493 }
494
495
496 }
497
498 raw_spin_unlock(&desc->lock);
Sonic Zhang86794b42012-12-14 11:19:24 +0800499
500 handle_fasteoi_irq(irq, desc);
Steven Miao4f6b6002012-05-16 17:56:51 +0800501}
502
Sonic Zhang06051fd2012-07-04 19:22:55 +0800503void handle_core_fault(unsigned int irq, struct irq_desc *desc)
504{
505 struct pt_regs *fp = get_irq_regs();
506
507 raw_spin_lock(&desc->lock);
508
509 switch (irq) {
510 case IRQ_C0_DBL_FAULT:
511 double_fault_c(fp);
512 break;
513 case IRQ_C0_HW_ERR:
514 dump_bfin_process(fp);
515 dump_bfin_mem(fp);
516 show_regs(fp);
517 printk(KERN_NOTICE "Kernel Stack\n");
518 show_stack(current, NULL);
519 print_modules();
Sonic Zhang86794b42012-12-14 11:19:24 +0800520 panic("Core 0 hardware error");
Sonic Zhang06051fd2012-07-04 19:22:55 +0800521 break;
522 case IRQ_C0_NMI_L1_PARITY_ERR:
Sonic Zhang86794b42012-12-14 11:19:24 +0800523 panic("Core 0 NMI L1 parity error");
Sonic Zhang06051fd2012-07-04 19:22:55 +0800524 break;
525 default:
Sonic Zhang86794b42012-12-14 11:19:24 +0800526 panic("Core 1 fault %d occurs unexpectedly", irq);
Sonic Zhang06051fd2012-07-04 19:22:55 +0800527 }
528
529 raw_spin_unlock(&desc->lock);
530}
Sonic Zhang86794b42012-12-14 11:19:24 +0800531#endif /* SEC_GCTL */
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800532
Bryan Wu1394f032007-05-06 14:50:22 -0700533static struct irq_chip bfin_core_irqchip = {
Graf Yang763e63c2008-10-08 17:08:15 +0800534 .name = "CORE",
Thomas Gleixner4f19ea42011-02-06 18:23:27 +0000535 .irq_mask = bfin_core_mask_irq,
536 .irq_unmask = bfin_core_unmask_irq,
Bryan Wu1394f032007-05-06 14:50:22 -0700537};
538
Sonic Zhang86794b42012-12-14 11:19:24 +0800539#ifndef SEC_GCTL
Bryan Wu1394f032007-05-06 14:50:22 -0700540static struct irq_chip bfin_internal_irqchip = {
Graf Yang763e63c2008-10-08 17:08:15 +0800541 .name = "INTN",
Thomas Gleixnerff43a672011-02-06 18:23:29 +0000542 .irq_mask = bfin_internal_mask_irq_chip,
543 .irq_unmask = bfin_internal_unmask_irq_chip,
Thomas Gleixnerff43a672011-02-06 18:23:29 +0000544 .irq_disable = bfin_internal_mask_irq_chip,
545 .irq_enable = bfin_internal_unmask_irq_chip,
Sonic Zhang0325f252009-12-28 07:29:57 +0000546#ifdef CONFIG_SMP
Thomas Gleixnerff43a672011-02-06 18:23:29 +0000547 .irq_set_affinity = bfin_internal_set_affinity,
Sonic Zhang0325f252009-12-28 07:29:57 +0000548#endif
Thomas Gleixnerff43a672011-02-06 18:23:29 +0000549 .irq_set_wake = bfin_internal_set_wake_chip,
Bryan Wu1394f032007-05-06 14:50:22 -0700550};
Sonic Zhang86794b42012-12-14 11:19:24 +0800551#else
Steven Miao4f6b6002012-05-16 17:56:51 +0800552static struct irq_chip bfin_sec_irqchip = {
553 .name = "SEC",
554 .irq_mask_ack = bfin_sec_mask_ack_irq,
555 .irq_mask = bfin_sec_mask_ack_irq,
556 .irq_unmask = bfin_sec_unmask_irq,
557 .irq_eoi = bfin_sec_unmask_irq,
558 .irq_disable = bfin_sec_disable,
559 .irq_enable = bfin_sec_enable,
560};
561#endif
562
Mike Frysingerf58c3272011-04-15 03:08:20 -0400563void bfin_handle_irq(unsigned irq)
Yi Li6a01f232009-01-07 23:14:39 +0800564{
565#ifdef CONFIG_IPIPE
566 struct pt_regs regs; /* Contents not used. */
567 ipipe_trace_irq_entry(irq);
568 __ipipe_handle_irq(irq, &regs);
569 ipipe_trace_irq_exit(irq);
570#else /* !CONFIG_IPIPE */
Thomas Gleixnerb10bbbb2011-02-06 18:23:25 +0000571 generic_handle_irq(irq);
Yi Li6a01f232009-01-07 23:14:39 +0800572#endif /* !CONFIG_IPIPE */
573}
574
Michael Hennerichaec59c92010-02-19 15:09:10 +0000575#if defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE)
576static int mac_stat_int_mask;
577
578static void bfin_mac_status_ack_irq(unsigned int irq)
579{
580 switch (irq) {
581 case IRQ_MAC_MMCINT:
582 bfin_write_EMAC_MMC_TIRQS(
583 bfin_read_EMAC_MMC_TIRQE() &
584 bfin_read_EMAC_MMC_TIRQS());
585 bfin_write_EMAC_MMC_RIRQS(
586 bfin_read_EMAC_MMC_RIRQE() &
587 bfin_read_EMAC_MMC_RIRQS());
588 break;
589 case IRQ_MAC_RXFSINT:
590 bfin_write_EMAC_RX_STKY(
591 bfin_read_EMAC_RX_IRQE() &
592 bfin_read_EMAC_RX_STKY());
593 break;
594 case IRQ_MAC_TXFSINT:
595 bfin_write_EMAC_TX_STKY(
596 bfin_read_EMAC_TX_IRQE() &
597 bfin_read_EMAC_TX_STKY());
598 break;
599 case IRQ_MAC_WAKEDET:
600 bfin_write_EMAC_WKUP_CTL(
601 bfin_read_EMAC_WKUP_CTL() | MPKS | RWKS);
602 break;
603 default:
604 /* These bits are W1C */
605 bfin_write_EMAC_SYSTAT(1L << (irq - IRQ_MAC_PHYINT));
606 break;
607 }
608}
609
Thomas Gleixner172d2d12011-02-06 18:23:34 +0000610static void bfin_mac_status_mask_irq(struct irq_data *d)
Michael Hennerichaec59c92010-02-19 15:09:10 +0000611{
Thomas Gleixner172d2d12011-02-06 18:23:34 +0000612 unsigned int irq = d->irq;
613
Michael Hennerichaec59c92010-02-19 15:09:10 +0000614 mac_stat_int_mask &= ~(1L << (irq - IRQ_MAC_PHYINT));
Mike Frysingerf58c3272011-04-15 03:08:20 -0400615#ifdef BF537_FAMILY
Michael Hennerichaec59c92010-02-19 15:09:10 +0000616 switch (irq) {
617 case IRQ_MAC_PHYINT:
618 bfin_write_EMAC_SYSCTL(bfin_read_EMAC_SYSCTL() & ~PHYIE);
619 break;
620 default:
621 break;
622 }
623#else
624 if (!mac_stat_int_mask)
625 bfin_internal_mask_irq(IRQ_MAC_ERROR);
626#endif
627 bfin_mac_status_ack_irq(irq);
628}
629
Thomas Gleixner172d2d12011-02-06 18:23:34 +0000630static void bfin_mac_status_unmask_irq(struct irq_data *d)
Michael Hennerichaec59c92010-02-19 15:09:10 +0000631{
Thomas Gleixner172d2d12011-02-06 18:23:34 +0000632 unsigned int irq = d->irq;
633
Mike Frysingerf58c3272011-04-15 03:08:20 -0400634#ifdef BF537_FAMILY
Michael Hennerichaec59c92010-02-19 15:09:10 +0000635 switch (irq) {
636 case IRQ_MAC_PHYINT:
637 bfin_write_EMAC_SYSCTL(bfin_read_EMAC_SYSCTL() | PHYIE);
638 break;
639 default:
640 break;
641 }
642#else
643 if (!mac_stat_int_mask)
644 bfin_internal_unmask_irq(IRQ_MAC_ERROR);
645#endif
646 mac_stat_int_mask |= 1L << (irq - IRQ_MAC_PHYINT);
647}
648
649#ifdef CONFIG_PM
Thomas Gleixner172d2d12011-02-06 18:23:34 +0000650int bfin_mac_status_set_wake(struct irq_data *d, unsigned int state)
Michael Hennerichaec59c92010-02-19 15:09:10 +0000651{
Mike Frysingerf58c3272011-04-15 03:08:20 -0400652#ifdef BF537_FAMILY
Michael Hennerichaec59c92010-02-19 15:09:10 +0000653 return bfin_internal_set_wake(IRQ_GENERIC_ERROR, state);
654#else
655 return bfin_internal_set_wake(IRQ_MAC_ERROR, state);
656#endif
657}
Mike Frysingerfc6bd7b2011-04-15 01:35:53 -0400658#else
659# define bfin_mac_status_set_wake NULL
Michael Hennerichaec59c92010-02-19 15:09:10 +0000660#endif
661
662static struct irq_chip bfin_mac_status_irqchip = {
663 .name = "MACST",
Thomas Gleixner172d2d12011-02-06 18:23:34 +0000664 .irq_mask = bfin_mac_status_mask_irq,
665 .irq_unmask = bfin_mac_status_unmask_irq,
Thomas Gleixner172d2d12011-02-06 18:23:34 +0000666 .irq_set_wake = bfin_mac_status_set_wake,
Michael Hennerichaec59c92010-02-19 15:09:10 +0000667};
668
Mike Frysingerf58c3272011-04-15 03:08:20 -0400669void bfin_demux_mac_status_irq(unsigned int int_err_irq,
670 struct irq_desc *inta_desc)
Michael Hennerichaec59c92010-02-19 15:09:10 +0000671{
672 int i, irq = 0;
673 u32 status = bfin_read_EMAC_SYSTAT();
674
Michael Hennerichbedeea62010-08-20 11:59:27 +0000675 for (i = 0; i <= (IRQ_MAC_STMDONE - IRQ_MAC_PHYINT); i++)
Michael Hennerichaec59c92010-02-19 15:09:10 +0000676 if (status & (1L << i)) {
677 irq = IRQ_MAC_PHYINT + i;
678 break;
679 }
680
681 if (irq) {
682 if (mac_stat_int_mask & (1L << (irq - IRQ_MAC_PHYINT))) {
683 bfin_handle_irq(irq);
684 } else {
685 bfin_mac_status_ack_irq(irq);
686 pr_debug("IRQ %d:"
Steven Miao4f6b6002012-05-16 17:56:51 +0800687 " MASKED MAC ERROR INTERRUPT ASSERTED\n",
688 irq);
Michael Hennerichaec59c92010-02-19 15:09:10 +0000689 }
690 } else
691 printk(KERN_ERR
Steven Miao4f6b6002012-05-16 17:56:51 +0800692 "%s : %s : LINE %d :\nIRQ ?: MAC ERROR"
693 " INTERRUPT ASSERTED BUT NO SOURCE FOUND"
694 "(EMAC_SYSTAT=0x%X)\n",
695 __func__, __FILE__, __LINE__, status);
Michael Hennerichaec59c92010-02-19 15:09:10 +0000696}
697#endif
698
Graf Yangbfd15112008-10-08 18:02:44 +0800699static inline void bfin_set_irq_handler(unsigned irq, irq_flow_handler_t handle)
700{
Yi Li6a01f232009-01-07 23:14:39 +0800701#ifdef CONFIG_IPIPE
Philippe Gerum5b5da4c2011-03-17 02:12:48 -0400702 handle = handle_level_irq;
Yi Li6a01f232009-01-07 23:14:39 +0800703#endif
Thomas Gleixner43f2f112011-03-24 17:22:30 +0100704 __irq_set_handler_locked(irq, handle);
Graf Yangbfd15112008-10-08 18:02:44 +0800705}
706
Michael Hennerich8d022372008-11-18 17:48:22 +0800707static DECLARE_BITMAP(gpio_enabled, MAX_BLACKFIN_GPIOS);
Michael Hennerichaffee2b2008-04-24 08:10:10 +0800708extern void bfin_gpio_irq_prepare(unsigned gpio);
Michael Hennerich6fce6a82007-12-24 16:56:12 +0800709
Mike Frysinger01f8e342011-06-26 13:56:23 -0400710#if !BFIN_GPIO_PINT
Michael Hennerich8d022372008-11-18 17:48:22 +0800711
Thomas Gleixnere9502852011-02-06 18:23:36 +0000712static void bfin_gpio_ack_irq(struct irq_data *d)
Bryan Wu1394f032007-05-06 14:50:22 -0700713{
Michael Hennerich8d022372008-11-18 17:48:22 +0800714 /* AFAIK ack_irq in case mask_ack is provided
715 * get's only called for edge sense irqs
716 */
Thomas Gleixnere9502852011-02-06 18:23:36 +0000717 set_gpio_data(irq_to_gpio(d->irq), 0);
Bryan Wu1394f032007-05-06 14:50:22 -0700718}
719
Thomas Gleixnere9502852011-02-06 18:23:36 +0000720static void bfin_gpio_mask_ack_irq(struct irq_data *d)
Bryan Wu1394f032007-05-06 14:50:22 -0700721{
Thomas Gleixnere9502852011-02-06 18:23:36 +0000722 unsigned int irq = d->irq;
Michael Hennerich8d022372008-11-18 17:48:22 +0800723 u32 gpionr = irq_to_gpio(irq);
Bryan Wu1394f032007-05-06 14:50:22 -0700724
Thomas Gleixner1907d8b2011-03-24 17:21:01 +0100725 if (!irqd_is_level_type(d))
Bryan Wu1394f032007-05-06 14:50:22 -0700726 set_gpio_data(gpionr, 0);
Bryan Wu1394f032007-05-06 14:50:22 -0700727
728 set_gpio_maska(gpionr, 0);
Bryan Wu1394f032007-05-06 14:50:22 -0700729}
730
Thomas Gleixnere9502852011-02-06 18:23:36 +0000731static void bfin_gpio_mask_irq(struct irq_data *d)
Bryan Wu1394f032007-05-06 14:50:22 -0700732{
Thomas Gleixnere9502852011-02-06 18:23:36 +0000733 set_gpio_maska(irq_to_gpio(d->irq), 0);
Bryan Wu1394f032007-05-06 14:50:22 -0700734}
735
Thomas Gleixnere9502852011-02-06 18:23:36 +0000736static void bfin_gpio_unmask_irq(struct irq_data *d)
Bryan Wu1394f032007-05-06 14:50:22 -0700737{
Thomas Gleixnere9502852011-02-06 18:23:36 +0000738 set_gpio_maska(irq_to_gpio(d->irq), 1);
Bryan Wu1394f032007-05-06 14:50:22 -0700739}
740
Thomas Gleixnere9502852011-02-06 18:23:36 +0000741static unsigned int bfin_gpio_irq_startup(struct irq_data *d)
Bryan Wu1394f032007-05-06 14:50:22 -0700742{
Thomas Gleixnere9502852011-02-06 18:23:36 +0000743 u32 gpionr = irq_to_gpio(d->irq);
Bryan Wu1394f032007-05-06 14:50:22 -0700744
Michael Hennerich8d022372008-11-18 17:48:22 +0800745 if (__test_and_set_bit(gpionr, gpio_enabled))
Michael Hennerichaffee2b2008-04-24 08:10:10 +0800746 bfin_gpio_irq_prepare(gpionr);
Bryan Wu1394f032007-05-06 14:50:22 -0700747
Thomas Gleixnere9502852011-02-06 18:23:36 +0000748 bfin_gpio_unmask_irq(d);
Bryan Wu1394f032007-05-06 14:50:22 -0700749
Michael Hennerichaffee2b2008-04-24 08:10:10 +0800750 return 0;
Bryan Wu1394f032007-05-06 14:50:22 -0700751}
752
Thomas Gleixnere9502852011-02-06 18:23:36 +0000753static void bfin_gpio_irq_shutdown(struct irq_data *d)
Bryan Wu1394f032007-05-06 14:50:22 -0700754{
Thomas Gleixnere9502852011-02-06 18:23:36 +0000755 u32 gpionr = irq_to_gpio(d->irq);
Graf Yang30af6d42008-11-18 17:48:21 +0800756
Thomas Gleixnere9502852011-02-06 18:23:36 +0000757 bfin_gpio_mask_irq(d);
Graf Yang30af6d42008-11-18 17:48:21 +0800758 __clear_bit(gpionr, gpio_enabled);
Graf Yang9570ff42009-01-07 23:14:38 +0800759 bfin_gpio_irq_free(gpionr);
Bryan Wu1394f032007-05-06 14:50:22 -0700760}
761
Thomas Gleixnere9502852011-02-06 18:23:36 +0000762static int bfin_gpio_irq_type(struct irq_data *d, unsigned int type)
Bryan Wu1394f032007-05-06 14:50:22 -0700763{
Thomas Gleixnere9502852011-02-06 18:23:36 +0000764 unsigned int irq = d->irq;
Graf Yang8eb3e3b2008-11-18 17:48:22 +0800765 int ret;
766 char buf[16];
Michael Hennerich8d022372008-11-18 17:48:22 +0800767 u32 gpionr = irq_to_gpio(irq);
Bryan Wu1394f032007-05-06 14:50:22 -0700768
769 if (type == IRQ_TYPE_PROBE) {
770 /* only probe unenabled GPIO interrupt lines */
Mike Frysingerc3695342009-06-13 10:32:29 -0400771 if (test_bit(gpionr, gpio_enabled))
Bryan Wu1394f032007-05-06 14:50:22 -0700772 return 0;
773 type = IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING;
774 }
775
776 if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING |
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800777 IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW)) {
Michael Hennerich8d022372008-11-18 17:48:22 +0800778
Graf Yang9570ff42009-01-07 23:14:38 +0800779 snprintf(buf, 16, "gpio-irq%d", irq);
780 ret = bfin_gpio_irq_request(gpionr, buf);
781 if (ret)
782 return ret;
783
Michael Hennerich8d022372008-11-18 17:48:22 +0800784 if (__test_and_set_bit(gpionr, gpio_enabled))
Michael Hennerichaffee2b2008-04-24 08:10:10 +0800785 bfin_gpio_irq_prepare(gpionr);
Bryan Wu1394f032007-05-06 14:50:22 -0700786
Bryan Wu1394f032007-05-06 14:50:22 -0700787 } else {
Michael Hennerich8d022372008-11-18 17:48:22 +0800788 __clear_bit(gpionr, gpio_enabled);
Bryan Wu1394f032007-05-06 14:50:22 -0700789 return 0;
790 }
791
Michael Hennerichf1bceb42008-02-02 16:17:52 +0800792 set_gpio_inen(gpionr, 0);
Bryan Wu1394f032007-05-06 14:50:22 -0700793 set_gpio_dir(gpionr, 0);
Bryan Wu1394f032007-05-06 14:50:22 -0700794
795 if ((type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING))
796 == (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING))
797 set_gpio_both(gpionr, 1);
798 else
799 set_gpio_both(gpionr, 0);
800
801 if ((type & (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_LEVEL_LOW)))
802 set_gpio_polar(gpionr, 1); /* low or falling edge denoted by one */
803 else
804 set_gpio_polar(gpionr, 0); /* high or rising edge denoted by zero */
805
Michael Hennerichf1bceb42008-02-02 16:17:52 +0800806 if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING)) {
807 set_gpio_edge(gpionr, 1);
808 set_gpio_inen(gpionr, 1);
Michael Hennerichf1bceb42008-02-02 16:17:52 +0800809 set_gpio_data(gpionr, 0);
810
811 } else {
812 set_gpio_edge(gpionr, 0);
Michael Hennerichf1bceb42008-02-02 16:17:52 +0800813 set_gpio_inen(gpionr, 1);
814 }
815
Bryan Wu1394f032007-05-06 14:50:22 -0700816 if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING))
Graf Yangbfd15112008-10-08 18:02:44 +0800817 bfin_set_irq_handler(irq, handle_edge_irq);
Bryan Wu1394f032007-05-06 14:50:22 -0700818 else
Graf Yangbfd15112008-10-08 18:02:44 +0800819 bfin_set_irq_handler(irq, handle_level_irq);
Bryan Wu1394f032007-05-06 14:50:22 -0700820
821 return 0;
822}
823
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800824#ifdef CONFIG_PM
Mike Frysingerdd8cb372011-04-15 03:19:22 -0400825static int bfin_gpio_set_wake(struct irq_data *d, unsigned int state)
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800826{
Thomas Gleixnere9502852011-02-06 18:23:36 +0000827 return gpio_pm_wakeup_ctrl(irq_to_gpio(d->irq), state);
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800828}
Mike Frysingerfc6bd7b2011-04-15 01:35:53 -0400829#else
830# define bfin_gpio_set_wake NULL
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800831#endif
832
Mike Frysingere2a80922011-04-15 12:51:33 -0400833static void bfin_demux_gpio_block(unsigned int irq)
834{
835 unsigned int gpio, mask;
836
837 gpio = irq_to_gpio(irq);
838 mask = get_gpiop_data(gpio) & get_gpiop_maska(gpio);
839
840 while (mask) {
841 if (mask & 1)
842 bfin_handle_irq(irq);
843 irq++;
844 mask >>= 1;
845 }
846}
847
Mike Frysinger8c054102011-04-15 13:04:59 -0400848void bfin_demux_gpio_irq(unsigned int inta_irq,
Steven Miao4f6b6002012-05-16 17:56:51 +0800849 struct irq_desc *desc)
Bryan Wu1394f032007-05-06 14:50:22 -0700850{
Mike Frysingere2a80922011-04-15 12:51:33 -0400851 unsigned int irq;
Bryan Wu1394f032007-05-06 14:50:22 -0700852
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800853 switch (inta_irq) {
Mike Frysingere2a80922011-04-15 12:51:33 -0400854#if defined(BF537_FAMILY)
Mike Frysinger8c054102011-04-15 13:04:59 -0400855 case IRQ_PF_INTA_PG_INTA:
Mike Frysingere2a80922011-04-15 12:51:33 -0400856 bfin_demux_gpio_block(IRQ_PF0);
857 irq = IRQ_PG0;
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800858 break;
Mike Frysinger8c054102011-04-15 13:04:59 -0400859 case IRQ_PH_INTA_MAC_RX:
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800860 irq = IRQ_PH0;
861 break;
Mike Frysingere2a80922011-04-15 12:51:33 -0400862#elif defined(BF533_FAMILY)
863 case IRQ_PROG_INTA:
864 irq = IRQ_PF0;
865 break;
Mike Frysingerfc6bd7b2011-04-15 01:35:53 -0400866#elif defined(BF538_FAMILY)
Michael Hennerichdc26aec2008-11-18 17:48:22 +0800867 case IRQ_PORTF_INTA:
868 irq = IRQ_PF0;
869 break;
Bryan Wu2f6f4bc2008-11-18 17:48:21 +0800870#elif defined(CONFIG_BF52x) || defined(CONFIG_BF51x)
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800871 case IRQ_PORTF_INTA:
872 irq = IRQ_PF0;
873 break;
874 case IRQ_PORTG_INTA:
875 irq = IRQ_PG0;
876 break;
877 case IRQ_PORTH_INTA:
878 irq = IRQ_PH0;
879 break;
880#elif defined(CONFIG_BF561)
881 case IRQ_PROG0_INTA:
882 irq = IRQ_PF0;
883 break;
884 case IRQ_PROG1_INTA:
885 irq = IRQ_PF16;
886 break;
887 case IRQ_PROG2_INTA:
888 irq = IRQ_PF32;
889 break;
890#endif
891 default:
892 BUG();
893 return;
Bryan Wu1394f032007-05-06 14:50:22 -0700894 }
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800895
Mike Frysingere2a80922011-04-15 12:51:33 -0400896 bfin_demux_gpio_block(irq);
Bryan Wu1394f032007-05-06 14:50:22 -0700897}
898
Mike Frysinger01f8e342011-06-26 13:56:23 -0400899#else
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800900
Steven Miao4f6b6002012-05-16 17:56:51 +0800901#define NR_PINT_BITS 32
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800902#define IRQ_NOT_AVAIL 0xFF
903
904#define PINT_2_BANK(x) ((x) >> 5)
905#define PINT_2_BIT(x) ((x) & 0x1F)
906#define PINT_BIT(x) (1 << (PINT_2_BIT(x)))
907
908static unsigned char irq2pint_lut[NR_PINTS];
Michael Henneriche3f23002007-07-12 16:39:29 +0800909static unsigned char pint2irq_lut[NR_PINT_SYS_IRQS * NR_PINT_BITS];
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800910
Mike Frysinger82ed5f72011-06-26 13:22:05 -0400911static struct bfin_pint_regs * const pint[NR_PINT_SYS_IRQS] = {
912 (struct bfin_pint_regs *)PINT0_MASK_SET,
913 (struct bfin_pint_regs *)PINT1_MASK_SET,
914 (struct bfin_pint_regs *)PINT2_MASK_SET,
915 (struct bfin_pint_regs *)PINT3_MASK_SET,
Steven Miao4f6b6002012-05-16 17:56:51 +0800916#ifdef CONFIG_BF60x
917 (struct bfin_pint_regs *)PINT4_MASK_SET,
918 (struct bfin_pint_regs *)PINT5_MASK_SET,
919#endif
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800920};
921
Michael Hennerich8d022372008-11-18 17:48:22 +0800922inline unsigned int get_irq_base(u32 bank, u8 bmap)
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800923{
Michael Hennerich8d022372008-11-18 17:48:22 +0800924 unsigned int irq_base;
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800925
Sonic Zhang11b27cb2012-06-28 19:16:48 +0800926#ifndef CONFIG_BF60x
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800927 if (bank < 2) { /*PA-PB */
928 irq_base = IRQ_PA0 + bmap * 16;
929 } else { /*PC-PJ */
930 irq_base = IRQ_PC0 + bmap * 16;
931 }
Steven Miao4f6b6002012-05-16 17:56:51 +0800932#else
Steven Miao4f6b6002012-05-16 17:56:51 +0800933 irq_base = IRQ_PA0 + bank * 16 + bmap * 16;
Sonic Zhang11b27cb2012-06-28 19:16:48 +0800934#endif
Steven Miao4f6b6002012-05-16 17:56:51 +0800935 return irq_base;
936}
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800937
938 /* Whenever PINTx_ASSIGN is altered init_pint_lut() must be executed! */
939void init_pint_lut(void)
940{
941 u16 bank, bit, irq_base, bit_pos;
942 u32 pint_assign;
943 u8 bmap;
944
945 memset(irq2pint_lut, IRQ_NOT_AVAIL, sizeof(irq2pint_lut));
946
947 for (bank = 0; bank < NR_PINT_SYS_IRQS; bank++) {
948
949 pint_assign = pint[bank]->assign;
950
951 for (bit = 0; bit < NR_PINT_BITS; bit++) {
952
953 bmap = (pint_assign >> ((bit / 8) * 8)) & 0xFF;
954
955 irq_base = get_irq_base(bank, bmap);
956
957 irq_base += (bit % 8) + ((bit / 8) & 1 ? 8 : 0);
958 bit_pos = bit + bank * NR_PINT_BITS;
959
Michael Henneriche3f23002007-07-12 16:39:29 +0800960 pint2irq_lut[bit_pos] = irq_base - SYS_IRQS;
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800961 irq2pint_lut[irq_base - SYS_IRQS] = bit_pos;
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800962 }
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800963 }
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800964}
965
Thomas Gleixnere9502852011-02-06 18:23:36 +0000966static void bfin_gpio_ack_irq(struct irq_data *d)
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800967{
Thomas Gleixnere9502852011-02-06 18:23:36 +0000968 u32 pint_val = irq2pint_lut[d->irq - SYS_IRQS];
Michael Hennerich8baf5602007-12-24 18:51:34 +0800969 u32 pintbit = PINT_BIT(pint_val);
Michael Hennerich8d022372008-11-18 17:48:22 +0800970 u32 bank = PINT_2_BANK(pint_val);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800971
Thomas Gleixner1907d8b2011-03-24 17:21:01 +0100972 if (irqd_get_trigger_type(d) == IRQ_TYPE_EDGE_BOTH) {
Michael Hennerich8baf5602007-12-24 18:51:34 +0800973 if (pint[bank]->invert_set & pintbit)
974 pint[bank]->invert_clear = pintbit;
975 else
976 pint[bank]->invert_set = pintbit;
977 }
978 pint[bank]->request = pintbit;
979
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800980}
981
Thomas Gleixnere9502852011-02-06 18:23:36 +0000982static void bfin_gpio_mask_ack_irq(struct irq_data *d)
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800983{
Thomas Gleixnere9502852011-02-06 18:23:36 +0000984 u32 pint_val = irq2pint_lut[d->irq - SYS_IRQS];
Michael Henneriche3f23002007-07-12 16:39:29 +0800985 u32 pintbit = PINT_BIT(pint_val);
Michael Hennerich8d022372008-11-18 17:48:22 +0800986 u32 bank = PINT_2_BANK(pint_val);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800987
Thomas Gleixner1907d8b2011-03-24 17:21:01 +0100988 if (irqd_get_trigger_type(d) == IRQ_TYPE_EDGE_BOTH) {
Michael Hennerich8baf5602007-12-24 18:51:34 +0800989 if (pint[bank]->invert_set & pintbit)
990 pint[bank]->invert_clear = pintbit;
991 else
992 pint[bank]->invert_set = pintbit;
993 }
994
Michael Henneriche3f23002007-07-12 16:39:29 +0800995 pint[bank]->request = pintbit;
996 pint[bank]->mask_clear = pintbit;
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800997}
998
Thomas Gleixnere9502852011-02-06 18:23:36 +0000999static void bfin_gpio_mask_irq(struct irq_data *d)
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001000{
Thomas Gleixnere9502852011-02-06 18:23:36 +00001001 u32 pint_val = irq2pint_lut[d->irq - SYS_IRQS];
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001002
1003 pint[PINT_2_BANK(pint_val)]->mask_clear = PINT_BIT(pint_val);
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001004}
1005
Thomas Gleixnere9502852011-02-06 18:23:36 +00001006static void bfin_gpio_unmask_irq(struct irq_data *d)
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001007{
Thomas Gleixnere9502852011-02-06 18:23:36 +00001008 u32 pint_val = irq2pint_lut[d->irq - SYS_IRQS];
Michael Henneriche3f23002007-07-12 16:39:29 +08001009 u32 pintbit = PINT_BIT(pint_val);
Michael Hennerich8d022372008-11-18 17:48:22 +08001010 u32 bank = PINT_2_BANK(pint_val);
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001011
Michael Henneriche3f23002007-07-12 16:39:29 +08001012 pint[bank]->mask_set = pintbit;
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001013}
1014
Thomas Gleixnere9502852011-02-06 18:23:36 +00001015static unsigned int bfin_gpio_irq_startup(struct irq_data *d)
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001016{
Thomas Gleixnere9502852011-02-06 18:23:36 +00001017 unsigned int irq = d->irq;
Michael Hennerich8d022372008-11-18 17:48:22 +08001018 u32 gpionr = irq_to_gpio(irq);
1019 u32 pint_val = irq2pint_lut[irq - SYS_IRQS];
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001020
Michael Hennerich50e163c2007-07-24 16:17:28 +08001021 if (pint_val == IRQ_NOT_AVAIL) {
1022 printk(KERN_ERR
1023 "GPIO IRQ %d :Not in PINT Assign table "
1024 "Reconfigure Interrupt to Port Assignemt\n", irq);
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001025 return -ENODEV;
Michael Hennerich50e163c2007-07-24 16:17:28 +08001026 }
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001027
Michael Hennerich8d022372008-11-18 17:48:22 +08001028 if (__test_and_set_bit(gpionr, gpio_enabled))
Michael Hennerichaffee2b2008-04-24 08:10:10 +08001029 bfin_gpio_irq_prepare(gpionr);
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001030
Thomas Gleixnere9502852011-02-06 18:23:36 +00001031 bfin_gpio_unmask_irq(d);
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001032
Michael Hennerichaffee2b2008-04-24 08:10:10 +08001033 return 0;
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001034}
1035
Thomas Gleixnere9502852011-02-06 18:23:36 +00001036static void bfin_gpio_irq_shutdown(struct irq_data *d)
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001037{
Thomas Gleixnere9502852011-02-06 18:23:36 +00001038 u32 gpionr = irq_to_gpio(d->irq);
Michael Hennerich8baf5602007-12-24 18:51:34 +08001039
Thomas Gleixnere9502852011-02-06 18:23:36 +00001040 bfin_gpio_mask_irq(d);
Michael Hennerich8d022372008-11-18 17:48:22 +08001041 __clear_bit(gpionr, gpio_enabled);
Graf Yang9570ff42009-01-07 23:14:38 +08001042 bfin_gpio_irq_free(gpionr);
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001043}
1044
Thomas Gleixnere9502852011-02-06 18:23:36 +00001045static int bfin_gpio_irq_type(struct irq_data *d, unsigned int type)
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001046{
Thomas Gleixnere9502852011-02-06 18:23:36 +00001047 unsigned int irq = d->irq;
Graf Yang8eb3e3b2008-11-18 17:48:22 +08001048 int ret;
1049 char buf[16];
Michael Hennerich8d022372008-11-18 17:48:22 +08001050 u32 gpionr = irq_to_gpio(irq);
1051 u32 pint_val = irq2pint_lut[irq - SYS_IRQS];
Michael Henneriche3f23002007-07-12 16:39:29 +08001052 u32 pintbit = PINT_BIT(pint_val);
Michael Hennerich8d022372008-11-18 17:48:22 +08001053 u32 bank = PINT_2_BANK(pint_val);
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001054
1055 if (pint_val == IRQ_NOT_AVAIL)
1056 return -ENODEV;
1057
1058 if (type == IRQ_TYPE_PROBE) {
1059 /* only probe unenabled GPIO interrupt lines */
Mike Frysingerc3695342009-06-13 10:32:29 -04001060 if (test_bit(gpionr, gpio_enabled))
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001061 return 0;
1062 type = IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING;
1063 }
1064
1065 if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING |
1066 IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW)) {
Graf Yang9570ff42009-01-07 23:14:38 +08001067
1068 snprintf(buf, 16, "gpio-irq%d", irq);
1069 ret = bfin_gpio_irq_request(gpionr, buf);
1070 if (ret)
1071 return ret;
1072
Michael Hennerich8d022372008-11-18 17:48:22 +08001073 if (__test_and_set_bit(gpionr, gpio_enabled))
Michael Hennerichaffee2b2008-04-24 08:10:10 +08001074 bfin_gpio_irq_prepare(gpionr);
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001075
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001076 } else {
Michael Hennerich8d022372008-11-18 17:48:22 +08001077 __clear_bit(gpionr, gpio_enabled);
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001078 return 0;
1079 }
1080
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001081 if ((type & (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_LEVEL_LOW)))
Michael Henneriche3f23002007-07-12 16:39:29 +08001082 pint[bank]->invert_set = pintbit; /* low or falling edge denoted by one */
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001083 else
Michael Hennerich8baf5602007-12-24 18:51:34 +08001084 pint[bank]->invert_clear = pintbit; /* high or rising edge denoted by zero */
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001085
Michael Hennerich8baf5602007-12-24 18:51:34 +08001086 if ((type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING))
1087 == (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING)) {
Michael Hennerich8baf5602007-12-24 18:51:34 +08001088 if (gpio_get_value(gpionr))
1089 pint[bank]->invert_set = pintbit;
1090 else
1091 pint[bank]->invert_clear = pintbit;
Michael Hennerich8baf5602007-12-24 18:51:34 +08001092 }
1093
1094 if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING)) {
1095 pint[bank]->edge_set = pintbit;
Graf Yangbfd15112008-10-08 18:02:44 +08001096 bfin_set_irq_handler(irq, handle_edge_irq);
Michael Hennerich8baf5602007-12-24 18:51:34 +08001097 } else {
1098 pint[bank]->edge_clear = pintbit;
Graf Yangbfd15112008-10-08 18:02:44 +08001099 bfin_set_irq_handler(irq, handle_level_irq);
Michael Hennerich8baf5602007-12-24 18:51:34 +08001100 }
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001101
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001102 return 0;
1103}
1104
Michael Hennerichcfefe3c2008-02-09 04:12:37 +08001105#ifdef CONFIG_PM
Steven Miaod49cdf8402012-06-14 18:04:01 +08001106static struct bfin_pm_pint_save save_pint_reg[NR_PINT_SYS_IRQS];
1107static u32 save_pint_sec_ctl[NR_PINT_SYS_IRQS];
1108
Mike Frysingerdd8cb372011-04-15 03:19:22 -04001109static int bfin_gpio_set_wake(struct irq_data *d, unsigned int state)
Michael Hennerichcfefe3c2008-02-09 04:12:37 +08001110{
1111 u32 pint_irq;
Thomas Gleixnere9502852011-02-06 18:23:36 +00001112 u32 pint_val = irq2pint_lut[d->irq - SYS_IRQS];
Michael Hennerichcfefe3c2008-02-09 04:12:37 +08001113 u32 bank = PINT_2_BANK(pint_val);
Michael Hennerichcfefe3c2008-02-09 04:12:37 +08001114
1115 switch (bank) {
1116 case 0:
1117 pint_irq = IRQ_PINT0;
1118 break;
1119 case 2:
1120 pint_irq = IRQ_PINT2;
1121 break;
1122 case 3:
1123 pint_irq = IRQ_PINT3;
1124 break;
1125 case 1:
1126 pint_irq = IRQ_PINT1;
1127 break;
Bob Liu494b7942012-04-27 14:13:01 +08001128#ifdef CONFIG_BF60x
Steven Miao4f6b6002012-05-16 17:56:51 +08001129 case 4:
1130 pint_irq = IRQ_PINT4;
1131 break;
1132 case 5:
1133 pint_irq = IRQ_PINT5;
1134 break;
Bob Liu494b7942012-04-27 14:13:01 +08001135#endif
Michael Hennerichcfefe3c2008-02-09 04:12:37 +08001136 default:
1137 return -EINVAL;
1138 }
1139
Sonic Zhang86794b42012-12-14 11:19:24 +08001140#ifndef SEC_GCTL
Michael Hennerichcfefe3c2008-02-09 04:12:37 +08001141 bfin_internal_set_wake(pint_irq, state);
Sonic Zhang86794b42012-12-14 11:19:24 +08001142#endif
Michael Hennerichcfefe3c2008-02-09 04:12:37 +08001143
Michael Hennerichcfefe3c2008-02-09 04:12:37 +08001144 return 0;
1145}
Steven Miaod49cdf8402012-06-14 18:04:01 +08001146
1147void bfin_pint_suspend(void)
1148{
1149 u32 bank;
1150
1151 for (bank = 0; bank < NR_PINT_SYS_IRQS; bank++) {
1152 save_pint_reg[bank].mask_set = pint[bank]->mask_set;
1153 save_pint_reg[bank].assign = pint[bank]->assign;
1154 save_pint_reg[bank].edge_set = pint[bank]->edge_set;
1155 save_pint_reg[bank].invert_set = pint[bank]->invert_set;
1156 }
1157}
1158
1159void bfin_pint_resume(void)
1160{
1161 u32 bank;
1162
1163 for (bank = 0; bank < NR_PINT_SYS_IRQS; bank++) {
1164 pint[bank]->mask_set = save_pint_reg[bank].mask_set;
1165 pint[bank]->assign = save_pint_reg[bank].assign;
1166 pint[bank]->edge_set = save_pint_reg[bank].edge_set;
1167 pint[bank]->invert_set = save_pint_reg[bank].invert_set;
1168 }
1169}
1170
Sonic Zhang11b27cb2012-06-28 19:16:48 +08001171#ifdef SEC_GCTL
Steven Miaod49cdf8402012-06-14 18:04:01 +08001172static int sec_suspend(void)
1173{
1174 u32 bank;
1175
1176 for (bank = 0; bank < NR_PINT_SYS_IRQS; bank++)
Sonic Zhang86794b42012-12-14 11:19:24 +08001177 save_pint_sec_ctl[bank] = bfin_read_SEC_SCTL(bank + BFIN_SYSIRQ(IRQ_PINT0));
Steven Miaod49cdf8402012-06-14 18:04:01 +08001178 return 0;
1179}
1180
1181static void sec_resume(void)
1182{
1183 u32 bank;
1184
1185 bfin_write_SEC_SCI(0, SEC_CCTL, SEC_CCTL_RESET);
1186 udelay(100);
1187 bfin_write_SEC_GCTL(SEC_GCTL_EN);
1188 bfin_write_SEC_SCI(0, SEC_CCTL, SEC_CCTL_EN | SEC_CCTL_NMI_EN);
1189
1190 for (bank = 0; bank < NR_PINT_SYS_IRQS; bank++)
Sonic Zhang86794b42012-12-14 11:19:24 +08001191 bfin_write_SEC_SCTL(bank + BFIN_SYSIRQ(IRQ_PINT0), save_pint_sec_ctl[bank]);
Steven Miaod49cdf8402012-06-14 18:04:01 +08001192}
1193
1194static struct syscore_ops sec_pm_syscore_ops = {
1195 .suspend = sec_suspend,
1196 .resume = sec_resume,
1197};
Steven Miao3375a432012-06-15 12:59:19 +08001198#endif
Mike Frysingerfc6bd7b2011-04-15 01:35:53 -04001199#else
1200# define bfin_gpio_set_wake NULL
Michael Hennerichcfefe3c2008-02-09 04:12:37 +08001201#endif
1202
Mike Frysinger8c054102011-04-15 13:04:59 -04001203void bfin_demux_gpio_irq(unsigned int inta_irq,
Steven Miao4f6b6002012-05-16 17:56:51 +08001204 struct irq_desc *desc)
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001205{
Michael Hennerich8d022372008-11-18 17:48:22 +08001206 u32 bank, pint_val;
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001207 u32 request, irq;
Steven Miao4f6b6002012-05-16 17:56:51 +08001208 u32 level_mask;
1209 int umask = 0;
1210 struct irq_chip *chip = irq_desc_get_chip(desc);
1211
1212 if (chip->irq_mask_ack) {
1213 chip->irq_mask_ack(&desc->irq_data);
1214 } else {
1215 chip->irq_mask(&desc->irq_data);
1216 if (chip->irq_ack)
1217 chip->irq_ack(&desc->irq_data);
1218 }
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001219
Michael Hennerich2c4f8292008-02-09 04:11:14 +08001220 switch (inta_irq) {
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001221 case IRQ_PINT0:
1222 bank = 0;
1223 break;
1224 case IRQ_PINT2:
1225 bank = 2;
1226 break;
1227 case IRQ_PINT3:
1228 bank = 3;
1229 break;
1230 case IRQ_PINT1:
1231 bank = 1;
1232 break;
Steven Miao4f6b6002012-05-16 17:56:51 +08001233#ifdef CONFIG_BF60x
1234 case IRQ_PINT4:
1235 bank = 4;
1236 break;
1237 case IRQ_PINT5:
1238 bank = 5;
1239 break;
1240#endif
Michael Henneriche3f23002007-07-12 16:39:29 +08001241 default:
1242 return;
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001243 }
1244
1245 pint_val = bank * NR_PINT_BITS;
1246
1247 request = pint[bank]->request;
1248
Steven Miao4f6b6002012-05-16 17:56:51 +08001249 level_mask = pint[bank]->edge_set & request;
1250
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001251 while (request) {
1252 if (request & 1) {
Michael Henneriche3f23002007-07-12 16:39:29 +08001253 irq = pint2irq_lut[pint_val] + SYS_IRQS;
Steven Miao4f6b6002012-05-16 17:56:51 +08001254 if (level_mask & PINT_BIT(pint_val)) {
1255 umask = 1;
1256 chip->irq_unmask(&desc->irq_data);
1257 }
Yi Li6a01f232009-01-07 23:14:39 +08001258 bfin_handle_irq(irq);
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001259 }
1260 pint_val++;
1261 request >>= 1;
1262 }
1263
Steven Miao4f6b6002012-05-16 17:56:51 +08001264 if (!umask)
1265 chip->irq_unmask(&desc->irq_data);
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001266}
Mike Frysingera055b2b2007-11-15 21:12:32 +08001267#endif
Bryan Wu1394f032007-05-06 14:50:22 -07001268
Michael Hennerich8d022372008-11-18 17:48:22 +08001269static struct irq_chip bfin_gpio_irqchip = {
1270 .name = "GPIO",
Thomas Gleixnere9502852011-02-06 18:23:36 +00001271 .irq_ack = bfin_gpio_ack_irq,
1272 .irq_mask = bfin_gpio_mask_irq,
1273 .irq_mask_ack = bfin_gpio_mask_ack_irq,
1274 .irq_unmask = bfin_gpio_unmask_irq,
1275 .irq_disable = bfin_gpio_mask_irq,
1276 .irq_enable = bfin_gpio_unmask_irq,
1277 .irq_set_type = bfin_gpio_irq_type,
1278 .irq_startup = bfin_gpio_irq_startup,
1279 .irq_shutdown = bfin_gpio_irq_shutdown,
Thomas Gleixnere9502852011-02-06 18:23:36 +00001280 .irq_set_wake = bfin_gpio_set_wake,
Michael Hennerich8d022372008-11-18 17:48:22 +08001281};
1282
Graf Yang6b3087c2009-01-07 23:14:39 +08001283void __cpuinit init_exception_vectors(void)
Bernd Schmidt8be80ed2007-07-25 14:44:49 +08001284{
Mike Frysingerf0b5d122007-08-05 17:03:59 +08001285 /* cannot program in software:
1286 * evt0 - emulation (jtag)
1287 * evt1 - reset
1288 */
1289 bfin_write_EVT2(evt_nmi);
Bernd Schmidt8be80ed2007-07-25 14:44:49 +08001290 bfin_write_EVT3(trap);
1291 bfin_write_EVT5(evt_ivhw);
1292 bfin_write_EVT6(evt_timer);
1293 bfin_write_EVT7(evt_evt7);
1294 bfin_write_EVT8(evt_evt8);
1295 bfin_write_EVT9(evt_evt9);
1296 bfin_write_EVT10(evt_evt10);
1297 bfin_write_EVT11(evt_evt11);
1298 bfin_write_EVT12(evt_evt12);
1299 bfin_write_EVT13(evt_evt13);
Philippe Gerum9703a732009-06-22 18:23:48 +02001300 bfin_write_EVT14(evt_evt14);
Bernd Schmidt8be80ed2007-07-25 14:44:49 +08001301 bfin_write_EVT15(evt_system_call);
1302 CSYNC();
1303}
1304
Sonic Zhang11b27cb2012-06-28 19:16:48 +08001305#ifndef SEC_GCTL
Bryan Wu1394f032007-05-06 14:50:22 -07001306/*
1307 * This function should be called during kernel startup to initialize
1308 * the BFin IRQ handling routines.
1309 */
Michael Hennerich8d022372008-11-18 17:48:22 +08001310
Bryan Wu1394f032007-05-06 14:50:22 -07001311int __init init_arch_irq(void)
1312{
1313 int irq;
1314 unsigned long ilat = 0;
Mike Frysingerfc6bd7b2011-04-15 01:35:53 -04001315
Bryan Wu1394f032007-05-06 14:50:22 -07001316 /* Disable all the peripheral intrs - page 4-29 HW Ref manual */
Mike Frysingerfc6bd7b2011-04-15 01:35:53 -04001317#ifdef SIC_IMASK0
Roy Huang24a07a12007-07-12 22:41:45 +08001318 bfin_write_SIC_IMASK0(SIC_UNMASK_ALL);
1319 bfin_write_SIC_IMASK1(SIC_UNMASK_ALL);
Mike Frysingerfc6bd7b2011-04-15 01:35:53 -04001320# ifdef SIC_IMASK2
Michael Hennerich59003142007-10-21 16:54:27 +08001321 bfin_write_SIC_IMASK2(SIC_UNMASK_ALL);
Mike Frysingera055b2b2007-11-15 21:12:32 +08001322# endif
Steven Miao4f6b6002012-05-16 17:56:51 +08001323# if defined(CONFIG_SMP) || defined(CONFIG_ICC)
Graf Yang6b3087c2009-01-07 23:14:39 +08001324 bfin_write_SICB_IMASK0(SIC_UNMASK_ALL);
1325 bfin_write_SICB_IMASK1(SIC_UNMASK_ALL);
1326# endif
Roy Huang24a07a12007-07-12 22:41:45 +08001327#else
Bryan Wu1394f032007-05-06 14:50:22 -07001328 bfin_write_SIC_IMASK(SIC_UNMASK_ALL);
Roy Huang24a07a12007-07-12 22:41:45 +08001329#endif
Bryan Wu1394f032007-05-06 14:50:22 -07001330
1331 local_irq_disable();
1332
Mike Frysinger01f8e342011-06-26 13:56:23 -04001333#if BFIN_GPIO_PINT
Mike Frysingera055b2b2007-11-15 21:12:32 +08001334# ifdef CONFIG_PINTx_REASSIGN
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001335 pint[0]->assign = CONFIG_PINT0_ASSIGN;
1336 pint[1]->assign = CONFIG_PINT1_ASSIGN;
1337 pint[2]->assign = CONFIG_PINT2_ASSIGN;
1338 pint[3]->assign = CONFIG_PINT3_ASSIGN;
Mike Frysingera055b2b2007-11-15 21:12:32 +08001339# endif
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001340 /* Whenever PINTx_ASSIGN is altered init_pint_lut() must be executed! */
1341 init_pint_lut();
1342#endif
1343
1344 for (irq = 0; irq <= SYS_IRQS; irq++) {
Bryan Wu1394f032007-05-06 14:50:22 -07001345 if (irq <= IRQ_CORETMR)
Thomas Gleixner43f2f112011-03-24 17:22:30 +01001346 irq_set_chip(irq, &bfin_core_irqchip);
Bryan Wu1394f032007-05-06 14:50:22 -07001347 else
Thomas Gleixner43f2f112011-03-24 17:22:30 +01001348 irq_set_chip(irq, &bfin_internal_irqchip);
Bryan Wu1394f032007-05-06 14:50:22 -07001349
Michael Hennerich464abc52008-02-25 13:50:20 +08001350 switch (irq) {
Mike Frysinger01f8e342011-06-26 13:56:23 -04001351#if BFIN_GPIO_PINT
Michael Hennerich464abc52008-02-25 13:50:20 +08001352 case IRQ_PINT0:
1353 case IRQ_PINT1:
1354 case IRQ_PINT2:
1355 case IRQ_PINT3:
Mike Frysinger01f8e342011-06-26 13:56:23 -04001356#elif defined(BF537_FAMILY)
1357 case IRQ_PH_INTA_MAC_RX:
1358 case IRQ_PF_INTA_PG_INTA:
1359#elif defined(BF533_FAMILY)
1360 case IRQ_PROG_INTA:
Bryan Wu2f6f4bc2008-11-18 17:48:21 +08001361#elif defined(CONFIG_BF52x) || defined(CONFIG_BF51x)
Michael Hennerich464abc52008-02-25 13:50:20 +08001362 case IRQ_PORTF_INTA:
1363 case IRQ_PORTG_INTA:
1364 case IRQ_PORTH_INTA:
Michael Hennerich2c4f8292008-02-09 04:11:14 +08001365#elif defined(CONFIG_BF561)
Michael Hennerich464abc52008-02-25 13:50:20 +08001366 case IRQ_PROG0_INTA:
1367 case IRQ_PROG1_INTA:
1368 case IRQ_PROG2_INTA:
Mike Frysingerfc6bd7b2011-04-15 01:35:53 -04001369#elif defined(BF538_FAMILY)
Michael Hennerichdc26aec2008-11-18 17:48:22 +08001370 case IRQ_PORTF_INTA:
Michael Hennerich59003142007-10-21 16:54:27 +08001371#endif
Thomas Gleixner43f2f112011-03-24 17:22:30 +01001372 irq_set_chained_handler(irq, bfin_demux_gpio_irq);
Michael Hennerich464abc52008-02-25 13:50:20 +08001373 break;
Michael Hennerichaec59c92010-02-19 15:09:10 +00001374#if defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE)
1375 case IRQ_MAC_ERROR:
Thomas Gleixner43f2f112011-03-24 17:22:30 +01001376 irq_set_chained_handler(irq,
1377 bfin_demux_mac_status_irq);
Michael Hennerichaec59c92010-02-19 15:09:10 +00001378 break;
1379#endif
Steven Miao4f6b6002012-05-16 17:56:51 +08001380#if defined(CONFIG_SMP) || defined(CONFIG_ICC)
Graf Yang6b3087c2009-01-07 23:14:39 +08001381 case IRQ_SUPPLE_0:
1382 case IRQ_SUPPLE_1:
Thomas Gleixner43f2f112011-03-24 17:22:30 +01001383 irq_set_handler(irq, handle_percpu_irq);
Graf Yang6b3087c2009-01-07 23:14:39 +08001384 break;
1385#endif
Graf Yang179413142009-08-18 04:29:33 +00001386
Yi Licb191712009-12-30 07:12:50 +00001387#ifdef CONFIG_TICKSOURCE_CORETMR
1388 case IRQ_CORETMR:
1389# ifdef CONFIG_SMP
Thomas Gleixner43f2f112011-03-24 17:22:30 +01001390 irq_set_handler(irq, handle_percpu_irq);
Yi Licb191712009-12-30 07:12:50 +00001391# else
Thomas Gleixner43f2f112011-03-24 17:22:30 +01001392 irq_set_handler(irq, handle_simple_irq);
Yi Licb191712009-12-30 07:12:50 +00001393# endif
Mike Frysingerfc6bd7b2011-04-15 01:35:53 -04001394 break;
Yi Licb191712009-12-30 07:12:50 +00001395#endif
1396
1397#ifdef CONFIG_TICKSOURCE_GPTMR0
Philippe Geruma40494a2009-06-16 05:25:42 +02001398 case IRQ_TIMER0:
Thomas Gleixner43f2f112011-03-24 17:22:30 +01001399 irq_set_handler(irq, handle_simple_irq);
Michael Hennerich464abc52008-02-25 13:50:20 +08001400 break;
Graf Yang179413142009-08-18 04:29:33 +00001401#endif
Yi Licb191712009-12-30 07:12:50 +00001402
Mike Frysingerfc6bd7b2011-04-15 01:35:53 -04001403 default:
Yi Licb191712009-12-30 07:12:50 +00001404#ifdef CONFIG_IPIPE
Thomas Gleixner43f2f112011-03-24 17:22:30 +01001405 irq_set_handler(irq, handle_level_irq);
Mike Frysingerfc6bd7b2011-04-15 01:35:53 -04001406#else
Thomas Gleixner43f2f112011-03-24 17:22:30 +01001407 irq_set_handler(irq, handle_simple_irq);
Mike Frysingerfc6bd7b2011-04-15 01:35:53 -04001408#endif
Philippe Geruma40494a2009-06-16 05:25:42 +02001409 break;
Bryan Wu1394f032007-05-06 14:50:22 -07001410 }
Bryan Wu1394f032007-05-06 14:50:22 -07001411 }
Michael Hennerich464abc52008-02-25 13:50:20 +08001412
Mike Frysingerf58c3272011-04-15 03:08:20 -04001413 init_mach_irq();
Bryan Wu1394f032007-05-06 14:50:22 -07001414
Sonic Zhang11b27cb2012-06-28 19:16:48 +08001415#if (defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE))
Michael Hennerichaec59c92010-02-19 15:09:10 +00001416 for (irq = IRQ_MAC_PHYINT; irq <= IRQ_MAC_STMDONE; irq++)
Thomas Gleixner43f2f112011-03-24 17:22:30 +01001417 irq_set_chip_and_handler(irq, &bfin_mac_status_irqchip,
Michael Hennerichaec59c92010-02-19 15:09:10 +00001418 handle_level_irq);
1419#endif
Michael Hennerich464abc52008-02-25 13:50:20 +08001420 /* if configured as edge, then will be changed to do_edge_IRQ */
Michael Hennerichaec59c92010-02-19 15:09:10 +00001421 for (irq = GPIO_IRQ_BASE;
1422 irq < (GPIO_IRQ_BASE + MAX_BLACKFIN_GPIOS); irq++)
Thomas Gleixner43f2f112011-03-24 17:22:30 +01001423 irq_set_chip_and_handler(irq, &bfin_gpio_irqchip,
Michael Hennerich464abc52008-02-25 13:50:20 +08001424 handle_level_irq);
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 */
1436 program_IAR();
1437 /* Therefore it's better to setup IARs before interrupts enabled */
1438 search_IAR();
1439
1440 /* Enable interrupts IVG7-15 */
Mike Frysinger40059782008-11-18 17:48:22 +08001441 bfin_irq_flags |= IMASK_IVG15 |
Steven Miao4f6b6002012-05-16 17:56:51 +08001442 IMASK_IVG14 | IMASK_IVG13 | IMASK_IVG12 | IMASK_IVG11 |
1443 IMASK_IVG10 | IMASK_IVG9 | IMASK_IVG8 | IMASK_IVG7 | IMASK_IVGHW;
1444
Bryan Wu1394f032007-05-06 14:50:22 -07001445
Michael Hennerich349ebbc2009-04-15 08:48:08 +00001446 /* This implicitly covers ANOMALY_05000171
1447 * Boot-ROM code modifies SICA_IWRx wakeup registers
1448 */
Mike Frysingerbe1d8542009-02-04 16:49:45 +08001449#ifdef SIC_IWR0
Michael Hennerich56f5f592008-08-06 17:55:32 +08001450 bfin_write_SIC_IWR0(IWR_DISABLE_ALL);
Mike Frysingerbe1d8542009-02-04 16:49:45 +08001451# ifdef SIC_IWR1
Bryan Wu2f6f4bc2008-11-18 17:48:21 +08001452 /* BF52x/BF51x system reset does not properly reset SIC_IWR1 which
Michael Hennerich55546ac2008-08-13 17:41:13 +08001453 * will screw up the bootrom as it relies on MDMA0/1 waking it
1454 * up from IDLE instructions. See this report for more info:
1455 * http://blackfin.uclinux.org/gf/tracker/4323
1456 */
Mike Frysingerb7e11292008-11-18 17:48:22 +08001457 if (ANOMALY_05000435)
1458 bfin_write_SIC_IWR1(IWR_ENABLE(10) | IWR_ENABLE(11));
1459 else
1460 bfin_write_SIC_IWR1(IWR_DISABLE_ALL);
Mike Frysingerbe1d8542009-02-04 16:49:45 +08001461# endif
1462# ifdef SIC_IWR2
Michael Hennerich56f5f592008-08-06 17:55:32 +08001463 bfin_write_SIC_IWR2(IWR_DISABLE_ALL);
Michael Hennerichfe9ec9b2008-02-25 12:04:57 +08001464# endif
1465#else
Michael Hennerich56f5f592008-08-06 17:55:32 +08001466 bfin_write_SIC_IWR(IWR_DISABLE_ALL);
Michael Hennerichfe9ec9b2008-02-25 12:04:57 +08001467#endif
Bryan Wu1394f032007-05-06 14:50:22 -07001468 return 0;
1469}
1470
1471#ifdef CONFIG_DO_IRQ_L1
Mike Frysingera055b2b2007-11-15 21:12:32 +08001472__attribute__((l1_text))
Bryan Wu1394f032007-05-06 14:50:22 -07001473#endif
Mike Frysinger6b108042011-03-30 01:35:41 -04001474static int vec_to_irq(int vec)
1475{
1476 struct ivgx *ivg = ivg7_13[vec - IVG7].ifirst;
1477 struct ivgx *ivg_stop = ivg7_13[vec - IVG7].istop;
1478 unsigned long sic_status[3];
Mike Frysinger6b108042011-03-30 01:35:41 -04001479 if (likely(vec == EVT_IVTMR_P))
1480 return IRQ_CORETMR;
Mike Frysinger6b108042011-03-30 01:35:41 -04001481#ifdef SIC_ISR
1482 sic_status[0] = bfin_read_SIC_IMASK() & bfin_read_SIC_ISR();
1483#else
1484 if (smp_processor_id()) {
1485# ifdef SICB_ISR0
1486 /* This will be optimized out in UP mode. */
1487 sic_status[0] = bfin_read_SICB_ISR0() & bfin_read_SICB_IMASK0();
1488 sic_status[1] = bfin_read_SICB_ISR1() & bfin_read_SICB_IMASK1();
1489# endif
1490 } else {
1491 sic_status[0] = bfin_read_SIC_ISR0() & bfin_read_SIC_IMASK0();
1492 sic_status[1] = bfin_read_SIC_ISR1() & bfin_read_SIC_IMASK1();
1493 }
1494#endif
1495#ifdef SIC_ISR2
1496 sic_status[2] = bfin_read_SIC_ISR2() & bfin_read_SIC_IMASK2();
1497#endif
1498
1499 for (;; ivg++) {
1500 if (ivg >= ivg_stop)
1501 return -1;
1502#ifdef SIC_ISR
1503 if (sic_status[0] & ivg->isrflag)
1504#else
1505 if (sic_status[(ivg->irqno - IVG7) / 32] & ivg->isrflag)
1506#endif
1507 return ivg->irqno;
1508 }
1509}
1510
Sonic Zhang11b27cb2012-06-28 19:16:48 +08001511#else /* SEC_GCTL */
1512
1513/*
1514 * This function should be called during kernel startup to initialize
1515 * the BFin IRQ handling routines.
1516 */
1517
1518int __init init_arch_irq(void)
1519{
1520 int irq;
1521 unsigned long ilat = 0;
1522
1523 bfin_write_SEC_GCTL(SEC_GCTL_RESET);
1524
1525 local_irq_disable();
1526
1527#if BFIN_GPIO_PINT
1528# ifdef CONFIG_PINTx_REASSIGN
1529 pint[0]->assign = CONFIG_PINT0_ASSIGN;
1530 pint[1]->assign = CONFIG_PINT1_ASSIGN;
1531 pint[2]->assign = CONFIG_PINT2_ASSIGN;
1532 pint[3]->assign = CONFIG_PINT3_ASSIGN;
1533 pint[4]->assign = CONFIG_PINT4_ASSIGN;
1534 pint[5]->assign = CONFIG_PINT5_ASSIGN;
1535# endif
1536 /* Whenever PINTx_ASSIGN is altered init_pint_lut() must be executed! */
1537 init_pint_lut();
1538#endif
1539
1540 for (irq = 0; irq <= SYS_IRQS; irq++) {
1541 if (irq <= IRQ_CORETMR) {
Sonic Zhang86794b42012-12-14 11:19:24 +08001542 irq_set_chip_and_handler(irq, &bfin_core_irqchip,
1543 handle_simple_irq);
1544#if defined(CONFIG_TICKSOURCE_CORETMR) && defined(CONFIG_SMP)
Sonic Zhang11b27cb2012-06-28 19:16:48 +08001545 if (irq == IRQ_CORETMR)
Sonic Zhang11b27cb2012-06-28 19:16:48 +08001546 irq_set_handler(irq, handle_percpu_irq);
Sonic Zhang11b27cb2012-06-28 19:16:48 +08001547#endif
Sonic Zhang11b27cb2012-06-28 19:16:48 +08001548 } else if (irq >= BFIN_IRQ(21) && irq <= BFIN_IRQ(26)) {
1549 irq_set_chip(irq, &bfin_sec_irqchip);
1550 irq_set_chained_handler(irq, bfin_demux_gpio_irq);
1551 } else if (irq >= BFIN_IRQ(34) && irq <= BFIN_IRQ(37)) {
Sonic Zhang11b27cb2012-06-28 19:16:48 +08001552 irq_set_chip_and_handler(irq, &bfin_sec_irqchip,
Sonic Zhang86794b42012-12-14 11:19:24 +08001553 handle_percpu_irq);
1554 } else {
1555 irq_set_chip(irq, &bfin_sec_irqchip);
1556 if (irq == IRQ_SEC_ERR)
1557 irq_set_handler(irq, handle_sec_fault);
1558 else if (irq >= IRQ_C0_DBL_FAULT && irq < CORE_IRQS)
1559 irq_set_handler(irq, handle_core_fault);
1560 else
1561 irq_set_handler(irq, handle_fasteoi_irq);
Sonic Zhang11b27cb2012-06-28 19:16:48 +08001562 __irq_set_preflow_handler(irq, bfin_sec_preflow_handler);
1563 }
1564 }
1565 for (irq = GPIO_IRQ_BASE;
1566 irq < (GPIO_IRQ_BASE + MAX_BLACKFIN_GPIOS); irq++)
1567 irq_set_chip_and_handler(irq, &bfin_gpio_irqchip,
1568 handle_level_irq);
1569
1570 bfin_write_IMASK(0);
1571 CSYNC();
1572 ilat = bfin_read_ILAT();
1573 CSYNC();
1574 bfin_write_ILAT(ilat);
1575 CSYNC();
1576
1577 printk(KERN_INFO "Configuring Blackfin Priority Driven Interrupts\n");
1578
Sonic Zhange0a59312012-06-29 18:19:29 +08001579 bfin_sec_set_priority(CONFIG_SEC_IRQ_PRIORITY_LEVELS, sec_int_priority);
1580
1581 bfin_sec_set_priority(CONFIG_SEC_IRQ_PRIORITY_LEVELS, sec_int_priority);
1582
Sonic Zhang11b27cb2012-06-28 19:16:48 +08001583 /* Enable interrupts IVG7-15 */
1584 bfin_irq_flags |= IMASK_IVG15 |
1585 IMASK_IVG14 | IMASK_IVG13 | IMASK_IVG12 | IMASK_IVG11 |
1586 IMASK_IVG10 | IMASK_IVG9 | IMASK_IVG8 | IMASK_IVG7 | IMASK_IVGHW;
1587
1588
1589 bfin_write_SEC_FCTL(SEC_FCTL_EN | SEC_FCTL_SYSRST_EN | SEC_FCTL_FLTIN_EN);
Sonic Zhang86794b42012-12-14 11:19:24 +08001590 bfin_sec_enable_sci(BFIN_SYSIRQ(IRQ_WATCH0));
1591 bfin_sec_enable_ssi(BFIN_SYSIRQ(IRQ_WATCH0));
Sonic Zhang11b27cb2012-06-28 19:16:48 +08001592 bfin_write_SEC_SCI(0, SEC_CCTL, SEC_CCTL_RESET);
1593 udelay(100);
1594 bfin_write_SEC_GCTL(SEC_GCTL_EN);
1595 bfin_write_SEC_SCI(0, SEC_CCTL, SEC_CCTL_EN | SEC_CCTL_NMI_EN);
1596 bfin_write_SEC_SCI(1, SEC_CCTL, SEC_CCTL_EN | SEC_CCTL_NMI_EN);
1597
1598 init_software_driven_irq();
1599 register_syscore_ops(&sec_pm_syscore_ops);
1600
1601 return 0;
1602}
1603
1604#ifdef CONFIG_DO_IRQ_L1
1605__attribute__((l1_text))
1606#endif
1607static int vec_to_irq(int vec)
1608{
1609 if (likely(vec == EVT_IVTMR_P))
1610 return IRQ_CORETMR;
1611
1612 return BFIN_IRQ(bfin_read_SEC_SCI(0, SEC_CSID));
1613}
1614#endif /* SEC_GCTL */
1615
Mike Frysinger6b108042011-03-30 01:35:41 -04001616#ifdef CONFIG_DO_IRQ_L1
1617__attribute__((l1_text))
1618#endif
Bryan Wu1394f032007-05-06 14:50:22 -07001619void do_irq(int vec, struct pt_regs *fp)
1620{
Mike Frysinger6b108042011-03-30 01:35:41 -04001621 int irq = vec_to_irq(vec);
1622 if (irq == -1)
1623 return;
1624 asm_do_IRQ(irq, fp);
Bryan Wu1394f032007-05-06 14:50:22 -07001625}
Yi Li6a01f232009-01-07 23:14:39 +08001626
1627#ifdef CONFIG_IPIPE
1628
1629int __ipipe_get_irq_priority(unsigned irq)
1630{
1631 int ient, prio;
1632
1633 if (irq <= IRQ_CORETMR)
1634 return irq;
1635
Sonic Zhang11b27cb2012-06-28 19:16:48 +08001636#ifdef SEC_GCTL
1637 if (irq >= BFIN_IRQ(0))
1638 return IVG11;
1639#else
Yi Li6a01f232009-01-07 23:14:39 +08001640 for (ient = 0; ient < NR_PERI_INTS; ient++) {
1641 struct ivgx *ivg = ivg_table + ient;
1642 if (ivg->irqno == irq) {
1643 for (prio = 0; prio <= IVG13-IVG7; prio++) {
1644 if (ivg7_13[prio].ifirst <= ivg &&
1645 ivg7_13[prio].istop > ivg)
1646 return IVG7 + prio;
1647 }
1648 }
1649 }
Sonic Zhang11b27cb2012-06-28 19:16:48 +08001650#endif
Yi Li6a01f232009-01-07 23:14:39 +08001651
1652 return IVG15;
1653}
1654
Yi Li6a01f232009-01-07 23:14:39 +08001655/* Hw interrupts are disabled on entry (check SAVE_CONTEXT). */
1656#ifdef CONFIG_DO_IRQ_L1
1657__attribute__((l1_text))
1658#endif
1659asmlinkage int __ipipe_grab_irq(int vec, struct pt_regs *regs)
1660{
Philippe Gerum9bd50df2009-03-04 16:52:38 +08001661 struct ipipe_percpu_domain_data *p = ipipe_root_cpudom_ptr();
Philippe Geruma40494a2009-06-16 05:25:42 +02001662 struct ipipe_domain *this_domain = __ipipe_current_domain;
Philippe Gerum5b5da4c2011-03-17 02:12:48 -04001663 int irq, s = 0;
Yi Li6a01f232009-01-07 23:14:39 +08001664
Mike Frysinger6b108042011-03-30 01:35:41 -04001665 irq = vec_to_irq(vec);
1666 if (irq == -1)
1667 return 0;
Yi Li6a01f232009-01-07 23:14:39 +08001668
1669 if (irq == IRQ_SYSTMR) {
Philippe Geruma40494a2009-06-16 05:25:42 +02001670#if !defined(CONFIG_GENERIC_CLOCKEVENTS) || defined(CONFIG_TICKSOURCE_GPTMR0)
Yi Li6a01f232009-01-07 23:14:39 +08001671 bfin_write_TIMER_STATUS(1); /* Latch TIMIL0 */
Philippe Gerum9bd50df2009-03-04 16:52:38 +08001672#endif
Yi Li6a01f232009-01-07 23:14:39 +08001673 /* This is basically what we need from the register frame. */
1674 __raw_get_cpu_var(__ipipe_tick_regs).ipend = regs->ipend;
1675 __raw_get_cpu_var(__ipipe_tick_regs).pc = regs->pc;
Philippe Gerum9bd50df2009-03-04 16:52:38 +08001676 if (this_domain != ipipe_root_domain)
Yi Li6a01f232009-01-07 23:14:39 +08001677 __raw_get_cpu_var(__ipipe_tick_regs).ipend &= ~0x10;
Philippe Gerum9bd50df2009-03-04 16:52:38 +08001678 else
1679 __raw_get_cpu_var(__ipipe_tick_regs).ipend |= 0x10;
Yi Li6a01f232009-01-07 23:14:39 +08001680 }
1681
Philippe Gerum5b5da4c2011-03-17 02:12:48 -04001682 /*
1683 * We don't want Linux interrupt handlers to run at the
1684 * current core priority level (i.e. < EVT15), since this
1685 * might delay other interrupts handled by a high priority
1686 * domain. Here is what we do instead:
1687 *
1688 * - we raise the SYNCDEFER bit to prevent
1689 * __ipipe_handle_irq() to sync the pipeline for the root
1690 * stage for the incoming interrupt. Upon return, that IRQ is
1691 * pending in the interrupt log.
1692 *
1693 * - we raise the TIF_IRQ_SYNC bit for the current thread, so
1694 * that _schedule_and_signal_from_int will eventually sync the
1695 * pipeline from EVT15.
1696 */
Philippe Gerum9bd50df2009-03-04 16:52:38 +08001697 if (this_domain == ipipe_root_domain) {
1698 s = __test_and_set_bit(IPIPE_SYNCDEFER_FLAG, &p->status);
1699 barrier();
1700 }
Yi Li6a01f232009-01-07 23:14:39 +08001701
1702 ipipe_trace_irq_entry(irq);
1703 __ipipe_handle_irq(irq, regs);
Philippe Gerum9bd50df2009-03-04 16:52:38 +08001704 ipipe_trace_irq_exit(irq);
Yi Li6a01f232009-01-07 23:14:39 +08001705
Philippe Gerum5b5da4c2011-03-17 02:12:48 -04001706 if (user_mode(regs) &&
1707 !ipipe_test_foreign_stack() &&
1708 (current->ipipe_flags & PF_EVTRET) != 0) {
1709 /*
1710 * Testing for user_regs() does NOT fully eliminate
1711 * foreign stack contexts, because of the forged
1712 * interrupt returns we do through
1713 * __ipipe_call_irqtail. In that case, we might have
1714 * preempted a foreign stack context in a high
1715 * priority domain, with a single interrupt level now
1716 * pending after the irqtail unwinding is done. In
1717 * which case user_mode() is now true, and the event
1718 * gets dispatched spuriously.
1719 */
1720 current->ipipe_flags &= ~PF_EVTRET;
1721 __ipipe_dispatch_event(IPIPE_EVENT_RETURN, regs);
1722 }
1723
Philippe Gerum9bd50df2009-03-04 16:52:38 +08001724 if (this_domain == ipipe_root_domain) {
1725 set_thread_flag(TIF_IRQ_SYNC);
1726 if (!s) {
1727 __clear_bit(IPIPE_SYNCDEFER_FLAG, &p->status);
1728 return !test_bit(IPIPE_STALL_FLAG, &p->status);
1729 }
1730 }
Yi Li6a01f232009-01-07 23:14:39 +08001731
Graf Yang1fa9be72009-05-15 11:01:59 +00001732 return 0;
Yi Li6a01f232009-01-07 23:14:39 +08001733}
1734
1735#endif /* CONFIG_IPIPE */