gt64260_pic.c 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  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].handler = &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. * Input Variable(s):
  96. * struct pt_regs* not used
  97. *
  98. * Output Variable(s):
  99. * None.
  100. *
  101. * Returns:
  102. * int <interrupt number> or -2 (bogus interrupt)
  103. */
  104. int
  105. gt64260_get_irq(struct pt_regs *regs)
  106. {
  107. int irq;
  108. int irq_gpp;
  109. irq = mv64x60_read(&bh, GT64260_IC_MAIN_CAUSE_LO);
  110. irq = __ilog2((irq & 0x3dfffffe) & ppc_cached_irq_mask[0]);
  111. if (irq == -1) {
  112. irq = mv64x60_read(&bh, GT64260_IC_MAIN_CAUSE_HI);
  113. irq = __ilog2((irq & 0x0f000db7) & ppc_cached_irq_mask[1]);
  114. if (irq == -1)
  115. irq = -2; /* bogus interrupt, should never happen */
  116. else {
  117. if (irq >= 24) {
  118. irq_gpp = mv64x60_read(&bh,
  119. MV64x60_GPP_INTR_CAUSE);
  120. irq_gpp = __ilog2(irq_gpp &
  121. ppc_cached_irq_mask[2]);
  122. if (irq_gpp == -1)
  123. irq = -2;
  124. else {
  125. irq = irq_gpp + 64;
  126. mv64x60_write(&bh,
  127. MV64x60_GPP_INTR_CAUSE,
  128. ~(1 << (irq - 64)));
  129. }
  130. } else
  131. irq += 32;
  132. }
  133. }
  134. (void)mv64x60_read(&bh, MV64x60_GPP_INTR_CAUSE);
  135. if (irq < 0)
  136. return (irq);
  137. else
  138. return (gt64260_irq_base + irq);
  139. }
  140. /* gt64260_unmask_irq()
  141. *
  142. * This function enables an interrupt.
  143. *
  144. * Input Variable(s):
  145. * unsigned int interrupt number (IRQ0...IRQ95).
  146. *
  147. * Output Variable(s):
  148. * None.
  149. *
  150. * Returns:
  151. * void
  152. */
  153. static void
  154. gt64260_unmask_irq(unsigned int irq)
  155. {
  156. irq -= gt64260_irq_base;
  157. if (irq > 31)
  158. if (irq > 63) /* unmask GPP irq */
  159. mv64x60_write(&bh, MV64x60_GPP_INTR_MASK,
  160. ppc_cached_irq_mask[2] |= (1 << (irq - 64)));
  161. else /* mask high interrupt register */
  162. mv64x60_write(&bh, GT64260_IC_CPU_INTR_MASK_HI,
  163. ppc_cached_irq_mask[1] |= (1 << (irq - 32)));
  164. else /* mask low interrupt register */
  165. mv64x60_write(&bh, GT64260_IC_CPU_INTR_MASK_LO,
  166. ppc_cached_irq_mask[0] |= (1 << irq));
  167. (void)mv64x60_read(&bh, MV64x60_GPP_INTR_MASK);
  168. return;
  169. }
  170. /* gt64260_mask_irq()
  171. *
  172. * This function disables the requested interrupt.
  173. *
  174. * Input Variable(s):
  175. * unsigned int interrupt number (IRQ0...IRQ95).
  176. *
  177. * Output Variable(s):
  178. * None.
  179. *
  180. * Returns:
  181. * void
  182. */
  183. static void
  184. gt64260_mask_irq(unsigned int irq)
  185. {
  186. irq -= gt64260_irq_base;
  187. if (irq > 31)
  188. if (irq > 63) /* mask GPP irq */
  189. mv64x60_write(&bh, MV64x60_GPP_INTR_MASK,
  190. ppc_cached_irq_mask[2] &= ~(1 << (irq - 64)));
  191. else /* mask high interrupt register */
  192. mv64x60_write(&bh, GT64260_IC_CPU_INTR_MASK_HI,
  193. ppc_cached_irq_mask[1] &= ~(1 << (irq - 32)));
  194. else /* mask low interrupt register */
  195. mv64x60_write(&bh, GT64260_IC_CPU_INTR_MASK_LO,
  196. ppc_cached_irq_mask[0] &= ~(1 << irq));
  197. (void)mv64x60_read(&bh, MV64x60_GPP_INTR_MASK);
  198. return;
  199. }
  200. static irqreturn_t
  201. gt64260_cpu_error_int_handler(int irq, void *dev_id, struct pt_regs *regs)
  202. {
  203. printk(KERN_ERR "gt64260_cpu_error_int_handler: %s 0x%08x\n",
  204. "Error on CPU interface - Cause regiser",
  205. mv64x60_read(&bh, MV64x60_CPU_ERR_CAUSE));
  206. printk(KERN_ERR "\tCPU error register dump:\n");
  207. printk(KERN_ERR "\tAddress low 0x%08x\n",
  208. mv64x60_read(&bh, MV64x60_CPU_ERR_ADDR_LO));
  209. printk(KERN_ERR "\tAddress high 0x%08x\n",
  210. mv64x60_read(&bh, MV64x60_CPU_ERR_ADDR_HI));
  211. printk(KERN_ERR "\tData low 0x%08x\n",
  212. mv64x60_read(&bh, MV64x60_CPU_ERR_DATA_LO));
  213. printk(KERN_ERR "\tData high 0x%08x\n",
  214. mv64x60_read(&bh, MV64x60_CPU_ERR_DATA_HI));
  215. printk(KERN_ERR "\tParity 0x%08x\n",
  216. mv64x60_read(&bh, MV64x60_CPU_ERR_PARITY));
  217. mv64x60_write(&bh, MV64x60_CPU_ERR_CAUSE, 0);
  218. return IRQ_HANDLED;
  219. }
  220. static irqreturn_t
  221. gt64260_pci_error_int_handler(int irq, void *dev_id, struct pt_regs *regs)
  222. {
  223. u32 val;
  224. unsigned int pci_bus = (unsigned int)dev_id;
  225. if (pci_bus == 0) { /* Error on PCI 0 */
  226. val = mv64x60_read(&bh, MV64x60_PCI0_ERR_CAUSE);
  227. printk(KERN_ERR "%s: Error in PCI %d Interface\n",
  228. "gt64260_pci_error_int_handler", pci_bus);
  229. printk(KERN_ERR "\tPCI %d error register dump:\n", pci_bus);
  230. printk(KERN_ERR "\tCause register 0x%08x\n", val);
  231. printk(KERN_ERR "\tAddress Low 0x%08x\n",
  232. mv64x60_read(&bh, MV64x60_PCI0_ERR_ADDR_LO));
  233. printk(KERN_ERR "\tAddress High 0x%08x\n",
  234. mv64x60_read(&bh, MV64x60_PCI0_ERR_ADDR_HI));
  235. printk(KERN_ERR "\tAttribute 0x%08x\n",
  236. mv64x60_read(&bh, MV64x60_PCI0_ERR_DATA_LO));
  237. printk(KERN_ERR "\tCommand 0x%08x\n",
  238. mv64x60_read(&bh, MV64x60_PCI0_ERR_CMD));
  239. mv64x60_write(&bh, MV64x60_PCI0_ERR_CAUSE, ~val);
  240. }
  241. if (pci_bus == 1) { /* Error on PCI 1 */
  242. val = mv64x60_read(&bh, MV64x60_PCI1_ERR_CAUSE);
  243. printk(KERN_ERR "%s: Error in PCI %d Interface\n",
  244. "gt64260_pci_error_int_handler", pci_bus);
  245. printk(KERN_ERR "\tPCI %d error register dump:\n", pci_bus);
  246. printk(KERN_ERR "\tCause register 0x%08x\n", val);
  247. printk(KERN_ERR "\tAddress Low 0x%08x\n",
  248. mv64x60_read(&bh, MV64x60_PCI1_ERR_ADDR_LO));
  249. printk(KERN_ERR "\tAddress High 0x%08x\n",
  250. mv64x60_read(&bh, MV64x60_PCI1_ERR_ADDR_HI));
  251. printk(KERN_ERR "\tAttribute 0x%08x\n",
  252. mv64x60_read(&bh, MV64x60_PCI1_ERR_DATA_LO));
  253. printk(KERN_ERR "\tCommand 0x%08x\n",
  254. mv64x60_read(&bh, MV64x60_PCI1_ERR_CMD));
  255. mv64x60_write(&bh, MV64x60_PCI1_ERR_CAUSE, ~val);
  256. }
  257. return IRQ_HANDLED;
  258. }
  259. static int __init
  260. gt64260_register_hdlrs(void)
  261. {
  262. int rc;
  263. /* Register CPU interface error interrupt handler */
  264. if ((rc = request_irq(MV64x60_IRQ_CPU_ERR,
  265. gt64260_cpu_error_int_handler, SA_INTERRUPT, CPU_INTR_STR, 0)))
  266. printk(KERN_WARNING "Can't register cpu error handler: %d", rc);
  267. mv64x60_write(&bh, MV64x60_CPU_ERR_MASK, 0);
  268. mv64x60_write(&bh, MV64x60_CPU_ERR_MASK, 0x000000fe);
  269. /* Register PCI 0 error interrupt handler */
  270. if ((rc = request_irq(MV64360_IRQ_PCI0, gt64260_pci_error_int_handler,
  271. SA_INTERRUPT, PCI0_INTR_STR, (void *)0)))
  272. printk(KERN_WARNING "Can't register pci 0 error handler: %d",
  273. rc);
  274. mv64x60_write(&bh, MV64x60_PCI0_ERR_MASK, 0);
  275. mv64x60_write(&bh, MV64x60_PCI0_ERR_MASK, 0x003c0c24);
  276. /* Register PCI 1 error interrupt handler */
  277. if ((rc = request_irq(MV64360_IRQ_PCI1, gt64260_pci_error_int_handler,
  278. SA_INTERRUPT, PCI1_INTR_STR, (void *)1)))
  279. printk(KERN_WARNING "Can't register pci 1 error handler: %d",
  280. rc);
  281. mv64x60_write(&bh, MV64x60_PCI1_ERR_MASK, 0);
  282. mv64x60_write(&bh, MV64x60_PCI1_ERR_MASK, 0x003c0c24);
  283. return 0;
  284. }
  285. arch_initcall(gt64260_register_hdlrs);