irq-eint.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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_FALLEDGE;
  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 = __raw_readl(S5P_EINT_PEND(EINT_REG_NR(start)));
  115. u32 mask = __raw_readl(S5P_EINT_MASK(EINT_REG_NR(start)));
  116. unsigned int irq;
  117. status &= ~mask;
  118. status &= 0xff;
  119. while (status) {
  120. irq = fls(status) - 1;
  121. generic_handle_irq(irq + start);
  122. status &= ~(1 << irq);
  123. }
  124. }
  125. static void s5p_irq_demux_eint16_31(unsigned int irq, struct irq_desc *desc)
  126. {
  127. s5p_irq_demux_eint(IRQ_EINT(16));
  128. s5p_irq_demux_eint(IRQ_EINT(24));
  129. }
  130. static inline void s5p_irq_vic_eint_mask(unsigned int irq)
  131. {
  132. void __iomem *base = get_irq_chip_data(irq);
  133. s5p_irq_eint_mask(irq);
  134. writel(1 << EINT_OFFSET(irq), base + VIC_INT_ENABLE_CLEAR);
  135. }
  136. static void s5p_irq_vic_eint_unmask(unsigned int irq)
  137. {
  138. void __iomem *base = get_irq_chip_data(irq);
  139. s5p_irq_eint_unmask(irq);
  140. writel(1 << EINT_OFFSET(irq), base + VIC_INT_ENABLE);
  141. }
  142. static inline void s5p_irq_vic_eint_ack(unsigned int irq)
  143. {
  144. __raw_writel(eint_irq_to_bit(irq), S5P_EINT_PEND(EINT_REG_NR(irq)));
  145. }
  146. static void s5p_irq_vic_eint_maskack(unsigned int irq)
  147. {
  148. s5p_irq_vic_eint_mask(irq);
  149. s5p_irq_vic_eint_ack(irq);
  150. }
  151. static struct irq_chip s5p_irq_vic_eint = {
  152. .name = "s5p_vic_eint",
  153. .mask = s5p_irq_vic_eint_mask,
  154. .unmask = s5p_irq_vic_eint_unmask,
  155. .mask_ack = s5p_irq_vic_eint_maskack,
  156. .ack = s5p_irq_vic_eint_ack,
  157. .set_type = s5p_irq_eint_set_type,
  158. #ifdef CONFIG_PM
  159. .set_wake = s3c_irqext_wake,
  160. #endif
  161. };
  162. int __init s5p_init_irq_eint(void)
  163. {
  164. int irq;
  165. for (irq = IRQ_EINT(0); irq <= IRQ_EINT(15); irq++)
  166. set_irq_chip(irq, &s5p_irq_vic_eint);
  167. for (irq = IRQ_EINT(16); irq <= IRQ_EINT(31); irq++) {
  168. set_irq_chip(irq, &s5p_irq_eint);
  169. set_irq_handler(irq, handle_level_irq);
  170. set_irq_flags(irq, IRQF_VALID);
  171. }
  172. set_irq_chained_handler(IRQ_EINT16_31, s5p_irq_demux_eint16_31);
  173. return 0;
  174. }
  175. arch_initcall(s5p_init_irq_eint);