kn02-irq.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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, 2005 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 *)CKSEG1ADDR(KN02_SLOT_BASE +
  33. KN02_CSR);
  34. cached_kn02_csr |= (1 << (irq - kn02_irq_base + 16));
  35. *csr = cached_kn02_csr;
  36. }
  37. static inline void mask_kn02_irq(unsigned int irq)
  38. {
  39. volatile u32 *csr = (volatile u32 *)CKSEG1ADDR(KN02_SLOT_BASE +
  40. KN02_CSR);
  41. cached_kn02_csr &= ~(1 << (irq - kn02_irq_base + 16));
  42. *csr = cached_kn02_csr;
  43. }
  44. static inline void enable_kn02_irq(unsigned int irq)
  45. {
  46. unsigned long flags;
  47. spin_lock_irqsave(&kn02_lock, flags);
  48. unmask_kn02_irq(irq);
  49. spin_unlock_irqrestore(&kn02_lock, flags);
  50. }
  51. static inline void disable_kn02_irq(unsigned int irq)
  52. {
  53. unsigned long flags;
  54. spin_lock_irqsave(&kn02_lock, flags);
  55. mask_kn02_irq(irq);
  56. spin_unlock_irqrestore(&kn02_lock, flags);
  57. }
  58. static unsigned int startup_kn02_irq(unsigned int irq)
  59. {
  60. enable_kn02_irq(irq);
  61. return 0;
  62. }
  63. #define shutdown_kn02_irq disable_kn02_irq
  64. static void ack_kn02_irq(unsigned int irq)
  65. {
  66. spin_lock(&kn02_lock);
  67. mask_kn02_irq(irq);
  68. spin_unlock(&kn02_lock);
  69. iob();
  70. }
  71. static void end_kn02_irq(unsigned int irq)
  72. {
  73. if (!(irq_desc[irq].status & (IRQ_DISABLED | IRQ_INPROGRESS)))
  74. enable_kn02_irq(irq);
  75. }
  76. static struct hw_interrupt_type kn02_irq_type = {
  77. .typename = "KN02-CSR",
  78. .startup = startup_kn02_irq,
  79. .shutdown = shutdown_kn02_irq,
  80. .enable = enable_kn02_irq,
  81. .disable = disable_kn02_irq,
  82. .ack = ack_kn02_irq,
  83. .end = end_kn02_irq,
  84. };
  85. void __init init_kn02_irqs(int base)
  86. {
  87. volatile u32 *csr = (volatile u32 *)CKSEG1ADDR(KN02_SLOT_BASE +
  88. KN02_CSR);
  89. unsigned long flags;
  90. int i;
  91. /* Mask interrupts. */
  92. spin_lock_irqsave(&kn02_lock, flags);
  93. cached_kn02_csr &= ~KN02_CSR_IOINTEN;
  94. *csr = cached_kn02_csr;
  95. iob();
  96. spin_unlock_irqrestore(&kn02_lock, flags);
  97. for (i = base; i < base + KN02_IRQ_LINES; i++) {
  98. irq_desc[i].status = IRQ_DISABLED;
  99. irq_desc[i].action = 0;
  100. irq_desc[i].depth = 1;
  101. irq_desc[i].handler = &kn02_irq_type;
  102. }
  103. kn02_irq_base = base;
  104. }