kn02-irq.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /*
  2. * linux/arch/mips/dec/kn02-irq.c
  3. *
  4. * DECstation 5000/200 (KN02) Control and Status Register
  5. * interrupts.
  6. *
  7. * Copyright (c) 2002, 2003 Maciej W. Rozycki
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License
  11. * as published by the Free Software Foundation; either version
  12. * 2 of the License, or (at your option) any later version.
  13. */
  14. #include <linux/init.h>
  15. #include <linux/irq.h>
  16. #include <linux/spinlock.h>
  17. #include <linux/types.h>
  18. #include <asm/dec/kn02.h>
  19. /*
  20. * Bits 7:0 of the Control Register are write-only -- the
  21. * corresponding bits of the Status Register have a different
  22. * meaning. Hence we use a cache. It speeds up things a bit
  23. * as well.
  24. *
  25. * There is no default value -- it has to be initialized.
  26. */
  27. u32 cached_kn02_csr;
  28. DEFINE_SPINLOCK(kn02_lock);
  29. static int kn02_irq_base;
  30. static inline void unmask_kn02_irq(unsigned int irq)
  31. {
  32. volatile u32 *csr = (volatile u32 *)KN02_CSR_BASE;
  33. cached_kn02_csr |= (1 << (irq - kn02_irq_base + 16));
  34. *csr = cached_kn02_csr;
  35. }
  36. static inline void mask_kn02_irq(unsigned int irq)
  37. {
  38. volatile u32 *csr = (volatile u32 *)KN02_CSR_BASE;
  39. cached_kn02_csr &= ~(1 << (irq - kn02_irq_base + 16));
  40. *csr = cached_kn02_csr;
  41. }
  42. static inline void enable_kn02_irq(unsigned int irq)
  43. {
  44. unsigned long flags;
  45. spin_lock_irqsave(&kn02_lock, flags);
  46. unmask_kn02_irq(irq);
  47. spin_unlock_irqrestore(&kn02_lock, flags);
  48. }
  49. static inline void disable_kn02_irq(unsigned int irq)
  50. {
  51. unsigned long flags;
  52. spin_lock_irqsave(&kn02_lock, flags);
  53. mask_kn02_irq(irq);
  54. spin_unlock_irqrestore(&kn02_lock, flags);
  55. }
  56. static unsigned int startup_kn02_irq(unsigned int irq)
  57. {
  58. enable_kn02_irq(irq);
  59. return 0;
  60. }
  61. #define shutdown_kn02_irq disable_kn02_irq
  62. static void ack_kn02_irq(unsigned int irq)
  63. {
  64. spin_lock(&kn02_lock);
  65. mask_kn02_irq(irq);
  66. spin_unlock(&kn02_lock);
  67. iob();
  68. }
  69. static void end_kn02_irq(unsigned int irq)
  70. {
  71. if (!(irq_desc[irq].status & (IRQ_DISABLED | IRQ_INPROGRESS)))
  72. enable_kn02_irq(irq);
  73. }
  74. static struct hw_interrupt_type kn02_irq_type = {
  75. .typename = "KN02-CSR",
  76. .startup = startup_kn02_irq,
  77. .shutdown = shutdown_kn02_irq,
  78. .enable = enable_kn02_irq,
  79. .disable = disable_kn02_irq,
  80. .ack = ack_kn02_irq,
  81. .end = end_kn02_irq,
  82. };
  83. void __init init_kn02_irqs(int base)
  84. {
  85. volatile u32 *csr = (volatile u32 *)KN02_CSR_BASE;
  86. unsigned long flags;
  87. int i;
  88. /* Mask interrupts. */
  89. spin_lock_irqsave(&kn02_lock, flags);
  90. cached_kn02_csr &= ~KN03_CSR_IOINTEN;
  91. *csr = cached_kn02_csr;
  92. iob();
  93. spin_unlock_irqrestore(&kn02_lock, flags);
  94. for (i = base; i < base + KN02_IRQ_LINES; i++) {
  95. irq_desc[i].status = IRQ_DISABLED;
  96. irq_desc[i].action = 0;
  97. irq_desc[i].depth = 1;
  98. irq_desc[i].handler = &kn02_irq_type;
  99. }
  100. kn02_irq_base = base;
  101. }