fpga.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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 <asm/hardware.h>
  24. #include <asm/io.h>
  25. #include <asm/irq.h>
  26. #include <asm/mach/irq.h>
  27. #include <asm/arch/fpga.h>
  28. #include <asm/arch/gpio.h>
  29. static void fpga_mask_irq(unsigned int irq)
  30. {
  31. irq -= OMAP1510_IH_FPGA_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(unsigned int irq)
  53. {
  54. /* Don't need to explicitly ACK FPGA interrupts */
  55. }
  56. static void fpga_unmask_irq(unsigned int irq)
  57. {
  58. irq -= OMAP1510_IH_FPGA_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(unsigned int irq)
  70. {
  71. fpga_mask_irq(irq);
  72. fpga_ack_irq(irq);
  73. }
  74. void innovator_fpga_IRQ_demux(unsigned int irq, struct irqdesc *desc,
  75. struct pt_regs *regs)
  76. {
  77. struct irqdesc *d;
  78. u32 stat;
  79. int fpga_irq;
  80. stat = get_fpga_unmasked_irqs();
  81. if (!stat)
  82. return;
  83. for (fpga_irq = OMAP1510_IH_FPGA_BASE;
  84. (fpga_irq < (OMAP1510_IH_FPGA_BASE + NR_FPGA_IRQS)) && stat;
  85. fpga_irq++, stat >>= 1) {
  86. if (stat & 1) {
  87. d = irq_desc + fpga_irq;
  88. desc_handle_irq(fpga_irq, d, regs);
  89. }
  90. }
  91. }
  92. static struct irqchip omap_fpga_irq_ack = {
  93. .ack = fpga_mask_ack_irq,
  94. .mask = fpga_mask_irq,
  95. .unmask = fpga_unmask_irq,
  96. };
  97. static struct irqchip omap_fpga_irq = {
  98. .ack = fpga_ack_irq,
  99. .mask = fpga_mask_irq,
  100. .unmask = fpga_unmask_irq,
  101. };
  102. /*
  103. * All of the FPGA interrupt request inputs except for the touchscreen are
  104. * edge-sensitive; the touchscreen is level-sensitive. The edge-sensitive
  105. * interrupts are acknowledged as a side-effect of reading the interrupt
  106. * status register from the FPGA. The edge-sensitive interrupt inputs
  107. * cause a problem with level interrupt requests, such as Ethernet. The
  108. * problem occurs when a level interrupt request is asserted while its
  109. * interrupt input is masked in the FPGA, which results in a missed
  110. * interrupt.
  111. *
  112. * In an attempt to workaround the problem with missed interrupts, the
  113. * mask_ack routine for all of the FPGA interrupts has been changed from
  114. * fpga_mask_ack_irq() to fpga_ack_irq() so that the specific FPGA interrupt
  115. * being serviced is left unmasked. We can do this because the FPGA cascade
  116. * interrupt is installed with the IRQF_DISABLED flag, which leaves all
  117. * interrupts masked at the CPU while an FPGA interrupt handler executes.
  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;
  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 = OMAP1510_IH_FPGA_BASE; i < (OMAP1510_IH_FPGA_BASE + NR_FPGA_IRQS); 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. set_irq_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. set_irq_chip(i, &omap_fpga_irq);
  145. }
  146. set_irq_handler(i, do_edge_IRQ);
  147. set_irq_flags(i, IRQF_VALID);
  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. omap_request_gpio(13);
  157. omap_set_gpio_direction(13, 1);
  158. set_irq_type(OMAP_GPIO_IRQ(13), IRQT_RISING);
  159. set_irq_chained_handler(OMAP1510_INT_FPGA, innovator_fpga_IRQ_demux);
  160. }
  161. EXPORT_SYMBOL(omap1510_fpga_init_irq);