hid-primax.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /*
  2. * HID driver for primax and similar keyboards with in-band modifiers
  3. *
  4. * Copyright 2011 Google Inc. All Rights Reserved
  5. *
  6. * Author:
  7. * Terry Lambert <tlambert@google.com>
  8. *
  9. * This software is licensed under the terms of the GNU General Public
  10. * License version 2, as published by the Free Software Foundation, and
  11. * may be copied, distributed, and modified under those terms.
  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. #include <linux/device.h>
  19. #include <linux/hid.h>
  20. #include <linux/module.h>
  21. #include "hid-ids.h"
  22. static int px_raw_event(struct hid_device *hid, struct hid_report *report,
  23. u8 *data, int size)
  24. {
  25. int idx = size;
  26. switch (report->id) {
  27. case 0: /* keyboard input */
  28. /*
  29. * Convert in-band modifier key values into out of band
  30. * modifier bits and pull the key strokes from the report.
  31. * Thus a report data set which looked like:
  32. *
  33. * [00][00][E0][30][00][00][00][00]
  34. * (no modifier bits + "Left Shift" key + "1" key)
  35. *
  36. * Would be converted to:
  37. *
  38. * [01][00][00][30][00][00][00][00]
  39. * (Left Shift modifier bit + "1" key)
  40. *
  41. * As long as it's in the size range, the upper level
  42. * drivers don't particularly care if there are in-band
  43. * 0-valued keys, so they don't stop parsing.
  44. */
  45. while (--idx > 1) {
  46. if (data[idx] < 0xE0 || data[idx] > 0xE7)
  47. continue;
  48. data[0] |= (1 << (data[idx] - 0xE0));
  49. data[idx] = 0;
  50. }
  51. hid_report_raw_event(hid, HID_INPUT_REPORT, data, size, 0);
  52. return 1;
  53. default: /* unknown report */
  54. /* Unknown report type; pass upstream */
  55. hid_info(hid, "unknown report type %d\n", report->id);
  56. break;
  57. }
  58. return 0;
  59. }
  60. static int px_probe(struct hid_device *hid, const struct hid_device_id *id)
  61. {
  62. int ret;
  63. ret = hid_parse(hid);
  64. if (ret) {
  65. hid_err(hid, "parse failed\n");
  66. goto fail;
  67. }
  68. ret = hid_hw_start(hid, HID_CONNECT_DEFAULT);
  69. if (ret)
  70. hid_err(hid, "hw start failed\n");
  71. fail:
  72. return ret;
  73. }
  74. static void px_remove(struct hid_device *hid)
  75. {
  76. hid_hw_stop(hid);
  77. }
  78. static const struct hid_device_id px_devices[] = {
  79. { HID_USB_DEVICE(USB_VENDOR_ID_PRIMAX, USB_DEVICE_ID_PRIMAX_KEYBOARD) },
  80. { }
  81. };
  82. MODULE_DEVICE_TABLE(hid, px_devices);
  83. static struct hid_driver px_driver = {
  84. .name = "primax",
  85. .id_table = px_devices,
  86. .raw_event = px_raw_event,
  87. .probe = px_probe,
  88. .remove = px_remove,
  89. };
  90. static int __init px_init(void)
  91. {
  92. return hid_register_driver(&px_driver);
  93. }
  94. static void __exit px_exit(void)
  95. {
  96. hid_unregister_driver(&px_driver);
  97. }
  98. module_init(px_init);
  99. module_exit(px_exit);
  100. MODULE_AUTHOR("Terry Lambert <tlambert@google.com>");
  101. MODULE_LICENSE("GPL");