irq.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /*
  2. * arch/arm/mach-ns9xxx/irq.c
  3. *
  4. * Copyright (C) 2006,2007 by Digi International Inc.
  5. * All rights reserved.
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License version 2 as published by
  9. * the Free Software Foundation.
  10. */
  11. #include <linux/interrupt.h>
  12. #include <linux/kernel_stat.h>
  13. #include <asm/io.h>
  14. #include <asm/mach/irq.h>
  15. #include <asm/mach-types.h>
  16. #include <asm/arch-ns9xxx/regs-sys-common.h>
  17. #include <asm/arch-ns9xxx/irqs.h>
  18. #include <asm/arch-ns9xxx/board.h>
  19. #include "generic.h"
  20. /* simple interrupt prio table: prio(x) < prio(y) <=> x < y */
  21. #define irq2prio(i) (i)
  22. #define prio2irq(p) (p)
  23. static void ns9xxx_mask_irq(unsigned int irq)
  24. {
  25. /* XXX: better use cpp symbols */
  26. int prio = irq2prio(irq);
  27. u32 ic = __raw_readl(SYS_IC(prio / 4));
  28. ic &= ~(1 << (7 + 8 * (3 - (prio & 3))));
  29. __raw_writel(ic, SYS_IC(prio / 4));
  30. }
  31. static void ns9xxx_ack_irq(unsigned int irq)
  32. {
  33. __raw_writel(0, SYS_ISRADDR);
  34. }
  35. static void ns9xxx_maskack_irq(unsigned int irq)
  36. {
  37. ns9xxx_mask_irq(irq);
  38. ns9xxx_ack_irq(irq);
  39. }
  40. static void ns9xxx_unmask_irq(unsigned int irq)
  41. {
  42. /* XXX: better use cpp symbols */
  43. int prio = irq2prio(irq);
  44. u32 ic = __raw_readl(SYS_IC(prio / 4));
  45. ic |= 1 << (7 + 8 * (3 - (prio & 3)));
  46. __raw_writel(ic, SYS_IC(prio / 4));
  47. }
  48. static struct irq_chip ns9xxx_chip = {
  49. .ack = ns9xxx_ack_irq,
  50. .mask = ns9xxx_mask_irq,
  51. .mask_ack = ns9xxx_maskack_irq,
  52. .unmask = ns9xxx_unmask_irq,
  53. };
  54. #if 0
  55. #define handle_irq handle_level_irq
  56. #else
  57. static void handle_prio_irq(unsigned int irq, struct irq_desc *desc)
  58. {
  59. unsigned int cpu = smp_processor_id();
  60. struct irqaction *action;
  61. irqreturn_t action_ret;
  62. spin_lock(&desc->lock);
  63. BUG_ON(desc->status & IRQ_INPROGRESS);
  64. desc->status &= ~(IRQ_REPLAY | IRQ_WAITING);
  65. kstat_cpu(cpu).irqs[irq]++;
  66. action = desc->action;
  67. if (unlikely(!action || (desc->status & IRQ_DISABLED)))
  68. goto out_mask;
  69. desc->status |= IRQ_INPROGRESS;
  70. spin_unlock(&desc->lock);
  71. action_ret = handle_IRQ_event(irq, action);
  72. /* XXX: There is no direct way to access noirqdebug, so check
  73. * unconditionally for spurious irqs...
  74. * Maybe this function should go to kernel/irq/chip.c? */
  75. note_interrupt(irq, desc, action_ret);
  76. spin_lock(&desc->lock);
  77. desc->status &= ~IRQ_INPROGRESS;
  78. if (desc->status & IRQ_DISABLED)
  79. out_mask:
  80. desc->chip->mask(irq);
  81. /* ack unconditionally to unmask lower prio irqs */
  82. desc->chip->ack(irq);
  83. spin_unlock(&desc->lock);
  84. }
  85. #define handle_irq handle_prio_irq
  86. #endif
  87. void __init ns9xxx_init_irq(void)
  88. {
  89. int i;
  90. /* disable all IRQs */
  91. for (i = 0; i < 8; ++i)
  92. __raw_writel(prio2irq(4 * i) << 24 |
  93. prio2irq(4 * i + 1) << 16 |
  94. prio2irq(4 * i + 2) << 8 |
  95. prio2irq(4 * i + 3),
  96. SYS_IC(i));
  97. for (i = 0; i < 32; ++i)
  98. __raw_writel(prio2irq(i), SYS_IVA(i));
  99. for (i = 0; i <= 31; ++i) {
  100. set_irq_chip(i, &ns9xxx_chip);
  101. set_irq_handler(i, handle_irq);
  102. set_irq_flags(i, IRQF_VALID);
  103. }
  104. }