gt64260_pic.c 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  1. /*
  2. * Interrupt controller support for Galileo's GT64260.
  3. *
  4. * Author: Chris Zankel <source@mvista.com>
  5. * Modified by: Mark A. Greer <mgreer@mvista.com>
  6. *
  7. * Based on sources from Rabeeh Khoury / Galileo Technology
  8. *
  9. * 2001 (c) MontaVista, Software, Inc. This file is licensed under
  10. * the terms of the GNU General Public License version 2. This program
  11. * is licensed "as is" without any warranty of any kind, whether express
  12. * or implied.
  13. */
  14. /*
  15. * This file contains the specific functions to support the GT64260
  16. * interrupt controller.
  17. *
  18. * The GT64260 has two main interrupt registers (high and low) that
  19. * summarizes the interrupts generated by the units of the GT64260.
  20. * Each bit is assigned to an interrupt number, where the low register
  21. * are assigned from IRQ0 to IRQ31 and the high cause register
  22. * from IRQ32 to IRQ63
  23. * The GPP (General Purpose Port) interrupts are assigned from IRQ64 (GPP0)
  24. * to IRQ95 (GPP31).
  25. * get_irq() returns the lowest interrupt number that is currently asserted.
  26. *
  27. * Note:
  28. * - This driver does not initialize the GPP when used as an interrupt
  29. * input.
  30. */
  31. #include <linux/stddef.h>
  32. #include <linux/init.h>
  33. #include <linux/interrupt.h>
  34. #include <linux/sched.h>
  35. #include <linux/signal.h>
  36. #include <linux/delay.h>
  37. #include <linux/irq.h>
  38. #include <asm/io.h>
  39. #include <asm/system.h>
  40. #include <asm/irq.h>
  41. #include <asm/mv64x60.h>
  42. #include <asm/machdep.h>
  43. #define CPU_INTR_STR "gt64260 cpu interface error"
  44. #define PCI0_INTR_STR "gt64260 pci 0 error"
  45. #define PCI1_INTR_STR "gt64260 pci 1 error"
  46. /* ========================== forward declaration ========================== */
  47. static void gt64260_unmask_irq(unsigned int);
  48. static void gt64260_mask_irq(unsigned int);
  49. /* ========================== local declarations =========================== */
  50. struct hw_interrupt_type gt64260_pic = {
  51. .typename = " gt64260_pic ",
  52. .enable = gt64260_unmask_irq,
  53. .disable = gt64260_mask_irq,
  54. .ack = gt64260_mask_irq,
  55. .end = gt64260_unmask_irq,
  56. };
  57. u32 gt64260_irq_base = 0; /* GT64260 handles the next 96 IRQs from here */
  58. static struct mv64x60_handle bh;
  59. /* gt64260_init_irq()
  60. *
  61. * This function initializes the interrupt controller. It assigns
  62. * all interrupts from IRQ0 to IRQ95 to the gt64260 interrupt controller.
  63. *
  64. * Note:
  65. * We register all GPP inputs as interrupt source, but disable them.
  66. */
  67. void __init
  68. gt64260_init_irq(void)
  69. {
  70. int i;
  71. if (ppc_md.progress)
  72. ppc_md.progress("gt64260_init_irq: enter", 0x0);
  73. bh.v_base = mv64x60_get_bridge_vbase();
  74. ppc_cached_irq_mask[0] = 0;
  75. ppc_cached_irq_mask[1] = 0x0f000000; /* Enable GPP intrs */
  76. ppc_cached_irq_mask[2] = 0;
  77. /* disable all interrupts and clear current interrupts */
  78. mv64x60_write(&bh, MV64x60_GPP_INTR_MASK, ppc_cached_irq_mask[2]);
  79. mv64x60_write(&bh, MV64x60_GPP_INTR_CAUSE, 0);
  80. mv64x60_write(&bh, GT64260_IC_CPU_INTR_MASK_LO, ppc_cached_irq_mask[0]);
  81. mv64x60_write(&bh, GT64260_IC_CPU_INTR_MASK_HI, ppc_cached_irq_mask[1]);
  82. /* use the gt64260 for all (possible) interrupt sources */
  83. for (i = gt64260_irq_base; i < (gt64260_irq_base + 96); i++)
  84. irq_desc[i].chip = &gt64260_pic;
  85. if (ppc_md.progress)
  86. ppc_md.progress("gt64260_init_irq: exit", 0x0);
  87. }
  88. /*
  89. * gt64260_get_irq()
  90. *
  91. * This function returns the lowest interrupt number of all interrupts that
  92. * are currently asserted.
  93. *
  94. * Output Variable(s):
  95. * None.
  96. *
  97. * Returns:
  98. * int <interrupt number> or -2 (bogus interrupt)
  99. */
  100. int
  101. gt64260_get_irq(void)
  102. {
  103. int irq;
  104. int irq_gpp;
  105. irq = mv64x60_read(&bh, GT64260_IC_MAIN_CAUSE_LO);
  106. irq = __ilog2((irq & 0x3dfffffe) & ppc_cached_irq_mask[0]);
  107. if (irq == -1) {
  108. irq = mv64x60_read(&bh, GT64260_IC_MAIN_CAUSE_HI);
  109. irq = __ilog2((irq & 0x0f000db7) & ppc_cached_irq_mask[1]);
  110. if (irq == -1)
  111. irq = -2; /* bogus interrupt, should never happen */
  112. else {
  113. if (irq >= 24) {
  114. irq_gpp = mv64x60_read(&bh,
  115. MV64x60_GPP_INTR_CAUSE);
  116. irq_gpp = __ilog2(irq_gpp &
  117. ppc_cached_irq_mask[2]);
  118. if (irq_gpp == -1)
  119. irq = -2;
  120. else {
  121. irq = irq_gpp + 64;
  122. mv64x60_write(&bh,
  123. MV64x60_GPP_INTR_CAUSE,
  124. ~(1 << (irq - 64)));
  125. }
  126. } else
  127. irq += 32;
  128. }
  129. }
  130. (void)mv64x60_read(&bh, MV64x60_GPP_INTR_CAUSE);
  131. if (irq < 0)
  132. return (irq);
  133. else
  134. return (gt64260_irq_base + irq);
  135. }
  136. /* gt64260_unmask_irq()
  137. *
  138. * This function enables an interrupt.
  139. *
  140. * Input Variable(s):
  141. * unsigned int interrupt number (IRQ0...IRQ95).
  142. *
  143. * Output Variable(s):
  144. * None.
  145. *
  146. * Returns:
  147. * void
  148. */
  149. static void
  150. gt64260_unmask_irq(unsigned int irq)
  151. {
  152. irq -= gt64260_irq_base;
  153. if (irq > 31)
  154. if (irq > 63) /* unmask GPP irq */
  155. mv64x60_write(&bh, MV64x60_GPP_INTR_MASK,
  156. ppc_cached_irq_mask[2] |= (1 << (irq - 64)));
  157. else /* mask high interrupt register */
  158. mv64x60_write(&bh, GT64260_IC_CPU_INTR_MASK_HI,
  159. ppc_cached_irq_mask[1] |= (1 << (irq - 32)));
  160. else /* mask low interrupt register */
  161. mv64x60_write(&bh, GT64260_IC_CPU_INTR_MASK_LO,
  162. ppc_cached_irq_mask[0] |= (1 << irq));
  163. (void)mv64x60_read(&bh, MV64x60_GPP_INTR_MASK);
  164. return;
  165. }
  166. /* gt64260_mask_irq()
  167. *
  168. * This function disables the requested interrupt.
  169. *
  170. * Input Variable(s):
  171. * unsigned int interrupt number (IRQ0...IRQ95).
  172. *
  173. * Output Variable(s):
  174. * None.
  175. *
  176. * Returns:
  177. * void
  178. */
  179. static void
  180. gt64260_mask_irq(unsigned int irq)
  181. {
  182. irq -= gt64260_irq_base;
  183. if (irq > 31)
  184. if (irq > 63) /* mask GPP irq */
  185. mv64x60_write(&bh, MV64x60_GPP_INTR_MASK,
  186. ppc_cached_irq_mask[2] &= ~(1 << (irq - 64)));
  187. else /* mask high interrupt register */
  188. mv64x60_write(&bh, GT64260_IC_CPU_INTR_MASK_HI,
  189. ppc_cached_irq_mask[1] &= ~(1 << (irq - 32)));
  190. else /* mask low interrupt register */
  191. mv64x60_write(&bh, GT64260_IC_CPU_INTR_MASK_LO,
  192. ppc_cached_irq_mask[0] &= ~(1 << irq));
  193. (void)mv64x60_read(&bh, MV64x60_GPP_INTR_MASK);
  194. return;
  195. }
  196. static irqreturn_t
  197. gt64260_cpu_error_int_handler(int irq, void *dev_id)
  198. {
  199. printk(KERN_ERR "gt64260_cpu_error_int_handler: %s 0x%08x\n",
  200. "Error on CPU interface - Cause regiser",
  201. mv64x60_read(&bh, MV64x60_CPU_ERR_CAUSE));
  202. printk(KERN_ERR "\tCPU error register dump:\n");
  203. printk(KERN_ERR "\tAddress low 0x%08x\n",
  204. mv64x60_read(&bh, MV64x60_CPU_ERR_ADDR_LO));
  205. printk(KERN_ERR "\tAddress high 0x%08x\n",
  206. mv64x60_read(&bh, MV64x60_CPU_ERR_ADDR_HI));
  207. printk(KERN_ERR "\tData low 0x%08x\n",
  208. mv64x60_read(&bh, MV64x60_CPU_ERR_DATA_LO));
  209. printk(KERN_ERR "\tData high 0x%08x\n",
  210. mv64x60_read(&bh, MV64x60_CPU_ERR_DATA_HI));
  211. printk(KERN_ERR "\tParity 0x%08x\n",
  212. mv64x60_read(&bh, MV64x60_CPU_ERR_PARITY));
  213. mv64x60_write(&bh, MV64x60_CPU_ERR_CAUSE, 0);
  214. return IRQ_HANDLED;
  215. }
  216. static irqreturn_t
  217. gt64260_pci_error_int_handler(int irq, void *dev_id)
  218. {
  219. u32 val;
  220. unsigned int pci_bus = (unsigned int)dev_id;
  221. if (pci_bus == 0) { /* Error on PCI 0 */
  222. val = mv64x60_read(&bh, MV64x60_PCI0_ERR_CAUSE);
  223. printk(KERN_ERR "%s: Error in PCI %d Interface\n",
  224. "gt64260_pci_error_int_handler", pci_bus);
  225. printk(KERN_ERR "\tPCI %d error register dump:\n", pci_bus);
  226. printk(KERN_ERR "\tCause register 0x%08x\n", val);
  227. printk(KERN_ERR "\tAddress Low 0x%08x\n",
  228. mv64x60_read(&bh, MV64x60_PCI0_ERR_ADDR_LO));
  229. printk(KERN_ERR "\tAddress High 0x%08x\n",
  230. mv64x60_read(&bh, MV64x60_PCI0_ERR_ADDR_HI));
  231. printk(KERN_ERR "\tAttribute 0x%08x\n",
  232. mv64x60_read(&bh, MV64x60_PCI0_ERR_DATA_LO));
  233. printk(KERN_ERR "\tCommand 0x%08x\n",
  234. mv64x60_read(&bh, MV64x60_PCI0_ERR_CMD));
  235. mv64x60_write(&bh, MV64x60_PCI0_ERR_CAUSE, ~val);
  236. }
  237. if (pci_bus == 1) { /* Error on PCI 1 */
  238. val = mv64x60_read(&bh, MV64x60_PCI1_ERR_CAUSE);
  239. printk(KERN_ERR "%s: Error in PCI %d Interface\n",
  240. "gt64260_pci_error_int_handler", pci_bus);
  241. printk(KERN_ERR "\tPCI %d error register dump:\n", pci_bus);
  242. printk(KERN_ERR "\tCause register 0x%08x\n", val);
  243. printk(KERN_ERR "\tAddress Low 0x%08x\n",
  244. mv64x60_read(&bh, MV64x60_PCI1_ERR_ADDR_LO));
  245. printk(KERN_ERR "\tAddress High 0x%08x\n",
  246. mv64x60_read(&bh, MV64x60_PCI1_ERR_ADDR_HI));
  247. printk(KERN_ERR "\tAttribute 0x%08x\n",
  248. mv64x60_read(&bh, MV64x60_PCI1_ERR_DATA_LO));
  249. printk(KERN_ERR "\tCommand 0x%08x\n",
  250. mv64x60_read(&bh, MV64x60_PCI1_ERR_CMD));
  251. mv64x60_write(&bh, MV64x60_PCI1_ERR_CAUSE, ~val);
  252. }
  253. return IRQ_HANDLED;
  254. }
  255. static int __init
  256. gt64260_register_hdlrs(void)
  257. {
  258. int rc;
  259. /* Register CPU interface error interrupt handler */
  260. if ((rc = request_irq(MV64x60_IRQ_CPU_ERR,
  261. gt64260_cpu_error_int_handler, IRQF_DISABLED, CPU_INTR_STR, 0)))
  262. printk(KERN_WARNING "Can't register cpu error handler: %d", rc);
  263. mv64x60_write(&bh, MV64x60_CPU_ERR_MASK, 0);
  264. mv64x60_write(&bh, MV64x60_CPU_ERR_MASK, 0x000000fe);
  265. /* Register PCI 0 error interrupt handler */
  266. if ((rc = request_irq(MV64360_IRQ_PCI0, gt64260_pci_error_int_handler,
  267. IRQF_DISABLED, PCI0_INTR_STR, (void *)0)))
  268. printk(KERN_WARNING "Can't register pci 0 error handler: %d",
  269. rc);
  270. mv64x60_write(&bh, MV64x60_PCI0_ERR_MASK, 0);
  271. mv64x60_write(&bh, MV64x60_PCI0_ERR_MASK, 0x003c0c24);
  272. /* Register PCI 1 error interrupt handler */
  273. if ((rc = request_irq(MV64360_IRQ_PCI1, gt64260_pci_error_int_handler,
  274. IRQF_DISABLED, PCI1_INTR_STR, (void *)1)))
  275. printk(KERN_WARNING "Can't register pci 1 error handler: %d",
  276. rc);
  277. mv64x60_write(&bh, MV64x60_PCI1_ERR_MASK, 0);
  278. mv64x60_write(&bh, MV64x60_PCI1_ERR_MASK, 0x003c0c24);
  279. return 0;
  280. }
  281. arch_initcall(gt64260_register_hdlrs);