fpga.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. /*
  2. * linux/arch/arm/mach-omap1/fpga.c
  3. *
  4. * Interrupt handler for OMAP-1510 Innovator FPGA
  5. *
  6. * Copyright (C) 2001 RidgeRun, Inc.
  7. * Author: Greg Lonnon <glonnon@ridgerun.com>
  8. *
  9. * Copyright (C) 2002 MontaVista Software, Inc.
  10. *
  11. * Separated FPGA interrupts from innovator1510.c and cleaned up for 2.6
  12. * Copyright (C) 2004 Nokia Corporation by Tony Lindrgen <tony@atomide.com>
  13. *
  14. * This program is free software; you can redistribute it and/or modify
  15. * it under the terms of the GNU General Public License version 2 as
  16. * published by the Free Software Foundation.
  17. */
  18. #include <linux/types.h>
  19. #include <linux/init.h>
  20. #include <linux/kernel.h>
  21. #include <linux/device.h>
  22. #include <linux/errno.h>
  23. #include <linux/io.h>
  24. #include <mach/hardware.h>
  25. #include <asm/irq.h>
  26. #include <asm/mach/irq.h>
  27. #include <plat/fpga.h>
  28. #include <mach/gpio.h>
  29. static void fpga_mask_irq(struct irq_data *d)
  30. {
  31. unsigned int irq = d->irq - OMAP_FPGA_IRQ_BASE;
  32. if (irq < 8)
  33. __raw_writeb((__raw_readb(OMAP1510_FPGA_IMR_LO)
  34. & ~(1 << irq)), OMAP1510_FPGA_IMR_LO);
  35. else if (irq < 16)
  36. __raw_writeb((__raw_readb(OMAP1510_FPGA_IMR_HI)
  37. & ~(1 << (irq - 8))), OMAP1510_FPGA_IMR_HI);
  38. else
  39. __raw_writeb((__raw_readb(INNOVATOR_FPGA_IMR2)
  40. & ~(1 << (irq - 16))), INNOVATOR_FPGA_IMR2);
  41. }
  42. static inline u32 get_fpga_unmasked_irqs(void)
  43. {
  44. return
  45. ((__raw_readb(OMAP1510_FPGA_ISR_LO) &
  46. __raw_readb(OMAP1510_FPGA_IMR_LO))) |
  47. ((__raw_readb(OMAP1510_FPGA_ISR_HI) &
  48. __raw_readb(OMAP1510_FPGA_IMR_HI)) << 8) |
  49. ((__raw_readb(INNOVATOR_FPGA_ISR2) &
  50. __raw_readb(INNOVATOR_FPGA_IMR2)) << 16);
  51. }
  52. static void fpga_ack_irq(struct irq_data *d)
  53. {
  54. /* Don't need to explicitly ACK FPGA interrupts */
  55. }
  56. static void fpga_unmask_irq(struct irq_data *d)
  57. {
  58. unsigned int irq = d->irq - OMAP_FPGA_IRQ_BASE;
  59. if (irq < 8)
  60. __raw_writeb((__raw_readb(OMAP1510_FPGA_IMR_LO) | (1 << irq)),
  61. OMAP1510_FPGA_IMR_LO);
  62. else if (irq < 16)
  63. __raw_writeb((__raw_readb(OMAP1510_FPGA_IMR_HI)
  64. | (1 << (irq - 8))), OMAP1510_FPGA_IMR_HI);
  65. else
  66. __raw_writeb((__raw_readb(INNOVATOR_FPGA_IMR2)
  67. | (1 << (irq - 16))), INNOVATOR_FPGA_IMR2);
  68. }
  69. static void fpga_mask_ack_irq(struct irq_data *d)
  70. {
  71. fpga_mask_irq(d);
  72. fpga_ack_irq(d);
  73. }
  74. void innovator_fpga_IRQ_demux(unsigned int irq, struct irq_desc *desc)
  75. {
  76. u32 stat;
  77. int fpga_irq;
  78. stat = get_fpga_unmasked_irqs();
  79. if (!stat)
  80. return;
  81. for (fpga_irq = OMAP_FPGA_IRQ_BASE;
  82. (fpga_irq < OMAP_FPGA_IRQ_END) && stat;
  83. fpga_irq++, stat >>= 1) {
  84. if (stat & 1) {
  85. generic_handle_irq(fpga_irq);
  86. }
  87. }
  88. }
  89. static struct irq_chip omap_fpga_irq_ack = {
  90. .name = "FPGA-ack",
  91. .irq_ack = fpga_mask_ack_irq,
  92. .irq_mask = fpga_mask_irq,
  93. .irq_unmask = fpga_unmask_irq,
  94. };
  95. static struct irq_chip omap_fpga_irq = {
  96. .name = "FPGA",
  97. .irq_ack = fpga_ack_irq,
  98. .irq_mask = fpga_mask_irq,
  99. .irq_unmask = fpga_unmask_irq,
  100. };
  101. /*
  102. * All of the FPGA interrupt request inputs except for the touchscreen are
  103. * edge-sensitive; the touchscreen is level-sensitive. The edge-sensitive
  104. * interrupts are acknowledged as a side-effect of reading the interrupt
  105. * status register from the FPGA. The edge-sensitive interrupt inputs
  106. * cause a problem with level interrupt requests, such as Ethernet. The
  107. * problem occurs when a level interrupt request is asserted while its
  108. * interrupt input is masked in the FPGA, which results in a missed
  109. * interrupt.
  110. *
  111. * In an attempt to workaround the problem with missed interrupts, the
  112. * mask_ack routine for all of the FPGA interrupts has been changed from
  113. * fpga_mask_ack_irq() to fpga_ack_irq() so that the specific FPGA interrupt
  114. * being serviced is left unmasked. We can do this because the FPGA cascade
  115. * interrupt is installed with the IRQF_DISABLED flag, which leaves all
  116. * interrupts masked at the CPU while an FPGA interrupt handler executes.
  117. *
  118. * Limited testing indicates that this workaround appears to be effective
  119. * for the smc9194 Ethernet driver used on the Innovator. It should work
  120. * on other FPGA interrupts as well, but any drivers that explicitly mask
  121. * interrupts at the interrupt controller via disable_irq/enable_irq
  122. * could pose a problem.
  123. */
  124. void omap1510_fpga_init_irq(void)
  125. {
  126. int i, res;
  127. __raw_writeb(0, OMAP1510_FPGA_IMR_LO);
  128. __raw_writeb(0, OMAP1510_FPGA_IMR_HI);
  129. __raw_writeb(0, INNOVATOR_FPGA_IMR2);
  130. for (i = OMAP_FPGA_IRQ_BASE; i < OMAP_FPGA_IRQ_END; i++) {
  131. if (i == OMAP1510_INT_FPGA_TS) {
  132. /*
  133. * The touchscreen interrupt is level-sensitive, so
  134. * we'll use the regular mask_ack routine for it.
  135. */
  136. irq_set_chip(i, &omap_fpga_irq_ack);
  137. }
  138. else {
  139. /*
  140. * All FPGA interrupts except the touchscreen are
  141. * edge-sensitive, so we won't mask them.
  142. */
  143. irq_set_chip(i, &omap_fpga_irq);
  144. }
  145. irq_set_handler(i, handle_edge_irq);
  146. set_irq_flags(i, IRQF_VALID);
  147. }
  148. /*
  149. * The FPGA interrupt line is connected to GPIO13. Claim this pin for
  150. * the ARM.
  151. *
  152. * NOTE: For general GPIO/MPUIO access and interrupts, please see
  153. * gpio.[ch]
  154. */
  155. res = gpio_request(13, "FPGA irq");
  156. if (res) {
  157. pr_err("%s failed to get gpio\n", __func__);
  158. return;
  159. }
  160. gpio_direction_input(13);
  161. irq_set_irq_type(gpio_to_irq(13), IRQ_TYPE_EDGE_RISING);
  162. irq_set_chained_handler(OMAP1510_INT_FPGA, innovator_fpga_IRQ_demux);
  163. }