gt64260_pic.c 9.3 KB

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