irq-mb93093.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /* irq-mb93093.c: MB93093 FPGA interrupt handling
  2. *
  3. * Copyright (C) 2006 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/system.h>
  22. #include <asm/delay.h>
  23. #include <asm/irq.h>
  24. #include <asm/irc-regs.h>
  25. #define __reg16(ADDR) (*(volatile unsigned short *)(__region_CS2 + (ADDR)))
  26. #define __get_IMR() ({ __reg16(0x0a); })
  27. #define __set_IMR(M) do { __reg16(0x0a) = (M); wmb(); } while(0)
  28. #define __get_IFR() ({ __reg16(0x02); })
  29. #define __clr_IFR(M) do { __reg16(0x02) = ~(M); wmb(); } while(0)
  30. /*
  31. * off-CPU FPGA PIC operations
  32. */
  33. static void frv_fpga_mask(struct irq_data *d)
  34. {
  35. uint16_t imr = __get_IMR();
  36. imr |= 1 << (d->irq - IRQ_BASE_FPGA);
  37. __set_IMR(imr);
  38. }
  39. static void frv_fpga_ack(struct irq_data *d)
  40. {
  41. __clr_IFR(1 << (d->irq - IRQ_BASE_FPGA));
  42. }
  43. static void frv_fpga_mask_ack(struct irq_data *d)
  44. {
  45. uint16_t imr = __get_IMR();
  46. imr |= 1 << (d->irq - IRQ_BASE_FPGA);
  47. __set_IMR(imr);
  48. __clr_IFR(1 << (d->irq - IRQ_BASE_FPGA));
  49. }
  50. static void frv_fpga_unmask(struct irq_data *d)
  51. {
  52. uint16_t imr = __get_IMR();
  53. imr &= ~(1 << (d->irq - IRQ_BASE_FPGA));
  54. __set_IMR(imr);
  55. }
  56. static struct irq_chip frv_fpga_pic = {
  57. .name = "mb93093",
  58. .irq_ack = frv_fpga_ack,
  59. .irq_mask = frv_fpga_mask,
  60. .irq_mask_ack = frv_fpga_mask_ack,
  61. .irq_unmask = frv_fpga_unmask,
  62. };
  63. /*
  64. * FPGA PIC interrupt handler
  65. */
  66. static irqreturn_t fpga_interrupt(int irq, void *_mask)
  67. {
  68. uint16_t imr, mask = (unsigned long) _mask;
  69. imr = __get_IMR();
  70. mask = mask & ~imr & __get_IFR();
  71. /* poll all the triggered IRQs */
  72. while (mask) {
  73. int irq;
  74. asm("scan %1,gr0,%0" : "=r"(irq) : "r"(mask));
  75. irq = 31 - irq;
  76. mask &= ~(1 << irq);
  77. generic_handle_irq(IRQ_BASE_FPGA + irq);
  78. }
  79. return IRQ_HANDLED;
  80. }
  81. /*
  82. * define an interrupt action for each FPGA PIC output
  83. * - use dev_id to indicate the FPGA PIC input to output mappings
  84. */
  85. static struct irqaction fpga_irq[1] = {
  86. [0] = {
  87. .handler = fpga_interrupt,
  88. .flags = IRQF_DISABLED,
  89. .name = "fpga.0",
  90. .dev_id = (void *) 0x0700UL,
  91. }
  92. };
  93. /*
  94. * initialise the motherboard FPGA's PIC
  95. */
  96. void __init fpga_init(void)
  97. {
  98. int irq;
  99. /* all PIC inputs are all set to be edge triggered */
  100. __set_IMR(0x0700);
  101. __clr_IFR(0x0000);
  102. for (irq = IRQ_BASE_FPGA + 8; irq <= IRQ_BASE_FPGA + 10; irq++)
  103. irq_set_chip_and_handler(irq, &frv_fpga_pic, handle_edge_irq);
  104. /* the FPGA drives external IRQ input #2 on the CPU PIC */
  105. setup_irq(IRQ_CPU_EXTERNAL2, &fpga_irq[0]);
  106. }