blob: f6bf25a2ff804a89beec32ed9c0bdae2a01e3b01 [file] [log] [blame]
Sam Ravnborge7870982011-01-28 22:08:19 +00001/*
2 * sun4c irq support
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 *
4 * djhr: Hacked out of irq.c into a CPU dependent version.
5 *
6 * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
7 * Copyright (C) 1995 Miguel de Icaza (miguel@nuclecu.unam.mx)
8 * Copyright (C) 1995 Pete A. Zaitcev (zaitcev@yahoo.com)
9 * Copyright (C) 1996 Dave Redman (djhr@tadpole.co.uk)
10 */
11
Linus Torvalds1da177e2005-04-16 15:20:36 -070012#include <linux/init.h>
13
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include <asm/oplib.h>
Sam Ravnborge7870982011-01-28 22:08:19 +000015#include <asm/timer.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070016#include <asm/irq.h>
17#include <asm/io.h>
Sam Ravnborge7870982011-01-28 22:08:19 +000018
19#include "irq.h"
20
21/* Sun4c interrupts are typically laid out as follows:
22 *
23 * 1 - Software interrupt, SBUS level 1
24 * 2 - SBUS level 2
25 * 3 - ESP SCSI, SBUS level 3
26 * 4 - Software interrupt
27 * 5 - Lance ethernet, SBUS level 4
28 * 6 - Software interrupt
29 * 7 - Graphics card, SBUS level 5
30 * 8 - SBUS level 6
31 * 9 - SBUS level 7
32 * 10 - Counter timer
33 * 11 - Floppy
34 * 12 - Zilog uart
35 * 13 - CS4231 audio
36 * 14 - Profiling timer
37 * 15 - NMI
38 *
39 * The interrupt enable bits in the interrupt mask register are
40 * really only used to enable/disable the timer interrupts, and
41 * for signalling software interrupts. There is also a master
42 * interrupt enable bit in this register.
43 *
44 * Interrupts are enabled by setting the SUN4C_INT_* bits, they
45 * are disabled by clearing those bits.
46 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070047
Al Viro32231a62007-07-21 19:18:57 -070048/*
49 * Bit field defines for the interrupt registers on various
50 * Sparc machines.
51 */
52
53/* The sun4c interrupt register. */
54#define SUN4C_INT_ENABLE 0x01 /* Allow interrupts. */
55#define SUN4C_INT_E14 0x80 /* Enable level 14 IRQ. */
56#define SUN4C_INT_E10 0x20 /* Enable level 10 IRQ. */
57#define SUN4C_INT_E8 0x10 /* Enable level 8 IRQ. */
58#define SUN4C_INT_E6 0x08 /* Enable level 6 IRQ. */
59#define SUN4C_INT_E4 0x04 /* Enable level 4 IRQ. */
60#define SUN4C_INT_E1 0x02 /* Enable level 1 IRQ. */
61
Sam Ravnborge7870982011-01-28 22:08:19 +000062/*
63 * Pointer to the interrupt enable byte
64 * Used by entry.S
Linus Torvalds1da177e2005-04-16 15:20:36 -070065 */
Sam Ravnborge7870982011-01-28 22:08:19 +000066unsigned char __iomem *interrupt_enable;
Linus Torvalds1da177e2005-04-16 15:20:36 -070067
Sam Ravnborg6baa9b22011-04-18 11:25:44 +000068static void sun4c_mask_irq(struct irq_data *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -070069{
Sam Ravnborg6baa9b22011-04-18 11:25:44 +000070 unsigned long mask = (unsigned long)data->chip_data;
Sam Ravnborge7870982011-01-28 22:08:19 +000071
Sam Ravnborg6baa9b22011-04-18 11:25:44 +000072 if (mask) {
73 unsigned long flags;
74
75 local_irq_save(flags);
76 mask = sbus_readb(interrupt_enable) & ~mask;
77 sbus_writeb(mask, interrupt_enable);
Linus Torvalds1da177e2005-04-16 15:20:36 -070078 local_irq_restore(flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -070079 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070080}
81
Sam Ravnborg6baa9b22011-04-18 11:25:44 +000082static void sun4c_unmask_irq(struct irq_data *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -070083{
Sam Ravnborg6baa9b22011-04-18 11:25:44 +000084 unsigned long mask = (unsigned long)data->chip_data;
Sam Ravnborge7870982011-01-28 22:08:19 +000085
Sam Ravnborg6baa9b22011-04-18 11:25:44 +000086 if (mask) {
87 unsigned long flags;
88
89 local_irq_save(flags);
90 mask = sbus_readb(interrupt_enable) | mask;
91 sbus_writeb(mask, interrupt_enable);
Linus Torvalds1da177e2005-04-16 15:20:36 -070092 local_irq_restore(flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -070093 }
Sam Ravnborg6baa9b22011-04-18 11:25:44 +000094}
95
96static unsigned int sun4c_startup_irq(struct irq_data *data)
97{
98 irq_link(data->irq);
99 sun4c_unmask_irq(data);
100
101 return 0;
102}
103
104static void sun4c_shutdown_irq(struct irq_data *data)
105{
106 sun4c_mask_irq(data);
107 irq_unlink(data->irq);
108}
109
110static struct irq_chip sun4c_irq = {
111 .name = "sun4c",
112 .irq_startup = sun4c_startup_irq,
113 .irq_shutdown = sun4c_shutdown_irq,
114 .irq_mask = sun4c_mask_irq,
115 .irq_unmask = sun4c_unmask_irq,
116};
117
118static unsigned int sun4c_build_device_irq(struct platform_device *op,
119 unsigned int real_irq)
120{
121 unsigned int irq;
122
123 if (real_irq >= 16) {
124 prom_printf("Bogus sun4c IRQ %u\n", real_irq);
125 prom_halt();
126 }
127
128 irq = irq_alloc(real_irq, real_irq);
129 if (irq) {
130 unsigned long mask = 0UL;
131
132 switch (real_irq) {
133 case 1:
134 mask = SUN4C_INT_E1;
135 break;
136 case 8:
137 mask = SUN4C_INT_E8;
138 break;
139 case 10:
140 mask = SUN4C_INT_E10;
141 break;
142 case 14:
143 mask = SUN4C_INT_E14;
144 break;
145 default:
146 /* All the rest are either always enabled,
147 * or are for signalling software interrupts.
148 */
149 break;
150 }
151 irq_set_chip_and_handler_name(irq, &sun4c_irq,
152 handle_level_irq, "level");
153 irq_set_chip_data(irq, (void *)mask);
154 }
155 return irq;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156}
157
David S. Miller8bd8dee2008-09-13 22:47:43 -0700158struct sun4c_timer_info {
159 u32 l10_count;
160 u32 l10_limit;
161 u32 l14_count;
162 u32 l14_limit;
163};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164
David S. Miller8bd8dee2008-09-13 22:47:43 -0700165static struct sun4c_timer_info __iomem *sun4c_timers;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167static void sun4c_clear_clock_irq(void)
168{
David S. Miller8bd8dee2008-09-13 22:47:43 -0700169 sbus_readl(&sun4c_timers->l10_limit);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170}
171
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172static void sun4c_load_profile_irq(int cpu, unsigned int limit)
173{
174 /* Errm.. not sure how to do this.. */
175}
176
David Howells40220c12006-10-09 12:19:47 +0100177static void __init sun4c_init_timers(irq_handler_t counter_fn)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178{
Sam Ravnborg6baa9b22011-04-18 11:25:44 +0000179 const struct linux_prom_irqs *prom_irqs;
David S. Miller8bd8dee2008-09-13 22:47:43 -0700180 struct device_node *dp;
Sam Ravnborg6baa9b22011-04-18 11:25:44 +0000181 unsigned int irq;
David S. Miller8bd8dee2008-09-13 22:47:43 -0700182 const u32 *addr;
183 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184
David S. Miller8bd8dee2008-09-13 22:47:43 -0700185 dp = of_find_node_by_name(NULL, "counter-timer");
186 if (!dp) {
187 prom_printf("sun4c_init_timers: Unable to find counter-timer\n");
188 prom_halt();
189 }
190
191 addr = of_get_property(dp, "address", NULL);
192 if (!addr) {
193 prom_printf("sun4c_init_timers: No address property\n");
194 prom_halt();
195 }
196
197 sun4c_timers = (void __iomem *) (unsigned long) addr[0];
198
Sam Ravnborg6baa9b22011-04-18 11:25:44 +0000199 prom_irqs = of_get_property(dp, "intr", NULL);
Nicolas Palixc2e27c32008-12-03 21:10:57 -0800200 of_node_put(dp);
Sam Ravnborg6baa9b22011-04-18 11:25:44 +0000201 if (!prom_irqs) {
David S. Miller8bd8dee2008-09-13 22:47:43 -0700202 prom_printf("sun4c_init_timers: No intr property\n");
203 prom_halt();
204 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205
206 /* Have the level 10 timer tick at 100HZ. We don't touch the
207 * level 14 timer limit since we are letting the prom handle
208 * them until we have a real console driver so L1-A works.
209 */
David S. Miller8bd8dee2008-09-13 22:47:43 -0700210 sbus_writel((((1000000/HZ) + 1) << 10), &sun4c_timers->l10_limit);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211
David S. Miller8bd8dee2008-09-13 22:47:43 -0700212 master_l10_counter = &sun4c_timers->l10_count;
David S. Miller8bd8dee2008-09-13 22:47:43 -0700213
Sam Ravnborg6baa9b22011-04-18 11:25:44 +0000214 irq = sun4c_build_device_irq(NULL, prom_irqs[0].pri);
215 err = request_irq(irq, counter_fn, IRQF_TIMER, "timer", NULL);
David S. Miller8bd8dee2008-09-13 22:47:43 -0700216 if (err) {
217 prom_printf("sun4c_init_timers: request_irq() fails with %d\n", err);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218 prom_halt();
219 }
Sam Ravnborge7870982011-01-28 22:08:19 +0000220
Sam Ravnborg6baa9b22011-04-18 11:25:44 +0000221 /* disable timer interrupt */
222 sun4c_mask_irq(irq_get_irq_data(irq));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223}
224
225#ifdef CONFIG_SMP
Sam Ravnborge7870982011-01-28 22:08:19 +0000226static void sun4c_nop(void)
227{
228}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229#endif
230
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231void __init sun4c_init_IRQ(void)
232{
David S. Miller45bb5a72008-09-13 22:43:48 -0700233 struct device_node *dp;
234 const u32 *addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235
David S. Miller45bb5a72008-09-13 22:43:48 -0700236 dp = of_find_node_by_name(NULL, "interrupt-enable");
237 if (!dp) {
238 prom_printf("sun4c_init_IRQ: Unable to find interrupt-enable\n");
239 prom_halt();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240 }
David S. Miller45bb5a72008-09-13 22:43:48 -0700241
242 addr = of_get_property(dp, "address", NULL);
Nicolas Palixc2e27c32008-12-03 21:10:57 -0800243 of_node_put(dp);
David S. Miller45bb5a72008-09-13 22:43:48 -0700244 if (!addr) {
245 prom_printf("sun4c_init_IRQ: No address property\n");
246 prom_halt();
247 }
248
249 interrupt_enable = (void __iomem *) (unsigned long) addr[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251 BTFIXUPSET_CALL(clear_clock_irq, sun4c_clear_clock_irq, BTFIXUPCALL_NORM);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252 BTFIXUPSET_CALL(load_profile_irq, sun4c_load_profile_irq, BTFIXUPCALL_NOP);
Sam Ravnborgbbdc2662011-02-25 23:00:19 -0800253
Sam Ravnborg6baa9b22011-04-18 11:25:44 +0000254 sparc_irq_config.init_timers = sun4c_init_timers;
255 sparc_irq_config.build_device_irq = sun4c_build_device_irq;
Sam Ravnborgbbdc2662011-02-25 23:00:19 -0800256
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257#ifdef CONFIG_SMP
258 BTFIXUPSET_CALL(set_cpu_int, sun4c_nop, BTFIXUPCALL_NOP);
259 BTFIXUPSET_CALL(clear_cpu_int, sun4c_nop, BTFIXUPCALL_NOP);
260 BTFIXUPSET_CALL(set_irq_udt, sun4c_nop, BTFIXUPCALL_NOP);
261#endif
David S. Miller45bb5a72008-09-13 22:43:48 -0700262 sbus_writeb(SUN4C_INT_ENABLE, interrupt_enable);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263 /* Cannot enable interrupts until OBP ticker is disabled. */
264}