irq.c 4.2 KB

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