xtkbd.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. /*
  2. * $Id: xtkbd.c,v 1.1.1.1 2007/06/12 07:27:09 eyryu Exp $
  3. *
  4. * Copyright (c) 1999-2001 Vojtech Pavlik
  5. */
  6. /*
  7. * XT keyboard driver for Linux
  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. #include <linux/slab.h>
  29. #include <linux/module.h>
  30. #include <linux/input.h>
  31. #include <linux/init.h>
  32. #include <linux/serio.h>
  33. #define DRIVER_DESC "XT keyboard driver"
  34. MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
  35. MODULE_DESCRIPTION(DRIVER_DESC);
  36. MODULE_LICENSE("GPL");
  37. #define XTKBD_EMUL0 0xe0
  38. #define XTKBD_EMUL1 0xe1
  39. #define XTKBD_KEY 0x7f
  40. #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,
  49. 106
  50. };
  51. struct xtkbd {
  52. unsigned char keycode[256];
  53. struct input_dev *dev;
  54. struct serio *serio;
  55. char phys[32];
  56. };
  57. static irqreturn_t xtkbd_interrupt(struct serio *serio,
  58. unsigned char data, unsigned int flags)
  59. {
  60. struct xtkbd *xtkbd = serio_get_drvdata(serio);
  61. switch (data) {
  62. case XTKBD_EMUL0:
  63. case XTKBD_EMUL1:
  64. break;
  65. default:
  66. if (xtkbd->keycode[data & XTKBD_KEY]) {
  67. input_report_key(xtkbd->dev, xtkbd->keycode[data & XTKBD_KEY], !(data & XTKBD_RELEASE));
  68. input_sync(xtkbd->dev);
  69. } else {
  70. printk(KERN_WARNING "xtkbd.c: Unknown key (scancode %#x) %s.\n",
  71. data & XTKBD_KEY, data & XTKBD_RELEASE ? "released" : "pressed");
  72. }
  73. }
  74. return IRQ_HANDLED;
  75. }
  76. static int xtkbd_connect(struct serio *serio, struct serio_driver *drv)
  77. {
  78. struct xtkbd *xtkbd;
  79. struct input_dev *input_dev;
  80. int err = -ENOMEM;
  81. int i;
  82. xtkbd = kmalloc(sizeof(struct xtkbd), GFP_KERNEL);
  83. input_dev = input_allocate_device();
  84. if (!xtkbd || !input_dev)
  85. goto fail1;
  86. xtkbd->serio = serio;
  87. xtkbd->dev = input_dev;
  88. snprintf(xtkbd->phys, sizeof(xtkbd->phys), "%s/input0", serio->phys);
  89. memcpy(xtkbd->keycode, xtkbd_keycode, sizeof(xtkbd->keycode));
  90. input_dev->name = "XT Keyboard";
  91. input_dev->phys = xtkbd->phys;
  92. input_dev->id.bustype = BUS_XTKBD;
  93. input_dev->id.vendor = 0x0001;
  94. input_dev->id.product = 0x0001;
  95. input_dev->id.version = 0x0100;
  96. input_dev->cdev.dev = &serio->dev;
  97. input_dev->private = xtkbd;
  98. input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REP);
  99. input_dev->keycode = xtkbd->keycode;
  100. input_dev->keycodesize = sizeof(unsigned char);
  101. input_dev->keycodemax = ARRAY_SIZE(xtkbd_keycode);
  102. for (i = 0; i < 255; i++)
  103. set_bit(xtkbd->keycode[i], input_dev->keybit);
  104. clear_bit(0, input_dev->keybit);
  105. serio_set_drvdata(serio, xtkbd);
  106. err = serio_open(serio, drv);
  107. if (err)
  108. goto fail2;
  109. err = input_register_device(xtkbd->dev);
  110. if (err)
  111. goto fail3;
  112. return 0;
  113. fail3: serio_close(serio);
  114. fail2: serio_set_drvdata(serio, NULL);
  115. fail1: input_free_device(input_dev);
  116. kfree(xtkbd);
  117. return err;
  118. }
  119. static void xtkbd_disconnect(struct serio *serio)
  120. {
  121. struct xtkbd *xtkbd = serio_get_drvdata(serio);
  122. serio_close(serio);
  123. serio_set_drvdata(serio, NULL);
  124. input_unregister_device(xtkbd->dev);
  125. kfree(xtkbd);
  126. }
  127. static struct serio_device_id xtkbd_serio_ids[] = {
  128. {
  129. .type = SERIO_XT,
  130. .proto = SERIO_ANY,
  131. .id = SERIO_ANY,
  132. .extra = SERIO_ANY,
  133. },
  134. { 0 }
  135. };
  136. MODULE_DEVICE_TABLE(serio, xtkbd_serio_ids);
  137. static struct serio_driver xtkbd_drv = {
  138. .driver = {
  139. .name = "xtkbd",
  140. },
  141. .description = DRIVER_DESC,
  142. .id_table = xtkbd_serio_ids,
  143. .interrupt = xtkbd_interrupt,
  144. .connect = xtkbd_connect,
  145. .disconnect = xtkbd_disconnect,
  146. };
  147. static int __init xtkbd_init(void)
  148. {
  149. return serio_register_driver(&xtkbd_drv);
  150. }
  151. static void __exit xtkbd_exit(void)
  152. {
  153. serio_unregister_driver(&xtkbd_drv);
  154. }
  155. module_init(xtkbd_init);
  156. module_exit(xtkbd_exit);