GUI: Fix Tomato RAF theme for all builds. Compilation typo.
[tomato.git] / release / src-rt-6.x.4708 / linux / linux-2.6.36 / arch / sh / boards / mach-dreamcast / irq.c
blobd932667410ab9f79533f10be378e5b4218c37e4c
1 /*
2 * arch/sh/boards/dreamcast/irq.c
4 * Holly IRQ support for the Sega Dreamcast.
6 * Copyright (c) 2001, 2002 M. R. Brown <mrbrown@0xd6.org>
8 * This file is part of the LinuxDC project (www.linuxdc.org)
9 * Released under the terms of the GNU GPL v2.0
12 #include <linux/irq.h>
13 #include <linux/io.h>
14 #include <asm/irq.h>
15 #include <mach/sysasic.h>
18 * Dreamcast System ASIC Hardware Events -
20 * The Dreamcast's System ASIC (a.k.a. Holly) is responsible for receiving
21 * hardware events from system peripherals and triggering an SH7750 IRQ.
22 * Hardware events can trigger IRQs 13, 11, or 9 depending on which bits are
23 * set in the Event Mask Registers (EMRs). When a hardware event is
24 * triggered, its corresponding bit in the Event Status Registers (ESRs)
25 * is set, and that bit should be rewritten to the ESR to acknowledge that
26 * event.
28 * There are three 32-bit ESRs located at 0xa05f6900 - 0xa05f6908. Event
29 * types can be found in arch/sh/include/mach-dreamcast/mach/sysasic.h.
30 * There are three groups of EMRs that parallel the ESRs. Each EMR group
31 * corresponds to an IRQ, so 0xa05f6910 - 0xa05f6918 triggers IRQ 13,
32 * 0xa05f6920 - 0xa05f6928 triggers IRQ 11, and 0xa05f6930 - 0xa05f6938
33 * triggers IRQ 9.
35 * In the kernel, these events are mapped to virtual IRQs so that drivers can
36 * respond to them as they would a normal interrupt. In order to keep this
37 * mapping simple, the events are mapped as:
39 * 6900/6910 - Events 0-31, IRQ 13
40 * 6904/6924 - Events 32-63, IRQ 11
41 * 6908/6938 - Events 64-95, IRQ 9
45 #define ESR_BASE 0x005f6900 /* Base event status register */
46 #define EMR_BASE 0x005f6910 /* Base event mask register */
49 * Helps us determine the EMR group that this event belongs to: 0 = 0x6910,
50 * 1 = 0x6920, 2 = 0x6930; also determine the event offset.
52 #define LEVEL(event) (((event) - HW_EVENT_IRQ_BASE) / 32)
54 /* Return the hardware event's bit positon within the EMR/ESR */
55 #define EVENT_BIT(event) (((event) - HW_EVENT_IRQ_BASE) & 31)
58 * For each of these *_irq routines, the IRQ passed in is the virtual IRQ
59 * (logically mapped to the corresponding bit for the hardware event).
62 /* Disable the hardware event by masking its bit in its EMR */
63 static inline void disable_systemasic_irq(unsigned int irq)
65 __u32 emr = EMR_BASE + (LEVEL(irq) << 4) + (LEVEL(irq) << 2);
66 __u32 mask;
68 mask = inl(emr);
69 mask &= ~(1 << EVENT_BIT(irq));
70 outl(mask, emr);
73 /* Enable the hardware event by setting its bit in its EMR */
74 static inline void enable_systemasic_irq(unsigned int irq)
76 __u32 emr = EMR_BASE + (LEVEL(irq) << 4) + (LEVEL(irq) << 2);
77 __u32 mask;
79 mask = inl(emr);
80 mask |= (1 << EVENT_BIT(irq));
81 outl(mask, emr);
84 /* Acknowledge a hardware event by writing its bit back to its ESR */
85 static void mask_ack_systemasic_irq(unsigned int irq)
87 __u32 esr = ESR_BASE + (LEVEL(irq) << 2);
88 disable_systemasic_irq(irq);
89 outl((1 << EVENT_BIT(irq)), esr);
92 struct irq_chip systemasic_int = {
93 .name = "System ASIC",
94 .mask = disable_systemasic_irq,
95 .mask_ack = mask_ack_systemasic_irq,
96 .unmask = enable_systemasic_irq,
100 * Map the hardware event indicated by the processor IRQ to a virtual IRQ.
102 int systemasic_irq_demux(int irq)
104 __u32 emr, esr, status, level;
105 __u32 j, bit;
107 switch (irq) {
108 case 13:
109 level = 0;
110 break;
111 case 11:
112 level = 1;
113 break;
114 case 9:
115 level = 2;
116 break;
117 default:
118 return irq;
120 emr = EMR_BASE + (level << 4) + (level << 2);
121 esr = ESR_BASE + (level << 2);
123 /* Mask the ESR to filter any spurious, unwanted interrupts */
124 status = inl(esr);
125 status &= inl(emr);
127 /* Now scan and find the first set bit as the event to map */
128 for (bit = 1, j = 0; j < 32; bit <<= 1, j++) {
129 if (status & bit) {
130 irq = HW_EVENT_IRQ_BASE + j + (level << 5);
131 return irq;
135 /* Not reached */
136 return irq;
139 void systemasic_irq_init(void)
141 int i, nid = cpu_to_node(boot_cpu_data);
143 /* Assign all virtual IRQs to the System ASIC int. handler */
144 for (i = HW_EVENT_IRQ_BASE; i < HW_EVENT_IRQ_MAX; i++) {
145 unsigned int irq;
147 irq = create_irq_nr(i, nid);
148 if (unlikely(irq == 0)) {
149 pr_err("%s: failed hooking irq %d for systemasic\n",
150 __func__, i);
151 return;
154 if (unlikely(irq != i)) {
155 pr_err("%s: got irq %d but wanted %d, bailing.\n",
156 __func__, irq, i);
157 destroy_irq(irq);
158 return;
161 set_irq_chip_and_handler(i, &systemasic_int,
162 handle_level_irq);