ints-priority.c 26 KB

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