Linux 3.11-rc3
[cris-mirror.git] / drivers / media / usb / dvb-usb-v2 / dvb_usb_urb.c
blob33ff97e708e3a8c2defa22491ab56cd1619fac8a
1 /*
2 * DVB USB framework
4 * Copyright (C) 2004-6 Patrick Boettcher <patrick.boettcher@desy.de>
5 * Copyright (C) 2012 Antti Palosaari <crope@iki.fi>
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.
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.
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.
22 #include "dvb_usb_common.h"
24 static int dvb_usb_v2_generic_io(struct dvb_usb_device *d,
25 u8 *wbuf, u16 wlen, u8 *rbuf, u16 rlen)
27 int ret, actual_length;
29 if (!d || !wbuf || !wlen || !d->props->generic_bulk_ctrl_endpoint ||
30 !d->props->generic_bulk_ctrl_endpoint_response) {
31 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, -EINVAL);
32 return -EINVAL;
35 dev_dbg(&d->udev->dev, "%s: >>> %*ph\n", __func__, wlen, wbuf);
37 ret = usb_bulk_msg(d->udev, usb_sndbulkpipe(d->udev,
38 d->props->generic_bulk_ctrl_endpoint), wbuf, wlen,
39 &actual_length, 2000);
40 if (ret < 0)
41 dev_err(&d->udev->dev, "%s: usb_bulk_msg() failed=%d\n",
42 KBUILD_MODNAME, ret);
43 else
44 ret = actual_length != wlen ? -EIO : 0;
46 /* an answer is expected, and no error before */
47 if (!ret && rbuf && rlen) {
48 if (d->props->generic_bulk_ctrl_delay)
49 usleep_range(d->props->generic_bulk_ctrl_delay,
50 d->props->generic_bulk_ctrl_delay
51 + 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,
58 "%s: 2nd usb_bulk_msg() failed=%d\n",
59 KBUILD_MODNAME, ret);
61 dev_dbg(&d->udev->dev, "%s: <<< %*ph\n", __func__,
62 actual_length, rbuf);
65 return ret;
68 int dvb_usbv2_generic_rw(struct dvb_usb_device *d,
69 u8 *wbuf, u16 wlen, u8 *rbuf, u16 rlen)
71 int ret;
73 mutex_lock(&d->usb_mutex);
74 ret = dvb_usb_v2_generic_io(d, wbuf, wlen, rbuf, rlen);
75 mutex_unlock(&d->usb_mutex);
77 return ret;
79 EXPORT_SYMBOL(dvb_usbv2_generic_rw);
81 int dvb_usbv2_generic_write(struct dvb_usb_device *d, u8 *buf, u16 len)
83 int ret;
85 mutex_lock(&d->usb_mutex);
86 ret = dvb_usb_v2_generic_io(d, buf, len, NULL, 0);
87 mutex_unlock(&d->usb_mutex);
89 return ret;
91 EXPORT_SYMBOL(dvb_usbv2_generic_write);
93 int dvb_usbv2_generic_rw_locked(struct dvb_usb_device *d,
94 u8 *wbuf, u16 wlen, u8 *rbuf, u16 rlen)
96 return dvb_usb_v2_generic_io(d, wbuf, wlen, rbuf, rlen);
98 EXPORT_SYMBOL(dvb_usbv2_generic_rw_locked);
100 int dvb_usbv2_generic_write_locked(struct dvb_usb_device *d, u8 *buf, u16 len)
102 return dvb_usb_v2_generic_io(d, buf, len, NULL, 0);
104 EXPORT_SYMBOL(dvb_usbv2_generic_write_locked);