Frans Klaver | 59e931c4 | 2013-01-25 17:05:44 +0100 | [diff] [blame] | 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 | |
| 11 | #include <linux/kernel.h> |
Frans Klaver | 59e931c4 | 2013-01-25 17:05:44 +0100 | [diff] [blame] | 12 | #include <linux/tty.h> |
| 13 | #include <linux/module.h> |
| 14 | #include <linux/usb.h> |
| 15 | #include <linux/usb/serial.h> |
| 16 | #include <linux/uaccess.h> |
| 17 | |
| 18 | #define XSENS_VID 0x2639 |
| 19 | |
| 20 | #define MTi_10_IMU_PID 0x0001 |
| 21 | #define MTi_20_VRU_PID 0x0002 |
| 22 | #define MTi_30_AHRS_PID 0x0003 |
| 23 | |
| 24 | #define MTi_100_IMU_PID 0x0011 |
| 25 | #define MTi_200_VRU_PID 0x0012 |
| 26 | #define MTi_300_AHRS_PID 0x0013 |
| 27 | |
| 28 | #define MTi_G_700_GPS_INS_PID 0x0017 |
| 29 | |
| 30 | static const struct usb_device_id id_table[] = { |
| 31 | { USB_DEVICE(XSENS_VID, MTi_10_IMU_PID) }, |
| 32 | { USB_DEVICE(XSENS_VID, MTi_20_VRU_PID) }, |
| 33 | { USB_DEVICE(XSENS_VID, MTi_30_AHRS_PID) }, |
| 34 | |
| 35 | { USB_DEVICE(XSENS_VID, MTi_100_IMU_PID) }, |
| 36 | { USB_DEVICE(XSENS_VID, MTi_200_VRU_PID) }, |
| 37 | { USB_DEVICE(XSENS_VID, MTi_300_AHRS_PID) }, |
| 38 | |
| 39 | { USB_DEVICE(XSENS_VID, MTi_G_700_GPS_INS_PID) }, |
| 40 | { }, |
| 41 | }; |
| 42 | MODULE_DEVICE_TABLE(usb, id_table); |
| 43 | |
| 44 | static int has_required_endpoints(const struct usb_host_interface *interface) |
| 45 | { |
| 46 | __u8 i; |
| 47 | int has_bulk_in = 0; |
| 48 | int has_bulk_out = 0; |
| 49 | |
| 50 | for (i = 0; i < interface->desc.bNumEndpoints; ++i) { |
| 51 | if (usb_endpoint_is_bulk_in(&interface->endpoint[i].desc)) |
| 52 | has_bulk_in = 1; |
| 53 | else if (usb_endpoint_is_bulk_out(&interface->endpoint[i].desc)) |
| 54 | has_bulk_out = 1; |
| 55 | } |
| 56 | |
| 57 | return has_bulk_in && has_bulk_out; |
| 58 | } |
| 59 | |
| 60 | static int xsens_mt_probe(struct usb_serial *serial, |
| 61 | const struct usb_device_id *id) |
| 62 | { |
| 63 | if (!has_required_endpoints(serial->interface->cur_altsetting)) |
| 64 | return -ENODEV; |
| 65 | return 0; |
| 66 | } |
| 67 | |
| 68 | static struct usb_serial_driver xsens_mt_device = { |
| 69 | .driver = { |
| 70 | .owner = THIS_MODULE, |
| 71 | .name = "xsens_mt", |
| 72 | }, |
| 73 | .id_table = id_table, |
| 74 | .num_ports = 1, |
| 75 | |
| 76 | .probe = xsens_mt_probe, |
| 77 | }; |
| 78 | |
| 79 | static struct usb_serial_driver * const serial_drivers[] = { |
| 80 | &xsens_mt_device, NULL |
| 81 | }; |
| 82 | |
| 83 | module_usb_serial_driver(serial_drivers, id_table); |
| 84 | |
| 85 | MODULE_LICENSE("GPL"); |