mpc8xx_pic.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. #include <linux/kernel.h>
  2. #include <linux/stddef.h>
  3. #include <linux/sched.h>
  4. #include <linux/signal.h>
  5. #include <linux/irq.h>
  6. #include <linux/dma-mapping.h>
  7. #include <asm/prom.h>
  8. #include <asm/irq.h>
  9. #include <asm/io.h>
  10. #include <asm/8xx_immap.h>
  11. #include "mpc8xx_pic.h"
  12. #define PIC_VEC_SPURRIOUS 15
  13. extern int cpm_get_irq(struct pt_regs *regs);
  14. static struct irq_domain *mpc8xx_pic_host;
  15. static unsigned long mpc8xx_cached_irq_mask;
  16. static sysconf8xx_t __iomem *siu_reg;
  17. static inline unsigned long mpc8xx_irqd_to_bit(struct irq_data *d)
  18. {
  19. return 0x80000000 >> irqd_to_hwirq(d);
  20. }
  21. static void mpc8xx_unmask_irq(struct irq_data *d)
  22. {
  23. mpc8xx_cached_irq_mask |= mpc8xx_irqd_to_bit(d);
  24. out_be32(&siu_reg->sc_simask, mpc8xx_cached_irq_mask);
  25. }
  26. static void mpc8xx_mask_irq(struct irq_data *d)
  27. {
  28. mpc8xx_cached_irq_mask &= ~mpc8xx_irqd_to_bit(d);
  29. out_be32(&siu_reg->sc_simask, mpc8xx_cached_irq_mask);
  30. }
  31. static void mpc8xx_ack(struct irq_data *d)
  32. {
  33. out_be32(&siu_reg->sc_sipend, mpc8xx_irqd_to_bit(d));
  34. }
  35. static void mpc8xx_end_irq(struct irq_data *d)
  36. {
  37. mpc8xx_cached_irq_mask |= mpc8xx_irqd_to_bit(d);
  38. out_be32(&siu_reg->sc_simask, mpc8xx_cached_irq_mask);
  39. }
  40. static int mpc8xx_set_irq_type(struct irq_data *d, unsigned int flow_type)
  41. {
  42. /* only external IRQ senses are programmable */
  43. if ((flow_type & IRQ_TYPE_EDGE_FALLING) && !(irqd_to_hwirq(d) & 1)) {
  44. unsigned int siel = in_be32(&siu_reg->sc_siel);
  45. siel |= mpc8xx_irqd_to_bit(d);
  46. out_be32(&siu_reg->sc_siel, siel);
  47. irq_set_handler_locked(d, handle_edge_irq);
  48. }
  49. return 0;
  50. }
  51. static struct irq_chip mpc8xx_pic = {
  52. .name = "8XX SIU",
  53. .irq_unmask = mpc8xx_unmask_irq,
  54. .irq_mask = mpc8xx_mask_irq,
  55. .irq_ack = mpc8xx_ack,
  56. .irq_eoi = mpc8xx_end_irq,
  57. .irq_set_type = mpc8xx_set_irq_type,
  58. };
  59. unsigned int mpc8xx_get_irq(void)
  60. {
  61. int irq;
  62. /* For MPC8xx, read the SIVEC register and shift the bits down
  63. * to get the irq number.
  64. */
  65. irq = in_be32(&siu_reg->sc_sivec) >> 26;
  66. if (irq == PIC_VEC_SPURRIOUS)
  67. return 0;
  68. return irq_linear_revmap(mpc8xx_pic_host, irq);
  69. }
  70. static int mpc8xx_pic_host_map(struct irq_domain *h, unsigned int virq,
  71. irq_hw_number_t hw)
  72. {
  73. pr_debug("mpc8xx_pic_host_map(%d, 0x%lx)\n", virq, hw);
  74. /* Set default irq handle */
  75. irq_set_chip_and_handler(virq, &mpc8xx_pic, handle_level_irq);
  76. return 0;
  77. }
  78. static int mpc8xx_pic_host_xlate(struct irq_domain *h, struct device_node *ct,
  79. const u32 *intspec, unsigned int intsize,
  80. irq_hw_number_t *out_hwirq, unsigned int *out_flags)
  81. {
  82. static unsigned char map_pic_senses[4] = {
  83. IRQ_TYPE_EDGE_RISING,
  84. IRQ_TYPE_LEVEL_LOW,
  85. IRQ_TYPE_LEVEL_HIGH,
  86. IRQ_TYPE_EDGE_FALLING,
  87. };
  88. if (intspec[0] > 0x1f)
  89. return 0;
  90. *out_hwirq = intspec[0];
  91. if (intsize > 1 && intspec[1] < 4)
  92. *out_flags = map_pic_senses[intspec[1]];
  93. else
  94. *out_flags = IRQ_TYPE_NONE;
  95. return 0;
  96. }
  97. static const struct irq_domain_ops mpc8xx_pic_host_ops = {
  98. .map = mpc8xx_pic_host_map,
  99. .xlate = mpc8xx_pic_host_xlate,
  100. };
  101. int mpc8xx_pic_init(void)
  102. {
  103. struct resource res;
  104. struct device_node *np;
  105. int ret;
  106. np = of_find_compatible_node(NULL, NULL, "fsl,pq1-pic");
  107. if (np == NULL)
  108. np = of_find_node_by_type(NULL, "mpc8xx-pic");
  109. if (np == NULL) {
  110. printk(KERN_ERR "Could not find fsl,pq1-pic node\n");
  111. return -ENOMEM;
  112. }
  113. ret = of_address_to_resource(np, 0, &res);
  114. if (ret)
  115. goto out;
  116. siu_reg = ioremap(res.start, resource_size(&res));
  117. if (siu_reg == NULL) {
  118. ret = -EINVAL;
  119. goto out;
  120. }
  121. mpc8xx_pic_host = irq_domain_add_linear(np, 64, &mpc8xx_pic_host_ops, NULL);
  122. if (mpc8xx_pic_host == NULL) {
  123. printk(KERN_ERR "MPC8xx PIC: failed to allocate irq host!\n");
  124. ret = -ENOMEM;
  125. goto out;
  126. }
  127. return 0;
  128. out:
  129. of_node_put(np);
  130. return ret;
  131. }