irq-eint.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. /* arch/arm/plat-s3c64xx/irq-eint.c
  2. *
  3. * Copyright 2008 Openmoko, Inc.
  4. * Copyright 2008 Simtec Electronics
  5. * Ben Dooks <ben@simtec.co.uk>
  6. * http://armlinux.simtec.co.uk/
  7. *
  8. * S3C64XX - Interrupt handling for IRQ_EINT(x)
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License version 2 as
  12. * published by the Free Software Foundation.
  13. */
  14. #include <linux/kernel.h>
  15. #include <linux/interrupt.h>
  16. #include <linux/irq.h>
  17. #include <linux/io.h>
  18. #include <asm/hardware/vic.h>
  19. #include <plat/regs-irqtype.h>
  20. #include <mach/map.h>
  21. #include <plat/cpu.h>
  22. /* GPIO is 0x7F008xxx, */
  23. #define S3C64XX_GPIOREG(x) (S3C64XX_VA_GPIO + (x))
  24. #define S3C64XX_EINT0CON0 S3C64XX_GPIOREG(0x900)
  25. #define S3C64XX_EINT0CON1 S3C64XX_GPIOREG(0x904)
  26. #define S3C64XX_EINT0FLTCON0 S3C64XX_GPIOREG(0x910)
  27. #define S3C64XX_EINT0FLTCON1 S3C64XX_GPIOREG(0x914)
  28. #define S3C64XX_EINT0FLTCON2 S3C64XX_GPIOREG(0x918)
  29. #define S3C64XX_EINT0FLTCON3 S3C64XX_GPIOREG(0x91C)
  30. #define S3C64XX_EINT0MASK S3C64XX_GPIOREG(0x920)
  31. #define S3C64XX_EINT0PEND S3C64XX_GPIOREG(0x924)
  32. #define eint_offset(irq) ((irq) - IRQ_EINT(0))
  33. #define eint_irq_to_bit(irq) (1 << eint_offset(irq))
  34. static inline void s3c_irq_eint_mask(unsigned int irq)
  35. {
  36. u32 mask;
  37. mask = __raw_readl(S3C64XX_EINT0MASK);
  38. mask |= eint_irq_to_bit(irq);
  39. __raw_writel(mask, S3C64XX_EINT0MASK);
  40. }
  41. static void s3c_irq_eint_unmask(unsigned int irq)
  42. {
  43. u32 mask;
  44. mask = __raw_readl(S3C64XX_EINT0MASK);
  45. mask |= eint_irq_to_bit(irq);
  46. __raw_writel(mask, S3C64XX_EINT0MASK);
  47. }
  48. static inline void s3c_irq_eint_ack(unsigned int irq)
  49. {
  50. __raw_writel(eint_irq_to_bit(irq), S3C64XX_EINT0PEND);
  51. }
  52. static void s3c_irq_eint_maskack(unsigned int irq)
  53. {
  54. /* compiler should in-line these */
  55. s3c_irq_eint_mask(irq);
  56. s3c_irq_eint_ack(irq);
  57. }
  58. static int s3c_irq_eint_set_type(unsigned int irq, unsigned int type)
  59. {
  60. int offs = eint_offset(irq);
  61. int shift;
  62. u32 ctrl, mask;
  63. u32 newvalue = 0;
  64. void __iomem *reg;
  65. if (offs > 27)
  66. return -EINVAL;
  67. if (offs <= 15)
  68. reg = S3C64XX_EINT0CON0;
  69. else
  70. reg = S3C64XX_EINT0CON1;
  71. switch (type) {
  72. case IRQ_TYPE_NONE:
  73. printk(KERN_WARNING "No edge setting!\n");
  74. break;
  75. case IRQ_TYPE_EDGE_RISING:
  76. newvalue = S3C2410_EXTINT_RISEEDGE;
  77. break;
  78. case IRQ_TYPE_EDGE_FALLING:
  79. newvalue = S3C2410_EXTINT_FALLEDGE;
  80. break;
  81. case IRQ_TYPE_EDGE_BOTH:
  82. newvalue = S3C2410_EXTINT_BOTHEDGE;
  83. break;
  84. case IRQ_TYPE_LEVEL_LOW:
  85. newvalue = S3C2410_EXTINT_LOWLEV;
  86. break;
  87. case IRQ_TYPE_LEVEL_HIGH:
  88. newvalue = S3C2410_EXTINT_HILEV;
  89. break;
  90. default:
  91. printk(KERN_ERR "No such irq type %d", type);
  92. return -1;
  93. }
  94. shift = (offs / 2) * 4;
  95. mask = 0x7 << shift;
  96. ctrl = __raw_readl(reg);
  97. ctrl &= ~mask;
  98. ctrl |= newvalue << shift;
  99. __raw_writel(ctrl, reg);
  100. return 0;
  101. }
  102. static struct irq_chip s3c_irq_eint = {
  103. .name = "s3c-eint",
  104. .mask = s3c_irq_eint_mask,
  105. .unmask = s3c_irq_eint_unmask,
  106. .mask_ack = s3c_irq_eint_maskack,
  107. .ack = s3c_irq_eint_ack,
  108. .set_type = s3c_irq_eint_set_type,
  109. };
  110. /* s3c_irq_demux_eint
  111. *
  112. * This function demuxes the IRQ from the group0 external interrupts,
  113. * from IRQ_EINT(0) to IRQ_EINT(27). It is designed to be inlined into
  114. * the specific handlers s3c_irq_demux_eintX_Y.
  115. */
  116. static inline void s3c_irq_demux_eint(unsigned int start, unsigned int end)
  117. {
  118. u32 status = __raw_readl(S3C64XX_EINT0PEND);
  119. u32 mask = __raw_readl(S3C64XX_EINT0MASK);
  120. unsigned int irq;
  121. status &= ~mask;
  122. status >>= start;
  123. status &= (1 << (end - start + 1)) - 1;
  124. for (irq = IRQ_EINT(start); irq <= IRQ_EINT(end); irq++) {
  125. if (status & 1)
  126. generic_handle_irq(irq);
  127. status >>= 1;
  128. }
  129. }
  130. static void s3c_irq_demux_eint0_3(unsigned int irq, struct irq_desc *desc)
  131. {
  132. s3c_irq_demux_eint(0, 3);
  133. }
  134. static void s3c_irq_demux_eint4_11(unsigned int irq, struct irq_desc *desc)
  135. {
  136. s3c_irq_demux_eint(4, 11);
  137. }
  138. static void s3c_irq_demux_eint12_19(unsigned int irq, struct irq_desc *desc)
  139. {
  140. s3c_irq_demux_eint(12, 19);
  141. }
  142. static void s3c_irq_demux_eint20_27(unsigned int irq, struct irq_desc *desc)
  143. {
  144. s3c_irq_demux_eint(20, 27);
  145. }
  146. int __init s3c64xx_init_irq_eint(void)
  147. {
  148. int irq;
  149. for (irq = IRQ_EINT(0); irq <= IRQ_EINT(27); irq++) {
  150. set_irq_chip(irq, &s3c_irq_eint);
  151. set_irq_handler(irq, handle_level_irq);
  152. set_irq_flags(irq, IRQF_VALID);
  153. }
  154. set_irq_chained_handler(IRQ_EINT0_3, s3c_irq_demux_eint0_3);
  155. set_irq_chained_handler(IRQ_EINT4_11, s3c_irq_demux_eint4_11);
  156. set_irq_chained_handler(IRQ_EINT12_19, s3c_irq_demux_eint12_19);
  157. set_irq_chained_handler(IRQ_EINT20_27, s3c_irq_demux_eint20_27);
  158. return 0;
  159. }
  160. arch_initcall(s3c64xx_init_irq_eint);