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
27 * Should you need to contact me, the author, you can do so either by
28 * e-mail - mail your message to <vojtech@ucw.cz>, or by paper mail:
29 * Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic
32 #include <linux/module.h>
33 #include <linux/init.h>
34 #include <linux/input.h>
35 #include <linux/delay.h>
36 #include <linux/interrupt.h>
37 #include <linux/keyboard.h>
38 #include <linux/platform_device.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 #ifdef CONFIG_HW_CONSOLE
49 static unsigned char amikbd_keycode
[0x78] __initdata
= {
76 [27] = KEY_RIGHTBRACE
,
90 [42] = KEY_APOSTROPHE
,
111 [65] = KEY_BACKSPACE
,
132 [90] = KEY_KPLEFTPAREN
,
133 [91] = KEY_KPRIGHTPAREN
,
135 [93] = KEY_KPASTERISK
,
138 [96] = KEY_LEFTSHIFT
,
139 [97] = KEY_RIGHTSHIFT
,
143 [101] = KEY_RIGHTALT
,
144 [102] = KEY_LEFTMETA
,
145 [103] = KEY_RIGHTMETA
148 static void __init
amikbd_init_console_keymaps(void)
150 /* We can spare 512 bytes on stack for temp_map in init path. */
151 unsigned short temp_map
[NR_KEYS
];
154 for (i
= 0; i
< MAX_NR_KEYMAPS
; i
++) {
157 memset(temp_map
, 0, sizeof(temp_map
));
158 for (j
= 0; j
< 0x78; j
++) {
159 if (!amikbd_keycode
[j
])
161 temp_map
[j
] = key_maps
[i
][amikbd_keycode
[j
]];
163 for (j
= 0; j
< NR_KEYS
; j
++) {
165 temp_map
[j
] = 0xf200;
167 memcpy(key_maps
[i
], temp_map
, sizeof(temp_map
));
170 #else /* !CONFIG_HW_CONSOLE */
171 static inline void amikbd_init_console_keymaps(void) {}
172 #endif /* !CONFIG_HW_CONSOLE */
174 static const char *amikbd_messages
[8] = {
175 [0] = KERN_ALERT
"amikbd: Ctrl-Amiga-Amiga reset warning!!\n",
176 [1] = KERN_WARNING
"amikbd: keyboard lost sync\n",
177 [2] = KERN_WARNING
"amikbd: keyboard buffer overflow\n",
178 [3] = KERN_WARNING
"amikbd: keyboard controller failure\n",
179 [4] = KERN_ERR
"amikbd: keyboard selftest failure\n",
180 [5] = KERN_INFO
"amikbd: initiate power-up key stream\n",
181 [6] = KERN_INFO
"amikbd: terminate power-up key stream\n",
182 [7] = KERN_WARNING
"amikbd: keyboard interrupt\n"
185 static irqreturn_t
amikbd_interrupt(int irq
, void *data
)
187 struct input_dev
*dev
= data
;
188 unsigned char scancode
, down
;
190 scancode
= ~ciaa
.sdr
; /* get and invert scancode (keyboard is active low) */
191 ciaa
.cra
|= 0x40; /* switch SP pin to output for handshake */
192 udelay(85); /* wait until 85 us have expired */
193 ciaa
.cra
&= ~0x40; /* switch CIA serial port to input mode */
195 down
= !(scancode
& 1); /* lowest bit is release bit */
198 if (scancode
< 0x78) { /* scancodes < 0x78 are keys */
199 if (scancode
== 98) { /* CapsLock is a toggle switch key on Amiga */
200 input_report_key(dev
, scancode
, 1);
201 input_report_key(dev
, scancode
, 0);
203 input_report_key(dev
, scancode
, down
);
207 } else /* scancodes >= 0x78 are error codes */
208 printk(amikbd_messages
[scancode
- 0x78]);
213 static int __init
amikbd_probe(struct platform_device
*pdev
)
215 struct input_dev
*dev
;
218 dev
= input_allocate_device();
220 dev_err(&pdev
->dev
, "Not enough memory for input device\n");
224 dev
->name
= pdev
->name
;
225 dev
->phys
= "amikbd/input0";
226 dev
->id
.bustype
= BUS_AMIGA
;
227 dev
->id
.vendor
= 0x0001;
228 dev
->id
.product
= 0x0001;
229 dev
->id
.version
= 0x0100;
230 dev
->dev
.parent
= &pdev
->dev
;
232 dev
->evbit
[0] = BIT_MASK(EV_KEY
) | BIT_MASK(EV_REP
);
234 for (i
= 0; i
< 0x78; i
++)
235 set_bit(i
, dev
->keybit
);
237 amikbd_init_console_keymaps();
239 ciaa
.cra
&= ~0x41; /* serial data in, turn off TA */
240 err
= request_irq(IRQ_AMIGA_CIAA_SP
, amikbd_interrupt
, 0, "amikbd",
245 err
= input_register_device(dev
);
249 platform_set_drvdata(pdev
, dev
);
253 fail3
: free_irq(IRQ_AMIGA_CIAA_SP
, dev
);
254 fail2
: input_free_device(dev
);
258 static int __exit
amikbd_remove(struct platform_device
*pdev
)
260 struct input_dev
*dev
= platform_get_drvdata(pdev
);
262 free_irq(IRQ_AMIGA_CIAA_SP
, dev
);
263 input_unregister_device(dev
);
267 static struct platform_driver amikbd_driver
= {
268 .remove
= __exit_p(amikbd_remove
),
270 .name
= "amiga-keyboard",
274 module_platform_driver_probe(amikbd_driver
, amikbd_probe
);
276 MODULE_ALIAS("platform:amiga-keyboard");