dvb_usb_urb.c 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. * DVB USB framework
  3. *
  4. * Copyright (C) 2004-6 Patrick Boettcher <patrick.boettcher@desy.de>
  5. * Copyright (C) 2012 Antti Palosaari <crope@iki.fi>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License along
  18. * with this program; if not, write to the Free Software Foundation, Inc.,
  19. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  20. */
  21. #include "dvb_usb_common.h"
  22. #undef DVB_USB_XFER_DEBUG
  23. int dvb_usbv2_generic_rw(struct dvb_usb_device *d, u8 *wbuf, u16 wlen, u8 *rbuf,
  24. u16 rlen)
  25. {
  26. int ret, actual_length;
  27. if (!d || !wbuf || !wlen || !d->props->generic_bulk_ctrl_endpoint ||
  28. !d->props->generic_bulk_ctrl_endpoint_response) {
  29. dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, -EINVAL);
  30. return -EINVAL;
  31. }
  32. ret = mutex_lock_interruptible(&d->usb_mutex);
  33. if (ret < 0)
  34. return ret;
  35. #ifdef DVB_USB_XFER_DEBUG
  36. print_hex_dump(KERN_DEBUG, KBUILD_MODNAME ": >>> ", DUMP_PREFIX_NONE,
  37. 32, 1, wbuf, wlen, 0);
  38. #endif
  39. ret = usb_bulk_msg(d->udev, usb_sndbulkpipe(d->udev,
  40. d->props->generic_bulk_ctrl_endpoint), wbuf, wlen,
  41. &actual_length, 2000);
  42. if (ret < 0)
  43. dev_err(&d->udev->dev, "%s: usb_bulk_msg() failed=%d\n",
  44. KBUILD_MODNAME, ret);
  45. else
  46. ret = actual_length != wlen ? -EIO : 0;
  47. /* an answer is expected, and no error before */
  48. if (!ret && rbuf && rlen) {
  49. if (d->props->generic_bulk_ctrl_delay)
  50. usleep_range(d->props->generic_bulk_ctrl_delay,
  51. d->props->generic_bulk_ctrl_delay
  52. + 20000);
  53. ret = usb_bulk_msg(d->udev, usb_rcvbulkpipe(d->udev,
  54. d->props->generic_bulk_ctrl_endpoint_response),
  55. rbuf, rlen, &actual_length, 2000);
  56. if (ret)
  57. dev_err(&d->udev->dev, "%s: 2nd usb_bulk_msg() " \
  58. "failed=%d\n", KBUILD_MODNAME, ret);
  59. #ifdef DVB_USB_XFER_DEBUG
  60. print_hex_dump(KERN_DEBUG, KBUILD_MODNAME ": <<< ",
  61. DUMP_PREFIX_NONE, 32, 1, rbuf, actual_length,
  62. 0);
  63. #endif
  64. }
  65. mutex_unlock(&d->usb_mutex);
  66. return ret;
  67. }
  68. EXPORT_SYMBOL(dvb_usbv2_generic_rw);
  69. int dvb_usbv2_generic_write(struct dvb_usb_device *d, u8 *buf, u16 len)
  70. {
  71. return dvb_usbv2_generic_rw(d, buf, len, NULL, 0);
  72. }
  73. EXPORT_SYMBOL(dvb_usbv2_generic_write);