irq-eint.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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 <plat/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;
  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. shift = (offs / 2) * 4;
  91. mask = 0x7 << shift;
  92. ctrl = __raw_readl(reg);
  93. ctrl &= ~mask;
  94. ctrl |= newvalue << shift;
  95. __raw_writel(ctrl, reg);
  96. /* set the GPIO pin appropriately */
  97. if (offs < 23)
  98. pin = S3C64XX_GPN(offs);
  99. else
  100. pin = S3C64XX_GPM(offs - 23);
  101. s3c_gpio_cfgpin(pin, S3C_GPIO_SFN(2));
  102. return 0;
  103. }
  104. static struct irq_chip s3c_irq_eint = {
  105. .name = "s3c-eint",
  106. .mask = s3c_irq_eint_mask,
  107. .unmask = s3c_irq_eint_unmask,
  108. .mask_ack = s3c_irq_eint_maskack,
  109. .ack = s3c_irq_eint_ack,
  110. .set_type = s3c_irq_eint_set_type,
  111. .set_wake = s3c_irqext_wake,
  112. };
  113. /* s3c_irq_demux_eint
  114. *
  115. * This function demuxes the IRQ from the group0 external interrupts,
  116. * from IRQ_EINT(0) to IRQ_EINT(27). It is designed to be inlined into
  117. * the specific handlers s3c_irq_demux_eintX_Y.
  118. */
  119. static inline void s3c_irq_demux_eint(unsigned int start, unsigned int end)
  120. {
  121. u32 status = __raw_readl(S3C64XX_EINT0PEND);
  122. u32 mask = __raw_readl(S3C64XX_EINT0MASK);
  123. unsigned int irq;
  124. status &= ~mask;
  125. status >>= start;
  126. status &= (1 << (end - start + 1)) - 1;
  127. for (irq = IRQ_EINT(start); irq <= IRQ_EINT(end); irq++) {
  128. if (status & 1)
  129. generic_handle_irq(irq);
  130. status >>= 1;
  131. }
  132. }
  133. static void s3c_irq_demux_eint0_3(unsigned int irq, struct irq_desc *desc)
  134. {
  135. s3c_irq_demux_eint(0, 3);
  136. }
  137. static void s3c_irq_demux_eint4_11(unsigned int irq, struct irq_desc *desc)
  138. {
  139. s3c_irq_demux_eint(4, 11);
  140. }
  141. static void s3c_irq_demux_eint12_19(unsigned int irq, struct irq_desc *desc)
  142. {
  143. s3c_irq_demux_eint(12, 19);
  144. }
  145. static void s3c_irq_demux_eint20_27(unsigned int irq, struct irq_desc *desc)
  146. {
  147. s3c_irq_demux_eint(20, 27);
  148. }
  149. static int __init s3c64xx_init_irq_eint(void)
  150. {
  151. int irq;
  152. for (irq = IRQ_EINT(0); irq <= IRQ_EINT(27); irq++) {
  153. set_irq_chip(irq, &s3c_irq_eint);
  154. set_irq_handler(irq, handle_level_irq);
  155. set_irq_flags(irq, IRQF_VALID);
  156. }
  157. set_irq_chained_handler(IRQ_EINT0_3, s3c_irq_demux_eint0_3);
  158. set_irq_chained_handler(IRQ_EINT4_11, s3c_irq_demux_eint4_11);
  159. set_irq_chained_handler(IRQ_EINT12_19, s3c_irq_demux_eint12_19);
  160. set_irq_chained_handler(IRQ_EINT20_27, s3c_irq_demux_eint20_27);
  161. return 0;
  162. }
  163. arch_initcall(s3c64xx_init_irq_eint);