ints-priority.c 40 KB

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