hid-cherry.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * HID driver for some cherry "special" devices
  3. *
  4. * Copyright (c) 1999 Andreas Gal
  5. * Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz>
  6. * Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc
  7. * Copyright (c) 2006-2007 Jiri Kosina
  8. * Copyright (c) 2007 Paul Walmsley
  9. * Copyright (c) 2008 Jiri Slaby
  10. */
  11. /*
  12. * This program is free software; you can redistribute it and/or modify it
  13. * under the terms of the GNU General Public License as published by the Free
  14. * Software Foundation; either version 2 of the License, or (at your option)
  15. * any later version.
  16. */
  17. #include <linux/device.h>
  18. #include <linux/hid.h>
  19. #include <linux/module.h>
  20. #include "hid-ids.h"
  21. /*
  22. * Cherry Cymotion keyboard have an invalid HID report descriptor,
  23. * that needs fixing before we can parse it.
  24. */
  25. static __u8 *ch_report_fixup(struct hid_device *hdev, __u8 *rdesc,
  26. unsigned int *rsize)
  27. {
  28. if (*rsize >= 17 && rdesc[11] == 0x3c && rdesc[12] == 0x02) {
  29. hid_info(hdev, "fixing up Cherry Cymotion report descriptor\n");
  30. rdesc[11] = rdesc[16] = 0xff;
  31. rdesc[12] = rdesc[17] = 0x03;
  32. }
  33. return rdesc;
  34. }
  35. #define ch_map_key_clear(c) hid_map_usage_clear(hi, usage, bit, max, \
  36. EV_KEY, (c))
  37. static int ch_input_mapping(struct hid_device *hdev, struct hid_input *hi,
  38. struct hid_field *field, struct hid_usage *usage,
  39. unsigned long **bit, int *max)
  40. {
  41. if ((usage->hid & HID_USAGE_PAGE) != HID_UP_CONSUMER)
  42. return 0;
  43. switch (usage->hid & HID_USAGE) {
  44. case 0x301: ch_map_key_clear(KEY_PROG1); break;
  45. case 0x302: ch_map_key_clear(KEY_PROG2); break;
  46. case 0x303: ch_map_key_clear(KEY_PROG3); break;
  47. default:
  48. return 0;
  49. }
  50. return 1;
  51. }
  52. static const struct hid_device_id ch_devices[] = {
  53. { HID_USB_DEVICE(USB_VENDOR_ID_CHERRY, USB_DEVICE_ID_CHERRY_CYMOTION) },
  54. { HID_USB_DEVICE(USB_VENDOR_ID_CHERRY, USB_DEVICE_ID_CHERRY_CYMOTION_SOLAR) },
  55. { }
  56. };
  57. MODULE_DEVICE_TABLE(hid, ch_devices);
  58. static struct hid_driver ch_driver = {
  59. .name = "cherry",
  60. .id_table = ch_devices,
  61. .report_fixup = ch_report_fixup,
  62. .input_mapping = ch_input_mapping,
  63. };
  64. static int __init ch_init(void)
  65. {
  66. return hid_register_driver(&ch_driver);
  67. }
  68. static void __exit ch_exit(void)
  69. {
  70. hid_unregister_driver(&ch_driver);
  71. }
  72. module_init(ch_init);
  73. module_exit(ch_exit);
  74. MODULE_LICENSE("GPL");