ints-priority.c 37 KB

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