ints-priority-dc.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485
  1. /*
  2. * File: arch/blackfin/mach-common/ints-priority-dc.c
  3. * Based on:
  4. * Author:
  5. *
  6. * Created: ?
  7. * Description: Set up the interrupt priorities
  8. *
  9. * Modified:
  10. * 1996 Roman Zippel
  11. * 1999 D. Jeff Dionne <jeff@uclinux.org>
  12. * 2000-2001 Lineo, Inc. D. Jefff Dionne <jeff@lineo.ca>
  13. * 2002 Arcturus Networks Inc. MaTed <mated@sympatico.ca>
  14. * 2003 Metrowerks/Motorola
  15. * 2003 Bas Vermeulen <bas@buyways.nl>
  16. * Copyright 2004-2006 Analog Devices Inc.
  17. *
  18. * Bugs: Enter bugs at http://blackfin.uclinux.org/
  19. *
  20. * This program is free software; you can redistribute it and/or modify
  21. * it under the terms of the GNU General Public License as published by
  22. * the Free Software Foundation; either version 2 of the License, or
  23. * (at your option) any later version.
  24. *
  25. * This program is distributed in the hope that it will be useful,
  26. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  27. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  28. * GNU General Public License for more details.
  29. *
  30. * You should have received a copy of the GNU General Public License
  31. * along with this program; if not, see the file COPYING, or write
  32. * to the Free Software Foundation, Inc.,
  33. * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  34. */
  35. #include <linux/module.h>
  36. #include <linux/kernel_stat.h>
  37. #include <linux/seq_file.h>
  38. #include <linux/irq.h>
  39. #ifdef CONFIG_KGDB
  40. #include <linux/kgdb.h>
  41. #endif
  42. #include <asm/traps.h>
  43. #include <asm/blackfin.h>
  44. #include <asm/gpio.h>
  45. #include <asm/irq_handler.h>
  46. /*
  47. * NOTES:
  48. * - we have separated the physical Hardware interrupt from the
  49. * levels that the LINUX kernel sees (see the description in irq.h)
  50. * -
  51. */
  52. unsigned long irq_flags = 0;
  53. /* The number of spurious interrupts */
  54. atomic_t num_spurious;
  55. struct ivgx {
  56. /* irq number for request_irq, available in mach-bf561/irq.h */
  57. int irqno;
  58. /* corresponding bit in the SICA_ISR0 register */
  59. int isrflag0;
  60. /* corresponding bit in the SICA_ISR1 register */
  61. int isrflag1;
  62. } ivg_table[NR_PERI_INTS];
  63. struct ivg_slice {
  64. /* position of first irq in ivg_table for given ivg */
  65. struct ivgx *ifirst;
  66. struct ivgx *istop;
  67. } ivg7_13[IVG13 - IVG7 + 1];
  68. static void search_IAR(void);
  69. /*
  70. * Search SIC_IAR and fill tables with the irqvalues
  71. * and their positions in the SIC_ISR register.
  72. */
  73. static void __init search_IAR(void)
  74. {
  75. unsigned ivg, irq_pos = 0;
  76. for (ivg = 0; ivg <= IVG13 - IVG7; ivg++) {
  77. int irqn;
  78. ivg7_13[ivg].istop = ivg7_13[ivg].ifirst = &ivg_table[irq_pos];
  79. for (irqn = 0; irqn < NR_PERI_INTS; irqn++) {
  80. int iar_shift = (irqn & 7) * 4;
  81. if (ivg ==
  82. (0xf &
  83. bfin_read32((unsigned long *)SICA_IAR0 +
  84. (irqn >> 3)) >> iar_shift)) {
  85. ivg_table[irq_pos].irqno = IVG7 + irqn;
  86. ivg_table[irq_pos].isrflag0 =
  87. (irqn < 32 ? (1 << irqn) : 0);
  88. ivg_table[irq_pos].isrflag1 =
  89. (irqn < 32 ? 0 : (1 << (irqn - 32)));
  90. ivg7_13[ivg].istop++;
  91. irq_pos++;
  92. }
  93. }
  94. }
  95. }
  96. /*
  97. * This is for BF561 internal IRQs
  98. */
  99. static void ack_noop(unsigned int irq)
  100. {
  101. /* Dummy function. */
  102. }
  103. static void bf561_core_mask_irq(unsigned int irq)
  104. {
  105. irq_flags &= ~(1 << irq);
  106. if (!irqs_disabled())
  107. local_irq_enable();
  108. }
  109. static void bf561_core_unmask_irq(unsigned int irq)
  110. {
  111. irq_flags |= 1 << irq;
  112. /*
  113. * If interrupts are enabled, IMASK must contain the same value
  114. * as irq_flags. Make sure that invariant holds. If interrupts
  115. * are currently disabled we need not do anything; one of the
  116. * callers will take care of setting IMASK to the proper value
  117. * when reenabling interrupts.
  118. * local_irq_enable just does "STI irq_flags", so it's exactly
  119. * what we need.
  120. */
  121. if (!irqs_disabled())
  122. local_irq_enable();
  123. return;
  124. }
  125. static void bf561_internal_mask_irq(unsigned int irq)
  126. {
  127. unsigned long irq_mask;
  128. if ((irq - (IRQ_CORETMR + 1)) < 32) {
  129. irq_mask = (1 << (irq - (IRQ_CORETMR + 1)));
  130. bfin_write_SICA_IMASK0(bfin_read_SICA_IMASK0() & ~irq_mask);
  131. } else {
  132. irq_mask = (1 << (irq - (IRQ_CORETMR + 1) - 32));
  133. bfin_write_SICA_IMASK1(bfin_read_SICA_IMASK1() & ~irq_mask);
  134. }
  135. }
  136. static void bf561_internal_unmask_irq(unsigned int irq)
  137. {
  138. unsigned long irq_mask;
  139. if ((irq - (IRQ_CORETMR + 1)) < 32) {
  140. irq_mask = (1 << (irq - (IRQ_CORETMR + 1)));
  141. bfin_write_SICA_IMASK0(bfin_read_SICA_IMASK0() | irq_mask);
  142. } else {
  143. irq_mask = (1 << (irq - (IRQ_CORETMR + 1) - 32));
  144. bfin_write_SICA_IMASK1(bfin_read_SICA_IMASK1() | irq_mask);
  145. }
  146. SSYNC();
  147. }
  148. static struct irq_chip bf561_core_irqchip = {
  149. .ack = ack_noop,
  150. .mask = bf561_core_mask_irq,
  151. .unmask = bf561_core_unmask_irq,
  152. };
  153. static struct irq_chip bf561_internal_irqchip = {
  154. .ack = ack_noop,
  155. .mask = bf561_internal_mask_irq,
  156. .unmask = bf561_internal_unmask_irq,
  157. };
  158. #ifdef CONFIG_IRQCHIP_DEMUX_GPIO
  159. static unsigned short gpio_enabled[gpio_bank(MAX_BLACKFIN_GPIOS)];
  160. static unsigned short gpio_edge_triggered[gpio_bank(MAX_BLACKFIN_GPIOS)];
  161. static void bf561_gpio_ack_irq(unsigned int irq)
  162. {
  163. u16 gpionr = irq - IRQ_PF0;
  164. if (gpio_edge_triggered[gpio_bank(gpionr)] & gpio_bit(gpionr)) {
  165. set_gpio_data(gpionr, 0);
  166. SSYNC();
  167. }
  168. }
  169. static void bf561_gpio_mask_ack_irq(unsigned int irq)
  170. {
  171. u16 gpionr = irq - IRQ_PF0;
  172. if (gpio_edge_triggered[gpio_bank(gpionr)] & gpio_bit(gpionr)) {
  173. set_gpio_data(gpionr, 0);
  174. SSYNC();
  175. }
  176. set_gpio_maska(gpionr, 0);
  177. SSYNC();
  178. }
  179. static void bf561_gpio_mask_irq(unsigned int irq)
  180. {
  181. set_gpio_maska(irq - IRQ_PF0, 0);
  182. SSYNC();
  183. }
  184. static void bf561_gpio_unmask_irq(unsigned int irq)
  185. {
  186. set_gpio_maska(irq - IRQ_PF0, 1);
  187. SSYNC();
  188. }
  189. static unsigned int bf561_gpio_irq_startup(unsigned int irq)
  190. {
  191. unsigned int ret;
  192. u16 gpionr = irq - IRQ_PF0;
  193. if (!(gpio_enabled[gpio_bank(gpionr)] & gpio_bit(gpionr))) {
  194. ret = gpio_request(gpionr, "IRQ");
  195. if (ret)
  196. return ret;
  197. }
  198. gpio_enabled[gpio_bank(gpionr)] |= gpio_bit(gpionr);
  199. bf561_gpio_unmask_irq(irq);
  200. return ret;
  201. }
  202. static void bf561_gpio_irq_shutdown(unsigned int irq)
  203. {
  204. bf561_gpio_mask_irq(irq);
  205. gpio_free(irq - IRQ_PF0);
  206. gpio_enabled[gpio_bank(irq - IRQ_PF0)] &= ~gpio_bit(irq - IRQ_PF0);
  207. }
  208. static int bf561_gpio_irq_type(unsigned int irq, unsigned int type)
  209. {
  210. unsigned int ret;
  211. u16 gpionr = irq - IRQ_PF0;
  212. if (type == IRQ_TYPE_PROBE) {
  213. /* only probe unenabled GPIO interrupt lines */
  214. if (gpio_enabled[gpio_bank(gpionr)] & gpio_bit(gpionr))
  215. return 0;
  216. type = IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING;
  217. }
  218. if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING |
  219. IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW)) {
  220. if (!(gpio_enabled[gpio_bank(gpionr)] & gpio_bit(gpionr))) {
  221. ret = gpio_request(gpionr, "IRQ");
  222. if (ret)
  223. return ret;
  224. }
  225. gpio_enabled[gpio_bank(gpionr)] |= gpio_bit(gpionr);
  226. } else {
  227. gpio_enabled[gpio_bank(gpionr)] &= ~gpio_bit(gpionr);
  228. return 0;
  229. }
  230. set_gpio_dir(gpionr, 0);
  231. set_gpio_inen(gpionr, 1);
  232. if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING)) {
  233. gpio_edge_triggered[gpio_bank(gpionr)] |= gpio_bit(gpionr);
  234. set_gpio_edge(gpionr, 1);
  235. } else {
  236. set_gpio_edge(gpionr, 0);
  237. gpio_edge_triggered[gpio_bank(gpionr)] &= ~gpio_bit(gpionr);
  238. }
  239. if ((type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING))
  240. == (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING))
  241. set_gpio_both(gpionr, 1);
  242. else
  243. set_gpio_both(gpionr, 0);
  244. if ((type & (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_LEVEL_LOW)))
  245. set_gpio_polar(gpionr, 1); /* low or falling edge denoted by one */
  246. else
  247. set_gpio_polar(gpionr, 0); /* high or rising edge denoted by zero */
  248. SSYNC();
  249. if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING))
  250. set_irq_handler(irq, handle_edge_irq);
  251. else
  252. set_irq_handler(irq, handle_level_irq);
  253. return 0;
  254. }
  255. static struct irq_chip bf561_gpio_irqchip = {
  256. .ack = bf561_gpio_ack_irq,
  257. .mask = bf561_gpio_mask_irq,
  258. .mask_ack = bf561_gpio_mask_ack_irq,
  259. .unmask = bf561_gpio_unmask_irq,
  260. .set_type = bf561_gpio_irq_type,
  261. .startup = bf561_gpio_irq_startup,
  262. .shutdown = bf561_gpio_irq_shutdown
  263. };
  264. static void bf561_demux_gpio_irq(unsigned int inta_irq,
  265. struct irq_desc *intb_desc)
  266. {
  267. int irq, flag_d, mask;
  268. u16 gpio;
  269. switch (inta_irq) {
  270. case IRQ_PROG0_INTA:
  271. irq = IRQ_PF0;
  272. break;
  273. case IRQ_PROG1_INTA:
  274. irq = IRQ_PF16;
  275. break;
  276. case IRQ_PROG2_INTA:
  277. irq = IRQ_PF32;
  278. break;
  279. default:
  280. dump_stack();
  281. return;
  282. }
  283. gpio = irq - IRQ_PF0;
  284. flag_d = get_gpiop_data(gpio);
  285. mask = flag_d & (gpio_enabled[gpio_bank(gpio)] &
  286. get_gpiop_maska(gpio));
  287. do {
  288. if (mask & 1) {
  289. struct irq_desc *desc = irq_desc + irq;
  290. desc->handle_irq(irq, desc);
  291. }
  292. irq++;
  293. mask >>= 1;
  294. } while (mask);
  295. }
  296. #endif /* CONFIG_IRQCHIP_DEMUX_GPIO */
  297. void __init init_exception_vectors(void)
  298. {
  299. SSYNC();
  300. /* cannot program in software:
  301. * evt0 - emulation (jtag)
  302. * evt1 - reset
  303. */
  304. bfin_write_EVT2(evt_nmi);
  305. bfin_write_EVT3(trap);
  306. bfin_write_EVT5(evt_ivhw);
  307. bfin_write_EVT6(evt_timer);
  308. bfin_write_EVT7(evt_evt7);
  309. bfin_write_EVT8(evt_evt8);
  310. bfin_write_EVT9(evt_evt9);
  311. bfin_write_EVT10(evt_evt10);
  312. bfin_write_EVT11(evt_evt11);
  313. bfin_write_EVT12(evt_evt12);
  314. bfin_write_EVT13(evt_evt13);
  315. bfin_write_EVT14(evt14_softirq);
  316. bfin_write_EVT15(evt_system_call);
  317. CSYNC();
  318. }
  319. /*
  320. * This function should be called during kernel startup to initialize
  321. * the BFin IRQ handling routines.
  322. */
  323. int __init init_arch_irq(void)
  324. {
  325. int irq;
  326. unsigned long ilat = 0;
  327. /* Disable all the peripheral intrs - page 4-29 HW Ref manual */
  328. bfin_write_SICA_IMASK0(SIC_UNMASK_ALL);
  329. bfin_write_SICA_IMASK1(SIC_UNMASK_ALL);
  330. SSYNC();
  331. bfin_write_SICA_IWR0(IWR_ENABLE_ALL);
  332. bfin_write_SICA_IWR1(IWR_ENABLE_ALL);
  333. local_irq_disable();
  334. init_exception_buff();
  335. for (irq = 0; irq <= SYS_IRQS; irq++) {
  336. if (irq <= IRQ_CORETMR)
  337. set_irq_chip(irq, &bf561_core_irqchip);
  338. else
  339. set_irq_chip(irq, &bf561_internal_irqchip);
  340. #ifdef CONFIG_IRQCHIP_DEMUX_GPIO
  341. if ((irq != IRQ_PROG0_INTA) &&
  342. (irq != IRQ_PROG1_INTA) && (irq != IRQ_PROG2_INTA)) {
  343. #endif
  344. set_irq_handler(irq, handle_simple_irq);
  345. #ifdef CONFIG_IRQCHIP_DEMUX_GPIO
  346. } else {
  347. set_irq_chained_handler(irq, bf561_demux_gpio_irq);
  348. }
  349. #endif
  350. }
  351. #ifdef CONFIG_IRQCHIP_DEMUX_GPIO
  352. for (irq = IRQ_PF0; irq <= IRQ_PF47; irq++) {
  353. set_irq_chip(irq, &bf561_gpio_irqchip);
  354. /* if configured as edge, then will be changed to do_edge_IRQ */
  355. set_irq_handler(irq, handle_level_irq);
  356. }
  357. #endif
  358. bfin_write_IMASK(0);
  359. CSYNC();
  360. ilat = bfin_read_ILAT();
  361. CSYNC();
  362. bfin_write_ILAT(ilat);
  363. CSYNC();
  364. printk(KERN_INFO "Configuring Blackfin Priority Driven Interrupts\n");
  365. /* IMASK=xxx is equivalent to STI xx or irq_flags=xx,
  366. * local_irq_enable()
  367. */
  368. program_IAR();
  369. /* Therefore it's better to setup IARs before interrupts enabled */
  370. search_IAR();
  371. /* Enable interrupts IVG7-15 */
  372. irq_flags = irq_flags | IMASK_IVG15 |
  373. IMASK_IVG14 | IMASK_IVG13 | IMASK_IVG12 | IMASK_IVG11 |
  374. IMASK_IVG10 | IMASK_IVG9 | IMASK_IVG8 | IMASK_IVG7 | IMASK_IVGHW;
  375. return 0;
  376. }
  377. #ifdef CONFIG_DO_IRQ_L1
  378. void do_irq(int vec, struct pt_regs *fp)__attribute__((l1_text));
  379. #endif
  380. void do_irq(int vec, struct pt_regs *fp)
  381. {
  382. if (vec == EVT_IVTMR_P) {
  383. vec = IRQ_CORETMR;
  384. } else {
  385. struct ivgx *ivg = ivg7_13[vec - IVG7].ifirst;
  386. struct ivgx *ivg_stop = ivg7_13[vec - IVG7].istop;
  387. unsigned long sic_status0, sic_status1;
  388. SSYNC();
  389. sic_status0 = bfin_read_SICA_IMASK0() & bfin_read_SICA_ISR0();
  390. sic_status1 = bfin_read_SICA_IMASK1() & bfin_read_SICA_ISR1();
  391. for (;; ivg++) {
  392. if (ivg >= ivg_stop) {
  393. atomic_inc(&num_spurious);
  394. return;
  395. } else if ((sic_status0 & ivg->isrflag0) ||
  396. (sic_status1 & ivg->isrflag1))
  397. break;
  398. }
  399. vec = ivg->irqno;
  400. }
  401. asm_do_IRQ(vec, fp);
  402. #ifdef CONFIG_KGDB
  403. kgdb_process_breakpoint();
  404. #endif
  405. }