irq-eint.c 5.3 KB

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