fpga.c 5.1 KB

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