Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 |
Ralf Baechle | 89742e5 | 2007-10-18 13:51:15 +0100 | [diff] [blame] | 7 | * Copyright (C) 1994 - 2001, 2003, 07 Ralf Baechle |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | */ |
Ralf Baechle | 584d98b | 2007-10-11 23:46:09 +0100 | [diff] [blame] | 9 | #include <linux/clockchips.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | #include <linux/init.h> |
| 11 | #include <linux/interrupt.h> |
| 12 | #include <linux/kernel.h> |
Ralf Baechle | 631330f | 2009-06-19 14:05:26 +0100 | [diff] [blame] | 13 | #include <linux/smp.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | #include <linux/spinlock.h> |
David Howells | ca4d3e67 | 2010-10-07 14:08:54 +0100 | [diff] [blame] | 15 | #include <linux/irq.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | |
Thomas Bogendoerfer | ea202c6 | 2007-08-25 11:01:50 +0200 | [diff] [blame] | 17 | #include <asm/irq_cpu.h> |
Ralf Baechle | 89742e5 | 2007-10-18 13:51:15 +0100 | [diff] [blame] | 18 | #include <asm/i8253.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | #include <asm/i8259.h> |
| 20 | #include <asm/io.h> |
| 21 | #include <asm/jazz.h> |
Thomas Bogendoerfer | ea202c6 | 2007-08-25 11:01:50 +0200 | [diff] [blame] | 22 | #include <asm/pgtable.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | |
Ralf Baechle | 4a41abe5 | 2010-02-27 12:53:31 +0100 | [diff] [blame] | 24 | static DEFINE_RAW_SPINLOCK(r4030_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | |
| 26 | static void enable_r4030_irq(unsigned int irq) |
| 27 | { |
Thomas Bogendoerfer | ea202c6 | 2007-08-25 11:01:50 +0200 | [diff] [blame] | 28 | unsigned int mask = 1 << (irq - JAZZ_IRQ_START); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | unsigned long flags; |
| 30 | |
Ralf Baechle | 4a41abe5 | 2010-02-27 12:53:31 +0100 | [diff] [blame] | 31 | raw_spin_lock_irqsave(&r4030_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | mask |= r4030_read_reg16(JAZZ_IO_IRQ_ENABLE); |
| 33 | r4030_write_reg16(JAZZ_IO_IRQ_ENABLE, mask); |
Ralf Baechle | 4a41abe5 | 2010-02-27 12:53:31 +0100 | [diff] [blame] | 34 | raw_spin_unlock_irqrestore(&r4030_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | } |
| 36 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | void disable_r4030_irq(unsigned int irq) |
| 38 | { |
Thomas Bogendoerfer | ea202c6 | 2007-08-25 11:01:50 +0200 | [diff] [blame] | 39 | unsigned int mask = ~(1 << (irq - JAZZ_IRQ_START)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | unsigned long flags; |
| 41 | |
Ralf Baechle | 4a41abe5 | 2010-02-27 12:53:31 +0100 | [diff] [blame] | 42 | raw_spin_lock_irqsave(&r4030_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | mask &= r4030_read_reg16(JAZZ_IO_IRQ_ENABLE); |
| 44 | r4030_write_reg16(JAZZ_IO_IRQ_ENABLE, mask); |
Ralf Baechle | 4a41abe5 | 2010-02-27 12:53:31 +0100 | [diff] [blame] | 45 | raw_spin_unlock_irqrestore(&r4030_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | } |
| 47 | |
Ralf Baechle | 94dee17 | 2006-07-02 14:41:42 +0100 | [diff] [blame] | 48 | static struct irq_chip r4030_irq_type = { |
Atsushi Nemoto | 70d21cd | 2007-01-15 00:07:25 +0900 | [diff] [blame] | 49 | .name = "R4030", |
Atsushi Nemoto | 1603b5a | 2006-11-02 02:08:36 +0900 | [diff] [blame] | 50 | .ack = disable_r4030_irq, |
| 51 | .mask = disable_r4030_irq, |
| 52 | .mask_ack = disable_r4030_irq, |
| 53 | .unmask = enable_r4030_irq, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | }; |
| 55 | |
| 56 | void __init init_r4030_ints(void) |
| 57 | { |
| 58 | int i; |
| 59 | |
Thomas Bogendoerfer | ea202c6 | 2007-08-25 11:01:50 +0200 | [diff] [blame] | 60 | for (i = JAZZ_IRQ_START; i <= JAZZ_IRQ_END; i++) |
Atsushi Nemoto | 1417836 | 2006-11-14 01:13:18 +0900 | [diff] [blame] | 61 | set_irq_chip_and_handler(i, &r4030_irq_type, handle_level_irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | |
| 63 | r4030_write_reg16(JAZZ_IO_IRQ_ENABLE, 0); |
| 64 | r4030_read_reg16(JAZZ_IO_IRQ_SOURCE); /* clear pending IRQs */ |
| 65 | r4030_read_reg32(JAZZ_R4030_INVAL_ADDR); /* clear error bits */ |
| 66 | } |
| 67 | |
| 68 | /* |
| 69 | * On systems with i8259-style interrupt controllers we assume for |
| 70 | * driver compatibility reasons interrupts 0 - 15 to be the i8259 |
| 71 | * interrupts even if the hardware uses a different interrupt numbering. |
| 72 | */ |
| 73 | void __init arch_init_irq(void) |
| 74 | { |
Thomas Bogendoerfer | ea202c6 | 2007-08-25 11:01:50 +0200 | [diff] [blame] | 75 | /* |
| 76 | * this is a hack to get back the still needed wired mapping |
| 77 | * killed by init_mm() |
| 78 | */ |
| 79 | |
| 80 | /* Map 0xe0000000 -> 0x0:800005C0, 0xe0010000 -> 0x1:30000580 */ |
| 81 | add_wired_entry(0x02000017, 0x03c00017, 0xe0000000, PM_64K); |
| 82 | /* Map 0xe2000000 -> 0x0:900005C0, 0xe3010000 -> 0x0:910005C0 */ |
| 83 | add_wired_entry(0x02400017, 0x02440017, 0xe2000000, PM_16M); |
| 84 | /* Map 0xe4000000 -> 0x0:600005C0, 0xe4100000 -> 400005C0 */ |
| 85 | add_wired_entry(0x01800017, 0x01000017, 0xe4000000, PM_4M); |
| 86 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | init_i8259_irqs(); /* Integrated i8259 */ |
Thomas Bogendoerfer | ea202c6 | 2007-08-25 11:01:50 +0200 | [diff] [blame] | 88 | mips_cpu_irq_init(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | init_r4030_ints(); |
| 90 | |
Thomas Bogendoerfer | ea202c6 | 2007-08-25 11:01:50 +0200 | [diff] [blame] | 91 | change_c0_status(ST0_IM, IE_IRQ2 | IE_IRQ1); |
Ralf Baechle | e4ac58a | 2006-04-03 17:56:36 +0100 | [diff] [blame] | 92 | } |
| 93 | |
Ralf Baechle | 937a801 | 2006-10-07 19:44:33 +0100 | [diff] [blame] | 94 | asmlinkage void plat_irq_dispatch(void) |
Ralf Baechle | e4ac58a | 2006-04-03 17:56:36 +0100 | [diff] [blame] | 95 | { |
Thiemo Seufer | 119537c | 2007-03-19 00:13:37 +0000 | [diff] [blame] | 96 | unsigned int pending = read_c0_cause() & read_c0_status(); |
Thomas Bogendoerfer | ea202c6 | 2007-08-25 11:01:50 +0200 | [diff] [blame] | 97 | unsigned int irq; |
Ralf Baechle | e4ac58a | 2006-04-03 17:56:36 +0100 | [diff] [blame] | 98 | |
Thomas Bogendoerfer | ea202c6 | 2007-08-25 11:01:50 +0200 | [diff] [blame] | 99 | if (pending & IE_IRQ4) { |
Ralf Baechle | e4ac58a | 2006-04-03 17:56:36 +0100 | [diff] [blame] | 100 | r4030_read_reg32(JAZZ_TIMER_REGISTER); |
Ralf Baechle | 937a801 | 2006-10-07 19:44:33 +0100 | [diff] [blame] | 101 | do_IRQ(JAZZ_TIMER_IRQ); |
Thomas Bogendoerfer | 3be51f7 | 2007-11-02 11:17:13 +0100 | [diff] [blame] | 102 | } else if (pending & IE_IRQ2) { |
| 103 | irq = *(volatile u8 *)JAZZ_EISA_IRQ_ACK; |
| 104 | do_IRQ(irq); |
| 105 | } else if (pending & IE_IRQ1) { |
Thomas Bogendoerfer | ea202c6 | 2007-08-25 11:01:50 +0200 | [diff] [blame] | 106 | irq = *(volatile u8 *)JAZZ_IO_IRQ_SOURCE >> 2; |
| 107 | if (likely(irq > 0)) |
| 108 | do_IRQ(irq + JAZZ_IRQ_START - 1); |
| 109 | else |
| 110 | panic("Unimplemented loc_no_irq handler"); |
Ralf Baechle | e4ac58a | 2006-04-03 17:56:36 +0100 | [diff] [blame] | 111 | } |
| 112 | } |
Ralf Baechle | 584d98b | 2007-10-11 23:46:09 +0100 | [diff] [blame] | 113 | |
| 114 | static void r4030_set_mode(enum clock_event_mode mode, |
| 115 | struct clock_event_device *evt) |
| 116 | { |
| 117 | /* Nothing to do ... */ |
| 118 | } |
| 119 | |
| 120 | struct clock_event_device r4030_clockevent = { |
| 121 | .name = "r4030", |
| 122 | .features = CLOCK_EVT_FEAT_PERIODIC, |
Thomas Bogendoerfer | 3be51f7 | 2007-11-02 11:17:13 +0100 | [diff] [blame] | 123 | .rating = 300, |
Ralf Baechle | 584d98b | 2007-10-11 23:46:09 +0100 | [diff] [blame] | 124 | .irq = JAZZ_TIMER_IRQ, |
Ralf Baechle | 584d98b | 2007-10-11 23:46:09 +0100 | [diff] [blame] | 125 | .set_mode = r4030_set_mode, |
| 126 | }; |
| 127 | |
| 128 | static irqreturn_t r4030_timer_interrupt(int irq, void *dev_id) |
| 129 | { |
Thomas Bogendoerfer | 3be51f7 | 2007-11-02 11:17:13 +0100 | [diff] [blame] | 130 | struct clock_event_device *cd = dev_id; |
Ralf Baechle | 584d98b | 2007-10-11 23:46:09 +0100 | [diff] [blame] | 131 | |
Thomas Bogendoerfer | 3be51f7 | 2007-11-02 11:17:13 +0100 | [diff] [blame] | 132 | cd->event_handler(cd); |
Ralf Baechle | 584d98b | 2007-10-11 23:46:09 +0100 | [diff] [blame] | 133 | return IRQ_HANDLED; |
| 134 | } |
| 135 | |
| 136 | static struct irqaction r4030_timer_irqaction = { |
| 137 | .handler = r4030_timer_interrupt, |
Wu Zhangjin | f45e518 | 2009-10-08 21:17:54 +0800 | [diff] [blame] | 138 | .flags = IRQF_DISABLED | IRQF_TIMER, |
Thomas Bogendoerfer | 3be51f7 | 2007-11-02 11:17:13 +0100 | [diff] [blame] | 139 | .name = "R4030 timer", |
Ralf Baechle | 584d98b | 2007-10-11 23:46:09 +0100 | [diff] [blame] | 140 | }; |
| 141 | |
Ralf Baechle | 89742e5 | 2007-10-18 13:51:15 +0100 | [diff] [blame] | 142 | void __init plat_time_init(void) |
Ralf Baechle | 584d98b | 2007-10-11 23:46:09 +0100 | [diff] [blame] | 143 | { |
Thomas Bogendoerfer | 3be51f7 | 2007-11-02 11:17:13 +0100 | [diff] [blame] | 144 | struct clock_event_device *cd = &r4030_clockevent; |
| 145 | struct irqaction *action = &r4030_timer_irqaction; |
| 146 | unsigned int cpu = smp_processor_id(); |
Ralf Baechle | 584d98b | 2007-10-11 23:46:09 +0100 | [diff] [blame] | 147 | |
| 148 | BUG_ON(HZ != 100); |
| 149 | |
Rusty Russell | 320ab2b | 2008-12-13 21:20:26 +1030 | [diff] [blame] | 150 | cd->cpumask = cpumask_of(cpu); |
Thomas Bogendoerfer | 3be51f7 | 2007-11-02 11:17:13 +0100 | [diff] [blame] | 151 | clockevents_register_device(cd); |
| 152 | action->dev_id = cd; |
| 153 | setup_irq(JAZZ_TIMER_IRQ, action); |
| 154 | |
Ralf Baechle | 584d98b | 2007-10-11 23:46:09 +0100 | [diff] [blame] | 155 | /* |
| 156 | * Set clock to 100Hz. |
| 157 | * |
| 158 | * The R4030 timer receives an input clock of 1kHz which is divieded by |
| 159 | * a programmable 4-bit divider. This makes it fairly inflexible. |
| 160 | */ |
| 161 | r4030_write_reg32(JAZZ_TIMER_INTERVAL, 9); |
Ralf Baechle | 89742e5 | 2007-10-18 13:51:15 +0100 | [diff] [blame] | 162 | setup_pit_timer(); |
Ralf Baechle | 584d98b | 2007-10-11 23:46:09 +0100 | [diff] [blame] | 163 | } |