Re: usbtmc: vendor specific i/o

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Aug 03, 2016 at 05:59:59AM +0200, Greg Kroah-Hartman wrote:
> But your patch was "one-way", once you switched to the other mode, the
> old one could not be used :(

Yes, also was lacking proper description and signoff. So, I'm considering
ioctls based approach okay, although that question (the only one I really
had) was never answered.

After re-reading specifications [*] I decided to allow arbitrary MsgID
selection, as USB488 adds MsgID=TRIGGER (128) and other subclass
specifications may add other values.

[*] http://www.usb.org/developers/docs/devclass_docs/USBTMC_1_006a.zip

After sorting out all eventual objections, patch bellow will be turned
into proper one.

Thank you,
	ladis

diff --git a/drivers/usb/class/usbtmc.c b/drivers/usb/class/usbtmc.c
index 917a55c..c6d3ca3 100644
--- a/drivers/usb/class/usbtmc.c
+++ b/drivers/usb/class/usbtmc.c
@@ -84,6 +84,9 @@ struct usbtmc_device_data {
 	unsigned int bulk_in;
 	unsigned int bulk_out;
 
+	u8 msgid_in;
+	u8 msgid_out;
+
 	u8 bTag;
 	u8 bTag_last_write;	/* needed for abort */
 	u8 bTag_last_read;	/* needed for abort */
@@ -393,6 +396,20 @@ exit:
 	return rv;
 }
 
+static int usbtmc_ioctl_set_msgids(struct usbtmc_device_data *data,
+				void __user *arg)
+{
+	struct usbtmc_msg_ids val;
+
+	if (copy_from_user(&val, arg, sizeof(val)))
+		return -EFAULT;
+
+	data->msgid_in = val.in;
+	data->msgid_out = val.out;
+
+	return 0;
+}
+
 static int usbtmc488_ioctl_read_stb(struct usbtmc_device_data *data,
 				void __user *arg)
 {
@@ -549,7 +566,7 @@ static int send_request_dev_dep_msg_in(struct usbtmc_device_data *data, size_t t
 	/* Setup IO buffer for REQUEST_DEV_DEP_MSG_IN message
 	 * Refer to class specs for details
 	 */
-	buffer[0] = 2;
+	buffer[0] = data->msgid_in;
 	buffer[1] = data->bTag;
 	buffer[2] = ~data->bTag;
 	buffer[3] = 0; /* Reserved */
@@ -677,8 +694,8 @@ static ssize_t usbtmc_read(struct file *filp, char __user *buf,
 				goto exit;
 			}
 
-			if (buffer[0] != 2) {
-				dev_err(dev, "Device sent reply with wrong MsgID: %u != 2\n", buffer[0]);
+			if (buffer[0] != data->msgid_in) {
+				dev_err(dev, "Device sent reply with wrong MsgID: %u != %u\n", buffer[0], data->msgid_in);
 				if (data->auto_abort)
 					usbtmc_ioctl_abort_bulk_in(data);
 				goto exit;
@@ -807,7 +824,7 @@ static ssize_t usbtmc_write(struct file *filp, const char __user *buf,
 		}
 
 		/* Setup IO buffer for DEV_DEP_MSG_OUT message */
-		buffer[0] = 1;
+		buffer[0] = data->msgid_out;
 		buffer[1] = data->bTag;
 		buffer[2] = ~data->bTag;
 		buffer[3] = 0; /* Reserved */
@@ -1227,6 +1244,10 @@ static long usbtmc_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
 		retval = usbtmc_ioctl_abort_bulk_in(data);
 		break;
 
+	case USBTMC_IOCTL_SET_MSGIDS:
+		retval = usbtmc_ioctl_set_msgids(data, (void __user *)arg);
+		break;
+
 	case USBTMC488_IOCTL_GET_CAPS:
 		retval = copy_to_user((void __user *)arg,
 				&data->usb488_caps,
@@ -1409,6 +1430,8 @@ static int usbtmc_probe(struct usb_interface *intf,
 	}
 
 	/* Initialize USBTMC bTag and other fields */
+	data->msgid_in  = 2;
+	data->msgid_out = 1;
 	data->bTag	= 1;
 	data->TermCharEnabled = 0;
 	data->TermChar = '\n';
diff --git a/include/uapi/linux/usb/tmc.h b/include/uapi/linux/usb/tmc.h
index 2e59d9c..46f21cc 100644
--- a/include/uapi/linux/usb/tmc.h
+++ b/include/uapi/linux/usb/tmc.h
@@ -37,6 +37,12 @@
 #define USBTMC488_REQUEST_GOTO_LOCAL			161
 #define USBTMC488_REQUEST_LOCAL_LOCKOUT			162
 
+/* USB TMC command messages ids */
+struct usbtmc_msg_ids {
+	__u8 in;
+	__u8 out;
+};
+
 /* Request values for USBTMC driver's ioctl entry point */
 #define USBTMC_IOC_NR			91
 #define USBTMC_IOCTL_INDICATOR_PULSE	_IO(USBTMC_IOC_NR, 1)
@@ -45,6 +51,7 @@
 #define USBTMC_IOCTL_ABORT_BULK_IN	_IO(USBTMC_IOC_NR, 4)
 #define USBTMC_IOCTL_CLEAR_OUT_HALT	_IO(USBTMC_IOC_NR, 6)
 #define USBTMC_IOCTL_CLEAR_IN_HALT	_IO(USBTMC_IOC_NR, 7)
+#define USBTMC_IOCTL_SET_MSGIDS		_IOW(USBTMC_IOC_NR, 8, struct usbtmc_msg_ids)
 #define USBTMC488_IOCTL_GET_CAPS	_IOR(USBTMC_IOC_NR, 17, unsigned char)
 #define USBTMC488_IOCTL_READ_STB	_IOR(USBTMC_IOC_NR, 18, unsigned char)
 #define USBTMC488_IOCTL_REN_CONTROL	_IOW(USBTMC_IOC_NR, 19, unsigned char)
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux