hid-sunplus.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * HID driver for some sunplus "special" devices
  4. *
  5. * Copyright (c) 1999 Andreas Gal
  6. * Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz>
  7. * Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> 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. static __u8 *sp_report_fixup(struct hid_device *hdev, __u8 *rdesc,
  18. unsigned int *rsize)
  19. {
  20. if (*rsize >= 112 && rdesc[104] == 0x26 && rdesc[105] == 0x80 &&
  21. rdesc[106] == 0x03) {
  22. hid_info(hdev, "fixing up Sunplus Wireless Desktop report descriptor\n");
  23. rdesc[105] = rdesc[110] = 0x03;
  24. rdesc[106] = rdesc[111] = 0x21;
  25. }
  26. return rdesc;
  27. }
  28. #define sp_map_key_clear(c) hid_map_usage_clear(hi, usage, bit, max, \
  29. EV_KEY, (c))
  30. static int sp_input_mapping(struct hid_device *hdev, struct hid_input *hi,
  31. struct hid_field *field, struct hid_usage *usage,
  32. unsigned long **bit, int *max)
  33. {
  34. if ((usage->hid & HID_USAGE_PAGE) != HID_UP_CONSUMER)
  35. return 0;
  36. switch (usage->hid & HID_USAGE) {
  37. case 0x2003: sp_map_key_clear(KEY_ZOOMIN); break;
  38. case 0x2103: sp_map_key_clear(KEY_ZOOMOUT); break;
  39. default:
  40. return 0;
  41. }
  42. return 1;
  43. }
  44. static const struct hid_device_id sp_devices[] = {
  45. { HID_USB_DEVICE(USB_VENDOR_ID_SUNPLUS, USB_DEVICE_ID_SUNPLUS_WDESKTOP) },
  46. { }
  47. };
  48. MODULE_DEVICE_TABLE(hid, sp_devices);
  49. static struct hid_driver sp_driver = {
  50. .name = "sunplus",
  51. .id_table = sp_devices,
  52. .report_fixup = sp_report_fixup,
  53. .input_mapping = sp_input_mapping,
  54. };
  55. module_hid_driver(sp_driver);
  56. MODULE_LICENSE("GPL");