xsens_mt.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * Xsens MT USB driver
  3. *
  4. * Copyright (C) 2013 Xsens <info@xsens.com>
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License version
  8. * 2 as published by the Free Software Foundation.
  9. */
  10. #include <linux/kernel.h>
  11. #include <linux/tty.h>
  12. #include <linux/module.h>
  13. #include <linux/usb.h>
  14. #include <linux/usb/serial.h>
  15. #include <linux/uaccess.h>
  16. #define XSENS_VID 0x2639
  17. #define MTi_10_IMU_PID 0x0001
  18. #define MTi_20_VRU_PID 0x0002
  19. #define MTi_30_AHRS_PID 0x0003
  20. #define MTi_100_IMU_PID 0x0011
  21. #define MTi_200_VRU_PID 0x0012
  22. #define MTi_300_AHRS_PID 0x0013
  23. #define MTi_G_700_GPS_INS_PID 0x0017
  24. static const struct usb_device_id id_table[] = {
  25. { USB_DEVICE(XSENS_VID, MTi_10_IMU_PID) },
  26. { USB_DEVICE(XSENS_VID, MTi_20_VRU_PID) },
  27. { USB_DEVICE(XSENS_VID, MTi_30_AHRS_PID) },
  28. { USB_DEVICE(XSENS_VID, MTi_100_IMU_PID) },
  29. { USB_DEVICE(XSENS_VID, MTi_200_VRU_PID) },
  30. { USB_DEVICE(XSENS_VID, MTi_300_AHRS_PID) },
  31. { USB_DEVICE(XSENS_VID, MTi_G_700_GPS_INS_PID) },
  32. { },
  33. };
  34. MODULE_DEVICE_TABLE(usb, id_table);
  35. static int has_required_endpoints(const struct usb_host_interface *interface)
  36. {
  37. __u8 i;
  38. int has_bulk_in = 0;
  39. int has_bulk_out = 0;
  40. for (i = 0; i < interface->desc.bNumEndpoints; ++i) {
  41. if (usb_endpoint_is_bulk_in(&interface->endpoint[i].desc))
  42. has_bulk_in = 1;
  43. else if (usb_endpoint_is_bulk_out(&interface->endpoint[i].desc))
  44. has_bulk_out = 1;
  45. }
  46. return has_bulk_in && has_bulk_out;
  47. }
  48. static int xsens_mt_probe(struct usb_serial *serial,
  49. const struct usb_device_id *id)
  50. {
  51. if (!has_required_endpoints(serial->interface->cur_altsetting))
  52. return -ENODEV;
  53. return 0;
  54. }
  55. static struct usb_serial_driver xsens_mt_device = {
  56. .driver = {
  57. .owner = THIS_MODULE,
  58. .name = "xsens_mt",
  59. },
  60. .id_table = id_table,
  61. .num_ports = 1,
  62. .probe = xsens_mt_probe,
  63. };
  64. static struct usb_serial_driver * const serial_drivers[] = {
  65. &xsens_mt_device, NULL
  66. };
  67. module_usb_serial_driver(serial_drivers, id_table);
  68. MODULE_LICENSE("GPL");