irq.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. /*
  2. * linux/arch/arm/mach-w90x900/irq.c
  3. *
  4. * based on linux/arch/arm/plat-s3c24xx/irq.c by Ben Dooks
  5. *
  6. * Copyright (c) 2008 Nuvoton technology corporation
  7. * All rights reserved.
  8. *
  9. * Wan ZongShun <mcuos.com@gmail.com>
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation;version 2 of the License.
  14. *
  15. */
  16. #include <linux/init.h>
  17. #include <linux/module.h>
  18. #include <linux/interrupt.h>
  19. #include <linux/ioport.h>
  20. #include <linux/ptrace.h>
  21. #include <linux/sysdev.h>
  22. #include <linux/io.h>
  23. #include <asm/irq.h>
  24. #include <asm/mach/irq.h>
  25. #include <mach/hardware.h>
  26. #include <mach/regs-irq.h>
  27. struct group_irq {
  28. unsigned long gpen;
  29. unsigned int enabled;
  30. void (*enable)(struct group_irq *, int enable);
  31. };
  32. static DEFINE_SPINLOCK(groupirq_lock);
  33. #define DEFINE_GROUP(_name, _ctrlbit, _num) \
  34. struct group_irq group_##_name = { \
  35. .enable = nuc900_group_enable, \
  36. .gpen = ((1 << _num) - 1) << _ctrlbit, \
  37. }
  38. static void nuc900_group_enable(struct group_irq *gpirq, int enable);
  39. static DEFINE_GROUP(nirq0, 0, 4);
  40. static DEFINE_GROUP(nirq1, 4, 4);
  41. static DEFINE_GROUP(usbh, 8, 2);
  42. static DEFINE_GROUP(ottimer, 16, 3);
  43. static DEFINE_GROUP(gdma, 20, 2);
  44. static DEFINE_GROUP(sc, 24, 2);
  45. static DEFINE_GROUP(i2c, 26, 2);
  46. static DEFINE_GROUP(ps2, 28, 2);
  47. static int group_irq_enable(struct group_irq *group_irq)
  48. {
  49. unsigned long flags;
  50. spin_lock_irqsave(&groupirq_lock, flags);
  51. if (group_irq->enabled++ == 0)
  52. (group_irq->enable)(group_irq, 1);
  53. spin_unlock_irqrestore(&groupirq_lock, flags);
  54. return 0;
  55. }
  56. static void group_irq_disable(struct group_irq *group_irq)
  57. {
  58. unsigned long flags;
  59. WARN_ON(group_irq->enabled == 0);
  60. spin_lock_irqsave(&groupirq_lock, flags);
  61. if (--group_irq->enabled == 0)
  62. (group_irq->enable)(group_irq, 0);
  63. spin_unlock_irqrestore(&groupirq_lock, flags);
  64. }
  65. static void nuc900_group_enable(struct group_irq *gpirq, int enable)
  66. {
  67. unsigned int groupen = gpirq->gpen;
  68. unsigned long regval;
  69. regval = __raw_readl(REG_AIC_GEN);
  70. if (enable)
  71. regval |= groupen;
  72. else
  73. regval &= ~groupen;
  74. __raw_writel(regval, REG_AIC_GEN);
  75. }
  76. static void nuc900_irq_mask(struct irq_data *d)
  77. {
  78. struct group_irq *group_irq;
  79. group_irq = NULL;
  80. __raw_writel(1 << d->irq, REG_AIC_MDCR);
  81. switch (d->irq) {
  82. case IRQ_GROUP0:
  83. group_irq = &group_nirq0;
  84. break;
  85. case IRQ_GROUP1:
  86. group_irq = &group_nirq1;
  87. break;
  88. case IRQ_USBH:
  89. group_irq = &group_usbh;
  90. break;
  91. case IRQ_T_INT_GROUP:
  92. group_irq = &group_ottimer;
  93. break;
  94. case IRQ_GDMAGROUP:
  95. group_irq = &group_gdma;
  96. break;
  97. case IRQ_SCGROUP:
  98. group_irq = &group_sc;
  99. break;
  100. case IRQ_I2CGROUP:
  101. group_irq = &group_i2c;
  102. break;
  103. case IRQ_P2SGROUP:
  104. group_irq = &group_ps2;
  105. break;
  106. }
  107. if (group_irq)
  108. group_irq_disable(group_irq);
  109. }
  110. /*
  111. * By the w90p910 spec,any irq,only write 1
  112. * to REG_AIC_EOSCR for ACK
  113. */
  114. static void nuc900_irq_ack(struct irq_data *d)
  115. {
  116. __raw_writel(0x01, REG_AIC_EOSCR);
  117. }
  118. static void nuc900_irq_unmask(struct irq_data *d)
  119. {
  120. struct group_irq *group_irq;
  121. group_irq = NULL;
  122. __raw_writel(1 << d->irq, REG_AIC_MECR);
  123. switch (d->irq) {
  124. case IRQ_GROUP0:
  125. group_irq = &group_nirq0;
  126. break;
  127. case IRQ_GROUP1:
  128. group_irq = &group_nirq1;
  129. break;
  130. case IRQ_USBH:
  131. group_irq = &group_usbh;
  132. break;
  133. case IRQ_T_INT_GROUP:
  134. group_irq = &group_ottimer;
  135. break;
  136. case IRQ_GDMAGROUP:
  137. group_irq = &group_gdma;
  138. break;
  139. case IRQ_SCGROUP:
  140. group_irq = &group_sc;
  141. break;
  142. case IRQ_I2CGROUP:
  143. group_irq = &group_i2c;
  144. break;
  145. case IRQ_P2SGROUP:
  146. group_irq = &group_ps2;
  147. break;
  148. }
  149. if (group_irq)
  150. group_irq_enable(group_irq);
  151. }
  152. static struct irq_chip nuc900_irq_chip = {
  153. .irq_ack = nuc900_irq_ack,
  154. .irq_mask = nuc900_irq_mask,
  155. .irq_unmask = nuc900_irq_unmask,
  156. };
  157. void __init nuc900_init_irq(void)
  158. {
  159. int irqno;
  160. __raw_writel(0xFFFFFFFE, REG_AIC_MDCR);
  161. for (irqno = IRQ_WDT; irqno <= IRQ_ADC; irqno++) {
  162. irq_set_chip_and_handler(irqno, &nuc900_irq_chip,
  163. handle_level_irq);
  164. set_irq_flags(irqno, IRQF_VALID);
  165. }
  166. }