Skip to content

Commit 29779d8

Browse files
dpenklergregkh
authored andcommitted
Add ioctl to retrieve USBTMC-USB488 capabilities
This is a convenience function to obtain an instrument's capabilities from its file descriptor without having to access sysfs from the user program. Signed-off-by: Dave Penkler <dpenkler@gmail.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent eb6b92e commit 29779d8

2 files changed

Lines changed: 30 additions & 3 deletions

File tree

‎drivers/usb/class/usbtmc.c‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ struct usbtmc_device_data {
102102
u16 iin_wMaxPacketSize;
103103
atomic_t srq_asserted;
104104

105+
/* coalesced usb488_caps from usbtmc_dev_capabilities */
106+
__u8 usb488_caps;
107+
105108
u8 rigol_quirk;
106109

107110
/* attributes from the USB TMC spec for this device */
@@ -993,6 +996,7 @@ static int get_capabilities(struct usbtmc_device_data *data)
993996
data->capabilities.device_capabilities = buffer[5];
994997
data->capabilities.usb488_interface_capabilities = buffer[14];
995998
data->capabilities.usb488_device_capabilities = buffer[15];
999+
data->usb488_caps = (buffer[14] & 0x07) | ((buffer[15] & 0x0f) << 4);
9961000
rv = 0;
9971001

9981002
err_out:
@@ -1168,6 +1172,14 @@ static long usbtmc_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
11681172
retval = usbtmc_ioctl_abort_bulk_in(data);
11691173
break;
11701174

1175+
case USBTMC488_IOCTL_GET_CAPS:
1176+
retval = copy_to_user((void __user *)arg,
1177+
&data->usb488_caps,
1178+
sizeof(data->usb488_caps));
1179+
if (retval)
1180+
retval = -EFAULT;
1181+
break;
1182+
11711183
case USBTMC488_IOCTL_READ_STB:
11721184
retval = usbtmc488_ioctl_read_stb(data, (void __user *)arg);
11731185
break;

‎include/uapi/linux/usb/tmc.h‎

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22
* Copyright (C) 2007 Stefan Kopp, Gechingen, Germany
33
* Copyright (C) 2008 Novell, Inc.
44
* Copyright (C) 2008 Greg Kroah-Hartman <gregkh@suse.de>
5+
* Copyright (C) 2015 Dave Penkler <dpenkler@gmail.com>
56
*
67
* This file holds USB constants defined by the USB Device Class
7-
* Definition for Test and Measurement devices published by the USB-IF.
8+
* and USB488 Subclass Definitions for Test and Measurement devices
9+
* published by the USB-IF.
810
*
9-
* It also has the ioctl definitions for the usbtmc kernel driver that
10-
* userspace needs to know about.
11+
* It also has the ioctl and capability definitions for the
12+
* usbtmc kernel driver that userspace needs to know about.
1113
*/
1214

1315
#ifndef __LINUX_USB_TMC_H
@@ -40,6 +42,19 @@
4042
#define USBTMC_IOCTL_ABORT_BULK_IN _IO(USBTMC_IOC_NR, 4)
4143
#define USBTMC_IOCTL_CLEAR_OUT_HALT _IO(USBTMC_IOC_NR, 6)
4244
#define USBTMC_IOCTL_CLEAR_IN_HALT _IO(USBTMC_IOC_NR, 7)
45+
#define USBTMC488_IOCTL_GET_CAPS _IOR(USBTMC_IOC_NR, 17, unsigned char)
4346
#define USBTMC488_IOCTL_READ_STB _IOR(USBTMC_IOC_NR, 18, unsigned char)
4447

48+
/* Driver encoded usb488 capabilities */
49+
#define USBTMC488_CAPABILITY_TRIGGER 1
50+
#define USBTMC488_CAPABILITY_SIMPLE 2
51+
#define USBTMC488_CAPABILITY_REN_CONTROL 2
52+
#define USBTMC488_CAPABILITY_GOTO_LOCAL 2
53+
#define USBTMC488_CAPABILITY_LOCAL_LOCKOUT 2
54+
#define USBTMC488_CAPABILITY_488_DOT_2 4
55+
#define USBTMC488_CAPABILITY_DT1 16
56+
#define USBTMC488_CAPABILITY_RL1 32
57+
#define USBTMC488_CAPABILITY_SR1 64
58+
#define USBTMC488_CAPABILITY_FULL_SCPI 128
59+
4560
#endif

0 commit comments

Comments
 (0)