2 * Copyright (c) 2000 Justin Cormack
6 * Newton keyboard driver for Linux
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 * Should you need to contact me, the author, you can do so either by
25 * e-mail - mail your message to <j.cormack@doc.ic.ac.uk>, or by paper mail:
26 * Justin Cormack, 68 Dartmouth Park Road, London NW5 1SN, UK.
29 #include <linux/slab.h>
30 #include <linux/module.h>
31 #include <linux/input.h>
32 #include <linux/init.h>
33 #include <linux/serio.h>
35 MODULE_AUTHOR("Justin Cormack <j.cormack@doc.ic.ac.uk>");
36 MODULE_DESCRIPTION("Newton keyboard driver");
37 MODULE_LICENSE("GPL");
40 #define NKBD_PRESS 0x80
42 static unsigned char nkbd_keycode[128] = {
43 KEY_A, KEY_S, KEY_D, KEY_F, KEY_H, KEY_G, KEY_Z, KEY_X,
44 KEY_C, KEY_V, 0, KEY_B, KEY_Q, KEY_W, KEY_E, KEY_R,
45 KEY_Y, KEY_T, KEY_1, KEY_2, KEY_3, KEY_4, KEY_6, KEY_5,
46 KEY_EQUAL, KEY_9, KEY_7, KEY_MINUS, KEY_8, KEY_0, KEY_RIGHTBRACE, KEY_O,
47 KEY_U, KEY_LEFTBRACE, KEY_I, KEY_P, KEY_ENTER, KEY_L, KEY_J, KEY_APOSTROPHE,
48 KEY_K, KEY_SEMICOLON, KEY_BACKSLASH, KEY_COMMA, KEY_SLASH, KEY_N, KEY_M, KEY_DOT,
49 KEY_TAB, KEY_SPACE, KEY_GRAVE, KEY_DELETE, 0, 0, 0, KEY_LEFTMETA,
50 KEY_LEFTSHIFT, KEY_CAPSLOCK, KEY_LEFTALT, KEY_LEFTCTRL, KEY_RIGHTSHIFT, 0, 0, 0,
51 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
52 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
53 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
54 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
55 KEY_LEFT, KEY_RIGHT, KEY_DOWN, KEY_UP, 0
58 static char *nkbd_name = "Newton Keyboard";
61 unsigned char keycode[128];
67 irqreturn_t nkbd_interrupt(struct serio *serio,
68 unsigned char data, unsigned int flags, struct pt_regs *regs)
70 struct nkbd *nkbd = serio->private;
72 /* invalid scan codes are probably the init sequence, so we ignore them */
73 if (nkbd->keycode[data & NKBD_KEY]) {
74 input_regs(&nkbd->dev, regs);
75 input_report_key(&nkbd->dev, nkbd->keycode[data & NKBD_KEY], data & NKBD_PRESS);
76 input_sync(&nkbd->dev);
79 else if (data == 0xe7) /* end of init sequence */
80 printk(KERN_INFO "input: %s on %s\n", nkbd_name, serio->phys);
85 void nkbd_connect(struct serio *serio, struct serio_dev *dev)
90 if (serio->type != (SERIO_RS232 | SERIO_NEWTON))
93 if (!(nkbd = kmalloc(sizeof(struct nkbd), GFP_KERNEL)))
96 memset(nkbd, 0, sizeof(struct nkbd));
98 nkbd->dev.evbit[0] = BIT(EV_KEY) | BIT(EV_REP);
102 init_input_dev(&nkbd->dev);
103 nkbd->dev.keycode = nkbd->keycode;
104 nkbd->dev.keycodesize = sizeof(unsigned char);
105 nkbd->dev.keycodemax = ARRAY_SIZE(nkbd_keycode);
106 nkbd->dev.private = nkbd;
107 serio->private = nkbd;
109 if (serio_open(serio, dev)) {
114 memcpy(nkbd->keycode, nkbd_keycode, sizeof(nkbd->keycode));
115 for (i = 0; i < 128; i++)
116 set_bit(nkbd->keycode[i], nkbd->dev.keybit);
117 clear_bit(0, nkbd->dev.keybit);
119 sprintf(nkbd->phys, "%s/input0", serio->phys);
121 nkbd->dev.name = nkbd_name;
122 nkbd->dev.phys = nkbd->phys;
123 nkbd->dev.id.bustype = BUS_RS232;
124 nkbd->dev.id.vendor = SERIO_NEWTON;
125 nkbd->dev.id.product = 0x0001;
126 nkbd->dev.id.version = 0x0100;
128 input_register_device(&nkbd->dev);
130 printk(KERN_INFO "input: %s on %s\n", nkbd_name, serio->phys);
133 void nkbd_disconnect(struct serio *serio)
135 struct nkbd *nkbd = serio->private;
136 input_unregister_device(&nkbd->dev);
141 struct serio_dev nkbd_dev = {
142 .interrupt = nkbd_interrupt,
143 .connect = nkbd_connect,
144 .disconnect = nkbd_disconnect
147 int __init nkbd_init(void)
149 serio_register_device(&nkbd_dev);
153 void __exit nkbd_exit(void)
155 serio_unregister_device(&nkbd_dev);
158 module_init(nkbd_init);
159 module_exit(nkbd_exit);