hid-primax.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * HID driver for primax and similar keyboards with in-band modifiers
  4. *
  5. * Copyright 2011 Google Inc. All Rights Reserved
  6. *
  7. * Author:
  8. * Terry Lambert <[email protected]>
  9. */
  10. #include <linux/device.h>
  11. #include <linux/hid.h>
  12. #include <linux/module.h>
  13. #include "hid-ids.h"
  14. static int px_raw_event(struct hid_device *hid, struct hid_report *report,
  15. u8 *data, int size)
  16. {
  17. int idx = size;
  18. switch (report->id) {
  19. case 0: /* keyboard input */
  20. /*
  21. * Convert in-band modifier key values into out of band
  22. * modifier bits and pull the key strokes from the report.
  23. * Thus a report data set which looked like:
  24. *
  25. * [00][00][E0][30][00][00][00][00]
  26. * (no modifier bits + "Left Shift" key + "1" key)
  27. *
  28. * Would be converted to:
  29. *
  30. * [01][00][00][30][00][00][00][00]
  31. * (Left Shift modifier bit + "1" key)
  32. *
  33. * As long as it's in the size range, the upper level
  34. * drivers don't particularly care if there are in-band
  35. * 0-valued keys, so they don't stop parsing.
  36. */
  37. while (--idx > 1) {
  38. if (data[idx] < 0xE0 || data[idx] > 0xE7)
  39. continue;
  40. data[0] |= (1 << (data[idx] - 0xE0));
  41. data[idx] = 0;
  42. }
  43. hid_report_raw_event(hid, HID_INPUT_REPORT, data, size, 0);
  44. return 1;
  45. default: /* unknown report */
  46. /* Unknown report type; pass upstream */
  47. hid_info(hid, "unknown report type %d\n", report->id);
  48. break;
  49. }
  50. return 0;
  51. }
  52. static const struct hid_device_id px_devices[] = {
  53. { HID_USB_DEVICE(USB_VENDOR_ID_PRIMAX, USB_DEVICE_ID_PRIMAX_KEYBOARD) },
  54. { }
  55. };
  56. MODULE_DEVICE_TABLE(hid, px_devices);
  57. static struct hid_driver px_driver = {
  58. .name = "primax",
  59. .id_table = px_devices,
  60. .raw_event = px_raw_event,
  61. };
  62. module_hid_driver(px_driver);
  63. MODULE_AUTHOR("Terry Lambert <[email protected]>");
  64. MODULE_LICENSE("GPL");