ppc4xx_pic.c 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. /*
  2. * arch/ppc/syslib/ppc4xx_pic.c
  3. *
  4. * Interrupt controller driver for PowerPC 4xx-based processors.
  5. *
  6. * Eugene Surovegin <eugene.surovegin@zultys.com> or <ebs@ebshome.net>
  7. * Copyright (c) 2004, 2005 Zultys Technologies
  8. *
  9. * Based on original code by
  10. * Copyright (c) 1999 Grant Erickson <grant@lcse.umn.edu>
  11. * Armin Custer <akuster@mvista.com>
  12. *
  13. * This program is free software; you can redistribute it and/or modify it
  14. * under the terms of the GNU General Public License as published by the
  15. * Free Software Foundation; either version 2 of the License, or (at your
  16. * option) any later version.
  17. */
  18. #include <linux/config.h>
  19. #include <linux/init.h>
  20. #include <linux/sched.h>
  21. #include <linux/signal.h>
  22. #include <linux/stddef.h>
  23. #include <asm/processor.h>
  24. #include <asm/system.h>
  25. #include <asm/irq.h>
  26. #include <asm/ppc4xx_pic.h>
  27. #include <asm/machdep.h>
  28. /* See comment in include/arch-ppc/ppc4xx_pic.h
  29. * for more info about these two variables
  30. */
  31. extern struct ppc4xx_uic_settings ppc4xx_core_uic_cfg[NR_UICS]
  32. __attribute__ ((weak));
  33. extern unsigned char ppc4xx_uic_ext_irq_cfg[] __attribute__ ((weak));
  34. #define IRQ_MASK_UIC0(irq) (1 << (31 - (irq)))
  35. #define IRQ_MASK_UICx(irq) (1 << (31 - ((irq) & 0x1f)))
  36. #define IRQ_MASK_UIC1(irq) IRQ_MASK_UICx(irq)
  37. #define IRQ_MASK_UIC2(irq) IRQ_MASK_UICx(irq)
  38. #define UIC_HANDLERS(n) \
  39. static void ppc4xx_uic##n##_enable(unsigned int irq) \
  40. { \
  41. u32 mask = IRQ_MASK_UIC##n(irq); \
  42. if (irq_desc[irq].status & IRQ_LEVEL) \
  43. mtdcr(DCRN_UIC_SR(UIC##n), mask); \
  44. ppc_cached_irq_mask[n] |= mask; \
  45. mtdcr(DCRN_UIC_ER(UIC##n), ppc_cached_irq_mask[n]); \
  46. } \
  47. \
  48. static void ppc4xx_uic##n##_disable(unsigned int irq) \
  49. { \
  50. ppc_cached_irq_mask[n] &= ~IRQ_MASK_UIC##n(irq); \
  51. mtdcr(DCRN_UIC_ER(UIC##n), ppc_cached_irq_mask[n]); \
  52. ACK_UIC##n##_PARENT \
  53. } \
  54. \
  55. static void ppc4xx_uic##n##_ack(unsigned int irq) \
  56. { \
  57. u32 mask = IRQ_MASK_UIC##n(irq); \
  58. ppc_cached_irq_mask[n] &= ~mask; \
  59. mtdcr(DCRN_UIC_ER(UIC##n), ppc_cached_irq_mask[n]); \
  60. mtdcr(DCRN_UIC_SR(UIC##n), mask); \
  61. ACK_UIC##n##_PARENT \
  62. } \
  63. \
  64. static void ppc4xx_uic##n##_end(unsigned int irq) \
  65. { \
  66. unsigned int status = irq_desc[irq].status; \
  67. u32 mask = IRQ_MASK_UIC##n(irq); \
  68. if (status & IRQ_LEVEL) { \
  69. mtdcr(DCRN_UIC_SR(UIC##n), mask); \
  70. ACK_UIC##n##_PARENT \
  71. } \
  72. if (!(status & (IRQ_DISABLED | IRQ_INPROGRESS))) { \
  73. ppc_cached_irq_mask[n] |= mask; \
  74. mtdcr(DCRN_UIC_ER(UIC##n), ppc_cached_irq_mask[n]); \
  75. } \
  76. }
  77. #define DECLARE_UIC(n) \
  78. { \
  79. .typename = "UIC"#n, \
  80. .enable = ppc4xx_uic##n##_enable, \
  81. .disable = ppc4xx_uic##n##_disable, \
  82. .ack = ppc4xx_uic##n##_ack, \
  83. .end = ppc4xx_uic##n##_end, \
  84. } \
  85. #if NR_UICS == 3
  86. #define ACK_UIC0_PARENT mtdcr(DCRN_UIC_SR(UICB), UICB_UIC0NC);
  87. #define ACK_UIC1_PARENT mtdcr(DCRN_UIC_SR(UICB), UICB_UIC1NC);
  88. #define ACK_UIC2_PARENT mtdcr(DCRN_UIC_SR(UICB), UICB_UIC2NC);
  89. UIC_HANDLERS(0);
  90. UIC_HANDLERS(1);
  91. UIC_HANDLERS(2);
  92. static int ppc4xx_pic_get_irq(struct pt_regs *regs)
  93. {
  94. u32 uicb = mfdcr(DCRN_UIC_MSR(UICB));
  95. if (uicb & UICB_UIC0NC)
  96. return 32 - ffs(mfdcr(DCRN_UIC_MSR(UIC0)));
  97. else if (uicb & UICB_UIC1NC)
  98. return 64 - ffs(mfdcr(DCRN_UIC_MSR(UIC1)));
  99. else if (uicb & UICB_UIC2NC)
  100. return 96 - ffs(mfdcr(DCRN_UIC_MSR(UIC2)));
  101. else
  102. return -1;
  103. }
  104. static void __init ppc4xx_pic_impl_init(void)
  105. {
  106. #if defined(CONFIG_440GX)
  107. /* Disable 440GP compatibility mode if it was enabled in firmware */
  108. SDR_WRITE(DCRN_SDR_MFR, SDR_READ(DCRN_SDR_MFR) & ~DCRN_SDR_MFR_PCM);
  109. #endif
  110. /* Configure Base UIC */
  111. mtdcr(DCRN_UIC_CR(UICB), 0);
  112. mtdcr(DCRN_UIC_TR(UICB), 0);
  113. mtdcr(DCRN_UIC_PR(UICB), 0xffffffff);
  114. mtdcr(DCRN_UIC_SR(UICB), 0xffffffff);
  115. mtdcr(DCRN_UIC_ER(UICB), UICB_UIC0NC | UICB_UIC1NC | UICB_UIC2NC);
  116. }
  117. #elif NR_UICS == 2
  118. #define ACK_UIC0_PARENT
  119. #define ACK_UIC1_PARENT mtdcr(DCRN_UIC_SR(UIC0), UIC0_UIC1NC);
  120. UIC_HANDLERS(0);
  121. UIC_HANDLERS(1);
  122. static int ppc4xx_pic_get_irq(struct pt_regs *regs)
  123. {
  124. u32 uic0 = mfdcr(DCRN_UIC_MSR(UIC0));
  125. if (uic0 & UIC0_UIC1NC)
  126. return 64 - ffs(mfdcr(DCRN_UIC_MSR(UIC1)));
  127. else
  128. return uic0 ? 32 - ffs(uic0) : -1;
  129. }
  130. static void __init ppc4xx_pic_impl_init(void)
  131. {
  132. /* Enable cascade interrupt in UIC0 */
  133. ppc_cached_irq_mask[0] |= UIC0_UIC1NC;
  134. mtdcr(DCRN_UIC_SR(UIC0), UIC0_UIC1NC);
  135. mtdcr(DCRN_UIC_ER(UIC0), ppc_cached_irq_mask[0]);
  136. }
  137. #elif NR_UICS == 1
  138. #define ACK_UIC0_PARENT
  139. UIC_HANDLERS(0);
  140. static int ppc4xx_pic_get_irq(struct pt_regs *regs)
  141. {
  142. u32 uic0 = mfdcr(DCRN_UIC_MSR(UIC0));
  143. return uic0 ? 32 - ffs(uic0) : -1;
  144. }
  145. static inline void ppc4xx_pic_impl_init(void)
  146. {
  147. }
  148. #endif
  149. static struct ppc4xx_uic_impl {
  150. struct hw_interrupt_type decl;
  151. int base; /* Base DCR number */
  152. } __uic[] = {
  153. { .decl = DECLARE_UIC(0), .base = UIC0 },
  154. #if NR_UICS > 1
  155. { .decl = DECLARE_UIC(1), .base = UIC1 },
  156. #if NR_UICS > 2
  157. { .decl = DECLARE_UIC(2), .base = UIC2 },
  158. #endif
  159. #endif
  160. };
  161. static inline int is_level_sensitive(int irq)
  162. {
  163. u32 tr = mfdcr(DCRN_UIC_TR(__uic[irq >> 5].base));
  164. return (tr & IRQ_MASK_UICx(irq)) == 0;
  165. }
  166. void __init ppc4xx_pic_init(void)
  167. {
  168. int i;
  169. unsigned char *eirqs = ppc4xx_uic_ext_irq_cfg;
  170. for (i = 0; i < NR_UICS; ++i) {
  171. int base = __uic[i].base;
  172. /* Disable everything by default */
  173. ppc_cached_irq_mask[i] = 0;
  174. mtdcr(DCRN_UIC_ER(base), 0);
  175. /* We don't use critical interrupts */
  176. mtdcr(DCRN_UIC_CR(base), 0);
  177. /* Configure polarity and triggering */
  178. if (ppc4xx_core_uic_cfg) {
  179. struct ppc4xx_uic_settings *p = ppc4xx_core_uic_cfg + i;
  180. u32 mask = p->ext_irq_mask;
  181. u32 pr = mfdcr(DCRN_UIC_PR(base)) & mask;
  182. u32 tr = mfdcr(DCRN_UIC_TR(base)) & mask;
  183. /* "Fixed" interrupts (on-chip devices) */
  184. pr |= p->polarity & ~mask;
  185. tr |= p->triggering & ~mask;
  186. /* Merge external IRQs settings if board port
  187. * provided them
  188. */
  189. if (eirqs && mask) {
  190. pr &= ~mask;
  191. tr &= ~mask;
  192. while (mask) {
  193. /* Extract current external IRQ mask */
  194. u32 eirq_mask = 1 << __ilog2(mask);
  195. if (!(*eirqs & IRQ_SENSE_LEVEL))
  196. tr |= eirq_mask;
  197. if (*eirqs & IRQ_POLARITY_POSITIVE)
  198. pr |= eirq_mask;
  199. mask &= ~eirq_mask;
  200. ++eirqs;
  201. }
  202. }
  203. mtdcr(DCRN_UIC_PR(base), pr);
  204. mtdcr(DCRN_UIC_TR(base), tr);
  205. }
  206. /* ACK any pending interrupts to prevent false
  207. * triggering after first enable
  208. */
  209. mtdcr(DCRN_UIC_SR(base), 0xffffffff);
  210. }
  211. /* Perform optional implementation specific setup
  212. * (e.g. enable cascade interrupts for multi-UIC configurations)
  213. */
  214. ppc4xx_pic_impl_init();
  215. /* Attach low-level handlers */
  216. for (i = 0; i < (NR_UICS << 5); ++i) {
  217. irq_desc[i].handler = &__uic[i >> 5].decl;
  218. if (is_level_sensitive(i))
  219. irq_desc[i].status |= IRQ_LEVEL;
  220. }
  221. ppc_md.get_irq = ppc4xx_pic_get_irq;
  222. }