irq.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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/device.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. #include "nuc9xx.h"
  28. struct group_irq {
  29. unsigned long gpen;
  30. unsigned int enabled;
  31. void (*enable)(struct group_irq *, int enable);
  32. };
  33. static DEFINE_SPINLOCK(groupirq_lock);
  34. #define DEFINE_GROUP(_name, _ctrlbit, _num) \
  35. struct group_irq group_##_name = { \
  36. .enable = nuc900_group_enable, \
  37. .gpen = ((1 << _num) - 1) << _ctrlbit, \
  38. }
  39. static void nuc900_group_enable(struct group_irq *gpirq, int enable);
  40. static DEFINE_GROUP(nirq0, 0, 4);
  41. static DEFINE_GROUP(nirq1, 4, 4);
  42. static DEFINE_GROUP(usbh, 8, 2);
  43. static DEFINE_GROUP(ottimer, 16, 3);
  44. static DEFINE_GROUP(gdma, 20, 2);
  45. static DEFINE_GROUP(sc, 24, 2);
  46. static DEFINE_GROUP(i2c, 26, 2);
  47. static DEFINE_GROUP(ps2, 28, 2);
  48. static int group_irq_enable(struct group_irq *group_irq)
  49. {
  50. unsigned long flags;
  51. spin_lock_irqsave(&groupirq_lock, flags);
  52. if (group_irq->enabled++ == 0)
  53. (group_irq->enable)(group_irq, 1);
  54. spin_unlock_irqrestore(&groupirq_lock, flags);
  55. return 0;
  56. }
  57. static void group_irq_disable(struct group_irq *group_irq)
  58. {
  59. unsigned long flags;
  60. WARN_ON(group_irq->enabled == 0);
  61. spin_lock_irqsave(&groupirq_lock, flags);
  62. if (--group_irq->enabled == 0)
  63. (group_irq->enable)(group_irq, 0);
  64. spin_unlock_irqrestore(&groupirq_lock, flags);
  65. }
  66. static void nuc900_group_enable(struct group_irq *gpirq, int enable)
  67. {
  68. unsigned int groupen = gpirq->gpen;
  69. unsigned long regval;
  70. regval = __raw_readl(REG_AIC_GEN);
  71. if (enable)
  72. regval |= groupen;
  73. else
  74. regval &= ~groupen;
  75. __raw_writel(regval, REG_AIC_GEN);
  76. }
  77. static void nuc900_irq_mask(struct irq_data *d)
  78. {
  79. struct group_irq *group_irq;
  80. group_irq = NULL;
  81. __raw_writel(1 << d->irq, REG_AIC_MDCR);
  82. switch (d->irq) {
  83. case IRQ_GROUP0:
  84. group_irq = &group_nirq0;
  85. break;
  86. case IRQ_GROUP1:
  87. group_irq = &group_nirq1;
  88. break;
  89. case IRQ_USBH:
  90. group_irq = &group_usbh;
  91. break;
  92. case IRQ_T_INT_GROUP:
  93. group_irq = &group_ottimer;
  94. break;
  95. case IRQ_GDMAGROUP:
  96. group_irq = &group_gdma;
  97. break;
  98. case IRQ_SCGROUP:
  99. group_irq = &group_sc;
  100. break;
  101. case IRQ_I2CGROUP:
  102. group_irq = &group_i2c;
  103. break;
  104. case IRQ_P2SGROUP:
  105. group_irq = &group_ps2;
  106. break;
  107. }
  108. if (group_irq)
  109. group_irq_disable(group_irq);
  110. }
  111. /*
  112. * By the w90p910 spec,any irq,only write 1
  113. * to REG_AIC_EOSCR for ACK
  114. */
  115. static void nuc900_irq_ack(struct irq_data *d)
  116. {
  117. __raw_writel(0x01, REG_AIC_EOSCR);
  118. }
  119. static void nuc900_irq_unmask(struct irq_data *d)
  120. {
  121. struct group_irq *group_irq;
  122. group_irq = NULL;
  123. __raw_writel(1 << d->irq, REG_AIC_MECR);
  124. switch (d->irq) {
  125. case IRQ_GROUP0:
  126. group_irq = &group_nirq0;
  127. break;
  128. case IRQ_GROUP1:
  129. group_irq = &group_nirq1;
  130. break;
  131. case IRQ_USBH:
  132. group_irq = &group_usbh;
  133. break;
  134. case IRQ_T_INT_GROUP:
  135. group_irq = &group_ottimer;
  136. break;
  137. case IRQ_GDMAGROUP:
  138. group_irq = &group_gdma;
  139. break;
  140. case IRQ_SCGROUP:
  141. group_irq = &group_sc;
  142. break;
  143. case IRQ_I2CGROUP:
  144. group_irq = &group_i2c;
  145. break;
  146. case IRQ_P2SGROUP:
  147. group_irq = &group_ps2;
  148. break;
  149. }
  150. if (group_irq)
  151. group_irq_enable(group_irq);
  152. }
  153. static struct irq_chip nuc900_irq_chip = {
  154. .irq_ack = nuc900_irq_ack,
  155. .irq_mask = nuc900_irq_mask,
  156. .irq_unmask = nuc900_irq_unmask,
  157. };
  158. void __init nuc900_init_irq(void)
  159. {
  160. int irqno;
  161. __raw_writel(0xFFFFFFFE, REG_AIC_MDCR);
  162. for (irqno = IRQ_WDT; irqno <= IRQ_ADC; irqno++) {
  163. irq_set_chip_and_handler(irqno, &nuc900_irq_chip,
  164. handle_level_irq);
  165. irq_clear_status_flags(irqno, IRQ_NOREQUEST);
  166. }
  167. }