irq-eint.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. /* linux/arch/arm/plat-s5p/irq-eint.c
  2. *
  3. * Copyright (c) 2010 Samsung Electronics Co., Ltd.
  4. * http://www.samsung.com
  5. *
  6. * S5P - IRQ EINT support
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. */
  12. #include <linux/kernel.h>
  13. #include <linux/interrupt.h>
  14. #include <linux/irq.h>
  15. #include <linux/io.h>
  16. #include <linux/sysdev.h>
  17. #include <linux/gpio.h>
  18. #include <asm/hardware/vic.h>
  19. #include <plat/regs-irqtype.h>
  20. #include <mach/map.h>
  21. #include <plat/cpu.h>
  22. #include <plat/pm.h>
  23. #include <plat/gpio-cfg.h>
  24. #include <mach/regs-gpio.h>
  25. static inline void s5p_irq_eint_mask(unsigned int irq)
  26. {
  27. u32 mask;
  28. mask = __raw_readl(S5P_EINT_MASK(EINT_REG_NR(irq)));
  29. mask |= eint_irq_to_bit(irq);
  30. __raw_writel(mask, S5P_EINT_MASK(EINT_REG_NR(irq)));
  31. }
  32. static void s5p_irq_eint_unmask(unsigned int irq)
  33. {
  34. u32 mask;
  35. mask = __raw_readl(S5P_EINT_MASK(EINT_REG_NR(irq)));
  36. mask &= ~(eint_irq_to_bit(irq));
  37. __raw_writel(mask, S5P_EINT_MASK(EINT_REG_NR(irq)));
  38. }
  39. static inline void s5p_irq_eint_ack(unsigned int irq)
  40. {
  41. __raw_writel(eint_irq_to_bit(irq), S5P_EINT_PEND(EINT_REG_NR(irq)));
  42. }
  43. static void s5p_irq_eint_maskack(unsigned int irq)
  44. {
  45. /* compiler should in-line these */
  46. s5p_irq_eint_mask(irq);
  47. s5p_irq_eint_ack(irq);
  48. }
  49. static int s5p_irq_eint_set_type(unsigned int irq, unsigned int type)
  50. {
  51. int offs = eint_offset(irq);
  52. int shift;
  53. u32 ctrl, mask;
  54. u32 newvalue = 0;
  55. switch (type) {
  56. case IRQ_TYPE_EDGE_RISING:
  57. newvalue = S5P_EXTINT_RISEEDGE;
  58. break;
  59. case IRQ_TYPE_EDGE_FALLING:
  60. newvalue = S5P_EXTINT_RISEEDGE;
  61. break;
  62. case IRQ_TYPE_EDGE_BOTH:
  63. newvalue = S5P_EXTINT_BOTHEDGE;
  64. break;
  65. case IRQ_TYPE_LEVEL_LOW:
  66. newvalue = S5P_EXTINT_LOWLEV;
  67. break;
  68. case IRQ_TYPE_LEVEL_HIGH:
  69. newvalue = S5P_EXTINT_HILEV;
  70. break;
  71. default:
  72. printk(KERN_ERR "No such irq type %d", type);
  73. return -EINVAL;
  74. }
  75. shift = (offs & 0x7) * 4;
  76. mask = 0x7 << shift;
  77. ctrl = __raw_readl(S5P_EINT_CON(EINT_REG_NR(irq)));
  78. ctrl &= ~mask;
  79. ctrl |= newvalue << shift;
  80. __raw_writel(ctrl, S5P_EINT_CON(EINT_REG_NR(irq)));
  81. if ((0 <= offs) && (offs < 8))
  82. s3c_gpio_cfgpin(EINT_GPIO_0(offs & 0x7), EINT_MODE);
  83. else if ((8 <= offs) && (offs < 16))
  84. s3c_gpio_cfgpin(EINT_GPIO_1(offs & 0x7), EINT_MODE);
  85. else if ((16 <= offs) && (offs < 24))
  86. s3c_gpio_cfgpin(EINT_GPIO_2(offs & 0x7), EINT_MODE);
  87. else if ((24 <= offs) && (offs < 32))
  88. s3c_gpio_cfgpin(EINT_GPIO_3(offs & 0x7), EINT_MODE);
  89. else
  90. printk(KERN_ERR "No such irq number %d", offs);
  91. return 0;
  92. }
  93. static struct irq_chip s5p_irq_eint = {
  94. .name = "s5p-eint",
  95. .mask = s5p_irq_eint_mask,
  96. .unmask = s5p_irq_eint_unmask,
  97. .mask_ack = s5p_irq_eint_maskack,
  98. .ack = s5p_irq_eint_ack,
  99. .set_type = s5p_irq_eint_set_type,
  100. #ifdef CONFIG_PM
  101. .set_wake = s3c_irqext_wake,
  102. #endif
  103. };
  104. /* s5p_irq_demux_eint
  105. *
  106. * This function demuxes the IRQ from the group0 external interrupts,
  107. * from EINTs 16 to 31. It is designed to be inlined into the specific
  108. * handler s5p_irq_demux_eintX_Y.
  109. *
  110. * Each EINT pend/mask registers handle eight of them.
  111. */
  112. static inline void s5p_irq_demux_eint(unsigned int start)
  113. {
  114. u32 status;
  115. u32 mask = __raw_readl(S5P_EINT_MASK(EINT_REG_NR(start)));
  116. unsigned int irq;
  117. status = __raw_readl(S5P_EINT_PEND(EINT_REG_NR(start)));
  118. status &= ~mask;
  119. status &= 0xff;
  120. while (status) {
  121. irq = fls(status);
  122. generic_handle_irq(irq - 1 + start);
  123. status &= ~(1 << irq);
  124. }
  125. }
  126. static void s5p_irq_demux_eint16_31(unsigned int irq, struct irq_desc *desc)
  127. {
  128. s5p_irq_demux_eint(IRQ_EINT(16));
  129. s5p_irq_demux_eint(IRQ_EINT(24));
  130. }
  131. static inline void s5p_irq_vic_eint_mask(unsigned int irq)
  132. {
  133. s5p_irq_eint_mask(irq);
  134. }
  135. static void s5p_irq_vic_eint_unmask(unsigned int irq)
  136. {
  137. s5p_irq_eint_unmask(irq);
  138. }
  139. static inline void s5p_irq_vic_eint_ack(unsigned int irq)
  140. {
  141. __raw_writel(eint_irq_to_bit(irq), S5P_EINT_PEND(EINT_REG_NR(irq)));
  142. }
  143. static void s5p_irq_vic_eint_maskack(unsigned int irq)
  144. {
  145. s5p_irq_vic_eint_mask(irq);
  146. s5p_irq_vic_eint_ack(irq);
  147. }
  148. static struct irq_chip s5p_irq_vic_eint = {
  149. .name = "s5p_vic_eint",
  150. .mask = s5p_irq_vic_eint_mask,
  151. .unmask = s5p_irq_vic_eint_unmask,
  152. .mask_ack = s5p_irq_vic_eint_maskack,
  153. .ack = s5p_irq_vic_eint_ack,
  154. .set_type = s5p_irq_eint_set_type,
  155. #ifdef CONFIG_PM
  156. .set_wake = s3c_irqext_wake,
  157. #endif
  158. };
  159. int __init s5p_init_irq_eint(void)
  160. {
  161. int irq;
  162. for (irq = IRQ_EINT(0); irq <= IRQ_EINT(15); irq++)
  163. set_irq_chip(irq, &s5p_irq_vic_eint);
  164. for (irq = IRQ_EINT(16); irq <= IRQ_EINT(31); irq++) {
  165. set_irq_chip(irq, &s5p_irq_eint);
  166. set_irq_handler(irq, handle_level_irq);
  167. set_irq_flags(irq, IRQF_VALID);
  168. }
  169. set_irq_chained_handler(IRQ_EINT16_31, s5p_irq_demux_eint16_31);
  170. return 0;
  171. }
  172. arch_initcall(s5p_init_irq_eint);