3 * This file is subject to the terms and conditions of the GNU General Public
4 * License. See the file "COPYING" in the main directory of this archive
7 * Copyright (C) 1999-2002 Harald Koerfgen <hkoerfg@web.de>
8 * Copyright (C) 2001, 2002, 2003, 2004 Maciej W. Rozycki
12 #include <linux/errno.h>
13 #include <linux/sched.h>
14 #include <linux/tty.h>
15 #include <linux/kernel.h>
16 #include <linux/init.h>
17 #include <linux/delay.h>
18 #include <linux/kbd_ll.h>
19 #include <linux/kbd_kern.h>
20 #include <linux/vt_kern.h>
22 #include <asm/keyboard.h>
23 #include <asm/dec/tc.h>
24 #include <asm/dec/machtype.h>
25 #include <asm/dec/serial.h>
30 * Only handle DECstations that have an LK201 interface.
31 * Maxine uses LK501 at the Access.Bus and various DECsystems
32 * have no keyboard interface at all.
34 #define LK_IFACE (mips_machtype == MACH_DS23100 || \
35 mips_machtype == MACH_DS5000_200 || \
36 mips_machtype == MACH_DS5000_1XX || \
37 mips_machtype == MACH_DS5000_2X0)
39 * These use the Z8530 SCC. Others use the DZ11.
41 #define LK_IFACE_ZS (mips_machtype == MACH_DS5000_1XX || \
42 mips_machtype == MACH_DS5000_2X0)
44 /* Simple translation table for the SysRq keys */
46 #ifdef CONFIG_MAGIC_SYSRQ
48 * Actually no translation at all, at least until we figure out
49 * how to define SysRq for LK201 and friends. --macro
51 unsigned char lk201_sysrq_xlate[128];
52 unsigned char *kbd_sysrq_xlate = lk201_sysrq_xlate;
54 unsigned char kbd_sysrq_key = -1;
59 static int __init lk201_init(void *);
60 static void __init lk201_info(void *);
61 static void lk201_rx_char(unsigned char, unsigned char);
63 static struct dec_serial_hook lk201_hook = {
64 .init_channel = lk201_init,
65 .init_info = lk201_info,
69 .cflags = B4800 | CS8 | CSTOPB | CLOCAL,
73 * This is used during keyboard initialisation
75 static unsigned char lk201_reset_string[] = {
77 LK_CMD_MODE(LK_MODE_RPT_DOWN, 1),
78 LK_CMD_MODE(LK_MODE_RPT_DOWN, 2),
79 LK_CMD_MODE(LK_MODE_RPT_DOWN, 3),
80 LK_CMD_MODE(LK_MODE_RPT_DOWN, 4),
81 LK_CMD_MODE(LK_MODE_DOWN_UP, 5),
82 LK_CMD_MODE(LK_MODE_DOWN_UP, 6),
83 LK_CMD_MODE(LK_MODE_RPT_DOWN, 7),
84 LK_CMD_MODE(LK_MODE_RPT_DOWN, 8),
85 LK_CMD_MODE(LK_MODE_RPT_DOWN, 9),
86 LK_CMD_MODE(LK_MODE_RPT_DOWN, 10),
87 LK_CMD_MODE(LK_MODE_RPT_DOWN, 11),
88 LK_CMD_MODE(LK_MODE_RPT_DOWN, 12),
89 LK_CMD_MODE(LK_MODE_DOWN, 13),
90 LK_CMD_MODE(LK_MODE_RPT_DOWN, 14),
92 LK_CMD_ENB_BELL, LK_PARAM_VOLUME(4),
95 static void *lk201_handle;
97 static int lk201_send(unsigned char ch)
99 if (lk201_hook.poll_tx_char(lk201_handle, ch)) {
100 printk(KERN_ERR "lk201: transmit timeout\n");
106 static inline int lk201_get_id(void)
108 return lk201_send(LK_CMD_REQ_ID);
111 static int lk201_reset(void)
115 for (i = 0; i < sizeof(lk201_reset_string); i++) {
116 r = lk201_send(lk201_reset_string[i]);
123 static void lk201_report(unsigned char id[6])
125 char *report = "lk201: keyboard attached, ";
128 case LK_STAT_PWRUP_OK:
129 printk(KERN_INFO "%sself-test OK\n", report);
131 case LK_STAT_PWRUP_KDOWN:
132 /* The keyboard will resend the power-up ID
133 after all keys are released, so we don't
134 bother handling the error specially. Still
135 there may be a short-circuit inside.
137 printk(KERN_ERR "%skey down (stuck?), code: 0x%02x\n",
140 case LK_STAT_PWRUP_ERROR:
141 printk(KERN_ERR "%sself-test failure\n", report);
144 printk(KERN_ERR "%sunknown error: 0x%02x\n",
149 static void lk201_id(unsigned char id[6])
152 * Report whether there is an LK201 or an LK401
153 * The LK401 has ALT keys...
157 printk(KERN_INFO "lk201: LK201 detected\n");
160 printk(KERN_INFO "lk201: LK401 detected\n");
163 printk(KERN_INFO "lk201: LK443 detected\n");
166 printk(KERN_INFO "lk201: LK421 detected\n");
170 "lk201: unknown keyboard detected, ID %d\n", id[4]);
171 printk(KERN_WARNING "lk201: ... please report to "
172 "<linux-mips@linux-mips.org>\n");
176 #define DEFAULT_KEYB_REP_DELAY (250/5) /* [5ms] */
177 #define DEFAULT_KEYB_REP_RATE 30 /* [cps] */
179 static struct kbd_repeat kbdrate = {
180 DEFAULT_KEYB_REP_DELAY,
181 DEFAULT_KEYB_REP_RATE
184 static void parse_kbd_rate(struct kbd_repeat *r)
187 r->delay = kbdrate.delay;
189 r->rate = kbdrate.rate;
203 static int write_kbd_rate(struct kbd_repeat *rep)
208 delay = rep->delay / 5;
210 for (i = 0; i < 4; i++) {
211 if (lk201_hook.poll_tx_char(lk201_handle,
214 if (lk201_hook.poll_tx_char(lk201_handle,
215 LK_PARAM_DELAY(delay)))
217 if (lk201_hook.poll_tx_char(lk201_handle,
218 LK_PARAM_RATE(rate)))
224 static int lk201_kbd_rate(struct kbd_repeat *rep)
231 if (write_kbd_rate(rep)) {
232 memcpy(rep, &kbdrate, sizeof(struct kbd_repeat));
236 memcpy(&kbdrate, rep, sizeof(struct kbd_repeat));
241 static void lk201_kd_mksound(unsigned int hz, unsigned int ticks)
247 * Can't set frequency and we "approximate"
248 * duration by volume. ;-)
255 if (lk201_hook.poll_tx_char(lk201_handle, LK_CMD_ENB_BELL))
257 if (lk201_hook.poll_tx_char(lk201_handle, LK_PARAM_VOLUME(ticks)))
259 if (lk201_hook.poll_tx_char(lk201_handle, LK_CMD_BELL))
263 void kbd_leds(unsigned char leds)
267 if (!lk201_handle) /* FIXME */
270 /* FIXME -- Only Hold and Lock LEDs for now. --macro */
276 if (lk201_hook.poll_tx_char(lk201_handle, LK_CMD_LEDS_ON))
278 if (lk201_hook.poll_tx_char(lk201_handle, LK_PARAM_LED_MASK(l)))
280 if (lk201_hook.poll_tx_char(lk201_handle, LK_CMD_LEDS_OFF))
282 if (lk201_hook.poll_tx_char(lk201_handle, LK_PARAM_LED_MASK(~l)))
286 int kbd_setkeycode(unsigned int scancode, unsigned int keycode)
291 int kbd_getkeycode(unsigned int scancode)
296 int kbd_translate(unsigned char scancode, unsigned char *keycode,
303 char kbd_unexpected_up(unsigned char keycode)
308 static void lk201_rx_char(unsigned char ch, unsigned char fl)
310 static unsigned char id[6];
313 static int shift_state = 0;
314 static int prev_scancode;
315 unsigned char c = scancodeRemap[ch];
317 if (fl != TTY_NORMAL && fl != TTY_OVERRUN) {
318 printk(KERN_ERR "lk201: keyboard receive error: 0x%02x\n", fl);
322 /* Assume this is a power-up ID. */
323 if (ch == LK_STAT_PWRUP_ID && !id_i) {
328 /* Handle the power-up sequence. */
332 /* OK, the power-up concluded. */
334 if (id[2] == LK_STAT_PWRUP_OK)
338 printk(KERN_ERR "lk201: keyboard power-up "
339 "error, skipping initialization\n");
341 } else if (id_i == 6) {
342 /* We got the ID; report it and start operation. */
350 /* Everything else is a scancode/status response. */
353 case LK_STAT_RESUME_ERR:
355 case LK_STAT_INHIBIT_ACK:
356 case LK_STAT_TEST_ACK:
357 case LK_STAT_MODE_KEYDOWN:
358 case LK_STAT_MODE_ACK:
361 shift_state ^= LK_LOCK;
362 handle_scancode(c, (shift_state & LK_LOCK) ? 1 : 0);
365 shift_state ^= LK_SHIFT;
366 handle_scancode(c, (shift_state & LK_SHIFT) ? 1 : 0);
369 shift_state ^= LK_CTRL;
370 handle_scancode(c, (shift_state & LK_CTRL) ? 1 : 0);
373 shift_state ^= LK_COMP;
374 handle_scancode(c, (shift_state & LK_COMP) ? 1 : 0);
377 if (shift_state & LK_SHIFT)
378 handle_scancode(scancodeRemap[LK_KEY_SHIFT], 0);
379 if (shift_state & LK_CTRL)
380 handle_scancode(scancodeRemap[LK_KEY_CTRL], 0);
381 if (shift_state & LK_COMP)
382 handle_scancode(scancodeRemap[LK_KEY_COMP], 0);
383 if (shift_state & LK_LOCK)
384 handle_scancode(scancodeRemap[LK_KEY_LOCK], 0);
388 handle_scancode(prev_scancode, 1);
392 handle_scancode(c, 1);
395 tasklet_schedule(&keyboard_tasklet);
398 static void __init lk201_info(void *handle)
402 static int __init lk201_init(void *handle)
404 /* First install handlers. */
405 lk201_handle = handle;
406 kbd_rate = lk201_kbd_rate;
407 kd_mksound = lk201_kd_mksound;
409 lk201_hook.rx_char = lk201_rx_char;
411 /* Then just issue a reset -- the handlers will do the rest. */
412 lk201_send(LK_CMD_POWER_UP);
417 void __init kbd_init_hw(void)
419 /* Maxine uses LK501 at the Access.Bus. */
423 printk(KERN_INFO "lk201: DECstation LK keyboard driver v0.05.\n");
427 * kbd_init_hw() is being called before
428 * rs_init() so just register the kbd hook
429 * and let zs_init do the rest :-)
431 if (!register_dec_serial_hook(KEYB_LINE, &lk201_hook))
432 unregister_dec_serial_hook(KEYB_LINE);
435 * TODO: modify dz.c to allow similar hooks
436 * for LK201 handling on DS2100, DS3100, and DS5000/200
438 printk(KERN_ERR "lk201: support for DZ11 not yet ready.\n");