The most noticeable part of this is that the run_task_queue fix should
[davej-history.git] / arch / m68k / amiga / cia.c
blobd72d8af9ff14d861fc945dc076fa67763c141577
1 /*
2 * linux/arch/m68k/amiga/cia.c - CIA support
4 * Copyright (C) 1996 Roman Zippel
6 * The concept of some functions bases on the original Amiga OS function
8 * This file is subject to the terms and conditions of the GNU General Public
9 * License. See the file COPYING in the main directory of this archive
10 * for more details.
13 #include <linux/types.h>
14 #include <linux/kernel.h>
15 #include <linux/sched.h>
16 #include <linux/errno.h>
17 #include <linux/kernel_stat.h>
18 #include <linux/init.h>
20 #include <asm/irq.h>
21 #include <asm/amigahw.h>
22 #include <asm/amigaints.h>
24 struct ciabase {
25 volatile struct CIA *cia;
26 u_char icr_mask, icr_data;
27 u_short int_mask;
28 int handler_irq, cia_irq, server_irq;
29 char *name;
30 irq_handler_t irq_list[CIA_IRQS];
31 } ciaa_base = {
32 &ciaa, 0, 0, IF_PORTS,
33 IRQ_AMIGA_AUTO_2, IRQ_AMIGA_CIAA,
34 IRQ_AMIGA_PORTS,
35 "CIAA handler"
36 }, ciab_base = {
37 &ciab, 0, 0, IF_EXTER,
38 IRQ_AMIGA_AUTO_6, IRQ_AMIGA_CIAB,
39 IRQ_AMIGA_EXTER,
40 "CIAB handler"
44 * Cause or clear CIA interrupts, return old interrupt status.
47 unsigned char cia_set_irq(struct ciabase *base, unsigned char mask)
49 u_char old;
51 old = (base->icr_data |= base->cia->icr);
52 if (mask & CIA_ICR_SETCLR)
53 base->icr_data |= mask;
54 else
55 base->icr_data &= ~mask;
56 if (base->icr_data & base->icr_mask)
57 custom.intreq = IF_SETCLR | base->int_mask;
58 return old & base->icr_mask;
62 * Enable or disable CIA interrupts, return old interrupt mask,
63 * interrupts will only be enabled if a handler exists
66 unsigned char cia_able_irq(struct ciabase *base, unsigned char mask)
68 u_char old, tmp;
69 int i;
71 old = base->icr_mask;
72 base->icr_data |= base->cia->icr;
73 base->cia->icr = mask;
74 if (mask & CIA_ICR_SETCLR)
75 base->icr_mask |= mask;
76 else
77 base->icr_mask &= ~mask;
78 base->icr_mask &= CIA_ICR_ALL;
79 for (i = 0, tmp = 1; i < CIA_IRQS; i++, tmp <<= 1) {
80 if ((tmp & base->icr_mask) && !base->irq_list[i].handler) {
81 base->icr_mask &= ~tmp;
82 base->cia->icr = tmp;
85 if (base->icr_data & base->icr_mask)
86 custom.intreq = IF_SETCLR | base->int_mask;
87 return old;
90 int cia_request_irq(struct ciabase *base, unsigned int irq,
91 void (*handler)(int, void *, struct pt_regs *),
92 unsigned long flags, const char *devname, void *dev_id)
94 u_char mask;
96 base->irq_list[irq].handler = handler;
97 base->irq_list[irq].flags = flags;
98 base->irq_list[irq].dev_id = dev_id;
99 base->irq_list[irq].devname = devname;
101 /* enable the interrupt */
102 mask = 1 << irq;
103 cia_set_irq(base, mask);
104 cia_able_irq(base, CIA_ICR_SETCLR | mask);
105 return 0;
108 void cia_free_irq(struct ciabase *base, unsigned int irq, void *dev_id)
110 if (base->irq_list[irq].dev_id != dev_id)
111 printk("%s: removing probably wrong IRQ %i from %s\n",
112 __FUNCTION__, base->cia_irq + irq,
113 base->irq_list[irq].devname);
115 base->irq_list[irq].handler = NULL;
116 base->irq_list[irq].flags = 0;
118 cia_able_irq(base, 1 << irq);
121 static void cia_handler(int irq, void *dev_id, struct pt_regs *fp)
123 struct ciabase *base = (struct ciabase *)dev_id;
124 int mach_irq, i;
125 unsigned char ints;
127 mach_irq = base->cia_irq;
128 irq = SYS_IRQS + mach_irq;
129 ints = cia_set_irq(base, CIA_ICR_ALL);
130 custom.intreq = base->int_mask;
131 for (i = 0; i < CIA_IRQS; i++, irq++, mach_irq++) {
132 if (ints & 1) {
133 kstat.irqs[0][irq]++;
134 base->irq_list[i].handler(mach_irq, base->irq_list[i].dev_id, fp);
136 ints >>= 1;
138 amiga_do_irq_list(base->server_irq, fp);
141 void __init cia_init_IRQ(struct ciabase *base)
143 int i;
145 /* init isr handlers */
146 for (i = 0; i < CIA_IRQS; i++) {
147 base->irq_list[i].handler = NULL;
148 base->irq_list[i].flags = 0;
151 /* clear any pending interrupt and turn off all interrupts */
152 cia_set_irq(base, CIA_ICR_ALL);
153 cia_able_irq(base, CIA_ICR_ALL);
155 /* install CIA handler */
156 request_irq(base->handler_irq, cia_handler, 0, base->name, base);
158 custom.intena = IF_SETCLR | base->int_mask;
161 int cia_get_irq_list(struct ciabase *base, char *buf)
163 int i, j, len = 0;
165 j = base->cia_irq;
166 for (i = 0; i < CIA_IRQS; i++) {
167 len += sprintf(buf+len, "cia %2d: %10d ", j + i,
168 kstat.irqs[0][SYS_IRQS + j + i]);
169 len += sprintf(buf+len, " ");
170 len += sprintf(buf+len, "%s\n", base->irq_list[i].devname);
172 return len;