blob: 2081b8cd5591c6d77385de8594e737c9d421f7be [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>
Thomas Gleixner14b43192014-03-19 11:17:40 +010021#include <linux/irq.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070022
23#include <asm/irq.h>
24#include <asm/amigahw.h>
25#include <asm/amigaints.h>
26
27struct ciabase {
28 volatile struct CIA *cia;
29 unsigned char icr_mask, icr_data;
30 unsigned short int_mask;
31 int handler_irq, cia_irq, server_irq;
32 char *name;
Linus Torvalds1da177e2005-04-16 15:20:36 -070033} ciaa_base = {
34 .cia = &ciaa,
35 .int_mask = IF_PORTS,
Roman Zippel74be8d02006-06-25 05:47:01 -070036 .handler_irq = IRQ_AMIGA_PORTS,
Linus Torvalds1da177e2005-04-16 15:20:36 -070037 .cia_irq = IRQ_AMIGA_CIAA,
Roman Zippel74be8d02006-06-25 05:47:01 -070038 .name = "CIAA"
Linus Torvalds1da177e2005-04-16 15:20:36 -070039}, ciab_base = {
40 .cia = &ciab,
41 .int_mask = IF_EXTER,
Roman Zippel74be8d02006-06-25 05:47:01 -070042 .handler_irq = IRQ_AMIGA_EXTER,
Linus Torvalds1da177e2005-04-16 15:20:36 -070043 .cia_irq = IRQ_AMIGA_CIAB,
Roman Zippel74be8d02006-06-25 05:47:01 -070044 .name = "CIAB"
Linus Torvalds1da177e2005-04-16 15:20:36 -070045};
46
47/*
48 * Cause or clear CIA interrupts, return old interrupt status.
49 */
50
51unsigned char cia_set_irq(struct ciabase *base, unsigned char mask)
52{
53 unsigned char old;
54
55 old = (base->icr_data |= base->cia->icr);
56 if (mask & CIA_ICR_SETCLR)
57 base->icr_data |= mask;
58 else
59 base->icr_data &= ~mask;
60 if (base->icr_data & base->icr_mask)
Al Virob4290a22006-01-12 01:06:12 -080061 amiga_custom.intreq = IF_SETCLR | base->int_mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -070062 return old & base->icr_mask;
63}
64
65/*
66 * Enable or disable CIA interrupts, return old interrupt mask,
Linus Torvalds1da177e2005-04-16 15:20:36 -070067 */
68
69unsigned char cia_able_irq(struct ciabase *base, unsigned char mask)
70{
Roman Zippel74be8d02006-06-25 05:47:01 -070071 unsigned char old;
Linus Torvalds1da177e2005-04-16 15:20:36 -070072
73 old = base->icr_mask;
74 base->icr_data |= base->cia->icr;
75 base->cia->icr = mask;
76 if (mask & CIA_ICR_SETCLR)
77 base->icr_mask |= mask;
78 else
79 base->icr_mask &= ~mask;
80 base->icr_mask &= CIA_ICR_ALL;
Linus Torvalds1da177e2005-04-16 15:20:36 -070081 if (base->icr_data & base->icr_mask)
Al Virob4290a22006-01-12 01:06:12 -080082 amiga_custom.intreq = IF_SETCLR | base->int_mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -070083 return old;
84}
85
Al Viro2850bc22006-10-07 14:16:45 +010086static irqreturn_t cia_handler(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -070087{
Jeff Garzik15aafa22008-02-06 01:36:20 -080088 struct ciabase *base = dev_id;
Roman Zippel74be8d02006-06-25 05:47:01 -070089 int mach_irq;
Linus Torvalds1da177e2005-04-16 15:20:36 -070090 unsigned char ints;
91
92 mach_irq = base->cia_irq;
Linus Torvalds1da177e2005-04-16 15:20:36 -070093 ints = cia_set_irq(base, CIA_ICR_ALL);
Al Virob4290a22006-01-12 01:06:12 -080094 amiga_custom.intreq = base->int_mask;
Roman Zippel74be8d02006-06-25 05:47:01 -070095 for (; ints; mach_irq++, ints >>= 1) {
96 if (ints & 1)
Geert Uytterhoeven1425df82011-07-01 20:39:19 +020097 generic_handle_irq(mach_irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070099 return IRQ_HANDLED;
100}
101
Geert Uytterhoevene8abf5e2011-04-17 22:53:04 +0200102static void cia_irq_enable(struct irq_data *data)
Roman Zippel74be8d02006-06-25 05:47:01 -0700103{
Geert Uytterhoevene8abf5e2011-04-17 22:53:04 +0200104 unsigned int irq = data->irq;
Roman Zippel74be8d02006-06-25 05:47:01 -0700105 unsigned char mask;
106
107 if (irq >= IRQ_AMIGA_CIAB) {
108 mask = 1 << (irq - IRQ_AMIGA_CIAB);
109 cia_set_irq(&ciab_base, mask);
110 cia_able_irq(&ciab_base, CIA_ICR_SETCLR | mask);
111 } else {
112 mask = 1 << (irq - IRQ_AMIGA_CIAA);
113 cia_set_irq(&ciaa_base, mask);
114 cia_able_irq(&ciaa_base, CIA_ICR_SETCLR | mask);
115 }
116}
117
Geert Uytterhoevene8abf5e2011-04-17 22:53:04 +0200118static void cia_irq_disable(struct irq_data *data)
Roman Zippel74be8d02006-06-25 05:47:01 -0700119{
Geert Uytterhoevene8abf5e2011-04-17 22:53:04 +0200120 unsigned int irq = data->irq;
121
Roman Zippel74be8d02006-06-25 05:47:01 -0700122 if (irq >= IRQ_AMIGA_CIAB)
123 cia_able_irq(&ciab_base, 1 << (irq - IRQ_AMIGA_CIAB));
124 else
125 cia_able_irq(&ciaa_base, 1 << (irq - IRQ_AMIGA_CIAA));
126}
127
Geert Uytterhoevenc288bf22011-04-13 22:31:28 +0200128static struct irq_chip cia_irq_chip = {
Roman Zippel74be8d02006-06-25 05:47:01 -0700129 .name = "cia",
Geert Uytterhoevene8abf5e2011-04-17 22:53:04 +0200130 .irq_enable = cia_irq_enable,
131 .irq_disable = cia_irq_disable,
Roman Zippel74be8d02006-06-25 05:47:01 -0700132};
133
134/*
135 * Override auto irq 2 & 6 and use them as general chain
136 * for external interrupts, we link the CIA interrupt sources
137 * into this chain.
138 */
139
Geert Uytterhoevene8abf5e2011-04-17 22:53:04 +0200140static void auto_irq_enable(struct irq_data *data)
Roman Zippel74be8d02006-06-25 05:47:01 -0700141{
Geert Uytterhoevene8abf5e2011-04-17 22:53:04 +0200142 switch (data->irq) {
Roman Zippel74be8d02006-06-25 05:47:01 -0700143 case IRQ_AUTO_2:
144 amiga_custom.intena = IF_SETCLR | IF_PORTS;
145 break;
146 case IRQ_AUTO_6:
147 amiga_custom.intena = IF_SETCLR | IF_EXTER;
148 break;
149 }
150}
151
Geert Uytterhoevene8abf5e2011-04-17 22:53:04 +0200152static void auto_irq_disable(struct irq_data *data)
Roman Zippel74be8d02006-06-25 05:47:01 -0700153{
Geert Uytterhoevene8abf5e2011-04-17 22:53:04 +0200154 switch (data->irq) {
Roman Zippel74be8d02006-06-25 05:47:01 -0700155 case IRQ_AUTO_2:
156 amiga_custom.intena = IF_PORTS;
157 break;
158 case IRQ_AUTO_6:
159 amiga_custom.intena = IF_EXTER;
160 break;
161 }
162}
163
Geert Uytterhoevenc288bf22011-04-13 22:31:28 +0200164static struct irq_chip auto_irq_chip = {
Roman Zippel74be8d02006-06-25 05:47:01 -0700165 .name = "auto",
Geert Uytterhoevene8abf5e2011-04-17 22:53:04 +0200166 .irq_enable = auto_irq_enable,
167 .irq_disable = auto_irq_disable,
Roman Zippel74be8d02006-06-25 05:47:01 -0700168};
169
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170void __init cia_init_IRQ(struct ciabase *base)
171{
Geert Uytterhoevenedb34722011-06-01 11:15:21 +0200172 m68k_setup_irq_controller(&cia_irq_chip, handle_simple_irq,
173 base->cia_irq, CIA_IRQS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174
175 /* clear any pending interrupt and turn off all interrupts */
176 cia_set_irq(base, CIA_ICR_ALL);
177 cia_able_irq(base, CIA_ICR_ALL);
178
Roman Zippel74be8d02006-06-25 05:47:01 -0700179 /* override auto int and install CIA handler */
Geert Uytterhoevenedb34722011-06-01 11:15:21 +0200180 m68k_setup_irq_controller(&auto_irq_chip, handle_simple_irq,
181 base->handler_irq, 1);
Geert Uytterhoevene8abf5e2011-04-17 22:53:04 +0200182 m68k_irq_startup_irq(base->handler_irq);
Geert Uytterhoeven66acd252008-12-30 14:00:34 +0100183 if (request_irq(base->handler_irq, cia_handler, IRQF_SHARED,
184 base->name, base))
185 pr_err("Couldn't register %s interrupt\n", base->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186}