dvb_usb_urb.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. static int dvb_usb_v2_generic_io(struct dvb_usb_device *d,
  23. u8 *wbuf, u16 wlen, u8 *rbuf, u16 rlen)
  24. {
  25. int ret, actual_length;
  26. if (!wbuf || !wlen || !d->props->generic_bulk_ctrl_endpoint ||
  27. !d->props->generic_bulk_ctrl_endpoint_response) {
  28. dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, -EINVAL);
  29. return -EINVAL;
  30. }
  31. dev_dbg(&d->udev->dev, "%s: >>> %*ph\n", __func__, wlen, wbuf);
  32. ret = usb_bulk_msg(d->udev, usb_sndbulkpipe(d->udev,
  33. d->props->generic_bulk_ctrl_endpoint), wbuf, wlen,
  34. &actual_length, 2000);
  35. if (ret < 0)
  36. dev_err(&d->udev->dev, "%s: usb_bulk_msg() failed=%d\n",
  37. KBUILD_MODNAME, ret);
  38. else
  39. ret = actual_length != wlen ? -EIO : 0;
  40. /* an answer is expected, and no error before */
  41. if (!ret && rbuf && rlen) {
  42. if (d->props->generic_bulk_ctrl_delay)
  43. usleep_range(d->props->generic_bulk_ctrl_delay,
  44. d->props->generic_bulk_ctrl_delay
  45. + 20000);
  46. ret = usb_bulk_msg(d->udev, usb_rcvbulkpipe(d->udev,
  47. d->props->generic_bulk_ctrl_endpoint_response),
  48. rbuf, rlen, &actual_length, 2000);
  49. if (ret)
  50. dev_err(&d->udev->dev,
  51. "%s: 2nd usb_bulk_msg() failed=%d\n",
  52. KBUILD_MODNAME, ret);
  53. dev_dbg(&d->udev->dev, "%s: <<< %*ph\n", __func__,
  54. actual_length, rbuf);
  55. }
  56. return ret;
  57. }
  58. int dvb_usbv2_generic_rw(struct dvb_usb_device *d,
  59. u8 *wbuf, u16 wlen, u8 *rbuf, u16 rlen)
  60. {
  61. int ret;
  62. mutex_lock(&d->usb_mutex);
  63. ret = dvb_usb_v2_generic_io(d, wbuf, wlen, rbuf, rlen);
  64. mutex_unlock(&d->usb_mutex);
  65. return ret;
  66. }
  67. EXPORT_SYMBOL(dvb_usbv2_generic_rw);
  68. int dvb_usbv2_generic_write(struct dvb_usb_device *d, u8 *buf, u16 len)
  69. {
  70. int ret;
  71. mutex_lock(&d->usb_mutex);
  72. ret = dvb_usb_v2_generic_io(d, buf, len, NULL, 0);
  73. mutex_unlock(&d->usb_mutex);
  74. return ret;
  75. }
  76. EXPORT_SYMBOL(dvb_usbv2_generic_write);
  77. int dvb_usbv2_generic_rw_locked(struct dvb_usb_device *d,
  78. u8 *wbuf, u16 wlen, u8 *rbuf, u16 rlen)
  79. {
  80. return dvb_usb_v2_generic_io(d, wbuf, wlen, rbuf, rlen);
  81. }
  82. EXPORT_SYMBOL(dvb_usbv2_generic_rw_locked);
  83. int dvb_usbv2_generic_write_locked(struct dvb_usb_device *d, u8 *buf, u16 len)
  84. {
  85. return dvb_usb_v2_generic_io(d, buf, len, NULL, 0);
  86. }
  87. EXPORT_SYMBOL(dvb_usbv2_generic_write_locked);