ints-priority-dc.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482
  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. /* Initialize this to an actual value to force it into the .data
  53. * section so that we know it is properly initialized at entry into
  54. * the kernel but before bss is initialized to zero (which is where
  55. * it would live otherwise). The 0x1f magic represents the IRQs we
  56. * cannot actually mask out in hardware.
  57. */
  58. unsigned long irq_flags = 0x1f;
  59. /* The number of spurious interrupts */
  60. atomic_t num_spurious;
  61. struct ivgx {
  62. /* irq number for request_irq, available in mach-bf561/irq.h */
  63. int irqno;
  64. /* corresponding bit in the SICA_ISR0 register */
  65. int isrflag0;
  66. /* corresponding bit in the SICA_ISR1 register */
  67. int isrflag1;
  68. } ivg_table[NR_PERI_INTS];
  69. struct ivg_slice {
  70. /* position of first irq in ivg_table for given ivg */
  71. struct ivgx *ifirst;
  72. struct ivgx *istop;
  73. } ivg7_13[IVG13 - IVG7 + 1];
  74. static void search_IAR(void);
  75. /*
  76. * Search SIC_IAR and fill tables with the irqvalues
  77. * and their positions in the SIC_ISR register.
  78. */
  79. static void __init search_IAR(void)
  80. {
  81. unsigned ivg, irq_pos = 0;
  82. for (ivg = 0; ivg <= IVG13 - IVG7; ivg++) {
  83. int irqn;
  84. ivg7_13[ivg].istop = ivg7_13[ivg].ifirst = &ivg_table[irq_pos];
  85. for (irqn = 0; irqn < NR_PERI_INTS; irqn++) {
  86. int iar_shift = (irqn & 7) * 4;
  87. if (ivg ==
  88. (0xf &
  89. bfin_read32((unsigned long *)SICA_IAR0 +
  90. (irqn >> 3)) >> iar_shift)) {
  91. ivg_table[irq_pos].irqno = IVG7 + irqn;
  92. ivg_table[irq_pos].isrflag0 =
  93. (irqn < 32 ? (1 << irqn) : 0);
  94. ivg_table[irq_pos].isrflag1 =
  95. (irqn < 32 ? 0 : (1 << (irqn - 32)));
  96. ivg7_13[ivg].istop++;
  97. irq_pos++;
  98. }
  99. }
  100. }
  101. }
  102. /*
  103. * This is for BF561 internal IRQs
  104. */
  105. static void ack_noop(unsigned int irq)
  106. {
  107. /* Dummy function. */
  108. }
  109. static void bf561_core_mask_irq(unsigned int irq)
  110. {
  111. irq_flags &= ~(1 << irq);
  112. if (!irqs_disabled())
  113. local_irq_enable();
  114. }
  115. static void bf561_core_unmask_irq(unsigned int irq)
  116. {
  117. irq_flags |= 1 << irq;
  118. /*
  119. * If interrupts are enabled, IMASK must contain the same value
  120. * as irq_flags. Make sure that invariant holds. If interrupts
  121. * are currently disabled we need not do anything; one of the
  122. * callers will take care of setting IMASK to the proper value
  123. * when reenabling interrupts.
  124. * local_irq_enable just does "STI irq_flags", so it's exactly
  125. * what we need.
  126. */
  127. if (!irqs_disabled())
  128. local_irq_enable();
  129. return;
  130. }
  131. static void bf561_internal_mask_irq(unsigned int irq)
  132. {
  133. unsigned long irq_mask;
  134. if ((irq - (IRQ_CORETMR + 1)) < 32) {
  135. irq_mask = (1 << (irq - (IRQ_CORETMR + 1)));
  136. bfin_write_SICA_IMASK0(bfin_read_SICA_IMASK0() & ~irq_mask);
  137. } else {
  138. irq_mask = (1 << (irq - (IRQ_CORETMR + 1) - 32));
  139. bfin_write_SICA_IMASK1(bfin_read_SICA_IMASK1() & ~irq_mask);
  140. }
  141. }
  142. static void bf561_internal_unmask_irq(unsigned int irq)
  143. {
  144. unsigned long irq_mask;
  145. if ((irq - (IRQ_CORETMR + 1)) < 32) {
  146. irq_mask = (1 << (irq - (IRQ_CORETMR + 1)));
  147. bfin_write_SICA_IMASK0(bfin_read_SICA_IMASK0() | irq_mask);
  148. } else {
  149. irq_mask = (1 << (irq - (IRQ_CORETMR + 1) - 32));
  150. bfin_write_SICA_IMASK1(bfin_read_SICA_IMASK1() | irq_mask);
  151. }
  152. SSYNC();
  153. }
  154. static struct irq_chip bf561_core_irqchip = {
  155. .ack = ack_noop,
  156. .mask = bf561_core_mask_irq,
  157. .unmask = bf561_core_unmask_irq,
  158. };
  159. static struct irq_chip bf561_internal_irqchip = {
  160. .ack = ack_noop,
  161. .mask = bf561_internal_mask_irq,
  162. .unmask = bf561_internal_unmask_irq,
  163. };
  164. static unsigned short gpio_enabled[gpio_bank(MAX_BLACKFIN_GPIOS)];
  165. static unsigned short gpio_edge_triggered[gpio_bank(MAX_BLACKFIN_GPIOS)];
  166. static void bf561_gpio_ack_irq(unsigned int irq)
  167. {
  168. u16 gpionr = irq - IRQ_PF0;
  169. if (gpio_edge_triggered[gpio_bank(gpionr)] & gpio_bit(gpionr)) {
  170. set_gpio_data(gpionr, 0);
  171. SSYNC();
  172. }
  173. }
  174. static void bf561_gpio_mask_ack_irq(unsigned int irq)
  175. {
  176. u16 gpionr = irq - IRQ_PF0;
  177. if (gpio_edge_triggered[gpio_bank(gpionr)] & gpio_bit(gpionr)) {
  178. set_gpio_data(gpionr, 0);
  179. SSYNC();
  180. }
  181. set_gpio_maska(gpionr, 0);
  182. SSYNC();
  183. }
  184. static void bf561_gpio_mask_irq(unsigned int irq)
  185. {
  186. set_gpio_maska(irq - IRQ_PF0, 0);
  187. SSYNC();
  188. }
  189. static void bf561_gpio_unmask_irq(unsigned int irq)
  190. {
  191. set_gpio_maska(irq - IRQ_PF0, 1);
  192. SSYNC();
  193. }
  194. static unsigned int bf561_gpio_irq_startup(unsigned int irq)
  195. {
  196. unsigned int ret;
  197. u16 gpionr = irq - IRQ_PF0;
  198. if (!(gpio_enabled[gpio_bank(gpionr)] & gpio_bit(gpionr))) {
  199. ret = gpio_request(gpionr, "IRQ");
  200. if (ret)
  201. return ret;
  202. }
  203. gpio_enabled[gpio_bank(gpionr)] |= gpio_bit(gpionr);
  204. bf561_gpio_unmask_irq(irq);
  205. return ret;
  206. }
  207. static void bf561_gpio_irq_shutdown(unsigned int irq)
  208. {
  209. bf561_gpio_mask_irq(irq);
  210. gpio_free(irq - IRQ_PF0);
  211. gpio_enabled[gpio_bank(irq - IRQ_PF0)] &= ~gpio_bit(irq - IRQ_PF0);
  212. }
  213. static int bf561_gpio_irq_type(unsigned int irq, unsigned int type)
  214. {
  215. unsigned int ret;
  216. u16 gpionr = irq - IRQ_PF0;
  217. if (type == IRQ_TYPE_PROBE) {
  218. /* only probe unenabled GPIO interrupt lines */
  219. if (gpio_enabled[gpio_bank(gpionr)] & gpio_bit(gpionr))
  220. return 0;
  221. type = IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING;
  222. }
  223. if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING |
  224. IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW)) {
  225. if (!(gpio_enabled[gpio_bank(gpionr)] & gpio_bit(gpionr))) {
  226. ret = gpio_request(gpionr, "IRQ");
  227. if (ret)
  228. return ret;
  229. }
  230. gpio_enabled[gpio_bank(gpionr)] |= gpio_bit(gpionr);
  231. } else {
  232. gpio_enabled[gpio_bank(gpionr)] &= ~gpio_bit(gpionr);
  233. return 0;
  234. }
  235. set_gpio_dir(gpionr, 0);
  236. set_gpio_inen(gpionr, 1);
  237. if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING)) {
  238. gpio_edge_triggered[gpio_bank(gpionr)] |= gpio_bit(gpionr);
  239. set_gpio_edge(gpionr, 1);
  240. } else {
  241. set_gpio_edge(gpionr, 0);
  242. gpio_edge_triggered[gpio_bank(gpionr)] &= ~gpio_bit(gpionr);
  243. }
  244. if ((type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING))
  245. == (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING))
  246. set_gpio_both(gpionr, 1);
  247. else
  248. set_gpio_both(gpionr, 0);
  249. if ((type & (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_LEVEL_LOW)))
  250. set_gpio_polar(gpionr, 1); /* low or falling edge denoted by one */
  251. else
  252. set_gpio_polar(gpionr, 0); /* high or rising edge denoted by zero */
  253. SSYNC();
  254. if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING))
  255. set_irq_handler(irq, handle_edge_irq);
  256. else
  257. set_irq_handler(irq, handle_level_irq);
  258. return 0;
  259. }
  260. static struct irq_chip bf561_gpio_irqchip = {
  261. .ack = bf561_gpio_ack_irq,
  262. .mask = bf561_gpio_mask_irq,
  263. .mask_ack = bf561_gpio_mask_ack_irq,
  264. .unmask = bf561_gpio_unmask_irq,
  265. .set_type = bf561_gpio_irq_type,
  266. .startup = bf561_gpio_irq_startup,
  267. .shutdown = bf561_gpio_irq_shutdown
  268. };
  269. static void bf561_demux_gpio_irq(unsigned int inta_irq,
  270. struct irq_desc *intb_desc)
  271. {
  272. int irq, flag_d, mask;
  273. u16 gpio;
  274. switch (inta_irq) {
  275. case IRQ_PROG0_INTA:
  276. irq = IRQ_PF0;
  277. break;
  278. case IRQ_PROG1_INTA:
  279. irq = IRQ_PF16;
  280. break;
  281. case IRQ_PROG2_INTA:
  282. irq = IRQ_PF32;
  283. break;
  284. default:
  285. dump_stack();
  286. return;
  287. }
  288. gpio = irq - IRQ_PF0;
  289. flag_d = get_gpiop_data(gpio);
  290. mask = flag_d & (gpio_enabled[gpio_bank(gpio)] &
  291. get_gpiop_maska(gpio));
  292. do {
  293. if (mask & 1) {
  294. struct irq_desc *desc = irq_desc + irq;
  295. desc->handle_irq(irq, desc);
  296. }
  297. irq++;
  298. mask >>= 1;
  299. } while (mask);
  300. }
  301. void __init init_exception_vectors(void)
  302. {
  303. SSYNC();
  304. /* cannot program in software:
  305. * evt0 - emulation (jtag)
  306. * evt1 - reset
  307. */
  308. bfin_write_EVT2(evt_nmi);
  309. bfin_write_EVT3(trap);
  310. bfin_write_EVT5(evt_ivhw);
  311. bfin_write_EVT6(evt_timer);
  312. bfin_write_EVT7(evt_evt7);
  313. bfin_write_EVT8(evt_evt8);
  314. bfin_write_EVT9(evt_evt9);
  315. bfin_write_EVT10(evt_evt10);
  316. bfin_write_EVT11(evt_evt11);
  317. bfin_write_EVT12(evt_evt12);
  318. bfin_write_EVT13(evt_evt13);
  319. bfin_write_EVT14(evt14_softirq);
  320. bfin_write_EVT15(evt_system_call);
  321. CSYNC();
  322. }
  323. /*
  324. * This function should be called during kernel startup to initialize
  325. * the BFin IRQ handling routines.
  326. */
  327. int __init init_arch_irq(void)
  328. {
  329. int irq;
  330. unsigned long ilat = 0;
  331. /* Disable all the peripheral intrs - page 4-29 HW Ref manual */
  332. bfin_write_SICA_IMASK0(SIC_UNMASK_ALL);
  333. bfin_write_SICA_IMASK1(SIC_UNMASK_ALL);
  334. SSYNC();
  335. bfin_write_SICA_IWR0(IWR_ENABLE_ALL);
  336. bfin_write_SICA_IWR1(IWR_ENABLE_ALL);
  337. local_irq_disable();
  338. init_exception_buff();
  339. for (irq = 0; irq <= SYS_IRQS; irq++) {
  340. if (irq <= IRQ_CORETMR)
  341. set_irq_chip(irq, &bf561_core_irqchip);
  342. else
  343. set_irq_chip(irq, &bf561_internal_irqchip);
  344. if ((irq != IRQ_PROG0_INTA) &&
  345. (irq != IRQ_PROG1_INTA) &&
  346. (irq != IRQ_PROG2_INTA))
  347. set_irq_handler(irq, handle_simple_irq);
  348. else
  349. set_irq_chained_handler(irq, bf561_demux_gpio_irq);
  350. }
  351. for (irq = IRQ_PF0; irq <= IRQ_PF47; irq++) {
  352. set_irq_chip(irq, &bf561_gpio_irqchip);
  353. /* if configured as edge, then will be changed to do_edge_IRQ */
  354. set_irq_handler(irq, handle_level_irq);
  355. }
  356. bfin_write_IMASK(0);
  357. CSYNC();
  358. ilat = bfin_read_ILAT();
  359. CSYNC();
  360. bfin_write_ILAT(ilat);
  361. CSYNC();
  362. printk(KERN_INFO "Configuring Blackfin Priority Driven Interrupts\n");
  363. /* IMASK=xxx is equivalent to STI xx or irq_flags=xx,
  364. * local_irq_enable()
  365. */
  366. program_IAR();
  367. /* Therefore it's better to setup IARs before interrupts enabled */
  368. search_IAR();
  369. /* Enable interrupts IVG7-15 */
  370. irq_flags = irq_flags | IMASK_IVG15 |
  371. IMASK_IVG14 | IMASK_IVG13 | IMASK_IVG12 | IMASK_IVG11 |
  372. IMASK_IVG10 | IMASK_IVG9 | IMASK_IVG8 | IMASK_IVG7 | IMASK_IVGHW;
  373. return 0;
  374. }
  375. #ifdef CONFIG_DO_IRQ_L1
  376. __attribute__((l1_text))
  377. #endif
  378. void do_irq(int vec, struct pt_regs *fp)
  379. {
  380. if (vec == EVT_IVTMR_P) {
  381. vec = IRQ_CORETMR;
  382. } else {
  383. struct ivgx *ivg = ivg7_13[vec - IVG7].ifirst;
  384. struct ivgx *ivg_stop = ivg7_13[vec - IVG7].istop;
  385. unsigned long sic_status0, sic_status1;
  386. SSYNC();
  387. sic_status0 = bfin_read_SICA_IMASK0() & bfin_read_SICA_ISR0();
  388. sic_status1 = bfin_read_SICA_IMASK1() & bfin_read_SICA_ISR1();
  389. for (;; ivg++) {
  390. if (ivg >= ivg_stop) {
  391. atomic_inc(&num_spurious);
  392. return;
  393. } else if ((sic_status0 & ivg->isrflag0) ||
  394. (sic_status1 & ivg->isrflag1))
  395. break;
  396. }
  397. vec = ivg->irqno;
  398. }
  399. asm_do_IRQ(vec, fp);
  400. #ifdef CONFIG_KGDB
  401. kgdb_process_breakpoint();
  402. #endif
  403. }