ints-priority.c 26 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135
  1. /*
  2. * File: arch/blackfin/mach-common/ints-priority.c
  3. *
  4. * Description: Set up the interrupt priorities
  5. *
  6. * Modified:
  7. * 1996 Roman Zippel
  8. * 1999 D. Jeff Dionne <jeff@uclinux.org>
  9. * 2000-2001 Lineo, Inc. D. Jefff Dionne <jeff@lineo.ca>
  10. * 2002 Arcturus Networks Inc. MaTed <mated@sympatico.ca>
  11. * 2003 Metrowerks/Motorola
  12. * 2003 Bas Vermeulen <bas@buyways.nl>
  13. * Copyright 2004-2008 Analog Devices Inc.
  14. *
  15. * Bugs: Enter bugs at http://blackfin.uclinux.org/
  16. *
  17. * This program is free software; you can redistribute it and/or modify
  18. * it under the terms of the GNU General Public License as published by
  19. * the Free Software Foundation; either version 2 of the License, or
  20. * (at your option) any later version.
  21. *
  22. * This program is distributed in the hope that it will be useful,
  23. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  24. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  25. * GNU General Public License for more details.
  26. *
  27. * You should have received a copy of the GNU General Public License
  28. * along with this program; if not, see the file COPYING, or write
  29. * to the Free Software Foundation, Inc.,
  30. * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  31. */
  32. #include <linux/module.h>
  33. #include <linux/kernel_stat.h>
  34. #include <linux/seq_file.h>
  35. #include <linux/irq.h>
  36. #ifdef CONFIG_KGDB
  37. #include <linux/kgdb.h>
  38. #endif
  39. #include <asm/traps.h>
  40. #include <asm/blackfin.h>
  41. #include <asm/gpio.h>
  42. #include <asm/irq_handler.h>
  43. #ifdef BF537_FAMILY
  44. # define BF537_GENERIC_ERROR_INT_DEMUX
  45. #else
  46. # undef BF537_GENERIC_ERROR_INT_DEMUX
  47. #endif
  48. /*
  49. * NOTES:
  50. * - we have separated the physical Hardware interrupt from the
  51. * levels that the LINUX kernel sees (see the description in irq.h)
  52. * -
  53. */
  54. #ifndef CONFIG_SMP
  55. /* Initialize this to an actual value to force it into the .data
  56. * section so that we know it is properly initialized at entry into
  57. * the kernel but before bss is initialized to zero (which is where
  58. * it would live otherwise). The 0x1f magic represents the IRQs we
  59. * cannot actually mask out in hardware.
  60. */
  61. unsigned long irq_flags = 0x1f;
  62. EXPORT_SYMBOL(irq_flags);
  63. #endif
  64. /* The number of spurious interrupts */
  65. atomic_t num_spurious;
  66. #ifdef CONFIG_PM
  67. unsigned long bfin_sic_iwr[3]; /* Up to 3 SIC_IWRx registers */
  68. unsigned vr_wakeup;
  69. #endif
  70. struct ivgx {
  71. /* irq number for request_irq, available in mach-bf5xx/irq.h */
  72. unsigned int irqno;
  73. /* corresponding bit in the SIC_ISR register */
  74. unsigned int isrflag;
  75. } ivg_table[NR_PERI_INTS];
  76. struct ivg_slice {
  77. /* position of first irq in ivg_table for given ivg */
  78. struct ivgx *ifirst;
  79. struct ivgx *istop;
  80. } ivg7_13[IVG13 - IVG7 + 1];
  81. /*
  82. * Search SIC_IAR and fill tables with the irqvalues
  83. * and their positions in the SIC_ISR register.
  84. */
  85. static void __init search_IAR(void)
  86. {
  87. unsigned ivg, irq_pos = 0;
  88. for (ivg = 0; ivg <= IVG13 - IVG7; ivg++) {
  89. int irqn;
  90. ivg7_13[ivg].istop = ivg7_13[ivg].ifirst = &ivg_table[irq_pos];
  91. for (irqn = 0; irqn < NR_PERI_INTS; irqn++) {
  92. int iar_shift = (irqn & 7) * 4;
  93. if (ivg == (0xf &
  94. #if defined(CONFIG_BF52x) || defined(CONFIG_BF538) \
  95. || defined(CONFIG_BF539) || defined(CONFIG_BF51x)
  96. bfin_read32((unsigned long *)SIC_IAR0 +
  97. ((irqn % 32) >> 3) + ((irqn / 32) *
  98. ((SIC_IAR4 - SIC_IAR0) / 4))) >> iar_shift)) {
  99. #else
  100. bfin_read32((unsigned long *)SIC_IAR0 +
  101. (irqn >> 3)) >> iar_shift)) {
  102. #endif
  103. ivg_table[irq_pos].irqno = IVG7 + irqn;
  104. ivg_table[irq_pos].isrflag = 1 << (irqn % 32);
  105. ivg7_13[ivg].istop++;
  106. irq_pos++;
  107. }
  108. }
  109. }
  110. }
  111. /*
  112. * This is for core internal IRQs
  113. */
  114. static void bfin_ack_noop(unsigned int irq)
  115. {
  116. /* Dummy function. */
  117. }
  118. static void bfin_core_mask_irq(unsigned int irq)
  119. {
  120. irq_flags &= ~(1 << irq);
  121. if (!irqs_disabled())
  122. local_irq_enable();
  123. }
  124. static void bfin_core_unmask_irq(unsigned int irq)
  125. {
  126. irq_flags |= 1 << irq;
  127. /*
  128. * If interrupts are enabled, IMASK must contain the same value
  129. * as irq_flags. Make sure that invariant holds. If interrupts
  130. * are currently disabled we need not do anything; one of the
  131. * callers will take care of setting IMASK to the proper value
  132. * when reenabling interrupts.
  133. * local_irq_enable just does "STI irq_flags", so it's exactly
  134. * what we need.
  135. */
  136. if (!irqs_disabled())
  137. local_irq_enable();
  138. return;
  139. }
  140. static void bfin_internal_mask_irq(unsigned int irq)
  141. {
  142. #ifdef CONFIG_BF53x
  143. bfin_write_SIC_IMASK(bfin_read_SIC_IMASK() &
  144. ~(1 << SIC_SYSIRQ(irq)));
  145. #else
  146. unsigned mask_bank, mask_bit;
  147. mask_bank = SIC_SYSIRQ(irq) / 32;
  148. mask_bit = SIC_SYSIRQ(irq) % 32;
  149. bfin_write_SIC_IMASK(mask_bank, bfin_read_SIC_IMASK(mask_bank) &
  150. ~(1 << mask_bit));
  151. #ifdef CONFIG_SMP
  152. bfin_write_SICB_IMASK(mask_bank, bfin_read_SICB_IMASK(mask_bank) &
  153. ~(1 << mask_bit));
  154. #endif
  155. #endif
  156. }
  157. static void bfin_internal_unmask_irq(unsigned int irq)
  158. {
  159. #ifdef CONFIG_BF53x
  160. bfin_write_SIC_IMASK(bfin_read_SIC_IMASK() |
  161. (1 << SIC_SYSIRQ(irq)));
  162. #else
  163. unsigned mask_bank, mask_bit;
  164. mask_bank = SIC_SYSIRQ(irq) / 32;
  165. mask_bit = SIC_SYSIRQ(irq) % 32;
  166. bfin_write_SIC_IMASK(mask_bank, bfin_read_SIC_IMASK(mask_bank) |
  167. (1 << mask_bit));
  168. #ifdef CONFIG_SMP
  169. bfin_write_SICB_IMASK(mask_bank, bfin_read_SICB_IMASK(mask_bank) |
  170. (1 << mask_bit));
  171. #endif
  172. #endif
  173. }
  174. #ifdef CONFIG_PM
  175. int bfin_internal_set_wake(unsigned int irq, unsigned int state)
  176. {
  177. u32 bank, bit, wakeup = 0;
  178. unsigned long flags;
  179. bank = SIC_SYSIRQ(irq) / 32;
  180. bit = SIC_SYSIRQ(irq) % 32;
  181. switch (irq) {
  182. #ifdef IRQ_RTC
  183. case IRQ_RTC:
  184. wakeup |= WAKE;
  185. break;
  186. #endif
  187. #ifdef IRQ_CAN0_RX
  188. case IRQ_CAN0_RX:
  189. wakeup |= CANWE;
  190. break;
  191. #endif
  192. #ifdef IRQ_CAN1_RX
  193. case IRQ_CAN1_RX:
  194. wakeup |= CANWE;
  195. break;
  196. #endif
  197. #ifdef IRQ_USB_INT0
  198. case IRQ_USB_INT0:
  199. wakeup |= USBWE;
  200. break;
  201. #endif
  202. #ifdef IRQ_KEY
  203. case IRQ_KEY:
  204. wakeup |= KPADWE;
  205. break;
  206. #endif
  207. #ifdef CONFIG_BF54x
  208. case IRQ_CNT:
  209. wakeup |= ROTWE;
  210. break;
  211. #endif
  212. default:
  213. break;
  214. }
  215. local_irq_save(flags);
  216. if (state) {
  217. bfin_sic_iwr[bank] |= (1 << bit);
  218. vr_wakeup |= wakeup;
  219. } else {
  220. bfin_sic_iwr[bank] &= ~(1 << bit);
  221. vr_wakeup &= ~wakeup;
  222. }
  223. local_irq_restore(flags);
  224. return 0;
  225. }
  226. #endif
  227. static struct irq_chip bfin_core_irqchip = {
  228. .name = "CORE",
  229. .ack = bfin_ack_noop,
  230. .mask = bfin_core_mask_irq,
  231. .unmask = bfin_core_unmask_irq,
  232. };
  233. static struct irq_chip bfin_internal_irqchip = {
  234. .name = "INTN",
  235. .ack = bfin_ack_noop,
  236. .mask = bfin_internal_mask_irq,
  237. .unmask = bfin_internal_unmask_irq,
  238. .mask_ack = bfin_internal_mask_irq,
  239. .disable = bfin_internal_mask_irq,
  240. .enable = bfin_internal_unmask_irq,
  241. #ifdef CONFIG_PM
  242. .set_wake = bfin_internal_set_wake,
  243. #endif
  244. };
  245. #ifdef BF537_GENERIC_ERROR_INT_DEMUX
  246. static int error_int_mask;
  247. static void bfin_generic_error_mask_irq(unsigned int irq)
  248. {
  249. error_int_mask &= ~(1L << (irq - IRQ_PPI_ERROR));
  250. if (!error_int_mask)
  251. bfin_internal_mask_irq(IRQ_GENERIC_ERROR);
  252. }
  253. static void bfin_generic_error_unmask_irq(unsigned int irq)
  254. {
  255. bfin_internal_unmask_irq(IRQ_GENERIC_ERROR);
  256. error_int_mask |= 1L << (irq - IRQ_PPI_ERROR);
  257. }
  258. static struct irq_chip bfin_generic_error_irqchip = {
  259. .name = "ERROR",
  260. .ack = bfin_ack_noop,
  261. .mask_ack = bfin_generic_error_mask_irq,
  262. .mask = bfin_generic_error_mask_irq,
  263. .unmask = bfin_generic_error_unmask_irq,
  264. };
  265. static void bfin_demux_error_irq(unsigned int int_err_irq,
  266. struct irq_desc *inta_desc)
  267. {
  268. int irq = 0;
  269. #if (defined(CONFIG_BF537) || defined(CONFIG_BF536))
  270. if (bfin_read_EMAC_SYSTAT() & EMAC_ERR_MASK)
  271. irq = IRQ_MAC_ERROR;
  272. else
  273. #endif
  274. if (bfin_read_SPORT0_STAT() & SPORT_ERR_MASK)
  275. irq = IRQ_SPORT0_ERROR;
  276. else if (bfin_read_SPORT1_STAT() & SPORT_ERR_MASK)
  277. irq = IRQ_SPORT1_ERROR;
  278. else if (bfin_read_PPI_STATUS() & PPI_ERR_MASK)
  279. irq = IRQ_PPI_ERROR;
  280. else if (bfin_read_CAN_GIF() & CAN_ERR_MASK)
  281. irq = IRQ_CAN_ERROR;
  282. else if (bfin_read_SPI_STAT() & SPI_ERR_MASK)
  283. irq = IRQ_SPI_ERROR;
  284. else if ((bfin_read_UART0_IIR() & UART_ERR_MASK_STAT1) &&
  285. (bfin_read_UART0_IIR() & UART_ERR_MASK_STAT0))
  286. irq = IRQ_UART0_ERROR;
  287. else if ((bfin_read_UART1_IIR() & UART_ERR_MASK_STAT1) &&
  288. (bfin_read_UART1_IIR() & UART_ERR_MASK_STAT0))
  289. irq = IRQ_UART1_ERROR;
  290. if (irq) {
  291. if (error_int_mask & (1L << (irq - IRQ_PPI_ERROR))) {
  292. struct irq_desc *desc = irq_desc + irq;
  293. desc->handle_irq(irq, desc);
  294. } else {
  295. switch (irq) {
  296. case IRQ_PPI_ERROR:
  297. bfin_write_PPI_STATUS(PPI_ERR_MASK);
  298. break;
  299. #if (defined(CONFIG_BF537) || defined(CONFIG_BF536))
  300. case IRQ_MAC_ERROR:
  301. bfin_write_EMAC_SYSTAT(EMAC_ERR_MASK);
  302. break;
  303. #endif
  304. case IRQ_SPORT0_ERROR:
  305. bfin_write_SPORT0_STAT(SPORT_ERR_MASK);
  306. break;
  307. case IRQ_SPORT1_ERROR:
  308. bfin_write_SPORT1_STAT(SPORT_ERR_MASK);
  309. break;
  310. case IRQ_CAN_ERROR:
  311. bfin_write_CAN_GIS(CAN_ERR_MASK);
  312. break;
  313. case IRQ_SPI_ERROR:
  314. bfin_write_SPI_STAT(SPI_ERR_MASK);
  315. break;
  316. default:
  317. break;
  318. }
  319. pr_debug("IRQ %d:"
  320. " MASKED PERIPHERAL ERROR INTERRUPT ASSERTED\n",
  321. irq);
  322. }
  323. } else
  324. printk(KERN_ERR
  325. "%s : %s : LINE %d :\nIRQ ?: PERIPHERAL ERROR"
  326. " INTERRUPT ASSERTED BUT NO SOURCE FOUND\n",
  327. __func__, __FILE__, __LINE__);
  328. }
  329. #endif /* BF537_GENERIC_ERROR_INT_DEMUX */
  330. static inline void bfin_set_irq_handler(unsigned irq, irq_flow_handler_t handle)
  331. {
  332. struct irq_desc *desc = irq_desc + irq;
  333. /* May not call generic set_irq_handler() due to spinlock
  334. recursion. */
  335. desc->handle_irq = handle;
  336. }
  337. static DECLARE_BITMAP(gpio_enabled, MAX_BLACKFIN_GPIOS);
  338. extern void bfin_gpio_irq_prepare(unsigned gpio);
  339. #if !defined(CONFIG_BF54x)
  340. static void bfin_gpio_ack_irq(unsigned int irq)
  341. {
  342. /* AFAIK ack_irq in case mask_ack is provided
  343. * get's only called for edge sense irqs
  344. */
  345. set_gpio_data(irq_to_gpio(irq), 0);
  346. }
  347. static void bfin_gpio_mask_ack_irq(unsigned int irq)
  348. {
  349. struct irq_desc *desc = irq_desc + irq;
  350. u32 gpionr = irq_to_gpio(irq);
  351. if (desc->handle_irq == handle_edge_irq)
  352. set_gpio_data(gpionr, 0);
  353. set_gpio_maska(gpionr, 0);
  354. }
  355. static void bfin_gpio_mask_irq(unsigned int irq)
  356. {
  357. set_gpio_maska(irq_to_gpio(irq), 0);
  358. }
  359. static void bfin_gpio_unmask_irq(unsigned int irq)
  360. {
  361. set_gpio_maska(irq_to_gpio(irq), 1);
  362. }
  363. static unsigned int bfin_gpio_irq_startup(unsigned int irq)
  364. {
  365. u32 gpionr = irq_to_gpio(irq);
  366. if (__test_and_set_bit(gpionr, gpio_enabled))
  367. bfin_gpio_irq_prepare(gpionr);
  368. bfin_gpio_unmask_irq(irq);
  369. return 0;
  370. }
  371. static void bfin_gpio_irq_shutdown(unsigned int irq)
  372. {
  373. bfin_gpio_mask_irq(irq);
  374. __clear_bit(irq_to_gpio(irq), gpio_enabled);
  375. }
  376. static int bfin_gpio_irq_type(unsigned int irq, unsigned int type)
  377. {
  378. u32 gpionr = irq_to_gpio(irq);
  379. if (type == IRQ_TYPE_PROBE) {
  380. /* only probe unenabled GPIO interrupt lines */
  381. if (__test_bit(gpionr, gpio_enabled))
  382. return 0;
  383. type = IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING;
  384. }
  385. if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING |
  386. IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW)) {
  387. if (__test_and_set_bit(gpionr, gpio_enabled))
  388. bfin_gpio_irq_prepare(gpionr);
  389. } else {
  390. __clear_bit(gpionr, gpio_enabled);
  391. return 0;
  392. }
  393. set_gpio_inen(gpionr, 0);
  394. set_gpio_dir(gpionr, 0);
  395. if ((type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING))
  396. == (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING))
  397. set_gpio_both(gpionr, 1);
  398. else
  399. set_gpio_both(gpionr, 0);
  400. if ((type & (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_LEVEL_LOW)))
  401. set_gpio_polar(gpionr, 1); /* low or falling edge denoted by one */
  402. else
  403. set_gpio_polar(gpionr, 0); /* high or rising edge denoted by zero */
  404. if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING)) {
  405. set_gpio_edge(gpionr, 1);
  406. set_gpio_inen(gpionr, 1);
  407. set_gpio_data(gpionr, 0);
  408. } else {
  409. set_gpio_edge(gpionr, 0);
  410. set_gpio_inen(gpionr, 1);
  411. }
  412. if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING))
  413. bfin_set_irq_handler(irq, handle_edge_irq);
  414. else
  415. bfin_set_irq_handler(irq, handle_level_irq);
  416. return 0;
  417. }
  418. #ifdef CONFIG_PM
  419. int bfin_gpio_set_wake(unsigned int irq, unsigned int state)
  420. {
  421. unsigned gpio = irq_to_gpio(irq);
  422. if (state)
  423. gpio_pm_wakeup_request(gpio, PM_WAKE_IGNORE);
  424. else
  425. gpio_pm_wakeup_free(gpio);
  426. return 0;
  427. }
  428. #endif
  429. static void bfin_demux_gpio_irq(unsigned int inta_irq,
  430. struct irq_desc *desc)
  431. {
  432. unsigned int i, gpio, mask, irq, search = 0;
  433. switch (inta_irq) {
  434. #if defined(CONFIG_BF53x)
  435. case IRQ_PROG_INTA:
  436. irq = IRQ_PF0;
  437. search = 1;
  438. break;
  439. # if defined(BF537_FAMILY) && !(defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE))
  440. case IRQ_MAC_RX:
  441. irq = IRQ_PH0;
  442. break;
  443. # endif
  444. #elif defined(CONFIG_BF538) || defined(CONFIG_BF539)
  445. case IRQ_PORTF_INTA:
  446. irq = IRQ_PF0;
  447. break;
  448. #elif defined(CONFIG_BF52x) || defined(CONFIG_BF51x)
  449. case IRQ_PORTF_INTA:
  450. irq = IRQ_PF0;
  451. break;
  452. case IRQ_PORTG_INTA:
  453. irq = IRQ_PG0;
  454. break;
  455. case IRQ_PORTH_INTA:
  456. irq = IRQ_PH0;
  457. break;
  458. #elif defined(CONFIG_BF561)
  459. case IRQ_PROG0_INTA:
  460. irq = IRQ_PF0;
  461. break;
  462. case IRQ_PROG1_INTA:
  463. irq = IRQ_PF16;
  464. break;
  465. case IRQ_PROG2_INTA:
  466. irq = IRQ_PF32;
  467. break;
  468. #endif
  469. default:
  470. BUG();
  471. return;
  472. }
  473. if (search) {
  474. for (i = 0; i < MAX_BLACKFIN_GPIOS; i += GPIO_BANKSIZE) {
  475. irq += i;
  476. mask = get_gpiop_data(i) & get_gpiop_maska(i);
  477. while (mask) {
  478. if (mask & 1) {
  479. desc = irq_desc + irq;
  480. desc->handle_irq(irq, desc);
  481. }
  482. irq++;
  483. mask >>= 1;
  484. }
  485. }
  486. } else {
  487. gpio = irq_to_gpio(irq);
  488. mask = get_gpiop_data(gpio) & get_gpiop_maska(gpio);
  489. do {
  490. if (mask & 1) {
  491. desc = irq_desc + irq;
  492. desc->handle_irq(irq, desc);
  493. }
  494. irq++;
  495. mask >>= 1;
  496. } while (mask);
  497. }
  498. }
  499. #else /* CONFIG_BF54x */
  500. #define NR_PINT_SYS_IRQS 4
  501. #define NR_PINT_BITS 32
  502. #define NR_PINTS 160
  503. #define IRQ_NOT_AVAIL 0xFF
  504. #define PINT_2_BANK(x) ((x) >> 5)
  505. #define PINT_2_BIT(x) ((x) & 0x1F)
  506. #define PINT_BIT(x) (1 << (PINT_2_BIT(x)))
  507. static unsigned char irq2pint_lut[NR_PINTS];
  508. static unsigned char pint2irq_lut[NR_PINT_SYS_IRQS * NR_PINT_BITS];
  509. struct pin_int_t {
  510. unsigned int mask_set;
  511. unsigned int mask_clear;
  512. unsigned int request;
  513. unsigned int assign;
  514. unsigned int edge_set;
  515. unsigned int edge_clear;
  516. unsigned int invert_set;
  517. unsigned int invert_clear;
  518. unsigned int pinstate;
  519. unsigned int latch;
  520. };
  521. static struct pin_int_t *pint[NR_PINT_SYS_IRQS] = {
  522. (struct pin_int_t *)PINT0_MASK_SET,
  523. (struct pin_int_t *)PINT1_MASK_SET,
  524. (struct pin_int_t *)PINT2_MASK_SET,
  525. (struct pin_int_t *)PINT3_MASK_SET,
  526. };
  527. inline unsigned int get_irq_base(u32 bank, u8 bmap)
  528. {
  529. unsigned int irq_base;
  530. if (bank < 2) { /*PA-PB */
  531. irq_base = IRQ_PA0 + bmap * 16;
  532. } else { /*PC-PJ */
  533. irq_base = IRQ_PC0 + bmap * 16;
  534. }
  535. return irq_base;
  536. }
  537. /* Whenever PINTx_ASSIGN is altered init_pint_lut() must be executed! */
  538. void init_pint_lut(void)
  539. {
  540. u16 bank, bit, irq_base, bit_pos;
  541. u32 pint_assign;
  542. u8 bmap;
  543. memset(irq2pint_lut, IRQ_NOT_AVAIL, sizeof(irq2pint_lut));
  544. for (bank = 0; bank < NR_PINT_SYS_IRQS; bank++) {
  545. pint_assign = pint[bank]->assign;
  546. for (bit = 0; bit < NR_PINT_BITS; bit++) {
  547. bmap = (pint_assign >> ((bit / 8) * 8)) & 0xFF;
  548. irq_base = get_irq_base(bank, bmap);
  549. irq_base += (bit % 8) + ((bit / 8) & 1 ? 8 : 0);
  550. bit_pos = bit + bank * NR_PINT_BITS;
  551. pint2irq_lut[bit_pos] = irq_base - SYS_IRQS;
  552. irq2pint_lut[irq_base - SYS_IRQS] = bit_pos;
  553. }
  554. }
  555. }
  556. static void bfin_gpio_ack_irq(unsigned int irq)
  557. {
  558. struct irq_desc *desc = irq_desc + irq;
  559. u32 pint_val = irq2pint_lut[irq - SYS_IRQS];
  560. u32 pintbit = PINT_BIT(pint_val);
  561. u32 bank = PINT_2_BANK(pint_val);
  562. if ((desc->status & IRQ_TYPE_SENSE_MASK) == IRQ_TYPE_EDGE_BOTH) {
  563. if (pint[bank]->invert_set & pintbit)
  564. pint[bank]->invert_clear = pintbit;
  565. else
  566. pint[bank]->invert_set = pintbit;
  567. }
  568. pint[bank]->request = pintbit;
  569. }
  570. static void bfin_gpio_mask_ack_irq(unsigned int irq)
  571. {
  572. struct irq_desc *desc = irq_desc + irq;
  573. u32 pint_val = irq2pint_lut[irq - SYS_IRQS];
  574. u32 pintbit = PINT_BIT(pint_val);
  575. u32 bank = PINT_2_BANK(pint_val);
  576. if ((desc->status & IRQ_TYPE_SENSE_MASK) == IRQ_TYPE_EDGE_BOTH) {
  577. if (pint[bank]->invert_set & pintbit)
  578. pint[bank]->invert_clear = pintbit;
  579. else
  580. pint[bank]->invert_set = pintbit;
  581. }
  582. pint[bank]->request = pintbit;
  583. pint[bank]->mask_clear = pintbit;
  584. }
  585. static void bfin_gpio_mask_irq(unsigned int irq)
  586. {
  587. u32 pint_val = irq2pint_lut[irq - SYS_IRQS];
  588. pint[PINT_2_BANK(pint_val)]->mask_clear = PINT_BIT(pint_val);
  589. }
  590. static void bfin_gpio_unmask_irq(unsigned int irq)
  591. {
  592. u32 pint_val = irq2pint_lut[irq - SYS_IRQS];
  593. u32 pintbit = PINT_BIT(pint_val);
  594. u32 bank = PINT_2_BANK(pint_val);
  595. pint[bank]->request = pintbit;
  596. pint[bank]->mask_set = pintbit;
  597. }
  598. static unsigned int bfin_gpio_irq_startup(unsigned int irq)
  599. {
  600. u32 gpionr = irq_to_gpio(irq);
  601. u32 pint_val = irq2pint_lut[irq - SYS_IRQS];
  602. if (pint_val == IRQ_NOT_AVAIL) {
  603. printk(KERN_ERR
  604. "GPIO IRQ %d :Not in PINT Assign table "
  605. "Reconfigure Interrupt to Port Assignemt\n", irq);
  606. return -ENODEV;
  607. }
  608. if (__test_and_set_bit(gpionr, gpio_enabled))
  609. bfin_gpio_irq_prepare(gpionr);
  610. bfin_gpio_unmask_irq(irq);
  611. return 0;
  612. }
  613. static void bfin_gpio_irq_shutdown(unsigned int irq)
  614. {
  615. u32 gpionr = irq_to_gpio(irq);
  616. bfin_gpio_mask_irq(irq);
  617. __clear_bit(gpionr, gpio_enabled);
  618. }
  619. static int bfin_gpio_irq_type(unsigned int irq, unsigned int type)
  620. {
  621. u32 gpionr = irq_to_gpio(irq);
  622. u32 pint_val = irq2pint_lut[irq - SYS_IRQS];
  623. u32 pintbit = PINT_BIT(pint_val);
  624. u32 bank = PINT_2_BANK(pint_val);
  625. if (pint_val == IRQ_NOT_AVAIL)
  626. return -ENODEV;
  627. if (type == IRQ_TYPE_PROBE) {
  628. /* only probe unenabled GPIO interrupt lines */
  629. if (__test_bit(gpionr, gpio_enabled))
  630. return 0;
  631. type = IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING;
  632. }
  633. if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING |
  634. IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW)) {
  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. if ((type & (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_LEVEL_LOW)))
  642. pint[bank]->invert_set = pintbit; /* low or falling edge denoted by one */
  643. else
  644. pint[bank]->invert_clear = pintbit; /* high or rising edge denoted by zero */
  645. if ((type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING))
  646. == (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING)) {
  647. if (gpio_get_value(gpionr))
  648. pint[bank]->invert_set = pintbit;
  649. else
  650. pint[bank]->invert_clear = pintbit;
  651. }
  652. if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING)) {
  653. pint[bank]->edge_set = pintbit;
  654. bfin_set_irq_handler(irq, handle_edge_irq);
  655. } else {
  656. pint[bank]->edge_clear = pintbit;
  657. bfin_set_irq_handler(irq, handle_level_irq);
  658. }
  659. return 0;
  660. }
  661. #ifdef CONFIG_PM
  662. u32 pint_saved_masks[NR_PINT_SYS_IRQS];
  663. u32 pint_wakeup_masks[NR_PINT_SYS_IRQS];
  664. int bfin_gpio_set_wake(unsigned int irq, unsigned int state)
  665. {
  666. u32 pint_irq;
  667. u32 pint_val = irq2pint_lut[irq - SYS_IRQS];
  668. u32 bank = PINT_2_BANK(pint_val);
  669. u32 pintbit = PINT_BIT(pint_val);
  670. switch (bank) {
  671. case 0:
  672. pint_irq = IRQ_PINT0;
  673. break;
  674. case 2:
  675. pint_irq = IRQ_PINT2;
  676. break;
  677. case 3:
  678. pint_irq = IRQ_PINT3;
  679. break;
  680. case 1:
  681. pint_irq = IRQ_PINT1;
  682. break;
  683. default:
  684. return -EINVAL;
  685. }
  686. bfin_internal_set_wake(pint_irq, state);
  687. if (state)
  688. pint_wakeup_masks[bank] |= pintbit;
  689. else
  690. pint_wakeup_masks[bank] &= ~pintbit;
  691. return 0;
  692. }
  693. u32 bfin_pm_setup(void)
  694. {
  695. u32 val, i;
  696. for (i = 0; i < NR_PINT_SYS_IRQS; i++) {
  697. val = pint[i]->mask_clear;
  698. pint_saved_masks[i] = val;
  699. if (val ^ pint_wakeup_masks[i]) {
  700. pint[i]->mask_clear = val;
  701. pint[i]->mask_set = pint_wakeup_masks[i];
  702. }
  703. }
  704. return 0;
  705. }
  706. void bfin_pm_restore(void)
  707. {
  708. u32 i, val;
  709. for (i = 0; i < NR_PINT_SYS_IRQS; i++) {
  710. val = pint_saved_masks[i];
  711. if (val ^ pint_wakeup_masks[i]) {
  712. pint[i]->mask_clear = pint[i]->mask_clear;
  713. pint[i]->mask_set = val;
  714. }
  715. }
  716. }
  717. #endif
  718. static void bfin_demux_gpio_irq(unsigned int inta_irq,
  719. struct irq_desc *desc)
  720. {
  721. u32 bank, pint_val;
  722. u32 request, irq;
  723. switch (inta_irq) {
  724. case IRQ_PINT0:
  725. bank = 0;
  726. break;
  727. case IRQ_PINT2:
  728. bank = 2;
  729. break;
  730. case IRQ_PINT3:
  731. bank = 3;
  732. break;
  733. case IRQ_PINT1:
  734. bank = 1;
  735. break;
  736. default:
  737. return;
  738. }
  739. pint_val = bank * NR_PINT_BITS;
  740. request = pint[bank]->request;
  741. while (request) {
  742. if (request & 1) {
  743. irq = pint2irq_lut[pint_val] + SYS_IRQS;
  744. desc = irq_desc + irq;
  745. desc->handle_irq(irq, desc);
  746. }
  747. pint_val++;
  748. request >>= 1;
  749. }
  750. }
  751. #endif
  752. static struct irq_chip bfin_gpio_irqchip = {
  753. .name = "GPIO",
  754. .ack = bfin_gpio_ack_irq,
  755. .mask = bfin_gpio_mask_irq,
  756. .mask_ack = bfin_gpio_mask_ack_irq,
  757. .unmask = bfin_gpio_unmask_irq,
  758. .disable = bfin_gpio_mask_irq,
  759. .enable = bfin_gpio_unmask_irq,
  760. .set_type = bfin_gpio_irq_type,
  761. .startup = bfin_gpio_irq_startup,
  762. .shutdown = bfin_gpio_irq_shutdown,
  763. #ifdef CONFIG_PM
  764. .set_wake = bfin_gpio_set_wake,
  765. #endif
  766. };
  767. void __cpuinit init_exception_vectors(void)
  768. {
  769. /* cannot program in software:
  770. * evt0 - emulation (jtag)
  771. * evt1 - reset
  772. */
  773. bfin_write_EVT2(evt_nmi);
  774. bfin_write_EVT3(trap);
  775. bfin_write_EVT5(evt_ivhw);
  776. bfin_write_EVT6(evt_timer);
  777. bfin_write_EVT7(evt_evt7);
  778. bfin_write_EVT8(evt_evt8);
  779. bfin_write_EVT9(evt_evt9);
  780. bfin_write_EVT10(evt_evt10);
  781. bfin_write_EVT11(evt_evt11);
  782. bfin_write_EVT12(evt_evt12);
  783. bfin_write_EVT13(evt_evt13);
  784. bfin_write_EVT14(evt14_softirq);
  785. bfin_write_EVT15(evt_system_call);
  786. CSYNC();
  787. }
  788. /*
  789. * This function should be called during kernel startup to initialize
  790. * the BFin IRQ handling routines.
  791. */
  792. int __init init_arch_irq(void)
  793. {
  794. int irq;
  795. unsigned long ilat = 0;
  796. /* Disable all the peripheral intrs - page 4-29 HW Ref manual */
  797. #if defined(CONFIG_BF54x) || defined(CONFIG_BF52x) || defined(CONFIG_BF561) \
  798. || defined(BF538_FAMILY) || defined(CONFIG_BF51x)
  799. bfin_write_SIC_IMASK0(SIC_UNMASK_ALL);
  800. bfin_write_SIC_IMASK1(SIC_UNMASK_ALL);
  801. # ifdef CONFIG_BF54x
  802. bfin_write_SIC_IMASK2(SIC_UNMASK_ALL);
  803. # endif
  804. # ifdef CONFIG_SMP
  805. bfin_write_SICB_IMASK0(SIC_UNMASK_ALL);
  806. bfin_write_SICB_IMASK1(SIC_UNMASK_ALL);
  807. # endif
  808. #else
  809. bfin_write_SIC_IMASK(SIC_UNMASK_ALL);
  810. #endif
  811. local_irq_disable();
  812. #if (defined(CONFIG_BF537) || defined(CONFIG_BF536))
  813. /* Clear EMAC Interrupt Status bits so we can demux it later */
  814. bfin_write_EMAC_SYSTAT(-1);
  815. #endif
  816. #ifdef CONFIG_BF54x
  817. # ifdef CONFIG_PINTx_REASSIGN
  818. pint[0]->assign = CONFIG_PINT0_ASSIGN;
  819. pint[1]->assign = CONFIG_PINT1_ASSIGN;
  820. pint[2]->assign = CONFIG_PINT2_ASSIGN;
  821. pint[3]->assign = CONFIG_PINT3_ASSIGN;
  822. # endif
  823. /* Whenever PINTx_ASSIGN is altered init_pint_lut() must be executed! */
  824. init_pint_lut();
  825. #endif
  826. for (irq = 0; irq <= SYS_IRQS; irq++) {
  827. if (irq <= IRQ_CORETMR)
  828. set_irq_chip(irq, &bfin_core_irqchip);
  829. else
  830. set_irq_chip(irq, &bfin_internal_irqchip);
  831. switch (irq) {
  832. #if defined(CONFIG_BF53x)
  833. case IRQ_PROG_INTA:
  834. # if defined(BF537_FAMILY) && !(defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE))
  835. case IRQ_MAC_RX:
  836. # endif
  837. #elif defined(CONFIG_BF54x)
  838. case IRQ_PINT0:
  839. case IRQ_PINT1:
  840. case IRQ_PINT2:
  841. case IRQ_PINT3:
  842. #elif defined(CONFIG_BF52x) || defined(CONFIG_BF51x)
  843. case IRQ_PORTF_INTA:
  844. case IRQ_PORTG_INTA:
  845. case IRQ_PORTH_INTA:
  846. #elif defined(CONFIG_BF561)
  847. case IRQ_PROG0_INTA:
  848. case IRQ_PROG1_INTA:
  849. case IRQ_PROG2_INTA:
  850. #elif defined(CONFIG_BF538) || defined(CONFIG_BF539)
  851. case IRQ_PORTF_INTA:
  852. #endif
  853. set_irq_chained_handler(irq,
  854. bfin_demux_gpio_irq);
  855. break;
  856. #ifdef BF537_GENERIC_ERROR_INT_DEMUX
  857. case IRQ_GENERIC_ERROR:
  858. set_irq_handler(irq, bfin_demux_error_irq);
  859. break;
  860. #endif
  861. #ifdef CONFIG_TICK_SOURCE_SYSTMR0
  862. case IRQ_TIMER0:
  863. set_irq_handler(irq, handle_percpu_irq);
  864. break;
  865. #endif
  866. #ifdef CONFIG_SMP
  867. case IRQ_SUPPLE_0:
  868. case IRQ_SUPPLE_1:
  869. set_irq_handler(irq, handle_percpu_irq);
  870. break;
  871. #endif
  872. default:
  873. set_irq_handler(irq, handle_simple_irq);
  874. break;
  875. }
  876. }
  877. #ifdef BF537_GENERIC_ERROR_INT_DEMUX
  878. for (irq = IRQ_PPI_ERROR; irq <= IRQ_UART1_ERROR; irq++)
  879. set_irq_chip_and_handler(irq, &bfin_generic_error_irqchip,
  880. handle_level_irq);
  881. #endif
  882. /* if configured as edge, then will be changed to do_edge_IRQ */
  883. for (irq = GPIO_IRQ_BASE; irq < NR_IRQS; irq++)
  884. set_irq_chip_and_handler(irq, &bfin_gpio_irqchip,
  885. handle_level_irq);
  886. bfin_write_IMASK(0);
  887. CSYNC();
  888. ilat = bfin_read_ILAT();
  889. CSYNC();
  890. bfin_write_ILAT(ilat);
  891. CSYNC();
  892. printk(KERN_INFO "Configuring Blackfin Priority Driven Interrupts\n");
  893. /* IMASK=xxx is equivalent to STI xx or irq_flags=xx,
  894. * local_irq_enable()
  895. */
  896. program_IAR();
  897. /* Therefore it's better to setup IARs before interrupts enabled */
  898. search_IAR();
  899. /* Enable interrupts IVG7-15 */
  900. irq_flags |= IMASK_IVG15 |
  901. IMASK_IVG14 | IMASK_IVG13 | IMASK_IVG12 | IMASK_IVG11 |
  902. IMASK_IVG10 | IMASK_IVG9 | IMASK_IVG8 | IMASK_IVG7 | IMASK_IVGHW;
  903. #if defined(CONFIG_BF54x) || defined(CONFIG_BF52x) || defined(CONFIG_BF561) \
  904. || defined(BF538_FAMILY) || defined(CONFIG_BF51x)
  905. bfin_write_SIC_IWR0(IWR_DISABLE_ALL);
  906. #if defined(CONFIG_BF52x) || defined(CONFIG_BF51x)
  907. /* BF52x/BF51x system reset does not properly reset SIC_IWR1 which
  908. * will screw up the bootrom as it relies on MDMA0/1 waking it
  909. * up from IDLE instructions. See this report for more info:
  910. * http://blackfin.uclinux.org/gf/tracker/4323
  911. */
  912. bfin_write_SIC_IWR1(IWR_ENABLE(10) | IWR_ENABLE(11));
  913. #else
  914. bfin_write_SIC_IWR1(IWR_DISABLE_ALL);
  915. #endif
  916. # ifdef CONFIG_BF54x
  917. bfin_write_SIC_IWR2(IWR_DISABLE_ALL);
  918. # endif
  919. #else
  920. bfin_write_SIC_IWR(IWR_DISABLE_ALL);
  921. #endif
  922. return 0;
  923. }
  924. #ifdef CONFIG_DO_IRQ_L1
  925. __attribute__((l1_text))
  926. #endif
  927. void do_irq(int vec, struct pt_regs *fp)
  928. {
  929. if (vec == EVT_IVTMR_P) {
  930. vec = IRQ_CORETMR;
  931. } else {
  932. struct ivgx *ivg = ivg7_13[vec - IVG7].ifirst;
  933. struct ivgx *ivg_stop = ivg7_13[vec - IVG7].istop;
  934. #if defined(CONFIG_BF54x) || defined(CONFIG_BF52x) || defined(CONFIG_BF561) \
  935. || defined(BF538_FAMILY) || defined(CONFIG_BF51x)
  936. unsigned long sic_status[3];
  937. if (smp_processor_id()) {
  938. #ifdef CONFIG_SMP
  939. /* This will be optimized out in UP mode. */
  940. sic_status[0] = bfin_read_SICB_ISR0() & bfin_read_SICB_IMASK0();
  941. sic_status[1] = bfin_read_SICB_ISR1() & bfin_read_SICB_IMASK1();
  942. #endif
  943. } else {
  944. sic_status[0] = bfin_read_SIC_ISR0() & bfin_read_SIC_IMASK0();
  945. sic_status[1] = bfin_read_SIC_ISR1() & bfin_read_SIC_IMASK1();
  946. }
  947. #ifdef CONFIG_BF54x
  948. sic_status[2] = bfin_read_SIC_ISR2() & bfin_read_SIC_IMASK2();
  949. #endif
  950. for (;; ivg++) {
  951. if (ivg >= ivg_stop) {
  952. atomic_inc(&num_spurious);
  953. return;
  954. }
  955. if (sic_status[(ivg->irqno - IVG7) / 32] & ivg->isrflag)
  956. break;
  957. }
  958. #else
  959. unsigned long sic_status;
  960. sic_status = bfin_read_SIC_IMASK() & bfin_read_SIC_ISR();
  961. for (;; ivg++) {
  962. if (ivg >= ivg_stop) {
  963. atomic_inc(&num_spurious);
  964. return;
  965. } else if (sic_status & ivg->isrflag)
  966. break;
  967. }
  968. #endif
  969. vec = ivg->irqno;
  970. }
  971. asm_do_IRQ(vec, fp);
  972. }