Merge tag 'regmap-fix-v5.11-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git...
[linux/fpc-iii.git] / drivers / media / usb / dvb-usb-v2 / dvb_usb_urb.c
blob7e817ea506c6a7875f1f3752ac50b6f6b474d525
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * DVB USB framework
5 * Copyright (C) 2004-6 Patrick Boettcher <patrick.boettcher@posteo.de>
6 * Copyright (C) 2012 Antti Palosaari <crope@iki.fi>
7 */
9 #include "dvb_usb_common.h"
11 static int dvb_usb_v2_generic_io(struct dvb_usb_device *d,
12 u8 *wbuf, u16 wlen, u8 *rbuf, u16 rlen)
14 int ret, actual_length;
16 if (!wbuf || !wlen || !d->props->generic_bulk_ctrl_endpoint ||
17 !d->props->generic_bulk_ctrl_endpoint_response) {
18 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, -EINVAL);
19 return -EINVAL;
22 dev_dbg(&d->udev->dev, "%s: >>> %*ph\n", __func__, wlen, wbuf);
24 ret = usb_bulk_msg(d->udev, usb_sndbulkpipe(d->udev,
25 d->props->generic_bulk_ctrl_endpoint), wbuf, wlen,
26 &actual_length, 2000);
27 if (ret) {
28 dev_err(&d->udev->dev, "%s: usb_bulk_msg() failed=%d\n",
29 KBUILD_MODNAME, ret);
30 return ret;
32 if (actual_length != wlen) {
33 dev_err(&d->udev->dev, "%s: usb_bulk_msg() write length=%d, actual=%d\n",
34 KBUILD_MODNAME, wlen, actual_length);
35 return -EIO;
38 /* an answer is expected */
39 if (rbuf && rlen) {
40 if (d->props->generic_bulk_ctrl_delay)
41 usleep_range(d->props->generic_bulk_ctrl_delay,
42 d->props->generic_bulk_ctrl_delay
43 + 20000);
45 ret = usb_bulk_msg(d->udev, usb_rcvbulkpipe(d->udev,
46 d->props->generic_bulk_ctrl_endpoint_response),
47 rbuf, rlen, &actual_length, 2000);
48 if (ret)
49 dev_err(&d->udev->dev,
50 "%s: 2nd usb_bulk_msg() failed=%d\n",
51 KBUILD_MODNAME, ret);
53 dev_dbg(&d->udev->dev, "%s: <<< %*ph\n", __func__,
54 actual_length, rbuf);
57 return ret;
60 int dvb_usbv2_generic_rw(struct dvb_usb_device *d,
61 u8 *wbuf, u16 wlen, u8 *rbuf, u16 rlen)
63 int ret;
65 mutex_lock(&d->usb_mutex);
66 ret = dvb_usb_v2_generic_io(d, wbuf, wlen, rbuf, rlen);
67 mutex_unlock(&d->usb_mutex);
69 return ret;
71 EXPORT_SYMBOL(dvb_usbv2_generic_rw);
73 int dvb_usbv2_generic_write(struct dvb_usb_device *d, u8 *buf, u16 len)
75 int ret;
77 mutex_lock(&d->usb_mutex);
78 ret = dvb_usb_v2_generic_io(d, buf, len, NULL, 0);
79 mutex_unlock(&d->usb_mutex);
81 return ret;
83 EXPORT_SYMBOL(dvb_usbv2_generic_write);
85 int dvb_usbv2_generic_rw_locked(struct dvb_usb_device *d,
86 u8 *wbuf, u16 wlen, u8 *rbuf, u16 rlen)
88 return dvb_usb_v2_generic_io(d, wbuf, wlen, rbuf, rlen);
90 EXPORT_SYMBOL(dvb_usbv2_generic_rw_locked);
92 int dvb_usbv2_generic_write_locked(struct dvb_usb_device *d, u8 *buf, u16 len)
94 return dvb_usb_v2_generic_io(d, buf, len, NULL, 0);
96 EXPORT_SYMBOL(dvb_usbv2_generic_write_locked);