Merge branch 'for-4.6-ns' of git://git.kernel.org/pub/scm/linux/kernel/git/tj/cgroup
[deliverable/linux.git] / drivers / input / keyboard / xtkbd.c
CommitLineData
1da177e4 1/*
1da177e4
LT
2 * Copyright (c) 1999-2001 Vojtech Pavlik
3 */
4
5/*
6 * XT keyboard driver for Linux
7 */
8
9/*
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.
14 *
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.
19 *
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
23 *
24 * Should you need to contact me, the author, you can do so either by
25 * e-mail - mail your message to <vojtech@ucw.cz>, or by paper mail:
26 * Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic
27 */
28
29#include <linux/slab.h>
30#include <linux/module.h>
31#include <linux/input.h>
1da177e4
LT
32#include <linux/serio.h>
33
34#define DRIVER_DESC "XT keyboard driver"
35
36MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
37MODULE_DESCRIPTION(DRIVER_DESC);
38MODULE_LICENSE("GPL");
39
40#define XTKBD_EMUL0 0xe0
41#define XTKBD_EMUL1 0xe1
42#define XTKBD_KEY 0x7f
43#define XTKBD_RELEASE 0x80
44
45static unsigned char xtkbd_keycode[256] = {
46 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
47 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
48 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
49 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
50 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
51 80, 81, 82, 83, 0, 0, 0, 87, 88, 0, 0, 0, 0, 0, 0, 0,
52 0, 0, 0, 0, 0, 87, 88, 0, 0, 0, 0,110,111,103,108,105,
53 106
54};
55
1da177e4
LT
56struct xtkbd {
57 unsigned char keycode[256];
3c42f0c3 58 struct input_dev *dev;
1da177e4
LT
59 struct serio *serio;
60 char phys[32];
61};
62
63static irqreturn_t xtkbd_interrupt(struct serio *serio,
7d12e780 64 unsigned char data, unsigned int flags)
1da177e4
LT
65{
66 struct xtkbd *xtkbd = serio_get_drvdata(serio);
67
68 switch (data) {
69 case XTKBD_EMUL0:
70 case XTKBD_EMUL1:
71 break;
72 default:
73
74 if (xtkbd->keycode[data & XTKBD_KEY]) {
3c42f0c3
DT
75 input_report_key(xtkbd->dev, xtkbd->keycode[data & XTKBD_KEY], !(data & XTKBD_RELEASE));
76 input_sync(xtkbd->dev);
1da177e4
LT
77 } else {
78 printk(KERN_WARNING "xtkbd.c: Unknown key (scancode %#x) %s.\n",
79 data & XTKBD_KEY, data & XTKBD_RELEASE ? "released" : "pressed");
80 }
81 }
82 return IRQ_HANDLED;
83}
84
85static int xtkbd_connect(struct serio *serio, struct serio_driver *drv)
86{
87 struct xtkbd *xtkbd;
3c42f0c3
DT
88 struct input_dev *input_dev;
89 int err = -ENOMEM;
1da177e4 90 int i;
1da177e4 91
3c42f0c3
DT
92 xtkbd = kmalloc(sizeof(struct xtkbd), GFP_KERNEL);
93 input_dev = input_allocate_device();
94 if (!xtkbd || !input_dev)
2b03b60e 95 goto fail1;
1da177e4
LT
96
97 xtkbd->serio = serio;
3c42f0c3 98 xtkbd->dev = input_dev;
ea08c6fa 99 snprintf(xtkbd->phys, sizeof(xtkbd->phys), "%s/input0", serio->phys);
3c42f0c3 100 memcpy(xtkbd->keycode, xtkbd_keycode, sizeof(xtkbd->keycode));
1da177e4 101
3c42f0c3
DT
102 input_dev->name = "XT Keyboard";
103 input_dev->phys = xtkbd->phys;
104 input_dev->id.bustype = BUS_XTKBD;
105 input_dev->id.vendor = 0x0001;
106 input_dev->id.product = 0x0001;
107 input_dev->id.version = 0x0100;
469ba4df 108 input_dev->dev.parent = &serio->dev;
1da177e4 109
7b19ada2 110 input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REP);
3c42f0c3
DT
111 input_dev->keycode = xtkbd->keycode;
112 input_dev->keycodesize = sizeof(unsigned char);
113 input_dev->keycodemax = ARRAY_SIZE(xtkbd_keycode);
1da177e4 114
1da177e4 115 for (i = 0; i < 255; i++)
3c42f0c3
DT
116 set_bit(xtkbd->keycode[i], input_dev->keybit);
117 clear_bit(0, input_dev->keybit);
1da177e4 118
3c42f0c3 119 serio_set_drvdata(serio, xtkbd);
1da177e4 120
3c42f0c3
DT
121 err = serio_open(serio, drv);
122 if (err)
2b03b60e
DT
123 goto fail2;
124
125 err = input_register_device(xtkbd->dev);
126 if (err)
127 goto fail3;
1da177e4
LT
128
129 return 0;
3c42f0c3 130
2b03b60e
DT
131 fail3: serio_close(serio);
132 fail2: serio_set_drvdata(serio, NULL);
133 fail1: input_free_device(input_dev);
3c42f0c3
DT
134 kfree(xtkbd);
135 return err;
1da177e4
LT
136}
137
138static void xtkbd_disconnect(struct serio *serio)
139{
140 struct xtkbd *xtkbd = serio_get_drvdata(serio);
141
1da177e4
LT
142 serio_close(serio);
143 serio_set_drvdata(serio, NULL);
3c42f0c3 144 input_unregister_device(xtkbd->dev);
1da177e4
LT
145 kfree(xtkbd);
146}
147
148static struct serio_device_id xtkbd_serio_ids[] = {
149 {
150 .type = SERIO_XT,
151 .proto = SERIO_ANY,
152 .id = SERIO_ANY,
153 .extra = SERIO_ANY,
154 },
155 { 0 }
156};
157
158MODULE_DEVICE_TABLE(serio, xtkbd_serio_ids);
159
160static struct serio_driver xtkbd_drv = {
161 .driver = {
162 .name = "xtkbd",
163 },
164 .description = DRIVER_DESC,
165 .id_table = xtkbd_serio_ids,
166 .interrupt = xtkbd_interrupt,
167 .connect = xtkbd_connect,
168 .disconnect = xtkbd_disconnect,
169};
170
65ac9f7a 171module_serio_driver(xtkbd_drv);
This page took 0.7387 seconds and 5 git commands to generate.