s5p-irq-eint.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. /*
  2. * Copyright (c) 2010 Samsung Electronics Co., Ltd.
  3. * http://www.samsung.com
  4. *
  5. * S5P - IRQ EINT support
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. */
  11. #include <linux/kernel.h>
  12. #include <linux/interrupt.h>
  13. #include <linux/irq.h>
  14. #include <linux/io.h>
  15. #include <linux/device.h>
  16. #include <linux/gpio.h>
  17. #include <linux/irqchip/arm-vic.h>
  18. #include <plat/regs-irqtype.h>
  19. #include <mach/map.h>
  20. #include <plat/cpu.h>
  21. #include <plat/pm.h>
  22. #include <plat/gpio-cfg.h>
  23. #include <mach/regs-gpio.h>
  24. static inline void s5p_irq_eint_mask(struct irq_data *data)
  25. {
  26. u32 mask;
  27. mask = __raw_readl(S5P_EINT_MASK(EINT_REG_NR(data->irq)));
  28. mask |= eint_irq_to_bit(data->irq);
  29. __raw_writel(mask, S5P_EINT_MASK(EINT_REG_NR(data->irq)));
  30. }
  31. static void s5p_irq_eint_unmask(struct irq_data *data)
  32. {
  33. u32 mask;
  34. mask = __raw_readl(S5P_EINT_MASK(EINT_REG_NR(data->irq)));
  35. mask &= ~(eint_irq_to_bit(data->irq));
  36. __raw_writel(mask, S5P_EINT_MASK(EINT_REG_NR(data->irq)));
  37. }
  38. static inline void s5p_irq_eint_ack(struct irq_data *data)
  39. {
  40. __raw_writel(eint_irq_to_bit(data->irq),
  41. S5P_EINT_PEND(EINT_REG_NR(data->irq)));
  42. }
  43. static void s5p_irq_eint_maskack(struct irq_data *data)
  44. {
  45. /* compiler should in-line these */
  46. s5p_irq_eint_mask(data);
  47. s5p_irq_eint_ack(data);
  48. }
  49. static int s5p_irq_eint_set_type(struct irq_data *data, unsigned int type)
  50. {
  51. int offs = EINT_OFFSET(data->irq);
  52. int shift;
  53. u32 ctrl, mask;
  54. u32 newvalue = 0;
  55. switch (type) {
  56. case IRQ_TYPE_EDGE_RISING:
  57. newvalue = S5P_IRQ_TYPE_EDGE_RISING;
  58. break;
  59. case IRQ_TYPE_EDGE_FALLING:
  60. newvalue = S5P_IRQ_TYPE_EDGE_FALLING;
  61. break;
  62. case IRQ_TYPE_EDGE_BOTH:
  63. newvalue = S5P_IRQ_TYPE_EDGE_BOTH;
  64. break;
  65. case IRQ_TYPE_LEVEL_LOW:
  66. newvalue = S5P_IRQ_TYPE_LEVEL_LOW;
  67. break;
  68. case IRQ_TYPE_LEVEL_HIGH:
  69. newvalue = S5P_IRQ_TYPE_LEVEL_HIGH;
  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(data->irq)));
  78. ctrl &= ~mask;
  79. ctrl |= newvalue << shift;
  80. __raw_writel(ctrl, S5P_EINT_CON(EINT_REG_NR(data->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. .irq_mask = s5p_irq_eint_mask,
  96. .irq_unmask = s5p_irq_eint_unmask,
  97. .irq_mask_ack = s5p_irq_eint_maskack,
  98. .irq_ack = s5p_irq_eint_ack,
  99. .irq_set_type = s5p_irq_eint_set_type,
  100. #ifdef CONFIG_PM
  101. .irq_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(struct irq_data *data)
  131. {
  132. void __iomem *base = irq_data_get_irq_chip_data(data);
  133. s5p_irq_eint_mask(data);
  134. writel(1 << EINT_OFFSET(data->irq), base + VIC_INT_ENABLE_CLEAR);
  135. }
  136. static void s5p_irq_vic_eint_unmask(struct irq_data *data)
  137. {
  138. void __iomem *base = irq_data_get_irq_chip_data(data);
  139. s5p_irq_eint_unmask(data);
  140. writel(1 << EINT_OFFSET(data->irq), base + VIC_INT_ENABLE);
  141. }
  142. static inline void s5p_irq_vic_eint_ack(struct irq_data *data)
  143. {
  144. __raw_writel(eint_irq_to_bit(data->irq),
  145. S5P_EINT_PEND(EINT_REG_NR(data->irq)));
  146. }
  147. static void s5p_irq_vic_eint_maskack(struct irq_data *data)
  148. {
  149. s5p_irq_vic_eint_mask(data);
  150. s5p_irq_vic_eint_ack(data);
  151. }
  152. static struct irq_chip s5p_irq_vic_eint = {
  153. .name = "s5p_vic_eint",
  154. .irq_mask = s5p_irq_vic_eint_mask,
  155. .irq_unmask = s5p_irq_vic_eint_unmask,
  156. .irq_mask_ack = s5p_irq_vic_eint_maskack,
  157. .irq_ack = s5p_irq_vic_eint_ack,
  158. .irq_set_type = s5p_irq_eint_set_type,
  159. #ifdef CONFIG_PM
  160. .irq_set_wake = s3c_irqext_wake,
  161. #endif
  162. };
  163. static int __init s5p_init_irq_eint(void)
  164. {
  165. int irq;
  166. for (irq = IRQ_EINT(0); irq <= IRQ_EINT(15); irq++)
  167. irq_set_chip(irq, &s5p_irq_vic_eint);
  168. for (irq = IRQ_EINT(16); irq <= IRQ_EINT(31); irq++) {
  169. irq_set_chip_and_handler(irq, &s5p_irq_eint, handle_level_irq);
  170. set_irq_flags(irq, IRQF_VALID);
  171. }
  172. irq_set_chained_handler(IRQ_EINT16_31, s5p_irq_demux_eint16_31);
  173. return 0;
  174. }
  175. arch_initcall(s5p_init_irq_eint);