fpga.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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/config.h>
  19. #include <linux/types.h>
  20. #include <linux/init.h>
  21. #include <linux/kernel.h>
  22. #include <linux/device.h>
  23. #include <linux/errno.h>
  24. #include <asm/hardware.h>
  25. #include <asm/io.h>
  26. #include <asm/irq.h>
  27. #include <asm/mach/irq.h>
  28. #include <asm/arch/fpga.h>
  29. #include <asm/arch/gpio.h>
  30. static void fpga_mask_irq(unsigned int irq)
  31. {
  32. irq -= OMAP1510_IH_FPGA_BASE;
  33. if (irq < 8)
  34. __raw_writeb((__raw_readb(OMAP1510_FPGA_IMR_LO)
  35. & ~(1 << irq)), OMAP1510_FPGA_IMR_LO);
  36. else if (irq < 16)
  37. __raw_writeb((__raw_readb(OMAP1510_FPGA_IMR_HI)
  38. & ~(1 << (irq - 8))), OMAP1510_FPGA_IMR_HI);
  39. else
  40. __raw_writeb((__raw_readb(INNOVATOR_FPGA_IMR2)
  41. & ~(1 << (irq - 16))), INNOVATOR_FPGA_IMR2);
  42. }
  43. static inline u32 get_fpga_unmasked_irqs(void)
  44. {
  45. return
  46. ((__raw_readb(OMAP1510_FPGA_ISR_LO) &
  47. __raw_readb(OMAP1510_FPGA_IMR_LO))) |
  48. ((__raw_readb(OMAP1510_FPGA_ISR_HI) &
  49. __raw_readb(OMAP1510_FPGA_IMR_HI)) << 8) |
  50. ((__raw_readb(INNOVATOR_FPGA_ISR2) &
  51. __raw_readb(INNOVATOR_FPGA_IMR2)) << 16);
  52. }
  53. static void fpga_ack_irq(unsigned int irq)
  54. {
  55. /* Don't need to explicitly ACK FPGA interrupts */
  56. }
  57. static void fpga_unmask_irq(unsigned int irq)
  58. {
  59. irq -= OMAP1510_IH_FPGA_BASE;
  60. if (irq < 8)
  61. __raw_writeb((__raw_readb(OMAP1510_FPGA_IMR_LO) | (1 << irq)),
  62. OMAP1510_FPGA_IMR_LO);
  63. else if (irq < 16)
  64. __raw_writeb((__raw_readb(OMAP1510_FPGA_IMR_HI)
  65. | (1 << (irq - 8))), OMAP1510_FPGA_IMR_HI);
  66. else
  67. __raw_writeb((__raw_readb(INNOVATOR_FPGA_IMR2)
  68. | (1 << (irq - 16))), INNOVATOR_FPGA_IMR2);
  69. }
  70. static void fpga_mask_ack_irq(unsigned int irq)
  71. {
  72. fpga_mask_irq(irq);
  73. fpga_ack_irq(irq);
  74. }
  75. void innovator_fpga_IRQ_demux(unsigned int irq, struct irqdesc *desc,
  76. struct pt_regs *regs)
  77. {
  78. struct irqdesc *d;
  79. u32 stat;
  80. int fpga_irq;
  81. stat = get_fpga_unmasked_irqs();
  82. if (!stat)
  83. return;
  84. for (fpga_irq = OMAP1510_IH_FPGA_BASE;
  85. (fpga_irq < (OMAP1510_IH_FPGA_BASE + NR_FPGA_IRQS)) && stat;
  86. fpga_irq++, stat >>= 1) {
  87. if (stat & 1) {
  88. d = irq_desc + fpga_irq;
  89. desc_handle_irq(fpga_irq, d, regs);
  90. }
  91. }
  92. }
  93. static struct irqchip omap_fpga_irq_ack = {
  94. .ack = fpga_mask_ack_irq,
  95. .mask = fpga_mask_irq,
  96. .unmask = fpga_unmask_irq,
  97. };
  98. static struct irqchip omap_fpga_irq = {
  99. .ack = fpga_ack_irq,
  100. .mask = fpga_mask_irq,
  101. .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 installed with the SA_INTERRUPT flag, which leaves all
  118. * interrupts masked at the CPU while an FPGA interrupt handler executes.
  119. *
  120. * Limited testing indicates that this workaround appears to be effective
  121. * for the smc9194 Ethernet driver used on the Innovator. It should work
  122. * on other FPGA interrupts as well, but any drivers that explicitly mask
  123. * interrupts at the interrupt controller via disable_irq/enable_irq
  124. * could pose a problem.
  125. */
  126. void omap1510_fpga_init_irq(void)
  127. {
  128. int i;
  129. __raw_writeb(0, OMAP1510_FPGA_IMR_LO);
  130. __raw_writeb(0, OMAP1510_FPGA_IMR_HI);
  131. __raw_writeb(0, INNOVATOR_FPGA_IMR2);
  132. for (i = OMAP1510_IH_FPGA_BASE; i < (OMAP1510_IH_FPGA_BASE + NR_FPGA_IRQS); i++) {
  133. if (i == OMAP1510_INT_FPGA_TS) {
  134. /*
  135. * The touchscreen interrupt is level-sensitive, so
  136. * we'll use the regular mask_ack routine for it.
  137. */
  138. set_irq_chip(i, &omap_fpga_irq_ack);
  139. }
  140. else {
  141. /*
  142. * All FPGA interrupts except the touchscreen are
  143. * edge-sensitive, so we won't mask them.
  144. */
  145. set_irq_chip(i, &omap_fpga_irq);
  146. }
  147. set_irq_handler(i, do_edge_IRQ);
  148. set_irq_flags(i, IRQF_VALID);
  149. }
  150. /*
  151. * The FPGA interrupt line is connected to GPIO13. Claim this pin for
  152. * the ARM.
  153. *
  154. * NOTE: For general GPIO/MPUIO access and interrupts, please see
  155. * gpio.[ch]
  156. */
  157. omap_request_gpio(13);
  158. omap_set_gpio_direction(13, 1);
  159. set_irq_type(OMAP_GPIO_IRQ(13), IRQT_RISING);
  160. set_irq_chained_handler(OMAP1510_INT_FPGA, innovator_fpga_IRQ_demux);
  161. }
  162. EXPORT_SYMBOL(omap1510_fpga_init_irq);