MIPS: Lasat: Convert to proc_fops / seq_file
[safe/jmp/linux-2.6] / arch / mips / jazz / irq.c
index 0b608fa..7bd32d0 100644 (file)
@@ -4,24 +4,27 @@
  * for more details.
  *
  * Copyright (C) 1992 Linus Torvalds
- * Copyright (C) 1994 - 2001, 2003 Ralf Baechle
+ * Copyright (C) 1994 - 2001, 2003, 07 Ralf Baechle
  */
+#include <linux/clockchips.h>
 #include <linux/init.h>
 #include <linux/interrupt.h>
 #include <linux/kernel.h>
+#include <linux/smp.h>
 #include <linux/spinlock.h>
 
+#include <asm/irq_cpu.h>
+#include <asm/i8253.h>
 #include <asm/i8259.h>
 #include <asm/io.h>
 #include <asm/jazz.h>
-
-extern asmlinkage void jazz_handle_int(void);
+#include <asm/pgtable.h>
 
 static DEFINE_SPINLOCK(r4030_lock);
 
 static void enable_r4030_irq(unsigned int irq)
 {
-       unsigned int mask = 1 << (irq - JAZZ_PARALLEL_IRQ);
+       unsigned int mask = 1 << (irq - JAZZ_IRQ_START);
        unsigned long flags;
 
        spin_lock_irqsave(&r4030_lock, flags);
@@ -30,17 +33,9 @@ static void enable_r4030_irq(unsigned int irq)
        spin_unlock_irqrestore(&r4030_lock, flags);
 }
 
-static unsigned int startup_r4030_irq(unsigned int irq)
-{
-       enable_r4030_irq(irq);
-       return 0; /* never anything pending */
-}
-
-#define shutdown_r4030_irq     disable_r4030_irq
-
 void disable_r4030_irq(unsigned int irq)
 {
-       unsigned int mask = ~(1 << (irq - JAZZ_PARALLEL_IRQ));
+       unsigned int mask = ~(1 << (irq - JAZZ_IRQ_START));
        unsigned long flags;
 
        spin_lock_irqsave(&r4030_lock, flags);
@@ -49,35 +44,20 @@ void disable_r4030_irq(unsigned int irq)
        spin_unlock_irqrestore(&r4030_lock, flags);
 }
 
