ints-priority.c 37 KB

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