irq-eint.c 4.8 KB

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