ints-priority.c 39 KB

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