hid-kensington.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. * HID driver for Kensigton Slimblade Trackball
  3. *
  4. * Copyright (c) 2009 Jiri Kosina
  5. */
  6. /*
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License as published by the Free
  9. * Software Foundation; either version 2 of the License, or (at your option)
  10. * any later version.
  11. */
  12. #include <linux/device.h>
  13. #include <linux/input.h>
  14. #include <linux/hid.h>
  15. #include <linux/module.h>
  16. #include "hid-ids.h"
  17. #define ks_map_key(c) hid_map_usage(hi, usage, bit, max, EV_KEY, (c))
  18. static int ks_input_mapping(struct hid_device *hdev, struct hid_input *hi,
  19. struct hid_field *field, struct hid_usage *usage,
  20. unsigned long **bit, int *max)
  21. {
  22. if ((usage->hid & HID_USAGE_PAGE) != HID_UP_MSVENDOR)
  23. return 0;
  24. switch (usage->hid & HID_USAGE) {
  25. case 0x01: ks_map_key(BTN_MIDDLE); break;
  26. case 0x02: ks_map_key(BTN_SIDE); break;
  27. default:
  28. return 0;
  29. }
  30. return 1;
  31. }
  32. static const struct hid_device_id ks_devices[] = {
  33. { HID_USB_DEVICE(USB_VENDOR_ID_KENSINGTON, USB_DEVICE_ID_KS_SLIMBLADE) },
  34. { }
  35. };
  36. MODULE_DEVICE_TABLE(hid, ks_devices);
  37. static struct hid_driver ks_driver = {
  38. .name = "kensington",
  39. .id_table = ks_devices,
  40. .input_mapping = ks_input_mapping,
  41. };
  42. static int __init ks_init(void)
  43. {
  44. return hid_register_driver(&ks_driver);
  45. }
  46. static void __exit ks_exit(void)
  47. {
  48. hid_unregister_driver(&ks_driver);
  49. }
  50. module_init(ks_init);
  51. module_exit(ks_exit);
  52. MODULE_LICENSE("GPL");