Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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> |
| 32 | #include <linux/init.h> |
| 33 | #include <linux/serio.h> |
| 34 | |
| 35 | #define DRIVER_DESC "XT keyboard driver" |
| 36 | |
| 37 | MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>"); |
| 38 | MODULE_DESCRIPTION(DRIVER_DESC); |
| 39 | MODULE_LICENSE("GPL"); |
| 40 | |
| 41 | #define XTKBD_EMUL0 0xe0 |
| 42 | #define XTKBD_EMUL1 0xe1 |
| 43 | #define XTKBD_KEY 0x7f |
| 44 | #define XTKBD_RELEASE 0x80 |
| 45 | |
| 46 | static unsigned char xtkbd_keycode[256] = { |
| 47 | 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, |
| 48 | 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, |
| 49 | 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, |
| 50 | 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, |
| 51 | 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, |
| 52 | 80, 81, 82, 83, 0, 0, 0, 87, 88, 0, 0, 0, 0, 0, 0, 0, |
| 53 | 0, 0, 0, 0, 0, 87, 88, 0, 0, 0, 0,110,111,103,108,105, |
| 54 | 106 |
| 55 | }; |
| 56 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | struct xtkbd { |
| 58 | unsigned char keycode[256]; |
Dmitry Torokhov | 3c42f0c | 2005-09-15 02:01:45 -0500 | [diff] [blame] | 59 | struct input_dev *dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | struct serio *serio; |
| 61 | char phys[32]; |
| 62 | }; |
| 63 | |
| 64 | static irqreturn_t xtkbd_interrupt(struct serio *serio, |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 65 | unsigned char data, unsigned int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | { |
| 67 | struct xtkbd *xtkbd = serio_get_drvdata(serio); |
| 68 | |
| 69 | switch (data) { |
| 70 | case XTKBD_EMUL0: |
| 71 | case XTKBD_EMUL1: |
| 72 | break; |
| 73 | default: |
| 74 | |
| 75 | if (xtkbd->keycode[data & XTKBD_KEY]) { |
Dmitry Torokhov | 3c42f0c | 2005-09-15 02:01:45 -0500 | [diff] [blame] | 76 | input_report_key(xtkbd->dev, xtkbd->keycode[data & XTKBD_KEY], !(data & XTKBD_RELEASE)); |
| 77 | input_sync(xtkbd->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | } else { |
| 79 | printk(KERN_WARNING "xtkbd.c: Unknown key (scancode %#x) %s.\n", |
| 80 | data & XTKBD_KEY, data & XTKBD_RELEASE ? "released" : "pressed"); |
| 81 | } |
| 82 | } |
| 83 | return IRQ_HANDLED; |
| 84 | } |
| 85 | |
| 86 | static int xtkbd_connect(struct serio *serio, struct serio_driver *drv) |
| 87 | { |
| 88 | struct xtkbd *xtkbd; |
Dmitry Torokhov | 3c42f0c | 2005-09-15 02:01:45 -0500 | [diff] [blame] | 89 | struct input_dev *input_dev; |
| 90 | int err = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | |
Dmitry Torokhov | 3c42f0c | 2005-09-15 02:01:45 -0500 | [diff] [blame] | 93 | xtkbd = kmalloc(sizeof(struct xtkbd), GFP_KERNEL); |
| 94 | input_dev = input_allocate_device(); |
| 95 | if (!xtkbd || !input_dev) |
Dmitry Torokhov | 2b03b60 | 2006-11-05 22:39:56 -0500 | [diff] [blame] | 96 | goto fail1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | |
| 98 | xtkbd->serio = serio; |
Dmitry Torokhov | 3c42f0c | 2005-09-15 02:01:45 -0500 | [diff] [blame] | 99 | xtkbd->dev = input_dev; |
Dmitry Torokhov | ea08c6f | 2006-06-26 01:46:17 -0400 | [diff] [blame] | 100 | snprintf(xtkbd->phys, sizeof(xtkbd->phys), "%s/input0", serio->phys); |
Dmitry Torokhov | 3c42f0c | 2005-09-15 02:01:45 -0500 | [diff] [blame] | 101 | memcpy(xtkbd->keycode, xtkbd_keycode, sizeof(xtkbd->keycode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | |
Dmitry Torokhov | 3c42f0c | 2005-09-15 02:01:45 -0500 | [diff] [blame] | 103 | input_dev->name = "XT Keyboard"; |
| 104 | input_dev->phys = xtkbd->phys; |
| 105 | input_dev->id.bustype = BUS_XTKBD; |
| 106 | input_dev->id.vendor = 0x0001; |
| 107 | input_dev->id.product = 0x0001; |
| 108 | input_dev->id.version = 0x0100; |
Dmitry Torokhov | 469ba4d | 2007-04-12 01:34:58 -0400 | [diff] [blame] | 109 | input_dev->dev.parent = &serio->dev; |
Dmitry Torokhov | 3c42f0c | 2005-09-15 02:01:45 -0500 | [diff] [blame] | 110 | |
Jiri Slaby | 7b19ada | 2007-10-18 23:40:32 -0700 | [diff] [blame] | 111 | input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REP); |
Dmitry Torokhov | 3c42f0c | 2005-09-15 02:01:45 -0500 | [diff] [blame] | 112 | input_dev->keycode = xtkbd->keycode; |
| 113 | input_dev->keycodesize = sizeof(unsigned char); |
| 114 | input_dev->keycodemax = ARRAY_SIZE(xtkbd_keycode); |
| 115 | |
| 116 | for (i = 0; i < 255; i++) |
| 117 | set_bit(xtkbd->keycode[i], input_dev->keybit); |
| 118 | clear_bit(0, input_dev->keybit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | |
| 120 | serio_set_drvdata(serio, xtkbd); |
| 121 | |
| 122 | err = serio_open(serio, drv); |
Dmitry Torokhov | 3c42f0c | 2005-09-15 02:01:45 -0500 | [diff] [blame] | 123 | if (err) |
Dmitry Torokhov | 2b03b60 | 2006-11-05 22:39:56 -0500 | [diff] [blame] | 124 | goto fail2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | |
Dmitry Torokhov | 2b03b60 | 2006-11-05 22:39:56 -0500 | [diff] [blame] | 126 | err = input_register_device(xtkbd->dev); |
| 127 | if (err) |
| 128 | goto fail3; |
| 129 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | return 0; |
Dmitry Torokhov | 3c42f0c | 2005-09-15 02:01:45 -0500 | [diff] [blame] | 131 | |
Dmitry Torokhov | 2b03b60 | 2006-11-05 22:39:56 -0500 | [diff] [blame] | 132 | fail3: serio_close(serio); |
| 133 | fail2: serio_set_drvdata(serio, NULL); |
| 134 | fail1: input_free_device(input_dev); |
Dmitry Torokhov | 3c42f0c | 2005-09-15 02:01:45 -0500 | [diff] [blame] | 135 | kfree(xtkbd); |
| 136 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | } |
| 138 | |
| 139 | static void xtkbd_disconnect(struct serio *serio) |
| 140 | { |
| 141 | struct xtkbd *xtkbd = serio_get_drvdata(serio); |
| 142 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | serio_close(serio); |
| 144 | serio_set_drvdata(serio, NULL); |
Dmitry Torokhov | 3c42f0c | 2005-09-15 02:01:45 -0500 | [diff] [blame] | 145 | input_unregister_device(xtkbd->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | kfree(xtkbd); |
| 147 | } |
| 148 | |
| 149 | static struct serio_device_id xtkbd_serio_ids[] = { |
| 150 | { |
| 151 | .type = SERIO_XT, |
| 152 | .proto = SERIO_ANY, |
| 153 | .id = SERIO_ANY, |
| 154 | .extra = SERIO_ANY, |
| 155 | }, |
| 156 | { 0 } |
| 157 | }; |
| 158 | |
| 159 | MODULE_DEVICE_TABLE(serio, xtkbd_serio_ids); |
| 160 | |
| 161 | static struct serio_driver xtkbd_drv = { |
| 162 | .driver = { |
| 163 | .name = "xtkbd", |
| 164 | }, |
| 165 | .description = DRIVER_DESC, |
| 166 | .id_table = xtkbd_serio_ids, |
| 167 | .interrupt = xtkbd_interrupt, |
| 168 | .connect = xtkbd_connect, |
| 169 | .disconnect = xtkbd_disconnect, |
| 170 | }; |
| 171 | |
| 172 | static int __init xtkbd_init(void) |
| 173 | { |
Akinobu Mita | 153a9df0 | 2006-11-23 23:35:10 -0500 | [diff] [blame] | 174 | return serio_register_driver(&xtkbd_drv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | static void __exit xtkbd_exit(void) |
| 178 | { |
| 179 | serio_unregister_driver(&xtkbd_drv); |
| 180 | } |
| 181 | |
| 182 | module_init(xtkbd_init); |
| 183 | module_exit(xtkbd_exit); |