xtkbd.c 4.3 KB

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