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
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>
21 #include <asm/amigahw.h>
22 #include <asm/amigaints.h>
25 volatile struct CIA
*cia
;
26 u_char icr_mask
, icr_data
;
28 int handler_irq
, cia_irq
, server_irq
;
30 irq_handler_t irq_list
[CIA_IRQS
];
32 &ciaa
, 0, 0, IF_PORTS
,
33 IRQ_AMIGA_AUTO_2
, IRQ_AMIGA_CIAA
,
37 &ciab
, 0, 0, IF_EXTER
,
38 IRQ_AMIGA_AUTO_6
, IRQ_AMIGA_CIAB
,
44 * Cause or clear CIA interrupts, return old interrupt status.
47 unsigned char cia_set_irq(struct ciabase
*base
, unsigned char mask
)
51 old
= (base
->icr_data
|= base
->cia
->icr
);
52 if (mask
& CIA_ICR_SETCLR
)
53 base
->icr_data
|= mask
;
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
)
72 base
->icr_data
|= base
->cia
->icr
;
73 base
->cia
->icr
= mask
;
74 if (mask
& CIA_ICR_SETCLR
)
75 base
->icr_mask
|= mask
;
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
;
85 if (base
->icr_data
& base
->icr_mask
)
86 custom
.intreq
= IF_SETCLR
| base
->int_mask
;
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
)
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 */
103 cia_set_irq(base
, mask
);
104 cia_able_irq(base
, CIA_ICR_SETCLR
| mask
);
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
;
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
++) {
133 kstat
.irqs
[0][irq
]++;
134 base
->irq_list
[i
].handler(mach_irq
, base
->irq_list
[i
].dev_id
, fp
);
138 amiga_do_irq_list(base
->server_irq
, fp
);
141 void __init
cia_init_IRQ(struct ciabase
*base
)
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
)
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
);