2 * Copyright (c) 1999-2001 Vojtech Pavlik
6 * XT 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
25 #include <linux/slab.h>
26 #include <linux/module.h>
27 #include <linux/input.h>
28 #include <linux/serio.h>
30 #define DRIVER_DESC "XT keyboard driver"
32 MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
33 MODULE_DESCRIPTION(DRIVER_DESC
);
34 MODULE_LICENSE("GPL");
36 #define XTKBD_EMUL0 0xe0
37 #define XTKBD_EMUL1 0xe1
38 #define XTKBD_KEY 0x7f
39 #define XTKBD_RELEASE 0x80
41 static unsigned char xtkbd_keycode
[256] = {
42 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
43 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
44 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
45 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
46 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
47 80, 81, 82, 83, 0, 0, 0, 87, 88, 0, 0, 0, 0, 0, 0, 0,
48 0, 0, 0, 0, 0, 87, 88, 0, 0, 0, 0,110,111,103,108,105,
53 unsigned char keycode
[256];
54 struct input_dev
*dev
;
59 static irqreturn_t
xtkbd_interrupt(struct serio
*serio
,
60 unsigned char data
, unsigned int flags
)
62 struct xtkbd
*xtkbd
= serio_get_drvdata(serio
);
70 if (xtkbd
->keycode
[data
& XTKBD_KEY
]) {
71 input_report_key(xtkbd
->dev
, xtkbd
->keycode
[data
& XTKBD_KEY
], !(data
& XTKBD_RELEASE
));
72 input_sync(xtkbd
->dev
);
74 printk(KERN_WARNING
"xtkbd.c: Unknown key (scancode %#x) %s.\n",
75 data
& XTKBD_KEY
, data
& XTKBD_RELEASE
? "released" : "pressed");
81 static int xtkbd_connect(struct serio
*serio
, struct serio_driver
*drv
)
84 struct input_dev
*input_dev
;
88 xtkbd
= kmalloc(sizeof(struct xtkbd
), GFP_KERNEL
);
89 input_dev
= input_allocate_device();
90 if (!xtkbd
|| !input_dev
)
94 xtkbd
->dev
= input_dev
;
95 snprintf(xtkbd
->phys
, sizeof(xtkbd
->phys
), "%s/input0", serio
->phys
);
96 memcpy(xtkbd
->keycode
, xtkbd_keycode
, sizeof(xtkbd
->keycode
));
98 input_dev
->name
= "XT Keyboard";
99 input_dev
->phys
= xtkbd
->phys
;
100 input_dev
->id
.bustype
= BUS_XTKBD
;
101 input_dev
->id
.vendor
= 0x0001;
102 input_dev
->id
.product
= 0x0001;
103 input_dev
->id
.version
= 0x0100;
104 input_dev
->dev
.parent
= &serio
->dev
;
106 input_dev
->evbit
[0] = BIT_MASK(EV_KEY
) | BIT_MASK(EV_REP
);
107 input_dev
->keycode
= xtkbd
->keycode
;
108 input_dev
->keycodesize
= sizeof(unsigned char);
109 input_dev
->keycodemax
= ARRAY_SIZE(xtkbd_keycode
);
111 for (i
= 0; i
< 255; i
++)
112 set_bit(xtkbd
->keycode
[i
], input_dev
->keybit
);
113 clear_bit(0, input_dev
->keybit
);
115 serio_set_drvdata(serio
, xtkbd
);
117 err
= serio_open(serio
, drv
);
121 err
= input_register_device(xtkbd
->dev
);
127 fail3
: serio_close(serio
);
128 fail2
: serio_set_drvdata(serio
, NULL
);
129 fail1
: input_free_device(input_dev
);
134 static void xtkbd_disconnect(struct serio
*serio
)
136 struct xtkbd
*xtkbd
= serio_get_drvdata(serio
);
139 serio_set_drvdata(serio
, NULL
);
140 input_unregister_device(xtkbd
->dev
);
144 static const struct serio_device_id xtkbd_serio_ids
[] = {
154 MODULE_DEVICE_TABLE(serio
, xtkbd_serio_ids
);
156 static struct serio_driver xtkbd_drv
= {
160 .description
= DRIVER_DESC
,
161 .id_table
= xtkbd_serio_ids
,
162 .interrupt
= xtkbd_interrupt
,
163 .connect
= xtkbd_connect
,
164 .disconnect
= xtkbd_disconnect
,
167 module_serio_driver(xtkbd_drv
);