irq-eint.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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. #define eint_offset(irq) ((irq) - IRQ_EINT(0))
  26. #define eint_irq_to_bit(irq) (1 << eint_offset(irq))
  27. static inline void s3c_irq_eint_mask(unsigned int irq)
  28. {
  29. u32 mask;
  30. mask = __raw_readl(S3C64XX_EINT0MASK);
  31. mask |= eint_irq_to_bit(irq);
  32. __raw_writel(mask, S3C64XX_EINT0MASK);
  33. }
  34. static void s3c_irq_eint_unmask(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 inline void s3c_irq_eint_ack(unsigned int irq)
  42. {
  43. __raw_writel(eint_irq_to_bit(irq), S3C64XX_EINT0PEND);
  44. }
  45. static void s3c_irq_eint_maskack(unsigned int irq)
  46. {
  47. /* compiler should in-line these */
  48. s3c_irq_eint_mask(irq);
  49. s3c_irq_eint_ack(irq);
  50. }
  51. static int s3c_irq_eint_set_type(unsigned int irq, unsigned int type)
  52. {
  53. int offs = eint_offset(irq);
  54. int pin;
  55. int shift;
  56. u32 ctrl, mask;
  57. u32 newvalue = 0;
  58. void __iomem *reg;
  59. if (offs > 27)
  60. return -EINVAL;
  61. if (offs <= 15)
  62. reg = S3C64XX_EINT0CON0;
  63. else
  64. reg = S3C64XX_EINT0CON1;
  65. switch (type) {
  66. case IRQ_TYPE_NONE:
  67. printk(KERN_WARNING "No edge setting!\n");
  68. break;
  69. case IRQ_TYPE_EDGE_RISING:
  70. newvalue = S3C2410_EXTINT_RISEEDGE;
  71. break;
  72. case IRQ_TYPE_EDGE_FALLING:
  73. newvalue = S3C2410_EXTINT_FALLEDGE;
  74. break;
  75. case IRQ_TYPE_EDGE_BOTH:
  76. newvalue = S3C2410_EXTINT_BOTHEDGE;
  77. break;
  78. case IRQ_TYPE_LEVEL_LOW:
  79. newvalue = S3C2410_EXTINT_LOWLEV;
  80. break;
  81. case IRQ_TYPE_LEVEL_HIGH:
  82. newvalue = S3C2410_EXTINT_HILEV;
  83. break;
  84. default:
  85. printk(KERN_ERR "No such irq type %d", type);
  86. return -1;
  87. }
  88. shift = (offs / 2) * 4;
  89. mask = 0x7 << shift;
  90. ctrl = __raw_readl(reg);
  91. ctrl &= ~mask;
  92. ctrl |= newvalue << shift;
  93. __raw_writel(ctrl, reg);
  94. /* set the GPIO pin appropriately */
  95. if (offs < 23)
  96. pin = S3C64XX_GPN(offs);
  97. else
  98. pin = S3C64XX_GPM(offs - 23);
  99. s3c_gpio_cfgpin(pin, S3C_GPIO_SFN(2));
  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. static 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);