memoryDefinitionHeterogeneousSynchronous.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. /* linux/arch/arm/plat-s3c24xx/irq.c
  2. *
  3. * Copyright (c) 2003-2004 Simtec Electronics
  4. * Ben Dooks <ben@simtec.co.uk>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. */
  20. #include <linux/init.h>
  21. #include <linux/module.h>
  22. #include <linux/interrupt.h>
  23. #include <linux/ioport.h>
  24. #include <linux/device.h>
  25. #include <linux/syscore_ops.h>
  26. #include <asm/irq.h>
  27. #include <asm/mach/irq.h>
  28. #include <plat/regs-irqtype.h>
  29. #include <plat/cpu.h>
  30. #include <plat/pm.h>
  31. #include <plat/irq.h>
  32. static void
  33. s3c_irq_mask(struct irq_data *data)
  34. {
  35. unsigned int irqno = data->irq - IRQ_EINT0;
  36. unsigned long mask;
  37. mask = __raw_readl(S3C2410_INTMSK);
  38. mask |= 1UL << irqno;
  39. __raw_writel(mask, S3C2410_INTMSK);
  40. }
  41. static inline void
  42. s3c_irq_ack(struct irq_data *data)
  43. {
  44. unsigned long bitval = 1UL << (data->irq - IRQ_EINT0);
  45. __raw_writel(bitval, S3C2410_SRCPND);
  46. __raw_writel(bitval, S3C2410_INTPND);
  47. }
  48. static inline void
  49. s3c_irq_maskack(struct irq_data *data)
  50. {
  51. unsigned long bitval = 1UL << (data->irq - IRQ_EINT0);
  52. unsigned long mask;
  53. mask = __raw_readl(S3C2410_INTMSK);
  54. __raw_writel(mask|bitval, S3C2410_INTMSK);
  55. __raw_writel(bitval, S3C2410_SRCPND);
  56. __raw_writel(bitval, S3C2410_INTPND);
  57. }
  58. static void
  59. s3c_irq_unmask(struct irq_data *data)
  60. {
  61. unsigned int irqno = data->irq;
  62. unsigned long mask;
  63. if (irqno != IRQ_TIMER4 && irqno != IRQ_EINT8t23)
  64. irqdbf2("s3c_irq_unmask %d\n", irqno);
  65. irqno -= IRQ_EINT0;
  66. mask = __raw_readl(S3C2410_INTMSK);
  67. mask &= ~(1UL << irqno);
  68. __raw_writel(mask, S3C2410_INTMSK);
  69. }
  70. struct irq_chip s3c_irq_level_chip = {
  71. .name = "s3c-level",
  72. .irq_ack = s3c_irq_maskack,
  73. .irq_mask = s3c_irq_mask,
  74. .irq_unmask = s3c_irq_unmask,
  75. .irq_set_wake = s3c_irq_wake
  76. };
  77. struct irq_chip s3c_irq_chip = {
  78. .name = "s3c",
  79. .irq_ack = s3c_irq_ack,
  80. .irq_mask = s3c_irq_mask,
  81. .irq_unmask = s3c_irq_unmask,
  82. .irq_set_wake = s3c_irq_wake
  83. };
  84. static void
  85. s3c_irqext_mask(struct irq_data *data)
  86. {
  87. unsigned int irqno = data->irq - EXTINT_OFF;
  88. unsigned long mask;
  89. mask = __raw_readl(S3C24XX_EINTMASK);
  90. mask |= ( 1UL << irqno);
  91. __raw_writel(mask, S3C24XX_EINTMASK);
  92. }
  93. static void
  94. s3c_irqext_ack(struct irq_data *data)
  95. {
  96. unsigned long req;
  97. unsigned long bit;
  98. unsigned long mask;
  99. bit = 1UL << (data->irq - EXTINT_OFF);
  100. mask = __raw_readl(S3C24XX_EINTMASK);
  101. __raw_writel(bit, S3C24XX_EINTPEND);
  102. req = __raw_readl(S3C24XX_EINTPEND);
  103. req &= ~mask;
  104. /* not sure if we should be acking the parent irq... */
  105. if (data->irq <= IRQ_EINT7) {
  106. if ((req & 0xf0) == 0)
  107. s3c_irq_ack(irq_get_irq_data(IRQ_EINT4t7));
  108. } else {
  109. if ((req >> 8) == 0)
  110. s3c_irq_ack(irq_get_irq_data(IRQ_EINT8t23));
  111. }
  112. }
  113. static void
  114. s3c_irqext_unmask(struct irq_data *data)
  115. {
  116. unsigned int irqno = data->irq - EXTINT_OFF;
  117. unsigned long mask;
  118. mask = __raw_readl(S3C24XX_EINTMASK);
  119. mask &= ~(1UL << irqno);
  120. __raw_writel(mask, S3C24XX_EINTMASK);
  121. }
  122. int
  123. s3c_irqext_type(struct irq_data *data, unsigned int type)
  124. {
  125. void __iomem *extint_reg;
  126. void __iomem *gpcon_reg;
  127. unsigned long gpcon_offset, extint_offset;
  128. unsigned long newvalue = 0, value;
  129. if ((data->irq >= IRQ_EINT0) && (data->irq <= IRQ_EINT3)) {
  130. gpcon_reg = S3C2410_GPFCON;
  131. extint_reg = S3C24XX_EXTINT0;
  132. gpcon_offset = (data->irq - IRQ_EINT0) * 2;
  133. extint_offset = (data->irq - IRQ_EINT0) * 4;
  134. } else if ((data->irq >= IRQ_EINT4) && (data->irq <= IRQ_EINT7)) {
  135. gpcon_reg = S3C2410_GPFCON;
  136. extint_reg = S3C24XX_EXTINT0;
  137. gpcon_offset = (data->irq - (EXTINT_OFF)) * 2;
  138. extint_offset = (data->irq - (EXTINT_OFF)) * 4;
  139. } else if ((data->irq >= IRQ_EINT8) && (data->irq <= IRQ_EINT15)) {
  140. gpcon_reg = S3C2410_GPGCON;
  141. extint_reg = S3C24XX_EXTINT1;
  142. gpcon_offset = (data->irq - IRQ_EINT8) * 2;
  143. extint_offset = (data->irq - IRQ_EINT8) * 4;
  144. } else if ((data->irq >= IRQ_EINT16) && (data->irq <= IRQ_EINT23)) {
  145. gpcon_reg = S3C2410_GPGCON;
  146. extint_reg = S3C24XX_EXTINT2;
  147. gpcon_offset = (data->irq - IRQ_EINT8) * 2;
  148. extint_offset = (data->irq - IRQ_EINT16) * 4;
  149. } else {
  150. return -1;
  151. }
  152. /* Set the GPIO to external interrupt mode */
  153. value = __raw_readl(gpcon_reg);
  154. value = (value & ~(3 << gpcon_offset)) | (0x02 << gpcon_offset);
  155. __raw_writel(value, gpcon_reg);
  156. /* Set the external interrupt to pointed trigger type */
  157. switch (type)
  158. {
  159. case IRQ_TYPE_NONE:
  160. printk(KERN_WARNING "No edge setting!\n");
  161. break;
  162. case IRQ_TYPE_EDGE_RISING:
  163. newvalue = S3C2410_EXTINT_RISEEDGE;
  164. break;
  165. case IRQ_TYPE_EDGE_FALLING:
  166. newvalue = S3C2410_EXTINT_FALLEDGE;
  167. break;
  168. case IRQ_TYPE_EDGE_BOTH:
  169. newvalue = S3C2410_EXTINT_BOTHEDGE;
  170. break;
  171. case IRQ_TYPE_LEVEL_LOW:
  172. newvalue = S3C2410_EXTINT_LOWLEV;
  173. break;
  174. case IRQ_TYPE_LEVEL_HIGH:
  175. newvalue = S3C2410_EXTINT_HILEV;
  176. break;
  177. default:
  178. printk(KERN_ERR "No such irq type %d", type);
  179. return -1;
  180. }
  181. value = __raw_readl(extint_reg);
  182. value = (value & ~(7 << extint_offset)) | (newvalue << extint_offset);
  183. __raw_writel(value, extint_reg);
  184. return 0;
  185. }
  186. static struct irq_chip s3c_irqext_chip = {
  187. .name = "s3c-ext",
  188. .irq_mask = s3c_irqext_mask,
  189. .irq_unmask = s3c_irqext_unmask,
  190. .irq_ack = s3c_irqext_ack,
  191. .irq_set_type = s3c_irqext_type,
  192. .irq_set_wake = s3c_irqext_wake
  193. };
  194. static struct irq_chip s3c_irq_eint0t4 = {
  195. .name = "s3c-ext0",
  196. .irq_ack = s3c_irq_ack,
  197. .irq_mask = s3c_irq_mask,
  198. .irq_unmask = s3c_irq_unmask,
  199. .irq_set_wake = s3c_irq_wake,
  200. .irq_set_type = s3c_irqext_type,
  201. };
  202. /* mask values for the parent registers for each of the interrupt types */
  203. #define INTMSK_UART0 (1UL << (IRQ_UART0 - IRQ_EINT0))
  204. #define INTMSK_UART1 (1UL << (IRQ_UART1 - IRQ_EINT0))
  205. #define INTMSK_UART2 (1UL << (IRQ_UART2 - IRQ_EINT0))
  206. #define INTMSK_ADCPARENT (1UL << (IRQ_ADCPARENT - IRQ_EINT0))
  207. /* UART0 */
  208. static void
  209. s3c_irq_uart0_mask(struct irq_data *data)
  210. {
  211. s3c_irqsub_mask(data->irq, INTMSK_UART0, 7);