irq.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * Copyright (C) 1992 Linus Torvalds
  7. * Copyright (C) 1994 - 2001, 2003 Ralf Baechle
  8. */
  9. #include <linux/clockchips.h>
  10. #include <linux/init.h>
  11. #include <linux/interrupt.h>
  12. #include <linux/kernel.h>
  13. #include <linux/spinlock.h>
  14. #include <asm/irq_cpu.h>
  15. #include <asm/i8259.h>
  16. #include <asm/io.h>
  17. #include <asm/jazz.h>
  18. #include <asm/pgtable.h>
  19. static DEFINE_SPINLOCK(r4030_lock);
  20. static void enable_r4030_irq(unsigned int irq)
  21. {
  22. unsigned int mask = 1 << (irq - JAZZ_IRQ_START);
  23. unsigned long flags;
  24. spin_lock_irqsave(&r4030_lock, flags);
  25. mask |= r4030_read_reg16(JAZZ_IO_IRQ_ENABLE);
  26. r4030_write_reg16(JAZZ_IO_IRQ_ENABLE, mask);
  27. spin_unlock_irqrestore(&r4030_lock, flags);
  28. }
  29. void disable_r4030_irq(unsigned int irq)
  30. {
  31. unsigned int mask = ~(1 << (irq - JAZZ_IRQ_START));
  32. unsigned long flags;
  33. spin_lock_irqsave(&r4030_lock, flags);
  34. mask &= r4030_read_reg16(JAZZ_IO_IRQ_ENABLE);
  35. r4030_write_reg16(JAZZ_IO_IRQ_ENABLE, mask);
  36. spin_unlock_irqrestore(&r4030_lock, flags);
  37. }
  38. static struct irq_chip r4030_irq_type = {
  39. .name = "R4030",
  40. .ack = disable_r4030_irq,
  41. .mask = disable_r4030_irq,
  42. .mask_ack = disable_r4030_irq,
  43. .unmask = enable_r4030_irq,
  44. };
  45. void __init init_r4030_ints(void)
  46. {
  47. int i;
  48. for (i = JAZZ_IRQ_START; i <= JAZZ_IRQ_END; i++)
  49. set_irq_chip_and_handler(i, &r4030_irq_type, handle_level_irq);
  50. r4030_write_reg16(JAZZ_IO_IRQ_ENABLE, 0);
  51. r4030_read_reg16(JAZZ_IO_IRQ_SOURCE); /* clear pending IRQs */
  52. r4030_read_reg32(JAZZ_R4030_INVAL_ADDR); /* clear error bits */
  53. }
  54. /*
  55. * On systems with i8259-style interrupt controllers we assume for
  56. * driver compatibility reasons interrupts 0 - 15 to be the i8259
  57. * interrupts even if the hardware uses a different interrupt numbering.
  58. */
  59. void __init arch_init_irq(void)
  60. {
  61. /*
  62. * this is a hack to get back the still needed wired mapping
  63. * killed by init_mm()
  64. */
  65. /* Map 0xe0000000 -> 0x0:800005C0, 0xe0010000 -> 0x1:30000580 */
  66. add_wired_entry(0x02000017, 0x03c00017, 0xe0000000, PM_64K);
  67. /* Map 0xe2000000 -> 0x0:900005C0, 0xe3010000 -> 0x0:910005C0 */
  68. add_wired_entry(0x02400017, 0x02440017, 0xe2000000, PM_16M);
  69. /* Map 0xe4000000 -> 0x0:600005C0, 0xe4100000 -> 400005C0 */
  70. add_wired_entry(0x01800017, 0x01000017, 0xe4000000, PM_4M);
  71. init_i8259_irqs(); /* Integrated i8259 */
  72. mips_cpu_irq_init();
  73. init_r4030_ints();
  74. change_c0_status(ST0_IM, IE_IRQ2 | IE_IRQ1);
  75. }
  76. asmlinkage void plat_irq_dispatch(void)
  77. {
  78. unsigned int pending = read_c0_cause() & read_c0_status();
  79. unsigned int irq;
  80. if (pending & IE_IRQ4) {
  81. r4030_read_reg32(JAZZ_TIMER_REGISTER);
  82. do_IRQ(JAZZ_TIMER_IRQ);
  83. } else if (pending & IE_IRQ2)
  84. do_IRQ(r4030_read_reg32(JAZZ_EISA_IRQ_ACK));
  85. else if (pending & IE_IRQ1) {
  86. irq = *(volatile u8 *)JAZZ_IO_IRQ_SOURCE >> 2;
  87. if (likely(irq > 0))
  88. do_IRQ(irq + JAZZ_IRQ_START - 1);
  89. else
  90. panic("Unimplemented loc_no_irq handler");
  91. }
  92. }
  93. static void r4030_set_mode(enum clock_event_mode mode,
  94. struct clock_event_device *evt)
  95. {
  96. /* Nothing to do ... */
  97. }
  98. struct clock_event_device r4030_clockevent = {
  99. .name = "r4030",
  100. .features = CLOCK_EVT_FEAT_PERIODIC,
  101. .rating = 100,
  102. .irq = JAZZ_TIMER_IRQ,
  103. .cpumask = CPU_MASK_CPU0,
  104. .set_mode = r4030_set_mode,
  105. };
  106. static irqreturn_t r4030_timer_interrupt(int irq, void *dev_id)
  107. {
  108. r4030_clockevent.event_handler(&r4030_clockevent);
  109. return IRQ_HANDLED;
  110. }
  111. static struct irqaction r4030_timer_irqaction = {
  112. .handler = r4030_timer_interrupt,
  113. .flags = IRQF_DISABLED,
  114. .mask = CPU_MASK_CPU0,
  115. .name = "timer",
  116. };
  117. void __init plat_timer_setup(struct irqaction *ignored)
  118. {
  119. struct irqaction *irq = &r4030_timer_irqaction;
  120. BUG_ON(HZ != 100);
  121. /*
  122. * Set clock to 100Hz.
  123. *
  124. * The R4030 timer receives an input clock of 1kHz which is divieded by
  125. * a programmable 4-bit divider. This makes it fairly inflexible.
  126. */
  127. r4030_write_reg32(JAZZ_TIMER_INTERVAL, 9);
  128. setup_irq(JAZZ_TIMER_IRQ, irq);
  129. clockevents_register_device(&r4030_clockevent);
  130. }