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
11 #include <linux/config.h>
13 #include <linux/errno.h>
14 #include <linux/sched.h>
15 #include <linux/tty.h>
16 #include <linux/kernel.h>
17 #include <linux/init.h>
18 #include <linux/delay.h>
19 #include <linux/kbd_ll.h>
20 #include <linux/kbd_kern.h>
21 #include <linux/vt_kern.h>
23 #include <asm/keyboard.h>
24 #include <asm/dec/tc.h>
25 #include <asm/dec/machtype.h>
26 #include <asm/dec/serial.h>
31 * Only handle DECstations that have an LK201 interface.
32 * Maxine uses LK501 at the Access.Bus and various DECsystems
33 * have no keyboard interface at all.
35 #define LK_IFACE (mips_machtype == MACH_DS23100 || \
36 mips_machtype == MACH_DS5000_200 || \
37 mips_machtype == MACH_DS5000_1XX || \
38 mips_machtype == MACH_DS5000_2X0)
40 * These use the Z8530 SCC. Others use the DZ11.
42 #define LK_IFACE_ZS (mips_machtype == MACH_DS5000_1XX || \
43 mips_machtype == MACH_DS5000_2X0)
45 /* Simple translation table for the SysRq keys */
47 #ifdef CONFIG_MAGIC_SYSRQ
49 * Actually no translation at all, at least until we figure out
50 * how to define SysRq for LK201 and friends. --macro
52 unsigned char lk201_sysrq_xlate[128];
53 unsigned char *kbd_sysrq_xlate = lk201_sysrq_xlate;
55 unsigned char kbd_sysrq_key = -1;
60 static int __init lk201_init(void *);
61 static void __init lk201_info(void *);
62 static void lk201_rx_char(unsigned char, unsigned char);
64 static struct dec_serial_hook lk201_hook = {
65 .init_channel = lk201_init,
66 .init_info = lk201_info,
70 .cflags = B4800 | CS8 | CSTOPB | CLOCAL,
74 * This is used during keyboard initialisation
76 static unsigned char lk201_reset_string[] = {
78 LK_CMD_MODE(LK_MODE_RPT_DOWN, 1),
79 LK_CMD_MODE(LK_MODE_RPT_DOWN, 2),
80 LK_CMD_MODE(LK_MODE_RPT_DOWN, 3),
81 LK_CMD_MODE(LK_MODE_RPT_DOWN, 4),
82 LK_CMD_MODE(LK_MODE_DOWN_UP, 5),
83 LK_CMD_MODE(LK_MODE_DOWN_UP, 6),
84 LK_CMD_MODE(LK_MODE_RPT_DOWN, 7),
85 LK_CMD_MODE(LK_MODE_RPT_DOWN, 8),
86 LK_CMD_MODE(LK_MODE_RPT_DOWN, 9),
87 LK_CMD_MODE(LK_MODE_RPT_DOWN, 10),
88 LK_CMD_MODE(LK_MODE_RPT_DOWN, 11),
89 LK_CMD_MODE(LK_MODE_RPT_DOWN, 12),
90 LK_CMD_MODE(LK_MODE_DOWN, 13),
91 LK_CMD_MODE(LK_MODE_RPT_DOWN, 14),
93 LK_CMD_ENB_BELL, LK_PARAM_VOLUME(4),
96 static void *lk201_handle;
98 static int lk201_send(unsigned char ch)
100 if (lk201_hook.poll_tx_char(lk201_handle, ch)) {
101 printk(KERN_ERR "lk201: transmit timeout\n");
107 static inline int lk201_get_id(void)
109 return lk201_send(LK_CMD_REQ_ID);
112 static int lk201_reset(void)
116 for (i = 0; i < sizeof(lk201_reset_string); i++) {
117 r = lk201_send(lk201_reset_string[i]);
124 static void lk201_report(unsigned char id[6])
126 char *report = "lk201: keyboard attached, ";
129 case LK_STAT_PWRUP_OK:
130 printk(KERN_INFO "%sself-test OK\n", report);
132 case LK_STAT_PWRUP_KDOWN:
133 /* The keyboard will resend the power-up ID
134 after all keys are released, so we don't
135 bother handling the error specially. Still
136 there may be a short-circuit inside.
138 printk(KERN_ERR "%skey down (stuck?), code: 0x%02x\n",
141 case LK_STAT_PWRUP_ERROR:
142 printk(KERN_ERR "%sself-test failure\n", report);
145 printk(KERN_ERR "%sunknown error: 0x%02x\n",
150 static void lk201_id(unsigned char id[6])
153 * Report whether there is an LK201 or an LK401
154 * The LK401 has ALT keys...
158 printk(KERN_INFO "lk201: LK201 detected\n");
161 printk(KERN_INFO "lk201: LK401 detected\n");
164 printk(KERN_INFO "lk201: LK443 detected\n");
167 printk(KERN_INFO "lk201: LK421 detected\n");
171 "lk201: unknown keyboard detected, ID %d\n", id[4]);
172 printk(KERN_WARNING "lk201: ... please report to "
173 "<linux-mips@linux-mips.org>\n");
177 #define DEFAULT_KEYB_REP_DELAY (250/5) /* [5ms] */
178 #define DEFAULT_KEYB_REP_RATE 30 /* [cps] */
180 static struct kbd_repeat kbdrate = {
181 DEFAULT_KEYB_REP_DELAY,
182 DEFAULT_KEYB_REP_RATE
185 static void parse_kbd_rate(struct kbd_repeat *r)
188 r->delay = kbdrate.delay;
190 r->rate = kbdrate.rate;
204 static int write_kbd_rate(struct kbd_repeat *rep)
209 delay = rep->delay / 5;
211 for (i = 0; i < 4; i++) {
212 if (lk201_hook.poll_tx_char(lk201_handle,
215 if (lk201_hook.poll_tx_char(lk201_handle,
216 LK_PARAM_DELAY(delay)))
218 if (lk201_hook.poll_tx_char(lk201_handle,
219 LK_PARAM_RATE(rate)))
225 static int lk201_kbd_rate(struct kbd_repeat *rep)
232 if (write_kbd_rate(rep)) {
233 memcpy(rep, &kbdrate, sizeof(struct kbd_repeat));
237 memcpy(&kbdrate, rep, sizeof(struct kbd_repeat));
242 static void lk201_kd_mksound(unsigned int hz, unsigned int ticks)
248 * Can't set frequency and we "approximate"
249 * duration by volume. ;-)
256 if (lk201_hook.poll_tx_char(lk201_handle, LK_CMD_ENB_BELL))
258 if (lk201_hook.poll_tx_char(lk201_handle, LK_PARAM_VOLUME(ticks)))
260 if (lk201_hook.poll_tx_char(lk201_handle, LK_CMD_BELL))
264 void kbd_leds(unsigned char leds)
268 if (!lk201_handle) /* FIXME */
271 /* FIXME -- Only Hold and Lock LEDs for now. --macro */
277 if (lk201_hook.poll_tx_char(lk201_handle, LK_CMD_LEDS_ON))
279 if (lk201_hook.poll_tx_char(lk201_handle, LK_PARAM_LED_MASK(l)))
281 if (lk201_hook.poll_tx_char(lk201_handle, LK_CMD_LEDS_OFF))
283 if (lk201_hook.poll_tx_char(lk201_handle, LK_PARAM_LED_MASK(~l)))
287 int kbd_setkeycode(unsigned int scancode, unsigned int keycode)
292 int kbd_getkeycode(unsigned int scancode)
297 int kbd_translate(unsigned char scancode, unsigned char *keycode,
304 char kbd_unexpected_up(unsigned char keycode)
309 static void lk201_rx_char(unsigned char ch, unsigned char fl)
311 static unsigned char id[6];
314 static int shift_state = 0;
315 static int prev_scancode;
316 unsigned char c = scancodeRemap[ch];
318 if (fl != TTY_NORMAL && fl != TTY_OVERRUN) {
319 printk(KERN_ERR "lk201: keyboard receive error: 0x%02x\n", fl);
323 /* Assume this is a power-up ID. */
324 if (ch == LK_STAT_PWRUP_ID && !id_i) {
329 /* Handle the power-up sequence. */
333 /* OK, the power-up concluded. */
335 if (id[2] == LK_STAT_PWRUP_OK)
339 printk(KERN_ERR "lk201: keyboard power-up "
340 "error, skipping initialization\n");
342 } else if (id_i == 6) {
343 /* We got the ID; report it and start operation. */
351 /* Everything else is a scancode/status response. */
354 case LK_STAT_RESUME_ERR:
356 case LK_STAT_INHIBIT_ACK:
357 case LK_STAT_TEST_ACK:
358 case LK_STAT_MODE_KEYDOWN:
359 case LK_STAT_MODE_ACK:
362 shift_state ^= LK_LOCK;
363 handle_scancode(c, (shift_state & LK_LOCK) ? 1 : 0);
366 shift_state ^= LK_SHIFT;
367 handle_scancode(c, (shift_state & LK_SHIFT) ? 1 : 0);
370 shift_state ^= LK_CTRL;
371 handle_scancode(c, (shift_state & LK_CTRL) ? 1 : 0);
374 shift_state ^= LK_COMP;
375 handle_scancode(c, (shift_state & LK_COMP) ? 1 : 0);
378 if (shift_state & LK_SHIFT)
379 handle_scancode(scancodeRemap[LK_KEY_SHIFT], 0);
380 if (shift_state & LK_CTRL)
381 handle_scancode(scancodeRemap[LK_KEY_CTRL], 0);
382 if (shift_state & LK_COMP)
383 handle_scancode(scancodeRemap[LK_KEY_COMP], 0);
384 if (shift_state & LK_LOCK)
385 handle_scancode(scancodeRemap[LK_KEY_LOCK], 0);
389 handle_scancode(prev_scancode, 1);
393 handle_scancode(c, 1);
396 tasklet_schedule(&keyboard_tasklet);
399 static void __init lk201_info(void *handle)
403 static int __init lk201_init(void *handle)
405 /* First install handlers. */
406 lk201_handle = handle;
407 kbd_rate = lk201_kbd_rate;
408 kd_mksound = lk201_kd_mksound;
410 lk201_hook.rx_char = lk201_rx_char;
412 /* Then just issue a reset -- the handlers will do the rest. */
413 lk201_send(LK_CMD_POWER_UP);
418 void __init kbd_init_hw(void)
420 /* Maxine uses LK501 at the Access.Bus. */
424 printk(KERN_INFO "lk201: DECstation LK keyboard driver v0.05.\n");
428 * kbd_init_hw() is being called before
429 * rs_init() so just register the kbd hook
430 * and let zs_init do the rest :-)
432 if (!register_dec_serial_hook(KEYB_LINE, &lk201_hook))
433 unregister_dec_serial_hook(KEYB_LINE);
436 * TODO: modify dz.c to allow similar hooks
437 * for LK201 handling on DS2100, DS3100, and DS5000/200
439 printk(KERN_ERR "lk201: support for DZ11 not yet ready.\n");