ints-priority.c 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498
  1. /*
  2. * Set up the interrupt priorities
  3. *
  4. * 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
  10. *
  11. * Licensed under the GPL-2
  12. */
  13. #include <linux/module.h>
  14. #include <linux/kernel_stat.h>
  15. #include <linux/seq_file.h>
  16. #include <linux/irq.h>
  17. #include <linux/sched.h>
  18. #ifdef CONFIG_IPIPE
  19. #include <linux/ipipe.h>
  20. #endif
  21. #ifdef CONFIG_KGDB
  22. #include <linux/kgdb.h>
  23. #endif
  24. #include <asm/traps.h>
  25. #include <asm/blackfin.h>
  26. #include <asm/gpio.h>
  27. #include <asm/irq_handler.h>
  28. #include <asm/dpmc.h>
  29. #include <asm/bfin5xx_spi.h>
  30. #include <asm/bfin_sport.h>
  31. #include <asm/bfin_can.h>
  32. #define SIC_SYSIRQ(irq) (irq - (IRQ_CORETMR + 1))
  33. #ifdef BF537_FAMILY
  34. # define BF537_GENERIC_ERROR_INT_DEMUX
  35. # define SPI_ERR_MASK (BIT_STAT_TXCOL | BIT_STAT_RBSY | BIT_STAT_MODF | BIT_STAT_TXE) /* SPI_STAT */
  36. # define SPORT_ERR_MASK (ROVF | RUVF | TOVF | TUVF) /* SPORT_STAT */
  37. # define PPI_ERR_MASK (0xFFFF & ~FLD) /* PPI_STATUS */
  38. # define EMAC_ERR_MASK (PHYINT | MMCINT | RXFSINT | TXFSINT | WAKEDET | RXDMAERR | TXDMAERR | STMDONE) /* EMAC_SYSTAT */
  39. # define UART_ERR_MASK (0x6) /* UART_IIR */
  40. # define CAN_ERR_MASK (EWTIF | EWRIF | EPIF | BOIF | WUIF | UIAIF | AAIF | RMLIF | UCEIF | EXTIF | ADIF) /* CAN_GIF */
  41. #else
  42. # undef BF537_GENERIC_ERROR_INT_DEMUX
  43. #endif
  44. /*
  45. * NOTES:
  46. * - we have separated the physical Hardware interrupt from the
  47. * levels that the LINUX kernel sees (see the description in irq.h)
  48. * -
  49. */
  50. #ifndef CONFIG_SMP
  51. /* Initialize this to an actual value to force it into the .data
  52. * section so that we know it is properly initialized at entry into
  53. * the kernel but before bss is initialized to zero (which is where
  54. * it would live otherwise). The 0x1f magic represents the IRQs we
  55. * cannot actually mask out in hardware.
  56. */
  57. unsigned long bfin_irq_flags = 0x1f;
  58. EXPORT_SYMBOL(bfin_irq_flags);
  59. #endif
  60. /* The number of spurious interrupts */
  61. atomic_t num_spurious;
  62. #ifdef CONFIG_PM
  63. unsigned long bfin_sic_iwr[3]; /* Up to 3 SIC_IWRx registers */
  64. unsigned vr_wakeup;
  65. #endif
  66. struct ivgx {
  67. /* irq number for request_irq, available in mach-bf5xx/irq.h */
  68. unsigned int irqno;
  69. /* corresponding bit in the SIC_ISR register */
  70. unsigned int isrflag;
  71. } ivg_table[NR_PERI_INTS];
  72. struct ivg_slice {
  73. /* position of first irq in ivg_table for given ivg */
  74. struct ivgx *ifirst;
  75. struct ivgx *istop;
  76. } ivg7_13[IVG13 - IVG7 + 1];
  77. /*
  78. * Search SIC_IAR and fill tables with the irqvalues
  79. * and their positions in the SIC_ISR register.
  80. */
  81. static void __init search_IAR(void)
  82. {
  83. unsigned ivg, irq_pos = 0;
  84. for (ivg = 0; ivg <= IVG13 - IVG7; ivg++) {
  85. int irqN;
  86. ivg7_13[ivg].istop = ivg7_13[ivg].ifirst = &ivg_table[irq_pos];
  87. for (irqN = 0; irqN < NR_PERI_INTS; irqN += 4) {
  88. int irqn;
  89. u32 iar = bfin_read32((unsigned long *)SIC_IAR0 +
  90. #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))
  93. #else
  94. (irqN >> 3)
  95. #endif
  96. );
  97. 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. }
  105. }
  106. }
  107. }
  108. }
  109. /*
  110. * This is for core internal IRQs
  111. */
  112. static void bfin_ack_noop(struct irq_data *d)
  113. {
  114. /* Dummy function. */
  115. }
  116. static void bfin_core_mask_irq(struct irq_data *d)
  117. {
  118. bfin_irq_flags &= ~(1 << d->irq);
  119. if (!hard_irqs_disabled())
  120. hard_local_irq_enable();
  121. }
  122. static void bfin_core_unmask_irq(struct irq_data *d)
  123. {
  124. bfin_irq_flags |= 1 << d->irq;
  125. /*
  126. * If interrupts are enabled, IMASK must contain the same value
  127. * as bfin_irq_flags. Make sure that invariant holds. If interrupts
  128. * are currently disabled we need not do anything; one of the
  129. * callers will take care of setting IMASK to the proper value
  130. * when reenabling interrupts.
  131. * local_irq_enable just does "STI bfin_irq_flags", so it's exactly
  132. * what we need.
  133. */
  134. if (!hard_irqs_disabled())
  135. hard_local_irq_enable();
  136. return;
  137. }
  138. static void bfin_internal_mask_irq(unsigned int irq)
  139. {
  140. unsigned long flags;
  141. #ifdef CONFIG_BF53x
  142. flags = hard_local_irq_save();
  143. bfin_write_SIC_IMASK(bfin_read_SIC_IMASK() &
  144. ~(1 << SIC_SYSIRQ(irq)));
  145. #else
  146. unsigned mask_bank, mask_bit;
  147. flags = hard_local_irq_save();
  148. mask_bank = SIC_SYSIRQ(irq) / 32;
  149. mask_bit = SIC_SYSIRQ(irq) % 32;
  150. bfin_write_SIC_IMASK(mask_bank, bfin_read_SIC_IMASK(mask_bank) &
  151. ~(1 << mask_bit));
  152. #ifdef CONFIG_SMP
  153. bfin_write_SICB_IMASK(mask_bank, bfin_read_SICB_IMASK(mask_bank) &
  154. ~(1 << mask_bit));
  155. #endif
  156. #endif
  157. hard_local_irq_restore(flags);
  158. }
  159. static void bfin_internal_mask_irq_chip(struct irq_data *d)
  160. {
  161. bfin_internal_mask_irq(d->irq);
  162. }
  163. #ifdef CONFIG_SMP
  164. static void bfin_internal_unmask_irq_affinity(unsigned int irq,
  165. const struct cpumask *affinity)
  166. #else
  167. static void bfin_internal_unmask_irq(unsigned int irq)
  168. #endif
  169. {
  170. unsigned long flags;
  171. #ifdef CONFIG_BF53x
  172. flags = hard_local_irq_save();
  173. bfin_write_SIC_IMASK(bfin_read_SIC_IMASK() |
  174. (1 << SIC_SYSIRQ(irq)));
  175. #else
  176. unsigned mask_bank, mask_bit;
  177. flags = hard_local_irq_save();
  178. mask_bank = SIC_SYSIRQ(irq) / 32;
  179. mask_bit = SIC_SYSIRQ(irq) % 32;
  180. #ifdef CONFIG_SMP
  181. if (cpumask_test_cpu(0, affinity))
  182. #endif
  183. bfin_write_SIC_IMASK(mask_bank,
  184. bfin_read_SIC_IMASK(mask_bank) |
  185. (1 << mask_bit));
  186. #ifdef CONFIG_SMP
  187. if (cpumask_test_cpu(1, affinity))
  188. bfin_write_SICB_IMASK(mask_bank,
  189. bfin_read_SICB_IMASK(mask_bank) |
  190. (1 << mask_bit));
  191. #endif
  192. #endif
  193. hard_local_irq_restore(flags);
  194. }
  195. #ifdef CONFIG_SMP
  196. static void bfin_internal_unmask_irq_chip(struct irq_data *d)
  197. {
  198. bfin_internal_unmask_irq_affinity(d->irq, d->affinity);
  199. }
  200. static 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. return 0;
  206. }
  207. #else
  208. static void bfin_internal_unmask_irq_chip(struct irq_data *d)
  209. {
  210. bfin_internal_unmask_irq(d->irq);
  211. }
  212. #endif
  213. #ifdef CONFIG_PM
  214. int bfin_internal_set_wake(unsigned int irq, unsigned int state)
  215. {
  216. u32 bank, bit, wakeup = 0;
  217. unsigned long flags;
  218. bank = SIC_SYSIRQ(irq) / 32;
  219. bit = SIC_SYSIRQ(irq) % 32;
  220. switch (irq) {
  221. #ifdef IRQ_RTC
  222. case IRQ_RTC:
  223. wakeup |= WAKE;
  224. break;
  225. #endif
  226. #ifdef IRQ_CAN0_RX
  227. case IRQ_CAN0_RX:
  228. wakeup |= CANWE;
  229. break;
  230. #endif
  231. #ifdef IRQ_CAN1_RX
  232. case IRQ_CAN1_RX:
  233. wakeup |= CANWE;
  234. break;
  235. #endif
  236. #ifdef IRQ_USB_INT0
  237. case IRQ_USB_INT0:
  238. wakeup |= USBWE;
  239. break;
  240. #endif
  241. #ifdef CONFIG_BF54x
  242. case IRQ_CNT:
  243. wakeup |= ROTWE;
  244. break;
  245. #endif
  246. default:
  247. break;
  248. }
  249. flags = hard_local_irq_save();
  250. if (state) {
  251. bfin_sic_iwr[bank] |= (1 << bit);
  252. vr_wakeup |= wakeup;
  253. } else {
  254. bfin_sic_iwr[bank] &= ~(1 << bit);
  255. vr_wakeup &= ~wakeup;
  256. }
  257. hard_local_irq_restore(flags);
  258. return 0;
  259. }
  260. static int bfin_internal_set_wake_chip(struct irq_data *d, unsigned int state)
  261. {
  262. return bfin_internal_set_wake(d->irq, state);
  263. }
  264. #endif
  265. static struct irq_chip bfin_core_irqchip = {
  266. .name = "CORE",
  267. .irq_ack = bfin_ack_noop,
  268. .irq_mask = bfin_core_mask_irq,
  269. .irq_unmask = bfin_core_unmask_irq,
  270. };
  271. static struct irq_chip bfin_internal_irqchip = {
  272. .name = "INTN",
  273. .irq_ack = bfin_ack_noop,
  274. .irq_mask = bfin_internal_mask_irq_chip,
  275. .irq_unmask = bfin_internal_unmask_irq_chip,
  276. .irq_mask_ack = bfin_internal_mask_irq_chip,
  277. .irq_disable = bfin_internal_mask_irq_chip,
  278. .irq_enable = bfin_internal_unmask_irq_chip,
  279. #ifdef CONFIG_SMP
  280. .irq_set_affinity = bfin_internal_set_affinity,
  281. #endif
  282. #ifdef CONFIG_PM
  283. .irq_set_wake = bfin_internal_set_wake_chip,
  284. #endif
  285. };
  286. static void bfin_handle_irq(unsigned irq)
  287. {
  288. #ifdef CONFIG_IPIPE
  289. struct pt_regs regs; /* Contents not used. */
  290. ipipe_trace_irq_entry(irq);
  291. __ipipe_handle_irq(irq, &regs);
  292. ipipe_trace_irq_exit(irq);
  293. #else /* !CONFIG_IPIPE */
  294. generic_handle_irq(irq);
  295. #endif /* !CONFIG_IPIPE */
  296. }
  297. #ifdef BF537_GENERIC_ERROR_INT_DEMUX
  298. static int error_int_mask;
  299. static void bfin_generic_error_mask_irq(struct irq_data *d)
  300. {
  301. error_int_mask &= ~(1L << (d->irq - IRQ_PPI_ERROR));
  302. if (!error_int_mask)
  303. bfin_internal_mask_irq(IRQ_GENERIC_ERROR);
  304. }
  305. static void bfin_generic_error_unmask_irq(struct irq_data *d)
  306. {
  307. bfin_internal_unmask_irq(IRQ_GENERIC_ERROR);
  308. error_int_mask |= 1L << (d->irq - IRQ_PPI_ERROR);
  309. }
  310. static struct irq_chip bfin_generic_error_irqchip = {
  311. .name = "ERROR",
  312. .irq_ack = bfin_ack_noop,
  313. .irq_mask_ack = bfin_generic_error_mask_irq,
  314. .irq_mask = bfin_generic_error_mask_irq,
  315. .irq_unmask = bfin_generic_error_unmask_irq,
  316. };
  317. static void bfin_demux_error_irq(unsigned int int_err_irq,
  318. struct irq_desc *inta_desc)
  319. {
  320. int irq = 0;
  321. #if (defined(CONFIG_BF537) || defined(CONFIG_BF536))
  322. if (bfin_read_EMAC_SYSTAT() & EMAC_ERR_MASK)
  323. irq = IRQ_MAC_ERROR;
  324. else
  325. #endif
  326. if (bfin_read_SPORT0_STAT() & SPORT_ERR_MASK)
  327. irq = IRQ_SPORT0_ERROR;
  328. else if (bfin_read_SPORT1_STAT() & SPORT_ERR_MASK)
  329. irq = IRQ_SPORT1_ERROR;
  330. else if (bfin_read_PPI_STATUS() & PPI_ERR_MASK)
  331. irq = IRQ_PPI_ERROR;
  332. else if (bfin_read_CAN_GIF() & CAN_ERR_MASK)
  333. irq = IRQ_CAN_ERROR;
  334. else if (bfin_read_SPI_STAT() & SPI_ERR_MASK)
  335. irq = IRQ_SPI_ERROR;
  336. else if ((bfin_read_UART0_IIR() & UART_ERR_MASK) == UART_ERR_MASK)
  337. irq = IRQ_UART0_ERROR;
  338. else if ((bfin_read_UART1_IIR() & UART_ERR_MASK) == UART_ERR_MASK)
  339. irq = IRQ_UART1_ERROR;
  340. if (irq) {
  341. if (error_int_mask & (1L << (irq - IRQ_PPI_ERROR)))
  342. bfin_handle_irq(irq);
  343. else {
  344. switch (irq) {
  345. case IRQ_PPI_ERROR:
  346. bfin_write_PPI_STATUS(PPI_ERR_MASK);
  347. break;
  348. #if (defined(CONFIG_BF537) || defined(CONFIG_BF536))
  349. case IRQ_MAC_ERROR:
  350. bfin_write_EMAC_SYSTAT(EMAC_ERR_MASK);
  351. break;
  352. #endif
  353. case IRQ_SPORT0_ERROR:
  354. bfin_write_SPORT0_STAT(SPORT_ERR_MASK);
  355. break;
  356. case IRQ_SPORT1_ERROR:
  357. bfin_write_SPORT1_STAT(SPORT_ERR_MASK);
  358. break;
  359. case IRQ_CAN_ERROR:
  360. bfin_write_CAN_GIS(CAN_ERR_MASK);
  361. break;
  362. case IRQ_SPI_ERROR:
  363. bfin_write_SPI_STAT(SPI_ERR_MASK);
  364. break;
  365. default:
  366. break;
  367. }
  368. pr_debug("IRQ %d:"
  369. " MASKED PERIPHERAL ERROR INTERRUPT ASSERTED\n",
  370. irq);
  371. }
  372. } else
  373. printk(KERN_ERR
  374. "%s : %s : LINE %d :\nIRQ ?: PERIPHERAL ERROR"
  375. " INTERRUPT ASSERTED BUT NO SOURCE FOUND\n",
  376. __func__, __FILE__, __LINE__);
  377. }
  378. #endif /* BF537_GENERIC_ERROR_INT_DEMUX */
  379. #if defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE)
  380. static int mac_stat_int_mask;
  381. static void bfin_mac_status_ack_irq(unsigned int irq)
  382. {
  383. switch (irq) {
  384. case IRQ_MAC_MMCINT:
  385. bfin_write_EMAC_MMC_TIRQS(
  386. bfin_read_EMAC_MMC_TIRQE() &
  387. bfin_read_EMAC_MMC_TIRQS());
  388. bfin_write_EMAC_MMC_RIRQS(
  389. bfin_read_EMAC_MMC_RIRQE() &
  390. bfin_read_EMAC_MMC_RIRQS());
  391. break;
  392. case IRQ_MAC_RXFSINT:
  393. bfin_write_EMAC_RX_STKY(
  394. bfin_read_EMAC_RX_IRQE() &
  395. bfin_read_EMAC_RX_STKY());
  396. break;
  397. case IRQ_MAC_TXFSINT:
  398. bfin_write_EMAC_TX_STKY(
  399. bfin_read_EMAC_TX_IRQE() &
  400. bfin_read_EMAC_TX_STKY());
  401. break;
  402. case IRQ_MAC_WAKEDET:
  403. bfin_write_EMAC_WKUP_CTL(
  404. bfin_read_EMAC_WKUP_CTL() | MPKS | RWKS);
  405. break;
  406. default:
  407. /* These bits are W1C */
  408. bfin_write_EMAC_SYSTAT(1L << (irq - IRQ_MAC_PHYINT));
  409. break;
  410. }
  411. }
  412. static void bfin_mac_status_mask_irq(struct irq_data *d)
  413. {
  414. unsigned int irq = d->irq;
  415. mac_stat_int_mask &= ~(1L << (irq - IRQ_MAC_PHYINT));
  416. #ifdef BF537_GENERIC_ERROR_INT_DEMUX
  417. switch (irq) {
  418. case IRQ_MAC_PHYINT:
  419. bfin_write_EMAC_SYSCTL(bfin_read_EMAC_SYSCTL() & ~PHYIE);
  420. break;
  421. default:
  422. break;
  423. }
  424. #else
  425. if (!mac_stat_int_mask)
  426. bfin_internal_mask_irq(IRQ_MAC_ERROR);
  427. #endif
  428. bfin_mac_status_ack_irq(irq);
  429. }
  430. static void bfin_mac_status_unmask_irq(struct irq_data *d)
  431. {
  432. unsigned int irq = d->irq;
  433. #ifdef BF537_GENERIC_ERROR_INT_DEMUX
  434. switch (irq) {
  435. case IRQ_MAC_PHYINT:
  436. bfin_write_EMAC_SYSCTL(bfin_read_EMAC_SYSCTL() | PHYIE);
  437. break;
  438. default:
  439. break;
  440. }
  441. #else
  442. if (!mac_stat_int_mask)
  443. bfin_internal_unmask_irq(IRQ_MAC_ERROR);
  444. #endif
  445. mac_stat_int_mask |= 1L << (irq - IRQ_MAC_PHYINT);
  446. }
  447. #ifdef CONFIG_PM
  448. int bfin_mac_status_set_wake(struct irq_data *d, unsigned int state)
  449. {
  450. #ifdef BF537_GENERIC_ERROR_INT_DEMUX
  451. return bfin_internal_set_wake(IRQ_GENERIC_ERROR, state);
  452. #else
  453. return bfin_internal_set_wake(IRQ_MAC_ERROR, state);
  454. #endif
  455. }
  456. #endif
  457. static struct irq_chip bfin_mac_status_irqchip = {
  458. .name = "MACST",
  459. .irq_ack = bfin_ack_noop,
  460. .irq_mask_ack = bfin_mac_status_mask_irq,
  461. .irq_mask = bfin_mac_status_mask_irq,
  462. .irq_unmask = bfin_mac_status_unmask_irq,
  463. #ifdef CONFIG_PM
  464. .irq_set_wake = bfin_mac_status_set_wake,
  465. #endif
  466. };
  467. static void bfin_demux_mac_status_irq(unsigned int int_err_irq,
  468. struct irq_desc *inta_desc)
  469. {
  470. int i, irq = 0;
  471. u32 status = bfin_read_EMAC_SYSTAT();
  472. for (i = 0; i <= (IRQ_MAC_STMDONE - IRQ_MAC_PHYINT); i++)
  473. if (status & (1L << i)) {
  474. irq = IRQ_MAC_PHYINT + i;
  475. break;
  476. }
  477. if (irq) {
  478. if (mac_stat_int_mask & (1L << (irq - IRQ_MAC_PHYINT))) {
  479. bfin_handle_irq(irq);
  480. } else {
  481. bfin_mac_status_ack_irq(irq);
  482. pr_debug("IRQ %d:"
  483. " MASKED MAC ERROR INTERRUPT ASSERTED\n",
  484. irq);
  485. }
  486. } else
  487. printk(KERN_ERR
  488. "%s : %s : LINE %d :\nIRQ ?: MAC ERROR"
  489. " INTERRUPT ASSERTED BUT NO SOURCE FOUND"
  490. "(EMAC_SYSTAT=0x%X)\n",
  491. __func__, __FILE__, __LINE__, status);
  492. }
  493. #endif
  494. static inline void bfin_set_irq_handler(unsigned irq, irq_flow_handler_t handle)
  495. {
  496. #ifdef CONFIG_IPIPE
  497. handle = handle_level_irq;
  498. #endif
  499. __set_irq_handler_unlocked(irq, handle);
  500. }
  501. static DECLARE_BITMAP(gpio_enabled, MAX_BLACKFIN_GPIOS);
  502. extern void bfin_gpio_irq_prepare(unsigned gpio);
  503. #if !defined(CONFIG_BF54x)
  504. static void bfin_gpio_ack_irq(struct irq_data *d)
  505. {
  506. /* AFAIK ack_irq in case mask_ack is provided
  507. * get's only called for edge sense irqs
  508. */
  509. set_gpio_data(irq_to_gpio(d->irq), 0);
  510. }
  511. static void bfin_gpio_mask_ack_irq(struct irq_data *d)
  512. {
  513. unsigned int irq = d->irq;
  514. struct irq_desc *desc = irq_to_desc(irq);
  515. u32 gpionr = irq_to_gpio(irq);
  516. if (desc->handle_irq == handle_edge_irq)
  517. set_gpio_data(gpionr, 0);
  518. set_gpio_maska(gpionr, 0);
  519. }
  520. static void bfin_gpio_mask_irq(struct irq_data *d)
  521. {
  522. set_gpio_maska(irq_to_gpio(d->irq), 0);
  523. }
  524. static void bfin_gpio_unmask_irq(struct irq_data *d)
  525. {
  526. set_gpio_maska(irq_to_gpio(d->irq), 1);
  527. }
  528. static unsigned int bfin_gpio_irq_startup(struct irq_data *d)
  529. {
  530. u32 gpionr = irq_to_gpio(d->irq);
  531. if (__test_and_set_bit(gpionr, gpio_enabled))
  532. bfin_gpio_irq_prepare(gpionr);
  533. bfin_gpio_unmask_irq(d);
  534. return 0;
  535. }
  536. static void bfin_gpio_irq_shutdown(struct irq_data *d)
  537. {
  538. u32 gpionr = irq_to_gpio(d->irq);
  539. bfin_gpio_mask_irq(d);
  540. __clear_bit(gpionr, gpio_enabled);
  541. bfin_gpio_irq_free(gpionr);
  542. }
  543. static int bfin_gpio_irq_type(struct irq_data *d, unsigned int type)
  544. {
  545. unsigned int irq = d->irq;
  546. int ret;
  547. char buf[16];
  548. u32 gpionr = irq_to_gpio(irq);
  549. if (type == IRQ_TYPE_PROBE) {
  550. /* only probe unenabled GPIO interrupt lines */
  551. if (test_bit(gpionr, gpio_enabled))
  552. return 0;
  553. type = IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING;
  554. }
  555. if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING |
  556. IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW)) {
  557. snprintf(buf, 16, "gpio-irq%d", irq);
  558. ret = bfin_gpio_irq_request(gpionr, buf);
  559. if (ret)
  560. return ret;
  561. if (__test_and_set_bit(gpionr, gpio_enabled))
  562. bfin_gpio_irq_prepare(gpionr);
  563. } else {
  564. __clear_bit(gpionr, gpio_enabled);
  565. return 0;
  566. }
  567. set_gpio_inen(gpionr, 0);
  568. set_gpio_dir(gpionr, 0);
  569. if ((type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING))
  570. == (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING))
  571. set_gpio_both(gpionr, 1);
  572. else
  573. set_gpio_both(gpionr, 0);
  574. if ((type & (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_LEVEL_LOW)))
  575. set_gpio_polar(gpionr, 1); /* low or falling edge denoted by one */
  576. else
  577. set_gpio_polar(gpionr, 0); /* high or rising edge denoted by zero */
  578. if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING)) {
  579. set_gpio_edge(gpionr, 1);
  580. set_gpio_inen(gpionr, 1);
  581. set_gpio_data(gpionr, 0);
  582. } else {
  583. set_gpio_edge(gpionr, 0);
  584. set_gpio_inen(gpionr, 1);
  585. }
  586. if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING))
  587. bfin_set_irq_handler(irq, handle_edge_irq);
  588. else
  589. bfin_set_irq_handler(irq, handle_level_irq);
  590. return 0;
  591. }
  592. #ifdef CONFIG_PM
  593. int bfin_gpio_set_wake(struct irq_data *d, unsigned int state)
  594. {
  595. return gpio_pm_wakeup_ctrl(irq_to_gpio(d->irq), state);
  596. }
  597. #endif
  598. static void bfin_demux_gpio_irq(unsigned int inta_irq,
  599. struct irq_desc *desc)
  600. {
  601. unsigned int i, gpio, mask, irq, search = 0;
  602. switch (inta_irq) {
  603. #if defined(CONFIG_BF53x)
  604. case IRQ_PROG_INTA:
  605. irq = IRQ_PF0;
  606. search = 1;
  607. break;
  608. # if defined(BF537_FAMILY) && !(defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE))
  609. case IRQ_MAC_RX:
  610. irq = IRQ_PH0;
  611. break;
  612. # endif
  613. #elif defined(CONFIG_BF538) || defined(CONFIG_BF539)
  614. case IRQ_PORTF_INTA:
  615. irq = IRQ_PF0;
  616. break;
  617. #elif defined(CONFIG_BF52x) || defined(CONFIG_BF51x)
  618. case IRQ_PORTF_INTA:
  619. irq = IRQ_PF0;
  620. break;
  621. case IRQ_PORTG_INTA:
  622. irq = IRQ_PG0;
  623. break;
  624. case IRQ_PORTH_INTA:
  625. irq = IRQ_PH0;
  626. break;
  627. #elif defined(CONFIG_BF561)
  628. case IRQ_PROG0_INTA:
  629. irq = IRQ_PF0;
  630. break;
  631. case IRQ_PROG1_INTA:
  632. irq = IRQ_PF16;
  633. break;
  634. case IRQ_PROG2_INTA:
  635. irq = IRQ_PF32;
  636. break;
  637. #endif
  638. default:
  639. BUG();
  640. return;
  641. }
  642. if (search) {
  643. for (i = 0; i < MAX_BLACKFIN_GPIOS; i += GPIO_BANKSIZE) {
  644. irq += i;
  645. mask = get_gpiop_data(i) & get_gpiop_maska(i);
  646. while (mask) {
  647. if (mask & 1)
  648. bfin_handle_irq(irq);
  649. irq++;
  650. mask >>= 1;
  651. }
  652. }
  653. } else {
  654. gpio = irq_to_gpio(irq);
  655. mask = get_gpiop_data(gpio) & get_gpiop_maska(gpio);
  656. do {
  657. if (mask & 1)
  658. bfin_handle_irq(irq);
  659. irq++;
  660. mask >>= 1;
  661. } while (mask);
  662. }
  663. }
  664. #else /* CONFIG_BF54x */
  665. #define NR_PINT_SYS_IRQS 4
  666. #define NR_PINT_BITS 32
  667. #define NR_PINTS 160
  668. #define IRQ_NOT_AVAIL 0xFF
  669. #define PINT_2_BANK(x) ((x) >> 5)
  670. #define PINT_2_BIT(x) ((x) & 0x1F)
  671. #define PINT_BIT(x) (1 << (PINT_2_BIT(x)))
  672. static unsigned char irq2pint_lut[NR_PINTS];
  673. static unsigned char pint2irq_lut[NR_PINT_SYS_IRQS * NR_PINT_BITS];
  674. struct pin_int_t {
  675. unsigned int mask_set;
  676. unsigned int mask_clear;
  677. unsigned int request;
  678. unsigned int assign;
  679. unsigned int edge_set;
  680. unsigned int edge_clear;
  681. unsigned int invert_set;
  682. unsigned int invert_clear;
  683. unsigned int pinstate;
  684. unsigned int latch;
  685. };
  686. static struct pin_int_t *pint[NR_PINT_SYS_IRQS] = {
  687. (struct pin_int_t *)PINT0_MASK_SET,
  688. (struct pin_int_t *)PINT1_MASK_SET,
  689. (struct pin_int_t *)PINT2_MASK_SET,
  690. (struct pin_int_t *)PINT3_MASK_SET,
  691. };
  692. inline unsigned int get_irq_base(u32 bank, u8 bmap)
  693. {
  694. unsigned int irq_base;
  695. if (bank < 2) { /*PA-PB */
  696. irq_base = IRQ_PA0 + bmap * 16;
  697. } else { /*PC-PJ */
  698. irq_base = IRQ_PC0 + bmap * 16;
  699. }
  700. return irq_base;
  701. }
  702. /* Whenever PINTx_ASSIGN is altered init_pint_lut() must be executed! */
  703. void init_pint_lut(void)
  704. {
  705. u16 bank, bit, irq_base, bit_pos;
  706. u32 pint_assign;
  707. u8 bmap;
  708. memset(irq2pint_lut, IRQ_NOT_AVAIL, sizeof(irq2pint_lut));
  709. for (bank = 0; bank < NR_PINT_SYS_IRQS; bank++) {
  710. pint_assign = pint[bank]->assign;
  711. for (bit = 0; bit < NR_PINT_BITS; bit++) {
  712. bmap = (pint_assign >> ((bit / 8) * 8)) & 0xFF;
  713. irq_base = get_irq_base(bank, bmap);
  714. irq_base += (bit % 8) + ((bit / 8) & 1 ? 8 : 0);
  715. bit_pos = bit + bank * NR_PINT_BITS;
  716. pint2irq_lut[bit_pos] = irq_base - SYS_IRQS;
  717. irq2pint_lut[irq_base - SYS_IRQS] = bit_pos;
  718. }
  719. }
  720. }
  721. static void bfin_gpio_ack_irq(struct irq_data *d)
  722. {
  723. struct irq_desc *desc = irq_to_desc(d->irq);
  724. u32 pint_val = irq2pint_lut[d->irq - SYS_IRQS];
  725. u32 pintbit = PINT_BIT(pint_val);
  726. u32 bank = PINT_2_BANK(pint_val);
  727. if ((desc->status & IRQ_TYPE_SENSE_MASK) == IRQ_TYPE_EDGE_BOTH) {
  728. if (pint[bank]->invert_set & pintbit)
  729. pint[bank]->invert_clear = pintbit;
  730. else
  731. pint[bank]->invert_set = pintbit;
  732. }
  733. pint[bank]->request = pintbit;
  734. }
  735. static void bfin_gpio_mask_ack_irq(struct irq_data *d)
  736. {
  737. struct irq_desc *desc = irq_to_desc(d->irq);
  738. u32 pint_val = irq2pint_lut[d->irq - SYS_IRQS];
  739. u32 pintbit = PINT_BIT(pint_val);
  740. u32 bank = PINT_2_BANK(pint_val);
  741. if ((desc->status & IRQ_TYPE_SENSE_MASK) == IRQ_TYPE_EDGE_BOTH) {
  742. if (pint[bank]->invert_set & pintbit)
  743. pint[bank]->invert_clear = pintbit;
  744. else
  745. pint[bank]->invert_set = pintbit;
  746. }
  747. pint[bank]->request = pintbit;
  748. pint[bank]->mask_clear = pintbit;
  749. }
  750. static void bfin_gpio_mask_irq(struct irq_data *d)
  751. {
  752. u32 pint_val = irq2pint_lut[d->irq - SYS_IRQS];
  753. pint[PINT_2_BANK(pint_val)]->mask_clear = PINT_BIT(pint_val);
  754. }
  755. static void bfin_gpio_unmask_irq(struct irq_data *d)
  756. {
  757. u32 pint_val = irq2pint_lut[d->irq - SYS_IRQS];
  758. u32 pintbit = PINT_BIT(pint_val);
  759. u32 bank = PINT_2_BANK(pint_val);
  760. pint[bank]->mask_set = pintbit;
  761. }
  762. static unsigned int bfin_gpio_irq_startup(struct irq_data *d)
  763. {
  764. unsigned int irq = d->irq;
  765. u32 gpionr = irq_to_gpio(irq);
  766. u32 pint_val = irq2pint_lut[irq - SYS_IRQS];
  767. if (pint_val == IRQ_NOT_AVAIL) {
  768. printk(KERN_ERR
  769. "GPIO IRQ %d :Not in PINT Assign table "
  770. "Reconfigure Interrupt to Port Assignemt\n", irq);
  771. return -ENODEV;
  772. }
  773. if (__test_and_set_bit(gpionr, gpio_enabled))
  774. bfin_gpio_irq_prepare(gpionr);
  775. bfin_gpio_unmask_irq(d);
  776. return 0;
  777. }
  778. static void bfin_gpio_irq_shutdown(struct irq_data *d)
  779. {
  780. u32 gpionr = irq_to_gpio(d->irq);
  781. bfin_gpio_mask_irq(d);
  782. __clear_bit(gpionr, gpio_enabled);
  783. bfin_gpio_irq_free(gpionr);
  784. }
  785. static int bfin_gpio_irq_type(struct irq_data *d, unsigned int type)
  786. {
  787. unsigned int irq = d->irq;
  788. int ret;
  789. char buf[16];
  790. u32 gpionr = irq_to_gpio(irq);
  791. u32 pint_val = irq2pint_lut[irq - SYS_IRQS];
  792. u32 pintbit = PINT_BIT(pint_val);
  793. u32 bank = PINT_2_BANK(pint_val);
  794. if (pint_val == IRQ_NOT_AVAIL)
  795. return -ENODEV;
  796. if (type == IRQ_TYPE_PROBE) {
  797. /* only probe unenabled GPIO interrupt lines */
  798. if (test_bit(gpionr, gpio_enabled))
  799. return 0;
  800. type = IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING;
  801. }
  802. if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING |
  803. IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW)) {
  804. snprintf(buf, 16, "gpio-irq%d", irq);
  805. ret = bfin_gpio_irq_request(gpionr, buf);
  806. if (ret)
  807. return ret;
  808. if (__test_and_set_bit(gpionr, gpio_enabled))
  809. bfin_gpio_irq_prepare(gpionr);
  810. } else {
  811. __clear_bit(gpionr, gpio_enabled);
  812. return 0;
  813. }
  814. if ((type & (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_LEVEL_LOW)))
  815. pint[bank]->invert_set = pintbit; /* low or falling edge denoted by one */
  816. else
  817. pint[bank]->invert_clear = pintbit; /* high or rising edge denoted by zero */
  818. if ((type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING))
  819. == (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING)) {
  820. if (gpio_get_value(gpionr))
  821. pint[bank]->invert_set = pintbit;
  822. else
  823. pint[bank]->invert_clear = pintbit;
  824. }
  825. if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING)) {
  826. pint[bank]->edge_set = pintbit;
  827. bfin_set_irq_handler(irq, handle_edge_irq);
  828. } else {
  829. pint[bank]->edge_clear = pintbit;
  830. bfin_set_irq_handler(irq, handle_level_irq);
  831. }
  832. return 0;
  833. }
  834. #ifdef CONFIG_PM
  835. u32 pint_saved_masks[NR_PINT_SYS_IRQS];
  836. u32 pint_wakeup_masks[NR_PINT_SYS_IRQS];
  837. int bfin_gpio_set_wake(struct irq_data *d, unsigned int state)
  838. {
  839. u32 pint_irq;
  840. u32 pint_val = irq2pint_lut[d->irq - SYS_IRQS];
  841. u32 bank = PINT_2_BANK(pint_val);
  842. u32 pintbit = PINT_BIT(pint_val);
  843. switch (bank) {
  844. case 0:
  845. pint_irq = IRQ_PINT0;
  846. break;
  847. case 2:
  848. pint_irq = IRQ_PINT2;
  849. break;
  850. case 3:
  851. pint_irq = IRQ_PINT3;
  852. break;
  853. case 1:
  854. pint_irq = IRQ_PINT1;
  855. break;
  856. default:
  857. return -EINVAL;
  858. }
  859. bfin_internal_set_wake(pint_irq, state);
  860. if (state)
  861. pint_wakeup_masks[bank] |= pintbit;
  862. else
  863. pint_wakeup_masks[bank] &= ~pintbit;
  864. return 0;
  865. }
  866. u32 bfin_pm_setup(void)
  867. {
  868. u32 val, i;
  869. for (i = 0; i < NR_PINT_SYS_IRQS; i++) {
  870. val = pint[i]->mask_clear;
  871. pint_saved_masks[i] = val;
  872. if (val ^ pint_wakeup_masks[i]) {
  873. pint[i]->mask_clear = val;
  874. pint[i]->mask_set = pint_wakeup_masks[i];
  875. }
  876. }
  877. return 0;
  878. }
  879. void bfin_pm_restore(void)
  880. {
  881. u32 i, val;
  882. for (i = 0; i < NR_PINT_SYS_IRQS; i++) {
  883. val = pint_saved_masks[i];
  884. if (val ^ pint_wakeup_masks[i]) {
  885. pint[i]->mask_clear = pint[i]->mask_clear;
  886. pint[i]->mask_set = val;
  887. }
  888. }
  889. }
  890. #endif
  891. static void bfin_demux_gpio_irq(unsigned int inta_irq,
  892. struct irq_desc *desc)
  893. {
  894. u32 bank, pint_val;
  895. u32 request, irq;
  896. switch (inta_irq) {
  897. case IRQ_PINT0:
  898. bank = 0;
  899. break;
  900. case IRQ_PINT2:
  901. bank = 2;
  902. break;
  903. case IRQ_PINT3:
  904. bank = 3;
  905. break;
  906. case IRQ_PINT1:
  907. bank = 1;
  908. break;
  909. default:
  910. return;
  911. }
  912. pint_val = bank * NR_PINT_BITS;
  913. request = pint[bank]->request;
  914. while (request) {
  915. if (request & 1) {
  916. irq = pint2irq_lut[pint_val] + SYS_IRQS;
  917. bfin_handle_irq(irq);
  918. }
  919. pint_val++;
  920. request >>= 1;
  921. }
  922. }
  923. #endif
  924. static struct irq_chip bfin_gpio_irqchip = {
  925. .name = "GPIO",
  926. .irq_ack = bfin_gpio_ack_irq,
  927. .irq_mask = bfin_gpio_mask_irq,
  928. .irq_mask_ack = bfin_gpio_mask_ack_irq,
  929. .irq_unmask = bfin_gpio_unmask_irq,
  930. .irq_disable = bfin_gpio_mask_irq,
  931. .irq_enable = bfin_gpio_unmask_irq,
  932. .irq_set_type = bfin_gpio_irq_type,
  933. .irq_startup = bfin_gpio_irq_startup,
  934. .irq_shutdown = bfin_gpio_irq_shutdown,
  935. #ifdef CONFIG_PM
  936. .irq_set_wake = bfin_gpio_set_wake,
  937. #endif
  938. };
  939. void __cpuinit init_exception_vectors(void)
  940. {
  941. /* cannot program in software:
  942. * evt0 - emulation (jtag)
  943. * evt1 - reset
  944. */
  945. bfin_write_EVT2(evt_nmi);
  946. bfin_write_EVT3(trap);
  947. bfin_write_EVT5(evt_ivhw);
  948. bfin_write_EVT6(evt_timer);
  949. bfin_write_EVT7(evt_evt7);
  950. bfin_write_EVT8(evt_evt8);
  951. bfin_write_EVT9(evt_evt9);
  952. bfin_write_EVT10(evt_evt10);
  953. bfin_write_EVT11(evt_evt11);
  954. bfin_write_EVT12(evt_evt12);
  955. bfin_write_EVT13(evt_evt13);
  956. bfin_write_EVT14(evt_evt14);
  957. bfin_write_EVT15(evt_system_call);
  958. CSYNC();
  959. }
  960. /*
  961. * This function should be called during kernel startup to initialize
  962. * the BFin IRQ handling routines.
  963. */
  964. int __init init_arch_irq(void)
  965. {
  966. int irq;
  967. unsigned long ilat = 0;
  968. /* Disable all the peripheral intrs - page 4-29 HW Ref manual */
  969. #if defined(CONFIG_BF54x) || defined(CONFIG_BF52x) || defined(CONFIG_BF561) \
  970. || defined(BF538_FAMILY) || defined(CONFIG_BF51x)
  971. bfin_write_SIC_IMASK0(SIC_UNMASK_ALL);
  972. bfin_write_SIC_IMASK1(SIC_UNMASK_ALL);
  973. # ifdef CONFIG_BF54x
  974. bfin_write_SIC_IMASK2(SIC_UNMASK_ALL);
  975. # endif
  976. # ifdef CONFIG_SMP
  977. bfin_write_SICB_IMASK0(SIC_UNMASK_ALL);
  978. bfin_write_SICB_IMASK1(SIC_UNMASK_ALL);
  979. # endif
  980. #else
  981. bfin_write_SIC_IMASK(SIC_UNMASK_ALL);
  982. #endif
  983. local_irq_disable();
  984. #if (defined(CONFIG_BF537) || defined(CONFIG_BF536))
  985. /* Clear EMAC Interrupt Status bits so we can demux it later */
  986. bfin_write_EMAC_SYSTAT(-1);
  987. #endif
  988. #ifdef CONFIG_BF54x
  989. # ifdef CONFIG_PINTx_REASSIGN
  990. pint[0]->assign = CONFIG_PINT0_ASSIGN;
  991. pint[1]->assign = CONFIG_PINT1_ASSIGN;
  992. pint[2]->assign = CONFIG_PINT2_ASSIGN;
  993. pint[3]->assign = CONFIG_PINT3_ASSIGN;
  994. # endif
  995. /* Whenever PINTx_ASSIGN is altered init_pint_lut() must be executed! */
  996. init_pint_lut();
  997. #endif
  998. for (irq = 0; irq <= SYS_IRQS; irq++) {
  999. if (irq <= IRQ_CORETMR)
  1000. set_irq_chip(irq, &bfin_core_irqchip);
  1001. else
  1002. set_irq_chip(irq, &bfin_internal_irqchip);
  1003. switch (irq) {
  1004. #if defined(CONFIG_BF53x)
  1005. case IRQ_PROG_INTA:
  1006. # if defined(BF537_FAMILY) && !(defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE))
  1007. case IRQ_MAC_RX:
  1008. # endif
  1009. #elif defined(CONFIG_BF54x)
  1010. case IRQ_PINT0:
  1011. case IRQ_PINT1:
  1012. case IRQ_PINT2:
  1013. case IRQ_PINT3:
  1014. #elif defined(CONFIG_BF52x) || defined(CONFIG_BF51x)
  1015. case IRQ_PORTF_INTA:
  1016. case IRQ_PORTG_INTA:
  1017. case IRQ_PORTH_INTA:
  1018. #elif defined(CONFIG_BF561)
  1019. case IRQ_PROG0_INTA:
  1020. case IRQ_PROG1_INTA:
  1021. case IRQ_PROG2_INTA:
  1022. #elif defined(CONFIG_BF538) || defined(CONFIG_BF539)
  1023. case IRQ_PORTF_INTA:
  1024. #endif
  1025. set_irq_chained_handler(irq,
  1026. bfin_demux_gpio_irq);
  1027. break;
  1028. #ifdef BF537_GENERIC_ERROR_INT_DEMUX
  1029. case IRQ_GENERIC_ERROR:
  1030. set_irq_chained_handler(irq, bfin_demux_error_irq);
  1031. break;
  1032. #endif
  1033. #if defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE)
  1034. case IRQ_MAC_ERROR:
  1035. set_irq_chained_handler(irq, bfin_demux_mac_status_irq);
  1036. break;
  1037. #endif
  1038. #ifdef CONFIG_SMP
  1039. case IRQ_SUPPLE_0:
  1040. case IRQ_SUPPLE_1:
  1041. set_irq_handler(irq, handle_percpu_irq);
  1042. break;
  1043. #endif
  1044. #ifdef CONFIG_TICKSOURCE_CORETMR
  1045. case IRQ_CORETMR:
  1046. # ifdef CONFIG_SMP
  1047. set_irq_handler(irq, handle_percpu_irq);
  1048. break;
  1049. # else
  1050. set_irq_handler(irq, handle_simple_irq);
  1051. break;
  1052. # endif
  1053. #endif
  1054. #ifdef CONFIG_TICKSOURCE_GPTMR0
  1055. case IRQ_TIMER0:
  1056. set_irq_handler(irq, handle_simple_irq);
  1057. break;
  1058. #endif
  1059. #ifdef CONFIG_IPIPE
  1060. default:
  1061. set_irq_handler(irq, handle_level_irq);
  1062. break;
  1063. #else /* !CONFIG_IPIPE */
  1064. default:
  1065. set_irq_handler(irq, handle_simple_irq);
  1066. break;
  1067. #endif /* !CONFIG_IPIPE */
  1068. }
  1069. }
  1070. #ifdef BF537_GENERIC_ERROR_INT_DEMUX
  1071. for (irq = IRQ_PPI_ERROR; irq <= IRQ_UART1_ERROR; irq++)
  1072. set_irq_chip_and_handler(irq, &bfin_generic_error_irqchip,
  1073. handle_level_irq);
  1074. #if defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE)
  1075. set_irq_chained_handler(IRQ_MAC_ERROR, bfin_demux_mac_status_irq);
  1076. #endif
  1077. #endif
  1078. #if defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE)
  1079. for (irq = IRQ_MAC_PHYINT; irq <= IRQ_MAC_STMDONE; irq++)
  1080. set_irq_chip_and_handler(irq, &bfin_mac_status_irqchip,
  1081. handle_level_irq);
  1082. #endif
  1083. /* if configured as edge, then will be changed to do_edge_IRQ */
  1084. for (irq = GPIO_IRQ_BASE;
  1085. irq < (GPIO_IRQ_BASE + MAX_BLACKFIN_GPIOS); irq++)
  1086. set_irq_chip_and_handler(irq, &bfin_gpio_irqchip,
  1087. handle_level_irq);
  1088. bfin_write_IMASK(0);
  1089. CSYNC();
  1090. ilat = bfin_read_ILAT();
  1091. CSYNC();
  1092. bfin_write_ILAT(ilat);
  1093. CSYNC();
  1094. printk(KERN_INFO "Configuring Blackfin Priority Driven Interrupts\n");
  1095. /* IMASK=xxx is equivalent to STI xx or bfin_irq_flags=xx,
  1096. * local_irq_enable()
  1097. */
  1098. program_IAR();
  1099. /* Therefore it's better to setup IARs before interrupts enabled */
  1100. search_IAR();
  1101. /* Enable interrupts IVG7-15 */
  1102. bfin_irq_flags |= IMASK_IVG15 |
  1103. IMASK_IVG14 | IMASK_IVG13 | IMASK_IVG12 | IMASK_IVG11 |
  1104. IMASK_IVG10 | IMASK_IVG9 | IMASK_IVG8 | IMASK_IVG7 | IMASK_IVGHW;
  1105. /* This implicitly covers ANOMALY_05000171
  1106. * Boot-ROM code modifies SICA_IWRx wakeup registers
  1107. */
  1108. #ifdef SIC_IWR0
  1109. bfin_write_SIC_IWR0(IWR_DISABLE_ALL);
  1110. # ifdef SIC_IWR1
  1111. /* BF52x/BF51x system reset does not properly reset SIC_IWR1 which
  1112. * will screw up the bootrom as it relies on MDMA0/1 waking it
  1113. * up from IDLE instructions. See this report for more info:
  1114. * http://blackfin.uclinux.org/gf/tracker/4323
  1115. */
  1116. if (ANOMALY_05000435)
  1117. bfin_write_SIC_IWR1(IWR_ENABLE(10) | IWR_ENABLE(11));
  1118. else
  1119. bfin_write_SIC_IWR1(IWR_DISABLE_ALL);
  1120. # endif
  1121. # ifdef SIC_IWR2
  1122. bfin_write_SIC_IWR2(IWR_DISABLE_ALL);
  1123. # endif
  1124. #else
  1125. bfin_write_SIC_IWR(IWR_DISABLE_ALL);
  1126. #endif
  1127. return 0;
  1128. }
  1129. #ifdef CONFIG_DO_IRQ_L1
  1130. __attribute__((l1_text))
  1131. #endif
  1132. void do_irq(int vec, struct pt_regs *fp)
  1133. {
  1134. if (vec == EVT_IVTMR_P) {
  1135. vec = IRQ_CORETMR;
  1136. } else {
  1137. struct ivgx *ivg = ivg7_13[vec - IVG7].ifirst;
  1138. struct ivgx *ivg_stop = ivg7_13[vec - IVG7].istop;
  1139. #if defined(SIC_ISR0)
  1140. unsigned long sic_status[3];
  1141. if (smp_processor_id()) {
  1142. # ifdef SICB_ISR0
  1143. /* This will be optimized out in UP mode. */
  1144. sic_status[0] = bfin_read_SICB_ISR0() & bfin_read_SICB_IMASK0();
  1145. sic_status[1] = bfin_read_SICB_ISR1() & bfin_read_SICB_IMASK1();
  1146. # endif
  1147. } else {
  1148. sic_status[0] = bfin_read_SIC_ISR0() & bfin_read_SIC_IMASK0();
  1149. sic_status[1] = bfin_read_SIC_ISR1() & bfin_read_SIC_IMASK1();
  1150. }
  1151. # ifdef SIC_ISR2
  1152. sic_status[2] = bfin_read_SIC_ISR2() & bfin_read_SIC_IMASK2();
  1153. # endif
  1154. for (;; ivg++) {
  1155. if (ivg >= ivg_stop) {
  1156. atomic_inc(&num_spurious);
  1157. return;
  1158. }
  1159. if (sic_status[(ivg->irqno - IVG7) / 32] & ivg->isrflag)
  1160. break;
  1161. }
  1162. #else
  1163. unsigned long sic_status;
  1164. sic_status = bfin_read_SIC_IMASK() & bfin_read_SIC_ISR();
  1165. for (;; ivg++) {
  1166. if (ivg >= ivg_stop) {
  1167. atomic_inc(&num_spurious);
  1168. return;
  1169. } else if (sic_status & ivg->isrflag)
  1170. break;
  1171. }
  1172. #endif
  1173. vec = ivg->irqno;
  1174. }
  1175. asm_do_IRQ(vec, fp);
  1176. }
  1177. #ifdef CONFIG_IPIPE
  1178. int __ipipe_get_irq_priority(unsigned irq)
  1179. {
  1180. int ient, prio;
  1181. if (irq <= IRQ_CORETMR)
  1182. return irq;
  1183. for (ient = 0; ient < NR_PERI_INTS; ient++) {
  1184. struct ivgx *ivg = ivg_table + ient;
  1185. if (ivg->irqno == irq) {
  1186. for (prio = 0; prio <= IVG13-IVG7; prio++) {
  1187. if (ivg7_13[prio].ifirst <= ivg &&
  1188. ivg7_13[prio].istop > ivg)
  1189. return IVG7 + prio;
  1190. }
  1191. }
  1192. }
  1193. return IVG15;
  1194. }
  1195. /* Hw interrupts are disabled on entry (check SAVE_CONTEXT). */
  1196. #ifdef CONFIG_DO_IRQ_L1
  1197. __attribute__((l1_text))
  1198. #endif
  1199. asmlinkage int __ipipe_grab_irq(int vec, struct pt_regs *regs)
  1200. {
  1201. struct ipipe_percpu_domain_data *p = ipipe_root_cpudom_ptr();
  1202. struct ipipe_domain *this_domain = __ipipe_current_domain;
  1203. struct ivgx *ivg_stop = ivg7_13[vec-IVG7].istop;
  1204. struct ivgx *ivg = ivg7_13[vec-IVG7].ifirst;
  1205. int irq, s = 0;
  1206. if (likely(vec == EVT_IVTMR_P))
  1207. irq = IRQ_CORETMR;
  1208. else {
  1209. #if defined(SIC_ISR0)
  1210. unsigned long sic_status[3];
  1211. sic_status[0] = bfin_read_SIC_ISR0() & bfin_read_SIC_IMASK0();
  1212. sic_status[1] = bfin_read_SIC_ISR1() & bfin_read_SIC_IMASK1();
  1213. # ifdef SIC_ISR2
  1214. sic_status[2] = bfin_read_SIC_ISR2() & bfin_read_SIC_IMASK2();
  1215. # endif
  1216. for (;; ivg++) {
  1217. if (ivg >= ivg_stop) {
  1218. atomic_inc(&num_spurious);
  1219. return 0;
  1220. }
  1221. if (sic_status[(ivg->irqno - IVG7) / 32] & ivg->isrflag)
  1222. break;
  1223. }
  1224. #else
  1225. unsigned long sic_status;
  1226. sic_status = bfin_read_SIC_IMASK() & bfin_read_SIC_ISR();
  1227. for (;; ivg++) {
  1228. if (ivg >= ivg_stop) {
  1229. atomic_inc(&num_spurious);
  1230. return 0;
  1231. } else if (sic_status & ivg->isrflag)
  1232. break;
  1233. }
  1234. #endif
  1235. irq = ivg->irqno;
  1236. }
  1237. if (irq == IRQ_SYSTMR) {
  1238. #if !defined(CONFIG_GENERIC_CLOCKEVENTS) || defined(CONFIG_TICKSOURCE_GPTMR0)
  1239. bfin_write_TIMER_STATUS(1); /* Latch TIMIL0 */
  1240. #endif
  1241. /* This is basically what we need from the register frame. */
  1242. __raw_get_cpu_var(__ipipe_tick_regs).ipend = regs->ipend;
  1243. __raw_get_cpu_var(__ipipe_tick_regs).pc = regs->pc;
  1244. if (this_domain != ipipe_root_domain)
  1245. __raw_get_cpu_var(__ipipe_tick_regs).ipend &= ~0x10;
  1246. else
  1247. __raw_get_cpu_var(__ipipe_tick_regs).ipend |= 0x10;
  1248. }
  1249. /*
  1250. * We don't want Linux interrupt handlers to run at the
  1251. * current core priority level (i.e. < EVT15), since this
  1252. * might delay other interrupts handled by a high priority
  1253. * domain. Here is what we do instead:
  1254. *
  1255. * - we raise the SYNCDEFER bit to prevent
  1256. * __ipipe_handle_irq() to sync the pipeline for the root
  1257. * stage for the incoming interrupt. Upon return, that IRQ is
  1258. * pending in the interrupt log.
  1259. *
  1260. * - we raise the TIF_IRQ_SYNC bit for the current thread, so
  1261. * that _schedule_and_signal_from_int will eventually sync the
  1262. * pipeline from EVT15.
  1263. */
  1264. if (this_domain == ipipe_root_domain) {
  1265. s = __test_and_set_bit(IPIPE_SYNCDEFER_FLAG, &p->status);
  1266. barrier();
  1267. }
  1268. ipipe_trace_irq_entry(irq);
  1269. __ipipe_handle_irq(irq, regs);
  1270. ipipe_trace_irq_exit(irq);
  1271. if (user_mode(regs) &&
  1272. !ipipe_test_foreign_stack() &&
  1273. (current->ipipe_flags & PF_EVTRET) != 0) {
  1274. /*
  1275. * Testing for user_regs() does NOT fully eliminate
  1276. * foreign stack contexts, because of the forged
  1277. * interrupt returns we do through
  1278. * __ipipe_call_irqtail. In that case, we might have
  1279. * preempted a foreign stack context in a high
  1280. * priority domain, with a single interrupt level now
  1281. * pending after the irqtail unwinding is done. In
  1282. * which case user_mode() is now true, and the event
  1283. * gets dispatched spuriously.
  1284. */
  1285. current->ipipe_flags &= ~PF_EVTRET;
  1286. __ipipe_dispatch_event(IPIPE_EVENT_RETURN, regs);
  1287. }
  1288. if (this_domain == ipipe_root_domain) {
  1289. set_thread_flag(TIF_IRQ_SYNC);
  1290. if (!s) {
  1291. __clear_bit(IPIPE_SYNCDEFER_FLAG, &p->status);
  1292. return !test_bit(IPIPE_STALL_FLAG, &p->status);
  1293. }
  1294. }
  1295. return 0;
  1296. }
  1297. #endif /* CONFIG_IPIPE */