Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 26 | struct 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; |
| 32 | irq_handler_t irq_list[CIA_IRQS]; |
| 33 | } ciaa_base = { |
| 34 | .cia = &ciaa, |
| 35 | .int_mask = IF_PORTS, |
Roman Zippel | 1d174cfb | 2006-06-25 05:47:00 -0700 | [diff] [blame^] | 36 | .handler_irq = IRQ_AUTO_2, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | .cia_irq = IRQ_AMIGA_CIAA, |
| 38 | .server_irq = IRQ_AMIGA_PORTS, |
| 39 | .name = "CIAA handler" |
| 40 | }, ciab_base = { |
| 41 | .cia = &ciab, |
| 42 | .int_mask = IF_EXTER, |
Roman Zippel | 1d174cfb | 2006-06-25 05:47:00 -0700 | [diff] [blame^] | 43 | .handler_irq = IRQ_AUTO_6, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | .cia_irq = IRQ_AMIGA_CIAB, |
| 45 | .server_irq = IRQ_AMIGA_EXTER, |
| 46 | .name = "CIAB handler" |
| 47 | }; |
| 48 | |
| 49 | /* |
| 50 | * Cause or clear CIA interrupts, return old interrupt status. |
| 51 | */ |
| 52 | |
| 53 | unsigned char cia_set_irq(struct ciabase *base, unsigned char mask) |
| 54 | { |
| 55 | unsigned char old; |
| 56 | |
| 57 | old = (base->icr_data |= base->cia->icr); |
| 58 | if (mask & CIA_ICR_SETCLR) |
| 59 | base->icr_data |= mask; |
| 60 | else |
| 61 | base->icr_data &= ~mask; |
| 62 | if (base->icr_data & base->icr_mask) |
Al Viro | b4290a2 | 2006-01-12 01:06:12 -0800 | [diff] [blame] | 63 | amiga_custom.intreq = IF_SETCLR | base->int_mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | return old & base->icr_mask; |
| 65 | } |
| 66 | |
| 67 | /* |
| 68 | * Enable or disable CIA interrupts, return old interrupt mask, |
| 69 | * interrupts will only be enabled if a handler exists |
| 70 | */ |
| 71 | |
| 72 | unsigned char cia_able_irq(struct ciabase *base, unsigned char mask) |
| 73 | { |
| 74 | unsigned char old, tmp; |
| 75 | int i; |
| 76 | |
| 77 | old = base->icr_mask; |
| 78 | base->icr_data |= base->cia->icr; |
| 79 | base->cia->icr = mask; |
| 80 | if (mask & CIA_ICR_SETCLR) |
| 81 | base->icr_mask |= mask; |
| 82 | else |
| 83 | base->icr_mask &= ~mask; |
| 84 | base->icr_mask &= CIA_ICR_ALL; |
| 85 | for (i = 0, tmp = 1; i < CIA_IRQS; i++, tmp <<= 1) { |
| 86 | if ((tmp & base->icr_mask) && !base->irq_list[i].handler) { |
| 87 | base->icr_mask &= ~tmp; |
| 88 | base->cia->icr = tmp; |
| 89 | } |
| 90 | } |
| 91 | if (base->icr_data & base->icr_mask) |
Al Viro | b4290a2 | 2006-01-12 01:06:12 -0800 | [diff] [blame] | 92 | amiga_custom.intreq = IF_SETCLR | base->int_mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | return old; |
| 94 | } |
| 95 | |
| 96 | int cia_request_irq(struct ciabase *base, unsigned int irq, |
| 97 | irqreturn_t (*handler)(int, void *, struct pt_regs *), |
| 98 | unsigned long flags, const char *devname, void *dev_id) |
| 99 | { |
| 100 | unsigned char mask; |
| 101 | |
| 102 | base->irq_list[irq].handler = handler; |
| 103 | base->irq_list[irq].flags = flags; |
| 104 | base->irq_list[irq].dev_id = dev_id; |
| 105 | base->irq_list[irq].devname = devname; |
| 106 | |
| 107 | /* enable the interrupt */ |
| 108 | mask = 1 << irq; |
| 109 | cia_set_irq(base, mask); |
| 110 | cia_able_irq(base, CIA_ICR_SETCLR | mask); |
| 111 | return 0; |
| 112 | } |
| 113 | |
| 114 | void cia_free_irq(struct ciabase *base, unsigned int irq, void *dev_id) |
| 115 | { |
| 116 | if (base->irq_list[irq].dev_id != dev_id) |
| 117 | printk("%s: removing probably wrong IRQ %i from %s\n", |
| 118 | __FUNCTION__, base->cia_irq + irq, |
| 119 | base->irq_list[irq].devname); |
| 120 | |
| 121 | base->irq_list[irq].handler = NULL; |
| 122 | base->irq_list[irq].flags = 0; |
| 123 | |
| 124 | cia_able_irq(base, 1 << irq); |
| 125 | } |
| 126 | |
| 127 | static irqreturn_t cia_handler(int irq, void *dev_id, struct pt_regs *fp) |
| 128 | { |
| 129 | struct ciabase *base = (struct ciabase *)dev_id; |
| 130 | int mach_irq, i; |
| 131 | unsigned char ints; |
| 132 | |
| 133 | mach_irq = base->cia_irq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | ints = cia_set_irq(base, CIA_ICR_ALL); |
Al Viro | b4290a2 | 2006-01-12 01:06:12 -0800 | [diff] [blame] | 135 | amiga_custom.intreq = base->int_mask; |
Roman Zippel | 1d174cfb | 2006-06-25 05:47:00 -0700 | [diff] [blame^] | 136 | for (i = 0; i < CIA_IRQS; i++, mach_irq++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | if (ints & 1) { |
Roman Zippel | 1d174cfb | 2006-06-25 05:47:00 -0700 | [diff] [blame^] | 138 | kstat_cpu(0).irqs[mach_irq]++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | base->irq_list[i].handler(mach_irq, base->irq_list[i].dev_id, fp); |
| 140 | } |
| 141 | ints >>= 1; |
| 142 | } |
| 143 | amiga_do_irq_list(base->server_irq, fp); |
| 144 | return IRQ_HANDLED; |
| 145 | } |
| 146 | |
| 147 | void __init cia_init_IRQ(struct ciabase *base) |
| 148 | { |
| 149 | int i; |
| 150 | |
| 151 | /* init isr handlers */ |
| 152 | for (i = 0; i < CIA_IRQS; i++) { |
| 153 | base->irq_list[i].handler = NULL; |
| 154 | base->irq_list[i].flags = 0; |
| 155 | } |
| 156 | |
| 157 | /* clear any pending interrupt and turn off all interrupts */ |
| 158 | cia_set_irq(base, CIA_ICR_ALL); |
| 159 | cia_able_irq(base, CIA_ICR_ALL); |
| 160 | |
| 161 | /* install CIA handler */ |
| 162 | request_irq(base->handler_irq, cia_handler, 0, base->name, base); |
| 163 | |
Al Viro | b4290a2 | 2006-01-12 01:06:12 -0800 | [diff] [blame] | 164 | amiga_custom.intena = IF_SETCLR | base->int_mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | } |
| 166 | |
| 167 | int cia_get_irq_list(struct ciabase *base, struct seq_file *p) |
| 168 | { |
| 169 | int i, j; |
| 170 | |
| 171 | j = base->cia_irq; |
| 172 | for (i = 0; i < CIA_IRQS; i++) { |
| 173 | seq_printf(p, "cia %2d: %10d ", j + i, |
Roman Zippel | 1d174cfb | 2006-06-25 05:47:00 -0700 | [diff] [blame^] | 174 | kstat_cpu(0).irqs[j + i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | seq_puts(p, " "); |
| 176 | seq_printf(p, "%s\n", base->irq_list[i].devname); |
| 177 | } |
| 178 | return 0; |
| 179 | } |