cpm2_pic.c 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  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 <asm/fs_pd.h>
  37. #include "cpm2_pic.h"
  38. /* External IRQS */
  39. #define CPM2_IRQ_EXT1 19
  40. #define CPM2_IRQ_EXT7 25
  41. /* Port C IRQS */
  42. #define CPM2_IRQ_PORTC15 48
  43. #define CPM2_IRQ_PORTC0 63
  44. static intctl_cpm2_t __iomem *cpm2_intctl;
  45. static struct irq_host *cpm2_pic_host;
  46. #define NR_MASK_WORDS ((NR_IRQS + 31) / 32)
  47. static unsigned long ppc_cached_irq_mask[NR_MASK_WORDS];
  48. static const u_char irq_to_siureg[] = {
  49. 1, 1, 1, 1, 1, 1, 1, 1,
  50. 1, 1, 1, 1, 1, 1, 1, 1,
  51. 0, 0, 0, 0, 0, 0, 0, 0,
  52. 0, 0, 0, 0, 0, 0, 0, 0,
  53. 1, 1, 1, 1, 1, 1, 1, 1,
  54. 1, 1, 1, 1, 1, 1, 1, 1,
  55. 0, 0, 0, 0, 0, 0, 0, 0,
  56. 0, 0, 0, 0, 0, 0, 0, 0
  57. };
  58. /* bit numbers do not match the docs, these are precomputed so the bit for
  59. * a given irq is (1 << irq_to_siubit[irq]) */
  60. static const u_char irq_to_siubit[] = {
  61. 0, 15, 14, 13, 12, 11, 10, 9,
  62. 8, 7, 6, 5, 4, 3, 2, 1,
  63. 2, 1, 0, 14, 13, 12, 11, 10,
  64. 9, 8, 7, 6, 5, 4, 3, 0,
  65. 31, 30, 29, 28, 27, 26, 25, 24,
  66. 23, 22, 21, 20, 19, 18, 17, 16,
  67. 16, 17, 18, 19, 20, 21, 22, 23,
  68. 24, 25, 26, 27, 28, 29, 30, 31,
  69. };
  70. static void cpm2_mask_irq(unsigned int virq)
  71. {
  72. int bit, word;
  73. unsigned int irq_nr = virq_to_hw(virq);
  74. bit = irq_to_siubit[irq_nr];
  75. word = irq_to_siureg[irq_nr];
  76. ppc_cached_irq_mask[word] &= ~(1 << bit);
  77. out_be32(&cpm2_intctl->ic_simrh + word, ppc_cached_irq_mask[word]);
  78. }
  79. static void cpm2_unmask_irq(unsigned int virq)
  80. {
  81. int bit, word;
  82. unsigned int irq_nr = virq_to_hw(virq);
  83. bit = irq_to_siubit[irq_nr];
  84. word = irq_to_siureg[irq_nr];
  85. ppc_cached_irq_mask[word] |= 1 << bit;
  86. out_be32(&cpm2_intctl->ic_simrh + word, ppc_cached_irq_mask[word]);
  87. }
  88. static void cpm2_ack(unsigned int virq)
  89. {
  90. int bit, word;
  91. unsigned int irq_nr = virq_to_hw(virq);
  92. bit = irq_to_siubit[irq_nr];
  93. word = irq_to_siureg[irq_nr];
  94. out_be32(&cpm2_intctl->ic_sipnrh + word, 1 << bit);
  95. }
  96. static void cpm2_end_irq(unsigned int virq)
  97. {
  98. int bit, word;
  99. unsigned int irq_nr = virq_to_hw(virq);
  100. if (!(irq_desc[irq_nr].status & (IRQ_DISABLED|IRQ_INPROGRESS))
  101. && irq_desc[irq_nr].action) {
  102. bit = irq_to_siubit[irq_nr];
  103. word = irq_to_siureg[irq_nr];
  104. ppc_cached_irq_mask[word] |= 1 << bit;
  105. out_be32(&cpm2_intctl->ic_simrh + word, ppc_cached_irq_mask[word]);
  106. /*
  107. * Work around large numbers of spurious IRQs on PowerPC 82xx
  108. * systems.
  109. */
  110. mb();
  111. }
  112. }
  113. static int cpm2_set_irq_type(unsigned int virq, unsigned int flow_type)
  114. {
  115. unsigned int src = virq_to_hw(virq);
  116. struct irq_desc *desc = get_irq_desc(virq);
  117. unsigned int vold, vnew, edibit;
  118. if (flow_type == IRQ_TYPE_NONE)
  119. flow_type = IRQ_TYPE_LEVEL_LOW;
  120. if (flow_type & IRQ_TYPE_EDGE_RISING) {
  121. printk(KERN_ERR "CPM2 PIC: sense type 0x%x not supported\n",
  122. flow_type);
  123. return -EINVAL;
  124. }
  125. desc->status &= ~(IRQ_TYPE_SENSE_MASK | IRQ_LEVEL);
  126. desc->status |= flow_type & IRQ_TYPE_SENSE_MASK;
  127. if (flow_type & IRQ_TYPE_LEVEL_LOW) {
  128. desc->status |= IRQ_LEVEL;
  129. desc->handle_irq = handle_level_irq;
  130. } else
  131. desc->handle_irq = handle_edge_irq;
  132. /* internal IRQ senses are LEVEL_LOW
  133. * EXT IRQ and Port C IRQ senses are programmable
  134. */
  135. if (src >= CPM2_IRQ_EXT1 && src <= CPM2_IRQ_EXT7)
  136. edibit = (14 - (src - CPM2_IRQ_EXT1));
  137. else
  138. if (src >= CPM2_IRQ_PORTC15 && src <= CPM2_IRQ_PORTC0)
  139. edibit = (31 - (CPM2_IRQ_PORTC0 - src));
  140. else
  141. return (flow_type & IRQ_TYPE_LEVEL_LOW) ? 0 : -EINVAL;
  142. vold = in_be32(&cpm2_intctl->ic_siexr);
  143. if ((flow_type & IRQ_TYPE_SENSE_MASK) == IRQ_TYPE_EDGE_FALLING)
  144. vnew = vold | (1 << edibit);
  145. else
  146. vnew = vold & ~(1 << edibit);
  147. if (vold != vnew)
  148. out_be32(&cpm2_intctl->ic_siexr, vnew);
  149. return 0;
  150. }
  151. static struct irq_chip cpm2_pic = {
  152. .typename = " CPM2 SIU ",
  153. .mask = cpm2_mask_irq,
  154. .unmask = cpm2_unmask_irq,
  155. .ack = cpm2_ack,
  156. .eoi = cpm2_end_irq,
  157. .set_type = cpm2_set_irq_type,
  158. };
  159. unsigned int cpm2_get_irq(void)
  160. {
  161. int irq;
  162. unsigned long bits;
  163. /* For CPM2, read the SIVEC register and shift the bits down
  164. * to get the irq number. */
  165. bits = in_be32(&cpm2_intctl->ic_sivec);
  166. irq = bits >> 26;
  167. if (irq == 0)
  168. return(-1);
  169. return irq_linear_revmap(cpm2_pic_host, irq);
  170. }
  171. static int cpm2_pic_host_map(struct irq_host *h, unsigned int virq,
  172. irq_hw_number_t hw)
  173. {
  174. pr_debug("cpm2_pic_host_map(%d, 0x%lx)\n", virq, hw);
  175. get_irq_desc(virq)->status |= IRQ_LEVEL;
  176. set_irq_chip_and_handler(virq, &cpm2_pic, handle_level_irq);
  177. return 0;
  178. }
  179. static int cpm2_pic_host_xlate(struct irq_host *h, struct device_node *ct,
  180. u32 *intspec, unsigned int intsize,
  181. irq_hw_number_t *out_hwirq, unsigned int *out_flags)
  182. {
  183. *out_hwirq = intspec[0];
  184. if (intsize > 1)
  185. *out_flags = intspec[1];
  186. else
  187. *out_flags = IRQ_TYPE_NONE;
  188. return 0;
  189. }
  190. static struct irq_host_ops cpm2_pic_host_ops = {
  191. .map = cpm2_pic_host_map,
  192. .xlate = cpm2_pic_host_xlate,
  193. };
  194. void cpm2_pic_init(struct device_node *node)
  195. {
  196. int i;
  197. cpm2_intctl = cpm2_map(im_intctl);
  198. /* Clear the CPM IRQ controller, in case it has any bits set
  199. * from the bootloader
  200. */
  201. /* Mask out everything */
  202. out_be32(&cpm2_intctl->ic_simrh, 0x00000000);
  203. out_be32(&cpm2_intctl->ic_simrl, 0x00000000);
  204. wmb();
  205. /* Ack everything */
  206. out_be32(&cpm2_intctl->ic_sipnrh, 0xffffffff);
  207. out_be32(&cpm2_intctl->ic_sipnrl, 0xffffffff);
  208. wmb();
  209. /* Dummy read of the vector */
  210. i = in_be32(&cpm2_intctl->ic_sivec);
  211. rmb();
  212. /* Initialize the default interrupt mapping priorities,
  213. * in case the boot rom changed something on us.
  214. */
  215. out_be16(&cpm2_intctl->ic_sicr, 0);
  216. out_be32(&cpm2_intctl->ic_scprrh, 0x05309770);
  217. out_be32(&cpm2_intctl->ic_scprrl, 0x05309770);
  218. /* create a legacy host */
  219. cpm2_pic_host = irq_alloc_host(node, IRQ_HOST_MAP_LINEAR,
  220. 64, &cpm2_pic_host_ops, 64);
  221. if (cpm2_pic_host == NULL) {
  222. printk(KERN_ERR "CPM2 PIC: failed to allocate irq host!\n");
  223. return;
  224. }
  225. }