Greg Kroah-Hartman | 5b775f6 | 2008-08-26 16:22:06 -0700 | [diff] [blame] | 1 | /** |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 2 | * drivers/usb/class/usbtmc.c - USB Test & Measurement class driver |
Greg Kroah-Hartman | 5b775f6 | 2008-08-26 16:22:06 -0700 | [diff] [blame] | 3 | * |
| 4 | * Copyright (C) 2007 Stefan Kopp, Gechingen, Germany |
| 5 | * Copyright (C) 2008 Novell, Inc. |
| 6 | * Copyright (C) 2008 Greg Kroah-Hartman <gregkh@suse.de> |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU General Public License |
| 10 | * as published by the Free Software Foundation; either version 2 |
| 11 | * of the License, or (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * The GNU General Public License is available at |
| 19 | * http://www.gnu.org/copyleft/gpl.html. |
| 20 | */ |
| 21 | |
Andy Shevchenko | f4d844c | 2013-07-15 11:59:42 +0300 | [diff] [blame] | 22 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 23 | |
Greg Kroah-Hartman | 5b775f6 | 2008-08-26 16:22:06 -0700 | [diff] [blame] | 24 | #include <linux/init.h> |
| 25 | #include <linux/module.h> |
Ilpo Järvinen | 857cc4d | 2008-10-30 13:56:47 +0200 | [diff] [blame] | 26 | #include <linux/kernel.h> |
Greg Kroah-Hartman | 5b775f6 | 2008-08-26 16:22:06 -0700 | [diff] [blame] | 27 | #include <linux/fs.h> |
| 28 | #include <linux/uaccess.h> |
| 29 | #include <linux/kref.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 30 | #include <linux/slab.h> |
Greg Kroah-Hartman | 5b775f6 | 2008-08-26 16:22:06 -0700 | [diff] [blame] | 31 | #include <linux/mutex.h> |
| 32 | #include <linux/usb.h> |
| 33 | #include <linux/usb/tmc.h> |
| 34 | |
| 35 | |
Alexandre Peixoto Ferreira | 8402db5 | 2013-04-30 00:51:50 -0500 | [diff] [blame] | 36 | #define RIGOL 1 |
| 37 | #define USBTMC_HEADER_SIZE 12 |
Greg Kroah-Hartman | 5b775f6 | 2008-08-26 16:22:06 -0700 | [diff] [blame] | 38 | #define USBTMC_MINOR_BASE 176 |
| 39 | |
| 40 | /* |
| 41 | * Size of driver internal IO buffer. Must be multiple of 4 and at least as |
| 42 | * large as wMaxPacketSize (which is usually 512 bytes). |
| 43 | */ |
| 44 | #define USBTMC_SIZE_IOBUFFER 2048 |
| 45 | |
| 46 | /* Default USB timeout (in milliseconds) */ |
Gergely Imreh | 35f76e89 | 2009-09-15 16:03:31 +0800 | [diff] [blame] | 47 | #define USBTMC_TIMEOUT 5000 |
Greg Kroah-Hartman | 5b775f6 | 2008-08-26 16:22:06 -0700 | [diff] [blame] | 48 | |
| 49 | /* |
| 50 | * Maximum number of read cycles to empty bulk in endpoint during CLEAR and |
| 51 | * ABORT_BULK_IN requests. Ends the loop if (for whatever reason) a short |
| 52 | * packet is never read. |
| 53 | */ |
| 54 | #define USBTMC_MAX_READS_TO_CLEAR_BULK_IN 100 |
| 55 | |
Németh Márton | 6ef4852 | 2010-01-10 15:33:45 +0100 | [diff] [blame] | 56 | static const struct usb_device_id usbtmc_devices[] = { |
Greg Kroah-Hartman | 5b775f6 | 2008-08-26 16:22:06 -0700 | [diff] [blame] | 57 | { USB_INTERFACE_INFO(USB_CLASS_APP_SPEC, 3, 0), }, |
Greg Kroah-Hartman | 228dd05 | 2009-03-11 13:51:42 -0700 | [diff] [blame] | 58 | { USB_INTERFACE_INFO(USB_CLASS_APP_SPEC, 3, 1), }, |
Greg Kroah-Hartman | 5b775f6 | 2008-08-26 16:22:06 -0700 | [diff] [blame] | 59 | { 0, } /* terminating entry */ |
| 60 | }; |
Greg Kroah-Hartman | 5413aa4 | 2008-12-03 16:33:09 -0800 | [diff] [blame] | 61 | MODULE_DEVICE_TABLE(usb, usbtmc_devices); |
Greg Kroah-Hartman | 5b775f6 | 2008-08-26 16:22:06 -0700 | [diff] [blame] | 62 | |
| 63 | /* |
| 64 | * This structure is the capabilities for the device |
Gergely Imreh | d0a3836 | 2009-09-07 10:47:01 +0800 | [diff] [blame] | 65 | * See section 4.2.1.8 of the USBTMC specification, |
| 66 | * and section 4.2.2 of the USBTMC usb488 subclass |
| 67 | * specification for details. |
Greg Kroah-Hartman | 5b775f6 | 2008-08-26 16:22:06 -0700 | [diff] [blame] | 68 | */ |
| 69 | struct usbtmc_dev_capabilities { |
| 70 | __u8 interface_capabilities; |
| 71 | __u8 device_capabilities; |
| 72 | __u8 usb488_interface_capabilities; |
| 73 | __u8 usb488_device_capabilities; |
| 74 | }; |
| 75 | |
| 76 | /* This structure holds private data for each USBTMC device. One copy is |
| 77 | * allocated for each USBTMC device in the driver's probe function. |
| 78 | */ |
| 79 | struct usbtmc_device_data { |
| 80 | const struct usb_device_id *id; |
| 81 | struct usb_device *usb_dev; |
| 82 | struct usb_interface *intf; |
| 83 | |
| 84 | unsigned int bulk_in; |
| 85 | unsigned int bulk_out; |
| 86 | |
| 87 | u8 bTag; |
| 88 | u8 bTag_last_write; /* needed for abort */ |
| 89 | u8 bTag_last_read; /* needed for abort */ |
| 90 | |
Alexandre Peixoto Ferreira | 8402db5 | 2013-04-30 00:51:50 -0500 | [diff] [blame] | 91 | u8 rigol_quirk; |
| 92 | |
Greg Kroah-Hartman | 5b775f6 | 2008-08-26 16:22:06 -0700 | [diff] [blame] | 93 | /* attributes from the USB TMC spec for this device */ |
| 94 | u8 TermChar; |
| 95 | bool TermCharEnabled; |
| 96 | bool auto_abort; |
| 97 | |
Oliver Neukum | 8628688 | 2009-07-02 11:36:30 +0200 | [diff] [blame] | 98 | bool zombie; /* fd of disconnected device */ |
| 99 | |
Greg Kroah-Hartman | 5b775f6 | 2008-08-26 16:22:06 -0700 | [diff] [blame] | 100 | struct usbtmc_dev_capabilities capabilities; |
| 101 | struct kref kref; |
| 102 | struct mutex io_mutex; /* only one i/o function running at a time */ |
| 103 | }; |
| 104 | #define to_usbtmc_data(d) container_of(d, struct usbtmc_device_data, kref) |
| 105 | |
Alexandre Peixoto Ferreira | 8402db5 | 2013-04-30 00:51:50 -0500 | [diff] [blame] | 106 | struct usbtmc_ID_rigol_quirk { |
| 107 | __u16 idVendor; |
| 108 | __u16 idProduct; |
| 109 | }; |
| 110 | |
| 111 | static const struct usbtmc_ID_rigol_quirk usbtmc_id_quirk[] = { |
| 112 | { 0x1ab1, 0x0588 }, |
| 113 | { 0, 0 } |
| 114 | }; |
| 115 | |
Greg Kroah-Hartman | 5b775f6 | 2008-08-26 16:22:06 -0700 | [diff] [blame] | 116 | /* Forward declarations */ |
| 117 | static struct usb_driver usbtmc_driver; |
| 118 | |
| 119 | static void usbtmc_delete(struct kref *kref) |
| 120 | { |
| 121 | struct usbtmc_device_data *data = to_usbtmc_data(kref); |
| 122 | |
| 123 | usb_put_dev(data->usb_dev); |
| 124 | kfree(data); |
| 125 | } |
| 126 | |
| 127 | static int usbtmc_open(struct inode *inode, struct file *filp) |
| 128 | { |
| 129 | struct usb_interface *intf; |
| 130 | struct usbtmc_device_data *data; |
Greg Kroah-Hartman | 5b10916 | 2009-03-10 20:42:55 -0700 | [diff] [blame] | 131 | int retval = 0; |
Greg Kroah-Hartman | 5b775f6 | 2008-08-26 16:22:06 -0700 | [diff] [blame] | 132 | |
| 133 | intf = usb_find_interface(&usbtmc_driver, iminor(inode)); |
| 134 | if (!intf) { |
Andy Shevchenko | f4d844c | 2013-07-15 11:59:42 +0300 | [diff] [blame] | 135 | pr_err("can not find device for minor %d", iminor(inode)); |
| 136 | return -ENODEV; |
Greg Kroah-Hartman | 5b775f6 | 2008-08-26 16:22:06 -0700 | [diff] [blame] | 137 | } |
| 138 | |
| 139 | data = usb_get_intfdata(intf); |
| 140 | kref_get(&data->kref); |
| 141 | |
| 142 | /* Store pointer in file structure's private data field */ |
| 143 | filp->private_data = data; |
| 144 | |
Greg Kroah-Hartman | 5b775f6 | 2008-08-26 16:22:06 -0700 | [diff] [blame] | 145 | return retval; |
| 146 | } |
| 147 | |
| 148 | static int usbtmc_release(struct inode *inode, struct file *file) |
| 149 | { |
| 150 | struct usbtmc_device_data *data = file->private_data; |
| 151 | |
| 152 | kref_put(&data->kref, usbtmc_delete); |
| 153 | return 0; |
| 154 | } |
| 155 | |
| 156 | static int usbtmc_ioctl_abort_bulk_in(struct usbtmc_device_data *data) |
| 157 | { |
Chris Malley | b361a6e | 2008-10-25 22:07:32 +0100 | [diff] [blame] | 158 | u8 *buffer; |
Greg Kroah-Hartman | 5b775f6 | 2008-08-26 16:22:06 -0700 | [diff] [blame] | 159 | struct device *dev; |
| 160 | int rv; |
| 161 | int n; |
| 162 | int actual; |
| 163 | struct usb_host_interface *current_setting; |
| 164 | int max_size; |
| 165 | |
| 166 | dev = &data->intf->dev; |
| 167 | buffer = kmalloc(USBTMC_SIZE_IOBUFFER, GFP_KERNEL); |
| 168 | if (!buffer) |
| 169 | return -ENOMEM; |
| 170 | |
| 171 | rv = usb_control_msg(data->usb_dev, |
| 172 | usb_rcvctrlpipe(data->usb_dev, 0), |
| 173 | USBTMC_REQUEST_INITIATE_ABORT_BULK_IN, |
| 174 | USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_ENDPOINT, |
| 175 | data->bTag_last_read, data->bulk_in, |
| 176 | buffer, 2, USBTMC_TIMEOUT); |
| 177 | |
| 178 | if (rv < 0) { |
| 179 | dev_err(dev, "usb_control_msg returned %d\n", rv); |
| 180 | goto exit; |
| 181 | } |
| 182 | |
| 183 | dev_dbg(dev, "INITIATE_ABORT_BULK_IN returned %x\n", buffer[0]); |
| 184 | |
| 185 | if (buffer[0] == USBTMC_STATUS_FAILED) { |
| 186 | rv = 0; |
| 187 | goto exit; |
| 188 | } |
| 189 | |
| 190 | if (buffer[0] != USBTMC_STATUS_SUCCESS) { |
| 191 | dev_err(dev, "INITIATE_ABORT_BULK_IN returned %x\n", |
| 192 | buffer[0]); |
| 193 | rv = -EPERM; |
| 194 | goto exit; |
| 195 | } |
| 196 | |
| 197 | max_size = 0; |
| 198 | current_setting = data->intf->cur_altsetting; |
| 199 | for (n = 0; n < current_setting->desc.bNumEndpoints; n++) |
| 200 | if (current_setting->endpoint[n].desc.bEndpointAddress == |
| 201 | data->bulk_in) |
Kuninori Morimoto | 29cc889 | 2011-08-23 03:12:03 -0700 | [diff] [blame] | 202 | max_size = usb_endpoint_maxp(¤t_setting->endpoint[n].desc); |
Greg Kroah-Hartman | 5b775f6 | 2008-08-26 16:22:06 -0700 | [diff] [blame] | 203 | |
| 204 | if (max_size == 0) { |
| 205 | dev_err(dev, "Couldn't get wMaxPacketSize\n"); |
| 206 | rv = -EPERM; |
| 207 | goto exit; |
| 208 | } |
| 209 | |
| 210 | dev_dbg(&data->intf->dev, "wMaxPacketSize is %d\n", max_size); |
| 211 | |
| 212 | n = 0; |
| 213 | |
| 214 | do { |
| 215 | dev_dbg(dev, "Reading from bulk in EP\n"); |
| 216 | |
| 217 | rv = usb_bulk_msg(data->usb_dev, |
| 218 | usb_rcvbulkpipe(data->usb_dev, |
| 219 | data->bulk_in), |
| 220 | buffer, USBTMC_SIZE_IOBUFFER, |
| 221 | &actual, USBTMC_TIMEOUT); |
| 222 | |
| 223 | n++; |
| 224 | |
| 225 | if (rv < 0) { |
| 226 | dev_err(dev, "usb_bulk_msg returned %d\n", rv); |
| 227 | goto exit; |
| 228 | } |
| 229 | } while ((actual == max_size) && |
| 230 | (n < USBTMC_MAX_READS_TO_CLEAR_BULK_IN)); |
| 231 | |
| 232 | if (actual == max_size) { |
| 233 | dev_err(dev, "Couldn't clear device buffer within %d cycles\n", |
| 234 | USBTMC_MAX_READS_TO_CLEAR_BULK_IN); |
| 235 | rv = -EPERM; |
| 236 | goto exit; |
| 237 | } |
| 238 | |
| 239 | n = 0; |
| 240 | |
| 241 | usbtmc_abort_bulk_in_status: |
| 242 | rv = usb_control_msg(data->usb_dev, |
| 243 | usb_rcvctrlpipe(data->usb_dev, 0), |
| 244 | USBTMC_REQUEST_CHECK_ABORT_BULK_IN_STATUS, |
| 245 | USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_ENDPOINT, |
| 246 | 0, data->bulk_in, buffer, 0x08, |
| 247 | USBTMC_TIMEOUT); |
| 248 | |
| 249 | if (rv < 0) { |
| 250 | dev_err(dev, "usb_control_msg returned %d\n", rv); |
| 251 | goto exit; |
| 252 | } |
| 253 | |
| 254 | dev_dbg(dev, "INITIATE_ABORT_BULK_IN returned %x\n", buffer[0]); |
| 255 | |
| 256 | if (buffer[0] == USBTMC_STATUS_SUCCESS) { |
| 257 | rv = 0; |
| 258 | goto exit; |
| 259 | } |
| 260 | |
| 261 | if (buffer[0] != USBTMC_STATUS_PENDING) { |
| 262 | dev_err(dev, "INITIATE_ABORT_BULK_IN returned %x\n", buffer[0]); |
| 263 | rv = -EPERM; |
| 264 | goto exit; |
| 265 | } |
| 266 | |
| 267 | if (buffer[1] == 1) |
| 268 | do { |
| 269 | dev_dbg(dev, "Reading from bulk in EP\n"); |
| 270 | |
| 271 | rv = usb_bulk_msg(data->usb_dev, |
| 272 | usb_rcvbulkpipe(data->usb_dev, |
| 273 | data->bulk_in), |
| 274 | buffer, USBTMC_SIZE_IOBUFFER, |
| 275 | &actual, USBTMC_TIMEOUT); |
| 276 | |
| 277 | n++; |
| 278 | |
| 279 | if (rv < 0) { |
| 280 | dev_err(dev, "usb_bulk_msg returned %d\n", rv); |
| 281 | goto exit; |
| 282 | } |
Maxim Nikulin | 4f1a7a3 | 2011-07-09 23:44:44 +0700 | [diff] [blame] | 283 | } while ((actual == max_size) && |
Greg Kroah-Hartman | 5b775f6 | 2008-08-26 16:22:06 -0700 | [diff] [blame] | 284 | (n < USBTMC_MAX_READS_TO_CLEAR_BULK_IN)); |
| 285 | |
| 286 | if (actual == max_size) { |
| 287 | dev_err(dev, "Couldn't clear device buffer within %d cycles\n", |
| 288 | USBTMC_MAX_READS_TO_CLEAR_BULK_IN); |
| 289 | rv = -EPERM; |
| 290 | goto exit; |
| 291 | } |
| 292 | |
| 293 | goto usbtmc_abort_bulk_in_status; |
| 294 | |
| 295 | exit: |
| 296 | kfree(buffer); |
| 297 | return rv; |
| 298 | |
| 299 | } |
| 300 | |
| 301 | static int usbtmc_ioctl_abort_bulk_out(struct usbtmc_device_data *data) |
| 302 | { |
| 303 | struct device *dev; |
| 304 | u8 *buffer; |
| 305 | int rv; |
| 306 | int n; |
| 307 | |
| 308 | dev = &data->intf->dev; |
| 309 | |
| 310 | buffer = kmalloc(8, GFP_KERNEL); |
| 311 | if (!buffer) |
| 312 | return -ENOMEM; |
| 313 | |
| 314 | rv = usb_control_msg(data->usb_dev, |
| 315 | usb_rcvctrlpipe(data->usb_dev, 0), |
| 316 | USBTMC_REQUEST_INITIATE_ABORT_BULK_OUT, |
| 317 | USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_ENDPOINT, |
| 318 | data->bTag_last_write, data->bulk_out, |
| 319 | buffer, 2, USBTMC_TIMEOUT); |
| 320 | |
| 321 | if (rv < 0) { |
| 322 | dev_err(dev, "usb_control_msg returned %d\n", rv); |
| 323 | goto exit; |
| 324 | } |
| 325 | |
| 326 | dev_dbg(dev, "INITIATE_ABORT_BULK_OUT returned %x\n", buffer[0]); |
| 327 | |
| 328 | if (buffer[0] != USBTMC_STATUS_SUCCESS) { |
| 329 | dev_err(dev, "INITIATE_ABORT_BULK_OUT returned %x\n", |
| 330 | buffer[0]); |
| 331 | rv = -EPERM; |
| 332 | goto exit; |
| 333 | } |
| 334 | |
| 335 | n = 0; |
| 336 | |
| 337 | usbtmc_abort_bulk_out_check_status: |
| 338 | rv = usb_control_msg(data->usb_dev, |
| 339 | usb_rcvctrlpipe(data->usb_dev, 0), |
| 340 | USBTMC_REQUEST_CHECK_ABORT_BULK_OUT_STATUS, |
| 341 | USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_ENDPOINT, |
| 342 | 0, data->bulk_out, buffer, 0x08, |
| 343 | USBTMC_TIMEOUT); |
| 344 | n++; |
| 345 | if (rv < 0) { |
| 346 | dev_err(dev, "usb_control_msg returned %d\n", rv); |
| 347 | goto exit; |
| 348 | } |
| 349 | |
| 350 | dev_dbg(dev, "CHECK_ABORT_BULK_OUT returned %x\n", buffer[0]); |
| 351 | |
| 352 | if (buffer[0] == USBTMC_STATUS_SUCCESS) |
| 353 | goto usbtmc_abort_bulk_out_clear_halt; |
| 354 | |
| 355 | if ((buffer[0] == USBTMC_STATUS_PENDING) && |
| 356 | (n < USBTMC_MAX_READS_TO_CLEAR_BULK_IN)) |
| 357 | goto usbtmc_abort_bulk_out_check_status; |
| 358 | |
| 359 | rv = -EPERM; |
| 360 | goto exit; |
| 361 | |
| 362 | usbtmc_abort_bulk_out_clear_halt: |
Sarah Sharp | 3342ecd | 2009-12-03 11:35:59 -0800 | [diff] [blame] | 363 | rv = usb_clear_halt(data->usb_dev, |
| 364 | usb_sndbulkpipe(data->usb_dev, data->bulk_out)); |
Greg Kroah-Hartman | 5b775f6 | 2008-08-26 16:22:06 -0700 | [diff] [blame] | 365 | |
| 366 | if (rv < 0) { |
| 367 | dev_err(dev, "usb_control_msg returned %d\n", rv); |
| 368 | goto exit; |
| 369 | } |
| 370 | rv = 0; |
| 371 | |
| 372 | exit: |
| 373 | kfree(buffer); |
| 374 | return rv; |
| 375 | } |
| 376 | |
Alexandre Peixoto Ferreira | 88d9b2b | 2013-04-30 00:51:51 -0500 | [diff] [blame] | 377 | /* |
| 378 | * Sends a REQUEST_DEV_DEP_MSG_IN message on the Bulk-IN endpoint. |
| 379 | * @transfer_size: number of bytes to request from the device. |
| 380 | * |
| 381 | * See the USBTMC specification, Table 4. |
| 382 | * |
| 383 | * Also updates bTag_last_write. |
| 384 | */ |
| 385 | static int send_request_dev_dep_msg_in(struct usbtmc_device_data *data, size_t transfer_size) |
| 386 | { |
| 387 | int retval; |
| 388 | u8 buffer[USBTMC_HEADER_SIZE]; |
| 389 | int actual; |
| 390 | |
| 391 | /* Setup IO buffer for REQUEST_DEV_DEP_MSG_IN message |
| 392 | * Refer to class specs for details |
| 393 | */ |
| 394 | buffer[0] = 2; |
| 395 | buffer[1] = data->bTag; |
Andy Shevchenko | bbf4976 | 2013-07-15 11:59:43 +0300 | [diff] [blame^] | 396 | buffer[2] = ~data->bTag; |
Alexandre Peixoto Ferreira | 88d9b2b | 2013-04-30 00:51:51 -0500 | [diff] [blame] | 397 | buffer[3] = 0; /* Reserved */ |
Andy Shevchenko | bbf4976 | 2013-07-15 11:59:43 +0300 | [diff] [blame^] | 398 | buffer[4] = transfer_size >> 0; |
| 399 | buffer[5] = transfer_size >> 8; |
| 400 | buffer[6] = transfer_size >> 16; |
| 401 | buffer[7] = transfer_size >> 24; |
Alexandre Peixoto Ferreira | 88d9b2b | 2013-04-30 00:51:51 -0500 | [diff] [blame] | 402 | buffer[8] = data->TermCharEnabled * 2; |
| 403 | /* Use term character? */ |
| 404 | buffer[9] = data->TermChar; |
| 405 | buffer[10] = 0; /* Reserved */ |
| 406 | buffer[11] = 0; /* Reserved */ |
| 407 | |
| 408 | /* Send bulk URB */ |
| 409 | retval = usb_bulk_msg(data->usb_dev, |
| 410 | usb_sndbulkpipe(data->usb_dev, |
| 411 | data->bulk_out), |
| 412 | buffer, USBTMC_HEADER_SIZE, &actual, USBTMC_TIMEOUT); |
| 413 | |
| 414 | /* Store bTag (in case we need to abort) */ |
| 415 | data->bTag_last_write = data->bTag; |
| 416 | |
| 417 | /* Increment bTag -- and increment again if zero */ |
| 418 | data->bTag++; |
| 419 | if (!data->bTag) |
Andy Shevchenko | bbf4976 | 2013-07-15 11:59:43 +0300 | [diff] [blame^] | 420 | data->bTag++; |
Alexandre Peixoto Ferreira | 88d9b2b | 2013-04-30 00:51:51 -0500 | [diff] [blame] | 421 | |
| 422 | if (retval < 0) { |
| 423 | dev_err(&data->intf->dev, "usb_bulk_msg in send_request_dev_dep_msg_in() returned %d\n", retval); |
| 424 | return retval; |
| 425 | } |
| 426 | |
| 427 | return 0; |
| 428 | } |
| 429 | |
Greg Kroah-Hartman | 5b775f6 | 2008-08-26 16:22:06 -0700 | [diff] [blame] | 430 | static ssize_t usbtmc_read(struct file *filp, char __user *buf, |
| 431 | size_t count, loff_t *f_pos) |
| 432 | { |
| 433 | struct usbtmc_device_data *data; |
| 434 | struct device *dev; |
Guus Sliepen | 665d766 | 2009-07-22 17:39:42 +0200 | [diff] [blame] | 435 | u32 n_characters; |
Greg Kroah-Hartman | 5b775f6 | 2008-08-26 16:22:06 -0700 | [diff] [blame] | 436 | u8 *buffer; |
| 437 | int actual; |
Guus Sliepen | 665d766 | 2009-07-22 17:39:42 +0200 | [diff] [blame] | 438 | size_t done; |
| 439 | size_t remaining; |
Greg Kroah-Hartman | 5b775f6 | 2008-08-26 16:22:06 -0700 | [diff] [blame] | 440 | int retval; |
Guus Sliepen | 665d766 | 2009-07-22 17:39:42 +0200 | [diff] [blame] | 441 | size_t this_part; |
Greg Kroah-Hartman | 5b775f6 | 2008-08-26 16:22:06 -0700 | [diff] [blame] | 442 | |
| 443 | /* Get pointer to private data structure */ |
| 444 | data = filp->private_data; |
| 445 | dev = &data->intf->dev; |
| 446 | |
| 447 | buffer = kmalloc(USBTMC_SIZE_IOBUFFER, GFP_KERNEL); |
| 448 | if (!buffer) |
| 449 | return -ENOMEM; |
| 450 | |
| 451 | mutex_lock(&data->io_mutex); |
Oliver Neukum | 8628688 | 2009-07-02 11:36:30 +0200 | [diff] [blame] | 452 | if (data->zombie) { |
| 453 | retval = -ENODEV; |
| 454 | goto exit; |
| 455 | } |
Greg Kroah-Hartman | 5b775f6 | 2008-08-26 16:22:06 -0700 | [diff] [blame] | 456 | |
Alexandre Peixoto Ferreira | d2ddce3 | 2013-04-30 00:51:53 -0500 | [diff] [blame] | 457 | if (data->rigol_quirk) { |
| 458 | dev_dbg(dev, "usb_bulk_msg_in: count(%zu)\n", count); |
Greg Kroah-Hartman | 5b775f6 | 2008-08-26 16:22:06 -0700 | [diff] [blame] | 459 | |
Alexandre Peixoto Ferreira | d2ddce3 | 2013-04-30 00:51:53 -0500 | [diff] [blame] | 460 | retval = send_request_dev_dep_msg_in(data, count); |
Greg Kroah-Hartman | 5b775f6 | 2008-08-26 16:22:06 -0700 | [diff] [blame] | 461 | |
Greg Kroah-Hartman | 5b775f6 | 2008-08-26 16:22:06 -0700 | [diff] [blame] | 462 | if (retval < 0) { |
Greg Kroah-Hartman | 5b775f6 | 2008-08-26 16:22:06 -0700 | [diff] [blame] | 463 | if (data->auto_abort) |
| 464 | usbtmc_ioctl_abort_bulk_out(data); |
| 465 | goto exit; |
| 466 | } |
Alexandre Peixoto Ferreira | d2ddce3 | 2013-04-30 00:51:53 -0500 | [diff] [blame] | 467 | } |
| 468 | |
| 469 | /* Loop until we have fetched everything we requested */ |
| 470 | remaining = count; |
| 471 | this_part = remaining; |
| 472 | done = 0; |
| 473 | |
| 474 | while (remaining > 0) { |
Andy Shevchenko | bbf4976 | 2013-07-15 11:59:43 +0300 | [diff] [blame^] | 475 | if (!data->rigol_quirk) { |
Alexandre Peixoto Ferreira | d2ddce3 | 2013-04-30 00:51:53 -0500 | [diff] [blame] | 476 | dev_dbg(dev, "usb_bulk_msg_in: remaining(%zu), count(%zu)\n", remaining, count); |
| 477 | |
| 478 | if (remaining > USBTMC_SIZE_IOBUFFER - USBTMC_HEADER_SIZE - 3) |
| 479 | this_part = USBTMC_SIZE_IOBUFFER - USBTMC_HEADER_SIZE - 3; |
| 480 | else |
| 481 | this_part = remaining; |
| 482 | |
| 483 | retval = send_request_dev_dep_msg_in(data, this_part); |
| 484 | if (retval < 0) { |
| 485 | dev_err(dev, "usb_bulk_msg returned %d\n", retval); |
| 486 | if (data->auto_abort) |
| 487 | usbtmc_ioctl_abort_bulk_out(data); |
| 488 | goto exit; |
| 489 | } |
| 490 | } |
Greg Kroah-Hartman | 5b775f6 | 2008-08-26 16:22:06 -0700 | [diff] [blame] | 491 | |
| 492 | /* Send bulk URB */ |
| 493 | retval = usb_bulk_msg(data->usb_dev, |
| 494 | usb_rcvbulkpipe(data->usb_dev, |
| 495 | data->bulk_in), |
| 496 | buffer, USBTMC_SIZE_IOBUFFER, &actual, |
| 497 | USBTMC_TIMEOUT); |
| 498 | |
Alexandre Peixoto Ferreira | d2ddce3 | 2013-04-30 00:51:53 -0500 | [diff] [blame] | 499 | dev_dbg(dev, "usb_bulk_msg: retval(%u), done(%zu), remaining(%zu), actual(%d)\n", retval, done, remaining, actual); |
| 500 | |
Greg Kroah-Hartman | 5b775f6 | 2008-08-26 16:22:06 -0700 | [diff] [blame] | 501 | /* Store bTag (in case we need to abort) */ |
| 502 | data->bTag_last_read = data->bTag; |
| 503 | |
| 504 | if (retval < 0) { |
Alexandre Peixoto Ferreira | d2ddce3 | 2013-04-30 00:51:53 -0500 | [diff] [blame] | 505 | dev_dbg(dev, "Unable to read data, error %d\n", retval); |
Greg Kroah-Hartman | 5b775f6 | 2008-08-26 16:22:06 -0700 | [diff] [blame] | 506 | if (data->auto_abort) |
| 507 | usbtmc_ioctl_abort_bulk_in(data); |
| 508 | goto exit; |
| 509 | } |
| 510 | |
Alexandre Peixoto Ferreira | d2ddce3 | 2013-04-30 00:51:53 -0500 | [diff] [blame] | 511 | /* Parse header in first packet */ |
Andy Shevchenko | bbf4976 | 2013-07-15 11:59:43 +0300 | [diff] [blame^] | 512 | if ((done == 0) || !data->rigol_quirk) { |
Alexandre Peixoto Ferreira | d2ddce3 | 2013-04-30 00:51:53 -0500 | [diff] [blame] | 513 | /* Sanity checks for the header */ |
| 514 | if (actual < USBTMC_HEADER_SIZE) { |
| 515 | dev_err(dev, "Device sent too small first packet: %u < %u\n", actual, USBTMC_HEADER_SIZE); |
| 516 | if (data->auto_abort) |
| 517 | usbtmc_ioctl_abort_bulk_in(data); |
| 518 | goto exit; |
| 519 | } |
Greg Kroah-Hartman | 5b775f6 | 2008-08-26 16:22:06 -0700 | [diff] [blame] | 520 | |
Alexandre Peixoto Ferreira | d2ddce3 | 2013-04-30 00:51:53 -0500 | [diff] [blame] | 521 | if (buffer[0] != 2) { |
| 522 | dev_err(dev, "Device sent reply with wrong MsgID: %u != 2\n", buffer[0]); |
| 523 | if (data->auto_abort) |
| 524 | usbtmc_ioctl_abort_bulk_in(data); |
| 525 | goto exit; |
| 526 | } |
| 527 | |
| 528 | if (buffer[1] != data->bTag_last_write) { |
| 529 | dev_err(dev, "Device sent reply with wrong bTag: %u != %u\n", buffer[1], data->bTag_last_write); |
| 530 | if (data->auto_abort) |
| 531 | usbtmc_ioctl_abort_bulk_in(data); |
| 532 | goto exit; |
| 533 | } |
| 534 | |
| 535 | /* How many characters did the instrument send? */ |
| 536 | n_characters = buffer[4] + |
| 537 | (buffer[5] << 8) + |
| 538 | (buffer[6] << 16) + |
| 539 | (buffer[7] << 24); |
| 540 | |
| 541 | if (n_characters > this_part) { |
| 542 | dev_err(dev, "Device wants to return more data than requested: %u > %zu\n", n_characters, count); |
| 543 | if (data->auto_abort) |
| 544 | usbtmc_ioctl_abort_bulk_in(data); |
| 545 | goto exit; |
| 546 | } |
| 547 | |
| 548 | /* Remove the USBTMC header */ |
| 549 | actual -= USBTMC_HEADER_SIZE; |
| 550 | |
| 551 | /* Check if the message is smaller than requested */ |
| 552 | if (data->rigol_quirk) { |
| 553 | if (remaining > n_characters) |
| 554 | remaining = n_characters; |
| 555 | /* Remove padding if it exists */ |
Andy Shevchenko | 92f78dd | 2013-07-15 11:59:40 +0300 | [diff] [blame] | 556 | if (actual > remaining) |
Alexandre Peixoto Ferreira | d2ddce3 | 2013-04-30 00:51:53 -0500 | [diff] [blame] | 557 | actual = remaining; |
| 558 | } |
| 559 | else { |
| 560 | if (this_part > n_characters) |
| 561 | this_part = n_characters; |
| 562 | /* Remove padding if it exists */ |
Andy Shevchenko | 92f78dd | 2013-07-15 11:59:40 +0300 | [diff] [blame] | 563 | if (actual > this_part) |
Alexandre Peixoto Ferreira | d2ddce3 | 2013-04-30 00:51:53 -0500 | [diff] [blame] | 564 | actual = this_part; |
| 565 | } |
| 566 | |
| 567 | dev_dbg(dev, "Bulk-IN header: N_characters(%u), bTransAttr(%u)\n", n_characters, buffer[8]); |
| 568 | |
| 569 | remaining -= actual; |
| 570 | |
| 571 | /* Terminate if end-of-message bit received from device */ |
Andy Shevchenko | bbf4976 | 2013-07-15 11:59:43 +0300 | [diff] [blame^] | 572 | if ((buffer[8] & 0x01) && (actual >= n_characters)) |
Alexandre Peixoto Ferreira | d2ddce3 | 2013-04-30 00:51:53 -0500 | [diff] [blame] | 573 | remaining = 0; |
| 574 | |
| 575 | dev_dbg(dev, "Bulk-IN header: remaining(%zu), buf(%p), buffer(%p) done(%zu)\n", remaining,buf,buffer,done); |
| 576 | |
| 577 | |
| 578 | /* Copy buffer to user space */ |
| 579 | if (copy_to_user(buf + done, &buffer[USBTMC_HEADER_SIZE], actual)) { |
| 580 | /* There must have been an addressing problem */ |
| 581 | retval = -EFAULT; |
| 582 | goto exit; |
| 583 | } |
| 584 | done += actual; |
Guus Sliepen | 665d766 | 2009-07-22 17:39:42 +0200 | [diff] [blame] | 585 | } |
Alexandre Peixoto Ferreira | d2ddce3 | 2013-04-30 00:51:53 -0500 | [diff] [blame] | 586 | else { |
Andy Shevchenko | 92f78dd | 2013-07-15 11:59:40 +0300 | [diff] [blame] | 587 | if (actual > remaining) |
Alexandre Peixoto Ferreira | d2ddce3 | 2013-04-30 00:51:53 -0500 | [diff] [blame] | 588 | actual = remaining; |
Guus Sliepen | 665d766 | 2009-07-22 17:39:42 +0200 | [diff] [blame] | 589 | |
Alexandre Peixoto Ferreira | d2ddce3 | 2013-04-30 00:51:53 -0500 | [diff] [blame] | 590 | remaining -= actual; |
| 591 | |
| 592 | dev_dbg(dev, "Bulk-IN header cont: actual(%u), done(%zu), remaining(%zu), buf(%p), buffer(%p)\n", actual, done, remaining,buf,buffer); |
| 593 | |
| 594 | /* Copy buffer to user space */ |
| 595 | if (copy_to_user(buf + done, buffer, actual)) { |
| 596 | /* There must have been an addressing problem */ |
| 597 | retval = -EFAULT; |
| 598 | goto exit; |
| 599 | } |
| 600 | done += actual; |
Guus Sliepen | 665d766 | 2009-07-22 17:39:42 +0200 | [diff] [blame] | 601 | } |
Greg Kroah-Hartman | 5b775f6 | 2008-08-26 16:22:06 -0700 | [diff] [blame] | 602 | } |
| 603 | |
| 604 | /* Update file position value */ |
| 605 | *f_pos = *f_pos + done; |
| 606 | retval = done; |
| 607 | |
| 608 | exit: |
| 609 | mutex_unlock(&data->io_mutex); |
| 610 | kfree(buffer); |
| 611 | return retval; |
| 612 | } |
| 613 | |
| 614 | static ssize_t usbtmc_write(struct file *filp, const char __user *buf, |
| 615 | size_t count, loff_t *f_pos) |
| 616 | { |
| 617 | struct usbtmc_device_data *data; |
| 618 | u8 *buffer; |
| 619 | int retval; |
| 620 | int actual; |
| 621 | unsigned long int n_bytes; |
Greg Kroah-Hartman | 5b775f6 | 2008-08-26 16:22:06 -0700 | [diff] [blame] | 622 | int remaining; |
| 623 | int done; |
| 624 | int this_part; |
| 625 | |
| 626 | data = filp->private_data; |
| 627 | |
| 628 | buffer = kmalloc(USBTMC_SIZE_IOBUFFER, GFP_KERNEL); |
| 629 | if (!buffer) |
| 630 | return -ENOMEM; |
| 631 | |
| 632 | mutex_lock(&data->io_mutex); |
Oliver Neukum | 8628688 | 2009-07-02 11:36:30 +0200 | [diff] [blame] | 633 | if (data->zombie) { |
| 634 | retval = -ENODEV; |
| 635 | goto exit; |
| 636 | } |
Greg Kroah-Hartman | 5b775f6 | 2008-08-26 16:22:06 -0700 | [diff] [blame] | 637 | |
| 638 | remaining = count; |
| 639 | done = 0; |
| 640 | |
| 641 | while (remaining > 0) { |
Alexandre Peixoto Ferreira | 50c9ba3 | 2013-04-30 00:51:54 -0500 | [diff] [blame] | 642 | if (remaining > USBTMC_SIZE_IOBUFFER - USBTMC_HEADER_SIZE) { |
| 643 | this_part = USBTMC_SIZE_IOBUFFER - USBTMC_HEADER_SIZE; |
Greg Kroah-Hartman | 5b775f6 | 2008-08-26 16:22:06 -0700 | [diff] [blame] | 644 | buffer[8] = 0; |
| 645 | } else { |
| 646 | this_part = remaining; |
| 647 | buffer[8] = 1; |
| 648 | } |
| 649 | |
| 650 | /* Setup IO buffer for DEV_DEP_MSG_OUT message */ |
| 651 | buffer[0] = 1; |
| 652 | buffer[1] = data->bTag; |
Andy Shevchenko | bbf4976 | 2013-07-15 11:59:43 +0300 | [diff] [blame^] | 653 | buffer[2] = ~data->bTag; |
Greg Kroah-Hartman | 5b775f6 | 2008-08-26 16:22:06 -0700 | [diff] [blame] | 654 | buffer[3] = 0; /* Reserved */ |
Andy Shevchenko | bbf4976 | 2013-07-15 11:59:43 +0300 | [diff] [blame^] | 655 | buffer[4] = this_part >> 0; |
| 656 | buffer[5] = this_part >> 8; |
| 657 | buffer[6] = this_part >> 16; |
| 658 | buffer[7] = this_part >> 24; |
Greg Kroah-Hartman | 5b775f6 | 2008-08-26 16:22:06 -0700 | [diff] [blame] | 659 | /* buffer[8] is set above... */ |
| 660 | buffer[9] = 0; /* Reserved */ |
| 661 | buffer[10] = 0; /* Reserved */ |
| 662 | buffer[11] = 0; /* Reserved */ |
| 663 | |
Alexandre Peixoto Ferreira | 50c9ba3 | 2013-04-30 00:51:54 -0500 | [diff] [blame] | 664 | if (copy_from_user(&buffer[USBTMC_HEADER_SIZE], buf + done, this_part)) { |
Greg Kroah-Hartman | 5b775f6 | 2008-08-26 16:22:06 -0700 | [diff] [blame] | 665 | retval = -EFAULT; |
| 666 | goto exit; |
| 667 | } |
| 668 | |
Alexandre Peixoto Ferreira | 50c9ba3 | 2013-04-30 00:51:54 -0500 | [diff] [blame] | 669 | n_bytes = roundup(USBTMC_HEADER_SIZE + this_part, 4); |
| 670 | memset(buffer + USBTMC_HEADER_SIZE + this_part, 0, n_bytes - (USBTMC_HEADER_SIZE + this_part)); |
Greg Kroah-Hartman | 5b775f6 | 2008-08-26 16:22:06 -0700 | [diff] [blame] | 671 | |
Andre Herms | ec412b9 | 2009-11-19 18:14:49 +0100 | [diff] [blame] | 672 | do { |
| 673 | retval = usb_bulk_msg(data->usb_dev, |
| 674 | usb_sndbulkpipe(data->usb_dev, |
| 675 | data->bulk_out), |
| 676 | buffer, n_bytes, |
| 677 | &actual, USBTMC_TIMEOUT); |
| 678 | if (retval != 0) |
| 679 | break; |
| 680 | n_bytes -= actual; |
| 681 | } while (n_bytes); |
Greg Kroah-Hartman | 5b775f6 | 2008-08-26 16:22:06 -0700 | [diff] [blame] | 682 | |
| 683 | data->bTag_last_write = data->bTag; |
| 684 | data->bTag++; |
| 685 | |
| 686 | if (!data->bTag) |
| 687 | data->bTag++; |
| 688 | |
| 689 | if (retval < 0) { |
| 690 | dev_err(&data->intf->dev, |
| 691 | "Unable to send data, error %d\n", retval); |
| 692 | if (data->auto_abort) |
| 693 | usbtmc_ioctl_abort_bulk_out(data); |
| 694 | goto exit; |
| 695 | } |
| 696 | |
| 697 | remaining -= this_part; |
| 698 | done += this_part; |
| 699 | } |
| 700 | |
| 701 | retval = count; |
| 702 | exit: |
| 703 | mutex_unlock(&data->io_mutex); |
| 704 | kfree(buffer); |
| 705 | return retval; |
| 706 | } |
| 707 | |
| 708 | static int usbtmc_ioctl_clear(struct usbtmc_device_data *data) |
| 709 | { |
| 710 | struct usb_host_interface *current_setting; |
| 711 | struct usb_endpoint_descriptor *desc; |
| 712 | struct device *dev; |
| 713 | u8 *buffer; |
| 714 | int rv; |
| 715 | int n; |
| 716 | int actual; |
| 717 | int max_size; |
| 718 | |
| 719 | dev = &data->intf->dev; |
| 720 | |
| 721 | dev_dbg(dev, "Sending INITIATE_CLEAR request\n"); |
| 722 | |
| 723 | buffer = kmalloc(USBTMC_SIZE_IOBUFFER, GFP_KERNEL); |
| 724 | if (!buffer) |
| 725 | return -ENOMEM; |
| 726 | |
| 727 | rv = usb_control_msg(data->usb_dev, |
| 728 | usb_rcvctrlpipe(data->usb_dev, 0), |
| 729 | USBTMC_REQUEST_INITIATE_CLEAR, |
| 730 | USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE, |
| 731 | 0, 0, buffer, 1, USBTMC_TIMEOUT); |
| 732 | if (rv < 0) { |
| 733 | dev_err(dev, "usb_control_msg returned %d\n", rv); |
| 734 | goto exit; |
| 735 | } |
| 736 | |
| 737 | dev_dbg(dev, "INITIATE_CLEAR returned %x\n", buffer[0]); |
| 738 | |
| 739 | if (buffer[0] != USBTMC_STATUS_SUCCESS) { |
| 740 | dev_err(dev, "INITIATE_CLEAR returned %x\n", buffer[0]); |
| 741 | rv = -EPERM; |
| 742 | goto exit; |
| 743 | } |
| 744 | |
| 745 | max_size = 0; |
| 746 | current_setting = data->intf->cur_altsetting; |
| 747 | for (n = 0; n < current_setting->desc.bNumEndpoints; n++) { |
| 748 | desc = ¤t_setting->endpoint[n].desc; |
| 749 | if (desc->bEndpointAddress == data->bulk_in) |
Kuninori Morimoto | 29cc889 | 2011-08-23 03:12:03 -0700 | [diff] [blame] | 750 | max_size = usb_endpoint_maxp(desc); |
Greg Kroah-Hartman | 5b775f6 | 2008-08-26 16:22:06 -0700 | [diff] [blame] | 751 | } |
| 752 | |
| 753 | if (max_size == 0) { |
| 754 | dev_err(dev, "Couldn't get wMaxPacketSize\n"); |
| 755 | rv = -EPERM; |
| 756 | goto exit; |
| 757 | } |
| 758 | |
| 759 | dev_dbg(dev, "wMaxPacketSize is %d\n", max_size); |
| 760 | |
| 761 | n = 0; |
| 762 | |
| 763 | usbtmc_clear_check_status: |
| 764 | |
| 765 | dev_dbg(dev, "Sending CHECK_CLEAR_STATUS request\n"); |
| 766 | |
| 767 | rv = usb_control_msg(data->usb_dev, |
| 768 | usb_rcvctrlpipe(data->usb_dev, 0), |
| 769 | USBTMC_REQUEST_CHECK_CLEAR_STATUS, |
| 770 | USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE, |
| 771 | 0, 0, buffer, 2, USBTMC_TIMEOUT); |
| 772 | if (rv < 0) { |
| 773 | dev_err(dev, "usb_control_msg returned %d\n", rv); |
| 774 | goto exit; |
| 775 | } |
| 776 | |
| 777 | dev_dbg(dev, "CHECK_CLEAR_STATUS returned %x\n", buffer[0]); |
| 778 | |
| 779 | if (buffer[0] == USBTMC_STATUS_SUCCESS) |
| 780 | goto usbtmc_clear_bulk_out_halt; |
| 781 | |
| 782 | if (buffer[0] != USBTMC_STATUS_PENDING) { |
| 783 | dev_err(dev, "CHECK_CLEAR_STATUS returned %x\n", buffer[0]); |
| 784 | rv = -EPERM; |
| 785 | goto exit; |
| 786 | } |
| 787 | |
| 788 | if (buffer[1] == 1) |
| 789 | do { |
| 790 | dev_dbg(dev, "Reading from bulk in EP\n"); |
| 791 | |
| 792 | rv = usb_bulk_msg(data->usb_dev, |
| 793 | usb_rcvbulkpipe(data->usb_dev, |
| 794 | data->bulk_in), |
| 795 | buffer, USBTMC_SIZE_IOBUFFER, |
| 796 | &actual, USBTMC_TIMEOUT); |
| 797 | n++; |
| 798 | |
| 799 | if (rv < 0) { |
| 800 | dev_err(dev, "usb_control_msg returned %d\n", |
| 801 | rv); |
| 802 | goto exit; |
| 803 | } |
| 804 | } while ((actual == max_size) && |
| 805 | (n < USBTMC_MAX_READS_TO_CLEAR_BULK_IN)); |
| 806 | |
| 807 | if (actual == max_size) { |
| 808 | dev_err(dev, "Couldn't clear device buffer within %d cycles\n", |
| 809 | USBTMC_MAX_READS_TO_CLEAR_BULK_IN); |
| 810 | rv = -EPERM; |
| 811 | goto exit; |
| 812 | } |
| 813 | |
| 814 | goto usbtmc_clear_check_status; |
| 815 | |
| 816 | usbtmc_clear_bulk_out_halt: |
| 817 | |
Sarah Sharp | 3342ecd | 2009-12-03 11:35:59 -0800 | [diff] [blame] | 818 | rv = usb_clear_halt(data->usb_dev, |
| 819 | usb_sndbulkpipe(data->usb_dev, data->bulk_out)); |
Greg Kroah-Hartman | 5b775f6 | 2008-08-26 16:22:06 -0700 | [diff] [blame] | 820 | if (rv < 0) { |
| 821 | dev_err(dev, "usb_control_msg returned %d\n", rv); |
| 822 | goto exit; |
| 823 | } |
| 824 | rv = 0; |
| 825 | |
| 826 | exit: |
| 827 | kfree(buffer); |
| 828 | return rv; |
| 829 | } |
| 830 | |
| 831 | static int usbtmc_ioctl_clear_out_halt(struct usbtmc_device_data *data) |
| 832 | { |
Greg Kroah-Hartman | 5b775f6 | 2008-08-26 16:22:06 -0700 | [diff] [blame] | 833 | int rv; |
| 834 | |
Sarah Sharp | 3342ecd | 2009-12-03 11:35:59 -0800 | [diff] [blame] | 835 | rv = usb_clear_halt(data->usb_dev, |
| 836 | usb_sndbulkpipe(data->usb_dev, data->bulk_out)); |
Greg Kroah-Hartman | 5b775f6 | 2008-08-26 16:22:06 -0700 | [diff] [blame] | 837 | |
| 838 | if (rv < 0) { |
| 839 | dev_err(&data->usb_dev->dev, "usb_control_msg returned %d\n", |
| 840 | rv); |
Ming Lei | ac9e59c | 2013-04-18 12:17:38 +0800 | [diff] [blame] | 841 | return rv; |
Greg Kroah-Hartman | 5b775f6 | 2008-08-26 16:22:06 -0700 | [diff] [blame] | 842 | } |
Ming Lei | ac9e59c | 2013-04-18 12:17:38 +0800 | [diff] [blame] | 843 | return 0; |
Greg Kroah-Hartman | 5b775f6 | 2008-08-26 16:22:06 -0700 | [diff] [blame] | 844 | } |
| 845 | |
| 846 | static int usbtmc_ioctl_clear_in_halt(struct usbtmc_device_data *data) |
| 847 | { |
Greg Kroah-Hartman | 5b775f6 | 2008-08-26 16:22:06 -0700 | [diff] [blame] | 848 | int rv; |
| 849 | |
Sarah Sharp | 3342ecd | 2009-12-03 11:35:59 -0800 | [diff] [blame] | 850 | rv = usb_clear_halt(data->usb_dev, |
| 851 | usb_rcvbulkpipe(data->usb_dev, data->bulk_in)); |
Greg Kroah-Hartman | 5b775f6 | 2008-08-26 16:22:06 -0700 | [diff] [blame] | 852 | |
| 853 | if (rv < 0) { |
| 854 | dev_err(&data->usb_dev->dev, "usb_control_msg returned %d\n", |
| 855 | rv); |
Ming Lei | ac9e59c | 2013-04-18 12:17:38 +0800 | [diff] [blame] | 856 | return rv; |
Greg Kroah-Hartman | 5b775f6 | 2008-08-26 16:22:06 -0700 | [diff] [blame] | 857 | } |
Ming Lei | ac9e59c | 2013-04-18 12:17:38 +0800 | [diff] [blame] | 858 | return 0; |
Greg Kroah-Hartman | 5b775f6 | 2008-08-26 16:22:06 -0700 | [diff] [blame] | 859 | } |
| 860 | |
| 861 | static int get_capabilities(struct usbtmc_device_data *data) |
| 862 | { |
| 863 | struct device *dev = &data->usb_dev->dev; |
| 864 | char *buffer; |
Oliver Neukum | ca157c4 | 2009-07-02 16:41:39 +0200 | [diff] [blame] | 865 | int rv = 0; |
Greg Kroah-Hartman | 5b775f6 | 2008-08-26 16:22:06 -0700 | [diff] [blame] | 866 | |
| 867 | buffer = kmalloc(0x18, GFP_KERNEL); |
| 868 | if (!buffer) |
| 869 | return -ENOMEM; |
| 870 | |
| 871 | rv = usb_control_msg(data->usb_dev, usb_rcvctrlpipe(data->usb_dev, 0), |
| 872 | USBTMC_REQUEST_GET_CAPABILITIES, |
| 873 | USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE, |
| 874 | 0, 0, buffer, 0x18, USBTMC_TIMEOUT); |
| 875 | if (rv < 0) { |
| 876 | dev_err(dev, "usb_control_msg returned %d\n", rv); |
Oliver Neukum | ca157c4 | 2009-07-02 16:41:39 +0200 | [diff] [blame] | 877 | goto err_out; |
Greg Kroah-Hartman | 5b775f6 | 2008-08-26 16:22:06 -0700 | [diff] [blame] | 878 | } |
| 879 | |
| 880 | dev_dbg(dev, "GET_CAPABILITIES returned %x\n", buffer[0]); |
Greg Kroah-Hartman | 5b775f6 | 2008-08-26 16:22:06 -0700 | [diff] [blame] | 881 | if (buffer[0] != USBTMC_STATUS_SUCCESS) { |
| 882 | dev_err(dev, "GET_CAPABILITIES returned %x\n", buffer[0]); |
Oliver Neukum | ca157c4 | 2009-07-02 16:41:39 +0200 | [diff] [blame] | 883 | rv = -EPERM; |
| 884 | goto err_out; |
Greg Kroah-Hartman | 5b775f6 | 2008-08-26 16:22:06 -0700 | [diff] [blame] | 885 | } |
Gergely Imreh | d0a3836 | 2009-09-07 10:47:01 +0800 | [diff] [blame] | 886 | dev_dbg(dev, "Interface capabilities are %x\n", buffer[4]); |
| 887 | dev_dbg(dev, "Device capabilities are %x\n", buffer[5]); |
| 888 | dev_dbg(dev, "USB488 interface capabilities are %x\n", buffer[14]); |
| 889 | dev_dbg(dev, "USB488 device capabilities are %x\n", buffer[15]); |
Greg Kroah-Hartman | 5b775f6 | 2008-08-26 16:22:06 -0700 | [diff] [blame] | 890 | |
| 891 | data->capabilities.interface_capabilities = buffer[4]; |
| 892 | data->capabilities.device_capabilities = buffer[5]; |
| 893 | data->capabilities.usb488_interface_capabilities = buffer[14]; |
| 894 | data->capabilities.usb488_device_capabilities = buffer[15]; |
Gergely Imreh | d0a3836 | 2009-09-07 10:47:01 +0800 | [diff] [blame] | 895 | rv = 0; |
Greg Kroah-Hartman | 5b775f6 | 2008-08-26 16:22:06 -0700 | [diff] [blame] | 896 | |
Oliver Neukum | ca157c4 | 2009-07-02 16:41:39 +0200 | [diff] [blame] | 897 | err_out: |
Greg Kroah-Hartman | 5b775f6 | 2008-08-26 16:22:06 -0700 | [diff] [blame] | 898 | kfree(buffer); |
Oliver Neukum | ca157c4 | 2009-07-02 16:41:39 +0200 | [diff] [blame] | 899 | return rv; |
Greg Kroah-Hartman | 5b775f6 | 2008-08-26 16:22:06 -0700 | [diff] [blame] | 900 | } |
| 901 | |
| 902 | #define capability_attribute(name) \ |
| 903 | static ssize_t show_##name(struct device *dev, \ |
| 904 | struct device_attribute *attr, char *buf) \ |
| 905 | { \ |
| 906 | struct usb_interface *intf = to_usb_interface(dev); \ |
| 907 | struct usbtmc_device_data *data = usb_get_intfdata(intf); \ |
| 908 | \ |
| 909 | return sprintf(buf, "%d\n", data->capabilities.name); \ |
| 910 | } \ |
| 911 | static DEVICE_ATTR(name, S_IRUGO, show_##name, NULL) |
| 912 | |
| 913 | capability_attribute(interface_capabilities); |
| 914 | capability_attribute(device_capabilities); |
| 915 | capability_attribute(usb488_interface_capabilities); |
| 916 | capability_attribute(usb488_device_capabilities); |
| 917 | |
| 918 | static struct attribute *capability_attrs[] = { |
| 919 | &dev_attr_interface_capabilities.attr, |
| 920 | &dev_attr_device_capabilities.attr, |
| 921 | &dev_attr_usb488_interface_capabilities.attr, |
| 922 | &dev_attr_usb488_device_capabilities.attr, |
| 923 | NULL, |
| 924 | }; |
| 925 | |
| 926 | static struct attribute_group capability_attr_grp = { |
| 927 | .attrs = capability_attrs, |
| 928 | }; |
| 929 | |
| 930 | static ssize_t show_TermChar(struct device *dev, |
| 931 | struct device_attribute *attr, char *buf) |
| 932 | { |
| 933 | struct usb_interface *intf = to_usb_interface(dev); |
| 934 | struct usbtmc_device_data *data = usb_get_intfdata(intf); |
| 935 | |
| 936 | return sprintf(buf, "%c\n", data->TermChar); |
| 937 | } |
| 938 | |
| 939 | static ssize_t store_TermChar(struct device *dev, |
| 940 | struct device_attribute *attr, |
| 941 | const char *buf, size_t count) |
| 942 | { |
| 943 | struct usb_interface *intf = to_usb_interface(dev); |
| 944 | struct usbtmc_device_data *data = usb_get_intfdata(intf); |
| 945 | |
| 946 | if (count < 1) |
| 947 | return -EINVAL; |
| 948 | data->TermChar = buf[0]; |
| 949 | return count; |
| 950 | } |
| 951 | static DEVICE_ATTR(TermChar, S_IRUGO, show_TermChar, store_TermChar); |
| 952 | |
| 953 | #define data_attribute(name) \ |
| 954 | static ssize_t show_##name(struct device *dev, \ |
| 955 | struct device_attribute *attr, char *buf) \ |
| 956 | { \ |
| 957 | struct usb_interface *intf = to_usb_interface(dev); \ |
| 958 | struct usbtmc_device_data *data = usb_get_intfdata(intf); \ |
| 959 | \ |
| 960 | return sprintf(buf, "%d\n", data->name); \ |
| 961 | } \ |
| 962 | static ssize_t store_##name(struct device *dev, \ |
| 963 | struct device_attribute *attr, \ |
| 964 | const char *buf, size_t count) \ |
| 965 | { \ |
| 966 | struct usb_interface *intf = to_usb_interface(dev); \ |
| 967 | struct usbtmc_device_data *data = usb_get_intfdata(intf); \ |
| 968 | ssize_t result; \ |
| 969 | unsigned val; \ |
| 970 | \ |
| 971 | result = sscanf(buf, "%u\n", &val); \ |
| 972 | if (result != 1) \ |
| 973 | result = -EINVAL; \ |
| 974 | data->name = val; \ |
| 975 | if (result < 0) \ |
| 976 | return result; \ |
| 977 | else \ |
| 978 | return count; \ |
| 979 | } \ |
| 980 | static DEVICE_ATTR(name, S_IRUGO, show_##name, store_##name) |
| 981 | |
| 982 | data_attribute(TermCharEnabled); |
| 983 | data_attribute(auto_abort); |
| 984 | |
| 985 | static struct attribute *data_attrs[] = { |
| 986 | &dev_attr_TermChar.attr, |
| 987 | &dev_attr_TermCharEnabled.attr, |
| 988 | &dev_attr_auto_abort.attr, |
| 989 | NULL, |
| 990 | }; |
| 991 | |
| 992 | static struct attribute_group data_attr_grp = { |
| 993 | .attrs = data_attrs, |
| 994 | }; |
| 995 | |
| 996 | static int usbtmc_ioctl_indicator_pulse(struct usbtmc_device_data *data) |
| 997 | { |
| 998 | struct device *dev; |
| 999 | u8 *buffer; |
| 1000 | int rv; |
| 1001 | |
| 1002 | dev = &data->intf->dev; |
| 1003 | |
| 1004 | buffer = kmalloc(2, GFP_KERNEL); |
| 1005 | if (!buffer) |
| 1006 | return -ENOMEM; |
| 1007 | |
| 1008 | rv = usb_control_msg(data->usb_dev, |
| 1009 | usb_rcvctrlpipe(data->usb_dev, 0), |
| 1010 | USBTMC_REQUEST_INDICATOR_PULSE, |
| 1011 | USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE, |
| 1012 | 0, 0, buffer, 0x01, USBTMC_TIMEOUT); |
| 1013 | |
| 1014 | if (rv < 0) { |
| 1015 | dev_err(dev, "usb_control_msg returned %d\n", rv); |
| 1016 | goto exit; |
| 1017 | } |
| 1018 | |
| 1019 | dev_dbg(dev, "INDICATOR_PULSE returned %x\n", buffer[0]); |
| 1020 | |
| 1021 | if (buffer[0] != USBTMC_STATUS_SUCCESS) { |
| 1022 | dev_err(dev, "INDICATOR_PULSE returned %x\n", buffer[0]); |
| 1023 | rv = -EPERM; |
| 1024 | goto exit; |
| 1025 | } |
| 1026 | rv = 0; |
| 1027 | |
| 1028 | exit: |
| 1029 | kfree(buffer); |
| 1030 | return rv; |
| 1031 | } |
| 1032 | |
| 1033 | static long usbtmc_ioctl(struct file *file, unsigned int cmd, unsigned long arg) |
| 1034 | { |
| 1035 | struct usbtmc_device_data *data; |
| 1036 | int retval = -EBADRQC; |
| 1037 | |
| 1038 | data = file->private_data; |
| 1039 | mutex_lock(&data->io_mutex); |
Oliver Neukum | 8628688 | 2009-07-02 11:36:30 +0200 | [diff] [blame] | 1040 | if (data->zombie) { |
| 1041 | retval = -ENODEV; |
| 1042 | goto skip_io_on_zombie; |
| 1043 | } |
Greg Kroah-Hartman | 5b775f6 | 2008-08-26 16:22:06 -0700 | [diff] [blame] | 1044 | |
| 1045 | switch (cmd) { |
| 1046 | case USBTMC_IOCTL_CLEAR_OUT_HALT: |
| 1047 | retval = usbtmc_ioctl_clear_out_halt(data); |
Greg Kroah-Hartman | a92b63e | 2009-06-15 13:13:05 -0700 | [diff] [blame] | 1048 | break; |
Greg Kroah-Hartman | 5b775f6 | 2008-08-26 16:22:06 -0700 | [diff] [blame] | 1049 | |
| 1050 | case USBTMC_IOCTL_CLEAR_IN_HALT: |
| 1051 | retval = usbtmc_ioctl_clear_in_halt(data); |
Greg Kroah-Hartman | a92b63e | 2009-06-15 13:13:05 -0700 | [diff] [blame] | 1052 | break; |
Greg Kroah-Hartman | 5b775f6 | 2008-08-26 16:22:06 -0700 | [diff] [blame] | 1053 | |
| 1054 | case USBTMC_IOCTL_INDICATOR_PULSE: |
| 1055 | retval = usbtmc_ioctl_indicator_pulse(data); |
Greg Kroah-Hartman | a92b63e | 2009-06-15 13:13:05 -0700 | [diff] [blame] | 1056 | break; |
Greg Kroah-Hartman | 5b775f6 | 2008-08-26 16:22:06 -0700 | [diff] [blame] | 1057 | |
| 1058 | case USBTMC_IOCTL_CLEAR: |
| 1059 | retval = usbtmc_ioctl_clear(data); |
Greg Kroah-Hartman | a92b63e | 2009-06-15 13:13:05 -0700 | [diff] [blame] | 1060 | break; |
Greg Kroah-Hartman | 5b775f6 | 2008-08-26 16:22:06 -0700 | [diff] [blame] | 1061 | |
| 1062 | case USBTMC_IOCTL_ABORT_BULK_OUT: |
| 1063 | retval = usbtmc_ioctl_abort_bulk_out(data); |
Greg Kroah-Hartman | a92b63e | 2009-06-15 13:13:05 -0700 | [diff] [blame] | 1064 | break; |
Greg Kroah-Hartman | 5b775f6 | 2008-08-26 16:22:06 -0700 | [diff] [blame] | 1065 | |
| 1066 | case USBTMC_IOCTL_ABORT_BULK_IN: |
| 1067 | retval = usbtmc_ioctl_abort_bulk_in(data); |
Greg Kroah-Hartman | a92b63e | 2009-06-15 13:13:05 -0700 | [diff] [blame] | 1068 | break; |
Greg Kroah-Hartman | 5b775f6 | 2008-08-26 16:22:06 -0700 | [diff] [blame] | 1069 | } |
| 1070 | |
Oliver Neukum | 8628688 | 2009-07-02 11:36:30 +0200 | [diff] [blame] | 1071 | skip_io_on_zombie: |
Greg Kroah-Hartman | 5b775f6 | 2008-08-26 16:22:06 -0700 | [diff] [blame] | 1072 | mutex_unlock(&data->io_mutex); |
| 1073 | return retval; |
| 1074 | } |
| 1075 | |
Alexey Dobriyan | 828c095 | 2009-10-01 15:43:56 -0700 | [diff] [blame] | 1076 | static const struct file_operations fops = { |
Greg Kroah-Hartman | 5b775f6 | 2008-08-26 16:22:06 -0700 | [diff] [blame] | 1077 | .owner = THIS_MODULE, |
| 1078 | .read = usbtmc_read, |
| 1079 | .write = usbtmc_write, |
| 1080 | .open = usbtmc_open, |
| 1081 | .release = usbtmc_release, |
| 1082 | .unlocked_ioctl = usbtmc_ioctl, |
Arnd Bergmann | 6038f37 | 2010-08-15 18:52:59 +0200 | [diff] [blame] | 1083 | .llseek = default_llseek, |
Greg Kroah-Hartman | 5b775f6 | 2008-08-26 16:22:06 -0700 | [diff] [blame] | 1084 | }; |
| 1085 | |
| 1086 | static struct usb_class_driver usbtmc_class = { |
| 1087 | .name = "usbtmc%d", |
| 1088 | .fops = &fops, |
| 1089 | .minor_base = USBTMC_MINOR_BASE, |
| 1090 | }; |
| 1091 | |
| 1092 | |
| 1093 | static int usbtmc_probe(struct usb_interface *intf, |
| 1094 | const struct usb_device_id *id) |
| 1095 | { |
| 1096 | struct usbtmc_device_data *data; |
| 1097 | struct usb_host_interface *iface_desc; |
| 1098 | struct usb_endpoint_descriptor *endpoint; |
| 1099 | int n; |
| 1100 | int retcode; |
| 1101 | |
| 1102 | dev_dbg(&intf->dev, "%s called\n", __func__); |
| 1103 | |
| 1104 | data = kmalloc(sizeof(struct usbtmc_device_data), GFP_KERNEL); |
| 1105 | if (!data) { |
| 1106 | dev_err(&intf->dev, "Unable to allocate kernel memory\n"); |
| 1107 | return -ENOMEM; |
| 1108 | } |
| 1109 | |
| 1110 | data->intf = intf; |
| 1111 | data->id = id; |
| 1112 | data->usb_dev = usb_get_dev(interface_to_usbdev(intf)); |
| 1113 | usb_set_intfdata(intf, data); |
| 1114 | kref_init(&data->kref); |
| 1115 | mutex_init(&data->io_mutex); |
Oliver Neukum | 8628688 | 2009-07-02 11:36:30 +0200 | [diff] [blame] | 1116 | data->zombie = 0; |
Greg Kroah-Hartman | 5b775f6 | 2008-08-26 16:22:06 -0700 | [diff] [blame] | 1117 | |
Alexandre Peixoto Ferreira | c2e3148 | 2013-04-30 00:51:52 -0500 | [diff] [blame] | 1118 | /* Determine if it is a Rigol or not */ |
| 1119 | data->rigol_quirk = 0; |
| 1120 | dev_dbg(&intf->dev, "Trying to find if device Vendor 0x%04X Product 0x%04X has the RIGOL quirk\n", |
| 1121 | data->usb_dev->descriptor.idVendor, |
| 1122 | data->usb_dev->descriptor.idProduct); |
| 1123 | for(n = 0; usbtmc_id_quirk[n].idVendor > 0; n++) { |
| 1124 | if ((usbtmc_id_quirk[n].idVendor == data->usb_dev->descriptor.idVendor) && |
| 1125 | (usbtmc_id_quirk[n].idProduct == data->usb_dev->descriptor.idProduct)) { |
| 1126 | dev_dbg(&intf->dev, "Setting this device as having the RIGOL quirk\n"); |
| 1127 | data->rigol_quirk = 1; |
| 1128 | break; |
| 1129 | } |
| 1130 | } |
| 1131 | |
Greg Kroah-Hartman | 5b775f6 | 2008-08-26 16:22:06 -0700 | [diff] [blame] | 1132 | /* Initialize USBTMC bTag and other fields */ |
| 1133 | data->bTag = 1; |
| 1134 | data->TermCharEnabled = 0; |
| 1135 | data->TermChar = '\n'; |
| 1136 | |
| 1137 | /* USBTMC devices have only one setting, so use that */ |
| 1138 | iface_desc = data->intf->cur_altsetting; |
| 1139 | |
| 1140 | /* Find bulk in endpoint */ |
| 1141 | for (n = 0; n < iface_desc->desc.bNumEndpoints; n++) { |
| 1142 | endpoint = &iface_desc->endpoint[n].desc; |
| 1143 | |
| 1144 | if (usb_endpoint_is_bulk_in(endpoint)) { |
| 1145 | data->bulk_in = endpoint->bEndpointAddress; |
| 1146 | dev_dbg(&intf->dev, "Found bulk in endpoint at %u\n", |
| 1147 | data->bulk_in); |
| 1148 | break; |
| 1149 | } |
| 1150 | } |
| 1151 | |
| 1152 | /* Find bulk out endpoint */ |
| 1153 | for (n = 0; n < iface_desc->desc.bNumEndpoints; n++) { |
| 1154 | endpoint = &iface_desc->endpoint[n].desc; |
| 1155 | |
| 1156 | if (usb_endpoint_is_bulk_out(endpoint)) { |
| 1157 | data->bulk_out = endpoint->bEndpointAddress; |
| 1158 | dev_dbg(&intf->dev, "Found Bulk out endpoint at %u\n", |
| 1159 | data->bulk_out); |
| 1160 | break; |
| 1161 | } |
| 1162 | } |
| 1163 | |
| 1164 | retcode = get_capabilities(data); |
| 1165 | if (retcode) |
| 1166 | dev_err(&intf->dev, "can't read capabilities\n"); |
| 1167 | else |
| 1168 | retcode = sysfs_create_group(&intf->dev.kobj, |
| 1169 | &capability_attr_grp); |
| 1170 | |
| 1171 | retcode = sysfs_create_group(&intf->dev.kobj, &data_attr_grp); |
| 1172 | |
| 1173 | retcode = usb_register_dev(intf, &usbtmc_class); |
| 1174 | if (retcode) { |
| 1175 | dev_err(&intf->dev, "Not able to get a minor" |
| 1176 | " (base %u, slice default): %d\n", USBTMC_MINOR_BASE, |
| 1177 | retcode); |
| 1178 | goto error_register; |
| 1179 | } |
| 1180 | dev_dbg(&intf->dev, "Using minor number %d\n", intf->minor); |
| 1181 | |
| 1182 | return 0; |
| 1183 | |
| 1184 | error_register: |
| 1185 | sysfs_remove_group(&intf->dev.kobj, &capability_attr_grp); |
| 1186 | sysfs_remove_group(&intf->dev.kobj, &data_attr_grp); |
| 1187 | kref_put(&data->kref, usbtmc_delete); |
| 1188 | return retcode; |
| 1189 | } |
| 1190 | |
| 1191 | static void usbtmc_disconnect(struct usb_interface *intf) |
| 1192 | { |
| 1193 | struct usbtmc_device_data *data; |
| 1194 | |
| 1195 | dev_dbg(&intf->dev, "usbtmc_disconnect called\n"); |
| 1196 | |
| 1197 | data = usb_get_intfdata(intf); |
| 1198 | usb_deregister_dev(intf, &usbtmc_class); |
| 1199 | sysfs_remove_group(&intf->dev.kobj, &capability_attr_grp); |
| 1200 | sysfs_remove_group(&intf->dev.kobj, &data_attr_grp); |
Oliver Neukum | 8628688 | 2009-07-02 11:36:30 +0200 | [diff] [blame] | 1201 | mutex_lock(&data->io_mutex); |
| 1202 | data->zombie = 1; |
| 1203 | mutex_unlock(&data->io_mutex); |
Greg Kroah-Hartman | 5b775f6 | 2008-08-26 16:22:06 -0700 | [diff] [blame] | 1204 | kref_put(&data->kref, usbtmc_delete); |
| 1205 | } |
| 1206 | |
Oliver Neukum | dca8cd0 | 2009-09-24 00:33:45 +0200 | [diff] [blame] | 1207 | static int usbtmc_suspend(struct usb_interface *intf, pm_message_t message) |
Oliver Neukum | a470810 | 2009-07-02 11:44:33 +0200 | [diff] [blame] | 1208 | { |
| 1209 | /* this driver does not have pending URBs */ |
| 1210 | return 0; |
| 1211 | } |
| 1212 | |
Oliver Neukum | dca8cd0 | 2009-09-24 00:33:45 +0200 | [diff] [blame] | 1213 | static int usbtmc_resume(struct usb_interface *intf) |
Oliver Neukum | a470810 | 2009-07-02 11:44:33 +0200 | [diff] [blame] | 1214 | { |
| 1215 | return 0; |
| 1216 | } |
| 1217 | |
Greg Kroah-Hartman | 5b775f6 | 2008-08-26 16:22:06 -0700 | [diff] [blame] | 1218 | static struct usb_driver usbtmc_driver = { |
| 1219 | .name = "usbtmc", |
| 1220 | .id_table = usbtmc_devices, |
| 1221 | .probe = usbtmc_probe, |
Oliver Neukum | a470810 | 2009-07-02 11:44:33 +0200 | [diff] [blame] | 1222 | .disconnect = usbtmc_disconnect, |
| 1223 | .suspend = usbtmc_suspend, |
| 1224 | .resume = usbtmc_resume, |
Greg Kroah-Hartman | 5b775f6 | 2008-08-26 16:22:06 -0700 | [diff] [blame] | 1225 | }; |
| 1226 | |
Greg Kroah-Hartman | 65db430 | 2011-11-18 09:34:02 -0800 | [diff] [blame] | 1227 | module_usb_driver(usbtmc_driver); |
Greg Kroah-Hartman | 5b775f6 | 2008-08-26 16:22:06 -0700 | [diff] [blame] | 1228 | |
| 1229 | MODULE_LICENSE("GPL"); |