xtkbd.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /*
  2. * Copyright (c) 1999-2001 Vojtech Pavlik
  3. */
  4. /*
  5. * XT keyboard driver for Linux
  6. */
  7. /*
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. *
  22. * Should you need to contact me, the author, you can do so either by
  23. * e-mail - mail your message to <vojtech@ucw.cz>, or by paper mail:
  24. * Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic
  25. */
  26. #include <linux/slab.h>
  27. #include <linux/module.h>
  28. #include <linux/input.h>
  29. #include <linux/serio.h>
  30. #define DRIVER_DESC "XT keyboard driver"
  31. MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
  32. MODULE_DESCRIPTION(DRIVER_DESC);
  33. MODULE_LICENSE("GPL");
  34. #define XTKBD_EMUL0 0xe0
  35. #define XTKBD_EMUL1 0xe1
  36. #define XTKBD_KEY 0x7f
  37. #define XTKBD_RELEASE 0x80
  38. static unsigned char xtkbd_keycode[256] = {
  39. 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
  40. 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
  41. 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
  42. 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
  43. 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
  44. 80, 81, 82, 83, 0, 0, 0, 87, 88, 0, 0, 0, 0, 0, 0, 0,
  45. 0, 0, 0, 0, 0, 87, 88, 0, 0, 0, 0,110,111,103,108,105,
  46. 106
  47. };
  48. struct xtkbd {
  49. unsigned char keycode[256];
  50. struct input_dev *dev;
  51. struct serio *serio;
  52. char phys[32];
  53. };
  54. static irqreturn_t xtkbd_interrupt(struct serio *serio,
  55. unsigned char data, unsigned int flags)
  56. {
  57. struct xtkbd *xtkbd = serio_get_drvdata(serio);
  58. switch (data) {
  59. case XTKBD_EMUL0:
  60. case XTKBD_EMUL1:
  61. break;
  62. default:
  63. if (xtkbd->keycode[data & XTKBD_KEY]) {
  64. input_report_key(xtkbd->dev, xtkbd->keycode[data & XTKBD_KEY], !(data & XTKBD_RELEASE));
  65. input_sync(xtkbd->dev);
  66. } else {
  67. printk(KERN_WARNING "xtkbd.c: Unknown key (scancode %#x) %s.\n",
  68. data & XTKBD_KEY, data & XTKBD_RELEASE ? "released" : "pressed");
  69. }
  70. }
  71. return IRQ_HANDLED;
  72. }
  73. static int xtkbd_connect(struct serio *serio, struct serio_driver *drv)
  74. {
  75. struct xtkbd *xtkbd;
  76. struct input_dev *input_dev;
  77. int err = -ENOMEM;
  78. int i;
  79. xtkbd = kmalloc(sizeof(struct xtkbd), GFP_KERNEL);
  80. input_dev = input_allocate_device();
  81. if (!xtkbd || !input_dev)
  82. goto fail1;
  83. xtkbd->serio = serio;
  84. xtkbd->dev = input_dev;
  85. snprintf(xtkbd->phys, sizeof(xtkbd->phys), "%s/input0", serio->phys);
  86. memcpy(xtkbd->keycode, xtkbd_keycode, sizeof(xtkbd->keycode));
  87. input_dev->name = "XT Keyboard";
  88. input_dev->phys = xtkbd->phys;
  89. input_dev->id.bustype = BUS_XTKBD;
  90. input_dev->id.vendor = 0x0001;
  91. input_dev->id.product = 0x0001;
  92. input_dev->id.version = 0x0100;
  93. input_dev->dev.parent = &serio->dev;
  94. input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REP);
  95. input_dev->keycode = xtkbd->keycode;
  96. input_dev->keycodesize = sizeof(unsigned char);
  97. input_dev->keycodemax = ARRAY_SIZE(xtkbd_keycode);
  98. for (i = 0; i < 255; i++)
  99. set_bit(xtkbd->keycode[i], input_dev->keybit);
  100. clear_bit(0, input_dev->keybit);
  101. serio_set_drvdata(serio, xtkbd);
  102. err = serio_open(serio, drv);
  103. if (err)
  104. goto fail2;
  105. err = input_register_device(xtkbd->dev);
  106. if (err)
  107. goto fail3;
  108. return 0;
  109. fail3: serio_close(serio);
  110. fail2: serio_set_drvdata(serio, NULL);
  111. fail1: input_free_device(input_dev);
  112. kfree(xtkbd);
  113. return err;
  114. }
  115. static void xtkbd_disconnect(struct serio *serio)
  116. {
  117. struct xtkbd *xtkbd = serio_get_drvdata(serio);
  118. serio_close(serio);
  119. serio_set_drvdata(serio, NULL);
  120. input_unregister_device(xtkbd->dev);
  121. kfree(xtkbd);
  122. }
  123. static struct serio_device_id xtkbd_serio_ids[] = {
  124. {
  125. .type = SERIO_XT,
  126. .proto = SERIO_ANY,
  127. .id = SERIO_ANY,
  128. .extra = SERIO_ANY,
  129. },
  130. { 0 }
  131. };
  132. MODULE_DEVICE_TABLE(serio, xtkbd_serio_ids);
  133. static struct serio_driver xtkbd_drv = {
  134. .driver = {
  135. .name = "xtkbd",
  136. },
  137. .description = DRIVER_DESC,
  138. .id_table = xtkbd_serio_ids,
  139. .interrupt = xtkbd_interrupt,
  140. .connect = xtkbd_connect,
  141. .disconnect = xtkbd_disconnect,
  142. };
  143. module_serio_driver(xtkbd_drv);