hid-belkin.c 2.6 KB

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