-#define mask_and_ack_r4030_irq disable_r4030_irq
-
-static void end_r4030_irq(unsigned int irq)
-{
-       if (!(irq_desc[irq].status & (IRQ_DISABLED|IRQ_INPROGRESS)))
-               enable_r4030_irq(irq);
-}
-
-static struct hw_interrupt_type r4030_irq_type = {
-       "R4030",
-       startup_r4030_irq,
-       shutdown_r4030_irq,
-       enable_r4030_irq,
-       disable_r4030_irq,
-       mask_and_ack_r4030_irq,
-       end_r4030_irq,
-       NULL
+static struct irq_chip r4030_irq_type = {
+       .name = "R4030",
+       .ack = disable_r4030_irq,
+       .mask = disable_r4030_irq,
+       .mask_ack = disable_r4030_irq,
+       .unmask = enable_r4030_irq,
 };
 
 void __init init_r4030_ints(void)
 {
        int i;
 
-       for (i = JAZZ_PARALLEL_IRQ; i <= JAZZ_TIMER_IRQ; i++) {
-               irq_desc[i].status     = IRQ_DISABLED;
-               irq_desc[i].action     = 0;
-               irq_desc[i].depth      = 1;
-               irq_desc[i].handler    = &r4030_irq_type;
-       }
+       for (i = JAZZ_IRQ_START; i <= JAZZ_IRQ_END; i++)
+               set_irq_chip_and_handler(i, &r4030_irq_type, handle_level_irq);
 
        r4030_write_reg16(JAZZ_IO_IRQ_ENABLE, 0);
        r4030_read_reg16(JAZZ_IO_IRQ_SOURCE);           /* clear pending IRQs */
@@ -91,10 +71,92 @@ void __init init_r4030_ints(void)
  */
 void __init arch_init_irq(void)
 {
-       set_except_vector(0, jazz_handle_int);
+       /*
+        * this is a hack to get back the still needed wired mapping
+        * killed by init_mm()
+        */
+
+       /* Map 0xe0000000 -> 0x0:800005C0, 0xe0010000 -> 0x1:30000580 */
+       add_wired_entry(0x02000017, 0x03c00017, 0xe0000000, PM_64K);
+       /* Map 0xe2000000 -> 0x0:900005C0, 0xe3010000 -> 0x0:910005C0 */
+       add_wired_entry(0x02400017, 0x02440017, 0xe2000000, PM_16M);
+       /* Map 0xe4000000 -> 0x0:600005C0, 0xe4100000 -> 400005C0 */
+       add_wired_entry(0x01800017, 0x01000017, 0xe4000000, PM_4M);
 
        init_i8259_irqs();                      /* Integrated i8259  */
+       mips_cpu_irq_init();
        init_r4030_ints();
 
-       change_c0_status(ST0_IM, IE_IRQ4 | IE_IRQ3 | IE_IRQ2 | IE_IRQ1);
+       change_c0_status(ST0_IM, IE_IRQ2 | IE_IRQ1);
+}
+
+asmlinkage void plat_irq_dispatch(void)
+{
+       unsigned int pending = read_c0_cause() & read_c0_status();
+       unsigned int irq;
+
+       if (pending & IE_IRQ4) {
+               r4030_read_reg32(JAZZ_TIMER_REGISTER);
+               do_IRQ(JAZZ_TIMER_IRQ);
+       } else if (pending & IE_IRQ2) {
+               irq = *(volatile u8 *)JAZZ_EISA_IRQ_ACK;
+               do_IRQ(irq);
+       } else if (pending & IE_IRQ1) {
+               irq = *(volatile u8 *)JAZZ_IO_IRQ_SOURCE >> 2;
+               if (likely(irq > 0))
+                       do_IRQ(irq + JAZZ_IRQ_START - 1);
+               else
+                       panic("Unimplemented loc_no_irq handler");
+       }
+}
+
+static void r4030_set_mode(enum clock_event_mode mode,
+                           struct clock_event_device *evt)
+{
+       /* Nothing to do ...  */
+}
+
+struct clock_event_device r4030_clockevent = {
+       .name           = "r4030",
+       .features       = CLOCK_EVT_FEAT_PERIODIC,
+       .rating         = 300,
+       .irq            = JAZZ_TIMER_IRQ,
+       .set_mode       = r4030_set_mode,
+};
+
+static irqreturn_t r4030_timer_interrupt(int irq, void *dev_id)
+{
+       struct clock_event_device *cd = dev_id;
+
+       cd->event_handler(cd);
+       return IRQ_HANDLED;
+}
+
+static struct irqaction r4030_timer_irqaction = {
+       .handler        = r4030_timer_interrupt,
+       .flags          = IRQF_DISABLED | IRQF_TIMER,
+       .name           = "R4030 timer",
+};
+
+void __init plat_time_init(void)
+{
+       struct clock_event_device *cd = &r4030_clockevent;
+       struct irqaction *action = &r4030_timer_irqaction;
+       unsigned int cpu = smp_processor_id();
+
+       BUG_ON(HZ != 100);
+
+       cd->cpumask             = cpumask_of(cpu);
+       clockevents_register_device(cd);
+       action->dev_id = cd;
+       setup_irq(JAZZ_TIMER_IRQ, action);
+
+       /*
+        * Set clock to 100Hz.
+        *
+        * The R4030 timer receives an input clock of 1kHz which is divieded by
+        * a programmable 4-bit divider.  This makes it fairly inflexible.
+        */
+       r4030_write_reg32(JAZZ_TIMER_INTERVAL, 9);
+       setup_pit_timer();
 }