hid-cherry.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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) 2008 Jiri Slaby
  9. */
  10. /*
  11. * This program is free software; you can redistribute it and/or modify it
  12. * under the terms of the GNU General Public License as published by the Free
  13. * Software Foundation; either version 2 of the License, or (at your option)
  14. * any later version.
  15. */
  16. #include <linux/device.h>
  17. #include <linux/hid.h>
  18. #include <linux/module.h>
  19. #include "hid-ids.h"
  20. /*
  21. * Cherry Cymotion keyboard have an invalid HID report descriptor,
  22. * that needs fixing before we can parse it.
  23. */
  24. static __u8 *ch_report_fixup(struct hid_device *hdev, __u8 *rdesc,
  25. unsigned int *rsize)
  26. {
  27. if (*rsize >= 18 && rdesc[11] == 0x3c && rdesc[12] == 0x02) {
  28. hid_info(hdev, "fixing up Cherry Cymotion report descriptor\n");
  29. rdesc[11] = rdesc[16] = 0xff;
  30. rdesc[12] = rdesc[17] = 0x03;
  31. }
  32. return rdesc;
  33. }
  34. #define ch_map_key_clear(c) hid_map_usage_clear(hi, usage, bit, max, \
  35. EV_KEY, (c))
  36. static int ch_input_mapping(struct hid_device *hdev, struct hid_input *hi,
  37. struct hid_field *field, struct hid_usage *usage,
  38. unsigned long **bit, int *max)
  39. {
  40. if ((usage->hid & HID_USAGE_PAGE) != HID_UP_CONSUMER)
  41. return 0;
  42. switch (usage->hid & HID_USAGE) {
  43. case 0x301: ch_map_key_clear(KEY_PROG1); break;
  44. case 0x302: ch_map_key_clear(KEY_PROG2); break;
  45. case 0x303: ch_map_key_clear(KEY_PROG3); break;
  46. default:
  47. return 0;
  48. }
  49. return 1;
  50. }
  51. static const struct hid_device_id ch_devices[] = {
  52. { HID_USB_DEVICE(USB_VENDOR_ID_CHERRY, USB_DEVICE_ID_CHERRY_CYMOTION) },
  53. { HID_USB_DEVICE(USB_VENDOR_ID_CHERRY, USB_DEVICE_ID_CHERRY_CYMOTION_SOLAR) },
  54. { }
  55. };
  56. MODULE_DEVICE_TABLE(hid, ch_devices);
  57. static struct hid_driver ch_driver = {
  58. .name = "cherry",
  59. .id_table = ch_devices,
  60. .report_fixup = ch_report_fixup,
  61. .input_mapping = ch_input_mapping,
  62. };
  63. module_hid_driver(ch_driver);
  64. MODULE_LICENSE("GPL");