irq.c 4.2 KB

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