|
| 1 | +/* |
| 2 | + * u3v.h: Driver for USB3 Vision(TM) class devices |
| 3 | + * |
| 4 | + * (C) Copyright 2014 National Instruments Corp. |
| 5 | + * Authors: Katie Ensign <[email protected]>, |
| 6 | + * Jared Jenson <[email protected]> |
| 7 | + * |
| 8 | + * The "USB3 Vision" name and logo are trademarks of the AIA and may not |
| 9 | + * be used without the authorization of the AIA <www.visiononline.org> |
| 10 | + * |
| 11 | + * Anyone wishing to develop, manufacture, or sell private labeled |
| 12 | + * compliant product for commercial purposes or to develop compliant |
| 13 | + * software for distribution must obtain a license to use the USB3 |
| 14 | + * Vision standard and the USB3 Vision name and logo from the AIA. |
| 15 | + * All products (including software) must be registered with the AIA and |
| 16 | + * must be tested for compliancy with the standard. |
| 17 | + * |
| 18 | + * This program is free software; you can redistribute it and/or |
| 19 | + * modify it under the terms of the GNU General Public License |
| 20 | + * as published by the Free Software Foundation; version 2 |
| 21 | + * of the License, or (at your option) any later version. |
| 22 | + * |
| 23 | + * This program is distributed in the hope that it will be useful, |
| 24 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 25 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 26 | + * GNU General Public License for more details. |
| 27 | + * |
| 28 | + * You should have received a copy of the GNU General Public License |
| 29 | + * along with this program; if not, write to the Free Software |
| 30 | + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 31 | + */ |
| 32 | + |
| 33 | +#ifndef _U3V_H_ |
| 34 | +#define _U3V_H_ |
| 35 | + |
| 36 | +/* |
| 37 | + * pr_fmt has to be redefined prior to including linux/kernel.h to prevent |
| 38 | + * a compiler warning for its redefinition |
| 39 | + */ |
| 40 | +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 41 | + |
| 42 | +#include <linux/ioctl.h> |
| 43 | +#include <linux/usb.h> |
| 44 | +#include <linux/kernel.h> |
| 45 | +#include <linux/kref.h> |
| 46 | + |
| 47 | + |
| 48 | +/* General device info */ |
| 49 | +#define DRIVER_DESC "USB3 Vision Driver" |
| 50 | +#define U3V_DEVICE_CLASS 0xEF |
| 51 | +#define U3V_DEVICE_SUBCLASS 0x02 |
| 52 | +#define U3V_DEVICE_PROTOCOL 0x01 |
| 53 | +#define U3V_INTERFACE_CLASS 0xEF |
| 54 | +#define U3V_INTERFACE_SUBCLASS 0x05 |
| 55 | +#define U3V_INTERFACE_PROTOCOL_CONTROL 0x00 |
| 56 | +#define U3V_INTERFACE_PROTOCOL_EVENT 0x01 |
| 57 | +#define U3V_INTERFACE_PROTOCOL_STREAM 0x02 |
| 58 | +#define U3V_INTERFACE 0x24 |
| 59 | +#define U3V_DEVICEINFO 0x01 |
| 60 | +#define MIN_U3V_INFO_LENGTH 20 |
| 61 | +#define U3V_MINOR_BASE 208 |
| 62 | +#define U3V_MAX_STR 64 |
| 63 | +#define U3V_REQUEST_ACK 0x4000 |
| 64 | +#define U3V_TIMEOUT 5000 |
| 65 | +#define U3V_DEV_DISCONNECTED 1 |
| 66 | + |
| 67 | + |
| 68 | +struct u3v_interface_info { |
| 69 | + u8 idx; |
| 70 | + struct usb_endpoint_descriptor *bulk_in; |
| 71 | + struct usb_endpoint_descriptor *bulk_out; |
| 72 | + struct mutex interface_lock; |
| 73 | + struct mutex ioctl_count_lock; |
| 74 | + int ioctl_count; |
| 75 | + struct completion ioctl_complete; |
| 76 | + void *interface_ptr; |
| 77 | +}; |
| 78 | + |
| 79 | + |
| 80 | +/* |
| 81 | + * A copy of this structure exists for each U3V device to contain its |
| 82 | + * private data. |
| 83 | + */ |
| 84 | +struct u3v_device { |
| 85 | + struct usb_device *udev; |
| 86 | + struct usb_interface *intf; |
| 87 | + struct device *device; |
| 88 | + struct kref kref; |
| 89 | + struct u3v_device_info *u3v_info; /* device attributes */ |
| 90 | + struct usb_driver *u3v_driver; |
| 91 | + int device_state; |
| 92 | + atomic_t device_available; |
| 93 | + bool stalling_disabled; |
| 94 | + bool device_connected; |
| 95 | + struct u3v_interface_info control_info; |
| 96 | + struct u3v_interface_info event_info; |
| 97 | + struct u3v_interface_info stream_info; |
| 98 | +}; |
| 99 | + |
| 100 | + |
| 101 | +#define to_u3v_device(d) container_of(d, struct u3v_device, kref) |
| 102 | + |
| 103 | +/* |
| 104 | + * Each u3v_device contains a u3v_device_info struct to store |
| 105 | + * device attributes |
| 106 | + */ |
| 107 | +struct u3v_device_info { |
| 108 | + u32 gen_cp_version; |
| 109 | + u32 u3v_version; |
| 110 | + char device_guid[U3V_MAX_STR]; |
| 111 | + char vendor_name[U3V_MAX_STR]; |
| 112 | + char model_name[U3V_MAX_STR]; |
| 113 | + char family_name[U3V_MAX_STR]; |
| 114 | + char device_version[U3V_MAX_STR]; |
| 115 | + char manufacturer_info[U3V_MAX_STR]; |
| 116 | + char serial_number_u3v[U3V_MAX_STR]; |
| 117 | + char user_defined_name[U3V_MAX_STR]; |
| 118 | + u8 speed_support; |
| 119 | + u8 previously_initialized; |
| 120 | + u32 host_byte_alignment; |
| 121 | + u32 os_max_transfer_size; |
| 122 | + u64 sirm_addr; |
| 123 | + u32 transfer_alignment; |
| 124 | +}; |
| 125 | + |
| 126 | +/* Helper functions for interfaces */ |
| 127 | +int reset_pipe(struct u3v_device *u3v, struct u3v_interface_info *iface_info); |
| 128 | +#endif /* _U3V_H_ */ |
0 commit comments