blob: d7f8a782aae4d9a3200c307f383be28ed83b2b18 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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
Ralf Baechle89742e52007-10-18 13:51:15 +01007 * Copyright (C) 1994 - 2001, 2003, 07 Ralf Baechle
Linus Torvalds1da177e2005-04-16 15:20:36 -07008 */
Ralf Baechle584d98b2007-10-11 23:46:09 +01009#include <linux/clockchips.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070010#include <linux/init.h>
11#include <linux/interrupt.h>
12#include <linux/kernel.h>
13#include <linux/spinlock.h>
14
Thomas Bogendoerferea202c62007-08-25 11:01:50 +020015#include <asm/irq_cpu.h>
Ralf Baechle89742e52007-10-18 13:51:15 +010016#include <asm/i8253.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017#include <asm/i8259.h>
18#include <asm/io.h>
19#include <asm/jazz.h>
Thomas Bogendoerferea202c62007-08-25 11:01:50 +020020#include <asm/pgtable.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070021
Linus Torvalds1da177e2005-04-16 15:20:36 -070022static DEFINE_SPINLOCK(r4030_lock);
23
24static void enable_r4030_irq(unsigned int irq)
25{
Thomas Bogendoerferea202c62007-08-25 11:01:50 +020026 unsigned int mask = 1 << (irq - JAZZ_IRQ_START);
Linus Torvalds1da177e2005-04-16 15:20:36 -070027 unsigned long flags;
28
29 spin_lock_irqsave(&r4030_lock, flags);
30 mask |= r4030_read_reg16(JAZZ_IO_IRQ_ENABLE);
31 r4030_write_reg16(JAZZ_IO_IRQ_ENABLE, mask);
32 spin_unlock_irqrestore(&r4030_lock, flags);
33}
34
Linus Torvalds1da177e2005-04-16 15:20:36 -070035void disable_r4030_irq(unsigned int irq)
36{
Thomas Bogendoerferea202c62007-08-25 11:01:50 +020037 unsigned int mask = ~(1 << (irq - JAZZ_IRQ_START));
Linus Torvalds1da177e2005-04-16 15:20:36 -070038 unsigned long flags;
39
40 spin_lock_irqsave(&r4030_lock, flags);
41 mask &= r4030_read_reg16(JAZZ_IO_IRQ_ENABLE);
42 r4030_write_reg16(JAZZ_IO_IRQ_ENABLE, mask);
43 spin_unlock_irqrestore(&r4030_lock, flags);
44}
45
Ralf Baechle94dee172006-07-02 14:41:42 +010046static struct irq_chip r4030_irq_type = {
Atsushi Nemoto70d21cd2007-01-15 00:07:25 +090047 .name = "R4030",
Atsushi Nemoto1603b5a2006-11-02 02:08:36 +090048 .ack = disable_r4030_irq,
49 .mask = disable_r4030_irq,
50 .mask_ack = disable_r4030_irq,
51 .unmask = enable_r4030_irq,
Linus Torvalds1da177e2005-04-16 15:20:36 -070052};
53
54void __init init_r4030_ints(void)
55{
56 int i;
57
Thomas Bogendoerferea202c62007-08-25 11:01:50 +020058 for (i = JAZZ_IRQ_START; i <= JAZZ_IRQ_END; i++)
Atsushi Nemoto14178362006-11-14 01:13:18 +090059 set_irq_chip_and_handler(i, &r4030_irq_type, handle_level_irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -070060
61 r4030_write_reg16(JAZZ_IO_IRQ_ENABLE, 0);
62 r4030_read_reg16(JAZZ_IO_IRQ_SOURCE); /* clear pending IRQs */
63 r4030_read_reg32(JAZZ_R4030_INVAL_ADDR); /* clear error bits */
64}
65
66/*
67 * On systems with i8259-style interrupt controllers we assume for
68 * driver compatibility reasons interrupts 0 - 15 to be the i8259
69 * interrupts even if the hardware uses a different interrupt numbering.
70 */
71void __init arch_init_irq(void)
72{
Thomas Bogendoerferea202c62007-08-25 11:01:50 +020073 /*
74 * this is a hack to get back the still needed wired mapping
75 * killed by init_mm()
76 */
77
78 /* Map 0xe0000000 -> 0x0:800005C0, 0xe0010000 -> 0x1:30000580 */
79 add_wired_entry(0x02000017, 0x03c00017, 0xe0000000, PM_64K);
80 /* Map 0xe2000000 -> 0x0:900005C0, 0xe3010000 -> 0x0:910005C0 */
81 add_wired_entry(0x02400017, 0x02440017, 0xe2000000, PM_16M);
82 /* Map 0xe4000000 -> 0x0:600005C0, 0xe4100000 -> 400005C0 */
83 add_wired_entry(0x01800017, 0x01000017, 0xe4000000, PM_4M);
84
Linus Torvalds1da177e2005-04-16 15:20:36 -070085 init_i8259_irqs(); /* Integrated i8259 */
Thomas Bogendoerferea202c62007-08-25 11:01:50 +020086 mips_cpu_irq_init();
Linus Torvalds1da177e2005-04-16 15:20:36 -070087 init_r4030_ints();
88
Thomas Bogendoerferea202c62007-08-25 11:01:50 +020089 change_c0_status(ST0_IM, IE_IRQ2 | IE_IRQ1);
Ralf Baechlee4ac58a2006-04-03 17:56:36 +010090}
91
Ralf Baechle937a8012006-10-07 19:44:33 +010092asmlinkage void plat_irq_dispatch(void)
Ralf Baechlee4ac58a2006-04-03 17:56:36 +010093{
Thiemo Seufer119537c2007-03-19 00:13:37 +000094 unsigned int pending = read_c0_cause() & read_c0_status();
Thomas Bogendoerferea202c62007-08-25 11:01:50 +020095 unsigned int irq;
Ralf Baechlee4ac58a2006-04-03 17:56:36 +010096
Thomas Bogendoerferea202c62007-08-25 11:01:50 +020097 if (pending & IE_IRQ4) {
Ralf Baechlee4ac58a2006-04-03 17:56:36 +010098 r4030_read_reg32(JAZZ_TIMER_REGISTER);
Ralf Baechle937a8012006-10-07 19:44:33 +010099 do_IRQ(JAZZ_TIMER_IRQ);
Thomas Bogendoerfer3be51f72007-11-02 11:17:13 +0100100 } else if (pending & IE_IRQ2) {
101 irq = *(volatile u8 *)JAZZ_EISA_IRQ_ACK;
102 do_IRQ(irq);
103 } else if (pending & IE_IRQ1) {
Thomas Bogendoerferea202c62007-08-25 11:01:50 +0200104 irq = *(volatile u8 *)JAZZ_IO_IRQ_SOURCE >> 2;
105 if (likely(irq > 0))
106 do_IRQ(irq + JAZZ_IRQ_START - 1);
107 else
108 panic("Unimplemented loc_no_irq handler");
Ralf Baechlee4ac58a2006-04-03 17:56:36 +0100109 }
110}
Ralf Baechle584d98b2007-10-11 23:46:09 +0100111
112static void r4030_set_mode(enum clock_event_mode mode,
113 struct clock_event_device *evt)
114{
115 /* Nothing to do ... */
116}
117
118struct clock_event_device r4030_clockevent = {
119 .name = "r4030",
120 .features = CLOCK_EVT_FEAT_PERIODIC,
Thomas Bogendoerfer3be51f72007-11-02 11:17:13 +0100121 .rating = 300,
Ralf Baechle584d98b2007-10-11 23:46:09 +0100122 .irq = JAZZ_TIMER_IRQ,
Ralf Baechle584d98b2007-10-11 23:46:09 +0100123 .set_mode = r4030_set_mode,
124};
125
126static irqreturn_t r4030_timer_interrupt(int irq, void *dev_id)
127{
Thomas Bogendoerfer3be51f72007-11-02 11:17:13 +0100128 struct clock_event_device *cd = dev_id;
Ralf Baechle584d98b2007-10-11 23:46:09 +0100129
Thomas Bogendoerfer3be51f72007-11-02 11:17:13 +0100130 cd->event_handler(cd);
Ralf Baechle584d98b2007-10-11 23:46:09 +0100131 return IRQ_HANDLED;
132}
133
134static struct irqaction r4030_timer_irqaction = {
135 .handler = r4030_timer_interrupt,
136 .flags = IRQF_DISABLED,
137 .mask = CPU_MASK_CPU0,
Thomas Bogendoerfer3be51f72007-11-02 11:17:13 +0100138 .name = "R4030 timer",
Ralf Baechle584d98b2007-10-11 23:46:09 +0100139};
140
Ralf Baechle89742e52007-10-18 13:51:15 +0100141void __init plat_time_init(void)
Ralf Baechle584d98b2007-10-11 23:46:09 +0100142{
Thomas Bogendoerfer3be51f72007-11-02 11:17:13 +0100143 struct clock_event_device *cd = &r4030_clockevent;
144 struct irqaction *action = &r4030_timer_irqaction;
145 unsigned int cpu = smp_processor_id();
Ralf Baechle584d98b2007-10-11 23:46:09 +0100146
147 BUG_ON(HZ != 100);
148
Thomas Bogendoerfer3be51f72007-11-02 11:17:13 +0100149 cd->cpumask = cpumask_of_cpu(cpu);
150 clockevents_register_device(cd);
151 action->dev_id = cd;
152 setup_irq(JAZZ_TIMER_IRQ, action);
153
Ralf Baechle584d98b2007-10-11 23:46:09 +0100154 /*
155 * Set clock to 100Hz.
156 *
157 * The R4030 timer receives an input clock of 1kHz which is divieded by
158 * a programmable 4-bit divider. This makes it fairly inflexible.
159 */
160 r4030_write_reg32(JAZZ_TIMER_INTERVAL, 9);
Ralf Baechle89742e52007-10-18 13:51:15 +0100161 setup_pit_timer();
Ralf Baechle584d98b2007-10-11 23:46:09 +0100162}