ppc4xx_pic.c 7.6 KB

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