ints-priority-dc.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484
  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. char buf[8];
  198. u16 gpionr = irq - IRQ_PF0;
  199. if (!(gpio_enabled[gpio_bank(gpionr)] & gpio_bit(gpionr))) {
  200. snprintf(buf, sizeof buf, "IRQ %d", irq);
  201. ret = gpio_request(gpionr, buf);
  202. if (ret)
  203. return ret;
  204. }
  205. gpio_enabled[gpio_bank(gpionr)] |= gpio_bit(gpionr);
  206. bf561_gpio_unmask_irq(irq);
  207. return ret;
  208. }
  209. static void bf561_gpio_irq_shutdown(unsigned int irq)
  210. {
  211. bf561_gpio_mask_irq(irq);
  212. gpio_free(irq - IRQ_PF0);
  213. gpio_enabled[gpio_bank(irq - IRQ_PF0)] &= ~gpio_bit(irq - IRQ_PF0);
  214. }
  215. static int bf561_gpio_irq_type(unsigned int irq, unsigned int type)
  216. {
  217. unsigned int ret;
  218. char buf[8];
  219. u16 gpionr = irq - IRQ_PF0;
  220. if (type == IRQ_TYPE_PROBE) {
  221. /* only probe unenabled GPIO interrupt lines */
  222. if (gpio_enabled[gpio_bank(gpionr)] & gpio_bit(gpionr))
  223. return 0;
  224. type = IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING;
  225. }
  226. if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING |
  227. IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW)) {
  228. if (!(gpio_enabled[gpio_bank(gpionr)] & gpio_bit(gpionr))) {
  229. snprintf(buf, sizeof buf, "IRQ %d", irq);
  230. ret = gpio_request(gpionr, buf);
  231. if (ret)
  232. return ret;
  233. }
  234. gpio_enabled[gpio_bank(gpionr)] |= gpio_bit(gpionr);
  235. } else {
  236. gpio_enabled[gpio_bank(gpionr)] &= ~gpio_bit(gpionr);
  237. return 0;
  238. }
  239. set_gpio_dir(gpionr, 0);
  240. set_gpio_inen(gpionr, 1);
  241. if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING)) {
  242. gpio_edge_triggered[gpio_bank(gpionr)] |= gpio_bit(gpionr);
  243. set_gpio_edge(gpionr, 1);
  244. } else {
  245. set_gpio_edge(gpionr, 0);
  246. gpio_edge_triggered[gpio_bank(gpionr)] &= ~gpio_bit(gpionr);
  247. }
  248. if ((type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING))
  249. == (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING))
  250. set_gpio_both(gpionr, 1);
  251. else
  252. set_gpio_both(gpionr, 0);
  253. if ((type & (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_LEVEL_LOW)))
  254. set_gpio_polar(gpionr, 1); /* low or falling edge denoted by one */
  255. else
  256. set_gpio_polar(gpionr, 0); /* high or rising edge denoted by zero */
  257. SSYNC();
  258. if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING))
  259. set_irq_handler(irq, handle_edge_irq);
  260. else
  261. set_irq_handler(irq, handle_level_irq);
  262. return 0;
  263. }
  264. static struct irq_chip bf561_gpio_irqchip = {
  265. .ack = bf561_gpio_ack_irq,
  266. .mask = bf561_gpio_mask_irq,
  267. .mask_ack = bf561_gpio_mask_ack_irq,
  268. .unmask = bf561_gpio_unmask_irq,
  269. .set_type = bf561_gpio_irq_type,
  270. .startup = bf561_gpio_irq_startup,
  271. .shutdown = bf561_gpio_irq_shutdown
  272. };
  273. static void bf561_demux_gpio_irq(unsigned int inta_irq,
  274. struct irq_desc *intb_desc)
  275. {
  276. int irq, flag_d, mask;
  277. u16 gpio;
  278. switch (inta_irq) {
  279. case IRQ_PROG0_INTA:
  280. irq = IRQ_PF0;
  281. break;
  282. case IRQ_PROG1_INTA:
  283. irq = IRQ_PF16;
  284. break;
  285. case IRQ_PROG2_INTA:
  286. irq = IRQ_PF32;
  287. break;
  288. default:
  289. dump_stack();
  290. return;
  291. }
  292. gpio = irq - IRQ_PF0;
  293. flag_d = get_gpiop_data(gpio);
  294. mask = flag_d & (gpio_enabled[gpio_bank(gpio)] &
  295. get_gpiop_maska(gpio));
  296. do {
  297. if (mask & 1) {
  298. struct irq_desc *desc = irq_desc + irq;
  299. desc->handle_irq(irq, desc);
  300. }
  301. irq++;
  302. mask >>= 1;
  303. } while (mask);
  304. }
  305. void __init init_exception_vectors(void)
  306. {
  307. SSYNC();
  308. /* cannot program in software:
  309. * evt0 - emulation (jtag)
  310. * evt1 - reset
  311. */
  312. bfin_write_EVT2(evt_nmi);
  313. bfin_write_EVT3(trap);
  314. bfin_write_EVT5(evt_ivhw);
  315. bfin_write_EVT6(evt_timer);
  316. bfin_write_EVT7(evt_evt7);
  317. bfin_write_EVT8(evt_evt8);
  318. bfin_write_EVT9(evt_evt9);
  319. bfin_write_EVT10(evt_evt10);
  320. bfin_write_EVT11(evt_evt11);
  321. bfin_write_EVT12(evt_evt12);
  322. bfin_write_EVT13(evt_evt13);
  323. bfin_write_EVT14(evt14_softirq);
  324. bfin_write_EVT15(evt_system_call);
  325. CSYNC();
  326. }
  327. /*
  328. * This function should be called during kernel startup to initialize
  329. * the BFin IRQ handling routines.
  330. */
  331. int __init init_arch_irq(void)
  332. {
  333. int irq;
  334. unsigned long ilat = 0;
  335. /* Disable all the peripheral intrs - page 4-29 HW Ref manual */
  336. bfin_write_SICA_IMASK0(SIC_UNMASK_ALL);
  337. bfin_write_SICA_IMASK1(SIC_UNMASK_ALL);
  338. SSYNC();
  339. bfin_write_SICA_IWR0(IWR_ENABLE_ALL);
  340. bfin_write_SICA_IWR1(IWR_ENABLE_ALL);
  341. local_irq_disable();
  342. init_exception_buff();
  343. for (irq = 0; irq <= SYS_IRQS; irq++) {
  344. if (irq <= IRQ_CORETMR)
  345. set_irq_chip(irq, &bf561_core_irqchip);
  346. else
  347. set_irq_chip(irq, &bf561_internal_irqchip);
  348. if ((irq != IRQ_PROG0_INTA) &&
  349. (irq != IRQ_PROG1_INTA) &&
  350. (irq != IRQ_PROG2_INTA))
  351. set_irq_handler(irq, handle_simple_irq);
  352. else
  353. set_irq_chained_handler(irq, bf561_demux_gpio_irq);
  354. }
  355. for (irq = IRQ_PF0; irq <= IRQ_PF47; irq++) {
  356. set_irq_chip(irq, &bf561_gpio_irqchip);
  357. /* if configured as edge, then will be changed to do_edge_IRQ */
  358. set_irq_handler(irq, handle_level_irq);
  359. }
  360. bfin_write_IMASK(0);
  361. CSYNC();
  362. ilat = bfin_read_ILAT();
  363. CSYNC();
  364. bfin_write_ILAT(ilat);
  365. CSYNC();
  366. printk(KERN_INFO "Configuring Blackfin Priority Driven Interrupts\n");
  367. /* IMASK=xxx is equivalent to STI xx or irq_flags=xx,
  368. * local_irq_enable()
  369. */
  370. program_IAR();
  371. /* Therefore it's better to setup IARs before interrupts enabled */
  372. search_IAR();
  373. /* Enable interrupts IVG7-15 */
  374. irq_flags = irq_flags | IMASK_IVG15 |
  375. IMASK_IVG14 | IMASK_IVG13 | IMASK_IVG12 | IMASK_IVG11 |
  376. IMASK_IVG10 | IMASK_IVG9 | IMASK_IVG8 | IMASK_IVG7 | IMASK_IVGHW;
  377. return 0;
  378. }
  379. #ifdef CONFIG_DO_IRQ_L1
  380. __attribute__((l1_text))
  381. #endif
  382. void do_irq(int vec, struct pt_regs *fp)
  383. {
  384. if (vec == EVT_IVTMR_P) {
  385. vec = IRQ_CORETMR;
  386. } else {
  387. struct ivgx *ivg = ivg7_13[vec - IVG7].ifirst;
  388. struct ivgx *ivg_stop = ivg7_13[vec - IVG7].istop;
  389. unsigned long sic_status0, sic_status1;
  390. SSYNC();
  391. sic_status0 = bfin_read_SICA_IMASK0() & bfin_read_SICA_ISR0();
  392. sic_status1 = bfin_read_SICA_IMASK1() & bfin_read_SICA_ISR1();
  393. for (;; ivg++) {
  394. if (ivg >= ivg_stop) {
  395. atomic_inc(&num_spurious);
  396. return;
  397. } else if ((sic_status0 & ivg->isrflag0) ||
  398. (sic_status1 & ivg->isrflag1))
  399. break;
  400. }
  401. vec = ivg->irqno;
  402. }
  403. asm_do_IRQ(vec, fp);
  404. #ifdef CONFIG_KGDB
  405. kgdb_process_breakpoint();
  406. #endif
  407. }