irq.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. /* linux/arch/arm/mach-s3c2412/irq.c
  2. *
  3. * Copyright (c) 2006 Simtec Electronics
  4. * Ben Dooks <ben@simtec.co.uk>
  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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. *
  20. */
  21. #include <linux/init.h>
  22. #include <linux/module.h>
  23. #include <linux/interrupt.h>
  24. #include <linux/ioport.h>
  25. #include <linux/sysdev.h>
  26. #include <linux/io.h>
  27. #include <mach/hardware.h>
  28. #include <asm/irq.h>
  29. #include <asm/mach/irq.h>
  30. #include <mach/regs-irq.h>
  31. #include <mach/regs-gpio.h>
  32. #include <mach/regs-power.h>
  33. #include <plat/cpu.h>
  34. #include <plat/irq.h>
  35. #include <plat/pm.h>
  36. #define INTMSK(start, end) ((1 << ((end) + 1 - (start))) - 1)
  37. #define INTMSK_SUB(start, end) (INTMSK(start, end) << ((start - S3C2410_IRQSUB(0))))
  38. /* the s3c2412 changes the behaviour of IRQ_EINT0 through IRQ_EINT3 by
  39. * having them turn up in both the INT* and the EINT* registers. Whilst
  40. * both show the status, they both now need to be acked when the IRQs
  41. * go off.
  42. */
  43. static void
  44. s3c2412_irq_mask(unsigned int irqno)
  45. {
  46. unsigned long bitval = 1UL << (irqno - IRQ_EINT0);
  47. unsigned long mask;
  48. mask = __raw_readl(S3C2410_INTMSK);
  49. __raw_writel(mask | bitval, S3C2410_INTMSK);
  50. mask = __raw_readl(S3C2412_EINTMASK);
  51. __raw_writel(mask | bitval, S3C2412_EINTMASK);
  52. }
  53. static inline void
  54. s3c2412_irq_ack(unsigned int irqno)
  55. {
  56. unsigned long bitval = 1UL << (irqno - IRQ_EINT0);
  57. __raw_writel(bitval, S3C2412_EINTPEND);
  58. __raw_writel(bitval, S3C2410_SRCPND);
  59. __raw_writel(bitval, S3C2410_INTPND);
  60. }
  61. static inline void
  62. s3c2412_irq_maskack(unsigned int irqno)
  63. {
  64. unsigned long bitval = 1UL << (irqno - IRQ_EINT0);
  65. unsigned long mask;
  66. mask = __raw_readl(S3C2410_INTMSK);
  67. __raw_writel(mask|bitval, S3C2410_INTMSK);
  68. mask = __raw_readl(S3C2412_EINTMASK);
  69. __raw_writel(mask | bitval, S3C2412_EINTMASK);
  70. __raw_writel(bitval, S3C2412_EINTPEND);
  71. __raw_writel(bitval, S3C2410_SRCPND);
  72. __raw_writel(bitval, S3C2410_INTPND);
  73. }
  74. static void
  75. s3c2412_irq_unmask(unsigned int irqno)
  76. {
  77. unsigned long bitval = 1UL << (irqno - IRQ_EINT0);
  78. unsigned long mask;
  79. mask = __raw_readl(S3C2412_EINTMASK);
  80. __raw_writel(mask & ~bitval, S3C2412_EINTMASK);
  81. mask = __raw_readl(S3C2410_INTMSK);
  82. __raw_writel(mask & ~bitval, S3C2410_INTMSK);
  83. }
  84. static struct irq_chip s3c2412_irq_eint0t4 = {
  85. .ack = s3c2412_irq_ack,
  86. .mask = s3c2412_irq_mask,
  87. .unmask = s3c2412_irq_unmask,
  88. .set_wake = s3c_irq_wake,
  89. .set_type = s3c_irqext_type,
  90. };
  91. #define INTBIT(x) (1 << ((x) - S3C2410_IRQSUB(0)))
  92. /* CF and SDI sub interrupts */
  93. static void s3c2412_irq_demux_cfsdi(unsigned int irq, struct irq_desc *desc)
  94. {
  95. unsigned int subsrc, submsk;
  96. subsrc = __raw_readl(S3C2410_SUBSRCPND);
  97. submsk = __raw_readl(S3C2410_INTSUBMSK);
  98. subsrc &= ~submsk;
  99. if (subsrc & INTBIT(IRQ_S3C2412_SDI))
  100. generic_handle_irq(IRQ_S3C2412_SDI);
  101. if (subsrc & INTBIT(IRQ_S3C2412_CF))
  102. generic_handle_irq(IRQ_S3C2412_CF);
  103. }
  104. #define INTMSK_CFSDI (1UL << (IRQ_S3C2412_CFSDI - IRQ_EINT0))
  105. #define SUBMSK_CFSDI INTMSK_SUB(IRQ_S3C2412_SDI, IRQ_S3C2412_CF)
  106. static void s3c2412_irq_cfsdi_mask(unsigned int irqno)
  107. {
  108. s3c_irqsub_mask(irqno, INTMSK_CFSDI, SUBMSK_CFSDI);
  109. }
  110. static void s3c2412_irq_cfsdi_unmask(unsigned int irqno)
  111. {
  112. s3c_irqsub_unmask(irqno, INTMSK_CFSDI);
  113. }
  114. static void s3c2412_irq_cfsdi_ack(unsigned int irqno)
  115. {
  116. s3c_irqsub_maskack(irqno, INTMSK_CFSDI, SUBMSK_CFSDI);
  117. }
  118. static struct irq_chip s3c2412_irq_cfsdi = {
  119. .name = "s3c2412-cfsdi",
  120. .ack = s3c2412_irq_cfsdi_ack,
  121. .mask = s3c2412_irq_cfsdi_mask,
  122. .unmask = s3c2412_irq_cfsdi_unmask,
  123. };
  124. static int s3c2412_irq_rtc_wake(unsigned int irqno, unsigned int state)
  125. {
  126. unsigned long pwrcfg;
  127. pwrcfg = __raw_readl(S3C2412_PWRCFG);
  128. if (state)
  129. pwrcfg &= ~S3C2412_PWRCFG_RTC_MASKIRQ;
  130. else
  131. pwrcfg |= S3C2412_PWRCFG_RTC_MASKIRQ;
  132. __raw_writel(pwrcfg, S3C2412_PWRCFG);
  133. return s3c_irq_chip.set_wake(irqno, state);
  134. }
  135. static struct irq_chip s3c2412_irq_rtc_chip;
  136. static int s3c2412_irq_add(struct sys_device *sysdev)
  137. {
  138. unsigned int irqno;
  139. for (irqno = IRQ_EINT0; irqno <= IRQ_EINT3; irqno++) {
  140. set_irq_chip(irqno, &s3c2412_irq_eint0t4);
  141. set_irq_handler(irqno, handle_edge_irq);
  142. set_irq_flags(irqno, IRQF_VALID);
  143. }
  144. /* add demux support for CF/SDI */
  145. set_irq_chained_handler(IRQ_S3C2412_CFSDI, s3c2412_irq_demux_cfsdi);
  146. for (irqno = IRQ_S3C2412_SDI; irqno <= IRQ_S3C2412_CF; irqno++) {
  147. set_irq_chip(irqno, &s3c2412_irq_cfsdi);
  148. set_irq_handler(irqno, handle_level_irq);
  149. set_irq_flags(irqno, IRQF_VALID);
  150. }
  151. /* change RTC IRQ's set wake method */
  152. s3c2412_irq_rtc_chip = s3c_irq_chip;
  153. s3c2412_irq_rtc_chip.set_wake = s3c2412_irq_rtc_wake;
  154. set_irq_chip(IRQ_RTC, &s3c2412_irq_rtc_chip);
  155. return 0;
  156. }
  157. static struct sysdev_driver s3c2412_irq_driver = {
  158. .add = s3c2412_irq_add,
  159. .suspend = s3c24xx_irq_suspend,
  160. .resume = s3c24xx_irq_resume,
  161. };
  162. static int s3c2412_irq_init(void)
  163. {
  164. return sysdev_driver_register(&s3c2412_sysclass, &s3c2412_irq_driver);
  165. }
  166. arch_initcall(s3c2412_irq_init);