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 Maciej W. Rozycki <macro@ds2.pg.gda.pl>
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>
30 /* Simple translation table for the SysRq keys */
32 #ifdef CONFIG_MAGIC_SYSRQ
34 * Actually no translation at all, at least until we figure out
35 * how to define SysRq for LK201 and friends. --macro
37 unsigned char lk201_sysrq_xlate[128];
38 unsigned char *kbd_sysrq_xlate = lk201_sysrq_xlate;
40 unsigned char kbd_sysrq_key = -1;
45 static int __init lk201_init(struct dec_serial *);
46 static void __init lk201_info(struct dec_serial *);
47 static void lk201_kbd_rx_char(unsigned char, unsigned char);
49 struct zs_hook lk201_kbdhook = {
50 init_channel: lk201_init,
51 init_info: lk201_info,
55 cflags: B4800 | CS8 | CSTOPB | CLOCAL
59 * This is used during keyboard initialisation
61 static unsigned char lk201_reset_string[] = {
63 LK_CMD_MODE(LK_MODE_RPT_DOWN, 1),
64 LK_CMD_MODE(LK_MODE_RPT_DOWN, 2),
65 LK_CMD_MODE(LK_MODE_RPT_DOWN, 3),
66 LK_CMD_MODE(LK_MODE_RPT_DOWN, 4),
67 LK_CMD_MODE(LK_MODE_DOWN_UP, 5),
68 LK_CMD_MODE(LK_MODE_DOWN_UP, 6),
69 LK_CMD_MODE(LK_MODE_RPT_DOWN, 7),
70 LK_CMD_MODE(LK_MODE_RPT_DOWN, 8),
71 LK_CMD_MODE(LK_MODE_RPT_DOWN, 9),
72 LK_CMD_MODE(LK_MODE_RPT_DOWN, 10),
73 LK_CMD_MODE(LK_MODE_RPT_DOWN, 11),
74 LK_CMD_MODE(LK_MODE_RPT_DOWN, 12),
75 LK_CMD_MODE(LK_MODE_DOWN, 13),
76 LK_CMD_MODE(LK_MODE_RPT_DOWN, 14),
78 LK_CMD_ENB_BELL, LK_PARAM_VOLUME(4),
81 static struct dec_serial* lk201kbd_info;
83 static int lk201_send(struct dec_serial *info, unsigned char ch)
85 if (info->hook->poll_tx_char(info, ch)) {
86 printk(KERN_ERR "lk201: transmit timeout\n");
92 static inline int lk201_get_id(struct dec_serial *info)
94 return lk201_send(info, LK_CMD_REQ_ID);
97 static int lk201_reset(struct dec_serial *info)
101 for (i = 0; i < sizeof(lk201_reset_string); i++) {
102 r = lk201_send(info, lk201_reset_string[i]);
109 static void lk201_report(unsigned char id[6])
111 char *report = "lk201: keyboard attached, ";
114 case LK_STAT_PWRUP_OK:
115 printk(KERN_INFO "%sself-test OK\n", report);
117 case LK_STAT_PWRUP_KDOWN:
118 /* The keyboard will resend the power-up ID
119 after all keys are released, so we don't
120 bother handling the error specially. Still
121 there may be a short-circuit inside.
123 printk(KERN_ERR "%skey down (stuck?), code: 0x%02x\n",
126 case LK_STAT_PWRUP_ERROR:
127 printk(KERN_ERR "%sself-test failure\n", report);
130 printk(KERN_ERR "%sunknown error: 0x%02x\n",
135 static void lk201_id(unsigned char id[6])
138 * Report whether there is an LK201 or an LK401
139 * The LK401 has ALT keys...
143 printk(KERN_INFO "lk201: LK201 detected\n");
146 printk(KERN_INFO "lk201: LK401 detected\n");
150 "lk201: unknown keyboard detected, ID %d\n", id[4]);
151 printk(KERN_WARNING "lk201: ... please report to "
152 "<linux-mips@oss.sgi.com>\n");
156 #define DEFAULT_KEYB_REP_DELAY (250/5) /* [5ms] */
157 #define DEFAULT_KEYB_REP_RATE 30 /* [cps] */
159 static struct kbd_repeat kbdrate = {
160 DEFAULT_KEYB_REP_DELAY,
161 DEFAULT_KEYB_REP_RATE
164 static void parse_kbd_rate(struct kbd_repeat *r)
167 r->delay = kbdrate.delay;
169 r->rate = kbdrate.rate;
183 static int write_kbd_rate(struct kbd_repeat *rep)
185 struct dec_serial* info = lk201kbd_info;
189 delay = rep->delay / 5;
191 for (i = 0; i < 4; i++) {
192 if (info->hook->poll_tx_char(info, LK_CMD_RPT_RATE(i)))
194 if (info->hook->poll_tx_char(info, LK_PARAM_DELAY(delay)))
196 if (info->hook->poll_tx_char(info, LK_PARAM_RATE(rate)))
202 static int lk201kbd_rate(struct kbd_repeat *rep)
209 if (write_kbd_rate(rep)) {
210 memcpy(rep, &kbdrate, sizeof(struct kbd_repeat));
214 memcpy(&kbdrate, rep, sizeof(struct kbd_repeat));
219 static void lk201kd_mksound(unsigned int hz, unsigned int ticks)
221 struct dec_serial* info = lk201kbd_info;
227 * Can't set frequency and we "approximate"
228 * duration by volume. ;-)
235 if (info->hook->poll_tx_char(info, LK_CMD_ENB_BELL))
237 if (info->hook->poll_tx_char(info, LK_PARAM_VOLUME(ticks)))
239 if (info->hook->poll_tx_char(info, LK_CMD_BELL))
243 void kbd_leds(unsigned char leds)
245 struct dec_serial* info = lk201kbd_info;
248 if (!info) /* FIXME */
251 /* FIXME -- Only Hold and Lock LEDs for now. --macro */
257 if (info->hook->poll_tx_char(info, LK_CMD_LEDS_ON))
259 if (info->hook->poll_tx_char(info, LK_PARAM_LED_MASK(l)))
261 if (info->hook->poll_tx_char(info, LK_CMD_LEDS_OFF))
263 if (info->hook->poll_tx_char(info, LK_PARAM_LED_MASK(~l)))
267 int kbd_setkeycode(unsigned int scancode, unsigned int keycode)
272 int kbd_getkeycode(unsigned int scancode)
277 int kbd_translate(unsigned char scancode, unsigned char *keycode,
284 char kbd_unexpected_up(unsigned char keycode)
289 static void lk201_kbd_rx_char(unsigned char ch, unsigned char stat)
291 static unsigned char id[6];
294 static int shift_state = 0;
295 static int prev_scancode;
296 unsigned char c = scancodeRemap[ch];
298 if (stat && stat != 4) {
299 printk(KERN_ERR "lk201: keyboard receive error: 0x%02x\n",
304 /* Assume this is a power-up ID. */
305 if (ch == LK_STAT_PWRUP_ID && !id_i) {
310 /* Handle the power-up sequence. */
314 /* OK, the power-up concluded. */
316 if (id[2] == LK_STAT_PWRUP_OK)
317 lk201_get_id(lk201kbd_info);
320 printk(KERN_ERR "lk201: keyboard power-up "
321 "error, skipping initialization\n");
323 } else if (id_i == 6) {
324 /* We got the ID; report it and start an operation. */
327 lk201_reset(lk201kbd_info);
332 /* Everything else is a scancode/status response. */
335 case LK_STAT_RESUME_ERR:
337 case LK_STAT_INHIBIT_ACK:
338 case LK_STAT_TEST_ACK:
339 case LK_STAT_MODE_KEYDOWN:
340 case LK_STAT_MODE_ACK:
343 shift_state ^= LK_LOCK;
344 handle_scancode(c, shift_state && LK_LOCK ? 1 : 0);
347 shift_state ^= LK_SHIFT;
348 handle_scancode(c, shift_state && LK_SHIFT ? 1 : 0);
351 shift_state ^= LK_CTRL;
352 handle_scancode(c, shift_state && LK_CTRL ? 1 : 0);
355 shift_state ^= LK_COMP;
356 handle_scancode(c, shift_state && LK_COMP ? 1 : 0);
359 if (shift_state & LK_SHIFT)
360 handle_scancode(scancodeRemap[LK_KEY_SHIFT], 0);
361 if (shift_state & LK_CTRL)
362 handle_scancode(scancodeRemap[LK_KEY_CTRL], 0);
363 if (shift_state & LK_COMP)
364 handle_scancode(scancodeRemap[LK_KEY_COMP], 0);
365 if (shift_state & LK_LOCK)
366 handle_scancode(scancodeRemap[LK_KEY_LOCK], 0);
370 handle_scancode(prev_scancode, 1);
374 handle_scancode(c, 1);
377 tasklet_schedule(&keyboard_tasklet);
380 static void __init lk201_info(struct dec_serial *info)
384 static int __init lk201_init(struct dec_serial *info)
386 /* First install handlers. */
387 lk201kbd_info = info;
388 kbd_rate = lk201kbd_rate;
389 kd_mksound = lk201kd_mksound;
391 info->hook->rx_char = lk201_kbd_rx_char;
393 /* Then just issue a reset -- the handlers will do the rest. */
394 lk201_send(info, LK_CMD_POWER_UP);
399 void __init kbd_init_hw(void)
401 extern int register_zs_hook(unsigned int, struct zs_hook *);
402 extern int unregister_zs_hook(unsigned int);
404 /* Maxine uses LK501 at the Access.Bus. */
405 if (mips_machtype == MACH_DS5000_XX)
408 printk(KERN_INFO "lk201: DECstation LK keyboard driver v0.05.\n");
412 * kbd_init_hw() is being called before
413 * rs_init() so just register the kbd hook
414 * and let zs_init do the rest :-)
416 if (mips_machtype == MACH_DS5000_200)
417 printk(KERN_ERR "lk201: support for DS5000/200 "
420 if(!register_zs_hook(KEYB_LINE, &lk201_kbdhook))
421 unregister_zs_hook(KEYB_LINE);
424 * TODO: modify dz.c to allow similar hooks
425 * for LK201 handling on DS2100, DS3100, and DS5000/200
427 printk(KERN_ERR "lk201: support for DS3100 not yet ready.\n");