irq-mb93091.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /* irq-mb93091.c: MB93091 FPGA interrupt handling
  2. *
  3. * Copyright (C) 2003 Red Hat, Inc. All Rights Reserved.
  4. * Written by David Howells (dhowells@redhat.com)
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version
  9. * 2 of the License, or (at your option) any later version.
  10. */
  11. #include <linux/ptrace.h>
  12. #include <linux/errno.h>
  13. #include <linux/signal.h>
  14. #include <linux/sched.h>
  15. #include <linux/ioport.h>
  16. #include <linux/interrupt.h>
  17. #include <linux/init.h>
  18. #include <linux/irq.h>
  19. #include <linux/bitops.h>
  20. #include <asm/io.h>
  21. #include <asm/delay.h>
  22. #include <asm/irq.h>
  23. #include <asm/irc-regs.h>
  24. #define __reg16(ADDR) (*(volatile unsigned short *)(ADDR))
  25. #define __get_IMR() ({ __reg16(0xffc00004); })
  26. #define __set_IMR(M) do { __reg16(0xffc00004) = (M); wmb(); } while(0)
  27. #define __get_IFR() ({ __reg16(0xffc0000c); })
  28. #define __clr_IFR(M) do { __reg16(0xffc0000c) = ~(M); wmb(); } while(0)
  29. /*
  30. * on-motherboard FPGA PIC operations
  31. */
  32. static void frv_fpga_mask(struct irq_data *d)
  33. {
  34. uint16_t imr = __get_IMR();
  35. imr |= 1 << (d->irq - IRQ_BASE_FPGA);
  36. __set_IMR(imr);
  37. }
  38. static void frv_fpga_ack(struct irq_data *d)
  39. {
  40. __clr_IFR(1 << (d->irq - IRQ_BASE_FPGA));
  41. }
  42. static void frv_fpga_mask_ack(struct irq_data *d)
  43. {
  44. uint16_t imr = __get_IMR();
  45. imr |= 1 << (d->irq - IRQ_BASE_FPGA);
  46. __set_IMR(imr);
  47. __clr_IFR(1 << (d->irq - IRQ_BASE_FPGA));
  48. }
  49. static void frv_fpga_unmask(struct irq_data *d)
  50. {
  51. uint16_t imr = __get_IMR();
  52. imr &= ~(1 << (d->irq - IRQ_BASE_FPGA));
  53. __set_IMR(imr);
  54. }
  55. static struct irq_chip frv_fpga_pic = {
  56. .name = "mb93091",
  57. .irq_ack = frv_fpga_ack,
  58. .irq_mask = frv_fpga_mask,
  59. .irq_mask_ack = frv_fpga_mask_ack,
  60. .irq_unmask = frv_fpga_unmask,
  61. };
  62. /*
  63. * FPGA PIC interrupt handler
  64. */
  65. static irqreturn_t fpga_interrupt(int irq, void *_mask)
  66. {
  67. uint16_t imr, mask = (unsigned long) _mask;
  68. imr = __get_IMR();
  69. mask = mask & ~imr & __get_IFR();
  70. /* poll all the triggered IRQs */
  71. while (mask) {
  72. int irq;
  73. asm("scan %1,gr0,%0" : "=r"(irq) : "r"(mask));
  74. irq = 31 - irq;
  75. mask &= ~(1 << irq);
  76. generic_handle_irq(IRQ_BASE_FPGA + irq);
  77. }
  78. return IRQ_HANDLED;
  79. }
  80. /*
  81. * define an interrupt action for each FPGA PIC output
  82. * - use dev_id to indicate the FPGA PIC input to output mappings
  83. */
  84. static struct irqaction fpga_irq[4] = {
  85. [0] = {
  86. .handler = fpga_interrupt,
  87. .flags = IRQF_SHARED,
  88. .name = "fpga.0",
  89. .dev_id = (void *) 0x0028UL,
  90. },
  91. [1] = {
  92. .handler = fpga_interrupt,
  93. .flags = IRQF_SHARED,
  94. .name = "fpga.1",
  95. .dev_id = (void *) 0x0050UL,
  96. },
  97. [2] = {
  98. .handler = fpga_interrupt,
  99. .flags = IRQF_SHARED,
  100. .name = "fpga.2",
  101. .dev_id = (void *) 0x1c00UL,
  102. },
  103. [3] = {
  104. .handler = fpga_interrupt,
  105. .flags = IRQF_SHARED,
  106. .name = "fpga.3",
  107. .dev_id = (void *) 0x6386UL,
  108. }
  109. };
  110. /*
  111. * initialise the motherboard FPGA's PIC
  112. */
  113. void __init fpga_init(void)
  114. {
  115. int irq;
  116. /* all PIC inputs are all set to be low-level driven, apart from the
  117. * NMI button (15) which is fixed at falling-edge
  118. */
  119. __set_IMR(0x7ffe);
  120. __clr_IFR(0x0000);
  121. for (irq = IRQ_BASE_FPGA + 1; irq <= IRQ_BASE_FPGA + 14; irq++)
  122. irq_set_chip_and_handler(irq, &frv_fpga_pic, handle_level_irq);
  123. irq_set_chip_and_handler(IRQ_FPGA_NMI, &frv_fpga_pic, handle_edge_irq);
  124. /* the FPGA drives the first four external IRQ inputs on the CPU PIC */
  125. setup_irq(IRQ_CPU_EXTERNAL0, &fpga_irq[0]);
  126. setup_irq(IRQ_CPU_EXTERNAL1, &fpga_irq[1]);
  127. setup_irq(IRQ_CPU_EXTERNAL2, &fpga_irq[2]);
  128. setup_irq(IRQ_CPU_EXTERNAL3, &fpga_irq[3]);
  129. }