ints-priority.c 37 KB

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