1 // SPDX-License-Identifier: GPL-2.0+
3 * drivers/usb/class/usbtmc.c - USB Test & Measurement class driver
5 * Copyright (C) 2007 Stefan Kopp, Gechingen, Germany
6 * Copyright (C) 2008 Novell, Inc.
7 * Copyright (C) 2008 Greg Kroah-Hartman <gregkh@suse.de>
10 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
12 #include <linux/module.h>
13 #include <linux/kernel.h>
15 #include <linux/uaccess.h>
16 #include <linux/kref.h>
17 #include <linux/slab.h>
18 #include <linux/poll.h>
19 #include <linux/mutex.h>
20 #include <linux/usb.h>
21 #include <linux/compat.h>
22 #include <linux/usb/tmc.h>
25 #define USBTMC_HEADER_SIZE 12
26 #define USBTMC_MINOR_BASE 176
29 * Size of driver internal IO buffer. Must be multiple of 4 and at least as
30 * large as wMaxPacketSize (which is usually 512 bytes).
32 #define USBTMC_SIZE_IOBUFFER 2048
34 /* Minimum USB timeout (in milliseconds) */
35 #define USBTMC_MIN_TIMEOUT 100
36 /* Default USB timeout (in milliseconds) */
37 #define USBTMC_TIMEOUT 5000
40 * Maximum number of read cycles to empty bulk in endpoint during CLEAR and
41 * ABORT_BULK_IN requests. Ends the loop if (for whatever reason) a short
42 * packet is never read.
44 #define USBTMC_MAX_READS_TO_CLEAR_BULK_IN 100
46 static const struct usb_device_id usbtmc_devices
[] = {
47 { USB_INTERFACE_INFO(USB_CLASS_APP_SPEC
, 3, 0), },
48 { USB_INTERFACE_INFO(USB_CLASS_APP_SPEC
, 3, 1), },
49 { 0, } /* terminating entry */
51 MODULE_DEVICE_TABLE(usb
, usbtmc_devices
);
54 * This structure is the capabilities for the device
55 * See section 4.2.1.8 of the USBTMC specification,
56 * and section 4.2.2 of the USBTMC usb488 subclass
57 * specification for details.
59 struct usbtmc_dev_capabilities
{
60 __u8 interface_capabilities
;
61 __u8 device_capabilities
;
62 __u8 usb488_interface_capabilities
;
63 __u8 usb488_device_capabilities
;
66 /* This structure holds private data for each USBTMC device. One copy is
67 * allocated for each USBTMC device in the driver's probe function.
69 struct usbtmc_device_data
{
70 const struct usb_device_id
*id
;
71 struct usb_device
*usb_dev
;
72 struct usb_interface
*intf
;
73 struct list_head file_list
;
76 unsigned int bulk_out
;
79 u8 bTag_last_write
; /* needed for abort */
80 u8 bTag_last_read
; /* needed for abort */
82 /* data for interrupt in endpoint handling */
88 atomic_t iin_data_valid
;
93 u16 iin_wMaxPacketSize
;
95 /* coalesced usb488_caps from usbtmc_dev_capabilities */
98 /* attributes from the USB TMC spec for this device */
100 bool TermCharEnabled
;
103 bool zombie
; /* fd of disconnected device */
105 struct usbtmc_dev_capabilities capabilities
;
107 struct mutex io_mutex
; /* only one i/o function running at a time */
108 wait_queue_head_t waitq
;
109 struct fasync_struct
*fasync
;
110 spinlock_t dev_lock
; /* lock for file_list */
112 #define to_usbtmc_data(d) container_of(d, struct usbtmc_device_data, kref)
115 * This structure holds private data for each USBTMC file handle.
117 struct usbtmc_file_data
{
118 struct usbtmc_device_data
*data
;
119 struct list_head file_elem
;
123 atomic_t srq_asserted
;
126 bool term_char_enabled
;
129 /* Forward declarations */
130 static struct usb_driver usbtmc_driver
;
132 static void usbtmc_delete(struct kref
*kref
)
134 struct usbtmc_device_data
*data
= to_usbtmc_data(kref
);
136 usb_put_dev(data
->usb_dev
);
140 static int usbtmc_open(struct inode
*inode
, struct file
*filp
)
142 struct usb_interface
*intf
;
143 struct usbtmc_device_data
*data
;
144 struct usbtmc_file_data
*file_data
;
146 intf
= usb_find_interface(&usbtmc_driver
, iminor(inode
));
148 pr_err("can not find device for minor %d", iminor(inode
));
152 file_data
= kzalloc(sizeof(*file_data
), GFP_KERNEL
);
156 data
= usb_get_intfdata(intf
);
157 /* Protect reference to data from file structure until release */
158 kref_get(&data
->kref
);
160 mutex_lock(&data
->io_mutex
);
161 file_data
->data
= data
;
163 /* copy default values from device settings */
164 file_data
->timeout
= USBTMC_TIMEOUT
;
165 file_data
->term_char
= data
->TermChar
;
166 file_data
->term_char_enabled
= data
->TermCharEnabled
;
167 file_data
->eom_val
= 1;
169 INIT_LIST_HEAD(&file_data
->file_elem
);
170 spin_lock_irq(&data
->dev_lock
);
171 list_add_tail(&file_data
->file_elem
, &data
->file_list
);
172 spin_unlock_irq(&data
->dev_lock
);
173 mutex_unlock(&data
->io_mutex
);
175 /* Store pointer in file structure's private data field */
176 filp
->private_data
= file_data
;
181 static int usbtmc_release(struct inode
*inode
, struct file
*file
)
183 struct usbtmc_file_data
*file_data
= file
->private_data
;
185 /* prevent IO _AND_ usbtmc_interrupt */
186 mutex_lock(&file_data
->data
->io_mutex
);
187 spin_lock_irq(&file_data
->data
->dev_lock
);
189 list_del(&file_data
->file_elem
);
191 spin_unlock_irq(&file_data
->data
->dev_lock
);
192 mutex_unlock(&file_data
->data
->io_mutex
);
194 kref_put(&file_data
->data
->kref
, usbtmc_delete
);
195 file_data
->data
= NULL
;
200 static int usbtmc_ioctl_abort_bulk_in(struct usbtmc_device_data
*data
)
207 struct usb_host_interface
*current_setting
;
210 dev
= &data
->intf
->dev
;
211 buffer
= kmalloc(USBTMC_SIZE_IOBUFFER
, GFP_KERNEL
);
215 rv
= usb_control_msg(data
->usb_dev
,
216 usb_rcvctrlpipe(data
->usb_dev
, 0),
217 USBTMC_REQUEST_INITIATE_ABORT_BULK_IN
,
218 USB_DIR_IN
| USB_TYPE_CLASS
| USB_RECIP_ENDPOINT
,
219 data
->bTag_last_read
, data
->bulk_in
,
220 buffer
, 2, USBTMC_TIMEOUT
);
223 dev_err(dev
, "usb_control_msg returned %d\n", rv
);
227 dev_dbg(dev
, "INITIATE_ABORT_BULK_IN returned %x\n", buffer
[0]);
229 if (buffer
[0] == USBTMC_STATUS_FAILED
) {
234 if (buffer
[0] != USBTMC_STATUS_SUCCESS
) {
235 dev_err(dev
, "INITIATE_ABORT_BULK_IN returned %x\n",
242 current_setting
= data
->intf
->cur_altsetting
;
243 for (n
= 0; n
< current_setting
->desc
.bNumEndpoints
; n
++)
244 if (current_setting
->endpoint
[n
].desc
.bEndpointAddress
==
246 max_size
= usb_endpoint_maxp(¤t_setting
->endpoint
[n
].desc
);
249 dev_err(dev
, "Couldn't get wMaxPacketSize\n");
254 dev_dbg(&data
->intf
->dev
, "wMaxPacketSize is %d\n", max_size
);
259 dev_dbg(dev
, "Reading from bulk in EP\n");
261 rv
= usb_bulk_msg(data
->usb_dev
,
262 usb_rcvbulkpipe(data
->usb_dev
,
264 buffer
, USBTMC_SIZE_IOBUFFER
,
265 &actual
, USBTMC_TIMEOUT
);
270 dev_err(dev
, "usb_bulk_msg returned %d\n", rv
);
273 } while ((actual
== max_size
) &&
274 (n
< USBTMC_MAX_READS_TO_CLEAR_BULK_IN
));
276 if (actual
== max_size
) {
277 dev_err(dev
, "Couldn't clear device buffer within %d cycles\n",
278 USBTMC_MAX_READS_TO_CLEAR_BULK_IN
);
285 usbtmc_abort_bulk_in_status
:
286 rv
= usb_control_msg(data
->usb_dev
,
287 usb_rcvctrlpipe(data
->usb_dev
, 0),
288 USBTMC_REQUEST_CHECK_ABORT_BULK_IN_STATUS
,
289 USB_DIR_IN
| USB_TYPE_CLASS
| USB_RECIP_ENDPOINT
,
290 0, data
->bulk_in
, buffer
, 0x08,
294 dev_err(dev
, "usb_control_msg returned %d\n", rv
);
298 dev_dbg(dev
, "INITIATE_ABORT_BULK_IN returned %x\n", buffer
[0]);
300 if (buffer
[0] == USBTMC_STATUS_SUCCESS
) {
305 if (buffer
[0] != USBTMC_STATUS_PENDING
) {
306 dev_err(dev
, "INITIATE_ABORT_BULK_IN returned %x\n", buffer
[0]);
313 dev_dbg(dev
, "Reading from bulk in EP\n");
315 rv
= usb_bulk_msg(data
->usb_dev
,
316 usb_rcvbulkpipe(data
->usb_dev
,
318 buffer
, USBTMC_SIZE_IOBUFFER
,
319 &actual
, USBTMC_TIMEOUT
);
324 dev_err(dev
, "usb_bulk_msg returned %d\n", rv
);
327 } while ((actual
== max_size
) &&
328 (n
< USBTMC_MAX_READS_TO_CLEAR_BULK_IN
));
330 if (actual
== max_size
) {
331 dev_err(dev
, "Couldn't clear device buffer within %d cycles\n",
332 USBTMC_MAX_READS_TO_CLEAR_BULK_IN
);
337 goto usbtmc_abort_bulk_in_status
;
345 static int usbtmc_ioctl_abort_bulk_out_tag(struct usbtmc_device_data
*data
,
353 dev
= &data
->intf
->dev
;
355 buffer
= kmalloc(8, GFP_KERNEL
);
359 rv
= usb_control_msg(data
->usb_dev
,
360 usb_rcvctrlpipe(data
->usb_dev
, 0),
361 USBTMC_REQUEST_INITIATE_ABORT_BULK_OUT
,
362 USB_DIR_IN
| USB_TYPE_CLASS
| USB_RECIP_ENDPOINT
,
364 buffer
, 2, USB_CTRL_GET_TIMEOUT
);
367 dev_err(dev
, "usb_control_msg returned %d\n", rv
);
371 dev_dbg(dev
, "INITIATE_ABORT_BULK_OUT returned %x\n", buffer
[0]);
373 if (buffer
[0] != USBTMC_STATUS_SUCCESS
) {
374 dev_err(dev
, "INITIATE_ABORT_BULK_OUT returned %x\n",
382 usbtmc_abort_bulk_out_check_status
:
383 /* do not stress device with subsequent requests */
385 rv
= usb_control_msg(data
->usb_dev
,
386 usb_rcvctrlpipe(data
->usb_dev
, 0),
387 USBTMC_REQUEST_CHECK_ABORT_BULK_OUT_STATUS
,
388 USB_DIR_IN
| USB_TYPE_CLASS
| USB_RECIP_ENDPOINT
,
389 0, data
->bulk_out
, buffer
, 0x08,
390 USB_CTRL_GET_TIMEOUT
);
393 dev_err(dev
, "usb_control_msg returned %d\n", rv
);
397 dev_dbg(dev
, "CHECK_ABORT_BULK_OUT returned %x\n", buffer
[0]);
399 if (buffer
[0] == USBTMC_STATUS_SUCCESS
)
400 goto usbtmc_abort_bulk_out_clear_halt
;
402 if ((buffer
[0] == USBTMC_STATUS_PENDING
) &&
403 (n
< USBTMC_MAX_READS_TO_CLEAR_BULK_IN
))
404 goto usbtmc_abort_bulk_out_check_status
;
409 usbtmc_abort_bulk_out_clear_halt
:
410 rv
= usb_clear_halt(data
->usb_dev
,
411 usb_sndbulkpipe(data
->usb_dev
, data
->bulk_out
));
414 dev_err(dev
, "usb_control_msg returned %d\n", rv
);
424 static int usbtmc_ioctl_abort_bulk_out(struct usbtmc_device_data
*data
)
426 return usbtmc_ioctl_abort_bulk_out_tag(data
, data
->bTag_last_write
);
429 static int usbtmc488_ioctl_read_stb(struct usbtmc_file_data
*file_data
,
432 struct usbtmc_device_data
*data
= file_data
->data
;
433 struct device
*dev
= &data
->intf
->dev
;
434 int srq_asserted
= 0;
440 dev_dbg(dev
, "Enter ioctl_read_stb iin_ep_present: %d\n",
441 data
->iin_ep_present
);
443 spin_lock_irq(&data
->dev_lock
);
444 srq_asserted
= atomic_xchg(&file_data
->srq_asserted
, srq_asserted
);
446 /* a STB with SRQ is already received */
447 stb
= file_data
->srq_byte
;
448 spin_unlock_irq(&data
->dev_lock
);
449 rv
= put_user(stb
, (__u8 __user
*)arg
);
450 dev_dbg(dev
, "stb:0x%02x with srq received %d\n",
451 (unsigned int)stb
, rv
);
454 spin_unlock_irq(&data
->dev_lock
);
456 buffer
= kmalloc(8, GFP_KERNEL
);
460 atomic_set(&data
->iin_data_valid
, 0);
462 rv
= usb_control_msg(data
->usb_dev
,
463 usb_rcvctrlpipe(data
->usb_dev
, 0),
464 USBTMC488_REQUEST_READ_STATUS_BYTE
,
465 USB_DIR_IN
| USB_TYPE_CLASS
| USB_RECIP_INTERFACE
,
468 buffer
, 0x03, USBTMC_TIMEOUT
);
470 dev_err(dev
, "stb usb_control_msg returned %d\n", rv
);
474 if (buffer
[0] != USBTMC_STATUS_SUCCESS
) {
475 dev_err(dev
, "control status returned %x\n", buffer
[0]);
480 if (data
->iin_ep_present
) {
481 rv
= wait_event_interruptible_timeout(
483 atomic_read(&data
->iin_data_valid
) != 0,
486 dev_dbg(dev
, "wait interrupted %d\n", rv
);
491 dev_dbg(dev
, "wait timed out\n");
496 tag
= data
->bNotify1
& 0x7f;
497 if (tag
!= data
->iin_bTag
) {
498 dev_err(dev
, "expected bTag %x got %x\n",
499 data
->iin_bTag
, tag
);
502 stb
= data
->bNotify2
;
507 rv
= put_user(stb
, (__u8 __user
*)arg
);
508 dev_dbg(dev
, "stb:0x%02x received %d\n", (unsigned int)stb
, rv
);
511 /* bump interrupt bTag */
513 if (data
->iin_bTag
> 127)
514 /* 1 is for SRQ see USBTMC-USB488 subclass spec section 4.3.1 */
521 static int usbtmc488_ioctl_simple(struct usbtmc_device_data
*data
,
522 void __user
*arg
, unsigned int cmd
)
524 struct device
*dev
= &data
->intf
->dev
;
530 if (!(data
->usb488_caps
& USBTMC488_CAPABILITY_SIMPLE
))
533 buffer
= kmalloc(8, GFP_KERNEL
);
537 if (cmd
== USBTMC488_REQUEST_REN_CONTROL
) {
538 rv
= copy_from_user(&val
, arg
, sizeof(val
));
543 wValue
= val
? 1 : 0;
548 rv
= usb_control_msg(data
->usb_dev
,
549 usb_rcvctrlpipe(data
->usb_dev
, 0),
551 USB_DIR_IN
| USB_TYPE_CLASS
| USB_RECIP_INTERFACE
,
554 buffer
, 0x01, USBTMC_TIMEOUT
);
556 dev_err(dev
, "simple usb_control_msg failed %d\n", rv
);
558 } else if (rv
!= 1) {
559 dev_warn(dev
, "simple usb_control_msg returned %d\n", rv
);
564 if (buffer
[0] != USBTMC_STATUS_SUCCESS
) {
565 dev_err(dev
, "simple control status returned %x\n", buffer
[0]);
577 * Sends a TRIGGER Bulk-OUT command message
578 * See the USBTMC-USB488 specification, Table 2.
580 * Also updates bTag_last_write.
582 static int usbtmc488_ioctl_trigger(struct usbtmc_file_data
*file_data
)
584 struct usbtmc_device_data
*data
= file_data
->data
;
589 buffer
= kzalloc(USBTMC_HEADER_SIZE
, GFP_KERNEL
);
594 buffer
[1] = data
->bTag
;
595 buffer
[2] = ~data
->bTag
;
597 retval
= usb_bulk_msg(data
->usb_dev
,
598 usb_sndbulkpipe(data
->usb_dev
,
600 buffer
, USBTMC_HEADER_SIZE
,
601 &actual
, file_data
->timeout
);
603 /* Store bTag (in case we need to abort) */
604 data
->bTag_last_write
= data
->bTag
;
606 /* Increment bTag -- and increment again if zero */
613 dev_err(&data
->intf
->dev
, "%s returned %d\n",
622 * Sends a REQUEST_DEV_DEP_MSG_IN message on the Bulk-OUT endpoint.
623 * @transfer_size: number of bytes to request from the device.
625 * See the USBTMC specification, Table 4.
627 * Also updates bTag_last_write.
629 static int send_request_dev_dep_msg_in(struct usbtmc_file_data
*file_data
,
630 size_t transfer_size
)
632 struct usbtmc_device_data
*data
= file_data
->data
;
637 buffer
= kmalloc(USBTMC_HEADER_SIZE
, GFP_KERNEL
);
640 /* Setup IO buffer for REQUEST_DEV_DEP_MSG_IN message
641 * Refer to class specs for details
644 buffer
[1] = data
->bTag
;
645 buffer
[2] = ~data
->bTag
;
646 buffer
[3] = 0; /* Reserved */
647 buffer
[4] = transfer_size
>> 0;
648 buffer
[5] = transfer_size
>> 8;
649 buffer
[6] = transfer_size
>> 16;
650 buffer
[7] = transfer_size
>> 24;
651 buffer
[8] = file_data
->term_char_enabled
* 2;
652 /* Use term character? */
653 buffer
[9] = file_data
->term_char
;
654 buffer
[10] = 0; /* Reserved */
655 buffer
[11] = 0; /* Reserved */
658 retval
= usb_bulk_msg(data
->usb_dev
,
659 usb_sndbulkpipe(data
->usb_dev
,
661 buffer
, USBTMC_HEADER_SIZE
,
662 &actual
, file_data
->timeout
);
664 /* Store bTag (in case we need to abort) */
665 data
->bTag_last_write
= data
->bTag
;
667 /* Increment bTag -- and increment again if zero */
674 dev_err(&data
->intf
->dev
, "usb_bulk_msg in send_request_dev_dep_msg_in() returned %d\n", retval
);
681 static ssize_t
usbtmc_read(struct file
*filp
, char __user
*buf
,
682 size_t count
, loff_t
*f_pos
)
684 struct usbtmc_file_data
*file_data
;
685 struct usbtmc_device_data
*data
;
695 /* Get pointer to private data structure */
696 file_data
= filp
->private_data
;
697 data
= file_data
->data
;
698 dev
= &data
->intf
->dev
;
700 buffer
= kmalloc(USBTMC_SIZE_IOBUFFER
, GFP_KERNEL
);
704 mutex_lock(&data
->io_mutex
);
710 dev_dbg(dev
, "usb_bulk_msg_in: count(%zu)\n", count
);
712 retval
= send_request_dev_dep_msg_in(file_data
, count
);
715 if (data
->auto_abort
)
716 usbtmc_ioctl_abort_bulk_out(data
);
720 /* Loop until we have fetched everything we requested */
722 this_part
= remaining
;
725 while (remaining
> 0) {
727 retval
= usb_bulk_msg(data
->usb_dev
,
728 usb_rcvbulkpipe(data
->usb_dev
,
730 buffer
, USBTMC_SIZE_IOBUFFER
, &actual
,
733 dev_dbg(dev
, "usb_bulk_msg: retval(%u), done(%zu), remaining(%zu), actual(%d)\n", retval
, done
, remaining
, actual
);
735 /* Store bTag (in case we need to abort) */
736 data
->bTag_last_read
= data
->bTag
;
739 dev_dbg(dev
, "Unable to read data, error %d\n", retval
);
740 if (data
->auto_abort
)
741 usbtmc_ioctl_abort_bulk_in(data
);
745 /* Parse header in first packet */
747 /* Sanity checks for the header */
748 if (actual
< USBTMC_HEADER_SIZE
) {
749 dev_err(dev
, "Device sent too small first packet: %u < %u\n", actual
, USBTMC_HEADER_SIZE
);
750 if (data
->auto_abort
)
751 usbtmc_ioctl_abort_bulk_in(data
);
755 if (buffer
[0] != 2) {
756 dev_err(dev
, "Device sent reply with wrong MsgID: %u != 2\n", buffer
[0]);
757 if (data
->auto_abort
)
758 usbtmc_ioctl_abort_bulk_in(data
);
762 if (buffer
[1] != data
->bTag_last_write
) {
763 dev_err(dev
, "Device sent reply with wrong bTag: %u != %u\n", buffer
[1], data
->bTag_last_write
);
764 if (data
->auto_abort
)
765 usbtmc_ioctl_abort_bulk_in(data
);
769 /* How many characters did the instrument send? */
770 n_characters
= buffer
[4] +
775 if (n_characters
> this_part
) {
776 dev_err(dev
, "Device wants to return more data than requested: %u > %zu\n", n_characters
, count
);
777 if (data
->auto_abort
)
778 usbtmc_ioctl_abort_bulk_in(data
);
782 /* Remove the USBTMC header */
783 actual
-= USBTMC_HEADER_SIZE
;
785 /* Check if the message is smaller than requested */
786 if (remaining
> n_characters
)
787 remaining
= n_characters
;
788 /* Remove padding if it exists */
789 if (actual
> remaining
)
792 dev_dbg(dev
, "Bulk-IN header: N_characters(%u), bTransAttr(%u)\n", n_characters
, buffer
[8]);
796 /* Terminate if end-of-message bit received from device */
797 if ((buffer
[8] & 0x01) && (actual
>= n_characters
))
800 dev_dbg(dev
, "Bulk-IN header: remaining(%zu), buf(%p), buffer(%p) done(%zu)\n", remaining
,buf
,buffer
,done
);
803 /* Copy buffer to user space */
804 if (copy_to_user(buf
+ done
, &buffer
[USBTMC_HEADER_SIZE
], actual
)) {
805 /* There must have been an addressing problem */
812 if (actual
> remaining
)
817 dev_dbg(dev
, "Bulk-IN header cont: actual(%u), done(%zu), remaining(%zu), buf(%p), buffer(%p)\n", actual
, done
, remaining
,buf
,buffer
);
819 /* Copy buffer to user space */
820 if (copy_to_user(buf
+ done
, buffer
, actual
)) {
821 /* There must have been an addressing problem */
829 /* Update file position value */
830 *f_pos
= *f_pos
+ done
;
834 mutex_unlock(&data
->io_mutex
);
839 static ssize_t
usbtmc_write(struct file
*filp
, const char __user
*buf
,
840 size_t count
, loff_t
*f_pos
)
842 struct usbtmc_file_data
*file_data
;
843 struct usbtmc_device_data
*data
;
847 unsigned long int n_bytes
;
852 file_data
= filp
->private_data
;
853 data
= file_data
->data
;
855 buffer
= kmalloc(USBTMC_SIZE_IOBUFFER
, GFP_KERNEL
);
859 mutex_lock(&data
->io_mutex
);
868 while (remaining
> 0) {
869 if (remaining
> USBTMC_SIZE_IOBUFFER
- USBTMC_HEADER_SIZE
) {
870 this_part
= USBTMC_SIZE_IOBUFFER
- USBTMC_HEADER_SIZE
;
873 this_part
= remaining
;
874 buffer
[8] = file_data
->eom_val
;
877 /* Setup IO buffer for DEV_DEP_MSG_OUT message */
879 buffer
[1] = data
->bTag
;
880 buffer
[2] = ~data
->bTag
;
881 buffer
[3] = 0; /* Reserved */
882 buffer
[4] = this_part
>> 0;
883 buffer
[5] = this_part
>> 8;
884 buffer
[6] = this_part
>> 16;
885 buffer
[7] = this_part
>> 24;
886 /* buffer[8] is set above... */
887 buffer
[9] = 0; /* Reserved */
888 buffer
[10] = 0; /* Reserved */
889 buffer
[11] = 0; /* Reserved */
891 if (copy_from_user(&buffer
[USBTMC_HEADER_SIZE
], buf
+ done
, this_part
)) {
896 n_bytes
= roundup(USBTMC_HEADER_SIZE
+ this_part
, 4);
897 memset(buffer
+ USBTMC_HEADER_SIZE
+ this_part
, 0, n_bytes
- (USBTMC_HEADER_SIZE
+ this_part
));
900 retval
= usb_bulk_msg(data
->usb_dev
,
901 usb_sndbulkpipe(data
->usb_dev
,
904 &actual
, file_data
->timeout
);
910 data
->bTag_last_write
= data
->bTag
;
917 dev_err(&data
->intf
->dev
,
918 "Unable to send data, error %d\n", retval
);
919 if (data
->auto_abort
)
920 usbtmc_ioctl_abort_bulk_out(data
);
924 remaining
-= this_part
;
930 mutex_unlock(&data
->io_mutex
);
935 static int usbtmc_ioctl_clear(struct usbtmc_device_data
*data
)
937 struct usb_host_interface
*current_setting
;
938 struct usb_endpoint_descriptor
*desc
;
946 dev
= &data
->intf
->dev
;
948 dev_dbg(dev
, "Sending INITIATE_CLEAR request\n");
950 buffer
= kmalloc(USBTMC_SIZE_IOBUFFER
, GFP_KERNEL
);
954 rv
= usb_control_msg(data
->usb_dev
,
955 usb_rcvctrlpipe(data
->usb_dev
, 0),
956 USBTMC_REQUEST_INITIATE_CLEAR
,
957 USB_DIR_IN
| USB_TYPE_CLASS
| USB_RECIP_INTERFACE
,
958 0, 0, buffer
, 1, USBTMC_TIMEOUT
);
960 dev_err(dev
, "usb_control_msg returned %d\n", rv
);
964 dev_dbg(dev
, "INITIATE_CLEAR returned %x\n", buffer
[0]);
966 if (buffer
[0] != USBTMC_STATUS_SUCCESS
) {
967 dev_err(dev
, "INITIATE_CLEAR returned %x\n", buffer
[0]);
973 current_setting
= data
->intf
->cur_altsetting
;
974 for (n
= 0; n
< current_setting
->desc
.bNumEndpoints
; n
++) {
975 desc
= ¤t_setting
->endpoint
[n
].desc
;
976 if (desc
->bEndpointAddress
== data
->bulk_in
)
977 max_size
= usb_endpoint_maxp(desc
);
981 dev_err(dev
, "Couldn't get wMaxPacketSize\n");
986 dev_dbg(dev
, "wMaxPacketSize is %d\n", max_size
);
990 usbtmc_clear_check_status
:
992 dev_dbg(dev
, "Sending CHECK_CLEAR_STATUS request\n");
994 rv
= usb_control_msg(data
->usb_dev
,
995 usb_rcvctrlpipe(data
->usb_dev
, 0),
996 USBTMC_REQUEST_CHECK_CLEAR_STATUS
,
997 USB_DIR_IN
| USB_TYPE_CLASS
| USB_RECIP_INTERFACE
,
998 0, 0, buffer
, 2, USBTMC_TIMEOUT
);
1000 dev_err(dev
, "usb_control_msg returned %d\n", rv
);
1004 dev_dbg(dev
, "CHECK_CLEAR_STATUS returned %x\n", buffer
[0]);
1006 if (buffer
[0] == USBTMC_STATUS_SUCCESS
)
1007 goto usbtmc_clear_bulk_out_halt
;
1009 if (buffer
[0] != USBTMC_STATUS_PENDING
) {
1010 dev_err(dev
, "CHECK_CLEAR_STATUS returned %x\n", buffer
[0]);
1017 dev_dbg(dev
, "Reading from bulk in EP\n");
1020 rv
= usb_bulk_msg(data
->usb_dev
,
1021 usb_rcvbulkpipe(data
->usb_dev
,
1023 buffer
, USBTMC_SIZE_IOBUFFER
,
1024 &actual
, USBTMC_TIMEOUT
);
1028 dev_err(dev
, "usb_control_msg returned %d\n",
1032 } while ((actual
== max_size
) &&
1033 (n
< USBTMC_MAX_READS_TO_CLEAR_BULK_IN
));
1035 if (actual
== max_size
) {
1036 dev_err(dev
, "Couldn't clear device buffer within %d cycles\n",
1037 USBTMC_MAX_READS_TO_CLEAR_BULK_IN
);
1042 goto usbtmc_clear_check_status
;
1044 usbtmc_clear_bulk_out_halt
:
1046 rv
= usb_clear_halt(data
->usb_dev
,
1047 usb_sndbulkpipe(data
->usb_dev
, data
->bulk_out
));
1049 dev_err(dev
, "usb_control_msg returned %d\n", rv
);
1059 static int usbtmc_ioctl_clear_out_halt(struct usbtmc_device_data
*data
)
1063 rv
= usb_clear_halt(data
->usb_dev
,
1064 usb_sndbulkpipe(data
->usb_dev
, data
->bulk_out
));
1067 dev_err(&data
->usb_dev
->dev
, "usb_control_msg returned %d\n",
1074 static int usbtmc_ioctl_clear_in_halt(struct usbtmc_device_data
*data
)
1078 rv
= usb_clear_halt(data
->usb_dev
,
1079 usb_rcvbulkpipe(data
->usb_dev
, data
->bulk_in
));
1082 dev_err(&data
->usb_dev
->dev
, "usb_control_msg returned %d\n",
1089 static int get_capabilities(struct usbtmc_device_data
*data
)
1091 struct device
*dev
= &data
->usb_dev
->dev
;
1095 buffer
= kmalloc(0x18, GFP_KERNEL
);
1099 rv
= usb_control_msg(data
->usb_dev
, usb_rcvctrlpipe(data
->usb_dev
, 0),
1100 USBTMC_REQUEST_GET_CAPABILITIES
,
1101 USB_DIR_IN
| USB_TYPE_CLASS
| USB_RECIP_INTERFACE
,
1102 0, 0, buffer
, 0x18, USBTMC_TIMEOUT
);
1104 dev_err(dev
, "usb_control_msg returned %d\n", rv
);
1108 dev_dbg(dev
, "GET_CAPABILITIES returned %x\n", buffer
[0]);
1109 if (buffer
[0] != USBTMC_STATUS_SUCCESS
) {
1110 dev_err(dev
, "GET_CAPABILITIES returned %x\n", buffer
[0]);
1114 dev_dbg(dev
, "Interface capabilities are %x\n", buffer
[4]);
1115 dev_dbg(dev
, "Device capabilities are %x\n", buffer
[5]);
1116 dev_dbg(dev
, "USB488 interface capabilities are %x\n", buffer
[14]);
1117 dev_dbg(dev
, "USB488 device capabilities are %x\n", buffer
[15]);
1119 data
->capabilities
.interface_capabilities
= buffer
[4];
1120 data
->capabilities
.device_capabilities
= buffer
[5];
1121 data
->capabilities
.usb488_interface_capabilities
= buffer
[14];
1122 data
->capabilities
.usb488_device_capabilities
= buffer
[15];
1123 data
->usb488_caps
= (buffer
[14] & 0x07) | ((buffer
[15] & 0x0f) << 4);
1131 #define capability_attribute(name) \
1132 static ssize_t name##_show(struct device *dev, \
1133 struct device_attribute *attr, char *buf) \
1135 struct usb_interface *intf = to_usb_interface(dev); \
1136 struct usbtmc_device_data *data = usb_get_intfdata(intf); \
1138 return sprintf(buf, "%d\n", data->capabilities.name); \
1140 static DEVICE_ATTR_RO(name)
1142 capability_attribute(interface_capabilities
);
1143 capability_attribute(device_capabilities
);
1144 capability_attribute(usb488_interface_capabilities
);
1145 capability_attribute(usb488_device_capabilities
);
1147 static struct attribute
*capability_attrs
[] = {
1148 &dev_attr_interface_capabilities
.attr
,
1149 &dev_attr_device_capabilities
.attr
,
1150 &dev_attr_usb488_interface_capabilities
.attr
,
1151 &dev_attr_usb488_device_capabilities
.attr
,
1155 static const struct attribute_group capability_attr_grp
= {
1156 .attrs
= capability_attrs
,
1159 static ssize_t
TermChar_show(struct device
*dev
,
1160 struct device_attribute
*attr
, char *buf
)
1162 struct usb_interface
*intf
= to_usb_interface(dev
);
1163 struct usbtmc_device_data
*data
= usb_get_intfdata(intf
);
1165 return sprintf(buf
, "%c\n", data
->TermChar
);
1168 static ssize_t
TermChar_store(struct device
*dev
,
1169 struct device_attribute
*attr
,
1170 const char *buf
, size_t count
)
1172 struct usb_interface
*intf
= to_usb_interface(dev
);
1173 struct usbtmc_device_data
*data
= usb_get_intfdata(intf
);
1177 data
->TermChar
= buf
[0];
1180 static DEVICE_ATTR_RW(TermChar
);
1182 #define data_attribute(name) \
1183 static ssize_t name##_show(struct device *dev, \
1184 struct device_attribute *attr, char *buf) \
1186 struct usb_interface *intf = to_usb_interface(dev); \
1187 struct usbtmc_device_data *data = usb_get_intfdata(intf); \
1189 return sprintf(buf, "%d\n", data->name); \
1191 static ssize_t name##_store(struct device *dev, \
1192 struct device_attribute *attr, \
1193 const char *buf, size_t count) \
1195 struct usb_interface *intf = to_usb_interface(dev); \
1196 struct usbtmc_device_data *data = usb_get_intfdata(intf); \
1200 result = sscanf(buf, "%u\n", &val); \
1209 static DEVICE_ATTR_RW(name)
1211 data_attribute(TermCharEnabled
);
1212 data_attribute(auto_abort
);
1214 static struct attribute
*data_attrs
[] = {
1215 &dev_attr_TermChar
.attr
,
1216 &dev_attr_TermCharEnabled
.attr
,
1217 &dev_attr_auto_abort
.attr
,
1221 static const struct attribute_group data_attr_grp
= {
1222 .attrs
= data_attrs
,
1225 static int usbtmc_ioctl_indicator_pulse(struct usbtmc_device_data
*data
)
1231 dev
= &data
->intf
->dev
;
1233 buffer
= kmalloc(2, GFP_KERNEL
);
1237 rv
= usb_control_msg(data
->usb_dev
,
1238 usb_rcvctrlpipe(data
->usb_dev
, 0),
1239 USBTMC_REQUEST_INDICATOR_PULSE
,
1240 USB_DIR_IN
| USB_TYPE_CLASS
| USB_RECIP_INTERFACE
,
1241 0, 0, buffer
, 0x01, USBTMC_TIMEOUT
);
1244 dev_err(dev
, "usb_control_msg returned %d\n", rv
);
1248 dev_dbg(dev
, "INDICATOR_PULSE returned %x\n", buffer
[0]);
1250 if (buffer
[0] != USBTMC_STATUS_SUCCESS
) {
1251 dev_err(dev
, "INDICATOR_PULSE returned %x\n", buffer
[0]);
1263 * Get the usb timeout value
1265 static int usbtmc_ioctl_get_timeout(struct usbtmc_file_data
*file_data
,
1270 timeout
= file_data
->timeout
;
1272 return put_user(timeout
, (__u32 __user
*)arg
);
1276 * Set the usb timeout value
1278 static int usbtmc_ioctl_set_timeout(struct usbtmc_file_data
*file_data
,
1283 if (get_user(timeout
, (__u32 __user
*)arg
))
1286 /* Note that timeout = 0 means
1287 * MAX_SCHEDULE_TIMEOUT in usb_control_msg
1289 if (timeout
< USBTMC_MIN_TIMEOUT
)
1292 file_data
->timeout
= timeout
;
1298 * enables/disables sending EOM on write
1300 static int usbtmc_ioctl_eom_enable(struct usbtmc_file_data
*file_data
,
1305 if (copy_from_user(&eom_enable
, arg
, sizeof(eom_enable
)))
1311 file_data
->eom_val
= eom_enable
;
1317 * Configure termination character for read()
1319 static int usbtmc_ioctl_config_termc(struct usbtmc_file_data
*file_data
,
1322 struct usbtmc_termchar termc
;
1324 if (copy_from_user(&termc
, arg
, sizeof(termc
)))
1327 if ((termc
.term_char_enabled
> 1) ||
1328 (termc
.term_char_enabled
&&
1329 !(file_data
->data
->capabilities
.device_capabilities
& 1)))
1332 file_data
->term_char
= termc
.term_char
;
1333 file_data
->term_char_enabled
= termc
.term_char_enabled
;
1338 static long usbtmc_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
1340 struct usbtmc_file_data
*file_data
;
1341 struct usbtmc_device_data
*data
;
1342 int retval
= -EBADRQC
;
1344 file_data
= file
->private_data
;
1345 data
= file_data
->data
;
1347 mutex_lock(&data
->io_mutex
);
1350 goto skip_io_on_zombie
;
1354 case USBTMC_IOCTL_CLEAR_OUT_HALT
:
1355 retval
= usbtmc_ioctl_clear_out_halt(data
);
1358 case USBTMC_IOCTL_CLEAR_IN_HALT
:
1359 retval
= usbtmc_ioctl_clear_in_halt(data
);
1362 case USBTMC_IOCTL_INDICATOR_PULSE
:
1363 retval
= usbtmc_ioctl_indicator_pulse(data
);
1366 case USBTMC_IOCTL_CLEAR
:
1367 retval
= usbtmc_ioctl_clear(data
);
1370 case USBTMC_IOCTL_ABORT_BULK_OUT
:
1371 retval
= usbtmc_ioctl_abort_bulk_out(data
);
1374 case USBTMC_IOCTL_ABORT_BULK_IN
:
1375 retval
= usbtmc_ioctl_abort_bulk_in(data
);
1378 case USBTMC_IOCTL_GET_TIMEOUT
:
1379 retval
= usbtmc_ioctl_get_timeout(file_data
,
1380 (void __user
*)arg
);
1383 case USBTMC_IOCTL_SET_TIMEOUT
:
1384 retval
= usbtmc_ioctl_set_timeout(file_data
,
1385 (void __user
*)arg
);
1388 case USBTMC_IOCTL_EOM_ENABLE
:
1389 retval
= usbtmc_ioctl_eom_enable(file_data
,
1390 (void __user
*)arg
);
1393 case USBTMC_IOCTL_CONFIG_TERMCHAR
:
1394 retval
= usbtmc_ioctl_config_termc(file_data
,
1395 (void __user
*)arg
);
1398 case USBTMC488_IOCTL_GET_CAPS
:
1399 retval
= copy_to_user((void __user
*)arg
,
1401 sizeof(data
->usb488_caps
));
1406 case USBTMC488_IOCTL_READ_STB
:
1407 retval
= usbtmc488_ioctl_read_stb(file_data
,
1408 (void __user
*)arg
);
1411 case USBTMC488_IOCTL_REN_CONTROL
:
1412 retval
= usbtmc488_ioctl_simple(data
, (void __user
*)arg
,
1413 USBTMC488_REQUEST_REN_CONTROL
);
1416 case USBTMC488_IOCTL_GOTO_LOCAL
:
1417 retval
= usbtmc488_ioctl_simple(data
, (void __user
*)arg
,
1418 USBTMC488_REQUEST_GOTO_LOCAL
);
1421 case USBTMC488_IOCTL_LOCAL_LOCKOUT
:
1422 retval
= usbtmc488_ioctl_simple(data
, (void __user
*)arg
,
1423 USBTMC488_REQUEST_LOCAL_LOCKOUT
);
1426 case USBTMC488_IOCTL_TRIGGER
:
1427 retval
= usbtmc488_ioctl_trigger(file_data
);
1432 mutex_unlock(&data
->io_mutex
);
1436 static int usbtmc_fasync(int fd
, struct file
*file
, int on
)
1438 struct usbtmc_file_data
*file_data
= file
->private_data
;
1440 return fasync_helper(fd
, file
, on
, &file_data
->data
->fasync
);
1443 static __poll_t
usbtmc_poll(struct file
*file
, poll_table
*wait
)
1445 struct usbtmc_file_data
*file_data
= file
->private_data
;
1446 struct usbtmc_device_data
*data
= file_data
->data
;
1449 mutex_lock(&data
->io_mutex
);
1452 mask
= EPOLLHUP
| EPOLLERR
;
1456 poll_wait(file
, &data
->waitq
, wait
);
1458 mask
= (atomic_read(&file_data
->srq_asserted
)) ? EPOLLPRI
: 0;
1461 mutex_unlock(&data
->io_mutex
);
1465 static const struct file_operations fops
= {
1466 .owner
= THIS_MODULE
,
1467 .read
= usbtmc_read
,
1468 .write
= usbtmc_write
,
1469 .open
= usbtmc_open
,
1470 .release
= usbtmc_release
,
1471 .unlocked_ioctl
= usbtmc_ioctl
,
1472 #ifdef CONFIG_COMPAT
1473 .compat_ioctl
= usbtmc_ioctl
,
1475 .fasync
= usbtmc_fasync
,
1476 .poll
= usbtmc_poll
,
1477 .llseek
= default_llseek
,
1480 static struct usb_class_driver usbtmc_class
= {
1483 .minor_base
= USBTMC_MINOR_BASE
,
1486 static void usbtmc_interrupt(struct urb
*urb
)
1488 struct usbtmc_device_data
*data
= urb
->context
;
1489 struct device
*dev
= &data
->intf
->dev
;
1490 int status
= urb
->status
;
1493 dev_dbg(&data
->intf
->dev
, "int status: %d len %d\n",
1494 status
, urb
->actual_length
);
1497 case 0: /* SUCCESS */
1498 /* check for valid STB notification */
1499 if (data
->iin_buffer
[0] > 0x81) {
1500 data
->bNotify1
= data
->iin_buffer
[0];
1501 data
->bNotify2
= data
->iin_buffer
[1];
1502 atomic_set(&data
->iin_data_valid
, 1);
1503 wake_up_interruptible(&data
->waitq
);
1506 /* check for SRQ notification */
1507 if (data
->iin_buffer
[0] == 0x81) {
1508 unsigned long flags
;
1509 struct list_head
*elem
;
1512 kill_fasync(&data
->fasync
,
1515 spin_lock_irqsave(&data
->dev_lock
, flags
);
1516 list_for_each(elem
, &data
->file_list
) {
1517 struct usbtmc_file_data
*file_data
;
1519 file_data
= list_entry(elem
,
1520 struct usbtmc_file_data
,
1522 file_data
->srq_byte
= data
->iin_buffer
[1];
1523 atomic_set(&file_data
->srq_asserted
, 1);
1525 spin_unlock_irqrestore(&data
->dev_lock
, flags
);
1527 dev_dbg(dev
, "srq received bTag %x stb %x\n",
1528 (unsigned int)data
->iin_buffer
[0],
1529 (unsigned int)data
->iin_buffer
[1]);
1530 wake_up_interruptible_all(&data
->waitq
);
1533 dev_warn(dev
, "invalid notification: %x\n",
1534 data
->iin_buffer
[0]);
1537 dev_err(dev
, "overflow with length %d, actual length is %d\n",
1538 data
->iin_wMaxPacketSize
, urb
->actual_length
);
1546 /* urb terminated, clean up */
1547 dev_dbg(dev
, "urb terminated, status: %d\n", status
);
1550 dev_err(dev
, "unknown status received: %d\n", status
);
1553 rv
= usb_submit_urb(urb
, GFP_ATOMIC
);
1555 dev_err(dev
, "usb_submit_urb failed: %d\n", rv
);
1558 static void usbtmc_free_int(struct usbtmc_device_data
*data
)
1560 if (!data
->iin_ep_present
|| !data
->iin_urb
)
1562 usb_kill_urb(data
->iin_urb
);
1563 kfree(data
->iin_buffer
);
1564 usb_free_urb(data
->iin_urb
);
1565 kref_put(&data
->kref
, usbtmc_delete
);
1568 static int usbtmc_probe(struct usb_interface
*intf
,
1569 const struct usb_device_id
*id
)
1571 struct usbtmc_device_data
*data
;
1572 struct usb_host_interface
*iface_desc
;
1573 struct usb_endpoint_descriptor
*bulk_in
, *bulk_out
, *int_in
;
1576 dev_dbg(&intf
->dev
, "%s called\n", __func__
);
1578 data
= kzalloc(sizeof(*data
), GFP_KERNEL
);
1584 data
->usb_dev
= usb_get_dev(interface_to_usbdev(intf
));
1585 usb_set_intfdata(intf
, data
);
1586 kref_init(&data
->kref
);
1587 mutex_init(&data
->io_mutex
);
1588 init_waitqueue_head(&data
->waitq
);
1589 atomic_set(&data
->iin_data_valid
, 0);
1590 INIT_LIST_HEAD(&data
->file_list
);
1591 spin_lock_init(&data
->dev_lock
);
1595 /* Initialize USBTMC bTag and other fields */
1597 data
->TermCharEnabled
= 0;
1598 data
->TermChar
= '\n';
1599 /* 2 <= bTag <= 127 USBTMC-USB488 subclass specification 4.3.1 */
1602 /* USBTMC devices have only one setting, so use that */
1603 iface_desc
= data
->intf
->cur_altsetting
;
1604 data
->ifnum
= iface_desc
->desc
.bInterfaceNumber
;
1606 /* Find bulk endpoints */
1607 retcode
= usb_find_common_endpoints(iface_desc
,
1608 &bulk_in
, &bulk_out
, NULL
, NULL
);
1610 dev_err(&intf
->dev
, "bulk endpoints not found\n");
1614 data
->bulk_in
= bulk_in
->bEndpointAddress
;
1615 dev_dbg(&intf
->dev
, "Found bulk in endpoint at %u\n", data
->bulk_in
);
1617 data
->bulk_out
= bulk_out
->bEndpointAddress
;
1618 dev_dbg(&intf
->dev
, "Found Bulk out endpoint at %u\n", data
->bulk_out
);
1620 /* Find int endpoint */
1621 retcode
= usb_find_int_in_endpoint(iface_desc
, &int_in
);
1623 data
->iin_ep_present
= 1;
1624 data
->iin_ep
= int_in
->bEndpointAddress
;
1625 data
->iin_wMaxPacketSize
= usb_endpoint_maxp(int_in
);
1626 data
->iin_interval
= int_in
->bInterval
;
1627 dev_dbg(&intf
->dev
, "Found Int in endpoint at %u\n",
1631 retcode
= get_capabilities(data
);
1633 dev_err(&intf
->dev
, "can't read capabilities\n");
1635 retcode
= sysfs_create_group(&intf
->dev
.kobj
,
1636 &capability_attr_grp
);
1638 if (data
->iin_ep_present
) {
1639 /* allocate int urb */
1640 data
->iin_urb
= usb_alloc_urb(0, GFP_KERNEL
);
1641 if (!data
->iin_urb
) {
1643 goto error_register
;
1646 /* Protect interrupt in endpoint data until iin_urb is freed */
1647 kref_get(&data
->kref
);
1649 /* allocate buffer for interrupt in */
1650 data
->iin_buffer
= kmalloc(data
->iin_wMaxPacketSize
,
1652 if (!data
->iin_buffer
) {
1654 goto error_register
;
1657 /* fill interrupt urb */
1658 usb_fill_int_urb(data
->iin_urb
, data
->usb_dev
,
1659 usb_rcvintpipe(data
->usb_dev
, data
->iin_ep
),
1660 data
->iin_buffer
, data
->iin_wMaxPacketSize
,
1662 data
, data
->iin_interval
);
1664 retcode
= usb_submit_urb(data
->iin_urb
, GFP_KERNEL
);
1666 dev_err(&intf
->dev
, "Failed to submit iin_urb\n");
1667 goto error_register
;
1671 retcode
= sysfs_create_group(&intf
->dev
.kobj
, &data_attr_grp
);
1673 retcode
= usb_register_dev(intf
, &usbtmc_class
);
1675 dev_err(&intf
->dev
, "Not able to get a minor"
1676 " (base %u, slice default): %d\n", USBTMC_MINOR_BASE
,
1678 goto error_register
;
1680 dev_dbg(&intf
->dev
, "Using minor number %d\n", intf
->minor
);
1685 sysfs_remove_group(&intf
->dev
.kobj
, &capability_attr_grp
);
1686 sysfs_remove_group(&intf
->dev
.kobj
, &data_attr_grp
);
1687 usbtmc_free_int(data
);
1689 kref_put(&data
->kref
, usbtmc_delete
);
1693 static void usbtmc_disconnect(struct usb_interface
*intf
)
1695 struct usbtmc_device_data
*data
= usb_get_intfdata(intf
);
1697 usb_deregister_dev(intf
, &usbtmc_class
);
1698 sysfs_remove_group(&intf
->dev
.kobj
, &capability_attr_grp
);
1699 sysfs_remove_group(&intf
->dev
.kobj
, &data_attr_grp
);
1700 mutex_lock(&data
->io_mutex
);
1702 wake_up_interruptible_all(&data
->waitq
);
1703 mutex_unlock(&data
->io_mutex
);
1704 usbtmc_free_int(data
);
1705 kref_put(&data
->kref
, usbtmc_delete
);
1708 static int usbtmc_suspend(struct usb_interface
*intf
, pm_message_t message
)
1710 /* this driver does not have pending URBs */
1714 static int usbtmc_resume(struct usb_interface
*intf
)
1719 static struct usb_driver usbtmc_driver
= {
1721 .id_table
= usbtmc_devices
,
1722 .probe
= usbtmc_probe
,
1723 .disconnect
= usbtmc_disconnect
,
1724 .suspend
= usbtmc_suspend
,
1725 .resume
= usbtmc_resume
,
1728 module_usb_driver(usbtmc_driver
);
1730 MODULE_LICENSE("GPL");