irq-eint.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. /* linux/arch/arm/mach-s5pv310/irq-eint.c
  2. *
  3. * Copyright (c) 2010 Samsung Electronics Co., Ltd.
  4. * http://www.samsung.com
  5. *
  6. * S5PV310 - 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 <plat/pm.h>
  19. #include <plat/cpu.h>
  20. #include <plat/gpio-cfg.h>
  21. #include <mach/regs-gpio.h>
  22. static DEFINE_SPINLOCK(eint_lock);
  23. static unsigned int eint0_15_data[16];
  24. static unsigned int s5pv310_get_irq_nr(unsigned int number)
  25. {
  26. u32 ret = 0;
  27. switch (number) {
  28. case 0 ... 3:
  29. ret = (number + IRQ_EINT0);
  30. break;
  31. case 4 ... 7:
  32. ret = (number + (IRQ_EINT4 - 4));
  33. break;
  34. case 8 ... 15:
  35. ret = (number + (IRQ_EINT8 - 8));
  36. break;
  37. default:
  38. printk(KERN_ERR "number available : %d\n", number);
  39. }
  40. return ret;
  41. }
  42. static inline void s5pv310_irq_eint_mask(unsigned int irq)
  43. {
  44. u32 mask;
  45. spin_lock(&eint_lock);
  46. mask = __raw_readl(S5P_EINT_MASK(EINT_REG_NR(irq)));
  47. mask |= eint_irq_to_bit(irq);
  48. __raw_writel(mask, S5P_EINT_MASK(EINT_REG_NR(irq)));
  49. spin_unlock(&eint_lock);
  50. }
  51. static void s5pv310_irq_eint_unmask(unsigned int irq)
  52. {
  53. u32 mask;
  54. spin_lock(&eint_lock);
  55. mask = __raw_readl(S5P_EINT_MASK(EINT_REG_NR(irq)));
  56. mask &= ~(eint_irq_to_bit(irq));
  57. __raw_writel(mask, S5P_EINT_MASK(EINT_REG_NR(irq)));
  58. spin_unlock(&eint_lock);
  59. }
  60. static inline void s5pv310_irq_eint_ack(unsigned int irq)
  61. {
  62. __raw_writel(eint_irq_to_bit(irq), S5P_EINT_PEND(EINT_REG_NR(irq)));
  63. }
  64. static void s5pv310_irq_eint_maskack(unsigned int irq)
  65. {
  66. s5pv310_irq_eint_mask(irq);
  67. s5pv310_irq_eint_ack(irq);
  68. }
  69. static int s5pv310_irq_eint_set_type(unsigned int irq, unsigned int type)
  70. {
  71. int offs = EINT_OFFSET(irq);
  72. int shift;
  73. u32 ctrl, mask;
  74. u32 newvalue = 0;
  75. switch (type) {
  76. case IRQ_TYPE_EDGE_RISING:
  77. newvalue = S5P_IRQ_TYPE_EDGE_RISING;
  78. break;
  79. case IRQ_TYPE_EDGE_FALLING:
  80. newvalue = S5P_IRQ_TYPE_EDGE_FALLING;
  81. break;
  82. case IRQ_TYPE_EDGE_BOTH:
  83. newvalue = S5P_IRQ_TYPE_EDGE_BOTH;
  84. break;
  85. case IRQ_TYPE_LEVEL_LOW:
  86. newvalue = S5P_IRQ_TYPE_LEVEL_LOW;
  87. break;
  88. case IRQ_TYPE_LEVEL_HIGH:
  89. newvalue = S5P_IRQ_TYPE_LEVEL_HIGH;
  90. break;
  91. default:
  92. printk(KERN_ERR "No such irq type %d", type);
  93. return -EINVAL;
  94. }
  95. shift = (offs & 0x7) * 4;
  96. mask = 0x7 << shift;
  97. spin_lock(&eint_lock);
  98. ctrl = __raw_readl(S5P_EINT_CON(EINT_REG_NR(irq)));
  99. ctrl &= ~mask;
  100. ctrl |= newvalue << shift;
  101. __raw_writel(ctrl, S5P_EINT_CON(EINT_REG_NR(irq)));
  102. spin_unlock(&eint_lock);
  103. switch (offs) {
  104. case 0 ... 7:
  105. s3c_gpio_cfgpin(EINT_GPIO_0(offs & 0x7), EINT_MODE);
  106. break;
  107. case 8 ... 15:
  108. s3c_gpio_cfgpin(EINT_GPIO_1(offs & 0x7), EINT_MODE);
  109. break;
  110. case 16 ... 23:
  111. s3c_gpio_cfgpin(EINT_GPIO_2(offs & 0x7), EINT_MODE);
  112. break;
  113. case 24 ... 31:
  114. s3c_gpio_cfgpin(EINT_GPIO_3(offs & 0x7), EINT_MODE);
  115. break;
  116. default:
  117. printk(KERN_ERR "No such irq number %d", offs);
  118. }
  119. return 0;
  120. }
  121. static struct irq_chip s5pv310_irq_eint = {
  122. .name = "s5pv310-eint",
  123. .mask = s5pv310_irq_eint_mask,
  124. .unmask = s5pv310_irq_eint_unmask,
  125. .mask_ack = s5pv310_irq_eint_maskack,
  126. .ack = s5pv310_irq_eint_ack,
  127. .set_type = s5pv310_irq_eint_set_type,
  128. #ifdef CONFIG_PM
  129. .set_wake = s3c_irqext_wake,
  130. #endif
  131. };
  132. /* s5pv310_irq_demux_eint
  133. *
  134. * This function demuxes the IRQ from from EINTs 16 to 31.
  135. * It is designed to be inlined into the specific handler
  136. * s5p_irq_demux_eintX_Y.
  137. *
  138. * Each EINT pend/mask registers handle eight of them.
  139. */
  140. static inline void s5pv310_irq_demux_eint(unsigned int start)
  141. {
  142. unsigned int irq;
  143. u32 status = __raw_readl(S5P_EINT_PEND(EINT_REG_NR(start)));
  144. u32 mask = __raw_readl(S5P_EINT_MASK(EINT_REG_NR(start)));
  145. status &= ~mask;
  146. status &= 0xff;
  147. while (status) {
  148. irq = fls(status) - 1;
  149. generic_handle_irq(irq + start);
  150. status &= ~(1 << irq);
  151. }
  152. }
  153. static void s5pv310_irq_demux_eint16_31(unsigned int irq, struct irq_desc *desc)
  154. {
  155. s5pv310_irq_demux_eint(IRQ_EINT(16));
  156. s5pv310_irq_demux_eint(IRQ_EINT(24));
  157. }
  158. static void s5pv310_irq_eint0_15(unsigned int irq, struct irq_desc *desc)
  159. {
  160. u32 *irq_data = get_irq_data(irq);
  161. struct irq_chip *chip = get_irq_chip(irq);
  162. chip->mask(irq);
  163. if (chip->ack)
  164. chip->ack(irq);
  165. generic_handle_irq(*irq_data);
  166. chip->unmask(irq);
  167. }
  168. int __init s5pv310_init_irq_eint(void)
  169. {
  170. int irq;
  171. for (irq = 0 ; irq <= 31 ; irq++) {
  172. set_irq_chip(IRQ_EINT(irq), &s5pv310_irq_eint);
  173. set_irq_handler(IRQ_EINT(irq), handle_level_irq);
  174. set_irq_flags(IRQ_EINT(irq), IRQF_VALID);
  175. }
  176. set_irq_chained_handler(IRQ_EINT16_31, s5pv310_irq_demux_eint16_31);
  177. for (irq = 0 ; irq <= 15 ; irq++) {
  178. eint0_15_data[irq] = IRQ_EINT(irq);
  179. set_irq_data(s5pv310_get_irq_nr(irq), &eint0_15_data[irq]);
  180. set_irq_chained_handler(s5pv310_get_irq_nr(irq),
  181. s5pv310_irq_eint0_15);
  182. }
  183. return 0;
  184. }
  185. arch_initcall(s5pv310_init_irq_eint);