gt64260_pic.c 9.4 KB

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