cpm2_pic.c 7.1 KB

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