irq-eint.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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/device.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(struct irq_data *data)
  26. {
  27. u32 mask;
  28. mask = __raw_readl(S5P_EINT_MASK(EINT_REG_NR(data->irq)));
  29. mask |= eint_irq_to_bit(data->irq);
  30. __raw_writel(mask, S5P_EINT_MASK(EINT_REG_NR(data->irq)));
  31. }
  32. static void s5p_irq_eint_unmask(struct irq_data *data)
  33. {
  34. u32 mask;
  35. mask = __raw_readl(S5P_EINT_MASK(EINT_REG_NR(data->irq)));
  36. mask &= ~(eint_irq_to_bit(data->irq));
  37. __raw_writel(mask, S5P_EINT_MASK(EINT_REG_NR(data->irq)));
  38. }
  39. static inline void s5p_irq_eint_ack(struct irq_data *data)
  40. {
  41. __raw_writel(eint_irq_to_bit(data->irq),
  42. S5P_EINT_PEND(EINT_REG_NR(data->irq)));
  43. }
  44. static void s5p_irq_eint_maskack(struct irq_data *data)
  45. {
  46. /* compiler should in-line these */
  47. s5p_irq_eint_mask(data);
  48. s5p_irq_eint_ack(data);
  49. }
  50. static int s5p_irq_eint_set_type(struct irq_data *data, unsigned int type)
  51. {
  52. int offs = EINT_OFFSET(data->irq);
  53. int shift;
  54. u32 ctrl, mask;
  55. u32 newvalue = 0;
  56. switch (type) {
  57. case IRQ_TYPE_EDGE_RISING:
  58. newvalue = S5P_IRQ_TYPE_EDGE_RISING;
  59. break;
  60. case IRQ_TYPE_EDGE_FALLING:
  61. newvalue = S5P_IRQ_TYPE_EDGE_FALLING;
  62. break;
  63. case IRQ_TYPE_EDGE_BOTH:
  64. newvalue = S5P_IRQ_TYPE_EDGE_BOTH;
  65. break;
  66. case IRQ_TYPE_LEVEL_LOW:
  67. newvalue = S5P_IRQ_TYPE_LEVEL_LOW;
  68. break;
  69. case IRQ_TYPE_LEVEL_HIGH:
  70. newvalue = S5P_IRQ_TYPE_LEVEL_HIGH;
  71. break;
  72. default:
  73. printk(KERN_ERR "No such irq type %d", type);
  74. return -EINVAL;
  75. }
  76. shift = (offs & 0x7) * 4;
  77. mask = 0x7 << shift;
  78. ctrl = __raw_readl(S5P_EINT_CON(EINT_REG_NR(data->irq)));
  79. ctrl &= ~mask;
  80. ctrl |= newvalue << shift;
  81. __raw_writel(ctrl, S5P_EINT_CON(EINT_REG_NR(data->irq)));
  82. if ((0 <= offs) && (offs < 8))
  83. s3c_gpio_cfgpin(EINT_GPIO_0(offs & 0x7), EINT_MODE);
  84. else if ((8 <= offs) && (offs < 16))
  85. s3c_gpio_cfgpin(EINT_GPIO_1(offs & 0x7), EINT_MODE);
  86. else if ((16 <= offs) && (offs < 24))
  87. s3c_gpio_cfgpin(EINT_GPIO_2(offs & 0x7), EINT_MODE);
  88. else if ((24 <= offs) && (offs < 32))
  89. s3c_gpio_cfgpin(EINT_GPIO_3(offs & 0x7), EINT_MODE);
  90. else
  91. printk(KERN_ERR "No such irq number %d", offs);
  92. return 0;
  93. }
  94. static struct irq_chip s5p_irq_eint = {
  95. .name = "s5p-eint",
  96. .irq_mask = s5p_irq_eint_mask,
  97. .irq_unmask = s5p_irq_eint_unmask,
  98. .irq_mask_ack = s5p_irq_eint_maskack,
  99. .irq_ack = s5p_irq_eint_ack,
  100. .irq_set_type = s5p_irq_eint_set_type,
  101. #ifdef CONFIG_PM
  102. .irq_set_wake = s3c_irqext_wake,
  103. #endif
  104. };
  105. /* s5p_irq_demux_eint
  106. *
  107. * This function demuxes the IRQ from the group0 external interrupts,
  108. * from EINTs 16 to 31. It is designed to be inlined into the specific
  109. * handler s5p_irq_demux_eintX_Y.
  110. *
  111. * Each EINT pend/mask registers handle eight of them.
  112. */
  113. static inline void s5p_irq_demux_eint(unsigned int start)
  114. {
  115. u32 status = __raw_readl(S5P_EINT_PEND(EINT_REG_NR(start)));
  116. u32 mask = __raw_readl(S5P_EINT_MASK(EINT_REG_NR(start)));
  117. unsigned int irq;
  118. status &= ~mask;
  119. status &= 0xff;
  120. while (status) {
  121. irq = fls(status) - 1;
  122. generic_handle_irq(irq + start);
  123. status &= ~(1 << irq);
  124. }
  125. }
  126. static void s5p_irq_demux_eint16_31(unsigned int irq, struct irq_desc *desc)
  127. {
  128. s5p_irq_demux_eint(IRQ_EINT(16));
  129. s5p_irq_demux_eint(IRQ_EINT(24));
  130. }
  131. static inline void s5p_irq_vic_eint_mask(struct irq_data *data)
  132. {
  133. void __iomem *base = irq_data_get_irq_chip_data(data);
  134. s5p_irq_eint_mask(data);
  135. writel(1 << EINT_OFFSET(data->irq), base + VIC_INT_ENABLE_CLEAR);
  136. }
  137. static void s5p_irq_vic_eint_unmask(struct irq_data *data)
  138. {
  139. void __iomem *base = irq_data_get_irq_chip_data(data);
  140. s5p_irq_eint_unmask(data);
  141. writel(1 << EINT_OFFSET(data->irq), base + VIC_INT_ENABLE);
  142. }
  143. static inline void s5p_irq_vic_eint_ack(struct irq_data *data)
  144. {
  145. __raw_writel(eint_irq_to_bit(data->irq),
  146. S5P_EINT_PEND(EINT_REG_NR(data->irq)));
  147. }
  148. static void s5p_irq_vic_eint_maskack(struct irq_data *data)
  149. {
  150. s5p_irq_vic_eint_mask(data);
  151. s5p_irq_vic_eint_ack(data);
  152. }
  153. static struct irq_chip s5p_irq_vic_eint = {
  154. .name = "s5p_vic_eint",
  155. .irq_mask = s5p_irq_vic_eint_mask,
  156. .irq_unmask = s5p_irq_vic_eint_unmask,
  157. .irq_mask_ack = s5p_irq_vic_eint_maskack,
  158. .irq_ack = s5p_irq_vic_eint_ack,
  159. .irq_set_type = s5p_irq_eint_set_type,
  160. #ifdef CONFIG_PM
  161. .irq_set_wake = s3c_irqext_wake,
  162. #endif
  163. };
  164. static int __init s5p_init_irq_eint(void)
  165. {
  166. int irq;
  167. for (irq = IRQ_EINT(0); irq <= IRQ_EINT(15); irq++)
  168. irq_set_chip(irq, &s5p_irq_vic_eint);
  169. for (irq = IRQ_EINT(16); irq <= IRQ_EINT(31); irq++) {
  170. irq_set_chip_and_handler(irq, &s5p_irq_eint, handle_level_irq);
  171. set_irq_flags(irq, IRQF_VALID);
  172. }
  173. irq_set_chained_handler(IRQ_EINT16_31, s5p_irq_demux_eint16_31);
  174. return 0;
  175. }
  176. arch_initcall(s5p_init_irq_eint);