irq-eint.c 4.6 KB

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