ints-priority.c 25 KB

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