ppc4xx_pic.c 7.7 KB

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