2 * Copyright (c) 2000-2001 Vojtech Pavlik
4 * Based on the work of:
9 * Amiga keyboard driver for Linux/m68k
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 #include <linux/module.h>
29 #include <linux/init.h>
30 #include <linux/input.h>
31 #include <linux/delay.h>
32 #include <linux/interrupt.h>
33 #include <linux/keyboard.h>
34 #include <linux/platform_device.h>
36 #include <asm/amigaints.h>
37 #include <asm/amigahw.h>
40 MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
41 MODULE_DESCRIPTION("Amiga keyboard driver");
42 MODULE_LICENSE("GPL");
44 #ifdef CONFIG_HW_CONSOLE
45 static unsigned char amikbd_keycode[0x78] __initdata = {
72 [27] = KEY_RIGHTBRACE,
86 [42] = KEY_APOSTROPHE,
107 [65] = KEY_BACKSPACE,
128 [90] = KEY_KPLEFTPAREN,
129 [91] = KEY_KPRIGHTPAREN,
131 [93] = KEY_KPASTERISK,
134 [96] = KEY_LEFTSHIFT,
135 [97] = KEY_RIGHTSHIFT,
139 [101] = KEY_RIGHTALT,
140 [102] = KEY_LEFTMETA,
141 [103] = KEY_RIGHTMETA
144 static void __init amikbd_init_console_keymaps(void)
146 /* We can spare 512 bytes on stack for temp_map in init path. */
147 unsigned short temp_map[NR_KEYS];
150 for (i = 0; i < MAX_NR_KEYMAPS; i++) {
153 memset(temp_map, 0, sizeof(temp_map));
154 for (j = 0; j < 0x78; j++) {
155 if (!amikbd_keycode[j])
157 temp_map[j] = key_maps[i][amikbd_keycode[j]];
159 for (j = 0; j < NR_KEYS; j++) {
161 temp_map[j] = 0xf200;
163 memcpy(key_maps[i], temp_map, sizeof(temp_map));
166 #else /* !CONFIG_HW_CONSOLE */
167 static inline void amikbd_init_console_keymaps(void) {}
168 #endif /* !CONFIG_HW_CONSOLE */
170 static const char *amikbd_messages[8] = {
171 [0] = KERN_ALERT "amikbd: Ctrl-Amiga-Amiga reset warning!!\n",
172 [1] = KERN_WARNING "amikbd: keyboard lost sync\n",
173 [2] = KERN_WARNING "amikbd: keyboard buffer overflow\n",
174 [3] = KERN_WARNING "amikbd: keyboard controller failure\n",
175 [4] = KERN_ERR "amikbd: keyboard selftest failure\n",
176 [5] = KERN_INFO "amikbd: initiate power-up key stream\n",
177 [6] = KERN_INFO "amikbd: terminate power-up key stream\n",
178 [7] = KERN_WARNING "amikbd: keyboard interrupt\n"
181 static irqreturn_t amikbd_interrupt(int irq, void *data)
183 struct input_dev *dev = data;
184 unsigned char scancode, down;
186 scancode = ~ciaa.sdr; /* get and invert scancode (keyboard is active low) */
187 ciaa.cra |= 0x40; /* switch SP pin to output for handshake */
188 udelay(85); /* wait until 85 us have expired */
189 ciaa.cra &= ~0x40; /* switch CIA serial port to input mode */
191 down = !(scancode & 1); /* lowest bit is release bit */
194 if (scancode < 0x78) { /* scancodes < 0x78 are keys */
195 if (scancode == 98) { /* CapsLock is a toggle switch key on Amiga */
196 input_report_key(dev, scancode, 1);
197 input_report_key(dev, scancode, 0);
199 input_report_key(dev, scancode, down);
203 } else /* scancodes >= 0x78 are error codes */
204 printk(amikbd_messages[scancode - 0x78]);
209 static int __init amikbd_probe(struct platform_device *pdev)
211 struct input_dev *dev;
214 dev = input_allocate_device();
216 dev_err(&pdev->dev, "Not enough memory for input device\n");
220 dev->name = pdev->name;
221 dev->phys = "amikbd/input0";
222 dev->id.bustype = BUS_AMIGA;
223 dev->id.vendor = 0x0001;
224 dev->id.product = 0x0001;
225 dev->id.version = 0x0100;
226 dev->dev.parent = &pdev->dev;
228 dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REP);
230 for (i = 0; i < 0x78; i++)
231 set_bit(i, dev->keybit);
233 amikbd_init_console_keymaps();
235 ciaa.cra &= ~0x41; /* serial data in, turn off TA */
236 err = request_irq(IRQ_AMIGA_CIAA_SP, amikbd_interrupt, 0, "amikbd",
241 err = input_register_device(dev);
245 platform_set_drvdata(pdev, dev);
249 fail3: free_irq(IRQ_AMIGA_CIAA_SP, dev);
250 fail2: input_free_device(dev);
254 static int __exit amikbd_remove(struct platform_device *pdev)
256 struct input_dev *dev = platform_get_drvdata(pdev);
258 free_irq(IRQ_AMIGA_CIAA_SP, dev);
259 input_unregister_device(dev);
263 static struct platform_driver amikbd_driver = {
264 .remove = __exit_p(amikbd_remove),
266 .name = "amiga-keyboard",
270 module_platform_driver_probe(amikbd_driver, amikbd_probe);
272 MODULE_ALIAS("platform:amiga-keyboard");