irq-gt641xx.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /*
  2. * GT641xx IRQ routines.
  3. *
  4. * Copyright (C) 2007 Yoichi Yuasa <yuasa@linux-mips.org>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #include <linux/hardirq.h>
  21. #include <linux/init.h>
  22. #include <linux/irq.h>
  23. #include <linux/spinlock.h>
  24. #include <linux/types.h>
  25. #include <asm/gt64120.h>
  26. #define GT641XX_IRQ_TO_BIT(irq) (1U << (irq - GT641XX_IRQ_BASE))
  27. static DEFINE_RAW_SPINLOCK(gt641xx_irq_lock);
  28. static void ack_gt641xx_irq(struct irq_data *d)
  29. {
  30. unsigned long flags;
  31. u32 cause;
  32. raw_spin_lock_irqsave(&gt641xx_irq_lock, flags);
  33. cause = GT_READ(GT_INTRCAUSE_OFS);
  34. cause &= ~GT641XX_IRQ_TO_BIT(d->irq);
  35. GT_WRITE(GT_INTRCAUSE_OFS, cause);
  36. raw_spin_unlock_irqrestore(&gt641xx_irq_lock, flags);
  37. }
  38. static void mask_gt641xx_irq(struct irq_data *d)
  39. {
  40. unsigned long flags;
  41. u32 mask;
  42. raw_spin_lock_irqsave(&gt641xx_irq_lock, flags);
  43. mask = GT_READ(GT_INTRMASK_OFS);
  44. mask &= ~GT641XX_IRQ_TO_BIT(d->irq);
  45. GT_WRITE(GT_INTRMASK_OFS, mask);
  46. raw_spin_unlock_irqrestore(&gt641xx_irq_lock, flags);
  47. }
  48. static void mask_ack_gt641xx_irq(struct irq_data *d)
  49. {
  50. unsigned long flags;
  51. u32 cause, mask;
  52. raw_spin_lock_irqsave(&gt641xx_irq_lock, flags);
  53. mask = GT_READ(GT_INTRMASK_OFS);
  54. mask &= ~GT641XX_IRQ_TO_BIT(d->irq);
  55. GT_WRITE(GT_INTRMASK_OFS, mask);
  56. cause = GT_READ(GT_INTRCAUSE_OFS);
  57. cause &= ~GT641XX_IRQ_TO_BIT(d->irq);
  58. GT_WRITE(GT_INTRCAUSE_OFS, cause);
  59. raw_spin_unlock_irqrestore(&gt641xx_irq_lock, flags);
  60. }
  61. static void unmask_gt641xx_irq(struct irq_data *d)
  62. {
  63. unsigned long flags;
  64. u32 mask;
  65. raw_spin_lock_irqsave(&gt641xx_irq_lock, flags);
  66. mask = GT_READ(GT_INTRMASK_OFS);
  67. mask |= GT641XX_IRQ_TO_BIT(d->irq);
  68. GT_WRITE(GT_INTRMASK_OFS, mask);
  69. raw_spin_unlock_irqrestore(&gt641xx_irq_lock, flags);
  70. }
  71. static struct irq_chip gt641xx_irq_chip = {
  72. .name = "GT641xx",
  73. .irq_ack = ack_gt641xx_irq,
  74. .irq_mask = mask_gt641xx_irq,
  75. .irq_mask_ack = mask_ack_gt641xx_irq,
  76. .irq_unmask = unmask_gt641xx_irq,
  77. };
  78. void gt641xx_irq_dispatch(void)
  79. {
  80. u32 cause, mask;
  81. int i;
  82. cause = GT_READ(GT_INTRCAUSE_OFS);
  83. mask = GT_READ(GT_INTRMASK_OFS);
  84. cause &= mask;
  85. /*
  86. * bit0 : logical or of all the interrupt bits.
  87. * bit30: logical or of bits[29:26,20:1].
  88. * bit31: logical or of bits[25:1].
  89. */
  90. for (i = 1; i < 30; i++) {
  91. if (cause & (1U << i)) {
  92. do_IRQ(GT641XX_IRQ_BASE + i);
  93. return;
  94. }
  95. }
  96. atomic_inc(&irq_err_count);
  97. }
  98. void __init gt641xx_irq_init(void)
  99. {
  100. int i;
  101. GT_WRITE(GT_INTRMASK_OFS, 0);
  102. GT_WRITE(GT_INTRCAUSE_OFS, 0);
  103. /*
  104. * bit0 : logical or of all the interrupt bits.
  105. * bit30: logical or of bits[29:26,20:1].
  106. * bit31: logical or of bits[25:1].
  107. */
  108. for (i = 1; i < 30; i++)
  109. irq_set_chip_and_handler(GT641XX_IRQ_BASE + i,
  110. &gt641xx_irq_chip, handle_level_irq);
  111. }