cpci-irq.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. * Copyright 2002 Momentum Computer
  3. * Author: mdharm@momenco.com
  4. *
  5. * arch/mips/momentum/ocelot_c/cpci-irq.c
  6. * Interrupt routines for cpci. Interrupt numbers are assigned from
  7. * CPCI_IRQ_BASE to CPCI_IRQ_BASE+8 (8 interrupt sources).
  8. *
  9. * Note that the high-level software will need to be careful about using
  10. * these interrupts. If this board is asserting a cPCI interrupt, it will
  11. * also see the asserted interrupt. Care must be taken to avoid an
  12. * interrupt flood.
  13. *
  14. * This program is free software; you can redistribute it and/or modify it
  15. * under the terms of the GNU General Public License as published by the
  16. * Free Software Foundation; either version 2 of the License, or (at your
  17. * option) any later version.
  18. */
  19. #include <linux/module.h>
  20. #include <linux/interrupt.h>
  21. #include <linux/irq.h>
  22. #include <linux/kernel.h>
  23. #include <linux/sched.h>
  24. #include <linux/kernel_stat.h>
  25. #include <asm/io.h>
  26. #include "ocelot_c_fpga.h"
  27. #define CPCI_IRQ_BASE 8
  28. static inline int ls1bit8(unsigned int x)
  29. {
  30. int b = 7, s;
  31. s = 4; if (((unsigned char)(x << 4)) == 0) s = 0; b -= s; x <<= s;
  32. s = 2; if (((unsigned char)(x << 2)) == 0) s = 0; b -= s; x <<= s;
  33. s = 1; if (((unsigned char)(x << 1)) == 0) s = 0; b -= s;
  34. return b;
  35. }
  36. /* mask off an interrupt -- 0 is enable, 1 is disable */
  37. static inline void mask_cpci_irq(unsigned int irq)
  38. {
  39. uint32_t value;
  40. value = OCELOT_FPGA_READ(INTMASK);
  41. value |= 1 << (irq - CPCI_IRQ_BASE);
  42. OCELOT_FPGA_WRITE(value, INTMASK);
  43. /* read the value back to assure that it's really been written */
  44. value = OCELOT_FPGA_READ(INTMASK);
  45. }
  46. /* unmask an interrupt -- 0 is enable, 1 is disable */
  47. static inline void unmask_cpci_irq(unsigned int irq)
  48. {
  49. uint32_t value;
  50. value = OCELOT_FPGA_READ(INTMASK);
  51. value &= ~(1 << (irq - CPCI_IRQ_BASE));
  52. OCELOT_FPGA_WRITE(value, INTMASK);
  53. /* read the value back to assure that it's really been written */
  54. value = OCELOT_FPGA_READ(INTMASK);
  55. }
  56. /*
  57. * Interrupt handler for interrupts coming from the FPGA chip.
  58. * It could be built in ethernet ports etc...
  59. */
  60. void ll_cpci_irq(void)
  61. {
  62. unsigned int irq_src, irq_mask;
  63. /* read the interrupt status registers */
  64. irq_src = OCELOT_FPGA_READ(INTSTAT);
  65. irq_mask = OCELOT_FPGA_READ(INTMASK);
  66. /* mask for just the interrupts we want */
  67. irq_src &= ~irq_mask;
  68. do_IRQ(ls1bit8(irq_src) + CPCI_IRQ_BASE);
  69. }
  70. struct irq_chip cpci_irq_type = {
  71. .name = "CPCI/FPGA",
  72. .ack = mask_cpci_irq,
  73. .mask = mask_cpci_irq,
  74. .mask_ack = mask_cpci_irq,
  75. .unmask = unmask_cpci_irq,
  76. };
  77. void cpci_irq_init(void)
  78. {
  79. int i;
  80. for (i = CPCI_IRQ_BASE; i < (CPCI_IRQ_BASE + 8); i++)
  81. set_irq_chip_and_handler(i, &cpci_irq_type, handle_level_irq);
  82. }