hid-elo.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /*
  2. * HID driver for ELO usb touchscreen 4000/4500
  3. *
  4. * Copyright (c) 2013 Jiri Slaby
  5. *
  6. * Data parsing taken from elousb driver by Vojtech Pavlik.
  7. *
  8. * This driver is licensed under the terms of GPLv2.
  9. */
  10. #include <linux/hid.h>
  11. #include <linux/input.h>
  12. #include <linux/module.h>
  13. #include "hid-ids.h"
  14. static void elo_input_configured(struct hid_device *hdev,
  15. struct hid_input *hidinput)
  16. {
  17. struct input_dev *input = hidinput->input;
  18. set_bit(BTN_TOUCH, input->keybit);
  19. set_bit(ABS_PRESSURE, input->absbit);
  20. input_set_abs_params(input, ABS_PRESSURE, 0, 256, 0, 0);
  21. }
  22. static void elo_process_data(struct input_dev *input, const u8 *data, int size)
  23. {
  24. int press;
  25. input_report_abs(input, ABS_X, (data[3] << 8) | data[2]);
  26. input_report_abs(input, ABS_Y, (data[5] << 8) | data[4]);
  27. press = 0;
  28. if (data[1] & 0x80)
  29. press = (data[7] << 8) | data[6];
  30. input_report_abs(input, ABS_PRESSURE, press);
  31. if (data[1] & 0x03) {
  32. input_report_key(input, BTN_TOUCH, 1);
  33. input_sync(input);
  34. }
  35. if (data[1] & 0x04)
  36. input_report_key(input, BTN_TOUCH, 0);
  37. input_sync(input);
  38. }
  39. static int elo_raw_event(struct hid_device *hdev, struct hid_report *report,
  40. u8 *data, int size)
  41. {
  42. struct hid_input *hidinput;
  43. if (!(hdev->claimed & HID_CLAIMED_INPUT) || list_empty(&hdev->inputs))
  44. return 0;
  45. hidinput = list_first_entry(&hdev->inputs, struct hid_input, list);
  46. switch (report->id) {
  47. case 0:
  48. if (data[0] == 'T') { /* Mandatory ELO packet marker */
  49. elo_process_data(hidinput->input, data, size);
  50. return 1;
  51. }
  52. break;
  53. default: /* unknown report */
  54. /* Unknown report type; pass upstream */
  55. hid_info(hdev, "unknown report type %d\n", report->id);
  56. break;
  57. }
  58. return 0;
  59. }
  60. static int elo_probe(struct hid_device *hdev, const struct hid_device_id *id)
  61. {
  62. int ret;
  63. ret = hid_parse(hdev);
  64. if (ret) {
  65. hid_err(hdev, "parse failed\n");
  66. goto err_free;
  67. }
  68. ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
  69. if (ret) {
  70. hid_err(hdev, "hw start failed\n");
  71. goto err_free;
  72. }
  73. return 0;
  74. err_free:
  75. return ret;
  76. }
  77. static void elo_remove(struct hid_device *hdev)
  78. {
  79. hid_hw_stop(hdev);
  80. }
  81. static const struct hid_device_id elo_devices[] = {
  82. { HID_USB_DEVICE(USB_VENDOR_ID_ELO, 0x0009), },
  83. { HID_USB_DEVICE(USB_VENDOR_ID_ELO, 0x0030), },
  84. { }
  85. };
  86. MODULE_DEVICE_TABLE(hid, elo_devices);
  87. static struct hid_driver elo_driver = {
  88. .name = "elo",
  89. .id_table = elo_devices,
  90. .probe = elo_probe,
  91. .remove = elo_remove,
  92. .raw_event = elo_raw_event,
  93. .input_configured = elo_input_configured,
  94. };
  95. static int __init elo_driver_init(void)
  96. {
  97. return hid_register_driver(&elo_driver);
  98. }
  99. module_init(elo_driver_init);
  100. static void __exit elo_driver_exit(void)
  101. {
  102. hid_unregister_driver(&elo_driver);
  103. }
  104. module_exit(elo_driver_exit);
  105. MODULE_AUTHOR("Jiri Slaby <jslaby@suse.cz>");
  106. MODULE_LICENSE("GPL");