2 * $Id: amikbd.c,v 1.13 2002/02/01 16:02:24 vojtech Exp $
4 * Copyright (c) 2000-2001 Vojtech Pavlik
6 * Based on the work of:
11 * Amiga keyboard driver for Linux/m68k
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2 of the License, or
18 * (at your option) any later version.
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 * Should you need to contact me, the author, you can do so either by
30 * e-mail - mail your message to <vojtech@ucw.cz>, or by paper mail:
31 * Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic
34 #include <linux/module.h>
35 #include <linux/init.h>
36 #include <linux/input.h>
37 #include <linux/delay.h>
38 #include <linux/interrupt.h>
40 #include <asm/amigaints.h>
41 #include <asm/amigahw.h>
44 MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
45 MODULE_DESCRIPTION("Amiga keyboard driver");
46 MODULE_LICENSE("GPL");
48 static unsigned char amikbd_keycode
[0x78] = {
75 [27] = KEY_RIGHTBRACE
,
89 [42] = KEY_APOSTROPHE
,
110 [65] = KEY_BACKSPACE
,
131 [90] = KEY_KPLEFTPAREN
,
132 [91] = KEY_KPRIGHTPAREN
,
134 [93] = KEY_KPASTERISK
,
137 [96] = KEY_LEFTSHIFT
,
138 [97] = KEY_RIGHTSHIFT
,
142 [101] = KEY_RIGHTALT
,
143 [102] = KEY_LEFTMETA
,
144 [103] = KEY_RIGHTMETA
147 static const char *amikbd_messages
[8] = {
148 [0] = KERN_ALERT
"amikbd: Ctrl-Amiga-Amiga reset warning!!\n",
149 [1] = KERN_WARNING
"amikbd: keyboard lost sync\n",
150 [2] = KERN_WARNING
"amikbd: keyboard buffer overflow\n",
151 [3] = KERN_WARNING
"amikbd: keyboard controller failure\n",
152 [4] = KERN_ERR
"amikbd: keyboard selftest failure\n",
153 [5] = KERN_INFO
"amikbd: initiate power-up key stream\n",
154 [6] = KERN_INFO
"amikbd: terminate power-up key stream\n",
155 [7] = KERN_WARNING
"amikbd: keyboard interrupt\n"
158 static struct input_dev
*amikbd_dev
;
160 static irqreturn_t
amikbd_interrupt(int irq
, void *dummy
, struct pt_regs
*fp
)
162 unsigned char scancode
, down
;
164 scancode
= ~ciaa
.sdr
; /* get and invert scancode (keyboard is active low) */
165 ciaa
.cra
|= 0x40; /* switch SP pin to output for handshake */
166 udelay(85); /* wait until 85 us have expired */
167 ciaa
.cra
&= ~0x40; /* switch CIA serial port to input mode */
169 down
= !(scancode
& 1); /* lowest bit is release bit */
172 if (scancode
< 0x78) { /* scancodes < 0x78 are keys */
174 scancode
= amikbd_keycode
[scancode
];
176 input_regs(amikbd_dev
, fp
);
178 if (scancode
== KEY_CAPSLOCK
) { /* CapsLock is a toggle switch key on Amiga */
179 input_report_key(amikbd_dev
, scancode
, 1);
180 input_report_key(amikbd_dev
, scancode
, 0);
182 input_report_key(amikbd_dev
, scancode
, down
);
185 input_sync(amikbd_dev
);
186 } else /* scancodes >= 0x78 are error codes */
187 printk(amikbd_messages
[scancode
- 0x78]);
192 static int __init
amikbd_init(void)
196 if (!AMIGAHW_PRESENT(AMI_KEYBOARD
))
199 if (!request_mem_region(CIAA_PHYSADDR
-1+0xb00, 0x100, "amikeyb"))
202 amikbd_dev
= input_allocate_device();
204 printk(KERN_ERR
"amikbd: not enough memory for input device\n");
205 release_mem_region(CIAA_PHYSADDR
- 1 + 0xb00, 0x100);
209 amikbd_dev
->name
= "Amiga Keyboard";
210 amikbd_dev
->phys
= "amikbd/input0";
211 amikbd_dev
->id
.bustype
= BUS_AMIGA
;
212 amikbd_dev
->id
.vendor
= 0x0001;
213 amikbd_dev
->id
.product
= 0x0001;
214 amikbd_dev
->id
.version
= 0x0100;
216 amikbd_dev
->evbit
[0] = BIT(EV_KEY
) | BIT(EV_REP
);
217 amikbd_dev
->keycode
= amikbd_keycode
;
218 amikbd_dev
->keycodesize
= sizeof(unsigned char);
219 amikbd_dev
->keycodemax
= ARRAY_SIZE(amikbd_keycode
);
221 for (i
= 0; i
< 0x78; i
++)
222 if (amikbd_keycode
[i
])
223 set_bit(amikbd_keycode
[i
], amikbd_dev
->keybit
);
225 ciaa
.cra
&= ~0x41; /* serial data in, turn off TA */
226 request_irq(IRQ_AMIGA_CIAA_SP
, amikbd_interrupt
, 0, "amikbd", amikbd_interrupt
);
228 input_register_device(amikbd_dev
);
232 static void __exit
amikbd_exit(void)
234 free_irq(IRQ_AMIGA_CIAA_SP
, amikbd_interrupt
);
235 input_unregister_device(amikbd_dev
);
236 release_mem_region(CIAA_PHYSADDR
- 1 + 0xb00, 0x100);
239 module_init(amikbd_init
);
240 module_exit(amikbd_exit
);