diff options
author | Alexandre Peixoto Ferreira <alexandref75@gmail.com> | 2013-04-30 01:51:51 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2013-05-16 20:50:50 -0400 |
commit | 88d9b2b38c99d7d7f5eb557a56b6aaeaa392df86 (patch) | |
tree | 746e33f9d4f26ed73bc76ba42a836a238faa5ba3 /drivers/usb/class | |
parent | 8402db5dda3ac167014c143a633efff340aaff5b (diff) |
USB: usbtmc: TMC request code segregated from usbtmc_read
These patches implement a modification of the USBTMC
protocol to allow operation with Rigol equipment. The TMC request portion of
the code in function usbtmc_read is segregated to a function
send_request_dev_dep_msg_in as implemented by tommie in
https://github.com/tommie/linux/blob/usbtmc-rigol/drivers/usb/class/usbtmc.c
allowing the reuse later.
Signed-off-by: Alexandre Peixoto Ferreira <alexandref75@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/usb/class')
-rw-r--r-- | drivers/usb/class/usbtmc.c | 85 |
1 files changed, 54 insertions, 31 deletions
diff --git a/drivers/usb/class/usbtmc.c b/drivers/usb/class/usbtmc.c index c450b047e365..9c370427d2ef 100644 --- a/drivers/usb/class/usbtmc.c +++ b/drivers/usb/class/usbtmc.c | |||
@@ -375,6 +375,59 @@ exit: | |||
375 | return rv; | 375 | return rv; |
376 | } | 376 | } |
377 | 377 | ||
378 | /* | ||
379 | * Sends a REQUEST_DEV_DEP_MSG_IN message on the Bulk-IN endpoint. | ||
380 | * @transfer_size: number of bytes to request from the device. | ||
381 | * | ||
382 | * See the USBTMC specification, Table 4. | ||
383 | * | ||
384 | * Also updates bTag_last_write. | ||
385 | */ | ||
386 | static int send_request_dev_dep_msg_in(struct usbtmc_device_data *data, size_t transfer_size) | ||
387 | { | ||
388 | int retval; | ||
389 | u8 buffer[USBTMC_HEADER_SIZE]; | ||
390 | int actual; | ||
391 | |||
392 | /* Setup IO buffer for REQUEST_DEV_DEP_MSG_IN message | ||
393 | * Refer to class specs for details | ||
394 | */ | ||
395 | buffer[0] = 2; | ||
396 | buffer[1] = data->bTag; | ||
397 | buffer[2] = ~(data->bTag); | ||
398 | buffer[3] = 0; /* Reserved */ | ||
399 | buffer[4] = (transfer_size) & 255; | ||
400 | buffer[5] = ((transfer_size) >> 8) & 255; | ||
401 | buffer[6] = ((transfer_size) >> 16) & 255; | ||
402 | buffer[7] = ((transfer_size) >> 24) & 255; | ||
403 | buffer[8] = data->TermCharEnabled * 2; | ||
404 | /* Use term character? */ | ||
405 | buffer[9] = data->TermChar; | ||
406 | buffer[10] = 0; /* Reserved */ | ||
407 | buffer[11] = 0; /* Reserved */ | ||
408 | |||
409 | /* Send bulk URB */ | ||
410 | retval = usb_bulk_msg(data->usb_dev, | ||
411 | usb_sndbulkpipe(data->usb_dev, | ||
412 | data->bulk_out), | ||
413 | buffer, USBTMC_HEADER_SIZE, &actual, USBTMC_TIMEOUT); | ||
414 | |||
415 | /* Store bTag (in case we need to abort) */ | ||
416 | data->bTag_last_write = data->bTag; | ||
417 | |||
418 | /* Increment bTag -- and increment again if zero */ | ||
419 | data->bTag++; | ||
420 | if (!data->bTag) | ||
421 | (data->bTag)++; | ||
422 | |||
423 | if (retval < 0) { | ||
424 | dev_err(&data->intf->dev, "usb_bulk_msg in send_request_dev_dep_msg_in() returned %d\n", retval); | ||
425 | return retval; | ||
426 | } | ||
427 | |||
428 | return 0; | ||
429 | } | ||
430 | |||
378 | static ssize_t usbtmc_read(struct file *filp, char __user *buf, | 431 | static ssize_t usbtmc_read(struct file *filp, char __user *buf, |
379 | size_t count, loff_t *f_pos) | 432 | size_t count, loff_t *f_pos) |
380 | { | 433 | { |
@@ -411,37 +464,7 @@ static ssize_t usbtmc_read(struct file *filp, char __user *buf, | |||
411 | else | 464 | else |
412 | this_part = remaining; | 465 | this_part = remaining; |
413 | 466 | ||
414 | /* Setup IO buffer for DEV_DEP_MSG_IN message | 467 | retval = send_request_dev_dep_msg_in(data, this_part); |
415 | * Refer to class specs for details | ||
416 | */ | ||
417 | buffer[0] = 2; | ||
418 | buffer[1] = data->bTag; | ||
419 | buffer[2] = ~(data->bTag); | ||
420 | buffer[3] = 0; /* Reserved */ | ||
421 | buffer[4] = (this_part) & 255; | ||
422 | buffer[5] = ((this_part) >> 8) & 255; | ||
423 | buffer[6] = ((this_part) >> 16) & 255; | ||
424 | buffer[7] = ((this_part) >> 24) & 255; | ||
425 | buffer[8] = data->TermCharEnabled * 2; | ||
426 | /* Use term character? */ | ||
427 | buffer[9] = data->TermChar; | ||
428 | buffer[10] = 0; /* Reserved */ | ||
429 | buffer[11] = 0; /* Reserved */ | ||
430 | |||
431 | /* Send bulk URB */ | ||
432 | retval = usb_bulk_msg(data->usb_dev, | ||
433 | usb_sndbulkpipe(data->usb_dev, | ||
434 | data->bulk_out), | ||
435 | buffer, 12, &actual, USBTMC_TIMEOUT); | ||
436 | |||
437 | /* Store bTag (in case we need to abort) */ | ||
438 | data->bTag_last_write = data->bTag; | ||
439 | |||
440 | /* Increment bTag -- and increment again if zero */ | ||
441 | data->bTag++; | ||
442 | if (!data->bTag) | ||
443 | (data->bTag)++; | ||
444 | |||
445 | if (retval < 0) { | 468 | if (retval < 0) { |
446 | dev_err(dev, "usb_bulk_msg returned %d\n", retval); | 469 | dev_err(dev, "usb_bulk_msg returned %d\n", retval); |
447 | if (data->auto_abort) | 470 | if (data->auto_abort) |