blob: 18c0e29976e37475cf822b5b11d9bf32437791eb [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * linux/arch/m68k/amiga/cia.c - CIA support
3 *
4 * Copyright (C) 1996 Roman Zippel
5 *
6 * The concept of some functions bases on the original Amiga OS function
7 *
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.
11 */
12
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>
19#include <linux/seq_file.h>
20#include <linux/interrupt.h>
21
22#include <asm/irq.h>
23#include <asm/amigahw.h>
24#include <asm/amigaints.h>
25
26struct ciabase {
27 volatile struct CIA *cia;
28 unsigned char icr_mask, icr_data;
29 unsigned short int_mask;
30 int handler_irq, cia_irq, server_irq;
31 char *name;
Linus Torvalds1da177e2005-04-16 15:20:36 -070032} ciaa_base = {
33 .cia = &ciaa,
34 .int_mask = IF_PORTS,
Roman Zippel74be8d02006-06-25 05:47:01 -070035 .handler_irq = IRQ_AMIGA_PORTS,
Linus Torvalds1da177e2005-04-16 15:20:36 -070036 .cia_irq = IRQ_AMIGA_CIAA,
Roman Zippel74be8d02006-06-25 05:47:01 -070037 .name = "CIAA"
Linus Torvalds1da177e2005-04-16 15:20:36 -070038}, ciab_base = {
39 .cia = &ciab,
40 .int_mask = IF_EXTER,
Roman Zippel74be8d02006-06-25 05:47:01 -070041 .handler_irq = IRQ_AMIGA_EXTER,
Linus Torvalds1da177e2005-04-16 15:20:36 -070042 .cia_irq = IRQ_AMIGA_CIAB,
Roman Zippel74be8d02006-06-25 05:47:01 -070043 .name = "CIAB"
Linus Torvalds1da177e2005-04-16 15:20:36 -070044};
45
46/*
47 * Cause or clear CIA interrupts, return old interrupt status.
48 */
49
50unsigned char cia_set_irq(struct ciabase *base, unsigned char mask)
51{
52 unsigned char old;
53
54 old = (base->icr_data |= base->cia->icr);
55 if (mask & CIA_ICR_SETCLR)
56 base->icr_data |= mask;
57 else
58 base->icr_data &= ~mask;
59 if (base->icr_data & base->icr_mask)
Al Virob4290a22006-01-12 01:06:12 -080060 amiga_custom.intreq = IF_SETCLR | base->int_mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -070061 return old & base->icr_mask;
62}
63
64/*
65 * Enable or disable CIA interrupts, return old interrupt mask,
Linus Torvalds1da177e2005-04-16 15:20:36 -070066 */
67
68unsigned char cia_able_irq(struct ciabase *base, unsigned char mask)
69{
Roman Zippel74be8d02006-06-25 05:47:01 -070070 unsigned char old;
Linus Torvalds1da177e2005-04-16 15:20:36 -070071
72 old = base->icr_mask;
73 base->icr_data |= base->cia->icr;
74 base->cia->icr = mask;
75 if (mask & CIA_ICR_SETCLR)
76 base->icr_mask |= mask;
77 else
78 base->icr_mask &= ~mask;
79 base->icr_mask &= CIA_ICR_ALL;
Linus Torvalds1da177e2005-04-16 15:20:36 -070080 if (base->icr_data & base->icr_mask)
Al Virob4290a22006-01-12 01:06:12 -080081 amiga_custom.intreq = IF_SETCLR | base->int_mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -070082 return old;
83}
84
Al Viro2850bc22006-10-07 14:16:45 +010085static irqreturn_t cia_handler(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -070086{
Jeff Garzik15aafa22008-02-06 01:36:20 -080087 struct ciabase *base = dev_id;
Roman Zippel74be8d02006-06-25 05:47:01 -070088 int mach_irq;
Linus Torvalds1da177e2005-04-16 15:20:36 -070089 unsigned char ints;
90
91 mach_irq = base->cia_irq;
Linus Torvalds1da177e2005-04-16 15:20:36 -070092 ints = cia_set_irq(base, CIA_ICR_ALL);
Al Virob4290a22006-01-12 01:06:12 -080093 amiga_custom.intreq = base->int_mask;
Roman Zippel74be8d02006-06-25 05:47:01 -070094 for (; ints; mach_irq++, ints >>= 1) {
95 if (ints & 1)
Geert Uytterhoeven1425df82011-07-01 20:39:19 +020096 generic_handle_irq(mach_irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -070097 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 return IRQ_HANDLED;
99}
100
Geert Uytterhoevene8abf5e2011-04-17 22:53:04 +0200101static void cia_irq_enable(struct irq_data *data)
Roman Zippel74be8d02006-06-25 05:47:01 -0700102{
Geert Uytterhoevene8abf5e2011-04-17 22:53:04 +0200103 unsigned int irq = data->irq;
Roman Zippel74be8d02006-06-25 05:47:01 -0700104 unsigned char mask;
105
106 if (irq >= IRQ_AMIGA_CIAB) {
107 mask = 1 << (irq - IRQ_AMIGA_CIAB);
108 cia_set_irq(&ciab_base, mask);
109 cia_able_irq(&ciab_base, CIA_ICR_SETCLR | mask);
110 } else {
111 mask = 1 << (irq - IRQ_AMIGA_CIAA);
112 cia_set_irq(&ciaa_base, mask);
113 cia_able_irq(&ciaa_base, CIA_ICR_SETCLR | mask);
114 }
115}
116
Geert Uytterhoevene8abf5e2011-04-17 22:53:04 +0200117static void cia_irq_disable(struct irq_data *data)
Roman Zippel74be8d02006-06-25 05:47:01 -0700118{
Geert Uytterhoevene8abf5e2011-04-17 22:53:04 +0200119 unsigned int irq = data->irq;
120
Roman Zippel74be8d02006-06-25 05:47:01 -0700121 if (irq >= IRQ_AMIGA_CIAB)
122 cia_able_irq(&ciab_base, 1 << (irq - IRQ_AMIGA_CIAB));
123 else
124 cia_able_irq(&ciaa_base, 1 << (irq - IRQ_AMIGA_CIAA));
125}
126
Geert Uytterhoevenc288bf22011-04-13 22:31:28 +0200127static struct irq_chip cia_irq_chip = {
Roman Zippel74be8d02006-06-25 05:47:01 -0700128 .name = "cia",
Geert Uytterhoevene8abf5e2011-04-17 22:53:04 +0200129 .irq_enable = cia_irq_enable,
130 .irq_disable = cia_irq_disable,
Roman Zippel74be8d02006-06-25 05:47:01 -0700131};
132
133/*
134 * Override auto irq 2 & 6 and use them as general chain
135 * for external interrupts, we link the CIA interrupt sources
136 * into this chain.
137 */
138
Geert Uytterhoevene8abf5e2011-04-17 22:53:04 +0200139static void auto_irq_enable(struct irq_data *data)
Roman Zippel74be8d02006-06-25 05:47:01 -0700140{
Geert Uytterhoevene8abf5e2011-04-17 22:53:04 +0200141 switch (data->irq) {
Roman Zippel74be8d02006-06-25 05:47:01 -0700142 case IRQ_AUTO_2:
143 amiga_custom.intena = IF_SETCLR | IF_PORTS;
144 break;
145 case IRQ_AUTO_6:
146 amiga_custom.intena = IF_SETCLR | IF_EXTER;
147 break;
148 }
149}
150
Geert Uytterhoevene8abf5e2011-04-17 22:53:04 +0200151static void auto_irq_disable(struct irq_data *data)
Roman Zippel74be8d02006-06-25 05:47:01 -0700152{
Geert Uytterhoevene8abf5e2011-04-17 22:53:04 +0200153 switch (data->irq) {
Roman Zippel74be8d02006-06-25 05:47:01 -0700154 case IRQ_AUTO_2:
155 amiga_custom.intena = IF_PORTS;
156 break;
157 case IRQ_AUTO_6:
158 amiga_custom.intena = IF_EXTER;
159 break;
160 }
161}
162
Geert Uytterhoevenc288bf22011-04-13 22:31:28 +0200163static struct irq_chip auto_irq_chip = {
Roman Zippel74be8d02006-06-25 05:47:01 -0700164 .name = "auto",
Geert Uytterhoevene8abf5e2011-04-17 22:53:04 +0200165 .irq_enable = auto_irq_enable,
166 .irq_disable = auto_irq_disable,
Roman Zippel74be8d02006-06-25 05:47:01 -0700167};
168
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169void __init cia_init_IRQ(struct ciabase *base)
170{
Geert Uytterhoevenedb34722011-06-01 11:15:21 +0200171 m68k_setup_irq_controller(&cia_irq_chip, handle_simple_irq,
172 base->cia_irq, CIA_IRQS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173
174 /* clear any pending interrupt and turn off all interrupts */
175 cia_set_irq(base, CIA_ICR_ALL);
176 cia_able_irq(base, CIA_ICR_ALL);
177
Roman Zippel74be8d02006-06-25 05:47:01 -0700178 /* override auto int and install CIA handler */
Geert Uytterhoevenedb34722011-06-01 11:15:21 +0200179 m68k_setup_irq_controller(&auto_irq_chip, handle_simple_irq,
180 base->handler_irq, 1);
Geert Uytterhoevene8abf5e2011-04-17 22:53:04 +0200181 m68k_irq_startup_irq(base->handler_irq);
Geert Uytterhoeven66acd252008-12-30 14:00:34 +0100182 if (request_irq(base->handler_irq, cia_handler, IRQF_SHARED,
183 base->name, base))
184 pr_err("Couldn't register %s interrupt\n", base->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185}