ppc4xx_pic.c 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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. /* See comment in include/arch-ppc/ppc4xx_pic.h
  28. * for more info about these two variables
  29. */
  30. extern struct ppc4xx_uic_settings ppc4xx_core_uic_cfg[NR_UICS]
  31. __attribute__ ((weak));
  32. extern unsigned char ppc4xx_uic_ext_irq_cfg[] __attribute__ ((weak));
  33. #define IRQ_MASK_UIC0(irq) (1 << (31 - (irq)))
  34. #define IRQ_MASK_UICx(irq) (1 << (31 - ((irq) & 0x1f)))
  35. #define IRQ_MASK_UIC1(irq) IRQ_MASK_UICx(irq)
  36. #define IRQ_MASK_UIC2(irq) IRQ_MASK_UICx(irq)
  37. #define UIC_HANDLERS(n) \
  38. static void ppc4xx_uic##n##_enable(unsigned int irq) \
  39. { \
  40. u32 mask = IRQ_MASK_UIC##n(irq); \
  41. if (irq_desc[irq].status & IRQ_LEVEL) \
  42. mtdcr(DCRN_UIC_SR(UIC##n), mask); \
  43. ppc_cached_irq_mask[n] |= mask; \
  44. mtdcr(DCRN_UIC_ER(UIC##n), ppc_cached_irq_mask[n]); \
  45. } \
  46. \
  47. static void ppc4xx_uic##n##_disable(unsigned int irq) \
  48. { \
  49. ppc_cached_irq_mask[n] &= ~IRQ_MASK_UIC##n(irq); \
  50. mtdcr(DCRN_UIC_ER(UIC##n), ppc_cached_irq_mask[n]); \
  51. ACK_UIC##n##_PARENT \
  52. } \
  53. \
  54. static void ppc4xx_uic##n##_ack(unsigned int irq) \
  55. { \
  56. u32 mask = IRQ_MASK_UIC##n(irq); \
  57. ppc_cached_irq_mask[n] &= ~mask; \
  58. mtdcr(DCRN_UIC_ER(UIC##n), ppc_cached_irq_mask[n]); \
  59. mtdcr(DCRN_UIC_SR(UIC##n), mask); \
  60. ACK_UIC##n##_PARENT \
  61. } \
  62. \
  63. static void ppc4xx_uic##n##_end(unsigned int irq) \
  64. { \
  65. unsigned int status = irq_desc[irq].status; \
  66. u32 mask = IRQ_MASK_UIC##n(irq); \
  67. if (status & IRQ_LEVEL) { \
  68. mtdcr(DCRN_UIC_SR(UIC##n), mask); \
  69. ACK_UIC##n##_PARENT \
  70. } \
  71. if (!(status & (IRQ_DISABLED | IRQ_INPROGRESS))) { \
  72. ppc_cached_irq_mask[n] |= mask; \
  73. mtdcr(DCRN_UIC_ER(UIC##n), ppc_cached_irq_mask[n]); \
  74. } \
  75. }
  76. #define DECLARE_UIC(n) \
  77. { \
  78. .typename = "UIC"#n, \
  79. .enable = ppc4xx_uic##n##_enable, \
  80. .disable = ppc4xx_uic##n##_disable, \
  81. .ack = ppc4xx_uic##n##_ack, \
  82. .end = ppc4xx_uic##n##_end, \
  83. } \
  84. #if NR_UICS == 3
  85. #define ACK_UIC0_PARENT mtdcr(DCRN_UIC_SR(UICB), UICB_UIC0NC);
  86. #define ACK_UIC1_PARENT mtdcr(DCRN_UIC_SR(UICB), UICB_UIC1NC);
  87. #define ACK_UIC2_PARENT mtdcr(DCRN_UIC_SR(UICB), UICB_UIC2NC);
  88. UIC_HANDLERS(0);
  89. UIC_HANDLERS(1);
  90. UIC_HANDLERS(2);
  91. static int ppc4xx_pic_get_irq(struct pt_regs *regs)
  92. {
  93. u32 uicb = mfdcr(DCRN_UIC_MSR(UICB));
  94. if (uicb & UICB_UIC0NC)
  95. return 32 - ffs(mfdcr(DCRN_UIC_MSR(UIC0)));
  96. else if (uicb & UICB_UIC1NC)
  97. return 64 - ffs(mfdcr(DCRN_UIC_MSR(UIC1)));
  98. else if (uicb & UICB_UIC2NC)
  99. return 96 - ffs(mfdcr(DCRN_UIC_MSR(UIC2)));
  100. else
  101. return -1;
  102. }
  103. static void __init ppc4xx_pic_impl_init(void)
  104. {
  105. #if defined(CONFIG_440GX)
  106. /* Disable 440GP compatibility mode if it was enabled in firmware */
  107. SDR_WRITE(DCRN_SDR_MFR, SDR_READ(DCRN_SDR_MFR) & ~DCRN_SDR_MFR_PCM);
  108. #endif
  109. /* Configure Base UIC */
  110. mtdcr(DCRN_UIC_CR(UICB), 0);
  111. mtdcr(DCRN_UIC_TR(UICB), 0);
  112. mtdcr(DCRN_UIC_PR(UICB), 0xffffffff);
  113. mtdcr(DCRN_UIC_SR(UICB), 0xffffffff);
  114. mtdcr(DCRN_UIC_ER(UICB), UICB_UIC0NC | UICB_UIC1NC | UICB_UIC2NC);
  115. }
  116. #elif NR_UICS == 2
  117. #define ACK_UIC0_PARENT
  118. #define ACK_UIC1_PARENT mtdcr(DCRN_UIC_SR(UIC0), UIC0_UIC1NC);
  119. UIC_HANDLERS(0);
  120. UIC_HANDLERS(1);
  121. static int ppc4xx_pic_get_irq(struct pt_regs *regs)
  122. {
  123. u32 uic0 = mfdcr(DCRN_UIC_MSR(UIC0));
  124. if (uic0 & UIC0_UIC1NC)
  125. return 64 - ffs(mfdcr(DCRN_UIC_MSR(UIC1)));
  126. else
  127. return uic0 ? 32 - ffs(uic0) : -1;
  128. }
  129. static void __init ppc4xx_pic_impl_init(void)
  130. {
  131. /* Enable cascade interrupt in UIC0 */
  132. ppc_cached_irq_mask[0] |= UIC0_UIC1NC;
  133. mtdcr(DCRN_UIC_SR(UIC0), UIC0_UIC1NC);
  134. mtdcr(DCRN_UIC_ER(UIC0), ppc_cached_irq_mask[0]);
  135. }
  136. #elif NR_UICS == 1
  137. #define ACK_UIC0_PARENT
  138. UIC_HANDLERS(0);
  139. static int ppc4xx_pic_get_irq(struct pt_regs *regs)
  140. {
  141. u32 uic0 = mfdcr(DCRN_UIC_MSR(UIC0));
  142. return uic0 ? 32 - ffs(uic0) : -1;
  143. }
  144. static inline void ppc4xx_pic_impl_init(void)
  145. {
  146. }
  147. #endif
  148. static struct ppc4xx_uic_impl {
  149. struct hw_interrupt_type decl;
  150. int base; /* Base DCR number */
  151. } __uic[] = {
  152. { .decl = DECLARE_UIC(0), .base = UIC0 },
  153. #if NR_UICS > 1
  154. { .decl = DECLARE_UIC(1), .base = UIC1 },
  155. #if NR_UICS > 2
  156. { .decl = DECLARE_UIC(2), .base = UIC2 },
  157. #endif
  158. #endif
  159. };
  160. static inline int is_level_sensitive(int irq)
  161. {
  162. u32 tr = mfdcr(DCRN_UIC_TR(__uic[irq >> 5].base));
  163. return (tr & IRQ_MASK_UICx(irq)) == 0;
  164. }
  165. void __init ppc4xx_pic_init(void)
  166. {
  167. int i;
  168. unsigned char *eirqs = ppc4xx_uic_ext_irq_cfg;
  169. for (i = 0; i < NR_UICS; ++i) {
  170. int base = __uic[i].base;
  171. /* Disable everything by default */
  172. ppc_cached_irq_mask[i] = 0;
  173. mtdcr(DCRN_UIC_ER(base), 0);
  174. /* We don't use critical interrupts */
  175. mtdcr(DCRN_UIC_CR(base), 0);
  176. /* Configure polarity and triggering */
  177. if (ppc4xx_core_uic_cfg) {
  178. struct ppc4xx_uic_settings *p = ppc4xx_core_uic_cfg + i;
  179. u32 mask = p->ext_irq_mask;
  180. u32 pr = mfdcr(DCRN_UIC_PR(base)) & mask;
  181. u32 tr = mfdcr(DCRN_UIC_TR(base)) & mask;
  182. /* "Fixed" interrupts (on-chip devices) */
  183. pr |= p->polarity & ~mask;
  184. tr |= p->triggering & ~mask;
  185. /* Merge external IRQs settings if board port
  186. * provided them
  187. */
  188. if (eirqs && mask) {
  189. pr &= ~mask;
  190. tr &= ~mask;
  191. while (mask) {
  192. /* Extract current external IRQ mask */
  193. u32 eirq_mask = 1 << __ilog2(mask);
  194. if (!(*eirqs & IRQ_SENSE_LEVEL))
  195. tr |= eirq_mask;
  196. if (*eirqs & IRQ_POLARITY_POSITIVE)
  197. pr |= eirq_mask;
  198. mask &= ~eirq_mask;
  199. ++eirqs;
  200. }
  201. }
  202. mtdcr(DCRN_UIC_PR(base), pr);
  203. mtdcr(DCRN_UIC_TR(base), tr);
  204. }
  205. /* ACK any pending interrupts to prevent false
  206. * triggering after first enable
  207. */
  208. mtdcr(DCRN_UIC_SR(base), 0xffffffff);
  209. }
  210. /* Perform optional implementation specific setup
  211. * (e.g. enable cascade interrupts for multi-UIC configurations)
  212. */
  213. ppc4xx_pic_impl_init();
  214. /* Attach low-level handlers */
  215. for (i = 0; i < (NR_UICS << 5); ++i) {
  216. irq_desc[i].handler = &__uic[i >> 5].decl;
  217. if (is_level_sensitive(i))
  218. irq_desc[i].status |= IRQ_LEVEL;
  219. }
  220. ppc_md.get_irq = ppc4xx_pic_get_irq;
  221. }