ints-priority.c 38 KB

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