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 struct irq_server server
;
31 irq_handler_t irq_list
[CIA_IRQS
];
33 &ciaa
, 0, 0, IF_PORTS
,
34 IRQ_AMIGA_AUTO_2
, IRQ_AMIGA_CIAA
,
36 "CIAA handler", {0, 0}
38 &ciab
, 0, 0, IF_EXTER
,
39 IRQ_AMIGA_AUTO_6
, IRQ_AMIGA_CIAB
,
41 "CIAB handler", {0, 0}
45 * Cause or clear CIA interrupts, return old interrupt status.
48 unsigned char cia_set_irq(struct ciabase
*base
, unsigned char mask
)
52 old
= (base
->icr_data
|= base
->cia
->icr
);
53 if (mask
& CIA_ICR_SETCLR
)
54 base
->icr_data
|= mask
;
56 base
->icr_data
&= ~mask
;
57 if (base
->icr_data
& base
->icr_mask
)
58 custom
.intreq
= IF_SETCLR
| base
->int_mask
;
59 return old
& base
->icr_mask
;
63 * Enable or disable CIA interrupts, return old interrupt mask,
64 * interrupts will only be enabled if a handler exists
67 unsigned char cia_able_irq(struct ciabase
*base
, unsigned char mask
)
73 base
->icr_data
|= base
->cia
->icr
;
74 base
->cia
->icr
= mask
;
75 if (mask
& CIA_ICR_SETCLR
)
76 base
->icr_mask
|= mask
;
78 base
->icr_mask
&= ~mask
;
79 base
->icr_mask
&= CIA_ICR_ALL
;
80 for (i
= 0, tmp
= 1; i
< CIA_IRQS
; i
++, tmp
<<= 1) {
81 if ((tmp
& base
->icr_mask
) && !base
->irq_list
[i
].handler
) {
82 base
->icr_mask
&= ~tmp
;
86 if (base
->icr_data
& base
->icr_mask
)
87 custom
.intreq
= IF_SETCLR
| base
->int_mask
;
91 int cia_request_irq(struct ciabase
*base
, unsigned int irq
,
92 void (*handler
)(int, void *, struct pt_regs
*),
93 unsigned long flags
, const char *devname
, void *dev_id
)
97 base
->irq_list
[irq
].handler
= handler
;
98 base
->irq_list
[irq
].flags
= flags
;
99 base
->irq_list
[irq
].dev_id
= dev_id
;
100 base
->irq_list
[irq
].devname
= devname
;
102 /* enable the interrupt */
104 cia_set_irq(base
, mask
);
105 cia_able_irq(base
, CIA_ICR_SETCLR
| mask
);
109 void cia_free_irq(struct ciabase
*base
, unsigned int irq
, void *dev_id
)
111 if (base
->irq_list
[irq
].dev_id
!= dev_id
)
112 printk("%s: removing probably wrong IRQ %i from %s\n",
113 __FUNCTION__
, base
->cia_irq
+ irq
,
114 base
->irq_list
[irq
].devname
);
116 base
->irq_list
[irq
].handler
= NULL
;
117 base
->irq_list
[irq
].flags
= 0;
119 cia_able_irq(base
, 1 << irq
);
122 static void cia_handler(int irq
, void *dev_id
, struct pt_regs
*fp
)
124 struct ciabase
*base
= (struct ciabase
*)dev_id
;
128 mach_irq
= base
->cia_irq
;
129 irq
= SYS_IRQS
+ mach_irq
;
130 ints
= cia_set_irq(base
, CIA_ICR_ALL
);
131 custom
.intreq
= base
->int_mask
;
132 for (i
= 0; i
< CIA_IRQS
; i
++, irq
++, mach_irq
++) {
134 kstat
.irqs
[0][irq
]++;
135 base
->irq_list
[i
].handler(mach_irq
, base
->irq_list
[i
].dev_id
, fp
);
139 amiga_do_irq_list(base
->server_irq
, fp
, &base
->server
);
142 void __init
cia_init_IRQ(struct ciabase
*base
)
146 /* init isr handlers */
147 for (i
= 0; i
< CIA_IRQS
; i
++) {
148 base
->irq_list
[i
].handler
= NULL
;
149 base
->irq_list
[i
].flags
= 0;
152 /* clear any pending interrupt and turn off all interrupts */
153 cia_set_irq(base
, CIA_ICR_ALL
);
154 cia_able_irq(base
, CIA_ICR_ALL
);
156 /* install CIA handler */
157 request_irq(base
->handler_irq
, cia_handler
, 0, base
->name
, base
);
159 custom
.intena
= IF_SETCLR
| base
->int_mask
;
162 int cia_get_irq_list(struct ciabase
*base
, char *buf
)
167 for (i
= 0; i
< CIA_IRQS
; i
++) {
168 len
+= sprintf(buf
+len
, "cia %2d: %10d ", j
+ i
,
169 kstat
.irqs
[0][SYS_IRQS
+ j
+ i
]);
170 len
+= sprintf(buf
+len
, " ");
171 len
+= sprintf(buf
+len
, "%s\n", base
->irq_list
[i
].devname
);