ints-priority.c 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495
  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. __irq_set_handler_locked(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. u32 gpionr = irq_to_gpio(irq);
  515. if (!irqd_is_level_type(d))
  516. set_gpio_data(gpionr, 0);
  517. set_gpio_maska(gpionr, 0);
  518. }
  519. static void bfin_gpio_mask_irq(struct irq_data *d)
  520. {
  521. set_gpio_maska(irq_to_gpio(d->irq), 0);
  522. }
  523. static void bfin_gpio_unmask_irq(struct irq_data *d)
  524. {
  525. set_gpio_maska(irq_to_gpio(d->irq), 1);
  526. }
  527. static unsigned int bfin_gpio_irq_startup(struct irq_data *d)
  528. {
  529. u32 gpionr = irq_to_gpio(d->irq);
  530. if (__test_and_set_bit(gpionr, gpio_enabled))
  531. bfin_gpio_irq_prepare(gpionr);
  532. bfin_gpio_unmask_irq(d);
  533. return 0;
  534. }
  535. static void bfin_gpio_irq_shutdown(struct irq_data *d)
  536. {
  537. u32 gpionr = irq_to_gpio(d->irq);
  538. bfin_gpio_mask_irq(d);
  539. __clear_bit(gpionr, gpio_enabled);
  540. bfin_gpio_irq_free(gpionr);
  541. }
  542. static int bfin_gpio_irq_type(struct irq_data *d, unsigned int type)
  543. {
  544. unsigned int irq = d->irq;
  545. int ret;
  546. char buf[16];
  547. u32 gpionr = irq_to_gpio(irq);
  548. if (type == IRQ_TYPE_PROBE) {
  549. /* only probe unenabled GPIO interrupt lines */
  550. if (test_bit(gpionr, gpio_enabled))
  551. return 0;
  552. type = IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING;
  553. }
  554. if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING |
  555. IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW)) {
  556. snprintf(buf, 16, "gpio-irq%d", irq);
  557. ret = bfin_gpio_irq_request(gpionr, buf);
  558. if (ret)
  559. return ret;
  560. if (__test_and_set_bit(gpionr, gpio_enabled))
  561. bfin_gpio_irq_prepare(gpionr);
  562. } else {
  563. __clear_bit(gpionr, gpio_enabled);
  564. return 0;
  565. }
  566. set_gpio_inen(gpionr, 0);
  567. set_gpio_dir(gpionr, 0);
  568. if ((type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING))
  569. == (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING))
  570. set_gpio_both(gpionr, 1);
  571. else
  572. set_gpio_both(gpionr, 0);
  573. if ((type & (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_LEVEL_LOW)))
  574. set_gpio_polar(gpionr, 1); /* low or falling edge denoted by one */
  575. else
  576. set_gpio_polar(gpionr, 0); /* high or rising edge denoted by zero */
  577. if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING)) {
  578. set_gpio_edge(gpionr, 1);
  579. set_gpio_inen(gpionr, 1);
  580. set_gpio_data(gpionr, 0);
  581. } else {
  582. set_gpio_edge(gpionr, 0);
  583. set_gpio_inen(gpionr, 1);
  584. }
  585. if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING))
  586. bfin_set_irq_handler(irq, handle_edge_irq);
  587. else
  588. bfin_set_irq_handler(irq, handle_level_irq);
  589. return 0;
  590. }
  591. #ifdef CONFIG_PM
  592. int bfin_gpio_set_wake(struct irq_data *d, unsigned int state)
  593. {
  594. return gpio_pm_wakeup_ctrl(irq_to_gpio(d->irq), state);
  595. }
  596. #endif
  597. static void bfin_demux_gpio_irq(unsigned int inta_irq,
  598. struct irq_desc *desc)
  599. {
  600. unsigned int i, gpio, mask, irq, search = 0;
  601. switch (inta_irq) {
  602. #if defined(CONFIG_BF53x)
  603. case IRQ_PROG_INTA:
  604. irq = IRQ_PF0;
  605. search = 1;
  606. break;
  607. # if defined(BF537_FAMILY) && !(defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE))
  608. case IRQ_MAC_RX:
  609. irq = IRQ_PH0;
  610. break;
  611. # endif
  612. #elif defined(CONFIG_BF538) || defined(CONFIG_BF539)
  613. case IRQ_PORTF_INTA:
  614. irq = IRQ_PF0;
  615. break;
  616. #elif defined(CONFIG_BF52x) || defined(CONFIG_BF51x)
  617. case IRQ_PORTF_INTA:
  618. irq = IRQ_PF0;
  619. break;
  620. case IRQ_PORTG_INTA:
  621. irq = IRQ_PG0;
  622. break;
  623. case IRQ_PORTH_INTA:
  624. irq = IRQ_PH0;
  625. break;
  626. #elif defined(CONFIG_BF561)
  627. case IRQ_PROG0_INTA:
  628. irq = IRQ_PF0;
  629. break;
  630. case IRQ_PROG1_INTA:
  631. irq = IRQ_PF16;
  632. break;
  633. case IRQ_PROG2_INTA:
  634. irq = IRQ_PF32;
  635. break;
  636. #endif
  637. default:
  638. BUG();
  639. return;
  640. }
  641. if (search) {
  642. for (i = 0; i < MAX_BLACKFIN_GPIOS; i += GPIO_BANKSIZE) {
  643. irq += i;
  644. mask = get_gpiop_data(i) & get_gpiop_maska(i);
  645. while (mask) {
  646. if (mask & 1)
  647. bfin_handle_irq(irq);
  648. irq++;
  649. mask >>= 1;
  650. }
  651. }
  652. } else {
  653. gpio = irq_to_gpio(irq);
  654. mask = get_gpiop_data(gpio) & get_gpiop_maska(gpio);
  655. do {
  656. if (mask & 1)
  657. bfin_handle_irq(irq);
  658. irq++;
  659. mask >>= 1;
  660. } while (mask);
  661. }
  662. }
  663. #else /* CONFIG_BF54x */
  664. #define NR_PINT_SYS_IRQS 4
  665. #define NR_PINT_BITS 32
  666. #define NR_PINTS 160
  667. #define IRQ_NOT_AVAIL 0xFF
  668. #define PINT_2_BANK(x) ((x) >> 5)
  669. #define PINT_2_BIT(x) ((x) & 0x1F)
  670. #define PINT_BIT(x) (1 << (PINT_2_BIT(x)))
  671. static unsigned char irq2pint_lut[NR_PINTS];
  672. static unsigned char pint2irq_lut[NR_PINT_SYS_IRQS * NR_PINT_BITS];
  673. struct pin_int_t {
  674. unsigned int mask_set;
  675. unsigned int mask_clear;
  676. unsigned int request;
  677. unsigned int assign;
  678. unsigned int edge_set;
  679. unsigned int edge_clear;
  680. unsigned int invert_set;
  681. unsigned int invert_clear;
  682. unsigned int pinstate;
  683. unsigned int latch;
  684. };
  685. static struct pin_int_t *pint[NR_PINT_SYS_IRQS] = {
  686. (struct pin_int_t *)PINT0_MASK_SET,
  687. (struct pin_int_t *)PINT1_MASK_SET,
  688. (struct pin_int_t *)PINT2_MASK_SET,
  689. (struct pin_int_t *)PINT3_MASK_SET,
  690. };
  691. inline unsigned int get_irq_base(u32 bank, u8 bmap)
  692. {
  693. unsigned int irq_base;
  694. if (bank < 2) { /*PA-PB */
  695. irq_base = IRQ_PA0 + bmap * 16;
  696. } else { /*PC-PJ */
  697. irq_base = IRQ_PC0 + bmap * 16;
  698. }
  699. return irq_base;
  700. }
  701. /* Whenever PINTx_ASSIGN is altered init_pint_lut() must be executed! */
  702. void init_pint_lut(void)
  703. {
  704. u16 bank, bit, irq_base, bit_pos;
  705. u32 pint_assign;
  706. u8 bmap;
  707. memset(irq2pint_lut, IRQ_NOT_AVAIL, sizeof(irq2pint_lut));
  708. for (bank = 0; bank < NR_PINT_SYS_IRQS; bank++) {
  709. pint_assign = pint[bank]->assign;
  710. for (bit = 0; bit < NR_PINT_BITS; bit++) {
  711. bmap = (pint_assign >> ((bit / 8) * 8)) & 0xFF;
  712. irq_base = get_irq_base(bank, bmap);
  713. irq_base += (bit % 8) + ((bit / 8) & 1 ? 8 : 0);
  714. bit_pos = bit + bank * NR_PINT_BITS;
  715. pint2irq_lut[bit_pos] = irq_base - SYS_IRQS;
  716. irq2pint_lut[irq_base - SYS_IRQS] = bit_pos;
  717. }
  718. }
  719. }
  720. static void bfin_gpio_ack_irq(struct irq_data *d)
  721. {
  722. u32 pint_val = irq2pint_lut[d->irq - SYS_IRQS];
  723. u32 pintbit = PINT_BIT(pint_val);
  724. u32 bank = PINT_2_BANK(pint_val);
  725. if (irqd_get_trigger_type(d) == IRQ_TYPE_EDGE_BOTH) {
  726. if (pint[bank]->invert_set & pintbit)
  727. pint[bank]->invert_clear = pintbit;
  728. else
  729. pint[bank]->invert_set = pintbit;
  730. }
  731. pint[bank]->request = pintbit;
  732. }
  733. static void bfin_gpio_mask_ack_irq(struct irq_data *d)
  734. {
  735. u32 pint_val = irq2pint_lut[d->irq - SYS_IRQS];
  736. u32 pintbit = PINT_BIT(pint_val);
  737. u32 bank = PINT_2_BANK(pint_val);
  738. if (irqd_get_trigger_type(d) == IRQ_TYPE_EDGE_BOTH) {
  739. if (pint[bank]->invert_set & pintbit)
  740. pint[bank]->invert_clear = pintbit;
  741. else
  742. pint[bank]->invert_set = pintbit;
  743. }
  744. pint[bank]->request = pintbit;
  745. pint[bank]->mask_clear = pintbit;
  746. }
  747. static void bfin_gpio_mask_irq(struct irq_data *d)
  748. {
  749. u32 pint_val = irq2pint_lut[d->irq - SYS_IRQS];
  750. pint[PINT_2_BANK(pint_val)]->mask_clear = PINT_BIT(pint_val);
  751. }
  752. static void bfin_gpio_unmask_irq(struct irq_data *d)
  753. {
  754. u32 pint_val = irq2pint_lut[d->irq - SYS_IRQS];
  755. u32 pintbit = PINT_BIT(pint_val);
  756. u32 bank = PINT_2_BANK(pint_val);
  757. pint[bank]->mask_set = pintbit;
  758. }
  759. static unsigned int bfin_gpio_irq_startup(struct irq_data *d)
  760. {
  761. unsigned int irq = d->irq;
  762. u32 gpionr = irq_to_gpio(irq);
  763. u32 pint_val = irq2pint_lut[irq - SYS_IRQS];
  764. if (pint_val == IRQ_NOT_AVAIL) {
  765. printk(KERN_ERR
  766. "GPIO IRQ %d :Not in PINT Assign table "
  767. "Reconfigure Interrupt to Port Assignemt\n", irq);
  768. return -ENODEV;
  769. }
  770. if (__test_and_set_bit(gpionr, gpio_enabled))
  771. bfin_gpio_irq_prepare(gpionr);
  772. bfin_gpio_unmask_irq(d);
  773. return 0;
  774. }
  775. static void bfin_gpio_irq_shutdown(struct irq_data *d)
  776. {
  777. u32 gpionr = irq_to_gpio(d->irq);
  778. bfin_gpio_mask_irq(d);
  779. __clear_bit(gpionr, gpio_enabled);
  780. bfin_gpio_irq_free(gpionr);
  781. }
  782. static int bfin_gpio_irq_type(struct irq_data *d, unsigned int type)
  783. {
  784. unsigned int irq = d->irq;
  785. int ret;
  786. char buf[16];
  787. u32 gpionr = irq_to_gpio(irq);
  788. u32 pint_val = irq2pint_lut[irq - SYS_IRQS];
  789. u32 pintbit = PINT_BIT(pint_val);
  790. u32 bank = PINT_2_BANK(pint_val);
  791. if (pint_val == IRQ_NOT_AVAIL)
  792. return -ENODEV;
  793. if (type == IRQ_TYPE_PROBE) {
  794. /* only probe unenabled GPIO interrupt lines */
  795. if (test_bit(gpionr, gpio_enabled))
  796. return 0;
  797. type = IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING;
  798. }
  799. if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING |
  800. IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW)) {
  801. snprintf(buf, 16, "gpio-irq%d", irq);
  802. ret = bfin_gpio_irq_request(gpionr, buf);
  803. if (ret)
  804. return ret;
  805. if (__test_and_set_bit(gpionr, gpio_enabled))
  806. bfin_gpio_irq_prepare(gpionr);
  807. } else {
  808. __clear_bit(gpionr, gpio_enabled);
  809. return 0;
  810. }
  811. if ((type & (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_LEVEL_LOW)))
  812. pint[bank]->invert_set = pintbit; /* low or falling edge denoted by one */
  813. else
  814. pint[bank]->invert_clear = pintbit; /* high or rising edge denoted by zero */
  815. if ((type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING))
  816. == (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING)) {
  817. if (gpio_get_value(gpionr))
  818. pint[bank]->invert_set = pintbit;
  819. else
  820. pint[bank]->invert_clear = pintbit;
  821. }
  822. if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING)) {
  823. pint[bank]->edge_set = pintbit;
  824. bfin_set_irq_handler(irq, handle_edge_irq);
  825. } else {
  826. pint[bank]->edge_clear = pintbit;
  827. bfin_set_irq_handler(irq, handle_level_irq);
  828. }
  829. return 0;
  830. }
  831. #ifdef CONFIG_PM
  832. u32 pint_saved_masks[NR_PINT_SYS_IRQS];
  833. u32 pint_wakeup_masks[NR_PINT_SYS_IRQS];
  834. int bfin_gpio_set_wake(struct irq_data *d, unsigned int state)
  835. {
  836. u32 pint_irq;
  837. u32 pint_val = irq2pint_lut[d->irq - SYS_IRQS];
  838. u32 bank = PINT_2_BANK(pint_val);
  839. u32 pintbit = PINT_BIT(pint_val);
  840. switch (bank) {
  841. case 0:
  842. pint_irq = IRQ_PINT0;
  843. break;
  844. case 2:
  845. pint_irq = IRQ_PINT2;
  846. break;
  847. case 3:
  848. pint_irq = IRQ_PINT3;
  849. break;
  850. case 1:
  851. pint_irq = IRQ_PINT1;
  852. break;
  853. default:
  854. return -EINVAL;
  855. }
  856. bfin_internal_set_wake(pint_irq, state);
  857. if (state)
  858. pint_wakeup_masks[bank] |= pintbit;
  859. else
  860. pint_wakeup_masks[bank] &= ~pintbit;
  861. return 0;
  862. }
  863. u32 bfin_pm_setup(void)
  864. {
  865. u32 val, i;
  866. for (i = 0; i < NR_PINT_SYS_IRQS; i++) {
  867. val = pint[i]->mask_clear;
  868. pint_saved_masks[i] = val;
  869. if (val ^ pint_wakeup_masks[i]) {
  870. pint[i]->mask_clear = val;
  871. pint[i]->mask_set = pint_wakeup_masks[i];
  872. }
  873. }
  874. return 0;
  875. }
  876. void bfin_pm_restore(void)
  877. {
  878. u32 i, val;
  879. for (i = 0; i < NR_PINT_SYS_IRQS; i++) {
  880. val = pint_saved_masks[i];
  881. if (val ^ pint_wakeup_masks[i]) {
  882. pint[i]->mask_clear = pint[i]->mask_clear;
  883. pint[i]->mask_set = val;
  884. }
  885. }
  886. }
  887. #endif
  888. static void bfin_demux_gpio_irq(unsigned int inta_irq,
  889. struct irq_desc *desc)
  890. {
  891. u32 bank, pint_val;
  892. u32 request, irq;
  893. switch (inta_irq) {
  894. case IRQ_PINT0:
  895. bank = 0;
  896. break;
  897. case IRQ_PINT2:
  898. bank = 2;
  899. break;
  900. case IRQ_PINT3:
  901. bank = 3;
  902. break;
  903. case IRQ_PINT1:
  904. bank = 1;
  905. break;
  906. default:
  907. return;
  908. }
  909. pint_val = bank * NR_PINT_BITS;
  910. request = pint[bank]->request;
  911. while (request) {
  912. if (request & 1) {
  913. irq = pint2irq_lut[pint_val] + SYS_IRQS;
  914. bfin_handle_irq(irq);
  915. }
  916. pint_val++;
  917. request >>= 1;
  918. }
  919. }
  920. #endif
  921. static struct irq_chip bfin_gpio_irqchip = {
  922. .name = "GPIO",
  923. .irq_ack = bfin_gpio_ack_irq,
  924. .irq_mask = bfin_gpio_mask_irq,
  925. .irq_mask_ack = bfin_gpio_mask_ack_irq,
  926. .irq_unmask = bfin_gpio_unmask_irq,
  927. .irq_disable = bfin_gpio_mask_irq,
  928. .irq_enable = bfin_gpio_unmask_irq,
  929. .irq_set_type = bfin_gpio_irq_type,
  930. .irq_startup = bfin_gpio_irq_startup,
  931. .irq_shutdown = bfin_gpio_irq_shutdown,
  932. #ifdef CONFIG_PM
  933. .irq_set_wake = bfin_gpio_set_wake,
  934. #endif
  935. };
  936. void __cpuinit init_exception_vectors(void)
  937. {
  938. /* cannot program in software:
  939. * evt0 - emulation (jtag)
  940. * evt1 - reset
  941. */
  942. bfin_write_EVT2(evt_nmi);
  943. bfin_write_EVT3(trap);
  944. bfin_write_EVT5(evt_ivhw);
  945. bfin_write_EVT6(evt_timer);
  946. bfin_write_EVT7(evt_evt7);
  947. bfin_write_EVT8(evt_evt8);
  948. bfin_write_EVT9(evt_evt9);
  949. bfin_write_EVT10(evt_evt10);
  950. bfin_write_EVT11(evt_evt11);
  951. bfin_write_EVT12(evt_evt12);
  952. bfin_write_EVT13(evt_evt13);
  953. bfin_write_EVT14(evt_evt14);
  954. bfin_write_EVT15(evt_system_call);
  955. CSYNC();
  956. }
  957. /*
  958. * This function should be called during kernel startup to initialize
  959. * the BFin IRQ handling routines.
  960. */
  961. int __init init_arch_irq(void)
  962. {
  963. int irq;
  964. unsigned long ilat = 0;
  965. /* Disable all the peripheral intrs - page 4-29 HW Ref manual */
  966. #if defined(CONFIG_BF54x) || defined(CONFIG_BF52x) || defined(CONFIG_BF561) \
  967. || defined(BF538_FAMILY) || defined(CONFIG_BF51x)
  968. bfin_write_SIC_IMASK0(SIC_UNMASK_ALL);
  969. bfin_write_SIC_IMASK1(SIC_UNMASK_ALL);
  970. # ifdef CONFIG_BF54x
  971. bfin_write_SIC_IMASK2(SIC_UNMASK_ALL);
  972. # endif
  973. # ifdef CONFIG_SMP
  974. bfin_write_SICB_IMASK0(SIC_UNMASK_ALL);
  975. bfin_write_SICB_IMASK1(SIC_UNMASK_ALL);
  976. # endif
  977. #else
  978. bfin_write_SIC_IMASK(SIC_UNMASK_ALL);
  979. #endif
  980. local_irq_disable();
  981. #if (defined(CONFIG_BF537) || defined(CONFIG_BF536))
  982. /* Clear EMAC Interrupt Status bits so we can demux it later */
  983. bfin_write_EMAC_SYSTAT(-1);
  984. #endif
  985. #ifdef CONFIG_BF54x
  986. # ifdef CONFIG_PINTx_REASSIGN
  987. pint[0]->assign = CONFIG_PINT0_ASSIGN;
  988. pint[1]->assign = CONFIG_PINT1_ASSIGN;
  989. pint[2]->assign = CONFIG_PINT2_ASSIGN;
  990. pint[3]->assign = CONFIG_PINT3_ASSIGN;
  991. # endif
  992. /* Whenever PINTx_ASSIGN is altered init_pint_lut() must be executed! */
  993. init_pint_lut();
  994. #endif
  995. for (irq = 0; irq <= SYS_IRQS; irq++) {
  996. if (irq <= IRQ_CORETMR)
  997. irq_set_chip(irq, &bfin_core_irqchip);
  998. else
  999. irq_set_chip(irq, &bfin_internal_irqchip);
  1000. switch (irq) {
  1001. #if defined(CONFIG_BF53x)
  1002. case IRQ_PROG_INTA:
  1003. # if defined(BF537_FAMILY) && !(defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE))
  1004. case IRQ_MAC_RX:
  1005. # endif
  1006. #elif defined(CONFIG_BF54x)
  1007. case IRQ_PINT0:
  1008. case IRQ_PINT1:
  1009. case IRQ_PINT2:
  1010. case IRQ_PINT3:
  1011. #elif defined(CONFIG_BF52x) || defined(CONFIG_BF51x)
  1012. case IRQ_PORTF_INTA:
  1013. case IRQ_PORTG_INTA:
  1014. case IRQ_PORTH_INTA:
  1015. #elif defined(CONFIG_BF561)
  1016. case IRQ_PROG0_INTA:
  1017. case IRQ_PROG1_INTA:
  1018. case IRQ_PROG2_INTA:
  1019. #elif defined(CONFIG_BF538) || defined(CONFIG_BF539)
  1020. case IRQ_PORTF_INTA:
  1021. #endif
  1022. irq_set_chained_handler(irq, bfin_demux_gpio_irq);
  1023. break;
  1024. #ifdef BF537_GENERIC_ERROR_INT_DEMUX
  1025. case IRQ_GENERIC_ERROR:
  1026. irq_set_chained_handler(irq, bfin_demux_error_irq);
  1027. break;
  1028. #endif
  1029. #if defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE)
  1030. case IRQ_MAC_ERROR:
  1031. irq_set_chained_handler(irq,
  1032. bfin_demux_mac_status_irq);
  1033. break;
  1034. #endif
  1035. #ifdef CONFIG_SMP
  1036. case IRQ_SUPPLE_0:
  1037. case IRQ_SUPPLE_1:
  1038. irq_set_handler(irq, handle_percpu_irq);
  1039. break;
  1040. #endif
  1041. #ifdef CONFIG_TICKSOURCE_CORETMR
  1042. case IRQ_CORETMR:
  1043. # ifdef CONFIG_SMP
  1044. irq_set_handler(irq, handle_percpu_irq);
  1045. break;
  1046. # else
  1047. irq_set_handler(irq, handle_simple_irq);
  1048. break;
  1049. # endif
  1050. #endif
  1051. #ifdef CONFIG_TICKSOURCE_GPTMR0
  1052. case IRQ_TIMER0:
  1053. irq_set_handler(irq, handle_simple_irq);
  1054. break;
  1055. #endif
  1056. #ifdef CONFIG_IPIPE
  1057. default:
  1058. irq_set_handler(irq, handle_level_irq);
  1059. break;
  1060. #else /* !CONFIG_IPIPE */
  1061. default:
  1062. irq_set_handler(irq, handle_simple_irq);
  1063. break;
  1064. #endif /* !CONFIG_IPIPE */
  1065. }
  1066. }
  1067. #ifdef BF537_GENERIC_ERROR_INT_DEMUX
  1068. for (irq = IRQ_PPI_ERROR; irq <= IRQ_UART1_ERROR; irq++)
  1069. irq_set_chip_and_handler(irq, &bfin_generic_error_irqchip,
  1070. handle_level_irq);
  1071. #if defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE)
  1072. irq_set_chained_handler(IRQ_MAC_ERROR, bfin_demux_mac_status_irq);
  1073. #endif
  1074. #endif
  1075. #if defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE)
  1076. for (irq = IRQ_MAC_PHYINT; irq <= IRQ_MAC_STMDONE; irq++)
  1077. irq_set_chip_and_handler(irq, &bfin_mac_status_irqchip,
  1078. handle_level_irq);
  1079. #endif
  1080. /* if configured as edge, then will be changed to do_edge_IRQ */
  1081. for (irq = GPIO_IRQ_BASE;
  1082. irq < (GPIO_IRQ_BASE + MAX_BLACKFIN_GPIOS); irq++)
  1083. irq_set_chip_and_handler(irq, &bfin_gpio_irqchip,
  1084. handle_level_irq);
  1085. bfin_write_IMASK(0);
  1086. CSYNC();
  1087. ilat = bfin_read_ILAT();
  1088. CSYNC();
  1089. bfin_write_ILAT(ilat);
  1090. CSYNC();
  1091. printk(KERN_INFO "Configuring Blackfin Priority Driven Interrupts\n");
  1092. /* IMASK=xxx is equivalent to STI xx or bfin_irq_flags=xx,
  1093. * local_irq_enable()
  1094. */
  1095. program_IAR();
  1096. /* Therefore it's better to setup IARs before interrupts enabled */
  1097. search_IAR();
  1098. /* Enable interrupts IVG7-15 */
  1099. bfin_irq_flags |= IMASK_IVG15 |
  1100. IMASK_IVG14 | IMASK_IVG13 | IMASK_IVG12 | IMASK_IVG11 |
  1101. IMASK_IVG10 | IMASK_IVG9 | IMASK_IVG8 | IMASK_IVG7 | IMASK_IVGHW;
  1102. /* This implicitly covers ANOMALY_05000171
  1103. * Boot-ROM code modifies SICA_IWRx wakeup registers
  1104. */
  1105. #ifdef SIC_IWR0
  1106. bfin_write_SIC_IWR0(IWR_DISABLE_ALL);
  1107. # ifdef SIC_IWR1
  1108. /* BF52x/BF51x system reset does not properly reset SIC_IWR1 which
  1109. * will screw up the bootrom as it relies on MDMA0/1 waking it
  1110. * up from IDLE instructions. See this report for more info:
  1111. * http://blackfin.uclinux.org/gf/tracker/4323
  1112. */
  1113. if (ANOMALY_05000435)
  1114. bfin_write_SIC_IWR1(IWR_ENABLE(10) | IWR_ENABLE(11));
  1115. else
  1116. bfin_write_SIC_IWR1(IWR_DISABLE_ALL);
  1117. # endif
  1118. # ifdef SIC_IWR2
  1119. bfin_write_SIC_IWR2(IWR_DISABLE_ALL);
  1120. # endif
  1121. #else
  1122. bfin_write_SIC_IWR(IWR_DISABLE_ALL);
  1123. #endif
  1124. return 0;
  1125. }
  1126. #ifdef CONFIG_DO_IRQ_L1
  1127. __attribute__((l1_text))
  1128. #endif
  1129. void do_irq(int vec, struct pt_regs *fp)
  1130. {
  1131. if (vec == EVT_IVTMR_P) {
  1132. vec = IRQ_CORETMR;
  1133. } else {
  1134. struct ivgx *ivg = ivg7_13[vec - IVG7].ifirst;
  1135. struct ivgx *ivg_stop = ivg7_13[vec - IVG7].istop;
  1136. #if defined(SIC_ISR0)
  1137. unsigned long sic_status[3];
  1138. if (smp_processor_id()) {
  1139. # ifdef SICB_ISR0
  1140. /* This will be optimized out in UP mode. */
  1141. sic_status[0] = bfin_read_SICB_ISR0() & bfin_read_SICB_IMASK0();
  1142. sic_status[1] = bfin_read_SICB_ISR1() & bfin_read_SICB_IMASK1();
  1143. # endif
  1144. } else {
  1145. sic_status[0] = bfin_read_SIC_ISR0() & bfin_read_SIC_IMASK0();
  1146. sic_status[1] = bfin_read_SIC_ISR1() & bfin_read_SIC_IMASK1();
  1147. }
  1148. # ifdef SIC_ISR2
  1149. sic_status[2] = bfin_read_SIC_ISR2() & bfin_read_SIC_IMASK2();
  1150. # endif
  1151. for (;; ivg++) {
  1152. if (ivg >= ivg_stop) {
  1153. atomic_inc(&num_spurious);
  1154. return;
  1155. }
  1156. if (sic_status[(ivg->irqno - IVG7) / 32] & ivg->isrflag)
  1157. break;
  1158. }
  1159. #else
  1160. unsigned long sic_status;
  1161. sic_status = bfin_read_SIC_IMASK() & bfin_read_SIC_ISR();
  1162. for (;; ivg++) {
  1163. if (ivg >= ivg_stop) {
  1164. atomic_inc(&num_spurious);
  1165. return;
  1166. } else if (sic_status & ivg->isrflag)
  1167. break;
  1168. }
  1169. #endif
  1170. vec = ivg->irqno;
  1171. }
  1172. asm_do_IRQ(vec, fp);
  1173. }
  1174. #ifdef CONFIG_IPIPE
  1175. int __ipipe_get_irq_priority(unsigned irq)
  1176. {
  1177. int ient, prio;
  1178. if (irq <= IRQ_CORETMR)
  1179. return irq;
  1180. for (ient = 0; ient < NR_PERI_INTS; ient++) {
  1181. struct ivgx *ivg = ivg_table + ient;
  1182. if (ivg->irqno == irq) {
  1183. for (prio = 0; prio <= IVG13-IVG7; prio++) {
  1184. if (ivg7_13[prio].ifirst <= ivg &&
  1185. ivg7_13[prio].istop > ivg)
  1186. return IVG7 + prio;
  1187. }
  1188. }
  1189. }
  1190. return IVG15;
  1191. }
  1192. /* Hw interrupts are disabled on entry (check SAVE_CONTEXT). */
  1193. #ifdef CONFIG_DO_IRQ_L1
  1194. __attribute__((l1_text))
  1195. #endif
  1196. asmlinkage int __ipipe_grab_irq(int vec, struct pt_regs *regs)
  1197. {
  1198. struct ipipe_percpu_domain_data *p = ipipe_root_cpudom_ptr();
  1199. struct ipipe_domain *this_domain = __ipipe_current_domain;
  1200. struct ivgx *ivg_stop = ivg7_13[vec-IVG7].istop;
  1201. struct ivgx *ivg = ivg7_13[vec-IVG7].ifirst;
  1202. int irq, s = 0;
  1203. if (likely(vec == EVT_IVTMR_P))
  1204. irq = IRQ_CORETMR;
  1205. else {
  1206. #if defined(SIC_ISR0)
  1207. unsigned long sic_status[3];
  1208. sic_status[0] = bfin_read_SIC_ISR0() & bfin_read_SIC_IMASK0();
  1209. sic_status[1] = bfin_read_SIC_ISR1() & bfin_read_SIC_IMASK1();
  1210. # ifdef SIC_ISR2
  1211. sic_status[2] = bfin_read_SIC_ISR2() & bfin_read_SIC_IMASK2();
  1212. # endif
  1213. for (;; ivg++) {
  1214. if (ivg >= ivg_stop) {
  1215. atomic_inc(&num_spurious);
  1216. return 0;
  1217. }
  1218. if (sic_status[(ivg->irqno - IVG7) / 32] & ivg->isrflag)
  1219. break;
  1220. }
  1221. #else
  1222. unsigned long sic_status;
  1223. sic_status = bfin_read_SIC_IMASK() & bfin_read_SIC_ISR();
  1224. for (;; ivg++) {
  1225. if (ivg >= ivg_stop) {
  1226. atomic_inc(&num_spurious);
  1227. return 0;
  1228. } else if (sic_status & ivg->isrflag)
  1229. break;
  1230. }
  1231. #endif
  1232. irq = ivg->irqno;
  1233. }
  1234. if (irq == IRQ_SYSTMR) {
  1235. #if !defined(CONFIG_GENERIC_CLOCKEVENTS) || defined(CONFIG_TICKSOURCE_GPTMR0)
  1236. bfin_write_TIMER_STATUS(1); /* Latch TIMIL0 */
  1237. #endif
  1238. /* This is basically what we need from the register frame. */
  1239. __raw_get_cpu_var(__ipipe_tick_regs).ipend = regs->ipend;
  1240. __raw_get_cpu_var(__ipipe_tick_regs).pc = regs->pc;
  1241. if (this_domain != ipipe_root_domain)
  1242. __raw_get_cpu_var(__ipipe_tick_regs).ipend &= ~0x10;
  1243. else
  1244. __raw_get_cpu_var(__ipipe_tick_regs).ipend |= 0x10;
  1245. }
  1246. /*
  1247. * We don't want Linux interrupt handlers to run at the
  1248. * current core priority level (i.e. < EVT15), since this
  1249. * might delay other interrupts handled by a high priority
  1250. * domain. Here is what we do instead:
  1251. *
  1252. * - we raise the SYNCDEFER bit to prevent
  1253. * __ipipe_handle_irq() to sync the pipeline for the root
  1254. * stage for the incoming interrupt. Upon return, that IRQ is
  1255. * pending in the interrupt log.
  1256. *
  1257. * - we raise the TIF_IRQ_SYNC bit for the current thread, so
  1258. * that _schedule_and_signal_from_int will eventually sync the
  1259. * pipeline from EVT15.
  1260. */
  1261. if (this_domain == ipipe_root_domain) {
  1262. s = __test_and_set_bit(IPIPE_SYNCDEFER_FLAG, &p->status);
  1263. barrier();
  1264. }
  1265. ipipe_trace_irq_entry(irq);
  1266. __ipipe_handle_irq(irq, regs);
  1267. ipipe_trace_irq_exit(irq);
  1268. if (user_mode(regs) &&
  1269. !ipipe_test_foreign_stack() &&
  1270. (current->ipipe_flags & PF_EVTRET) != 0) {
  1271. /*
  1272. * Testing for user_regs() does NOT fully eliminate
  1273. * foreign stack contexts, because of the forged
  1274. * interrupt returns we do through
  1275. * __ipipe_call_irqtail. In that case, we might have
  1276. * preempted a foreign stack context in a high
  1277. * priority domain, with a single interrupt level now
  1278. * pending after the irqtail unwinding is done. In
  1279. * which case user_mode() is now true, and the event
  1280. * gets dispatched spuriously.
  1281. */
  1282. current->ipipe_flags &= ~PF_EVTRET;
  1283. __ipipe_dispatch_event(IPIPE_EVENT_RETURN, regs);
  1284. }
  1285. if (this_domain == ipipe_root_domain) {
  1286. set_thread_flag(TIF_IRQ_SYNC);
  1287. if (!s) {
  1288. __clear_bit(IPIPE_SYNCDEFER_FLAG, &p->status);
  1289. return !test_bit(IPIPE_STALL_FLAG, &p->status);
  1290. }
  1291. }
  1292. return 0;
  1293. }
  1294. #endif /* CONFIG_IPIPE */