hid-cherry.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * HID driver for some cherry "special" devices
  4. *
  5. * Copyright (c) 1999 Andreas Gal
  6. * Copyright (c) 2000-2005 Vojtech Pavlik <[email protected]>
  7. * Copyright (c) 2005 Michael Haboustak <[email protected]> for Concept2, Inc
  8. * Copyright (c) 2006-2007 Jiri Kosina
  9. * Copyright (c) 2008 Jiri Slaby
  10. */
  11. /*
  12. */
  13. #include <linux/device.h>
  14. #include <linux/hid.h>
  15. #include <linux/module.h>
  16. #include "hid-ids.h"
  17. /*
  18. * Cherry Cymotion keyboard have an invalid HID report descriptor,
  19. * that needs fixing before we can parse it.
  20. */
  21. static __u8 *ch_report_fixup(struct hid_device *hdev, __u8 *rdesc,
  22. unsigned int *rsize)
  23. {
  24. if (*rsize >= 18 && rdesc[11] == 0x3c && rdesc[12] == 0x02) {
  25. hid_info(hdev, "fixing up Cherry Cymotion report descriptor\n");
  26. rdesc[11] = rdesc[16] = 0xff;
  27. rdesc[12] = rdesc[17] = 0x03;
  28. }
  29. return rdesc;
  30. }
  31. #define ch_map_key_clear(c) hid_map_usage_clear(hi, usage, bit, max, \
  32. EV_KEY, (c))
  33. static int ch_input_mapping(struct hid_device *hdev, struct hid_input *hi,
  34. struct hid_field *field, struct hid_usage *usage,
  35. unsigned long **bit, int *max)
  36. {
  37. if ((usage->hid & HID_USAGE_PAGE) != HID_UP_CONSUMER)
  38. return 0;
  39. switch (usage->hid & HID_USAGE) {
  40. case 0x301: ch_map_key_clear(KEY_PROG1); break;
  41. case 0x302: ch_map_key_clear(KEY_PROG2); break;
  42. case 0x303: ch_map_key_clear(KEY_PROG3); break;
  43. default:
  44. return 0;
  45. }
  46. return 1;
  47. }
  48. static const struct hid_device_id ch_devices[] = {
  49. { HID_USB_DEVICE(USB_VENDOR_ID_CHERRY, USB_DEVICE_ID_CHERRY_CYMOTION) },
  50. { HID_USB_DEVICE(USB_VENDOR_ID_CHERRY, USB_DEVICE_ID_CHERRY_CYMOTION_SOLAR) },
  51. { }
  52. };
  53. MODULE_DEVICE_TABLE(hid, ch_devices);
  54. static struct hid_driver ch_driver = {
  55. .name = "cherry",
  56. .id_table = ch_devices,
  57. .report_fixup = ch_report_fixup,
  58. .input_mapping = ch_input_mapping,
  59. };
  60. module_hid_driver(ch_driver);
  61. MODULE_LICENSE("GPL");