irq-eint.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. /* linux/arch/arm/mach-exynos4/irq-eint.c
  2. *
  3. * Copyright (c) 2010-2011 Samsung Electronics Co., Ltd.
  4. * http://www.samsung.com
  5. *
  6. * EXYNOS4 - 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 exynos4_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 exynos4_irq_eint_mask(struct irq_data *data)
  43. {
  44. u32 mask;
  45. spin_lock(&eint_lock);
  46. mask = __raw_readl(S5P_EINT_MASK(EINT_REG_NR(data->irq)));
  47. mask |= eint_irq_to_bit(data->irq);
  48. __raw_writel(mask, S5P_EINT_MASK(EINT_REG_NR(data->irq)));
  49. spin_unlock(&eint_lock);
  50. }
  51. static void exynos4_irq_eint_unmask(struct irq_data *data)
  52. {
  53. u32 mask;
  54. spin_lock(&eint_lock);
  55. mask = __raw_readl(S5P_EINT_MASK(EINT_REG_NR(data->irq)));
  56. mask &= ~(eint_irq_to_bit(data->irq));
  57. __raw_writel(mask, S5P_EINT_MASK(EINT_REG_NR(data->irq)));
  58. spin_unlock(&eint_lock);
  59. }
  60. static inline void exynos4_irq_eint_ack(struct irq_data *data)
  61. {
  62. __raw_writel(eint_irq_to_bit(data->irq),
  63. S5P_EINT_PEND(EINT_REG_NR(data->irq)));
  64. }
  65. static void exynos4_irq_eint_maskack(struct irq_data *data)
  66. {
  67. exynos4_irq_eint_mask(data);
  68. exynos4_irq_eint_ack(data);
  69. }
  70. static int exynos4_irq_eint_set_type(struct irq_data *data, unsigned int type)
  71. {
  72. int offs = EINT_OFFSET(data->irq);
  73. int shift;
  74. u32 ctrl, mask;
  75. u32 newvalue = 0;
  76. switch (type) {
  77. case IRQ_TYPE_EDGE_RISING:
  78. newvalue = S5P_IRQ_TYPE_EDGE_RISING;
  79. break;
  80. case IRQ_TYPE_EDGE_FALLING:
  81. newvalue = S5P_IRQ_TYPE_EDGE_FALLING;
  82. break;
  83. case IRQ_TYPE_EDGE_BOTH:
  84. newvalue = S5P_IRQ_TYPE_EDGE_BOTH;
  85. break;
  86. case IRQ_TYPE_LEVEL_LOW:
  87. newvalue = S5P_IRQ_TYPE_LEVEL_LOW;
  88. break;
  89. case IRQ_TYPE_LEVEL_HIGH:
  90. newvalue = S5P_IRQ_TYPE_LEVEL_HIGH;
  91. break;
  92. default:
  93. printk(KERN_ERR "No such irq type %d", type);
  94. return -EINVAL;
  95. }
  96. shift = (offs & 0x7) * 4;
  97. mask = 0x7 << shift;
  98. spin_lock(&eint_lock);
  99. ctrl = __raw_readl(S5P_EINT_CON(EINT_REG_NR(data->irq)));
  100. ctrl &= ~mask;
  101. ctrl |= newvalue << shift;
  102. __raw_writel(ctrl, S5P_EINT_CON(EINT_REG_NR(data->irq)));
  103. spin_unlock(&eint_lock);
  104. switch (offs) {
  105. case 0 ... 7:
  106. s3c_gpio_cfgpin(EINT_GPIO_0(offs & 0x7), EINT_MODE);
  107. break;
  108. case 8 ... 15:
  109. s3c_gpio_cfgpin(EINT_GPIO_1(offs & 0x7), EINT_MODE);
  110. break;
  111. case 16 ... 23:
  112. s3c_gpio_cfgpin(EINT_GPIO_2(offs & 0x7), EINT_MODE);
  113. break;
  114. case 24 ... 31:
  115. s3c_gpio_cfgpin(EINT_GPIO_3(offs & 0x7), EINT_MODE);
  116. break;
  117. default:
  118. printk(KERN_ERR "No such irq number %d", offs);
  119. }
  120. return 0;
  121. }
  122. static struct irq_chip exynos4_irq_eint = {
  123. .name = "exynos4-eint",
  124. .irq_mask = exynos4_irq_eint_mask,
  125. .irq_unmask = exynos4_irq_eint_unmask,
  126. .irq_mask_ack = exynos4_irq_eint_maskack,
  127. .irq_ack = exynos4_irq_eint_ack,
  128. .irq_set_type = exynos4_irq_eint_set_type,
  129. #ifdef CONFIG_PM
  130. .irq_set_wake = s3c_irqext_wake,
  131. #endif
  132. };
  133. /* exynos4_irq_demux_eint
  134. *
  135. * This function demuxes the IRQ from from EINTs 16 to 31.
  136. * It is designed to be inlined into the specific handler
  137. * s5p_irq_demux_eintX_Y.
  138. *
  139. * Each EINT pend/mask registers handle eight of them.
  140. */
  141. static inline void exynos4_irq_demux_eint(unsigned int start)
  142. {
  143. unsigned int irq;
  144. u32 status = __raw_readl(S5P_EINT_PEND(EINT_REG_NR(start)));
  145. u32 mask = __raw_readl(S5P_EINT_MASK(EINT_REG_NR(start)));
  146. status &= ~mask;
  147. status &= 0xff;
  148. while (status) {
  149. irq = fls(status) - 1;
  150. generic_handle_irq(irq + start);
  151. status &= ~(1 << irq);
  152. }
  153. }
  154. static void exynos4_irq_demux_eint16_31(unsigned int irq, struct irq_desc *desc)
  155. {
  156. exynos4_irq_demux_eint(IRQ_EINT(16));
  157. exynos4_irq_demux_eint(IRQ_EINT(24));
  158. }
  159. static void exynos4_irq_eint0_15(unsigned int irq, struct irq_desc *desc)
  160. {
  161. u32 *irq_data = irq_get_handler_data(irq);
  162. struct irq_chip *chip = irq_get_chip(irq);
  163. chip->irq_mask(&desc->irq_data);
  164. if (chip->irq_ack)
  165. chip->irq_ack(&desc->irq_data);
  166. generic_handle_irq(*irq_data);
  167. chip->irq_unmask(&desc->irq_data);
  168. }
  169. int __init exynos4_init_irq_eint(void)
  170. {
  171. int irq;
  172. for (irq = 0 ; irq <= 31 ; irq++) {
  173. irq_set_chip_and_handler(IRQ_EINT(irq), &exynos4_irq_eint,
  174. handle_level_irq);
  175. set_irq_flags(IRQ_EINT(irq), IRQF_VALID);
  176. }
  177. irq_set_chained_handler(IRQ_EINT16_31, exynos4_irq_demux_eint16_31);
  178. for (irq = 0 ; irq <= 15 ; irq++) {
  179. eint0_15_data[irq] = IRQ_EINT(irq);
  180. irq_set_handler_data(exynos4_get_irq_nr(irq),
  181. &eint0_15_data[irq]);
  182. irq_set_chained_handler(exynos4_get_irq_nr(irq),
  183. exynos4_irq_eint0_15);
  184. }
  185. return 0;
  186. }
  187. arch_initcall(exynos4_init_irq_eint);