cpm2_pic.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. /*
  2. * Platform information definitions.
  3. *
  4. * Copied from arch/ppc/syslib/cpm2_pic.c with minor subsequent updates
  5. * to make in work in arch/powerpc/. Original (c) belongs to Dan Malek.
  6. *
  7. * Author: Vitaly Bordug <vbordug@ru.mvista.com>
  8. *
  9. * 1999-2001 (c) Dan Malek <dan@embeddedalley.com>
  10. * 2006 (c) MontaVista Software, Inc.
  11. *
  12. * This file is licensed under the terms of the GNU General Public License
  13. * version 2. This program is licensed "as is" without any warranty of any
  14. * kind, whether express or implied.
  15. */
  16. /* The CPM2 internal interrupt controller. It is usually
  17. * the only interrupt controller.
  18. * There are two 32-bit registers (high/low) for up to 64
  19. * possible interrupts.
  20. *
  21. * Now, the fun starts.....Interrupt Numbers DO NOT MAP
  22. * in a simple arithmetic fashion to mask or pending registers.
  23. * That is, interrupt 4 does not map to bit position 4.
  24. * We create two tables, indexed by vector number, to indicate
  25. * which register to use and which bit in the register to use.
  26. */
  27. #include <linux/stddef.h>
  28. #include <linux/init.h>
  29. #include <linux/sched.h>
  30. #include <linux/signal.h>
  31. #include <linux/irq.h>
  32. #include <asm/immap_cpm2.h>
  33. #include <asm/mpc8260.h>
  34. #include <asm/io.h>
  35. #include <asm/prom.h>
  36. #include "cpm2_pic.h"
  37. static struct device_node *cpm2_pic_node;
  38. static struct irq_host *cpm2_pic_host;
  39. #define NR_MASK_WORDS ((NR_IRQS + 31) / 32)
  40. static unsigned long ppc_cached_irq_mask[NR_MASK_WORDS];
  41. static const u_char irq_to_siureg[] = {
  42. 1, 1, 1, 1, 1, 1, 1, 1,
  43. 1, 1, 1, 1, 1, 1, 1, 1,
  44. 0, 0, 0, 0, 0, 0, 0, 0,
  45. 0, 0, 0, 0, 0, 0, 0, 0,
  46. 1, 1, 1, 1, 1, 1, 1, 1,
  47. 1, 1, 1, 1, 1, 1, 1, 1,
  48. 0, 0, 0, 0, 0, 0, 0, 0,
  49. 0, 0, 0, 0, 0, 0, 0, 0
  50. };
  51. /* bit numbers do not match the docs, these are precomputed so the bit for
  52. * a given irq is (1 << irq_to_siubit[irq]) */
  53. static const u_char irq_to_siubit[] = {
  54. 0, 15, 14, 13, 12, 11, 10, 9,
  55. 8, 7, 6, 5, 4, 3, 2, 1,
  56. 2, 1, 0, 14, 13, 12, 11, 10,
  57. 9, 8, 7, 6, 5, 4, 3, 0,
  58. 31, 30, 29, 28, 27, 26, 25, 24,
  59. 23, 22, 21, 20, 19, 18, 17, 16,
  60. 16, 17, 18, 19, 20, 21, 22, 23,
  61. 24, 25, 26, 27, 28, 29, 30, 31,
  62. };
  63. static void cpm2_mask_irq(unsigned int irq_nr)
  64. {
  65. int bit, word;
  66. volatile uint *simr;
  67. irq_nr -= CPM_IRQ_OFFSET;
  68. bit = irq_to_siubit[irq_nr];
  69. word = irq_to_siureg[irq_nr];
  70. simr = &(cpm2_intctl->ic_simrh);
  71. ppc_cached_irq_mask[word] &= ~(1 << bit);
  72. simr[word] = ppc_cached_irq_mask[word];
  73. }
  74. static void cpm2_unmask_irq(unsigned int irq_nr)
  75. {
  76. int bit, word;
  77. volatile uint *simr;
  78. irq_nr -= CPM_IRQ_OFFSET;
  79. bit = irq_to_siubit[irq_nr];
  80. word = irq_to_siureg[irq_nr];
  81. simr = &(cpm2_intctl->ic_simrh);
  82. ppc_cached_irq_mask[word] |= 1 << bit;
  83. simr[word] = ppc_cached_irq_mask[word];
  84. }
  85. static void cpm2_mask_and_ack(unsigned int irq_nr)
  86. {
  87. int bit, word;
  88. volatile uint *simr, *sipnr;
  89. irq_nr -= CPM_IRQ_OFFSET;
  90. bit = irq_to_siubit[irq_nr];
  91. word = irq_to_siureg[irq_nr];
  92. simr = &(cpm2_intctl->ic_simrh);
  93. sipnr = &(cpm2_intctl->ic_sipnrh);
  94. ppc_cached_irq_mask[word] &= ~(1 << bit);
  95. simr[word] = ppc_cached_irq_mask[word];
  96. sipnr[word] = 1 << bit;
  97. }
  98. static void cpm2_end_irq(unsigned int irq_nr)
  99. {
  100. int bit, word;
  101. volatile uint *simr;
  102. if (!(irq_desc[irq_nr].status & (IRQ_DISABLED|IRQ_INPROGRESS))
  103. && irq_desc[irq_nr].action) {
  104. irq_nr -= CPM_IRQ_OFFSET;
  105. bit = irq_to_siubit[irq_nr];
  106. word = irq_to_siureg[irq_nr];
  107. simr = &(cpm2_intctl->ic_simrh);
  108. ppc_cached_irq_mask[word] |= 1 << bit;
  109. simr[word] = ppc_cached_irq_mask[word];
  110. /*
  111. * Work around large numbers of spurious IRQs on PowerPC 82xx
  112. * systems.
  113. */
  114. mb();
  115. }
  116. }
  117. static struct irq_chip cpm2_pic = {
  118. .typename = " CPM2 SIU ",
  119. .enable = cpm2_unmask_irq,
  120. .disable = cpm2_mask_irq,
  121. .unmask = cpm2_unmask_irq,
  122. .mask_ack = cpm2_mask_and_ack,
  123. .end = cpm2_end_irq,
  124. };
  125. unsigned int cpm2_get_irq(void)
  126. {
  127. int irq;
  128. unsigned long bits;
  129. /* For CPM2, read the SIVEC register and shift the bits down
  130. * to get the irq number. */
  131. bits = cpm2_intctl->ic_sivec;
  132. irq = bits >> 26;
  133. if (irq == 0)
  134. return(-1);
  135. return irq+CPM_IRQ_OFFSET;
  136. }
  137. static int cpm2_pic_host_match(struct irq_host *h, struct device_node *node)
  138. {
  139. return cpm2_pic_node == NULL || cpm2_pic_node == node;
  140. }
  141. static int cpm2_pic_host_map(struct irq_host *h, unsigned int virq,
  142. irq_hw_number_t hw)
  143. {
  144. pr_debug("cpm2_pic_host_map(%d, 0x%lx)\n", virq, hw);
  145. get_irq_desc(virq)->status |= IRQ_LEVEL;
  146. set_irq_chip_and_handler(virq, &cpm2_pic, handle_level_irq);
  147. return 0;
  148. }
  149. static void cpm2_host_unmap(struct irq_host *h, unsigned int virq)
  150. {
  151. /* Make sure irq is masked in hardware */
  152. cpm2_mask_irq(virq);
  153. /* remove chip and handler */
  154. set_irq_chip_and_handler(virq, NULL, NULL);
  155. }
  156. static int cpm2_pic_host_xlate(struct irq_host *h, struct device_node *ct,
  157. u32 *intspec, unsigned int intsize,
  158. irq_hw_number_t *out_hwirq, unsigned int *out_flags)
  159. {
  160. static const unsigned char map_cpm2_senses[4] = {
  161. IRQ_TYPE_LEVEL_LOW,
  162. IRQ_TYPE_LEVEL_HIGH,
  163. IRQ_TYPE_EDGE_FALLING,
  164. IRQ_TYPE_EDGE_RISING,
  165. };
  166. *out_hwirq = intspec[0];
  167. if (intsize > 1 && intspec[1] < 4)
  168. *out_flags = map_cpm2_senses[intspec[1]];
  169. else
  170. *out_flags = IRQ_TYPE_NONE;
  171. return 0;
  172. }
  173. static struct irq_host_ops cpm2_pic_host_ops = {
  174. .match = cpm2_pic_host_match,
  175. .map = cpm2_pic_host_map,
  176. .unmap = cpm2_host_unmap,
  177. .xlate = cpm2_pic_host_xlate,
  178. };
  179. void cpm2_pic_init(struct device_node *node)
  180. {
  181. int i;
  182. /* Clear the CPM IRQ controller, in case it has any bits set
  183. * from the bootloader
  184. */
  185. /* Mask out everything */
  186. cpm2_intctl->ic_simrh = 0x00000000;
  187. cpm2_intctl->ic_simrl = 0x00000000;
  188. wmb();
  189. /* Ack everything */
  190. cpm2_intctl->ic_sipnrh = 0xffffffff;
  191. cpm2_intctl->ic_sipnrl = 0xffffffff;
  192. wmb();
  193. /* Dummy read of the vector */
  194. i = cpm2_intctl->ic_sivec;
  195. rmb();
  196. /* Initialize the default interrupt mapping priorities,
  197. * in case the boot rom changed something on us.
  198. */
  199. cpm2_intctl->ic_sicr = 0;
  200. cpm2_intctl->ic_scprrh = 0x05309770;
  201. cpm2_intctl->ic_scprrl = 0x05309770;
  202. /* create a legacy host */
  203. if (node)
  204. cpm2_pic_node = of_node_get(node);
  205. cpm2_pic_host = irq_alloc_host(IRQ_HOST_MAP_LINEAR, 64, &cpm2_pic_host_ops, 64);
  206. if (cpm2_pic_host == NULL) {
  207. printk(KERN_ERR "CPM2 PIC: failed to allocate irq host!\n");
  208. return;
  209. }
  210. }