ints-priority.c 40 KB

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