hid-belkin.c 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. * HID driver for some belkin "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. #define BELKIN_HIDDEV 0x01
  21. #define BELKIN_WKBD 0x02
  22. #define belkin_map_key_clear(c) hid_map_usage_clear(hi, usage, bit, max, \
  23. EV_KEY, (c))
  24. static int belkin_input_mapping(struct hid_device *hdev, struct hid_input *hi,
  25. struct hid_field *field, struct hid_usage *usage,
  26. unsigned long **bit, int *max)
  27. {
  28. unsigned long quirks = (unsigned long)hid_get_drvdata(hdev);
  29. if ((usage->hid & HID_USAGE_PAGE) != HID_UP_CONSUMER ||
  30. !(quirks & BELKIN_WKBD))
  31. return 0;
  32. switch (usage->hid & HID_USAGE) {
  33. case 0x03a: belkin_map_key_clear(KEY_SOUND); break;
  34. case 0x03b: belkin_map_key_clear(KEY_CAMERA); break;
  35. case 0x03c: belkin_map_key_clear(KEY_DOCUMENTS); break;
  36. default:
  37. return 0;
  38. }
  39. return 1;
  40. }
  41. static int belkin_probe(struct hid_device *hdev, const struct hid_device_id *id)
  42. {
  43. unsigned long quirks = id->driver_data;
  44. int ret;
  45. hid_set_drvdata(hdev, (void *)quirks);
  46. ret = hid_parse(hdev);
  47. if (ret) {
  48. hid_err(hdev, "parse failed\n");
  49. goto err_free;
  50. }
  51. ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT |
  52. ((quirks & BELKIN_HIDDEV) ? HID_CONNECT_HIDDEV_FORCE : 0));
  53. if (ret) {
  54. hid_err(hdev, "hw start failed\n");
  55. goto err_free;
  56. }
  57. return 0;
  58. err_free:
  59. return ret;
  60. }
  61. static const struct hid_device_id belkin_devices[] = {
  62. { HID_USB_DEVICE(USB_VENDOR_ID_BELKIN, USB_DEVICE_ID_FLIP_KVM),
  63. .driver_data = BELKIN_HIDDEV },
  64. { HID_USB_DEVICE(USB_VENDOR_ID_LABTEC, USB_DEVICE_ID_LABTEC_WIRELESS_KEYBOARD),
  65. .driver_data = BELKIN_WKBD },
  66. { }
  67. };
  68. MODULE_DEVICE_TABLE(hid, belkin_devices);
  69. static struct hid_driver belkin_driver = {
  70. .name = "belkin",
  71. .id_table = belkin_devices,
  72. .input_mapping = belkin_input_mapping,
  73. .probe = belkin_probe,
  74. };
  75. module_hid_driver(belkin_driver);
  76. MODULE_LICENSE("GPL");